test(handler): assign per-workspace issue number in self-mention fixture

The fixture inserts two issues in the same test workspace; without an
explicit number both default to 0 and the second insert violates
uq_issue_workspace_number, taking the backend CI job down on PR #2928.

Mirror the workspace-counter advancement pattern from
issue_scheduled_test.go so each fixture issue gets a unique number.

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
Jiang Bohan
2026-05-20 17:08:03 +08:00
parent b2291ebdea
commit d0caaeda45

View File

@@ -51,12 +51,22 @@ func newSelfMentionFixture(t *testing.T) selfMentionFixture {
insertIssue := func(title string) string {
t.Helper()
// Pick the next per-workspace issue number; without it both inserts
// land on the default number=0 and trip uq_issue_workspace_number.
var number int
if err := testPool.QueryRow(ctx, `
UPDATE workspace
SET issue_counter = GREATEST(issue_counter, (SELECT COALESCE(MAX(number), 0) FROM issue WHERE workspace_id = $1)) + 1
WHERE id = $1 RETURNING issue_counter
`, testWorkspaceID).Scan(&number); err != nil {
t.Fatalf("next issue number: %v", err)
}
var id string
if err := testPool.QueryRow(ctx, `
INSERT INTO issue (workspace_id, creator_type, creator_id, title, assignee_type, assignee_id)
VALUES ($1, 'member', $2, $3, 'agent', $4)
INSERT INTO issue (workspace_id, creator_type, creator_id, title, assignee_type, assignee_id, number)
VALUES ($1, 'member', $2, $3, 'agent', $4, $5)
RETURNING id
`, testWorkspaceID, testUserID, title, jID).Scan(&id); err != nil {
`, testWorkspaceID, testUserID, title, jID, number).Scan(&id); err != nil {
t.Fatalf("create issue %q: %v", title, err)
}
t.Cleanup(func() {