fix: reuse Goose binary in agent containers

This commit is contained in:
lezi-fun committed 2026-08-14 10:07:48 +08:00
1 parent 6f2594f994
commit 3647944ad7
4 files changed
+137 -43

No files matched your search

+32 -1
View File
@@ -1,6 +1,37 @@
import assert from "node:assert/strict";
import test from "node:test";
import { extractGooseFinalText } from "../src/ai/gooseCli.js";
import {
buildGooseAgentDockerArgs,
extractGooseFinalText
} from "../src/ai/gooseCli.js";
test("goose agent mounts the workflow binary read-only and keeps a visible install fallback", () => {
const args = buildGooseAgentDockerArgs({
containerName: "ghbot-agent-test",
realWorkingDirectory: "/tmp/worktree",
containerEnv: { OPENAI_API_KEY: "one-run-token" },
hostGooseBinary: "/tmp/goose/bin/goose",
prompt: "introduce this pull request"
});
assert.ok(args.includes("type=bind,source=/tmp/goose/bin/goose,target=/usr/local/bin/goose,readonly"));
const bootstrap = args[args.indexOf("-lc") + 1];
assert.match(bootstrap!, /command -v goose/);
assert.match(bootstrap!, /cat \/tmp\/goose-install\.log >&2/);
assert.equal(args.at(-1), "introduce this pull request");
});
test("goose agent can fall back to installing inside the container", () => {
const args = buildGooseAgentDockerArgs({
containerName: "ghbot-agent-test",
realWorkingDirectory: "/tmp/worktree",
containerEnv: {},
prompt: "inspect this pull request"
});
assert.equal(args.some((arg) => arg.includes("target=/usr/local/bin/goose")), false);
assert.match(args[args.indexOf("-lc") + 1]!, /GOOSE_VERSION="v1\.46\.0"/);
});
test("goose output extracts the latest assistant text", () => {
const output = JSON.stringify({
+1
View File
@@ -7,5 +7,6 @@ test("pull_request_target checks out a PR worktree only for same-repository head
const caller = await fs.readFile(".github/workflows/review.yml", "utf8");
assert.match(workflow, /pull_head_repository == format\('\{0\}\/\{1\}'/);
assert.doesNotMatch(workflow, /allow-unsafe-pr-checkout:\s*true/);
assert.match(workflow, /GHBOT_GOOSE_BINARY:\s*\$\{\{ runner\.temp \}\}\/goose\/bin\/goose/);
assert.match(caller, /pull_head_repository:\s*\$\{\{ github\.event\.pull_request\.head\.repo\.full_name \|\| '' \}\}/);
});