e071084ebe
govulncheck / govulncheck (push) Waiting to run
Harness (E2E) / Harnesses (mock LLM) (push) Waiting to run
Harness (E2E) / Provider harnesses (live LLM conformance) (push) Waiting to run
Lint / golangci-lint (push) Waiting to run
Run Tests / Unit Tests (push) Waiting to run
Run Tests / Etcd Integration Tests (push) Waiting to run
49 lines
1.0 KiB
Go
49 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestDurableAgentExampleResumesWithoutReplayingTool(t *testing.T) {
|
|
out := captureStdout(t, main)
|
|
if !strings.Contains(out, "simulated process interruption after checkpointed tool call") {
|
|
t.Fatalf("example output %q did not show the initial interrupted run", out)
|
|
}
|
|
if !strings.Contains(out, "resumed reply: sku-123 is reserved; no duplicate reservation was made") {
|
|
t.Fatalf("example output %q did not show the resumed response", out)
|
|
}
|
|
if !strings.Contains(out, "tool executions: 1") {
|
|
t.Fatalf("example output %q did not prove the tool was not replayed", out)
|
|
}
|
|
}
|
|
|
|
func captureStdout(t *testing.T, fn func()) string {
|
|
t.Helper()
|
|
|
|
old := os.Stdout
|
|
r, w, err := os.Pipe()
|
|
if err != nil {
|
|
t.Fatalf("pipe stdout: %v", err)
|
|
}
|
|
os.Stdout = w
|
|
|
|
var buf bytes.Buffer
|
|
done := make(chan struct{})
|
|
go func() {
|
|
_, _ = io.Copy(&buf, r)
|
|
close(done)
|
|
}()
|
|
|
|
fn()
|
|
|
|
_ = w.Close()
|
|
os.Stdout = old
|
|
<-done
|
|
_ = r.Close()
|
|
return buf.String()
|
|
}
|