Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ All notable changes to SkillEvaluator are documented in this file.

### Fixed

- Quality scoring reports unreadable or non-UTF-8 manifests per skill and
keeps quality results for healthy members of the same directory. Unreadable
members, including manifests that disappear after discovery, fail validation
without receiving a numeric quality score.
- Tier 3 grading now credits successful Hermes skill reads and shell commands in
trajectories from other runners. OpenCode file reads, writes, and edits keep
their paths and replacement text in grading evidence. An unfinished Hermes
Expand Down
9 changes: 7 additions & 2 deletions src/skillevaluator/validators/quality_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,15 @@ def _validate_single_skill(self, skill_path: Path) -> ValidationResult:
file_path=str(skill_path),
)
)
result.metadata["quality_scores"] = qs.to_dict()
return result

content = manifest.read_text(encoding="utf-8-sig")
try:
content = manifest.read_text(encoding="utf-8-sig")
except (OSError, UnicodeError) as exc:
result.fail_gate(
f"Cannot compute quality score for {manifest}: could not read the manifest as UTF-8 text ({exc})"
)
return result
lines = content.split("\n")

try:
Expand Down
43 changes: 40 additions & 3 deletions tests/test_precommit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import subprocess
import sys
from pathlib import Path
from typing import TYPE_CHECKING

import pytest
import yaml
Expand All @@ -25,6 +26,9 @@
)
from skillevaluator.tier1.commands import run_quality_check

if TYPE_CHECKING:
from skillevaluator.models.result import ValidationResult

REPO = Path(__file__).resolve().parents[1]

_VALID_SKILL_MD = """\
Expand Down Expand Up @@ -324,7 +328,7 @@ def test_precommit_fails_when_an_earlier_skill_fails(tmp_path: Path) -> None:
assert lines[1] == "PASS valid-skill schema"


def test_precommit_reports_skill_that_raises_and_checks_the_rest(tmp_path: Path) -> None:
def test_precommit_reports_unreadable_manifest_and_checks_the_rest(tmp_path: Path) -> None:
broken = tmp_path / "latin1-skill"
broken.mkdir()
text = _VALID_SKILL_MD.format(name="latin1-skill", title="Caf\u00e9 Skill")
Expand All @@ -337,8 +341,41 @@ def test_precommit_reports_skill_that_raises_and_checks_the_rest(tmp_path: Path)

assert code == 1
assert len(lines) == 2
assert lines[0].startswith("FAIL latin1-skill quality error: UnicodeDecodeError: ")
assert lines[1].startswith("PASS valid-skill quality")
assert lines[0].startswith(
f"FAIL latin1-skill quality Cannot compute quality score for {broken / 'SKILL.md'}: "
"could not read the manifest as UTF-8 text ("
)
assert "'utf-8' codec can't decode byte 0xe9" in lines[0]
assert "/100" not in lines[0]
assert re.fullmatch(r"PASS valid-skill quality \d+\.\d/100", lines[1])


def test_precommit_reports_skill_that_raises_and_checks_the_rest(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
broken = _write_skill(tmp_path, "broken-skill")
valid = _write_skill(tmp_path, "valid-skill")
checked: list[Path] = []

def raise_for_broken_skill(
skill_root: Path, *, min_score: int, quality_config: Path | None = None
) -> list[ValidationResult]:
checked.append(skill_root)
if skill_root == broken:
raise RuntimeError("unexpected validator failure")
return run_quality_check(skill_root, min_score=min_score, quality_config=quality_config)

monkeypatch.setattr("skillevaluator.precommit.run_quality_check", raise_for_broken_skill)

code, lines = run_precommit(
"quality", [str(broken / "SKILL.md"), str(valid / "SKILL.md")], min_score=0, cwd=tmp_path
)

assert code == 1
assert checked == [broken, valid]
assert len(lines) == 2
assert lines[0] == "FAIL broken-skill quality error: RuntimeError: unexpected validator failure"
assert re.fullmatch(r"PASS valid-skill quality \d+\.\d/100", lines[1])


def test_skill_root_finds_repo_root_skill_from_relative_path(tmp_path: Path) -> None:
Expand Down
103 changes: 103 additions & 0 deletions tests/validators/test_quality_manifest_read_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""One unreadable manifest must not discard quality results for other skills."""

