Skip to content

Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.

test(computer): stop daemon tests from waiting out production deadlines

shoudi zhengfa4e5e84a328
diff --git a/apps/computer/local-daemon/internal/daemon/operation_prepare.go b/apps/computer/local-daemon/internal/daemon/operation_prepare.go
index c8ae0c29..97731722 100644
--- a/apps/computer/local-daemon/internal/daemon/operation_prepare.go
+++ b/apps/computer/local-daemon/internal/daemon/operation_prepare.go
@@ -19,7 +19,7 @@ import (
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/provider/redact"
)
-const (
+var (
operationMCPPrepareTimeout = 3 * time.Second
operationMCPCleanupLimit = 3 * time.Second
)
diff --git a/apps/computer/local-daemon/internal/daemon/operation_prepare_test.go b/apps/computer/local-daemon/internal/daemon/operation_prepare_test.go
index 1efba288..8514a0c4 100644
--- a/apps/computer/local-daemon/internal/daemon/operation_prepare_test.go
+++ b/apps/computer/local-daemon/internal/daemon/operation_prepare_test.go
@@ -479,6 +479,8 @@ func TestOperationPrepareUnadoptedNativeFenceExpires(t *testing.T) {
func testUnadoptedPreparationExpires(t *testing.T, backend *prepareBackend) {
t.Helper()
+ // The ready but unadopted preparation reaches its speculative deadline.
+ shortenForTest(t, &operationMCPPrepareTimeout, 500*time.Millisecond)
d, stream, command := prepareDaemonFixture(t, backend)
if err := d.handleOperationPrepare(t.Context(), stream, command); err != nil {
t.Fatal(err)
@@ -504,6 +506,8 @@ func testUnadoptedPreparationExpires(t *testing.T, backend *prepareBackend) {
}
func TestOperationStartOwnsPrepareBeyondSpeculativeDeadline(t *testing.T) {
+ // The speculative deadline passes after start adopts the preparation.
+ shortenForTest(t, &operationMCPPrepareTimeout, 500*time.Millisecond)
release := make(chan struct{})
backend := &prepareBackend{prepareStarted: make(chan struct{}), blockPrepare: true, prepareRelease: release}
d, stream, prepare := prepareDaemonFixture(t, backend)
@@ -699,6 +703,8 @@ func TestOperationStartRevalidatesAssignmentAfterPrepareWait(t *testing.T) {
}
func TestOperationStartFallsBackOnlyAfterPrepareDeadlineAndCleanup(t *testing.T) {
+ // The unadopted preparation reaches its speculative deadline.
+ shortenForTest(t, &operationMCPPrepareTimeout, 500*time.Millisecond)
backend := &prepareBackend{prepareStarted: make(chan struct{}), blockPrepare: true}
d, stream, prepare := prepareDaemonFixture(t, backend)
startedAt := time.Now()
@@ -731,6 +737,9 @@ func TestOperationStartFallsBackOnlyAfterPrepareDeadlineAndCleanup(t *testing.T)
}
func TestPreparedOperationCleanupTimeoutDoesNotAuthorizeFallback(t *testing.T) {
+ // Both the speculative prepare deadline and the cleanup limit expire.
+ shortenForTest(t, &operationMCPPrepareTimeout, 500*time.Millisecond)
+ shortenForTest(t, &operationMCPCleanupLimit, 300*time.Millisecond)
release := make(chan struct{})
backend := &prepareBackend{
prepareStarted: make(chan struct{}),
diff --git a/apps/computer/local-daemon/internal/daemon/test_stores_test.go b/apps/computer/local-daemon/internal/daemon/test_stores_test.go
index 43000d73..96683671 100644
--- a/apps/computer/local-daemon/internal/daemon/test_stores_test.go
+++ b/apps/computer/local-daemon/internal/daemon/test_stores_test.go
@@ -2,11 +2,22 @@ package daemon
import (
"testing"
+ "time"
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/linger/assignment"
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/linger/registration"
)
+// shortenForTest lowers a package duration for one test and restores it in
+// t.Cleanup. Overriding a package variable is safe only because no test in
+// this package calls t.Parallel.
+func shortenForTest(t *testing.T, v *time.Duration, d time.Duration) {
+ t.Helper()
+ previous := *v
+ *v = d
+ t.Cleanup(func() { *v = previous })
+}
+
// newTestDaemon fills the stores a test leaves unset with fresh ones.
func newTestDaemon(t testing.TB, options Options) (*Daemon, error) {
t.Helper()
diff --git a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
index 51089d6d..8956947b 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/localtools_test.go
@@ -27,6 +27,16 @@ import (
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/provider"
)
+// shortenForTest lowers a package duration for one test and restores it in
+// t.Cleanup. Overriding a package variable is safe only because no test in
+// this package calls t.Parallel.
+func shortenForTest(t *testing.T, v *time.Duration, d time.Duration) {
+ t.Helper()
+ previous := *v
+ *v = d
+ t.Cleanup(func() { *v = previous })
+}
+
func TestLocalToolOperationPropagatesChildCleanupFailure(t *testing.T) {
reader, writer := io.Pipe()
defer reader.Close()
diff --git a/apps/computer/local-daemon/internal/linger/localtools/native_browser.go b/apps/computer/local-daemon/internal/linger/localtools/native_browser.go
index 728412be..29573048 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/native_browser.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/native_browser.go
@@ -20,6 +20,15 @@ import (
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/process"
)
+var (
+ // nativeBrowserCloseLimit bounds a whole browser close, including the
+ // process-tree fallback.
+ nativeBrowserCloseLimit = 10 * time.Second
+ // nativeBrowserGracefulCloseLimit bounds waiting for Browser.close to end
+ // the process before the process-tree fallback.
+ nativeBrowserGracefulCloseLimit = 2 * time.Second
+)
+
type nativeBrowser struct {
endpoint string
webSocketEndpoint string
@@ -179,9 +188,9 @@ func (b *nativeBrowser) close() error {
// A process-group signal can kill Chrome's Network Service before its
// Cookie store flushes. Ask the owned browser to exit first, then retain
// the original whole-tree termination and ten-second cleanup boundary.
- ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+ ctx, cancel := context.WithTimeout(context.Background(), nativeBrowserCloseLimit)
defer cancel()
- graceful, stopGraceful := context.WithTimeout(ctx, 2*time.Second)
+ graceful, stopGraceful := context.WithTimeout(ctx, nativeBrowserGracefulCloseLimit)
b.closeGracefully(graceful)
stopGraceful()
select {
diff --git a/apps/computer/local-daemon/internal/linger/localtools/native_browser_close_unix_test.go b/apps/computer/local-daemon/internal/linger/localtools/native_browser_close_unix_test.go
index 480ec5e9..a330acb0 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/native_browser_close_unix_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/native_browser_close_unix_test.go
@@ -137,6 +137,8 @@ func TestNativeBrowserCloseFlushesBeforeProcessGroupSignal(t *testing.T) {
}
func TestNativeBrowserCloseDoesNotTreatCDPReplyOrEOFAsExit(t *testing.T) {
+ // The peer never exits on Browser.close, so the graceful wait expires.
+ shortenForTest(t, &nativeBrowserGracefulCloseLimit, 200*time.Millisecond)
for _, mode := range []string{"ack-without-exit", "eof"} {
t.Run(mode, func(t *testing.T) {
f := newBrowserCloseFixture(t, mode)
@@ -166,6 +168,10 @@ func TestNativeBrowserCloseDoesNotTreatCDPReplyOrEOFAsExit(t *testing.T) {
}
func TestNativeBrowserReadinessFailureRetainsUnknownProcess(t *testing.T) {
+ // The stop is suppressed, so both the graceful wait and the whole close
+ // bound expire.
+ shortenForTest(t, &nativeBrowserGracefulCloseLimit, 200*time.Millisecond)
+ shortenForTest(t, &nativeBrowserCloseLimit, 400*time.Millisecond)
f := newBrowserCloseFixture(t, "ack-without-exit")
f.suppressStop.Store(true)
m := &Manager{browsers: map[string]*nativeBrowser{}}
diff --git a/apps/computer/local-daemon/internal/provider/native/codex_exit_unix_test.go b/apps/computer/local-daemon/internal/provider/native/codex_exit_unix_test.go
index 2a706a36..68bec13d 100644
--- a/apps/computer/local-daemon/internal/provider/native/codex_exit_unix_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/codex_exit_unix_test.go
@@ -6,6 +6,7 @@ import (
"path/filepath"
"strings"
"testing"
+ "time"
)
func TestCodexExternalLeaderExit(t *testing.T) {
@@ -19,6 +20,10 @@ func TestCodexExternalLeaderExit(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
fake := newCodexFake(t, []codexFakeTurn{{Die: tc.die}}, nil)
+ // The sleeper grandchild outlives the leader, and in one case holds
+ // stdout, so a stop grace expires; newCodexFake's cleanup restores
+ // the grace.
+ codexStopGrace.set(300 * time.Millisecond)
receipt := filepath.Join(fake.root, "pids")
fake.env["FAKE_GRANDCHILD"] = receipt
if tc.holdStdout {
diff --git a/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go b/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go
index e4ec818c..659a2180 100644
--- a/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go
@@ -162,6 +162,9 @@ func TestCodexStartupStallKillsTree(t *testing.T) {
for _, method := range []string{"initialize", "thread/start"} {
t.Run(method, func(t *testing.T) {
fake := newCodexFake(t, nil, nil)
+ // The fake never answers the stall, so each stop step waits out its
+ // grace; newCodexFake's cleanup restores the grace.
+ codexStopGrace.set(300 * time.Millisecond)
receipt := filepath.Join(fake.root, "pids")
fake.env["FAKE_STALL"], fake.env["FAKE_GRANDCHILD"] = method, receipt
spec := fake.spec()
@@ -180,6 +183,9 @@ func TestCodexStartupFailureKeepsSecretsOut(t *testing.T) {
for _, variant := range []string{"startup", "budget"} {
t.Run(variant, func(t *testing.T) {
fake := newCodexFake(t, nil, map[string]string{"FAKE_STDERR": "env " + secret, "FAKE_STALL": "initialize"})
+ // The fake never answers the stall, so each stop step waits out its
+ // grace; newCodexFake's cleanup restores the grace.
+ codexStopGrace.set(300 * time.Millisecond)
var log codexTestLog
spec := fake.spec()
if variant == "startup" {
@@ -238,6 +244,9 @@ func TestCodexInitializeCancelUnconfirmed(t *testing.T) {
func TestCodexInitializeTimeoutRetriesOnce(t *testing.T) {
fake := newCodexFake(t, nil, map[string]string{"FAKE_STALL": "initialize"})
+ // The fake never answers the stall, so each stop step waits out its
+ // grace; newCodexFake's cleanup restores the grace.
+ codexStopGrace.set(300 * time.Millisecond)
var log codexTestLog
spec := fake.spec()
spec.StartupBudget = 100 * time.Millisecond
diff --git a/apps/computer/local-daemon/internal/provider/native/pi_finish.go b/apps/computer/local-daemon/internal/provider/native/pi_finish.go
index 12360207..dac22f5a 100644
--- a/apps/computer/local-daemon/internal/provider/native/pi_finish.go
+++ b/apps/computer/local-daemon/internal/provider/native/pi_finish.go
@@ -12,10 +12,11 @@ import (
const (
piStatusCancelled = "cancelled"
piStartupBudget = 30 * time.Second
- piAbortBudget = 2 * time.Second
piProbeBudget = 2 * time.Second
)
+var piAbortBudget = 2 * time.Second
+
// drive runs the startup exchange, waits for the turn to settle, then parks
// the process or stops it, and delivers the single Outcome.
func (t *piTurn) drive(prompt string) {
diff --git a/apps/computer/local-daemon/internal/provider/native/pi_process.go b/apps/computer/local-daemon/internal/provider/native/pi_process.go
index 31d94be9..fe14e223 100644
--- a/apps/computer/local-daemon/internal/provider/native/pi_process.go
+++ b/apps/computer/local-daemon/internal/provider/native/pi_process.go
@@ -19,8 +19,9 @@ import (
"github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/process"
)
+var piExitWait = 3 * time.Second
+
const (
- piExitWait = 3 * time.Second
piTermWait = time.Second
piGroupGrace = 100 * time.Millisecond
piGroupConfirmWait = 3 * time.Second
diff --git a/apps/computer/local-daemon/internal/provider/native/pi_resident_test.go b/apps/computer/local-daemon/internal/provider/native/pi_resident_test.go
index faa9bbd6..32f5d9ef 100644
--- a/apps/computer/local-daemon/internal/provider/native/pi_resident_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/pi_resident_test.go
@@ -150,6 +150,9 @@ func piAwaitGone(t *testing.T, proc *piProcess) {
// Scenario 56.
func TestPiResidentReuseAcrossTurns(t *testing.T) {
+ // The fake hangs at exit, so the stop's stdin-close wait expires. Restore
+ // the wait only after the resident stop in the home's cleanup.
+ shortenForTest(t, &piExitWait, 200*time.Millisecond)
h := piNewResidentHome(t, map[string]string{piResidentExitHangEnv: "1"})
proc := h.createParked("reuse-session", RunSpec{})
if piProcessGone(proc.pid) {
diff --git a/apps/computer/local-daemon/internal/provider/native/pi_runtime_test.go b/apps/computer/local-daemon/internal/provider/native/pi_runtime_test.go
index 98d7cb9d..35ae59a6 100644
--- a/apps/computer/local-daemon/internal/provider/native/pi_runtime_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/pi_runtime_test.go
@@ -397,6 +397,10 @@ func TestPiInputUnderPipePressure(t *testing.T) {
})
}
t.Run("blocked", func(t *testing.T) {
+ // The blocked fake answers neither abort nor stdin close, so both
+ // waits expire before the stop escalates to signals.
+ shortenForTest(t, &piAbortBudget, 200*time.Millisecond)
+ shortenForTest(t, &piExitWait, 200*time.Millisecond)
h := piNewHarness(t, "blocked", nil)
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
diff --git a/apps/computer/local-daemon/internal/provider/native/resident_table_test.go b/apps/computer/local-daemon/internal/provider/native/resident_table_test.go
index 516af3d1..e045a5a3 100644
--- a/apps/computer/local-daemon/internal/provider/native/resident_table_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/resident_table_test.go
@@ -25,6 +25,16 @@ func withResidentCap[P residentProcess](t *testing.T, table *residentTable[P], l
t.Cleanup(func() { table.setCap(previous) })
}
+// shortenForTest lowers a package duration for one test and restores it in
+// t.Cleanup. Overriding a package variable is safe only because no test in
+// this package calls t.Parallel.
+func shortenForTest(t *testing.T, v *time.Duration, d time.Duration) {
+ t.Helper()
+ previous := *v
+ *v = d
+ t.Cleanup(func() { *v = previous })
+}
+
// holdsPrestart reports whether a live, non-retiring prestart of any
// provider is parked.
func holdsPrestart() bool {
diff --git a/apps/computer/local-daemon/internal/provider/native/version.go b/apps/computer/local-daemon/internal/provider/native/version.go
index 5d75a7fe..ee6cc9e5 100644
--- a/apps/computer/local-daemon/internal/provider/native/version.go
+++ b/apps/computer/local-daemon/internal/provider/native/version.go
@@ -154,7 +154,7 @@ func CodexSupportsPermissionHook(version string) bool {
return stableCodexAtLeast(version, codexPermissionHookVersion)
}
-const versionProbePipeBudget = 2 * time.Second
+var versionProbePipeBudget = 2 * time.Second
// versionProbeBudget bounds one ProbeVersion call; tests lower it.
var versionProbeBudget = 10 * time.Second
diff --git a/apps/computer/local-daemon/internal/provider/native/version_unix_test.go b/apps/computer/local-daemon/internal/provider/native/version_unix_test.go
index b7ddcf89..5f0461f9 100644
--- a/apps/computer/local-daemon/internal/provider/native/version_unix_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/version_unix_test.go
@@ -40,13 +40,16 @@ func TestProbeVersionWithDescendants(t *testing.T) {
cases := []struct {
name, body string
budget time.Duration
+ pipeBudget time.Duration
wantToken string
wantWaitErr bool
}{
- {"delayed answer", `(sleep 0.05; echo "fixture-cli 2.3.4") & echo "$$ $!" > "$RECEIPT"` + "\n", 0, "2.3.4", false},
- {"answer, open pipe", `echo "fixture-cli 2.3.4"; sleep 30 & echo "$$ $!" > "$RECEIPT"` + "\n", 0, "2.3.4", false},
- {"banner, open pipe", `echo "starting plugins"; sleep 30 & echo "$$ $!" > "$RECEIPT"` + "\n", 0, "", true},
- {"no answer", `sleep 30 & echo "$$ $!" > "$RECEIPT"; wait` + "\n", 150 * time.Millisecond, "", false},
+ // The delayed answer arrives after the leader exits, inside the pipe budget.
+ {"delayed answer", `(sleep 0.05; echo "fixture-cli 2.3.4") & echo "$$ $!" > "$RECEIPT"` + "\n", 0, 0, "2.3.4", false},
+ // A descendant holds the pipe open until the pipe budget expires.
+ {"answer, open pipe", `echo "fixture-cli 2.3.4"; sleep 30 & echo "$$ $!" > "$RECEIPT"` + "\n", 0, 200 * time.Millisecond, "2.3.4", false},
+ {"banner, open pipe", `echo "starting plugins"; sleep 30 & echo "$$ $!" > "$RECEIPT"` + "\n", 0, 200 * time.Millisecond, "", true},
+ {"no answer", `sleep 30 & echo "$$ $!" > "$RECEIPT"; wait` + "\n", 150 * time.Millisecond, 0, "", false},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
@@ -54,9 +57,10 @@ func TestProbeVersionWithDescendants(t *testing.T) {
receipt := filepath.Join(dir, "pids")
program := writeExecutable(t, dir, "fixture-cli", "#!/bin/sh\n"+tc.body)
if tc.budget > 0 {
- previous := versionProbeBudget
- versionProbeBudget = tc.budget
- defer func() { versionProbeBudget = previous }()
+ shortenForTest(t, &versionProbeBudget, tc.budget)
+ }
+ if tc.pipeBudget > 0 {
+ shortenForTest(t, &versionProbePipeBudget, tc.pipeBudget)
}
// A wrapper shell avoids the first-exec scan of a new executable,
// which can outlast the lowered budget on macOS.
diff --git a/apps/computer/local-daemon/internal/provider/pi_probe_test.go b/apps/computer/local-daemon/internal/provider/pi_probe_test.go
index ed0e483b..599f10c3 100644
--- a/apps/computer/local-daemon/internal/provider/pi_probe_test.go
+++ b/apps/computer/local-daemon/internal/provider/pi_probe_test.go
@@ -18,14 +18,18 @@ func TestPiAuthenticationBoundsUnresponsiveModelCatalog(t *testing.T) {
}
root := t.TempDir()
executable := filepath.Join(root, "pi")
- if err := os.WriteFile(executable, []byte("#!/bin/sh\necho \"$$\" > \"$HOME/pi-probe.pid\"\nexec /bin/sleep 60\n"), 0700); err != nil {
+ // Priming runs without HOME and exits at once.
+ if err := os.WriteFile(executable, []byte("#!/bin/sh\n[ -n \"$HOME\" ] || exit 0\necho \"$$\" > \"$HOME/pi-probe.pid\"\nexec /bin/sleep 60\n"), 0700); err != nil {
t.Fatal(err)
}
+ // macOS scans a new executable on its first run, which can outlast the
+ // probe's one second budget.
+ primeTestExecutable(t, executable, "PATH=/usr/bin:/bin")
ctx, cancel := context.WithCancel(t.Context())
defer cancel()
result := make(chan runtimeProbeOutcome, 1)
go func() {
- result <- probePiAuthentication(ctx, executable, map[string]string{"HOME": root, "PATH": root}, 5*time.Second)
+ result <- probePiAuthentication(ctx, executable, map[string]string{"HOME": root, "PATH": root}, time.Second)
}()
select {
case outcome := <-result: