MCPcopy Index your code
hub / github.com/coder/coder / TestAIBridgeListClients

Function TestAIBridgeListClients

enterprise/coderd/aibridge_test.go:1739–1821  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1737}
1738
1739func TestAIBridgeListClients(t *testing.T) {
1740 t.Parallel()
1741
1742 t.Run("RequiresLicenseFeature", func(t *testing.T) {
1743 t.Parallel()
1744
1745 dv := coderdtest.DeploymentValues(t)
1746 client, _ := coderdenttest.New(t, &coderdenttest.Options{
1747 Options: &coderdtest.Options{
1748 DeploymentValues: dv,
1749 },
1750 LicenseOptions: &coderdenttest.LicenseOptions{
1751 Features: license.Features{},
1752 },
1753 })
1754
1755 ctx := testutil.Context(t, testutil.WaitLong)
1756 //nolint:gocritic // Owner role is irrelevant here.
1757 _, err := client.AIBridgeListClients(ctx)
1758 var sdkErr *codersdk.Error
1759 require.ErrorAs(t, err, &sdkErr)
1760 require.Equal(t, http.StatusForbidden, sdkErr.StatusCode())
1761 })
1762
1763 dv := coderdtest.DeploymentValues(t)
1764 dv.AI.BridgeConfig.Enabled = serpent.Bool(true)
1765 client, db, firstUser := coderdenttest.NewWithDatabase(t, &coderdenttest.Options{
1766 Options: &coderdtest.Options{
1767 DeploymentValues: dv,
1768 },
1769 LicenseOptions: &coderdenttest.LicenseOptions{
1770 Features: license.Features{
1771 codersdk.FeatureAIBridge: 1,
1772 },
1773 },
1774 })
1775
1776 now := dbtime.Now()
1777 endedAt := now.Add(time.Minute)
1778
1779 // Completed interception with an explicit client.
1780 dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
1781 InitiatorID: firstUser.UserID,
1782 StartedAt: now,
1783 Client: sql.NullString{String: string(aiblib.ClientCursor), Valid: true},
1784 }, &endedAt)
1785
1786 // Completed interception with a different client.
1787 dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
1788 InitiatorID: firstUser.UserID,
1789 StartedAt: now,
1790 Client: sql.NullString{String: string(aiblib.ClientClaudeCode), Valid: true},
1791 }, &endedAt)
1792
1793 // Completed interception with no client — should appear as "Unknown".
1794 dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
1795 InitiatorID: firstUser.UserID,
1796 StartedAt: now,

Callers

nothing calls this directly

Calls 11

StatusCodeMethod · 0.95
DeploymentValuesFunction · 0.92
NewFunction · 0.92
ContextFunction · 0.92
NewWithDatabaseFunction · 0.92
NowFunction · 0.92
AIBridgeInterceptionFunction · 0.92
AIBridgeListClientsMethod · 0.80
RunMethod · 0.65
AddMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected