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

### Fixed

- Changing finding severities through a policy no longer clears an independent
quality-score threshold failure. A score below `--min-score` still fails.
- Tier 3 now uses one versioned, equal-weight five-dimension overall-score
policy across Harbor rewards, pass@k, Skill Lift, reports, comparisons, and
best-agent selection. Previously, some paths averaged all six evaluators
Expand Down
31 changes: 30 additions & 1 deletion src/skillevaluator/models/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ def incomplete_scans(self) -> list[str]:
return []
return [name for name in value if isinstance(name, str) and name]

@property
def gate_failures(self) -> list[str]:
"""Failed requirements independent of finding severity, such as a minimum score."""
value = self.metadata.get("gate_failures")
if not isinstance(value, list):
return []
return [message for message in value if isinstance(message, str) and message]

@property
def is_incomplete(self) -> bool:
"""Whether required validation evidence is missing or unusable."""
Expand Down Expand Up @@ -415,12 +423,16 @@ def recalculate_from_findings(self) -> None:

Call after mutating finding severities (e.g. LLM verification downgrade)
so that result state is consistent with the actual finding objects.
Independent gate failures remain errors regardless of those severities.
"""
self.errors.clear()
self.warnings.clear()
self.passed = not self.is_incomplete
self.summary.reset_finding_counts()

for message in self.gate_failures:
self.add_error(message)

for finding in self.findings:
sev = (
finding.severity if isinstance(finding.severity, Severity) else Severity(str(finding.severity).lower())
Expand Down Expand Up @@ -454,6 +466,14 @@ def add_warning(self, message: str) -> None:
self.warnings.append(message)
self.summary.warnings += 1

def fail_gate(self, message: str) -> None:
"""Record a failed requirement that severity overrides cannot waive."""
failures = self.gate_failures
if message not in failures:
failures.append(message)
self.metadata["gate_failures"] = failures
self.add_error(message)

def add_message(self, message: str) -> None:
"""Add an informational message.

Expand Down Expand Up @@ -487,9 +507,12 @@ def merge(self, other: ValidationResult) -> None:
# dict.update would let one sub-result's incomplete_scans clobber
# another's (e.g. bandit and semgrep both failing); concatenate.
incomplete = list(dict.fromkeys([*self.incomplete_scans, *other.incomplete_scans]))
gate_failures = [*self.gate_failures, *other.gate_failures]
self.metadata.update(other.metadata)
if incomplete:
self.metadata["incomplete_scans"] = incomplete
if gate_failures:
self.metadata["gate_failures"] = gate_failures

# Merge summary
self.summary.files_scanned += other.summary.files_scanned
Expand Down Expand Up @@ -538,14 +561,17 @@ def merge_with_prefix(self, other: ValidationResult, prefix: str) -> None:
incomplete = list(dict.fromkeys([*self.incomplete_scans, *other.incomplete_scans]))
if incomplete:
self.metadata["incomplete_scans"] = incomplete
gate_failures = [*self.gate_failures, *(f"[{prefix}] {message}" for message in other.gate_failures)]
if gate_failures:
self.metadata["gate_failures"] = gate_failures

# Merge summary
self.summary.errors += other.summary.errors
self.summary.warnings += other.summary.warnings

