Skip to content
Merged
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
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,13 @@ All notable changes to SkillEvaluator are documented in this file.
rebuilt, with the LLM when a provider is configured, and its
`what_to_fix.json` rewritten.

- Generated Tier 3 images now build when any staged skill declares packages
in `apt-packages.txt`. The generated `apt-get install` line ended the base
package list with `\ \`, so the shell passed apt-get a package named " "
and the build failed with `Unable to locate package`. This affected the
shared eval base image, generated task Dockerfiles and the default
Dockerfile for native Harbor tasks.

- Public MCP URL probes handle modern SDK client and stream APIs while retaining
checked-address connections, header grants, response limits, and bounded
cleanup. Redirect responses are refused before SDK-level redirect handling.
Expand Down
3 changes: 0 additions & 3 deletions src/skillevaluator/tier3/harbor/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,6 @@ def build_eval_base_image(
f" {_BASE_APT_PACKAGES} \\",
]
if extra_apt:
lines[-1] += " \\"
lines.append(" " + " ".join(extra_apt) + " \\")
lines.append(" && rm -rf /var/lib/apt/lists/*")

Expand Down Expand Up @@ -4389,7 +4388,6 @@ def _write_dockerfile(
f" {_BASE_APT_PACKAGES} \\",
]
if apt_pkgs:
dockerfile_lines[-1] += " \\"
dockerfile_lines.append(" " + " ".join(apt_pkgs) + " \\")
dockerfile_lines.append(" && rm -rf /var/lib/apt/lists/*")

Expand Down Expand Up @@ -4525,7 +4523,6 @@ def _write_default_environment_dockerfile(
f" {_BASE_APT_PACKAGES} \\",
]
if apt_pkgs:
dockerfile_lines[-1] += " \\"
dockerfile_lines.append(" " + " ".join(apt_pkgs) + " \\")
dockerfile_lines.append(" && rm -rf /var/lib/apt/lists/*")
if include_verifier_deps:
Expand Down
115 changes: 115 additions & 0 deletions tests/test_harbor_apt_install_lines.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

"""Generated Dockerfiles pass exactly the declared apt packages to apt-get."""

from __future__ import annotations

import json
import shlex
import subprocess
from pathlib import Path

import pytest

import skillevaluator.tier3.harbor.adapter as adapter_module
from skillevaluator.tier3.harbor.adapter import (
_write_default_environment_dockerfile,
build_eval_base_image,
generate_harbor_tasks,
)

# Derived from the code's own constant so adding a base package does not break
# these tests. The assertions below still compare the whole package list, so a
# blank or stray entry fails them.
_BASE_PACKAGES = adapter_module._BASE_APT_PACKAGES.split()


def _apt_install_packages(dockerfile: str) -> list[str]:
"""Return the words the shell passes to ``apt-get install``.

Docker joins a line that ends in ``\\`` with the next line before the shell
sees the command, so join the RUN instruction the same way and split it like
``sh`` does. A stray escaped space shows up here as a ``" "`` package.
"""
lines = dockerfile.splitlines()
start = next(index for index, line in enumerate(lines) if line.startswith("RUN apt-get "))
command = ""
for line in lines[start:]:
if not line.endswith("\\"):
command += line
break
command += line[:-1]
words = shlex.split(command.removeprefix("RUN "))
first = words.index("--no-install-recommends") + 1
return words[first : words.index("&&", first)]


def _write_skill(root: Path, apt_packages: str | None) -> Path:
skill = root / "apt-skill"
scripts = skill / "scripts"
scripts.mkdir(parents=True)
(skill / "SKILL.md").write_text("# apt-skill\n", encoding="utf-8")
(scripts / "run.py").write_text("print('runtime')\n", encoding="utf-8")
if apt_packages is not None:
(scripts / "apt-packages.txt").write_text(apt_packages, encoding="utf-8")
evals = skill / "evals"
evals.mkdir()
(evals / "evals.json").write_text(
json.dumps([{"id": "case-001", "question": "Run the skill.", "ground_truth": "done"}]),
encoding="utf-8",
)
return skill


_CASES = [
pytest.param(None, _BASE_PACKAGES, id="base-only"),
pytest.param("tree\n", [*_BASE_PACKAGES, "tree"], id="one-extra"),
pytest.param("zstd\n# comment\ntree\n", [*_BASE_PACKAGES, "tree", "zstd"], id="two-extras-and-comment"),
pytest.param("\r\n \r\n\t\r\n", _BASE_PACKAGES, id="blank-whitespace-crlf"),
pytest.param(" tree \r\n\t\r\n zstd\r\n", [*_BASE_PACKAGES, "tree", "zstd"], id="packages-crlf"),
]


@pytest.mark.parametrize(("apt_packages", "expected"), _CASES)
def test_generated_task_dockerfile_installs_declared_apt_packages(
tmp_path: Path, apt_packages: str | None, expected: list[str]
) -> None:
skill = _write_skill(tmp_path, apt_packages)

task = generate_harbor_tasks(skill, tmp_path / "tasks")[0]

assert _apt_install_packages((task / "environment" / "Dockerfile").read_text(encoding="utf-8")) == expected


@pytest.mark.parametrize(("apt_packages", "expected"), _CASES)
def test_shared_eval_base_image_installs_declared_apt_packages(
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, apt_packages: str | None, expected: list[str]
) -> None:
skill = _write_skill(tmp_path, apt_packages)
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)

assert build_eval_base_image(skill)
assert len(built) == 1
assert _apt_install_packages(built[0]) == expected


@pytest.mark.parametrize(("apt_packages", "expected"), _CASES)
def test_native_default_environment_installs_declared_apt_packages(
tmp_path: Path, apt_packages: str | None, expected: list[str]
) -> None:
env_dir = tmp_path / "environment"
_write_skill(env_dir / "skills", apt_packages)

_write_default_environment_dockerfile(env_dir, base_image="", agent_config_lines=[], include_input=False)

assert _apt_install_packages((env_dir / "Dockerfile").read_text(encoding="utf-8")) == expected
Loading