Repository navigation
Commit 3289a72
easonLiangWorldedtech
fix: pin the directories a confined write creates before it commits
Review row, quoted: "src/utils/safeWriteJson.ts:327-331 records only existing ancestor identities before safeWriteText creates directories, and src/services/file-safety/safeWriteText.ts:758-818 rechecks those identities" - the re-check therefore walks a list that omits the components this write itself made.
The gap is real and it is in the shared primitive, not in the caller. _confinedAncestorIdentities walks the whole chain from the scope root to the target's parent but records only what it can stat, and a directory that does not exist yet has no dev/ino to record. safeWriteText then measures the missing tail (_missingDirectoryTail, which exists so a failed write can remove what it made) and creates it with a recursive mkdir that reports nothing. So between that mkdir and the commit, a local process that replaces one of the freshly created components with a link to outside the scope sends the rename somewhere the confinement decision never made, while every recorded identity still matches - the names are unchanged. This is a defect whose conditions are not yet met, not a missing feature.
safeWriteText now pins what it created: after the mkdir, when the caller supplied expectedAncestorIdentities (a confined publication - an unconfined write has no scope for a swap to escape), it records the identity of each directory in createdDirs and the step-2b re-check walks the recorded list plus those. The stat-with-mapping that step 2b already had is extracted as _statDirectoryIdentity and used by both, so ENOENT still surfaces as AncestorReplacedError and any other failure still propagates as "no evidence, no publish", with one branch set rather than two.
Not adopted from the row, deliberately: no-follow directory handles and a descriptor-relative renameat/renameat2. Node has no descriptor-relative rename, which the option's own documentation already records as the reason a swap after the check cannot be eliminated - the pin narrows the window to the commit itself rather than the whole write. Pinning the created components leaves the residual window in exactly the same shape the existing pin already accepts, and it satisfies the property the row is after: validation and publication are bound to one authorized target rather than to a name that may have been repointed underneath them.
Red first, then green, then negative controls. Before the change the new test 'refuses the publish when a parent this write created is swapped for a link' was red (the publish went through with no error at all); with the pin it passes, and its companion 'publishes when a parent this write created keeps the identity it was given' shows the pin does not reject the ordinary case of a confined write into a tree it had to make. Two controls, because the fix has two halves: skipping the recording turns the test red, and recording without feeding the list to the re-check also turns it red. Both mutants were restored byte-exact.
This is a fix to a shared primitive, so every unit that carries safeWriteText inherits the defect; the ports are recorded as owed and must be re-derived per unit rather than copied, since each unit's call shape differs. Verification: 124 passed / 6 skipped across the file-safety, safeWriteJson and ApplyPatchTool specs; prettier --write then --check with the repo config clean; tsc --noEmit with the local paths override 0 errors; eslint . --ext=ts --max-warnings=0 exits 0; eslint-suppressions.json unchanged.1 parent 5131bc0 commit 3289a72
2 files changed
Lines changed: 115 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1574 | 1574 | | |
1575 | 1575 | | |
1576 | 1576 | | |
| 1577 | + | |
| 1578 | + | |
| 1579 | + | |
| 1580 | + | |
| 1581 | + | |
| 1582 | + | |
| 1583 | + | |
| 1584 | + | |
| 1585 | + | |
| 1586 | + | |
| 1587 | + | |
| 1588 | + | |
| 1589 | + | |
| 1590 | + | |
| 1591 | + | |
| 1592 | + | |
| 1593 | + | |
| 1594 | + | |
| 1595 | + | |
| 1596 | + | |
| 1597 | + | |
| 1598 | + | |
| 1599 | + | |
| 1600 | + | |
| 1601 | + | |
| 1602 | + | |
| 1603 | + | |
| 1604 | + | |
| 1605 | + | |
| 1606 | + | |
| 1607 | + | |
| 1608 | + | |
| 1609 | + | |
| 1610 | + | |
| 1611 | + | |
| 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 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
1577 | 1659 | | |
1578 | 1660 | | |
1579 | 1661 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
212 | 212 | | |
213 | 213 | | |
214 | 214 | | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
215 | 229 | | |
216 | 230 | | |
217 | 231 | | |
| |||
597 | 611 | | |
598 | 612 | | |
599 | 613 | | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
600 | 618 | | |
601 | 619 | | |
602 | 620 | | |
| |||
611 | 629 | | |
612 | 630 | | |
613 | 631 | | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
| 635 | + | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
614 | 643 | | |
615 | 644 | | |
616 | 645 | | |
| |||
755 | 784 | | |
756 | 785 | | |
757 | 786 | | |
758 | | - | |
759 | | - | |
760 | | - | |
761 | | - | |
762 | | - | |
763 | | - | |
764 | | - | |
765 | | - | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
766 | 791 | | |
767 | 792 | | |
768 | 793 | | |
| |||
0 commit comments