Strengthen startup and error regression tests
This commit is contained in:
@@ -31,13 +31,15 @@ func TestNativeMetadataWithoutConfiguration(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemovedSourceAndSchemaFlagsAreRejected(t *testing.T) {
|
||||
for _, command := range [][]string{{"run"}, {"serve"}, {"config", "show"}, {"promptkit", "list", "prompts"}} {
|
||||
nativePromptFixture(t, "http://127.0.0.1:1/v1")
|
||||
for _, command := range [][]string{{"run", "support/summary"}, {"serve"}, {"config", "show"}, {"promptkit", "list", "prompts"}} {
|
||||
for _, flag := range []string{"--promptkit-source=missing.yml", "--schema-dir=schemas"} {
|
||||
args := append(append([]string{}, command...), flag)
|
||||
args := append(append([]string{}, command...), "--config=app.yml", flag)
|
||||
var output, diagnostics bytes.Buffer
|
||||
outcome := Execute(context.Background(), commandkit.Identity{Name: "scriptorium"}, args, &output, &diagnostics)
|
||||
if outcome.Kind != commandkit.OutcomeUsage || outcome.Status != 2 {
|
||||
t.Fatalf("%v: %+v", args, outcome)
|
||||
flagName := strings.SplitN(flag, "=", 2)[0]
|
||||
if outcome.Kind != commandkit.OutcomeUsage || outcome.Status != 2 || !strings.Contains(diagnostics.String(), flagName) {
|
||||
t.Fatalf("%v: %+v diagnostics=%q", args, outcome, diagnostics.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/fs"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
@@ -377,3 +378,32 @@ func TestServeListenAndConfigurationFailures(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeCaptureFailureDoesNotListen(t *testing.T) {
|
||||
nativePromptFixture(t, "http://127.0.0.1:1/v1")
|
||||
writeNativeFile(t, "framework.yml", `prompts:
|
||||
- id: missing
|
||||
messages:
|
||||
- role: user
|
||||
content_file: absent-message.txt
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`)
|
||||
listened := false
|
||||
listen := func(context.Context, string, string) (net.Listener, error) {
|
||||
listened = true
|
||||
return nil, errors.New("unexpected listen")
|
||||
}
|
||||
app, err := commandkit.New(commandkit.Identity{Name: "scriptorium"}, commandkit.NewCommand(commandkit.CommandSpec[serveInput]{Name: "serve", Flags: serveFlags(), Run: func(inv commandkit.Invocation, input serveInput) commandkit.Outcome {
|
||||
return serveWithListener(inv, input, listen)
|
||||
}}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
var output, diagnostics bytes.Buffer
|
||||
outcome := app.Execute(context.Background(), []string{"serve", "--config=app.yml"}, commandkit.Streams{Out: &output, Err: &diagnostics})
|
||||
if outcome.Status != 1 || !errors.Is(outcome.Cause, promptkit.ErrInvalidConfig) || !errors.Is(outcome.Cause, fs.ErrNotExist) || output.Len() != 0 || listened {
|
||||
t.Fatalf("capture failure: outcome=%+v stdout=%q diagnostics=%q listened=%t", outcome, output.String(), diagnostics.String(), listened)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user