From 975ccb2d323ea9b54442f5f978220f3be8558103 Mon Sep 17 00:00:00 2001 From: "Molecule AI Dev Engineer A (Kimi)" Date: Tue, 2 Jun 2026 04:08:10 +0000 Subject: [PATCH] test(integration): pre-clean BroadcastOrgRoot fixtures to avoid unique-index collision Adds pre-test DELETE + defensive index creation to TestIntegration_BroadcastOrgRoot_NonRootSenderResolvesToRoot so a prior crashed run (or stale shared DB) does not leave rows that collide on workspaces_parent_name_uniq. Does not touch production logic. Co-Authored-By: Claude Opus 4.7 --- ...ace_broadcast_org_root_integration_test.go | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/workspace-server/internal/handlers/workspace_broadcast_org_root_integration_test.go b/workspace-server/internal/handlers/workspace_broadcast_org_root_integration_test.go index 00ac04677..2750caa43 100644 --- a/workspace-server/internal/handlers/workspace_broadcast_org_root_integration_test.go +++ b/workspace-server/internal/handlers/workspace_broadcast_org_root_integration_test.go @@ -70,6 +70,19 @@ func integrationDB_BroadcastOrgRoot(t *testing.T) *sql.DB { t.Fatalf("ping: %v", err) } t.Cleanup(func() { conn.Close() }) + + // Defensive: ensure the partial-unique index exists so the test + // exercises real constraint behaviour (not a silently-missing index). + if _, err := conn.ExecContext(context.Background(), ` + CREATE UNIQUE INDEX IF NOT EXISTS workspaces_parent_name_uniq + ON workspaces ( + COALESCE(parent_id, '00000000-0000-0000-0000-000000000000'::uuid), + name + ) + WHERE status != 'removed' + `); err != nil { + t.Fatalf("ensure constraint: %v", err) + } return conn } @@ -88,6 +101,13 @@ func TestIntegration_BroadcastOrgRoot_NonRootSenderResolvesToRoot(t *testing.T) ctx := context.Background() prefix := fmt.Sprintf("itest-bcastroot-%s", uuid.New().String()[:8]) + + // Pre-test cleanup: remove any stale rows left by a prior crashed run + // so the fixture INSERTs below don't hit the partial-unique index. + if _, err := conn.ExecContext(ctx, + `DELETE FROM workspaces WHERE name LIKE $1`, prefix+"%"); err != nil { + t.Logf("pre-test cleanup (non-fatal): %v", err) + } t.Cleanup(func() { if _, err := conn.ExecContext(ctx, `DELETE FROM workspaces WHERE name LIKE $1`, prefix+"%"); err != nil { -- 2.52.0