@@ -103,11 +103,12 @@ func TestAIBridgeListInterceptions(t *testing.T) {
103103 // Insert a bunch of test data.
104104 now := dbtime .Now ()
105105 i1ApiKey := sql.NullString {String : "some-api-key" , Valid : true }
106+ i1EndedAt := now .Add (- time .Hour + time .Minute )
106107 i1 := dbgen .AIBridgeInterception (t , db , database.InsertAIBridgeInterceptionParams {
107108 APIKeyID : i1ApiKey ,
108109 InitiatorID : user1 .ID ,
109110 StartedAt : now .Add (- time .Hour ),
110- }, nil )
111+ }, & i1EndedAt )
111112 i1tok1 := dbgen .AIBridgeTokenUsage (t , db , database.InsertAIBridgeTokenUsageParams {
112113 InterceptionID : i1 .ID ,
113114 CreatedAt : now ,
@@ -175,9 +176,11 @@ func TestAIBridgeListInterceptions(t *testing.T) {
175176 // Time comparison
176177 require .Len (t , res .Results , 2 )
177178 require .Equal (t , res .Results [0 ].ID , i2SDK .ID )
178- require .NotNil (t , now , res .Results [0 ].EndedAt )
179+ require .NotNil (t , res .Results [0 ].EndedAt )
179180 require .WithinDuration (t , now , * res .Results [0 ].EndedAt , 5 * time .Second )
180181 res .Results [0 ].EndedAt = i2SDK .EndedAt
182+ require .NotNil (t , res .Results [1 ].EndedAt )
183+ res .Results [1 ].EndedAt = i1SDK .EndedAt
181184
182185 require .Equal (t , []codersdk.AIBridgeInterception {i2SDK , i1SDK }, res .Results )
183186 })
@@ -217,11 +220,12 @@ func TestAIBridgeListInterceptions(t *testing.T) {
217220 randomOffset , err := cryptorand .Intn (10000 )
218221 require .NoError (t , err )
219222 randomOffsetDur := time .Duration (randomOffset ) * time .Second
223+ endedAt := now .Add (randomOffsetDur + time .Minute )
220224 interception := dbgen .AIBridgeInterception (t , db , database.InsertAIBridgeInterceptionParams {
221225 ID : uuid.UUID {byte (i + 10 )},
222226 InitiatorID : firstUser .UserID ,
223227 StartedAt : now .Add (randomOffsetDur ),
224- }, nil )
228+ }, & endedAt )
225229 allInterceptionIDs = append (allInterceptionIDs , interception .ID )
226230 }
227231
@@ -297,6 +301,39 @@ func TestAIBridgeListInterceptions(t *testing.T) {
297301 }
298302 })
299303
304+ t .Run ("InflightInterceptions" , func (t * testing.T ) {
305+ t .Parallel ()
306+ dv := coderdtest .DeploymentValues (t )
307+ client , db , firstUser := coderdenttest .NewWithDatabase (t , & coderdenttest.Options {
308+ Options : & coderdtest.Options {
309+ DeploymentValues : dv ,
310+ },
311+ LicenseOptions : & coderdenttest.LicenseOptions {
312+ Features : license.Features {
313+ codersdk .FeatureAIBridge : 1 ,
314+ },
315+ },
316+ })
317+ ctx := testutil .Context (t , testutil .WaitLong )
318+
319+ now := dbtime .Now ()
320+ i1EndedAt := now .Add (time .Minute )
321+ i1 := dbgen .AIBridgeInterception (t , db , database.InsertAIBridgeInterceptionParams {
322+ InitiatorID : firstUser .UserID ,
323+ StartedAt : now ,
324+ }, & i1EndedAt )
325+ dbgen .AIBridgeInterception (t , db , database.InsertAIBridgeInterceptionParams {
326+ InitiatorID : firstUser .UserID ,
327+ StartedAt : now .Add (- time .Hour ),
328+ }, nil )
329+
330+ res , err := client .AIBridgeListInterceptions (ctx , codersdk.AIBridgeListInterceptionsFilter {})
331+ require .NoError (t , err )
332+ require .EqualValues (t , 1 , res .Count )
333+ require .Len (t , res .Results , 1 )
334+ require .Equal (t , i1 .ID , res .Results [0 ].ID )
335+ })
336+
300337 t .Run ("Authorized" , func (t * testing.T ) {
301338 t .Parallel ()
302339 dv := coderdtest .DeploymentValues (t )
@@ -315,10 +352,11 @@ func TestAIBridgeListInterceptions(t *testing.T) {
315352 secondUserClient , secondUser := coderdtest .CreateAnotherUser (t , adminClient , firstUser .OrganizationID )
316353
317354 now := dbtime .Now ()
355+ i1EndedAt := now .Add (time .Minute )
318356 i1 := dbgen .AIBridgeInterception (t , db , database.InsertAIBridgeInterceptionParams {
319357 InitiatorID : firstUser .UserID ,
320358 StartedAt : now ,
321- }, nil )
359+ }, & i1EndedAt )
322360 i2 := dbgen .AIBridgeInterception (t , db , database.InsertAIBridgeInterceptionParams {
323361 InitiatorID : secondUser .ID ,
324362 StartedAt : now .Add (- time .Hour ),
@@ -374,13 +412,14 @@ func TestAIBridgeListInterceptions(t *testing.T) {
374412
375413 // Insert a bunch of test data with varying filterable fields.
376414 now := dbtime .Now ()
415+ i1EndedAt := now .Add (time .Minute )
377416 i1 := dbgen .AIBridgeInterception (t , db , database.InsertAIBridgeInterceptionParams {
378417 ID : uuid .MustParse ("00000000-0000-0000-0000-000000000001" ),
379418 InitiatorID : user1 .ID ,
380419 Provider : "one" ,
381420 Model : "one" ,
382421 StartedAt : now ,
383- }, nil )
422+ }, & i1EndedAt )
384423 i2 := dbgen .AIBridgeInterception (t , db , database.InsertAIBridgeInterceptionParams {
385424 ID : uuid .MustParse ("00000000-0000-0000-0000-000000000002" ),
386425 InitiatorID : user1 .ID ,
0 commit comments