Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: remove inflight interceptions from aibridge returned values#20852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
jakehwll merged 13 commits intomainfromjakehwll/remove-inflight-interceptions
Nov 24, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
13 commits
Select commitHold shift + click to select a range
d202e9d
fix: remove inflight interceptions from aibridge returned values
jakehwllNov 21, 2025
8325e23
Merge branch 'main' into jakehwll/remove-inflight-interceptions
jakehwllNov 23, 2025
48cc71e
fix: resolve the `Filter` test cases
jakehwllNov 23, 2025
6f466ca
fix: resolve the `OK` test cases
jakehwllNov 23, 2025
d23eecd
feat: add test for `InflightInterceptions`
jakehwllNov 24, 2025
0252028
Merge branch 'main' into jakehwll/remove-inflight-interceptions
jakehwllNov 24, 2025
c933abe
Update coderd/database/queries/aibridge.sql
jakehwllNov 24, 2025
7942fa8
chore: remove unnecessary loop
jakehwllNov 24, 2025
a8c6e87
fix: remove unnecessary user and interception from test
jakehwllNov 24, 2025
6a00655
Revert "fix: remove unnecessary user and interception from test"
jakehwllNov 24, 2025
432b450
fix: dont instantiate dummy user
jakehwllNov 24, 2025
7c94c69
fix: update missing content from other interception comment
jakehwllNov 24, 2025
1ace778
chore: resolve generated ts types
jakehwllNov 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletionscoderd/database/queries.sql.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

8 changes: 6 additions & 2 deletionscoderd/database/queries/aibridge.sql
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -89,8 +89,10 @@ SELECT
FROM
aibridge_interceptions
WHERE
-- Remove inflight interceptions (ones which lack an ended_at value).
aibridge_interceptions.ended_at IS NOT NULL
-- Filter by time frame
CASE
ANDCASE
WHEN @started_after::timestamptz != '0001-01-01 00:00:00+00'::timestamptz THEN aibridge_interceptions.started_at >= @started_after::timestamptz
ELSE true
END
Expand DownExpand Up@@ -126,8 +128,10 @@ FROM
JOIN
visible_users ON visible_users.id = aibridge_interceptions.initiator_id
WHERE
-- Remove inflight interceptions (ones which lack an ended_at value).
aibridge_interceptions.ended_at IS NOT NULL
-- Filter by time frame
CASE
ANDCASE
WHEN @started_after::timestamptz != '0001-01-01 00:00:00+00'::timestamptz THEN aibridge_interceptions.started_at >= @started_after::timestamptz
ELSE true
END
Expand Down
9 changes: 6 additions & 3 deletionsenterprise/cli/aibridge_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,10 +43,11 @@ func TestAIBridgeListInterceptions(t *testing.T) {
InitiatorID: member.ID,
StartedAt: now.Add(-time.Hour),
}, &now)
interception2EndedAt := now.Add(time.Minute)
interception2 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
InitiatorID: member.ID,
StartedAt: now,
},nil)
},&interception2EndedAt)
// Should not be returned because the user can't see it.
_ = dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
InitiatorID: owner.UserID,
Expand DownExpand Up@@ -91,12 +92,13 @@ func TestAIBridgeListInterceptions(t *testing.T) {
now := dbtime.Now()

// This interception should be returned since it matches all filters.
goodInterceptionEndedAt := now.Add(time.Minute)
goodInterception := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
InitiatorID: member.ID,
Provider: "real-provider",
Model: "real-model",
StartedAt: now,
},nil)
},&goodInterceptionEndedAt)