from __future__ import annotations

from pathlib import Path

import pytest

from skillevaluator.validators.quality_score import QualityScoreValidator


def _skill(root, name, *, readable=True):
skill = root / name
skill.mkdir()
content = f"---\nname: {name}\ndescription: Use when checking a valid skill.\n---\n# Instructions\n"
(skill / "SKILL.md").write_bytes(content.encode("utf-8") + (b"" if readable else b"\xff"))
return skill


def _unlink_after_discovery(validator, monkeypatch, manifests):
original = validator._find_all_skills

def discover(root):
skills = original(root)
for manifest in manifests:
manifest.unlink()
return skills

monkeypatch.setattr(validator, "_find_all_skills", discover)


def test_invalid_utf8_manifest_fails_without_a_quality_grade(tmp_path):
skill = _skill(tmp_path, "broken", readable=False)

result = QualityScoreValidator().validate(skill)

assert result.passed is False
assert any(str(skill / "SKILL.md") in reason and "read" in reason for reason in result.gate_failures)
assert "quality_scores" not in result.metadata
assert "quality_config" in result.metadata
assert not any(detail.check_name == "quality_score" for detail in result.success_details)


@pytest.mark.parametrize("failure", ["encoding", "permission", "disappeared", "disappeared_before_lookup"])
def test_unreadable_member_keeps_healthy_quality_results(tmp_path, monkeypatch, failure):
broken = _skill(tmp_path, "broken", readable=failure != "encoding")
healthy = _skill(tmp_path, "healthy")
validator = QualityScoreValidator()
expected = validator.validate(healthy).metadata["quality_scores"]
manifest = broken / "SKILL.md"

if failure == "disappeared_before_lookup":
_unlink_after_discovery(validator, monkeypatch, [manifest])
elif failure != "encoding":
original = Path.read_text

def fail_read(path, *args, **kwargs):
if path == manifest:
if failure == "permission":
raise PermissionError("manifest is not readable")
raise FileNotFoundError("manifest disappeared after discovery")
return original(path, *args, **kwargs)

monkeypatch.setattr(Path, "read_text", fail_read)

result = validator.validate(tmp_path)

assert result.passed is False
if failure == "disappeared_before_lookup":
assert not manifest.exists()
assert any(
finding.check_name == "skill_manifest"
and finding.message == "SKILL.md not found"
and str(broken) in finding.file_path
for finding in result.findings
)
else:
assert any("[broken]" in reason and str(manifest) in reason for reason in result.gate_failures)
assert result.metadata["quality_scores_all"] == [expected]
assert result.metadata["quality_scores"]["skill_count"] == 1
assert result.metadata["quality_scores"]["overall_score"] == expected["overall_score"]


@pytest.mark.parametrize("failure", ["encoding", "disappeared_before_lookup"])
def test_all_unreadable_members_do_not_produce_an_aggregate_grade(tmp_path, monkeypatch, failure):
members = [_skill(tmp_path, name, readable=failure != "encoding") for name in ("first", "second")]
validator = QualityScoreValidator()
if failure == "disappeared_before_lookup":
_unlink_after_discovery(validator, monkeypatch, [member / "SKILL.md" for member in members])

result = validator.validate(tmp_path)

assert result.passed is False
if failure == "disappeared_before_lookup":
assert all(not (member / "SKILL.md").exists() for member in members)
assert [finding.message for finding in result.findings] == ["SKILL.md not found"] * 2
else:
assert len(result.gate_failures) == 2
assert "quality_scores" not in result.metadata
assert "quality_scores_all" not in result.metadata
Loading