Skip to content

Multi-tier framework for evaluating AI agent skills and plugins with quality gates, security scanning, harness compatibility checks, semantic overlap detection, synthetic evaluation dataset generation, and live agent evaluation that measures how skills affect agent behavior. Ships reusable CI templates that bring every check to any repository.

5.3 KB
Raw Blame
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""report.html leads with the case-based verdict and fixes shared with the CLI."""

import json

from tests.reporting.test_resource_comparison import write_arm

from skillevaluator.evaluation.tier3_report import render_agent_eval_html_report
from skillevaluator.tier3.harbor.metrics import DEFAULT_METRICS


def _run(tmp_path, *, goal_accuracy: float):
    run = tmp_path / "run"
    trial = write_arm(run, "with-skill", 10, 3)
    write_arm(run, "without-skill", 20, 5)
    reward = {
        "entry_id": "case",
        "trial_id": "case__1",
        **dict.fromkeys(DEFAULT_METRICS, 1.0),
        "goal_accuracy": goal_accuracy,
    }
    reward["details"] = {"goal_accuracy": {"reason": "no report", "end_state": "asked for the data"}}
    (trial / "reward.json").write_text(json.dumps(reward))

    def condition(passed):
        attempt = {"attempt": 1, "trial": "case__1", "score": 0.9 if passed else 0.2, "passed": passed}
        return {
            "k": 1,
            "cases": {
                "case": {
                    "passed": passed,
                    "attempts_used": 1,
                    "attempts": [attempt],
                }
            },
        }

    agent = {"pass_at_k": {"with_skill": condition(True), "without_skill": condition(False)}}
    for arm, passed in (("with-skill", True), ("without-skill", False)):
        summary = json.loads((run / "opencode" / arm / "summary.json").read_text())
        (run / "opencode" / arm / "summary.json").write_text(json.dumps({**summary, "pass_at_k": condition(passed)}))
    (run / "result.json").write_text(json.dumps({"agents": {"opencode": agent}}))
    return run


def test_report_leads_with_skill_effect_and_goal_not_met_fix(tmp_path) -> None:
    run = _run(tmp_path, goal_accuracy=0.0)

    html = render_agent_eval_html_report(tmp_path, run, use_llm_judge=False).read_text(encoding="utf-8")

    [fix] = json.loads((run / "what_to_fix.json").read_text())
    assert fix["kind"] == "goal not met"
    assert (
        "per-case result: skill helps (opencode +100 pp). 1 passing with-skill attempt(s) did not meet the goal" in html
    )
    assert "1 issue to fix, most attempts lost first:" in html
    assert '<span class="t3-sug-cat">goal not met</span>' in html
    assert "passed on the other metrics but scored goal accuracy 0.00: asked for the data." in html
    assert "Evidence: opencode/with-skill/trials/case__1/trajectory.json" in html
    assert "FAIL</span> goal not met (goal accuracy 0.00)" in html


def test_report_says_nothing_to_fix_when_every_case_passes_and_meets_its_goal(tmp_path) -> None:
    run = _run(tmp_path, goal_accuracy=1.0)

    html = render_agent_eval_html_report(tmp_path, run, use_llm_judge=False).read_text(encoding="utf-8")

    assert json.loads((run / "what_to_fix.json").read_text()) == []
    assert "Nothing to fix in the available case evidence." in html
    assert "goal not met (goal accuracy 0.00)" not in html


def test_goal_flags_keep_agent_identity_when_trial_names_repeat(tmp_path) -> None:
    import re
    import shutil

    run = _run(tmp_path, goal_accuracy=0.0)
    shutil.copytree(run / "opencode", run / "z-other")
    reward_path = run / "z-other" / "with-skill" / "trials" / "case__1" / "reward.json"
    reward = json.loads(reward_path.read_text())
    reward["goal_accuracy"] = 1.0
    reward_path.write_text(json.dumps(reward))
    source = json.loads((run / "result.json").read_text())
    source["agents"]["z-other"] = source["agents"]["opencode"]
    (run / "result.json").write_text(json.dumps(source))

    html = render_agent_eval_html_report(tmp_path, run, use_llm_judge=False).read_text(encoding="utf-8")
    attempts = html.split('id="t3-attempts-table"', 1)[1].split("</table>", 1)[0]
    rows = re.findall(r"<tr>(.*?)</tr>", attempts, flags=re.DOTALL)
    missed = [row for row in rows if "goal not met (goal accuracy 0.00)" in row]
    assert len(missed) == 1
    assert "opencode" in missed[0] and "With skill" in missed[0]


def test_goal_count_includes_passes_in_a_case_with_other_failed_attempts(tmp_path) -> None:
    run = _run(tmp_path, goal_accuracy=0.0)
    source = json.loads((run / "result.json").read_text())
    case = source["agents"]["opencode"]["pass_at_k"]["with_skill"]["cases"]["case"]
    case["attempts"].append({"attempt": 2, "trial": "case__2", "score": 0.2, "passed": False})
    (run / "result.json").write_text(json.dumps(source))
    html = render_agent_eval_html_report(tmp_path, run, use_llm_judge=False).read_text(encoding="utf-8")
    assert "1 passing with-skill attempt(s) did not meet the goal" in html


def test_truncated_attempt_details_do_not_invent_an_attempts_passed_count(tmp_path) -> None:
    run = _run(tmp_path, goal_accuracy=1.0)
    for arm in ("with-skill", "without-skill"):
        summary_path = run / "opencode" / arm / "summary.json"
        summary = json.loads(summary_path.read_text())
        summary["pass_at_k"]["attempts_used"] = 4
        summary["pass_at_k"]["cases"]["case"]["attempt_details_truncated"] = True
        summary_path.write_text(json.dumps(summary))
    html = render_agent_eval_html_report(tmp_path, run, use_llm_judge=False).read_text(encoding="utf-8")
    assert "4 scored; pass details truncated" in html