Commit Graph

3 Commits

Author SHA1 Message Date
HAL9000 93567d1453 fix(subplans): repair SubplanSpawnError lazy import and invariant BDD steps
CI / lint (pull_request) Successful in 35s
CI / build (pull_request) Successful in 35s
CI / helm (pull_request) Successful in 43s
CI / quality (pull_request) Successful in 51s
CI / push-validation (pull_request) Successful in 35s
CI / typecheck (pull_request) Successful in 57s
CI / security (pull_request) Successful in 1m22s
CI / unit_tests (pull_request) Successful in 4m17s
CI / docker (pull_request) Successful in 1m30s
CI / integration_tests (pull_request) Successful in 9m26s
CI / coverage (pull_request) Successful in 9m6s
CI / status-check (pull_request) Successful in 3s
Fixes the four root causes behind PR #8733's red unit_tests + Robot
integration_tests gates after the post-rebase landing of the v3.3.0
spec + invariant enforcement work.

1. Lazy-import module path used a slash instead of a dot — the
   `__getattr__` lookup in `application/services/__init__.py` could
   never resolve `SubplanSpawnError` because `importlib.import_module`
   only accepts dotted module paths. This broke both the
   `svcov3 lazy-load SubplanSpawnError` Behave scenario AND the
   `Test Services Package Exports` Robot scenario (the
   `from cleveragents.application.services import *` star-import walks
   `__all__` and trips on the bad entry).

2. `subplan_service_coverage_boost.feature:11` contained the literal
   placeholder text `{1:d}` instead of the literal value `1`. Gherkin
   does not interpolate `{n:d}` in feature bodies — only in step
   patterns — so the existing
   `the SubplanSpawnError message should contain {n:d} semicolons`
   step could not match.

3. `step_load_invariants_plan_only` used `@when(re.compile(...))`
   without `use_step_matcher("re")`, so behave silently treated it as
   an undefined step. Switched the file's matcher to `re` for that
   single step (auto-anchored, no end marker — behave's `re` matcher
   refuses `$`) and back to `parse` for the rest, so it no longer
   collides with the parse-matched "with project" variant whose
   `{plan_id}` field is greedy.

4. `step_check_action_against_invariants` used the parse field
   `{action_text}` which doesn't match empty strings, so the
   "Empty action text" scenario reported the When step as undefined.
   Extracted the body into `_check_action_against_loaded` and added a
   literal-pattern `'I check action "" against loaded invariants'`
   step that delegates to it. Both step variants now also write
   `context.error` so the shared
   `the error message should contain "..."` step in `service_steps.py`
   (which reads `context.error`) works against either error type.

5. `step_attempt_strategy_decision` / `step_create_strategy_decision`
   only checked `context.strategize_invariants`, which is empty when
   the scenario adds a global invariant via `Given` but never runs the
   explicit `I start the Strategize phase` step. Added
   `_strategize_active_invariants` helper that falls back to all
   active invariants on the service — mirrors the same fallback
   pattern already used by `_check_action_against_loaded`.

6. `step_winning_scope` in `invariant_reconciliation_actor_steps.py`
   only read `context.reconciliation_result`, so reusing the
   `the winning invariant for "X" should be from "Y" scope` assertion
   in a non-reconciliation scenario errored with AttributeError. Now
   falls back to `context.loaded_invariants` (which
   `InvariantService.load_active_invariants` already merges with the
   plan > project > global precedence the scenario asserts).

Verified locally:
- `unit_tests` gate passes (16504 scenarios, 0 failed, 0 errored).
- `lint` gate passes.
- `Test Services Package Exports` star-import path resolves
  `SubplanSpawnError` cleanly via the package `__getattr__`.

ISSUES CLOSED: #8725
2026-06-02 19:50:41 -04:00
HAL9000 5e89f1016c refactor(subplans): Centralize subplan errors per v3.3.0 spec (#8725)
Move SubplanSpawnError from local subplan_service definition to centralized
cleveragents.core.exceptions alongside four new spec-defined error types:
SubplanExecutionError, MaxParallelExceededError, and SubplanDepthLimitError.

Per the v3.3.0 specification (AUTO-ARCH-6), all subplan-related errors are
defined in exceptions.py with proper inheritance hierarchy under DomainError/
PlanError/BusinessRuleViolation. The old local SpawnValidationError class has
been replaced with SubplanSpawnError(PlanError) with a simplified constructor
API (message string instead of validation_errors list).

Updates:
- exceptions.py: Added 4 subplan error classes + __all__ entries
- subplan_service.py: Remove local SpawnValidationError, import SubplanSpawnError from exceptions
- services/__init__.py: Update TYPE_CHECKING stub and _LAZY_IMPORTS for new location
- vulture_whitelist.py: Replace old entry with new error class names
- docs/reference/subplan_service.md: Update to reference SubplanSpawnError (v3.3.0)
- features/*.feature + steps: Update test references from SpawnValidationError to SubplanSpawnError
2026-06-02 19:50:41 -04:00
freemo a808c395f9 test(coverage): add Behave BDD tests to improve unit test coverage across 53 source modules
CI / benchmark-publish (pull_request) Has been skipped
CI / lint (pull_request) Successful in 15s
CI / build (pull_request) Successful in 15s
CI / quality (pull_request) Successful in 17s
CI / typecheck (pull_request) Successful in 35s
CI / security (pull_request) Successful in 50s
CI / unit_tests (pull_request) Successful in 2m46s
CI / integration_tests (pull_request) Successful in 3m16s
CI / docker (pull_request) Successful in 40s
CI / coverage (pull_request) Successful in 5m6s
CI / lint (push) Successful in 13s
CI / quality (push) Successful in 16s
CI / build (push) Successful in 18s
CI / security (push) Successful in 32s
CI / typecheck (push) Successful in 35s
CI / benchmark-regression (push) Has been skipped
CI / unit_tests (push) Successful in 2m52s
CI / integration_tests (push) Successful in 3m8s
CI / docker (push) Successful in 39s
CI / coverage (push) Successful in 5m53s
CI / benchmark-publish (push) Successful in 16m55s
CI / benchmark-regression (pull_request) Successful in 33m0s
Add 53 new .feature files and corresponding step definition files targeting
uncovered lines identified in build/coverage.xml. Fix AmbiguousStep conflicts
in 7 pre-existing step files by disambiguating step text.

New tests cover: ACP clients/facade, actor CLI/config, application container,
ACMS service/strategies, async worker, automation profile CLI, autonomy
guardrail, bridge, change model, config CLI/service, context service,
cross-plan correction, database models, decision service, decomposition
clustering/service, discovery handler, langchain chat provider, langgraph
nodes, materializers, multi-project service, plan apply/CLI/lifecycle/model/
preflight/resume/service, PostgreSQL analyzer, project CLI/context CLI,
provider registry, reactive application/route, repositories, resolver handler,
resource registry service, resume model, retry patterns, sandbox protocol,
server CLI, skill CLI/service, skills registry, subplan execution/service,
system CLI, UKO loader, UoW, and YAML template engine.

Closes #645
2026-03-09 13:01:58 -04:00