// These interceptions should not be returned since they don't match the
// filters.
Expand DownExpand Up@@ -173,10 +175,11 @@ func TestAIBridgeListInterceptions(t *testing.T) {
memberClient, member := coderdtest.CreateAnotherUser(t, client, owner.OrganizationID)

now := dbtime.Now()
firstInterceptionEndedAt := now.Add(time.Minute)
firstInterception := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
InitiatorID: member.ID,
StartedAt: now,
},nil)
},&firstInterceptionEndedAt)
returnedInterception := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
InitiatorID: member.ID,
StartedAt: now.Add(-time.Hour),
Expand Down
49 changes: 44 additions & 5 deletionsenterprise/coderd/aibridge_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -103,11 +103,12 @@ func TestAIBridgeListInterceptions(t *testing.T) {
// Insert a bunch of test data.
now := dbtime.Now()
i1ApiKey := sql.NullString{String: "some-api-key", Valid: true}
i1EndedAt := now.Add(-time.Hour + time.Minute)
i1 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
APIKeyID: i1ApiKey,
InitiatorID: user1.ID,
StartedAt: now.Add(-time.Hour),
},nil)
},&i1EndedAt)
i1tok1 := dbgen.AIBridgeTokenUsage(t, db, database.InsertAIBridgeTokenUsageParams{
InterceptionID: i1.ID,
CreatedAt: now,
Expand DownExpand Up@@ -175,9 +176,11 @@ func TestAIBridgeListInterceptions(t *testing.T) {
// Time comparison
require.Len(t, res.Results, 2)
require.Equal(t, res.Results[0].ID, i2SDK.ID)
require.NotNil(t,now,res.Results[0].EndedAt)
require.NotNil(t, res.Results[0].EndedAt)
require.WithinDuration(t, now, *res.Results[0].EndedAt, 5*time.Second)
res.Results[0].EndedAt = i2SDK.EndedAt
require.NotNil(t, res.Results[1].EndedAt)
res.Results[1].EndedAt = i1SDK.EndedAt

require.Equal(t, []codersdk.AIBridgeInterception{i2SDK, i1SDK}, res.Results)
})
Expand DownExpand Up@@ -217,11 +220,12 @@ func TestAIBridgeListInterceptions(t *testing.T) {
randomOffset, err := cryptorand.Intn(10000)
require.NoError(t, err)
randomOffsetDur := time.Duration(randomOffset) * time.Second
endedAt := now.Add(randomOffsetDur + time.Minute)
interception := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
ID: uuid.UUID{byte(i + 10)},
InitiatorID: firstUser.UserID,
StartedAt: now.Add(randomOffsetDur),
},nil)
},&endedAt)
allInterceptionIDs = append(allInterceptionIDs, interception.ID)
}

Expand DownExpand Up@@ -297,6 +301,39 @@ func TestAIBridgeListInterceptions(t *testing.T) {
}
})

t.Run("InflightInterceptions", func(t *testing.T) {
t.Parallel()
dv := coderdtest.DeploymentValues(t)
client, db, firstUser := coderdenttest.NewWithDatabase(t, &coderdenttest.Options{
Options: &coderdtest.Options{
DeploymentValues: dv,
},
LicenseOptions: &coderdenttest.LicenseOptions{
Features: license.Features{
codersdk.FeatureAIBridge: 1,
},
},
})
ctx := testutil.Context(t, testutil.WaitLong)

now := dbtime.Now()
i1EndedAt := now.Add(time.Minute)
i1 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
InitiatorID: firstUser.UserID,
StartedAt: now,
}, &i1EndedAt)
dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
InitiatorID: firstUser.UserID,
StartedAt: now.Add(-time.Hour),
}, nil)

res, err := client.AIBridgeListInterceptions(ctx, codersdk.AIBridgeListInterceptionsFilter{})
require.NoError(t, err)
require.EqualValues(t, 1, res.Count)
require.Len(t, res.Results, 1)
require.Equal(t, i1.ID, res.Results[0].ID)
})

t.Run("Authorized", func(t *testing.T) {
t.Parallel()
dv := coderdtest.DeploymentValues(t)
Expand All@@ -315,10 +352,11 @@ func TestAIBridgeListInterceptions(t *testing.T) {
secondUserClient, secondUser := coderdtest.CreateAnotherUser(t, adminClient, firstUser.OrganizationID)

now := dbtime.Now()
i1EndedAt := now.Add(time.Minute)
i1 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
InitiatorID: firstUser.UserID,
StartedAt: now,
},nil)
},&i1EndedAt)
i2 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
InitiatorID: secondUser.ID,
StartedAt: now.Add(-time.Hour),
Expand DownExpand Up@@ -374,13 +412,14 @@ func TestAIBridgeListInterceptions(t *testing.T) {

// Insert a bunch of test data with varying filterable fields.
now := dbtime.Now()
i1EndedAt := now.Add(time.Minute)
i1 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
ID: uuid.MustParse("00000000-0000-0000-0000-000000000001"),
InitiatorID: user1.ID,
Provider: "one",
Model: "one",
StartedAt: now,
},nil)
},&i1EndedAt)
i2 := dbgen.AIBridgeInterception(t, db, database.InsertAIBridgeInterceptionParams{
ID: uuid.MustParse("00000000-0000-0000-0000-000000000002"),
InitiatorID: user1.ID,
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp