Repository navigation
Commit 7532ed2
committed
fix(safe-write): compare directory identity in the safeWriteText staging guard
The windows required leg (node 22.23.4) failed at 0580426 in 20 tests, and both
shapes trace to delegating the JSON commit to safeWriteText:
- 8 in utils/__tests__/safeWriteJson.test.ts, raised at safeWriteText.ts:361:
StagingPathError: Staging file must sit in the target's directory
(C:\Users\runneradmin\AppData\Local\Temp\safeWriteJson-test-whV2CF), got
C:\Users\RUNNER~1\AppData\Local\Temp\...
- 12 in safeWriteJson.interruption.test.ts, all at line 187 with one payload:
AssertionError: expected 'WRITE_COMPLETED' to contain
'EXIT_AT_REPLACEMENT_RENAME'.
The guard's comparison has two operands produced by two different
canonicalisations - the spelling the caller's staging-file derivation hands down
(the short one, the message's 'got') and the spelling safeWriteText derives when
it re-resolves its own argument (the long one, the message's expected directory)
- and on NTFS one directory answers to more than one spelling: the 8.3 alias of
any name longer than eight characters, a junction, or a link. One directory, two
strings, in a single message.
Measured on node 22.23.4 (.tool-versions pins 22.23.4, package.json engines
repeats it, the hosted legs run it; this box's system node is v25.9.0) against a
real short-name alias of a directory:
path.resolve(SHORT) != path.resolve(LONG)
fs.realpathSync(SHORT) != fs.realpathSync(LONG)
fs.realpathSync.native(SHORT) == fs.realpathSync.native(LONG)
fs.stat(SHORT).dev == fs.stat(LONG).dev, and .ino == .ino
Node 22's JavaScript fs.realpath preserves whichever spelling it is handed, so
comparing realpaths would not have unified the runner's pair either. Only stat
identity unifies an 8.3 alias, a junction and a case difference at once.
Why not just stage from the resolved directory (option a): safeWriteJson.ts
already does that - :183 builds the staging name from resolvedTargetPath and :197
passes that same variable as the target - and the runner still splits the
spellings, because safeWriteText re-resolves the path it is handed and that
re-resolution can take a different route: an existing target canonicalises, a
target that does not exist yet falls through to path.resolve. The mismatch is
therefore not fixable from the call site, and it is not evidence that the guard
is too strict: the guard is textual on purpose. What it protects is a property of
directory identity - no cross-filesystem commit rename (EXDEV), and never
publishing an unrelated file onto the target - so a textual mismatch is now
settled by comparing dev+ino read as bigint, the idiom the staged-file check
below it already uses, and the rejection stands whenever either directory cannot
be stat'd. A staging file in a genuinely different directory is still rejected
under both spellings.
The interruption half: the fault hook is the child's monkey-patch of
fsPromises.rename inside safeWriteJson.interruption.test.ts, not the
options.trace replacement-rename line - EXIT_AT_REPLACEMENT_RENAME is printed by
that hook. The delegation moved the commit rename's destination from the caller's
string to safeWriteText's own resolved publish target, so the hook's textual
match against INTERRUPTION_TARGET_PATH misses whenever the directory is spelled
through an alias: the SIGKILL never fires, the write completes, and the parent
sees WRITE_COMPLETED. That is a behavioural consequence of the delegation, not a
test-only looseness, and ubuntu cannot see it because its temp directory has no
alias. The harness now recognises the commit rename by canonical destination, and
a new win32 case spells the target through a junction so the assertion is red
without the harness fix (reproduced: 1 failed | 12 passed with the CI assertion
text above; 13 passed after).
Tests, all on node 22.23.4:
- new services/file-safety/__tests__/safeWriteText.alias.spec.ts reproduces the
guard failure for real on this box at the pre-fix guard (blob 688f2ef):
same StagingPathError thrown at safeWriteText.ts:361, expected directory in
the long spelling, got directory in the short one. The suite skips itself
where the volume generates no 8.3 names, which is why ubuntu - and this box's
own long-spelled temp path - never showed it.
- negative control at 688f2ef across both specs: 2 failed | 77 passed; with
the fix: 79 passed.
- the misc project, which is the leg that was red, and the core project were
rerun on this tree; counts are in the push report.
The staging-name convention (the anchored .new_*.tmp rule in safeWriteText.ts) and
its spec pin are untouched. The guard's contract and the canonicalisation choice
belong to upstream, are tracked in Zoo-Code-Org#2350, and the cross-unit note is filed on
Zoo-Code-Org#1405.1 parent 793353a commit 7532ed2
4 files changed
Lines changed: 328 additions & 6 deletions
File tree
- src
- services/file-safety
- __tests__
- utils/__tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
108 | 114 | | |
109 | 115 | | |
110 | 116 | | |
| |||
1707 | 1713 | | |
1708 | 1714 | | |
1709 | 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 | + | |
1710 | 1786 | | |
1711 | 1787 | | |
1712 | 1788 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
358 | 358 | | |
359 | 359 | | |
360 | 360 | | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
365 | 391 | | |
366 | 392 | | |
367 | 393 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
32 | 60 | | |
33 | 61 | | |
34 | 62 | | |
35 | 63 | | |
36 | | - | |
| 64 | + | |
37 | 65 | | |
38 | 66 | | |
39 | 67 | | |
40 | | - | |
| 68 | + | |
41 | 69 | | |
42 | 70 | | |
43 | 71 | | |
| |||
239 | 267 | | |
240 | 268 | | |
241 | 269 | | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
242 | 349 | | |
0 commit comments