Allow prompt version selection without inputs
This commit is contained in:
@@ -87,9 +87,12 @@ func TestParseRunArgsRequiredFlags(t *testing.T) {
|
||||
t.Fatal("expected missing --prompt error")
|
||||
}
|
||||
|
||||
_, err = parseRunArgs([]string{"--config", configPath, "--prompt-dir", "./prompts", "--profile-dir", "./profiles", "--prompt", "p"})
|
||||
if err == nil {
|
||||
t.Fatal("expected missing --input error")
|
||||
cfg, err = parseRunArgs([]string{"--config", configPath, "--prompt-dir", "./prompts", "--profile-dir", "./profiles", "--prompt", "p"})
|
||||
if err != nil {
|
||||
t.Fatalf("expected omitted --input to be accepted, got %v", err)
|
||||
}
|
||||
if len(cfg.inputRaw) != 0 {
|
||||
t.Fatalf("expected no input mappings, got %#v", cfg.inputRaw)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +101,7 @@ func TestParseRunArgsFlagMapping(t *testing.T) {
|
||||
"--prompt-dir", "./prompts",
|
||||
"--profile-dir", "./profiles",
|
||||
"--prompt", "prompt.a",
|
||||
"--prompt-version", "2",
|
||||
"--profile", "profile.a",
|
||||
"--input", "a=b",
|
||||
"--llm-base-url", "http://x/v1",
|
||||
@@ -114,8 +118,8 @@ func TestParseRunArgsFlagMapping(t *testing.T) {
|
||||
if cfg.promptDir != filepath.Clean("./prompts") || cfg.profileDir != filepath.Clean("./profiles") {
|
||||
t.Fatalf("unexpected dirs: prompt=%q profile=%q", cfg.promptDir, cfg.profileDir)
|
||||
}
|
||||
if cfg.promptID != "prompt.a" || cfg.profileID != "profile.a" {
|
||||
t.Fatalf("unexpected prompt/profile ids: %q %q", cfg.promptID, cfg.profileID)
|
||||
if cfg.promptID != "prompt.a" || cfg.promptVersion != "2" || cfg.profileID != "profile.a" {
|
||||
t.Fatalf("unexpected prompt/version/profile ids: %q %q %q", cfg.promptID, cfg.promptVersion, cfg.profileID)
|
||||
}
|
||||
if !cfg.llmBaseURLSet || !cfg.modelSet || !cfg.temperatureSet || !cfg.maxTokensSet || !cfg.topPSet || !cfg.timeoutSet || !cfg.apiKeyEnvSet {
|
||||
t.Fatalf("expected override flags set, got %+v", cfg)
|
||||
@@ -192,7 +196,7 @@ func TestParseServeArgsRejectsRuntimeOverrideFlags(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUsageIncludesServeFileAndSizeLimitFlags(t *testing.T) {
|
||||
func TestUsageIncludesExecutionAndServeFlags(t *testing.T) {
|
||||
var stderr bytes.Buffer
|
||||
code := Run(nil, io.Discard, &stderr)
|
||||
if code != ExitRuntimeError {
|
||||
@@ -201,6 +205,7 @@ func TestUsageIncludesServeFileAndSizeLimitFlags(t *testing.T) {
|
||||
|
||||
usage := stderr.String()
|
||||
for _, want := range []string{
|
||||
"--prompt-version VERSION",
|
||||
"--artifact-root",
|
||||
"--max-request-bytes",
|
||||
"--max-artifact-bytes",
|
||||
@@ -689,6 +694,22 @@ func TestBuildRunRequestPreservesNumericOverridePresence(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildRunRequestAllowsOmittedInputsAndMapsPromptVersion(t *testing.T) {
|
||||
req, err := buildRunRequestFromConfig(&runConfig{
|
||||
promptID: "prompt-1",
|
||||
promptVersion: "2",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("expected request without inputs to build, got %v", err)
|
||||
}
|
||||
if req.PromptVersion != "2" {
|
||||
t.Fatalf("expected prompt version to be mapped, got %q", req.PromptVersion)
|
||||
}
|
||||
if req.Inputs != nil {
|
||||
t.Fatalf("expected omitted inputs to remain nil, got %#v", req.Inputs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseRunArgsFailsClearlyWhenNoEffectivePromptDir(t *testing.T) {
|
||||
configPath := writeAppConfigFile(t, `
|
||||
profile_dir: ./profiles
|
||||
@@ -1122,6 +1143,104 @@ func TestRenderCommandExplicitProfileOverridesPromptDefault(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderCommandUsesDefinitionInputRulesAndPromptVersions(t *testing.T) {
|
||||
lib := newCLITestLibrary(t)
|
||||
writeProfileFile(t, lib.profileDir, "local", "http://127.0.0.1:1/v1", "model")
|
||||
|
||||
writePromptDefinition(t, lib.promptDir, "sole.yaml", `id: sole
|
||||
version: "1"
|
||||
default_profile: local
|
||||
messages:
|
||||
- role: user
|
||||
content: "hello"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`)
|
||||
writePromptDefinition(t, lib.promptDir, "versioned-one.yaml", `id: versioned
|
||||
version: "1"
|
||||
default_profile: local
|
||||
messages:
|
||||
- role: user
|
||||
content: "one"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`)
|
||||
writePromptDefinition(t, lib.promptDir, "versioned-two.yaml", `id: versioned
|
||||
version: "2"
|
||||
default_profile: local
|
||||
messages:
|
||||
- role: user
|
||||
content: "two"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`)
|
||||
writePromptDefinition(t, lib.promptDir, "optional.yaml", `id: optional
|
||||
version: "1"
|
||||
default_profile: local
|
||||
inputs:
|
||||
- name: note
|
||||
required: false
|
||||
messages:
|
||||
- role: user
|
||||
content: "hello"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`)
|
||||
writePromptDefinition(t, lib.promptDir, "required.yaml", `id: required
|
||||
version: "1"
|
||||
default_profile: local
|
||||
inputs:
|
||||
- name: note
|
||||
required: true
|
||||
messages:
|
||||
- role: user
|
||||
content: "hello"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`)
|
||||
writePromptDefinition(t, lib.promptDir, "template.yaml", `id: template
|
||||
version: "1"
|
||||
default_profile: local
|
||||
messages:
|
||||
- role: user
|
||||
content: '{{input "note"}}'
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`)
|
||||
|
||||
baseArgs := []string{"--prompt-dir", lib.promptDir, "--profile-dir", lib.profileDir}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
args []string
|
||||
wantCode int
|
||||
wantText string
|
||||
}{
|
||||
{name: "sole version selected when omitted", args: []string{"--prompt", "sole"}, wantCode: ExitOK, wantText: "prompt_version: 1"},
|
||||
{name: "explicit version selected", args: []string{"--prompt", "versioned", "--prompt-version", "2"}, wantCode: ExitOK, wantText: "prompt_version: 2"},
|
||||
{name: "multiple versions require selection", args: []string{"--prompt", "versioned"}, wantCode: ExitRuntimeError, wantText: "duplicate prompt definition id"},
|
||||
{name: "no declared inputs", args: []string{"--prompt", "sole"}, wantCode: ExitOK, wantText: "prompt: sole"},
|
||||
{name: "optional input omitted", args: []string{"--prompt", "optional"}, wantCode: ExitOK, wantText: "prompt: optional"},
|
||||
{name: "required input omitted", args: []string{"--prompt", "required"}, wantCode: ExitRuntimeError, wantText: "required"},
|
||||
{name: "template input omitted", args: []string{"--prompt", "template"}, wantCode: ExitRuntimeError, wantText: "note"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
code, stdout, stderr := runCLICommand(t, renderCommand, append(append([]string{}, baseArgs...), tc.args...))
|
||||
if code != tc.wantCode {
|
||||
t.Fatalf("expected exit %d, got %d stderr=%q", tc.wantCode, code, stderr)
|
||||
}
|
||||
if !strings.Contains(stdout+stderr, tc.wantText) {
|
||||
t.Fatalf("expected output to contain %q, stdout=%q stderr=%q", tc.wantText, stdout, stderr)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunCommandPromptDefaultProfileWorksThroughCLIPath(t *testing.T) {
|
||||
lib := newCLITestLibrary(t)
|
||||
inputPath := lib.writeInputFile(t, "transcript.md", "hello")
|
||||
@@ -1340,6 +1459,13 @@ func writePromptFile(t *testing.T, dir, id, defaultProfile string) {
|
||||
writePromptFileWithTemplate(t, dir, id, defaultProfile, "Summarize: {{input \"transcript\"}}")
|
||||
}
|
||||
|
||||
func writePromptDefinition(t *testing.T, dir, name, definition string) {
|
||||
t.Helper()
|
||||
if err := os.WriteFile(filepath.Join(dir, name), []byte(definition), 0o644); err != nil {
|
||||
t.Fatalf("write prompt definition: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func writePromptFileWithTemplate(t *testing.T, dir, id, defaultProfile, templateContent string) {
|
||||
t.Helper()
|
||||
data := fmt.Sprintf(`id: %s
|
||||
|
||||
Reference in New Issue
Block a user