Strengthen startup and error regression tests
This commit is contained in:
@@ -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