Skip to content

fix(openspec): preserve internal markdown dividers in requirement content - #1161

Open
Haiagari wants to merge 1 commit into
Gentleman-Programming:mainfrom
Haiagari:fix/openspec-clean-requirement-content
Open

Haiagari wants to merge 1 commit into
Gentleman-Programming:mainfrom
Haiagari:fix/openspec-clean-requirement-content

Conversation

@Haiagari

@Haiagari Haiagari commented Sep 17, 2026

Copy link
Copy Markdown

Summary

Fixes an issue in cleanRequirementContent where internal markdown dividers/horizontal rules (---) within a requirement block were inadvertently stripped instead of the trailing boundary delimiter.

Problem

In lib/openspec-deltas.ts:31, cleanRequirementContent uses:

return content.trimEnd().replace(/\n\s*---\s*$/m, "").trimEnd();

Because the regular expression uses the multiline flag /m without the global flag /g and is not anchored to the end of the entire string, replace() matches the first line that ends with ---.

If a requirement body contains an internal separator—such as a markdown thematic break, table divider, or YAML code block—replace() removes that internal divider and leaves the trailing --- delimiter at the bottom of the section, corrupting the requirement content.

Solution

  • Anchor the trailing delimiter replacement to the end of the full string:
    return content.trimEnd().replace(/(?:\r?\n\s*---\s*)+$/, "").trimEnd();
    This ensures any internal --- lines remain untouched, and only the trailing delimiter separator at the end of the requirement block is stripped.
  • Added a regression unit test in tests/openspec-deltas.test.ts to verify that internal markdown horizontal rules are preserved while trailing delimiters are stripped.

Testing

  • node --experimental-strip-types --test tests/openspec-deltas.test.ts passes with all 9 tests green.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of trailing Markdown separators in requirement content, including consecutive separators, blank lines, and Windows-style line endings.
    • Internal Markdown horizontal rules are now preserved while only trailing separators are removed.
  • Tests

    • Added coverage for preserving internal separators and removing trailing separators from requirement blocks.

@coderabbitai

coderabbitai Bot commented Sep 17, 2026

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 341d6dfa-8e77-43dd-90b1-5f1349ab5177

📥 Commits

Reviewing files that changed from the base of the PR and between 2b579c8 and fa18d78.

📒 Files selected for processing (2)
  • lib/openspec-deltas.ts
  • tests/openspec-deltas.test.ts

Included review availability: Your plan provides up to 4 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

cleanRequirementContent now removes repeated trailing horizontal-rule separators, including blank-line-separated runs and CRLF line endings. Tests verify that internal horizontal rules remain and subsequent requirement blocks parse separately.

Changes

Requirement content cleanup

Layer / File(s) Summary
Separator cleanup and validation
lib/openspec-deltas.ts, tests/openspec-deltas.test.ts
The cleanup regex removes repeated trailing --- separators. Tests confirm that internal rules remain, trailing separators are removed, and later requirement blocks parse separately.

Priority: ⬇️ Low

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to fa18d

The parser preserves internal dividers and removes trailing separators as intended, with regression coverage and no merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 describes the main change: preserving internal Markdown dividers while fixing trailing delimiter handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

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