fix: harden conflict resolution pipeline
This commit is contained in:
1 parent
decf7ab8b4
commit
351d3148aa
9 files changed
+273
-55
No files matched your search
@@ -0,0 +1,11 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { formatBotDisplayName } from "../src/github/botIdentity.js";
|
||||
|
||||
test("GitHub App logins become readable comment identities with a goose fallback", () => {
|
||||
assert.equal(formatBotDisplayName("forumlify[bot]"), "forumlify bot");
|
||||
assert.equal(formatBotDisplayName("@forumlify[bot]"), "forumlify bot");
|
||||
assert.equal(formatBotDisplayName("forumlify"), "forumlify");
|
||||
assert.equal(formatBotDisplayName("ghbot"), "goose");
|
||||
assert.equal(formatBotDisplayName(undefined), "goose");
|
||||
});
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
canAutoResolveConflicts,
|
||||
describeConflictResolutionFailure,
|
||||
diffSnapshotInventories,
|
||||
isValidationInfrastructureFailure,
|
||||
parseDiffCheckWhitespaceDiagnostics,
|
||||
parseFinalConfirmation,
|
||||
repairDiffCheckContent
|
||||
@@ -88,6 +89,25 @@ test("conflict failures are actionable without exposing raw command output", ()
|
||||
describeConflictResolutionFailure(new Error("initial goose conflict-editing pass timed out")),
|
||||
/initial conflict-editing pass.*10-minute limit/i
|
||||
);
|
||||
assert.match(
|
||||
describeConflictResolutionFailure(
|
||||
new Error("Conflict validation infrastructure failed: dubious ownership"),
|
||||
"forumlify bot"
|
||||
),
|
||||
/validation environment failed.*No code-repair pass/i
|
||||
);
|
||||
assert.match(
|
||||
describeConflictResolutionFailure(new Error("validation goose correction timed out")),
|
||||
/focused validation-repair pass.*5-minute limit/i
|
||||
);
|
||||
assert.match(
|
||||
describeConflictResolutionFailure(new Error("final goose confirmation timed out")),
|
||||
/final read-only safety confirmation.*5-minute limit/i
|
||||
);
|
||||
assert.match(
|
||||
describeConflictResolutionFailure(new Error("Validation command failed"), "forumlify bot"),
|
||||
/^forumlify bot produced/
|
||||
);
|
||||
assert.match(
|
||||
describeConflictResolutionFailure(new Error("rejected: stale info")),
|
||||
/Run \/conflict again/
|
||||
@@ -98,6 +118,29 @@ test("conflict failures are actionable without exposing raw command output", ()
|
||||
);
|
||||
});
|
||||
|
||||
test("validation infrastructure failures are not sent to the code-repair agent", () => {
|
||||
assert.equal(isValidationInfrastructureFailure({
|
||||
code: 1,
|
||||
stdout: "",
|
||||
stderr: "fatal: detected dubious ownership in repository at '/workspace'"
|
||||
}), true);
|
||||
assert.equal(isValidationInfrastructureFailure({
|
||||
code: 125,
|
||||
stdout: "",
|
||||
stderr: "docker failed before the command started"
|
||||
}), true);
|
||||
assert.equal(isValidationInfrastructureFailure({
|
||||
code: 1,
|
||||
stdout: "",
|
||||
stderr: "permission denied while trying to connect to the Docker API at unix:///docker.sock"
|
||||
}), true);
|
||||
assert.equal(isValidationInfrastructureFailure({
|
||||
code: 1,
|
||||
stdout: "AssertionError: expected 2 but received 1",
|
||||
stderr: ""
|
||||
}), false);
|
||||
});
|
||||
|
||||
test("initial conflict prompt leaves full validation to the isolated host pass", () => {
|
||||
const validationCommand = "npm ci && npm test";
|
||||
const prompt = buildConflictPrompt(
|
||||
@@ -172,7 +215,7 @@ test("snapshot inventory detects related file additions, changes, and deletions"
|
||||
);
|
||||
});
|
||||
|
||||
test("validation repair prompt requires the exact command without allowing test weakening", () => {
|
||||
test("validation repair prompt leaves the authoritative rerun to the isolated host", () => {
|
||||
const prompt = buildValidationRepairPrompt({
|
||||
testCommand: "npm ci && npm test",
|
||||
output: "Exit code: 1\nThe handler and its test disagree."
|
||||
@@ -181,6 +224,8 @@ test("validation repair prompt requires the exact command without allowing test
|
||||
assert.match(prompt, /handler and its test disagree/);
|
||||
assert.match(prompt, /do not .*weaken\/delete tests/i);
|
||||
assert.match(prompt, /related validation failures/i);
|
||||
assert.match(prompt, /host will rerun this exact trusted repository validation command/i);
|
||||
assert.match(prompt, /Do not install dependencies or run the full validation command yourself/i);
|
||||
});
|
||||
|
||||
test("final confirmation parser accepts a JSON object surrounded by prose", () => {
|
||||
|
||||
+21
-2
@@ -5,7 +5,8 @@ import {
|
||||
buildGooseAgentEnvironment,
|
||||
buildIsolatedWorkspaceCommandDockerArgs,
|
||||
buildWorkspacePermissionDockerArgs,
|
||||
extractGooseFinalText
|
||||
extractGooseFinalText,
|
||||
redactProcessArgs
|
||||
} from "../src/ai/gooseCli.js";
|
||||
|
||||
test("goose agent mounts the workflow binary read-only and keeps a visible install fallback", () => {
|
||||
@@ -22,6 +23,7 @@ test("goose agent mounts the workflow binary read-only and keeps a visible insta
|
||||
assert.match(bootstrap!, /command -v goose/);
|
||||
assert.match(bootstrap!, /cat \/tmp\/goose-install\.log >&2/);
|
||||
assert.match(bootstrap!, /trap cleanup_workspace EXIT/);
|
||||
assert.match(bootstrap!, /safe\.directory \/workspace/);
|
||||
assert.match(bootstrap!, /chmod -R a\+rwX \/workspace/);
|
||||
assert.doesNotMatch(bootstrap!, /exec goose "\$@"/);
|
||||
assert.equal(args.at(-1), "introduce this pull request");
|
||||
@@ -34,13 +36,30 @@ test("isolated validation receives the repository but no model or GitHub credent
|
||||
command: "npm ci && npm test"
|
||||
});
|
||||
|
||||
assert.ok(args.includes("type=bind,source=/tmp/worktree,target=/workspace"));
|
||||
assert.ok(args.includes("type=bind,source=/tmp/worktree,target=/workspace,readonly"));
|
||||
assert.ok(args.includes("HOME=/tmp/ghbot-validation-home"));
|
||||
assert.ok(args.includes("CI=true"));
|
||||
const bootstrap = args[args.indexOf("-lc") + 1];
|
||||
assert.match(bootstrap!, /cp -R --no-preserve=ownership/);
|
||||
assert.match(bootstrap!, /safe\.directory "\$validation_workspace"/);
|
||||
assert.match(bootstrap!, /exec sh -lc "\$1"/);
|
||||
assert.equal(args.at(-2), "ghbot-validation");
|
||||
assert.equal(args.at(-1), "npm ci && npm test");
|
||||
assert.equal(args.some((arg) => /OPENAI|GITHUB|GHBOT_GIT_TOKEN/.test(arg)), false);
|
||||
});
|
||||
|
||||
test("process logging redacts only prompts and trusted validation commands", () => {
|
||||
assert.deepEqual(redactProcessArgs(["run", "--rm"], "workspace cleanup"), ["run", "--rm"]);
|
||||
assert.deepEqual(
|
||||
redactProcessArgs(["run", "--text", "secret prompt"], "goose agent container"),
|
||||
["run", "--text", "[goose prompt: 13 chars]"]
|
||||
);
|
||||
assert.deepEqual(
|
||||
redactProcessArgs(["run", "sh", "-lc", "npm ci && npm test"], "isolated repository validation"),
|
||||
["run", "sh", "-lc", "[validation command: 18 chars]"]
|
||||
);
|
||||
});
|
||||
|
||||
test("goose agent can fall back to installing inside the container", () => {
|
||||
const args = buildGooseAgentDockerArgs({
|
||||
containerName: "ghbot-agent-test",
|
||||
|
||||
Reference in new issue
Block a user