test(canonical-urls): the suite cannot leave the tree dirty, and says so when it cannot put it back #2485
No reviewers
Labels
No labels
blocked-on-build
bug
device
device-request
enhancement
from-github
needs-datasheet
needs-info
needs-triage
ready-for-agent
ready-for-human
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
jaylouisw/packetforge!2485
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "test/canonical-restores"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
The defect, measured
test/canonical-urls.test.jsplants a dead badge intoREADME.md, runs the checker, then restores the file. The restore was the last statement of atryblock, so any interruption that skipped the statement skipped the restore: a killed process, a timed-out terminal, a ctrl-C. The tree was left withM README.md, and the next suite run reported six failures that were one dirty file - three tool calls and one wrong diagnosis beforegit checkout -- .turned 6 failures into52 passed, 0 failed.The runner now refuses to start on a dirty tree (#2468), so the next run cannot be lied to. This is the other half: the suite must not be able to leave the tree dirty in the first place, and must say so when the restore fails.
What changed (
test/canonical-urls.test.jsonly)Restoration is now a property of touching the file, not a statement after the probe:
withReadme(mutated, body)is the only way the README is touched. Itsfinallyrestores whatever the probe did - including throwing - and the throw still reaches the caller. Both existing probes (the lost clone URL, the dead badge) now go through it.tmp/canonical-urls-restore/README.md.restore: one file, a JSON header line (v,target,bytes,sha256,pid,at) then the bytes. It lives undertmp/, which.gitignorealready covers, so a marker that outlives a run cannot itself dirty the tree, and its extension is not one the checker scans. This is not hypothetical:scripts/run-tests.jsSIGKILLs a suite that overruns its 300 s budget, and this suite is a slow one (~94 s, 13check()calls).SIGINT,SIGTERM,SIGHUP,uncaughtException,unhandledRejectionand plainexitall salvage through one function before the process goes, then exit. A marker we could not write (read-only checkout) is reported as one line rather than pretending the hard-kill path is covered.[heal] README.md was left modified by an interrupted run (pid ..., ...); restored 10545 bytes from tmp/canonical-urls-restore/README.md.restore. A marker that was itself truncated by the kill that wrote it is discarded, not written back - healing from it would be a second dirtying dressed up as a repair.README.mddiffers from the bytes captured at start, if a mutation is still open, if a marker survives, or ifgit status --porcelain -- README.mdsays anything at all.Proof (assertions, not claims)
A check that throws mid-probe still puts the README back(4): the probe really had the file modified when it threw, the error still reached the caller, the captured bytes were restored, the marker was cleared.A run killed mid-probe is healed by the next run(7): a mutation abandoned with its marker on disk - no finally, no exit hook, the SIGKILL case - is healed, in one line, restores the bytes captured before the kill, consumes the marker, and a second run finds nothing to heal.A marker that cannot be trusted is thrown away(4): a half-written marker and a garbage marker both heal nothing and leave the README alone; the bad marker is removed so it cannot fail every run from here on.The interruption hooks restore...(10): the handlers are registered, and the salvage path a signal runs is exercised in the state a signal would find it in and names the signal.This run leaves the tree exactly as it found it(4): byte-for-byte, no open mutation, no marker, andgitagrees.Verified end to end
A real
SIGKILLdelivered into a live run while the marker was on disk reproduced the original defect exactly -M README.mdplus the marker. The nextnode test/canonical-urls.test.jsprinted the single[heal]line, healed, and finished clean.Gates
node test/canonical-urls.test.js- 88 passed, 0 failed (was 58)node scripts/syntax-check.js-Syntax-checked 547 files: all OKgit status --porcelain- empty after the runnode scripts/run-tests.js --filter=canonical-urls-88 assertions passed, 0 failed,OK - every suite passed.838977384b4ee570a83b