Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to SkillEvaluator are documented in this file.

## Unreleased

### Fixed
Comment thread
rng1995 marked this conversation as resolved.
Resolved

- Report non-string YAML frontmatter keys, including keys under `metadata`,
as validation errors in rules and workflows instead of raising a `TypeError`.

### Added

- Transparent HTTP 429 (rate-limiting), transient 5xx, and timeout recovery for
Expand Down
2 changes: 1 addition & 1 deletion src/skillevaluator/models/field_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@ def parse_nested_model(model_class: type, v: Any, error_message: str | None = No
raise ValueError(error_message)
return None
if isinstance(v, dict):
return model_class(**v)
return model_class.model_validate(v)
Comment thread
rng1995 marked this conversation as resolved.
Resolved
return v
2 changes: 1 addition & 1 deletion src/skillevaluator/validators/frontmatter_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def validate_pydantic_model(
from pydantic import ValidationError

try:
return model_class(**data)
return model_class.model_validate(data)
Comment thread
rng1995 marked this conversation as resolved.
Resolved
except ValidationError as e:
for error in e.errors():
field = ".".join(str(loc) for loc in error["loc"])
Comment thread
rng1995 marked this conversation as resolved.
Resolved
Expand Down
28 changes: 28 additions & 0 deletions tests/validators/test_rules_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ def test_validate_valid_rule(self, validator: RulesSchemaValidator, valid_rule_f
assert result.passed, f"Expected validation to pass. Errors: {result.errors}"
assert any("python-standards" in msg.lower() for msg in result.messages)

@pytest.mark.parametrize("key", ["123", "true", "null", "2026-01-01"])
def test_non_string_frontmatter_key_returns_validation_error(self, validator, valid_rule_file, key):
content = valid_rule_file.read_text()
valid_rule_file.write_text(content.replace("---\n", f"---\n{key}: extra value\n", 1))

result = validator.validate(valid_rule_file)

assert not result.passed
assert any("Keys should be strings" in error for error in result.errors)

def test_string_extra_frontmatter_key_is_preserved(self, validator, valid_rule_file):
content = valid_rule_file.read_text()
valid_rule_file.write_text(content.replace("---\n", '---\n"123": extra value\n', 1))

result = validator.validate(valid_rule_file)

assert result.passed, result.errors
assert result.metadata["frontmatter"].model_extra["123"] == "extra value"

def test_non_string_metadata_key_returns_validation_error(self, validator, valid_rule_file):
content = valid_rule_file.read_text()
valid_rule_file.write_text(content.replace("metadata:\n", "metadata:\n 123: extra value\n", 1))

result = validator.validate(valid_rule_file)

assert not result.passed
assert any("metadata" in error and "Keys should be strings" in error for error in result.errors)

def test_validate_missing_required_fields(
self, validator: RulesSchemaValidator, invalid_rule_missing_required: Path
):
Expand Down
21 changes: 21 additions & 0 deletions tests/validators/test_workflows_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,27 @@ def test_validate_valid_workflow(self, validator: WorkflowsSchemaValidator, vali
assert result.passed, f"Expected validation to pass. Errors: {result.errors}"
assert any("fastapi-setup" in msg.lower() for msg in result.messages)

@pytest.mark.parametrize("relative_path", ["workflow-rules.mdc", "references/api-design.mdc"])
def test_non_string_frontmatter_key_returns_validation_error(self, validator, valid_workflow_dir, relative_path):
manifest = valid_workflow_dir / relative_path
content = manifest.read_text()
manifest.write_text(content.replace("---\n", "---\n123: extra value\n", 1))

result = validator.validate(valid_workflow_dir)

assert not result.passed
assert any("Keys should be strings" in error for error in result.errors)

def test_non_string_metadata_key_returns_validation_error(self, validator, valid_workflow_dir):
manifest = valid_workflow_dir / "workflow-rules.mdc"
content = manifest.read_text()
manifest.write_text(content.replace("metadata:\n", "metadata:\n 123: extra value\n", 1))

result = validator.validate(valid_workflow_dir)

assert not result.passed
assert any("metadata" in error and "Keys should be strings" in error for error in result.errors)

def test_validate_missing_readme(self, validator: WorkflowsSchemaValidator, incomplete_workflow_dir: Path):
"""Test validation fails when README.md is missing."""
result = validator.validate(incomplete_workflow_dir)
Expand Down
Loading