Repository navigation
Commit 0b40d66
committed
file-safety: close the four pre-commit and post-commit gaps CodeRabbit raised
Four fixes on the safeWriteText commit path, each behind a test that fails without it:
- validate the recorded ancestor identities BEFORE mkdir(recursive:true). mkdir follows
whatever the name resolves to at the moment it runs, so a parent already swapped for a
link outside the authorized chain was created through before the step 2b revalidation ever
compared identities. Step 2b stays: it is what catches a swap in the window between the
preflight and the commit. ENOENT is skipped, because an ancestor about to be created is
not a containment violation.
- compare both names after link(2). There was no post-commit identity check in the module
at all: a third party that replaced the staging file before the link published bytes this
write never staged. A mismatch now throws PublishedEntryMismatchError carrying targetPath
and leaves BOTH names in place (stagingCommitted is set first), because after the link the
staged name may belong to another process and an unlink by pathname could remove an entry
this write does not own. The rename path cannot be verified this way; the comment says so
and points at Zoo-Code-Org#2391 for what that follow-up must prove.
- report an orphaned staged file instead of swallowing the failed unlink, and report a failed
win32 DACL restore instead of swallowing the error. Both happen after the content is
committed, so failing the write would report a failure for bytes the caller can read back;
the new optional onPostCommitWarning callback names the residue and the cause while the
write still resolves. PostCommitDurabilityError remains a throw: there the caller cannot
rely on the write at all.
No export is added for the warning value type (the kinds are spelled inline) because no
production caller selects on them today, and an export whose only reader is a spec is dead
API. safeWriteText still returns Promise<void>, so no caller changes.
Tests: 4 added, 1 assertion updated (the ancestry refusal now happens before anything is
created, so it asserts that nothing was created). Mutants: removing the preflight call fails
2 tests, neutering the post-link guard fails 1, and dropping either warning report fails 1;
the unmutated pair is 2 files / 95 tests passing on the pinned node 22.23.4.
No .changeset, no CHANGELOG edit, no suppression count change.1 parent 970b3a4 commit 0b40d66
2 files changed
Lines changed: 255 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
112 | 119 | | |
113 | 120 | | |
114 | 121 | | |
| |||
977 | 984 | | |
978 | 985 | | |
979 | 986 | | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
| 999 | + | |
| 1000 | + | |
| 1001 | + | |
| 1002 | + | |
| 1003 | + | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
| 1007 | + | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
980 | 1020 | | |
981 | 1021 | | |
982 | 1022 | | |
| |||
1596 | 1636 | | |
1597 | 1637 | | |
1598 | 1638 | | |
| 1639 | + | |
| 1640 | + | |
| 1641 | + | |
| 1642 | + | |
| 1643 | + | |
| 1644 | + | |
| 1645 | + | |
| 1646 | + | |
| 1647 | + | |
| 1648 | + | |
| 1649 | + | |
| 1650 | + | |
| 1651 | + | |
| 1652 | + | |
| 1653 | + | |
| 1654 | + | |
| 1655 | + | |
| 1656 | + | |
| 1657 | + | |
| 1658 | + | |
| 1659 | + | |
| 1660 | + | |
| 1661 | + | |
| 1662 | + | |
| 1663 | + | |
| 1664 | + | |
| 1665 | + | |
| 1666 | + | |
| 1667 | + | |
| 1668 | + | |
| 1669 | + | |
| 1670 | + | |
| 1671 | + | |
| 1672 | + | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
| 1679 | + | |
| 1680 | + | |
| 1681 | + | |
| 1682 | + | |
| 1683 | + | |
| 1684 | + | |
| 1685 | + | |
| 1686 | + | |
| 1687 | + | |
| 1688 | + | |
| 1689 | + | |
| 1690 | + | |
| 1691 | + | |
| 1692 | + | |
| 1693 | + | |
| 1694 | + | |
| 1695 | + | |
| 1696 | + | |
| 1697 | + | |
| 1698 | + | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
| 1702 | + | |
| 1703 | + | |
| 1704 | + | |
| 1705 | + | |
1599 | 1706 | | |
1600 | 1707 | | |
1601 | 1708 | | |
| |||
1646 | 1753 | | |
1647 | 1754 | | |
1648 | 1755 | | |
1649 | | - | |
1650 | | - | |
| 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 | + | |
1651 | 1789 | | |
1652 | 1790 | | |
1653 | 1791 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
86 | 99 | | |
87 | 100 | | |
88 | 101 | | |
| |||
319 | 332 | | |
320 | 333 | | |
321 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
322 | 353 | | |
323 | 354 | | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
324 | 382 | | |
325 | 383 | | |
326 | 384 | | |
| |||
406 | 464 | | |
407 | 465 | | |
408 | 466 | | |
409 | | - | |
410 | | - | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
411 | 476 | | |
412 | 477 | | |
413 | 478 | | |
414 | 479 | | |
415 | 480 | | |
416 | 481 | | |
417 | 482 | | |
418 | | - | |
419 | | - | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
420 | 487 | | |
421 | 488 | | |
422 | 489 | | |
| |||
564 | 631 | | |
565 | 632 | | |
566 | 633 | | |
| 634 | + | |
567 | 635 | | |
568 | 636 | | |
569 | 637 | | |
| |||
937 | 1005 | | |
938 | 1006 | | |
939 | 1007 | | |
| 1008 | + | |
| 1009 | + | |
| 1010 | + | |
| 1011 | + | |
| 1012 | + | |
| 1013 | + | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
940 | 1032 | | |
941 | 1033 | | |
942 | 1034 | | |
943 | 1035 | | |
944 | | - | |
945 | | - | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
946 | 1047 | | |
947 | 1048 | | |
948 | 1049 | | |
| |||
983 | 1084 | | |
984 | 1085 | | |
985 | 1086 | | |
986 | | - | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
987 | 1095 | | |
988 | 1096 | | |
989 | 1097 | | |
| |||
0 commit comments