@@ -266,6 +266,57 @@ assert('the Chinese README carries the shipped version',
266266assert ( 'neither README still announces the old version' ,
267267 ! / 1 \. 0 \. 0 / . test ( readme ) && ! / 1 \. 0 \. 0 / . test ( readmeZh ) ) ;
268268
269+ /* ---------- 8. the harness must notice what the LAST run left behind ---------- */
270+
271+ // Section 1 is about a run that cannot find its interpreter. This one is about a run that cannot
272+ // see what the previous run left on disk, which is the failure mode the snapshot in run.mjs was
273+ // written for and then did not have.
274+ //
275+ // The gap was three bugs that each disabled the check on their own: the snapshot was written only
276+ // when the file already existed (so a fresh checkout never had a baseline), it recorded the run's
277+ // START state rather than the state it ended with, and — the one that made the whole thing
278+ // decorative — nothing ever read it. The visible symptom was exactly the one the reviewer reported:
279+ // after a `kill -9` mid-mutation, `index.html` stayed mutated and the next run reported unrelated
280+ // red with no mention of the residue, because the only guard that knew about residue was comparing
281+ // the start of a run with the end of the SAME run.
282+ //
283+ // Reproduced on 2026-10-14 before changing anything: a run left no snapshot at all, and with a
284+ // snapshot planted by hand plus one real mutation in index.html, `node tests/run.mjs
285+ // verify-ledger-jump` printed `0/1 guards passed / failed: verify-ledger-jump.mjs` and one line
286+ // about nothing being left over.
287+ assert ( 'the harness reads the snapshot the previous run wrote' ,
288+ / r e a d F i l e S y n c \( S N A P S H O T , / . test ( runMjs ) ) ;
289+ assert ( 'the startup comparison is per file, against the digest that was recorded' ,
290+ / p r e v i o u s \[ r e l \] ! = = u n d e f i n e d & & p r e v i o u s \[ r e l \] ! = = d i g e s t \( r e l \) / . test ( runMjs ) ) ;
291+ // A checkout nobody has run the suite on has no baseline. Treating that as "everything differs"
292+ // would warn on every first run, and treating it as a failure would fail every fresh clone.
293+ assert ( 'a missing baseline is neither a difference nor a failure' ,
294+ / c o n s t r e a d S n a p s h o t = \( \) = > \{ [ \s \S ] * ?r e t u r n n u l l ; / . test ( runMjs )
295+ && / c o n s t l e f t o v e r = p r e v i o u s \s * \? / . test ( runMjs ) ) ;
296+ // Reported, not failed. The suite runs on machines with uncommitted work, and "these files are not
297+ // what the last run left" is true of a contributor mid-edit. So this must never reach `failed`.
298+ assert ( 'files that differ from the last run are reported and not failed' ,
299+ / s h i p p e d f i l e s d i f f e r f r o m t h e l a s t r u n / . test ( runMjs )
300+ && ! / f a i l e d \. p u s h \( [ ^ \n ] * l e f t o v e r / . test ( runMjs ) ) ;
301+ // Written on every clean run. Gating the write on the file already existing is what left a fresh
302+ // checkout with nothing to compare against — the machine least likely to have a stale snapshot is
303+ // the one that could never get one.
304+ assert ( 'the snapshot is written on every clean run, not only when it already exists' ,
305+ ! / e x i s t s S y n c \( S N A P S H O T \) \s * & & / . test ( runMjs ) && ! / i f \s * \( e x i s t s S y n c \( S N A P S H O T \) / . test ( runMjs ) ) ;
306+ // And it records the state the run ENDED with, only when that state was clean. Recording a drifted
307+ // end would make the next run's comparison agree with the mutation, which is the one thing this
308+ // file exists to prevent.
309+ assert ( 'the snapshot records the state the run ended with, and only a clean end' ,
310+ / i f \( d r i f t \. l e n g t h = = = 0 \) \{ [ \s \S ] * ?w r i t e F i l e S y n c \( S N A P S H O T / . test ( runMjs )
311+ && ! / J S O N \. s t r i n g i f y \( s n a p s h o t B e f o r e \) / . test ( runMjs ) ) ;
312+ // Two findings, two names. Collapsing them into one line is the regression this section exists to
313+ // stop: "shipped files restored" means this run dirtied the source, "differ from the last run"
314+ // means it was already dirty, and a reader who cannot tell them apart cannot act on either.
315+ assert ( 'this run\'s own residue and last run\'s residue are named differently' ,
316+ / s h i p p e d f i l e s r e s t o r e d / . test ( runMjs )
317+ && / s h i p p e d f i l e s d i f f e r f r o m t h e l a s t r u n / . test ( runMjs )
318+ && / W A R N / . test ( runMjs ) ) ;
319+
269320console . log ( '[review16] ' + pass + ' passed, ' + failures . length + ' failed' ) ;
270321if ( failures . length ) {
271322 console . log ( 'FAILURES:\n - ' + failures . join ( '\n - ' ) ) ;
0 commit comments