Files
temp/features/tdd_tool_runner_env_precedence.feature
freemo 884fe12511 ```
fix(tool): wire 6-level execution environment precedence chain into ToolRunner

What was implemented
- Updated ToolRunner.execute() to accept plan_priority and project_priority parameters (optional) and to propagate these priority values through the execution path.
- Replaced the legacy four-level resolve_and_validate() with resolve_with_precedence() to implement the correct six-level precedence chain.
- Introduced devcontainer_available derived from has_devcontainer() on linked_resource_types and wired this into the resolution process.
- Updated all call sites (router.py and actor_runtime.py) to accept and forward the new priority parameters.
- Added 12 unit tests verifying the six-level precedence chain behavior in ToolRunner.execute().
- Added integration tests covering override vs. fallback scenarios to ensure correct end-to-end behavior.

Key design decisions and rationale
- Use resolve_with_precedence() instead of resolve_with_dag() because linked_resource_types already provides devcontainer availability information, eliminating the need for a full DAG walk while preserving correct precedence semantics.
- Preserve the existing contract of raising ContainerUnavailableError by retaining a final validate_container_available() call after resolution, ensuring proper error signaling when a container is resolved but no linked container resource exists.
- Make plan_priority and project_priority optional with None defaulting to fallback semantics, aligning with the resolver's _parse_priority() behavior and keeping backward-compatible defaults for existing callers.

ISSUES CLOSED: #2592
```
2026-04-05 08:47:35 +00:00

72 lines
3.8 KiB
Gherkin

@tdd_issue @tdd_issue_2592 @tdd_bug @tdd_bug_2592 @mock_only
Feature: TDD Issue #2592 — ToolRunner.execute() 6-level execution environment precedence chain
As the tool execution engine
I want ToolRunner.execute() to apply the correct 6-level precedence chain
So that override/fallback priority semantics are honoured at tool execution time
# Unit tests: 6-level precedence chain via ToolRunner.execute()
Scenario: Plan override wins over devcontainer (Level 1 beats Level 3)
Given a tool runner with a devcontainer-instance linked resource
When I execute the tool with plan_env "host" and plan_priority "override"
Then the resolved execution environment should be "host"
Scenario: Project override wins over devcontainer (Level 2 beats Level 3)
Given a tool runner with a devcontainer-instance linked resource
When I execute the tool with project_env "host" and project_priority "override"
Then the resolved execution environment should be "host"
Scenario: Devcontainer wins over plan fallback (Level 3 beats Level 4)
Given a tool runner with a devcontainer-instance linked resource
When I execute the tool with plan_env "host" and plan_priority "fallback"
Then the resolved execution environment should be "container"
Scenario: Devcontainer wins over project fallback (Level 3 beats Level 5)
Given a tool runner with a devcontainer-instance linked resource
When I execute the tool with project_env "host" and project_priority "fallback"
Then the resolved execution environment should be "container"
Scenario: Plan fallback used when no devcontainer (Level 4)
Given a tool runner with no linked resources
When I execute the tool with plan_env "container" and plan_priority "fallback"
Then the resolved execution environment should be "container"
Scenario: Project fallback used when no devcontainer and no plan env (Level 5)
Given a tool runner with no linked resources
When I execute the tool with project_env "container" and project_priority "fallback"
Then the resolved execution environment should be "container"
Scenario: Host default when nothing configured (Level 6)
Given a tool runner with no linked resources
When I execute the tool with no environment configuration
Then the resolved execution environment should be "host"
Scenario: Plan override beats project override (Level 1 beats Level 2)
Given a tool runner with no linked resources
When I execute the tool with plan_env "host" plan_priority "override" project_env "container" project_priority "override"
Then the resolved execution environment should be "host"
# ── Integration tests: override vs fallback scenarios ──
Scenario: Override bypasses devcontainer auto-detection
Given a tool runner with a devcontainer-instance linked resource
When I execute the tool with plan_env "host" and plan_priority "override"
Then the resolved execution environment should be "host"
And the devcontainer was not used
Scenario: Fallback defers to devcontainer when present
Given a tool runner with a devcontainer-instance linked resource
When I execute the tool with plan_env "host" and plan_priority "fallback"
Then the resolved execution environment should be "container"
And the devcontainer was used
Scenario: Fallback uses configured env when no devcontainer present
Given a tool runner with no linked resources
When I execute the tool with plan_env "host" and plan_priority "fallback"
Then the resolved execution environment should be "host"
Scenario: Default priority is fallback — devcontainer wins over unconfigured plan env
Given a tool runner with a devcontainer-instance linked resource
When I execute the tool with plan_env "host" and no explicit priority
Then the resolved execution environment should be "container"