Skip to content

Commit d58a8dc

Browse files
Compare the interruption injection against identity so main's rows fire on an aliased temp
The file this repairs is main's: src/utils/__tests__/safeWriteJson.interruption.test.ts, blob c9c5993 at 73931fe, and it was absent from this branch before the merge (git cat-file -e e62f198:src/utils/__tests__/safeWriteJson.interruption.test.ts exits 128). This is a prerequisite for a test main carries, not unit content: no production file is touched here. Main's kill point is whole-path equality - child line 40, `if (path.resolve(String(newPath)) === targetPath)`, with targetPath = path.resolve(process.env.INTERRUPTION_TARGET_PATH). This PR publishes through a realpath-resolved string, node's async fs.realpath expands an NTFS 8.3 alias, and path.resolve preserves the spelling it is handed. On a runner whose temp path is reported as an alias - the normal windows-latest condition, where the profile is RUNNER~1 - the writer's rename destination and the parent's authorized spelling are two strings naming one file, the injection never matches, the child prints WRITE_COMPLETED, and every row in the file fails. That is exactly what platform-unit-test (windows-latest) reported at 8fa7d85: 12 failures, all of them `expected 'WRITE_COMPLETED\n' to contain 'EXIT_AT_REPLACEMENT_RENAME'` at that file's line 187, with the leg failing on its own merit (03:53:47 -> 04:00:01) rather than as a cancellation. Measured on this box (pinned node v22.23.4; box node 25.9.0), in both directions: TEMP/TMP at C:\work\Zoo-Code-fork\.tmp-alias-vps2f\long-directory-name-under-alias -> 12 passed; TEMP/TMP at its 8.3 form C:\work\ZOO-CO~1\TMP-AL~2\LONG-D~1 with main's copy -> 12 failed carrying CI's assertion verbatim; the same aliased TEMP with the predicate below -> 12 passed; long spelling with the predicate -> 12 passed, so nothing here is pinned to the alias. The predicate is the basename plus the containing directory's dev+ino, cited from 1fb5fcc, which is where this fix exists today (Zoo-Code-Org#1912). It is written into main's shape of the file rather than copied over it: the two versions differ outside the predicate by 26 lines of surrounding harness content, so this is a second lane grafting the same mechanism, not one lane's text being adopted. Whichever merge lands first supplies the canonical text - merge order, not merit - and the conflict is expected rather than surprising. One disclosure about the previous commit that its own message did not carry: 7bf2654 added `chmod: vi.fn(actual.chmod)` to the fs/promises mock factory in safeWriteJson.test.ts. That spec's beforeEach pre-creates the target (line 90), so every row in that file that reaches the publish now calls chmod through the delegating spy where it previously reached the real function through `...actual`; behaviour is unchanged because the spy calls through, and no row before that commit asserted on chmod (`git grep -nE "vi\\.mocked\\(fs\\.chmod\\)" 8fa7d85` returns nothing). Gates on this commit's tree, pinned 22.23.4: interruption spec 12 passed under both temp spellings; prettier --check clean; eslint --max-warnings=0 exit 0 on the touched file, run without --prune-suppressions so src/eslint-suppressions.json is untouched; tsc -p src/tsconfig.json exit 0. The misc shard was measured on the identical tree at 7bf2654 (2118 passed / 17 skipped) and this commit touches only this spec file. Refs: Zoo-Code-Org#1375, Zoo-Code-Org#1991, Zoo-Code-Org#2019.
1 parent 7bf2654 commit d58a8dc

1 file changed

Lines changed: 34 additions & 2 deletions

File tree

‎src/utils/__tests__/safeWriteJson.interruption.test.ts‎

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,44 @@ const targetPath = path.resolve(process.env.INTERRUPTION_TARGET_PATH)
3232
const fsPromises = require("fs/promises")
3333
const actualRename = fsPromises.rename
3434
35+
// Identity, not spelling. The writer renames to the publish target it resolved through
36+
// symlinks, and node's async fs.realpath expands an NTFS 8.3 alias, so on a runner whose temp
37+
// path is reported as an alias (the normal windows-latest condition: the profile is RUNNER~1
38+
// there) the parent's authorized spelling and the writer's rename destination are different
39+
// strings for one file. Text equality here never fires, every case prints WRITE_COMPLETED, and
40+
// the injection silently stops being an injection. Decide what the destination IS: same name,
41+
// and the same directory by dev+ino. The basenames under test are unique inside the storage
42+
// directory, so the pair cannot land on another file.
43+
const targetBase = path.basename(targetPath)
44+
function sameTargetAsAuthorized(candidate) {
45+
if (path.basename(String(candidate)) !== targetBase) {
46+
return false
47+
}
48+
const resolved = path.resolve(String(candidate))
49+
if (resolved === targetPath) {
50+
return true
51+
}
52+
let candidateDir = null
53+
let authorizedDir = null
54+
try {
55+
candidateDir = fs.statSync(path.dirname(resolved), { bigint: true })
56+
} catch {
57+
return false
58+
}
59+
try {
60+
authorizedDir = fs.statSync(path.dirname(targetPath), { bigint: true })
61+
} catch {
62+
return false
63+
}
64+
return candidateDir.dev === authorizedDir.dev && candidateDir.ino === authorizedDir.ino
65+
}
66+
3567
// Fault injection: hard-kill before the replacement lands. Any rename
36-
// whose destination is the canonical path is the commit step, whatever
68+
// whose destination is the publish target is the commit step, whatever
3769
// replacement protocol the writer uses; exit before performing it.
3870
let commitAttempts = 0
3971
fsPromises.rename = async function interruptionRename(oldPath, newPath) {
40-
if (path.resolve(String(newPath)) === targetPath) {
72+
if (sameTargetAsAuthorized(newPath)) {
4173
commitAttempts++
4274
if (process.env.INTERRUPTION_MODE === "fallback" && commitAttempts === 1) {
4375
return Promise.reject(Object.assign(new Error("Injected EPERM"), { code: "EPERM" }))

0 commit comments

Comments
 (0)