Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ 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 fail validation without receiving a numeric quality score.
- `make lint` checks the whole repository, as CI does, instead of only `src` and `tests`, so a
lint error in `scripts/` or `ci/` no longer passes the documented local gate and then fails CI.
- Tier 2 deduplication verdict requests carry the documented output ceiling,
Expand Down
8 changes: 7 additions & 1 deletion src/skillevaluator/validators/quality_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,13 @@ def _validate_single_skill(self, skill_path: Path) -> ValidationResult:
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
73 changes: 73 additions & 0 deletions tests/validators/test_quality_manifest_read_errors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 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 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"])
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 != "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
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"]


def test_all_unreadable_members_do_not_produce_an_aggregate_grade(tmp_path):
_skill(tmp_path, "first", readable=False)
_skill(tmp_path, "second", readable=False)

result = QualityScoreValidator().validate(tmp_path)

assert result.passed is False
assert len(result.gate_failures) == 2
assert "quality_scores" not in result.metadata
assert "quality_scores_all" not in result.metadata