Skip to content

feat(specs-apply): error on unmatched tagged scenario ops in delta specs #847

Description

@coderabbitai

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

Activity

  1. clay-good commented on Aug 5, 2026

    @clay-good
    Collaborator

    Thanks — this is a good defensive check. It was raised as a deferred follow-up to PR #843 (scenario-level merge for MODIFIED requirements), and that PR is still open/unmerged. The mergeScenarios() code path and the per-scenario (MODIFIED)/(REMOVED) tagging this hardening applies to don't exist on main yet, so there's nothing to change here today. Closing as superseded-by #843 — the right home for this validation is inside that PR (or a fresh issue once scenario tagging actually merges) so the strict-error behavior ships together with the feature it protects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions