Launch test: the restart is heard as a second start line in the log, not polled from a file (issue 1966, review round 2)

Claude-Session: https://claude.ai/code/session_01NcbgfFfQ4Z9UE5jK32PmE5
This commit is contained in:
2026-11-09 13:59:13 +01:00
parent 312e29478e
commit a25c2b4d89
+10 -20
View File
@@ -80,7 +80,7 @@ const callingBundle = `#!/bin/sh
while IFS= read -r line; do
id=$(printf '%s' "$line" | sed -n 's/.*"id":\([0-9]*\)[,}].*/\1/p')
case "$line" in
*'"method":"initialize"'*) echo started >> "$STARTS"; printf '{"jsonrpc":"2.0","id":%s,"result":{}}\n' "$id" ;;
*'"method":"initialize"'*) echo started >&2; printf '{"jsonrpc":"2.0","id":%s,"result":{}}\n' "$id" ;;
*'"method":"tools/list"'*) printf '{"jsonrpc":"2.0","id":%s,"result":{"tools":[{"name":"t","description":"d"}]}}\n' "$id" ;;
*'"method":"tools/call"'*) [ "$MODE" = long ] && printf '%4096s\n' x ;;
esac
@@ -106,13 +106,12 @@ func TestAnOverlongLineAndAnUnansweredCallAreSaid(t *testing.T) {
CallTimeout = row.timeout
dir := t.TempDir()
entry := filepath.Join(dir, "bundle")
starts := filepath.Join(dir, "starts")
if err := os.WriteFile(entry, []byte(callingBundle), 0o755); err != nil {
t.Fatal(err)
}
said := make(chan string, 32)
logf := func(f string, a ...any) { said <- fmt.Sprintf(f, a...) }
l, err := Start("caller", entry, append(os.Environ(), "MODE="+row.mode, "STARTS="+starts), &refusingState{}, logf)
l, err := Start("caller", entry, append(os.Environ(), "MODE="+row.mode), &refusingState{}, logf)
if err != nil {
t.Fatal(err)
}
@@ -134,27 +133,18 @@ func TestAnOverlongLineAndAnUnansweredCallAreSaid(t *testing.T) {
t.Fatalf("the call failed with %q, not the cap's reason", err)
}
}
for found := false; !found; {
// For "long" the bundle is also started again: it says "started" on each start, so twice in all.
started, found := 0, false
for !found || (row.mode == "long" && started < 2) {
select {
case line := <-said:
heard = append(heard, line)
found = strings.Contains(line, want)
found = found || strings.Contains(line, want)
if line == "[caller] started" {
started++
}
case <-timeout:
t.Fatalf("not said; the log: %v", heard)
}
}
if row.mode != "long" {
return
}
// The bundle is started again: its start is written once more.
for {
if b, _ := os.ReadFile(starts); strings.Count(string(b), "started") >= 2 {
return
}
select {
case <-timeout:
t.Fatal("the bundle was not started again")
case <-time.After(10 * time.Millisecond):
t.Fatalf("not said, or the bundle not started again; the log: %v", heard)
}
}
})