Skip to content

feat(file-safety): atomic text publish primitive (S3 v2-1, epic #1375) - #43

Open
easonLiangWorldedtech wants to merge 1 commit into
mainfrom
feat/fws-v2-1-atomic-publish-core
Open

feat(file-safety): atomic text publish primitive (S3 v2-1, epic #1375)#43
easonLiangWorldedtech wants to merge 1 commit into
mainfrom
feat/fws-v2-1-atomic-publish-core

Conversation

@easonLiangWorldedtech

Copy link
Copy Markdown
Owner

Summary

First unit of the v2 split of the file-write-safety stack (epic Zoo-Code-Org#1375, A4). Recreates the reviewed content of upstream PR Zoo-Code-Org#1395 (S3: atomic text publish) on current main as a standalone unit, replacing the stacked PR chain that will be closed as superseded.

Changes

  • src/services/file-safety/safeWriteText.ts (new, 304 lines): atomic text publish primitive
    • resolvePublishTarget: realpath resolution for the target; ENOENT falls back to the given path, any other error propagates
    • safeWriteText(filePath, content, options):
      • ensures the parent directory exists
      • writes the content to a staging temp file (short-write loop) preserving the existing target's mode (0o644 for a new file), fsyncs the file, then commits atomically via rename — no torn writes on crash
      • win32: best-effort DACL save before the commit rename and DACL restore onto the parent directory after it (falls back to a plain rename when the save fails; the dump file is always cleaned up)
      • backup: true: renames the previous target to a backup before the commit and deletes it on success; on commit failure the backup is renamed back (rollback) and the temp file is discarded
      • tempPath: caller-supplied pre-written temp file (used by safeWriteJson in a later unit); the staging dir is not created and the temp file is not unlinked (caller's concern)
      • platform / execFileRunner: test seams for the win32 DACL path
  • src/services/file-safety/__tests__/safeWriteText.spec.ts (new, 672 lines): 31 unit tests — happy path/cleanup, fsync ordering, symlink resolution, backup/rollback semantics (ENOENT swallowing, error propagation), win32 DACL handling (save/restore args, fallback on failure, dump cleanup, default-platform path), pre-written tempPath behaviour (fchmod to target mode, 0o444 open ordering, no POSIX directory fsync), and durability regressions (short writes, POSIX directory fsync, realpath/access error propagation)

Tests

  • Targeted vitest (src/ workspace): 31/31 passed
  • eslint --prune-suppressions --max-warnings=0 on both files: clean, suppression counts unchanged
  • pnpm check-types: passed (11/11 tasks)
  • Stryker mutation-diff gate (scripts/stryker-diff.mjs ci, changed lines only): 115 mutants — 109 killed + 6 timeouts; 0 surviving, 0 NoCoverage
  • Line budget: 976 insertions / 0 deletions standalone against origin/main (measured via git merge-tree --write-tree); within the 1000 hard cap. A single self-contained new module plus its spec — splitting further would fragment the primitive from its tests.

Provenance

…ode-Org#1375)

Recreates upstream PR Zoo-Code-Org#1395 (A4) on current main as the first unit of the v2 split.

Adds src/services/file-safety/safeWriteText.ts: temp-file write + atomic commit
rename with optional backup, win32 DACL preservation/restore, and pre-commit
verification hook wiring (A4a guarded-write surface). Includes the unit spec
(safeWriteText.spec.ts). Content is byte-identical to the reviewed Zoo-Code-Org#1395 tip
(tree 0a6f4ac772, commit a37dd24).
@github-actions

github-actions Bot commented Sep 5, 2026

Copy link
Copy Markdown

Review status

Thanks for contributing. This comment tracks the review sequence and the next action.

Current step: Required CI passed. Waiting for automated review of the latest commit.

If automated review does not start, a maintainer must restart it.

Review-state labels are managed by this workflow; do not edit them manually.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-coderabbit Waiting for CodeRabbit to approve the latest commit coderabbit-review-active Required CI passed; CodeRabbit review is active

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants