Record delegated configuration exit status gaps
This commit is contained in:
@@ -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())
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user