fix: make requirement header parsing case-insensitive#1031
Conversation
📝 WalkthroughWalkthroughRequirement header detection was made case-insensitive across parsing and validation paths, so Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/core/parsers/requirement-blocks.ts`:
- Line 61: The loop boundary uses a stricter hardcoded regex
/^###\s+Requirement:/ (in the cursor/sectionBodyLines loops) which mismatches
the shared header regex /^###\s*Requirement:/ used elsewhere; update those loop
conditions to reuse the single shared predicate/regex (the existing shared
requirement header check used elsewhere in this module) instead of the hardcoded
pattern so headers like "###Requirement:" are treated consistently—replace the
inline /^###\s+Requirement:/ checks in the cursor loops with the shared
isRequirementHeader/isRequirementRegex symbol (or the canonical
/^###\s*Requirement:/) so all occurrences use the same predicate.
- Line 19: The REQUIREMENT_HEADER_REGEX in this file is currently
case-insensitive which permits headers like "### requirement:" but downstream
validators (specs-apply.ts and spec-structure.ts) expect case-sensitive headers
and thus fail; update REQUIREMENT_HEADER_REGEX to be case-sensitive (remove the
'i' flag) so it only matches the exact "Requirement" casing and stays consistent
with the header regexes used by validate/parse functions in spec-structure.ts
and specs-apply.ts, or alternatively make those other header regexes
case-insensitive to match this one—pick one consistent approach and apply it
across REQUIREMENT_HEADER_REGEX and the corresponding header regexes in
spec-structure.ts/specs-apply.ts so parsing and validation use the same casing
rules.
🪄 Autofix (Beta)
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
Run ID: bae62526-8e2d-4594-bb3b-e197b04c2dd1
📒 Files selected for processing (1)
src/core/parsers/requirement-blocks.ts
There was a problem hiding this comment.
♻️ Duplicate comments (1)
src/core/parsers/requirement-blocks.ts (1)
19-45:⚠️ Potential issue | 🟠 Major | ⚡ Quick winKeep the requirement header grammar aligned across the parser.
This regex now accepts
###Requirement:as well as mixed-case headers, but the rest of the requirement parsing/validation path still expects the spaced form. That means this file can accept blocks that downstream code will still reject, and the new no-space regression cases lock in that wider contract.Suggested fix
-const REQUIREMENT_HEADER_REGEX = /^###\s*Requirement:\s*(.+)\s*$/i; +const REQUIREMENT_HEADER_REGEX = /^###\s+Requirement:\s*(.+)\s*$/i;If you do want to support
###Requirement:, the remaining requirement regexes need the same treatment too.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/core/parsers/requirement-blocks.ts` around lines 19 - 45, The REQUIREMENT_HEADER_REGEX was loosened to accept headers like "###Requirement:" (no space) which misaligns with downstream parsing; restore strict grammar by changing REQUIREMENT_HEADER_REGEX in extractRequirementsSection to require a space after '###' (e.g. use a pattern requiring \s+ after '###') or, if you intentionally want to accept the no-space form, update all other requirement-related regexes/parsers in this module to match the same relaxed grammar so parsing/validation remain consistent (update any other requirement header/validation regexes to the same pattern).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@src/core/parsers/requirement-blocks.ts`:
- Around line 19-45: The REQUIREMENT_HEADER_REGEX was loosened to accept headers
like "###Requirement:" (no space) which misaligns with downstream parsing;
restore strict grammar by changing REQUIREMENT_HEADER_REGEX in
extractRequirementsSection to require a space after '###' (e.g. use a pattern
requiring \s+ after '###') or, if you intentionally want to accept the no-space
form, update all other requirement-related regexes/parsers in this module to
match the same relaxed grammar so parsing/validation remain consistent (update
any other requirement header/validation regexes to the same pattern).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: f7223acd-2757-4d84-be90-f6636917ab7d
📒 Files selected for processing (4)
src/core/parsers/requirement-blocks.tssrc/core/parsers/spec-structure.tssrc/core/specs-apply.tstest/core/parsers/requirement-blocks.test.ts
✅ Files skipped from review due to trivial changes (2)
- src/core/specs-apply.ts
- src/core/parsers/spec-structure.ts
|
@davseby We've moved away from header-based archiving. What version are you on? |
|
@TabishB I tried it with 1.3.1 and with the latest main commit. Error that I receive using archive: Example |
|
I updated the description to better reflect the issue 🙏🏿 |
* fix: make requirement header parsing case-insensitive * fix: add tests and cover the rest of requirement header places
Problem
REQUIREMENT_HEADER_REGEXand the inline seek/skip regexes use case-sensitive matching for### Requirement:, while the## Requirementssection header is found case-insensitively (/i).A user who writes
### requirement: Foogets a confusing validation error during archive — "no requirement entries parsed" — with no indication that header casing is the cause.Fix
Add the
iflag toREQUIREMENT_HEADER_REGEXand all four inline regexes inrequirement-blocks.tsthat seek or skip### Requirement:headers.