Skip to content

Commit 33ca46a

Browse files
test(utils): swap the escaped publish by rename in the identity-undo row
The row held the bytes equal and changed the file by rmSync plus writeFileSync of the same 13 bytes. On ext4 an unlink plus a create reuses dev, ino and size, so the guard at safeWriteJson.ts:202 read an unchanged identity and unlinked, which is the expected false to be true at safeWriteJson.test.ts:1352:44 that CI job 129946625964 reported while the Windows arm was green. A rename moves the inode on ext4 and on NTFS alike and is how the guarded writer itself replaces a file, so the swap now states the identity change the row asserts on every runner. The assertions are unchanged.
1 parent 44a862d commit 33ca46a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,8 +1343,15 @@ describe("safeWriteJson", () => {
13431343
fsSyncActual.writeFileSync(escaped, ours)
13441344
const actual = await vi.importActual<typeof import("fs/promises")>("fs/promises")
13451345
vi.mocked(fs.readFile).mockImplementationOnce(() => {
1346-
fsSyncActual.rmSync(escaped)
1347-
fsSyncActual.writeFileSync(escaped, ours)
1346+
// The swap has to change the file identity on whichever runner executes it. On ext4 an
1347+
// unlink plus a create of the same bytes reuses dev, ino and size (measured in WSL2: the
1348+
// same inode on both sides of such a swap), so a remove and recreate here let the guard
1349+
// at safeWriteJson.ts:202 read an unchanged identity and unlink the publish. A rename
1350+
// moves the inode on ext4 and on NTFS alike, and it is how the guarded writer itself
1351+
// replaces a file, so the row states the condition it asserts.
1352+
const peer = escaped + ".peer"
1353+
fsSyncActual.writeFileSync(peer, ours)
1354+
fsSyncActual.renameSync(peer, escaped)
13481355
return actual.readFile(escaped)
13491356
})
13501357
await undoEscapedPublish(escaped, ours)

0 commit comments

Comments
 (0)