Files
cleveragents-core/features/sandbox_manager_strategy_cast.feature
T
CI Bot 68a3cc40ca
CI / lint (pull_request) Successful in 32s
CI / typecheck (pull_request) Successful in 55s
CI / quality (pull_request) Successful in 48s
CI / security (pull_request) Successful in 1m2s
CI / build (pull_request) Successful in 23s
CI / helm (pull_request) Successful in 22s
CI / unit_tests (pull_request) Successful in 6m43s
CI / docker (pull_request) Successful in 1m28s
CI / e2e_tests (pull_request) Successful in 17m13s
CI / integration_tests (pull_request) Successful in 22m17s
CI / coverage (pull_request) Successful in 10m27s
CI / status-check (pull_request) Successful in 1s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Successful in 56m1s
fix(sandbox): remove type: ignore in SandboxManager strategy assignment
Implemented removal of the type: ignore in SandboxManager strategy assignment by introducing a proper typing.cast usage and added tests to cover the new path.

- What was implemented
  - Added from typing import cast to src/cleveragents/infrastructure/sandbox/manager.py.
  - Replaced strategy = boundary_resource.sandbox_strategy  # type: ignore[assignment] with strategy = cast("SandboxStrategyStr", boundary_resource.sandbox_strategy) at line 618 in get_or_create_sandbox_for_resource.
  - The cast is semantically correct: SandboxStrategy (StrEnum) values are exactly the same string set as SandboxStrategyStr (Literal), so the cast is a truthful type assertion with zero runtime overhead.
  - Added features/sandbox_manager_strategy_cast.feature with 2 Behave scenarios exercising the cast conversion path.
  - Added features/steps/sandbox_manager_strategy_cast_steps.py with step definitions.

- Key design decisions
  - Used cast() from typing rather than SandboxStrategyStr(...) constructor call, because SandboxStrategyStr is a Literal type alias (not a callable), so calling it as a constructor would fail at runtime.
  - Used string form "SandboxStrategyStr" in the cast call because the file uses from __future__ import annotations.
  - Mocked the boundary cache in tests to avoid DAG traversal, following the pattern established in sandbox_manager_coverage_r3_steps.py.

- Affected modules/components
  - src/cleveragents/infrastructure/sandbox/manager.py
  - features/sandbox_manager_strategy_cast.feature
  - features/steps/sandbox_manager_strategy_cast_steps.py

- Testing considerations
  - The new Behave scenarios exercise the cast path in isolation, reducing DAG traversal concerns and aligning with existing testing patterns.

ISSUES CLOSED: #2828
2026-04-05 04:37:45 +00:00

19 lines
996 B
Gherkin

Feature: Sandbox Manager strategy cast path
Exercises the cast("SandboxStrategyStr", boundary_resource.sandbox_strategy)
line in get_or_create_sandbox_for_resource, which is reached whenever the
boundary resource has a non-None sandbox_strategy.
Background:
Given smcast a sandbox factory instance
And smcast a sandbox manager with the factory
Scenario: get_or_create_sandbox_for_resource succeeds with SandboxStrategy.NONE
Given smcast a boundary resource with strategy "NONE" and location "/tmp/smcast-none"
When smcast I call get_or_create_sandbox_for_resource for plan "plan-smcast-1"
Then smcast a sandbox is returned without error
Scenario: get_or_create_sandbox_for_resource succeeds with SandboxStrategy.NONE on a second plan
Given smcast a boundary resource with strategy "NONE" and location "/tmp/smcast-none-2"
When smcast I call get_or_create_sandbox_for_resource for plan "plan-smcast-2"
Then smcast a sandbox is returned without error