Open-source LLM knowledge platform: turn raw documents into a queryable RAG, an autonomous reasoning agent, and a self-maintaining Wiki.
Go agentagenticaichatbotdsh-pluginembeddingsevaluationgenerative-aigolangknowledge-basellmmulti-tenantollamaopenaiquestion-answeringragrerankingsemantic-searchvector-searchwiki
fix(skills): stop racing background install in retry tests
wizardchenfc7f37da9b6d
diff --git a/internal/application/service/tenant_skill_install_test.go b/internal/application/service/tenant_skill_install_test.goindex 608017447..d908247f2 100644--- a/internal/application/service/tenant_skill_install_test.go+++ b/internal/application/service/tenant_skill_install_test.go@@ -798,6 +798,25 @@ func TestInstallSkillSkipsWhenReadyWithTheSameArchive(t *testing.T) {"a skip must still attach the install to the workspace catalog")}+// waitBackgroundInstallReady waits until the InstallSkill goroutine has+// finished the fixture run. InstallSkill only queues the work, so reading+// Status immediately after it returns races: the mock often lands on ready+// before the test process runs the next line. A skip never writes a new+// snapshot, so this is also the proof that a retry actually ran.+func waitBackgroundInstallReady(t *testing.T, fx *installFixture, msgAndArgs ...any) *types.TenantSkillEntity {+ t.Helper()+ var skill *types.TenantSkillEntity+ require.Eventually(t, func() bool {+ got, err := fx.skillRepo.GetSkill(context.Background(), 7, "cfg-1", "sk-1")+ if err != nil || got == nil {+ return false+ }+ skill = got+ return got.Status == types.SkillStatusReady && got.InstalledSnapshotID != ""+ }, 2*time.Second, 5*time.Millisecond, msgAndArgs...)+ return skill+}+func TestInstallSkillRetriesAFailedSkillWithTheSameArchive(t *testing.T) {fx := newInstallFixture(t)archive := zipBundle(t, map[string]string{@@ -816,10 +835,9 @@ func TestInstallSkillRetriesAFailedSkillWithTheSameArchive(t *testing.T) {require.NoError(t, err)require.Equal(t, "sk-1", id)- skill, getErr := fx.skillRepo.GetSkill(context.Background(), 7, "cfg-1", "sk-1")- require.NoError(t, getErr)- require.Equal(t, types.SkillStatusInstalling, skill.Status,+ skill := waitBackgroundInstallReady(t, fx,"a failed skill is a retry even when the archive digest is unchanged")+ require.Empty(t, skill.Error)}// Most failed installs fail for a reason the archive cannot fix, so the retry@@ -912,9 +930,7 @@ func TestInstallSkillReinstallsWhenTheLiveImageNoLongerCarriesTheSkill(t *testinrequire.NoError(t, err)require.Equal(t, "sk-1", id)- skill, getErr := fx.skillRepo.GetSkill(context.Background(), 7, "cfg-1", "sk-1")- require.NoError(t, getErr)- require.Equal(t, types.SkillStatusInstalling, skill.Status,+ waitBackgroundInstallReady(t, fx,"a ready row whose files left the image is a repair, not a skip")}@@ -990,13 +1006,10 @@ func TestInstallSkillRetriesAStaleInFlightInstallOfTheSameArchive(t *testing.T)require.NoError(t, err)require.Equal(t, "sk-1", id)- skill, getErr := fx.skillRepo.GetSkill(context.Background(), 7, "cfg-1", "sk-1")- require.NoError(t, getErr)- require.Equal(t, types.SkillStatusInstalling, skill.Status)- require.NotNil(t, skill.InstallingSince)- require.Equal(t, fx.now(), *skill.InstallingSince,+ skill := waitBackgroundInstallReady(t, fx,"a dead in-flight row must be allowed to start a new run, not wait for the reaper")require.Empty(t, skill.Error)+ require.Nil(t, skill.InstallingSince)}// The ledger records which skill an install snapshotted, not which archive, so@@ -1137,9 +1150,7 @@ func TestInstallSkillDoesNotSkipARemovalOfTheSameArchive(t *testing.T) {require.NoError(t, err)require.Equal(t, "sk-1", id)- skill, getErr := fx.skillRepo.GetSkill(context.Background(), 7, "cfg-1", "sk-1")- require.NoError(t, getErr)- require.Equal(t, types.SkillStatusInstalling, skill.Status,+ waitBackgroundInstallReady(t, fx,"re-uploading during a removal is how the upload cancels it")}