oficina / equipo Public

Mac slice F task 5: darwin Claude Code pin and self-provisioning

claude.ExecutableSHA256DarwinArm64 (task 1 S1) and ReleasePinFor(goos,
goarch). mac.ClaudeCLI keeps the pinned 2.1.312 darwin-arm64 binary at
<install>/tools/claude-2.1.312/claude: fetched from the official URL
built from constants, streamed through the hash with a 512 MB bound,
0600 until it matches, then 0700 and renamed into place, every write
through os.Root on a symlink-free chain. Argv and Launch re-hash before
each start and stop with engineering_unavailable on a mismatch.

The Mac no longer discovers or runs any claude (no EQUIPO_CLAUDE_PATH,
no PATH, no --version); the capability report states the pinned
version only while the file verifies. A darwin/arm64 worker keeps the
CLI with mac.KeepClaude. A local stand-in file exists only under the
testbuild tag. Thin's size exemption re-measured.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev 053eab8f329a68c23e4f28a2367561d534da98ba parent 098407b
11 files changed, +1,132 −13
  • .rastrillo/budgets.txt +1 −1
  • internal/runner/mac/caps.go +6 −2
  • internal/runner/mac/caps_test.go +2 −3
  • internal/runner/mac/claude.go +395 −0
  • internal/runner/mac/claude_release.go +9 −0
  • internal/runner/mac/claude_test.go +606 −0
  • internal/runner/mac/claude_testbuild.go +23 −0
  • internal/runner/provider/claude/pins.go +28 −4
  • internal/runner/thin/mac.go +16 −2
  • internal/runner/thin/mac_claude_test.go +42 −0
  • internal/runner/thin/startup_logs_test.go +4 −1
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt
index 2244870f..28510c0f 100644
--- a/.rastrillo/budgets.txt
+++ b/.rastrillo/budgets.txt
@@ -38,7 +38,7 @@ time internal/runner/provider 15s Plan 3 CI repair measured 10.346s for the full
perf GET /releases/* skip Verified runner release file downloads, not browser GET screens.
perf GET /install.sh skip Mac runners: the one-line bootstrap a terminal pipes to sh, not a browser screen.
time internal/runner/containment 15s Plan 3 loaded CI measured 10.817s;
-size internal/runner/thin 30330 25215 Protocol 31 facts, 35 diffs, merge credential, publication guards, kept work, CI units, 34 places publish, GitHub token scans, waiting cards in the Assistant opening; measured 30330/25215.
+size internal/runner/thin 30344 25260 Protocol 31 facts, 35 diffs, merge credential, publication guards, kept work, CI units, 34 places publish, GitHub token scans, waiting cards in the Assistant opening, Mac slice F pinned Claude Code; measured 30344/25260.
time internal/thintest 240s Thin contract and page tests, the Assistant's and the models' included, share one harness. Measured 202s on a shared 16 CPU box (2026-11-13); CI runs two lanes.
time internal/runner/mac 30s Mac runners (Darwin worker): real process groups killed after a grace and proven gone (SIGTERM, SIGKILL, the marker sweep), and the probes run end to end with fake srt and xcodebuild, P6 killing.
time internal/runner/thin 45s Thin v1 slice 4 review: real git repositories for the merge and squash checks, a stalled fetch, and a 16 MiB candidate streamed through the review diff and the checks pack (about 5s).
diff --git a/internal/runner/mac/caps.go b/internal/runner/mac/caps.go
index 8e589263..eec9551c 100644
--- a/internal/runner/mac/caps.go
+++ b/internal/runner/mac/caps.go
@@ -15,8 +15,10 @@ import (
type Exec func(ctx context.Context, name string, args ...string) (string, error)
// Tools are the executables the capability report asks; "" is absent.
+// Claude is the pinned CLI, which nothing looks up (ClaudeCLI).
type Tools struct {
- Xcodebuild, Xcrun, Swift, Node, SRT, RG, Claude, Codex, Git string
+ Xcodebuild, Xcrun, Swift, Node, SRT, RG, Codex, Git string
+ Claude ClaudeCLI
}
// Capabilities is a Mac's capability report (spec §1.3): Xcode, the
@@ -52,7 +54,9 @@ func Capabilities(ctx context.Context, x Exec, t Tools) wire.Capabilities {
}
c.Toolchains.Node = word(nodeVersion, ask(t.Node, "--version"))
c.Harness.SRT = word(plainVersion, ask(t.SRT, "--version"))
- c.Harness.Claude = word(plainVersion, ask(t.Claude, "--version"))
+ // Claude Code is never run to ask: the pinned version, only while the
+ // pinned file verifies (spec §8.2).
+ c.Harness.Claude = t.Claude.Version()
c.Harness.Codex = word(plainVersion, ask(t.Codex, "--version"))
// No claude or codex tag: a Mac worker runs checks only until slice
// F, so nothing that needs a harness is placed on it.
diff --git a/internal/runner/mac/caps_test.go b/internal/runner/mac/caps_test.go
index 5b80c8f1..d11d7d60 100644
--- a/internal/runner/mac/caps_test.go
+++ b/internal/runner/mac/caps_test.go
@@ -18,7 +18,6 @@ var recorded = map[string]string{
"swift --version": "swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)\nTarget: arm64-apple-macosx15.0\n",
"node --version": "v22.12.0\n",
"srt --version": "0.0.81\n",
- "claude --version": "2.1.312 (Claude Code)\n",
"xcrun simctl list -j devices available": "",
}
@@ -41,11 +40,11 @@ func recordedExec(t *testing.T) Exec {
}
func TestCapabilitiesFromRecordedTools(t *testing.T) {
- c := Capabilities(context.Background(), recordedExec(t), Tools{Xcodebuild: "xcodebuild", Xcrun: "xcrun", Swift: "swift", Node: "node", SRT: "srt", Claude: "claude"})
+ c := Capabilities(context.Background(), recordedExec(t), Tools{Xcodebuild: "xcodebuild", Xcrun: "xcrun", Swift: "swift", Node: "node", SRT: "srt"})
if err := wire.ValidCapabilities(c); err != nil {
t.Fatalf("%v: %+v", err, c)
}
- if c.Xcode != (wire.Xcode{Version: "16.2", Build: "16C5032a"}) || c.Toolchains.Swift != "6.0.3" || c.Toolchains.Node != "v22.12.0" || c.Harness.SRT != "0.0.81" || c.Harness.Claude != "2.1.312" {
+ if c.Xcode != (wire.Xcode{Version: "16.2", Build: "16C5032a"}) || c.Toolchains.Swift != "6.0.3" || c.Toolchains.Node != "v22.12.0" || c.Harness.SRT != "0.0.81" || c.Harness.Claude != "" {
t.Fatalf("versions %+v", c)
}
if !slices.Equal(c.Tags, []string{wire.TagMacOS, wire.TagXcode, wire.TagIOSSimulator}) {
diff --git a/internal/runner/mac/claude.go b/internal/runner/mac/claude.go
new file mode 100644
index 00000000..ebfd1342
--- /dev/null
+++ b/internal/runner/mac/claude.go
@@ -0,0 +1,395 @@
+package mac
+
+import (
+ "context"
+ "crypto/rand"
+ "crypto/sha256"
+ "encoding/hex"
+ "errors"
+ "fmt"
+ "io"
+ "io/fs"
+ "net/http"
+ "os"
+ "path/filepath"
+ "strings"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/runner/provider"
+ "amadan.net/oficina/equipo/internal/runner/provider/claude"
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// The Claude Code a Mac worker runs (Mac runners spec §8.2): the official
+// 2.1.312 darwin-arm64 binary, which the worker fetches itself and checks
+// against claude.ExecutableSHA256DarwinArm64, compiled in. It never runs
+// a claude it finds on PATH or is pointed at, not even for --version.
+//
+// The URL is built from these constants and provider.ClaudeVersion, as
+// the official installer builds it (task 1, S1). The release manifest
+// beside it is not read: the pin is the only trust.
+const (
+ ClaudeReleaseBase = "https://downloads.claude.ai/claude-code-releases"
+ ClaudePlatform = "darwin-arm64"
+ // MaxClaudeBinary bounds the download (2.1.312's is 275988512 bytes).
+ MaxClaudeBinary = 512 << 20
+)
+
+// ClaudeURL is the pinned release's official download.
+func ClaudeURL() string {
+ return ClaudeReleaseBase + "/" + provider.ClaudeVersion + "/" + ClaudePlatform + "/claude"
+}
+
+// claudeRel is where the CLI lives under the install dir, as path
+// components: tools/claude-<version>/claude, beside the pinned Node and
+// ripgrep. Checks may not write the install dir (ChecksSettings).
+var claudeRel = []string{"tools", "claude-" + provider.ClaudeVersion}
+
+const claudeName = "claude"
+
+// downloadPrefix names a download being written beside the CLI; one a
+// crash left behind is removed by the next Provision.
+const downloadPrefix = ".claude-download-"
+
+// ClaudeDir is the pinned CLI's directory under installDir.
+func ClaudeDir(installDir string) string {
+ return filepath.Join(append([]string{installDir}, claudeRel...)...)
+}
+
+// ClaudePath is the pinned CLI under installDir. Never run it by this
+// path: Argv and Launch verify it first.
+func ClaudePath(installDir string) string {
+ return filepath.Join(ClaudeDir(installDir), claudeName)
+}
+
+var (
+ // ErrClaudeUnpinned: no pinned CLI at its place, or what is there is
+ // not a plain 0700 file, reached through no link, that matches the pin.
+ ErrClaudeUnpinned = errors.New("mac: the pinned Claude Code is not in place")
+ // ErrClaudeRefused: a download that does not match the pin, or is
+ // over MaxClaudeBinary.
+ ErrClaudeRefused = errors.New("mac: Claude Code download refused")
+)
+
+// ClaudeUnavailable stops a launch of the CLI before anything starts:
+// the step ends wire.ReasonEngineeringUnavailable.
+type ClaudeUnavailable struct{ Err error }
+
+func (e *ClaudeUnavailable) Error() string {
+ return "engineering unavailable: " + e.Err.Error()
+}
+
+func (e *ClaudeUnavailable) Unwrap() error { return e.Err }
+
+// Reason is the step reason a launch stopped by e reports.
+func (e *ClaudeUnavailable) Reason() string { return wire.ReasonEngineeringUnavailable }
+
+// ClaudeFetch opens url's body. Provision only ever asks for ClaudeURL.
+type ClaudeFetch func(ctx context.Context, url string) (io.ReadCloser, error)
+
+// ClaudeCLI is the pinned CLI under a runner's install dir. Its path is
+// handed out only by Argv and Launch, after the file there has been
+// hashed and matched, so nothing can run an unverified claude through
+// it. The zero value has no CLI: it verifies nothing and launches
+// nothing.
+type ClaudeCLI struct {
+ installDir string
+ // pin is the digest the file must have (a test pins its own bytes).
+ pin string
+ // limit bounds a download; 0 is MaxClaudeBinary.
+ limit int64
+}
+
+// NewClaudeCLI is the pinned darwin-arm64 CLI under installDir
+// (~/.local/lib/equipo-runner on a Mac).
+func NewClaudeCLI(installDir string) ClaudeCLI {
+ return ClaudeCLI{installDir: installDir, pin: claude.ExecutableSHA256DarwinArm64}
+}
+
+func (c ClaudeCLI) bound() int64 {
+ if c.limit > 0 {
+ return c.limit
+ }
+ return MaxClaudeBinary
+}
+
+// Verify hashes the CLI at its place, once, and returns its path when it
+// matches the pin: a plain file, mode 0700, reached through no symbolic
+// link from the install dir.
+func (c ClaudeCLI) Verify() (string, error) {
+ if c.installDir == "" || c.pin == "" {
+ return "", ErrClaudeUnpinned
+ }
+ d, err := openClaudeDir(c.installDir, false)
+ if err != nil {
+ return "", ErrClaudeUnpinned
+ }
+ defer d.Close()
+ if err := c.verifyIn(d); err != nil {
+ return "", err
+ }
+ return ClaudePath(c.installDir), nil
+}
+
+// Version is the pinned version while the CLI verifies, else "". It
+// runs nothing: what the capability report states about Claude Code.
+func (c ClaudeCLI) Version() string {
+ if _, err := c.Verify(); err != nil {
+ return ""
+ }
+ return provider.ClaudeVersion
+}
+
+// Argv verifies the CLI now and returns the argv that starts it: its
+// path, then args. Every start of the CLI (an Engineering attempt, an
+// ask, a token check, a sign-in, a probe launch) takes its argv from
+// here immediately before it starts, never from an earlier call. A CLI
+// that does not verify is a *ClaudeUnavailable.
+func (c ClaudeCLI) Argv(args ...string) ([]string, error) {
+ path, err := c.Verify()
+ if err != nil {
+ return nil, &ClaudeUnavailable{Err: err}
+ }
+ return append([]string{path}, args...), nil
+}
+
+// Launch verifies the CLI and hands start its argv; nothing starts when
+// it does not verify (*ClaudeUnavailable, engineering_unavailable).
+func (c ClaudeCLI) Launch(ctx context.Context, start func(ctx context.Context, argv []string) error, args ...string) error {
+ argv, err := c.Argv(args...)
+ if err != nil {
+ return err
+ }
+ return start(ctx, argv)
+}
+
+// Provision puts the pinned CLI in place unless it already verifies:
+// fetch(ClaudeURL()) is streamed into a new file beside it, mode 0600,
+// bounded by MaxClaudeBinary and hashed as it is written; only a match
+// is made 0700 and renamed into place, replacing whatever was there. A
+// refused download is removed. Every write goes through an os.Root on a
+// directory chain with no symbolic link in it.
+func (c ClaudeCLI) Provision(ctx context.Context, fetch ClaudeFetch) error {
+ if c.installDir == "" || c.pin == "" {
+ return ErrClaudeUnpinned
+ }
+ d, err := openClaudeDir(c.installDir, true)
+ if err != nil {
+ return err
+ }
+ defer d.Close()
+ removeDownloads(d)
+ if c.verifyIn(d) == nil {
+ return nil
+ }
+ body, err := fetch(ctx, ClaudeURL())
+ if err != nil {
+ return err
+ }
+ defer body.Close()
+ name, err := downloadName()
+ if err != nil {
+ return err
+ }
+ f, err := d.OpenFile(name, os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600)
+ if err != nil {
+ return err
+ }
+ placed := false
+ defer func() {
+ // A second Close of a closed file is harmless.
+ if !placed {
+ _ = f.Close()
+ _ = d.Remove(name)
+ }
+ }()
+ h := sha256.New()
+ n, err := io.Copy(io.MultiWriter(f, h), io.LimitReader(body, c.bound()+1))
+ if err != nil {
+ return err
+ }
+ if n > c.bound() || hex.EncodeToString(h.Sum(nil)) != c.pin {
+ return ErrClaudeRefused
+ }
+ // Executable only now, by its descriptor.
+ if err := f.Chmod(0700); err != nil {
+ return err
+ }
+ if err := f.Sync(); err != nil {
+ return err
+ }
+ if err := f.Close(); err != nil {
+ return err
+ }
+ if err := d.Rename(name, claudeName); err != nil {
+ return err
+ }
+ placed = true
+ return c.verifyIn(d)
+}
+
+// verifyIn hashes d/claude: a regular file, not a link, mode 0700, the
+// file opened the one examined, read once.
+func (c ClaudeCLI) verifyIn(d *os.Root) error {
+ info, err := d.Lstat(claudeName)
+ if err != nil || !info.Mode().IsRegular() || info.Mode().Perm() != 0700 || info.Size() > c.bound() {
+ return ErrClaudeUnpinned
+ }
+ f, err := d.OpenFile(claudeName, os.O_RDONLY, 0)
+ if err != nil {
+ return ErrClaudeUnpinned
+ }
+ defer f.Close()
+ if opened, err := f.Stat(); err != nil || !os.SameFile(info, opened) {
+ return ErrClaudeUnpinned
+ }
+ h := sha256.New()
+ if _, err := io.Copy(h, io.LimitReader(f, c.bound()+1)); err != nil {
+ return ErrClaudeUnpinned
+ }
+ if hex.EncodeToString(h.Sum(nil)) != c.pin {
+ return ErrClaudeUnpinned
+ }
+ return nil
+}
+
+// openClaudeDir opens ClaudeDir(installDir) as an os.Root, one component
+// at a time from the install dir, each a real directory (Lstat: never a
+// symbolic link) that no group or other user may write, and the one
+// opened the one examined. create makes a missing component 0700.
+func openClaudeDir(installDir string, create bool) (*os.Root, error) {
+ r, err := os.OpenRoot(installDir)
+ if err != nil {
+ return nil, err
+ }
+ for _, name := range claudeRel {
+ next, err := openSubdir(r, name, create)
+ r.Close()
+ if err != nil {
+ return nil, err
+ }
+ r = next
+ }
+ return r, nil
+}
+
+func openSubdir(parent *os.Root, name string, create bool) (*os.Root, error) {
+ if create {
+ if err := parent.Mkdir(name, 0700); err != nil && !errors.Is(err, fs.ErrExist) {
+ return nil, err
+ }
+ }
+ info, err := parent.Lstat(name)
+ if err != nil {
+ return nil, err
+ }
+ if !info.IsDir() || info.Mode().Perm()&0022 != 0 {
+ return nil, fmt.Errorf("%w: %s is not a private directory", ErrClaudeUnpinned, name)
+ }
+ sub, err := parent.OpenRoot(name)
+ if err != nil {
+ return nil, err
+ }
+ if opened, err := sub.Stat("."); err != nil || !os.SameFile(info, opened) {
+ sub.Close()
+ return nil, fmt.Errorf("%w: %s moved while it was opened", ErrClaudeUnpinned, name)
+ }
+ return sub, nil
+}
+
+// removeDownloads removes what an interrupted download left in d.
+func removeDownloads(d *os.Root) {
+ dir, err := d.Open(".")
+ if err != nil {
+ return
+ }
+ names, _ := dir.Readdirnames(-1)
+ dir.Close()
+ for _, n := range names {
+ if strings.HasPrefix(n, downloadPrefix) {
+ _ = d.Remove(n)
+ }
+ }
+}
+
+func downloadName() (string, error) {
+ var b [8]byte
+ if _, err := rand.Read(b[:]); err != nil {
+ return "", err
+ }
+ return downloadPrefix + hex.EncodeToString(b[:]), nil
+}
+
+// ClaudeStandInEnv names a local file that stands in for the official
+// download, in a test build only (claude_testbuild.go). A release build
+// ignores it.
+const ClaudeStandInEnv = "EQUIPO_FAKE_CLAUDE_DARWIN"
+
+// claudeTransport carries the official download (tests stand in for the
+// network with their own).
+var claudeTransport http.RoundTripper = http.DefaultTransport
+
+// claudeDownloadLimit bounds the whole download, body included.
+const claudeDownloadLimit = 30 * time.Minute
+
+// OfficialClaude is the worker's ClaudeFetch: an HTTPS GET that follows
+// no redirect and takes only 200. In a test build, ClaudeStandInEnv may
+// name a local file to serve instead; the pin still decides.
+func OfficialClaude(getenv func(string) string) ClaudeFetch {
+ if f := claudeStandIn(getenv); f != nil {
+ return f
+ }
+ return fetchOfficialClaude
+}
+
+func fetchOfficialClaude(ctx context.Context, url string) (io.ReadCloser, error) {
+ c := http.Client{Transport: claudeTransport, Timeout: claudeDownloadLimit, CheckRedirect: func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse }}
+ req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
+ if err != nil {
+ return nil, err
+ }
+ resp, err := c.Do(req)
+ if err != nil {
+ return nil, err
+ }
+ if resp.StatusCode != http.StatusOK {
+ resp.Body.Close()
+ return nil, errors.New("claude download: " + resp.Status)
+ }
+ return resp.Body, nil
+}
+
+// ClaudeRetry is the first wait after a failed provisioning, doubling to
+// ClaudeRecheck, how often a verified CLI is checked again.
+var ClaudeRetry, ClaudeRecheck = time.Minute, time.Hour
+
+// KeepClaude keeps the pinned CLI in place (spec §8.2), so the person
+// installs nothing: Provision at start, again after a failure, and every
+// ClaudeRecheck, fetching anew when it is missing or no longer matches.
+// It never runs it. refresh is called whenever it starts or stops
+// verifying, so the capability report follows. It returns with ctx.
+func KeepClaude(ctx context.Context, c ClaudeCLI, fetch ClaudeFetch, refresh func(), warn func(string, ...any)) {
+ wait, verified := ClaudeRetry, false
+ for {
+ err := c.Provision(ctx, fetch)
+ if ctx.Err() != nil {
+ return
+ }
+ next := ClaudeRecheck
+ if err != nil {
+ warn("claude code not provisioned", "version", provider.ClaudeVersion, "err", err)
+ next, wait = wait, min(wait*2, ClaudeRecheck)
+ } else {
+ wait = ClaudeRetry
+ }
+ if (err == nil) != verified {
+ verified = err == nil
+ refresh()
+ }
+ select {
+ case <-ctx.Done():
+ return
+ case <-time.After(next):
+ }
+ }
+}
diff --git a/internal/runner/mac/claude_release.go b/internal/runner/mac/claude_release.go
new file mode 100644
index 00000000..57bb46d2
--- /dev/null
+++ b/internal/runner/mac/claude_release.go
@@ -0,0 +1,9 @@
+//go:build !testbuild
+
+package mac
+
+// A release build has no stand-in: the pinned CLI comes only from its
+// official URL.
+const claudeStandInBuild = false
+
+func claudeStandIn(func(string) string) ClaudeFetch { return nil }
diff --git a/internal/runner/mac/claude_test.go b/internal/runner/mac/claude_test.go
new file mode 100644
index 00000000..8400f95e
--- /dev/null
+++ b/internal/runner/mac/claude_test.go
@@ -0,0 +1,606 @@
+package mac
+
+import (
+ "bytes"
+ "context"
+ "crypto/sha256"
+ "encoding/hex"
+ "errors"
+ "io"
+ "io/fs"
+ "net/http"
+ "os"
+ "path/filepath"
+ "slices"
+ "strings"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/runner/provider"
+ "amadan.net/oficina/equipo/internal/runner/provider/claude"
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// fakeClaude stands in for the 276 MB darwin binary: the tests check the
+// pin's handling, so a test CLI carries its own digest (claudeFor).
+func fakeClaude() []byte {
+ return bytes.Repeat([]byte("#!/bin/sh\necho fake claude 2.1.312\n"), 1024)
+}
+
+func digest(b []byte) string {
+ s := sha256.Sum256(b)
+ return hex.EncodeToString(s[:])
+}
+
+// claudeFor is the pinned CLI under installDir, pinned to body's digest.
+func claudeFor(installDir string, body []byte) ClaudeCLI {
+ return ClaudeCLI{installDir: installDir, pin: digest(body)}
+}
+
+// serve answers every fetch with body and records the URLs asked.
+func serve(body []byte, urls *[]string) ClaudeFetch {
+ return func(_ context.Context, url string) (io.ReadCloser, error) {
+ if urls != nil {
+ *urls = append(*urls, url)
+ }
+ return io.NopCloser(bytes.NewReader(body)), nil
+ }
+}
+
+func noFetch(t *testing.T) ClaudeFetch {
+ return func(context.Context, string) (io.ReadCloser, error) {
+ t.Fatal("fetched although the pinned CLI is in place")
+ return nil, errors.New("no")
+ }
+}
+
+// watched calls atEOF once, when the download has been read to its end:
+// what is on disk then is what the provisioner wrote before it decided.
+type watched struct {
+ r io.Reader
+ atEOF func()
+ n int64
+}
+
+func (w *watched) Read(p []byte) (int, error) {
+ n, err := w.r.Read(p)
+ w.n += int64(n)
+ if err == io.EOF && w.atEOF != nil {
+ w.atEOF()
+ w.atEOF = nil
+ }
+ return n, err
+}
+
+func (w *watched) Close() error { return nil }
+
+// entries are the names under dir and their modes ("" for dir itself); a
+// missing dir has none.
+func entries(t *testing.T, dir string) map[string]fs.FileMode {
+ t.Helper()
+ out := map[string]fs.FileMode{}
+ err := filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
+ if errors.Is(err, fs.ErrNotExist) && path == dir {
+ return fs.SkipDir
+ }
+ if err != nil {
+ return err
+ }
+ if path == dir {
+ return nil
+ }
+ info, err := os.Lstat(path)
+ if err != nil {
+ return err
+ }
+ rel, _ := filepath.Rel(dir, path)
+ out[filepath.ToSlash(rel)] = info.Mode()
+ return nil
+ })
+ if err != nil {
+ t.Fatal(err)
+ }
+ return out
+}
+
+// The Mac's pin is the official 2.1.312 darwin-arm64 binary (task 1, S1):
+// nothing else on darwin has one, and the Linux pins did not move.
+func TestClaudePinDarwin(t *testing.T) {
+ const want = "6b5ec691195e551b02c41df9f7d723f4ea61eaa03c2df90acefe3736f1aeb620"
+ if claude.ExecutableSHA256DarwinArm64 != want {
+ t.Fatalf("darwin pin %q", claude.ExecutableSHA256DarwinArm64)
+ }
+ if pin, ok := claude.ReleasePinFor("darwin", "arm64"); !ok || pin != want {
+ t.Fatalf("darwin/arm64: %q %v", pin, ok)
+ }
+ for _, arch := range []string{"amd64", "386", "riscv64", ""} {
+ if pin, ok := claude.ReleasePinFor("darwin", arch); ok || pin != "" {
+ t.Fatalf("darwin/%s has a pin %q", arch, pin)
+ }
+ }
+ for _, p := range []struct{ goos, goarch, pin string }{{"linux", "amd64", claude.ExecutableSHA256}, {"linux", "arm64", claude.ExecutableSHA256Arm64}} {
+ if pin, ok := claude.ReleasePinFor(p.goos, p.goarch); !ok || pin != p.pin {
+ t.Fatalf("%s/%s: %q %v", p.goos, p.goarch, pin, ok)
+ }
+ }
+ if _, ok := claude.ReleasePinFor("windows", "amd64"); ok {
+ t.Fatal("windows has a pin")
+ }
+ // The Mac worker's CLI checks against exactly that pin.
+ if got := NewClaudeCLI("/Users/u/.local/lib/equipo-runner"); got.pin != want || got.installDir != "/Users/u/.local/lib/equipo-runner" {
+ t.Fatalf("NewClaudeCLI %+v", got)
+ }
+}
+
+// One changed byte is refused before the file is ever executable, and the
+// refused download leaves nothing behind.
+func TestProvisionChecksDigestBeforeExec(t *testing.T) {
+ dir := t.TempDir()
+ body := fakeClaude()
+ bad := slices.Clone(body)
+ bad[len(bad)/2] ^= 1
+ cli := claudeFor(dir, body)
+ for _, try := range [][]byte{bad, body} {
+ var during map[string]fs.FileMode
+ fetch := func(context.Context, string) (io.ReadCloser, error) {
+ return &watched{r: bytes.NewReader(try), atEOF: func() { during = entries(t, ClaudeDir(dir)) }}, nil
+ }
+ err := cli.Provision(context.Background(), fetch)
+ if len(during) != 1 {
+ t.Fatalf("the download was not staged as one file: %v", during)
+ }
+ for name, mode := range during {
+ if mode.Perm()&0111 != 0 || !mode.IsRegular() {
+ t.Fatalf("%s is %v while it downloads, before its digest is known", name, mode)
+ }
+ }
+ if bytes.Equal(try, bad) {
+ if !errors.Is(err, ErrClaudeRefused) {
+ t.Fatalf("one changed byte: %v", err)
+ }
+ if left := entries(t, ClaudeDir(dir)); len(left) != 0 {
+ t.Fatalf("a refused download left %v", left)
+ }
+ if _, err := cli.Verify(); err == nil {
+ t.Fatal("verified after a refused download")
+ }
+ continue
+ }
+ if err != nil {
+ t.Fatalf("the pinned bytes: %v", err)
+ }
+ path, err := cli.Verify()
+ if err != nil {
+ t.Fatal(err)
+ }
+ info, err := os.Lstat(path)
+ if err != nil || info.Mode().Perm() != 0700 {
+ t.Fatalf("placed %v %v", info.Mode(), err)
+ }
+ }
+}
+
+// A 512 MB bound; written only at tools/claude-2.1.312/claude under the
+// install dir, mode 0700, through no symlink; a wrong file in place is
+// replaced, a right one is kept.
+func TestProvisionBoundsAndPlace(t *testing.T) {
+ if MaxClaudeBinary != 512<<20 {
+ t.Fatalf("bound %d", MaxClaudeBinary)
+ }
+ if got := NewClaudeCLI("/i").bound(); got != MaxClaudeBinary {
+ t.Fatalf("the worker's bound is %d", got)
+ }
+ ctx := context.Background()
+ body := fakeClaude()
+
+ t.Run("bound", func(t *testing.T) {
+ dir := t.TempDir()
+ cli := claudeFor(dir, body)
+ cli.limit = int64(len(body)) - 1
+ w := &watched{r: io.MultiReader(bytes.NewReader(body), bytes.NewReader(make([]byte, 1<<20)))}
+ if err := cli.Provision(ctx, func(context.Context, string) (io.ReadCloser, error) { return w, nil }); !errors.Is(err, ErrClaudeRefused) {
+ t.Fatalf("over the bound: %v", err)
+ }
+ if w.n > cli.limit+1 {
+ t.Fatalf("read %d bytes past a %d bound", w.n, cli.limit)
+ }
+ if left := entries(t, ClaudeDir(dir)); len(left) != 0 {
+ t.Fatalf("left %v", left)
+ }
+ cli.limit = int64(len(body))
+ if err := cli.Provision(ctx, serve(body, nil)); err != nil {
+ t.Fatalf("at the bound: %v", err)
+ }
+ })
+
+ t.Run("place", func(t *testing.T) {
+ dir := t.TempDir()
+ cli := claudeFor(dir, body)
+ if err := cli.Provision(ctx, serve(body, nil)); err != nil {
+ t.Fatal(err)
+ }
+ want := filepath.Join(dir, "tools", "claude-2.1.312", "claude")
+ if ClaudeDir(dir) != filepath.Dir(want) {
+ t.Fatalf("ClaudeDir %q", ClaudeDir(dir))
+ }
+ if path, err := cli.Verify(); err != nil || path != want {
+ t.Fatalf("Verify %q %v", path, err)
+ }
+ got := entries(t, dir)
+ wantModes := map[string]fs.FileMode{"tools": fs.ModeDir | 0700, "tools/claude-2.1.312": fs.ModeDir | 0700, "tools/claude-2.1.312/claude": 0700}
+ if len(got) != len(wantModes) {
+ t.Fatalf("wrote %v", got)
+ }
+ for name, mode := range wantModes {
+ if got[name] != mode {
+ t.Fatalf("%s is %v, want %v (all: %v)", name, got[name], mode, got)
+ }
+ }
+ // In place and right: kept, nothing fetched.
+ if err := cli.Provision(ctx, noFetch(t)); err != nil {
+ t.Fatal(err)
+ }
+ // In place and wrong: replaced.
+ if err := os.WriteFile(want, append(slices.Clone(body), '\n'), 0700); err != nil {
+ t.Fatal(err)
+ }
+ var urls []string
+ if err := cli.Provision(ctx, serve(body, &urls)); err != nil || len(urls) != 1 {
+ t.Fatalf("a wrong file: %v %v", err, urls)
+ }
+ if raw, _ := os.ReadFile(want); !bytes.Equal(raw, body) {
+ t.Fatal("the wrong file was not replaced")
+ }
+ // A download a crash left behind goes.
+ stale := filepath.Join(ClaudeDir(dir), ".claude-download-stale")
+ if err := os.WriteFile(stale, []byte("half"), 0600); err != nil {
+ t.Fatal(err)
+ }
+ if err := cli.Provision(ctx, noFetch(t)); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := os.Lstat(stale); !errors.Is(err, fs.ErrNotExist) {
+ t.Fatalf("a stale download is still there: %v", err)
+ }
+ })
+
+ t.Run("tools is a symlink", func(t *testing.T) {
+ dir, outside := t.TempDir(), t.TempDir()
+ if err := os.Symlink(outside, filepath.Join(dir, "tools")); err != nil {
+ t.Fatal(err)
+ }
+ cli := claudeFor(dir, body)
+ if err := cli.Provision(ctx, serve(body, nil)); err == nil {
+ t.Fatal("provisioned through a symlinked tools directory")
+ }
+ if left := entries(t, outside); len(left) != 0 {
+ t.Fatalf("wrote through the link: %v", left)
+ }
+ })
+
+ // os.Root alone refuses a link that leaves it; these stay inside, so
+ // only the provisioner's own refusal stops them.
+ t.Run("tools is a symlink inside the install dir", func(t *testing.T) {
+ dir := t.TempDir()
+ elsewhere := filepath.Join(dir, "elsewhere")
+ if err := os.Mkdir(elsewhere, 0700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink("elsewhere", filepath.Join(dir, "tools")); err != nil {
+ t.Fatal(err)
+ }
+ cli := claudeFor(dir, body)
+ if err := cli.Provision(ctx, serve(body, nil)); err == nil {
+ t.Fatal("provisioned through a symlinked tools directory")
+ }
+ if left := entries(t, elsewhere); len(left) != 0 {
+ t.Fatalf("wrote through the link: %v", left)
+ }
+ })
+
+ t.Run("the version directory is a symlink", func(t *testing.T) {
+ dir := t.TempDir()
+ elsewhere := filepath.Join(dir, "tools", "elsewhere")
+ if err := os.MkdirAll(elsewhere, 0700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink("elsewhere", ClaudeDir(dir)); err != nil {
+ t.Fatal(err)
+ }
+ cli := claudeFor(dir, body)
+ if err := cli.Provision(ctx, serve(body, nil)); err == nil {
+ t.Fatal("provisioned through a symlinked version directory")
+ }
+ if left := entries(t, elsewhere); len(left) != 0 {
+ t.Fatalf("wrote through the link: %v", left)
+ }
+ if _, err := cli.Verify(); err == nil {
+ t.Fatal("verified through a symlinked version directory")
+ }
+ })
+
+ t.Run("the binary is a symlink", func(t *testing.T) {
+ dir := t.TempDir()
+ cli := claudeFor(dir, body)
+ if err := cli.Provision(ctx, serve(body, nil)); err != nil {
+ t.Fatal(err)
+ }
+ // A link to a right copy beside it: never verified, replaced by a
+ // real file, the copy untouched.
+ path := ClaudePath(dir)
+ real := filepath.Join(ClaudeDir(dir), "claude.real")
+ if err := os.Rename(path, real); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Symlink("claude.real", path); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := cli.Verify(); !errors.Is(err, ErrClaudeUnpinned) {
+ t.Fatalf("a symlink verified: %v", err)
+ }
+ var urls []string
+ if err := cli.Provision(ctx, serve(body, &urls)); err != nil || len(urls) != 1 {
+ t.Fatalf("a symlink in place: %v %v", err, urls)
+ }
+ if info, err := os.Lstat(path); err != nil || !info.Mode().IsRegular() {
+ t.Fatalf("still a link: %v %v", info, err)
+ }
+ if raw, err := os.ReadFile(real); err != nil || !bytes.Equal(raw, body) {
+ t.Fatalf("the link's target changed: %v", err)
+ }
+ })
+}
+
+// roundTrip stands in for the network: nothing in a test leaves the
+// machine.
+type roundTrip func(*http.Request) (*http.Response, error)
+
+func (f roundTrip) RoundTrip(r *http.Request) (*http.Response, error) { return f(r) }
+
+// The URL comes from the version and platform constants; the official
+// source is an HTTPS GET of it that follows no redirect; a local file
+// stands in only in a test build.
+func TestProvisionOnlyFromTheOfficialURL(t *testing.T) {
+ const official = "https://downloads.claude.ai/claude-code-releases/2.1.312/darwin-arm64/claude"
+ if ClaudeURL() != official || ClaudeURL() != ClaudeReleaseBase+"/"+provider.ClaudeVersion+"/"+ClaudePlatform+"/claude" {
+ t.Fatalf("ClaudeURL %q", ClaudeURL())
+ }
+ ctx := context.Background()
+ body := fakeClaude()
+ var urls []string
+ if err := claudeFor(t.TempDir(), body).Provision(ctx, serve(body, &urls)); err != nil || !slices.Equal(urls, []string{official}) {
+ t.Fatalf("asked %v: %v", urls, err)
+ }
+
+ defer func(was http.RoundTripper) { claudeTransport = was }(claudeTransport)
+ var asked []string
+ status, location := http.StatusOK, ""
+ claudeTransport = roundTrip(func(r *http.Request) (*http.Response, error) {
+ asked = append(asked, r.Method+" "+r.URL.String())
+ h, code := http.Header{}, status
+ if r.URL.String() != official {
+ // A redirect's target answers, so a client that follows one
+ // shows here as a second request rather than looping.
+ code = http.StatusOK
+ } else if location != "" {
+ h.Set("Location", location)
+ }
+ return &http.Response{StatusCode: code, Header: h, Body: io.NopCloser(bytes.NewReader(body)), Request: r}, nil
+ })
+ local := filepath.Join(t.TempDir(), "claude")
+ if err := os.WriteFile(local, body, 0600); err != nil {
+ t.Fatal(err)
+ }
+ getenv := func(k string) string {
+ if k == ClaudeStandInEnv {
+ return local
+ }
+ return ""
+ }
+ if err := claudeFor(t.TempDir(), body).Provision(ctx, OfficialClaude(getenv)); err != nil {
+ t.Fatal(err)
+ }
+ if claudeStandInBuild {
+ if len(asked) != 0 {
+ t.Fatalf("a test build with a stand-in fetched %v", asked)
+ }
+ } else if !slices.Equal(asked, []string{"GET " + official}) {
+ t.Fatalf("a release build asked %v, the stand-in must be ignored", asked)
+ }
+
+ // The official source itself: no redirect followed, 200 only.
+ none := func(string) string { return "" }
+ asked, status, location = nil, http.StatusFound, "https://elsewhere.example/claude"
+ if err := claudeFor(t.TempDir(), body).Provision(ctx, OfficialClaude(none)); err == nil || !slices.Equal(asked, []string{"GET " + official}) {
+ t.Fatalf("a redirect: %v %v", err, asked)
+ }
+ asked, status, location = nil, http.StatusNotFound, ""
+ if err := claudeFor(t.TempDir(), body).Provision(ctx, OfficialClaude(none)); err == nil || len(asked) != 1 {
+ t.Fatalf("a 404: %v %v", err, asked)
+ }
+}
+
+// The launcher hashes the CLI again before each launch: a file swapped
+// after a launch stops the next one with engineering_unavailable, and
+// nothing starts.
+func TestVerifyBeforeEveryLaunch(t *testing.T) {
+ dir := t.TempDir()
+ body := fakeClaude()
+ cli := claudeFor(dir, body)
+ if err := cli.Provision(context.Background(), serve(body, nil)); err != nil {
+ t.Fatal(err)
+ }
+ var started [][]string
+ start := func(_ context.Context, argv []string) error {
+ started = append(started, argv)
+ return nil
+ }
+ for range 2 {
+ if err := cli.Launch(context.Background(), start, "-p", "--output-format", "stream-json"); err != nil {
+ t.Fatal(err)
+ }
+ }
+ want := []string{ClaudePath(dir), "-p", "--output-format", "stream-json"}
+ if len(started) != 2 || !slices.Equal(started[0], want) || !slices.Equal(started[1], want) {
+ t.Fatalf("started %v", started)
+ }
+ unavailable := func(err error) bool {
+ var u *ClaudeUnavailable
+ return errors.As(err, &u) && u.Reason() == wire.ReasonEngineeringUnavailable
+ }
+ // Swapped in place, same size and mode, one byte changed.
+ swapped := slices.Clone(body)
+ swapped[0] ^= 1
+ next := ClaudePath(dir) + ".next"
+ if err := os.WriteFile(next, swapped, 0700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Rename(next, ClaudePath(dir)); err != nil {
+ t.Fatal(err)
+ }
+ if err := cli.Launch(context.Background(), start); !unavailable(err) {
+ t.Fatalf("a swapped CLI: %v", err)
+ }
+ if _, err := cli.Argv("--version"); !unavailable(err) {
+ t.Fatalf("Argv of a swapped CLI: %v", err)
+ }
+ // None in place at all, or no CLI configured: the same stop.
+ if err := os.Remove(ClaudePath(dir)); err != nil {
+ t.Fatal(err)
+ }
+ if err := cli.Launch(context.Background(), start); !unavailable(err) {
+ t.Fatalf("a missing CLI: %v", err)
+ }
+ if err := (ClaudeCLI{}).Launch(context.Background(), start); !unavailable(err) {
+ t.Fatalf("no CLI: %v", err)
+ }
+ if len(started) != 2 {
+ t.Fatalf("started an unverified CLI: %v", started)
+ }
+}
+
+// The capability report runs no claude at all: it states the pinned
+// version only while the pinned file verifies.
+func TestDiscoveryNeverRunsUnpinnedClaude(t *testing.T) {
+ dir := t.TempDir()
+ body := fakeClaude()
+ cli := claudeFor(dir, body)
+ var ran []string
+ x := func(ctx context.Context, name string, args ...string) (string, error) {
+ ran = append(ran, strings.Join(append([]string{name}, args...), " "))
+ return recordedExec(t)(ctx, name, args...)
+ }
+ tools := Tools{Xcodebuild: "xcodebuild", Xcrun: "xcrun", Swift: "swift", Node: "node", SRT: "srt", Claude: cli}
+ if c := Capabilities(context.Background(), x, tools); c.Harness.Claude != "" {
+ t.Fatalf("claimed %q with nothing provisioned", c.Harness.Claude)
+ }
+ if err := cli.Provision(context.Background(), serve(body, nil)); err != nil {
+ t.Fatal(err)
+ }
+ c := Capabilities(context.Background(), x, tools)
+ if c.Harness.Claude != provider.ClaudeVersion || slices.Contains(c.Tags, wire.TagClaude) {
+ t.Fatalf("verified: harness %q tags %v", c.Harness.Claude, c.Tags)
+ }
+ if err := os.WriteFile(ClaudePath(dir), append(slices.Clone(body), 0), 0700); err != nil {
+ t.Fatal(err)
+ }
+ if c := Capabilities(context.Background(), x, tools); c.Harness.Claude != "" {
+ t.Fatalf("claimed %q for a changed file", c.Harness.Claude)
+ }
+ if len(ran) == 0 {
+ t.Fatal("the recorder saw nothing")
+ }
+ for _, cmd := range ran {
+ if strings.Contains(cmd, "claude") {
+ t.Fatalf("discovery ran %q", cmd)
+ }
+ }
+}
+
+// The worker keeps the pinned CLI itself: fetched from the official URL
+// only, again after a failure (warned, nothing claimed), refreshed when
+// it starts verifying, fetched anew when it is swapped, never run.
+func TestKeepClaude(t *testing.T) {
+ defer func(r, c time.Duration) { ClaudeRetry, ClaudeRecheck = r, c }(ClaudeRetry, ClaudeRecheck)
+ ClaudeRetry, ClaudeRecheck = time.Millisecond, time.Millisecond
+ dir := t.TempDir()
+ body := fakeClaude()
+ cli := claudeFor(dir, body)
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ var urls, warned, versions []string
+ fetch := func(_ context.Context, url string) (io.ReadCloser, error) {
+ urls = append(urls, url)
+ switch len(urls) {
+ case 1, 2:
+ if v := cli.Version(); v != "" {
+ t.Errorf("claimed %q before any fetch succeeded", v)
+ }
+ return nil, errors.New("offline")
+ case 4:
+ cancel()
+ }
+ return io.NopCloser(bytes.NewReader(body)), nil
+ }
+ refresh := func() {
+ versions = append(versions, cli.Version())
+ // Swapped once it verified: found at the next check.
+ if err := os.WriteFile(ClaudePath(dir), append(slices.Clone(body), 1), 0700); err != nil {
+ t.Error(err)
+ }
+ }
+ done := make(chan struct{})
+ go func() {
+ KeepClaude(ctx, cli, fetch, refresh, func(msg string, _ ...any) { warned = append(warned, msg) })
+ close(done)
+ }()
+ select {
+ case <-done:
+ case <-time.After(10 * time.Second):
+ t.Fatal("KeepClaude did not stop with its context")
+ }
+ if len(urls) != 4 || slices.ContainsFunc(urls, func(u string) bool { return u != ClaudeURL() }) {
+ t.Fatalf("asked %v", urls)
+ }
+ if len(warned) != 2 || !slices.Equal(versions, []string{provider.ClaudeVersion}) {
+ t.Fatalf("warned %v versions %v", warned, versions)
+ }
+ if cli.Version() != provider.ClaudeVersion {
+ t.Fatal("the swapped CLI was not fetched again")
+ }
+}
+
+// Env-gated, run on docs-t1 with task 1's download (never executed: it
+// is a darwin binary): the official 2.1.312 darwin-arm64 build matches
+// the compiled pin and provisions as the Mac would.
+func TestClaudeDarwinBinaryMatchesPin(t *testing.T) {
+ path := os.Getenv("EQUIPO_CLAUDE_DARWIN_BINARY")
+ if path == "" {
+ t.Skip("EQUIPO_CLAUDE_DARWIN_BINARY not set")
+ }
+ f, err := os.Open(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer f.Close()
+ h := sha256.New()
+ if _, err := io.Copy(h, f); err != nil {
+ t.Fatal(err)
+ }
+ if got := hex.EncodeToString(h.Sum(nil)); got != claude.ExecutableSHA256DarwinArm64 {
+ t.Fatalf("%s is %s, the pin is %s", path, got, claude.ExecutableSHA256DarwinArm64)
+ }
+ dir := t.TempDir()
+ cli := NewClaudeCLI(dir)
+ var urls []string
+ fetch := func(_ context.Context, url string) (io.ReadCloser, error) {
+ urls = append(urls, url)
+ return os.Open(path)
+ }
+ if err := cli.Provision(context.Background(), fetch); err != nil || !slices.Equal(urls, []string{ClaudeURL()}) {
+ t.Fatalf("provision: %v %v", err, urls)
+ }
+ if cli.Version() != "2.1.312" {
+ t.Fatal("the provisioned binary does not verify")
+ }
+}
diff --git a/internal/runner/mac/claude_testbuild.go b/internal/runner/mac/claude_testbuild.go
new file mode 100644
index 00000000..f0f585f9
--- /dev/null
+++ b/internal/runner/mac/claude_testbuild.go
@@ -0,0 +1,23 @@
+//go:build testbuild
+
+package mac
+
+import (
+ "context"
+ "io"
+ "os"
+ "path/filepath"
+)
+
+// In a test build only, ClaudeStandInEnv may name a local file that
+// stands in for the official download (no test reaches the network).
+// What it serves is still checked against the pin.
+const claudeStandInBuild = true
+
+func claudeStandIn(getenv func(string) string) ClaudeFetch {
+ path := getenv(ClaudeStandInEnv)
+ if !filepath.IsAbs(path) {
+ return nil
+ }
+ return func(context.Context, string) (io.ReadCloser, error) { return os.Open(path) }
+}
diff --git a/internal/runner/provider/claude/pins.go b/internal/runner/provider/claude/pins.go
index a2db6154..cf9e368b 100644
--- a/internal/runner/provider/claude/pins.go
+++ b/internal/runner/provider/claude/pins.go
@@ -8,10 +8,10 @@ package claude
// machine.
const ExecutableSHA256Arm64 = "dc4af28917455e009d26704b82a438353a06149e825b6cdf782908b2d28661f5"
-// ReleasePin returns the digest of the official 2.1.312 binary built for
-// goarch: the certified pin on amd64, the arm64 build's on arm64. A test
-// hands it runtime.GOARCH to check the binary on the machine it runs on.
-// ok is false where there is no pinned build.
+// ReleasePin returns the digest of the official 2.1.312 Linux binary
+// built for goarch: the certified pin on amd64, the arm64 build's on
+// arm64. A test hands it runtime.GOARCH to check the binary on the
+// machine it runs on. ok is false where there is no pinned build.
func ReleasePin(goarch string) (pin string, ok bool) {
switch goarch {
case "amd64":
@@ -21,3 +21,27 @@ func ReleasePin(goarch string) (pin string, ok bool) {
}
return "", false
}
+
+// ExecutableSHA256DarwinArm64 is the official 2.1.312 darwin-arm64
+// binary, the one Claude Code a Mac worker runs (Mac runners spec §8.2).
+// Read on docs-t1 on 2026-11-28 (slice F task 1, S1): the release
+// manifest's darwin-arm64 checksum, and the sha256 of the 275988512
+// bytes downloaded from the official URL. The manifest is not trusted at
+// runtime; this constant is.
+const ExecutableSHA256DarwinArm64 = "6b5ec691195e551b02c41df9f7d723f4ea61eaa03c2df90acefe3736f1aeb620"
+
+// ReleasePinFor returns the digest of the official 2.1.312 binary for
+// goos/goarch: the certified linux/amd64 pin, the linux/arm64 test pin,
+// and darwin/arm64's. ok is false everywhere else, darwin/amd64
+// included: a Mac worker runs only the darwin/arm64 build.
+func ReleasePinFor(goos, goarch string) (pin string, ok bool) {
+ switch goos {
+ case "linux":
+ return ReleasePin(goarch)
+ case "darwin":
+ if goarch == "arm64" {
+ return ExecutableSHA256DarwinArm64, true
+ }
+ }
+ return "", false
+}
diff --git a/internal/runner/thin/mac.go b/internal/runner/thin/mac.go
index e7fcb547..f9720352 100644
--- a/internal/runner/thin/mac.go
+++ b/internal/runner/thin/mac.go
@@ -13,6 +13,7 @@ import (
"os"
"os/exec"
"path/filepath"
+ "runtime"
"slices"
"strconv"
"strings"
@@ -431,6 +432,8 @@ type macHost struct {
capsLogged atomic.Bool
// turns lets one gate at a time run (mac.Turns).
turns *mac.Turns
+ // fetchClaude fetches the pinned Claude Code (mac.OfficialClaude).
+ fetchClaude mac.ClaudeFetch
// warmMu guards warmed, the Xcode (version and build) whose plugin
// cache was last warmed.
warmMu sync.Mutex
@@ -473,6 +476,10 @@ func (h *macHost) warm(ctx context.Context, x wire.Xcode) {
h.warmed = key
}
+// claudeHere: only a darwin/arm64 worker provisions the pinned Claude
+// Code (the only darwin pin). Tests on Linux never fetch it.
+var claudeHere = runtime.GOOS == "darwin" && runtime.GOARCH == "arm64"
+
// slowCommand is how long a command the Mac worker runs may take before
// it is logged as slow: while it still runs, so a hung child shows.
var slowCommand = 10 * time.Second
@@ -483,7 +490,8 @@ var slowCommand = 10 * time.Second
var commandWaitDelay = 5 * time.Second
// Mac tool discovery (spec §3.3): EQUIPO_SRT_PATH and the installer's
-// private srt first, then the usual places.
+// private srt first, then the usual places. Claude Code is not
+// discovered: no EQUIPO_CLAUDE_PATH, no claude on a path (spec §8.2).
func macTools(installDir, home string, getenv func(string) string) mac.Tools {
dirs := []string{filepath.Join(installDir, "srt", "node_modules", ".bin"), filepath.Join(home, ".local", "bin"), "/opt/homebrew/bin", "/usr/local/bin", "/usr/bin"}
pinned := mac.PinnedTools(installDir)
@@ -503,7 +511,9 @@ func macTools(installDir, home string, getenv func(string) string) mac.Tools {
return ""
}
return mac.Tools{Xcodebuild: "/usr/bin/xcodebuild", Xcrun: "/usr/bin/xcrun", Swift: "/usr/bin/swift", Git: getenv("EQUIPO_GIT_PATH"),
- SRT: find("EQUIPO_SRT_PATH", "srt"), Node: find("EQUIPO_NODE_PATH", "node"), RG: find("EQUIPO_RG_PATH", "rg"), Claude: find("EQUIPO_CLAUDE_PATH", "claude"), Codex: find("EQUIPO_CODEX_PATH", "codex")}
+ SRT: find("EQUIPO_SRT_PATH", "srt"), Node: find("EQUIPO_NODE_PATH", "node"), RG: find("EQUIPO_RG_PATH", "rg"), Codex: find("EQUIPO_CODEX_PATH", "codex"),
+ // Never looked up: the pinned CLI the worker provisions itself.
+ Claude: mac.NewClaudeCLI(installDir)}
}
func executable(p string) bool {
@@ -643,6 +653,7 @@ func newMacHost(c runner.Config, o Options) (h *macHost, err error) {
others, err := mac.OtherHomes(macUsers, home)
h.paths = mac.Paths{Home: home, StateDir: c.StateDir, AccountsRoot: accounts, SessionRoot: SessionRoot(c), InstallDir: filepath.Dir(c.Executable), OtherHomes: others, HomesUnknown: err != nil}
h.tools = macTools(h.paths.InstallDir, home, getenv)
+ h.fetchClaude = mac.OfficialClaude(getenv)
h.env = []string{"HOME=" + home, "PATH=" + gatePath(h.tools), "CI=1", "LANG=en_US.UTF-8"}
// One turn for every gate and the warm, across this user's runner
// processes (the worker and the probe command).
@@ -837,6 +848,9 @@ func serveMac(ctx context.Context, c runner.Config, o Options, h *macHost) error
h.taint.changed = refresh
h.probes.start(ctx, refresh)
go h.probes.watch(ctx)
+ if claudeHere {
+ go mac.KeepClaude(ctx, h.tools.Claude, h.fetchClaude, refresh, h.warn)
+ }
},
welcomed: func(w wire.Welcome, worker *Worker, stop context.CancelCauseFunc) {
if w.Tainted {
diff --git a/internal/runner/thin/mac_claude_test.go b/internal/runner/thin/mac_claude_test.go
new file mode 100644
index 00000000..a451d992
--- /dev/null
+++ b/internal/runner/thin/mac_claude_test.go
@@ -0,0 +1,42 @@
+package thin
+
+import (
+ "os"
+ "path/filepath"
+ "reflect"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/runner/mac"
+)
+
+// Discovery on a Mac finds no claude: not EQUIPO_CLAUDE_PATH, not one on
+// the usual paths. The only Claude Code a Mac worker knows is the pinned
+// one under its install dir, which it verifies and never looks up.
+func TestMacToolsNeverFindAClaude(t *testing.T) {
+ root := t.TempDir()
+ install, home := filepath.Join(root, "lib"), filepath.Join(root, "home")
+ planted := []string{filepath.Join(root, "env", "claude"), filepath.Join(home, ".local", "bin", "claude")}
+ for _, p := range planted {
+ if err := os.MkdirAll(filepath.Dir(p), 0700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(p, []byte("#!/bin/sh\necho 2.1.312\n"), 0700); err != nil {
+ t.Fatal(err)
+ }
+ }
+ env := map[string]string{"EQUIPO_CLAUDE_PATH": planted[0]}
+ tools := macTools(install, home, func(k string) string { return env[k] })
+ v := reflect.ValueOf(tools)
+ for i := range v.NumField() {
+ if f := v.Field(i); f.Kind() == reflect.String {
+ for _, p := range planted {
+ if f.String() == p {
+ t.Fatalf("Tools.%s is the unpinned %s", v.Type().Field(i).Name, p)
+ }
+ }
+ }
+ }
+ if tools.Claude != mac.NewClaudeCLI(install) || tools.Claude.Version() != "" {
+ t.Fatalf("Tools.Claude %+v", tools.Claude)
+ }
+}
diff --git a/internal/runner/thin/startup_logs_test.go b/internal/runner/thin/startup_logs_test.go
index 16264388..4761ed84 100644
--- a/internal/runner/thin/startup_logs_test.go
+++ b/internal/runner/thin/startup_logs_test.go
@@ -147,7 +147,6 @@ func TestWorkerStartupLogs(t *testing.T) {
`level=INFO msg="capabilities gathering"`,
`level=INFO msg=command cmd=/usr/bin/xcodebuild args=-version took=`,
`level=INFO msg=command cmd=` + env["EQUIPO_NODE_PATH"] + ` args=--version took=`,
- `level=INFO msg=command cmd=` + env["EQUIPO_CLAUDE_PATH"] + ` args=--version took=`,
`level=INFO msg="capabilities gathered" took=`,
`level=INFO msg="hello sent" protocol=`,
`level=INFO msg=welcome protocol=2 role=worker generation=1`,
@@ -165,6 +164,10 @@ func TestWorkerStartupLogs(t *testing.T) {
}
at++
}
+ // The claude planted at EQUIPO_CLAUDE_PATH is never run (spec §8.2).
+ if strings.Contains(out, env["EQUIPO_CLAUDE_PATH"]) {
+ t.Fatalf("an unpinned claude ran:\n%s", out)
+ }
// The dial failure: the error and the wait before the next try.
if !strings.Contains(out, "503") || !strings.Contains(out, "retry_in=") {
t.Fatalf("the dial failure says neither why nor when:\n%s", out)