Run Claude sessions on tasks with event streaming and restart recovery

This commit is contained in:
Ian Gulliver
2026-10-13 22:30:39 -07:00
parent 2328904131
commit 09951e64e7
16 changed files with 1630 additions and 170 deletions
+18 -1
View File
@@ -6,6 +6,7 @@ import (
"os"
"os/exec"
"path/filepath"
"slices"
"strings"
"sync"
"testing"
@@ -70,6 +71,9 @@ func TestCommitIdentityHooksAndReport(t *testing.T) {
if len(tools) == 0 {
t.Fatalf("PostToolUse hook never fired")
}
if slices.Contains(tools, "ToolSearch") {
t.Fatalf("byre MCP tools were deferred behind ToolSearch")
}
log := git(t, repo, "log", "-1", "--format=%an <%ae>%n%cn <%ce>%n%B")
want := gitName + " <" + gitEmail + ">\n" + gitName + " <" + gitEmail + ">\nadd hello"
@@ -119,13 +123,26 @@ func TestInterrupt(t *testing.T) {
ctx := testContext(t)
s := start(t, ctx, claude.Options{Cwd: scratchRepo(t)})
send(t, s, "Run the bash command `sleep 120` in the foreground (not in the background), then say done.")
send(t, s, "Run the bash command `ping -c 120 127.0.0.1` in the foreground (not in the background) and wait for it to finish, then say done.")
interruptedAt := time.Time{}
waitResult(t, ctx, s, func(ev claude.Event) {
if ev.Type == "user" {
blocks, err := ev.Blocks()
if err != nil {
t.Fatalf("parse user: %v", err)
}
for _, b := range blocks {
if b.Type == "tool_result" && (!b.IsError || strings.Contains(string(b.Content), "Blocked")) {
t.Fatalf("command finished or was refused instead of being interrupted: %s", b.Content)
}
}
}
if !interruptedAt.IsZero() || !hasToolUse(t, ev) {
return
}
time.Sleep(2 * time.Second)
interruptedAt = time.Now()
err := s.Interrupt(ctx)
if err != nil {