Skip to content

Ensure atomic file replacement in --fix mode - #40

Merged
j9t merged 1 commit into
mainfrom
fix/atomic-file-replacement
Sep 8, 2026
Merged

j9t merged 1 commit into
mainfrom
fix/atomic-file-replacement

Conversation

@j9t

@j9t j9t commented Sep 8, 2026

Copy link
Copy Markdown
Owner

Resolves #27

Summary by CodeRabbit

  • Bug Fixes

    • --fix now atomically replaces CSS files, preventing interrupted writes from leaving files empty.
    • Original file permissions are preserved.
    • Symlink inputs continue updating their destination files without replacing the links.
  • Documentation

    • Clarified that --fix atomically replaces files, while STDIN input still outputs consolidated CSS to STDOUT.
  • Chores

    • Updated the release version to 1.13.2.

Implemented an atomic replacement mechanism for files modified with `--fix`, preventing potential data loss during interrupted operations. Added tests to verify file mode preservation and symlink handling, and updated documentation and changelog to reflect the changes.

(This commit message was AI-generated.)

Signed-off-by: Jens Oliver Meiert <jens@meiert.com>
@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 9e8a83af-a2d8-4068-a81a-d1e3bbbc0705

📥 Commits

Reviewing files that changed from the base of the PR and between 2af2a08 and 95f994c.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • CHANGELOG.md
  • README.md
  • package.json
  • src/cli/file-pass.js
  • src/cli/options.js
  • test/cli.test.js

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


Walkthrough

The --fix path now stages output beside each target and atomically renames it into place. It preserves file modes, updates symlink destinations, cleans up temporary directories, and documents the behavior in version 1.13.2.

Changes

Atomic --fix writes

Layer / File(s) Summary
Atomic replacement implementation
src/cli/file-pass.js
computeFixPass now stages output, preserves the target mode, atomically renames the staged file, and removes temporary files after completion or failure.
File replacement validation
test/cli.test.js
Tests verify mode preservation, temporary-file cleanup, and symlink target updates.
CLI contract and release metadata
src/cli/options.js, README.md, CHANGELOG.md, package.json
Help text and documentation describe atomic replacement. The package version is updated to 1.13.2.

Priority: ➖ Normal — Schedule the atomic `--fix` update because it prevents interrupted writes from leaving CSS files empty while preserving modes and symlink behavior.

Estimated code review effort: 2 (Simple) | ~15 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 95f99

The --fix path now replaces files through a staged atomic rename while preserving modes and updating symlink destinations. No actionable merge-blocking risk remains in the supplied change context.

Sequence Diagram(s)

sequenceDiagram
  participant computeFixPass
  participant replaceFileAtomically
  participant FileSystem
  computeFixPass->>replaceFileAtomically: pass target label and output
  replaceFileAtomically->>FileSystem: resolve target and read mode
  replaceFileAtomically->>FileSystem: create staged output beside target
  replaceFileAtomically->>FileSystem: apply mode and rename staged file
  FileSystem-->>computeFixPass: complete atomic replacement
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Linked Issues check ❓ Inconclusive The changes address issue #27 by staging output beside the target, atomically renaming it, preserving file modes, retaining symlink targets, cleaning up staging data, and adding focused tests. Windows… Provide evidence from the Windows CI leg or add platform-specific coverage that verifies rename behavior and cleanup on Windows.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: atomic file replacement in --fix mode.
Out of Scope Changes check ✅ Passed The file changes support the linked objective. The implementation, tests, documentation, changelog entry, and version update are related to atomic --fix replacement. No unrelated code changes are evid…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 3 files. (3 skipped: 3 …
Full details: Linked Issues check

Explanation

The changes address issue #27 by staging output beside the target, atomically renaming it, preserving file modes, retaining symlink targets, cleaning up staging data, and adding focused tests. Windows-specific behavior cannot be fully verified because the symlink test is skipped on Windows.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/atomic-file-replacement

Warning

Tools execution failed with the following error:

Failed to run tools: 13 INTERNAL: Received RST_STREAM with code 2 (Internal server error)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@j9t

j9t commented Sep 8, 2026

Copy link
Copy Markdown
Owner Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@j9t
j9t merged commit 35acd3d into main Sep 8, 2026
6 checks passed
@j9t
j9t deleted the fix/atomic-file-replacement branch September 8, 2026 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent that --fix can leave a file empty if the run is interrupted mid-write

1 participant