feat: launch Claude headless with pinned sandbox policy
19 files changed,
+4,584
−4
.rastrillo/budgets.txt+1 −0docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md+2,450 −0internal/runner/containment/mounts.go+1 −1internal/runner/containment/mounts_test.go+37 −0internal/runner/provider/accounts.go+86 −2internal/runner/provider/claude/budget_test.go+9 −0internal/runner/provider/claude/events.go+118 −0internal/runner/provider/claude/events_test.go+110 −0internal/runner/provider/claude/launcher.go+766 −0internal/runner/provider/claude/launcher_test.go+836 −0internal/runner/provider/claude/testdata/recording.json+81 −0internal/runner/provider/claude/testdata/resume-recording.json+61 −0internal/runner/provider/claude/testdata/resume-stderr.txt+0 −0internal/runner/provider/claude/testdata/resume-stdin.jsonl+1 −0internal/runner/provider/claude/testdata/resume-stdout.jsonl+4 −0internal/runner/provider/claude/testdata/stderr.txt+0 −0internal/runner/provider/claude/testdata/stdin.jsonl+2 −0internal/runner/provider/claude/testdata/stdout.jsonl+7 −0internal/runner/provider/policy.go+14 −1
CI failed — run details
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index c66b1010..c5f467f6 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -22,3 +22,4 @@ time internal/runner 330s Final corrected package rerun measured 152.897s; revie |
| perf GET /live skip Authorized notification stream, bounded to 30 seconds; not a GET screen. |
| perf GET /api/runner/v1/artifacts/{assignment}/{artifact} skip Authenticated runner artifact download, not a browser GET screen. Runner long-poll and blob downloads use POST and are outside the screen inventory. |
| size internal/runner 6500 - Final fixes add guarded journal reset, typed diagnostics and bounded prompts beside the mandated runner workflow; current source count: 5896. |
| +time internal/runner/provider/claude 45s Task 5 measured 32.430s for fake CLI sessions and fsynced account, policy, capture and refresh checks; 45s gives 38 percent headroom on the shared runner. |
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md| index 9f9f38de..b1b4f5ab 100644 |
| --- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md |
| +++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-2b.md |
| @@ -7890,3 +7890,2453 @@ No UI strings or copy.go entries changed. The new internal error code is `provid |
| No unresolved fix-round findings remain. Real refresh behavior, native provider tool restrictions and deployed-policy certification remain later live gates. The fake-login namespace tests do not certify a provider account or add release certificates. Adapters must use CommitRefresh, Preflight and the turn/resume checks in the stated order. |
| All mutation sources were restored. All test processes and namespace children exited through their cleanup paths. Owned scratch logs/scripts are removed after copying their evidence into these reports. No push, merge, deployment, README edit, other worktree change or production configuration change was made. |
| + |
| +## Task 5: Claude Code headless sessions |
| + |
| +Status: DONE_WITH_CONCERNS. |
| +Commit subject: `feat: launch Claude headless with pinned sandbox policy`. |
| +Branch: `plan-2b`. Work stayed in the authorized worktree. No push, merge, deployment, sign-in, enrolment, helper agent, copy-review server or .claude/HANDOFF.md. |
| + |
| +### What changed |
| + |
| +`claude.New(ProcessHost, CaptureFactory)` implements `provider.Launcher`. `claude.PolicyInputs(binding, inputs, specialist, model)` renders the exact specialist policy before the caller uses `provider.BuildPolicy`. The binding must come from an existing `AccountLease`. Open validates the pinned executable and policy, checks the account through captured no-prompt status, runs an empty-input dependency control, generates a UUID, starts the contained process and opens durable capture. The concrete launch manifest passed to CaptureFactory contains the UUID and exact argv before any user envelope is written. Open's context remains the attempt lifetime. |
| + |
| +StartTurn requires an attached Events consumer, a nonempty unused turn ID and admission ID, an available account lease, unchanged generated/managed/runtime files and an attested launch. BeginTurn/EndTurn bracket the active interval. Runtime refresh requires CommitRefresh and fresh Preflight before another prompt. Source-generation changes also require fresh Preflight. Containment failures stop the attempt. A cancelled or partial stdin write leaves the turn uncertain and cancels the process. StartTurn releases the launcher mutex during I/O so interruption and event capture can continue. |
| + |
| +Fresh sessions use `--session-id`; resume uses the saved ID. Resume requires the latest attempt for that session to have a captured successful result, clean capture completion and a zero process exit, with the same binding, selection and base policy. A newer attempt invalidates the older completion as resume authority. Used admissions carry forward. Unknown sessions, interrupted attempts and uncertain turns cannot resume. A graceful Close drains capture and checks process exit; Interrupt cancels the owned lifetime and does not manufacture containment proof. |
| + |
| +Decode accepts bounded complete JSON frames, rejects duplicate keys, preserves raw payloads and session/request/message/tool IDs, and maps result failures using both `is_error` and subtype. Result usage remains the recorded per-turn object; cumulative modelUsage is retained separately in the raw payload. The reader accepts repeated init records, including init after the first admitted input. It checks version, model, permission mode, tools, MCP servers, skills and plugin provenance. Capture sequences must increase; gaps are allowed because Task 1 does not promise contiguous journal sequence numbers. Non-JSON stderr belongs to capture and is not parsed as a provider stdout event. Partial, oversized, missing and mismatched stdout fail closed. Nonzero process exit prevents resume even after a success result. |
| + |
| +Engineering uses exactly `Bash,Read,Write,Edit,Glob,Grep`. Review and Product use exactly `Read,Glob,Grep,Bash`. Explicit Equipo MCP names are included in the policy inventory; permission is always registered. The CLI argv has no prompt and uses the exact pinned settings, strict MCP, manual permission and prompt-tool flags. Both required environment variables are constructed by BuildPolicy and admitted by containment. Sandbox dependency failure is fatal; unsandboxed retries, excluded commands, automatic shell approval, arbitrary hooks and user plugins are disabled. Native Read/Write/Edit/Glob/Grep and inner-shell read/write denies cover the selected login, runner home, supplied protected paths and aliases, /egress, /tool, /tool/equipo.sock, /config, /proc and /dev/fd. |
| + |
| +The fixed MCP shape is: |
| + |
| +```json |
| +{"mcpServers":{"equipo":{"type":"stdio","command":"/opt/equipo-tool-proxy","args":["--socket","/tool/equipo.sock"]}}} |
| +``` |
| + |
| +The helper must be supplied as an attested read-only runtime file. Task 8 owns that executable, registered tool implementation and permission relay. Respond currently refuses direct answers; it cannot grant permissions or create a hidden turn. |
| + |
| +Task 4 needed three narrow integration changes. A verified binding can expose its own lease to the adapter. Claude observations compare the CLI-reported account and pinned version without inventing an observed HomeID. The lease stages only native nonsecret account identifiers from the dedicated home's `.claude.json`, so `auth status --json` can report the account; it never imports settings, hooks, plugins or trust entries. Source metadata participates in generation checks and changed runtime identifiers latch containment. Missing metadata cannot become an expected-account fallback. |
| + |
| +The reusable policy hash normalizes a valid trailing Claude session UUID and start/resume selector. The concrete manifest and launch attestation retain them exactly. This keeps certificates reusable without allowing a different account, model, tools or settings to reuse a session. |
| + |
| +### Files |
| + |
| +- `internal/runner/provider/claude/launcher.go`, `events.go`: adapter, rendering, preflight, lifecycle and decoder. |
| +- `internal/runner/provider/claude/launcher_test.go`, `events_test.go`, `budget_test.go`: real local fake CLI processes, fake capture, recorded-frame assertions and the standard package budget entry point. |
| +- `internal/runner/provider/claude/testdata/`: sanitized stdin/stdout, empty stderr and timing/version/digest metadata for the two authorized invocations. |
| +- `internal/runner/provider/accounts.go`: lease access and Claude native metadata/identity checks. |
| +- `internal/runner/provider/policy.go`: required Claude environment and session UUID normalization in reusable policy hashes. |
| +- `internal/runner/containment/mounts.go`, `mounts_test.go`: the same required environment at the actual namespace boundary; the unsupported updater spelling is refused. |
| +- `.rastrillo/budgets.txt`: 45-second exception for the new package, whose offline run measured 32.430 seconds on the shared machine. It includes fsynced account/policy checks and many local fake processes. |
| +- This controller section and the ignored local task report. The two-line invocation tally remains at the requested ignored local path. |
| + |
| +### Authorized recording |
| + |
| +Exactly two Claude invocations were made. Before each, the recorder took a file lock, counted the tally lines, refused a third invocation, appended and fsynced its line, then executed Claude. No separate version, help or auth invocation was made. Version came from init; the executable digest came from the resolved binary file. No credential file was read, printed, copied or hashed by the recorder, and no provider settings, CLAUDE.md, plugins or skills were manually edited. |
| + |
| +The only home used was the existing signed-in home explicitly authorized in the dispatch. Its path is absent from code, tests and committed fixtures. Production still refuses ZeroSub homes. Task 2/3 launch was infeasible for this exception because Manager requires a manifest backed by Task 4's verified dedicated-home provenance, which refuses that home. The recording therefore used the authorized direct fallback. It did not weaken the production refusal. |
| + |
| +Resolved executable: `/home/paulca/.local/share/claude/versions/2.1.312`. |
| +CLI version: `2.1.312`, observed in both runs' init records. |
| +SHA-256: `4f4178ce41d83e23341ebfbaecdbcf8ea6bf7baea0690025abe49eeec3a5d01d`. |
| + |
| +The following is the exact argument/environment shape with private paths and UUID replaced by their fixture placeholders. `$RECORDING` was an owned directory under the on-disk TMPDIR, and cwd was `$RECORDING/workspace`: |
| + |
| +```sh |
| +CLAUDE_CONFIG_DIR="$AUTHORIZED_HOME" |
| +CLAUDE_SECURESTORAGE_CONFIG_DIR="$AUTHORIZED_HOME" |
| +HOME="$RECORDING/home" |
| +TMPDIR="$RECORDING/tmp" |
| +CLAUDE_TMPDIR="$RECORDING/tmp" |
| +PATH=/usr/bin:/bin |
| +LANG=C.UTF-8 |
| +CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1 |
| +DISABLE_AUTOUPDATER=1 |
| +# No inherited environment; settings.json contains disableAllHooks:true and enabledPlugins:{}. |
| +# mcp.json contains {"mcpServers":{}}. |
| +<resolved-claude> -p --verbose --input-format stream-json --output-format stream-json --session-id <fresh-uuid> --model claude-haiku-5-5 --setting-sources '' --strict-mcp-config --mcp-config "$RECORDING/mcp.json" --disable-slash-commands --tools '' --settings "$RECORDING/settings.json" |
| +# Invocation 2 replaces --session-id with --resume and uses the saved UUID. |
| +``` |
| + |
| +Each run waited three seconds without input to observe startup, then wrote the recorded JSON user envelope. Invocation 1 wrote the second envelope only after the first result. Stdin closed after the second result. Invocation 2 sent one envelope and closed stdin after its result. Prompts were exactly `Reply with the single word one.`, `Reply with the single word two.` and `Reply with the single word three.` No prompt appeared in argv. Both invocations had a 120-second kill bound and completed normally. |
| + |
| +Neither run emitted init before the first input. The first input was at 3.004893 seconds and first stdout at 3.026742 seconds. Init was repeated for the second turn. All session-bearing records in both runs used the supplied/saved session ID. Sanitization consistently replaced it with `00000000-0000-4000-8000-000000000001`. |
| + |
| +| Invocation/turn | Result | input_tokens | cache_creation_input_tokens | cache_read_input_tokens | output_tokens | result_index | |
| +| --- | --- | ---: | ---: | ---: | ---: | ---: | |
| +| fresh / one | success, is_error:false | 2 | 3906 | 0 | 3 | 0 | |
| +| same process / two | success, is_error:false | 2 | 378 | 3566 | 3 | 1 | |
| +| resume / three | success, is_error:false | 2 | 63 | 3919 | 3 | 0 | |
| + |
| +Invocation 1 exited 0 after 6.336797 seconds; invocation 2 exited 0 after 4.746490 seconds. Both stderr streams were empty. modelUsage input/output accumulated as 2/3, 4/6 and 6/9; the usage object above stayed per-turn across both the long-lived process and resume. The fixtures retain all usage numbers and other nonsecret frame fields. This is the accounting baseline, not a billing assertion. |
| + |
| +Fixtures were written and pinned to the observed version/digest before implementation. UUIDs and message/request IDs were consistently replaced, paths were replaced, and email/host/token-shaped data was sanitized. Capabilities, frame field names, types, turn boundaries and usage numbers were preserved. A final scan found none of the authorized home path, host names, account email or token prefixes in testdata. Raw capture and recorder scratch were deleted after extracting this evidence. |
| + |
| +### Interpretations and integration limits |
| + |
| +1. HomeID is Equipo-assigned. The public Preflight result deliberately has empty HomeID. The account lease compares only actual Claude account metadata and the pinned binary version, while retaining its separate local HomeID binding. Claude AccountID is the email returned by auth status; this remains local CLI metadata and trust-on-first-use, not remote identity attestation. |
| +2. The native `.claude.json` import is needed because the nesting report observed null email when only credentials were staged. It selects only emailAddress, accountUuid and organizationUuid, plus the onboarding boolean. Neither Equipo identity metadata nor the expected binding is echoed as a CLI observation. No credential or provider-home content from the real recording entered this implementation. |
| +3. The task's required updater spelling supersedes the older generic builder and namespace allowlist. Both now use DISABLE_AUTOUPDATER and CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC. |
| +4. Imported managed runtime settings are refused because Claude has no proven effective-config readback here. Instruction mounts may include the specifically hashed `/etc/claude-code/CLAUDE.md`, but cannot smuggle managed settings JSON into the masked directory. This favors refusal over an uncertified override. |
| +5. The recorded pinned executable lists two built-in plugins even with empty enabledPlugins: cc-plugin-agents-md and cc-plugin-plugin-authoring. Init accepts only those exact names with path builtin and matching @builtin source. Arbitrary plugins and skills are refused. Built-in agent names in init do not expose Task/subagent tools; the exact tools inventory remains enforced. |
| +6. Task 1 has no durable-session lookup/rehydration method. This adapter resumes only sessions whose durable frames and clean exit it observed in the current launcher lifetime. Unknown sessions after restart are refused. Task 7 must recover the journal and quarantine uncertainty before adding any rehydration authority; this task does not invent proof. |
| +7. CaptureFactory is the durable boundary. The adapter never reads stdout/stderr directly. The fake capture drains both streams and supplies frames for tests. The production journal and the Equipo MCP helper remain Tasks 7 and 8. Their absence does not authorize alternate capture or permission paths. |
| +8. The recording establishes stream input, session identity and usage, with tools disabled as authorized. Production strict-MCP helper behavior, empty-input dependency control, real refresh and full native/alias read-denial certification still belong to Task 11b. No additional provider run was made to test those release gates. |
| +9. The user's explicit task rules override generic copy-review, delegation and handoff workflows. No README prose or copy.go entry changed. |
| + |
| +### RED evidence |
| + |
| +Commands ran from `/home/paulca/amadan.net/oficina/equipo-plan-2b`, with CGO_ENABLED=0, the supplied on-disk TMPDIR and default Go caches. Initial tests preceded implementation. The initial API RED was: |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run '^TestClaude' -count=1 |
| +``` |
| + |
| +```text |
| +# amadan.net/oficina/equipo/internal/runner/provider/claude [amadan.net/oficina/equipo/internal/runner/provider/claude.test] |
| +internal/runner/provider/claude/launcher_test.go:74:68: undefined: MaxFrameBytes |
| +internal/runner/provider/claude/launcher_test.go:80:25: undefined: Launcher |
| +internal/runner/provider/claude/launcher_test.go:83:97: undefined: Version |
| +internal/runner/provider/claude/launcher_test.go:90:7: undefined: PolicyInputs |
| +internal/runner/provider/claude/events_test.go:17:15: undefined: Decode |
| +internal/runner/provider/claude/events_test.go:32:9: undefined: Decode |
| +internal/runner/provider/claude/events_test.go:37:9: undefined: Decode |
| +internal/runner/provider/claude/events_test.go:39:76: undefined: MaxFrameBytes |
| +internal/runner/provider/claude/events_test.go:40:11: undefined: Decode |
| +internal/runner/provider/claude/events_test.go:49:11: undefined: userEnvelope |
| +internal/runner/provider/claude/launcher_test.go:90:7: too many errors |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude [build failed] |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run 'TestClaudeLaunchPolicy|TestClaudePolicyRefusals|TestClaudeRefreshBeforeTurn|TestClaudeObservedIdentity' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.69s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.23s) |
| + launcher_test.go:283: session ID changed reusable policy hash |
| + --- FAIL: TestClaudeLaunchPolicy/Review (0.23s) |
| + launcher_test.go:283: session ID changed reusable policy hash |
| + --- FAIL: TestClaudeLaunchPolicy/Product (0.23s) |
| + launcher_test.go:283: session ID changed reusable policy hash |
| +--- FAIL: TestClaudePolicyRefusals (0.69s) |
| + --- FAIL: TestClaudePolicyRefusals/helper (0.23s) |
| + launcher_test.go:506: unsafe policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 2.381s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 2.383s |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run 'TestClaudeTerminalErrors|TestClaudeResumeLatestAttempt' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestClaudeTerminalErrors (3.41s) |
| + --- FAIL: TestClaudeTerminalErrors/missing (0.48s) |
| + launcher_test.go:464: events ended without terminal |
| + --- FAIL: TestClaudeTerminalErrors/oversized (0.48s) |
| + launcher_test.go:464: events ended without terminal |
| +--- FAIL: TestClaudeResumeLatestAttempt (1.11s) |
| + launcher_test.go:574: resumed admission replayed |
| + launcher_test.go:580: old completion overrode newer uncertainty |
| +FAIL |
| +rastrillo-budget/v1 ran 4.524s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 4.529s |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run '^TestClaudeNativeIdentityMetadata$' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestClaudeNativeIdentityMetadata (0.51s) |
| + --- FAIL: TestClaudeNativeIdentityMetadata/staged (0.08s) |
| + launcher_test.go:636: open /home/paulca/t/e2b/TestClaudeNativeIdentityMetadatastaged3043721488/001/homes/account-2540258232/.claude.json: no such file or directory |
| + --- FAIL: TestClaudeNativeIdentityMetadata/source (0.22s) |
| + launcher_test.go:643: provider_identity_mismatch |
| + --- FAIL: TestClaudeNativeIdentityMetadata/runtime (0.21s) |
| + launcher_test.go:643: provider_identity_mismatch |
| +FAIL |
| +rastrillo-budget/v1 ran 512ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.514s |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run 'TestClaudeConstructor|TestClaudeConcurrentSession' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestClaudeConstructor (0.00s) |
| + launcher_test.go:676: missing dependency accepted |
| +--- FAIL: TestClaudeConcurrentSession (1.31s) |
| + launcher_test.go:686: two processes admitted on one account lease |
| +FAIL |
| +rastrillo-budget/v1 ran 1.313s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 1.316s |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run '^TestClaudePolicyRefusals/managed$|^TestClaudeReadiness/malformed_capture$' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestClaudePolicyRefusals (0.85s) |
| + --- FAIL: TestClaudePolicyRefusals/managed (0.85s) |
| + launcher_test.go:588: unsafe policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 1.6s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 1.604s |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run '^TestClaudePolicyRefusals/managed_instruction$' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestClaudePolicyRefusals (0.82s) |
| + --- FAIL: TestClaudePolicyRefusals/managed_instruction (0.82s) |
| + launcher_test.go:611: unsafe policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 819ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.822s |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run '^TestNamespaceClaudeEnvironment$' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestNamespaceClaudeEnvironment (0.00s) |
| + --- FAIL: TestNamespaceClaudeEnvironment/CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC (0.00s) |
| + mounts_test.go:94: required Claude environment refused: namespace_mount_rejected |
| + --- FAIL: TestNamespaceClaudeEnvironment/DISABLE_AUTOUPDATER (0.00s) |
| + mounts_test.go:94: required Claude environment refused: namespace_mount_rejected |
| + mounts_test.go:111: unsupported updater environment accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 2ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.004s |
| +FAIL |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run '^TestClaudeWriteCancellation$' -count=1 |
| +``` |
| + |
| +```text |
| +--- FAIL: TestClaudeWriteCancellation (1.11s) |
| + launcher_test.go:814: cancelled admission left stdin blocked |
| +FAIL |
| +rastrillo-budget/v1 ran 1.112s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 1.144s |
| +FAIL |
| +``` |
| + |
| +An initial fake-process harness used Cmd.StdoutPipe with a concurrent Wait, which could close the read pipe early. The harness was corrected to own its pipes, and the lifecycle RED above was rerun afterward. Two newly added test cases initially lacked their case setup; those were corrected before the managed-settings RED recorded here. Those harness/setup failures are not claimed as behavioral evidence. |
| + |
| +### GREEN evidence |
| + |
| +Required adapter command after restoration of the first 70 mutations: |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run '^TestClaude' -count=1 |
| +``` |
| + |
| +```text |
| +ok amadan.net/oficina/equipo/internal/runner/provider/claude 32.430s |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider ./internal/runner/containment -run '^TestAccount|^TestEffectivePolicy|^TestUnexpectedConfig|^TestPrivateHome|^TestNamespaceClaudeEnvironment$|^TestNamespaceDirectPolicy$|^TestNamespaceProviderRequiresManifest$' -count=1 |
| +``` |
| + |
| +```text |
| +ok amadan.net/oficina/equipo/internal/runner/provider 15.910s |
| +ok amadan.net/oficina/equipo/internal/runner/containment 0.521s |
| +``` |
| + |
| +The related checks include an actual local bubblewrap namespace with a fake provider, the required environment at the mount boundary, mandatory provider manifests and Task 4 account/policy regressions. No model provider is involved. `git diff --check` passed and changed Go files were formatted. No full repository suite, make ci or live certification ran. |
| + |
| +### Mutation evidence |
| + |
| +71 independent mutations compiled and caused the named test to fail. Each was applied alone and restored in a finally block before the next mutation. The scratch driver invoked Go directly with CGO_ENABLED=0, captured the exit code and required a named test failure without a build failure. The driver was run in bounded batches using `python3 /home/paulca/t/e2b/task5-recording/mutations.py <start> <end>`. The exact mutation and Go command for every case follow. |
| + |
| +Two first attempts were not evidence: the oversized-input mutation matched Decode's earlier size expression, and the plugin mutation changed only one part of a compound predicate. Both initially passed. Each target was corrected and rerun; the final failures below replace those invalid attempts. No compile error is counted as mutation evidence. |
| + |
| +#### Mutation 1: sandbox-enabled |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"enabled": true |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"enabled": false |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.24s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.24s) |
| + launcher_test.go:305: sandbox weakened |
| +FAIL |
| +rastrillo-budget/v1 ran 236ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.241s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 2: sandbox-required |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"failIfUnavailable": true |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"failIfUnavailable": false |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.27s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.27s) |
| + launcher_test.go:305: sandbox weakened |
| +FAIL |
| +rastrillo-budget/v1 ran 268ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.274s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 3: unsandboxed-retry |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"allowUnsandboxedCommands": false |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"allowUnsandboxedCommands": true |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.16s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.16s) |
| + launcher_test.go:305: sandbox weakened |
| +FAIL |
| +rastrillo-budget/v1 ran 164ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.176s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 4: excluded-command |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"excludedCommands": []string{} |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"excludedCommands": []string{"sh"} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.19s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.19s) |
| + launcher_test.go:311: excluded commands |
| +FAIL |
| +rastrillo-budget/v1 ran 187ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.195s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 5: automatic-shell-approval |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"autoAllowBashIfSandboxed": false |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"autoAllowBashIfSandboxed": true |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.20s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.20s) |
| + launcher_test.go:308: automatic shell approval enabled |
| +FAIL |
| +rastrillo-budget/v1 ran 198ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.217s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 6: hooks-disabled |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"disableAllHooks": true |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"disableAllHooks": false |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.18s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.18s) |
| + launcher_test.go:298: hooks/plugins enabled |
| +FAIL |
| +rastrillo-budget/v1 ran 180ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.186s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 7: plugins-disabled |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"enabledPlugins": map[string]any{} |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"enabledPlugins": map[string]any{"arbitrary":true} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.17s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.17s) |
| + launcher_test.go:298: hooks/plugins enabled |
| +FAIL |
| +rastrillo-budget/v1 ran 175ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.178s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 8: strict-mcp-argv |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"--strict-mcp-config", |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.81s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.81s) |
| + launcher_test.go:330: argv [/opt/claude -p --verbose --input-format stream-json --output-format stream-json --model claude-haiku-5-5 --setting-sources --disable-slash-commands --mcp-config /config/equipo-mcp.json --settings /config/equipo-settings.json --permission-mode manual --permission-prompt-tool mcp__equipo__permission --tools Bash,Read,Write,Edit,Glob,Grep --session-id 15ad339f-a1cb-46d2-b604-9bafc986e758] |
| +FAIL |
| +rastrillo-budget/v1 ran 811ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.818s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 9: settings-sources |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"--setting-sources", "", |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"--setting-sources", "user,project", |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.86s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.86s) |
| + launcher_test.go:330: argv [/opt/claude -p --verbose --input-format stream-json --output-format stream-json --model claude-haiku-5-5 --setting-sources user,project --disable-slash-commands --strict-mcp-config --mcp-config /config/equipo-mcp.json --settings /config/equipo-settings.json --permission-mode manual --permission-prompt-tool mcp__equipo__permission --tools Bash,Read,Write,Edit,Glob,Grep --session-id 468287dc-4708-46b6-854d-2aa6bac62a56] |
| +FAIL |
| +rastrillo-budget/v1 ran 865ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.874s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 10: disable-slash |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"--disable-slash-commands", |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.82s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.82s) |
| + launcher_test.go:330: argv [/opt/claude -p --verbose --input-format stream-json --output-format stream-json --model claude-haiku-5-5 --setting-sources --strict-mcp-config --mcp-config /config/equipo-mcp.json --settings /config/equipo-settings.json --permission-mode manual --permission-prompt-tool mcp__equipo__permission --tools Bash,Read,Write,Edit,Glob,Grep --session-id 79877393-30c4-49f8-9fe6-34b0fd620c70] |
| +FAIL |
| +rastrillo-budget/v1 ran 821ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.831s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 11: manual-permission |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"--permission-mode", "manual" |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"--permission-mode", "default" |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.85s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.85s) |
| + launcher_test.go:330: argv [/opt/claude -p --verbose --input-format stream-json --output-format stream-json --model claude-haiku-5-5 --setting-sources --disable-slash-commands --strict-mcp-config --mcp-config /config/equipo-mcp.json --settings /config/equipo-settings.json --permission-mode default --permission-prompt-tool mcp__equipo__permission --tools Bash,Read,Write,Edit,Glob,Grep --session-id d0e89ca7-b09d-4025-8d88-fc0300f91ec2] |
| +FAIL |
| +rastrillo-budget/v1 ran 854ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.870s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 12: permission-tool |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"mcp__equipo__permission", "--tools" |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"mcp__other__permission", "--tools" |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.85s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.85s) |
| + launcher_test.go:330: argv [/opt/claude -p --verbose --input-format stream-json --output-format stream-json --model claude-haiku-5-5 --setting-sources --disable-slash-commands --strict-mcp-config --mcp-config /config/equipo-mcp.json --settings /config/equipo-settings.json --permission-mode manual --permission-prompt-tool mcp__other__permission --tools Bash,Read,Write,Edit,Glob,Grep --session-id 217cb9a7-f5fc-44f0-a009-bfb8c78aba9d] |
| +FAIL |
| +rastrillo-budget/v1 ran 849ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.861s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 13: mcp-shape |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"mcpServers":{"equipo": |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"mcpServers":{"other": |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.21s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.21s) |
| + launcher_test.go:301: MCP inventory expanded |
| +FAIL |
| +rastrillo-budget/v1 ran 214ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.218s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 14: engineering-tools |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +[]string{"Bash", "Read", "Write", "Edit", "Glob", "Grep"} |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +[]string{"Bash", "Read", "Write", "Edit", "Glob", "Grep", "WebFetch"} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.16s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.16s) |
| + launcher_test.go:293: tools [Bash Read Write Edit Glob Grep WebFetch mcp__equipo__permission] |
| +FAIL |
| +rastrillo-budget/v1 ran 156ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.175s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 15: review-tools |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +[]string{"Read", "Glob", "Grep", "Bash"} |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +[]string{"Read", "Glob", "Grep", "Bash", "Write"} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Review$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.23s) |
| + --- FAIL: TestClaudeLaunchPolicy/Review (0.23s) |
| + launcher_test.go:293: tools [Read Glob Grep Bash Write mcp__equipo__permission] |
| +FAIL |
| +rastrillo-budget/v1 ran 235ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.241s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 16: tool-hash |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +Tools: tools, |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +Tools: nil, |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeToolHash$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeToolHash (0.27s) |
| + launcher_test.go:622: tool inventory missing from policy hash |
| +FAIL |
| +rastrillo-budget/v1 ran 275ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.277s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 17: native-denies |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +[]string{"Read", "Write", "Edit", "Glob", "Grep"} |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +[]string{"Write", "Edit", "Glob", "Grep"} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.42s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.42s) |
| + launcher_test.go:315: missing protected path /home/runner |
| +FAIL |
| +rastrillo-budget/v1 ran 417ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.426s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 18: egress-denial |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"/egress", |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.18s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.18s) |
| + launcher_test.go:315: missing protected path /egress |
| +FAIL |
| +rastrillo-budget/v1 ran 183ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.189s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 19: socket-denial |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"/tool/equipo.sock", |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.19s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.19s) |
| + launcher_test.go:315: missing protected path /tool/equipo.sock |
| +FAIL |
| +rastrillo-budget/v1 ran 194ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.197s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 20: alias-denials |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +denied := append([]string{}, in.DeniedPaths...) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +denied := []string{} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.17s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.17s) |
| + launcher_test.go:315: missing protected path /private/state |
| +FAIL |
| +rastrillo-budget/v1 ran 171ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.173s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 21: traffic-environment |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +env["CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC"] = "1" |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +env["CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC"] = "0" |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.17s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.17s) |
| + launcher_test.go:318: provider_policy_rejected |
| +FAIL |
| +rastrillo-budget/v1 ran 166ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.168s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 22: updater-environment |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +env["DISABLE_AUTOUPDATER"] = "1" |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +env["DISABLE_AUTOUPDATER"] = "0" |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.17s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.17s) |
| + launcher_test.go:318: provider_policy_rejected |
| +FAIL |
| +rastrillo-budget/v1 ran 172ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.175s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 23: session-policy-normalization |
| + |
| +File: `internal/runner/provider/policy.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if m.Provider == "claude" && len(m.Argv) >= 3 { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && m.Provider == "claude" && len(m.Argv) >= 3 { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.66s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.66s) |
| + launcher_test.go:326: session ID changed reusable policy hash |
| +FAIL |
| +rastrillo-budget/v1 ran 661ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.664s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 24: helper-required |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if !helperFound { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && !helperFound { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudePolicyRefusals/helper$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudePolicyRefusals (0.71s) |
| + --- FAIL: TestClaudePolicyRefusals/helper (0.71s) |
| + launcher_test.go:563: unsafe policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 710ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.712s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 25: digest-pin |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +found = f.SHA256 == l.digest |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +found = true |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeReadiness/digest$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeReadiness (0.66s) |
| + --- FAIL: TestClaudeReadiness/digest (0.66s) |
| + launcher_test.go:459: unready launch accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 662ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.664s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 26: admission |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +t.AdmissionID == "" || |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeNoPromptBeforeAdmission$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeNoPromptBeforeAdmission (0.67s) |
| + launcher_test.go:363: missing admission accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 672ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.674s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 27: events-attached |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +!v.attached || |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeReadiness/no_events$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeReadiness (0.71s) |
| + --- FAIL: TestClaudeReadiness/no_events (0.71s) |
| + launcher_test.go:482: unready turn accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 708ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.710s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 28: account-observation |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +observed.AccountID == b.Expected.AccountID && |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +true && |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeReadiness/identity$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeReadiness (0.68s) |
| + --- FAIL: TestClaudeReadiness/identity (0.68s) |
| + launcher_test.go:459: unready launch accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 685ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.687s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 29: homeid-not-observed |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +provider.Identity{AccountID: status.Email, ProviderVersion: Version} |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +provider.Identity{AccountID: status.Email, HomeID:b.Expected.HomeID, ProviderVersion: Version} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeObservedIdentity$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeObservedIdentity (0.61s) |
| + launcher_test.go:525: identity was not CLI observed: {AccountID:account@example.invalid HomeID:equipo-home ProviderVersion:2.1.312} |
| +FAIL |
| +rastrillo-budget/v1 ran 608ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.619s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 30: begin-turn |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if e = v.lease.BeginTurn(ctx); e != nil { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if e = error(nil); e != nil { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeActiveLease$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeActiveLease (0.69s) |
| + launcher_test.go:643: active interval not checked: provider_preflight_required |
| +FAIL |
| +rastrillo-budget/v1 ran 693ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.698s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 31: end-turn |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +endErr := s.lease.EndTurn(context.Background()) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +endErr := error(nil) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeNoPromptBeforeAdmission$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeNoPromptBeforeAdmission (0.72s) |
| + launcher_test.go:367: provider_account_busy |
| +FAIL |
| +rastrillo-budget/v1 ran 721ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.723s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 32: refresh-commit |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if e = lease.CommitRefresh(ctx, probe); e != nil { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if e = error(nil); e != nil { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeRefreshBeforeTurn/runtime$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeRefreshBeforeTurn (0.80s) |
| + --- FAIL: TestClaudeRefreshBeforeTurn/runtime (0.80s) |
| + launcher_test.go:579: provider_refresh_pending |
| +FAIL |
| +rastrillo-budget/v1 ran 800ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.803s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 33: error-flag |
| + |
| +File: `internal/runner/provider/claude/events.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if !*v.IsError && v.Subtype == "success" { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if v.Subtype == "success" { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeStreamEvents/error_flag$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeStreamEvents (0.00s) |
| + --- FAIL: TestClaudeStreamEvents/error_flag (0.00s) |
| + events_test.go:62: error treated as success [{s turn.completed [123 34 116 121 112 101 34 58 34 114 101 115 117 108 116 34 44 34 115 117 98 116 121 112 101 34 58 34 115 117 99 99 101 115 115 34 44 34 105 115 95 101 114 114 111 114 34 58 116 114 117 101 44 34 115 101 115 115 105 111 110 95 105 100 34 58 34 115 34 44 34 114 101 115 117 108 116 34 58 34 114 97 116 101 32 108 105 109 105 116 101 100 34 44 34 117 115 97 103 101 34 58 123 125 125]}] <nil> |
| +FAIL |
| +rastrillo-budget/v1 ran 2ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.004s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 34: oversized-frame |
| + |
| +File: `internal/runner/provider/claude/events.go`. Replace the first matching fragment: |
| + |
| +```go |
| +len(raw) > MaxFrameBytes || |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeStreamEvents$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeStreamEvents (0.01s) |
| + events_test.go:74: invalid frame accepted: {"type":"assistant","session_id":"s","text":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| +FAIL |
| +rastrillo-budget/v1 ran 12ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.014s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 35: duplicate-json |
| + |
| +File: `internal/runner/provider/claude/events.go`. Replace the first matching fragment: |
| + |
| +```go |
| +!ok || seen[s] |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +!ok |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeStreamEvents$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeStreamEvents (0.00s) |
| + events_test.go:74: invalid frame accepted: {"type":"assistant","session_id":"a","session_id":"b"} |
| +FAIL |
| +rastrillo-budget/v1 ran 3ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.005s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 36: frame-session |
| + |
| +File: `internal/runner/provider/claude/events.go`. Replace the first matching fragment: |
| + |
| +```go |
| +|| v.Session == "" |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeStreamEvents$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeStreamEvents (0.00s) |
| + events_test.go:74: invalid frame accepted: {"type":"assistant"} |
| +FAIL |
| +rastrillo-budget/v1 ran 3ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.005s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 37: request-id |
| + |
| +File: `internal/runner/provider/claude/events.go`. Replace the first matching fragment: |
| + |
| +```go |
| +RequestID: v.Request |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +RequestID: "" |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeStreamEvents/tool_ids$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeStreamEvents (0.00s) |
| + --- FAIL: TestClaudeStreamEvents/tool_ids (0.00s) |
| + events_test.go:69: tool correlation lost |
| +FAIL |
| +rastrillo-budget/v1 ran 3ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.005s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 38: oversized-input |
| + |
| +File: `internal/runner/provider/claude/events.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if e != nil || len(raw) > MaxFrameBytes { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if e != nil { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeInputEnvelope$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeInputEnvelope (0.00s) |
| + events_test.go:81: oversized input accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 5ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.008s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 39: recorded-usage |
| + |
| +File: `internal/runner/provider/claude/events.go`. Replace the first matching fragment: |
| + |
| +```go |
| +Payload: bytes.Clone(raw) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +Payload: changedUsage(raw) |
| +``` |
| + |
| +Additional mutation-only helper: |
| + |
| +```go |
| +func changedUsage(raw []byte) []byte {var v map[string]any;json.Unmarshal(raw,&v);if usage,ok:=v["usage"].(map[string]any);ok{usage["cache_creation_input_tokens"]=0};out,_:=json.Marshal(v);return out} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeStreamEvents/stdout.jsonl$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeStreamEvents (0.00s) |
| + --- FAIL: TestClaudeStreamEvents/stdout.jsonl (0.00s) |
| + events_test.go:55: per-turn usage [0,0] |
| + --- FAIL: TestClaudeStreamEvents/resume-stdout.jsonl (0.00s) |
| + events_test.go:55: per-turn usage [0] |
| +FAIL |
| +rastrillo-budget/v1 ran 5ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.009s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 40: emitted-session |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if ev.SessionID != s.session.ID { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && ev.SessionID != s.session.ID { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeTerminalErrors/identity$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeTerminalErrors (1.37s) |
| + --- FAIL: TestClaudeTerminalErrors/identity (1.37s) |
| + launcher_test.go:525: failure completed |
| +FAIL |
| +rastrillo-budget/v1 ran 1.372s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 1.377s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 41: exit-status |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +captureErr != nil || waitErr != nil || exit.Code != 0 || exit.Signal != 0 |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +captureErr != nil || waitErr != nil || exit.Signal != 0 |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeTerminalErrors/exit$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeTerminalErrors (2.08s) |
| + --- FAIL: TestClaudeTerminalErrors/exit (2.08s) |
| + launcher_test.go:533: uncertain/failed session resumed |
| +FAIL |
| +rastrillo-budget/v1 ran 2.078s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 2.080s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 42: latest-resume |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +previous.clean = false |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +previous.clean = true |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeResumeLatestAttempt$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeResumeLatestAttempt (2.81s) |
| + launcher_test.go:643: old completion overrode newer uncertainty |
| +FAIL |
| +rastrillo-budget/v1 ran 2.806s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 2.811s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 43: resume-admission-replay |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +s.used[key] = value |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +s.used[key] = !value |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeResumeLatestAttempt$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeResumeLatestAttempt (1.59s) |
| + launcher_test.go:637: resumed admission replayed |
| +FAIL |
| +rastrillo-budget/v1 ran 1.587s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 1.600s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 44: resume-binding |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +prior.launch.Binding != launch.Binding || prior.launch.Selection != launch.Selection |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +false |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeResumeUsesSameBinding/connection$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeResumeUsesSameBinding (1.50s) |
| + --- FAIL: TestClaudeResumeUsesSameBinding/connection (0.63s) |
| + launcher_test.go:440: invalid resume accepted |
| + launcher_test.go:446: provider_account_busy |
| +FAIL |
| +rastrillo-budget/v1 ran 1.498s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 1.506s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 45: resume-policy |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +prior.base.Hash != launch.Policy.Hash || |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeResumeUsesSameBinding/policy$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeResumeUsesSameBinding (1.70s) |
| + --- FAIL: TestClaudeResumeUsesSameBinding/policy (0.82s) |
| + launcher_test.go:440: invalid resume accepted |
| + launcher_test.go:446: provider_account_busy |
| +FAIL |
| +rastrillo-budget/v1 ran 1.7s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 1.709s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 46: source-native-metadata |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +metadata, raw, state, native |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +metadata, raw, state, nil |
| +``` |
| + |
| +The mutation also adds `_ = native` before the digest so it compiles. |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeNativeIdentityMetadata/source$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeNativeIdentityMetadata (1.13s) |
| + --- FAIL: TestClaudeNativeIdentityMetadata/source (1.13s) |
| + launcher_test.go:693: changed native identity metadata admitted |
| +FAIL |
| +rastrillo-budget/v1 ran 1.126s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 1.129s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 47: runtime-native-metadata |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +e != nil || !bytes.Equal(native, l.claudeIdentity) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +e != nil |
| +``` |
| + |
| +The mutation also adds `_ = native` after reading metadata so it compiles. |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeNativeIdentityMetadata/runtime$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeNativeIdentityMetadata (0.89s) |
| + --- FAIL: TestClaudeNativeIdentityMetadata/runtime (0.89s) |
| + launcher_test.go:693: changed native identity metadata admitted |
| +FAIL |
| +rastrillo-budget/v1 ran 886ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.892s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 48: metadata-import |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if l.source.Provider == "claude" { |
| + native, e := claudeAccountMetadata(l.dir) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && l.source.Provider == "claude" { |
| + native, e := claudeAccountMetadata(l.dir) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeNativeIdentityMetadata/staged$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeNativeIdentityMetadata (0.15s) |
| + --- FAIL: TestClaudeNativeIdentityMetadata/staged (0.15s) |
| + launcher_test.go:679: open /home/paulca/t/e2b/TestClaudeNativeIdentityMetadatastaged2449404140/001/homes/account-312458637/.claude.json: no such file or directory |
| +FAIL |
| +rastrillo-budget/v1 ran 152ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.155s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 49: constructor |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +missing(host) || missing(captures) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +host == nil || captures == nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeConstructor$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeConstructor (0.00s) |
| + launcher_test.go:710: missing dependency accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 0s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.002s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 50: exclusive-session |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +prior.launch.Binding == launch.Binding && !prior.closed |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +false && prior.launch.Binding == launch.Binding && !prior.closed |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeConcurrentSession$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeConcurrentSession (1.37s) |
| + launcher_test.go:720: two processes admitted on one account lease |
| +FAIL |
| +rastrillo-budget/v1 ran 1.373s |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 1.379s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 51: managed-runtime |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if strings.HasPrefix(f.Mount.Target, "/etc/") { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && strings.HasPrefix(f.Mount.Target, "/etc/") { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudePolicyRefusals/managed$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudePolicyRefusals (0.73s) |
| + --- FAIL: TestClaudePolicyRefusals/managed (0.73s) |
| + launcher_test.go:611: unsafe policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 734ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.736s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 52: managed-instruction |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +strings.HasPrefix(file.Target, "/etc/") && file.Target != "/etc/claude-code/CLAUDE.md" |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +false && strings.HasPrefix(file.Target, "/etc/") && file.Target != "/etc/claude-code/CLAUDE.md" |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudePolicyRefusals/managed_instruction$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudePolicyRefusals (0.73s) |
| + --- FAIL: TestClaudePolicyRefusals/managed_instruction (0.72s) |
| + launcher_test.go:611: unsafe policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 726ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.728s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 53: capture-readiness |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if capture == nil || capture.Input == nil || capture.Frames == nil || capture.Done == nil { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeReadiness/malformed_capture$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeReadiness (0.66s) |
| + --- FAIL: TestClaudeReadiness/malformed_capture (0.66s) |
| + launcher_test.go:498: unready launch accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 662ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.667s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 54: capture-order |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if frame.Sequence <= sequence { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && frame.Sequence <= sequence { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeCaptureSequence$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeCaptureSequence (0.72s) |
| + launcher_test.go:770: unsequenced frame accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 718ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.720s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 55: init-tools |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +!reflect.DeepEqual(want, v.Tools) || |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeInitPolicy/tools$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeInitPolicy (0.67s) |
| + --- FAIL: TestClaudeInitPolicy/tools (0.67s) |
| + launcher_test.go:757: unexpected init policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 670ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.672s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 56: init-mcp |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +len(v.Servers) != 1 || |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeInitPolicy/mcp$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeInitPolicy (0.68s) |
| + --- FAIL: TestClaudeInitPolicy/mcp (0.68s) |
| + launcher_test.go:757: unexpected init policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 680ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.683s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 57: init-plugins |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +for _, p := range v.Plugins { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +for _, p := range v.Plugins[:0] { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeInitPolicy/plugins$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeInitPolicy (0.82s) |
| + --- FAIL: TestClaudeInitPolicy/plugins (0.82s) |
| + launcher_test.go:764: unexpected init policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 817ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.821s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 58: init-skills |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +|| len(v.Skills) != 0 |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeInitPolicy/skills$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeInitPolicy (0.70s) |
| + --- FAIL: TestClaudeInitPolicy/skills (0.70s) |
| + launcher_test.go:757: unexpected init policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 703ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.706s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 59: init-mode |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +|| v.Permission != "manual" |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeInitPolicy/permission$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeInitPolicy (0.71s) |
| + --- FAIL: TestClaudeInitPolicy/permission (0.71s) |
| + launcher_test.go:757: unexpected init policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 711ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.713s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 60: init-version |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +|| v.Version != Version |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeInitPolicy/version$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeInitPolicy (0.68s) |
| + --- FAIL: TestClaudeInitPolicy/version (0.68s) |
| + launcher_test.go:757: unexpected init policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 681ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.683s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 61: init-model |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +|| v.Model != s.session.Model |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeInitPolicy/model$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeInitPolicy (0.76s) |
| + --- FAIL: TestClaudeInitPolicy/model (0.76s) |
| + launcher_test.go:757: unexpected init policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 755ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.757s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 62: shell-read-denies |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"denyRead": denied |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"denyRead": []string{} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.19s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.19s) |
| + launcher_test.go:341: missing shell denyRead denial /home/runner |
| +FAIL |
| +rastrillo-budget/v1 ran 188ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.190s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 63: shell-write-denies |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"denyWrite": denied |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"denyWrite": []string{} |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeLaunchPolicy/Engineering$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeLaunchPolicy (0.19s) |
| + --- FAIL: TestClaudeLaunchPolicy/Engineering (0.19s) |
| + launcher_test.go:341: missing shell denyWrite denial /home/runner |
| +FAIL |
| +rastrillo-budget/v1 ran 191ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.193s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 64: namespace-traffic-env |
| + |
| +File: `internal/runner/containment/mounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": true |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": false |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run ^TestNamespaceClaudeEnvironment/CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestNamespaceClaudeEnvironment (0.01s) |
| + --- FAIL: TestNamespaceClaudeEnvironment/CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC (0.00s) |
| + mounts_test.go:94: required Claude environment refused: namespace_mount_rejected |
| +FAIL |
| +rastrillo-budget/v1 ran 7ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.019s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 65: namespace-updater-env |
| + |
| +File: `internal/runner/containment/mounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"DISABLE_AUTOUPDATER": true |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"DISABLE_AUTOUPDATER": false |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run ^TestNamespaceClaudeEnvironment/DISABLE_AUTOUPDATER$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestNamespaceClaudeEnvironment (0.01s) |
| + --- FAIL: TestNamespaceClaudeEnvironment/DISABLE_AUTOUPDATER (0.00s) |
| + mounts_test.go:94: required Claude environment refused: namespace_mount_rejected |
| +FAIL |
| +rastrillo-budget/v1 ran 10ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.019s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 66: namespace-unsupported-env |
| + |
| +File: `internal/runner/containment/mounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +"DISABLE_AUTOUPDATER": true |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +"DISABLE_AUTOUPDATER": true, "CLAUDE_CODE_DISABLE_AUTO_UPDATE":true |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/containment -run ^TestNamespaceClaudeEnvironment$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestNamespaceClaudeEnvironment (0.01s) |
| + mounts_test.go:111: unsupported updater environment accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 12ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/containment 0.020s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 67: cancel-blocked-write |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +context.AfterFunc(ctx, func() { v.cancel(); v.capture.Input.Close() }) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +context.AfterFunc(ctx, func() {}) |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeWriteCancellation$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeWriteCancellation (0.96s) |
| + launcher_test.go:814: cancelled admission left stdin blocked |
| +FAIL |
| +rastrillo-budget/v1 ran 956ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.959s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 68: metadata-fields-only |
| + |
| +File: `internal/runner/provider/accounts.go`. Replace the first matching fragment: |
| + |
| +```go |
| +return json.Marshal(map[string]any{"oauthAccount": selected, "hasCompletedOnboarding": true}) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +return raw,nil |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeNativeIdentityMetadata/staged$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeNativeIdentityMetadata (0.20s) |
| + --- FAIL: TestClaudeNativeIdentityMetadata/staged (0.19s) |
| + launcher_test.go:712: unsafe metadata import: {"hooks":{"evil":true},"oauthAccount":{"accountUuid":"fake-account","emailAddress":"account@example.invalid"},"projects":{"untrusted":"trust"}} |
| +FAIL |
| +rastrillo-budget/v1 ran 195ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.200s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 69: settings-validation |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +if !sameJSON(pair[0], pair[1]) { |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +if false && !sameJSON(pair[0], pair[1]) { |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudePolicyRefusals/settings$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudePolicyRefusals (0.79s) |
| + --- FAIL: TestClaudePolicyRefusals/settings (0.79s) |
| + launcher_test.go:618: unsafe policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 794ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.796s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 70: argv-validation |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace the first matching fragment: |
| + |
| +```go |
| +!reflect.DeepEqual(in.Argv, expected.Argv) || |
| +``` |
| + |
| +with: |
| + |
| +```go |
| + |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudePolicyRefusals/argv$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudePolicyRefusals (0.79s) |
| + --- FAIL: TestClaudePolicyRefusals/argv (0.79s) |
| + launcher_test.go:618: unsafe policy accepted |
| +FAIL |
| +rastrillo-budget/v1 ran 787ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.790s |
| +FAIL |
| +``` |
| + |
| +### User-facing strings and concerns |
| + |
| +No app UI strings or copy.go entries were added, so there are no new pending copy.go entries. The new internal error codes are `claude_protocol_rejected`, `claude_not_ready`, `claude_turn_uncertain` and `claude_process_failed`. If later shown in the UI, they need individually pending copy.go entries and the release copy pass. The fixture prompts are the three explicitly authorized recording prompts. Test assertions, source comments, the budget rationale and this controller report are the other new prose. |
| + |
| +The remaining concerns are the planned integration boundaries: Task 7 must supply durable capture and any journal-based restart recovery; Task 8 must supply the attested helper and permission relay; Task 11b must certify the deployed tuple and real refresh. Unknown recovered sessions and unsupported managed settings are refused today. The bounded recording is not a production release certificate. |
| + |
| +All mutation sources were restored. Test processes exited or were explicitly killed/reaped by owned cleanup. No recording process, fake CLI, namespace, server or watcher remains. Raw capture and owned scratch were removed after preserving these results. The invocation tally remains exactly two lines. No other worktree, default branch, provider home configuration or unrelated file was changed. |
| + |
| +### Final refresh/config interaction check |
| + |
| +Final diff review found that a simultaneous pending refresh and changed generated config refused input but left the idle attempt running. A new test was written first, then policy/lease errors in that pre-dispatch refresh path were routed through cancellation. BeginTurn errors use the same stop path. This does not manufacture containment proof. |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run '^TestClaudeRefreshWithConfigTamper$' -count=1 |
| +``` |
| + |
| +RED: |
| + |
| +```text |
| +--- FAIL: TestClaudeRefreshWithConfigTamper (0.68s) |
| + launcher_test.go:834: tampered refresh left the attempt running |
| +FAIL |
| +rastrillo-budget/v1 ran 679ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.687s |
| +FAIL |
| +``` |
| + |
| +#### Mutation 71: refresh-tamper-stop |
| + |
| +File: `internal/runner/provider/claude/launcher.go`. Replace: |
| + |
| +```go |
| +return fail(sourceErr) |
| +``` |
| + |
| +with: |
| + |
| +```go |
| +return sourceErr |
| +``` |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run ^TestClaudeRefreshWithConfigTamper$ -count=1 |
| +``` |
| + |
| +Exit 1, compiled named failure: |
| + |
| +```text |
| +--- FAIL: TestClaudeRefreshWithConfigTamper (0.68s) |
| + launcher_test.go:834: tampered refresh left the attempt running |
| +FAIL |
| +rastrillo-budget/v1 ran 683ms |
| +FAIL amadan.net/oficina/equipo/internal/runner/provider/claude 0.685s |
| +FAIL |
| +``` |
| + |
| +Final GREEN after restoring all 71 mutations and the final fix: |
| + |
| +```sh |
| +CGO_ENABLED=0 go test ./internal/runner/provider/claude -run '^TestClaude' -count=1 |
| +``` |
| + |
| +```text |
| +ok amadan.net/oficina/equipo/internal/runner/provider/claude 32.229s |
| +``` |
| + |
| +The earlier related account/containment regression results remain applicable; this final change is confined to the adapter's error cleanup. Formatting and git diff checks passed again. |
diff --git a/internal/runner/containment/mounts.go b/internal/runner/containment/mounts.go| index 489421de..f784b6de 100644 |
| --- a/internal/runner/containment/mounts.go |
| +++ b/internal/runner/containment/mounts.go |
| @@ -161,7 +161,7 @@ func (m *Manager) mountPlan(l provider.Launch, dir string) (_ *mounts, err error |
| targets[target] = true |
| } |
| p.args = append(p.args, "--clearenv", "--setenv", "PATH", "/usr/bin:/bin:/opt", "--setenv", "HOME", "/home/runner", "--setenv", "TMPDIR", "/tmp", "--setenv", "LANG", "C.UTF-8") |
| - allowed := map[string]bool{"LANG": true, "LC_ALL": true, "TERM": true, "CODEX_HOME": true, "CLAUDE_CONFIG_DIR": true, "CLAUDE_SECURESTORAGE_CONFIG_DIR": true, "CLAUDE_TMPDIR": true, "CLAUDE_CODE_DISABLE_AUTO_UPDATE": true} |
| + allowed := map[string]bool{"LANG": true, "LC_ALL": true, "TERM": true, "CODEX_HOME": true, "CLAUDE_CONFIG_DIR": true, "CLAUDE_SECURESTORAGE_CONFIG_DIR": true, "CLAUDE_TMPDIR": true, "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": true, "DISABLE_AUTOUPDATER": true} |
| keys := make([]string, 0, len(l.Policy.Env)) |
| for k := range l.Policy.Env { |
| keys = append(keys, k) |
diff --git a/internal/runner/containment/mounts_test.go b/internal/runner/containment/mounts_test.go| index d49e4a3e..dff253ae 100644 |
| --- a/internal/runner/containment/mounts_test.go |
| +++ b/internal/runner/containment/mounts_test.go |
| @@ -74,3 +74,40 @@ func TestNamespaceRejectsBroadWorkspace(t *testing.T) { |
| } |
| } |
| } |
| + |
| +func TestNamespaceClaudeEnvironment(t *testing.T) { |
| + m, l := fixture(t) |
| + dir, e := os.MkdirTemp(m.cfg.ScratchRoot, "claude-env-") |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + for _, name := range []string{"tmp", "home"} { |
| + if e = os.Mkdir(filepath.Join(dir, name), 0700); e != nil { |
| + t.Fatal(e) |
| + } |
| + } |
| + for _, key := range []string{"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC", "DISABLE_AUTOUPDATER"} { |
| + t.Run(key, func(t *testing.T) { |
| + l.Policy.Env = map[string]string{key: "1"} |
| + plan, e := m.mountPlan(l, dir) |
| + if e != nil { |
| + t.Fatalf("required Claude environment refused: %v", e) |
| + } |
| + defer plan.close() |
| + found := false |
| + for i, arg := range plan.args { |
| + if arg == "--setenv" && i+2 < len(plan.args) && plan.args[i+1] == key && plan.args[i+2] == "1" { |
| + found = true |
| + } |
| + } |
| + if !found { |
| + t.Fatal("required Claude environment omitted") |
| + } |
| + }) |
| + } |
| + l.Policy.Env = map[string]string{"CLAUDE_CODE_DISABLE_AUTO_UPDATE": "1"} |
| + if plan, e := m.mountPlan(l, dir); e == nil { |
| + plan.close() |
| + t.Fatal("unsupported updater environment accepted") |
| + } |
| +} |
diff --git a/internal/runner/provider/accounts.go b/internal/runner/provider/accounts.go| index 728dbb2e..972b55d0 100644 |
| --- a/internal/runner/provider/accounts.go |
| +++ b/internal/runner/provider/accounts.go |
| @@ -118,6 +118,7 @@ type AccountLease struct { |
| checking bool |
| contained bool |
| runtimeGeneration [32]byte |
| + claudeIdentity []byte |
| } |
| func OpenAccount(ctx context.Context, b Binding) (*AccountLease, error) { |
| @@ -296,7 +297,14 @@ func (l *AccountLease) snapshot() ([]byte, [32]byte, error) { |
| Dev, Ino uint64 |
| Mtime, Ctime unix.Timespec |
| }{uint64(stat.Dev), stat.Ino, stat.Mtim, stat.Ctim}) |
| - digest := sha256.Sum256(bytes.Join([][]byte{metadata, raw, state}, nil)) |
| + var native []byte |
| + if l.source.Provider == "claude" { |
| + native, e = claudeAccountMetadata(l.dir) |
| + if e != nil { |
| + return nil, zero, ErrIdentity |
| + } |
| + } |
| + digest := sha256.Sum256(bytes.Join([][]byte{metadata, raw, state, native}, nil)) |
| return raw, digest, nil |
| } |
| func (l *AccountLease) runtimeDir() (*os.File, error) { |
| @@ -373,6 +381,16 @@ func (l *AccountLease) stage() error { |
| if e = atomicPrivate(dir, IdentityFile, metadata); e != nil { |
| return e |
| } |
| + if l.source.Provider == "claude" { |
| + native, e := claudeAccountMetadata(l.dir) |
| + if e != nil { |
| + return e |
| + } |
| + if e = atomicPrivate(dir, ".claude.json", native); e != nil { |
| + return e |
| + } |
| + l.claudeIdentity = bytes.Clone(native) |
| + } |
| l.runtimeGeneration = sha256.Sum256(raw) |
| return nil |
| } |
| @@ -391,6 +409,12 @@ func (l *AccountLease) runtimeSnapshot() ([]byte, error) { |
| if e != nil || json.Unmarshal(metadata, &id) != nil || id != l.source.Expected { |
| return nil, ErrContainment |
| } |
| + if l.source.Provider == "claude" { |
| + native, e := claudeAccountMetadata(dir) |
| + if e != nil || !bytes.Equal(native, l.claudeIdentity) { |
| + return nil, ErrContainment |
| + } |
| + } |
| raw, e := readPrivate(dir, credentialName(l.source.Provider)) |
| if e != nil { |
| return nil, ErrContainment |
| @@ -542,7 +566,7 @@ func (l *AccountLease) check(ctx context.Context, probe func(context.Context, Bi |
| if probeErr != nil { |
| return probeErr |
| } |
| - if id != l.source.Expected { |
| + if !observedIdentityMatches(l.source, id) { |
| l.contained = true |
| return ErrIdentity |
| } |
| @@ -686,3 +710,63 @@ func makePrivateRoot(path string) (*os.File, error) { |
| } |
| return dir, nil |
| } |
| + |
| +// AccountLease returns only the lease that created this exact runtime binding. |
| +func (b Binding) AccountLease() (*AccountLease, error) { |
| + if !b.VerifiedDedicatedHome() { |
| + return nil, ErrIdentity |
| + } |
| + return b.provenance, nil |
| +} |
| + |
| +func observedIdentityMatches(b Binding, observed Identity) bool { |
| + if b.Provider == "claude" && observed.HomeID == "" { |
| + return observed.AccountID == b.Expected.AccountID && observed.ProviderVersion == b.Expected.ProviderVersion |
| + } |
| + return observed == b.Expected |
| +} |
| + |
| +// Claude reads account metadata from its native config during auth status. |
| +// Import only identifiers, never user settings, trust entries, hooks or plugins. |
| +func claudeAccountMetadata(dir *os.File) ([]byte, error) { |
| + var stat unix.Stat_t |
| + if e := unix.Fstatat(int(dir.Fd()), ".claude.json", &stat, unix.AT_SYMLINK_NOFOLLOW); e == unix.ENOENT { |
| + return []byte(`{}`), nil |
| + } else if e != nil { |
| + return nil, ErrIdentity |
| + } |
| + raw, e := readPrivate(dir, ".claude.json") |
| + if e != nil { |
| + return nil, e |
| + } |
| + raw, e = canonical(raw) |
| + if e != nil { |
| + return nil, e |
| + } |
| + var config map[string]json.RawMessage |
| + if json.Unmarshal(raw, &config) != nil { |
| + return nil, ErrIdentity |
| + } |
| + account, ok := config["oauthAccount"] |
| + if !ok { |
| + return []byte(`{}`), nil |
| + } |
| + var fields map[string]json.RawMessage |
| + if json.Unmarshal(account, &fields) != nil || fields == nil { |
| + return nil, ErrIdentity |
| + } |
| + selected := map[string]string{} |
| + for _, key := range []string{"emailAddress", "accountUuid", "organizationUuid"} { |
| + if raw, ok := fields[key]; ok { |
| + var v string |
| + if json.Unmarshal(raw, &v) != nil { |
| + return nil, ErrIdentity |
| + } |
| + selected[key] = v |
| + } |
| + } |
| + if selected["emailAddress"] == "" { |
| + return nil, ErrIdentity |
| + } |
| + return json.Marshal(map[string]any{"oauthAccount": selected, "hasCompletedOnboarding": true}) |
| +} |
diff --git a/internal/runner/provider/claude/budget_test.go b/internal/runner/provider/claude/budget_test.go| new file mode 100644 |
| index 00000000..fce9d652 |
| --- /dev/null |
| +++ b/internal/runner/provider/claude/budget_test.go |
| @@ -0,0 +1,9 @@ |
| +package claude |
| + |
| +import ( |
| + "amadan.net/rastrillo/rastrillo/budget" |
| + "os" |
| + "testing" |
| +) |
| + |
| +func TestMain(m *testing.M) { os.Exit(budget.Main(m)) } |
diff --git a/internal/runner/provider/claude/events.go b/internal/runner/provider/claude/events.go| new file mode 100644 |
| index 00000000..99407403 |
| --- /dev/null |
| +++ b/internal/runner/provider/claude/events.go |
| @@ -0,0 +1,118 @@ |
| +package claude |
| + |
| +import ( |
| + "bytes" |
| + "encoding/json" |
| + "io" |
| + |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| +) |
| + |
| +const MaxFrameBytes = 1024 * 1024 |
| +const errProtocol provider.Error = "claude_protocol_rejected" |
| + |
| +func Decode(raw []byte) ([]provider.Event, error) { |
| + if len(raw) == 0 || len(raw) > MaxFrameBytes || !uniqueJSON(raw) { |
| + return nil, errProtocol |
| + } |
| + var v struct { |
| + Type string `json:"type"` |
| + Subtype string `json:"subtype"` |
| + Session string `json:"session_id"` |
| + Request string `json:"request_id"` |
| + IsError *bool `json:"is_error"` |
| + } |
| + if json.Unmarshal(raw, &v) != nil || v.Type == "" || v.Session == "" { |
| + return nil, errProtocol |
| + } |
| + kind := v.Type |
| + switch v.Type { |
| + case "system": |
| + if v.Subtype == "init" { |
| + kind = "session.init" |
| + } |
| + case "assistant": |
| + kind = "message" |
| + case "result": |
| + if v.IsError == nil || v.Subtype == "" { |
| + return nil, errProtocol |
| + } |
| + kind = "turn.failed" |
| + if !*v.IsError && v.Subtype == "success" { |
| + kind = "turn.completed" |
| + } |
| + } |
| + return []provider.Event{{SessionID: v.Session, RequestID: v.Request, Kind: kind, Payload: bytes.Clone(raw)}}, nil |
| +} |
| + |
| +func uniqueJSON(raw []byte) bool { |
| + d := json.NewDecoder(bytes.NewReader(raw)) |
| + d.UseNumber() |
| + var value func() bool |
| + value = func() bool { |
| + token, e := d.Token() |
| + if e != nil { |
| + return false |
| + } |
| + delim, ok := token.(json.Delim) |
| + if !ok { |
| + return true |
| + } |
| + switch delim { |
| + case '{': |
| + seen := map[string]bool{} |
| + for d.More() { |
| + k, e := d.Token() |
| + if e != nil { |
| + return false |
| + } |
| + s, ok := k.(string) |
| + if !ok || seen[s] { |
| + return false |
| + } |
| + seen[s] = true |
| + if !value() { |
| + return false |
| + } |
| + } |
| + end, e := d.Token() |
| + return e == nil && end == json.Delim('}') |
| + case '[': |
| + for d.More() { |
| + if !value() { |
| + return false |
| + } |
| + } |
| + end, e := d.Token() |
| + return e == nil && end == json.Delim(']') |
| + } |
| + return false |
| + } |
| + if !value() { |
| + return false |
| + } |
| + _, e := d.Token() |
| + return e == io.EOF |
| +} |
| + |
| +func userEnvelope(session, prompt string) ([]byte, error) { |
| + if session == "" || prompt == "" { |
| + return nil, errProtocol |
| + } |
| + raw, e := json.Marshal(struct { |
| + Type string `json:"type"` |
| + Message struct { |
| + Role string `json:"role"` |
| + Content string `json:"content"` |
| + } `json:"message"` |
| + Session string `json:"session_id"` |
| + Parent *string `json:"parent_tool_use_id"` |
| + }{Type: "user", Message: struct { |
| + Role string `json:"role"` |
| + Content string `json:"content"` |
| + }{"user", prompt}, Session: session}) |
| + if e != nil || len(raw) > MaxFrameBytes { |
| + return nil, errProtocol |
| + } |
| + return append(raw, '\n'), nil |
| +} |
diff --git a/internal/runner/provider/claude/events_test.go b/internal/runner/provider/claude/events_test.go| new file mode 100644 |
| index 00000000..f112bafd |
| --- /dev/null |
| +++ b/internal/runner/provider/claude/events_test.go |
| @@ -0,0 +1,110 @@ |
| +package claude |
| + |
| +import ( |
| + "bufio" |
| + "encoding/json" |
| + "os" |
| + "strings" |
| + "testing" |
| +) |
| + |
| +func TestClaudeStreamEvents(t *testing.T) { |
| + for _, name := range []string{"stdout.jsonl", "resume-stdout.jsonl"} { |
| + t.Run(name, func(t *testing.T) { |
| + f, e := os.Open("testdata/" + name) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + defer f.Close() |
| + scan := bufio.NewScanner(f) |
| + var usages []int |
| + for scan.Scan() { |
| + events, e := Decode(scan.Bytes()) |
| + if e != nil || len(events) != 1 { |
| + t.Fatalf("decode: %v %v", events, e) |
| + } |
| + ev := events[0] |
| + if ev.SessionID != "00000000-0000-4000-8000-000000000001" { |
| + t.Fatal("session identity lost") |
| + } |
| + var raw map[string]any |
| + json.Unmarshal(ev.Payload, &raw) |
| + if raw["type"] == "result" { |
| + if ev.Kind != "turn.completed" { |
| + t.Fatalf("terminal kind %s", ev.Kind) |
| + } |
| + usage, ok := raw["usage"].(map[string]any) |
| + if !ok { |
| + t.Fatal("per-turn usage lost") |
| + } |
| + usages = append(usages, int(usage["cache_creation_input_tokens"].(float64))) |
| + } |
| + if raw["type"] == "assistant" && (ev.RequestID == "" || !strings.Contains(string(ev.Payload), "msg_sanitized")) { |
| + t.Fatal("request/message identity lost") |
| + } |
| + } |
| + if scan.Err() != nil { |
| + t.Fatal(scan.Err()) |
| + } |
| + want := "[3906 378]" |
| + if name == "resume-stdout.jsonl" { |
| + want = "[63]" |
| + } |
| + b, _ := json.Marshal(usages) |
| + if (want == "[3906 378]" && string(b) != "[3906,378]") || (want == "[63]" && string(b) != "[63]") { |
| + t.Fatalf("per-turn usage %s", b) |
| + } |
| + }) |
| + } |
| + t.Run("error_flag", func(t *testing.T) { |
| + es, e := Decode([]byte(`{"type":"result","subtype":"success","is_error":true,"session_id":"s","result":"rate limited","usage":{}}`)) |
| + if e != nil || len(es) != 1 || es[0].Kind != "turn.failed" { |
| + t.Fatalf("error treated as success %v %v", es, e) |
| + } |
| + }) |
| + t.Run("tool_ids", func(t *testing.T) { |
| + raw := `{"type":"assistant","session_id":"s","request_id":"r","message":{"id":"m","content":[{"type":"tool_use","id":"tool-1","name":"Read","input":{}}]},"parent_tool_use_id":"parent"}` |
| + es, e := Decode([]byte(raw)) |
| + if e != nil || es[0].RequestID != "r" || string(es[0].Payload) != raw { |
| + t.Fatal("tool correlation lost") |
| + } |
| + }) |
| + for _, raw := range []string{"not JSON stderr", `{"type":`, `{"type":"assistant","session_id":"s","text":"` + strings.Repeat("x", MaxFrameBytes) + `"}`, `{"type":"result","subtype":"success","session_id":"s"}`, `{"type":"assistant","session_id":"a","session_id":"b"}`, `{"type":"assistant"}`} { |
| + if _, e := Decode([]byte(raw)); e == nil { |
| + t.Fatalf("invalid frame accepted: %.80s", raw) |
| + } |
| + } |
| +} |
| + |
| +func TestClaudeInputEnvelope(t *testing.T) { |
| + if _, e := userEnvelope("s", strings.Repeat("x", MaxFrameBytes)); e == nil { |
| + t.Fatal("oversized input accepted") |
| + } |
| + for _, name := range []string{"stdin.jsonl", "resume-stdin.jsonl"} { |
| + raw, e := os.ReadFile("testdata/" + name) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + for _, line := range strings.Split(strings.TrimSpace(string(raw)), "\n") { |
| + var v struct { |
| + Session string `json:"session_id"` |
| + Message struct { |
| + Content string `json:"content"` |
| + } `json:"message"` |
| + } |
| + json.Unmarshal([]byte(line), &v) |
| + got, e := userEnvelope(v.Session, v.Message.Content) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + var a, b any |
| + json.Unmarshal(got, &a) |
| + json.Unmarshal([]byte(line), &b) |
| + ga, _ := json.Marshal(a) |
| + gb, _ := json.Marshal(b) |
| + if string(ga) != string(gb) { |
| + t.Fatalf("envelope differs %s %s", ga, gb) |
| + } |
| + } |
| + } |
| +} |
diff --git a/internal/runner/provider/claude/launcher.go b/internal/runner/provider/claude/launcher.go| new file mode 100644 |
| index 00000000..2c76a6e9 |
| --- /dev/null |
| +++ b/internal/runner/provider/claude/launcher.go |
| @@ -0,0 +1,766 @@ |
| +package claude |
| + |
| +import ( |
| + "bytes" |
| + "context" |
| + "crypto/rand" |
| + "encoding/json" |
| + "errors" |
| + "fmt" |
| + "path/filepath" |
| + "reflect" |
| + "sort" |
| + "strings" |
| + "sync" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| +) |
| + |
| +const Version = "2.1.312" |
| +const ExecutableSHA256 = "4f4178ce41d83e23341ebfbaecdbcf8ea6bf7baea0690025abe49eeec3a5d01d" |
| +const errNotReady provider.Error = "claude_not_ready" |
| +const errUncertain provider.Error = "claude_turn_uncertain" |
| +const errFailed provider.Error = "claude_process_failed" |
| +const helper = "/opt/equipo-tool-proxy" |
| + |
| +var _ provider.Launcher = (*Launcher)(nil) |
| + |
| +type Launcher struct { |
| + host provider.ProcessHost |
| + captures provider.CaptureFactory |
| + digest string |
| + mu sync.Mutex |
| + sessions map[string]*sessionState |
| +} |
| +type sessionState struct { |
| + session provider.Session |
| + launch provider.Launch |
| + base provider.Policy |
| + lease *provider.AccountLease |
| + process provider.Process |
| + capture *provider.Capture |
| + ctx context.Context |
| + cancel context.CancelFunc |
| + events chan provider.Event |
| + done chan struct{} |
| + attached, active, finished, closed, clean bool |
| + turn provider.Turn |
| + used map[string]bool |
| + err error |
| +} |
| + |
| +type manifest struct { |
| + CredentialHome string |
| + Argv []string |
| + Files []struct { |
| + Mount provider.Mount |
| + SHA256 string |
| + } |
| + Instructions []struct { |
| + Mount provider.Mount |
| + SHA256 string |
| + } |
| + DeniedPaths, EgressHosts, Tools []string |
| + ProviderVersion, LauncherVersion, BwrapVersion, Workspace, Scratch string |
| + Settings, MCP, ThreadPolicy, TurnPolicy json.RawMessage |
| + Env map[string]string |
| +} |
| +type threadPolicy struct { |
| + Specialist string `json:"specialist"` |
| + Model string `json:"model"` |
| + Start string `json:"start"` |
| + Resume string `json:"resume"` |
| +} |
| + |
| +func New(host provider.ProcessHost, captures provider.CaptureFactory) (*Launcher, error) { |
| + if missing(host) || missing(captures) { |
| + return nil, errNotReady |
| + } |
| + return &Launcher{host: host, captures: captures, digest: ExecutableSHA256, sessions: map[string]*sessionState{}}, nil |
| +} |
| +func missing(v any) bool { |
| + if v == nil { |
| + return true |
| + } |
| + r := reflect.ValueOf(v) |
| + switch r.Kind() { |
| + case reflect.Chan, reflect.Func, reflect.Interface, reflect.Map, reflect.Pointer, reflect.Slice: |
| + return r.IsNil() |
| + } |
| + return false |
| +} |
| +func baseArgs(model, tools string) []string { |
| + return []string{"/opt/claude", "-p", "--verbose", "--input-format", "stream-json", "--output-format", "stream-json", "--model", model, "--setting-sources", "", "--disable-slash-commands", "--strict-mcp-config", "--mcp-config", provider.MCPPath, "--settings", provider.SettingsPath, "--permission-mode", "manual", "--permission-prompt-tool", "mcp__equipo__permission", "--tools", tools} |
| +} |
| +func nativeTools(role string) ([]string, error) { |
| + switch role { |
| + case "Engineering": |
| + return []string{"Bash", "Read", "Write", "Edit", "Glob", "Grep"}, nil |
| + case "Review", "Product": |
| + return []string{"Read", "Glob", "Grep", "Bash"}, nil |
| + } |
| + return nil, provider.ErrPolicy |
| +} |
| + |
| +// PolicyInputs renders the provider policy before the runner calls BuildPolicy. |
| +// Tools may contain additional explicitly registered Equipo MCP tool names. |
| +func PolicyInputs(b provider.Binding, in provider.PolicyInputs, specialist, model string) (provider.PolicyInputs, error) { |
| + native, e := nativeTools(specialist) |
| + if e != nil || model == "" || strings.HasPrefix(model, "-") { |
| + return in, provider.ErrPolicy |
| + } |
| + tools := append(append([]string{}, native...), "mcp__equipo__permission") |
| + for _, tool := range in.Tools { |
| + if !strings.HasPrefix(tool, "mcp__equipo__") || strings.ContainsAny(tool, "* ,\t\n") || tool == "mcp__equipo__permission" { |
| + return in, provider.ErrPolicy |
| + } |
| + tools = append(tools, tool) |
| + } |
| + denied := append([]string{}, in.DeniedPaths...) |
| + denied = append(denied, b.CredentialHome, b.Home, b.RuntimeRoot, "/home/runner", "/egress", "/tool", "/tool/equipo.sock", "/config", "/proc", "/dev/fd") |
| + sort.Strings(denied) |
| + denied = compact(denied) |
| + var nativeDenies []string |
| + for _, path := range denied { |
| + if !filepath.IsAbs(path) || filepath.Clean(path) != path || strings.ContainsAny(path, "*?[]()\n\r") { |
| + return in, provider.ErrPolicy |
| + } |
| + for _, tool := range []string{"Read", "Write", "Edit", "Glob", "Grep"} { |
| + nativeDenies = append(nativeDenies, tool+"(/"+path+")", tool+"(/"+path+"/**)") |
| + } |
| + } |
| + settings := map[string]any{ |
| + "disableAllHooks": true, "enabledPlugins": map[string]any{}, |
| + "sandbox": map[string]any{"enabled": true, "failIfUnavailable": true, "allowUnsandboxedCommands": false, "autoAllowBashIfSandboxed": false, "excludedCommands": []string{}, "filesystem": map[string]any{"denyRead": denied, "denyWrite": denied}, "network": map[string]any{"allowUnixSockets": []string{}}}, |
| + "permissions": map[string]any{"deny": nativeDenies}, |
| + } |
| + in.Settings, _ = json.Marshal(settings) |
| + in.MCP = json.RawMessage(`{"mcpServers":{"equipo":{"type":"stdio","command":"/opt/equipo-tool-proxy","args":["--socket","/tool/equipo.sock"]}}}`) |
| + in.ThreadPolicy, _ = json.Marshal(threadPolicy{specialist, model, "session-id", "resume"}) |
| + in.TurnPolicy = json.RawMessage(`{}`) |
| + in.Tools = tools |
| + in.DeniedPaths = denied |
| + in.ProviderVersion = Version |
| + in.Argv = baseArgs(model, strings.Join(native, ",")) |
| + return in, nil |
| +} |
| +func compact(v []string) []string { |
| + out := []string{} |
| + for _, s := range v { |
| + if s != "" && (len(out) == 0 || out[len(out)-1] != s) { |
| + out = append(out, s) |
| + } |
| + } |
| + return out |
| +} |
| +func policyInputs(p provider.Policy) (provider.PolicyInputs, manifest, error) { |
| + var m manifest |
| + if !uniqueJSON(p.Manifest) || json.Unmarshal(p.Manifest, &m) != nil { |
| + return provider.PolicyInputs{}, m, provider.ErrPolicy |
| + } |
| + in := provider.PolicyInputs{Argv: append([]string{}, m.Argv...), DeniedPaths: m.DeniedPaths, EgressHosts: m.EgressHosts, ProviderVersion: m.ProviderVersion, LauncherVersion: m.LauncherVersion, BwrapVersion: m.BwrapVersion, Workspace: m.Workspace, Scratch: m.Scratch, Settings: m.Settings, MCP: m.MCP, ThreadPolicy: m.ThreadPolicy, TurnPolicy: m.TurnPolicy, Tools: m.Tools, Env: map[string]string{}} |
| + for _, automatic := range []string{m.CredentialHome, "/home/runner"} { |
| + for i, path := range in.DeniedPaths { |
| + if path == automatic { |
| + in.DeniedPaths = append(append([]string{}, in.DeniedPaths[:i]...), in.DeniedPaths[i+1:]...) |
| + break |
| + } |
| + } |
| + } |
| + for _, f := range m.Files { |
| + in.RuntimeFiles = append(in.RuntimeFiles, f.Mount) |
| + } |
| + for _, f := range m.Instructions { |
| + in.InstructionFiles = append(in.InstructionFiles, f.Mount) |
| + } |
| + for _, key := range []string{"LANG", "LC_ALL", "TERM"} { |
| + if v, ok := m.Env[key]; ok { |
| + in.Env[key] = v |
| + } |
| + } |
| + return in, m, nil |
| +} |
| +func (l *Launcher) validatePolicy(b provider.Binding, p provider.Policy) (provider.PolicyInputs, error) { |
| + in, m, e := policyInputs(p) |
| + if e != nil { |
| + return in, e |
| + } |
| + if b.Provider != "claude" || b.Expected.ProviderVersion != Version || in.ProviderVersion != Version { |
| + return in, provider.ErrVersion |
| + } |
| + if e = p.ValidateSources(b); e != nil { |
| + return in, e |
| + } |
| + var tp threadPolicy |
| + if json.Unmarshal(in.ThreadPolicy, &tp) != nil { |
| + return in, provider.ErrPolicy |
| + } |
| + native, e := nativeTools(tp.Specialist) |
| + if e != nil { |
| + return in, e |
| + } |
| + if len(in.Tools) < len(native)+1 || !reflect.DeepEqual(in.Tools[:len(native)], native) || in.Tools[len(native)] != "mcp__equipo__permission" { |
| + return in, provider.ErrPolicy |
| + } |
| + expectedIn := in |
| + expectedIn.Tools = append([]string{}, in.Tools[len(native)+1:]...) |
| + expected, e := PolicyInputs(b, expectedIn, tp.Specialist, tp.Model) |
| + if e != nil { |
| + return in, e |
| + } |
| + for _, pair := range [][2]json.RawMessage{{in.Settings, expected.Settings}, {in.MCP, expected.MCP}, {in.ThreadPolicy, expected.ThreadPolicy}, {in.TurnPolicy, expected.TurnPolicy}} { |
| + if !sameJSON(pair[0], pair[1]) { |
| + return in, provider.ErrPolicy |
| + } |
| + } |
| + if !reflect.DeepEqual(in.Argv, expected.Argv) || !reflect.DeepEqual(in.Tools, expected.Tools) { |
| + return in, provider.ErrPolicy |
| + } |
| + for _, file := range in.InstructionFiles { |
| + if strings.HasPrefix(file.Target, "/etc/") && file.Target != "/etc/claude-code/CLAUDE.md" { |
| + return in, provider.ErrPolicy |
| + } |
| + } |
| + found := false |
| + helperFound := false |
| + for _, f := range m.Files { |
| + if strings.HasPrefix(f.Mount.Target, "/etc/") { |
| + return in, provider.ErrPolicy |
| + } |
| + if f.Mount.Target == helper { |
| + helperFound = true |
| + } |
| + if f.Mount.Target == "/opt/claude" { |
| + found = f.SHA256 == l.digest |
| + } |
| + } |
| + if !helperFound { |
| + return in, provider.ErrPolicy |
| + } |
| + if !found { |
| + return in, provider.ErrVersion |
| + } |
| + for k, v := range map[string]string{"CLAUDE_CONFIG_DIR": "/home/runner", "CLAUDE_SECURESTORAGE_CONFIG_DIR": "/home/runner", "CLAUDE_TMPDIR": "/tmp", "CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1", "DISABLE_AUTOUPDATER": "1"} { |
| + if p.Env[k] != v { |
| + return in, provider.ErrPolicy |
| + } |
| + } |
| + // Rebuilding validates every manifest input and the lease's generated files. |
| + rebuilt, e := provider.BuildPolicy(b, in) |
| + if e != nil || rebuilt.Hash != p.Hash || rebuilt.ManifestHash != p.ManifestHash { |
| + return in, provider.ErrPolicy |
| + } |
| + return in, nil |
| +} |
| +func sameJSON(a, b []byte) bool { |
| + var x, y any |
| + return json.Unmarshal(a, &x) == nil && json.Unmarshal(b, &y) == nil && reflect.DeepEqual(x, y) |
| +} |
| +func uuid() string { |
| + var b [16]byte |
| + if _, e := rand.Read(b[:]); e != nil { |
| + panic(e) |
| + } |
| + b[6] = (b[6] & 15) | 64 |
| + b[8] = (b[8] & 63) | 128 |
| + return fmt.Sprintf("%x-%x-%x-%x-%x", b[:4], b[4:6], b[6:8], b[8:10], b[10:]) |
| +} |
| + |
| +func (l *Launcher) Preflight(ctx context.Context, b provider.Binding, p provider.Policy) (provider.Identity, error) { |
| + lease, e := b.AccountLease() |
| + if e != nil { |
| + return provider.Identity{}, e |
| + } |
| + in, e := l.validatePolicy(b, p) |
| + if e != nil { |
| + return provider.Identity{}, e |
| + } |
| + return l.preflight(ctx, b, lease, in) |
| +} |
| +func (l *Launcher) preflight(ctx context.Context, b provider.Binding, lease *provider.AccountLease, in provider.PolicyInputs) (provider.Identity, error) { |
| + var e error |
| + var observed provider.Identity |
| + probe := func(ctx context.Context, b provider.Binding) (provider.Identity, error) { |
| + var e error |
| + observed, e = l.probeIdentity(ctx, b, in) |
| + return observed, e |
| + } |
| + if e = lease.Validate(ctx); errors.Is(e, provider.ErrRefreshPending) { |
| + if e = lease.CommitRefresh(ctx, probe); e != nil { |
| + return observed, e |
| + } |
| + } |
| + if e = lease.Preflight(ctx, probe); e != nil { |
| + return observed, e |
| + } |
| + // Closing stdin proves dependency availability without supplying a user turn. |
| + args := append(append([]string{}, in.Argv...), "--session-id", uuid()) |
| + if _, e = l.probe(ctx, b, in, args); e != nil { |
| + return observed, e |
| + } |
| + _, e = provider.BuildPolicy(b, in) |
| + return observed, e |
| +} |
| +func (l *Launcher) probeIdentity(ctx context.Context, b provider.Binding, in provider.PolicyInputs) (provider.Identity, error) { |
| + frames, e := l.probe(ctx, b, in, []string{"/opt/claude", "--setting-sources", "", "--settings", provider.SettingsPath, "--strict-mcp-config", "--mcp-config", provider.MCPPath, "--disable-slash-commands", "auth", "status", "--json"}) |
| + if e != nil { |
| + return provider.Identity{}, e |
| + } |
| + if len(frames) != 1 { |
| + return provider.Identity{}, provider.ErrIdentity |
| + } |
| + var status struct { |
| + LoggedIn bool `json:"loggedIn"` |
| + Method string `json:"authMethod"` |
| + Email string `json:"email"` |
| + } |
| + if !uniqueJSON(frames[0]) || json.Unmarshal(frames[0], &status) != nil || !status.LoggedIn || status.Method != "claude.ai" || status.Email == "" { |
| + return provider.Identity{}, provider.ErrIdentity |
| + } |
| + // HomeID belongs to Equipo and is deliberately absent from CLI observations. |
| + return provider.Identity{AccountID: status.Email, ProviderVersion: Version}, nil |
| +} |
| +func (l *Launcher) probe(ctx context.Context, b provider.Binding, in provider.PolicyInputs, args []string) ([][]byte, error) { |
| + ctx, cancel := context.WithTimeout(ctx, 10*time.Second) |
| + defer cancel() |
| + in.Argv = args |
| + p, e := provider.BuildPolicy(b, in) |
| + if e != nil { |
| + return nil, e |
| + } |
| + launch := provider.Launch{AttemptKey: "claude-preflight-" + uuid(), Workspace: in.Workspace, Binding: b, Policy: p, Selection: provider.Selection{Provider: "claude", AccountID: b.AccountID}} |
| + proc, e := l.host.Start(ctx, launch, args) |
| + if e != nil { |
| + return nil, e |
| + } |
| + defer func() { |
| + cancel() |
| + waitCtx, stop := context.WithTimeout(context.Background(), 5*time.Second) |
| + defer stop() |
| + proc.Wait(waitCtx) |
| + }() |
| + cap, e := l.captures.Open(ctx, proc, launch) |
| + if e != nil { |
| + cancel() |
| + proc.Wait(context.Background()) |
| + return nil, e |
| + } |
| + if cap == nil || cap.Input == nil || cap.Frames == nil || cap.Done == nil { |
| + cancel() |
| + proc.Wait(context.Background()) |
| + return nil, errNotReady |
| + } |
| + if e = cap.Input.Close(); e != nil { |
| + return nil, e |
| + } |
| + var frames [][]byte |
| + total := 0 |
| + for { |
| + select { |
| + case <-ctx.Done(): |
| + return nil, ctx.Err() |
| + case f, ok := <-cap.Frames: |
| + if !ok { |
| + goto drained |
| + } |
| + total += len(f.Bytes) |
| + if total > MaxFrameBytes || !uniqueJSON(f.Bytes) { |
| + return nil, errProtocol |
| + } |
| + frames = append(frames, bytes.Clone(f.Bytes)) |
| + } |
| + } |
| +drained: |
| + select { |
| + case e = <-cap.Done: |
| + if e != nil { |
| + return nil, e |
| + } |
| + case <-ctx.Done(): |
| + return nil, ctx.Err() |
| + } |
| + exit, e := proc.Wait(ctx) |
| + if e != nil || exit.Code != 0 || exit.Signal != 0 { |
| + return nil, errFailed |
| + } |
| + for _, raw := range frames { |
| + var v struct { |
| + Type string `json:"type"` |
| + Error bool `json:"is_error"` |
| + } |
| + json.Unmarshal(raw, &v) |
| + if v.Type == "result" || v.Error { |
| + return nil, errFailed |
| + } |
| + } |
| + return frames, nil |
| +} |
| + |
| +func (l *Launcher) Open(ctx context.Context, launch provider.Launch) (provider.Session, error) { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + if launch.AttemptKey == "" || l.sessions[launch.AttemptKey] != nil { |
| + return provider.Session{}, errNotReady |
| + } |
| + for _, prior := range l.sessions { |
| + if prior.launch.Binding == launch.Binding && !prior.closed { |
| + return provider.Session{}, provider.ErrAccountBusy |
| + } |
| + } |
| + in, e := l.validatePolicy(launch.Binding, launch.Policy) |
| + if e != nil { |
| + return provider.Session{}, e |
| + } |
| + var tp threadPolicy |
| + json.Unmarshal(in.ThreadPolicy, &tp) |
| + if launch.Selection.Model != tp.Model { |
| + return provider.Session{}, provider.ErrIdentity |
| + } |
| + lease, e := launch.Binding.AccountLease() |
| + if e != nil { |
| + return provider.Session{}, e |
| + } |
| + id := uuid() |
| + var previous *sessionState |
| + if launch.ResumeSessionID != "" { |
| + prior := (*sessionState)(nil) |
| + for _, s := range l.sessions { |
| + if s.session.ID == launch.ResumeSessionID && s.closed && s.clean && s.finished && s.err == nil { |
| + prior = s |
| + } |
| + } |
| + if prior == nil || prior.base.Hash != launch.Policy.Hash || prior.launch.Binding != launch.Binding || prior.launch.Selection != launch.Selection { |
| + return provider.Session{}, errUncertain |
| + } |
| + id = launch.ResumeSessionID |
| + previous = prior |
| + } |
| + session := provider.Session{ID: id, AttemptKey: launch.AttemptKey, Provider: launch.Selection.Provider, AccountID: launch.Selection.AccountID, Model: launch.Selection.Model, Family: launch.Selection.Family} |
| + if e = session.Validate(launch); e != nil { |
| + return provider.Session{}, e |
| + } |
| + if _, e = l.preflight(ctx, launch.Binding, lease, in); e != nil { |
| + return provider.Session{}, e |
| + } |
| + if e = lease.ValidatePolicy(ctx); e != nil { |
| + return provider.Session{}, e |
| + } |
| + base := launch.Policy |
| + flag := "--session-id" |
| + if launch.ResumeSessionID != "" { |
| + flag = "--resume" |
| + } |
| + args := append(append([]string{}, in.Argv...), flag, id) |
| + in.Argv = args |
| + launch.Policy, e = provider.BuildPolicy(launch.Binding, in) |
| + if e != nil { |
| + return provider.Session{}, e |
| + } |
| + attempt, cancel := context.WithCancel(ctx) |
| + process, e := l.host.Start(attempt, launch, args) |
| + if e != nil { |
| + cancel() |
| + return provider.Session{}, e |
| + } |
| + capture, e := l.captures.Open(attempt, process, launch) |
| + if e != nil { |
| + cancel() |
| + process.Wait(context.Background()) |
| + return provider.Session{}, e |
| + } |
| + if capture == nil || capture.Input == nil || capture.Frames == nil || capture.Done == nil { |
| + cancel() |
| + process.Wait(context.Background()) |
| + return provider.Session{}, errNotReady |
| + } |
| + s := &sessionState{session: session, launch: launch, base: base, lease: lease, process: process, capture: capture, ctx: attempt, cancel: cancel, events: make(chan provider.Event, 64), done: make(chan struct{}), used: map[string]bool{}} |
| + if previous != nil { |
| + previous.clean = false |
| + for key, value := range previous.used { |
| + s.used[key] = value |
| + } |
| + } |
| + l.sessions[session.AttemptKey] = s |
| + go l.read(s) |
| + return session, nil |
| +} |
| +func (l *Launcher) state(s provider.Session) (*sessionState, error) { |
| + v := l.sessions[s.AttemptKey] |
| + if v == nil || v.session != s { |
| + return nil, provider.ErrIdentity |
| + } |
| + return v, nil |
| +} |
| +func (l *Launcher) Events(ctx context.Context, s provider.Session) (<-chan provider.Event, error) { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + v, e := l.state(s) |
| + if e != nil { |
| + return nil, e |
| + } |
| + if e = ctx.Err(); e != nil { |
| + return nil, e |
| + } |
| + if v.attached { |
| + return nil, errNotReady |
| + } |
| + v.attached = true |
| + return v.events, nil |
| +} |
| +func (l *Launcher) StartTurn(ctx context.Context, s provider.Session, t provider.Turn) error { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + v, e := l.state(s) |
| + if e != nil { |
| + return e |
| + } |
| + if v.closed || v.err != nil || v.active || !v.attached || t.ID == "" || t.AdmissionID == "" || v.used[t.ID] || v.used[t.AdmissionID] { |
| + return errNotReady |
| + } |
| + if e = ctx.Err(); e != nil { |
| + return e |
| + } |
| + if e = v.ctx.Err(); e != nil { |
| + return e |
| + } |
| + fail := func(e error) error { v.err = e; v.cancel(); return e } |
| + if e = v.lease.ValidatePolicy(ctx); errors.Is(e, provider.ErrRefreshPending) || errors.Is(e, provider.ErrPreflightRequired) { |
| + // Rebuild the base policy only after checking the currently mounted sources. |
| + if sourceErr := v.launch.Policy.ValidateSources(v.launch.Binding); sourceErr != nil { |
| + return fail(sourceErr) |
| + } |
| + in, _, inputErr := policyInputs(v.base) |
| + if inputErr != nil { |
| + return fail(inputErr) |
| + } |
| + base, buildErr := provider.BuildPolicy(v.launch.Binding, in) |
| + if buildErr != nil { |
| + return fail(buildErr) |
| + } |
| + if _, e = l.Preflight(ctx, v.launch.Binding, base); e == nil { |
| + actual, _, inputErr := policyInputs(v.launch.Policy) |
| + if inputErr != nil { |
| + return fail(inputErr) |
| + } |
| + _, e = provider.BuildPolicy(v.launch.Binding, actual) |
| + } |
| + } |
| + if e != nil { |
| + return fail(e) |
| + } |
| + if _, e = provider.AttestLaunch(v.launch, argv(v.launch.Policy)); e != nil { |
| + return fail(e) |
| + } |
| + raw, e := userEnvelope(s.ID, t.Prompt) |
| + if e != nil { |
| + return e |
| + } |
| + if e = v.lease.BeginTurn(ctx); e != nil { |
| + return fail(e) |
| + } |
| + v.active = true |
| + v.finished = false |
| + v.turn = t |
| + v.used[t.ID] = true |
| + v.used[t.AdmissionID] = true |
| + l.mu.Unlock() |
| + stopWrite := context.AfterFunc(ctx, func() { v.cancel(); v.capture.Input.Close() }) |
| + n, e := v.capture.Input.Write(raw) |
| + stopWrite() |
| + l.mu.Lock() |
| + if e != nil || n != len(raw) || ctx.Err() != nil || v.ctx.Err() != nil { |
| + v.err = errUncertain |
| + v.cancel() |
| + return errUncertain |
| + } |
| + return nil |
| +} |
| +func argv(p provider.Policy) []string { var m manifest; json.Unmarshal(p.Manifest, &m); return m.Argv } |
| +func (l *Launcher) Respond(context.Context, provider.Session, provider.Answer) error { |
| + return errNotReady |
| +} |
| +func (l *Launcher) Interrupt(ctx context.Context, s provider.Session) error { |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + v, e := l.state(s) |
| + if e != nil { |
| + return e |
| + } |
| + v.err = errUncertain |
| + v.cancel() |
| + return nil |
| +} |
| +func (l *Launcher) Close(ctx context.Context, s provider.Session) error { |
| + ctx, stop := context.WithTimeout(ctx, 5*time.Second) |
| + defer stop() |
| + l.mu.Lock() |
| + v, e := l.state(s) |
| + if e != nil { |
| + l.mu.Unlock() |
| + return e |
| + } |
| + if !v.closed { |
| + v.closed = true |
| + if v.active { |
| + v.err = errUncertain |
| + v.cancel() |
| + } |
| + v.capture.Input.Close() |
| + } |
| + l.mu.Unlock() |
| + select { |
| + case <-ctx.Done(): |
| + v.cancel() |
| + return ctx.Err() |
| + case <-v.done: |
| + } |
| + v.cancel() |
| + l.mu.Lock() |
| + defer l.mu.Unlock() |
| + return v.err |
| +} |
| +func (l *Launcher) read(s *sessionState) { |
| + defer close(s.done) |
| + defer close(s.events) |
| + var sequence int64 |
| + reportedFailure := false |
| + for { |
| + select { |
| + case <-s.ctx.Done(): |
| + goto finished |
| + case frame, ok := <-s.capture.Frames: |
| + if !ok { |
| + goto finished |
| + } |
| + l.mu.Lock() |
| + var events []provider.Event |
| + var e error |
| + if frame.Sequence <= sequence { |
| + e = errProtocol |
| + } else { |
| + events, e = Decode(frame.Bytes) |
| + } |
| + sequence = frame.Sequence |
| + if e == nil { |
| + for i := range events { |
| + ev := &events[i] |
| + if ev.SessionID != s.session.ID { |
| + e = provider.ErrIdentity |
| + break |
| + } |
| + if !s.active && ev.Kind != "session.init" { |
| + e = errProtocol |
| + break |
| + } |
| + ev.TurnID = s.turn.ID |
| + if ev.Kind == "session.init" { |
| + e = l.validateInit(s, ev.Payload) |
| + if e != nil { |
| + break |
| + } |
| + } |
| + if ev.Kind == "turn.completed" || ev.Kind == "turn.failed" { |
| + endErr := s.lease.EndTurn(context.Background()) |
| + s.active = false |
| + if endErr != nil && !errors.Is(endErr, provider.ErrRefreshPending) { |
| + e = endErr |
| + break |
| + } |
| + s.finished = ev.Kind == "turn.completed" |
| + if !s.finished { |
| + reportedFailure = true |
| + s.err = errFailed |
| + } |
| + } |
| + } |
| + } |
| + if e != nil { |
| + reportedFailure = true |
| + s.err = e |
| + s.cancel() |
| + events = []provider.Event{{SessionID: s.session.ID, TurnID: s.turn.ID, Kind: "turn.failed"}} |
| + } |
| + l.mu.Unlock() |
| + for _, ev := range events { |
| + if e != nil { |
| + select { |
| + case s.events <- ev: |
| + default: |
| + } |
| + continue |
| + } |
| + select { |
| + case s.events <- ev: |
| + case <-s.ctx.Done(): |
| + if e == nil { |
| + goto finished |
| + } |
| + } |
| + } |
| + if e != nil { |
| + goto finished |
| + } |
| + } |
| + } |
| +finished: |
| + var captureErr error |
| + select { |
| + case captureErr = <-s.capture.Done: |
| + case <-s.ctx.Done(): |
| + captureErr = s.ctx.Err() |
| + } |
| + waitCtx, cancel := context.WithTimeout(context.Background(), 5*time.Second) |
| + defer cancel() |
| + exit, waitErr := s.process.Wait(waitCtx) |
| + l.mu.Lock() |
| + if s.active { |
| + s.lease.EndTurn(context.Background()) |
| + s.active = false |
| + s.err = errUncertain |
| + } |
| + if captureErr != nil || waitErr != nil || exit.Code != 0 || exit.Signal != 0 { |
| + if s.err == nil { |
| + s.err = errFailed |
| + } |
| + } |
| + s.clean = s.closed && s.err == nil && s.finished |
| + failed := s.err != nil && !reportedFailure |
| + l.mu.Unlock() |
| + if failed { |
| + select { |
| + case s.events <- provider.Event{SessionID: s.session.ID, TurnID: s.turn.ID, Kind: "turn.failed"}: |
| + default: |
| + } |
| + } |
| + s.cancel() |
| +} |
| +func (l *Launcher) validateInit(s *sessionState, raw []byte) error { |
| + var v struct { |
| + Version string `json:"claude_code_version"` |
| + Model string `json:"model"` |
| + Permission string `json:"permissionMode"` |
| + Tools []string `json:"tools"` |
| + Skills []string `json:"skills"` |
| + Plugins []struct{ Name, Path, Source string } `json:"plugins"` |
| + Servers []struct{ Name, Status string } `json:"mcp_servers"` |
| + } |
| + if json.Unmarshal(raw, &v) != nil || v.Version != Version || v.Model != s.session.Model || v.Permission != "manual" || len(v.Skills) != 0 { |
| + return provider.ErrPolicy |
| + } |
| + // These two plugins are bundled into the pinned executable, not loaded homes. |
| + for _, p := range v.Plugins { |
| + if p.Path != "builtin" || (p.Name != "cc-plugin-agents-md" && p.Name != "cc-plugin-plugin-authoring") || p.Source != p.Name+"@builtin" { |
| + return provider.ErrPolicy |
| + } |
| + } |
| + var m manifest |
| + json.Unmarshal(s.launch.Policy.Manifest, &m) |
| + want := append([]string{}, m.Tools...) |
| + sort.Strings(want) |
| + sort.Strings(v.Tools) |
| + if !reflect.DeepEqual(want, v.Tools) || len(v.Servers) != 1 || v.Servers[0].Name != "equipo" || v.Servers[0].Status != "connected" { |
| + return provider.ErrPolicy |
| + } |
| + return nil |
| +} |
diff --git a/internal/runner/provider/claude/launcher_test.go b/internal/runner/provider/claude/launcher_test.go| new file mode 100644 |
| index 00000000..aa3c5d88 |
| --- /dev/null |
| +++ b/internal/runner/provider/claude/launcher_test.go |
| @@ -0,0 +1,836 @@ |
| +package claude |
| + |
| +import ( |
| + "bufio" |
| + "bytes" |
| + "context" |
| + "crypto/sha256" |
| + "encoding/hex" |
| + "encoding/json" |
| + "errors" |
| + "io" |
| + "os" |
| + "os/exec" |
| + "path/filepath" |
| + "reflect" |
| + "strings" |
| + "sync" |
| + "testing" |
| + "time" |
| + |
| + "amadan.net/oficina/equipo/internal/runner/provider" |
| +) |
| + |
| +const fakeCLI = `import sys,json,os |
| +args=sys.argv[1:] |
| +with open(os.path.join(os.environ['CLAUDE_CONFIG_DIR'],'settings.json'),'w') as config: config.write('{"trust":"fake-cli-write"}') |
| +if 'auth' in args: |
| + try: |
| + with open(os.path.join(os.environ['CLAUDE_CONFIG_DIR'],'.claude.json')) as f: email=json.load(f).get('oauthAccount',{}).get('emailAddress') |
| + except FileNotFoundError: email=None |
| + if os.environ['FAKE_ACCOUNT']!='account@example.invalid': email=os.environ['FAKE_ACCOUNT'] |
| + print(json.dumps({'loggedIn':True,'authMethod':'claude.ai','email':email})) |
| + sys.exit(0) |
| +if os.environ['FAKE_MODE']=='sandbox': |
| + print('Sandbox required but unavailable',file=sys.stderr) |
| + print(json.dumps({'type':'result','session_id':'dependency','subtype':'error_during_execution','is_error':True})) |
| + sys.exit(1) |
| +sid=args[args.index('--resume')+1] if '--resume' in args else args[args.index('--session-id')+1] |
| +idx=0 |
| +for line in sys.stdin: |
| + v=json.loads(line) |
| + if v['type']!='user': sys.exit(2) |
| + init={'type':'system','subtype':'init','session_id':sid,'claude_code_version':'2.1.312','model':args[args.index('--model')+1],'permissionMode':'manual','tools':args[args.index('--tools')+1].split(',')+['mcp__equipo__permission'],'mcp_servers':[{'name':'equipo','status':'connected'}],'skills':[],'plugins':[]} |
| + if os.environ['FAKE_MODE']=='identity': init['session_id']='different' |
| + if os.environ['FAKE_MODE']=='tools': init['tools'].append('WebFetch') |
| + if os.environ['FAKE_MODE']=='plugins': init['plugins']=[{'name':'extra','path':'/untrusted','source':'extra'}] |
| + if os.environ['FAKE_MODE']=='skills': init['skills']=['extra'] |
| + if os.environ['FAKE_MODE']=='permission': init['permissionMode']='bypassPermissions' |
| + if os.environ['FAKE_MODE']=='version': init['claude_code_version']='different' |
| + if os.environ['FAKE_MODE']=='model': init['model']='fallback' |
| + if os.environ['FAKE_MODE']=='mcp': init['mcp_servers'].append({'name':'extra','status':'connected'}) |
| + print(json.dumps(init),flush=True) |
| + if os.environ['FAKE_MODE']=='hang': continue |
| + if os.environ['FAKE_MODE']=='missing': sys.exit(0) |
| + if os.environ['FAKE_MODE']=='partial': |
| + print('{broken',flush=True) |
| + sys.exit(0) |
| + if os.environ['FAKE_MODE']=='oversized': |
| + print('x'*1048577,flush=True) |
| + sys.exit(0) |
| + print(json.dumps({'type':'result','subtype':'success','is_error':os.environ['FAKE_MODE']=='rate','session_id':sid,'result':'ok','usage':{'input_tokens':idx+2,'output_tokens':3},'result_index':idx}),flush=True) |
| + idx+=1 |
| +print('non JSON diagnostic',file=sys.stderr) |
| +sys.exit(7 if os.environ['FAKE_MODE']=='exit' and idx else 0) |
| +` |
| + |
| +type fakeProcess struct { |
| + cmd *exec.Cmd |
| + in io.WriteCloser |
| + out, err io.ReadCloser |
| + done chan struct{} |
| + exit provider.Exit |
| + waitErr error |
| +} |
| + |
| +func (p *fakeProcess) ID() string { return "fake" } |
| +func (p *fakeProcess) Stdin() io.WriteCloser { return p.in } |
| +func (p *fakeProcess) Stdout() io.ReadCloser { return p.out } |
| +func (p *fakeProcess) Stderr() io.ReadCloser { return p.err } |
| +func (p *fakeProcess) Wait(ctx context.Context) (provider.Exit, error) { |
| + select { |
| + case <-ctx.Done(): |
| + return provider.Exit{}, ctx.Err() |
| + case <-p.done: |
| + return p.exit, p.waitErr |
| + } |
| +} |
| + |
| +type fakeHost struct { |
| + processes []*fakeProcess |
| + mu sync.Mutex |
| + launches []provider.Launch |
| + argv [][]string |
| + mode, account, binary string |
| +} |
| + |
| +func (h *fakeHost) Start(ctx context.Context, l provider.Launch, args []string) (provider.Process, error) { |
| + if _, e := provider.AttestLaunch(l, args); e != nil { |
| + return nil, e |
| + } |
| + h.mu.Lock() |
| + h.launches = append(h.launches, l) |
| + h.argv = append(h.argv, append([]string(nil), args...)) |
| + mode, account := h.mode, h.account |
| + h.mu.Unlock() |
| + cmd := exec.CommandContext(ctx, "/usr/bin/python3", append([]string{h.binary}, args[1:]...)...) |
| + cmd.Dir = l.Workspace |
| + cmd.Env = []string{"PATH=/usr/bin:/bin", "HOME=" + l.Binding.Home, "FAKE_MODE=" + mode, "FAKE_ACCOUNT=" + account} |
| + for k, v := range l.Policy.Env { |
| + if k == "CLAUDE_CONFIG_DIR" || k == "CLAUDE_SECURESTORAGE_CONFIG_DIR" { |
| + v = l.Binding.Home |
| + } |
| + cmd.Env = append(cmd.Env, k+"="+v) |
| + } |
| + in, _ := cmd.StdinPipe() |
| + out, outWrite, _ := os.Pipe() |
| + errout, errWrite, _ := os.Pipe() |
| + cmd.Stdout = outWrite |
| + cmd.Stderr = errWrite |
| + if e := cmd.Start(); e != nil { |
| + return nil, e |
| + } |
| + p := &fakeProcess{cmd: cmd, in: in, out: out, err: errout, done: make(chan struct{})} |
| + h.mu.Lock() |
| + h.processes = append(h.processes, p) |
| + h.mu.Unlock() |
| + go func() { |
| + e := cmd.Wait() |
| + outWrite.Close() |
| + errWrite.Close() |
| + p.exit = provider.Exit{Code: cmd.ProcessState.ExitCode(), ObservedAt: time.Now()} |
| + if e != nil { |
| + var x *exec.ExitError |
| + if !errors.As(e, &x) { |
| + p.waitErr = e |
| + } |
| + } |
| + close(p.done) |
| + }() |
| + return p, nil |
| +} |
| + |
| +type captureFactory struct { |
| + block bool |
| + blocker *blockedInput |
| + malformed, zeroSequence bool |
| + opens int |
| + mu sync.Mutex |
| + inputs int |
| + fail bool |
| +} |
| +type recordedInput struct { |
| + io.WriteCloser |
| + owner *captureFactory |
| +} |
| + |
| +func (w recordedInput) Write(b []byte) (int, error) { |
| + w.owner.mu.Lock() |
| + w.owner.inputs++ |
| + w.owner.mu.Unlock() |
| + return w.WriteCloser.Write(b) |
| +} |
| +func (f *captureFactory) Open(ctx context.Context, p provider.Process, l provider.Launch) (*provider.Capture, error) { |
| + f.mu.Lock() |
| + f.opens++ |
| + nth := f.opens |
| + f.mu.Unlock() |
| + if f.fail { |
| + return nil, errors.New("capture failed") |
| + } |
| + if f.malformed && nth == 3 { |
| + return &provider.Capture{Input: p.Stdin()}, nil |
| + } |
| + frames := make(chan provider.Frame) |
| + done := make(chan error, 1) |
| + go func() { |
| + defer p.Stdout().Close() |
| + defer p.Stderr().Close() |
| + stderrDone := make(chan struct{}) |
| + go func() { io.Copy(io.Discard, p.Stderr()); close(stderrDone) }() |
| + scan := bufio.NewScanner(p.Stdout()) |
| + scan.Buffer(make([]byte, 4096), MaxFrameBytes+1) |
| + var seq int64 |
| + for scan.Scan() { |
| + seq++ |
| + if f.zeroSequence { |
| + seq = 0 |
| + } |
| + b := bytes.Clone(scan.Bytes()) |
| + select { |
| + case frames <- provider.Frame{Sequence: seq, Bytes: b}: |
| + case <-ctx.Done(): |
| + close(frames) |
| + done <- ctx.Err() |
| + return |
| + } |
| + } |
| + close(frames) |
| + <-stderrDone |
| + done <- scan.Err() |
| + close(done) |
| + }() |
| + var input io.WriteCloser = recordedInput{p.Stdin(), f} |
| + if f.block && nth == 3 { |
| + f.blocker = &blockedInput{underlying: input, started: make(chan struct{}), done: make(chan struct{})} |
| + input = f.blocker |
| + } |
| + return &provider.Capture{Input: input, Frames: frames, Done: done}, nil |
| +} |
| + |
| +type fixture struct { |
| + l *Launcher |
| + host *fakeHost |
| + capture *captureFactory |
| + lease *provider.AccountLease |
| + launch provider.Launch |
| + inputs provider.PolicyInputs |
| + interactive string |
| +} |
| + |
| +func fixtureFor(t *testing.T, role string) *fixture { |
| + t.Helper() |
| + root := t.TempDir() |
| + source := filepath.Join(root, "dedicated") |
| + os.Mkdir(source, 0700) |
| + id := provider.Identity{AccountID: "account@example.invalid", HomeID: "equipo-home", ProviderVersion: Version} |
| + b := provider.Binding{ID: "binding", Home: source, AccountID: id.AccountID, Provider: "claude", Expected: id, RuntimeRoot: filepath.Join(root, "homes")} |
| + raw, _ := json.Marshal(id) |
| + os.WriteFile(filepath.Join(source, provider.IdentityFile), raw, 0600) |
| + os.WriteFile(filepath.Join(source, ".credentials.json"), []byte(`{"fake":"login"}`), 0600) |
| + os.WriteFile(filepath.Join(source, ".claude.json"), []byte(`{"oauthAccount":{"emailAddress":"account@example.invalid","accountUuid":"fake-account"},"projects":{"untrusted":"trust"},"hooks":{"evil":true}}`), 0600) |
| + lease, e := provider.OpenAccount(context.Background(), b) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + t.Cleanup(func() { lease.Close() }) |
| + binary := filepath.Join(root, "fake-cli") |
| + os.WriteFile(binary, []byte(fakeCLI), 0700) |
| + helperFile := filepath.Join(root, "helper") |
| + os.WriteFile(helperFile, []byte("fake helper"), 0700) |
| + work, scratch := filepath.Join(root, "workspace"), filepath.Join(root, "scratch") |
| + os.Mkdir(work, 0700) |
| + os.Mkdir(scratch, 0700) |
| + interactive := filepath.Join(root, "interactive") |
| + os.Mkdir(interactive, 0700) |
| + os.WriteFile(filepath.Join(interactive, "settings.json"), []byte(`{"trust":"unchanged"}`), 0600) |
| + in := provider.PolicyInputs{RuntimeFiles: []provider.Mount{{Source: binary, Target: "/opt/claude", ReadOnly: true}, {Source: helperFile, Target: helper, ReadOnly: true}}, Workspace: work, Scratch: scratch, EgressHosts: []string{"api.anthropic.com"}, LauncherVersion: "2", BwrapVersion: "0.11.0", DeniedPaths: []string{"/private/state", "/alias/login"}} |
| + in, e = PolicyInputs(lease.Binding(), in, role, "claude-haiku-5-5") |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + policy, e := provider.BuildPolicy(lease.Binding(), in) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + host := &fakeHost{binary: binary, account: id.AccountID} |
| + t.Cleanup(func() { |
| + host.mu.Lock() |
| + defer host.mu.Unlock() |
| + for _, p := range host.processes { |
| + p.cmd.Process.Kill() |
| + <-p.done |
| + p.in.Close() |
| + p.out.Close() |
| + p.err.Close() |
| + } |
| + }) |
| + cap := &captureFactory{} |
| + l, e := New(host, cap) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + sum := sha256.Sum256([]byte(fakeCLI)) |
| + l.digest = hex.EncodeToString(sum[:]) |
| + return &fixture{l: l, host: host, capture: cap, lease: lease, launch: provider.Launch{AttemptKey: "attempt", Workspace: work, Binding: lease.Binding(), Policy: policy, Selection: provider.Selection{ConnectionID: "connection", Provider: "claude", Family: "claude", Model: "claude-haiku-5-5", AccountID: id.AccountID}}, inputs: in, interactive: interactive} |
| +} |
| +func openFixture(t *testing.T, f *fixture) (provider.Session, <-chan provider.Event) { |
| + t.Helper() |
| + ctx, cancel := context.WithTimeout(context.Background(), 8*time.Second) |
| + t.Cleanup(cancel) |
| + s, e := f.l.Open(ctx, f.launch) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + t.Cleanup(func() { ctx, c := context.WithTimeout(context.Background(), time.Second); defer c(); f.l.Close(ctx, s) }) |
| + events, e := f.l.Events(ctx, s) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + return s, events |
| +} |
| +func terminal(t *testing.T, events <-chan provider.Event) provider.Event { |
| + t.Helper() |
| + timer := time.NewTimer(3 * time.Second) |
| + defer timer.Stop() |
| + for { |
| + select { |
| + case ev, ok := <-events: |
| + if !ok { |
| + t.Fatal("events ended without terminal") |
| + } |
| + if strings.HasPrefix(ev.Kind, "turn.") { |
| + return ev |
| + } |
| + case <-timer.C: |
| + t.Fatal("no terminal event") |
| + } |
| + } |
| +} |
| +func TestClaudeLaunchPolicy(t *testing.T) { |
| + for _, role := range []string{"Engineering", "Review", "Product"} { |
| + t.Run(role, func(t *testing.T) { |
| + f := fixtureFor(t, role) |
| + want := []string{"Bash", "Read", "Write", "Edit", "Glob", "Grep"} |
| + if role != "Engineering" { |
| + want = []string{"Read", "Glob", "Grep", "Bash"} |
| + } |
| + if !reflect.DeepEqual(f.inputs.Tools, append(append([]string{}, want...), "mcp__equipo__permission")) { |
| + t.Fatalf("tools %v", f.inputs.Tools) |
| + } |
| + var settings map[string]any |
| + json.Unmarshal(f.inputs.Settings, &settings) |
| + if settings["disableAllHooks"] != true || len(settings["enabledPlugins"].(map[string]any)) != 0 { |
| + t.Fatal("hooks/plugins enabled") |
| + } |
| + if !sameJSON(f.inputs.MCP, []byte(`{"mcpServers":{"equipo":{"type":"stdio","command":"/opt/equipo-tool-proxy","args":["--socket","/tool/equipo.sock"]}}}`)) { |
| + t.Fatal("MCP inventory expanded") |
| + } |
| + sandbox := settings["sandbox"].(map[string]any) |
| + if sandbox["enabled"] != true || sandbox["failIfUnavailable"] != true || sandbox["allowUnsandboxedCommands"] != false { |
| + t.Fatal("sandbox weakened") |
| + } |
| + if sandbox["autoAllowBashIfSandboxed"] != false { |
| + t.Fatal("automatic shell approval enabled") |
| + } |
| + if len(sandbox["excludedCommands"].([]any)) != 0 { |
| + t.Fatal("excluded commands") |
| + } |
| + for _, path := range []string{"/home/runner", "/egress", "/tool", "/tool/equipo.sock", "/config", "/proc", "/dev/fd", "/private/state", "/alias/login"} { |
| + for _, key := range []string{"denyRead", "denyWrite"} { |
| + found := false |
| + for _, value := range sandbox["filesystem"].(map[string]any)[key].([]any) { |
| + if value == path { |
| + found = true |
| + } |
| + } |
| + if !found { |
| + t.Fatalf("missing shell %s denial %s", key, path) |
| + } |
| + } |
| + for _, tool := range []string{"Read", "Write", "Edit", "Glob", "Grep"} { |
| + for _, suffix := range []string{")", "/**)"} { |
| + if !strings.Contains(string(f.inputs.Settings), tool+"(/"+path+suffix) { |
| + t.Fatalf("missing native %s denial %s", tool, path) |
| + } |
| + } |
| + } |
| + if !strings.Contains(string(f.inputs.Settings), `"`+path+`"`) || !strings.Contains(string(f.inputs.Settings), "Read(/"+path+"/**)") { |
| + t.Fatalf("missing protected path %s", path) |
| + } |
| + } |
| + s, _ := openFixture(t, f) |
| + _ = s |
| + f.host.mu.Lock() |
| + last := len(f.host.argv) - 1 |
| + args := f.host.argv[last] |
| + launch := f.host.launches[last] |
| + f.host.mu.Unlock() |
| + if launch.Policy.Hash != f.launch.Policy.Hash { |
| + t.Fatal("session ID changed reusable policy hash") |
| + } |
| + expected := []string{"/opt/claude", "-p", "--verbose", "--input-format", "stream-json", "--output-format", "stream-json", "--model", "claude-haiku-5-5", "--setting-sources", "", "--disable-slash-commands", "--strict-mcp-config", "--mcp-config", provider.MCPPath, "--settings", provider.SettingsPath, "--permission-mode", "manual", "--permission-prompt-tool", "mcp__equipo__permission", "--tools", strings.Join(want, ","), "--session-id", s.ID} |
| + if !reflect.DeepEqual(args, expected) { |
| + t.Fatalf("argv %v", args) |
| + } |
| + for k, v := range map[string]string{"CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC": "1", "DISABLE_AUTOUPDATER": "1", "CLAUDE_CONFIG_DIR": "/home/runner"} { |
| + if launch.Policy.Env[k] != v { |
| + t.Fatalf("env %s", k) |
| + } |
| + } |
| + if _, ok := launch.Policy.Env["CLAUDE_CODE_DISABLE_AUTO_UPDATE"]; ok { |
| + t.Fatal("unsupported updater spelling") |
| + } |
| + in := f.inputs |
| + in.Tools = append(append([]string{}, in.Tools...), "WebFetch") |
| + p, e := provider.BuildPolicy(f.lease.Binding(), in) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if p.Hash == f.launch.Policy.Hash { |
| + t.Fatal("tool not hashed") |
| + } |
| + }) |
| + } |
| +} |
| +func TestClaudeNoPromptBeforeAdmission(t *testing.T) { |
| + f := fixtureFor(t, "Engineering") |
| + t.Setenv("CLAUDE_CONFIG_DIR", f.interactive) |
| + s, events := openFixture(t, f) |
| + f.capture.mu.Lock() |
| + n := f.capture.inputs |
| + f.capture.mu.Unlock() |
| + if n != 0 { |
| + t.Fatal("prompt before admission") |
| + } |
| + if e := f.l.StartTurn(context.Background(), s, provider.Turn{ID: "t", Prompt: "one"}); e == nil { |
| + t.Fatal("missing admission accepted") |
| + } |
| + for i, id := range []string{"t1", "t2"} { |
| + if e := f.l.StartTurn(context.Background(), s, provider.Turn{ID: id, AdmissionID: "admit-" + id, Prompt: "tiny"}); e != nil { |
| + t.Fatal(e) |
| + } |
| + ev := terminal(t, events) |
| + if ev.Kind != "turn.completed" || ev.TurnID != id || ev.SessionID != s.ID { |
| + t.Fatalf("turn %d: %+v", i, ev) |
| + } |
| + } |
| + if e := f.l.Close(context.Background(), s); e != nil { |
| + t.Fatal(e) |
| + } |
| + runtimeConfig, _ := os.ReadFile(filepath.Join(f.lease.Binding().Home, "settings.json")) |
| + if string(runtimeConfig) != `{"trust":"fake-cli-write"}` { |
| + t.Fatal("fake did not exercise config writes") |
| + } |
| + got, _ := os.ReadFile(filepath.Join(f.interactive, "settings.json")) |
| + if string(got) != `{"trust":"unchanged"}` { |
| + t.Fatal("interactive config changed") |
| + } |
| +} |
| +func TestClaudeResumeUsesSameBinding(t *testing.T) { |
| + f := fixtureFor(t, "Review") |
| + s, events := openFixture(t, f) |
| + turn := provider.Turn{ID: "t1", AdmissionID: "a1", Prompt: "tiny"} |
| + if e := f.l.StartTurn(context.Background(), s, turn); e != nil { |
| + t.Fatal(e) |
| + } |
| + terminal(t, events) |
| + if e := f.l.Close(context.Background(), s); e != nil { |
| + t.Fatal(e) |
| + } |
| + next := f.launch |
| + next.AttemptKey = "resume" |
| + next.ResumeSessionID = s.ID |
| + for _, kind := range []string{"unknown", "account", "connection", "policy"} { |
| + t.Run(kind, func(t *testing.T) { |
| + bad := next |
| + bad.AttemptKey = "bad" |
| + switch kind { |
| + case "unknown": |
| + bad.ResumeSessionID = "00000000-0000-4000-8000-000000000099" |
| + case "account": |
| + bad.Selection.AccountID = "different" |
| + case "connection": |
| + bad.Selection.ConnectionID = "different" |
| + case "policy": |
| + in := f.inputs |
| + in.Tools = append(append([]string{}, in.Tools...), "mcp__equipo__other") |
| + p, e := provider.BuildPolicy(f.lease.Binding(), in) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + bad.Policy = p |
| + } |
| + if _, e := f.l.Open(context.Background(), bad); e == nil { |
| + t.Fatal("invalid resume accepted") |
| + } |
| + }) |
| + } |
| + resumed, e := f.l.Open(context.Background(), next) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if resumed.ID != s.ID { |
| + t.Fatal("resume identity changed") |
| + } |
| + f.l.Close(context.Background(), resumed) |
| + |
| +} |
| +func TestClaudeSandboxUnavailable(t *testing.T) { |
| + f := fixtureFor(t, "Product") |
| + f.host.mode = "sandbox" |
| + if _, e := f.l.Open(context.Background(), f.launch); e == nil { |
| + t.Fatal("sandbox dependency failure admitted") |
| + } |
| + if f.capture.inputs != 0 { |
| + t.Fatal("dependency control sent prompt") |
| + } |
| +} |
| +func TestClaudeReadiness(t *testing.T) { |
| + for _, mode := range []string{"capture", "identity", "digest", "malformed_capture", "config", "no_events", "generation", "refresh", "contained"} { |
| + t.Run(mode, func(t *testing.T) { |
| + f := fixtureFor(t, "Engineering") |
| + switch mode { |
| + case "capture": |
| + f.capture.fail = true |
| + case "identity": |
| + f.host.account = "wrong" |
| + case "malformed_capture": |
| + f.capture.malformed = true |
| + case "digest": |
| + f.l.digest = strings.Repeat("0", 64) |
| + } |
| + if mode == "capture" || mode == "identity" || mode == "digest" || mode == "malformed_capture" { |
| + if _, e := f.l.Open(context.Background(), f.launch); e == nil { |
| + t.Fatal("unready launch accepted") |
| + } |
| + return |
| + } |
| + s, events := openFixture(t, f) |
| + _ = events |
| + switch mode { |
| + case "config": |
| + os.WriteFile(filepath.Join(filepath.Dir(f.launch.Policy.Mounts[len(f.launch.Policy.Mounts)-1].Source), "equipo-settings.json"), []byte(`{}`), 0600) |
| + case "no_events": |
| + f.l.mu.Lock() |
| + f.l.sessions[s.AttemptKey].attached = false |
| + f.l.mu.Unlock() |
| + case "generation": |
| + os.WriteFile(filepath.Join(f.lease.Binding().CredentialHome, ".credentials.json"), []byte(`{"fake":"new"}`), 0600) |
| + f.host.account = "wrong" |
| + case "refresh": |
| + os.WriteFile(filepath.Join(f.lease.Binding().Home, ".credentials.json"), []byte(`{"fake":"refresh"}`), 0600) |
| + f.host.account = "wrong" |
| + case "contained": |
| + os.Remove(filepath.Join(f.lease.Binding().Home, provider.IdentityFile)) |
| + } |
| + if e := f.l.StartTurn(context.Background(), s, provider.Turn{ID: "t", AdmissionID: "a", Prompt: "tiny"}); e == nil { |
| + t.Fatal("unready turn accepted") |
| + } |
| + if f.capture.inputs != 0 { |
| + t.Fatal("unready prompt written") |
| + } |
| + }) |
| + } |
| +} |
| +func TestClaudeTerminalErrors(t *testing.T) { |
| + for _, mode := range []string{"rate", "identity", "exit", "hang", "missing", "partial", "oversized"} { |
| + t.Run(mode, func(t *testing.T) { |
| + f := fixtureFor(t, "Review") |
| + f.host.mode = mode |
| + s, events := openFixture(t, f) |
| + if e := f.l.StartTurn(context.Background(), s, provider.Turn{ID: "t", AdmissionID: "a", Prompt: "tiny"}); e != nil { |
| + t.Fatal(e) |
| + } |
| + if mode == "hang" { |
| + f.l.Interrupt(context.Background(), s) |
| + } else { |
| + ev := terminal(t, events) |
| + if mode != "exit" && ev.Kind == "turn.completed" { |
| + t.Fatal("failure completed") |
| + } |
| + } |
| + f.l.Close(context.Background(), s) |
| + next := f.launch |
| + next.AttemptKey = "resume" |
| + next.ResumeSessionID = s.ID |
| + if _, e := f.l.Open(context.Background(), next); e == nil { |
| + t.Fatal("uncertain/failed session resumed") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestClaudeObservedIdentity(t *testing.T) { |
| + f := fixtureFor(t, "Engineering") |
| + observed, e := f.l.Preflight(context.Background(), f.lease.Binding(), f.launch.Policy) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if observed.HomeID != "" || observed.AccountID != "account@example.invalid" || observed.ProviderVersion != Version { |
| + t.Fatalf("identity was not CLI observed: %+v", observed) |
| + } |
| +} |
| +func TestClaudePolicyRefusals(t *testing.T) { |
| + for _, field := range []string{"settings", "mcp", "tools", "argv", "env", "version", "helper", "managed", "managed_instruction", "hash"} { |
| + t.Run(field, func(t *testing.T) { |
| + f := fixtureFor(t, "Engineering") |
| + in := f.inputs |
| + switch field { |
| + case "settings": |
| + var v map[string]any |
| + json.Unmarshal(in.Settings, &v) |
| + v["sandbox"].(map[string]any)["enabled"] = false |
| + in.Settings, _ = json.Marshal(v) |
| + case "mcp": |
| + in.MCP = json.RawMessage(`{"mcpServers":{"other":{"command":"/opt/evil"}}}`) |
| + case "tools": |
| + in.Tools = append(in.Tools, "WebFetch") |
| + case "argv": |
| + in.Argv = append(in.Argv, "--dangerously-skip-permissions") |
| + case "version": |
| + in.ProviderVersion = "2.1.313" |
| + case "managed", "managed_instruction": |
| + path := filepath.Join(t.TempDir(), "managed.json") |
| + os.WriteFile(path, []byte(`{"sandbox":{"enabled":false}}`), 0600) |
| + mount := provider.Mount{Source: path, Target: "/etc/claude-code/managed-settings.json", ReadOnly: true} |
| + if field == "managed_instruction" { |
| + in.InstructionFiles = append(in.InstructionFiles, mount) |
| + } else { |
| + in.RuntimeFiles = append(in.RuntimeFiles, mount) |
| + } |
| + case "helper": |
| + in.RuntimeFiles = in.RuntimeFiles[:1] |
| + } |
| + p, e := provider.BuildPolicy(f.lease.Binding(), in) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + switch field { |
| + case "env": |
| + delete(p.Env, "DISABLE_AUTOUPDATER") |
| + case "hash": |
| + p.Hash = "wrong" |
| + } |
| + launch := f.launch |
| + launch.Policy = p |
| + if _, e := f.l.Open(context.Background(), launch); e == nil { |
| + t.Fatal("unsafe policy accepted") |
| + } |
| + }) |
| + } |
| +} |
| +func TestClaudeRefreshBeforeTurn(t *testing.T) { |
| + for _, kind := range []string{"source", "runtime"} { |
| + t.Run(kind, func(t *testing.T) { |
| + f := fixtureFor(t, "Review") |
| + s, events := openFixture(t, f) |
| + home := f.lease.Binding().CredentialHome |
| + if kind == "runtime" { |
| + home = f.lease.Binding().Home |
| + } |
| + os.WriteFile(filepath.Join(home, ".credentials.json"), []byte(`{"fake":"new generation"}`), 0600) |
| + if e := f.l.StartTurn(context.Background(), s, provider.Turn{ID: "t", AdmissionID: "a", Prompt: "tiny"}); e != nil { |
| + t.Fatal(e) |
| + } |
| + terminal(t, events) |
| + if kind == "runtime" { |
| + got, _ := os.ReadFile(filepath.Join(f.lease.Binding().CredentialHome, ".credentials.json")) |
| + if string(got) != `{"fake":"new generation"}` { |
| + t.Fatal("refresh not committed before prompt") |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestClaudeResumeLatestAttempt(t *testing.T) { |
| + f := fixtureFor(t, "Review") |
| + s, events := openFixture(t, f) |
| + turn := provider.Turn{ID: "t1", AdmissionID: "a1", Prompt: "tiny"} |
| + if e := f.l.StartTurn(context.Background(), s, turn); e != nil { |
| + t.Fatal(e) |
| + } |
| + terminal(t, events) |
| + if e := f.l.Close(context.Background(), s); e != nil { |
| + t.Fatal(e) |
| + } |
| + next := f.launch |
| + next.AttemptKey = "resume-1" |
| + next.ResumeSessionID = s.ID |
| + s2, e := f.l.Open(context.Background(), next) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + f.l.Events(context.Background(), s2) |
| + if e = f.l.StartTurn(context.Background(), s2, turn); e == nil { |
| + t.Error("resumed admission replayed") |
| + } |
| + f.l.Interrupt(context.Background(), s2) |
| + f.l.Close(context.Background(), s2) |
| + next.AttemptKey = "resume-2" |
| + if _, e = f.l.Open(context.Background(), next); e == nil { |
| + t.Fatal("old completion overrode newer uncertainty") |
| + } |
| +} |
| + |
| +func TestClaudeToolHash(t *testing.T) { |
| + f := fixtureFor(t, "Engineering") |
| + in := f.inputs |
| + in.Tools = append(append([]string{}, in.Tools...), "mcp__equipo__new_tool") |
| + changed, e := provider.BuildPolicy(f.lease.Binding(), in) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if changed.Hash == f.launch.Policy.Hash { |
| + t.Fatal("tool inventory missing from policy hash") |
| + } |
| +} |
| +func TestClaudeActiveLease(t *testing.T) { |
| + f := fixtureFor(t, "Review") |
| + f.host.mode = "hang" |
| + s, _ := openFixture(t, f) |
| + if e := f.l.StartTurn(context.Background(), s, provider.Turn{ID: "t", AdmissionID: "a", Prompt: "tiny"}); e != nil { |
| + t.Fatal(e) |
| + } |
| + os.WriteFile(filepath.Join(f.lease.Binding().CredentialHome, ".credentials.json"), []byte(`{"fake":"replacement"}`), 0600) |
| + if e := f.lease.Validate(context.Background()); !errors.Is(e, provider.ErrContainment) { |
| + t.Fatalf("active interval not checked: %v", e) |
| + } |
| +} |
| + |
| +func TestClaudeNativeIdentityMetadata(t *testing.T) { |
| + for _, kind := range []string{"staged", "source", "runtime"} { |
| + t.Run(kind, func(t *testing.T) { |
| + f := fixtureFor(t, "Review") |
| + if kind == "staged" { |
| + raw, e := os.ReadFile(filepath.Join(f.lease.Binding().Home, ".claude.json")) |
| + if e != nil { |
| + t.Fatal(e) |
| + } |
| + if strings.Contains(string(raw), "hooks") || strings.Contains(string(raw), "projects") || !strings.Contains(string(raw), "account@example.invalid") { |
| + t.Fatalf("unsafe metadata import: %s", raw) |
| + } |
| + return |
| + } |
| + s, _ := openFixture(t, f) |
| + home := f.lease.Binding().CredentialHome |
| + if kind == "runtime" { |
| + home = f.lease.Binding().Home |
| + } |
| + os.WriteFile(filepath.Join(home, ".claude.json"), []byte(`{"oauthAccount":{"emailAddress":"wrong@example.invalid"}}`), 0600) |
| + if e := f.l.StartTurn(context.Background(), s, provider.Turn{ID: "t", AdmissionID: "a", Prompt: "tiny"}); e == nil { |
| + t.Fatal("changed native identity metadata admitted") |
| + } |
| + if f.capture.inputs != 0 { |
| + t.Fatal("prompt sent after metadata change") |
| + } |
| + }) |
| + } |
| +} |
| + |
| +func TestClaudeConstructor(t *testing.T) { |
| + var host *fakeHost |
| + var capture *captureFactory |
| + for _, pair := range []struct { |
| + host provider.ProcessHost |
| + capture provider.CaptureFactory |
| + }{{nil, &captureFactory{}}, {&fakeHost{}, nil}, {host, &captureFactory{}}, {&fakeHost{}, capture}} { |
| + if _, e := New(pair.host, pair.capture); e == nil { |
| + t.Fatal("missing dependency accepted") |
| + } |
| + } |
| +} |
| +func TestClaudeConcurrentSession(t *testing.T) { |
| + f := fixtureFor(t, "Review") |
| + _, _ = openFixture(t, f) |
| + next := f.launch |
| + next.AttemptKey = "second" |
| + if _, e := f.l.Open(context.Background(), next); e == nil { |
| + t.Fatal("two processes admitted on one account lease") |
| + } |
| +} |
| + |
| +func TestClaudeInitPolicy(t *testing.T) { |
| + for _, mode := range []string{"tools", "plugins", "skills", "permission", "version", "model", "mcp"} { |
| + t.Run(mode, func(t *testing.T) { |
| + f := fixtureFor(t, "Review") |
| + f.host.mode = mode |
| + s, events := openFixture(t, f) |
| + if e := f.l.StartTurn(context.Background(), s, provider.Turn{ID: "t", AdmissionID: "a", Prompt: "tiny"}); e != nil { |
| + t.Fatal(e) |
| + } |
| + if ev := terminal(t, events); ev.Kind != "turn.failed" { |
| + t.Fatal("unexpected init policy accepted") |
| + } |
| + }) |
| + } |
| +} |
| +func TestClaudeCaptureSequence(t *testing.T) { |
| + f := fixtureFor(t, "Review") |
| + f.capture.zeroSequence = true |
| + s, events := openFixture(t, f) |
| + if e := f.l.StartTurn(context.Background(), s, provider.Turn{ID: "t", AdmissionID: "a", Prompt: "tiny"}); e != nil { |
| + t.Fatal(e) |
| + } |
| + if ev := terminal(t, events); ev.Kind != "turn.failed" { |
| + t.Fatal("unsequenced frame accepted") |
| + } |
| +} |
| + |
| +type blockedInput struct { |
| + underlying io.WriteCloser |
| + started, done chan struct{} |
| + once sync.Once |
| +} |
| + |
| +func (b *blockedInput) Write(raw []byte) (int, error) { |
| + close(b.started) |
| + <-b.done |
| + return 0, io.ErrClosedPipe |
| +} |
| +func (b *blockedInput) Close() error { |
| + b.once.Do(func() { close(b.done) }) |
| + return b.underlying.Close() |
| +} |
| +func TestClaudeWriteCancellation(t *testing.T) { |
| + f := fixtureFor(t, "Review") |
| + f.capture.block = true |
| + s, _ := openFixture(t, f) |
| + ctx, cancel := context.WithCancel(context.Background()) |
| + defer cancel() |
| + returned := make(chan error, 1) |
| + go func() { returned <- f.l.StartTurn(ctx, s, provider.Turn{ID: "t", AdmissionID: "a", Prompt: "tiny"}) }() |
| + <-f.capture.blocker.started |
| + cancel() |
| + select { |
| + case e := <-returned: |
| + if e == nil { |
| + t.Fatal("cancelled write succeeded") |
| + } |
| + case <-time.After(200 * time.Millisecond): |
| + f.capture.blocker.Close() |
| + <-returned |
| + t.Fatal("cancelled admission left stdin blocked") |
| + } |
| +} |
| + |
| +func TestClaudeRefreshWithConfigTamper(t *testing.T) { |
| + f := fixtureFor(t, "Review") |
| + s, _ := openFixture(t, f) |
| + os.WriteFile(filepath.Join(f.lease.Binding().Home, ".credentials.json"), []byte(`{"fake":"refreshed"}`), 0600) |
| + for _, mount := range f.launch.Policy.Mounts { |
| + if mount.Target == provider.SettingsPath { |
| + os.WriteFile(mount.Source, []byte(`{}`), 0600) |
| + } |
| + } |
| + if e := f.l.StartTurn(context.Background(), s, provider.Turn{ID: "t", AdmissionID: "a", Prompt: "tiny"}); e == nil { |
| + t.Fatal("tampered config admitted after refresh") |
| + } |
| + f.l.mu.Lock() |
| + stopped := f.l.sessions[s.AttemptKey].ctx.Err() != nil |
| + f.l.mu.Unlock() |
| + if !stopped { |
| + t.Fatal("tampered refresh left the attempt running") |
| + } |
| +} |
diff --git a/internal/runner/provider/claude/testdata/recording.json b/internal/runner/provider/claude/testdata/recording.json| new file mode 100644 |
| index 00000000..80f64fe6 |
| --- /dev/null |
| +++ b/internal/runner/provider/claude/testdata/recording.json |
| @@ -0,0 +1,81 @@ |
| +{ |
| + "argv": [ |
| + "/sanitized/path", |
| + "-p", |
| + "--verbose", |
| + "--input-format", |
| + "stream-json", |
| + "--output-format", |
| + "stream-json", |
| + "--session-id", |
| + "00000000-0000-4000-8000-000000000001", |
| + "--model", |
| + "claude-haiku-5-5", |
| + "--setting-sources", |
| + "", |
| + "--strict-mcp-config", |
| + "--mcp-config", |
| + "/sanitized/path", |
| + "--disable-slash-commands", |
| + "--tools", |
| + "", |
| + "--settings", |
| + "/sanitized/path" |
| + ], |
| + "session_id": "00000000-0000-4000-8000-000000000001", |
| + "executable_sha256": "4f4178ce41d83e23341ebfbaecdbcf8ea6bf7baea0690025abe49eeec3a5d01d", |
| + "executable": "/sanitized/path", |
| + "init_before_first_input": false, |
| + "cli_version": "2.1.312", |
| + "exit_status": 0, |
| + "seconds": 6.336797021329403, |
| + "sent": 2, |
| + "result_count": 2, |
| + "timing": [ |
| + { |
| + "event": "stdin", |
| + "turn": 1, |
| + "seconds": 3.004892624914646 |
| + }, |
| + { |
| + "event": "stdout", |
| + "bytes": 1532, |
| + "seconds": 3.026741798967123 |
| + }, |
| + { |
| + "event": "stdout", |
| + "bytes": 789, |
| + "seconds": 4.543380985036492 |
| + }, |
| + { |
| + "event": "stdout", |
| + "bytes": 453, |
| + "seconds": 4.5483969040215015 |
| + }, |
| + { |
| + "event": "stdout", |
| + "bytes": 2129, |
| + "seconds": 4.551992719992995 |
| + }, |
| + { |
| + "event": "stdin", |
| + "turn": 2, |
| + "seconds": 4.552055707201362 |
| + }, |
| + { |
| + "event": "stdout", |
| + "bytes": 1532, |
| + "seconds": 4.559561720117927 |
| + }, |
| + { |
| + "event": "stdout", |
| + "bytes": 868, |
| + "seconds": 6.316034132614732 |
| + }, |
| + { |
| + "event": "stdout", |
| + "bytes": 2122, |
| + "seconds": 6.320148069411516 |
| + } |
| + ] |
| +} |
diff --git a/internal/runner/provider/claude/testdata/resume-recording.json b/internal/runner/provider/claude/testdata/resume-recording.json| new file mode 100644 |
| index 00000000..c9b7c8ad |
| --- /dev/null |
| +++ b/internal/runner/provider/claude/testdata/resume-recording.json |
| @@ -0,0 +1,61 @@ |
| +{ |
| + "argv": [ |
| + "/sanitized/path", |
| + "-p", |
| + "--verbose", |
| + "--input-format", |
| + "stream-json", |
| + "--output-format", |
| + "stream-json", |
| + "--resume", |
| + "00000000-0000-4000-8000-000000000001", |
| + "--model", |
| + "claude-haiku-5-5", |
| + "--setting-sources", |
| + "", |
| + "--strict-mcp-config", |
| + "--mcp-config", |
| + "/sanitized/path", |
| + "--disable-slash-commands", |
| + "--tools", |
| + "", |
| + "--settings", |
| + "/sanitized/path" |
| + ], |
| + "session_id": "00000000-0000-4000-8000-000000000001", |
| + "executable_sha256": "4f4178ce41d83e23341ebfbaecdbcf8ea6bf7baea0690025abe49eeec3a5d01d", |
| + "executable": "/sanitized/path", |
| + "init_before_first_input": false, |
| + "cli_version": "2.1.312", |
| + "exit_status": 0, |
| + "seconds": 4.746489774435759, |
| + "sent": 1, |
| + "result_count": 1, |
| + "timing": [ |
| + { |
| + "event": "stdin", |
| + "turn": 1, |
| + "seconds": 3.0047780871391296 |
| + }, |
| + { |
| + "event": "stdout", |
| + "bytes": 1532, |
| + "seconds": 3.033276876434684 |
| + }, |
| + { |
| + "event": "stdout", |
| + "bytes": 868, |
| + "seconds": 4.72058941796422 |
| + }, |
| + { |
| + "event": "stdout", |
| + "bytes": 453, |
| + "seconds": 4.7264325227588415 |
| + }, |
| + { |
| + "event": "stdout", |
| + "bytes": 2121, |
| + "seconds": 4.729811113327742 |
| + } |
| + ] |
| +} |
diff --git a/internal/runner/provider/claude/testdata/resume-stderr.txt b/internal/runner/provider/claude/testdata/resume-stderr.txt| new file mode 100644 |
| index 00000000..e69de29b |
diff --git a/internal/runner/provider/claude/testdata/resume-stdin.jsonl b/internal/runner/provider/claude/testdata/resume-stdin.jsonl| new file mode 100644 |
| index 00000000..6b9c7de0 |
| --- /dev/null |
| +++ b/internal/runner/provider/claude/testdata/resume-stdin.jsonl |
| @@ -0,0 +1 @@ |
| +{"type":"user","message":{"role":"user","content":"Reply with the single word three."},"session_id":"00000000-0000-4000-8000-000000000001","parent_tool_use_id":null} |
diff --git a/internal/runner/provider/claude/testdata/resume-stdout.jsonl b/internal/runner/provider/claude/testdata/resume-stdout.jsonl| new file mode 100644 |
| index 00000000..7259f0c3 |
| --- /dev/null |
| +++ b/internal/runner/provider/claude/testdata/resume-stdout.jsonl |
| @@ -0,0 +1,4 @@ |
| +{"type":"system","subtype":"init","cwd":"/sanitized/path","session_id":"00000000-0000-4000-8000-000000000001","tools":[],"mcp_servers":[],"model":"claude-haiku-5-5","permissionMode":"default","slash_commands":[],"apiKeySource":"none","claude_code_version":"2.1.312","output_style":"default","agents":["claude","Explore","general-purpose","Plan","statusline-setup"],"skills":[],"plugins":[{"name":"cc-plugin-agents-md","path":"builtin","source":"cc-plugin-agents-md@builtin"},{"name":"cc-plugin-plugin-authoring","path":"builtin","source":"cc-plugin-plugin-authoring@builtin"}],"capabilities":["interrupt_receipt_v1","interrupt_cancel_queued_v1","interrupt_send_now_v1","interrupt_requeue_taken_v1","msg_lifecycle_v1","request_marker_lists_v1","ask_user_question_unanswered_v1","lifecycle_wakeup_source_v1","sdk_mcp_tools_list_changed","sdk_mcp_manifests","mcp_read_resource_v1","mcp_tool_ui_meta_v1","ui_surface_v1","mcp_call_result_not_for_model_v1"],"analytics_disabled":true,"product_feedback_disabled":true,"uuid":"00000000-0000-4000-8000-000000000009","memory_paths":{"auto":"/sanitized/path"},"original_cwd":"/sanitized/path","additional_directories":[],"messaging_socket_path":"/sanitized/path","fast_mode_state":"off","fast_mode_disabled_reason":"sdk_opt_in_required","per_turn_effort_active":true,"view_mode":"default"} |
| +{"type":"assistant","message":{"model":"claude-haiku-5-5","id":"msg_sanitized_5","type":"message","role":"assistant","content":[{"type":"text","text":"three"}],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":2,"cache_creation_input_tokens":63,"cache_read_input_tokens":3919,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":63},"output_tokens":3,"service_tier":"standard","inference_geo":"global","speed":"standard"},"input_transformations":[],"diagnostics":{"cache_miss_reason":{"type":"messages_changed","cache_missed_input_tokens":1200}},"context_management":null},"parent_tool_use_id":null,"session_id":"00000000-0000-4000-8000-000000000001","uuid":"00000000-0000-4000-8000-000000000010","timestamp":"2026-11-03T13:13:11.348Z","request_id":"req_sanitized_6"} |
| +{"type":"rate_limit_event","rate_limit_info":{"status":"allowed_warning","resetsAt":1794211200,"rateLimitType":"seven_day","utilization":0.54,"overageStatus":"rejected","overageDisabledReason":"org_level_disabled","isUsingOverage":false,"unifiedWindows":{"seven_day":{"utilization":0.54,"resetsAt":1794211200,"status":"allowed"}},"overageEnabled":false},"uuid":"00000000-0000-4000-8000-000000000011","session_id":"00000000-0000-4000-8000-000000000001"} |
| +{"duration_api_ms":4948,"stop_reason":"end_turn","session_id":"00000000-0000-4000-8000-000000000001","total_cost_usd":0.0009493500000000001,"usage":{"input_tokens":2,"cache_creation_input_tokens":63,"cache_read_input_tokens":3919,"output_tokens":3,"output_tokens_details":{"thinking_tokens":0},"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":63,"ephemeral_5m_input_tokens":0},"inference_geo":"global","iterations":[],"speed":"standard","fallback_credit":null},"modelUsage":{"claude-haiku-5-5":{"inputTokens":6,"outputTokens":9,"thinkingTokens":0,"cacheReadInputTokens":7485,"cacheCreationInputTokens":4347,"cacheCreationEphemeral5mInputTokens":0,"cacheCreationEphemeral1hInputTokens":4347,"webSearchRequests":0,"costUSD":0.0009493500000000001,"contextWindow":1000000,"maxOutputTokens":128000,"canonicalModel":"claude-haiku-5-5","provider":"firstParty","costBasis":"list"}},"permission_denials":[],"terminal_reason":"completed","fast_mode_state":"off","fast_mode_disabled_reason":"sdk_opt_in_required","subagent_stats":{"spawned":0,"requested":{"background":0,"foreground":0,"unset":0},"started_in_background":0,"max_depth":0,"spawned_by_subagents":0,"completed":0,"failed":0,"killed":{"parent":0,"user":0,"system":0},"refused":{"depth_limit":0,"concurrency_limit":0,"budget":0},"by_type":{}},"safety_stops":0,"is_error":false,"num_turns":1,"subtype":"success","api_error_status":null,"result":"three","ttft_ms":1709,"type":"result","duration_ms":1718,"uuid":"00000000-0000-4000-8000-000000000012","ttft_stream_ms":1708,"time_to_request_ms":35,"first_content_frame_ms":1708,"queued_turn_count":0,"result_index":0,"model_usage_since_last_result":{"claude-haiku-5-5":{"inputTokens":2,"outputTokens":3,"cacheReadInputTokens":3919,"cacheCreationInputTokens":63,"webSearchRequests":0,"costUSD":5.349e-05,"contextWindow":1000000,"maxOutputTokens":128000,"thinkingTokens":0,"cacheCreationEphemeral5mInputTokens":0,"cacheCreationEphemeral1hInputTokens":63,"canonicalModel":"claude-haiku-5-5","provider":"firstParty","costBasis":"list"}}} |
diff --git a/internal/runner/provider/claude/testdata/stderr.txt b/internal/runner/provider/claude/testdata/stderr.txt| new file mode 100644 |
| index 00000000..e69de29b |
diff --git a/internal/runner/provider/claude/testdata/stdin.jsonl b/internal/runner/provider/claude/testdata/stdin.jsonl| new file mode 100644 |
| index 00000000..7ae0565a |
| --- /dev/null |
| +++ b/internal/runner/provider/claude/testdata/stdin.jsonl |
| @@ -0,0 +1,2 @@ |
| +{"type":"user","message":{"role":"user","content":"Reply with the single word one."},"session_id":"00000000-0000-4000-8000-000000000001","parent_tool_use_id":null} |
| +{"type":"user","message":{"role":"user","content":"Reply with the single word two."},"session_id":"00000000-0000-4000-8000-000000000001","parent_tool_use_id":null} |
diff --git a/internal/runner/provider/claude/testdata/stdout.jsonl b/internal/runner/provider/claude/testdata/stdout.jsonl| new file mode 100644 |
| index 00000000..237a9479 |
| --- /dev/null |
| +++ b/internal/runner/provider/claude/testdata/stdout.jsonl |
| @@ -0,0 +1,7 @@ |
| +{"type":"system","subtype":"init","cwd":"/sanitized/path","session_id":"00000000-0000-4000-8000-000000000001","tools":[],"mcp_servers":[],"model":"claude-haiku-5-5","permissionMode":"default","slash_commands":[],"apiKeySource":"none","claude_code_version":"2.1.312","output_style":"default","agents":["claude","Explore","general-purpose","Plan","statusline-setup"],"skills":[],"plugins":[{"name":"cc-plugin-agents-md","path":"builtin","source":"cc-plugin-agents-md@builtin"},{"name":"cc-plugin-plugin-authoring","path":"builtin","source":"cc-plugin-plugin-authoring@builtin"}],"capabilities":["interrupt_receipt_v1","interrupt_cancel_queued_v1","interrupt_send_now_v1","interrupt_requeue_taken_v1","msg_lifecycle_v1","request_marker_lists_v1","ask_user_question_unanswered_v1","lifecycle_wakeup_source_v1","sdk_mcp_tools_list_changed","sdk_mcp_manifests","mcp_read_resource_v1","mcp_tool_ui_meta_v1","ui_surface_v1","mcp_call_result_not_for_model_v1"],"analytics_disabled":true,"product_feedback_disabled":true,"uuid":"00000000-0000-4000-8000-000000000002","memory_paths":{"auto":"/sanitized/path"},"original_cwd":"/sanitized/path","additional_directories":[],"messaging_socket_path":"/sanitized/path","fast_mode_state":"off","fast_mode_disabled_reason":"sdk_opt_in_required","per_turn_effort_active":true,"view_mode":"default"} |
| +{"type":"assistant","message":{"model":"claude-haiku-5-5","id":"msg_sanitized_1","type":"message","role":"assistant","content":[{"type":"text","text":"one"}],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":2,"cache_creation_input_tokens":3906,"cache_read_input_tokens":0,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":3906},"output_tokens":1,"service_tier":"standard","inference_geo":"global","speed":"standard"},"input_transformations":[],"diagnostics":null,"context_management":null},"parent_tool_use_id":null,"session_id":"00000000-0000-4000-8000-000000000001","uuid":"00000000-0000-4000-8000-000000000003","timestamp":"2026-11-03T13:12:54.938Z","request_id":"req_sanitized_2"} |
| +{"type":"rate_limit_event","rate_limit_info":{"status":"allowed_warning","resetsAt":1794211200,"rateLimitType":"seven_day","utilization":0.54,"overageStatus":"rejected","overageDisabledReason":"org_level_disabled","isUsingOverage":false,"unifiedWindows":{"seven_day":{"utilization":0.54,"resetsAt":1794211200,"status":"allowed"}},"overageEnabled":false},"uuid":"00000000-0000-4000-8000-000000000004","session_id":"00000000-0000-4000-8000-000000000001"} |
| +{"duration_api_ms":1508,"stop_reason":"end_turn","session_id":"00000000-0000-4000-8000-000000000001","total_cost_usd":0.0007829000000000001,"usage":{"input_tokens":2,"cache_creation_input_tokens":3906,"cache_read_input_tokens":0,"output_tokens":3,"output_tokens_details":{"thinking_tokens":0},"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":3906,"ephemeral_5m_input_tokens":0},"inference_geo":"global","iterations":[],"speed":"standard","fallback_credit":null},"modelUsage":{"claude-haiku-5-5":{"inputTokens":2,"outputTokens":3,"cacheReadInputTokens":0,"cacheCreationInputTokens":3906,"webSearchRequests":0,"costUSD":0.0007829000000000001,"contextWindow":1000000,"maxOutputTokens":128000,"thinkingTokens":0,"cacheCreationEphemeral5mInputTokens":0,"cacheCreationEphemeral1hInputTokens":3906,"canonicalModel":"claude-haiku-5-5","provider":"firstParty","costBasis":"list"}},"permission_denials":[],"terminal_reason":"completed","fast_mode_state":"off","fast_mode_disabled_reason":"sdk_opt_in_required","subagent_stats":{"spawned":0,"requested":{"background":0,"foreground":0,"unset":0},"started_in_background":0,"max_depth":0,"spawned_by_subagents":0,"completed":0,"failed":0,"killed":{"parent":0,"user":0,"system":0},"refused":{"depth_limit":0,"concurrency_limit":0,"budget":0},"by_type":{}},"safety_stops":0,"is_error":false,"num_turns":1,"subtype":"success","api_error_status":null,"result":"one","ttft_ms":1531,"type":"result","duration_ms":1540,"uuid":"00000000-0000-4000-8000-000000000005","ttft_stream_ms":1305,"time_to_request_ms":32,"first_content_frame_ms":1305,"queued_turn_count":0,"result_index":0,"model_usage_since_last_result":{"claude-haiku-5-5":{"inputTokens":2,"outputTokens":3,"cacheReadInputTokens":0,"cacheCreationInputTokens":3906,"webSearchRequests":0,"costUSD":0.0007829000000000001,"contextWindow":1000000,"maxOutputTokens":128000,"thinkingTokens":0,"cacheCreationEphemeral5mInputTokens":0,"cacheCreationEphemeral1hInputTokens":3906,"canonicalModel":"claude-haiku-5-5","provider":"firstParty","costBasis":"list"}}} |
| +{"type":"system","subtype":"init","cwd":"/sanitized/path","session_id":"00000000-0000-4000-8000-000000000001","tools":[],"mcp_servers":[],"model":"claude-haiku-5-5","permissionMode":"default","slash_commands":[],"apiKeySource":"none","claude_code_version":"2.1.312","output_style":"default","agents":["claude","Explore","general-purpose","Plan","statusline-setup"],"skills":[],"plugins":[{"name":"cc-plugin-agents-md","path":"builtin","source":"cc-plugin-agents-md@builtin"},{"name":"cc-plugin-plugin-authoring","path":"builtin","source":"cc-plugin-plugin-authoring@builtin"}],"capabilities":["interrupt_receipt_v1","interrupt_cancel_queued_v1","interrupt_send_now_v1","interrupt_requeue_taken_v1","msg_lifecycle_v1","request_marker_lists_v1","ask_user_question_unanswered_v1","lifecycle_wakeup_source_v1","sdk_mcp_tools_list_changed","sdk_mcp_manifests","mcp_read_resource_v1","mcp_tool_ui_meta_v1","ui_surface_v1","mcp_call_result_not_for_model_v1"],"analytics_disabled":true,"product_feedback_disabled":true,"uuid":"00000000-0000-4000-8000-000000000006","memory_paths":{"auto":"/sanitized/path"},"original_cwd":"/sanitized/path","additional_directories":[],"messaging_socket_path":"/sanitized/path","fast_mode_state":"off","fast_mode_disabled_reason":"sdk_opt_in_required","per_turn_effort_active":true,"view_mode":"default"} |
| +{"type":"assistant","message":{"model":"claude-haiku-5-5","id":"msg_sanitized_3","type":"message","role":"assistant","content":[{"type":"text","text":"two"}],"container":null,"stop_reason":null,"stop_sequence":null,"stop_details":null,"usage":{"input_tokens":2,"cache_creation_input_tokens":378,"cache_read_input_tokens":3566,"cache_creation":{"ephemeral_5m_input_tokens":0,"ephemeral_1h_input_tokens":378},"output_tokens":3,"service_tier":"standard","inference_geo":"global","speed":"standard"},"input_transformations":[],"diagnostics":{"cache_miss_reason":{"type":"messages_changed","cache_missed_input_tokens":1151}},"context_management":null},"parent_tool_use_id":null,"session_id":"00000000-0000-4000-8000-000000000001","uuid":"00000000-0000-4000-8000-000000000007","timestamp":"2026-11-03T13:12:56.711Z","request_id":"req_sanitized_4"} |
| +{"duration_api_ms":3264,"stop_reason":"end_turn","session_id":"00000000-0000-4000-8000-000000000001","total_cost_usd":0.0008958600000000001,"usage":{"input_tokens":2,"cache_creation_input_tokens":378,"cache_read_input_tokens":3566,"output_tokens":3,"output_tokens_details":{"thinking_tokens":0},"server_tool_use":{"web_search_requests":0,"web_fetch_requests":0},"service_tier":"standard","cache_creation":{"ephemeral_1h_input_tokens":378,"ephemeral_5m_input_tokens":0},"inference_geo":"global","iterations":[],"speed":"standard","fallback_credit":null},"modelUsage":{"claude-haiku-5-5":{"inputTokens":4,"outputTokens":6,"cacheReadInputTokens":3566,"cacheCreationInputTokens":4284,"webSearchRequests":0,"costUSD":0.0008958600000000001,"contextWindow":1000000,"maxOutputTokens":128000,"thinkingTokens":0,"cacheCreationEphemeral5mInputTokens":0,"cacheCreationEphemeral1hInputTokens":4284,"canonicalModel":"claude-haiku-5-5","provider":"firstParty","costBasis":"list"}},"permission_denials":[],"terminal_reason":"completed","fast_mode_state":"off","fast_mode_disabled_reason":"sdk_opt_in_required","subagent_stats":{"spawned":0,"requested":{"background":0,"foreground":0,"unset":0},"started_in_background":0,"max_depth":0,"spawned_by_subagents":0,"completed":0,"failed":0,"killed":{"parent":0,"user":0,"system":0},"refused":{"depth_limit":0,"concurrency_limit":0,"budget":0},"by_type":{}},"safety_stops":0,"is_error":false,"num_turns":1,"subtype":"success","api_error_status":null,"result":"two","ttft_ms":1760,"type":"result","duration_ms":1764,"uuid":"00000000-0000-4000-8000-000000000008","ttft_stream_ms":1760,"time_to_request_ms":9,"first_content_frame_ms":1760,"queued_turn_count":0,"result_index":1,"model_usage_since_last_result":{"claude-haiku-5-5":{"inputTokens":2,"outputTokens":3,"cacheReadInputTokens":3566,"cacheCreationInputTokens":378,"webSearchRequests":0,"costUSD":0.00011296,"contextWindow":1000000,"maxOutputTokens":128000,"thinkingTokens":0,"cacheCreationEphemeral5mInputTokens":0,"cacheCreationEphemeral1hInputTokens":378,"canonicalModel":"claude-haiku-5-5","provider":"firstParty","costBasis":"list"}}} |
diff --git a/internal/runner/provider/policy.go b/internal/runner/provider/policy.go| index 92dc44fb..07143813 100644 |
| --- a/internal/runner/provider/policy.go |
| +++ b/internal/runner/provider/policy.go |
| @@ -262,7 +262,8 @@ func BuildPolicy(b Binding, in PolicyInputs) (Policy, error) { |
| env["CLAUDE_CONFIG_DIR"] = "/home/runner" |
| env["CLAUDE_SECURESTORAGE_CONFIG_DIR"] = "/home/runner" |
| env["CLAUDE_TMPDIR"] = "/tmp" |
| - env["CLAUDE_CODE_DISABLE_AUTO_UPDATE"] = "1" |
| + env["CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC"] = "1" |
| + env["DISABLE_AUTOUPDATER"] = "1" |
| } |
| for k, v := range in.Env { |
| if (k != "LANG" && k != "LC_ALL" && k != "TERM") || strings.ContainsRune(v, 0) { |
| @@ -569,6 +570,18 @@ func NamespaceArguments() []string { |
| return []string{"--unshare-user", "--unshare-pid", "--unshare-ipc", "--unshare-uts", "--unshare-cgroup", "--unshare-net", "--die-with-parent", "--new-session", "--as-pid-1", "--cap-drop", "ALL", "--json-status-fd", "3"} |
| } |
| func policyTemplate(m effectiveManifest) effectiveManifest { |
| + // Session identity is journaled in the concrete manifest. Both invocation |
| + // modes use the same certified thread policy and sandbox configuration. |
| + if m.Provider == "claude" && len(m.Argv) >= 3 { |
| + n := len(m.Argv) |
| + flag, id := m.Argv[n-2], m.Argv[n-1] |
| + if (flag == "--session-id" || flag == "--resume") && len(id) == 36 && id[8] == '-' && id[13] == '-' && id[18] == '-' && id[23] == '-' { |
| + if raw, e := hex.DecodeString(strings.ReplaceAll(id, "-", "")); e == nil && len(raw) == 16 { |
| + m.Argv = append([]string(nil), m.Argv[:n-2]...) |
| + } |
| + } |
| + } |
| + |
| m.OuterMounts = append([]Mount(nil), m.OuterMounts...) |
| m.GeneratedMounts = append([]Mount(nil), m.GeneratedMounts...) |
| for i := range m.OuterMounts { |