feat(resource): add deferred virtual resource types
CI / benchmark-publish (pull_request) Has been skipped
CI / build (pull_request) Successful in 20s
CI / lint (pull_request) Successful in 23s
CI / typecheck (pull_request) Successful in 45s
CI / quality (pull_request) Successful in 45s
CI / security (pull_request) Successful in 57s
CI / unit_tests (pull_request) Successful in 2m56s
CI / docker (pull_request) Successful in 55s
CI / e2e_tests (pull_request) Successful in 3m59s
CI / integration_tests (pull_request) Successful in 5m36s
CI / coverage (pull_request) Successful in 6m59s
CI / benchmark-regression (pull_request) Successful in 40m39s

Add 3 deferred virtual resource types (remote, submodule, symlink) with
equivalence metadata for physical-to-virtual resource linking.

Depends on: #662 (child_types reference types introduced by #662)

- Type definitions extracted to _resource_registry_virtual_deferred.py
  for consistency with _resource_registry_virtual.py (#329)
- YAML configs with equivalence criteria per spec, spec reference comments
- Bootstrap registration via BUILTIN_TYPES spread, hidden from
  resource add scaffolding (user_addable: false)
- Equivalence structural validation in ResourceTypeSpec model validator:
  criteria must be a non-empty list of non-empty strings; virtual types
  must have sandbox_strategy=none, user_addable=false, handler=None,
  all capabilities false
- Behave tests (52 scenarios), Robot tests (7), ASV benchmarks
- DB roundtrip tests verifying virtual types survive bootstrap persistence
- Negative tests: missing equivalence/name/kind, manual add rejection
  for all 3 virtual types (register_resource guard), invalid criteria
  elements (non-string, empty string)

ISSUES CLOSED: #331
This commit is contained in:
2026-03-10 00:19:59 +00:00
parent 3618bf4f7e
commit 5d6cb099ad
16 changed files with 1534 additions and 16 deletions
@@ -0,0 +1,116 @@
"""ASV benchmarks for deferred virtual resource type loading (#331).
Benchmarks cover YAML schema loading, domain model creation via
``ResourceTypeSpec.from_config``, and ``as_cli_dict`` rendering for the
three deferred virtual types: remote, submodule, symlink.
"""
from __future__ import annotations
from pathlib import Path
from typing import Any
_EXAMPLES_DIR = Path(__file__).resolve().parent.parent / "examples" / "resource-types"
_REMOTE_YAML = _EXAMPLES_DIR / "remote.yaml"
_SUBMODULE_YAML = _EXAMPLES_DIR / "submodule.yaml"
_SYMLINK_YAML = _EXAMPLES_DIR / "symlink.yaml"
class TimeDeferredVirtualSchemaLoad:
"""Benchmark deferred virtual resource type YAML schema loading."""
def setup(self) -> None:
"""Set up schema class and file paths."""
from cleveragents.resource.schema import ResourceTypeConfigSchema
self.schema_cls = ResourceTypeConfigSchema
self.remote_path = _REMOTE_YAML
self.submodule_path = _SUBMODULE_YAML
self.symlink_path = _SYMLINK_YAML
def time_load_remote_schema(self) -> None:
"""Benchmark loading remote.yaml via schema loader."""
self.schema_cls.from_yaml_file(self.remote_path)
def time_load_submodule_schema(self) -> None:
"""Benchmark loading submodule.yaml via schema loader."""
self.schema_cls.from_yaml_file(self.submodule_path)
def time_load_symlink_schema(self) -> None:
"""Benchmark loading symlink.yaml via schema loader."""
self.schema_cls.from_yaml_file(self.symlink_path)
def time_load_all_deferred_virtual_schemas(self) -> None:
"""Benchmark loading all three deferred virtual type schemas."""
self.schema_cls.from_yaml_file(self.remote_path)
self.schema_cls.from_yaml_file(self.submodule_path)
self.schema_cls.from_yaml_file(self.symlink_path)
class TimeDeferredVirtualDomainModelLoad:
"""Benchmark deferred virtual resource type domain model creation."""
def setup(self) -> None:
"""Set up ResourceTypeSpec and parsed configs."""
import yaml
from cleveragents.domain.models.core.resource_type import ResourceTypeSpec
self.spec_cls = ResourceTypeSpec
with open(_REMOTE_YAML) as f:
self.remote_config: dict[str, Any] = yaml.safe_load(f)
with open(_SUBMODULE_YAML) as f:
self.submodule_config: dict[str, Any] = yaml.safe_load(f)
with open(_SYMLINK_YAML) as f:
self.symlink_config: dict[str, Any] = yaml.safe_load(f)
def time_remote_from_config(self) -> None:
"""Benchmark creating remote ResourceTypeSpec from config."""
self.spec_cls.from_config(self.remote_config)
def time_submodule_from_config(self) -> None:
"""Benchmark creating submodule ResourceTypeSpec from config."""
self.spec_cls.from_config(self.submodule_config)
def time_symlink_from_config(self) -> None:
"""Benchmark creating symlink ResourceTypeSpec from config."""
self.spec_cls.from_config(self.symlink_config)
def time_all_deferred_virtual_from_config(self) -> None:
"""Benchmark creating all three deferred virtual specs."""
self.spec_cls.from_config(self.remote_config)
self.spec_cls.from_config(self.submodule_config)
self.spec_cls.from_config(self.symlink_config)
class TimeDeferredVirtualCliDict:
"""Benchmark as_cli_dict rendering for deferred virtual types."""
def setup(self) -> None:
"""Set up pre-built ResourceTypeSpec instances."""
import yaml
from cleveragents.domain.models.core.resource_type import ResourceTypeSpec
with open(_REMOTE_YAML) as f:
remote_cfg: dict[str, Any] = yaml.safe_load(f)
with open(_SUBMODULE_YAML) as f:
submodule_cfg: dict[str, Any] = yaml.safe_load(f)
with open(_SYMLINK_YAML) as f:
symlink_cfg: dict[str, Any] = yaml.safe_load(f)
self.remote_spec = ResourceTypeSpec.from_config(remote_cfg)
self.submodule_spec = ResourceTypeSpec.from_config(submodule_cfg)
self.symlink_spec = ResourceTypeSpec.from_config(symlink_cfg)
def time_remote_cli_dict(self) -> None:
"""Benchmark remote as_cli_dict rendering."""
self.remote_spec.as_cli_dict()
def time_submodule_cli_dict(self) -> None:
"""Benchmark submodule as_cli_dict rendering."""
self.submodule_spec.as_cli_dict()
def time_symlink_cli_dict(self) -> None:
"""Benchmark symlink as_cli_dict rendering."""
self.symlink_spec.as_cli_dict()