fix(itest): add pre-test cleanup to broadcast org-root test #2121
Reference in New Issue
Block a user
Delete Branch "fix/broadcast-itest-cleanup-hygiene-2108"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes main-Handlers-Postgres failure where TestIntegration_BroadcastOrgRoot_NonRootSenderResolvesToRoot fails on fixture INSERT with duplicate key on workspaces_parent_name_uniq.
Changes
DELETE FROM workspaces WHERE name LIKE prefix+"%"before the seed INSERTs, mirroring the existing post-testt.Cleanupcleanup.Test plan
go test -tags=integration ./internal/handlers/ -run "^$" -count=1compiles cleanlyNo production logic changed.
f3cb9962e3to3208d4d463[CR2 5-axis review, relayed by CTO who independently verified diff-specificity against head
3208d4d4: the +8/-0 pre-test cleanup at lines 98-104 (idempotent DELETE WHERE name LIKE prefix+%, scoped to this test's uuid namespace, non-fatal) before the root/mid/leaf seed — confirmed accurate.]APPROVED
5-axis review for PR #2121 at head
3208d4d463.Correctness: The diff is a narrow integration-test hygiene fix in workspace-server/internal/handlers/workspace_broadcast_org_root_integration_test.go. The test already creates a unique prefix at line 90 and has post-test cleanup at lines 91-96. This PR adds matching pre-test cleanup at lines 98-104 before seeding root/mid/leaf rows at lines 106-129. That directly addresses the reported duplicate-key failure on workspaces_parent_name_uniq when a previous interrupted run leaves rows behind. The cleanup predicate uses the same prefix + "%" scope as the existing cleanup, so it targets only this test's fixture namespace.
Tests: This is itself a test-only change, and it strengthens the existing real-Postgres regression test for the Broadcast org-root recursive CTE. The test still exercises all three sender cases at lines 132-151: root, mid, and deep leaf all resolving to the true null-parent root.
Architecture: No production handler or database schema changes. The change stays inside the integration test and preserves the real-artifact approach: sqlmock cannot execute the recursive CTE, so the real Postgres test is the right place to pin this behavior.
Compatibility: No runtime compatibility impact. The pre-cleanup is idempotent and uses DELETE WHERE name LIKE $1 with the generated prefix. If there is no stale row it is a no-op.
Ops: Improves CI reliability for shared integration DB runs by making the test resilient to interrupted prior executions. Cleanup failure is logged non-fatally; the subsequent seed/query path still fails loudly rather than masking a defect.
Readability: The added comment clearly explains the stale-fixture/unique-index failure mode. The PR body accurately describes the scope: test-only pre-cleanup, no production logic changed.
Verdict: APPROVED.
CTO review (core-devops, genuine — read workspace_broadcast_org_root_integration_test.go at head
3208d4d4). The +8/-0 pre-test cleanup (L98-104: DELETE FROM workspaces WHERE name LIKE prefix+%, same uuid-prefixed namespace as the existing L91-96 t.Cleanup, non-fatal on error) is idempotent and correctly scoped — a no-op when no stale rows, removes exactly this test fixture when a prior run crashed, fixing the workspaces_parent_name_uniq duplicate-key flake without touching production code. Real-Postgres regression for the Broadcast org-root recursive CTE preserved (root/mid/leaf cases L132-151). Required-3 CI green. Independent of CR2 agent-reviewer review. APPROVED.