diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index ba103fb61..0dce1d288 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -180,13 +180,26 @@ jobs: # agentop builds on Windows (#1520). Most of its tests drive a Unix shell, a service # manager or signals, so only the tests of the Windows-specific code and of commands - # that work there run here for now. + # that work there run here for now. `go test -run` passes when a name matches nothing, + # so each listed name must also have run: a renamed test fails the step instead of + # silently dropping out. Every entry is a full test name, matched exactly, not a prefix + # that stands for several tests. - name: Build, vet and test cmd/agentop working-directory: cmd/agentop run: | + set -euo pipefail go build ./... go vet ./... - go test -run 'TestRefuseUnsupported|TestProcessAlive|TestLockFile|TestWritable|TestTerminateRefusesOnWindows|TestNoRecordWanted|TestWithRecordOff|TestAddRecordOff' . + tests="TestRefuseUnsupported TestProcessAlive TestLockFile TestWritable TestTerminateRefusesOnWindows + TestNoRecordWanted TestWithRecordOff + TestAddRecordOff_RefusesASettingsOverride TestAddRecordOff_AppendsToTheEnvironment + TestAddRecordOff_RefusesAnUnreadableSettingsFile TestAddRecordOff_ChecksClaudeConfigDir + TestAddRecordOff_RefusesAChildThatIsNotClaudeCode" + go test -v -run "^($(echo ${tests} | tr ' ' '|'))\$" . | tee "${RUNNER_TEMP}/agentop-tests.txt" + for t in ${tests}; do + grep -qE "^--- (PASS|SKIP): ${t} \(" "${RUNNER_TEMP}/agentop-tests.txt" \ + || { echo "::error::${t} did not run"; exit 1; } + done # The cpex plugin's FFI-backed code sits behind the `cpex` build tag and needs # cgo plus the pinned libcpex_ffi.a, so no other job compiles or tests it. It diff --git a/cmd/agentop/cmd_doctor_checks_test.go b/cmd/agentop/cmd_doctor_checks_test.go index dbe8fea03..22a7c3b50 100644 --- a/cmd/agentop/cmd_doctor_checks_test.go +++ b/cmd/agentop/cmd_doctor_checks_test.go @@ -224,7 +224,7 @@ func TestDoctorChecksABackgroundInstallWhoseProxyIsGone(t *testing.T) { t.Fatal("setup --no-service left no proxy.pid") } killAndReap(pid) - if alive(pid) { + if processAlive(pid) { t.Fatalf("fixture: pid %d is still alive", pid) } writeHomeFile(t, pidFile, c.pidfile(pid)) diff --git a/cmd/agentop/cmd_uninstall.go b/cmd/agentop/cmd_uninstall.go index 3961343d0..319443ac1 100644 --- a/cmd/agentop/cmd_uninstall.go +++ b/cmd/agentop/cmd_uninstall.go @@ -1344,7 +1344,7 @@ func stopIfAlive(pid int) error { if pid <= 0 { return nil } - if err := stopPID(pid); err != nil && alive(pid) { + if err := stopPID(pid); err != nil && processAlive(pid) { return err } return nil diff --git a/cmd/agentop/cmd_uninstall_test.go b/cmd/agentop/cmd_uninstall_test.go index f10a9711a..2348c0080 100644 --- a/cmd/agentop/cmd_uninstall_test.go +++ b/cmd/agentop/cmd_uninstall_test.go @@ -359,7 +359,7 @@ func TestUninstallStopsABackgroundCortex(t *testing.T) { stopProcessOnCleanup(t, &pid) sc.setUp(t, "--no-service") pidFile := filepath.Join(sc.home, ".cortex", "proxy.pid") - if pid = readPIDFile(pidFile); !alive(pid) { + if pid = readPIDFile(pidFile); !processAlive(pid) { t.Fatal("fixture: setup --no-service left no live proxy") } // ps names the stub's sleep as cortex, as it names the real background proxy. @@ -369,7 +369,7 @@ func TestUninstallStopsABackgroundCortex(t *testing.T) { if row := consentRow(out, "stop and remove"); !strings.Contains(row, " the background Cortex ") || !strings.HasSuffix(row, " ~/.cortex/proxy.pid") { t.Errorf("the consent row is %q, want the background Cortex and its pidfile", row) } - if alive(pid) { + if processAlive(pid) { t.Errorf("the background Cortex (pid %d) is still running", pid) } if _, err := os.Stat(pidFile); !os.IsNotExist(err) { diff --git a/cmd/agentop/setup_prior_test.go b/cmd/agentop/setup_prior_test.go index 60caa6dbe..047fb0a12 100644 --- a/cmd/agentop/setup_prior_test.go +++ b/cmd/agentop/setup_prior_test.go @@ -87,7 +87,7 @@ func detachedSleeperAt(t *testing.T, path string) int { // ranFrom reports whether pid is alive and was started as path, by ps's argv[0]. func ranFrom(pid int, path string) bool { - if !alive(pid) { + if !processAlive(pid) { return false } out, err := exec.Command("ps", "-p", strconv.Itoa(pid), "-o", "args=").Output() @@ -231,7 +231,7 @@ func TestSetupStopsAPreRenameBackgroundProxyAndRestartsItOnRollback(t *testing.T if code != 1 { t.Errorf("a failed run exited %d", code) } - if alive(newPID) { + if processAlive(newPID) { t.Error("the rollback left the new cortex running") } if !ranFrom(restarted, filepath.Join(bin, "authbridge-proxy")) || restarted == old { @@ -496,7 +496,7 @@ func TestSetupRollbackRestartsTheBackgroundCortexBesideAStoppedService(t *testin running := filepath.Join(t.TempDir(), "running") sc := newSetupScene(t, func(w http.ResponseWriter, _ *http.Request) { _, err := os.Stat(running) - if err != nil && !alive(readPIDFile(filepath.Join(os.Getenv("HOME"), ".cortex", "proxy.pid"))) { + if err != nil && !processAlive(readPIDFile(filepath.Join(os.Getenv("HOME"), ".cortex", "proxy.pid"))) { w.WriteHeader(http.StatusServiceUnavailable) } }) diff --git a/cmd/agentop/setup_probe.go b/cmd/agentop/setup_probe.go index 9cd31a93d..b641c4eb5 100644 --- a/cmd/agentop/setup_probe.go +++ b/cmd/agentop/setup_probe.go @@ -208,8 +208,6 @@ func ourProxy(binDir, pidFile string, pid int, exe string) bool { return samePath(exe, filepath.Join(binDir, proxyBinary)) || samePath(exe, filepath.Join(binDir, preRenameBinary)) } -func alive(pid int) bool { return processAlive(pid) } - // psComm is ps's comm for pid, and whether ps answered at all. func psComm(pid int) (string, bool) { out, err := exec.Command("ps", "-o", "comm=", "-p", strconv.Itoa(pid)).Output() @@ -221,7 +219,7 @@ func psComm(pid int) (string, bool) { // and ps either cannot see it (sandbox-blind) or calls it cortex. func proxyRunning(pidFile string) (int, bool) { pid := readPIDFile(pidFile) - if !alive(pid) { + if !processAlive(pid) { return 0, false } comm, seen := psComm(pid) @@ -236,7 +234,7 @@ func proxyRunning(pidFile string) (int, bool) { // background proxy. proxyRunning does not count it: ps does not call it cortex. func preRenameProxyRunning(binDir, pidFile string) (int, bool) { pid := readPIDFile(pidFile) - if !alive(pid) { + if !processAlive(pid) { return 0, false } exe := setupPIDExePath(pid) @@ -250,7 +248,7 @@ func preRenameProxyRunning(binDir, pidFile string) (int, bool) { // process ps cannot name, which may still re-exec a pre-rename binary. func pidfileProcessUnnamed(pidFile string) bool { pid := readPIDFile(pidFile) - if !alive(pid) { + if !processAlive(pid) { return false } _, seen := psComm(pid) diff --git a/cmd/agentop/setup_step_service.go b/cmd/agentop/setup_step_service.go index 4bf525cb7..d283f83ea 100644 --- a/cmd/agentop/setup_step_service.go +++ b/cmd/agentop/setup_step_service.go @@ -364,7 +364,7 @@ func (s serviceStep) apply(env *setupEnv, act *checklist.Running) (string, undo, // once it is gone: a failure before the stop leaves it running, and a second copy // would take proxy.pid from it. Asked up to a minute after the stop, so a live pid // that now runs something else is gone too. - case adopt > 0 && (!alive(adopt) || setupPIDExePath(adopt) != adoptSeen): + case adopt > 0 && (!processAlive(adopt) || setupPIDExePath(adopt) != adoptSeen): env.priorDesc = "the previous background Cortex is running again" env.priorManual = startByHand(env, adoptExe) env.restorePrior = func() error { @@ -459,7 +459,7 @@ func (serviceStep) applyUnsupervised(env *setupEnv) (string, undo, error) { err = se } u := undo{label: "the background proxy", fn: func() error { - if alive(pid) { + if processAlive(pid) { if err := stopPID(pid); err != nil { return err } diff --git a/cmd/agentop/setup_step_service_test.go b/cmd/agentop/setup_step_service_test.go index 7b533b90f..749e5162a 100644 --- a/cmd/agentop/setup_step_service_test.go +++ b/cmd/agentop/setup_step_service_test.go @@ -201,7 +201,7 @@ func TestServiceStepUnsupervisedRestoreNamesItsStartByHand(t *testing.T) { if err != nil { t.Fatal(err) } - if alive(old) { + if processAlive(old) { t.Fatal("fixture: the step did not stop the background proxy") } want := "sh -c 'nohup ~/.local/bin/cortex --local --supervise >> ~/.cortex/proxy.log 2>&1 & echo $! > ~/.cortex/proxy.pid'" @@ -217,7 +217,7 @@ func TestServiceStepUnsupervisedRestoreNamesItsStartByHand(t *testing.T) { func stopProcessOnCleanup(t *testing.T, pid *int) { t.Helper() t.Cleanup(func() { - if alive(*pid) { + if processAlive(*pid) { killAndReap(*pid) } }) @@ -250,7 +250,7 @@ func TestServiceStepRunsUnsupervisedInASandbox(t *testing.T) { if err != nil { t.Fatal(err) } - if !alive(pid) { + if !processAlive(pid) { t.Fatal("no background proxy") } if u.manual != "kill $(cat ~/.cortex/proxy.pid)" { @@ -259,7 +259,7 @@ func TestServiceStepRunsUnsupervisedInASandbox(t *testing.T) { if err := u.fn(); err != nil { t.Fatal(err) } - if alive(pid) { + if processAlive(pid) { t.Error("undo left the background proxy running") return } @@ -611,7 +611,7 @@ func TestSupervisedHolderWhenPsCannotNameTheParent(t *testing.T) { t.Fatal(err) } if got := supervisedHolder(pidFile, 31337); got != tc.want { - t.Errorf("proxy.pid %d alive=%v: supervisedHolder = %v, want %v", tc.pf, alive(tc.pf), got, tc.want) + t.Errorf("proxy.pid %d alive=%v: supervisedHolder = %v, want %v", tc.pf, processAlive(tc.pf), got, tc.want) } } } @@ -924,8 +924,8 @@ func TestServiceStepBackgroundRestoreRefusesBesideALoadedUnhealthyJob(t *testing t.Fatalf("plan = %+v %v", p, prob) } _, u, err := serviceStep{}.apply(env, nil) - if err == nil || alive(old) || env.restorePrior == nil { - t.Fatalf("fixture: apply = %v, background proxy alive %v, restorePrior set %v", err, alive(old), env.restorePrior != nil) + if err == nil || processAlive(old) || env.restorePrior == nil { + t.Fatalf("fixture: apply = %v, background proxy alive %v, restorePrior set %v", err, processAlive(old), env.restorePrior != nil) } failingUnload(t, loaded) if err := u.fn(); err == nil { @@ -969,8 +969,8 @@ func TestStartByHandRunsFromAShell(t *testing.T) { stopProcessOnCleanup(t, &pid) waitStarted() log, _ := os.ReadFile(filepath.Join(env.cortexDir, "proxy.log")) - if !alive(pid) || !strings.Contains(string(log), "started --local --supervise") { - t.Errorf("%s: proxy.pid %d alive=%v, proxy.log %q", sh, pid, alive(pid), log) + if !processAlive(pid) || !strings.Contains(string(log), "started --local --supervise") { + t.Errorf("%s: proxy.pid %d alive=%v, proxy.log %q", sh, pid, processAlive(pid), log) } } }