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

Commit3e4d7b2

Browse files
committed
chore: review feedback
Signed-off-by: Danny Kopping <danny@coder.com>
1 parentf0a6d84 commit3e4d7b2

File tree

1 file changed

+59
-22
lines changed

1 file changed

+59
-22
lines changed

‎coderd/database/dbpurge/dbpurge_test.go‎

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -759,12 +759,13 @@ func TestDeleteOldTelemetryHeartbeats(t *testing.T) {
759759
},testutil.WaitShort,testutil.IntervalFast,"it should delete old telemetry heartbeats")
760760
}
761761

762-
//nolint:paralleltest // It uses LockIDDBPurge.
763762
funcTestDeleteOldAIBridgeRecords(t*testing.T) {
763+
t.Parallel()
764+
764765
ctx:=testutil.Context(t,testutil.WaitShort)
765766

766767
clk:=quartz.NewMock(t)
767-
now:=dbtime.Now()
768+
now:=time.Date(2025,1,15,7,30,0,0,time.UTC)
768769
retentionPeriod:=30*24*time.Hour// 30 days
769770
afterThreshold:=now.Add(-retentionPeriod).Add(-24*time.Hour)// 31 days ago (older than threshold)
770771
beforeThreshold:=now.Add(-15*24*time.Hour)// 15 days ago (newer than threshold)
@@ -774,12 +775,11 @@ func TestDeleteOldAIBridgeRecords(t *testing.T) {
774775
db,_:=dbtestutil.NewDB(t,dbtestutil.WithDumpOnFailure())
775776
logger:=slogtest.Make(t,&slogtest.Options{IgnoreErrors:true})
776777
user:=dbgen.User(t,db, database.User{})
777-
apiKey,_:=dbgen.APIKey(t,db, database.APIKey{UserID:user.ID})
778778

779779
// Create old AI Bridge interception (should be deleted)
780780
oldInterception:=dbgen.AIBridgeInterception(t,db, database.InsertAIBridgeInterceptionParams{
781781
ID:uuid.New(),
782-
APIKeyID: sql.NullString{String:apiKey.ID,Valid:true},
782+
APIKeyID: sql.NullString{},
783783
InitiatorID:user.ID,
784784
Provider:"anthropic",
785785
Model:"claude-3-5-sonnet",
@@ -789,14 +789,14 @@ func TestDeleteOldAIBridgeRecords(t *testing.T) {
789789
// Create old interception with related records (should all be deleted)
790790
oldInterceptionWithRelated:=dbgen.AIBridgeInterception(t,db, database.InsertAIBridgeInterceptionParams{
791791
ID:uuid.New(),
792-
APIKeyID: sql.NullString{String:apiKey.ID,Valid:true},
792+
APIKeyID: sql.NullString{},
793793
InitiatorID:user.ID,
794794
Provider:"openai",
795795
Model:"gpt-4",
796796
StartedAt:afterThreshold,
797797
},&afterThreshold)
798798

799-
oldTokenUsage:=dbgen.AIBridgeTokenUsage(t,db, database.InsertAIBridgeTokenUsageParams{
799+
_=dbgen.AIBridgeTokenUsage(t,db, database.InsertAIBridgeTokenUsageParams{
800800
ID:uuid.New(),
801801
InterceptionID:oldInterceptionWithRelated.ID,
802802
ProviderResponseID:"resp-1",
@@ -805,15 +805,15 @@ func TestDeleteOldAIBridgeRecords(t *testing.T) {
805805
CreatedAt:afterThreshold,
806806
})
807807

808-
oldUserPrompt:=dbgen.AIBridgeUserPrompt(t,db, database.InsertAIBridgeUserPromptParams{
808+
_=dbgen.AIBridgeUserPrompt(t,db, database.InsertAIBridgeUserPromptParams{
809809
ID:uuid.New(),
810810
InterceptionID:oldInterceptionWithRelated.ID,
811811
ProviderResponseID:"resp-1",
812812
Prompt:"test prompt",
813813
CreatedAt:afterThreshold,
814814
})
815815

816-
oldToolUsage:=dbgen.AIBridgeToolUsage(t,db, database.InsertAIBridgeToolUsageParams{
816+
_=dbgen.AIBridgeToolUsage(t,db, database.InsertAIBridgeToolUsageParams{
817817
ID:uuid.New(),
818818
InterceptionID:oldInterceptionWithRelated.ID,
819819
ProviderResponseID:"resp-1",
@@ -827,7 +827,7 @@ func TestDeleteOldAIBridgeRecords(t *testing.T) {
827827
// Create recent AI Bridge interception (should be kept)
828828
recentInterception:=dbgen.AIBridgeInterception(t,db, database.InsertAIBridgeInterceptionParams{
829829
ID:uuid.New(),
830-
APIKeyID: sql.NullString{String:apiKey.ID,Valid:true},
830+
APIKeyID: sql.NullString{},
831831
InitiatorID:user.ID,
832832
Provider:"anthropic",
833833
Model:"claude-3-5-sonnet",
@@ -837,13 +837,41 @@ func TestDeleteOldAIBridgeRecords(t *testing.T) {
837837
// Create interception close to threshold (should be kept)
838838
nearThresholdInterception:=dbgen.AIBridgeInterception(t,db, database.InsertAIBridgeInterceptionParams{
839839
ID:uuid.New(),
840-
APIKeyID: sql.NullString{String:apiKey.ID,Valid:true},
840+
APIKeyID: sql.NullString{},
841841
InitiatorID:user.ID,
842842
Provider:"anthropic",
843843
Model:"claude-3-5-sonnet",
844844
StartedAt:closeBeforeThreshold,
845845
},&closeBeforeThreshold)
846846

847+
_=dbgen.AIBridgeTokenUsage(t,db, database.InsertAIBridgeTokenUsageParams{
848+
ID:uuid.New(),
849+
InterceptionID:nearThresholdInterception.ID,
850+
ProviderResponseID:"resp-1",
851+
InputTokens:100,
852+
OutputTokens:50,
853+
CreatedAt:closeBeforeThreshold,
854+
})
855+
856+
_=dbgen.AIBridgeUserPrompt(t,db, database.InsertAIBridgeUserPromptParams{
857+
ID:uuid.New(),
858+
InterceptionID:nearThresholdInterception.ID,
859+
ProviderResponseID:"resp-1",
860+
Prompt:"test prompt",
861+
CreatedAt:closeBeforeThreshold,
862+
})
863+
864+
_=dbgen.AIBridgeToolUsage(t,db, database.InsertAIBridgeToolUsageParams{
865+
ID:uuid.New(),
866+
InterceptionID:nearThresholdInterception.ID,
867+
ProviderResponseID:"resp-1",
868+
Tool:"test-tool",
869+
ServerUrl: sql.NullString{String:"http://test",Valid:true},
870+
Input:"{}",
871+
Injected:true,
872+
CreatedAt:closeBeforeThreshold,
873+
})
874+
847875
// Run the purge with configured retention period
848876
done:=awaitDoTick(ctx,t,clk)
849877
closer:=dbpurge.New(ctx,logger,db,&codersdk.DeploymentValues{
@@ -869,24 +897,33 @@ func TestDeleteOldAIBridgeRecords(t *testing.T) {
869897

870898
require.NotContains(t,interceptionIDs,oldInterception.ID,"old interception should be deleted")
871899
require.NotContains(t,interceptionIDs,oldInterceptionWithRelated.ID,"old interception with related records should be deleted")
872-
require.Contains(t,interceptionIDs,recentInterception.ID,"recent interception should be kept")
873-
require.Contains(t,interceptionIDs,nearThresholdInterception.ID,"near threshold interception should be kept")
874900

875901
// Verify related records were also deleted
876-
tokenUsages,err:=db.GetAIBridgeTokenUsagesByInterceptionID(ctx,oldInterceptionWithRelated.ID)
902+
oldTokenUsages,err:=db.GetAIBridgeTokenUsagesByInterceptionID(ctx,oldInterceptionWithRelated.ID)
877903
require.NoError(t,err)
878-
require.Empty(t,tokenUsages,"old token usages should be deleted")
904+
require.Empty(t,oldTokenUsages,"old token usages should be deleted")
879905

880-
userPrompts,err:=db.GetAIBridgeUserPromptsByInterceptionID(ctx,oldInterceptionWithRelated.ID)
906+
oldUserPrompts,err:=db.GetAIBridgeUserPromptsByInterceptionID(ctx,oldInterceptionWithRelated.ID)
881907
require.NoError(t,err)
882-
require.Empty(t,userPrompts,"old user prompts should be deleted")
908+
require.Empty(t,oldUserPrompts,"old user prompts should be deleted")
883909

884-
toolUsages,err:=db.GetAIBridgeToolUsagesByInterceptionID(ctx,oldInterceptionWithRelated.ID)
910+
oldToolUsages,err:=db.GetAIBridgeToolUsagesByInterceptionID(ctx,oldInterceptionWithRelated.ID)
885911
require.NoError(t,err)
886-
require.Empty(t,toolUsages,"old tool usages should be deleted")
912+
require.Empty(t,oldToolUsages,"old tool usages should be deleted")
887913

888-
// Silence unused variable warnings
889-
_=oldTokenUsage
890-
_=oldUserPrompt
891-
_=oldToolUsage
914+
require.Contains(t,interceptionIDs,recentInterception.ID,"recent interception should be kept")
915+
require.Contains(t,interceptionIDs,nearThresholdInterception.ID,"near threshold interception should be kept")
916+
917+
// Verify related records were NOT deleted
918+
newTokenUsages,err:=db.GetAIBridgeTokenUsagesByInterceptionID(ctx,nearThresholdInterception.ID)
919+
require.NoError(t,err)
920+
require.Len(t,newTokenUsages,1,"near threshold token usages should not be deleted")
921+
922+
newUserPrompts,err:=db.GetAIBridgeUserPromptsByInterceptionID(ctx,nearThresholdInterception.ID)
923+
require.NoError(t,err)
924+
require.Len(t,newUserPrompts,1,"near threshold user prompts should not be deleted")
925+
926+
newToolUsages,err:=db.GetAIBridgeToolUsagesByInterceptionID(ctx,nearThresholdInterception.ID)
927+
require.NoError(t,err)
928+
require.Len(t,newToolUsages,1,"near threshold tool usages should not be deleted")
892929
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp