[BUG] ResourceTypeConfigSchema does not enforce equivalence.criteria for virtual types — inconsistent validation with domain model layer #9138

Open
opened 2026-04-14 08:31:33 +00:00 by HAL9000 · 1 comment
Owner

Metadata

  • Commit Message: fix(resources): enforce equivalence.criteria validation in ResourceTypeConfigSchema for virtual types
  • Branch: fix/resource-type-schema-virtual-equivalence-criteria

Background and Context

Virtual resource types require an equivalence configuration with a criteria list per the spec and the domain model validator in _resource_type_validation.py. However, the YAML-layer schema class ResourceTypeConfigSchema (in src/cleveragents/resource/schema.py) only checks that equivalence is not None — it does not validate the presence or content of the criteria key.

This means a virtual resource type YAML file can pass ResourceTypeConfigSchema.from_yaml() validation with an equivalence: {} or equivalence: {description: "foo"} (missing criteria), but will then fail at the domain model layer when ResourceTypeSpec.from_config() calls _validate_virtual_type().

The two validation layers are inconsistent: the YAML schema layer is more permissive than the domain model layer, causing confusing late failures.

Current Behavior

ResourceTypeConfigSchema cross-field validator (validate_cross_fields):

if self.resource_kind == "virtual" and self.equivalence is None:
    raise ValueError(...)

Only checks equivalence is not None. An equivalence: {} dict passes this check.

_resource_type_validation.validate_virtual_type() (domain model layer):

if equivalence is None:
    raise ValueError(...)
if "criteria" not in equivalence:
    raise ValueError(...)
criteria = equivalence["criteria"]
if not isinstance(criteria, list) or len(criteria) == 0:
    raise ValueError(...)

Requires criteria to be a non-empty list.

Expected Behavior

ResourceTypeConfigSchema.from_yaml() should enforce the same equivalence.criteria rules as the domain model layer, so that invalid virtual type YAML files are rejected at the earliest possible point with a clear error message.

Acceptance Criteria

  • ResourceTypeConfigSchema validates that virtual types have equivalence.criteria as a non-empty list of strings
  • A virtual type YAML with equivalence: {} raises ValidationError from ResourceTypeConfigSchema.from_yaml()
  • A virtual type YAML with equivalence: {criteria: []} raises ValidationError from ResourceTypeConfigSchema.from_yaml()
  • A virtual type YAML with equivalence: {criteria: ["content_hash"]} passes validation
  • Tests (Behave): Add scenarios for each invalid equivalence configuration

Supporting Information

  • src/cleveragents/resource/schema.pyResourceTypeConfigSchema.validate_cross_fields()
  • src/cleveragents/domain/models/core/_resource_type_validation.pyvalidate_virtual_type()
  • Spec: "Virtual types require equivalence configuration for deduplication"

Subtasks

  • Add criteria validation to ResourceTypeConfigSchema.validate_cross_fields() for virtual types
  • Ensure error messages match the domain model layer messages for consistency
  • Tests (Behave): Add scenarios for missing/empty criteria in virtual type YAML
  • Verify coverage >=97% via nox -s coverage_report
  • Run nox (all default sessions), fix any errors

Definition of Done

This issue is complete when:

  • All subtasks above are completed and checked off.
  • A Git commit is created where the first line of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation.
  • The commit is pushed to the remote on the branch matching the Branch in Metadata exactly.
  • The commit is submitted as a pull request to master, reviewed, and merged before this issue is marked done.

Automated by CleverAgents Bot
Supervisor: UAT Test Pool | Agent: uat-test-pool-supervisor

