Skip to content

Commit 4d9738f

Browse files
authored
Merge pull request #1923 from lidge-jun/codex/wave5-writer-ordering
test(codex): bind the writer effects to one temp path, in order
2 parents b5a6654 + 02e14a9 commit 4d9738f

2 files changed

Lines changed: 60 additions & 8 deletions

File tree

‎devlog/_plan/260817_wave5_execution/020_1899_harden_ordering.md‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,31 @@ their Windows/POSIX split is already correct on `dev`.
4141

4242
## Closure
4343

44-
#1899 cannot merge as-is (DIRTY). Land the one-file residue as a direct commit on
45-
`dev`, then close #1899 with a comment naming the commit, what was taken, and
46-
what #1881 already covered.
44+
#1899 cannot merge as-is (CONFLICTING/DIRTY, head `8ab0aa8d0` — re-verified after a
45+
transient `UNKNOWN` reading). Land the one-file residue as a direct commit on `dev`,
46+
then close #1899 with a comment naming the commit, what was taken, and what #1881
47+
already covered.
48+
49+
## Outcome (executed)
50+
51+
DONE. Two commits on `tests/codex-catalog-writer.test.ts`:
52+
53+
| Commit | Change |
54+
|--------|--------|
55+
| `fb5ceee35` | bind `temp:`/`harden:`/`publish:`\|`rename:` to one temp path; assert `hardenIndex < publishIndex` |
56+
| `50a057e20` | state the scope limit the review asked for |
57+
58+
**Red proof.** Forcing the harden index above the publish index fails 4 of 9 tests;
59+
restoring returns all 9 to green. An independent reviewer reproduced this with two
60+
ablations on a scratch copy and found something the plan had not predicted: for the
61+
two backup mutators the index comparison is the **only** detector. `publishNoReplace`
62+
is `linkSync`, so a temp hardened after publication still shares the destination's
63+
inode — `chmod` succeeds, `statSync` reads `0o600`, the leftover-`.tmp` check passes,
64+
and every other assertion agrees nothing is wrong. Only the order disagrees.
65+
66+
**Scope limit, now written into the test.** `io` is an injected seam, so what is
67+
asserted is production's call order (`src/config.ts:236`,
68+
`src/codex/internal/catalog-writer.ts:147` both run write → harden → publish).
69+
Supplying `io` bypasses `hardenSecretPath`, so this proves hardening is *requested*
70+
on the temp before publication, not that it restricts. The Windows NTFS ACL is
71+
covered in `tests/windows-secret-acl.test.ts`.

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

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,40 @@ for (const mutator of mutators) {
237237
);
238238

239239
expect(readFileSync(path, "utf8")).toBe("new bytes\n");
240-
// Windows exposes synthesized POSIX mode bits, so stat cannot prove that chmod took effect.
241-
// The recorded harden call still proves every mutator requested the permission transition.
242-
expect(effects.some(effect => effect.startsWith("harden:"))).toBe(true);
243240
if (process.platform !== "win32") expect(statSync(path).mode & 0o777).toBe(0o600);
244241
expect(readdirSync(targetDir).filter(name => name.endsWith(".tmp"))).toEqual([]);
245-
expect(effects.some(effect => effect.startsWith("temp:"))).toBe(true);
246-
expect(effects.some(effect => effect.startsWith(isBackup ? "publish:" : "rename:"))).toBe(true);
242+
243+
// Bind the three effects to ONE temp path, and to each other in order.
244+
//
245+
// Unbound `some()` checks — "a temp was written, something was hardened, something
246+
// was published" — hold even when the three touch different files, which is the
247+
// failure they exist to catch.
248+
//
249+
// Order matters as much as membership. Hardening lands on the temp file and
250+
// publishing moves that already-restricted file into place; if publish ran first,
251+
// the destination would sit world-readable for the width of the gap. A set-membership
252+
// assertion passes for that writer too, so the index comparison is what makes this a
253+
// claim about the race rather than about the call list. For the backup mutators it is
254+
// the ONLY detector: `publishNoReplace` is `linkSync`, so a temp hardened after
255+
// publication still shares the destination's inode — the mode check reads 0o600 and
256+
// the leftover-`.tmp` check passes, while the write was briefly exposed.
257+
//
258+
// Scope, stated plainly: `io` is an injected seam, so what is asserted here is
259+
// production's call ORDER (src/config.ts and src/codex/internal/catalog-writer.ts
260+
// both run write → harden → publish). Supplying `io` bypasses the real
261+
// implementations, so this proves hardening is REQUESTED on the temp before
262+
// publication — not that it restricts. The Windows NTFS ACL that does the actual
263+
// restricting is exercised in tests/windows-secret-acl.test.ts, and the POSIX mode
264+
// below is the only half `statSync` can observe (Windows reports 0o666 whatever
265+
// `chmodSync` did).
266+
const tempEffect = effects.find(effect => effect.startsWith("temp:"));
267+
expect(tempEffect).toBeDefined();
268+
const tempPath = tempEffect!.slice("temp:".length);
269+
const hardenIndex = effects.indexOf(`harden:${tempPath}`);
270+
const publishIndex = effects.indexOf(`${isBackup ? "publish" : "rename"}:${tempPath}->${path}`);
271+
expect(hardenIndex).toBeGreaterThanOrEqual(0);
272+
expect(publishIndex).toBeGreaterThanOrEqual(0);
273+
expect(hardenIndex).toBeLessThan(publishIndex);
247274
if (isBackup) expect(result).toBe("written");
248275
});
249276
}

0 commit comments

Comments
 (0)