Skip to content

Commit c095314

Browse files
committed
fix(tests): stop asserting POSIX modes Windows cannot produce
Six tests in the Codex write substrate assert `statSync(path).mode & 0o777` equals 0600. On Windows that can never hold: `chmodSync` moves the read-only flag and nothing else, so `statSync` keeps reporting 0o666 however the file was written. Two of them fail on their own setup line, before reaching the behavior they exist to check. The restriction they are guarding is real, but on Windows it is an ACL rather than a mode. All three call sites here reach it: the catalog writer hardens through `hardenSecretPath`, the shared claim through `hardenSecretPathAsync`, and the DSH settings write through `atomicWriteFile`, which the journal header already describes as "0600 plus Windows ACL hardening". So the assertion is scoped to the platform whose semantics it is written in, and the ACL half stays where it can be observed, in tests/windows-secret-acl.test.ts. Scoping alone would have weakened the catalog-writer cases, which is where the mode was the only evidence that the writer restricted anything. Those now assert the `harden:` effect instead — the half of the contract that holds on every platform, and a stricter check than the mode was: deleting `io.harden` from `publishCatalogBackup` and `atomicWriteFile` turns all four red, while the old mode assertion could not see that regression on Windows at all. `native-main-claim` is skipped rather than scoped because its own comment already states the split — "On POSIX that is the mode; the Windows branch is proven separately" — and every line of it, setup included, is written in mode terms. One neighbouring failure is deliberately left alone. `codex-transition-state`'s "a coordinator found group-readable is narrowed back to owner-only" fails the same way, but `src/codex/transition-state.ts` does not import `windows-secret-acl` at all — nor do `catalog-write-serialization.ts` or `history-lock.ts`, which carry the same `/* Windows applies ACLs in WP11. */` comment on a bare `chmodSync`. If that work is still outstanding, those coordinator databases are genuinely not narrowed on Windows and the red test is honest signal, not a platform artifact. Silencing it would have hidden that. Measured on Windows 11 against dev: - tests/codex-catalog-writer.test.ts: 5 pass/4 fail -> 9 pass/0 fail - the ten files carrying mode assertions: 171 pass/5 fail -> 172 pass/3 fail Refs #1059
1 parent 02da6cc commit c095314

3 files changed

Lines changed: 30 additions & 3 deletions

File tree

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,21 @@ for (const mutator of mutators) {
237237
);
238238

239239
expect(readFileSync(path, "utf8")).toBe("new bytes\n");
240-
expect(statSync(path).mode & 0o777).toBe(0o600);
240+
// Restriction is asserted in two halves, because it is enforced in two ways.
241+
//
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.
252+
if (process.platform !== "win32") {
253+
expect(statSync(path).mode & 0o777).toBe(0o600);
254+
}
241255
expect(readdirSync(targetDir).filter(name => name.endsWith(".tmp"))).toEqual([]);
242256
expect(effects.some(effect => effect.startsWith("temp:"))).toBe(true);
243257
expect(effects.some(effect => effect.startsWith(isBackup ? "publish:" : "rename:"))).toBe(true);

‎tests/dsh-writer-lock.test.ts‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,15 @@ describe("DSH coordinated mutations", () => {
167167
const seams = immediateLock(() => { acquisitions += 1; });
168168
expect((await applyIntegrationCoordinated(writeInput(), { lockSeams: seams })).ok).toBe(true);
169169
const configPath = INTEGRATION_CLIENTS.dsh.configPath({}, home);
170-
expect(statSync(configPath).mode & 0o777).toBe(0o600);
170+
// "Owner-only" is a mode on POSIX and an ACL on Windows: the write goes
171+
// through `atomicWriteFile`, which applies 0600 plus Windows ACL hardening.
172+
// Only the POSIX half is observable through `statSync`, which reports 0o666
173+
// on Windows whatever chmod did, so assert the file exists there instead and
174+
// leave the ACL to tests/windows-secret-acl.test.ts.
175+
expect(existsSync(configPath)).toBe(true);
176+
if (process.platform !== "win32") {
177+
expect(statSync(configPath).mode & 0o777).toBe(0o600);
178+
}
171179
const second = await applyIntegrationCoordinated(writeInput(), { lockSeams: seams });
172180
expect(second).toMatchObject({ ok: true, changed: false, state: "current" });
173181
expect(acquisitions).toBe(2);

‎tests/native-main-claim.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,13 @@ describe("the default hardener is actually reached from a claim", () => {
169169
* left behind. On POSIX that is the mode; the Windows branch is proven
170170
* separately in tests/windows-secret-acl.test.ts, where the ACL runner can be
171171
* observed.
172+
*
173+
* Hence the skip: the paragraph above already scopes this to POSIX, but the
174+
* test ran everywhere and failed on Windows, where `chmodSync` moves only the
175+
* read-only flag and `statSync` reports 0o666 regardless — so neither the
176+
* 0o644 setup nor the 0o600 conclusion can hold there.
172177
*/
173-
test("a shared claim narrows a permissive claim database to 0600", async () => {
178+
test.skipIf(process.platform === "win32")("a shared claim narrows a permissive claim database to 0600", async () => {
174179
const context = fixture();
175180
const path = nativeMainClaimPath(context);
176181
mkdirSync(join(context.codexHome), { recursive: true });

0 commit comments

Comments
 (0)