Repository navigation
refactor(ci): share sandbox base-image resolver primitives #6968
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
cv
merged 12 commits into
NVIDIA:main
from
HOYALIM:codex/issue-6957-base-image-resolver
Jul 16, 2026
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
04b6bb4
refactor(ci): share base image resolver primitives
HOYALIM a11c103
fix(ci): propagate resolver output failures
HOYALIM 8bfc616
test(ci): preserve resolver argument boundaries
HOYALIM e2596ad
test(ci): link resolver suite to issue
HOYALIM cfde5d1
merge(main): integrate shared base-image resolver
prekshivyas ae51f85
test(ci): avoid nested Node resolver harness
prekshivyas d552e19
test(ci): keep resolver harness linear
HOYALIM df150e3
test(ci): execute sandbox base resolver action
prekshivyas 8bc9b31
test(ci): split resolver workflow contract
HOYALIM 3ba787c
Merge remote-tracking branch 'origin/main' into codex/pr-6968-sync
prekshivyas c00ffdd
test(ci): isolate base image resolver contracts
prekshivyas ee1dd6c
Merge remote-tracking branch 'hoyalim/codex/issue-6957-base-image-res…
prekshivyas 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # shellcheck shell=bash | ||
|
|
||
| # Shared mechanics for the sandbox base-image resolver actions. Agent-specific | ||
| # candidate construction and validation intentionally remain in each action. | ||
|
|
||
| resolver_glibc_version() { | ||
| docker run --rm --entrypoint /usr/bin/ldd "$1" --version 2>/dev/null \ | ||
| | sed -nE 's/.*GLIBC ([0-9]+\.[0-9]+).*/\1/p; s/.* ([0-9]+\.[0-9]+)$/\1/p' \ | ||
| | head -n 1 | ||
| } | ||
|
|
||
| resolver_glibc_ok() { | ||
| local have="$1" minimum="$2" | ||
| [[ -n "$have" ]] \ | ||
| && [[ "$(printf '%s\n%s\n' "$minimum" "$have" | sort -V | head -n 1)" == "$minimum" ]] | ||
| } | ||
|
|
||
| resolver_pull() { | ||
| docker pull "$1" >/dev/null 2>&1 | ||
| } | ||
|
|
||
| resolver_repo_digest() { | ||
| local ref="$1" repository="$2" | ||
| docker image inspect "$ref" --format '{{range .RepoDigests}}{{println .}}{{end}}' \ | ||
| | grep -F -m 1 "${repository}@sha256:" | ||
| } | ||
|
|
||
| resolver_try_candidates() { | ||
| local callback="$1" ref | ||
| shift | ||
| for ref in "$@"; do | ||
| if "$callback" "$ref"; then | ||
| return 0 | ||
| fi | ||
| done | ||
| return 1 | ||
| } | ||
|
|
||
| resolver_build_local() { | ||
| local dockerfile="$1" tag="$2" | ||
| docker build -f "$dockerfile" -t "$tag" . | ||
| } | ||
|
|
||
| resolver_write_env() { | ||
| local name="$1" value="$2" | ||
| [[ "$name" =~ ^[A-Z_][A-Z0-9_]*$ ]] || { | ||
| echo "::error::Invalid GitHub environment variable name: ${name}" >&2 | ||
| return 1 | ||
| } | ||
| [[ "$value" != *$'\n'* && -n "$value" ]] || { | ||
| echo "::error::Invalid empty or multiline image reference" >&2 | ||
| return 1 | ||
| } | ||
| printf '%s=%s\n' "$name" "$value" >>"$GITHUB_ENV" | ||
| } |
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,166 @@ | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"; | ||
| import { tmpdir } from "node:os"; | ||
| import path from "node:path"; | ||
| import { spawnSync } from "node:child_process"; | ||
|
|
||
| import { afterEach, describe, expect, it } from "vitest"; | ||
|
|
||
| import { type CompositeAction, readYaml } from "./helpers/e2e-workflow-contract"; | ||
| import { execTimeout } from "./helpers/timeouts"; | ||
|
|
||
| const repoRoot = path.resolve(import.meta.dirname, ".."); | ||
| const helper = path.join(repoRoot, ".github/actions/base-image-resolver.sh"); | ||
| const sandboxAction = readYaml<CompositeAction>( | ||
| ".github/actions/resolve-sandbox-base-image/action.yaml", | ||
| ); | ||
| const tempDirs: string[] = []; | ||
|
|
||
| function run(script: string, env: NodeJS.ProcessEnv = {}) { | ||
| return spawnSync("bash", ["--noprofile", "--norc", "-c", `source "$HELPER"\n${script}`], { | ||
| encoding: "utf8", | ||
| env: { ...process.env, HELPER: helper, ...env }, | ||
| }); | ||
| } | ||
|
|
||
| function fakeDocker(body: string) { | ||
| const dir = mkdtempSync(path.join(tmpdir(), "nemoclaw-base-resolver-")); | ||
| tempDirs.push(dir); | ||
| const executable = path.join(dir, "docker"); | ||
| writeFileSync(executable, `#!/usr/bin/env bash\nset -eu\n${body}\n`, { mode: 0o755 }); | ||
| return dir; | ||
| } | ||
|
|
||
| afterEach(() => { | ||
| for (const dir of tempDirs.splice(0)) rmSync(dir, { recursive: true, force: true }); | ||
| }); | ||
|
|
||
| describe("base image resolver helper (#6957)", () => { | ||
| it("executes the sandbox action and exports a compatible candidate", () => { | ||
| const bin = fakeDocker(` | ||
| if [[ "$1" == pull ]]; then exit 0; fi | ||
| if [[ "$1" == run ]]; then echo "ldd (Ubuntu GLIBC 2.39-0ubuntu8) 2.39"; exit 0; fi | ||
| exit 1`); | ||
| const githubEnv = path.join(bin, "github.env"); | ||
| writeFileSync(githubEnv, ""); | ||
| const resolver = sandboxAction.runs.steps.find( | ||
| (step) => step.name === "Resolve sandbox base image", | ||
| )?.run; | ||
|
|
||
| const result = spawnSync("bash", ["--noprofile", "--norc", "-c", resolver ?? ""], { | ||
| cwd: repoRoot, | ||
| encoding: "utf8", | ||
| timeout: execTimeout(), | ||
| env: { | ||
| ...process.env, | ||
| GITHUB_ACTION_PATH: path.join(repoRoot, ".github/actions/resolve-sandbox-base-image"), | ||
| GITHUB_ENV: githubEnv, | ||
| GITHUB_SHA: "1".repeat(40), | ||
| PATH: `${bin}:${process.env.PATH}`, | ||
| }, | ||
| }); | ||
|
|
||
| expect(result.status, result.stderr).toBe(0); | ||
| expect(readFileSync(githubEnv, "utf8")).toBe( | ||
| "BASE_IMAGE=ghcr.io/nvidia/nemoclaw/sandbox-base:11111111\n", | ||
| ); | ||
| }); | ||
|
|
||
| it("pulls a remote image and accepts a compatible glibc version", () => { | ||
| const bin = fakeDocker(` | ||
| if [[ "$1" == pull ]]; then exit 0; fi | ||
| if [[ "$1" == run ]]; then echo "ldd (Ubuntu GLIBC 2.39-0ubuntu8) 2.39"; exit 0; fi | ||
| exit 1`); | ||
|
|
||
| const result = run( | ||
| 'resolver_pull example:test && version="$(resolver_glibc_version example:test)" && resolver_glibc_ok "$version" 2.39 && printf "%s" "$version"', | ||
| { PATH: `${bin}:${process.env.PATH}` }, | ||
| ); | ||
|
|
||
| expect(result.status).toBe(0); | ||
| expect(result.stdout).toBe("2.39"); | ||
| }); | ||
|
|
||
| it("rejects an incompatible or missing glibc version", () => { | ||
| expect(run('resolver_glibc_ok "2.38" 2.39').status).not.toBe(0); | ||
| expect(run('resolver_glibc_ok "" 2.39').status).not.toBe(0); | ||
| }); | ||
|
|
||
| it("returns only the requested repository digest", () => { | ||
| const bin = fakeDocker(` | ||
| cat <<'EOF' | ||
| other.example/base@sha256:aaaaaaaa | ||
| ghcr.io/nvidia/nemoclaw/hermes-sandbox-base@sha256:bbbbbbbb | ||
| EOF`); | ||
| const env = { PATH: `${bin}:${process.env.PATH}` }; | ||
|
|
||
| const found = run( | ||
| "resolver_repo_digest mutable:tag ghcr.io/nvidia/nemoclaw/hermes-sandbox-base", | ||
| env, | ||
| ); | ||
| const missing = run("resolver_repo_digest mutable:tag ghcr.io/nvidia/nemoclaw/missing", env); | ||
|
|
||
| expect(found.status).toBe(0); | ||
| expect(found.stdout.trim()).toBe("ghcr.io/nvidia/nemoclaw/hermes-sandbox-base@sha256:bbbbbbbb"); | ||
| expect(missing.status).not.toBe(0); | ||
| }); | ||
|
|
||
| it("iterates candidates through an agent-owned validator and reports exhaustion", () => { | ||
| const selected = run(` | ||
| validate() { [[ "$1" == compatible ]] && printf '%s' "$1"; } | ||
| resolver_try_candidates validate rejected compatible later`); | ||
| const exhausted = run(` | ||
| reject() { return 1; } | ||
| resolver_try_candidates reject first second`); | ||
|
|
||
| expect(selected.status).toBe(0); | ||
| expect(selected.stdout).toBe("compatible"); | ||
| expect(exhausted.status).not.toBe(0); | ||
| }); | ||
|
|
||
| it("builds a local fallback with the exact Dockerfile and tag", () => { | ||
| const bin = fakeDocker('printf "%s\\0" "$@" >> "$DOCKER_LOG"'); | ||
| const log = path.join(bin, "docker.log"); | ||
|
|
||
| const result = run("resolver_build_local agents/hermes/Dockerfile.base local:test", { | ||
| DOCKER_LOG: log, | ||
| PATH: `${bin}:${process.env.PATH}`, | ||
| }); | ||
|
|
||
| expect(result.status).toBe(0); | ||
| expect(readFileSync(log, "utf8").split("\0")).toEqual([ | ||
| "build", | ||
| "-f", | ||
| "agents/hermes/Dockerfile.base", | ||
| "-t", | ||
| "local:test", | ||
| ".", | ||
| "", | ||
| ]); | ||
| }); | ||
|
|
||
| it("writes one validated GitHub environment assignment", () => { | ||
| const dir = mkdtempSync(path.join(tmpdir(), "nemoclaw-base-env-")); | ||
| tempDirs.push(dir); | ||
| const githubEnv = path.join(dir, "github.env"); | ||
|
|
||
| const valid = run("resolver_write_env BASE_IMAGE ghcr.io/nvidia/nemoclaw/sandbox-base:latest", { | ||
| GITHUB_ENV: githubEnv, | ||
| }); | ||
| const invalidName = run('resolver_write_env "BAD-NAME" image', { GITHUB_ENV: githubEnv }); | ||
| const emptyValue = run('resolver_write_env BASE_IMAGE ""', { GITHUB_ENV: githubEnv }); | ||
| const multilineValue = run("resolver_write_env BASE_IMAGE $'first\\nsecond'", { | ||
| GITHUB_ENV: githubEnv, | ||
| }); | ||
|
|
||
| expect(valid.status).toBe(0); | ||
| expect(invalidName.status).not.toBe(0); | ||
| expect(emptyValue.status).not.toBe(0); | ||
| expect(multilineValue.status).not.toBe(0); | ||
| expect(readFileSync(githubEnv, "utf8")).toBe( | ||
| "BASE_IMAGE=ghcr.io/nvidia/nemoclaw/sandbox-base:latest\n", | ||
| ); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.