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 {