Repository navigation
fix(tier3): stop passing apt-get a blank package in generated Dockerfiles #471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0a9a82b
fix(tier3): stop passing apt-get a blank package in generated Dockerf…
rng1995 873a7b4
Merge branch 'main' into naren/apt-packages-continuation
chrisknvidia 44288c0
test(tier3): derive the expected apt base packages from the code
chrisknvidia 373c26e
test(tier3): cover whitespace and CRLF apt manifests
rng1995 1062908
Merge branch 'main' into naren/apt-packages-continuation
rng1995 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| # 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, | ||
| ) | ||
|
|
||
| _BASE_PACKAGES = ["bash", "curl", "git", "jq", "ripgrep"] | ||
|
|
||
|
|
||
| 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.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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.