From d1d46bd0008310f76d9ab7970f05589102cf3116 Mon Sep 17 00:00:00 2001 From: broisnees Date: Wed, 18 Nov 2026 06:33:09 +0000 Subject: [PATCH] Sync saved queries and the library again The sync engine and the server both know five record kinds, but the Rust encryption step still listed three, so the first saved query or library item failed every push with "Unknown record kind". List all five, and add a test that keeps the JS and Rust lists the same. --- src-tauri/src/sync.rs | 9 +++++++-- src/lib/sync/kinds.test.js | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src/lib/sync/kinds.test.js diff --git a/src-tauri/src/sync.rs b/src-tauri/src/sync.rs index 3d33dc82..62a4f9ea 100644 --- a/src-tauri/src/sync.rs +++ b/src-tauri/src/sync.rs @@ -37,7 +37,10 @@ const WRAP_AAD: &[u8] = b"stroke-sync-key-v1"; pub const KDF_M_KIB: u32 = 65_536; pub const KDF_T: u32 = 3; pub const KDF_P: u32 = 1; -pub const KINDS: [&str; 3] = ["workspace", "connection", "settings"]; +/// Record kinds the app syncs. Keep in step with KINDS in src/lib/sync/engine.js +/// and SYNC_KINDS in stroke-web's src/lib/sync/service.ts: a kind missing here +/// fails the whole push ("Unknown record kind"). +pub const KINDS: [&str; 5] = ["workspace", "connection", "settings", "query", "library"]; /// Server limit per push. const PUSH_BATCH: usize = 200; const MIN_PASSPHRASE: usize = 8; @@ -654,7 +657,9 @@ mod tests { assert!(encrypt_plain(&key, &mk("settings", "settings")).is_ok()); assert!(encrypt_plain(&key, &mk("a b", "workspace")).is_err()); assert!(encrypt_plain(&key, &mk(&"x".repeat(129), "workspace")).is_err()); - assert!(encrypt_plain(&key, &mk("x", "query")).is_err()); + assert!(encrypt_plain(&key, &mk("x", "query")).is_ok()); + assert!(encrypt_plain(&key, &mk("x", "library")).is_ok()); + assert!(encrypt_plain(&key, &mk("x", "secrets")).is_err()); let tomb = encrypt_plain(&key, &PlainRecord { deleted: true, plaintext: None, ..mk("x", "workspace") }).unwrap(); assert!(tomb.ciphertext.is_none()); // Wire shape: no seq/updated_at on push. diff --git a/src/lib/sync/kinds.test.js b/src/lib/sync/kinds.test.js new file mode 100644 index 00000000..70b45b21 --- /dev/null +++ b/src/lib/sync/kinds.test.js @@ -0,0 +1,15 @@ +import { describe, it, expect } from 'vitest' +import { readFileSync } from 'node:fs' +import { KINDS } from './engine.js' + +// The Rust side encrypts every pushed record and refuses kinds it doesn't +// list, which fails the whole push. Keep the two lists the same. +describe('sync kinds', () => { + it('match the Rust list', () => { + const rs = readFileSync(new URL('../../../src-tauri/src/sync.rs', import.meta.url), 'utf8') + const m = /pub const KINDS: \[&str; \d+\] = \[([^\]]*)\]/.exec(rs) + expect(m).toBeTruthy() + const rust = [...m[1].matchAll(/"([^"]+)"/g)].map((x) => x[1]) + expect([...rust].sort()).toEqual([...KINDS].sort()) + }) +})