Skip to content

Commit 7f600ee

Browse files
test(utils)(#1918 u159): inject the interruption fault at the resolved commit destination
The windows arm of platform-unit-test still fails at ca208a2, and its log names twelve rows in utils/__tests__/safeWriteJson.interruption.test.ts: `expected 'WRITE_COMPLETED\n' to contain 'EXIT_AT_REPLACEMENT_RENAME'` at line 187. The child's seam decides which rename is the commit step by comparing the rename's destination with `path.resolve(INTERRUPTION_TARGET_PATH)`, while the writer now commits to the path it resolved. On the hosted runner the temporary root arrives in its 8.3 short form, so the two spellings name the same directory differently, the seam never fires, and the child completes the write instead of dying at the rename. The seam resolves the destination the way the writer resolves its own destination - canonicalize the parent directory with realpathSync.native and re-join the basename - and compares that with the same resolution of the target, falling back to the handed spelling where the path is not there yet. Inside CHILD_SCRIPT that is 13 comment lines and 10 executable lines added and 1 executable line replaced; the outer TypeScript statement is unchanged and nothing outside __tests__ moved.
1 parent ca208a2 commit 7f600ee

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,31 @@ const actualRename = fsPromises.rename
3535
// Fault injection: hard-kill before the replacement lands. Any rename
3636
// whose destination is the canonical path is the commit step, whatever
3737
// replacement protocol the writer uses; exit before performing it.
38+
// "the canonical path" is the one the OS reports for the file, not the
39+
// spelling the test happened to be handed: on a hosted windows runner the
40+
// temporary root arrives in its 8.3 short form, so the handed spelling and
41+
// the resolved one name the same directory differently, and a seam that
42+
// compares the two lexically misses the commit rename and never fires.
43+
// Both sides are therefore resolved with the same call the writer's
44+
// canonicalization is answered by, falling back to the handed spelling
45+
// where the path is not there yet and has no resolution to report.
46+
// The resolution mirrors what the writer does to its own destination: the parent
47+
// directory is canonicalized and the basename is re-joined, so a spelling
48+
// difference in the directory is normalized and a difference in the name is
49+
// not. A directory that is not there yet has no resolution to report and
50+
// keeps the spelling it was handed.
51+
const resolveSeamPath = function (candidate) {
52+
const asPath = path.resolve(String(candidate))
53+
try {
54+
return path.join(fs.realpathSync.native(path.dirname(asPath)), path.basename(asPath))
55+
} catch {
56+
return asPath
57+
}
58+
}
59+
let canonicalTarget = resolveSeamPath(targetPath)
3860
let commitAttempts = 0
3961
fsPromises.rename = async function interruptionRename(oldPath, newPath) {
40-
if (path.resolve(String(newPath)) === targetPath) {
62+
if (resolveSeamPath(String(newPath)) === canonicalTarget) {
4163
commitAttempts++
4264
if (process.env.INTERRUPTION_MODE === "fallback" && commitAttempts === 1) {
4365
return Promise.reject(Object.assign(new Error("Injected EPERM"), { code: "EPERM" }))

0 commit comments

Comments
 (0)