Repository navigation
feat(task): observation registry with read completeness (U3, #1375) #1912
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
75
commits into
Zoo-Code-Org:main
Choose a base branch
from
easonLiangWorldedtech:fws/u3-observation-completeness
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.
Open
Changes from all commits
Commits
Show all changes
75 commits
Select commit
Hold shift + click to select a range
d5f8a79
split unit U1 of PR 1833 (issue 1375)
aa0cdab
fix(file-safety): close the pre-merge findings on the publish primiti…
c4120b0
fix(file-safety): propagate a non-ENOENT lstat failure in resolvePubl…
97b599d
fix(file-safety): keep the rollback pair typed and the mock stand-ins…
435be8b
rebuild unit u2 on the fixed chain
625a976
chore(lint): prune the safeWriteJson suppression this unit earns
4e2de13
rebuild unit u3 on the fixed chain
60376ca
fix(task): declare the observation registry on Task in this unit
58a1f1c
test(task): pin the clock and restore real timers in the observation …
9e40ad3
test(utils): make the rollback-failure test name match what it asserts
1476213
fix(file-safety): inherit U1 committed-guard and exact rmdir assertion
761dec8
fix(file-safety): keep the publish error message in RollbackFailureError
e65efb0
test(file-safety): assert the exact staging directory removed after a…
5bfb81d
test: re-trigger required checks - the queued runs were cancelled by …
0d0ee7d
fix(file-safety): give the Windows DACL dump a per-write name
9c111ce
test(utils): assert the RollbackFailureError message, not only its fi…
d8b34b8
fix(file-safety): keep the target present by backing it up with a dur…
631bfd8
fix(file-safety): remove a partial backup when the backup copy or its…
10d2d97
fix(file-safety): report a failed DACL restore, and cover the primiti…
38f8a59
test(file-safety): drop the duplicated failed-commit case and cover t…
96b6024
fix(file-safety): remove the backup copy after a post-commit failure …
ee17f99
fix(file-safety): make the backup copy writable before fsyncing it
0574ad4
fix(file-safety): create the backup privately before its content exists
1b6ce40
feat(utils): let a caller confine a write to a directory
75fe4a4
fix(file-safety): do not read a failed target lstat as a missing target
ea5b3ce
fix(file-safety): compare staging and target identity with bigint stats
f74cac9
test(file-safety): pin the bigint options in the staging-identity tests
3486dc7
fix(file-safety): report a Windows replacement whose DACL was not pre…
fac2c7e
fix(file-safety): keep DACL warning delivery from failing the save
5f07a25
fix(utils): check confinement before taking the advisory lock
783d1dc
fix(file-safety): handle async warning sinks and confine before mkdir
256091d
fix(mcp): confine project MCP writes to the workspace root
ff6e864
test(utils): pin the fail-closed scope canonicalization in safeWriteJson
dd142c6
fix(file-safety): report a leftover backup copy instead of discarding…
799962b
fix(file-safety): report the exact orphan paths when post-failure cle…
d03ea09
Merge branch 'main' into fws/u3-observation-completeness
easonLiangWorldedtech 0b76199
fix(file-safety): report a staging directory that cleanup could not r…
easonLiangWorldedtech 4605003
fix(file-safety): report a DACL dump that survives cleanup and guaran…
easonLiangWorldedtech 93edc9c
style: satisfy the repository prettier gate on the files this PR changes
easonLiangWorldedtech a6803b2
fix(file-safety): stand the post-commit cleanup down and stop reporti…
easonLiangWorldedtech d16872b
docs(file-safety): port the confineTo claim narrowing to this unit
cc84906
test(file-safety): pin the exact staging dir in the ENOENT cleanup test
032678d
fix(safe-write-json): keep the published target across a post-commit …
easonLiangWorldedtech 2525fc2
chore(merge): refresh onto main 4f1dee18e
easonLiangWorldedtech b890914
style(tools): drop imports unused after the main refresh and re-add s…
easonLiangWorldedtech 6aed302
test(file-safety): pin the durability wrapper's cause and the exact s…
easonLiangWorldedtech 8e919cb
test(file-safety): keep the durability probe platform-portable
easonLiangWorldedtech 6953d6b
test(file-safety): inject the durability failure without fabricating …
easonLiangWorldedtech 41832ac
fix(file-safety): fall back to the link walk only on a dangling link
easonLiangWorldedtech 8e07a5f
test(safety): drop the dead lstat mock in the EACCES lock-key test
easonLiangWorldedtech 12ae581
fix(safety): pin the caller-staged tempPath contract
easonLiangWorldedtech 2cb8bf5
test(safety): pin the identity guard with a convention-conforming alias
easonLiangWorldedtech 1ea16d9
test(safety): assert cleanup after the hard-link rejection
easonLiangWorldedtech b41213f
fix(file-safety): pin the authorized ancestry before the commit rename
easonLiangWorldedtech 9f142dc
fix(safety, task): cover the directory-failure paths and release the …
easonLiangWorldedtech 1e3a0af
style: apply prettier formatting to the disposal and directory-failur…
easonLiangWorldedtech eed4d05
test(safety): cover the backup chmod failure boundary
easonLiangWorldedtech f89719b
test(safety): pin the backup chmod cleanup path
easonLiangWorldedtech ae1375a
Merge remote-tracking branch 'upstream/main' into HEAD
easonLiangWorldedtech 3b51119
fix(mcp): fail closed on project writes without a workspace root
easonLiangWorldedtech ceca082
test(mcp): type the empty workspace-root mock as an empty string
easonLiangWorldedtech 7dc6302
Merge upstream/main into fws/u3-observation-completeness
192e522
fix(merge): restore the upstream hunks dropped by the main merge
easonLiangWorldedtech 9de3580
fix(file-safety): fail closed when an ancestor identity read fails
easonLiangWorldedtech 9713c4a
fix(file-safety): fail closed when a pinned ancestor disappears durin…
easonLiangWorldedtech 5da3231
Merge upstream main 73931fe8be25 into fws/u3-observation-completeness
easonLiangWorldedtech ddcb151
#1912 graft: make the lane trio the safeWriteText base and graft u3's…
easonLiangWorldedtech 54bb628
#1912 formatting: prettier --write on the two merged test files
easonLiangWorldedtech 22a4ba7
#1912 interruption injection compared spelling, not identity: the ali…
easonLiangWorldedtech 085fbf8
#1912 knip: the publish primitive has no production consumer yet, so …
easonLiangWorldedtech 7cd0106
#1912 review rows: resolve-or-refuse lock key, re-verify at the commit
easonLiangWorldedtech d3dd922
#1912 review rows: the midwrite ancestor-swap row restored its fixtur…
easonLiangWorldedtech 402e25d
#1912 review rows: the JSON fixture now speaks the spelling the write…
easonLiangWorldedtech 9d420ad
test(safeWriteJson): pin the mode-copy direction with a wider target
easonLiangWorldedtech 90f56d2
Merge upstream main 53cb5b5e7c80 into fws/u3-observation-completeness…
easonLiangWorldedtech 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
176 changes: 176 additions & 0 deletions
176
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,176 @@ | ||
| import * as fs from "fs/promises" | ||
| import * as os from "os" | ||
| import * as path from "path" | ||
|
|
||
| import { AncestorReplacedError, safeWriteText, TargetMovedError, type AncestorIdentity } from "../safeWriteText" | ||
|
|
||
| // No fs mocks in this file: the point is to assert what a real filesystem ends up | ||
| // holding after a publish attempt, which the mocked spec cannot show. The failure is | ||
| // provoked with real filesystem semantics rather than with a stubbed call. | ||
| describe("safeWriteText against a real filesystem", () => { | ||
| let dir: string | ||
|
|
||
| beforeEach(async () => { | ||
| dir = await fs.mkdtemp(path.join(os.tmpdir(), "safe-write-text-int-")) | ||
| }) | ||
|
|
||
| afterEach(async () => { | ||
| await fs.rm(dir, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| it("publishes the new bytes and leaves no staging or backup residue", async () => { | ||
| const targetPath = path.join(dir, "target.txt") | ||
| await fs.writeFile(targetPath, "old bytes") | ||
|
|
||
| // No platform override: the real platform's own durability and ACL steps run. | ||
| // A failed icacls restore in a throwaway temp directory is reported, not thrown, | ||
| // so the publish still lands. | ||
| await safeWriteText(targetPath, "new bytes", { backup: true }) | ||
|
|
||
| expect(await fs.readFile(targetPath, "utf8")).toBe("new bytes") | ||
| expect(await fs.readdir(dir)).toEqual(["target.txt"]) | ||
| }) | ||
|
|
||
| it("leaves the target bytes untouched when the backup copy of a directory target fails", async () => { | ||
| // A directory target makes the backup COPY fail first (a directory cannot be | ||
| // copied), so this covers the backup step, not the commit rename: the inner | ||
| // catch unlinks the partial backup and rethrows before the rename runs. | ||
| const targetPath = path.join(dir, "target-dir") | ||
| await fs.mkdir(targetPath) | ||
| const inside = path.join(targetPath, "payload.txt") | ||
| await fs.writeFile(inside, "original bytes") | ||
|
|
||
| await expect(safeWriteText(targetPath, "new data", { backup: true })).rejects.toThrow() | ||
|
|
||
| // The directory and its content are exactly as they were, and no backup copy | ||
| // or staging directory was left behind next to them. | ||
| expect(await fs.readFile(inside, "utf8")).toBe("original bytes") | ||
| expect(await fs.readdir(dir)).toEqual(["target-dir"]) | ||
| }) | ||
|
|
||
| it("leaves the target untouched when the commit rename itself cannot replace it", async () => { | ||
| // backup:false makes the commit rename the first operation that touches the | ||
| // target: a regular file cannot be renamed over a directory, so the failure | ||
| // under test is the commit, and the cleanup is the temp unlink plus the | ||
| // staging-directory removal. | ||
| const targetPath = path.join(dir, "target-dir") | ||
| await fs.mkdir(targetPath) | ||
| const inside = path.join(targetPath, "payload.txt") | ||
| await fs.writeFile(inside, "original bytes") | ||
|
|
||
| await expect(safeWriteText(targetPath, "new data", { backup: false })).rejects.toThrow() | ||
|
|
||
| // The directory and its content are exactly as they were, and neither the | ||
| // staged temp nor the staging directory was left behind. | ||
| expect(await fs.readFile(inside, "utf8")).toBe("original bytes") | ||
| expect(await fs.readdir(dir)).toEqual(["target-dir"]) | ||
| }) | ||
|
|
||
| // ── authorized-path pins: what the caller decided is what gets published ── | ||
|
|
||
| it("publishes when the pinned resolved path and ancestor identities still match", async () => { | ||
| const scope = path.join(dir, "scope") | ||
| const nested = path.join(scope, "nested") | ||
| await fs.mkdir(nested, { recursive: true }) | ||
| const targetPath = path.join(nested, "target.txt") | ||
| await fs.writeFile(targetPath, "old bytes") | ||
|
|
||
| // Exactly what safeWriteJson records: the resolved target plus the identity of every | ||
| // directory it walked, as canonical paths. | ||
| const identities: AncestorIdentity[] = [] | ||
| for (const candidate of [await fs.realpath(scope), await fs.realpath(nested)]) { | ||
| const stat = await fs.stat(candidate, { bigint: true }) | ||
| identities.push({ dir: candidate, dev: stat.dev, ino: stat.ino }) | ||
| } | ||
|
|
||
| await safeWriteText(targetPath, "new bytes", { | ||
| expectedResolvedPath: await fs.realpath(targetPath), | ||
| expectedAncestorIdentities: identities, | ||
| }) | ||
|
|
||
| // The pins do not turn an unchanged chain into a rejection: the publish lands and | ||
| // leaves no staging, backup or temporary residue beside it. | ||
| expect(await fs.readFile(targetPath, "utf8")).toBe("new bytes") | ||
| expect(await fs.readdir(nested)).toEqual(["target.txt"]) | ||
| }) | ||
|
|
||
| it("refuses to publish when the target no longer resolves to the authorized path", async () => { | ||
| const targetPath = path.join(dir, "target.txt") | ||
| await fs.writeFile(targetPath, "old bytes") | ||
| const authorized = path.join(dir, "other.txt") | ||
|
|
||
| // The caller authorized a different resolved path: publishing here would act on a | ||
| // decision that was never made about this file. | ||
| const error = await safeWriteText(targetPath, "new bytes", { expectedResolvedPath: authorized }).then( | ||
| () => undefined, | ||
| (reason: unknown) => reason, | ||
| ) | ||
|
|
||
| expect(error).toBeInstanceOf(TargetMovedError) | ||
| expect((error as TargetMovedError).authorizedPath).toBe(authorized) | ||
| expect((error as TargetMovedError).resolvedPath).toBe(await fs.realpath(targetPath)) | ||
| // Nothing was staged or published, and the existing bytes are untouched. | ||
| expect(await fs.readFile(targetPath, "utf8")).toBe("old bytes") | ||
| expect(await fs.readdir(dir)).toEqual(["target.txt"]) | ||
| }) | ||
|
|
||
| it("refuses the commit when an authorized ancestor directory was replaced", async () => { | ||
| const ancestor = path.join(dir, "settings") | ||
| await fs.mkdir(ancestor) | ||
| const targetPath = path.join(ancestor, "target.txt") | ||
| await fs.writeFile(targetPath, "old bytes") | ||
| // The canonical name and identity the caller walked, before the swap. | ||
| const authorizedDir = await fs.realpath(ancestor) | ||
| const authorized = await fs.stat(authorizedDir, { bigint: true }) | ||
|
|
||
| // Replace the directory between the caller's decision and the commit. The name still | ||
| // exists and still resolves to itself - only the directory under it is a different one. | ||
| const replaced = ancestor + "-replaced" | ||
| await fs.rename(ancestor, replaced) | ||
| await fs.mkdir(ancestor) | ||
|
|
||
| const error = await safeWriteText(targetPath, "new bytes", { | ||
| expectedAncestorIdentities: [{ dir: authorizedDir, dev: authorized.dev, ino: authorized.ino }], | ||
| }).then( | ||
| () => undefined, | ||
| (reason: unknown) => reason, | ||
| ) | ||
|
|
||
| // Fail closed with the replaced directory named, not with a cleanup or staging error: | ||
| // the staged temp and this write's staging directory are removed before it is thrown. | ||
| expect(error).toBeInstanceOf(AncestorReplacedError) | ||
| expect((error as AncestorReplacedError).directory).toBe(authorizedDir) | ||
| expect((error as AncestorReplacedError).message).toContain("no longer the directory that was authorized") | ||
| // Nothing was published into the replacement directory, and nothing leaked into it. | ||
| expect(await fs.readdir(ancestor)).toEqual([]) | ||
| // The directory that was moved aside still holds its pre-write bytes. | ||
| expect(await fs.readFile(path.join(replaced, "target.txt"), "utf8")).toBe("old bytes") | ||
| }) | ||
|
|
||
| it("refuses the commit when an authorized ancestor is moved and its name links to the moved copy", async () => { | ||
| const ancestor = path.join(dir, "linked") | ||
| await fs.mkdir(ancestor) | ||
| const targetPath = path.join(ancestor, "target.txt") | ||
| const authorizedDir = await fs.realpath(ancestor) | ||
| const authorized = await fs.stat(authorizedDir, { bigint: true }) | ||
|
|
||
| // A move preserves (dev, ino), and the link left at the old name makes stat() follow it, | ||
| // so the identity check alone matches. The name no longer resolves to the location the | ||
| // caller walked, and the commit below takes path strings - it would follow the link. | ||
| const moved = ancestor + "-moved" | ||
| await fs.rename(ancestor, moved) | ||
| await fs.symlink(moved, ancestor, process.platform === "win32" ? "junction" : "dir") | ||
|
|
||
| const error = await safeWriteText(targetPath, "new bytes", { | ||
| expectedAncestorIdentities: [{ dir: authorizedDir, dev: authorized.dev, ino: authorized.ino }], | ||
| }).then( | ||
| () => undefined, | ||
| (reason: unknown) => reason, | ||
| ) | ||
|
|
||
| expect(error).toBeInstanceOf(AncestorReplacedError) | ||
| expect((error as AncestorReplacedError).message).toContain("no longer resolves to the authorized location") | ||
| // Nothing was published through the link, and the staged temp was removed from it. | ||
| expect(await fs.readdir(moved)).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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the registry test out of the API handler group.
This test checks registry cleanup, but its enclosing
describe("API handler disposal")names a different subject. Move it to a registry or Task disposal group so targeted runs and failure reports identify the correct behavior. (raw.githubusercontent.com)As per path instructions: “Check that describe block names match the actual subjects of the tests they contain.”
Source: Path instructions