## Metadata - **Commit Message**: `fix(resources): enforce equivalence.criteria validation in ResourceTypeConfigSchema for virtual types` - **Branch**: `fix/resource-type-schema-virtual-equivalence-criteria` ## Background and Context Virtual resource types require an `equivalence` configuration with a `criteria` list per the spec and the domain model validator in `_resource_type_validation.py`. However, the YAML-layer schema class `ResourceTypeConfigSchema` (in `src/cleveragents/resource/schema.py`) only checks that `equivalence` is not `None` — it does not validate the presence or content of the `criteria` key. This means a virtual resource type YAML file can pass `ResourceTypeConfigSchema.from_yaml()` validation with an `equivalence: {}` or `equivalence: {description: "foo"}` (missing `criteria`), but will then fail at the domain model layer when `ResourceTypeSpec.from_config()` calls `_validate_virtual_type()`. The two validation layers are inconsistent: the YAML schema layer is more permissive than the domain model layer, causing confusing late failures. ## Current Behavior `ResourceTypeConfigSchema` cross-field validator (`validate_cross_fields`): ```python if self.resource_kind == "virtual" and self.equivalence is None: raise ValueError(...) ``` Only checks `equivalence is not None`. An `equivalence: {}` dict passes this check. `_resource_type_validation.validate_virtual_type()` (domain model layer): ```python if equivalence is None: raise ValueError(...) if "criteria" not in equivalence: raise ValueError(...) criteria = equivalence["criteria"] if not isinstance(criteria, list) or len(criteria) == 0: raise ValueError(...) ``` Requires `criteria` to be a non-empty list. ## Expected Behavior `ResourceTypeConfigSchema.from_yaml()` should enforce the same `equivalence.criteria` rules as the domain model layer, so that invalid virtual type YAML files are rejected at the earliest possible point with a clear error message. ## Acceptance Criteria - [ ] `ResourceTypeConfigSchema` validates that virtual types have `equivalence.criteria` as a non-empty list of strings - [ ] A virtual type YAML with `equivalence: {}` raises `ValidationError` from `ResourceTypeConfigSchema.from_yaml()` - [ ] A virtual type YAML with `equivalence: {criteria: []}` raises `ValidationError` from `ResourceTypeConfigSchema.from_yaml()` - [ ] A virtual type YAML with `equivalence: {criteria: ["content_hash"]}` passes validation - [ ] Tests (Behave): Add scenarios for each invalid equivalence configuration ## Supporting Information - `src/cleveragents/resource/schema.py` — `ResourceTypeConfigSchema.validate_cross_fields()` - `src/cleveragents/domain/models/core/_resource_type_validation.py` — `validate_virtual_type()` - Spec: "Virtual types require equivalence configuration for deduplication" ## Subtasks - [ ] Add `criteria` validation to `ResourceTypeConfigSchema.validate_cross_fields()` for virtual types - [ ] Ensure error messages match the domain model layer messages for consistency - [ ] Tests (Behave): Add scenarios for missing/empty criteria in virtual type YAML - [ ] Verify coverage >=97% via `nox -s coverage_report` - [ ] Run `nox` (all default sessions), fix any errors ## Definition of Done This issue is complete when: - All subtasks above are completed and checked off. - A Git commit is created where the **first line** of the commit message matches the Commit Message in Metadata exactly, followed by a blank line, then additional lines providing relevant details about the implementation. - The commit is pushed to the remote on the branch matching the **Branch** in Metadata exactly. - The commit is submitted as a **pull request** to `master`, reviewed, and **merged** before this issue is marked done. --- **Automated by CleverAgents Bot** Supervisor: UAT Test Pool | Agent: uat-test-pool-supervisor
HAL9000 added this to the v3.2.0 milestone 2026-04-14 08:50:07 +00:00
Author
Owner

Triage: Verified [AUTO-OWNR-1]

Valid bug: ResourceTypeConfigSchema does not enforce equivalence.criteria for virtual types, creating an inconsistency with the domain model layer validation. This is a validation gap that could allow invalid configurations.

Assigning to v3.2.0 as resource type management is a core M3 feature. Priority Medium — validation inconsistency.

MoSCoW: Should Have — consistent validation across schema and domain model layers is important for data integrity.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Triage: Verified** [AUTO-OWNR-1] Valid bug: `ResourceTypeConfigSchema` does not enforce `equivalence.criteria` for virtual types, creating an inconsistency with the domain model layer validation. This is a validation gap that could allow invalid configurations. Assigning to **v3.2.0** as resource type management is a core M3 feature. Priority **Medium** — validation inconsistency. MoSCoW: **Should Have** — consistent validation across schema and domain model layers is important for data integrity. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#9138
No description provided.