Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src-tauri/src/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down
15 changes: 15 additions & 0 deletions src/lib/sync/kinds.test.js
Original file line number Diff line number Diff line change
@@ -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())
})
})
Loading