Repository navigation
Commit 120cb05
committed
unit(u5b): guard machinery in the writer, with the identity and rights refusals
First unit of the #1914 split plan recorded on #1991: this branch's increment over PR #1913's
head 416179d for the writer-side paths (safeWriteText.ts and its spec, fileLock.ts and
its spec, Task.ts and Task.spec.ts). guardedWrite.ts and its spec stay in the next unit,
because the tool consumes this unit's guard API rather than the reverse.
Two refusals that the refresh merge surfaced as divergent between the two copies of
safeWriteText.ts are re-added here rather than left as a silent loss, per the lead's ruling
on #1991 question 1. Neither is a rival design: the staging-path (dev, ino) refusal applies
the contract confirmed on #2356 (identity compared after canonicalisation, consumers
compare identity) to the file this write stages through, and the DACL refusal is the same
fail-closed principle ruled for _copyTargetMode in #1917 - publishing without knowing the
target's access rights can widen who reads the file, and logging-and-continuing was
rejected there. Both are recorded as requirements on #2350.
1. Staging identity: the supplied staging path and the target are compared by (dev, ino)
read with bigint stats (file identities on NTFS/ReFS exceed Number.MAX_SAFE_INTEGER, and
a rounded number either hides an alias or rejects a valid staging file). Only ENOENT may
skip the comparison; EACCES/ELOOP/ENOTDIR means the comparison could not be made and is
itself a refusal, because otherwise an alias reaches the commit and the failure handler
unlinks the only remaining copy of the content - a failed write would delete the file it
was meant to protect. Pinned by two tests: the alias itself, and the non-ENOENT reason.
2. Access rights on win32: a target that exists but whose DACL cannot be saved, or whose
access rights cannot be read (getErrorCode != ENOENT), now yields DaclInspectionError
before anything is committed, with the phase and target path on the error. The class is
the one PR #1913's copy already carries; its text is taken unchanged.
Contract change, stated because tests move with it: two tests in this branch's spec asserted
the opposite behaviour - "win32 DACL failure falls back to plain rename (never fails the
write)" and the partial-dump test's assertion that the write commits. Both are replaced
with assertions of the refusal (rename never happens, the dump is still unlinked, one icacls
attempt, phase and path pinned). A third test covers the inspection refusal; it injects
platform win32 and stubs icacls, so it runs on either hosted leg rather than only on the
windows one, and the hosted windows leg passes this file.
One config line comes with this unit: knip.json declares services/file-safety/safeWriteText.ts as a src
workspace entry. Without it, knip --production fails on this unit in isolation - knip does
not credit imports from files it reports as unused, and the only production consumer of the
exported safeWriteText function arrives with the next unit - and knip is a required status
check on main (Protect Main ruleset: check-translations, both platform-unit-test legs,
compile, knip, e2e-mock). With the entry declared, both knip modes and the knip-policy test
pass on this unit alone.1 parent 416179d commit 120cb05
7 files changed
Lines changed: 1196 additions & 441 deletions
File tree
- src
- core/task
- __tests__
- services/file-safety
- __tests__
- utils
- __tests__
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
20 | 25 | | |
21 | 26 | | |
22 | 27 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
401 | 406 | | |
402 | 407 | | |
403 | 408 | | |
| |||
3596 | 3601 | | |
3597 | 3602 | | |
3598 | 3603 | | |
| 3604 | + | |
| 3605 | + | |
| 3606 | + | |
| 3607 | + | |
| 3608 | + | |
3599 | 3609 | | |
3600 | 3610 | | |
3601 | 3611 | | |
| |||
3606 | 3616 | | |
3607 | 3617 | | |
3608 | 3618 | | |
| 3619 | + | |
| 3620 | + | |
| 3621 | + | |
| 3622 | + | |
3609 | 3623 | | |
3610 | 3624 | | |
3611 | 3625 | | |
| |||
3634 | 3648 | | |
3635 | 3649 | | |
3636 | 3650 | | |
| 3651 | + | |
3637 | 3652 | | |
3638 | 3653 | | |
3639 | 3654 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4768 | 4768 | | |
4769 | 4769 | | |
4770 | 4770 | | |
| 4771 | + | |
| 4772 | + | |
| 4773 | + | |
| 4774 | + | |
| 4775 | + | |
| 4776 | + | |
| 4777 | + | |
| 4778 | + | |
| 4779 | + | |
| 4780 | + | |
| 4781 | + | |
| 4782 | + | |
| 4783 | + | |
| 4784 | + | |
| 4785 | + | |
| 4786 | + | |
| 4787 | + | |
| 4788 | + | |
| 4789 | + | |
| 4790 | + | |
| 4791 | + | |
| 4792 | + | |
| 4793 | + | |
| 4794 | + | |
| 4795 | + | |
| 4796 | + | |
| 4797 | + | |
| 4798 | + | |
| 4799 | + | |
| 4800 | + | |
| 4801 | + | |
| 4802 | + | |
| 4803 | + | |
| 4804 | + | |
| 4805 | + | |
| 4806 | + | |
| 4807 | + | |
| 4808 | + | |
| 4809 | + | |
| 4810 | + | |
| 4811 | + | |
| 4812 | + | |
| 4813 | + | |
| 4814 | + | |
| 4815 | + | |
| 4816 | + | |
| 4817 | + | |
| 4818 | + | |
| 4819 | + | |
| 4820 | + | |
4771 | 4821 | | |
4772 | 4822 | | |
4773 | 4823 | | |
| |||
0 commit comments