Skip to content

test: add rust-hook migration test for tags - #2365

Open
swarna1101 wants to merge 4 commits into
0xMiden:nextfrom
swarna1101:feat/sqlite-store-rust-hook-migration-tests
Open

test: add rust-hook migration test for tags#2365
swarna1101 wants to merge 4 commits into
0xMiden:nextfrom
swarna1101:feat/sqlite-store-rust-hook-migration-tests

Conversation

@swarna1101

@swarna1101 swarna1101 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@igamigo @gabrielbosio , follow-up to #2318. fixture v1->v2 on real tags; v2 uses M::up_with_hook to migrate legacy account-only source blobs to NoteTagSource wire format, via apply_migrations_with, checked with get_note_tags.

@igamigo igamigo added the no changelog This PR does not require an entry in the `CHANGELOG.md` file label Aug 6, 2026
@juan518munoz

Copy link
Copy Markdown
Collaborator

@swarna1101 I have pushed some tests that possibly raise issues with the hook implementation rather than the tests themselves, could you look into it?

@swarna1101

Copy link
Copy Markdown
Contributor Author

@swarna1101 I have pushed some tests that possibly raise issues with the hook implementation rather than the tests themselves, could you look into it?

the hook was using NoteTagSource::read_from_bytes as a skip probe, which misread 15-byte account ids starting with discriminant 2 as User. Fixed by checking len == AccountId::SERIALIZED_SIZE first; all three tests pass now.

@swarna1101

swarna1101 commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

hi @juan518munoz , let me know if you get a chance to take a look at this

@juan518munoz

Copy link
Copy Markdown
Collaborator

The happy path looks good. One gap worth naming before this lands: the schema fingerprint only covers sqlite_schema, so it cannot cross-check that a recorded user_version matches the data. Any migration with no footprint is invisible to it.

Concretely, a db stamped at v2 that never ran the hook is accepted and the re-encode is silently skipped:

#[test]
fn unencoded_rows_at_the_latest_version_go_undetected() {
    let mut conn = open_tags_db_at_v1();
    let account_id = test_account_id();
    insert_tag_row(&conn, NoteTag::with_account_target(account_id), &account_id.to_bytes());

    // Claim v2 without running the hook.
    conn.pragma_update(None, "user_version", 2).unwrap();

    // v2 has empty SQL, so both versions fingerprint identically and there is nothing to catch.
    assert_eq!(TAGS_FIXTURE_EXPECTED_SCHEMA_HASHES[0], TAGS_FIXTURE_EXPECTED_SCHEMA_HASHES[1]);
    apply_tags_fixture_migrations(&mut conn).expect("accepted despite legacy rows");
    assert_eq!(untransformed_source_count(&conn), 1);
}

Let's fix it here rather than leave it as a known hole.

@swarna1101

Copy link
Copy Markdown
Contributor Author

The happy path looks good. One gap worth naming before this lands: the schema fingerprint only covers sqlite_schema, so it cannot cross-check that a recorded user_version matches the data. Any migration with no footprint is invisible to it.

Concretely, a db stamped at v2 that never ran the hook is accepted and the re-encode is silently skipped:

#[test]
fn unencoded_rows_at_the_latest_version_go_undetected() {
    let mut conn = open_tags_db_at_v1();
    let account_id = test_account_id();
    insert_tag_row(&conn, NoteTag::with_account_target(account_id), &account_id.to_bytes());

    // Claim v2 without running the hook.
    conn.pragma_update(None, "user_version", 2).unwrap();

    // v2 has empty SQL, so both versions fingerprint identically and there is nothing to catch.
    assert_eq!(TAGS_FIXTURE_EXPECTED_SCHEMA_HASHES[0], TAGS_FIXTURE_EXPECTED_SCHEMA_HASHES[1]);
    apply_tags_fixture_migrations(&mut conn).expect("accepted despite legacy rows");
    assert_eq!(untransformed_source_count(&conn), 1);
}

Let's fix it here rather than leave it as a known hole.

Gave v2 a tags_encoding schema marker so a database stamped at v2 with a v1 schema now fails the fingerprint check instead of silently skipping the hook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no changelog This PR does not require an entry in the `CHANGELOG.md` file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants