Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/assets/qa/runner-startup/after-terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/qa/runner-startup/before-terminal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion internal/runner/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 68 additions & 0 deletions internal/runner/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
goruntime "runtime"
"strconv"
"strings"
"testing"
Expand Down Expand Up @@ -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
Expand Down