| 600 | } |
| 601 | |
| 602 | func TestAIBridgeInterception(t *testing.T) { |
| 603 | t.Parallel() |
| 604 | |
| 605 | now := dbtime.Now() |
| 606 | interceptionID := uuid.New() |
| 607 | initiatorID := uuid.New() |
| 608 | |
| 609 | cases := []struct { |
| 610 | name string |
| 611 | interception database.AIBridgeInterception |
| 612 | initiator database.VisibleUser |
| 613 | tokenUsages []database.AIBridgeTokenUsage |
| 614 | userPrompts []database.AIBridgeUserPrompt |
| 615 | toolUsages []database.AIBridgeToolUsage |
| 616 | expected codersdk.AIBridgeInterception |
| 617 | }{ |
| 618 | { |
| 619 | name: "all_optional_values_set", |
| 620 | interception: database.AIBridgeInterception{ |
| 621 | ID: interceptionID, |
| 622 | InitiatorID: initiatorID, |
| 623 | Provider: "anthropic", |
| 624 | Model: "claude-3-opus", |
| 625 | StartedAt: now, |
| 626 | Metadata: pqtype.NullRawMessage{ |
| 627 | RawMessage: json.RawMessage(`{"key":"value"}`), |
| 628 | Valid: true, |
| 629 | }, |
| 630 | EndedAt: sql.NullTime{ |
| 631 | Time: now.Add(time.Minute), |
| 632 | Valid: true, |
| 633 | }, |
| 634 | APIKeyID: sql.NullString{ |
| 635 | String: "api-key-123", |
| 636 | Valid: true, |
| 637 | }, |
| 638 | Client: sql.NullString{ |
| 639 | String: "claude-code/1.0.0", |
| 640 | Valid: true, |
| 641 | }, |
| 642 | }, |
| 643 | initiator: database.VisibleUser{ |
| 644 | ID: initiatorID, |
| 645 | Username: "testuser", |
| 646 | Name: "Test User", |
| 647 | AvatarURL: "https://example.com/avatar.png", |
| 648 | }, |
| 649 | tokenUsages: []database.AIBridgeTokenUsage{ |
| 650 | { |
| 651 | ID: uuid.New(), |
| 652 | InterceptionID: interceptionID, |
| 653 | ProviderResponseID: "resp-123", |
| 654 | InputTokens: 100, |
| 655 | OutputTokens: 200, |
| 656 | CacheReadInputTokens: 50, |
| 657 | CacheWriteInputTokens: 10, |
| 658 | Metadata: pqtype.NullRawMessage{ |
| 659 | RawMessage: json.RawMessage(`{"cache":"hit"}`), |