Add custom backend configuration
This commit is contained in:
@@ -963,6 +963,98 @@ profile_dir: %s
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderCommandUsesConfiguredCustomBackend(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-gpu:
|
||||
endpoint: http://localhost:11434/v1
|
||||
extra_params:
|
||||
provider_option: enabled
|
||||
concurrency_limit: 2
|
||||
queue_capacity: 0
|
||||
`, lib.promptDir, lib.profileDir))
|
||||
|
||||
code, _, stderr := runCLICommand(t, renderCommand, []string{
|
||||
"--config", configPath,
|
||||
"--prompt", "custom",
|
||||
})
|
||||
if code != ExitOK {
|
||||
t.Fatalf("expected ExitOK, got %d stderr=%q", code, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfiguredBackendValidationComesFromPromptkit(t *testing.T) {
|
||||
lib := newCLITestLibrary(t)
|
||||
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
backend string
|
||||
}{
|
||||
{
|
||||
name: "reserved ID",
|
||||
backend: `openrouter:
|
||||
endpoint: http://localhost:11434/v1`,
|
||||
},
|
||||
{
|
||||
name: "invalid endpoint",
|
||||
backend: `local-gpu:
|
||||
endpoint: not-a-url`,
|
||||
},
|
||||
{
|
||||
name: "invalid capacity relationship",
|
||||
backend: `local-gpu:
|
||||
endpoint: http://localhost:11434/v1
|
||||
queue_capacity: 0`,
|
||||
},
|
||||
{
|
||||
name: "reserved extra parameter",
|
||||
backend: `local-gpu:
|
||||
endpoint: http://localhost:11434/v1
|
||||
extra_params:
|
||||
model: forbidden`,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
configPath := writeAppConfigFile(t, fmt.Sprintf(`
|
||||
prompt_dir: %s
|
||||
profile_dir: %s
|
||||
backends:
|
||||
%s
|
||||
`, lib.promptDir, lib.profileDir, tc.backend))
|
||||
cfg, err := parseRenderArgs([]string{"--config", configPath, "--prompt", "custom"})
|
||||
if err != nil {
|
||||
t.Fatalf("expected config decoding to succeed, got %v", err)
|
||||
}
|
||||
_, err = newEngine(cfg.runConfig.engineSettings())
|
||||
if !errors.Is(err, promptkit.ErrInvalidConfig) {
|
||||
t.Fatalf("expected Promptkit ErrInvalidConfig, got %v", err)
|
||||
}
|
||||
if !strings.Contains(err.Error(), "engine initialization from application configuration") {
|
||||
t.Fatalf("expected application context, got %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