@@ -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