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 waiting on production timers in daemon tests

shoudi zhengcfb198516917
diff --git a/apps/computer/local-daemon/cmd/linger-computer-daemon/self_update_startup_test.go b/apps/computer/local-daemon/cmd/linger-computer-daemon/self_update_startup_test.go
index 08c5fb88..07f1e6f5 100644
--- a/apps/computer/local-daemon/cmd/linger-computer-daemon/self_update_startup_test.go
+++ b/apps/computer/local-daemon/cmd/linger-computer-daemon/self_update_startup_test.go
@@ -27,10 +27,6 @@ func TestUnconfirmedUpgradeRollsBackBeforeDaemonInitialization(t *testing.T) {
if output, err := build.CombinedOutput(); err != nil {
t.Fatalf("build daemon: %v\n%s", err, output)
}
- content, err := os.ReadFile(binary)
- if err != nil {
- t.Fatal(err)
- }
cases := []struct {
name string
@@ -44,7 +40,14 @@ func TestUnconfirmedUpgradeRollsBackBeforeDaemonInitialization(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
root := t.TempDir()
daemon := filepath.Join(root, "lib-new", "daemon", "linger-computer-daemon")
- writeStartupFile(t, daemon, content, 0o755)
+ // Link rather than copy: macOS scans every new executable inode on
+ // its first launch, which costs about a second for a daemon binary.
+ if err := os.MkdirAll(filepath.Dir(daemon), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.Link(binary, daemon); err != nil {
+ t.Fatal(err)
+ }
appSHA256 := strings.Repeat("a", 64)
writeStartupFile(t, filepath.Join(root, "lib-new", "app-sha256"), []byte(appSHA256+"\n"), 0o600)
started := filepath.Join(root, "previous-started")
diff --git a/apps/computer/local-daemon/internal/daemon/agent_runner_remove_residents_test.go b/apps/computer/local-daemon/internal/daemon/agent_runner_remove_residents_test.go
index c945ba04..8f871a07 100644
--- a/apps/computer/local-daemon/internal/daemon/agent_runner_remove_residents_test.go
+++ b/apps/computer/local-daemon/internal/daemon/agent_runner_remove_residents_test.go
@@ -54,15 +54,23 @@ while IFS= read -r line; do
done
`
+// writeParkedScript writes one fixture executable that every resident of a
+// Runtime shares: macOS scans each new executable on its first launch, so
+// one file per Runtime keeps that wait out of every further launch.
+func writeParkedScript(t *testing.T, name, script string) string {
+ t.Helper()
+ executable := filepath.Join(t.TempDir(), name)
+ if err := os.WriteFile(executable, []byte(script), 0o755); err != nil {
+ t.Fatal(err)
+ }
+ return executable
+}
+
// parkClaudeFor runs one turn on a Claude process of the Context and Agent, which
// leaves the process parked, and returns its pid.
-func parkClaudeFor(t *testing.T, contextKey, agentID string) int {
+func parkClaudeFor(t *testing.T, executable, contextKey, agentID string) int {
t.Helper()
root := t.TempDir()
- executable := filepath.Join(root, "claude")
- if err := os.WriteFile(executable, []byte(parkedClaudeScript), 0o755); err != nil {
- t.Fatal(err)
- }
backend, err := native.Open("claude", native.Profile{
Program: executable, Logger: slog.Default(), ContextKey: contextKey, AgentID: agentID,
Env: map[string]string{"LINGER_CLAUDE_SESSION_ROOT": filepath.Join(root, "sessions"), "FAKE_DIR": root},
@@ -89,13 +97,9 @@ func parkClaudeFor(t *testing.T, contextKey, agentID string) int {
return pid
}
-func parkCodexFor(t *testing.T, contextKey, agentID string) int {
+func parkCodexFor(t *testing.T, executable, contextKey, agentID string) int {
t.Helper()
root := t.TempDir()
- executable := filepath.Join(root, "codex")
- if err := os.WriteFile(executable, []byte(parkedCodexScript), 0o755); err != nil {
- t.Fatal(err)
- }
home := filepath.Join(root, "codex-home")
if err := os.MkdirAll(filepath.Join(home, "sessions"), 0o700); err != nil {
t.Fatal(err)
@@ -151,10 +155,12 @@ func newRemoveTestDaemon(t *testing.T, stream *fakeStream) *Daemon {
// another Agent's residents stay parked.
func TestAgentRunnerRemoveStopsOnlyThatAgentsParkedResidents(t *testing.T) {
t.Cleanup(func() { _, _ = native.StopAllParkedResidents() })
- removed := parkClaudeFor(t, "context-a1", "agent-1")
- removedCodex := parkCodexFor(t, "context-a1", "agent-1")
- kept := parkClaudeFor(t, "context-b1", "agent-2")
- keptCodex := parkCodexFor(t, "context-b1", "agent-2")
+ claude := writeParkedScript(t, "claude", parkedClaudeScript)
+ codex := writeParkedScript(t, "codex", parkedCodexScript)
+ removed := parkClaudeFor(t, claude, "context-a1", "agent-1")
+ removedCodex := parkCodexFor(t, codex, "context-a1", "agent-1")
+ kept := parkClaudeFor(t, claude, "context-b1", "agent-2")
+ keptCodex := parkCodexFor(t, codex, "context-b1", "agent-2")
stream := &fakeStream{}
d := newRemoveTestDaemon(t, stream)
ctx := context.Background()
diff --git a/apps/computer/local-daemon/internal/linger/localtools/browser.go b/apps/computer/local-daemon/internal/linger/localtools/browser.go
index 4760e0ee..43ea8673 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/browser.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/browser.go
@@ -26,6 +26,10 @@ func nativeDesktop() bool {
// same everyday Chrome profile, below the MCP client's tool timeout.
var profileWait = 40 * time.Second
+// profileRetry is how often a waiting task asks an idle Live call for the
+// profile again; a variable so tests can retry without a real second.
+var profileRetry = time.Second
+
// liveProfileWait is shorter: the user is waiting on the line, and the voice
// model answers that the browser is busy instead of falling silent.
var liveProfileWait = 8 * time.Second
@@ -330,7 +334,7 @@ func (m *Manager) acquireChromeProfile(ctx context.Context, seat string) (func()
m.mu.Unlock()
waitCtx, cancel := context.WithTimeout(ctx, profileWait)
defer cancel()
- retry := time.NewTicker(time.Second)
+ retry := time.NewTicker(profileRetry)
defer retry.Stop()
for {
select {
diff --git a/apps/computer/local-daemon/internal/linger/localtools/user_chrome_test.go b/apps/computer/local-daemon/internal/linger/localtools/user_chrome_test.go
index 8ab4a099..09e00128 100644
--- a/apps/computer/local-daemon/internal/linger/localtools/user_chrome_test.go
+++ b/apps/computer/local-daemon/internal/linger/localtools/user_chrome_test.go
@@ -471,9 +471,10 @@ func liveSessionOnProfile(t *testing.T, m *Manager, key, profile string) *operat
func TestTaskTakesTheChromeOfALiveCallBetweenItsTurns(t *testing.T) {
m := newConnectionManager(t)
live := liveSessionOnProfile(t, m, "tenant\x00owner\x00agent\x00voice-1", "Default")
- previous := profileWait
- profileWait = 1500 * time.Millisecond
- defer func() { profileWait = previous }()
+ previous, previousRetry := profileWait, profileRetry
+ // The wait spans several retries, so a retry also refuses the running call.
+ profileWait, profileRetry = 150*time.Millisecond, 40*time.Millisecond
+ defer func() { profileWait, profileRetry = previous, previousRetry }()
// A Live call in progress keeps the profile.
m.tryLockLive()
if _, err := m.acquireChromeProfile(t.Context(), "Default"); err == nil || !strings.Contains(err.Error(), "BROWSER_BUSY") {
diff --git a/apps/computer/local-daemon/internal/provider/claude_auth_recovery_test.go b/apps/computer/local-daemon/internal/provider/claude_auth_recovery_test.go
index 8948f233..ce9bde33 100644
--- a/apps/computer/local-daemon/internal/provider/claude_auth_recovery_test.go
+++ b/apps/computer/local-daemon/internal/provider/claude_auth_recovery_test.go
@@ -102,7 +102,7 @@ echo '{"loggedIn":true}'
primeTestExecutable(t, filepath.Join(root, "security"))
primeTestExecutable(t, executable, "AUTH_TRACE="+os.DevNull)
trace := filepath.Join(root, "trace")
- options := DiscoveryOptions{RuntimeHomeRoot: homes, Timeout: 2 * time.Second, Environment: map[string]string{
+ options := DiscoveryOptions{RuntimeHomeRoot: homes, Timeout: time.Second, Environment: map[string]string{
"HOME": root, "PATH": root, "ANTHROPIC_API_KEY": "fixture-key", "SLOW_CONFIG": slowest, "AUTH_TRACE": trace,
}}
current := DiscoveryResult{Diagnostics: []RuntimeDiagnostic{{Type: "claude", Status: "ready", ExecutablePath: executable}}}
diff --git a/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go b/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go
index 5acc9615..60134dc1 100644
--- a/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go
+++ b/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go
@@ -196,12 +196,10 @@ func TestCodexManagedProbeDisablesGoalsOnSupportedVersions(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("fixture uses a POSIX script")
}
- for _, version := range []string{"0.100.0", "0.125.0", "0.128.0", "0.150.1"} {
- t.Run(version, func(t *testing.T) {
- root := t.TempDir()
- executable := filepath.Join(root, "codex")
- trace := filepath.Join(root, "launches")
- script := `#!/bin/sh
+ // Every version runs one shared executable: macOS scans each new
+ // executable on its first launch.
+ executable := filepath.Join(t.TempDir(), "codex")
+ script := `#!/bin/sh
printf '%s\n' "$*" >> "$LAUNCH_TRACE"
[ "$*" = "$EXPECTED_ARGS" ] || exit 2
read initialize
@@ -210,9 +208,13 @@ if read initialized && read account; then
echo '{"id":2,"result":{"account":null,"requiresOpenaiAuth":false}}'
fi
`
- if err := os.WriteFile(executable, []byte(script), 0o700); err != nil {
- t.Fatal(err)
- }
+ if err := os.WriteFile(executable, []byte(script), 0o700); err != nil {
+ t.Fatal(err)
+ }
+ for _, version := range []string{"0.100.0", "0.125.0", "0.128.0", "0.150.1"} {
+ t.Run(version, func(t *testing.T) {
+ root := t.TempDir()
+ trace := filepath.Join(root, "launches")
expected := "app-server --disable plugins --listen stdio:// --config features.memories=false --config features.memory_tool=false --config features.apps=false --config features.image_generation=false"
if version == "0.128.0" {
expected = "app-server --disable plugins --disable goals --listen stdio:// --config features.memories=false --config features.memory_tool=false --config features.apps=false --config features.image_generation=false"
@@ -243,6 +245,23 @@ func TestCodexAuthenticationUsesActiveProviderAccountState(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("fixture uses a POSIX script")
}
+ // Every scenario runs the same script: macOS scans each new executable on
+ // its first launch, so one file keeps that wait out of every scenario.
+ executable := filepath.Join(t.TempDir(), "codex")
+ script := `#!/bin/sh
+if [ "$1 $2" = "login status" ]; then echo "Not logged in"; exit 1; fi
+[ "$1 $2 $3 $4 $5" = "app-server --disable plugins --listen stdio://" ] || exit 2
+read initialize
+echo '{"id":1,"result":{"userAgent":"test"}}'
+read initialized
+case "$initialized" in *'"method":"initialized"'*) ;; *) exit 3 ;; esac
+read account
+case "$account" in *'"method":"account/read"'*) ;; *) exit 4 ;; esac
+printf '{"id":2,"result":%s}\n' "$ACCOUNT_RESULT"
+`
+ if err := os.WriteFile(executable, []byte(script), 0o700); err != nil {
+ t.Fatal(err)
+ }
for _, scenario := range []struct {
name, response, want string
}{
@@ -257,21 +276,6 @@ func TestCodexAuthenticationUsesActiveProviderAccountState(t *testing.T) {
} {
t.Run(scenario.name, func(t *testing.T) {
root := t.TempDir()
- executable := filepath.Join(root, "codex")
- script := `#!/bin/sh
-if [ "$1 $2" = "login status" ]; then echo "Not logged in"; exit 1; fi
-[ "$1 $2 $3 $4 $5" = "app-server --disable plugins --listen stdio://" ] || exit 2
-read initialize
-echo '{"id":1,"result":{"userAgent":"test"}}'
-read initialized
-case "$initialized" in *'"method":"initialized"'*) ;; *) exit 3 ;; esac
-read account
-case "$account" in *'"method":"account/read"'*) ;; *) exit 4 ;; esac
-printf '{"id":2,"result":%s}\n' "$ACCOUNT_RESULT"
-`
- if err := os.WriteFile(executable, []byte(script), 0o700); err != nil {
- t.Fatal(err)
- }
result := probeCodexAuthentication(context.Background(), executable, map[string]string{
"HOME": root, "CODEX_HOME": root, "ACCOUNT_RESULT": scenario.response,
}, 5*time.Second)
diff --git a/apps/computer/local-daemon/internal/provider/discovery_test.go b/apps/computer/local-daemon/internal/provider/discovery_test.go
index 9fbf78d3..230e9022 100644
--- a/apps/computer/local-daemon/internal/provider/discovery_test.go
+++ b/apps/computer/local-daemon/internal/provider/discovery_test.go
@@ -216,6 +216,17 @@ func TestDiscoverUsesCodexRuntimeEnvironmentForModelCatalog(t *testing.T) {
if err := os.WriteFile(filepath.Join(ambient, "catalog.json"), []byte(`{"data":[{"id":"grok-4.7"}],"nextCursor":null}`), 0o600); err != nil {
t.Fatal(err)
}
+ // Every mode runs one shared executable: macOS scans each new executable
+ // on its first launch.
+ codex := filepath.Join(t.TempDir(), "codex")
+ script := `#!/bin/sh
+[ "$HOME" = "$EXPECTED_HOME" ] && [ "$CODEX_HOME" != "$AMBIENT_CODEX_HOME" ] || exit 2
+if [ "$1" = "--version" ]; then echo 'codex-cli 0.144.1'; exit 0; fi
+[ "$CODEX_HOME" != "$EXPECTED_CODEX_HOME" ] || exit 2
+` + fakeCodexModelCatalog
+ if err := os.WriteFile(codex, []byte(script), 0o700); err != nil {
+ t.Fatal(err)
+ }
for _, mode := range []string{"CODEX_HOME", "HOME", "tilde"} {
t.Run(mode, func(t *testing.T) {
root := t.TempDir()
@@ -241,15 +252,6 @@ func TestDiscoverUsesCodexRuntimeEnvironmentForModelCatalog(t *testing.T) {
if err := os.WriteFile(catalogPath, []byte(`{"data":[{"id":"deepseek-v4.1-flash","supportedReasoningEfforts":[{"reasoningEffort":"max"}],"defaultReasoningEffort":"max"}],"nextCursor":null}`), 0o600); err != nil {
t.Fatal(err)
}
- codex := filepath.Join(root, "codex")
- script := `#!/bin/sh
-[ "$HOME" = "$EXPECTED_HOME" ] && [ "$CODEX_HOME" != "$AMBIENT_CODEX_HOME" ] || exit 2
-if [ "$1" = "--version" ]; then echo 'codex-cli 0.144.1'; exit 0; fi
-[ "$CODEX_HOME" != "$EXPECTED_CODEX_HOME" ] || exit 2
-` + fakeCodexModelCatalog
- if err := os.WriteFile(codex, []byte(script), 0o700); err != nil {
- t.Fatal(err)
- }
options := DiscoveryOptions{ConfiguredPaths: map[string]string{"codex": codex}, Environment: environment, Timeout: 10 * time.Second}
result, err := Discover(context.Background(), options)
if err != nil {
diff --git a/apps/computer/local-daemon/internal/provider/discovery_version_unix_test.go b/apps/computer/local-daemon/internal/provider/discovery_version_unix_test.go
index 39d57084..2ded3a6e 100644
--- a/apps/computer/local-daemon/internal/provider/discovery_version_unix_test.go
+++ b/apps/computer/local-daemon/internal/provider/discovery_version_unix_test.go
@@ -78,6 +78,14 @@ done
}
func TestDiscoveryVersionFailuresRemainBounded(t *testing.T) {
+ // Every case runs one shared executable that takes its body from the
+ // environment, so only the first launch pays the macOS executable scan.
+ executable := filepath.Join(t.TempDir(), "pi")
+ script := "#!/bin/sh\nif [ \"$1\" = \"--fixture-warmup\" ]; then exit 0; fi\nif [ \"$1\" = \"--version\" ]; then\necho version >> \"$HOME/attempts\"\neval \"$FIXTURE_BODY\"\nexit\nfi\nexit 7\n"
+ if err := os.WriteFile(executable, []byte(script), 0700); err != nil {
+ t.Fatal(err)
+ }
+ warmVersionFixture(t, executable)
for _, tc := range []struct {
name, body, status string
attempts int
@@ -94,12 +102,6 @@ func TestDiscoveryVersionFailuresRemainBounded(t *testing.T) {
} {
t.Run(tc.name, func(t *testing.T) {
root := t.TempDir()
- executable := filepath.Join(root, "pi")
- script := "#!/bin/sh\nif [ \"$1\" = \"--fixture-warmup\" ]; then exit 0; fi\nif [ \"$1\" = \"--version\" ]; then\necho version >> \"$HOME/attempts\"\n" + tc.body + "\nexit\nfi\nexit 7\n"
- if err := os.WriteFile(executable, []byte(script), 0700); err != nil {
- t.Fatal(err)
- }
- warmVersionFixture(t, executable)
ctx := t.Context()
if tc.parentTimeout > 0 {
var cancel context.CancelFunc
@@ -107,7 +109,7 @@ func TestDiscoveryVersionFailuresRemainBounded(t *testing.T) {
defer cancel()
}
started := time.Now()
- result, err := Discover(ctx, DiscoveryOptions{Environment: map[string]string{"HOME": root, "PATH": root}, ConfiguredPaths: map[string]string{"pi": executable}, Timeout: 500 * time.Millisecond})
+ result, err := Discover(ctx, DiscoveryOptions{Environment: map[string]string{"HOME": root, "PATH": root, "FIXTURE_BODY": tc.body}, ConfiguredPaths: map[string]string{"pi": executable}, Timeout: 500 * time.Millisecond})
if err != nil {
t.Fatal(err)
}
diff --git a/apps/computer/local-daemon/internal/provider/live_check_test.go b/apps/computer/local-daemon/internal/provider/live_check_test.go
index 1efbe207..fcfd999f 100644
--- a/apps/computer/local-daemon/internal/provider/live_check_test.go
+++ b/apps/computer/local-daemon/internal/provider/live_check_test.go
@@ -13,25 +13,15 @@ func TestDiscoverLiveChecksOnlySelectedReadyRuntime(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("fixture uses a POSIX script")
}
- for _, test := range []struct {
- name, exec string
- passed bool
- reply string
- message string
- }{
- {name: "reply", exec: `echo OK`, passed: true, reply: "OK"},
- {name: "failure", exec: `echo "starting" >&2; echo "401 Unauthorized" >&2; exit 1`, message: "401 Unauthorized"},
- {name: "empty", exec: `exit 0`, message: "Runtime exited without a reply"},
- } {
- t.Run(test.name, func(t *testing.T) {
- root := t.TempDir()
- codex := filepath.Join(root, "codex")
- script := `#!/bin/sh
+ // Every case runs one shared executable that takes its exec reply from
+ // the environment: macOS scans each new executable on its first launch.
+ codex := filepath.Join(t.TempDir(), "codex")
+ script := `#!/bin/sh
case "$1 $2" in
"--version ") echo "codex-cli 0.100.0" ;;
"exec --skip-git-repo-check")
[ "$8" = "Reply with exactly: OK" ] || exit 2
- ` + test.exec + ` ;;
+ eval "$LIVE_EXEC" ;;
"app-server --disable")
read line
echo '{"jsonrpc":"2.0","id":1,"result":{"userAgent":"codex-test"}}'
@@ -47,12 +37,24 @@ case "$1 $2" in
*) exit 2 ;;
esac
`
- if err := os.WriteFile(codex, []byte(script), 0o700); err != nil {
- t.Fatal(err)
- }
+ if err := os.WriteFile(codex, []byte(script), 0o700); err != nil {
+ t.Fatal(err)
+ }
+ for _, test := range []struct {
+ name, exec string
+ passed bool
+ reply string
+ message string
+ }{
+ {name: "reply", exec: `echo OK`, passed: true, reply: "OK"},
+ {name: "failure", exec: `echo "starting" >&2; echo "401 Unauthorized" >&2; exit 1`, message: "401 Unauthorized"},
+ {name: "empty", exec: `exit 0`, message: "Runtime exited without a reply"},
+ } {
+ t.Run(test.name, func(t *testing.T) {
+ root := t.TempDir()
result, checks := DiscoverLive(context.Background(), DiscoveryOptions{
ConfiguredPaths: map[string]string{"codex": codex},
- Environment: map[string]string{"PATH": root, "HOME": root},
+ Environment: map[string]string{"PATH": root, "HOME": root, "LIVE_EXEC": test.exec},
Runtimes: []string{"codex"},
}, 10*time.Second)
if len(result.Diagnostics) != 1 || result.Diagnostics[0].Type != "codex" || result.Diagnostics[0].Status != "ready" {
diff --git a/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go b/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go
index b76a2e04..2b216a58 100644
--- a/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go
@@ -18,6 +18,10 @@ import (
// claudeFakeKey runs the named mode before TestMain.
const claudeFakeKey = "CLAUDE_FAKE_MODE"
+// claudeFakeSlowOutput is how long a resident "slow" or "late" turn holds its
+// output; timing assertions compare against it rather than a wall-clock guess.
+const claudeFakeSlowOutput = 500 * time.Millisecond
+
func init() {
if mode := os.Getenv(claudeFakeKey); mode != "" {
os.Exit(claudeFakeMain(mode))
@@ -308,7 +312,7 @@ func (f *claudeFake) resident() int {
f.emit(systemInit)
}
if strings.Contains(prompt, "late") || strings.Contains(prompt, "slow") {
- time.Sleep(time.Second)
+ time.Sleep(claudeFakeSlowOutput)
}
if strings.Contains(prompt, "noecho") {
f.emit(map[string]any{"type": "result", "subtype": "error", "is_error": true, "terminal_reason": "completed",
diff --git a/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go b/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go
index ec19c5d4..d923a435 100644
--- a/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go
@@ -73,7 +73,7 @@ func claudeCheckEarlyStart(t *testing.T, events []claudeTimedEvent, submitted, d
t.Fatalf("turn starts = %d", len(started))
}
s := started[0]
- if done.Sub(s.at) < 700*time.Millisecond || s.SentAt.IsZero() || s.SentAt.Before(submitted) || s.SentAt.After(s.at) {
+ if done.Sub(s.at) < claudeFakeSlowOutput*7/10 || s.SentAt.IsZero() || s.SentAt.Before(submitted) || s.SentAt.After(s.at) {
t.Fatalf("turn start at %v sent %v (submitted %v, done %v)", s.at, s.SentAt, submitted, done)
}
if s.SessionID != claudeTestSession || s.ProcessReused == nil || *s.ProcessReused != reused {
@@ -119,7 +119,7 @@ func TestClaudeTurnStartWaitsForEchoWithoutTurnInit(t *testing.T) {
events, outcome, submitted, _ := claudeTurnAt(t, home, "slow", RunSpec{}, nil)
claudeMustComplete(t, outcome)
started := claudeStartedEvents(events)
- if len(started) != 1 || started[0].at.Sub(submitted) < 900*time.Millisecond {
+ if len(started) != 1 || started[0].at.Sub(submitted) < claudeFakeSlowOutput*9/10 {
t.Fatalf("turn starts = %+v submitted %v", started, submitted)
}
})
diff --git a/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go b/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go
index 1965a4c7..a8138e71 100644
--- a/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go
@@ -496,7 +496,7 @@ func TestClaudeTurnStartedSentAt(t *testing.T) {
events, _ := home.turn(t, prompt, spec)
after := time.Now()
started := claudeTurnStarted(events)
- if started == nil || started.SentAt.Before(before) || after.Sub(started.SentAt) < 900*time.Millisecond {
+ if started == nil || started.SentAt.Before(before) || after.Sub(started.SentAt) < claudeFakeSlowOutput*9/10 {
t.Fatalf("turn %d SentAt = %+v window %v..%v", i, started, before, after)
}
for _, event := range events {
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 69443752..a5b66667 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
@@ -626,8 +626,8 @@ func TestCodexUsagePerTurnOnReusedProcess(t *testing.T) {
func TestCodexSteering(t *testing.T) {
fake := newCodexFake(t, []codexFakeTurn{{Stall: true}}, nil)
spec := fake.spec()
- spec.SilenceBudget = 2 * time.Second
- spec.FirstProgressBudget = 2 * time.Second
+ spec.SilenceBudget = time.Second
+ spec.FirstProgressBudget = time.Second
run, err := fake.runtime(nil).Start(context.Background(), "go", spec)
if err != nil {
t.Fatal(err)
@@ -951,7 +951,7 @@ func TestCodexSteerNeedsConsumptionEvidence(t *testing.T) {
fake := newCodexFake(t, []codexFakeTurn{{Stall: true}}, map[string]string{"FAKE_MODES": tc.mode})
fake.version = "0.166.0"
spec := fake.spec()
- spec.SilenceBudget = 3 * time.Second
+ spec.SilenceBudget = time.Second
spec.ExposeTurnStarted = true
run, err := fake.runtime(nil).Start(context.Background(), "go", spec)
if err != nil {
diff --git a/apps/computer/local-daemon/internal/provider/native/pi_resident_fake_test.go b/apps/computer/local-daemon/internal/provider/native/pi_resident_fake_test.go
index 4340fd78..c1076fce 100644
--- a/apps/computer/local-daemon/internal/provider/native/pi_resident_fake_test.go
+++ b/apps/computer/local-daemon/internal/provider/native/pi_resident_fake_test.go
@@ -125,12 +125,15 @@ func (f *piResidentFakeState) handle(id, kind, message string) int {
return -1
}
+// piSettleLaterDelay is how long a "settle_later" turn runs before it settles.
+const piSettleLaterDelay = 200 * time.Millisecond
+
func (f *piResidentFakeState) act(message string) {
switch message {
case "hold":
case "settle_later":
go func() {
- time.Sleep(500 * time.Millisecond)
+ time.Sleep(piSettleLaterDelay)
f.finish()
}()
case "fail":
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 32f5d9ef..cadf0645 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
@@ -419,7 +419,8 @@ func TestPiReleaseDuringParkProbe(t *testing.T) {
t.Run(name, func(t *testing.T) {
h := piNewResidentHome(t, nil)
proc, run, _ := piHeldReuse(t, h)
- time.Sleep(800 * time.Millisecond)
+ // Let the turn settle and reach the park probe that waits on writeMu.
+ time.Sleep(piSettleLaterDelay + 300*time.Millisecond)
_, err := stop(h)
proc.writeMu.Unlock()
if err != nil {
@@ -457,7 +458,8 @@ func TestPiSteerRacingParkIsRejected(t *testing.T) {
_, err := run.Steer(context.Background(), SteerRequest{ExpectedTurnID: turn, Input: "late"})
steered <- err
}()
- time.Sleep(800 * time.Millisecond)
+ // Let the turn settle and reach the park probe that waits on writeMu.
+ time.Sleep(piSettleLaterDelay + 300*time.Millisecond)
proc.writeMu.Unlock()
var refused *SteerError
if err := <-steered; !errors.As(err, &refused) || refused.Effect != "definitely_not_applied" {
diff --git a/apps/computer/local-daemon/internal/provider/pi_probe_context_test.go b/apps/computer/local-daemon/internal/provider/pi_probe_context_test.go
index 75ba479b..f66034a0 100644
--- a/apps/computer/local-daemon/internal/provider/pi_probe_context_test.go
+++ b/apps/computer/local-daemon/internal/provider/pi_probe_context_test.go
@@ -17,12 +17,10 @@ func TestPiAuthenticationPreservesClosedContextStage(t *testing.T) {
if runtime.GOOS == "windows" {
t.Skip("fixture uses a POSIX shell")
}
- for _, stage := range []string{"catalog", "auth"} {
- for _, kind := range []string{"deadline", "cancel"} {
- t.Run(stage+"/"+kind, func(t *testing.T) {
- root := t.TempDir()
- program := filepath.Join(root, "pi")
- script := `#!/bin/sh
+ // Every case runs one shared executable: macOS scans each new executable
+ // on its first run, which can outlast the probe's one second budget.
+ program := filepath.Join(t.TempDir(), "pi")
+ script := `#!/bin/sh
if [ "$FIXTURE_STAGE" = catalog ] || [ "$1" = auth ]; then echo $$ > "$HOME/pid"; exec /bin/sleep 60; fi
while IFS= read -r line; do
case "$line" in
@@ -31,12 +29,14 @@ while IFS= read -r line; do
esac
done
`
- if err := os.WriteFile(program, []byte(script), 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, program)
+ if err := os.WriteFile(program, []byte(script), 0700); err != nil {
+ t.Fatal(err)
+ }
+ primeTestExecutable(t, program)
+ for _, stage := range []string{"catalog", "auth"} {
+ for _, kind := range []string{"deadline", "cancel"} {
+ t.Run(stage+"/"+kind, func(t *testing.T) {
+ root := t.TempDir()
ctx, cancel := context.WithCancelCause(t.Context())
defer cancel(nil)
done := make(chan runtimeProbeOutcome, 1)
diff --git a/apps/computer/local-daemon/internal/provider/runtime_monitor_test.go b/apps/computer/local-daemon/internal/provider/runtime_monitor_test.go
index 3ae46a77..f9eae7db 100644
--- a/apps/computer/local-daemon/internal/provider/runtime_monitor_test.go
+++ b/apps/computer/local-daemon/internal/provider/runtime_monitor_test.go
@@ -16,6 +16,30 @@ func TestRuntimeMonitorBoundsTransientAuthenticationProbeFailures(t *testing.T)
if runtime.GOOS == "windows" {
t.Skip("fixture uses a POSIX script")
}
+ // Every scenario runs one shared executable: macOS scans each new
+ // executable on its first launch.
+ fixtures := t.TempDir()
+ codex := filepath.Join(fixtures, "codex")
+ script := `#!/bin/sh
+attempt=0
+if [ -f "$ATTEMPT_FILE" ]; then read attempt < "$ATTEMPT_FILE"; fi
+attempt=$((attempt + 1))
+echo "$attempt" > "$ATTEMPT_FILE"
+if [ "$attempt" -le "$FAILURES" ] && [ "$PROBE_EXIT" != "1" ]; then echo "$PROBE_OUTPUT"; exit "$PROBE_EXIT"; fi
+read initialize
+echo '{"id":1,"result":{"userAgent":"test"}}'
+read initialized
+read account
+if [ "$attempt" -le "$FAILURES" ]; then
+ echo '{"id":2,"result":{"account":null,"requiresOpenaiAuth":true}}'
+else
+ echo '{"id":2,"result":{"account":{"type":"chatgpt"},"requiresOpenaiAuth":true}}'
+fi
+`
+ if err := os.WriteFile(codex, []byte(script), 0o700); err != nil {
+ t.Fatal(err)
+ }
+ primeTestExecutable(t, codex, "ATTEMPT_FILE="+filepath.Join(fixtures, "prime-attempt"))
for _, scenario := range []struct {
name string
failures string
@@ -32,27 +56,6 @@ func TestRuntimeMonitorBoundsTransientAuthenticationProbeFailures(t *testing.T)
} {
t.Run(scenario.name, func(t *testing.T) {
root := t.TempDir()
- codex := filepath.Join(root, "codex")
- script := `#!/bin/sh
-attempt=0
-if [ -f "$ATTEMPT_FILE" ]; then read attempt < "$ATTEMPT_FILE"; fi
-attempt=$((attempt + 1))
-echo "$attempt" > "$ATTEMPT_FILE"
-if [ "$attempt" -le "$FAILURES" ] && [ "$PROBE_EXIT" != "1" ]; then echo "$PROBE_OUTPUT"; exit "$PROBE_EXIT"; fi
-read initialize
-echo '{"id":1,"result":{"userAgent":"test"}}'
-read initialized
-read account
-if [ "$attempt" -le "$FAILURES" ]; then
- echo '{"id":2,"result":{"account":null,"requiresOpenaiAuth":true}}'
-else
- echo '{"id":2,"result":{"account":{"type":"chatgpt"},"requiresOpenaiAuth":true}}'
-fi
-`
- if err := os.WriteFile(codex, []byte(script), 0o700); err != nil {
- t.Fatal(err)
- }
- primeTestExecutable(t, codex, "ATTEMPT_FILE="+filepath.Join(root, "prime-attempt"))
initial := DiscoveryResult{Diagnostics: []RuntimeDiagnostic{{
Type: "codex", Status: "ready", Protocol: "app-server", ExecutablePath: codex,
}}}