Skip to content

Commit 8ab0aa8

Browse files
committed
fix(tests): tie the write, harden and publish effects to one temp path
Review was right that `startsWith("harden:")` only claims something was hardened, not that it was this file: three unrelated effects would satisfy it. The suggested `toContain(\`harden:${path}\`)` cannot work, though — hardening never lands on the destination. Both writers harden the temp and then publish it (`io.write(tmp) -> io.harden(tmp) -> io.rename(tmp, target)`), because the point of the sequence is to put an already-restricted file in place. Asserting the destination turns all four cases red. So the temp path is read back out of the recorded `temp:` effect and used to anchor the other two, which is what makes the assertion a claim about this file's bytes reaching this destination hardened.
1 parent b72ea4d commit 8ab0aa8

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

‎tests/codex-catalog-writer.test.ts‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,28 @@ for (const mutator of mutators) {
239239
expect(readFileSync(path, "utf8")).toBe("new bytes\n");
240240
// Restriction is asserted in two halves, because it is enforced in two ways.
241241
//
242-
// Every mutator must ask its I/O to harden what it publishes; that half of the
243-
// contract holds on every platform, so assert it unconditionally.
244-
expect(effects.some(effect => effect.startsWith("harden:"))).toBe(true);
245-
// The resulting mode only carries the claim where POSIX modes do. Windows has
246-
// no mode bits to set: `chmodSync` there moves the read-only flag and nothing
247-
// else, so `statSync` keeps reporting 0o666 however the file was written, and
248-
// this assertion could never pass. Real restriction on Windows comes from the
249-
// per-user NTFS ACL `defaultBackupWriteIO` applies through `hardenSecretPath`
250-
// — machinery these doubles deliberately leave out, so there is nothing here
251-
// for a mode check to observe either way.
242+
// The platform-independent half: the mutator must harden the exact bytes it
243+
// is about to install. Tying all three effects to one temp path is what makes
244+
// that a claim about this file — "some temp was written, some path was
245+
// hardened, something was published" would hold even if they were different
246+
// files. Hardening lands on the temp, never the destination, because the
247+
// publish step is what puts an already-restricted file in place.
248+
const tempEffect = effects.find(effect => effect.startsWith("temp:"));
249+
expect(tempEffect).toBeDefined();
250+
const tempPath = tempEffect!.slice("temp:".length);
251+
expect(effects).toContain(`harden:${tempPath}`);
252+
expect(effects).toContain(`${isBackup ? "publish" : "rename"}:${tempPath}->${path}`);
253+
// The other half is the resulting mode, which only carries the claim where
254+
// POSIX modes do. Windows has no mode bits to set: `chmodSync` there moves the
255+
// read-only flag and nothing else, so `statSync` keeps reporting 0o666 however
256+
// the file was written, and this assertion could never pass. Real restriction
257+
// on Windows comes from the per-user NTFS ACL `defaultBackupWriteIO` applies
258+
// through `hardenSecretPath` — machinery these doubles deliberately leave out,
259+
// so there is nothing here for a mode check to observe either way.
252260
if (process.platform !== "win32") {
253261
expect(statSync(path).mode & 0o777).toBe(0o600);
254262
}
255263
expect(readdirSync(targetDir).filter(name => name.endsWith(".tmp"))).toEqual([]);
256-
expect(effects.some(effect => effect.startsWith("temp:"))).toBe(true);
257-
expect(effects.some(effect => effect.startsWith(isBackup ? "publish:" : "rename:"))).toBe(true);
258264
if (isBackup) expect(result).toBe("written");
259265
});
260266
}

0 commit comments

Comments
 (0)