Skip to content

Conversation

@harikrishnan83
Copy link
Contributor

@harikrishnan83 harikrishnan83 commented Dec 29, 2025

Add OpenSpec change proposal and test coverage for requirement validation bug where metadata fields (ID, Priority, etc.) were incorrectly checked for SHALL/MUST keywords instead of the requirement description.

The bug caused false validation failures on valid requirements that included metadata fields before the normative description text.

Following TDD approach:

  • Added failing test case for requirements with metadata fields
  • Test fails with buggy code (pre-c782462)
  • Test passes with fixed code (commit c782462)
  • Fix skips metadata field lines when extracting requirement text

🤖 Generated with Claude Code

Fixes #418

Summary by CodeRabbit

  • Bug Fixes
    • Fixed a validation issue where requirements with metadata fields (like ID or Priority) positioned before the description were incorrectly flagged as invalid, even when the description contained required keywords.
    • Added test coverage to ensure requirements with metadata fields are properly validated.

✏️ Tip: You can customize this high-level summary in your review settings.

Add OpenSpec change proposal and test coverage for requirement validation
bug where metadata fields (**ID**, **Priority**, etc.) were incorrectly
checked for SHALL/MUST keywords instead of the requirement description.

The bug caused false validation failures on valid requirements that included
metadata fields before the normative description text.

Following TDD approach:
- Added failing test case for requirements with metadata fields
- Test fails with buggy code (pre-c782462)
- Test passes with fixed code (commit c782462)
- Fix skips metadata field lines when extracting requirement text

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 29, 2025

📝 Walkthrough

Walkthrough

This PR introduces documentation and a test for fixing a metadata field validation bug in the requirements validator. The change proposes skipping bolded metadata lines (matching /^**[^*]+**:/) when extracting requirement descriptions to ensure validation correctly checks the normative text rather than metadata fields.

Changes

Cohort / File(s) Summary
Proposal & Specification Documents
openspec/changes/fix-metadata-field-validation-bug/proposal.md, openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md, openspec/changes/fix-metadata-field-validation-bug/tasks.md
Three new documentation files defining the bug, expected behavior after fix, and test-driven implementation workflow. Specifies that metadata lines matching bolded field patterns should be skipped during requirement text extraction.
Test Addition
test/core/validation.test.ts
Adds a test case under validateChangeDeltaSpecs verifying that requirements with metadata fields preceding the description pass validation when the description contains SHALL/MUST keywords.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~4 minutes

Possibly related PRs

Suggested reviewers

  • TabishB

Poem

🐰 Hop hop, a bug hops away,
Metadata fields led astray,
Skip the bold, find the true test,
Descriptions now pass validation's quest!
Requirements shine without the fret.

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a proposal to fix a metadata field validation bug in the requirements validator.
Linked Issues check ✅ Passed The PR fully addresses issue #418 objectives by adding extractRequirementText() fix logic, comprehensive tests for metadata-prefixed requirements, and updated specs documenting proper behavior.
Out of Scope Changes check ✅ Passed All changes in the PR are directly related to fixing the metadata field validation bug and are within scope of issue #418 objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@vibe-kanban-cloud
Copy link

Review Complete

Your review story is ready!

View Story

Comment !reviewfast on this PR to re-generate the story.

@harikrishnan83
Copy link
Contributor Author

Looks like this is addressed. Tested on the latest version. No need to merge this PR.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fb7ff52 and bac6ab7.

📒 Files selected for processing (4)
  • openspec/changes/fix-metadata-field-validation-bug/proposal.md
  • openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md
  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
  • test/core/validation.test.ts
🧰 Additional context used
📓 Path-based instructions (4)
openspec/changes/**/*.md

📄 CodeRabbit inference engine (openspec/AGENTS.md)

Scaffold proposal using proposal.md, tasks.md, optional design.md, and delta specs under openspec/changes/<id>/

Files:

  • openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md
  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
  • openspec/changes/fix-metadata-field-validation-bug/proposal.md
openspec/changes/**/specs/**/spec.md

📄 CodeRabbit inference engine (openspec/AGENTS.md)

openspec/changes/**/specs/**/spec.md: Use ## ADDED|MODIFIED|REMOVED|RENAMED Requirements headers in spec delta files
Include at least one #### Scenario: per requirement in spec delta files
Use #### Scenario: Name format (4 hashtags) for scenario headers, not bullets or bold text
Use ## ADDED Requirements for new orthogonal capabilities that can stand alone; use ## MODIFIED Requirements for behavior changes of existing requirements
When using MODIFIED Requirements, paste the full requirement block including header and all scenarios

Files:

  • openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md
openspec/changes/*/tasks.md

📄 CodeRabbit inference engine (openspec/AGENTS.md)

Ensure tasks.md contains implementation checklist with numbered sections and checkbox items

Files:

  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
openspec/changes/*/proposal.md

