Adapt inspection to native PromptKit records
This commit is contained in:
@@ -1442,26 +1442,29 @@ func TestRenderCommandRejectsOverlongSessionID(t *testing.T) {
|
||||
func TestInspectPromptCommandFormatsDefinitionWithoutProfileOrGeneration(t *testing.T) {
|
||||
lib := newCLITestLibrary(t)
|
||||
writePromptDefinition(t, lib.promptDir, "inspect.yaml", `prompts:
|
||||
inspect:
|
||||
"1":
|
||||
messages:
|
||||
- role: user
|
||||
content: "hello"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
- id: inspect
|
||||
inputs: []
|
||||
messages:
|
||||
- role: user
|
||||
content: "private message"
|
||||
output:
|
||||
format: text
|
||||
validation_mode: none
|
||||
`)
|
||||
code, stdout, stderr := runCLICommand(t, inspectCommand, []string{"prompt", "--config", lib.configPath, "--promptkit-source", lib.promptDir, "--prompt", "inspect", "--format", "json"})
|
||||
if code != ExitOK {
|
||||
t.Fatalf("expected ExitOK, got %d stderr=%q", code, stderr)
|
||||
}
|
||||
if !strings.Contains(stdout, `"prompt_id": "inspect"`) || !strings.Contains(stdout, `"inputs": []`) {
|
||||
if !strings.Contains(stdout, `"prompt_id": "inspect"`) || !strings.Contains(stdout, `"inputs": []`) || strings.Contains(stdout, "private message") || strings.Contains(stdout, "prompt_version") {
|
||||
t.Fatalf("unexpected inspection output: %s", stdout)
|
||||
}
|
||||
code, stdout, stderr = runCLICommand(t, inspectCommand, []string{"prompt", "--config", lib.configPath, "--promptkit-source", lib.promptDir, "--prompt", "missing"})
|
||||
if code != ExitRuntimeError || stdout != "" || !strings.Contains(stderr, "inspect error") {
|
||||
t.Fatalf("expected failed inspection without output, got code=%d stdout=%q stderr=%q", code, stdout, stderr)
|
||||
}
|
||||
if _, err := parsePromptInspectionArgs([]string{"--prompt", "inspect", "--prompt-version", "1"}); err == nil {
|
||||
t.Fatal("inspection accepted removed prompt version flag")
|
||||
}
|
||||
}
|
||||
|
||||
func TestInspectionParsersPreserveExplicitEmptyConfigPath(t *testing.T) {
|
||||
@@ -1821,28 +1824,34 @@ func TestExecutionReportPathValidationAndPreInvocationFailure(t *testing.T) {
|
||||
|
||||
func intPointer(value int) *int { return &value }
|
||||
|
||||
func TestPromptkitPromptInspectionSelectsVersionsAndContracts(t *testing.T) {
|
||||
func pointerValue[T any](value *T) T {
|
||||
if value == nil {
|
||||
var zero T
|
||||
return zero
|
||||
}
|
||||
return *value
|
||||
}
|
||||
|
||||
func TestPromptkitPromptInspectionSelectsIDsAndContracts(t *testing.T) {
|
||||
fixtureRoot := definitionFixtureRoot(t)
|
||||
configPath := writeDefinitionFixtureConfig(t, fixtureRoot)
|
||||
tests := []struct {
|
||||
promptID string
|
||||
version string
|
||||
format string
|
||||
mode string
|
||||
}{
|
||||
{promptID: "compat.complete", version: "1.0.0", format: "json", mode: "json_schema"},
|
||||
{promptID: "compat.complete", version: "2.0.0", format: "text", mode: "basic"},
|
||||
{promptID: "compat.json", version: "1.0.0", format: "json", mode: "json"},
|
||||
{promptID: "compat.none", version: "1.0.0", format: "text", mode: "none"},
|
||||
{promptID: "compat.complete", format: "json", mode: "json_schema"},
|
||||
{promptID: "compat.complete-text", format: "text", mode: "basic"},
|
||||
{promptID: "compat.json", format: "json", mode: "json"},
|
||||
{promptID: "compat.none", format: "text", mode: "none"},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.promptID+"@"+tc.version, func(t *testing.T) {
|
||||
t.Run(tc.promptID, func(t *testing.T) {
|
||||
code, stdout, stderr := runCLICommand(t, inspectCommand, []string{
|
||||
"prompt",
|
||||
"--config", configPath,
|
||||
"--prompt", tc.promptID,
|
||||
"--prompt-version", tc.version,
|
||||
"--format", "json",
|
||||
})
|
||||
if code != ExitOK {
|
||||
@@ -1852,7 +1861,7 @@ func TestPromptkitPromptInspectionSelectsVersionsAndContracts(t *testing.T) {
|
||||
if err := json.Unmarshal([]byte(stdout), &inspection); err != nil {
|
||||
t.Fatalf("decode prompt inspection: %v\nbody=%s", err, stdout)
|
||||
}
|
||||
if inspection.PromptVersion != tc.version || inspection.OutputContract.Format != tc.format || inspection.OutputContract.ValidationMode != tc.mode {
|
||||
if inspection.PromptID != tc.promptID || inspection.OutputContract.Format != tc.format || inspection.OutputContract.ValidationMode != tc.mode {
|
||||
t.Fatalf("unexpected prompt inspection: %+v", inspection)
|
||||
}
|
||||
})
|
||||
@@ -1891,12 +1900,12 @@ func TestPromptkitProfileInspectionResolvesSupportedTargets(t *testing.T) {
|
||||
if err := json.Unmarshal([]byte(stdout), &inspection); err != nil {
|
||||
t.Fatalf("decode profile inspection: %v\nbody=%s", err, stdout)
|
||||
}
|
||||
params := inspection.EffectiveModelParams
|
||||
if inspection.ProfileID != tc.profileID || params.BackendID != tc.wantBackend || params.Model != tc.wantModel || params.APIKeyEnv != tc.wantAPIKeyEnv {
|
||||
params := inspection.ProfileModelParams
|
||||
if inspection.ProfileID != tc.profileID || pointerValue(params.BackendID) != tc.wantBackend || pointerValue(params.Model) != tc.wantModel || pointerValue(params.APIKeyEnv) != tc.wantAPIKeyEnv {
|
||||
t.Fatalf("unexpected effective profile: %+v", inspection)
|
||||
}
|
||||
if tc.profileID == "custom-derived" {
|
||||
if params.ServiceTier != "flex" || params.ReasoningEffort != "high" || params.TimeoutSeconds != 45 || len(params.ExtraParams) == 0 {
|
||||
if pointerValue(params.ServiceTier) != "flex" || pointerValue(params.ReasoningEffort) != "high" || pointerValue(params.TimeoutSeconds) != 45 || len(pointerValue(params.ExtraParams)) == 0 {
|
||||
t.Fatalf("inherited profile controls were not resolved: %+v", params)
|
||||
}
|
||||
}
|
||||
@@ -1948,8 +1957,8 @@ prompts:
|
||||
if err := json.Unmarshal([]byte(stdout), &inspection); err != nil {
|
||||
t.Fatalf("decode combined-source profile inspection: %v", err)
|
||||
}
|
||||
if inspection.EffectiveModelParams.BackendID != "fixture" || inspection.EffectiveModelParams.Model != "fixture-model" {
|
||||
t.Fatalf("combined source did not provide the selected profile: %+v", inspection.EffectiveModelParams)
|
||||
if pointerValue(inspection.ProfileModelParams.BackendID) != "fixture" || pointerValue(inspection.ProfileModelParams.Model) != "fixture-model" {
|
||||
t.Fatalf("combined source did not provide the selected profile: %+v", inspection.ProfileModelParams)
|
||||
}
|
||||
|
||||
invalidCombined := strings.Replace(combined, `content: "valid unused prompt"`, `content: "{{"`, 1)
|
||||
@@ -1989,11 +1998,11 @@ func TestMaintainedProfilesResolveAcrossSelectionAndSourcePrecedence(t *testing.
|
||||
if err := json.Unmarshal([]byte(stdout), &inspection); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if inspection.ProfileID != profileID || inspection.EffectiveModelParams.BackendID != "openrouter" || inspection.EffectiveModelParams.Model == "" {
|
||||
if inspection.ProfileID != profileID || pointerValue(inspection.ProfileModelParams.BackendID) != "openrouter" || pointerValue(inspection.ProfileModelParams.Model) == "" {
|
||||
t.Fatalf("maintained profile did not resolve: %+v", inspection)
|
||||
}
|
||||
if profileID == "promptkit-openrouter-auto" && inspection.EffectiveModelParams.Model != "openrouter/auto" {
|
||||
t.Fatalf("unexpected auto target: %+v", inspection.EffectiveModelParams)
|
||||
if profileID == "promptkit-openrouter-auto" && pointerValue(inspection.ProfileModelParams.Model) != "openrouter/auto" {
|
||||
t.Fatalf("unexpected auto target: %+v", inspection.ProfileModelParams)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -2040,7 +2049,7 @@ func TestMaintainedProfilesResolveAcrossSelectionAndSourcePrecedence(t *testing.
|
||||
if err := json.Unmarshal([]byte(stdout), &inspection); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if inspection.EffectiveModelParams.BackendID != "openrouter" || inspection.EffectiveModelParams.Model != tc.model {
|
||||
if pointerValue(inspection.ProfileModelParams.BackendID) != "openrouter" || pointerValue(inspection.ProfileModelParams.Model) != tc.model {
|
||||
t.Fatalf("unexpected effective target: %+v", inspection)
|
||||
}
|
||||
})
|
||||
@@ -2071,7 +2080,7 @@ func TestProfileInspectionHonorsDirectoryPrecedenceOutputAndFailures(t *testing.
|
||||
if err != nil {
|
||||
t.Fatalf("read profile inspection output: %v", err)
|
||||
}
|
||||
if !strings.Contains(string(output), `"model": "override-model"`) || !strings.Contains(string(output), `"backend_id": ""`) {
|
||||
if !strings.Contains(string(output), `"model": "override-model"`) || strings.Contains(string(output), `"backend_id"`) {
|
||||
t.Fatalf("profile source override was not used: %s", output)
|
||||
}
|
||||
|
||||
@@ -2159,8 +2168,8 @@ func TestConfiguredBackendValidationComesFromPromptkit(t *testing.T) {
|
||||
if err := json.Unmarshal([]byte(stdout), &inspection); err != nil {
|
||||
t.Fatalf("decode built-in profile inspection: %v", err)
|
||||
}
|
||||
if inspection.EffectiveModelParams.BackendID != "openrouter" || inspection.EffectiveModelParams.Endpoint != "http://localhost:11434/v1" {
|
||||
t.Fatalf("caller overlay did not update the built-in backend: %+v", inspection.EffectiveModelParams)
|
||||
if pointerValue(inspection.ProfileModelParams.BackendID) != "openrouter" || inspection.ProfileModelParams.Endpoint != nil {
|
||||
t.Fatalf("profile inspection unexpectedly completed backend settings: %+v", inspection.ProfileModelParams)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user