fix(validator): hint main spec header-only SHALL/MUST#1162
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds a spec-specific Zod error converter that extracts requirement names from main-spec Markdown, maps Zod error paths to requirement indices, and produces targeted SHALL/MUST hints; wires this converter into ChangesMain-spec SHALL/MUST validation hints
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/core/validation/validator.ts (1)
545-549:⚠️ Potential issue | 🟡 Minor | ⚡ Quick winAvoid hard-coding the
### Requirement:header shape in the fix hint.Main specs in this suite are also accepted with bare
### ...requirement headers, so this remediation text can point users at a header form that does not exist in their file. Make the guidance refer to “the requirement header” generically instead.💡 Suggested wording
if (this.containsShallOrMust(blockName)) { - return `${base} in the requirement body, not only in the header. Move the SHALL/MUST statement to the line immediately after the "### Requirement: ..." header.`; + return `${base} in the requirement body, not only in the header. Move the SHALL/MUST statement to the line immediately after the requirement header.`; }🤖 Prompt for 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. In `@src/core/validation/validator.ts` around lines 545 - 549, The message in buildMissingShallOrMustMessage hard-codes '### Requirement: ...' which may not match actual headers; update the returned hint to reference "the requirement header" generically instead of the literal header shape (this function name and containsShallOrMust can be used to locate the logic). Modify the string returned when containsShallOrMust(blockName) is true so it instructs the user to move the SHALL/MUST statement to the line immediately after the requirement header (or the requirement header line) rather than naming '### Requirement: ...'.
🧹 Nitpick comments (1)
test/core/validation.test.ts (1)
228-254: ⚡ Quick winAdd the same regression for the existing bare
### ...requirement style.
validateSpecalready accepts main-spec requirements without theRequirement:prefix, but this new coverage only exercises the prefixed form. Adding one bare-header case here would protect the hint text for both supported syntaxes.🤖 Prompt for 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. In `@test/core/validation.test.ts` around lines 228 - 254, Add a second sub-case to this test that uses the bare main-spec requirement header style (e.g., "### System SHALL only say the keyword here" without the "Requirement:" prefix) to ensure Validator.validateSpec (via new Validator()) produces the same targeted hint; replicate the same assertions (report.valid false, find issue at 'requirements.0.text' containing 'not only in the header' and 'Move the SHALL/MUST statement', and assert the generic 'Requirement must contain SHALL or MUST keyword' message is not present) so both syntaxes are covered.
🤖 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.
Outside diff comments:
In `@src/core/validation/validator.ts`:
- Around line 545-549: The message in buildMissingShallOrMustMessage hard-codes
'### Requirement: ...' which may not match actual headers; update the returned
hint to reference "the requirement header" generically instead of the literal
header shape (this function name and containsShallOrMust can be used to locate
the logic). Modify the string returned when containsShallOrMust(blockName) is
true so it instructs the user to move the SHALL/MUST statement to the line
immediately after the requirement header (or the requirement header line) rather
than naming '### Requirement: ...'.
---
Nitpick comments:
In `@test/core/validation.test.ts`:
- Around line 228-254: Add a second sub-case to this test that uses the bare
main-spec requirement header style (e.g., "### System SHALL only say the keyword
here" without the "Requirement:" prefix) to ensure Validator.validateSpec (via
new Validator()) produces the same targeted hint; replicate the same assertions
(report.valid false, find issue at 'requirements.0.text' containing 'not only in
the header' and 'Move the SHALL/MUST statement', and assert the generic
'Requirement must contain SHALL or MUST keyword' message is not present) so both
syntaxes are covered.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 9e6a35e3-20e1-4ee0-b744-01583ca4ab85
📒 Files selected for processing (2)
src/core/validation/validator.tstest/core/validation.test.ts
|
Addressed the review feedback in 035622b:
Validation run locally:
|
Summary
Fixes #1156.
OpenSpec 1.4.0 already gives a targeted SHALL/MUST hint for change delta specs when the keyword appears only in the
### Requirement:header. Main specs underopenspec/specs/still went through the generic schema error, so authors saw onlyRequirement must contain SHALL or MUST keywordeven though the keyword was visible in the heading.This PR reuses the same diagnostic shape for main specs: when a requirement body lacks SHALL/MUST but the corresponding requirement heading contains it, the validator points the author to move the normative statement to the requirement body line. Cases where the keyword is missing everywhere keep the existing generic message.
Changes
requirements.N.texterrors while ignoring fenced code blocks.Verification
pnpm exec vitest run test/core/validation.test.tspnpm run buildpnpm run lintpnpm test(89 files, 1656 tests)openspec validate --all --jsonon a temporary main spec and confirmed the emitted error includesnot only in the headerinstead of the generic-only message.Summary by CodeRabbit
Bug Fixes
Tests