Skip to content

Commit f8de63d

Browse files
committed
钉住跨启动快照的三处退化
一个比对可以被三种方式悄悄去掉,而这三种读起来都完全正常:把读的那一行删掉(快照 从此只是写)、把写的条件改回「已存在时才写」(全新检出永远没有基线)、把记的内容 换回起点(等于什么都没记)。 verify-review16.mjs 加 7 条断言,mutate-review16.py 加 5 条变异,全捕。 其中两条值得单说,因为它们是「只有比较两个名字才发现」的那一类: - 把两条消息**改成同名**。`shipped files restored` 与 `shipped files differ from the last run` 合成一个名字,读者就无法分辨是哪一次运行弄脏的源码 —— 而这两种情况的 处置完全相反:一个是本次运行的守卫失败,另一个是启动时就带着上一轮的残留。 - 把快照改成**记起点**。起点与终点只在没有变脏时相等,所以这一条在每一次干净的运行 上都与正确版本没有区别。 另外三条分别是:不读快照、把逐文件比对换成常量、把「只在干净时写」改成总是写。最后 一条是唯一会**把问题藏两次**的 —— 记一个变脏的终点,下一次比对就与变异意见一致了。 断言里有一条值得单说:「缺失或读不出来的基线既不算差异也不算失败」。没有基线的是全新 检出,拿它当「全都不一样」会让每一次首跑都报警,拿它当失败会让每一个新克隆都红。 verify-review16.mjs 34 -> 41 assertions. mutate-review16.py 32 -> 37 mutations, all caught. node tests/run.mjs 57/57.
1 parent 9f2797f commit f8de63d

2 files changed

Lines changed: 89 additions & 0 deletions

File tree

‎plugins/avatasia/mmc-trajectory/tests/mutate-review16.py‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,44 @@
232232
'"version": "1.1.0",',
233233
'"version": "1.2.0",',
234234
"the English README carries the shipped version"),
235+
236+
# ---- the snapshot the last run left, and the run that never looked at it ----
237+
# All five break the cross-start check in tests/run.mjs, which existed on paper and did nothing:
238+
# the snapshot was written only when it already existed, recorded the run's start rather than
239+
# its end, and was never read. A hard kill mid-mutation therefore left the source mutated and
240+
# the next run said nothing about it -- it reported whatever guard happened to read the mutated
241+
# file, which reads as that guard being broken.
242+
243+
("the harness never reads the snapshot it writes",
244+
"readFileSync(SNAPSHOT, 'utf8')",
245+
"'{}'",
246+
"the harness reads the snapshot the previous run wrote"),
247+
248+
("the startup check stops comparing per file",
249+
"previous[rel] !== undefined && previous[rel] !== digest(rel)",
250+
"false",
251+
"the startup comparison is per file, against the digest that was recorded"),
252+
253+
# The old form: record the state the run STARTED with. Identical to the end state whenever
254+
# nothing drifted, and a record of the mutation whenever something did.
255+
("the snapshot records the state the run started with",
256+
"writeFileSync(SNAPSHOT, JSON.stringify(Object.fromEntries(SHIPPED.map((rel) => [rel, digest(rel)]))));",
257+
"writeFileSync(SNAPSHOT, JSON.stringify(snapshotBefore));",
258+
"the snapshot records the state the run ended with, and only a clean end"),
259+
260+
# Recording a drifted end is the one that hides the thing twice: the next run compares against
261+
# the mutation and agrees with it.
262+
("the snapshot is written even when this run dirtied the source",
263+
"if (drift.length === 0) {",
264+
"if (drift.length >= 0) {",
265+
"the snapshot records the state the run ended with, and only a clean end"),
266+
267+
# The two findings collapse into one line. Reads fine, costs the reader the only thing that
268+
# distinguishes "this run broke it" from "it was already broken".
269+
("last run's residue is named exactly like this run's",
270+
"'shipped files differ from the last run'",
271+
"'shipped files restored'",
272+
"this run's own residue and last run's residue are named differently"),
235273
]
236274

237275

‎plugins/avatasia/mmc-trajectory/tests/verify-review16.mjs‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,57 @@ assert('the Chinese README carries the shipped version',
266266
assert('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+
/readFileSync\(SNAPSHOT,/.test(runMjs));
289+
assert('the startup comparison is per file, against the digest that was recorded',
290+
/previous\[rel\] !== undefined && previous\[rel\] !== digest\(rel\)/.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+
/const readSnapshot = \(\) => \{[\s\S]*?return null;/.test(runMjs)
295+
&& /const leftover = previous\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+
/shipped files differ from the last run/.test(runMjs)
300+
&& !/failed\.push\([^\n]*leftover/.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+
!/existsSync\(SNAPSHOT\)\s*&&/.test(runMjs) && !/if\s*\(existsSync\(SNAPSHOT\)/.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+
/if \(drift\.length === 0\) \{[\s\S]*?writeFileSync\(SNAPSHOT/.test(runMjs)
311+
&& !/JSON\.stringify\(snapshotBefore\)/.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+
/shipped files restored/.test(runMjs)
317+
&& /shipped files differ from the last run/.test(runMjs)
318+
&& /WARN/.test(runMjs));
319+
269320
console.log('[review16] ' + pass + ' passed, ' + failures.length + ' failed');
270321
if (failures.length) {
271322
console.log('FAILURES:\n - ' + failures.join('\n - '));

0 commit comments

Comments
 (0)