Documentation cleanup and bugfixes

This commit is contained in:
2026-05-05 20:01:45 -05:00
parent 2b9658fb01
commit bf058a046e
10 changed files with 162 additions and 39 deletions

View File

@@ -5,12 +5,13 @@ import (
)
type runRequestDTO struct {
PromptID string `json:"prompt_id"`
PromptVersion string `json:"prompt_version,omitempty"`
ProfileID string `json:"profile_id,omitempty"`
Inputs map[string]inputRefDTO `json:"inputs"`
Vars map[string]string `json:"vars,omitempty"`
Model *modelOverrideRequestDTO `json:"model,omitempty"`
PromptID string `json:"prompt_id"`
PromptVersion string `json:"prompt_version,omitempty"`
ProfileID string `json:"profile_id,omitempty"`
Inputs map[string]inputRefDTO `json:"inputs"`
Vars map[string]string `json:"vars,omitempty"`
Model *modelOverrideRequestDTO `json:"model,omitempty"`
IncludeRawOutput bool `json:"include_raw_output,omitempty"`
}
type inputRefDTO struct {
@@ -35,7 +36,7 @@ type runResponseDTO struct {
Artifact artifactDTO `json:"artifact"`
Validation validationDTO `json:"validation"`
Metadata metadataDTO `json:"metadata"`
RawModelOutput string `json:"raw_model_output"`
RawModelOutput *string `json:"raw_model_output,omitempty"`
}
type artifactDTO struct {

View File

@@ -90,7 +90,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
writeJSON(w, http.StatusOK, runResponseDTO{
resp := runResponseDTO{
Artifact: artifactDTO{
Name: res.Artifact.Name,
ContentType: res.Artifact.ContentType,
@@ -133,8 +133,12 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ValidationStatus: string(res.Validation.Status),
RepairAttemptsUsed: res.Validation.RepairAttempts,
},
RawModelOutput: res.RawOutput,
})
}
if req.IncludeRawOutput {
raw := res.RawOutput
resp.RawModelOutput = &raw
}
writeJSON(w, http.StatusOK, resp)
}
func mapValidation(v domain.ValidationResult) validationDTO {

View File

@@ -117,6 +117,9 @@ func TestHandlerPostRunsSuccessWithExplicitProfileID(t *testing.T) {
if strings.Contains(w.Body.String(), secret) {
t.Fatalf("response leaked raw API key value: %s", w.Body.String())
}
if _, ok := resp["raw_model_output"]; ok {
t.Fatalf("expected raw_model_output to be omitted by default, got %#v", resp["raw_model_output"])
}
if r.last.PromptID != "prompt-1" {
t.Fatalf("expected request prompt_id prompt-1, got %q", r.last.PromptID)
@@ -265,7 +268,7 @@ func TestHandlerRawAPIKeyRejectedByStrictJSON(t *testing.T) {
}
}
func TestHandlerValidationFailureStillSuccess(t *testing.T) {
func TestHandlerValidationFailureStillSuccessAndRawOutputOptIn(t *testing.T) {
h := NewHandler(&fakeRunner{result: &domain.RunResult{
Artifact: domain.Artifact{Body: []byte("bad json")},
RawOutput: "bad json",
@@ -292,6 +295,24 @@ func TestHandlerValidationFailureStillSuccess(t *testing.T) {
if status, ok := validation["status"].(string); !ok || status != "failed" {
t.Fatalf("expected validation status=failed, got %#v", validation["status"])
}
if _, ok := resp["raw_model_output"]; ok {
t.Fatalf("expected raw_model_output omitted by default, got %#v", resp["raw_model_output"])
}
reqWithRaw := httptest.NewRequest(http.MethodPost, "/v1/runs", bytes.NewBufferString(`{"prompt_id":"p","inputs":{"x":{"type":"file","uri":"a"}},"include_raw_output":true}`))
wWithRaw := httptest.NewRecorder()
h.ServeHTTP(wWithRaw, reqWithRaw)
if wWithRaw.Code != http.StatusOK {
t.Fatalf("expected 200, got %d: %s", wWithRaw.Code, wWithRaw.Body.String())
}
var respWithRaw map[string]any
if err := json.Unmarshal(wWithRaw.Body.Bytes(), &respWithRaw); err != nil {
t.Fatalf("invalid JSON response: %v", err)
}
if got, ok := respWithRaw["raw_model_output"].(string); !ok || got != "bad json" {
t.Fatalf("expected raw_model_output to be included when requested, got %#v", respWithRaw["raw_model_output"])
}
}
func wrap(stage error, cause error) error {