From 85293308787bd4eee1b7a93e7be79f69a62f2d08 Mon Sep 17 00:00:00 2001 From: Phil Leggetter Date: Thu, 5 Nov 2026 21:06:58 +0000 Subject: [PATCH 1/5] Put the pinned Hookdeck CLI on PATH for login shells Codex runs every command as `/bin/bash -lc`. A login shell sources Debian's /etc/profile, which replaces PATH with a fixed list that leaves out /home/node/.npm-global/bin, so the PATH the harness passes on `docker exec` never reached a Codex tool call. In release run 42044644850 every Codex attempt that invoked `hookdeck` got `command not found` (26/26, 18/22, 16/16 and 19/19 across the four Codex arms) and worked around it by absolute path, `npx`, an unpinned `npx -y hookdeck-cli@latest`, or the REST API. Claude Code runs `bash -c`, inherits the PATH, and was unaffected. - Dockerfile: put the npm prefix on PATH with `ENV` (non-login shells and any exec without an explicit PATH) and with an /etc/profile.d/npm-global.sh entry (login shells). A profile.d entry rather than symlinks into /usr/local/bin, so `skills` and anything an agent installs with `npm install -g` are covered too. The installed CLI version is unchanged. - Image tag: include a hash of the Dockerfile, so a machine with a cached image rebuilds instead of reusing one without the fix. - Sandbox self-check: before a cell starts, run `command -v hookdeck && hookdeck --version` in a non-login and a login shell and throw unless both resolve the pinned version. The throw errors the cell, so no result file is written. `--version` rather than `hookdeck version`, which creates a config file and calls GitHub inside the agent's sandbox. - triage: flag PINNED CLI NOT USED for a cell whose shell said `hookdeck: command not found` or that ran a `hookdeck-cli@` other than the pin. Against run 42044644850 it flags 69 of 76 Codex cells and none of the 38 Claude Code cells. - AGENTS.md: a Trap entry for the login-shell PATH reset, and the new triage signal. Not verified in a built image: Docker was not available where this was written. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 19 +- apps/framework/lib/pinned-cli.ts | 144 ++++++++++++++ apps/framework/scripts/triage.ts | 18 +- apps/framework/test/pinned-cli.test.ts | 118 ++++++++++++ packages/sandbox/Dockerfile | 32 ++- packages/sandbox/src/agent-environment.ts | 5 + packages/sandbox/src/docker-sandbox.ts | 6 + packages/sandbox/src/image.ts | 28 ++- packages/sandbox/src/index.ts | 6 + packages/sandbox/src/toolchain-check.ts | 121 ++++++++++++ packages/sandbox/test/toolchain-check.test.ts | 182 ++++++++++++++++++ 11 files changed, 668 insertions(+), 11 deletions(-) create mode 100644 apps/framework/lib/pinned-cli.ts create mode 100644 apps/framework/test/pinned-cli.test.ts create mode 100644 packages/sandbox/src/toolchain-check.ts create mode 100644 packages/sandbox/test/toolchain-check.test.ts diff --git a/AGENTS.md b/AGENTS.md index 1e27bef..e8d132a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -770,8 +770,10 @@ with a plausible partial score, and one was written as a `2/6` agent failure), a run that failed while its own report claims success (nine of twelve baselines in one run, every one of them confidently building on the wrong product), a declared credential the agent never referenced, a skill offered and never -opened, a baseline that self-installed a product skill, and a cell whose only -green checks are the ones an idle agent satisfies. +opened, a baseline that self-installed a product skill, a cell whose only +green checks are the ones an idle agent satisfies, and a cell whose agent could +not find the pinned CLI or ran a different one (69 of the 76 Codex cells in run +42044644850). Nothing flagged is not the same as nothing to learn. It means no cell tripped a signal the script knows about, and the signals it knows about are the ones that @@ -1320,6 +1322,19 @@ deleted through the API, so a shared project accumulates history, and a scorer that just asks "did an event arrive?" will eventually say yes because of an earlier run. +**Codex runs every command in a login shell, and a login shell rebuilds PATH.** +Codex's tool calls are `/bin/bash -lc '…'`, so Debian's `/etc/profile` runs +and replaces whatever PATH the harness passed in with a fixed list. Claude Code +runs `bash -c` and inherits it. Until this was found, in release run +42044644850, the pinned `hookdeck` in the npm prefix was `command not found` +on every Codex arm, and the agents reached it by absolute path, by `npx`, by an +unpinned `npx -y hookdeck-cli@latest`, or not at all — all of it scored as +though both agents had the same baseline. So anything an agent needs on PATH +has to be on it for both kinds of shell: the image sets it in `ENV` and again +in `/etc/profile.d/`, and `toolchain-check.ts` errors a cell before it starts +if either shell does not resolve the pinned version. Setting `PATH` on +`docker exec` alone is not enough. + **Credentials reach the agent through `EvalSession.sandboxEnv`.** The session is created before the sandbox because the sandbox needs the lease. Disposal runs in reverse, so the container is torn down before the project is released. diff --git a/apps/framework/lib/pinned-cli.ts b/apps/framework/lib/pinned-cli.ts new file mode 100644 index 0000000..83322df --- /dev/null +++ b/apps/framework/lib/pinned-cli.ts @@ -0,0 +1,144 @@ +import { HOOKDECK_CLI_VERSION } from '@hookdeck-evals/sandbox'; + +/** + * Whether a cell's agent ran without the pinned Hookdeck CLI, and how it got + * round that. + * + * Every experiment is supposed to get the CLI baked into the sandbox image, so + * a row differs from its neighbour by skills and nothing else. On the Codex + * arms it was not on PATH: Codex runs each command in a login shell, and + * Debian's `/etc/profile` drops the npm prefix the CLI lives in. In release run + * 42044644850 every Codex attempt that invoked `hookdeck` met + * `command not found`, and the agents carried on through an absolute path into + * the package, `npx`, an unpinned `npx -y hookdeck-cli@latest`, or the REST API + * — all of which score, none of which is the baseline the row claims. + * + * The image now fixes the PATH and the sandbox refuses to start a cell whose + * shells cannot run the pin, so this should not fire on a new run for the + * first reason. It stays for two: rows already on disk carry it, and the + * self-check cannot see a CLI the agent fetches for itself mid-run. Flagged + * whether the cell passed or failed, because a passing row measured on a + * different CLI is still not comparable. + * + * Kept outside `scripts/triage.ts` because that file runs `main()` at module + * scope and so cannot be imported by a test. + */ +export interface PinnedCliEvidence { + /** The shell said `hookdeck` does not exist (bash's wording, or dash's). */ + notFound: boolean; + /** `hookdeck-cli` package specs the agent ran or installed that are not the pin. */ + unpinned: string[]; + /** It ran the platform binary inside the package directly. */ + absolutePath: boolean; +} + +const NOT_FOUND = /hookdeck: (command )?not found/; + +/** + * `npx hookdeck-cli@`, `npm install -g hookdeck-cli@`, and the bare + * `hookdeck-cli@` inside either. A spec with no version is not counted: npx + * resolved it to the installed 2.5.0 in every case run 42044644850 reported a + * version. + */ +const PACKAGE_SPEC = /hookdeck-cli@([A-Za-z0-9][\w.-]*)/g; + +const BINARY_PATH = /hookdeck-cli\/binaries\/[\w-]+\/hookdeck/; + +/** What a cell ran in a shell, and what came back, across every attempt. */ +export interface ShellActivity { + commands: string[]; + outputs: string[]; +} + +interface TranscriptLike { + type?: string; + input?: { command?: unknown }; + output?: unknown; + error?: unknown; +} + +export interface RowLike { + transcript?: TranscriptLike[]; + toolCalls?: unknown[]; + priorAttempts?: Array<{ transcript?: TranscriptLike[] }>; +} + +function asText(value: unknown): string { + if (value === undefined || value === null) return ''; + return typeof value === 'string' ? value : JSON.stringify(value); +} + +/** + * Shell commands only, by design. A docs page the agent fetched, or a README + * it wrote for the user, can say `npx hookdeck-cli@latest` without the agent + * having run it, and flagging that would make this cry wolf. Outputs are read + * only for the shell's own `not found`. + */ +export function shellActivity(row: RowLike): ShellActivity { + const commands: string[] = []; + const outputs: string[] = []; + const transcripts = [ + row.transcript ?? [], + ...(row.priorAttempts ?? []).map((attempt) => attempt.transcript ?? []), + ]; + for (const transcript of transcripts) { + for (const part of transcript) { + if (part?.type !== 'tool_call') continue; + const command = part.input?.command; + if (typeof command !== 'string') continue; + commands.push(command); + outputs.push(`${asText(part.output)}\n${asText(part.error)}`); + } + } + for (const raw of row.toolCalls ?? []) { + const call = raw as { + command?: unknown; + result?: unknown; + error?: unknown; + }; + if (typeof call?.command !== 'string') continue; + commands.push(call.command); + outputs.push(`${asText(call.result)}\n${asText(call.error)}`); + } + return { commands, outputs }; +} + +export function pinnedCliEvidence( + activity: ShellActivity, + pinned: string = HOOKDECK_CLI_VERSION +): PinnedCliEvidence | undefined { + const notFound = activity.outputs.some((output) => NOT_FOUND.test(output)); + const commands = activity.commands.join('\n'); + const unpinned = [ + ...new Set( + [...commands.matchAll(PACKAGE_SPEC)] + .map((match) => match[1]) + .filter((version) => version !== pinned && version !== `v${pinned}`) + .map((version) => `hookdeck-cli@${version}`) + ), + ].sort(); + const absolutePath = BINARY_PATH.test(commands); + if (!notFound && unpinned.length === 0) return undefined; + return { notFound, unpinned, absolutePath }; +} + +/** One line for `triage`. */ +export function describePinnedCliEvidence( + evidence: PinnedCliEvidence, + pinned: string = HOOKDECK_CLI_VERSION +): string { + const parts: string[] = []; + if (evidence.notFound) { + parts.push('`hookdeck: command not found` in its shell'); + } + if (evidence.unpinned.length > 0) { + parts.push(`ran ${evidence.unpinned.join(', ')} instead of ${pinned}`); + } + if (evidence.absolutePath) { + parts.push('called the binary inside the package by absolute path'); + } + return ( + `${parts.join('; ')}. This row was not measured with the pinned CLI the ` + + 'baseline promises, so do not compare it across agents' + ); +} diff --git a/apps/framework/scripts/triage.ts b/apps/framework/scripts/triage.ts index df72c41..a7783df 100644 --- a/apps/framework/scripts/triage.ts +++ b/apps/framework/scripts/triage.ts @@ -6,6 +6,12 @@ import { ERRORED_RUNS_DIRNAME, readErroredEvidenceTree, } from '../harness/errored-cell.js'; +import { + describePinnedCliEvidence, + pinnedCliEvidence, + type RowLike, + shellActivity, +} from '../lib/pinned-cli.js'; /** * Which cells of a run you have to read, and why. @@ -48,7 +54,7 @@ interface Check { passed?: boolean; } -interface Row { +interface Row extends RowLike { experiment: string; eval: string; passed?: boolean; @@ -237,6 +243,16 @@ function flagsFor(row: Row, requiredEnv: string[]): Flag[] { flags.push({ label: 'NO TOOL CALLS', detail: 'scored without acting' }); } + // Pass or fail: a row measured on a different CLI, or none, is not the + // baseline it claims to be either way. See `lib/pinned-cli.ts`. + const cli = pinnedCliEvidence(shellActivity(row)); + if (cli) { + flags.push({ + label: 'PINNED CLI NOT USED', + detail: describePinnedCliEvidence(cli), + }); + } + return flags; } diff --git a/apps/framework/test/pinned-cli.test.ts b/apps/framework/test/pinned-cli.test.ts new file mode 100644 index 0000000..d7fc453 --- /dev/null +++ b/apps/framework/test/pinned-cli.test.ts @@ -0,0 +1,118 @@ +import { describe, expect, it } from 'vitest'; +import { + describePinnedCliEvidence, + pinnedCliEvidence, + shellActivity, +} from '../lib/pinned-cli.js'; + +const call = (command: string, out: { output?: unknown; error?: string }) => ({ + type: 'tool_call', + name: 'command_execution', + input: { command }, + ...out, +}); + +describe('pinnedCliEvidence', () => { + it('flags the login-shell miss as Codex recorded it in run 42044644850', () => { + // Shape copied from a raw result: the error lands on the transcript part + // and on the tool call record alike. + const row = { + transcript: [ + call("/bin/bash -lc 'hookdeck ci && hookdeck whoami'", { + error: '/bin/bash: line 1: hookdeck: command not found\n', + }), + call( + '/home/node/.npm-global/lib/node_modules/hookdeck-cli/binaries/linux-amd64/hookdeck ci', + { output: 'Logged in' } + ), + ], + toolCalls: [ + { + command: "/bin/bash -lc 'hookdeck ci && hookdeck whoami'", + error: '/bin/bash: line 1: hookdeck: command not found\n', + }, + ], + }; + const evidence = pinnedCliEvidence(shellActivity(row), '2.5.0'); + expect(evidence).toEqual({ + notFound: true, + unpinned: [], + absolutePath: true, + }); + expect(describePinnedCliEvidence(evidence!, '2.5.0')).toMatch( + /command not found.*absolute path.*not measured with the pinned CLI/ + ); + }); + + it("recognises dash's wording too", () => { + const row = { + transcript: [ + call('sh -lc "hookdeck listen 3000"', { + error: 'sh: 1: hookdeck: not found', + }), + ], + }; + expect(pinnedCliEvidence(shellActivity(row), '2.5.0')?.notFound).toBe(true); + }); + + it('flags an unpinned CLI the agent fetched, in an earlier attempt too', () => { + const row = { + transcript: [], + priorAttempts: [ + { + transcript: [ + call("/bin/bash -lc 'npx -y hookdeck-cli@latest project list'", { + output: "You aren't authenticated yet.", + }), + call('npm install -g hookdeck-cli@3.1.0', { + output: 'added 1 package', + }), + ], + }, + ], + }; + expect(pinnedCliEvidence(shellActivity(row), '2.5.0')).toEqual({ + notFound: false, + unpinned: ['hookdeck-cli@3.1.0', 'hookdeck-cli@latest'], + absolutePath: false, + }); + }); + + it('does not flag the pin itself, or an unversioned npx that resolved to it', () => { + const row = { + transcript: [ + call('npx -y hookdeck-cli@2.5.0 --version', { + output: 'hookdeck version 2.5.0', + }), + call('npx --yes hookdeck-cli --version', { + output: 'hookdeck version 2.5.0', + }), + call('hookdeck listen 3000 stripe --output compact', { + output: 'Ready', + }), + ], + }; + expect(pinnedCliEvidence(shellActivity(row), '2.5.0')).toBeUndefined(); + }); + + it('reads commands, not documents the agent read or wrote', () => { + // A docs page or a README the agent wrote can mention an unpinned CLI + // without the agent having run one. + const row = { + transcript: [ + call('curl -s https://hookdeck.com/docs/cli', { + output: 'Run `npx hookdeck-cli@latest listen 3000`', + }), + { + type: 'tool_call', + name: 'file_change', + input: { + path: 'README.md', + content: 'npx hookdeck-cli@latest listen 3000', + }, + }, + ], + }; + expect(pinnedCliEvidence(shellActivity(row), '2.5.0')).toBeUndefined(); + }); +}); diff --git a/packages/sandbox/Dockerfile b/packages/sandbox/Dockerfile index 4510ccf..c52f428 100644 --- a/packages/sandbox/Dockerfile +++ b/packages/sandbox/Dockerfile @@ -7,13 +7,37 @@ RUN apt-get update -qq && apt-get install -y -qq --no-install-recommends \ ca-certificates curl git docker.io \ && rm -rf /var/lib/apt/lists/* -# Global npm installs (both the baked-in skills CLI below and the agent's own -# `npm install -g supabase` at setup time) land in a node-owned prefix instead -# of /usr/local, so they work without root/sudo — matching a typical user's +# Global npm installs (both the baked-in CLIs below and anything the agent +# installs with `npm install -g`) land in a node-owned prefix instead of +# /usr/local, so they work without root/sudo — matching a typical user's # machine, where global npm installs "just work" unelevated. +ENV NPM_CONFIG_PREFIX=/home/node/.npm-global + +# That prefix has to be on PATH in every shell an agent can start, and there +# are two kinds. A non-login shell (`bash -c`, which Claude Code and the +# harness use) inherits PATH from the environment, so the ENV below covers it. +# A login shell (`bash -lc`, which is how Codex runs every command) does not: +# Debian's /etc/profile overwrites PATH with a fixed list that has no npm +# prefix in it, so the pinned `hookdeck` was `command not found` on every Codex +# arm (found in run 42044644850; `toolchain-check.ts` now refuses to start a +# cell without it). /etc/profile then sources /etc/profile.d/*.sh, which is +# where the prefix is put back. +# +# A profile.d entry rather than symlinks into /usr/local/bin, because it covers +# the whole prefix: `skills`, and anything the agent itself installs globally +# mid-run, which a symlink made at build time cannot know about. +ENV PATH=/home/node/.npm-global/bin:$PATH +RUN printf '%s\n' \ + '# hookdeck-evals sandbox: /etc/profile resets PATH; put the npm prefix back.' \ + 'case ":${PATH}:" in' \ + ' *:/home/node/.npm-global/bin:*) ;;' \ + ' *) PATH="/home/node/.npm-global/bin:${PATH}"; export PATH ;;' \ + 'esac' \ + > /etc/profile.d/npm-global.sh \ + && chmod 0644 /etc/profile.d/npm-global.sh + USER node RUN mkdir -p /home/node/.npm-global -ENV NPM_CONFIG_PREFIX=/home/node/.npm-global # Vercel's agent-skills CLI, used to install agent skills from local sources # into each session's workspace (both modes). Baked in (pinned) so installs are diff --git a/packages/sandbox/src/agent-environment.ts b/packages/sandbox/src/agent-environment.ts index 6437684..f1aeab5 100644 --- a/packages/sandbox/src/agent-environment.ts +++ b/packages/sandbox/src/agent-environment.ts @@ -23,6 +23,7 @@ import type { SkillSource } from '@hookdeck-evals/core'; import { DockerSandbox } from './docker-sandbox.js'; import { ensureSandboxImage } from './image.js'; import { installSkills, type SkillEntry } from './skills.js'; +import { assertPinnedToolchain } from './toolchain-check.js'; export interface AgentEnvironmentOptions { /** Host directory whose contents seed the workspace. */ @@ -55,6 +56,10 @@ export async function createAgentEnvironment( // internet. Upstream used host networking only for the local stack. const sandbox = await DockerSandbox.create({ image }); try { + // Before anything is seeded or installed, and before credentials are in + // the environment: a sandbox whose shells cannot run the pinned CLI must + // error the cell rather than be scored. See `toolchain-check.ts`. + await assertPinnedToolchain(sandbox); if (options.localDir) { const seeded = expandSeedPlaceholders( options.localDir, diff --git a/packages/sandbox/src/docker-sandbox.ts b/packages/sandbox/src/docker-sandbox.ts index dbfd098..3f40b80 100644 --- a/packages/sandbox/src/docker-sandbox.ts +++ b/packages/sandbox/src/docker-sandbox.ts @@ -57,6 +57,12 @@ export const SANDBOX_CONTAINER_LABEL = 'supabase-evals-sandbox'; */ const CLIENT_TIMEOUT_HEADROOM_MS = 20_000; +/** + * PATH for commands the harness runs. Covers a non-login shell only: a login + * shell (`bash -lc`, which Codex uses for every command) re-reads + * /etc/profile and replaces it, which is why the image also puts the npm + * prefix back from /etc/profile.d. See the Dockerfile and `toolchain-check.ts`. + */ const SANDBOX_PATH = [ '/home/node/.npm-global/bin', '/usr/local/sbin', diff --git a/packages/sandbox/src/image.ts b/packages/sandbox/src/image.ts index 2265114..7bf8139 100644 --- a/packages/sandbox/src/image.ts +++ b/packages/sandbox/src/image.ts @@ -8,6 +8,7 @@ * retry helper, with no Supabase-specific logic to strip. */ +import { createHash } from 'node:crypto'; import { readFileSync } from 'node:fs'; import { fileURLToPath } from 'node:url'; import { dockerCli } from './docker-sandbox.js'; @@ -72,15 +73,34 @@ export const SANDBOX_DOCKERFILE_PATH = fileURLToPath( new URL('../Dockerfile', import.meta.url) ); +/** + * The tag a given Dockerfile builds to. + * + * The Dockerfile's own hash is part of it, not only the two pins. An image is + * reused whenever its tag exists, so a tag made of the pins alone meant an edit + * to the Dockerfile never reached a machine that had built the image before: + * the PATH fix for login shells would have been silently skipped on every + * machine with a cached image, and the toolchain check would then have refused + * every cell there. + */ +export function sandboxImageTag(dockerfile: string): string { + const definition = createHash('sha256') + .update(dockerfile) + .digest('hex') + .slice(0, 12); + return ( + `${SANDBOX_IMAGE_REPOSITORY}:` + + `skills-${SKILLS_CLI_VERSION}-hookdeck-${HOOKDECK_CLI_VERSION}-${definition}` + ); +} + /** Build (or reuse) the sandbox image and return its tag. */ export async function ensureSandboxImage(): Promise { - const tag = - `${SANDBOX_IMAGE_REPOSITORY}:` + - `skills-${SKILLS_CLI_VERSION}-hookdeck-${HOOKDECK_CLI_VERSION}`; + const dockerfile = readFileSync(SANDBOX_DOCKERFILE_PATH, 'utf8'); + const tag = sandboxImageTag(dockerfile); const existing = await dockerCli(['image', 'inspect', tag]); if (existing.ok) return tag; - const dockerfile = readFileSync(SANDBOX_DOCKERFILE_PATH, 'utf8'); await withTransientRetries( `build ${tag}`, () => diff --git a/packages/sandbox/src/index.ts b/packages/sandbox/src/index.ts index 6710de8..d568d28 100644 --- a/packages/sandbox/src/index.ts +++ b/packages/sandbox/src/index.ts @@ -5,6 +5,7 @@ export type { } from './docker-sandbox.js'; export { ensureSandboxImage, + sandboxImageTag, SANDBOX_DOCKERFILE_PATH, // Exported for provenance: the CLI pin is part of what a published row was // measured under, and a bump changes the product under test. See #60. @@ -31,4 +32,9 @@ export type { AgentEnvironment, AgentEnvironmentOptions, } from './agent-environment.js'; +export { + assertPinnedToolchain, + toolchainProblem, + TOOLCHAIN_PROBES, +} from './toolchain-check.js'; export type { SandboxCommandResult } from './types.js'; diff --git a/packages/sandbox/src/toolchain-check.ts b/packages/sandbox/src/toolchain-check.ts new file mode 100644 index 0000000..d6a7b7f --- /dev/null +++ b/packages/sandbox/src/toolchain-check.ts @@ -0,0 +1,121 @@ +/** + * A sandbox self-check: is the pinned Hookdeck CLI what an agent's shell + * actually runs? + * + * Every experiment is meant to differ from its neighbour by skills and nothing + * else, and the pinned CLI is part of the baseline both arms share. Nothing + * checked that it was reachable. It was not, on every Codex arm: Codex runs + * each command as `/bin/bash -lc`, a login shell, and Debian's `/etc/profile` + * overwrites PATH with a fixed list that leaves out the npm prefix the CLI is + * installed into. In release matrix run 42044644850 every Codex attempt that + * invoked `hookdeck` met `command not found` at least once — 26/26, 18/22, + * 16/16 and 19/19 across the four Codex arms — and worked around it with an + * absolute path into the package, `npx hookdeck`, an unpinned + * `npx -y hookdeck-cli@latest`, or the REST API. Claude Code runs a non-login + * shell, inherits the harness's PATH, and was unaffected. Those rows were + * scored and published as though both agents had the same CLI. + * + * So this runs both kinds of shell before the agent is installed, and refuses + * the cell when either does not resolve the pinned version. Throwing is the + * point: `createAgentEnvironment` throws, `runOne` throws, and the cell lands + * in `errored` with no result file — the same route as the empty-transcript + * and dead-process guards in `run-eval.ts`. An agent working without the tool + * the scenario assumes is not a result about the agent. + * + * `--version` rather than `hookdeck version`, deliberately. Cobra answers the + * flag before any of the CLI's own initialisation runs, so it creates no + * config file and makes no network call. `hookdeck version` does both — it + * initialises (and if absent, creates) `~/.config/hookdeck/config.toml` and + * asks GitHub for the latest release — which would change the state the agent + * finds and add a dependency that can fail a cell for reasons no agent caused. + */ + +import { HOOKDECK_CLI_VERSION } from './image.js'; +import type { SandboxCommandResult } from './types.js'; + +const PROBE = 'command -v hookdeck && hookdeck --version'; + +/** + * The two shells an agent can be handed. `runShell` already runs `bash -c` + * with the harness's PATH, so the login probe nests a `bash -lc` inside it, + * which is exactly what Codex does. + */ +export const TOOLCHAIN_PROBES = [ + { shell: 'non-login (bash -c)', command: PROBE }, + { shell: 'login (bash -lc)', command: `bash -lc '${PROBE}'` }, +] as const; + +const PROBE_TIMEOUT_MS = 60_000; + +export interface ToolchainProbeResult { + shell: string; + result: SandboxCommandResult; +} + +/** + * What is wrong with one probe's result, or `undefined` if it resolved the + * pinned CLI. Pure, so the rule can be tested without Docker. + */ +export function toolchainProblem( + probe: ToolchainProbeResult, + expectedVersion: string = HOOKDECK_CLI_VERSION +): string | undefined { + const { shell, result } = probe; + const output = `${result.stdout}\n${result.stderr}`.trim(); + if (!result.ok) { + return ( + `${shell}: \`hookdeck\` did not resolve or did not run ` + + `(exit ${result.exitCode ?? 'unknown'}): ${oneLine(output) || 'no output'}` + ); + } + // A whole whitespace-delimited token, so 12.5.0 and 2.5.0-beta.1 do not + // pass for 2.5.0. + const version = new RegExp( + `(^|\\s)v?${escapeRegExp(expectedVersion)}(\\s|$)` + ); + if (!version.test(result.stdout)) { + return ( + `${shell}: \`hookdeck\` resolved but is not the pinned ${expectedVersion}: ` + + oneLine(output) + ); + } + return undefined; +} + +/** + * Run every probe and throw if any shell would not hand the agent the pinned + * CLI. Accepts the narrow `runShell` surface so it can be exercised with a + * fake. + */ +export async function assertPinnedToolchain(sandbox: { + runShell( + command: string, + options?: { timeoutMs?: number } + ): Promise; +}): Promise { + const problems: string[] = []; + for (const { shell, command } of TOOLCHAIN_PROBES) { + const result = await sandbox.runShell(command, { + timeoutMs: PROBE_TIMEOUT_MS, + }); + const problem = toolchainProblem({ shell, result }); + if (problem) problems.push(problem); + } + if (problems.length > 0) { + throw new Error( + 'sandbox self-check failed: the pinned Hookdeck CLI is not what an ' + + `agent's shell runs, so this cell was not started and is not scored. ` + + `${problems.join('; ')}. The PATH for both shells is set in ` + + 'packages/sandbox/Dockerfile.' + ); + } +} + +function oneLine(text: string): string { + const flat = text.replace(/\s+/g, ' ').trim(); + return flat.length > 300 ? `${flat.slice(0, 300)}…` : flat; +} + +function escapeRegExp(value: string): string { + return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); +} diff --git a/packages/sandbox/test/toolchain-check.test.ts b/packages/sandbox/test/toolchain-check.test.ts new file mode 100644 index 0000000..4597a24 --- /dev/null +++ b/packages/sandbox/test/toolchain-check.test.ts @@ -0,0 +1,182 @@ +import { spawnSync } from 'node:child_process'; +import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs'; +import { tmpdir } from 'node:os'; +import { join } from 'node:path'; +import { describe, expect, it } from 'vitest'; +import { + HOOKDECK_CLI_VERSION, + SANDBOX_DOCKERFILE_PATH, + sandboxImageTag, +} from '../src/image.js'; +import { + assertPinnedToolchain, + TOOLCHAIN_PROBES, + toolchainProblem, +} from '../src/toolchain-check.js'; +import type { SandboxCommandResult } from '../src/types.js'; + +const NPM_BIN = '/home/node/.npm-global/bin'; +/** What Debian's /etc/profile sets for a non-root login shell. */ +const DEBIAN_LOGIN_PATH = + '/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games'; + +const ok = (stdout: string): SandboxCommandResult => ({ + ok: true, + exitCode: 0, + stdout, + stderr: '', +}); +const notFound: SandboxCommandResult = { + ok: false, + exitCode: 127, + stdout: '', + stderr: '/bin/bash: line 1: hookdeck: command not found\n', +}; +const resolved = ok( + `${NPM_BIN}/hookdeck\nhookdeck version ${HOOKDECK_CLI_VERSION}\n` +); + +describe('toolchainProblem', () => { + it('accepts a shell that resolves the pinned version', () => { + expect( + toolchainProblem({ shell: 'login', result: resolved }) + ).toBeUndefined(); + expect( + toolchainProblem({ + shell: 'login', + result: ok(`hookdeck version v${HOOKDECK_CLI_VERSION}\n`), + }) + ).toBeUndefined(); + }); + + it('refuses the shell that cannot find it, which is what Codex got', () => { + const problem = toolchainProblem({ shell: 'login', result: notFound }); + expect(problem).toMatch(/^login: /); + expect(problem).toContain('command not found'); + expect(problem).toContain('exit 127'); + }); + + it('refuses a different version, including one that contains the pin', () => { + for (const other of ['2.5.1', '12.5.0', '2.5.0-beta.1', '3.1.0']) { + expect( + toolchainProblem( + { shell: 'login', result: ok(`hookdeck version ${other}\n`) }, + '2.5.0' + ) + ).toContain('not the pinned 2.5.0'); + } + }); +}); + +describe('assertPinnedToolchain', () => { + const fake = (byCommand: (command: string) => SandboxCommandResult) => { + const seen: string[] = []; + return { + seen, + runShell: async (command: string) => { + seen.push(command); + return byCommand(command); + }, + }; + }; + + it('probes a non-login shell and a nested login shell', async () => { + const sandbox = fake(() => resolved); + await assertPinnedToolchain(sandbox); + expect(sandbox.seen).toEqual(TOOLCHAIN_PROBES.map((p) => p.command)); + expect(sandbox.seen.some((c) => c.startsWith('bash -lc '))).toBe(true); + // `--version` is answered before the CLI initialises, so the probe + // creates no config file and makes no network call. `hookdeck version` + // would do both inside the agent's sandbox. + for (const command of sandbox.seen) { + expect(command).toContain('hookdeck --version'); + expect(command).not.toMatch(/hookdeck version/); + } + }); + + it('throws when only the login shell is broken, naming it', async () => { + const sandbox = fake((command) => + command.startsWith('bash -lc') ? notFound : resolved + ); + await expect(assertPinnedToolchain(sandbox)).rejects.toThrow( + /sandbox self-check failed.*not scored.*login \(bash -lc\).*command not found/s + ); + }); +}); + +/** + * The /etc/profile.d entry, extracted from the Dockerfile and run under `sh` + * the way Debian's /etc/profile sources it: after PATH has been reset to the + * login list. Docker is not needed, so this runs in CI on every pull request, + * where the image itself is only built by an eval run. + */ +describe('sandbox Dockerfile PATH for login shells', () => { + const dockerfile = readFileSync(SANDBOX_DOCKERFILE_PATH, 'utf8'); + + const profileScript = () => { + const start = dockerfile.indexOf("RUN printf '%s\\n' \\"); + const end = dockerfile.indexOf('> /etc/profile.d/npm-global.sh', start); + expect(start).toBeGreaterThan(-1); + expect(end).toBeGreaterThan(start); + const lines = dockerfile + .slice(start, end) + .split('\n') + .slice(1) + .map((line) => line.trim()) + .filter((line) => line.startsWith("'")) + .map((line) => line.replace(/^'/, '').replace(/' \\$/, '')); + expect(lines.length).toBeGreaterThan(0); + const dir = mkdtempSync(join(tmpdir(), 'hd-profile-')); + const path = join(dir, 'npm-global.sh'); + writeFileSync(path, `${lines.join('\n')}\n`); + return path; + }; + + const sourced = (script: string, times: number) => { + const body = Array.from({ length: times }, () => '. "$1"').join('; '); + const result = spawnSync( + 'sh', + ['-c', `${body}; printf %s "$PATH"`, 'sh', script], + { + env: { PATH: DEBIAN_LOGIN_PATH }, + encoding: 'utf8', + } + ); + expect(result.status, result.stderr).toBe(0); + return result.stdout; + }; + + it('puts the npm prefix back in front of the login PATH', () => { + expect(sourced(profileScript(), 1)).toBe(`${NPM_BIN}:${DEBIAN_LOGIN_PATH}`); + }); + + it('adds it once however often it is sourced', () => { + expect(sourced(profileScript(), 3)).toBe(`${NPM_BIN}:${DEBIAN_LOGIN_PATH}`); + }); + + it('writes it as root, before the image switches to the node user', () => { + expect(dockerfile.indexOf('/etc/profile.d/npm-global.sh')).toBeLessThan( + dockerfile.indexOf('USER node') + ); + }); + + it('covers non-login shells through the image environment as well', () => { + expect(dockerfile).toContain(`ENV PATH=${NPM_BIN}:$PATH`); + expect(dockerfile).toContain( + 'ENV NPM_CONFIG_PREFIX=/home/node/.npm-global' + ); + }); +}); + +describe('sandboxImageTag', () => { + it('changes when the Dockerfile does, so an edit reaches a cached machine', () => { + const dockerfile = readFileSync(SANDBOX_DOCKERFILE_PATH, 'utf8'); + expect(sandboxImageTag(dockerfile)).not.toBe( + sandboxImageTag(`${dockerfile}\n# edit\n`) + ); + expect(sandboxImageTag(dockerfile)).toBe(sandboxImageTag(dockerfile)); + expect(sandboxImageTag(dockerfile)).toContain( + `hookdeck-${HOOKDECK_CLI_VERSION}` + ); + }); +}); From 4ce8d1f9105b4173b044b74da05342061fab3787 Mon Sep 17 00:00:00 2001 From: Phil Leggetter Date: Thu, 5 Nov 2026 21:10:59 +0000 Subject: [PATCH 2/5] Include the sandbox image definition in the harness fingerprint The login-shell PATH fix changed only the Dockerfile, and it gave the Codex arms the pinned Hookdeck CLI they had been missing. The harness fingerprint covered the base prompt, the CLI pin, the skills CLI and the skills submodule pin, so rows measured with and without the CLI on PATH would have carried the same `harness` hash and read as measured under one instrument. `harnessFingerprint` now also hashes the image definition: the same 12-character Dockerfile hash the image tag uses, exported from the sandbox package as `sandboxImageDefinition`. Every row recorded before this change has a different `harness` from every row after it, which is the point; `export-results --merge` will report carried-forward rows as measured under a different harness. reference/results-format.md and the two code comments that list the fingerprint inputs now name the image definition. Co-Authored-By: Claude Opus 5.5 --- apps/framework/lib/provenance.ts | 19 ++++++++++++++-- apps/framework/test/provenance.test.ts | 30 ++++++++++++++++++++++++++ packages/core/src/eval-metadata.ts | 3 ++- packages/sandbox/src/image.ts | 22 ++++++++++++++----- packages/sandbox/src/index.ts | 2 ++ reference/results-format.md | 8 +++++-- 6 files changed, 74 insertions(+), 10 deletions(-) diff --git a/apps/framework/lib/provenance.ts b/apps/framework/lib/provenance.ts index c29e609..080fbb3 100644 --- a/apps/framework/lib/provenance.ts +++ b/apps/framework/lib/provenance.ts @@ -5,6 +5,7 @@ import { join } from 'node:path'; import { HOOKDECK_CLI_VERSION, SKILLS_CLI_VERSION, + sandboxImageDefinition, } from '@hookdeck-evals/sandbox'; /** @@ -36,7 +37,10 @@ import { * instead of making it by default. */ export interface Provenance { - /** The harness every scenario shares: base prompt, CLI pin, skills pin. */ + /** + * The harness every scenario shares: base prompt, CLI pin, skills pin, + * sandbox image definition. + */ harness: string; /** The scenario's own files. Changes when its prompt, seed or scorer does. */ scenario: string; @@ -110,14 +114,25 @@ export function skillsPin(root: string): string { * exactly what happened on 27 August and is why this module exists now rather * than later. The skill *context* is deliberately excluded: that varies by arm * and is the treatment being measured, not a change to the instrument. + * + * The sandbox image definition is in here because the image decides what an + * agent's shell can run. Until it was, a Dockerfile change that gave Codex the + * pinned CLI it had been missing on PATH left every row's harness hash exactly + * where it was, so rows measured with and without the CLI read as measured + * under one instrument. */ -export function harnessFingerprint(basePrompt: string, root: string): string { +export function harnessFingerprint( + basePrompt: string, + root: string, + imageDefinition: string = sandboxImageDefinition() +): string { return short( [ `base-prompt:${basePrompt}`, `hookdeck-cli:${HOOKDECK_CLI_VERSION}`, `skills-cli:${SKILLS_CLI_VERSION}`, `skills-pin:${skillsPin(root)}`, + `sandbox-image:${imageDefinition}`, ].join('\n') ); } diff --git a/apps/framework/test/provenance.test.ts b/apps/framework/test/provenance.test.ts index 782ae46..b62ca65 100644 --- a/apps/framework/test/provenance.test.ts +++ b/apps/framework/test/provenance.test.ts @@ -3,7 +3,9 @@ import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { afterEach, describe, expect, it } from 'vitest'; +import { sandboxImageDefinition } from '@hookdeck-evals/sandbox'; import { + harnessFingerprint, SKILLS_PIN_DIRTY_SUFFIX, SKILLS_PIN_UNAVAILABLE, scenarioFingerprint, @@ -137,3 +139,31 @@ describe('skillsPin', () => { expect(skillsPin(root)).not.toBe(git(root, 'rev-parse', 'HEAD')); }); }); + +describe('harnessFingerprint', () => { + // A root with no skills submodule, so the pin is constant across calls. + const root = () => { + const dir = mkdtempSync(join(tmpdir(), 'prov-root-')); + dirs.push(dir); + return dir; + }; + + it('changes when the sandbox image definition does', () => { + // The login-shell PATH fix changed only the Dockerfile, and gave Codex a + // CLI it had not had. Rows either side of it must not share a harness. + const r = root(); + expect(harnessFingerprint('prompt', r, 'aaaaaaaaaaaa')).not.toBe( + harnessFingerprint('prompt', r, 'bbbbbbbbbbbb') + ); + }); + + it('reads the real Dockerfile by default, and is stable', () => { + const r = root(); + expect(harnessFingerprint('prompt', r)).toBe( + harnessFingerprint('prompt', r, sandboxImageDefinition()) + ); + expect(harnessFingerprint('prompt', r)).toBe( + harnessFingerprint('prompt', r) + ); + }); +}); diff --git a/packages/core/src/eval-metadata.ts b/packages/core/src/eval-metadata.ts index f9ad9e4..5bace16 100644 --- a/packages/core/src/eval-metadata.ts +++ b/packages/core/src/eval-metadata.ts @@ -490,7 +490,8 @@ const evalResultShape = { runId: z.string().optional(), /** * What the row was measured under: a fingerprint of the harness every - * scenario shares (base prompt, CLI pin, skills pin) and one of the + * scenario shares (base prompt, CLI pin, skills pin, sandbox image + * definition) and one of the * scenario's own files. `export-results --merge` compares a carried row's * against the fresh rows' to say whether it is still current. * diff --git a/packages/sandbox/src/image.ts b/packages/sandbox/src/image.ts index 7bf8139..a83021b 100644 --- a/packages/sandbox/src/image.ts +++ b/packages/sandbox/src/image.ts @@ -84,16 +84,28 @@ export const SANDBOX_DOCKERFILE_PATH = fileURLToPath( * every cell there. */ export function sandboxImageTag(dockerfile: string): string { - const definition = createHash('sha256') - .update(dockerfile) - .digest('hex') - .slice(0, 12); return ( `${SANDBOX_IMAGE_REPOSITORY}:` + - `skills-${SKILLS_CLI_VERSION}-hookdeck-${HOOKDECK_CLI_VERSION}-${definition}` + `skills-${SKILLS_CLI_VERSION}-hookdeck-${HOOKDECK_CLI_VERSION}-` + + sandboxImageDefinition(dockerfile) ); } +/** + * A short hash of the image definition: the Dockerfile's bytes. + * + * Exported for provenance as well as the tag. The image is part of the + * instrument, and the case that made it so is the login-shell PATH: the same + * pins, the same prompt and the same skills gave Codex no `hookdeck` on PATH + * before the Dockerfile changed and the pinned one after. A row's provenance + * has to tell those apart, and the pins alone cannot. + */ +export function sandboxImageDefinition( + dockerfile: string = readFileSync(SANDBOX_DOCKERFILE_PATH, 'utf8') +): string { + return createHash('sha256').update(dockerfile).digest('hex').slice(0, 12); +} + /** Build (or reuse) the sandbox image and return its tag. */ export async function ensureSandboxImage(): Promise { const dockerfile = readFileSync(SANDBOX_DOCKERFILE_PATH, 'utf8'); diff --git a/packages/sandbox/src/index.ts b/packages/sandbox/src/index.ts index d568d28..26f9696 100644 --- a/packages/sandbox/src/index.ts +++ b/packages/sandbox/src/index.ts @@ -6,6 +6,8 @@ export type { export { ensureSandboxImage, sandboxImageTag, + // Also for provenance: the image definition is part of the instrument. + sandboxImageDefinition, SANDBOX_DOCKERFILE_PATH, // Exported for provenance: the CLI pin is part of what a published row was // measured under, and a bump changes the product under test. See #60. diff --git a/reference/results-format.md b/reference/results-format.md index c63e561..51e03d4 100644 --- a/reference/results-format.md +++ b/reference/results-format.md @@ -73,8 +73,12 @@ with a warning rather than published as a failure. `low` | `medium` | `high` | `max`. `provenance`: what the row was measured under. `harness` covers what every -scenario shares — the base prompt, the sandbox CLI pin, the skills CLI and the -skills submodule pin — and `scenario` covers the scenario's own files. Two rows +scenario shares — the base prompt, the sandbox CLI pin, the skills CLI, the +skills submodule pin and the sandbox image definition (the Dockerfile) — and +`scenario` covers the scenario's own files. The image definition joined in +November 2026, so every row recorded before then has a different `harness` +from every row after it; that is correct, because the image change gave Codex +the pinned CLI on PATH for the first time. Two rows with the same `scenario` and different `harness` measured the same task under a different instrument. Opaque: compare for equality, do not parse. `skillsPin` is the skills submodule commit the row ran against, in the clear, possibly with a From df6cb2b7727f8a5f1ea886ec3004a63185196812 Mon Sep 17 00:00:00 2001 From: Phil Leggetter Date: Thu, 5 Nov 2026 21:13:44 +0000 Subject: [PATCH 3/5] Cancel the run when the sandbox fails its self-check A failed sandbox self-check is systemic: every matrix job builds the same image from the same Dockerfile, so one broken image errors every cell. Until now each cell errored on its own and the matrix ran to the end. Reuse the provider-refusal path (#103): - Run evals: when the eval exits non-zero and the log contains `sandbox self-check failed`, write sandbox-broken.marker (experiment, eval, matched string; no log lines) and exit 1. - Record broken sandbox: upload it as `sandbox-broken-__`, kept 90 days like the provider marker. - Cancel the run: now fires on either marker. - publish-results: refuses a run with any `sandbox-broken-*` artifact, the same way it refuses `provider-refused-*`, so a cancel that does not take still cannot publish. The string is exported from toolchain-check.ts as SANDBOX_SELF_CHECK_FAILED and starts the error the check throws. A test fails if eval-refresh.yml stops matching it. AGENTS.md's Trap entry says what CI does with the failure. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/eval-refresh.yml | 45 +++++++++++++++++-- AGENTS.md | 6 ++- packages/sandbox/src/index.ts | 1 + packages/sandbox/src/toolchain-check.ts | 12 ++++- packages/sandbox/test/toolchain-check.test.ts | 20 +++++++++ 5 files changed, 78 insertions(+), 6 deletions(-) diff --git a/.github/workflows/eval-refresh.yml b/.github/workflows/eval-refresh.yml index 41fabf8..e6cbde8 100644 --- a/.github/workflows/eval-refresh.yml +++ b/.github/workflows/eval-refresh.yml @@ -455,6 +455,25 @@ jobs: exit 1 fi + # The same treatment for a sandbox that fails its own self-check + # (`packages/sandbox/src/toolchain-check.ts`). It runs before the + # agent is installed and errors the cell when the pinned Hookdeck CLI + # is not what the agent's shells resolve. Every job builds the same + # image from the same Dockerfile, so one failure means all of them + # will fail, and the run should stop rather than error every remaining + # cell one at a time. The string is the error's own prefix, and a test in + # `packages/sandbox` fails if the two drift apart. + sandbox_broken="sandbox self-check failed" + if [ "$eval_status" -ne 0 ] && grep -qF "$sandbox_broken" "$run_log"; then + echo "::error::The sandbox image failed its self-check: the pinned Hookdeck CLI is not on PATH for the agent's shells. Cancelling the run: every remaining job builds the same image." + { + echo "experiment=${{ matrix.experiment }}" + echo "eval=${{ matrix.eval_id }}" + echo "matched=${sandbox_broken}" + } > sandbox-broken.marker + exit 1 + fi + if [ "$eval_status" -ne 0 ]; then exit "$eval_status" fi @@ -490,13 +509,25 @@ jobs: # later still sees it. retention-days: 90 + # The same fallback for a sandbox that failed its self-check: if the + # cancel below does not take, `publish-results` still refuses the run. + - name: Record broken sandbox + if: ${{ failure() && hashFiles('sandbox-broken.marker') != '' }} + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: sandbox-broken-${{ matrix.experiment }}__${{ matrix.eval_id }} + path: sandbox-broken.marker + if-no-files-found: error + retention-days: 90 + - name: Cancel the run # Fails closed. This used to be `gh run cancel … || true` inside the # step above, so a cancel that did not take let every remaining job run # and pay. Retried, and if it still fails the error says so: the # marker above still stops `publish-results`, but the remaining cells - # will run until somebody cancels by hand. - if: ${{ failure() && hashFiles('provider-refused.marker') != '' }} + # will run until somebody cancels by hand. Either marker cancels: a + # provider refusal and a broken sandbox both fail every remaining job. + if: ${{ failure() && hashFiles('provider-refused.marker', 'sandbox-broken.marker') != '' }} shell: bash run: | for attempt in 1 2 3; do @@ -507,7 +538,7 @@ jobs: echo "gh run cancel failed (attempt ${attempt}), retrying" sleep $((attempt * 10)) done - echo "::error::Could not cancel run ${{ github.run_id }} after three attempts. The provider-refusal marker stops publish-results, but the remaining cells will keep running and billing: cancel the run by hand." + echo "::error::Could not cancel run ${{ github.run_id }} after three attempts. The marker uploaded above stops publish-results, but the remaining cells will keep running and billing: cancel the run by hand." exit 1 - name: Upload raw results @@ -723,6 +754,14 @@ jobs: echo "::error::A provider refused requests during this run, so it is not published, whatever the floor says: $(paste -sd, - <<< "$refused")" exit 1 fi + # Likewise a sandbox that failed its self-check. Every job builds the + # same image, so whatever came back is a run with a broken instrument, + # and a merge would fill its holes with carried-forward rows. + broken="$(grep -E '^sandbox-broken-' <<< "$available" || true)" + if [ -n "$broken" ]; then + echo "::error::The sandbox image failed its self-check during this run, so it is not published, whatever the floor says: $(paste -sd, - <<< "$broken")" + exit 1 + fi while IFS= read -r name; do if grep -qxF "$name" <<< "$available"; then gh run download ${{ github.run_id }} --name "$name" --dir "downloaded-results/$name" diff --git a/AGENTS.md b/AGENTS.md index e8d132a..29f3fb2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1332,8 +1332,10 @@ unpinned `npx -y hookdeck-cli@latest`, or not at all — all of it scored as though both agents had the same baseline. So anything an agent needs on PATH has to be on it for both kinds of shell: the image sets it in `ENV` and again in `/etc/profile.d/`, and `toolchain-check.ts` errors a cell before it starts -if either shell does not resolve the pinned version. Setting `PATH` on -`docker exec` alone is not enough. +if either shell does not resolve the pinned version. In CI that failure is +treated like a provider refusal: it leaves a `sandbox-broken` marker that +`publish-results` refuses on and cancels the run, because every job builds the +same image. Setting `PATH` on `docker exec` alone is not enough. **Credentials reach the agent through `EvalSession.sandboxEnv`.** The session is created before the sandbox because the sandbox needs the lease. Disposal runs in diff --git a/packages/sandbox/src/index.ts b/packages/sandbox/src/index.ts index 26f9696..eccb838 100644 --- a/packages/sandbox/src/index.ts +++ b/packages/sandbox/src/index.ts @@ -36,6 +36,7 @@ export type { } from './agent-environment.js'; export { assertPinnedToolchain, + SANDBOX_SELF_CHECK_FAILED, toolchainProblem, TOOLCHAIN_PROBES, } from './toolchain-check.js'; diff --git a/packages/sandbox/src/toolchain-check.ts b/packages/sandbox/src/toolchain-check.ts index d6a7b7f..2bcb4a2 100644 --- a/packages/sandbox/src/toolchain-check.ts +++ b/packages/sandbox/src/toolchain-check.ts @@ -35,6 +35,16 @@ import type { SandboxCommandResult } from './types.js'; const PROBE = 'command -v hookdeck && hookdeck --version'; +/** + * The prefix of the error this check throws. The `Run evals` step in + * `eval-refresh.yml` greps the job log for it, treats it as a run-level + * failure like a provider refusal, leaves a `sandbox-broken` marker that + * `publish-results` refuses on, and cancels the run: every job builds the + * same image, so one broken sandbox means all of them are. A test fails if + * the workflow and this string drift apart. + */ +export const SANDBOX_SELF_CHECK_FAILED = 'sandbox self-check failed'; + /** * The two shells an agent can be handed. `runShell` already runs `bash -c` * with the harness's PATH, so the login probe nests a `bash -lc` inside it, @@ -103,7 +113,7 @@ export async function assertPinnedToolchain(sandbox: { } if (problems.length > 0) { throw new Error( - 'sandbox self-check failed: the pinned Hookdeck CLI is not what an ' + + `${SANDBOX_SELF_CHECK_FAILED}: the pinned Hookdeck CLI is not what an ` + `agent's shell runs, so this cell was not started and is not scored. ` + `${problems.join('; ')}. The PATH for both shells is set in ` + 'packages/sandbox/Dockerfile.' diff --git a/packages/sandbox/test/toolchain-check.test.ts b/packages/sandbox/test/toolchain-check.test.ts index 4597a24..4e74cad 100644 --- a/packages/sandbox/test/toolchain-check.test.ts +++ b/packages/sandbox/test/toolchain-check.test.ts @@ -10,6 +10,7 @@ import { } from '../src/image.js'; import { assertPinnedToolchain, + SANDBOX_SELF_CHECK_FAILED, TOOLCHAIN_PROBES, toolchainProblem, } from '../src/toolchain-check.js'; @@ -102,6 +103,25 @@ describe('assertPinnedToolchain', () => { /sandbox self-check failed.*not scored.*login \(bash -lc\).*command not found/s ); }); + + it('fails with the string CI cancels the run on', async () => { + // `eval-refresh.yml` greps the job log for this prefix to cancel the run + // and leave a `sandbox-broken` marker that blocks publishing. If the two + // drift, a broken image goes back to erroring every cell one at a time. + const workflow = readFileSync( + new URL('../../../.github/workflows/eval-refresh.yml', import.meta.url), + 'utf8' + ); + expect(workflow).toContain(`sandbox_broken="${SANDBOX_SELF_CHECK_FAILED}"`); + expect(workflow).toContain('> sandbox-broken.marker'); + expect(workflow).toMatch(/grep -E '\^sandbox-broken-'/); + + const sandbox = fake(() => notFound); + const error = await assertPinnedToolchain(sandbox).catch((e) => e); + expect(String(error.message).startsWith(SANDBOX_SELF_CHECK_FAILED)).toBe( + true + ); + }); }); /** From 041428690b0beaacab879342c538b1d7fd9c3b67 Mon Sep 17 00:00:00 2001 From: Phil Leggetter Date: Thu, 5 Nov 2026 21:31:11 +0000 Subject: [PATCH 4/5] Cancel only on a deterministic self-check failure Review fixes for the sandbox self-check and the wording around it. The self-check gave every failed probe the `sandbox self-check failed` prefix, which CI now treats as a run-level failure. An in-container timeout (124/137), a `docker exec` the daemon refused or a container that had died would therefore have cancelled the whole matrix over one cell's bad minute. - The probe now prints a sentinel and exits 3 when `command -v hookdeck` resolves nothing, so a missing CLI cannot be confused with `docker exec` exiting 1 for a dead container. - Only two outcomes are facts about the image and carry the cancelling prefix: no `hookdeck` on PATH, or a recognisable version line that is not the pin. Anything else, including a probe that throws, is retried once and then throws `sandbox self-check could not complete`, which errors that cell alone. A test holds the second prefix to not containing the first. - Tests run the real probe in a local shell, both directly and nested in single quotes as the login probe is, against a PATH with no `hookdeck`, a stand-in printing 2.5.0 and one printing 3.1.0. The fixtures for a missing CLI now match what the probe returns. - The drift test also checks that `Record broken sandbox` exists and uploads the marker, and that `Cancel the run` fires on `sandbox-broken.marker` as well as `provider-refused.marker`. - triage: the single PINNED CLI NOT USED flag is now two. PINNED CLI NOT ON PATH says the agent had to find the CLI, which by absolute path or unversioned `npx` was still the pinned 2.5.0. UNPINNED CLI is raised only where a `hookdeck-cli@` ran. Against run 42044644850: 69 of 76 Codex cells flagged, 2 of them also UNPINNED CLI, and none of the 38 Claude Code cells. - Wording: Codex runs most commands in a login shell, not every one. In run 42044644850, 2,233 of its 2,456 shell commands were `bash -lc`. The four Codex attempts that invoked `hookdeck` without hitting `command not found` ran it only through `bash -c`. AGENTS.md, the Dockerfile, docker-sandbox.ts, toolchain-check.ts and pinned-cli.ts now say so. reference/results-format.md, provenance.ts and image.ts no longer claim the image change has given Codex the CLI. That is for the first run on the new image to confirm. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/eval-refresh.yml | 6 + AGENTS.md | 32 +-- apps/framework/lib/pinned-cli.ts | 60 +++-- apps/framework/lib/provenance.ts | 9 +- apps/framework/scripts/triage.ts | 14 +- apps/framework/test/pinned-cli.test.ts | 29 ++- packages/sandbox/Dockerfile | 10 +- packages/sandbox/src/docker-sandbox.ts | 2 +- packages/sandbox/src/image.ts | 9 +- packages/sandbox/src/index.ts | 4 +- packages/sandbox/src/toolchain-check.ts | 184 ++++++++++----- packages/sandbox/test/toolchain-check.test.ts | 211 +++++++++++++++--- reference/results-format.md | 6 +- 13 files changed, 431 insertions(+), 145 deletions(-) diff --git a/.github/workflows/eval-refresh.yml b/.github/workflows/eval-refresh.yml index e6cbde8..4064001 100644 --- a/.github/workflows/eval-refresh.yml +++ b/.github/workflows/eval-refresh.yml @@ -463,6 +463,12 @@ jobs: # will fail, and the run should stop rather than error every remaining # cell one at a time. The string is the error's own prefix, and a test in # `packages/sandbox` fails if the two drift apart. + # + # Only a deterministic answer carries it: `command -v hookdeck` + # resolving nothing, or the wrong version. A probe that times out or + # hits a dead container is retried once and then throws + # "sandbox self-check could not complete", which errors that cell + # alone and does not match here. sandbox_broken="sandbox self-check failed" if [ "$eval_status" -ne 0 ] && grep -qF "$sandbox_broken" "$run_log"; then echo "::error::The sandbox image failed its self-check: the pinned Hookdeck CLI is not on PATH for the agent's shells. Cancelling the run: every remaining job builds the same image." diff --git a/AGENTS.md b/AGENTS.md index 29f3fb2..d57d8cd 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1322,20 +1322,24 @@ deleted through the API, so a shared project accumulates history, and a scorer that just asks "did an event arrive?" will eventually say yes because of an earlier run. -**Codex runs every command in a login shell, and a login shell rebuilds PATH.** -Codex's tool calls are `/bin/bash -lc '…'`, so Debian's `/etc/profile` runs -and replaces whatever PATH the harness passed in with a fixed list. Claude Code -runs `bash -c` and inherits it. Until this was found, in release run -42044644850, the pinned `hookdeck` in the npm prefix was `command not found` -on every Codex arm, and the agents reached it by absolute path, by `npx`, by an -unpinned `npx -y hookdeck-cli@latest`, or not at all — all of it scored as -though both agents had the same baseline. So anything an agent needs on PATH -has to be on it for both kinds of shell: the image sets it in `ENV` and again -in `/etc/profile.d/`, and `toolchain-check.ts` errors a cell before it starts -if either shell does not resolve the pinned version. In CI that failure is -treated like a provider refusal: it leaves a `sandbox-broken` marker that -`publish-results` refuses on and cancels the run, because every job builds the -same image. Setting `PATH` on `docker exec` alone is not enough. +**Codex runs most commands in a login shell, and a login shell rebuilds PATH.** +In release run 42044644850, 2,233 of Codex's 2,456 shell commands were +`/bin/bash -lc '…'`; the rest were `bash -c`. A login shell runs Debian's +`/etc/profile`, which replaces whatever PATH the harness passed in with a fixed +list. Claude Code runs `bash -c` and inherits it. Of the Codex attempts in that +run that invoked the pinned `hookdeck`, 26/26, 18/22, 16/16 and 19/19 across +the four arms met `command not found`, and the four that did not had run it +only through `bash -c`. The agents carried on by absolute path, by `npx`, by an +unpinned `npx -y hookdeck-cli@latest`, or through the REST API — all of it +scored as though both agents had the same baseline. So anything an agent needs +on PATH has to be on it for both kinds of shell: the image sets it in `ENV` and +again in `/etc/profile.d/`, and `toolchain-check.ts` errors a cell before it +starts if either shell does not resolve the pinned version. A missing or wrong +CLI is treated in CI like a provider refusal: it leaves a `sandbox-broken` +marker that `publish-results` refuses on and cancels the run, because every +job builds the same image. A probe that times out or hits a dead container is +retried once and then errors only its own cell. Setting `PATH` on +`docker exec` alone is not enough. **Credentials reach the agent through `EvalSession.sandboxEnv`.** The session is created before the sandbox because the sandbox needs the lease. Disposal runs in diff --git a/apps/framework/lib/pinned-cli.ts b/apps/framework/lib/pinned-cli.ts index 83322df..7e0fa31 100644 --- a/apps/framework/lib/pinned-cli.ts +++ b/apps/framework/lib/pinned-cli.ts @@ -6,19 +6,22 @@ import { HOOKDECK_CLI_VERSION } from '@hookdeck-evals/sandbox'; * * Every experiment is supposed to get the CLI baked into the sandbox image, so * a row differs from its neighbour by skills and nothing else. On the Codex - * arms it was not on PATH: Codex runs each command in a login shell, and - * Debian's `/etc/profile` drops the npm prefix the CLI lives in. In release run - * 42044644850 every Codex attempt that invoked `hookdeck` met - * `command not found`, and the agents carried on through an absolute path into - * the package, `npx`, an unpinned `npx -y hookdeck-cli@latest`, or the REST API - * — all of which score, none of which is the baseline the row claims. + * arms it was mostly not on PATH: Codex runs most commands in a login shell + * (`bash -lc`), and Debian's `/etc/profile` drops the npm prefix the CLI lives + * in. In release run 42044644850, of the Codex attempts that invoked + * `hookdeck`, 26/26, 18/22, 16/16 and 19/19 across the four arms met + * `command not found`; the four that did not had run it only through + * `bash -c`. The agents carried on through an absolute path into the package, + * `npx`, an unpinned `npx -y hookdeck-cli@latest`, or the REST API. The first + * two still ran the pinned 2.5.0; the third did not; none of them is the + * baseline the row claims, a CLI that is simply there. * * The image now fixes the PATH and the sandbox refuses to start a cell whose * shells cannot run the pin, so this should not fire on a new run for the * first reason. It stays for two: rows already on disk carry it, and the * self-check cannot see a CLI the agent fetches for itself mid-run. Flagged - * whether the cell passed or failed, because a passing row measured on a - * different CLI is still not comparable. + * whether the cell passed or failed, because a passing row whose agent had to + * find the CLI, or ran a different one, is still not comparable. * * Kept outside `scripts/triage.ts` because that file runs `main()` at module * scope and so cannot be imported by a test. @@ -122,23 +125,38 @@ export function pinnedCliEvidence( return { notFound, unpinned, absolutePath }; } -/** One line for `triage`. */ -export function describePinnedCliEvidence( +/** + * The `triage` flags for this evidence: up to two, because they say different + * things. A CLI that was not on PATH leaves a row that may still have run the + * pinned version — reached by absolute path, or by an unversioned `npx` that + * resolved to the install — but whose agent had to go looking for a tool the + * other agent was handed. Only a `hookdeck-cli@` that actually ran + * makes the row unpinned. + */ +export function pinnedCliFlags( evidence: PinnedCliEvidence, pinned: string = HOOKDECK_CLI_VERSION -): string { - const parts: string[] = []; +): Array<{ label: string; detail: string }> { + const flags: Array<{ label: string; detail: string }> = []; if (evidence.notFound) { - parts.push('`hookdeck: command not found` in its shell'); + const workaround = evidence.absolutePath + ? ', then called the binary inside the package by absolute path' + : ''; + flags.push({ + label: 'PINNED CLI NOT ON PATH', + detail: + `\`hookdeck: command not found\` in its shell${workaround}. The pinned ` + + 'CLI was installed but not on PATH, so this agent had to find a tool ' + + 'the baseline promises is simply there; do not compare the row across agents', + }); } if (evidence.unpinned.length > 0) { - parts.push(`ran ${evidence.unpinned.join(', ')} instead of ${pinned}`); - } - if (evidence.absolutePath) { - parts.push('called the binary inside the package by absolute path'); + flags.push({ + label: 'UNPINNED CLI', + detail: + `ran ${evidence.unpinned.join(', ')} instead of ${pinned}, so this ` + + 'row was not measured with the pinned CLI', + }); } - return ( - `${parts.join('; ')}. This row was not measured with the pinned CLI the ` + - 'baseline promises, so do not compare it across agents' - ); + return flags; } diff --git a/apps/framework/lib/provenance.ts b/apps/framework/lib/provenance.ts index 080fbb3..9e75f83 100644 --- a/apps/framework/lib/provenance.ts +++ b/apps/framework/lib/provenance.ts @@ -116,10 +116,11 @@ export function skillsPin(root: string): string { * and is the treatment being measured, not a change to the instrument. * * The sandbox image definition is in here because the image decides what an - * agent's shell can run. Until it was, a Dockerfile change that gave Codex the - * pinned CLI it had been missing on PATH left every row's harness hash exactly - * where it was, so rows measured with and without the CLI read as measured - * under one instrument. + * agent's shell can run. Until it was, a Dockerfile change meant to put the + * pinned CLI on PATH for Codex's login shells, where it had been + * `command not found`, would have left every row's harness hash where it was, + * so rows either side of it would read as measured under one instrument + * whether or not the change worked. */ export function harnessFingerprint( basePrompt: string, diff --git a/apps/framework/scripts/triage.ts b/apps/framework/scripts/triage.ts index a7783df..397a80e 100644 --- a/apps/framework/scripts/triage.ts +++ b/apps/framework/scripts/triage.ts @@ -7,8 +7,8 @@ import { readErroredEvidenceTree, } from '../harness/errored-cell.js'; import { - describePinnedCliEvidence, pinnedCliEvidence, + pinnedCliFlags, type RowLike, shellActivity, } from '../lib/pinned-cli.js'; @@ -243,15 +243,11 @@ function flagsFor(row: Row, requiredEnv: string[]): Flag[] { flags.push({ label: 'NO TOOL CALLS', detail: 'scored without acting' }); } - // Pass or fail: a row measured on a different CLI, or none, is not the - // baseline it claims to be either way. See `lib/pinned-cli.ts`. + // Pass or fail: a row whose agent could not find the pinned CLI, or ran a + // different one, is not the baseline it claims to be either way. See + // `lib/pinned-cli.ts`. const cli = pinnedCliEvidence(shellActivity(row)); - if (cli) { - flags.push({ - label: 'PINNED CLI NOT USED', - detail: describePinnedCliEvidence(cli), - }); - } + if (cli) flags.push(...pinnedCliFlags(cli)); return flags; } diff --git a/apps/framework/test/pinned-cli.test.ts b/apps/framework/test/pinned-cli.test.ts index d7fc453..2d48752 100644 --- a/apps/framework/test/pinned-cli.test.ts +++ b/apps/framework/test/pinned-cli.test.ts @@ -1,7 +1,7 @@ import { describe, expect, it } from 'vitest'; import { - describePinnedCliEvidence, pinnedCliEvidence, + pinnedCliFlags, shellActivity, } from '../lib/pinned-cli.js'; @@ -39,8 +39,31 @@ describe('pinnedCliEvidence', () => { unpinned: [], absolutePath: true, }); - expect(describePinnedCliEvidence(evidence!, '2.5.0')).toMatch( - /command not found.*absolute path.*not measured with the pinned CLI/ + // Not "unpinned": the absolute path reached the pinned 2.5.0. What is + // wrong with the row is that the agent had to go and find it. + const flags = pinnedCliFlags(evidence!, '2.5.0'); + expect(flags.map((f) => f.label)).toEqual(['PINNED CLI NOT ON PATH']); + expect(flags[0].detail).toMatch( + /command not found.*absolute path.*installed but not on PATH/ + ); + expect(flags[0].detail).not.toMatch(/not measured with the pinned CLI/); + }); + + it('says unpinned only when a different hookdeck-cli actually ran', () => { + const flags = pinnedCliFlags( + { + notFound: true, + unpinned: ['hookdeck-cli@latest'], + absolutePath: false, + }, + '2.5.0' + ); + expect(flags.map((f) => f.label)).toEqual([ + 'PINNED CLI NOT ON PATH', + 'UNPINNED CLI', + ]); + expect(flags[1].detail).toBe( + 'ran hookdeck-cli@latest instead of 2.5.0, so this row was not measured with the pinned CLI' ); }); diff --git a/packages/sandbox/Dockerfile b/packages/sandbox/Dockerfile index c52f428..8f88164 100644 --- a/packages/sandbox/Dockerfile +++ b/packages/sandbox/Dockerfile @@ -16,12 +16,12 @@ ENV NPM_CONFIG_PREFIX=/home/node/.npm-global # That prefix has to be on PATH in every shell an agent can start, and there # are two kinds. A non-login shell (`bash -c`, which Claude Code and the # harness use) inherits PATH from the environment, so the ENV below covers it. -# A login shell (`bash -lc`, which is how Codex runs every command) does not: +# A login shell (`bash -lc`, which is how Codex runs most commands) does not: # Debian's /etc/profile overwrites PATH with a fixed list that has no npm -# prefix in it, so the pinned `hookdeck` was `command not found` on every Codex -# arm (found in run 42044644850; `toolchain-check.ts` now refuses to start a -# cell without it). /etc/profile then sources /etc/profile.d/*.sh, which is -# where the prefix is put back. +# prefix in it, so the pinned `hookdeck` was `command not found` in Codex's +# login shells on all four Codex arms (found in run 42044644850; +# `toolchain-check.ts` now refuses to start a cell without it). /etc/profile +# then sources /etc/profile.d/*.sh, which is where the prefix is put back. # # A profile.d entry rather than symlinks into /usr/local/bin, because it covers # the whole prefix: `skills`, and anything the agent itself installs globally diff --git a/packages/sandbox/src/docker-sandbox.ts b/packages/sandbox/src/docker-sandbox.ts index 3f40b80..8bb06bd 100644 --- a/packages/sandbox/src/docker-sandbox.ts +++ b/packages/sandbox/src/docker-sandbox.ts @@ -59,7 +59,7 @@ const CLIENT_TIMEOUT_HEADROOM_MS = 20_000; /** * PATH for commands the harness runs. Covers a non-login shell only: a login - * shell (`bash -lc`, which Codex uses for every command) re-reads + * shell (`bash -lc`, which Codex uses for most commands) re-reads * /etc/profile and replaces it, which is why the image also puts the npm * prefix back from /etc/profile.d. See the Dockerfile and `toolchain-check.ts`. */ diff --git a/packages/sandbox/src/image.ts b/packages/sandbox/src/image.ts index a83021b..e784ccc 100644 --- a/packages/sandbox/src/image.ts +++ b/packages/sandbox/src/image.ts @@ -95,10 +95,11 @@ export function sandboxImageTag(dockerfile: string): string { * A short hash of the image definition: the Dockerfile's bytes. * * Exported for provenance as well as the tag. The image is part of the - * instrument, and the case that made it so is the login-shell PATH: the same - * pins, the same prompt and the same skills gave Codex no `hookdeck` on PATH - * before the Dockerfile changed and the pinned one after. A row's provenance - * has to tell those apart, and the pins alone cannot. + * instrument, and the case that made it so is the login-shell PATH: with the + * same pins, prompt and skills, Codex's login shells had no `hookdeck` on PATH + * before the Dockerfile changed, and the change is meant to give them the + * pinned one. A row's provenance has to tell those apart, and the pins alone + * cannot. */ export function sandboxImageDefinition( dockerfile: string = readFileSync(SANDBOX_DOCKERFILE_PATH, 'utf8') diff --git a/packages/sandbox/src/index.ts b/packages/sandbox/src/index.ts index eccb838..516a17c 100644 --- a/packages/sandbox/src/index.ts +++ b/packages/sandbox/src/index.ts @@ -36,8 +36,10 @@ export type { } from './agent-environment.js'; export { assertPinnedToolchain, + classifyToolchainProbe, SANDBOX_SELF_CHECK_FAILED, - toolchainProblem, + SANDBOX_SELF_CHECK_INCONCLUSIVE, TOOLCHAIN_PROBES, } from './toolchain-check.js'; +export type { ToolchainOutcome } from './toolchain-check.js'; export type { SandboxCommandResult } from './types.js'; diff --git a/packages/sandbox/src/toolchain-check.ts b/packages/sandbox/src/toolchain-check.ts index 2bcb4a2..36f0c29 100644 --- a/packages/sandbox/src/toolchain-check.ts +++ b/packages/sandbox/src/toolchain-check.ts @@ -4,16 +4,18 @@ * * Every experiment is meant to differ from its neighbour by skills and nothing * else, and the pinned CLI is part of the baseline both arms share. Nothing - * checked that it was reachable. It was not, on every Codex arm: Codex runs - * each command as `/bin/bash -lc`, a login shell, and Debian's `/etc/profile` - * overwrites PATH with a fixed list that leaves out the npm prefix the CLI is - * installed into. In release matrix run 42044644850 every Codex attempt that - * invoked `hookdeck` met `command not found` at least once — 26/26, 18/22, - * 16/16 and 19/19 across the four Codex arms — and worked around it with an - * absolute path into the package, `npx hookdeck`, an unpinned - * `npx -y hookdeck-cli@latest`, or the REST API. Claude Code runs a non-login - * shell, inherits the harness's PATH, and was unaffected. Those rows were - * scored and published as though both agents had the same CLI. + * checked that it was reachable, and for most Codex commands it was not. Codex + * runs most commands in a login shell (`/bin/bash -lc`), and Debian's + * `/etc/profile` overwrites PATH with a fixed list that leaves out the npm + * prefix the CLI is installed into. In release matrix run 42044644850, 2,233 of + * Codex's 2,456 shell commands were `bash -lc`. Of the Codex attempts that + * invoked `hookdeck`, 26/26, 18/22, 16/16 and 19/19 across the four arms met + * `command not found`; the four that did not ran it only through `bash -c`. + * The agents worked around it with an absolute path into the package, + * `npx hookdeck`, an unpinned `npx -y hookdeck-cli@latest`, or the REST API. + * Claude Code runs a non-login shell, inherits the harness's PATH, and was + * unaffected. Those rows were scored and published as though both agents had + * the same CLI on PATH. * * So this runs both kinds of shell before the agent is installed, and refuses * the cell when either does not resolve the pinned version. Throwing is the @@ -22,6 +24,16 @@ * and dead-process guards in `run-eval.ts`. An agent working without the tool * the scenario assumes is not a result about the agent. * + * Two kinds of failure, and only one of them cancels the run. A shell that + * resolves no `hookdeck`, or resolves the wrong version, is a fact about the + * image, so every cell will see it: that throws {@link SANDBOX_SELF_CHECK_FAILED}, + * which CI treats as a run-level failure. Anything else — an in-container + * timeout, a `docker exec` the daemon refused, a container that died — could + * be one cell's bad minute. That probe is retried once and, if it still says + * nothing conclusive, throws {@link SANDBOX_SELF_CHECK_INCONCLUSIVE}, which + * errors this cell and leaves the rest of the matrix running. Cancelling five + * hours of work for a transient hiccup is the opposite mistake. + * * `--version` rather than `hookdeck version`, deliberately. Cobra answers the * flag before any of the CLI's own initialisation runs, so it creates no * config file and makes no network call. `hookdeck version` does both — it @@ -33,22 +45,41 @@ import { HOOKDECK_CLI_VERSION } from './image.js'; import type { SandboxCommandResult } from './types.js'; -const PROBE = 'command -v hookdeck && hookdeck --version'; +/** + * Printed, with exit 3, when `command -v` resolves nothing. A sentinel on + * stdout rather than an exit status alone, because `docker exec` itself exits + * 1 when the container has gone, and that must not read as a missing CLI. + */ +export const NOT_ON_PATH = 'HOOKDECK_NOT_ON_PATH'; +const NOT_ON_PATH_EXIT = 3; + +// No single quotes: the login probe wraps this in them. +const PROBE = + `if ! command -v hookdeck; then echo ${NOT_ON_PATH}; exit ${NOT_ON_PATH_EXIT}; fi; ` + + 'hookdeck --version'; /** - * The prefix of the error this check throws. The `Run evals` step in - * `eval-refresh.yml` greps the job log for it, treats it as a run-level - * failure like a provider refusal, leaves a `sandbox-broken` marker that - * `publish-results` refuses on, and cancels the run: every job builds the - * same image, so one broken sandbox means all of them are. A test fails if - * the workflow and this string drift apart. + * The prefix of the error thrown when the image itself is wrong. The + * `Run evals` step in `eval-refresh.yml` greps the job log for it, treats it as + * a run-level failure like a provider refusal, leaves a `sandbox-broken` marker + * that `publish-results` refuses on, and cancels the run: every job builds the + * same image, so one broken sandbox means all of them are. A test fails if the + * workflow and this string drift apart. */ export const SANDBOX_SELF_CHECK_FAILED = 'sandbox self-check failed'; +/** + * The prefix of the error thrown when the check could not get an answer. Must + * not contain {@link SANDBOX_SELF_CHECK_FAILED}, or a transient error would + * cancel the whole matrix; a test holds it to that. + */ +export const SANDBOX_SELF_CHECK_INCONCLUSIVE = + 'sandbox self-check could not complete'; + /** * The two shells an agent can be handed. `runShell` already runs `bash -c` * with the harness's PATH, so the login probe nests a `bash -lc` inside it, - * which is exactly what Codex does. + * which is what Codex does for most commands. */ export const TOOLCHAIN_PROBES = [ { shell: 'non-login (bash -c)', command: PROBE }, @@ -63,60 +94,113 @@ export interface ToolchainProbeResult { } /** - * What is wrong with one probe's result, or `undefined` if it resolved the - * pinned CLI. Pure, so the rule can be tested without Docker. + * What one probe says. `not-on-path` and `wrong-version` are facts about the + * image; `inconclusive` is anything that could be this cell's bad luck. */ -export function toolchainProblem( +export type ToolchainOutcome = + | { kind: 'ok' } + | { kind: 'not-on-path' | 'wrong-version' | 'inconclusive'; detail: string }; + +/** Classify one probe's result. Pure, so the rule can be tested without Docker. */ +export function classifyToolchainProbe( probe: ToolchainProbeResult, expectedVersion: string = HOOKDECK_CLI_VERSION -): string | undefined { +): ToolchainOutcome { const { shell, result } = probe; - const output = `${result.stdout}\n${result.stderr}`.trim(); + const output = oneLine(`${result.stdout}\n${result.stderr}`) || 'no output'; + const stdoutLines = result.stdout.split('\n').map((line) => line.trim()); + + if ( + result.exitCode === NOT_ON_PATH_EXIT && + stdoutLines.includes(NOT_ON_PATH) + ) { + return { + kind: 'not-on-path', + detail: `${shell}: \`command -v hookdeck\` resolved nothing`, + }; + } if (!result.ok) { - return ( - `${shell}: \`hookdeck\` did not resolve or did not run ` + - `(exit ${result.exitCode ?? 'unknown'}): ${oneLine(output) || 'no output'}` - ); + return { + kind: 'inconclusive', + detail: `${shell}: probe exited ${result.exitCode ?? 'without a status'}: ${output}`, + }; } // A whole whitespace-delimited token, so 12.5.0 and 2.5.0-beta.1 do not // pass for 2.5.0. - const version = new RegExp( - `(^|\\s)v?${escapeRegExp(expectedVersion)}(\\s|$)` - ); - if (!version.test(result.stdout)) { - return ( - `${shell}: \`hookdeck\` resolved but is not the pinned ${expectedVersion}: ` + - oneLine(output) - ); + const pinned = new RegExp(`(^|\\s)v?${escapeRegExp(expectedVersion)}(\\s|$)`); + if (pinned.test(result.stdout)) return { kind: 'ok' }; + // Only a recognisable version line counts as the wrong version. Output that + // says nothing about a version is not evidence about the image. + if (/\bversion\s+\S+/.test(result.stdout)) { + return { + kind: 'wrong-version', + detail: `${shell}: \`hookdeck\` is not the pinned ${expectedVersion}: ${output}`, + }; } - return undefined; + return { + kind: 'inconclusive', + detail: `${shell}: \`hookdeck --version\` printed no version: ${output}`, + }; } -/** - * Run every probe and throw if any shell would not hand the agent the pinned - * CLI. Accepts the narrow `runShell` surface so it can be exercised with a - * fake. - */ -export async function assertPinnedToolchain(sandbox: { +interface ShellRunner { runShell( command: string, options?: { timeoutMs?: number } ): Promise; -}): Promise { - const problems: string[] = []; - for (const { shell, command } of TOOLCHAIN_PROBES) { +} + +async function runProbe( + sandbox: ShellRunner, + shell: string, + command: string +): Promise { + try { const result = await sandbox.runShell(command, { timeoutMs: PROBE_TIMEOUT_MS, }); - const problem = toolchainProblem({ shell, result }); - if (problem) problems.push(problem); + return classifyToolchainProbe({ shell, result }); + } catch (err) { + // `dockerCli` throws rather than returning when its own client times out. + return { + kind: 'inconclusive', + detail: `${shell}: probe threw: ${err instanceof Error ? err.message : String(err)}`, + }; + } +} + +/** + * Run every probe and throw if any shell would not hand the agent the pinned + * CLI. Accepts the narrow `runShell` surface so it can be exercised with a + * fake. + */ +export async function assertPinnedToolchain( + sandbox: ShellRunner +): Promise { + const broken: string[] = []; + const unknown: string[] = []; + for (const { shell, command } of TOOLCHAIN_PROBES) { + let outcome = await runProbe(sandbox, shell, command); + if (outcome.kind === 'inconclusive') { + outcome = await runProbe(sandbox, shell, command); + } + if (outcome.kind === 'ok') continue; + (outcome.kind === 'inconclusive' ? unknown : broken).push(outcome.detail); } - if (problems.length > 0) { + if (broken.length > 0) { throw new Error( `${SANDBOX_SELF_CHECK_FAILED}: the pinned Hookdeck CLI is not what an ` + `agent's shell runs, so this cell was not started and is not scored. ` + - `${problems.join('; ')}. The PATH for both shells is set in ` + - 'packages/sandbox/Dockerfile.' + `${[...broken, ...unknown].join('; ')}. The PATH for both shells is ` + + 'set in packages/sandbox/Dockerfile.' + ); + } + if (unknown.length > 0) { + throw new Error( + `${SANDBOX_SELF_CHECK_INCONCLUSIVE}: the probe for the pinned Hookdeck ` + + 'CLI got no answer after a retry, so this cell was not started and is ' + + `not scored. ${unknown.join('; ')}. Not a verdict on the image: re-run ` + + 'the cell.' ); } } diff --git a/packages/sandbox/test/toolchain-check.test.ts b/packages/sandbox/test/toolchain-check.test.ts index 4e74cad..c89be45 100644 --- a/packages/sandbox/test/toolchain-check.test.ts +++ b/packages/sandbox/test/toolchain-check.test.ts @@ -1,5 +1,5 @@ import { spawnSync } from 'node:child_process'; -import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs'; +import { chmodSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs'; import { tmpdir } from 'node:os'; import { join } from 'node:path'; import { describe, expect, it } from 'vitest'; @@ -10,9 +10,11 @@ import { } from '../src/image.js'; import { assertPinnedToolchain, + classifyToolchainProbe, + NOT_ON_PATH, SANDBOX_SELF_CHECK_FAILED, + SANDBOX_SELF_CHECK_INCONCLUSIVE, TOOLCHAIN_PROBES, - toolchainProblem, } from '../src/toolchain-check.js'; import type { SandboxCommandResult } from '../src/types.js'; @@ -27,56 +29,152 @@ const ok = (stdout: string): SandboxCommandResult => ({ stdout, stderr: '', }); -const notFound: SandboxCommandResult = { +/** What the real probe returns when `command -v hookdeck` resolves nothing. */ +const notOnPath: SandboxCommandResult = { ok: false, - exitCode: 127, - stdout: '', - stderr: '/bin/bash: line 1: hookdeck: command not found\n', + exitCode: 3, + stdout: `${NOT_ON_PATH}\n`, + stderr: '', }; const resolved = ok( `${NPM_BIN}/hookdeck\nhookdeck version ${HOOKDECK_CLI_VERSION}\n` ); +/** coreutils `timeout` firing inside the container. */ +const timedOut: SandboxCommandResult = { + ok: false, + exitCode: 124, + stdout: '', + stderr: '[command timed out after 60s and was terminated]', +}; +/** `docker exec` against a container that has gone: exit 1, nothing on stdout. */ +const deadContainer: SandboxCommandResult = { + ok: false, + exitCode: 1, + stdout: '', + stderr: 'Error response from daemon: container abc is not running', +}; + +/** Run a probe for real, in a local shell with the given PATH. */ +function runLocally(command: string, path: string): SandboxCommandResult { + const result = spawnSync('bash', ['-c', command], { + env: { PATH: path }, + encoding: 'utf8', + }); + return { + ok: result.status === 0, + exitCode: result.status, + stdout: result.stdout, + stderr: result.stderr, + }; +} + +/** A directory holding a stand-in `hookdeck` that prints the given version. */ +function fakeCliDir(version: string): string { + const dir = mkdtempSync(join(tmpdir(), 'hd-fake-cli-')); + const bin = join(dir, 'hookdeck'); + writeFileSync( + bin, + `#!/bin/sh\n[ "$1" = "--version" ] && echo "hookdeck version ${version}"\n` + ); + chmodSync(bin, 0o755); + return dir; +} + +/** + * The login probe with `-l` dropped, so it runs here without this machine's + * own /etc/profile deciding the PATH. What it checks is that the probe + * survives being nested in single quotes. + */ +const nestedProbe = TOOLCHAIN_PROBES[1].command.replace( + /^bash -lc /, + 'bash -c ' +); + +describe('the probe, run for real', () => { + it('reports a missing CLI with the sentinel and exit 3', () => { + for (const command of [TOOLCHAIN_PROBES[0].command, nestedProbe]) { + const result = runLocally(command, '/usr/bin:/bin'); + expect(result.exitCode).toBe(3); + expect(result.stdout.trim()).toBe(NOT_ON_PATH); + expect(classifyToolchainProbe({ shell: 's', result }).kind).toBe( + 'not-on-path' + ); + } + }); + + it('accepts the pin and refuses another version', () => { + for (const command of [TOOLCHAIN_PROBES[0].command, nestedProbe]) { + const pinned = runLocally( + command, + `${fakeCliDir(HOOKDECK_CLI_VERSION)}:/usr/bin:/bin` + ); + expect(classifyToolchainProbe({ shell: 's', result: pinned })).toEqual({ + kind: 'ok', + }); + const other = runLocally(command, `${fakeCliDir('3.1.0')}:/usr/bin:/bin`); + expect(classifyToolchainProbe({ shell: 's', result: other }).kind).toBe( + 'wrong-version' + ); + } + }); +}); -describe('toolchainProblem', () => { +describe('classifyToolchainProbe', () => { it('accepts a shell that resolves the pinned version', () => { expect( - toolchainProblem({ shell: 'login', result: resolved }) - ).toBeUndefined(); + classifyToolchainProbe({ shell: 'login', result: resolved }) + ).toEqual({ kind: 'ok' }); expect( - toolchainProblem({ + classifyToolchainProbe({ shell: 'login', result: ok(`hookdeck version v${HOOKDECK_CLI_VERSION}\n`), }) - ).toBeUndefined(); + ).toEqual({ kind: 'ok' }); }); - it('refuses the shell that cannot find it, which is what Codex got', () => { - const problem = toolchainProblem({ shell: 'login', result: notFound }); - expect(problem).toMatch(/^login: /); - expect(problem).toContain('command not found'); - expect(problem).toContain('exit 127'); + it('calls a missing CLI a fact about the image, which is what Codex got', () => { + const outcome = classifyToolchainProbe({ + shell: 'login', + result: notOnPath, + }); + expect(outcome.kind).toBe('not-on-path'); }); - it('refuses a different version, including one that contains the pin', () => { + it('calls a different version a fact about the image, including one that contains the pin', () => { for (const other of ['2.5.1', '12.5.0', '2.5.0-beta.1', '3.1.0']) { - expect( - toolchainProblem( - { shell: 'login', result: ok(`hookdeck version ${other}\n`) }, - '2.5.0' - ) - ).toContain('not the pinned 2.5.0'); + const outcome = classifyToolchainProbe( + { shell: 'login', result: ok(`hookdeck version ${other}\n`) }, + '2.5.0' + ); + expect(outcome.kind).toBe('wrong-version'); + } + }); + + it('calls a timeout, a dead container or no version line inconclusive', () => { + for (const result of [ + timedOut, + deadContainer, + { ...timedOut, exitCode: 137 }, + { ...timedOut, exitCode: null }, + ok(`${NPM_BIN}/hookdeck\n`), + ]) { + expect(classifyToolchainProbe({ shell: 'login', result }).kind).toBe( + 'inconclusive' + ); } }); }); describe('assertPinnedToolchain', () => { - const fake = (byCommand: (command: string) => SandboxCommandResult) => { + const fake = ( + byCommand: (command: string, call: number) => SandboxCommandResult + ) => { const seen: string[] = []; return { seen, runShell: async (command: string) => { seen.push(command); - return byCommand(command); + return byCommand(command, seen.length); }, }; }; @@ -95,16 +193,50 @@ describe('assertPinnedToolchain', () => { } }); - it('throws when only the login shell is broken, naming it', async () => { + it('cancels-the-run error when only the login shell is missing the CLI', async () => { const sandbox = fake((command) => - command.startsWith('bash -lc') ? notFound : resolved + command.startsWith('bash -lc') ? notOnPath : resolved ); - await expect(assertPinnedToolchain(sandbox)).rejects.toThrow( - /sandbox self-check failed.*not scored.*login \(bash -lc\).*command not found/s + const error = await assertPinnedToolchain(sandbox).catch((e) => e); + expect(error.message).toMatch( + /^sandbox self-check failed.*not scored.*login \(bash -lc\).*resolved nothing/s ); + // A deterministic outcome is not retried. + expect(sandbox.seen).toHaveLength(2); + }); + + it('retries a transient failure once and passes if the retry does', async () => { + const sandbox = fake((_, call) => (call === 1 ? timedOut : resolved)); + await assertPinnedToolchain(sandbox); + expect(sandbox.seen).toHaveLength(3); }); - it('fails with the string CI cancels the run on', async () => { + it('errors only this cell when a probe stays inconclusive', async () => { + const sandbox = fake((command) => + command.startsWith('bash -lc') ? deadContainer : resolved + ); + const error = await assertPinnedToolchain(sandbox).catch((e) => e); + expect( + String(error.message).startsWith(SANDBOX_SELF_CHECK_INCONCLUSIVE) + ).toBe(true); + // Must not carry the string CI cancels the whole run on. + expect(error.message).not.toContain(SANDBOX_SELF_CHECK_FAILED); + expect(sandbox.seen).toHaveLength(3); + }); + + it('treats a probe that throws as inconclusive', async () => { + const sandbox = { + runShell: async () => { + throw new Error('sandbox command timed out after 80000ms'); + }, + }; + const error = await assertPinnedToolchain(sandbox).catch((e) => e); + expect( + String(error.message).startsWith(SANDBOX_SELF_CHECK_INCONCLUSIVE) + ).toBe(true); + }); + + it('fails with the string CI cancels the run on, and CI is wired to it', async () => { // `eval-refresh.yml` greps the job log for this prefix to cancel the run // and leave a `sandbox-broken` marker that blocks publishing. If the two // drift, a broken image goes back to erroring every cell one at a time. @@ -112,11 +244,28 @@ describe('assertPinnedToolchain', () => { new URL('../../../.github/workflows/eval-refresh.yml', import.meta.url), 'utf8' ); + const step = (name: string) => { + const start = workflow.indexOf(`- name: ${name}\n`); + expect(start, `step "${name}"`).toBeGreaterThan(-1); + const next = workflow.indexOf('- name: ', start + 1); + return workflow.slice(start, next === -1 ? undefined : next); + }; + expect(workflow).toContain(`sandbox_broken="${SANDBOX_SELF_CHECK_FAILED}"`); expect(workflow).toContain('> sandbox-broken.marker'); expect(workflow).toMatch(/grep -E '\^sandbox-broken-'/); - const sandbox = fake(() => notFound); + const record = step('Record broken sandbox'); + expect(record).toContain("hashFiles('sandbox-broken.marker')"); + expect(record).toContain('path: sandbox-broken.marker'); + expect(record).toContain('name: sandbox-broken-'); + + const cancel = step('Cancel the run'); + const cancelIf = cancel.split('\n').find((line) => /^\s+if:/.test(line)); + expect(cancelIf).toContain("'sandbox-broken.marker'"); + expect(cancelIf).toContain("'provider-refused.marker'"); + + const sandbox = fake(() => notOnPath); const error = await assertPinnedToolchain(sandbox).catch((e) => e); expect(String(error.message).startsWith(SANDBOX_SELF_CHECK_FAILED)).toBe( true diff --git a/reference/results-format.md b/reference/results-format.md index 51e03d4..83ebce5 100644 --- a/reference/results-format.md +++ b/reference/results-format.md @@ -77,8 +77,10 @@ scenario shares — the base prompt, the sandbox CLI pin, the skills CLI, the skills submodule pin and the sandbox image definition (the Dockerfile) — and `scenario` covers the scenario's own files. The image definition joined in November 2026, so every row recorded before then has a different `harness` -from every row after it; that is correct, because the image change gave Codex -the pinned CLI on PATH for the first time. Two rows +from every row after it. That is intended: the image change that came with it +puts the pinned CLI on PATH for Codex's login shells (`bash -lc`), where in +earlier runs it was `command not found`. Whether it does so in practice is for +the first run on the new image to confirm. Two rows with the same `scenario` and different `harness` measured the same task under a different instrument. Opaque: compare for equality, do not parse. `skillsPin` is the skills submodule commit the row ran against, in the clear, possibly with a From 80c0b3892c895914f13b7d2c9d19c210665831ea Mon Sep 17 00:00:00 2001 From: Phil Leggetter Date: Thu, 5 Nov 2026 21:38:21 +0000 Subject: [PATCH 5/5] Read the self-check version through ANSI colour The version match in classifyToolchainProbe is a whole whitespace-delimited token. A CLI release that coloured `--version` would put an escape code against the number. Every cell of a working image would then read as the wrong version, and the run would cancel. stdout and stderr are now stripped of CSI sequences (including SGR colour) and OSC sequences (including hyperlinks) before anything is matched. A test covers coloured output with CRLF, an OSC 8 hyperlink with both terminators, and a coloured 3.1.0, which must still read as the wrong version. The Run evals `::error::` for a broken sandbox no longer says the CLI is not on PATH, since a wrong version raises it too: "The sandbox image failed its self-check (pinned Hookdeck CLI missing from PATH or wrong version)". Co-Authored-By: Claude Opus 5.5 --- .github/workflows/eval-refresh.yml | 2 +- packages/sandbox/src/toolchain-check.ts | 30 ++++++++++++++--- packages/sandbox/test/toolchain-check.test.ts | 33 +++++++++++++++++++ 3 files changed, 60 insertions(+), 5 deletions(-) diff --git a/.github/workflows/eval-refresh.yml b/.github/workflows/eval-refresh.yml index 4064001..263d17d 100644 --- a/.github/workflows/eval-refresh.yml +++ b/.github/workflows/eval-refresh.yml @@ -471,7 +471,7 @@ jobs: # alone and does not match here. sandbox_broken="sandbox self-check failed" if [ "$eval_status" -ne 0 ] && grep -qF "$sandbox_broken" "$run_log"; then - echo "::error::The sandbox image failed its self-check: the pinned Hookdeck CLI is not on PATH for the agent's shells. Cancelling the run: every remaining job builds the same image." + echo "::error::The sandbox image failed its self-check (pinned Hookdeck CLI missing from PATH or wrong version). Cancelling the run: every remaining job builds the same image." { echo "experiment=${{ matrix.experiment }}" echo "eval=${{ matrix.eval_id }}" diff --git a/packages/sandbox/src/toolchain-check.ts b/packages/sandbox/src/toolchain-check.ts index 36f0c29..d4f2fcf 100644 --- a/packages/sandbox/src/toolchain-check.ts +++ b/packages/sandbox/src/toolchain-check.ts @@ -107,8 +107,14 @@ export function classifyToolchainProbe( expectedVersion: string = HOOKDECK_CLI_VERSION ): ToolchainOutcome { const { shell, result } = probe; - const output = oneLine(`${result.stdout}\n${result.stderr}`) || 'no output'; - const stdoutLines = result.stdout.split('\n').map((line) => line.trim()); + // Colour is stripped before anything is matched. A CLI release that styles + // `--version` would otherwise put an escape code against the version + // number, fail the whole-token match on every cell of a working image, and + // cancel the run. + const stdout = stripAnsi(result.stdout); + const output = + oneLine(`${stdout}\n${stripAnsi(result.stderr)}`) || 'no output'; + const stdoutLines = stdout.split('\n').map((line) => line.trim()); if ( result.exitCode === NOT_ON_PATH_EXIT && @@ -128,10 +134,10 @@ export function classifyToolchainProbe( // A whole whitespace-delimited token, so 12.5.0 and 2.5.0-beta.1 do not // pass for 2.5.0. const pinned = new RegExp(`(^|\\s)v?${escapeRegExp(expectedVersion)}(\\s|$)`); - if (pinned.test(result.stdout)) return { kind: 'ok' }; + if (pinned.test(stdout)) return { kind: 'ok' }; // Only a recognisable version line counts as the wrong version. Output that // says nothing about a version is not evidence about the image. - if (/\bversion\s+\S+/.test(result.stdout)) { + if (/\bversion\s+\S+/.test(stdout)) { return { kind: 'wrong-version', detail: `${shell}: \`hookdeck\` is not the pinned ${expectedVersion}: ${output}`, @@ -205,6 +211,22 @@ export async function assertPinnedToolchain( } } +const ESC = String.fromCharCode(0x1b); +const BEL = String.fromCharCode(0x07); +/** + * ANSI escape sequences: CSI (`ESC [ … final`, which covers SGR colour) and + * OSC (`ESC ] … BEL` or `ESC ] … ESC \`, which covers hyperlinks). Built from + * character codes so the source carries no literal control characters. + */ +const ANSI = new RegExp( + `${ESC}\\[[0-?]*[ -/]*[@-~]|${ESC}\\][^${BEL}${ESC}]*(?:${BEL}|${ESC}\\\\)`, + 'g' +); + +export function stripAnsi(text: string): string { + return text.replace(ANSI, ''); +} + function oneLine(text: string): string { const flat = text.replace(/\s+/g, ' ').trim(); return flat.length > 300 ? `${flat.slice(0, 300)}…` : flat; diff --git a/packages/sandbox/test/toolchain-check.test.ts b/packages/sandbox/test/toolchain-check.test.ts index c89be45..1978432 100644 --- a/packages/sandbox/test/toolchain-check.test.ts +++ b/packages/sandbox/test/toolchain-check.test.ts @@ -150,6 +150,39 @@ describe('classifyToolchainProbe', () => { } }); + it('reads through colour, so a styled --version does not cancel every run', () => { + const esc = '\u001b'; + const bel = '\u0007'; + const coloured = (version: string) => + ok( + `${esc}[1mhookdeck${esc}[0m version ${esc}[32m${version}${esc}[0m\r\n` + ); + expect( + classifyToolchainProbe({ + shell: 'login', + result: coloured(HOOKDECK_CLI_VERSION), + }) + ).toEqual({ kind: 'ok' }); + // An OSC 8 hyperlink around the version, terminated either way. + for (const end of [bel, `${esc}\\`]) { + expect( + classifyToolchainProbe({ + shell: 'login', + result: ok( + `hookdeck version ${esc}]8;;https://example.test${end}${HOOKDECK_CLI_VERSION}${esc}]8;;${end}\n` + ), + }) + ).toEqual({ kind: 'ok' }); + } + // Stripping colour must not turn a different version into the pin. + const other = classifyToolchainProbe( + { shell: 'login', result: coloured('3.1.0') }, + '2.5.0' + ); + expect(other.kind).toBe('wrong-version'); + expect(other.kind === 'ok' ? '' : other.detail).not.toContain(esc); + }); + it('calls a timeout, a dead container or no version line inconclusive', () => { for (const result of [ timedOut,