Skip to content

Commit da6e079

Browse files
test(e2e): assert requested audit model
1 parent 00134ed commit da6e079

2 files changed

Lines changed: 52 additions & 4 deletions

File tree

internal/admin/handler_test.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -823,6 +823,54 @@ func TestAuditLog_Success(t *testing.T) {
823823
}
824824
}
825825

826+
func TestAuditLog_EmitsRequestedModel(t *testing.T) {
827+
now := time.Now().UTC()
828+
reader := &mockAuditReader{
829+
logResult: &auditlog.LogListResult{
830+
Entries: []auditlog.LogEntry{
831+
{
832+
ID: "log-1",
833+
Timestamp: now,
834+
RequestedModel: "does-not-exist-model",
835+
StatusCode: http.StatusBadRequest,
836+
RequestID: "req-1",
837+
Method: http.MethodPost,
838+
Path: "/v1/chat/completions",
839+
ErrorType: string(core.ErrorTypeInvalidRequest),
840+
},
841+
},
842+
Total: 1,
843+
Limit: 25,
844+
Offset: 0,
845+
},
846+
}
847+
848+
h := NewHandler(nil, nil, WithAuditReader(reader))
849+
c, rec := newHandlerContext("/admin/api/v1/audit/log?search=req-1")
850+
851+
if err := h.AuditLog(c); err != nil {
852+
t.Fatalf("unexpected error: %v", err)
853+
}
854+
if rec.Code != http.StatusOK {
855+
t.Fatalf("expected 200, got %d", rec.Code)
856+
}
857+
858+
var result struct {
859+
Entries []struct {
860+
RequestedModel string `json:"requested_model"`
861+
} `json:"entries"`
862+
}
863+
if err := json.Unmarshal(rec.Body.Bytes(), &result); err != nil {
864+
t.Fatalf("failed to unmarshal: %v", err)
865+
}
866+
if len(result.Entries) != 1 {
867+
t.Fatalf("expected 1 entry, got %d", len(result.Entries))
868+
}
869+
if result.Entries[0].RequestedModel != "does-not-exist-model" {
870+
t.Fatalf("requested_model = %q, want does-not-exist-model", result.Entries[0].RequestedModel)
871+
}
872+
}
873+
826874
func TestAuditLog_EnrichesEntriesWithUsageSummary(t *testing.T) {
827875
now := time.Now().UTC()
828876
usageReader := &mockUsageReader{

tests/e2e/release-e2e-scenarios.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,12 +819,12 @@ jq -e '.error.type == "invalid_request_error"' "$BODY_FILE" >/dev/null
819819
sleep 6
820820
AUDIT_JSON_FILE="$QA_RUN_DIR/s61.audit.json"
821821
curl -fsS "$BASE_URL/admin/api/v1/audit/log?search=$REQUEST_ID&limit=5" > "$AUDIT_JSON_FILE"
822-
jq --arg request_id "$REQUEST_ID" '{total:(.entries|map(select(.request_id==$request_id))|length),entries:(.entries|map(select(.request_id==$request_id))|map({request_id,path,model,resolved_model,provider,status_code,error_type}))}' "$AUDIT_JSON_FILE"
822+
jq --arg request_id "$REQUEST_ID" '{total:(.entries|map(select(.request_id==$request_id))|length),entries:(.entries|map(select(.request_id==$request_id))|map({request_id,path,requested_model,resolved_model,provider,status_code,error_type}))}' "$AUDIT_JSON_FILE"
823823
jq -e --arg request_id "$REQUEST_ID" '
824824
any(.entries[]?;
825825
.request_id == $request_id
826826
and .path == "/v1/chat/completions"
827-
and .model == "does-not-exist-model"
827+
and .requested_model == "does-not-exist-model"
828828
and .status_code == 400
829829
and .error_type == "invalid_request_error"
830830
)
@@ -850,12 +850,12 @@ jq -e '.error.type == "invalid_request_error"' "$BODY_FILE" >/dev/null
850850
sleep 6
851851
AUDIT_JSON_FILE="$QA_RUN_DIR/s62.audit.json"
852852
curl -fsS "$BASE_URL/admin/api/v1/audit/log?search=$REQUEST_ID&limit=5" > "$AUDIT_JSON_FILE"
853-
jq --arg request_id "$REQUEST_ID" '{total:(.entries|map(select(.request_id==$request_id))|length),entries:(.entries|map(select(.request_id==$request_id))|map({request_id,path,model,provider,status_code,error_type}))}' "$AUDIT_JSON_FILE"
853+
jq --arg request_id "$REQUEST_ID" '{total:(.entries|map(select(.request_id==$request_id))|length),entries:(.entries|map(select(.request_id==$request_id))|map({request_id,path,requested_model,provider,status_code,error_type}))}' "$AUDIT_JSON_FILE"
854854
jq -e --arg request_id "$REQUEST_ID" '
855855
any(.entries[]?;
856856
.request_id == $request_id
857857
and .path == "/p/not-a-real-provider/responses"
858-
and .model == "gpt-4.1-nano"
858+
and .requested_model == "gpt-4.1-nano"
859859
and .provider == "not-a-real-provider"
860860
and .status_code == 400
861861
and .error_type == "invalid_request_error"

0 commit comments

Comments
 (0)