Add a whole-run deadline to CLI execution

This commit is contained in:
2026-09-26 15:34:55 +00:00
parent a4ef91fb7e
commit 911ca5485a
6 changed files with 87 additions and 3 deletions

View File

@@ -1331,6 +1331,54 @@ func TestTransientRetrySettingsAndCLIOverride(t *testing.T) {
}
}
func TestRunTimeoutParsingAndCancellation(t *testing.T) {
lib := newCLITestLibrary(t)
inputPath := lib.writeInputFile(t, "transcript.md", "hello")
args := []string{"--prompt-dir", lib.promptDir, "--profile-dir", lib.profileDir, "--prompt", "timed", "--input", "transcript=" + inputPath}
for _, tc := range []struct {
name string
flag []string
want time.Duration
}{
{name: "omitted"},
{name: "zero", flag: []string{"--run-timeout", "0s"}},
{name: "subsecond", flag: []string{"--run-timeout", "125ms"}, want: 125 * time.Millisecond},
} {
t.Run(tc.name, func(t *testing.T) {
cfg, err := parseRunArgs(append(append([]string{}, args...), tc.flag...))
if err != nil || cfg.runTimeout != tc.want {
t.Fatalf("run timeout: cfg=%+v err=%v", cfg, err)
}
})
}
if _, err := parseRunArgs(append(append([]string{}, args...), "--run-timeout", "-1ms")); err == nil {
t.Fatal("negative run timeout accepted")
}
if _, err := parseRenderArgs(append(append([]string{}, args...), "--run-timeout", "1s")); err == nil {
t.Fatal("render accepted run-only timeout")
}
started := make(chan struct{}, 1)
release := make(chan struct{})
provider := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
started <- struct{}{}
<-release
}))
defer provider.Close()
defer close(release)
writePromptFile(t, lib.promptDir, "timed", "local-default")
writeProfileFile(t, lib.profileDir, "local-default", provider.URL+"/v1", "local-model")
code, stdout, stderr := runCLICommand(t, runCommand, append(append([]string{}, args...), "--run-timeout", "500ms", "--transient-retries", "0"))
if code != ExitRuntimeError || stdout != "" || !strings.Contains(stderr, "execution deadline exceeded") {
t.Fatalf("deadline outcome: code=%d stdout=%q stderr=%q", code, stdout, stderr)
}
select {
case <-started:
default:
t.Fatal("provider call did not start before deadline")
}
}
func intPointer(value int) *int { return &value }
func TestPromptkitPromptInspectionSelectsVersionsAndContracts(t *testing.T) {