(t *testing.T)
| 1460 | } |
| 1461 | |
| 1462 | func TestStructuredLogging(t *testing.T) { |
| 1463 | t.Parallel() |
| 1464 | |
| 1465 | metadataProto := map[string]*anypb.Any{ |
| 1466 | "key": mustMarshalAny(t, &structpb.Value{Kind: &structpb.Value_StringValue{StringValue: "value"}}), |
| 1467 | } |
| 1468 | |
| 1469 | type testCase struct { |
| 1470 | name string |
| 1471 | structuredLogging bool |
| 1472 | expectedErr error |
| 1473 | setupMocks func(db *dbmock.MockStore, interceptionID uuid.UUID) |
| 1474 | recordFn func(srv *aibridgedserver.Server, ctx context.Context, interceptionID uuid.UUID) error |
| 1475 | expectedFields map[string]any |
| 1476 | } |
| 1477 | |
| 1478 | interceptionID := uuid.UUID{1} |
| 1479 | initiatorID := uuid.UUID{2} |
| 1480 | threadParentID := uuid.UUID{3} |
| 1481 | threadRootID := uuid.UUID{4} |
| 1482 | |
| 1483 | toolCallID := "my-tool-call" |
| 1484 | sessionID := "some-session-id" |
| 1485 | |
| 1486 | cases := []testCase{ |
| 1487 | { |
| 1488 | name: "RecordInterception_logs_when_enabled", |
| 1489 | structuredLogging: true, |
| 1490 | setupMocks: func(db *dbmock.MockStore, intcID uuid.UUID) { |
| 1491 | db.EXPECT().GetAIBridgeInterceptionLineageByToolCallID(gomock.Any(), toolCallID).Return(database.GetAIBridgeInterceptionLineageByToolCallIDRow{ |
| 1492 | ThreadParentID: threadParentID, |
| 1493 | ThreadRootID: threadRootID, |
| 1494 | }, nil) |
| 1495 | |
| 1496 | db.EXPECT().InsertAIBridgeInterception(gomock.Any(), gomock.Any()).Return(database.AIBridgeInterception{ |
| 1497 | ID: intcID, |
| 1498 | InitiatorID: initiatorID, |
| 1499 | ThreadParentID: uuid.NullUUID{UUID: threadParentID, Valid: true}, |
| 1500 | ThreadRootID: uuid.NullUUID{UUID: threadRootID, Valid: true}, |
| 1501 | }, nil) |
| 1502 | }, |
| 1503 | recordFn: func(srv *aibridgedserver.Server, ctx context.Context, intcID uuid.UUID) error { |
| 1504 | _, err := srv.RecordInterception(ctx, &proto.RecordInterceptionRequest{ |
| 1505 | Id: intcID.String(), |
| 1506 | ApiKeyId: "api-key-123", |
| 1507 | InitiatorId: initiatorID.String(), |
| 1508 | Provider: "anthropic", |
| 1509 | Model: "claude-4-opus", |
| 1510 | Metadata: metadataProto, |
| 1511 | StartedAt: timestamppb.Now(), |
| 1512 | CorrelatingToolCallId: ptr.Ref(toolCallID), |
| 1513 | ClientSessionId: ptr.Ref(sessionID), |
| 1514 | }) |
| 1515 | |
| 1516 | return err |
| 1517 | }, |
| 1518 | expectedFields: map[string]any{ |
| 1519 | "record_type": "interception_start", |
nothing calls this directly
no test coverage detected