Skip to content

Commit 0e8af36

Browse files
test(S4b Zoo-Code-Org#1375): sort the acceptance row's four-name list and make its geometry assert itself
Two fixes in one file, both found by running things rather than by reading them. The case-sensitive branch of the acceptance row asserted a lowercased entry list in insertion order while the assertion itself sorts what the directory returns, so on a case-sensitive filesystem the two orders differ and the row failed on the count comparison even though every content assertion above it passed. The list is now in sorted order, which is what the comparison asked for all along. The fact that the content assertions ahead of it passed on ubuntu is the evidence that the rename-target reading in the previous commit was right: the writer's own spelling carries this writer's content, and the row's earlier failure there was the row asking the wrong file. The acceptance row now also asserts its own geometry before it asserts anything about the guard: the key handed to acquireFileLock has to be the spelling the writer asked in with (the near half of the divergence), and the writer's own spelling has to exist by the time acquisition returns (the far half). Both are recorded from inside the acquisition seam, not inferred from the fixture. That self-check earned its place immediately. Installed into the propagation row as well, it came back with an empty capture array on this host: that row's doMocked ../fileLock seam never runs here, so the pair the row says it builds during acquisition is not being built by that seam, and the stat count the row reports comes from the folding filesystem's own restating rather than from the fixture. A diagnostic that says "your double is not running" is not a verdict about the guard, so the capture and its assertions were removed from that row and the stat-count assertion keeps a message that says what a zero means. The propagation row's case-sensitive half therefore stays unverified, and the question of which seam should supply the peer's appearance during acquisition is open - it is a design choice about the lock machinery, not a line I land on my own. Local at this head: safeWriteJson.lockKey.spec.ts 10 passed (the case-folding branch; the case-sensitive branch cannot execute on a case-insensitive host - a hard link onto the other-case name answers EEXIST and readdir still lists one entry, measured). eslint --prune-suppressions --max-warnings=0 exits 0 with src/eslint-suppressions.json back equal to HEAD, prettier --check clean, tsc reports only the known activate/registerCommands.ts(88,102) TS2739 junction artefact. Test-only, no platform gate added.
1 parent 258c5fe commit 0e8af36

1 file changed

Lines changed: 29 additions & 3 deletions

File tree

‎src/utils/__tests__/safeWriteJson.lockKey.spec.ts‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ describe("safeWriteJson lock key under a peer commit", () => {
183183

184184
it("accepts the name the filesystem itself answers for the spelling the key was computed from", async () => {
185185
const dir = await makeDir("lockkey-casefold-")
186+
// The fixture's own geometry, recorded during acquisition rather than assumed: the key the product
187+
// hands to acquireFileLock is the spelling its pre-lock resolution answered with, and whether the
188+
// writer's own spelling exists by the time acquisition returns is the far half of the divergence the
189+
// guard is then asked about. Both rows assert these before asserting anything about the guard, so a
190+
// platform that stops building the pair fails here instead of somewhere harder to read.
191+
const acquisitionFacts: Array<{ key: string; spellingPresentDuringAcquisition: boolean }> = []
186192
const lower = path.join(dir, "settings.json")
187193
const upper = path.join(dir, "SETTINGS.JSON")
188194
const real = await vi.importActual<typeof import("fs/promises")>("fs/promises")
@@ -236,6 +242,13 @@ describe("safeWriteJson lock key under a peer commit", () => {
236242
await fs.link(lower, upper)
237243
await fs.link(ownArtefact, lockPathFor(lower))
238244
}
245+
acquisitionFacts.push({
246+
key: String(file),
247+
spellingPresentDuringAcquisition: await fs.lstat(upper).then(
248+
() => true,
249+
() => false,
250+
),
251+
})
239252
return async () => {}
240253
})
241254

@@ -247,6 +260,17 @@ describe("safeWriteJson lock key under a peer commit", () => {
247260
// names reach one artefact, so this writer holds the lock the other spelling would take and
248261
// the write is not refused. Where the two platforms differ is in how many names exist, which
249262
// is a property of the directory and not of the guard, so only the counts branch.
263+
// Geometry before verdict.
264+
expect(
265+
acquisitionFacts.map((fact: { key: string }) => path.basename(fact.key)),
266+
"the lock key handed to acquisition was not this writer's spelling, so no divergence reached the guard",
267+
).toEqual(["SETTINGS.JSON"])
268+
expect(
269+
acquisitionFacts.map(
270+
(fact: { spellingPresentDuringAcquisition: boolean }) => fact.spellingPresentDuringAcquisition,
271+
),
272+
"the writer's spelling never appeared during acquisition, so the under-lock resolution had nothing to restate",
273+
).toEqual([true])
250274
expect(String(error && error.name)).toBe("undefined")
251275
expect(JSON.parse(await fs.readFile(upper, "utf8"))).toEqual({ mcpServers: { mine: true } })
252276
if (!foldsCase) {
@@ -264,7 +288,7 @@ describe("safeWriteJson lock key under a peer commit", () => {
264288
expect(entries.map((name: string) => name.toLowerCase()).sort()).toEqual(
265289
foldsCase
266290
? ["settings.json", "settings.json.lock"]
267-
: ["settings.json", "settings.json.lock", "settings.json", "settings.json.lock"],
291+
: ["settings.json", "settings.json", "settings.json.lock", "settings.json.lock"],
268292
)
269293
expect(entries.length).toBe(foldsCase ? 2 : 4)
270294
// The guard answered from object identity, so the identity is read back off the filesystem
@@ -550,7 +574,6 @@ describe("safeWriteJson lock key under a peer commit", () => {
550574
await fs.link(lower, upper)
551575
await fs.link(ownArtefact, actual.lockPathFor(lower))
552576
}
553-
return async () => {}
554577
}),
555578
}
556579
})
@@ -562,7 +585,10 @@ describe("safeWriteJson lock key under a peer commit", () => {
562585
(caught: unknown) => caught as Error,
563586
)
564587

565-
expect(statCalls).toBeGreaterThan(0)
588+
expect(
589+
statCalls,
590+
"the guard never put its identity question to the filesystem on this platform",
591+
).toBeGreaterThan(0)
566592
expect(String(error && (error as { code?: string }).code)).toBe("EACCES")
567593
expect(String(error && error.name)).not.toBe("LockKeyDriftError")
568594
// Fail closed: the writer published nothing, and the file it would have replaced still

0 commit comments

Comments
 (0)