Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions plugins/pstack/skills/poteto-mode/references/model-catalog.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ The runner refuses an access mode outside a provider's Access modes cell before
- Host prerequisites: none.
- State paths: the Claude config home (`CLAUDE_CONFIG_DIR`, else `~/.claude`).
- Child environment: read-only: inherited; isolated-write: inherited without `GIT_*`.
- `--verbose` makes Claude emit its event array, so the runner reports `child-failed` when every Bash call fails to start its sandbox (`apply-seccomp:` or `bwrap:`).
- The runner passes `ANTHROPIC_BASE_URL` and `ANTHROPIC_AUTH_TOKEN` from the `env` of `settings.json` in the Claude config home only when the shell sets none of `ANTHROPIC_BASE_URL`, `ANTHROPIC_AUTH_TOKEN`, or `ANTHROPIC_API_KEY`.
- When the runner uses those settings, it also forwards `apiKeyHelper` if the settings `env` supplies neither `ANTHROPIC_API_KEY` nor `ANTHROPIC_AUTH_TOKEN`.

### codex: Codex CLI

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { describe, expect, it } from "bun:test";
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { access } from "../registry/contract.ts";
import type { LaneRequest } from "../registry/index.ts";
import { adapterSuite, testLane } from "./adapter-suite.ts";
Expand All @@ -9,9 +12,29 @@ adapterSuite(claude);

const lane = (request: Partial<LaneRequest> = {}) =>
testLane({ provider: "claude", model: "fable", ...request });
const argv = (request: Partial<LaneRequest> = {}, sharedGitDir: string | null = null) =>
claude.launch.argv(lane(request), { sharedGitDir, providerSidecar: null });
const parse = (stdout: string) => claude.parse({ exitCode: 0, stdout, stderr: "", sidecar: null }, lane());
const argv = (
request: Partial<LaneRequest> = {},
sharedGitDir: string | null = null,
sourceEnv?: NodeJS.ProcessEnv
) => claude.launch.argv(lane(request), {
sharedGitDir,
providerSidecar: null,
hostConfig: sourceEnv === undefined ? undefined : claude.hostConfig?.(sourceEnv),
});
const launchSettings = (args: readonly string[]): unknown =>
JSON.parse(args[args.indexOf("--settings") + 1] ?? "");
const parse = (stdout: string, request: Partial<LaneRequest> = {}) =>
claude.parse({ exitCode: 0, stdout, stderr: "", sidecar: null }, lane(request));

const seccomp = "apply-seccomp: failed to apply seccomp filter: Operation not permitted";
const toolUse = (id: string, name = "Bash") =>
({ type: "assistant", message: { content: [{ type: "tool_use", id, name, input: {} }] } });
const toolResult = (id: string, content: unknown, isError = true) =>
({ type: "user", message: { content: [{ type: "tool_result", tool_use_id: id, content, is_error: isError }] } });
const terminal = {
type: "result", is_error: false, result: "I could not run commands.",
session_id: "s1", modelUsage: { "claude-fable-9-9": {} },
};

