Carry optional prompt labels through results

This commit is contained in:
2026-10-17 05:54:32 +00:00
parent 8cbb7c0daf
commit ec3245c97e
40 changed files with 363 additions and 121 deletions

View File

@@ -12,6 +12,10 @@ import (
"gitea.maximumdirect.net/eric/promptkit"
)
func stringPointerForTest(value string) *string {
return &value
}
func TestGenerateResponseUsagePresenceJSON(t *testing.T) {
value := promptkit.GenerateResponse{
Content: "ok",
@@ -42,6 +46,45 @@ func TestGenerateResponseUsagePresenceJSON(t *testing.T) {
}
}
func TestPromptVersionJSONDistinguishesAbsenceAndDeclaredEmpty(t *testing.T) {
tests := []struct {
name string
value *string
wantPresent bool
wantValue string
}{
{name: "absent"},
{name: "declared empty", value: stringPointerForTest(""), wantPresent: true},
{name: "declared text", value: stringPointerForTest("release/v1"), wantPresent: true, wantValue: "release/v1"},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
check := func(label string, marshal func() ([]byte, error)) {
t.Helper()
payload, err := marshal()
if err != nil {
t.Fatal(err)
}
object := decodeJSONObject(t, payload)
value, present := object["prompt_version"]
if present != test.wantPresent {
t.Errorf("%s prompt_version present=%t, want %t: %s", label, present, test.wantPresent, payload)
}
var decoded string
if test.wantPresent && (json.Unmarshal(value, &decoded) != nil || decoded != test.wantValue) {
t.Errorf("%s prompt_version=%#v, want %q", label, value, test.wantValue)
}
}
check("prepared", func() ([]byte, error) {
return json.Marshal(promptkit.PreparedRun{PromptVersion: test.value})
})
check("result", func() ([]byte, error) {
return json.Marshal(promptkit.RunResult{PromptVersion: test.value})
})
})
}
}
func TestPreparedRunJSONContractRoundTripsAllFields(t *testing.T) {
value := fullyPopulatedPreparedRun()
payload, err := json.Marshal(value)
@@ -216,7 +259,7 @@ func fullyPopulatedPreparedRun() promptkit.PreparedRun {
start := time.Date(2026, time.August, 11, 12, 13, 14, 150_000_000, time.UTC)
return promptkit.PreparedRun{
PromptID: "prompt.prepared",
PromptVersion: "2.1.0",
PromptVersion: stringPointerForTest("2.1.0"),
PromptHash: "prompt-hash",
SelectedProfileID: "profile-prepared",
SelectedBackendID: "backend-prepared",
@@ -283,7 +326,7 @@ func fullyPopulatedRunResult() promptkit.RunResult {
IsValid: false,
},
PromptID: "prompt.result",
PromptVersion: "3.2.1",
PromptVersion: stringPointerForTest("3.2.1"),
PromptHash: "result-prompt-hash",
SessionID: "session-result",
RenderedPromptHash: "result-rendered-hash",