Skip to content

fix(core): canonicalize rebuilt spec EOF - #1528

Open
Marzx13 wants to merge 3 commits into
Fission-AI:mainfrom
Marzx13:fix/spec-eof-newline
Open

fix(core): canonicalize rebuilt spec EOF#1528
Marzx13 wants to merge 3 commits into
Fission-AI:mainfrom
Marzx13:fix/spec-eof-newline

Conversation

@Marzx13

@Marzx13 Marzx13 commented Aug 6, 2026

Copy link
Copy Markdown

Summary

  • Canonicalize rebuilt specs to exactly one final LF.
  • Preserve existing internal-spacing behavior and content after the Requirements section.
  • Add focused regression coverage for LF, CRLF, and later-section content.

Fixes #1527

Testing

  • pnpm exec vitest run test/core/specs-apply.serialization.test.ts — 5 tests passed
  • pnpm run lint
  • pnpm run build
  • pnpm test — 127 test files passed, 1 skipped; 3,789 tests passed, 66 skipped
  • git diff --check

Notes

This changes only terminal whitespace after the complete spec has been rebuilt. Parsing, requirement ordering, and the existing internal Markdown normalization are unchanged.

AI-assisted with OpenAI Codex using a GPT-5 family model. I reviewed the patch and verification results before submission.

Summary by CodeRabbit

  • Bug Fixes

    • Rebuilt specifications now use consistent spacing and end with exactly one trailing newline.
    • Prevented extra blank lines after the Requirements section.
    • Preserved meaningful paragraph breaks and content in sections that follow Requirements.
  • Tests

    • Added coverage for missing, LF, and CRLF newline formats to ensure consistent output.

@Marzx13
Marzx13 requested a review from a team as a code owner August 6, 2026 14:26
@Marzx13
Marzx13 requested review from clay-good and removed request for a team August 6, 2026 14:26
@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The spec rebuild now collapses excessive blank lines, trims trailing whitespace, and adds exactly one terminal newline. End-to-end tests cover missing, LF, and CRLF inputs while preserving internal paragraph breaks and sections after Requirements.

Changes

Spec serialization

Layer / File(s) Summary
Normalize rebuilt spec endings
src/core/specs-apply.ts, test/core/specs-apply.serialization.test.ts, .changeset/canonicalize-spec-eof.md
Rebuilt specifications now end with exactly one newline. Tests cover newline normalization, internal paragraph breaks, content after Requirements, and temporary file cleanup. The changeset documents the canonicalization behavior.

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

Possibly related PRs

  • Fission-AI/OpenSpec#1376: Both PRs modify spec rebuilding logic in src/core/specs-apply.ts, but address different behaviors.
  • Fission-AI/OpenSpec#1386: Both PRs modify buildUpdatedSpec, but this PR addresses EOF newline canonicalization.
  • Fission-AI/OpenSpec#1437: Both PRs modify spec rebuilding behavior in src/core/specs-apply.ts, but this PR focuses on trailing newlines.

Suggested reviewers: clay-good

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The implementation and tests satisfy issue #1527 by enforcing one final LF while preserving internal spacing and later sections.
Out of Scope Changes check ✅ Passed The changes are limited to EOF canonicalization, regression tests, and the related changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the core change: canonicalizing the end-of-file format for rebuilt specs.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/core/specs-apply.ts`:
- Around line 551-552: Remove the global newline-collapsing replace from the
full rebuilt specification flow, keeping only trimEnd() plus a single trailing
newline. Add coverage verifying an internal \n\n\n sequence, including within
authored Markdown content, remains unchanged.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: f43e2b65-6a61-4357-92d9-372f43d02aef

📥 Commits

Reviewing files that changed from the base of the PR and between d578896 and 40fea72.

📒 Files selected for processing (2)
  • src/core/specs-apply.ts
  • test/core/specs-apply.serialization.test.ts

Comment thread src/core/specs-apply.ts
alfred-openspec
alfred-openspec previously approved these changes Aug 6, 2026

@alfred-openspec alfred-openspec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified exact head 40fea72. A frozen install, build, lint, 249 focused archive/spec tests, and the full 3,789-test suite pass locally. The final trim runs only after reconstruction, preserves internal spacing and later sections, normalizes LF/CRLF inputs to one final LF, and closes #1527 cleanly. Approved.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@clay-good

Copy link
Copy Markdown
Collaborator

Merge-prep pass (maintainer): pushed one commit adding the missing changeset (.changeset/canonicalize-spec-eof.md, patch bump) so this user-facing fix lands in the changelog and version bump. No production code changed.

Verification on this head:

  • pnpm build + full vitest run: the fix and its 5 new serialization tests pass; the specs-apply + archive suites (232 tests) are green. The two unrelated failures in config-profile/artifact-workflow are pre-existing on main (this PR touches only specs-apply.ts).
  • The three red CI checks (Audit, macos-bash, Test) were transient GitHub Actions infra outages ("Service Unavailable"/"Internal Server Error" resolving action downloads), not real failures — a re-run should clear them.

Re: the CodeRabbit comment to delete .replace(/\n{3,}/g, '\n\n') — declining. That collapse is pre-existing (introduced in #450), other suites assert it (legacy-cleanup, marker-updates both check not.toMatch(/\n{3,}/)), and collapsing 3+ blank lines to 2 is lossless for Markdown rendering. The load-bearing change here is the added .trimEnd() + '\n', which is correct and minimal.

@alfred-openspec alfred-openspec left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-verified exact head 1b62d87. The follow-up adds only the missing patch changeset, and its description matches the tested one-final-LF behavior without overstating scope. The underlying code and regression coverage remain unchanged from the previously approved patch.

@clay-good clay-good closed this Aug 7, 2026
@clay-good clay-good reopened this Aug 7, 2026
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.

archive: rebuilt specs end with an extra blank line at EOF

3 participants