Skip to content

Commit 6093d2a

Browse files
author
abort-merge
committed
test(task-history): assert the values a duplicate-id restore puts back
The duplicate-id restore test asserted membership: that the cache holds the id, that an mtime record exists beside it, and that the write-through payload mentions the id. A restoration that rebuilt the entry with different metadata, or wrote back a zero mtime, satisfied every one of those. Capture the entry and the mtime this store serves before the batch runs - as a copy, because the restoration hands back the very object a plain capture would have aliased - and compare the restored entry, the restored mtime and the whole published payload against them. The three-attempt test beside it gets the same treatment. Control: with the restore site changed to write a mutated prompt and a zeroed mtime, both tests fail - 2 failed | 38 passed, each on the deep equality of the restored entry - and both pass at 60f9c8c, so this pins what the restore must preserve without changing what it does. Spec-only: no production line moved in this commit.
1 parent 60f9c8c commit 6093d2a

1 file changed

Lines changed: 19 additions & 7 deletions

File tree

‎src/core/task-persistence/__tests__/TaskHistoryStore.deleteSemantics.spec.ts‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,13 @@ describe("TaskHistoryStore best-effort deletion semantics", () => {
14921492
// entry rather than an entry alone.
14931493
await store.reconcile()
14941494
onWrite.mockClear()
1495+
// Captured before the batch runs, and as a copy: the restoration hands back the very object this
1496+
// store was serving, so a reference captured here would travel with any change made to it and
1497+
// could not tell a preserved entry from a rebuilt one, or a restored mtime from a zeroed one.
1498+
const servedEntry = structuredClone(store.get("dup-restored"))
1499+
const servedMtime = storeInternals(store).taskFileMtimes.get("dup-restored")
1500+
expect(servedEntry).toBeDefined()
1501+
expect(servedMtime).toBeTypeOf("number")
14951502
const taskPath = historyFilePath(storagePath, "dup-restored")
14961503
// A removed item costs two locked calls: the removal itself, and main's delete helper running
14971504
// once more after the lock was released. The counter puts the republish after that cleanup and
@@ -1526,13 +1533,14 @@ describe("TaskHistoryStore best-effort deletion semantics", () => {
15261533
await expect(fs.access(taskPath)).resolves.toBeUndefined()
15271534
const after = storeInternals(store)
15281535
expect(after.cache.has("dup-restored")).toBe(true)
1529-
expect(store.get("dup-restored")).toBeDefined()
1530-
expect(after.taskFileMtimes.has("dup-restored")).toBe(true)
1531-
// One write-through for a batch that removed one file, and the id the error names is inside the
1532-
// payload that write sent.
1536+
expect(store.get("dup-restored")).toEqual(servedEntry)
1537+
expect(after.taskFileMtimes.get("dup-restored")).toBe(servedMtime)
1538+
// One write-through for a batch that removed one file, and the complete payload it published:
1539+
// the id the error names has to appear in it as the entry this store served before the batch,
1540+
// not as a placeholder record.
15331541
expect(onWrite).toHaveBeenCalledTimes(1)
15341542
const payload = onWrite.mock.calls[0]?.[0] as HistoryItem[]
1535-
expect(payload.some((entry: HistoryItem) => entry.id === "dup-restored")).toBe(true)
1543+
expect(payload).toEqual([servedEntry])
15361544
})
15371545

15381546
it("keeps the served entry through a second successful attempt of the same id", async () => {
@@ -1547,8 +1555,12 @@ describe("TaskHistoryStore best-effort deletion semantics", () => {
15471555
await store.upsert(item)
15481556
await store.reconcile()
15491557
onWrite.mockClear()
1550-
const servedEntry = store.get("dup-twice")
1558+
// Captured as a copy, and before any attempt ran, for the same reason as in the test above:
1559+
// a reference would move with the object the restoration hands back.
1560+
const servedEntry = structuredClone(store.get("dup-twice"))
15511561
const servedMtime = storeInternals(store).taskFileMtimes.get("dup-twice")
1562+
expect(servedEntry).toBeDefined()
1563+
expect(servedMtime).toBeTypeOf("number")
15521564
const taskPath = historyFilePath(storagePath, "dup-twice")
15531565
// Two locked calls per successful attempt: the removal, then main's delete helper running once
15541566
// more after that lock was released. The republishes land in the windows between attempts, and
@@ -1593,7 +1605,7 @@ describe("TaskHistoryStore best-effort deletion semantics", () => {
15931605
// One write-through, and the id the error names is in the payload it published.
15941606
expect(onWrite).toHaveBeenCalledTimes(1)
15951607
const payload = onWrite.mock.calls[0]?.[0] as HistoryItem[]
1596-
expect(payload.some((entry: HistoryItem) => entry.id === "dup-twice")).toBe(true)
1608+
expect(payload).toEqual([servedEntry])
15971609
})
15981610
})
15991611
})

0 commit comments

Comments
 (0)