Expose backend identity and capacity errors
This commit is contained in:
@@ -148,7 +148,7 @@ func runCommand(args []string, stdout, stderr io.Writer) int {
|
||||
|
||||
res, runErr := engine.Run(context.Background(), req)
|
||||
if runErr != nil {
|
||||
fmt.Fprintf(stderr, "run error: %v\n", runErr)
|
||||
fmt.Fprintln(stderr, runErrorMessage(runErr))
|
||||
return ExitRuntimeError
|
||||
}
|
||||
|
||||
@@ -732,9 +732,19 @@ func printSummary(stderr io.Writer, res *promptkit.RunResult) {
|
||||
if res.Usage.CachedTokens != 0 || res.Usage.CacheWriteTokens != 0 {
|
||||
fmt.Fprintf(stderr, " cached_tokens=%d cache_write_tokens=%d", res.Usage.CachedTokens, res.Usage.CacheWriteTokens)
|
||||
}
|
||||
if res.SelectedBackendID != "" {
|
||||
fmt.Fprintf(stderr, " backend=%s", res.SelectedBackendID)
|
||||
}
|
||||
fmt.Fprintln(stderr)
|
||||
}
|
||||
|
||||
func runErrorMessage(err error) string {
|
||||
if errors.Is(err, promptkit.ErrCapacityExceeded) {
|
||||
return "run error: model backend capacity is exhausted"
|
||||
}
|
||||
return fmt.Sprintf("run error: %v", err)
|
||||
}
|
||||
|
||||
func printUsage(w io.Writer) {
|
||||
fmt.Fprintln(w, "usage: scriptorium <run|render|serve> ...")
|
||||
fmt.Fprintln(w, " run: scriptorium run [--config PATH] [--prompt-dir DIR] [--profile-dir DIR] --prompt ID [--prompt-version VERSION] [--input name=path] [--profile ID] [--session-id ID] [--llm-base-url URL] [--model NAME] [--api-key-env ENV] [--temperature N] [--max-tokens N] [--top-p N] [--reasoning-effort VALUE] [--var k=v] [--out path] [--timeout 10m]")
|
||||
|
||||
@@ -1033,13 +1033,16 @@ backends:
|
||||
queue_capacity: 0
|
||||
`, lib.promptDir, lib.profileDir))
|
||||
|
||||
code, _, stderr := runCLICommand(t, renderCommand, []string{
|
||||
code, stdout, stderr := runCLICommand(t, renderCommand, []string{
|
||||
"--config", configPath,
|
||||
"--prompt", "custom",
|
||||
})
|
||||
if code != ExitOK {
|
||||
t.Fatalf("expected ExitOK, got %d stderr=%q", code, stderr)
|
||||
}
|
||||
if !strings.Contains(stdout, "selected_backend_id: local-gpu") {
|
||||
t.Fatalf("expected configured backend in prepared output, got:\n%s", stdout)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderCommandMapsReasoningEffortAndSessionID(t *testing.T) {
|
||||
@@ -1624,6 +1627,9 @@ func TestWriteOutputAndSummaryUseSeparateWriters(t *testing.T) {
|
||||
if strings.Contains(stderr.String(), "cached_tokens=") || strings.Contains(stderr.String(), "cache_write_tokens=") {
|
||||
t.Fatalf("expected zero cache usage to be omitted from summary, got %q", stderr.String())
|
||||
}
|
||||
if strings.Contains(stderr.String(), "backend=") {
|
||||
t.Fatalf("expected endpoint-only backend to be omitted from summary, got %q", stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintSummaryIncludesCacheUsageWhenPresent(t *testing.T) {
|
||||
@@ -1653,6 +1659,32 @@ func TestPrintSummaryIncludesCacheUsageWhenPresent(t *testing.T) {
|
||||
if !strings.Contains(summary, "cached_tokens=0 cache_write_tokens=3") {
|
||||
t.Fatalf("expected cache usage in summary, got %q", summary)
|
||||
}
|
||||
if strings.Contains(summary, "backend=") {
|
||||
t.Fatalf("expected endpoint-only backend to be omitted from summary, got %q", summary)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPrintSummaryIncludesBackendWhenPresent(t *testing.T) {
|
||||
var stderr bytes.Buffer
|
||||
printSummary(&stderr, &promptkit.RunResult{
|
||||
PromptID: "p",
|
||||
PromptVersion: "1",
|
||||
SelectedProfileID: "exec",
|
||||
SelectedBackendID: "local",
|
||||
ModelName: "m",
|
||||
Validation: promptkit.ValidationResult{Status: promptkit.ValidationPassed, Mode: promptkit.ValidationBasic},
|
||||
RenderedPromptHash: "h",
|
||||
})
|
||||
if !strings.Contains(stderr.String(), "backend=local") {
|
||||
t.Fatalf("expected backend in summary, got %q", stderr.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunErrorMessageDoesNotExposeCapacityDetails(t *testing.T) {
|
||||
got := runErrorMessage(&promptkit.CapacityError{BackendID: "private-backend"})
|
||||
if got != "run error: model backend capacity is exhausted" {
|
||||
t.Fatalf("unexpected capacity diagnostic: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
type cliTestLibrary struct {
|
||||
|
||||
Reference in New Issue
Block a user