Summary
When applying a delta spec, a #### Scenario: Foo (MODIFIED) that does not match any existing scenario in the main requirement currently falls through to the append path and becomes a brand-new scenario. Similarly, a #### Scenario: Foo (REMOVED) that matches nothing is silently ignored. Both behaviors hide typos in delta specs and diverge from the strict error semantics used at the requirement level (e.g., MODIFIED failing when the requirement is not found).
Expected Behavior
Only untagged scenarios should be appendable. A tagged scenario (MODIFIED or REMOVED) that does not match any existing scenario in the main requirement should produce an explicit error, e.g.:
Scenario "Foo" is tagged MODIFIED but was not found in requirement "<requirement name>"
Suggested Fix
In the append loop inside mergeScenarios() in src/core/specs-apply.ts, check whether an unused delta scenario has a tag:
for (const s of delta.scenarios) {
const name = normalizeScenarioName(s.name);
- if (!usedDeltaNames.has(name) && s.tag !== 'REMOVED') {
- result.push(stripScenarioTag(s));
+ if (!usedDeltaNames.has(name)) {
+ if (s.tag === undefined) {
+ result.push(stripScenarioTag(s));
+ usedDeltaNames.add(name);
+ } else {
+ throw new Error(
+ `Scenario "${s.name}" is tagged ${s.tag} but was not found in requirement "${main.name}"`
+ );
+ }
+ }
}
Context
Requested by
@phuongvm
Summary
When applying a delta spec, a
#### Scenario: Foo (MODIFIED)that does not match any existing scenario in the main requirement currently falls through to the append path and becomes a brand-new scenario. Similarly, a#### Scenario: Foo (REMOVED)that matches nothing is silently ignored. Both behaviors hide typos in delta specs and diverge from the strict error semantics used at the requirement level (e.g.,MODIFIEDfailing when the requirement is not found).Expected Behavior
Only untagged scenarios should be appendable. A tagged scenario (
MODIFIEDorREMOVED) that does not match any existing scenario in the main requirement should produce an explicit error, e.g.:Suggested Fix
In the append loop inside
mergeScenarios()insrc/core/specs-apply.ts, check whether an unused delta scenario has a tag:for (const s of delta.scenarios) { const name = normalizeScenarioName(s.name); - if (!usedDeltaNames.has(name) && s.tag !== 'REMOVED') { - result.push(stripScenarioTag(s)); + if (!usedDeltaNames.has(name)) { + if (s.tag === undefined) { + result.push(stripScenarioTag(s)); + usedDeltaNames.add(name); + } else { + throw new Error( + `Scenario "${s.name}" is tagged ${s.tag} but was not found in requirement "${main.name}"` + ); + } + } }Context
Requested by
@phuongvm