Skip to content

Support calling scenarios within the same feature file with recursion detection#33

Draft
Copilot wants to merge 5 commits intomainfrom
copilot/support-scenario-calls-same-file
Draft

Support calling scenarios within the same feature file with recursion detection#33
Copilot wants to merge 5 commits intomainfrom
copilot/support-scenario-calls-same-file

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

Scenario calls were restricted to cross-feature references. Same-feature calls would fail during lookup, and self-referencing scenarios could cause infinite expansion without detection.

Changes

Core Implementation

  • Modified FindScenarioSteps to accept current feature content, enabling same-feature lookups without additional file I/O
  • Added call stack tracking (HashSet<string>) in PreprocessFeatureContent to detect direct self-reference
  • Call stack scoped per top-level scenario; cleared on each new scenario to maintain test independence

Error Handling

  • Circular reference detection returns clear error comment instead of failing silently
  • Extracted CreateCallStackKey and CircularReferenceErrorFormat for consistency

Example

Feature: User Management

Scenario: Common Setup
    Given the system is initialized
    And test data is loaded

Scenario: Create User
    Given I call scenario "Common Setup" from feature "User Management"
    When I create a new user
    Then the user should be created

Scenario: Self Reference (Blocked)
    Given I call scenario "Self Reference" from feature "User Management"
    # Error: Circular reference detected - scenario "Self Reference" 
    # from feature "User Management" is already in the call chain

Design Notes

  • One-level expansion maintained (nested scenario calls not recursively expanded per existing limitation)
  • Indirect circular references (A→B→A) won't cause infinite loops since B's calls aren't expanded
  • Backward compatible with all existing cross-feature and cross-project scenario calls

Test Coverage

Added 6 unit tests covering same-feature calls, self-reference detection, multiple calls, mixed cross-feature/same-feature, case insensitivity, and indirect recursion behavior. All 85 existing tests pass.

Original prompt

This section details on the original issue you should resolve

<issue_title>Support calling another scenario within the same feature file</issue_title>
<issue_description>It is currently not possible (or not supported) to call another scenario within the same feature file, although this is a useful reuse pattern.

Current situation:

  • Scenario calls are primarily designed around referencing another feature (often another file).
  • Calling within the same feature file can be desirable, but may be blocked by:
    • lookup logic that assumes an external target feature file, and/or
    • missing recursion/loop protection if a scenario can (directly or indirectly) call itself.

Expected functionality:

  • Allow scenario calls where the target scenario is located in the same feature file.
  • Add safeguards:
    • detect self-reference,
    • prevent infinite recursion,
    • provide a clear error if recursion is detected.

References:

Implementation hint:

  • Allow featureName in a scenario call to resolve to the current feature context (e.g., omit “from feature …” or allow an explicit marker), then resolve target scenarios from the already-loaded content.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 4 commits December 19, 2025 08:16
Co-authored-by: jgerits <6541449+jgerits@users.noreply.github.com>
Co-authored-by: jgerits <6541449+jgerits@users.noreply.github.com>
Co-authored-by: jgerits <6541449+jgerits@users.noreply.github.com>
…ve maintainability

Co-authored-by: jgerits <6541449+jgerits@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for calling scenarios within the same feature file Support calling scenarios within the same feature file with recursion detection Dec 19, 2025
Copilot AI requested a review from jgerits December 19, 2025 08:34
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.

Support calling another scenario within the same feature file

2 participants