diff --git a/docs/assets/qa/runner-startup/after-terminal.png b/docs/assets/qa/runner-startup/after-terminal.png new file mode 100644 index 00000000..00968d43 Binary files /dev/null and b/docs/assets/qa/runner-startup/after-terminal.png differ diff --git a/docs/assets/qa/runner-startup/after-workbench.png b/docs/assets/qa/runner-startup/after-workbench.png new file mode 100644 index 00000000..919abc32 Binary files /dev/null and b/docs/assets/qa/runner-startup/after-workbench.png differ diff --git a/docs/assets/qa/runner-startup/before-terminal.png b/docs/assets/qa/runner-startup/before-terminal.png new file mode 100644 index 00000000..804e5a67 Binary files /dev/null and b/docs/assets/qa/runner-startup/before-terminal.png differ diff --git a/internal/runner/daemon.go b/internal/runner/daemon.go index dc305a06..c5725164 100644 --- a/internal/runner/daemon.go +++ b/internal/runner/daemon.go @@ -150,10 +150,15 @@ func trimTrailingSlash(s string) string { func (d *Daemon) Run(ctx context.Context) error { ctx, stop := context.WithCancel(ctx) defer stop() + hadSession := d.clientSession() != "" if err := d.ensureRegistered(ctx); err != nil { return err } - d.refreshRuntimes(ctx) + // Fresh registration already probed the CLIs for its request. A restart + // must discover them again, as must a registration whose discovery failed. + if hadSession || len(d.currentRuntimes()) == 0 { + d.refreshRuntimes(ctx) + } claimCtx, cancelClaim := context.WithCancel(ctx) defer cancelClaim() d.cancelClaimLoop = cancelClaim diff --git a/internal/runner/daemon_test.go b/internal/runner/daemon_test.go index c9d83734..dd5511fc 100644 --- a/internal/runner/daemon_test.go +++ b/internal/runner/daemon_test.go @@ -7,6 +7,7 @@ import ( "os" "os/exec" "path/filepath" + goruntime "runtime" "strconv" "strings" "testing" @@ -476,6 +477,73 @@ func TestDaemonRestartImmediatelyRestoresPresence(t *testing.T) { } } +func TestDaemonDiscoversCLIsOncePerStart(t *testing.T) { + server, store, _ := newDaemonTestServer(t) + dir := t.TempDir() + probe := filepath.Join(dir, "probe") + script := "#!/bin/sh\necho called >> \"$LOOPFORGE_TEST_PROBES\"\necho \"$LOOPFORGE_TEST_VERSION\"\n" + if goruntime.GOOS == "windows" { + probe += ".cmd" + script = "@echo off\r\necho called>>\"%LOOPFORGE_TEST_PROBES%\"\r\necho %LOOPFORGE_TEST_VERSION%\r\n" + } + if err := os.WriteFile(probe, []byte(script), 0o755); err != nil { + t.Fatal(err) + } + binaries := make(map[string]string) + for _, provider := range defaultProviders { + binaries[provider.Kind] = filepath.Join(dir, "absent") + } + binaries["codebuddy"] = probe + cfg := Config{ + ServerURL: server.URL, BootstrapToken: "boot-secret", StatePath: filepath.Join(dir, "state.json"), + Name: "discovery-runner", DefaultWorkspaceRoot: dir, ExtraBinaries: binaries, + } + var id string + for _, version := range []string{"1.0", "2.0"} { + t.Run(version, func(t *testing.T) { + logPath := filepath.Join(t.TempDir(), "probes") + t.Setenv("LOOPFORGE_TEST_PROBES", logPath) + t.Setenv("LOOPFORGE_TEST_VERSION", version) + d, err := New(cfg) + if err != nil { + t.Fatal(err) + } + ctx, cancel := context.WithCancel(context.Background()) + done := make(chan error, 1) + go func() { done <- d.Run(ctx) }() + t.Cleanup(func() { + cancel() + select { + case <-done: + case <-time.After(5 * time.Second): + t.Error("runner did not stop") + } + }) + waitFor(t, 10*time.Second, "connected runner reporting the installed version", func() bool { + row, ok := store.Runner(d.runnerID()) + if !ok || !d.wsOnline.Load() { + return false + } + for _, rt := range row.Runtimes { + if rt.Provider == "codebuddy" && rt.Version == version { + return true + } + } + return false + }) + if id != "" && d.runnerID() != id { + t.Fatal("restarting with a saved session changed the runner identity") + } + id = d.runnerID() + cfg.BootstrapToken = "already-used" + calls, err := os.ReadFile(logPath) + if err != nil || len(strings.Fields(string(calls))) != 1 { + t.Errorf("expected one version probe, got %q (read error %v)", calls, err) + } + }) + } +} + func TestDaemonExecuteProcessRunsRealCommand(t *testing.T) { server, s, _ := newDaemonTestServer(t) _ = server