Skip to content

Commit d5ade04

Browse files
u917 make the inherited delete-semantics expectation use the canonical lock key the delete takes
1 parent 3721aa3 commit d5ade04

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,16 @@ function historyFilePath(storagePath: string, taskId: string): string {
5454
return path.join(storagePath, "tasks", taskId, GlobalFileNames.historyItem)
5555
}
5656

57+
// The lock key is canonicalized through the parent directory, so the expected key is
58+
// the canonical directory plus the basename rather than the path built from
59+
// os.tmpdir(), which can be an 8.3 short path on the Windows runner. canonicalDirKey,
60+
// in src/services/file-safety/safeWriteText.ts, canonicalizes the nearest existing
61+
// ancestor with fs/promises realpath, and that call expands the short spelling, so the
62+
// expectation is canonicalized the way the delete takes the lock.
63+
async function canonicalKey(filePath: string): Promise<string> {
64+
return path.join(await actualFs.realpath(path.dirname(filePath)), path.basename(filePath))
65+
}
66+
5767
function storeInternals(store: TaskHistoryStore): {
5868
cache: Map<string, HistoryItem>
5969
taskFileMtimes: Map<string, number>
@@ -152,12 +162,17 @@ describe("TaskHistoryStore best-effort deletion semantics", () => {
152162
const store = createStore()
153163
await store.initialize()
154164
await store.upsert(makeHistoryItem({ id: "locked-delete" }))
165+
// The lock spy is created once for the whole file, so clear it to make the
166+
// assertion below about this delete and not about every case before it.
167+
vi.mocked(withFileLock).mockClear()
155168
onWrite.mockClear()
156169

157170
await expect(store.delete("locked-delete")).resolves.toBeUndefined()
158171

172+
// The delete takes the lock on the canonical key, so the expectation is built the
173+
// same way rather than from the spelling os.tmpdir handed to mkdtemp.
159174
expect(vi.mocked(withFileLock)).toHaveBeenCalledWith(
160-
historyFilePath(storagePath, "locked-delete"),
175+
await canonicalKey(historyFilePath(storagePath, "locked-delete")),
161176
expect.any(Function),
162177
)
163178
await expect(fs.access(historyFilePath(storagePath, "locked-delete"))).rejects.toMatchObject({

0 commit comments

Comments
 (0)