Skip to content

Tracking S3: atomic text publish primitive (A4) - safeWriteText #1391

Description

@easonLiangWorldedtech

Tracking issue for the S3 / A4 PR (branch feat/atomic-publish-s3; PR to be opened after review).

Part of the file-write safety series — plan: easonLiangWorldedtech/Zoo-Code#33, epic: #1375. Item: S3 / A4 — Atomic text publish.

Scope

  • New src/services/file-safety/safeWriteText.ts: atomic publish primitive — write to a staging temp file in the target directory, fsync, close, then atomic fs.rename over the target; optional backup flag (keeps a .bak copy of the previous contents, matching safeWriteJson semantics); win32 DACL preservation via icacls (rename fallback if it fails); platform injection for testability.
  • src/utils/safeWriteJson.ts refactored to delegate to it (lock/merge/streaming behavior preserved; existing suite passes unchanged).
  • DiffViewProvider.saveDirectly (the single funnel for all five write tools) switched from raw fs.writeFile to safeWriteText default options.

Acceptance

  • No torn writes: readers observe either the old or the new full content (rename is atomic on both POSIX and NTFS)
  • win32: file ACL preserved after publish (DACL copy); linux: covered via injected platform
  • safeWriteJson suite green without changes (behavior preserved)
  • CI green (ubuntu unit-test gate), 100% codecov patch coverage

Status

  • PR: #1395 open, all CI checks green on head 1a2ade2a5 (ubuntu + windows unit, codecov/patch 100%, CodeRabbit review complete)
  • CodeRabbit: 4/4 findings fixed, confirmed by the bot and replied (2026-08-27); 2 threads remain open only because the platform blocks bot self-resolve (same limitation seen on feat(task): per-task file observation registry (A2, #1375) #1394)
  • Head: 1a2ade2a5 (amended after findings: mock-based cross-platform symlink test, DACL save-before/restore-after, fd try/finally, duplicate spec mock removed)
  • Awaiting maintainer merge

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions