Test CLI inheritance inspection and use
This commit is contained in:
@@ -1148,6 +1148,59 @@ backends:
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderCommandUsesInheritedCustomBackend(t *testing.T) {
|
||||
lib := newCLITestLibrary(t)
|
||||
writePromptDefinition(t, lib.promptDir, "custom.yaml", `id: custom
|
||||
version: "1"
|
||||
default_profile: local-gpu
|
||||
messages:
|
||||
- role: user
|
||||
content: "hello"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`)
|
||||
if err := os.WriteFile(filepath.Join(lib.profileDir, "local-gpu.yaml"), []byte(`id: local-gpu
|
||||
backend: local-gpu
|
||||
model: local-model
|
||||
`), 0o644); err != nil {
|
||||
t.Fatalf("write profile fixture: %v", err)
|
||||
}
|
||||
configPath := writeAppConfigFile(t, fmt.Sprintf(`
|
||||
prompt_dir: %s
|
||||
profile_dir: %s
|
||||
backends:
|
||||
local-base:
|
||||
endpoint: http://localhost:11434/v1
|
||||
api_key_env: LOCAL_GPU_API_KEY
|
||||
concurrency_limit: 2
|
||||
local-gpu:
|
||||
extends: local-base
|
||||
queue_capacity: 0
|
||||
extra_params:
|
||||
provider_option: false
|
||||
`, lib.promptDir, lib.profileDir))
|
||||
|
||||
code, stdout, stderr := runCLICommand(t, renderCommand, []string{
|
||||
"--config", configPath,
|
||||
"--prompt", "custom",
|
||||
"--format", "json",
|
||||
})
|
||||
if code != ExitOK {
|
||||
t.Fatalf("expected inherited backend preparation to succeed, got %d stderr=%q", code, stderr)
|
||||
}
|
||||
var prepared promptkit.PreparedRun
|
||||
if err := json.Unmarshal([]byte(stdout), &prepared); err != nil {
|
||||
t.Fatalf("decode prepared output: %v\n%s", err, stdout)
|
||||
}
|
||||
if prepared.SelectedBackendID != "local-gpu" || prepared.EffectiveModelParams.BackendID != "local-gpu" {
|
||||
t.Fatalf("prepared run did not select the child backend: %+v", prepared)
|
||||
}
|
||||
if prepared.EffectiveModelParams.Endpoint != "http://localhost:11434/v1" {
|
||||
t.Fatalf("prepared run did not use the inherited endpoint: %+v", prepared.EffectiveModelParams)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfiguredBackendPreservesIntegerParameterAndOptionalCredential(t *testing.T) {
|
||||
lib := newCLITestLibrary(t)
|
||||
writePromptDefinition(t, lib.promptDir, "custom.yaml", `id: custom
|
||||
@@ -1974,6 +2027,27 @@ backends:
|
||||
}
|
||||
}
|
||||
|
||||
func TestInheritedBackendParentStillReceivesPromptkitValidation(t *testing.T) {
|
||||
lib := newCLITestLibrary(t)
|
||||
configPath := writeAppConfigFile(t, fmt.Sprintf(`
|
||||
prompt_dir: %s
|
||||
profile_dir: %s
|
||||
backends:
|
||||
base:
|
||||
endpoint: not-a-url
|
||||
child:
|
||||
extends: base
|
||||
endpoint: http://localhost:11434/v1
|
||||
`, lib.promptDir, lib.profileDir))
|
||||
cfg, err := parseRenderArgs([]string{"--config", configPath, "--prompt", "custom"})
|
||||
if err != nil {
|
||||
t.Fatalf("application loading rejected the configured parent before Promptkit: %v", err)
|
||||
}
|
||||
if _, err := newEngine(cfg.runConfig.engineSettings()); !errors.Is(err, promptkit.ErrInvalidConfig) {
|
||||
t.Fatalf("invalid parent backend was not validated by Promptkit: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderCommandExplicitTextFormatWorks(t *testing.T) {
|
||||
lib := newCLITestLibrary(t)
|
||||
inputPath := lib.writeInputFile(t, "transcript.md", "hello transcript")
|
||||
|
||||
Reference in New Issue
Block a user