feat(resources): implement virtual resource type base class for abstract/computed resources #10605

Merged
HAL9000 merged 5 commits from feat/v3.6.0-virtual-resource-types into master 2026-06-04 08:42:50 +00:00

5 Commits

Author SHA1 Message Date
HAL9000 36a6bd6011 fix(resources): resolve unit_tests failures and review blockers for virtual resource PR
CI / build (pull_request) Successful in 33s
CI / lint (pull_request) Successful in 56s
CI / helm (pull_request) Successful in 53s
CI / quality (pull_request) Successful in 57s
CI / typecheck (pull_request) Successful in 1m3s
CI / security (pull_request) Successful in 1m4s
CI / push-validation (pull_request) Successful in 25s
CI / unit_tests (pull_request) Successful in 5m21s
CI / integration_tests (pull_request) Successful in 10m15s
CI / docker (pull_request) Successful in 1m33s
CI / coverage (pull_request) Successful in 10m44s
CI / status-check (pull_request) Successful in 4s
Restores green unit_tests by removing the duplicate Pydantic virtual-resource
implementation that had no production consumers and was causing behave step
collisions, fixing parse-library step patterns that never matched, and giving
the failing-test scenarios concrete step definitions.

Changes:
- Remove unused parallel implementation `src/cleveragents/domain/models/core/
  virtual_resource.py`, its feature file `features/virtual_resource_types.feature`,
  and its step file `features/steps/virtual_resource_types_steps.py`. The
  canonical `src/cleveragents/resource/virtual.py` (re-exported by
  `src/cleveragents/resource/__init__.py`) is the only public API; the
  Pydantic copy had zero non-test consumers and its step file duplicated
  step text patterns (e.g., `the computed value should be ...`), triggering
  `behave.step_registry.AmbiguousStep` errors at module load.
- Fix `VirtualResource.__init__` name validation in
  `src/cleveragents/resource/virtual.py`: replace the
  `name.replace("-", "").replace("_", "").isalnum()` check with a single
  regex `^[a-zA-Z][a-zA-Z0-9_-]*$`. The old check accepted leading digits
  (e.g., `"123-invalid"` would strip the hyphen and pass `isalnum()`), so
  the "Reject invalid resource names" scenario was silently failing.
- Fix step patterns in `features/steps/resource_virtual_types_steps.py`:
  replace unsupported `{name!r}` parse-library syntax with literal-quoted
  `"{name}"` (confirmed via `parse.parse(...)` REPL that `!r` returns
  `None`); rename the over-broad `it should contain "{text}"` /
  `it should raise {error_type} with message containing "{message}"`
  patterns to specific forms that don't collide with steps in
  `execution_environment_steps.py` and `structural_validation_steps.py`;
  add try/except in the `When I compute the virtual resource` step so the
  exception-handling scenario can reach its `Then` step.
- Fix table headers in `features/resource_virtual_types.feature` so behave's
  table parser sees a proper `| name | value |` header row instead of
  treating the first data row as headers.
- Drop the now-unused E501 override for the deleted file from `pyproject.toml`.
- Add CHANGELOG.md entry under `[Unreleased]`.

Verified locally: unit_tests gate against `features/resource_virtual_types.feature`
passes 18/18 scenarios; lint and typecheck both green.

Refs: #8610
2026-06-04 04:23:37 -04:00
HAL9000 08e5fd4c01 fix(resources): resolve lint, type-safety, and test failures in virtual resource PR
- Remove # type: ignore from resource_virtual_types_steps.py (zero tolerance)
- Replace all eval() calls with ast.literal_eval() and _parse_lambda_body() helper
- Fix step mismatch: 'the complex computed value should be correct'
- Fix trailing whitespace and import ordering (W293, I001, RUF100)
- Fix B011 assert False -> raise AssertionError()
- Fix UP035/UP045/UP046 modernisation in domain model and resource virtual module
- Fix RUF022 __all__ sorting in resource/__init__.py
- Fix E501 long lines in virtual_resource.py via per-file-ignores
- Assign PR milestone to v3.6.0
2026-06-04 04:23:37 -04:00
HAL9000 00ff8b162b fix(resources): correct logger call in VirtualResource.compute() 2026-06-04 04:23:37 -04:00
HAL9000 abda05bd13 feat(resources): implement virtual resource type base class with examples
- Implement VirtualResource base class for abstract/computed resources
- Add MetricResource example for computed metrics
- Add APIEndpointResource example for API endpoints
- Implement comprehensive BDD tests for virtual resource types
- Full type annotations with Generic support
- Support for on-demand computation via compute_fn
- Support for kwargs passing to compute functions

Closes #8610
2026-06-04 04:23:37 -04:00
HAL9000 f6e84d384d feat(resources): implement virtual resource type base class for abstract/computed resources
- Implement VirtualResource base class with name, description, compute_fn, and metadata
- Implement MetricResource example for computed metrics with unit support
- Implement APIEndpointResource example for API endpoints with HTTP method support
- Add comprehensive BDD tests with 20+ scenarios covering all functionality
- Support on-demand computation via compute_fn callable
- Support metadata management with with_metadata() method
- Full type annotations and Pydantic validation
2026-06-04 04:23:37 -04:00