//go:build testbuild package thin import ( "context" "log/slog" "path/filepath" "testing" "time" "amadan.net/oficina/equipo/internal/runner/mac" "amadan.net/oficina/equipo/internal/runnerproto" "amadan.net/oficina/equipo/internal/wire" ) // CI fix (hosted run on 5da6f1fb, M9c): the connections' hourly refresh // of the Mac's one Claude connection took the account's lock and then // waited, inside its refresh (the darwin auth status), for the Mac's // turn, while the fix round held that turn and waited for the lock: the // round gave up after LockWait with provider_account_busy, ending // account_unavailable. Here that refresh starts exactly while a step // holds the turn, before it opens its account: the step must run. func TestWorkerRefreshNeverHoldsTheAccountForTheTurn(t *testing.T) { x := newEngRig(t) x.note("edit:Swipe.swift|false|true") wc := openWorkerConns(x.cfg, Options{Claude: x.opts, Logger: slog.New(slog.NewTextHandler(&x.logs, nil))}, x.state, runnerproto.RunnerCredential{}, x.m, func() {}, func() {}) if err := wc.conns.load(context.Background()); err != nil { t.Fatal(err) } b, ok := x.binding(filepath.Base(x.homes[0])) if !ok { t.Fatal("no binding") } refreshed := make(chan struct{}) started := false ready := x.w.Eng.Status x.w.Eng.Status = func(ctx context.Context) *wire.EngineeringStatus { if u, free := x.m.turns.TryTake(mac.OpCheck); free { u.Give() } else if !started { // The step holds the turn and has not opened its account yet. started = true go func() { wc.conns.checkOne(context.Background(), b); close(refreshed) }() time.Sleep(500 * time.Millisecond) } return ready(ctx) } rep := x.run(t) if !started { t.Fatal("the refresh never started inside the step's turn") } if rep.State != wire.StepDone || rep.CandidateSHA == "" { t.Fatalf("a refresh waiting for the turn failed the step: %+v", rep) } select { case <-refreshed: case <-time.After(time.Minute): t.Fatal("the refresh never ran after the step") } }