Record delegated configuration exit status gaps

This commit is contained in:
2026-11-16 03:32:19 +00:00
parent d226bdd697
commit e34672f7fe
2 changed files with 58 additions and 3 deletions

View File

@@ -3,10 +3,13 @@ package cli
import (
"bytes"
"context"
"errors"
"os"
"path/filepath"
"strings"
"testing"
commandkit "go.maximumdirect.net/commandkit"
)
func writeRuntimeErrorConfig(t *testing.T, operatorDocument string) string {
@@ -44,10 +47,28 @@ func TestResourceCommandsClassifyOperatorPromptErrorsAsInputErrors(t *testing.T)
func TestResourceCommandKeepsCallerCancellationAsFailure(t *testing.T) {
main := writeRuntimeErrorConfig(t, "profiles:\n - id: proposal\n model: local-model\n")
transcript := filepath.Join(filepath.Dir(main), "transcript.json")
if err := os.WriteFile(transcript, []byte("[]\n"), 0600); err != nil {
t.Fatal(err)
}
app, err := buildApplication()
if err != nil {
t.Fatal(err)
}
ctx, cancel := context.WithCancel(context.Background())
cancel()
var stdout, stderr bytes.Buffer
if code := Run(ctx, []string{"promptkit", "list", "prompts", "--config", main}, &stdout, &stderr); code == 0 {
t.Fatalf("cancellation succeeded: stdout=%q stderr=%q", stdout.String(), stderr.String())
commands := map[string][]string{
"prompt catalog": {"promptkit", "list", "prompts", "--config", main},
"configuration": {"config", "show", "--scope", "promptkit", "--config", main},
"process": {"process", transcript, "--config", main},
}
for name, args := range commands {
t.Run(name, func(t *testing.T) {
var stdout, stderr bytes.Buffer
outcome := app.Execute(ctx, args, commandkit.Streams{Out: &stdout, Err: &stderr})
if outcome.Status != 1 || !errors.Is(outcome.Cause, context.Canceled) || stdout.Len() != 0 {
t.Fatalf("cancellation: status=%d cause=%v stdout=%q stderr=%q", outcome.Status, outcome.Cause, stdout.String(), stderr.String())
}
})
}
}