Mac slice F task 10 fix 3: unreadable watches close; recorded run pinned
After the final review (controller: both findings right, no fourth round): 1. creds Keychain.Unproven returns the records listing's error. Gate refuses and caps say credential_unproven on an error as well as on an unproven watch. Regressions: TestKeychainUnprovenUnreadable and TestDarwinUnreadableWatchesStayClosed (no token stored, status kept). 2. TestDarwinClearanceVerifiesTheRecordedRun: a live recorded group with nothing marked, and a boot before the watch, is not cleared. It kills mutation R4 (Verify by the marker alone), which survived round 2. Mutations R4, U1, U1t, U2 and U3 were all killed. The thin test budget was re-measured at 28115.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7 files changed,
+132
−20
.rastrillo/budgets.txt+1 −1internal/runner/mac/creds/keychain.go+8 −4internal/runner/mac/creds/keychain_test.go+37 −6internal/runner/thin/mac.go+1 −1internal/runner/thin/maccreds.go+1 −1internal/runner/thin/maccreds_fix1_test.go+3 −3internal/runner/thin/maccreds_fix2_test.go+81 −4
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index f2641e6b..d6b0558f 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 31482 28038 Protocols 31 to 35, merge credential, publication guards, kept work, scans, Mac pin, paths, bases, endpoint, Mac turns, Mac credentials; measured 31482/28038. |
| +size internal/runner/thin 31482 28115 Protocols 31 to 35, merge credential, publication guards, kept work, scans, Mac pin, paths, bases, endpoint, Mac turns, Mac credentials; measured 31482/28115. |
| 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 45s Real processes killed and proven gone: groups, sessions, the runner-user sweep, turns, restarts; probes end to end. Measured 29.3s locally. |
| 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/creds/keychain.go b/internal/runner/mac/creds/keychain.go| index c3a6adbf..b11a21ac 100644 |
| --- a/internal/runner/mac/creds/keychain.go |
| +++ b/internal/runner/mac/creds/keychain.go |
| @@ -269,9 +269,13 @@ func (k *Keychain) Abandon(marker string) { |
| } |
| // Unproven are the watches whose launch's end is not proven and that no |
| -// launch here still runs: each keeps the Mac's connections closed. |
| -func (k *Keychain) Unproven() []string { |
| - names, _ := k.names() |
| +// launch here still runs: each keeps the Mac's connections closed. An |
| +// error (the records cannot be listed) must close them too. |
| +func (k *Keychain) Unproven() ([]string, error) { |
| + names, err := k.names() |
| + if err != nil { |
| + return nil, err |
| + } |
| var out []string |
| for _, name := range names { |
| rec, err := k.load(name) |
| @@ -282,7 +286,7 @@ func (k *Keychain) Unproven() []string { |
| out = append(out, name) |
| } |
| } |
| - return out |
| + return out, nil |
| } |
| // existingRecord names the record of CLI items found already there. |
diff --git a/internal/runner/mac/creds/keychain_test.go b/internal/runner/mac/creds/keychain_test.go| index 79b6247e..294b653d 100644 |
| --- a/internal/runner/mac/creds/keychain_test.go |
| +++ b/internal/runner/mac/creds/keychain_test.go |
| @@ -475,26 +475,26 @@ func TestKeychainWatchUnproven(t *testing.T) { |
| if err := k.Ran("signin-1", "pg:4242:signin-1"); err != nil { |
| t.Fatal(err) |
| } |
| - if len(k.Unproven()) != 0 { |
| + if len(unproven(k)) != 0 { |
| t.Fatal("a running watch is unproven") |
| } |
| k.Abandon("signin-1") |
| - if !slices.Equal(k.Unproven(), []string{"signin-1"}) || !k.Held() { |
| - t.Fatalf("an abandoned watch: %v held=%v", k.Unproven(), k.Held()) |
| + if !slices.Equal(unproven(k), []string{"signin-1"}) || !k.Held() { |
| + t.Fatalf("an abandoned watch: %v held=%v", unproven(k), k.Held()) |
| } |
| if err := k.Settle(ctx, false, func(Watch) bool { return true }); err != nil || !k.Held() { |
| t.Fatal("settled without a restart") |
| } |
| restarted := &Keychain{Dir: k.Dir, Login: login, User: "paulequipo", List: f.list, Delete: f.delete} |
| - if !slices.Equal(restarted.Unproven(), []string{"signin-1"}) { |
| - t.Fatalf("after a restart: %v", restarted.Unproven()) |
| + if !slices.Equal(unproven(restarted), []string{"signin-1"}) { |
| + t.Fatalf("after a restart: %v", unproven(restarted)) |
| } |
| var asked Watch |
| _ = restarted.Settle(ctx, true, func(w Watch) bool { asked = w; return false }) |
| if asked.Run != "pg:4242:signin-1" || asked.Started.Before(before) || asked.Started.After(time.Now()) || !restarted.Held() { |
| t.Fatalf("asked %+v", asked) |
| } |
| - if err := restarted.Settle(ctx, true, func(Watch) bool { return true }); err != nil || restarted.Held() || len(restarted.Unproven()) != 0 { |
| + if err := restarted.Settle(ctx, true, func(Watch) bool { return true }); err != nil || restarted.Held() || len(unproven(restarted)) != 0 { |
| t.Fatalf("once ended: %v held=%v", err, restarted.Held()) |
| } |
| } |
| @@ -505,3 +505,34 @@ func TestBootTime(t *testing.T) { |
| t.Fatalf("boot %v %v", boot, err) |
| } |
| } |
| + |
| +// unproven is k's unproven watches ("?" for an error). |
| +func unproven(k *Keychain) []string { |
| + left, err := k.Unproven() |
| + if err != nil { |
| + return []string{"?"} |
| + } |
| + return left |
| +} |
| + |
| +// TestKeychainUnprovenUnreadable (fix round 3, #1): records that cannot |
| +// be listed are an error, never "none unproven". |
| +func TestKeychainUnprovenUnreadable(t *testing.T) { |
| + ctx := context.Background() |
| + f := &fakeKeychain{} |
| + k := newWatch(t, f) |
| + if err := k.Before(ctx, "signin-1", configDir); err != nil { |
| + t.Fatal(err) |
| + } |
| + k.Abandon("signin-1") |
| + if err := os.Chmod(k.Dir, 0); err != nil { |
| + t.Fatal(err) |
| + } |
| + defer os.Chmod(k.Dir, 0o700) |
| + if left, err := k.Unproven(); err == nil { |
| + t.Fatalf("unreadable records read as %v", left) |
| + } |
| + if !k.Held() { |
| + t.Fatal("unreadable records released the hold") |
| + } |
| +} |
diff --git a/internal/runner/thin/mac.go b/internal/runner/thin/mac.go| index 6c8c83b0..6d4b4462 100644 |
| --- a/internal/runner/thin/mac.go |
| +++ b/internal/runner/thin/mac.go |
| @@ -774,7 +774,7 @@ func (h *macHost) credentialCaps(ctx context.Context, caps *wire.Capabilities) { |
| if h.creds.Held() { |
| h.creds.settle(ctx, false) |
| } |
| - if len(h.creds.keychain.Unproven()) > 0 { |
| + if left, err := h.creds.keychain.Unproven(); err != nil || len(left) > 0 { |
| // Said before an incomplete attempt record: it closes the Mac's |
| // connections, and a restart of the Mac clears it. |
| caps.Unproven = wire.UnprovenCredential |
diff --git a/internal/runner/thin/maccreds.go b/internal/runner/thin/maccreds.go| index a875b206..2cc623ad 100644 |
| --- a/internal/runner/thin/maccreds.go |
| +++ b/internal/runner/thin/maccreds.go |
| @@ -192,7 +192,7 @@ func (m *macCreds) Gate() error { |
| if m.taint.Tainted() { |
| return errTainted |
| } |
| - if len(m.keychain.Unproven()) > 0 { |
| + if left, err := m.keychain.Unproven(); err != nil || len(left) > 0 { |
| return errCredentialUnproven |
| } |
| if r := m.guard(); !r.OK() { |
diff --git a/internal/runner/thin/maccreds_fix1_test.go b/internal/runner/thin/maccreds_fix1_test.go| index dcb6964f..7b3b8767 100644 |
| --- a/internal/runner/thin/maccreds_fix1_test.go |
| +++ b/internal/runner/thin/maccreds_fix1_test.go |
| @@ -197,8 +197,8 @@ func TestDarwinCheckUnprovenIsNotSuccess(t *testing.T) { |
| r := newDarwinRig(t) |
| local, home := connected(t, r, fakeclaude.Token("a@example.com")) |
| r.lingering(t, "auth") |
| - if _, err := r.m.authStatus(r.ctx, statusBinding(local, home)); !errors.Is(err, mac.ErrUnproven) || !r.m.Held() || len(r.m.keychain.Unproven()) != 1 { |
| - t.Fatalf("an unproven auth status: %v held=%v unproven=%v", err, r.m.Held(), r.m.keychain.Unproven()) |
| + if _, err := r.m.authStatus(r.ctx, statusBinding(local, home)); !errors.Is(err, mac.ErrUnproven) || !r.m.Held() || len(unprovenOf(r.m)) != 1 { |
| + t.Fatalf("an unproven auth status: %v held=%v unproven=%v", err, r.m.Held(), unprovenOf(r.m)) |
| } |
| }) |
| } |
| @@ -295,7 +295,7 @@ func TestDarwinSignInUnprovenKeepsTheWatch(t *testing.T) { |
| r.waitFor(func() bool { return r.turnFree() }, "the sign-in to stop") |
| var state string |
| _ = r.state.db.QueryRow("SELECT state FROM connect_attempts WHERE id='s1'").Scan(&state) |
| - if !r.m.Held() || state != "running" || len(r.m.keychain.Unproven()) != 1 { |
| + if !r.m.Held() || state != "running" || len(unprovenOf(r.m)) != 1 { |
| t.Fatalf("an unproven sign-in: held=%v state=%s", r.m.Held(), state) |
| } |
| } |
diff --git a/internal/runner/thin/maccreds_fix2_test.go b/internal/runner/thin/maccreds_fix2_test.go| index bbdcb7a7..cc93cebf 100644 |
| --- a/internal/runner/thin/maccreds_fix2_test.go |
| +++ b/internal/runner/thin/maccreds_fix2_test.go |
| @@ -14,6 +14,7 @@ import ( |
| "time" |
| "amadan.net/oficina/equipo/internal/fakeclaude" |
| + "amadan.net/oficina/equipo/internal/runner/mac" |
| "amadan.net/oficina/equipo/internal/runner/mac/creds" |
| "amadan.net/oficina/equipo/internal/wire" |
| ) |
| @@ -82,8 +83,8 @@ func TestDarwinCrashedWatchHeldUntilReboot(t *testing.T) { |
| } |
| defer func() { _ = survivor.Wait() }() |
| r.connector() |
| - if !r.m.Held() || len(r.m.keychain.Unproven()) != 1 { |
| - t.Fatalf("the restart let go of a launch it could not prove ended: held=%v unproven=%v", r.m.Held(), r.m.keychain.Unproven()) |
| + if !r.m.Held() || len(unprovenOf(r.m)) != 1 { |
| + t.Fatalf("the restart let go of a launch it could not prove ended: held=%v unproven=%v", r.m.Held(), unprovenOf(r.m)) |
| } |
| b, _ := r.binding(local) |
| if _, err := r.opts.CheckToken(r.ctx, b); !errors.Is(err, errCredentialUnproven) { |
| @@ -103,8 +104,8 @@ func TestDarwinCrashedWatchHeldUntilReboot(t *testing.T) { |
| } |
| r.rebooted() |
| r.m.settle(r.ctx, true) |
| - if r.kc.has(item) || len(r.m.keychain.Unproven()) != 0 { |
| - t.Fatalf("after a reboot: item kept=%v unproven=%v", r.kc.has(item), r.m.keychain.Unproven()) |
| + if r.kc.has(item) || len(unprovenOf(r.m)) != 0 { |
| + t.Fatalf("after a reboot: item kept=%v unproven=%v", r.kc.has(item), unprovenOf(r.m)) |
| } |
| r.m.settle(r.ctx, false) |
| if r.m.Held() { |
| @@ -146,3 +147,79 @@ func TestDarwinUnprovenClosesConnections(t *testing.T) { |
| t.Fatalf("after the restart proved it over: %v", err) |
| } |
| } |
| + |
| +// unprovenOf is m's unproven watches ("?" for an error). |
| +func unprovenOf(m *macCreds) []string { |
| + left, err := m.keychain.Unproven() |
| + if err != nil { |
| + return []string{"?"} |
| + } |
| + return left |
| +} |
| + |
| +// TestDarwinUnreadableWatchesStayClosed (fix round 3, #1): with an |
| +// unproven launch on record and the watch records unreadable, no token |
| +// is stored and the Mac still says credential_unproven. |
| +func TestDarwinUnreadableWatchesStayClosed(t *testing.T) { |
| + r := newDarwinRig(t) |
| + c := r.connector() |
| + home, _ := r.paste(c, "c1", fakeclaude.Token("a@example.com")) |
| + b, _ := r.binding(filepath.Base(home)) |
| + r.lingering(t, "-p") |
| + if _, err := r.opts.CheckToken(r.ctx, b); err == nil { |
| + t.Fatal("an unproven check passed") |
| + } |
| + if err := os.Chmod(r.m.keychain.Dir, 0); err != nil { |
| + t.Fatal(err) |
| + } |
| + defer os.Chmod(r.m.keychain.Dir, 0o700) |
| + if _, end := r.paste(c, "c2", fakeclaude.Token("b@example.com")); end.Reason != "provider_refused" || r.seals("c2") != 0 { |
| + t.Fatalf("a token stored with the watch records unreadable: %+v seals=%d", end, r.seals("c2")) |
| + } |
| + h := &macHost{creds: r.m, taint: r.m.taint, turns: r.m.turns} |
| + caps := wire.Capabilities{} |
| + h.credentialCaps(r.ctx, &caps) |
| + if caps.Unproven != wire.UnprovenCredential { |
| + t.Fatalf("caps %+v", caps.Unproven) |
| + } |
| +} |
| + |
| +// TestDarwinClearanceVerifiesTheRecordedRun (fix round 3, #2): a watch |
| +// whose launch's recorded group is still alive, with nothing in it |
| +// carrying the marker (a child that scrubbed its environment), and the |
| +// Mac booted before the watch began, is not cleared: Verify judges the |
| +// recorded run, group and all, not the marker alone. Once the group is |
| +// gone it clears. |
| +func TestDarwinClearanceVerifiesTheRecordedRun(t *testing.T) { |
| + r := newDarwinRig(t) |
| + marker := "status-scrubbed" |
| + if err := r.m.keychain.Before(r.ctx, marker, filepath.Join(r.cfg.ScratchRoot, "homes", marker)); err != nil { |
| + t.Fatal(err) |
| + } |
| + group := exec.Command("/bin/sleep", "60") |
| + group.Env = []string{} |
| + group.SysProcAttr = &syscall.SysProcAttr{Setsid: true} |
| + if err := group.Start(); err != nil { |
| + t.Fatal(err) |
| + } |
| + waited := make(chan struct{}) |
| + go func() { _ = group.Wait(); close(waited) }() |
| + defer func() { _ = group.Process.Kill(); <-waited }() |
| + if err := r.m.keychain.Ran(marker, mac.RecordID(group.Process.Pid, marker)); err != nil { |
| + t.Fatal(err) |
| + } |
| + r.m.keychain.Abandon(marker) |
| + if boot, err := r.m.boot(); err != nil || !boot.Before(time.Now()) { |
| + t.Fatalf("boot %v %v", boot, err) |
| + } |
| + r.m.settle(r.ctx, true) |
| + if !r.m.Held() || len(unprovenOf(r.m)) != 1 || !pidAlive(group.Process.Pid) { |
| + t.Fatalf("cleared with its recorded group alive: held=%v unproven=%v", r.m.Held(), unprovenOf(r.m)) |
| + } |
| + _ = group.Process.Kill() |
| + <-waited |
| + r.m.settle(r.ctx, true) |
| + if r.m.Held() || len(unprovenOf(r.m)) != 0 { |
| + t.Fatalf("held once its group is gone: %v", unprovenOf(r.m)) |
| + } |
| +} |