Repository navigation
Commit 28129e1
committed
test(file-safety,fileLock): answer five review threads with pinned behaviour and kill the hop-budget mutants
Five CodeRabbit threads on PR 2383 stay open because the behaviour they ask about is
either unpinned or pinned by an upper bound. Each one is answered here with a row that
fails without the fix plus negative-control numbers against the behaviour as it stands.
The merge of the U4 head ahead of this commit brings the lstat cast fix through the
ancestor, which is the earliest-carrier consequence drawn from line 14 of comment
6767513159 and the keep-1914-versions recommendation at line 21 of comment 6739877102;
the record does not state that consequence itself.
Thread 4525471078 - fileLock.spec.ts cycle test asserted only
toBeLessThanOrEqual(64), so a walk that spent a different number of hops and stopped on
a different cycle member still passed. It now asserts the exact lock key and the exact
hop count: eight frames of eight hops spend the 64-hop budget, 64 mod 3 leaves the
cursor on the second member, realpath reports ENOENT to the root, so the key is the
lexical second member. Measured against mutants in this worktree:
- frame budget 8 to 9 at fileLock.ts:61 -> 1 failed, 6 passed
- hop budget not carried to the next frame at fileLock.ts:74 -> 1 failed, 6 passed
Both were killed by the new rows; the unmutated tree runs 7 passed in that file.
Thread 4525470987 - the crash-safety test named a post-commit backup cleanup failure
as swallowed, but the step that makes it pass is step 6 retrying once. The name, the
comment and the assertions now say that: the failing attempt and the retry are both
counted. Removing the retry (attempt < 2 to attempt < 1 at safeWriteText.ts:796) turns
3 tests red, including this one and its twin, so the assertion is load-bearing.
Thread 4525471043 - the failure path after the commit rename removes the backup copy
with one unlink whose error is swallowed, while the success path makes two attempts and
reports a leftover as OrphanedPublishedBackupError. No source change this round:
reporting the leftover would change which error the caller sees. A new top-level
describe pins what happens today - one attempt, the durability failure reported, and
nothing in it naming the path the failed unlink left beside the target. The desired
contract was measured instead of assumed: the same test with toHaveLength(2) fails on
this tree with 1 failed, 73 passed, which is the row a source fix would have to make
pass. Skipping the unlink at safeWriteText.ts:841 turns 4 tests red, including this pin.
Thread 4525471113 - fileLock.ts carried its own copy of the error-code extractor. It
now calls getErrorCode from utils/errorCode.ts, which drops 3 counted source lines. The
two copies differ only in accepting a non-string code property, and the only use is a
comparison against two string literals, so the behaviour is identical and no test had
to change: six suites covering fileLock.ts and safeWriteJson.ts run 157 passed, 6
skipped, exit 0.
Thread 4525471006 - canonicalKey.spec.ts now pins the divergence the reviewer asked to
see, with the two requirements quoted in the comment above it: an ancestor realpath
that fails with EACCES makes resolveLockKey reject while withFileLock still locks the
lexical path. Swallowing the rethrow at safeWriteText.ts:356 turns that row red with
'promise resolved ... instead of rejecting'.
Verification, all of it in worktree wt-r161-1914 at node v22.23.4 (the version in
.nvmrc) with a frozen-lockfile install of this tree's own pnpm-lock.yaml:
- vitest run over the six affected specs: 6 files passed, 157 passed, 6 skipped, exit 0.
- vitest run of the three directly edited specs before the mutants: 3 files passed, 84
tests passed, exit 0.
- eslint --prune-suppressions --max-warnings=0 on each of the four touched files:
exit 0, no output, and none of the four has an entry in src/eslint-suppressions.json,
so each file's count is 0 before and 0 after. Summed over the file the counts read
2,866 before and 2,866 after across 265 file keys; the prune run rewrote the JSON from
tab indent to two-space indent (30,910 B to 33,294 B, 0 semantic count diffs) and that
churn was reverted, so this commit carries only the four paths in its stat.
- tsc --noEmit in src exit 0; tsc -p tsconfig.json --noEmit at the root exit 0.
- no --no-verify, no HUSKY=0, no git add -A, no changeset and no CHANGELOG change.1 parent c2ca88c commit 28129e1
4 files changed
Lines changed: 91 additions & 13 deletions
File tree
- src
- services/file-safety/__tests__
- utils
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
364 | 364 | | |
365 | 365 | | |
366 | 366 | | |
367 | | - | |
| 367 | + | |
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | | - | |
372 | | - | |
373 | | - | |
374 | | - | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
375 | 385 | | |
376 | 386 | | |
377 | 387 | | |
378 | 388 | | |
379 | 389 | | |
380 | 390 | | |
381 | 391 | | |
382 | | - | |
| 392 | + | |
| 393 | + | |
383 | 394 | | |
| 395 | + | |
384 | 396 | | |
385 | 397 | | |
386 | 398 | | |
| |||
1598 | 1610 | | |
1599 | 1611 | | |
1600 | 1612 | | |
| 1613 | + | |
| 1614 | + | |
| 1615 | + | |
| 1616 | + | |
| 1617 | + | |
| 1618 | + | |
| 1619 | + | |
| 1620 | + | |
| 1621 | + | |
| 1622 | + | |
| 1623 | + | |
| 1624 | + | |
| 1625 | + | |
| 1626 | + | |
| 1627 | + | |
| 1628 | + | |
| 1629 | + | |
| 1630 | + | |
| 1631 | + | |
| 1632 | + | |
| 1633 | + | |
| 1634 | + | |
| 1635 | + | |
| 1636 | + | |
| 1637 | + | |
| 1638 | + | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
1601 | 1654 | | |
1602 | 1655 | | |
1603 | 1656 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
71 | 92 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
163 | | - | |
164 | | - | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
165 | 170 | | |
166 | | - | |
| 171 | + | |
| 172 | + | |
167 | 173 | | |
168 | 174 | | |
169 | 175 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
| 83 | + | |
86 | 84 | | |
87 | 85 | | |
88 | 86 | | |
| |||
0 commit comments