def to_dict(self) -> dict:
"""Convert to dictionary for JSON serialization."""
return {
result = {
"validator": self.validator_name,
"description": self.validator_description,
"passed": self.passed,
Expand All @@ -555,3 +581,6 @@ def to_dict(self) -> dict:
"findings": [f.to_dict() for f in self.findings],
"success_details": [s.to_dict() for s in self.success_details],
}
if self.gate_failures:
result["gate_failures"] = self.gate_failures
return result
4 changes: 3 additions & 1 deletion src/skillevaluator/validators/quality_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,9 @@ def _validate_single_skill(self, skill_path: Path) -> ValidationResult:

# Determine pass/fail based on min_score
if qs.overall_score < self.min_score:
result.passed = False
result.fail_gate(
Comment thread
rng1995 marked this conversation as resolved.
Resolved
f"Quality score {qs.overall_score:.1f}/100 is below the required {self.min_score}/100 in {manifest}"
)

result.metadata["quality_scores"] = qs.to_dict()

Expand Down
174 changes: 174 additions & 0 deletions tests/test_quality_policy_gate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Quality thresholds remain binding when policies reclassify findings."""

from pathlib import Path

import pytest
from click.testing import CliRunner

from skillevaluator.cli import cli
from skillevaluator.models.result import Finding, Severity, ValidationResult
from skillevaluator.validators.policy import ValidationPolicy, apply_policy
from skillevaluator.validators.quality_score import QualityScoreValidator


@pytest.fixture
def below_threshold_skill(tmp_path: Path) -> Path:
skill = tmp_path / "minimal-skill"
skill.mkdir()
(skill / "SKILL.md").write_text(
"---\n"
"name: minimal-skill\n"
"description: I can handle various things and stuff for your data documents and projects. "
"This general tool processes files and helps your workflow.\n"
"---\n"
"Short content.\n\n"
"## Instructions\n\n"
"The paradigm is synergy and awareness.\n",
encoding="utf-8",
)
return skill


def test_raising_efficiency_severity_keeps_cli_minimum_score_failure(
below_threshold_skill: Path, tmp_path: Path
) -> None:
result = QualityScoreValidator(min_score=70).validate(below_threshold_skill)
assert result.metadata["quality_scores"]["overall_score"] == 67.8
assert not result.passed
policy = tmp_path / "stricter-policy.yaml"
policy.write_text("severity_overrides:\n QUALITY.quality_efficiency: medium\n", encoding="utf-8")
args = [
"validate",
str(below_threshold_skill),
"--tiers",
"1",
"--checks",
"quality",
"--no-llm",
"-r",
"cli",
"-o",
str(tmp_path / "reports"),
]

runner = CliRunner()
default = runner.invoke(cli, args)
stricter = runner.invoke(cli, [*args, "--policy", str(policy)])

assert default.exit_code == 1, default.output
assert stricter.exit_code == 1, stricter.output
assert "[PASS] All validations passed" not in stricter.output
assert "67.8/100 is below the required 70/100" in stricter.output
Comment thread
rng1995 marked this conversation as resolved.
Resolved


def test_quality_minimum_survives_recalculation(below_threshold_skill: Path) -> None:
result = QualityScoreValidator(min_score=70).validate(below_threshold_skill)
errors = list(result.errors)

result.recalculate_from_findings()
result.recalculate_from_findings()

assert not result.passed
assert result.errors == errors
assert result.summary.errors == 1
assert result.to_dict()["gate_failures"] == result.gate_failures


def test_lowering_all_quality_severities_does_not_disable_minimum(below_threshold_skill: Path) -> None:
result = QualityScoreValidator(min_score=70).validate(below_threshold_skill)

apply_policy([result], ValidationPolicy(severity_overrides={"QUALITY.*": Severity.INFO}))

assert not result.passed


@pytest.mark.parametrize("merge_method", ["merge", "merge_with_prefix"])
def test_quality_minimum_survives_merged_results(below_threshold_skill: Path, merge_method: str) -> None:
parent = ValidationResult()
for min_score in (70, 80):
child = QualityScoreValidator(min_score=min_score).validate(below_threshold_skill)
if merge_method == "merge_with_prefix":
parent.merge_with_prefix(child, "minimal-skill")
else:
parent.merge(child)

apply_policy([parent], ValidationPolicy(severity_overrides={"QUALITY.quality_efficiency": Severity.MEDIUM}))

assert not parent.passed
assert len(parent.gate_failures) == 2
assert parent.summary.errors == 2
assert "required 70/100" in parent.errors[0]
assert "required 80/100" in parent.errors[1]


def test_folder_average_does_not_hide_a_skill_below_minimum(below_threshold_skill: Path) -> None:
good_skill = below_threshold_skill.parent / "good-skill"
good_skill.mkdir()
(good_skill / "SKILL.md").write_text(
"---\n"
"name: good-skill\n"
"description: Converts CSV documents to JSON. Use when converting tabular files.\n"
"version: 1.0.0\n"
"metadata:\n"
" author: Test User <test@example.com>\n"
" tags: [csv, json]\n"
"---\n"
"## Purpose\n\nConvert tabular data.\n\n"
"## Instructions\n\n1. Read the input file.\n2. Write the JSON output.\n\n"
"## Examples\n\n```text\ninput.csv -> output.json\n```\n\n"
"## Prerequisites\n\nNone.\n\n"
"## Limitations\n\nOnly CSV files are supported.\n\n"
"## Troubleshooting\n\nReport invalid input errors.\n",
encoding="utf-8",
)
result = QualityScoreValidator(min_score=70).validate(below_threshold_skill.parent)
assert result.metadata["quality_scores"]["overall_score"] > 70

apply_policy([result], ValidationPolicy(severity_overrides={"QUALITY.quality_efficiency": Severity.MEDIUM}))

assert not result.passed
assert len(result.gate_failures) == 1
assert result.gate_failures[0].startswith("[minimal-skill]")


def test_minimum_below_score_still_passes_after_policy(below_threshold_skill: Path) -> None:
result = QualityScoreValidator(min_score=67).validate(below_threshold_skill)

apply_policy([result], ValidationPolicy(severity_overrides={"QUALITY.quality_efficiency": Severity.MEDIUM}))

assert result.passed
assert "gate_failures" not in result.to_dict()


def test_quality_severity_waiver_still_passes_when_score_is_above_minimum(below_threshold_skill: Path) -> None:
manifest = below_threshold_skill / "SKILL.md"
manifest.write_text(manifest.read_text(encoding="utf-8").replace("name: minimal-skill", "name: Bad_Name"))
result = QualityScoreValidator(min_score=0).validate(below_threshold_skill)
assert not result.passed
assert result.metadata["quality_scores"]["overall_score"] > 0

apply_policy([result], ValidationPolicy(severity_overrides={"QUALITY.*": Severity.INFO}))

assert result.passed
assert result.errors == []


def test_policy_can_still_clear_a_severity_based_failure() -> None:
result = ValidationResult(validator_name="SCHEMA")
result.add_finding(
Finding(
category="SCHEMA",
severity=Severity.HIGH,
check_name="author_missing",
message="Missing author",
file_path="SKILL.md",
)
)

apply_policy([result], ValidationPolicy(severity_overrides={"SCHEMA.author_missing": Severity.INFO}))

assert result.passed
assert result.errors == []
Loading