MCPcopy Create free account
hub / github.com/github/gh-aw / TestAuditDataJSONStructure

Function TestAuditDataJSONStructure

pkg/cli/audit_agent_output_test.go:321–406  ·  view source on GitHub ↗

TestAuditDataJSONStructure verifies the JSON structure includes all new fields

(t *testing.T)

Source from the content-addressed store, hash-verified

319
320// TestAuditDataJSONStructure verifies the JSON structure includes all new fields
321func TestAuditDataJSONStructure(t *testing.T) {
322 // Create comprehensive audit data
323 run := WorkflowRun{
324 DatabaseID: 123456,
325 WorkflowName: "Test Workflow",
326 Status: "completed",
327 Conclusion: "failure",
328 CreatedAt: time.Now(),
329 Event: "push",
330 HeadBranch: "main",
331 URL: "https://github.com/org/repo/actions/runs/123456",
332 TokenUsage: 5000,
333 Turns: 8,
334 ErrorCount: 2,
335 WarningCount: 1,
336 Duration: 5 * time.Minute,
337 }
338
339 metrics := LogMetrics{
340 TokenUsage: 5000,
341 Turns: 8,
342 ToolCalls: []workflow.ToolCallInfo{
343 {Name: "bash", CallCount: 5, MaxDuration: 2 * time.Second},
344 },
345 }
346
347 processedRun := ProcessedRun{
348 Run: run,
349 MissingTools: []MissingToolReport{
350 {Tool: "missing_tool", Reason: "Not configured"},
351 },
352 MCPFailures: []MCPFailureReport{
353 {ServerName: "test-server", Status: "failed"},
354 },
355 JobDetails: []JobInfoWithDuration{
356 {JobInfo: JobInfo{Name: "test", Conclusion: "failure"}},
357 },
358 }
359
360 // Build audit data
361 auditData := buildAuditData(processedRun, metrics, nil)
362
363 // Marshal to JSON
364 jsonBytes, err := json.MarshalIndent(auditData, "", " ")
365 require.NoError(t, err, "Failed to marshal audit data to JSON")
366
367 jsonStr := string(jsonBytes)
368
369 // Verify all new fields are present
370 // Note: "errors" and "warnings" fields are omitempty and will not appear in JSON
371 // since error/warning extraction was removed from buildAuditData
372 expectedFields := []string{
373 "key_findings",
374 "recommendations",
375 "performance_metrics",
376 "overview",
377 "metrics",
378 "jobs",

Callers

nothing calls this directly

Calls 1

buildAuditDataFunction · 0.85

Tested by

no test coverage detected