📄 CodeRabbit inference engine (openspec/AGENTS.md)

Ensure proposal.md includes sections: Why (1-2 sentences), What Changes (bullet list with breaking change markers), and Impact (affected specs and code)

Files:

  • openspec/changes/fix-metadata-field-validation-bug/proposal.md
🧠 Learnings (10)
📓 Common learnings
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Applies to openspec/changes/*/proposal.md : Ensure `proposal.md` includes sections: Why (1-2 sentences), What Changes (bullet list with breaking change markers), and Impact (affected specs and code)
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Applies to openspec/changes/**/specs/**/spec.md : When using MODIFIED Requirements, paste the full requirement block including header and all scenarios
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Run `openspec validate [change-id] --strict` before requesting approval
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Applies to openspec/changes/**/specs/**/spec.md : Use `## ADDED Requirements` for new orthogonal capabilities that can stand alone; use `## MODIFIED Requirements` for behavior changes of existing requirements
📚 Learning: 2025-11-25T01:08:19.004Z
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Applies to openspec/specs/**/spec.md : Use SHALL/MUST for normative requirements in spec files; avoid should/may unless intentionally non-normative

Applied to files:

  • openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md
  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
  • test/core/validation.test.ts
  • openspec/changes/fix-metadata-field-validation-bug/proposal.md
📚 Learning: 2025-11-25T01:08:19.004Z
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Applies to openspec/changes/**/specs/**/spec.md : Use `## ADDED Requirements` for new orthogonal capabilities that can stand alone; use `## MODIFIED Requirements` for behavior changes of existing requirements

Applied to files:

  • openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md
  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
  • test/core/validation.test.ts
  • openspec/changes/fix-metadata-field-validation-bug/proposal.md
📚 Learning: 2025-11-25T01:08:19.004Z
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Run `openspec validate [change-id] --strict` before requesting approval

Applied to files:

  • openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md
  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
  • openspec/changes/fix-metadata-field-validation-bug/proposal.md
📚 Learning: 2025-11-25T01:08:19.004Z
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Applies to openspec/changes/**/specs/**/spec.md : Use `## ADDED|MODIFIED|REMOVED|RENAMED Requirements` headers in spec delta files

Applied to files:

  • openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md
  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
  • test/core/validation.test.ts
  • openspec/changes/fix-metadata-field-validation-bug/proposal.md
📚 Learning: 2025-11-25T01:08:19.004Z
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Applies to openspec/changes/*/proposal.md : Ensure `proposal.md` includes sections: Why (1-2 sentences), What Changes (bullet list with breaking change markers), and Impact (affected specs and code)

Applied to files:

  • openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md
  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
  • openspec/changes/fix-metadata-field-validation-bug/proposal.md
📚 Learning: 2025-11-25T01:08:19.004Z
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Applies to openspec/changes/**/specs/**/spec.md : When using MODIFIED Requirements, paste the full requirement block including header and all scenarios

Applied to files:

  • openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md
  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
  • test/core/validation.test.ts
  • openspec/changes/fix-metadata-field-validation-bug/proposal.md
📚 Learning: 2025-11-25T01:08:19.004Z
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Applies to openspec/changes/**/specs/**/spec.md : Include at least one `#### Scenario:` per requirement in spec delta files

Applied to files:

  • openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md
  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
  • test/core/validation.test.ts
📚 Learning: 2025-11-25T01:08:19.004Z
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Applies to openspec/changes/*/tasks.md : Ensure `tasks.md` contains implementation checklist with numbered sections and checkbox items

Applied to files:

  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
📚 Learning: 2025-11-25T01:08:19.004Z
Learnt from: CR
Repo: Fission-AI/OpenSpec PR: 0
File: openspec/AGENTS.md:0-0
Timestamp: 2025-11-25T01:08:19.004Z
Learning: Applies to openspec/changes/**/*.md : Scaffold proposal using `proposal.md`, `tasks.md`, optional `design.md`, and delta specs under `openspec/changes/<id>/`

Applied to files:

  • openspec/changes/fix-metadata-field-validation-bug/tasks.md
  • openspec/changes/fix-metadata-field-validation-bug/proposal.md
🧬 Code graph analysis (1)
test/core/validation.test.ts (1)
src/core/validation/validator.ts (1)
  • Validator (16-449)
🔇 Additional comments (3)
openspec/changes/fix-metadata-field-validation-bug/specs/cli-validate/spec.md (1)

1-29: LGTM! Well-structured spec delta.

The spec delta correctly documents the metadata field extraction behavior using MODIFIED Requirements. All three scenarios are properly formatted with the required #### Scenario: headers and use normative SHALL language. The regex pattern /^\*\*[^*]+\*\*:/ accurately captures metadata field lines.

