Repository navigation
Commit 7cd0106
committed
Zoo-Code-Org#1912 review rows: resolve-or-refuse lock key, re-verify at the commit
Eleven review rows were open on Zoo-Code-Org#1912 at 085fbf8. Every production change below carries a row that
fails without it, and that claim was tested rather than asserted: the two source files were read out of
085fbf8 with 'git show', written into this worktree unchanged, and the three affected spec files were
run against them. 15 of this unit's rows failed - 5 in services/file-safety/__tests__/safeWriteText.spec,
9 in utils/__tests__/safeWriteJson.test, 1 in utils/__tests__/safeWriteJson.lockKey.spec - while every
pre-existing row in those files stayed green. safeWriteJson.interruption.test (12) and
safeWriteText.integration.spec (7) were green in both states.
safeWriteText.ts - the lock key is resolved or refused, never guessed
canonicalDirKey now walks upward only while the lookup answers ENOENT: it collects the missing names,
retries the parent, and rethrows any other code, so a directory that exists but cannot be read is no
longer treated as absent. resolveLockKey bounds the link walk at 8 links and throws instead of returning
whichever link the bound stopped on; it reads a relative referent against the link's real parent rather
than the spelled one; and it accepts only ENOENT and EINVAL from readlink as 'not a link' - measured on
this box, those are the two answers a real readlink gives (EINVAL for a plain file, ENOENT for a missing
path) - so any other code propagates instead of being read as a verdict about the path.
Rows: refuses a lock key when an ancestor exists but cannot be canonicalized; keys a relative referent
through the link's real parent, not the spelled one; propagates a readlink failure that says nothing
about whether the path is a link; and the existing cycle row, retitled to terminates on a link cycle and
refuses rather than naming whichever link the bound stopped on. The last of those is a contract change,
not an addition: at 085fbf8 the same fixture returned the 8th link's spelling and the old row asserted
the return, so the row now asserts the rejection and keeps the eight-call evidence.
Before the commit rename, safeWriteText compares the staging name against the identity it just fsynced
(fstatSync with bigint stats, then lstat at the rename, nlink compared against 1n because every bigint
field is a bigint and 1n !== 1 is always true) and refuses with StagingPathError when a different file
sits there; the cleanup gate skips the unlink in that case, because the name now belongs to another
file's write. Rows: refuses the commit rename when a different file sits at the staging name after the
fsync (rename not called, unlink not called) and keeps the commit when the staged name still holds the
file that was fsynced. The second row is a control and passes at 085fbf8 as well, which is what a
control is for.
Two pre-existing rows needed better doubles rather than a looser product: rows whose subject is target
resolution mocked fs.lstat to reject ENOENT for every path, and the staging check reads the same mock,
so those doubles are now path-aware; and the lock-key spec's two 'not a link' doubles threw a bare Error
with no code, which the new taxonomy cannot treat as 'not a link', so they now carry EINVAL.
safeWriteJson.ts - the confinement decision is pinned and re-checked at the rename
The confinement root resolved before the lock is captured once (confinedScopeRoot) and every later check
uses it, so a peer that replaces the scope directory's name while the writer waits for the lock can no
longer move the publish outside the scope the write was authorised for. Recovery now runs after the
confinement check rather than before it, against the same pinned root, and is keyed to the lock key -
the referent's directory - so an interrupted EPERM fallback is found by the next writer that arrives
through a differently named alias. _assertConfinementStillHolds compares the re-resolved target with the
pinned target and re-checks each pinned directory's identity and its resolved path, and it runs both
before the staged write and immediately before the commit rename, so an ancestor swapped while the JSON
was streaming cannot publish outside the scope. ENOENT and ENOTDIR from those lookups mean the directory
is gone or is no longer a directory; every other code propagates, so a transient EACCES is no longer
reported as an ancestor replacement. TargetMovedError now names the target the caller authorised and the
target it resolves to now, which are different things. _streamDataToFile creates the staged file with
mode 0o600, and _copyTargetMode fails closed: a stat or chmod failure aborts the publish instead of
logging past it and publishing a world-readable replacement for a private target.
Rows: refuses the commit when an ancestor is swapped while the staged write is in flight; refuses the
commit when a moved ancestor's old name is replaced by a link back to it; propagates a transient ancestor
lookup failure instead of reporting a replaced ancestor; reports what the target resolves to now when it
no longer resolves to the pinned target; holds the confined scope to the directory named before the lock
when a peer replaces that name; does not recover an interrupted write through an ancestor that was
replaced while the lock was waited for; creates the staged JSON private and puts the target's own mode on
it before publishing; aborts the publish when the staged file cannot take the target's mode; aborts the
publish when the target's mode cannot be read; and, in the lock-key spec, recovers an interrupted write
beside the referent the lock key names, not beside the spelling the caller arrived with.
The post-commit directory-fsync row was strengthened in place instead of added beside itself. It used to
assert only that the warning mentions fsync, which the warning also satisfies when the directory cannot
be opened at all, so no fsync ever ran. It now records the fsyncSync descriptors and the openSync calls
for the published file's directory and requires a fsync on one of those handles after the commit rename.
The vacuity was demonstrated in three runs of that one row: the old assertion plus a mocked openSync
failure passed (1 passed, 61 skipped), the new assertions plus the same mocked failure failed, and the
new assertions on the unmodified run passed. Two harness facts shaped the row: reading a spy's calls
after mockRestore is vacuous because restoring clears the call history, and createWriteStream opens the
file lazily, so the staged file's own mode is read on the stream's open event.
Gates, this worktree, node 22.23.4 win32, cwd src unless noted:
eslint --max-warnings=0 --no-warn-ignored --no-cache, the five delta files: exit 0, no output.
prettier --check, the same five: exit 0 (All matched files use Prettier code style).
tsc --noEmit -p tsconfig.json: exit 2, one line - activate/registerCommands.ts(88,102): error TS2739 -
the same pre-existing error the parent reports; nothing else.
src/eslint-suppressions.json: 0 bytes of diff; no suppressed count moved.
safeWriteText.spec 94 passed (103 rows at parent, 109 now); safeWriteText.integration.spec 7 passed;
safeWriteJson.test 62 passed (46 rows at parent, 55 now, 1 row strengthened);
safeWriteJson.lockKey.spec 6 passed (5 at parent); safeWriteJson.interruption.test 12 passed.
Lanes, run one at a time: misc 2119 passed 13 skipped; core 4247 passed 9 skipped; services 1704
passed 11 failed; api 4069 passed 1 failed.
Coverage with those specs: safeWriteText.ts 96.93 statements 91.23 branch 96.75 lines; safeWriteJson.ts
94.94 statements 82 branch 94.94 lines (misc lane, exit 0).
The services and api failures are local and pre-existing: with the parent's two source files restored
the same specs give the same 11 and 1 (marketplace 4, rules 5, parser 2 - TelemetryService not
initialized through the junction'd donor telemetry package, and EPERM on fs.symlink; and
api/providers/__tests__/poe.spec.ts expecting maxTokens 8192 and receiving 128000). poe.spec fails
alone as well, so it is not lane contention.
knip and knip:production could not run here at all: both stop with 'Cannot find module
@roo-code/config-eslint/base' while loading apps/cli/eslint.config.mjs, and
scripts/knip-policy.test.mjs reports 7 pass 1 fail with this unit's changes stashed, the same numbers
it reports unstashed. knip's arm was green at the parent and this delta exports nothing new, so the
local inability to run it is recorded as a gap in this checkout's install, not as evidence.
No changeset and no CHANGELOG entry, per AGENTS.md. Delta: 5 files, 858 insertions, 86 deletions, of
which 603 insertions are test rows.1 parent 085fbf8 commit 7cd0106
5 files changed
Lines changed: 858 additions & 86 deletions
File tree
- src
- services/file-safety
- __tests__
- utils
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1447 | 1447 | | |
1448 | 1448 | | |
1449 | 1449 | | |
1450 | | - | |
1451 | | - | |
1452 | | - | |
1453 | | - | |
| 1450 | + | |
| 1451 | + | |
| 1452 | + | |
| 1453 | + | |
| 1454 | + | |
| 1455 | + | |
| 1456 | + | |
| 1457 | + | |
| 1458 | + | |
1454 | 1459 | | |
1455 | 1460 | | |
1456 | 1461 | | |
| |||
1653 | 1658 | | |
1654 | 1659 | | |
1655 | 1660 | | |
1656 | | - | |
1657 | | - | |
1658 | | - | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
1659 | 1671 | | |
1660 | 1672 | | |
1661 | 1673 | | |
| |||
1664 | 1676 | | |
1665 | 1677 | | |
1666 | 1678 | | |
1667 | | - | |
| 1679 | + | |
1668 | 1680 | | |
1669 | 1681 | | |
1670 | 1682 | | |
1671 | 1683 | | |
1672 | | - | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
1673 | 1688 | | |
1674 | 1689 | | |
1675 | | - | |
1676 | | - | |
1677 | | - | |
| 1690 | + | |
| 1691 | + | |
1678 | 1692 | | |
1679 | 1693 | | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
| 1706 | + | |
| 1707 | + | |
| 1708 | + | |
| 1709 | + | |
| 1710 | + | |
| 1711 | + | |
| 1712 | + | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
| 1718 | + | |
| 1719 | + | |
| 1720 | + | |
| 1721 | + | |
| 1722 | + | |
| 1723 | + | |
| 1724 | + | |
| 1725 | + | |
| 1726 | + | |
| 1727 | + | |
| 1728 | + | |
| 1729 | + | |
| 1730 | + | |
| 1731 | + | |
| 1732 | + | |
| 1733 | + | |
| 1734 | + | |
| 1735 | + | |
| 1736 | + | |
| 1737 | + | |
| 1738 | + | |
| 1739 | + | |
| 1740 | + | |
| 1741 | + | |
| 1742 | + | |
| 1743 | + | |
| 1744 | + | |
| 1745 | + | |
| 1746 | + | |
| 1747 | + | |
| 1748 | + | |
| 1749 | + | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
| 1753 | + | |
| 1754 | + | |
| 1755 | + | |
| 1756 | + | |
| 1757 | + | |
| 1758 | + | |
| 1759 | + | |
| 1760 | + | |
| 1761 | + | |
| 1762 | + | |
| 1763 | + | |
| 1764 | + | |
| 1765 | + | |
| 1766 | + | |
| 1767 | + | |
| 1768 | + | |
| 1769 | + | |
| 1770 | + | |
| 1771 | + | |
| 1772 | + | |
| 1773 | + | |
| 1774 | + | |
| 1775 | + | |
| 1776 | + | |
| 1777 | + | |
| 1778 | + | |
| 1779 | + | |
| 1780 | + | |
| 1781 | + | |
| 1782 | + | |
| 1783 | + | |
| 1784 | + | |
| 1785 | + | |
| 1786 | + | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
| 1799 | + | |
| 1800 | + | |
| 1801 | + | |
| 1802 | + | |
| 1803 | + | |
| 1804 | + | |
| 1805 | + | |
| 1806 | + | |
1680 | 1807 | | |
1681 | 1808 | | |
1682 | 1809 | | |
| |||
1945 | 2072 | | |
1946 | 2073 | | |
1947 | 2074 | | |
1948 | | - | |
| 2075 | + | |
| 2076 | + | |
| 2077 | + | |
| 2078 | + | |
| 2079 | + | |
| 2080 | + | |
1949 | 2081 | | |
1950 | 2082 | | |
1951 | 2083 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
348 | 348 | | |
349 | 349 | | |
350 | 350 | | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
351 | 358 | | |
352 | 359 | | |
353 | 360 | | |
354 | | - | |
355 | | - | |
356 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
357 | 382 | | |
358 | 383 | | |
359 | 384 | | |
| |||
362 | 387 | | |
363 | 388 | | |
364 | 389 | | |
365 | | - | |
366 | | - | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
367 | 394 | | |
368 | 395 | | |
369 | 396 | | |
| |||
376 | 403 | | |
377 | 404 | | |
378 | 405 | | |
379 | | - | |
380 | | - | |
381 | | - | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
382 | 414 | | |
383 | | - | |
384 | | - | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
385 | 421 | | |
386 | | - | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
387 | 431 | | |
388 | | - | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
389 | 437 | | |
390 | 438 | | |
391 | 439 | | |
| |||
531 | 579 | | |
532 | 580 | | |
533 | 581 | | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
534 | 591 | | |
535 | 592 | | |
536 | 593 | | |
| |||
599 | 656 | | |
600 | 657 | | |
601 | 658 | | |
| 659 | + | |
602 | 660 | | |
603 | 661 | | |
604 | 662 | | |
| |||
637 | 695 | | |
638 | 696 | | |
639 | 697 | | |
| 698 | + | |
640 | 699 | | |
641 | 700 | | |
642 | 701 | | |
| |||
805 | 864 | | |
806 | 865 | | |
807 | 866 | | |
| 867 | + | |
| 868 | + | |
| 869 | + | |
| 870 | + | |
| 871 | + | |
| 872 | + | |
| 873 | + | |
| 874 | + | |
| 875 | + | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
| 884 | + | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
808 | 903 | | |
809 | 904 | | |
810 | 905 | | |
| |||
939 | 1034 | | |
940 | 1035 | | |
941 | 1036 | | |
942 | | - | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
943 | 1041 | | |
944 | 1042 | | |
945 | 1043 | | |
| |||
0 commit comments