Skip to content

fix(studio): protect external source changes - #9

Merged
aetosdios27 merged 1 commit into
mainfrom
aetosdios/aet-15-verify-studio-atomic-save-newline-preservation-and-conflict
Jul 20, 2026
Merged

aetosdios27 merged 1 commit into
mainfrom
aetosdios/aet-15-verify-studio-atomic-save-newline-preservation-and-conflict

Conversation

@aetosdios27

@aetosdios27 aetosdios27 commented Jul 20, 2026 •

Copy link
Copy Markdown
Owner

Linear

Fixes AET-15

Summary

  • revalidate the source file immediately before Studio saves
  • preserve the unsaved draft when the source is deleted or renamed
  • reload explicitly from current disk content and retain LF/CRLF style
  • cover the external-edit conflict through the Studio browser flow

Verification

  • bunx vitest run packages/cli/src/studio.test.ts (13 tests)
  • bunx vitest run packages/cli/src (43 tests)
  • bun run --cwd packages/cli build
  • bun run typecheck
  • bun run test:studio:browser -- --project=chromium
  • bunx changeset status
  • git diff --check
  • Added a Changeset for the consumer-visible CLI fix
  • Documentation is unchanged because the existing explicit-save contract remains accurate
  • Existing coverage was not weakened or skipped

Visual evidence

Not applicable — this changes filesystem safety behavior without changing Studio presentation.

Summary by CodeRabbit

  • Bug Fixes
    • Studio now detects external file changes immediately before saving to prevent overwriting newer edits.
    • Unsaved drafts are preserved when the source file is deleted or renamed.
    • Reloading from disk now reliably clears conflicts and updates the editor and preview.
    • Saved files preserve their existing LF or CRLF line-ending format.

@linear-code

linear-code Bot commented Jul 20, 2026

Copy link
Copy Markdown

AET-15

@aetosdios27
aetosdios27 merged commit c8d3dec into main Jul 20, 2026
6 checks passed
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 152347c2-7bb2-4014-bfc6-608d422a29c4

📥 Commits

Reviewing files that changed from the base of the PR and between a5b3613 and 822eb44.

📒 Files selected for processing (4)
  • .changeset/safe-studios-save.md
  • packages/cli/src/studio.test.ts
  • packages/cli/src/studio.ts
  • tests/studio-browser/studio.spec.ts

📝 Walkthrough

Walkthrough

Scribe Studio now revalidates disk content before saving or discarding, preserves drafts when sources are missing, refreshes state from disk, tracks line endings, and adds integration and browser coverage.

Changes

Studio conflict handling

Layer / File(s) Summary
State and diagnostic helpers
packages/cli/src/studio.ts
Line-ending detection and missing-source diagnostics are centralized and applied during initialization, file watching, and source deletion.
Conflict-safe save and discard operations
packages/cli/src/studio.ts
Save and discard re-read the source, return 409 conflicts for stale or missing files, preserve drafts when needed, and refresh disk, preview, conflict, dirty, diagnostic, and line-ending state.
Integration coverage and release metadata
packages/cli/src/studio.test.ts, tests/studio-browser/studio.spec.ts, .changeset/safe-studios-save.md
Tests cover external edits, deletion, discard and reload behavior, conflict responses, CRLF preservation, and browser-level Studio flows; a patch changeset documents the update.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant StudioUI
  participant StudioAPI
  participant DiskSource
  StudioUI->>StudioAPI: Save draft
  StudioAPI->>DiskSource: Re-read current source
  DiskSource-->>StudioAPI: Current contents or missing-file error
  StudioAPI-->>StudioUI: Save result or 409 conflict
  StudioUI->>StudioAPI: Reload from disk
  StudioAPI->>DiskSource: Read source
  DiskSource-->>StudioAPI: Source contents
  StudioAPI-->>StudioUI: Updated editor state
Loading
✨ 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 aetosdios/aet-15-verify-studio-atomic-save-newline-preservation-and-conflict

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.

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.

1 participant