As per coding guidelines, remember to run openspec validate fix-metadata-field-validation-bug --strict before requesting approval.

openspec/changes/fix-metadata-field-validation-bug/tasks.md (1)

1-38: LGTM! Clear TDD workflow documentation.

The tasks file follows the required structure with numbered sections and checkboxes. The test-driven development approach is well-documented, showing the RED-GREEN cycle and validation steps. The inclusion of the openspec validate command aligns with the coding guidelines.

openspec/changes/fix-metadata-field-validation-bug/proposal.md (1)

1-33: LGTM! Comprehensive proposal structure.

The proposal includes all required sections (Why, What Changes, Impact) as specified in the coding guidelines. The Why section is more detailed than the suggested "1-2 sentences," but the additional context (bug description, example, root cause, and impact) is valuable for understanding the fix. The What Changes section provides a clear bullet list, and the Impact section properly identifies affected specs and confirms no breaking changes.

Based on coding guidelines, this proposal follows the required structure for openspec/changes/*/proposal.md.

Comment on lines +489 to +521
it('should pass when requirement has metadata fields before description with SHALL/MUST', async () => {
const changeDir = path.join(testDir, 'test-change-with-metadata');
const specsDir = path.join(changeDir, 'specs', 'test-spec');
await fs.mkdir(specsDir, { recursive: true });

// This is the exact pattern that was failing before the metadata fix
// The bug: old code would check **ID** line for SHALL/MUST instead of the description
const deltaSpec = `# Test Spec
## ADDED Requirements
### Requirement: File Serving
**ID**: REQ-FILE-001
**Priority**: P1
The system MUST serve static files from the root directory.
#### Scenario: File is requested
**Given** a static file exists
**When** the file is requested
**Then** the system SHALL serve the file successfully`;

const specPath = path.join(specsDir, 'spec.md');
await fs.writeFile(specPath, deltaSpec);

const validator = new Validator(true);
const report = await validator.validateChangeDeltaSpecs(changeDir);

// This should PASS because the description (not metadata) contains MUST
// Before fix c782462, this would FAIL because it checked the **ID** line
expect(report.valid).toBe(true);
expect(report.summary.errors).toBe(0);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Duplicate test coverage detected.

This test case appears to duplicate the existing test at lines 343-371 ("should validate requirement with metadata before SHALL/MUST text"). Both tests verify the same scenario:

  • Metadata fields (ID, Priority) before the description
  • Description contains MUST/SHALL keywords
  • Validation should pass

The only differences are the specific requirement content (Circuit Breaker vs File Serving), which don't provide additional coverage for the metadata extraction logic. Consider removing this test to avoid redundancy, as the existing test at lines 343-371 already covers this scenario.

📊 Comparison of the two tests

Existing test (343-371):

  • Title: "Circuit Breaker State Management SHALL be implemented"
  • Metadata: ID: REQ-CB-001, Priority: P1 (High)
  • Description: "The system MUST implement a circuit breaker..."

New test (489-521):

  • Title: "File Serving"
  • Metadata: ID: REQ-FILE-001, Priority: P1
  • Description: "The system MUST serve static files..."

Both tests validate identical extraction logic for metadata fields.

🤖 Prompt for AI Agents
In test/core/validation.test.ts around lines 489-521 there is a duplicate test
that repeats the existing scenario at lines 343-371 (metadata before description
with SHALL/MUST) — remove this redundant test or replace it with a case that
exercises a different path (for example: metadata present but no SHALL/MUST
anywhere, SHALL/MUST in metadata only, or multiple requirements in one file) so
the suite adds coverage; update the spec files and assertions accordingly and
run tests to ensure no behavioral change.

@harikrishnan83 harikrishnan83 marked this pull request as draft December 29, 2025 09:20
- Modified `extractRequirementText()` in src/core/validation/validator.ts
- Changed from collecting all lines and finding first non-empty
- To: iterating through lines, skipping blanks and metadata fields
- Returns first line that is NOT blank and NOT metadata pattern `/^\*\*[^*]+\*\*:/`
Copy link
Contributor

@TabishB TabishB Dec 29, 2025

Choose a reason for hiding this comment

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

This address the fix but it's very specific to the case where the metadata is defined in the following format **<tag>**.

I think the option is to either to make it more general or to just incorporate the tags as part of the standard itself.

Could using markdown frontmatter tags here help instead? I see from the example that this is on a per file basis not per requirement.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hello @TabishB, I am leaning towards making tags a part of the standard. Let me go over a few examples of specs from real apps and see what make most sense and update this PR. Will keep in draft mode until then. Thanks for your suggestions.

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.

[BUG] Requirement Validation Fails When Metadata Fields Precede Description

2 participants