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.

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

"""The installed SkillSpector library reports an AE1 finding only for a helper it cannot parse.

Run explicitly (``-m integration``) with SkillSpector v2.13.1 or later
importable. Earlier releases stop early on the inert help string as well. The
helper scripts are scanned as text and never run.
"""

import json
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path

import pytest

from skillevaluator.validators.base import ValidationResult
from skillevaluator.validators.security import SecurityValidator

pytestmark = pytest.mark.integration


def _installed_version() -> tuple[int, ...]:
    try:
        return tuple(int(part) for part in version("skillspector").split(".")[:3])
    except (PackageNotFoundError, ValueError):
        return ()


@pytest.mark.parametrize(
    ("statement", "expected_rule", "expected_complete"),
    [
        ('print "Use rm to remove a project\\n";\n', None, True),
        ('system("rm -rf /");\n', "TM1", True),
        ('print "Use rm ' + "safe " * 2000 + '-rf *";\n', "AE1", False),
    ],
    ids=["inert-help-string", "executable-removal", "genuine-parser-limit"],
)
def test_installed_scanner_reference_analysis_contract(
    tmp_path: Path, statement: str, expected_rule: str | None, expected_complete: bool
) -> None:
    graph = pytest.importorskip("skillspector.graph").graph
    if _installed_version() < (2, 13, 1):
        pytest.skip("SkillSpector before v2.13.1 stops early on valid Perl helpers")
    (tmp_path / "scripts").mkdir()
    (tmp_path / "SKILL.md").write_text(
        "---\nname: perl-help\ndescription: Inspect a Perl helper.\n---\n\n"
        "Run `scripts/helper.pl`.\n\nSee `scripts/helper.pl`.\n",
        encoding="utf-8",
    )
    (tmp_path / "scripts" / "helper.pl").write_text(
        "#!/usr/bin/env perl\nuse strict;\nuse warnings;\n" + statement, encoding="utf-8"
    )

    state = graph.invoke({"input_path": str(tmp_path), "use_llm": False, "output_format": "json"})
    report = json.loads(state["report_body"])
    result = ValidationResult(validator_name="Security Scan")
    SecurityValidator(use_llm=False, content_type="skill")._process_skillspector_cli_result(
        report, result, source_root=tmp_path
    )

    assert report["analysis_completeness"]["is_complete"] is expected_complete
    if expected_rule is None:
        assert report["issues"] == []
        assert result.passed
    else:
        assert any(issue["id"] == expected_rule for issue in report["issues"])
        assert not result.passed
    if expected_rule == "AE1":
        ae1 = [finding for finding in result.findings if finding.check_name.endswith("(AE1)")]
        assert len(ae1) == 2
        assert all("static_parse_limit" in finding.suggestion for finding in ae1)
        assert all(finding.check_name == "Incomplete referenced artifact analysis (AE1)" for finding in ae1)
        assert result.metadata["skillspector_reference_summary"]["reference_occurrences"] == 2