Files
notarius/internal/cli/promptkit_commands_test.go

93 lines
3.1 KiB
Go
Raw Normal View History

package cli
import (
"bytes"
"context"
"encoding/json"
"path/filepath"
"strings"
"sync/atomic"
"testing"
"go.maximumdirect.net/commandkit"
"go.maximumdirect.net/promptkit"
)
type diagnosticClient struct{ calls atomic.Int32 }
func (client *diagnosticClient) Generate(context.Context, promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
client.calls.Add(1)
return &promptkit.GenerateResponse{Content: "PROMPTKIT_OK"}, nil
}
func TestNativePromptCommandsInspectPreviewAndSmokeExplicitly(t *testing.T) {
t.Parallel()
main := filepath.Join(t.TempDir(), "config.yml")
writeConfigKitFile(t, main, `version: 6
promptkit:
profiles:
- id: partial
model: fixture-model
- id: ready
endpoint: https://example.invalid/v1
model: fixture-model
api_key_required: false
prompts:
- id: preview
default_profile: ready
inputs: [{name: topic, required: true}]
messages: [{role: user, content: 'Topic: {{input "topic"}}'}]
output: {format: text, validation_mode: none}
`)
client := &diagnosticClient{}
app, err := NewApplication("development", Options{LLMClient: client})
if err != nil {
t.Fatal(err)
}
execute := func(args ...string) (commandkit.Outcome, []byte, string) {
var out, diagnostics bytes.Buffer
args = append(args, "--config", main, "--format", "json")
outcome := app.Execute(context.Background(), args, commandkit.Streams{Out: &out, Err: &diagnostics})
return outcome, out.Bytes(), diagnostics.String()
}
for _, args := range [][]string{
{"promptkit", "list", "prompts", "--all-namespaces"},
{"promptkit", "list", "profiles", "--all-namespaces"},
{"promptkit", "list", "backends", "--all-namespaces"},
{"promptkit", "list", "namespaces"},
{"promptkit", "list", "collections"},
{"promptkit", "show", "profile", "partial"},
{"promptkit", "show", "prompt", "preview"},
{"promptkit", "show", "backend", "openrouter"},
{"promptkit", "requirements", "show", "preview"},
{"promptkit", "requirements", "validate", "preview", "--llm-input-text=topic=fixture-topic"},
// The short input spelling comes from the native scoped alias declarations.
{"promptkit", "show", "prepared", "preview", "--input=topic=fixture-topic", "--reasoning-effort=", "--transient-retries=0"},
} {
outcome, out, diagnostics := execute(args...)
if outcome.Status != 0 || !json.Valid(out) {
t.Fatalf("%v: %#v, %s, %s", args, outcome, out, diagnostics)
}
if len(args) > 2 && args[1] == "show" && args[2] == "prepared" && !strings.Contains(string(out), "fixture-topic") {
t.Fatalf("preview lost explicit input: %s", out)
}
}
if client.calls.Load() != 0 {
t.Fatal("inspection implicitly called provider")
}
outcome, out, diagnostics := execute("promptkit", "test", "text-inference", "--llm-profile=ready")
if outcome.Status != 0 || client.calls.Load() == 0 {
t.Fatalf("explicit smoke: %#v, %s, %s", outcome, out, diagnostics)
}
var report struct {
Supported bool `json:"supported"`
Completed bool `json:"completed"`
}
if err := json.Unmarshal(out, &report); err != nil {
t.Fatal(err)
}
if !report.Supported || !report.Completed {
t.Fatalf("native smoke distinctions lost: %s", out)
}
}