Files
cleveragents-core/features/resource_cli_coverage_boost.feature
hamza.khyari bb8175aa11 feat(resource): add resource type inheritance and polymorphic tool matching
Implement ADR-042 single-inheritance for resource types with polymorphic
tool and handler resolution.

Core changes:
- Add `inherits` field to ResourceTypeConfigSchema, ResourceTypeSpec, and
  ResourceTypeModel with chain depth validation (max 5), circular
  inheritance detection, and built-in-from-custom guard
- New inheritance.py module (390 lines): resolve_inheritance_chain(),
  validate_chain(), is_subtype_of(), resolve_fields(), find_subtypes()
- Wire inheritance into ResourceRegistryService: chain validation on
  register_type(), resolve_type_inheritance_chain(), is_subtype_of()
- Add find_tools_for_resource() to ToolRegistry with polymorphic matching
  that walks the inheritance chain
- Add resolve_handler_polymorphic() to handler resolver
- Alembic migration m6_004_resource_type_inherits adds inherits column
  and index to resource_types table

CLI changes:
- `agents resource type list` shows Inherits column
- `agents resource type show` displays inheritance chain

Tests:
- 30 BDD scenarios in resource_type_inheritance.feature (all pass)
- 18 Robot Framework test cases
- 14 ASV benchmark timing methods across 4 suites

Docs:
- docs/reference/resource_type_inheritance.md (full reference)
- Updated docs/schema/resource_type.schema.yaml
- CHANGELOG entry for #513

ISSUES CLOSED: #513
2026-03-10 03:39:32 +00:00

68 lines
3.3 KiB
Gherkin

Feature: Resource CLI coverage boost for remaining uncovered lines
As a developer
I want edge-case paths in resource.py thoroughly tested
So that the line-rate and branch-rate improve beyond 0.93 / 0.88
# ---- _get_registry_service (lines 79-81) ----
Scenario: _get_registry_service delegates to the DI container
Given the DI container is mocked for resource registry
When _get_registry_service is called directly
Then the returned service should be the mock registry service
# ---- type_add --update re-raises ValidationError (line 181) ----
Scenario: type_add --update re-raises ValidationError whose message lacks "already exists"
Given a mock resource service that raises a non-already-exists ValidationError on register_type
When I invoke type add with update flag via CliRunner
Then the CliRunner exit code should be non-zero
And the CliRunner output should contain "Validation error"
# ---- type_add FileNotFoundError (lines 193-195) ----
Scenario: type_add catches FileNotFoundError from service
Given a mock resource service that raises FileNotFoundError on register_type
When I invoke type add with a dummy config via CliRunner
Then the CliRunner exit code should be non-zero
And the CliRunner output should contain "Config file not found"
# ---- type_remove confirm declined (lines 234-236) ----
Scenario: type_remove aborts when user declines confirmation prompt
Given a mock resource service with a removable custom type
When I invoke type remove without --yes and answer no via CliRunner
Then the CliRunner exit code should be non-zero
And the CliRunner output should contain "Aborted"
# ---- type_remove NotFoundError from service (lines 263-265) ----
Scenario: type_remove aborts when service.remove_type raises NotFoundError
Given a mock resource service whose remove_type raises NotFoundError
When I invoke type remove with --yes via CliRunner for the phantom type
Then the CliRunner exit code should be non-zero
And the CliRunner output should contain "Resource type not found"
# ---- type_remove ValidationError from service (lines 269-271) ----
Scenario: type_remove aborts when service.remove_type raises ValidationError
Given a mock resource service whose remove_type raises ValidationError
When I invoke type remove with --yes via CliRunner for the failing type
Then the CliRunner exit code should be non-zero
And the CliRunner output should contain "Error:"
# ---- resource_remove edge_count > 0 (lines 653-658) ----
Scenario: resource_remove aborts when resource has edges
Given a mock resource service whose session reports edges on the resource
When I invoke resource remove with --yes via CliRunner for the edged resource
Then the CliRunner exit code should be non-zero
And the CliRunner output should contain "edge(s) still reference it"
# ---- resource_remove generic Exception rollback (lines 668-672) ----
Scenario: resource_remove rolls back session on unexpected exception
Given a mock resource service whose session delete raises a generic exception for resource
When I invoke resource remove with --yes via CliRunner for the failing resource
Then the CliRunner exit code should be non-zero
And the mock session rollback should have been called for resource remove