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.
Python agent-evaluationagent-pluginsagent-securityagent-skillsagentic-aibenchmarkci-templatesclaude-codecodexevaluateevaluationharnesspluginplugin-evaluationsecurity-scannerskill-evalskill-evaluationskill-evaluatorskill-gap-analysisskills
fix(tier3): check verifier imports with python3 -I at image build (#470)
Narendran Raghavanbcac5e05b1b8
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 48de26ce..fd4e79c5 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -534,6 +534,17 @@ All notable changes to SkillEvaluator are documented in this file.preserves source files and retained role logs; local whole-log-tree transfersfail before modifying their destination.+- With default or default-plus-custom grading, a Tier 3 task image now fails+ to build when `python3 -I` cannot import the verifier's packages: idna,+ openai, ragas or boto3. This happens, for example, when a custom Dockerfile+ sets `ENV PIP_USER=1`, or when the packages are reachable only through+ `PYTHONPATH`. The build-time import check ran plain `python`, which sees+ those locations. `test.sh` runs the verifier as `python3 -I`, which does not.+ Such images built, and then every trial's verifier failed on `import idna`,+ or the goal-accuracy judge fell back from RAGAS to the custom judge when only+ ragas was hidden. The check now runs as `python3 -I`. `custom_only` grading+ never runs that verifier, so its images no longer run the check.+- Repository CI can opt in to reviewed, per-skill SkillSpector baselines fromthe PR or merge request's target revision. Policy files from the proposedchanges cannot approve their own exceptions.diff --git a/docs/agents-and-sandboxes.mdx b/docs/agents-and-sandboxes.mdxindex ccdad603..361deda7 100644--- a/docs/agents-and-sandboxes.mdx+++ b/docs/agents-and-sandboxes.mdx@@ -624,6 +624,17 @@ When a skill ships its own `evals/environment/Dockerfile`,| `rebase` (built-in default) | Swaps your `FROM` line onto the eval base image, keeping the rest of your Dockerfile. || `preserve` | Keeps your `FROM` exactly as written and appends the eval dependencies on top. |+With either value, SkillEvaluator appends a `python -m pip install` of the eval+dependencies after your instructions. It then checks that `python3 -I` can+import the packages the verifier uses, because the verifier runs as+`python3 -I`. `-I` ignores `PYTHONPATH` and the user site, so make sure those+packages land in the system or virtual environment site-packages that+`python3` uses. In a custom image, `python` and `python3` must use the same+interpreter so the install and verifier see the same packages. Do not use+`ENV PIP_USER=1`, `PIP_TARGET` or a `PYTHONPATH` entry for them. If the check fails, the image build stops with+`ModuleNotFoundError`. `custom_only` grading never runs that verifier, so it+skips the check.+Environment rules — size limits, auto-generated fallbacks, and sidecarcontainers — are part of the `evals/` contract in[Eval Datasets](eval-datasets.mdx).diff --git a/skills/skillevaluator/references/troubleshooting.md b/skills/skillevaluator/references/troubleshooting.mdindex 5e6767d7..829959a3 100644--- a/skills/skillevaluator/references/troubleshooting.md+++ b/skills/skillevaluator/references/troubleshooting.md@@ -16,6 +16,6 @@| Skill never activated | Description and prompts do not match | Name the tasks in the description; add explicit cases || Agent auth fails | Agent credential not exported where `skillevaluator` runs | Export it on the host; `doctor -a AGENT` || `AgentTimeoutError` or rate-limit errors | Slow model or too much concurrency | `--timeout-multiplier 2`, lower `--n-concurrent` |-| Custom Dockerfile build fails | Base image lacks tools the agent or grader needs | Fix `<skill-dir>/evals/environment/Dockerfile`; rerun with `--harbor-keep-jobs` to read the build log |+| Custom Dockerfile build fails | Base image lacks tools the agent or grader needs, or `python3 -I` cannot import the verifier packages (`ENV PIP_USER=1`, `PIP_TARGET` or `PYTHONPATH` installs) | Fix `<skill-dir>/evals/environment/Dockerfile`; install verifier packages into `python3`'s site-packages; rerun with `--harbor-keep-jobs` to read the build log || Results need debugging | Harbor jobs deleted by default | Rerun with `--harbor-keep-jobs`, then `skillevaluator harbor-view JOBS_DIR` || Lift differs between runs | LLM judges and agents are stochastic | Increase `--n-attempts`; compare only identical setups |diff --git a/src/skillevaluator/tier3/harbor/adapter.py b/src/skillevaluator/tier3/harbor/adapter.pyindex 08740376..542f4d65 100644--- a/src/skillevaluator/tier3/harbor/adapter.py+++ b/src/skillevaluator/tier3/harbor/adapter.py@@ -3555,7 +3555,14 @@ def _custom_compose_path(environment_dir: Path) -> Path | None:_VERIFIER_DEPS = "ragas~=0.4.0 langchain-community<0.4.2 openai>=1.0 anthropic>=0.40 boto3>=1.34 idna>=3.10,<4"+# Run this check with the interpreter and flags test.sh uses for eval.py (see+# _write_test_sh). `python3 -I` ignores PYTHONPATH and the user site, so+# packages installed only there fail the image build instead of every trial's+# verifier. It covers each third-party module the verifier imports: idna at+# startup, openai and ragas for RAGAS, and boto3 for the Bedrock judge._VERIFIER_IMPORT_SMOKE = (+ "import boto3, idna; "+ "from openai import AsyncOpenAI; ""from ragas.llms.base import llm_factory; ""from ragas.messages import AIMessage, HumanMessage; ""from ragas.metrics.collections import AgentGoalAccuracyWithReference"@@ -3568,13 +3575,17 @@ def _managed_run(command: str, *args: str) -> str:return "RUN " + json.dumps(["/bin/sh", "-c", _MANAGED_PATH_SHELL, "skillevaluator", command, *args])-def _verifier_install_lines(extra_requirements: Sequence[str] = ()) -> list[str]:- """Install verifier and skill requirements in one resolver transaction."""+def _verifier_install_lines(extra_requirements: Sequence[str] = (), *, import_check: bool = True) -> list[str]:+ """Install verifier and skill requirements in one resolver transaction.++ ``import_check=False`` skips the eval.py import check for custom_only+ grading, whose test.sh never runs eval.py.+ """requirements = [*_VERIFIER_DEPS.split(), *extra_requirements]- return [- _managed_run("python", "-m", "pip", "install", "--no-cache-dir", *requirements),- _managed_run("python", "-c", _VERIFIER_IMPORT_SMOKE),- ]+ lines = [_managed_run("python", "-m", "pip", "install", "--no-cache-dir", *requirements)]+ if import_check:+ lines.append(_managed_run("python3", "-I", "-c", _VERIFIER_IMPORT_SMOKE))+ return lines_WORKSPACE_SKILL_PATH = "COPY skills/ /workspace/skills/"@@ -3947,6 +3958,7 @@ def _rebase_custom_dockerfile_content(include_repo: bool = False,include_repo_linked_root: bool = False,agent_workdir: str | None = None,+ verifier_import_check: bool = True,) -> tuple[str, str]:"""Return custom Dockerfile content layered on top of the eval base image.@@ -3965,7 +3977,7 @@ def _rebase_custom_dockerfile_content(rebased_content = _append_evaluator_runtime_lines(rebased_source + f"\n# SkillEvaluator: original base was {original_from}\n",[- *_verifier_install_lines(),+ *_verifier_install_lines(import_check=verifier_import_check),*_runtime_copy_lines(agent_config_lines,include_input,@@ -3993,12 +4005,13 @@ def _ensure_verifier_deps(include_repo: bool = False,include_repo_linked_root: bool = False,agent_workdir: str | None = None,+ verifier_import_check: bool = True,) -> None:"""Append verifier deps and runtime COPY lines to a custom Dockerfile."""content = dockerfile_path.read_text(encoding="utf-8")restore_user = _dockerfile_final_explicit_user(content)user_prefix = "USER root\n" if restore_user is not None else ""- additions = f"\n{user_prefix}" + "\n".join(_verifier_install_lines()) + "\n"+ additions = f"\n{user_prefix}" + "\n".join(_verifier_install_lines(import_check=verifier_import_check)) + "\n"updated = _append_evaluator_runtime_lines(content + additions,_runtime_copy_lines(@@ -4183,6 +4196,7 @@ def _write_dockerfile(repo_context_exclude_paths: Sequence[Path] = (),agent_workdir: str | None = None,baseline_aliases_prevalidated: bool = False,+ grading_mode: str = "default",) -> None:"""Generate a Dockerfile that installs skills into the container.@@ -4194,6 +4208,7 @@ def _write_dockerfile("""env_dir = task_dir / "environment"env_dir.mkdir(parents=True, exist_ok=True)+ verifier_import_check = grading_mode != "custom_only"if not has_skill and skill_path is not None and not baseline_aliases_prevalidated:_check_baseline_skill_candidates_do_not_alias_target(@@ -4334,6 +4349,7 @@ def _write_dockerfile(include_repo=include_repo,include_repo_linked_root=include_repo_linked_root,agent_workdir=agent_workdir,+ verifier_import_check=verifier_import_check,)if rebased is not None:rebased_content, original_from = rebased@@ -4351,6 +4367,7 @@ def _write_dockerfile(include_repo=include_repo,include_repo_linked_root=include_repo_linked_root,agent_workdir=agent_workdir,+ verifier_import_check=verifier_import_check,)returnfinally:@@ -4391,7 +4408,7 @@ def _write_dockerfile(dockerfile_lines.append(" " + " ".join(apt_pkgs) + " \\")dockerfile_lines.append(" && rm -rf /var/lib/apt/lists/*")- dockerfile_lines.extend(["", *_verifier_install_lines(pip_reqs)])+ dockerfile_lines.extend(["", *_verifier_install_lines(pip_reqs, import_check=verifier_import_check)])dockerfile_lines.extend([@@ -4628,6 +4645,7 @@ def _prepare_native_environment(include_repo=include_repo,include_repo_linked_root=include_repo_linked_root,agent_workdir=agent_workdir,+ verifier_import_check=grading_mode != "custom_only",)if rebased is not None:rebased_content, original_from = rebased@@ -6322,6 +6340,7 @@ def _generate_harbor_tasks_into(repo_context_exclude_paths=effective_excluded_roots,agent_workdir=agent_workdir,baseline_aliases_prevalidated=baseline_aliases_prevalidated,+ grading_mode=grading_mode,)task_dirs.append(case_id)diff --git a/tests/test_harbor_adapter_safety.py b/tests/test_harbor_adapter_safety.pyindex 5de4b96b..ab19b388 100644--- a/tests/test_harbor_adapter_safety.py+++ b/tests/test_harbor_adapter_safety.py@@ -14,6 +14,7 @@ from pathlib import Pathimport pytestfrom skillevaluator.tier3.harbor.adapter import (+ _VERIFIER_IMPORT_SMOKE,_copy_custom_grader,_rebase_custom_dockerfile_content,_stage_repo_context,@@ -311,7 +312,8 @@ def test_generated_task_rebases_custom_dockerfile_content(tmp_path: Path) -> Non)-def test_native_task_rebases_custom_dockerfile_content(tmp_path: Path) -> None:[email protected]("grading_mode", ["custom_only", "default"])+def test_native_task_rebases_custom_dockerfile_content(tmp_path: Path, grading_mode: str) -> None:skill = _write_native_skill(tmp_path)native_task = skill / "evals" / "harbor" / "case-001"environment = native_task / "environment"@@ -323,11 +325,17 @@ def test_native_task_rebases_custom_dockerfile_content(tmp_path: Path) -> None:tests_dir = native_task / "tests"tests_dir.mkdir()(tests_dir / "test.sh").write_text("#!/bin/sh\nexit 0\n", encoding="utf-8")+ if grading_mode == "default":+ # Default grading reads its case metadata from evals.json.+ (skill / "evals" / "evals.json").write_text(+ json.dumps([{"id": "case-001", "question": "Run case", "expected_skill": skill.name}]),+ encoding="utf-8",+ )task = stage_native_harbor_tasks(skill,tmp_path / "native-tasks",- grading_mode="custom_only",+ grading_mode=grading_mode,base_image="registry.example/eval-base:verified",)[0]@@ -336,6 +344,9 @@ def test_native_task_rebases_custom_dockerfile_content(tmp_path: Path) -> None:assert dockerfile.index("RUN echo native-custom-layer\n") < dockerfile.index("# SkillEvaluator: original base was FROM ubuntu:24.04\n")+ assert dockerfile.count('"pip", "install"') == 1+ # Only eval.py needs the verifier imports; custom_only never runs it.+ assert (_VERIFIER_IMPORT_SMOKE in dockerfile) is (grading_mode != "custom_only")def test_rebase_custom_dockerfile_content_without_from_fails_closed() -> None:diff --git a/tests/test_harbor_runtime_skill_isolation.py b/tests/test_harbor_runtime_skill_isolation.pyindex b72a1094..9832b186 100644--- a/tests/test_harbor_runtime_skill_isolation.py+++ b/tests/test_harbor_runtime_skill_isolation.py@@ -5,6 +5,7 @@from __future__ import annotations+import astimport jsonimport osimport shutil@@ -4253,6 +4254,164 @@ def test_rebase_reasserts_verifier_constraint_after_authored_dependencies(tmp_paassert dockerfile.rfind("from ragas.llms.base import llm_factory") > dockerfile.find("langchain-community>=0.4.2")+_FAKE_VERIFIER_MODULES = {+ "boto3/__init__.py": "",+ "idna/__init__.py": "",+ "openai/__init__.py": "class AsyncOpenAI:\n pass\n",+ "ragas/__init__.py": "",+ "ragas/llms/__init__.py": "",+ "ragas/llms/base.py": "def llm_factory(*args, **kwargs):\n return None\n",+ "ragas/messages.py": "class AIMessage:\n pass\n\n\nclass HumanMessage:\n pass\n",+ "ragas/metrics/__init__.py": "",+ "ragas/metrics/collections.py": "class AgentGoalAccuracyWithReference:\n pass\n",+}+++def _write_fake_verifier_modules(root: Path) -> None:+ for relative, source in _FAKE_VERIFIER_MODULES.items():+ path = root / relative+ path.parent.mkdir(parents=True, exist_ok=True)+ path.write_text(source, encoding="utf-8")+++def _third_party_imports(source: str) -> set[str]:+ names: set[str] = set()+ for node in ast.walk(ast.parse(source)):+ if isinstance(node, ast.Import):+ names.update(alias.name.split(".")[0] for alias in node.names)+ elif isinstance(node, ast.ImportFrom) and node.level == 0 and node.module:+ names.add(node.module.split(".")[0])+ return {name for name in names if name not in sys.stdlib_module_names and name != "__future__"}+++def _verifier_smoke_command(dockerfile: str) -> list[str] | None:+ lines = [line for line in dockerfile.splitlines() if adapter_module._VERIFIER_IMPORT_SMOKE in line]+ if not lines:+ return None+ assert len(lines) == 1+ argv = json.loads(lines[0].removeprefix("RUN "))+ assert argv[:4] == ["/bin/sh", "-c", adapter_module._MANAGED_PATH_SHELL, "skillevaluator"]+ return argv+++def test_verifier_dependency_smoke_covers_every_verifier_third_party_import() -> None:+ bundled = {path.stem for path in adapter_module._VERIFIER_FILES}+ imported = set().union(+ *(_third_party_imports(path.read_text(encoding="utf-8")) for path in adapter_module._VERIFIER_FILES)+ )+ # The verifier works without these: google.auth falls back to the metadata+ # server and gcloud, skillevaluator to the bundled siblings, and boto3+ # imports botocore.+ optional = {"botocore", "google", "skillevaluator"}+ expected = imported - bundled - optional++ assert expected == _third_party_imports(adapter_module._VERIFIER_IMPORT_SMOKE)+ installed = {+ requirement.split("~")[0].split(">")[0].split("<")[0] for requirement in adapter_module._VERIFIER_DEPS.split()+ }+ assert expected <= installed+++def test_shared_eval_base_image_keeps_verifier_dependency_smoke(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ _, target, references_dir, _ = _write_projection_fixture(tmp_path)+ built: list[str] = []++ def fake_run(cmd: list[str], *args: object, **kwargs: object) -> subprocess.CompletedProcess[str]:+ if cmd[:3] == ["docker", "image", "inspect"]:+ return subprocess.CompletedProcess(cmd, 1, "", "")+ assert cmd[:2] == ["docker", "build"]+ built.append((Path(cmd[-1]) / "Dockerfile").read_text(encoding="utf-8"))+ return subprocess.CompletedProcess(cmd, 0, "", "")++ monkeypatch.setattr(adapter_module.subprocess, "run", fake_run)++ # The shared image serves every grading mode, so it keeps the check.+ assert adapter_module.build_eval_base_image(target, references_dir)+ assert len(built) == 1+ argv = _verifier_smoke_command(built[0])+ assert argv is not None+ assert argv[4:7] == ["python3", "-I", "-c"]++[email protected]("grading_mode", ["default", "custom_only"])[email protected]("mode", ["generated", "preserve", "rebase"])+def test_verifier_dependency_smoke_runs_like_the_verifier(tmp_path: Path, mode: str, grading_mode: str) -> None:+ _, target, _, _ = _write_projection_fixture(tmp_path)+ options: dict[str, str] = {}+ if mode != "generated":+ (target / "evals" / "environment" / "Dockerfile").write_text(+ "FROM python:3.12-slim\nENV PIP_USER=1\n",+ encoding="utf-8",+ )+ if mode == "rebase":+ options = {"base_image": "skillevaluator-base:test", "custom_dockerfile_mode": "rebase"}++ task = generate_harbor_tasks(+ target,+ tmp_path / f"verifier-smoke-{mode}-{grading_mode}",+ grading_mode=grading_mode,+ **options,+ )[0]++ dockerfile = (task / "environment" / "Dockerfile").read_text(encoding="utf-8")+ test_sh = (task / "tests" / "test.sh").read_text(encoding="utf-8")+ argv = _verifier_smoke_command(dockerfile)+ assert dockerfile.count('"pip", "install"') == 1+ if grading_mode == "custom_only":+ # test.sh never runs eval.py, so its imports are not a build requirement.+ assert "/eval.py" not in test_sh+ assert argv is None+ return+ assert argv is not None+ command = argv[4:]+ verifier = next(line for line in test_sh.splitlines() if line.endswith('/eval.py"'))+ assert command[:3] == ["python3", "-I", "-c"]+ assert verifier.split()[:2] == command[:2]++[email protected](os.name == "nt", reason="the exec-form RUN starts /bin/sh")+def test_verifier_dependency_smoke_fails_when_isolated_verifier_cannot_import(tmp_path: Path) -> None:+ _, target, _, _ = _write_projection_fixture(tmp_path)+ task = generate_harbor_tasks(target, tmp_path / "verifier-smoke-behavior")[0]+ argv = _verifier_smoke_command((task / "environment" / "Dockerfile").read_text(encoding="utf-8"))+ assert argv is not None++ image = tmp_path / "image"+ subprocess.run([sys.executable, "-m", "venv", "--without-pip", str(image)], check=True)+ site_packages = Path(+ subprocess.run(+ [str(image / "bin" / "python3"), "-c", "import sysconfig; print(sysconfig.get_path('purelib'))"],+ check=True,+ capture_output=True,+ text=True,+ ).stdout.strip()+ )+ path = os.pathsep.join([str(image / "bin"), "/usr/bin", "/bin"])++ def smoke(**env: str) -> subprocess.CompletedProcess[str]:+ return subprocess.run(argv, env={"PATH": path, **env}, capture_output=True, text=True, timeout=60)++ # A PIP_TARGET-style install that only PYTHONPATH reaches is invisible to `python3 -I`.+ pythonpath = tmp_path / "pythonpath"+ _write_fake_verifier_modules(pythonpath)+ hidden = smoke(PYTHONPATH=str(pythonpath))+ assert hidden.returncode != 0+ assert "ModuleNotFoundError" in hidden.stderr++ _write_fake_verifier_modules(site_packages)+ installed = smoke()+ assert installed.returncode == 0, installed.stderr++ for package in sorted({relative.split("/")[0] for relative in _FAKE_VERIFIER_MODULES}):+ shutil.rmtree(site_packages / package)+ missing = smoke()+ assert missing.returncode != 0, package+ assert f"No module named '{package}'" in missing.stderr+ _write_fake_verifier_modules(site_packages)++def test_baseline_rejects_target_manifest_payload_with_appended_comment(tmp_path: Path) -> None:_, target, _, _ = _write_projection_fixture(tmp_path)environment = target / "evals" / "environment"