Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
test(sync): enforce harness invariants
Marshall Bosee92db90dad54
diff --git a/test/helpers/harness/fakeCloud.js b/test/helpers/harness/fakeCloud.jsindex f779edeac..93d139530 100644--- a/test/helpers/harness/fakeCloud.js+++ b/test/helpers/harness/fakeCloud.js@@ -227,12 +227,17 @@ function createFakeCloud(config = {}) {const limitRaw = Number(query.get("limit"));const limit = Number.isFinite(limitRaw) && limitRaw > 0 ? limitRaw : 50;const since = query.get("since");+ const sinceId = query.get("since_id");const before = query.get("before");+ const beforeId = query.get("before_id");let rows = [...collection.store.values()];if (since) {const bound = normalizeTimestamp(since);- rows = rows.filter((r) => normalizeTimestamp(r.updated_at) > bound);+ rows = rows.filter((r) => {+ const timestampOrder = compare(normalizeTimestamp(r.updated_at), bound);+ return timestampOrder > 0 || (timestampOrder === 0 && (!sinceId || r.id > sinceId));+ });rows.sort((a, b) =>compare(normalizeTimestamp(a.updated_at), normalizeTimestamp(b.updated_at)) ||@@ -242,7 +247,10 @@ function createFakeCloud(config = {}) {rows = rows.filter((r) => !r.deleted_at);if (before) {const bound = normalizeTimestamp(before);- rows = rows.filter((r) => normalizeTimestamp(r[orderKey]) < bound);+ rows = rows.filter((r) => {+ const timestampOrder = compare(normalizeTimestamp(r[orderKey]), bound);+ return timestampOrder < 0 || (timestampOrder === 0 && !!beforeId && r.id < beforeId);+ });}rows.sort((a, b) =>diff --git a/test/helpers/harness/invariants.js b/test/helpers/harness/invariants.jsindex 317d6803a..405dc73c7 100644--- a/test/helpers/harness/invariants.js+++ b/test/helpers/harness/invariants.js@@ -40,21 +40,35 @@ function erasureExcused(cloudRow, before, after, field) {return (cloudRow[field] ?? null) === (after[field] ?? null);}+function deletionExcused(cloudRow, before) {+ if (before.deleted_at) return true;+ if (!cloudRow?.deleted_at) return false;+ return normalizeTimestamp(cloudRow.deleted_at) >= normalizeTimestamp(before.updated_at);+}+function assertNoContentRegression(dbBefore, dbAfter, cloudTruth) {const before = indexByClientId(dbBefore);+ const after = indexByClientId(dbAfter);const cloud = indexByClientId(cloudTruth instanceof Map ? [...cloudTruth.values()] : (cloudTruth ?? []));- for (const after of dbAfter ?? []) {- const prior = before.get(after.client_note_id);- if (!prior) continue;+ for (const prior of before.values()) {+ const current = after.get(prior.client_note_id);+ if (!current) {+ if (!CONTENT_FIELDS.some((field) => !isEmpty(prior[field]))) continue;+ if (deletionExcused(cloud.get(prior.client_note_id), prior)) continue;+ assert.fail(+ `sync hard-deleted note ${prior.id} (client_note_id ${prior.client_note_id}) ` ++ "without a matching cloud tombstone"+ );+ }for (const field of CONTENT_FIELDS) {- if (isEmpty(prior[field]) || !isEmpty(after[field])) continue;- if (erasureExcused(cloud.get(after.client_note_id), prior, after, field)) continue;+ if (isEmpty(prior[field]) || !isEmpty(current[field])) continue;+ if (erasureExcused(cloud.get(current.client_note_id), prior, current, field)) continue;assert.fail(- `sync erased ${field} on note ${after.id} (client_note_id ${after.client_note_id}): ` +- `had ${JSON.stringify(String(prior[field]).slice(0, 60))}, now ${JSON.stringify(after[field])}` ++ `sync erased ${field} on note ${current.id} (client_note_id ${current.client_note_id}): ` ++ `had ${JSON.stringify(String(prior[field]).slice(0, 60))}, now ${JSON.stringify(current[field])}` +" — and no strictly-newer non-empty cloud copy explains it");}diff --git a/test/helpers/syncHarness.test.js b/test/helpers/syncHarness.test.jsnew file mode 100644index 000000000..aed2b4178--- /dev/null+++ b/test/helpers/syncHarness.test.js@@ -0,0 +1,77 @@+const test = require("node:test");+const assert = require("node:assert/strict");++const { createFakeCloud } = require("./harness/fakeCloud.js");+const { assertNoContentRegression } = require("./harness/invariants.js");++const T1 = "2026-07-20T10:00:00.000Z";+const T2 = "2026-07-20T11:00:00.000Z";++function note(overrides = {}) {+ return {+ id: "local-1",+ client_note_id: "client-1",+ content: "important text",+ transcript: null,+ enhanced_content: null,+ deleted_at: null,+ updated_at: T1,+ ...overrides,+ };+}++test("content invariant rejects a note that disappears without a cloud tombstone", () => {+ assert.throws(+ () => assertNoContentRegression([note()], [], []),+ /sync hard-deleted note local-1/+ );+});++test("content invariant allows a note removed by a current cloud tombstone", () => {+ const tombstone = note({ id: "note-1", deleted_at: T2, updated_at: T2 });+ assert.doesNotThrow(() => assertNoContentRegression([note()], [], [tombstone]));+});++test("fake cloud paginates tied timestamps with the composite cursor id", async () => {+ const cloud = createFakeCloud();+ for (let i = 1; i <= 51; i += 1) {+ cloud.seedNote({+ client_note_id: `client-${i}`,+ content: `note ${i}`,+ created_at: T1,+ updated_at: T1,+ });+ }++ const snapshotFirst = await cloud.request({+ path: `/api/notes/list?limit=50&before=${encodeURIComponent(T2)}`,+ });+ assert.equal(snapshotFirst.success, true);+ assert.equal(snapshotFirst.data.notes.length, 50);+ const snapshotCursor = snapshotFirst.data.notes.at(-1);+ const snapshotSecond = await cloud.request({+ path:+ `/api/notes/list?limit=50&before=${encodeURIComponent(snapshotCursor.created_at)}` ++ `&before_id=${snapshotCursor.id}`,+ });+ assert.deepEqual(+ snapshotSecond.data.notes.map((row) => row.id),+ ["note-0001"]+ );++ const deltaFirst = await cloud.request({+ path: `/api/notes/list?limit=50&since=${encodeURIComponent(T1)}` + "&since_id=note-0000",+ });+ assert.equal(deltaFirst.success, true);+ assert.equal(deltaFirst.data.notes.length, 50);+ const deltaCursor = deltaFirst.data.notes.at(-1);+ const deltaSecond = await cloud.request({+ path:+ `/api/notes/list?limit=50&since=${encodeURIComponent(deltaCursor.updated_at)}` ++ `&since_id=${deltaCursor.id}`,+ });+ assert.deepEqual(+ deltaSecond.data.notes.map((row) => row.id),+ ["note-0051"]+ );+});