describe("claude launch", () => {
it("passes Claude model, effort, permissions, and no-recursion controls", () => {
Expand All @@ -37,6 +60,7 @@ describe("claude launch", () => {
"Agent,Task,WebSearch,WebFetch,Edit,Write,NotebookEdit",
"--output-format",
"json",
"--verbose",
]);
expect(args).not.toContain("bypassPermissions");
});
Expand All @@ -60,14 +84,11 @@ describe("claude launch", () => {
allowUnsandboxedCommands: false,
failIfUnavailable: true,
};
const settings = (args: readonly string[]): unknown =>
JSON.parse(args[args.indexOf("--settings") + 1] ?? "");

expect(settings(argv(writer))).toEqual({ sandbox });
expect(settings(argv(writer, "/repo/.git"))).toEqual({
expect(launchSettings(argv(writer))).toEqual({ sandbox });
expect(launchSettings(argv(writer, "/repo/.git"))).toEqual({
sandbox: { ...sandbox, filesystem: { denyWrite: ["/repo/.git"] } },
});
expect(settings(argv(writer, "/srv/my repo/.git"))).toEqual({
expect(launchSettings(argv(writer, "/srv/my repo/.git"))).toEqual({
sandbox: { ...sandbox, filesystem: { denyWrite: ["/srv/my repo/.git"] } },
});

Expand All @@ -88,6 +109,75 @@ describe("claude launch", () => {
});
});

describe("claude launch authentication", () => {
const apiKeyHelper = "/example/claude-auth";
let configDir: string;
let sourceEnv: NodeJS.ProcessEnv;

beforeEach(() => {
configDir = mkdtempSync(join(tmpdir(), "pstack-claude-settings-"));
sourceEnv = { CLAUDE_CONFIG_DIR: configDir };
});
afterEach(() => rmSync(configDir, { recursive: true }));

function writeSettings(settings: object): void {
writeFileSync(join(configDir, "settings.json"), JSON.stringify(settings));
}

it("passes the settings gateway and helper when the source has no connection or auth values", () => {
const env = { ANTHROPIC_BASE_URL: "https://gateway.example" };
writeSettings({ apiKeyHelper, env });
expect(claude.hostConfig?.(sourceEnv)?.environmentDefaults).toEqual(env);
expect(launchSettings(argv({}, null, sourceEnv))).toEqual({ apiKeyHelper });
});

it("leaves the settings gateway, token, and helper out when the source has an API key", () => {
writeSettings({
apiKeyHelper,
env: { ANTHROPIC_BASE_URL: "https://gateway.example", ANTHROPIC_AUTH_TOKEN: "settings-token" },
});
const source = { ...sourceEnv, ANTHROPIC_API_KEY: "source-key" };
expect(claude.hostConfig?.(source)).toEqual({ environmentDefaults: {}, settings: {} });
expect(argv({}, null, source)).not.toContain("--settings");
});

it("merges helper and sandbox into one inline settings object for a writer", () => {
writeSettings({ apiKeyHelper });
const writer = { mode: "isolated-write" };
const args = argv(writer, "/repo/.git", sourceEnv);
expect(args.filter((arg) => arg === "--settings")).toHaveLength(1);
expect(launchSettings(args)).toEqual({
apiKeyHelper,
sandbox: {
enabled: true,
autoAllowBashIfSandboxed: true,
allowUnsandboxedCommands: false,
failIfUnavailable: true,
filesystem: { denyWrite: ["/repo/.git"] },
},
});
});

for (const key of ["ANTHROPIC_AUTH_TOKEN", "ANTHROPIC_API_KEY"]) {
it(`omits the helper when ${key} is set in the source or settings env`, () => {
writeSettings({ apiKeyHelper });
expect(argv({}, null, { ...sourceEnv, [key]: "source-auth" })).toEqual(argv());
writeSettings({ apiKeyHelper, env: { [key]: "settings-auth" } });
expect(argv({}, null, sourceEnv)).toEqual(argv());
});
}

it("keeps the existing argv without a settings file or a non-empty string helper", () => {
const writer = { mode: "isolated-write" };
expect(argv({}, null, sourceEnv)).toEqual(argv());
for (const apiKeyHelper of [undefined, "", 42]) {
writeSettings({ apiKeyHelper });
expect(argv({}, null, sourceEnv)).toEqual(argv());
expect(argv(writer, null, sourceEnv)).toEqual(argv(writer));
}
});
});

describe("claude parse", () => {
it("extracts Claude text, model, usage, cost, and session", () => {
expect(parse(JSON.stringify({
Expand Down Expand Up @@ -176,6 +266,69 @@ describe("claude parse", () => {
});
});

describe("claude Bash sandbox startup failure", () => {
const sandboxFailed = (line: string) => ({
kind: "provider-failure",
status: "child-failed",
message: `claude could not start its Bash sandbox: ${line}`,
metadata: { reportedModel: "claude-fable-9-9", sessionId: "s1" },
});
const bwrap = "bwrap: No permissions to create new namespace";

for (const { name, events, mode, expected } of [
{
name: "apply-seccomp string content",
events: [toolUse("b1"), toolResult("b1", `Exit code 1\n${seccomp}`)],
expected: sandboxFailed(seccomp),
},
{
name: "bwrap text-block content",
events: [toolUse("b1"), toolResult("b1", [{ type: "text", text: ` ${bwrap}\nmore` }])],
expected: sandboxFailed(bwrap),
},
{
name: "read-only lane",
events: [toolUse("b1"), toolResult("b1", seccomp)],
mode: "read-only" as const,
expected: sandboxFailed(seccomp),
},
{
name: "mixed success and failure",
events: [toolUse("b1"), toolResult("b1", seccomp), toolUse("b2"), toolResult("b2", "ok", false)],
expected: { kind: "complete" },
},
{
name: "mixed sandbox startup failure and ordinary Bash error",
events: [
toolUse("b1"), toolResult("b1", seccomp),
toolUse("b2"), toolResult("b2", "Exit code 1\nno matches"),
],
expected: { kind: "complete", text: terminal.result },
},
{
name: "two sandbox startup failures",
events: [toolUse("b1"), toolResult("b1", seccomp), toolUse("b2"), toolResult("b2", bwrap)],
expected: sandboxFailed(seccomp),
},
{
name: "ordinary Bash error",
events: [toolUse("b1"), toolResult("b1", "Exit code 2\nls: missing: No such file or directory")],
expected: { kind: "complete" },
},
{ name: "no tool calls", events: [], expected: { kind: "complete" } },
{
name: "non-Bash tool error",
events: [toolUse("r1", "Read"), toolResult("r1", bwrap)],
expected: { kind: "complete" },
},
]) {
it(`classifies ${name}`, () => {
expect(parse(JSON.stringify([...events, terminal]), { mode: mode ?? "isolated-write" }))
.toMatchObject(expected);
});
}
});

describe("claude model proof", () => {
it("matches only concrete Claude revisions from the requested rolling family", () => {
const fable = lane();
Expand Down
Loading
Loading