//go:build testbuild package thin import ( "os" "os/exec" "path/filepath" "testing" "amadan.net/oficina/equipo/internal/fakeclaude" ) // Whole-branch fix 1, #1: a credential watch clears only by the // Executor's proof (Verify), which a reboot satisfies only boot- // qualified: another kern.bootsessionuuid and a later boot time. A clock // stepped forward moves kern.boottime past the watch's start with the // same boot identity: the watch, the hold and the closed connections // stay. func TestDarwinWatchHeldWhenOnlyTheClockMoves(t *testing.T) { r := newDarwinRig(t) local, _ := connected(t, r, fakeclaude.Token("a@example.com")) if err := os.WriteFile(filepath.Join(r.dir, "hang"), nil, 0o600); err != nil { t.Fatal(err) } helper := exec.Command(os.Args[0], "-test.run=^TestDarwinTokenCheckCrashHelper$", "-test.count=1") helper.Env = append(os.Environ(), "EQUIPO_DARWIN_CRASH_DIR="+r.dir, "EQUIPO_DARWIN_CRASH_LOCAL="+local) if err := helper.Start(); err != nil { t.Fatal(err) } pid := waitPid(t, filepath.Join(r.dir, "hang.pid")) _ = helper.Process.Kill() _ = helper.Wait() // What its CLI stored meanwhile. r.creating("-p ", r.own) r.kc.mu.Lock() delete(r.kc.created, pid) r.kc.mu.Unlock() r.connector() if !r.m.Held() || len(unprovenOf(r.m)) != 1 { t.Fatalf("after the crash: held=%v unproven=%v", r.m.Held(), unprovenOf(r.m)) } r.clockForward(t) r.connector() r.m.settle(r.ctx, true) if !r.m.Held() || len(unprovenOf(r.m)) != 1 || len(r.kc.deleted) != 0 { t.Fatalf("the clock moved forward, no reboot: held=%v unproven=%v deleted %+v", r.m.Held(), unprovenOf(r.m), r.kc.deleted) } b, _ := r.binding(local) if _, err := r.opts.CheckToken(r.ctx, b); err == nil { t.Fatal("a check ran with the watch held") } r.rebooted(t, pid) r.connector() if r.m.Held() || len(r.kc.deleted) != 1 { t.Fatalf("after a reboot: held=%v deleted %+v", r.m.Held(), r.kc.deleted) } }