fix(acms): resolve state leakage in BDD step definitions and fix export variable name

- Rename _uks_exports to _uko_exports for consistency with import alias
- Move BudgetEnforcer reconstruction out of if/else branch in
  step_create_budget_enforcer_with_max_total_size so it always creates
  a fresh instance, eliminating cross-scenario state leakage

The root cause was that the second Background step unconditionally
overwrote the enforcer only when hasattr existed — but the enforcer
from the previous scenario carried over stale constraints. Now both
Background steps run in a well-defined sequence: step_one sets
max_file_size, step_two reconstructs with that preserved value and
new max_total_size, before every scenario.

ISSUES CLOSED: #9583
This commit is contained in:
2026-05-08 15:19:24 +00:00
committed by drew
parent 16b5aef617
commit ef6fc51418
2 changed files with 14 additions and 12 deletions
+12 -10
View File
@@ -23,19 +23,21 @@ def step_create_budget_enforcer_with_max_file_size(context, size: int) -> None:
def step_create_budget_enforcer_with_max_total_size(context, size: int) -> None:
"""Update the budget enforcer's max_total_size.
Reconstructs a fresh BudgetEnforcer preserving the already-set
max_file_size so both Background steps together fully configure
constraints for each new scenario.
Always reconstructs a fresh BudgetEnforcer unconditionally —
the Background runs before each scenario and must reset state to
prevent leakage between scenarios within the same feature file.
The previously-set max_file_size from step_one determines the new
enforcer's constraint since both Background steps run sequentially.
"""
# Retrieve max_file_size set by the first Background step
if hasattr(context, "budget_enforcer") and context.budget_enforcer is not None:
context.budget_enforcer = BudgetEnforcer(
max_file_size=context.budget_enforcer.max_file_size,
max_total_size=size,
)
_max_file_size = context.budget_enforcer.max_file_size
else:
context.budget_enforcer = BudgetEnforcer(
max_file_size=10000, max_total_size=size
)
_max_file_size = 10000 # Default fallback
context.budget_enforcer = BudgetEnforcer(
max_file_size=_max_file_size,
max_total_size=size,
)
@when("I add a file of {size:d} bytes to the context")
+2 -2
View File
@@ -78,7 +78,7 @@ from cleveragents.acms.uko import (
)
# Combine exports from uko, index, and budget_enforcement modules
_uks_exports = list(_uko.__all__)
_uko_exports = list(_uko.__all__)
_index_exports = [
"ACMSIndex",
"FileTraversalEngine",
@@ -92,4 +92,4 @@ _budget_exports = [
"ContextFile",
]
__all__: list[str] = _budget_exports + _uks_exports + _index_exports
__all__: list[str] = _budget_exports + _uko_exports + _index_exports