| 364 | } |
| 365 | |
| 366 | func TestGeneratedSchemasValidateRealOutput(t *testing.T) { |
| 367 | t.Run("validates LogsData schema against real data", func(t *testing.T) { |
| 368 | // Generate schema for LogsData |
| 369 | schema, err := GenerateSchema[LogsData]() |
| 370 | if err != nil { |
| 371 | t.Fatalf("GenerateSchema failed: %v", err) |
| 372 | } |
| 373 | |
| 374 | // Resolve the schema to prepare it for validation |
| 375 | resolved, err := schema.Resolve(&jsonschema.ResolveOptions{}) |
| 376 | if err != nil { |
| 377 | t.Fatalf("Schema.Resolve failed: %v", err) |
| 378 | } |
| 379 | |
| 380 | // Create realistic test data |
| 381 | data := LogsData{ |
| 382 | Summary: LogsSummary{ |
| 383 | TotalRuns: 5, |
| 384 | TotalDuration: "10m30s", |
| 385 | TotalTurns: 25, |
| 386 | }, |
| 387 | Runs: []RunData{ |
| 388 | { |
| 389 | RunID: 123456, |
| 390 | Number: 1, |
| 391 | WorkflowName: "test-workflow", |
| 392 | Agent: "copilot", |
| 393 | Status: "completed", |
| 394 | Conclusion: "success", |
| 395 | Duration: "2m5s", |
| 396 | TokenUsage: 3000, |
| 397 | Turns: 5, |
| 398 | }, |
| 399 | }, |
| 400 | LogsLocation: "/path/to/logs", |
| 401 | } |
| 402 | |
| 403 | // Marshal to JSON and then to map[string]any for validation |
| 404 | jsonBytes, err := json.Marshal(data) |
| 405 | if err != nil { |
| 406 | t.Fatalf("json.Marshal failed: %v", err) |
| 407 | } |
| 408 | |
| 409 | var jsonValue map[string]any |
| 410 | if err := json.Unmarshal(jsonBytes, &jsonValue); err != nil { |
| 411 | t.Fatalf("json.Unmarshal failed: %v", err) |
| 412 | } |
| 413 | |
| 414 | // Validate the data against the schema |
| 415 | err = resolved.Validate(jsonValue) |
| 416 | if err != nil { |
| 417 | t.Errorf("Schema should validate real LogsData output: %v", err) |
| 418 | } |
| 419 | }) |
| 420 | |
| 421 | t.Run("validates AuditData schema against real data", func(t *testing.T) { |
| 422 | // Generate schema for AuditData |
| 423 | schema, err := GenerateSchema[AuditData]() |