Repository navigation
feat(file-safety): atomic text publish primitive + safeWriteJson refactor (A4, #1375) #1395
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
easonLiangWorldedtech
wants to merge
49
commits into
Zoo-Code-Org:main
Choose a base branch
from
easonLiangWorldedtech:feat/atomic-publish-s3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,490
−174
Open
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
a37dd24
feat(file-safety): atomic text publish primitive + safeWriteJson refa…
easonliang28 7fd49bc
chore(ci): empty commit — re-trigger CI and the CodeRabbit current-he…
easonliang28 744f3a3
merge(upstream): take main into the atomic publish unit
8f9cf8b
fix(file-safety): keep the target in place and track the DACL dump on…
14d26dc
fix(file-safety): narrow the DACL dump path before the restore call
df2694b
test(utils): bring the safeWriteJson backup tests onto the copy seman…
db3cc26
fix(file-safety): give each write its own DACL dump and assert the sa…
34b37ae
fix(file-safety): keep the unique DACL dump in the target directory
d3aec7c
test(file-safety): put the failure-path cases inside the describe tha…
8b838f3
fix(file-safety): close the staging symlink hole, surface unconfirmed…
e7843fb
test(file-safety): assert the icacls arguments and the staged file cl…
8e37bc1
fix(file-safety): re-create the staging directory if a concurrent wri…
99fee2c
fix(utils): stage the JSON temp with the target mode instead of the p…
febe20d
fix(utils): keep the staged JSON file owner-writable and surface non-…
e367bdb
fix(utils): key the safeWriteJson lock on the canonical publish target
5ce4613
test(file-safety): cover the staging-directory ownership rejection
964ec83
chore: trigger a fresh review pass at this head
ed72010
fix(file-safety): never discard a committed file, and cover the retry…
1a0430c
test(file-safety): wrap the fsync spy so the durability case type-checks
7470a19
fix(file-safety): keep the write-permission contract and follow dangl…
157946f
fix(file-safety): apply the target mode with fchmodSync on the staged…
41c1de3
test+fix(file-safety): pin the symlink-cycle guard and stop abandonin…
f65e913
test(editor): assert the write-permission guard is handed the absolut…
843176e
fix(file-safety): keep the backup when the DACL restore failed, and c…
4b2193c
fix(file-safety): remove a partially copied backup, and cover the fai…
4d45c87
fix(file-safety): fail closed when a Windows target's DACL cannot be …
aa85a3d
fix(file-safety): propagate a failed lstat in resolvePublishTarget, a…
4f0a85c
fix(file-safety): judge the DACL capture by its artifact on both call…
fa740b0
test(file-safety): make the target-probe propagation tests load-bearing
823a0e7
fix(file-safety): release a staging directory this call created, and …
568f981
test(file-safety): cover the parent-directory create/verify failures …
6df83d8
fix(file-safety): remove a partial backup after a successful publish,…
80de8fb
test(file-safety): cover the zero-byte icacls dump in the win32 DACL …
de893fa
fix(file-safety): classify staging-directory release errors instead o…
110f944
fix(file-safety): do not strand a staging directory when the post-cre…
56dad4d
test(file-safety): exercise safeWriteText against a real filesystem
4468ee7
test(file-safety): cover the win32 DACL restore retry that succeeds o…
65e6dc9
test(file-safety): cover the non-regular DACL dump branch
1a2c41b
fix(file-safety): retry the staging temp unlink instead of swallowing…
9159a87
Merge org main into the atomic-publish branch
30cefbb
style: bring the branch's own files to the repo's prettier output
64923c6
fix(file-safety): stop the icacls tree walk and the restore that cann…
easonLiangWorldedtech 73a842a
fix(file-safety): keep the target's group when publishing over it
easonLiangWorldedtech 1476e58
test(file-safety,editor): name the retained path, catch the dump, ass…
easonLiangWorldedtech e25d642
test(file-safety): assert the exact icacls count in the privilege-mem…
easonLiangWorldedtech 796e412
feat(file-safety): report a lost DACL restore as DaclRestoreError aft…
d10554d
test(file-safety): make the DACL backup and leftover-temp assertions …
b98c07b
fix(file-safety): report a publish that ran with DACL restoration dis…
8c78c20
fix(file-safety): name the staging directory per write
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
src/services/file-safety/__tests__/safeWriteText.integration.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| import fsSync from "node:fs" | ||
| import os from "node:os" | ||
| import path from "node:path" | ||
|
|
||
| import { safeWriteText } from "../safeWriteText" | ||
|
|
||
| /** | ||
| * Every other suite in this directory mocks fs/promises and fs, so nothing there proves the real | ||
| * open/write/fsync/rename sequence produces a file on disk. This suite uses a real temporary | ||
| * directory and no mocks at all: it asserts the outcome (bytes on disk) and the absence of residue | ||
| * (staging directory, temp file, backup). | ||
| */ | ||
| describe("safeWriteText against a real filesystem", () => { | ||
| let dir: string | ||
|
|
||
| beforeEach(() => { | ||
| dir = fsSync.mkdtempSync(path.join(os.tmpdir(), "safe-write-it-")) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| fsSync.rmSync(dir, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| function _leftovers(): string[] { | ||
| return ( | ||
| fsSync | ||
| .readdirSync(dir) | ||
| // The Windows DACL dump is written next to the target and only ever shows up on the | ||
| // windows-latest run, so a filter that misses it lets a leaked dump pass a suite | ||
| // whose claim is the absence of residue. | ||
| .filter(function (name) { | ||
| return ( | ||
| name.includes(".file-safety-staging") || | ||
| name.includes(".new_") || | ||
| name.includes(".bak") || | ||
| name.includes(".acl.tmp") | ||
| ) | ||
| }) | ||
| ) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| it("creates a new file with the requested bytes and leaves no residue", async () => { | ||
| const target = path.join(dir, "brand-new.txt") | ||
|
|
||
| await safeWriteText(target, "first content") | ||
|
|
||
| expect(fsSync.readFileSync(target, "utf8")).toBe("first content") | ||
| expect(_leftovers()).toEqual([]) | ||
| }) | ||
|
|
||
| it("replaces an existing file and leaves no residue", async () => { | ||
| const target = path.join(dir, "existing.txt") | ||
| fsSync.writeFileSync(target, "old") | ||
|
|
||
| await safeWriteText(target, "replacement") | ||
|
|
||
| expect(fsSync.readFileSync(target, "utf8")).toBe("replacement") | ||
| expect(_leftovers()).toEqual([]) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.