Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
fix(search): recognize digit-containing issue prefixes across search paths (#9101)
Bohan Jiang647b18b18a87
diff --git a/packages/core/search-index/engine.test.ts b/packages/core/search-index/engine.test.tsindex d793298e00..e989470841 100644--- a/packages/core/search-index/engine.test.ts+++ b/packages/core/search-index/engine.test.ts@@ -144,18 +144,27 @@ describe("SearchIndexEngine.searchIssues ranking", () => {]);});- it("puts an exact identifier or bare number first, even without a text match", () => {- const target = issue({ title: "no text overlap", number: 4242, identifier: "MUL-4242" });+ it.each(["MUL", "V2", "A1"])("puts a %s identifier or bare number first, even without a text match", (prefix) => {+ const target = issue({ title: "no text overlap", number: 4242, identifier: `${prefix}-4242` });const textHit = issue({ title: "mentions 4242 in the title" });const engine = engineWith([textHit, target]);- const byIdentifier = engine.searchIssues({ q: "mul-4242" });+ const byIdentifier = engine.searchIssues({ q: ` ${prefix.toLowerCase()}-4242 ` });expect(byIdentifier.map((h) => h.id)).toEqual([target.id]);expect(byIdentifier[0]!.matchSource).toBe("comment");expect(engine.searchIssues({ q: "4242" }).map((h) => h.id)).toEqual([target.id, textHit.id]);});+ it("keeps a cancelled digit-prefix identifier ahead of text hits before limiting", () => {+ const target = issue({ title: "no text overlap", number: 12, identifier: "V2-12", status: "cancelled" });+ const textHit = issue({ title: "notes about V2-12" });+ const engine = engineWith([textHit, target]);++ expect(engine.searchIssues({ q: "V2-12", include_closed: true, limit: 1 }).map((h) => h.id)).toEqual([target.id]);+ expect(engine.searchIssues({ q: "V2-12", limit: 1 }).map((h) => h.id)).toEqual([textHit.id]);+ });+it("demotes cancelled issues unless the query targets them directly", () => {const cancelled = issue({ title: "billing export", status: "cancelled" });const live = issue({ title: "old billing export job", status: "done" });diff --git a/packages/core/search-index/engine.ts b/packages/core/search-index/engine.tsindex 865a5f3948..5aedf5b143 100644--- a/packages/core/search-index/engine.ts+++ b/packages/core/search-index/engine.ts@@ -140,10 +140,10 @@ function isTerminal(issue: Pick<SearchIndexIssue, "status" | "status_category">)return category === "done" || category === "closed";}-/** Server parseQueryNumber: "MUL-123" or a bare "123". */+/** Server parseQueryNumber: "MUL-123", "V2-12", or a bare "123". */function parseQueryNumber(query: string): number | null {const q = query.trim();- const match = /^[a-z]+-(\d+)$/i.exec(q) ?? /^(\d+)$/.exec(q);+ const match = /^[a-z][a-z0-9]*-(\d+)$/i.exec(q) ?? /^(\d+)$/.exec(q);if (!match) return null;const n = Number.parseInt(match[1]!, 10);return Number.isInteger(n) && n > 0 ? n : null;diff --git a/packages/core/search/cancelled-rank.test.ts b/packages/core/search/cancelled-rank.test.tsindex f80d79c64c..26fde8e5a6 100644--- a/packages/core/search/cancelled-rank.test.ts+++ b/packages/core/search/cancelled-rank.test.ts@@ -1,3 +1,4 @@+// @vitest-environment nodeimport { describe, it, expect } from "vitest";import type { SearchIssueResult, SearchProjectResult } from "../types/api";import {@@ -39,6 +40,20 @@ describe("parseSearchQueryNumber", () => {expect(parseSearchQueryNumber(" 123 ")).toBe(123);});+ it.each([+ ["V2-12", 12],+ [" v2-12 ", 12],+ ["A1-7", 7],+ ["a1b2-42", 42],+ ])("reads a digit-containing prefix in %s", (query, number) => {+ expect(parseSearchQueryNumber(query)).toBe(number);+ });++ it.each(["12-3", "2FAS-1", "V2-0", "V2--12", "V2-12x", "V_2-12"])(+ "does not read %s as an issue number",+ (query) => expect(parseSearchQueryNumber(query)).toBeNull(),+ );+it("returns null for anything that is not a target", () => {expect(parseSearchQueryNumber("search")).toBeNull();expect(parseSearchQueryNumber("MUL-")).toBeNull();diff --git a/packages/core/search/cancelled-rank.ts b/packages/core/search/cancelled-rank.tsindex e5884e5795..4085202be5 100644--- a/packages/core/search/cancelled-rank.ts+++ b/packages/core/search/cancelled-rank.ts@@ -24,9 +24,9 @@ import { issueBehavesAs } from "../issues/status-category";/*** Mirrors the server's identifier pattern (parseQueryNumber in- * server/internal/handler/issue.go): "MUL-123" or a bare "123".+ * server/internal/handler/issue.go): "MUL-123", "V2-12", or a bare "123".*/-const IDENTIFIER_NUMBER_RE = /^[a-z]+-(\d+)$/i;+const IDENTIFIER_NUMBER_RE = /^[a-z][a-z0-9]*-(\d+)$/i;/** Extracts the issue number a query targets, or null when it targets none. */export function parseSearchQueryNumber(query: string): number | null {diff --git a/packages/views/editor/extensions/mention-suggestion.test.tsx b/packages/views/editor/extensions/mention-suggestion.test.tsxindex 2a8bd3de81..1ea13332a4 100644--- a/packages/views/editor/extensions/mention-suggestion.test.tsx+++ b/packages/views/editor/extensions/mention-suggestion.test.tsx@@ -1304,13 +1304,17 @@ describe("MentionList cancelled demotion", () => {expect(headings()).not.toContain("Cancelled");});- it("keeps a cancelled direct hit visible behind a full window of live candidates", async () => {+ it.each([+ ["MUL-99", "MUL-99"],+ ["V2-99", "v2-99"],+ ["V2-99", "99"],+ ])("keeps cancelled %s visible behind a full window when searching %s", async (identifier, query) => {// 20 non-cancelled cached candidates already fill every slot. Exempting// the direct hit from the demotion would leave it at position 21 and the// truncation would still delete it, so it has to be pinned to the front.searchIssuesMock.mockResolvedValue({issues: [- { id: "i-hit", identifier: "MUL-99", title: "Abandoned plan", status: "cancelled" },+ { id: "i-hit", identifier, title: "Abandoned plan", status: "cancelled" },],total: 1,});@@ -1322,15 +1326,15 @@ describe("MentionList cancelled demotion", () => {status: "todo" as const,}));- render(<I18nWrapper><MentionList items={items} query="MUL-99" command={vi.fn()} /></I18nWrapper>);+ render(<I18nWrapper><MentionList items={items} query={query} command={vi.fn()} /></I18nWrapper>);await waitFor(() => {- expect(screen.getByText("MUL-99")).toBeInTheDocument();+ expect(screen.getByText(identifier)).toBeInTheDocument();});const labels = rowLabels();expect(labels).toHaveLength(20);- expect(labels[0]).toBe("MUL-99");+ expect(labels[0]).toBe(identifier);// A live candidate gave up the last slot, not the record the user typed.expect(labels).not.toContain("MUL-219");});diff --git a/server/internal/handler/issue.go b/server/internal/handler/issue.goindex 05cae67638..879cf4ac58 100644--- a/server/internal/handler/issue.go+++ b/server/internal/handler/issue.go@@ -774,11 +774,11 @@ func splitSearchTerms(q string) []string {return terms}-// identifierNumberRe matches patterns like "MUL-123" or "ABC-45".-var identifierNumberRe = regexp.MustCompile(`(?i)^[a-z]+-(\d+)$`)+// identifierNumberRe matches letter-leading prefixes like "MUL-123" or "V2-12".+var identifierNumberRe = regexp.MustCompile(`(?i)^[a-z][a-z0-9]*-(\d+)$`)// parseQueryNumber extracts an issue number from the query if it looks like-// an identifier (e.g. "MUL-123") or a bare number (e.g. "123").+// an identifier (e.g. "MUL-123" or "V2-12") or a bare number (e.g. "123").func parseQueryNumber(q string) (int, bool) {q = strings.TrimSpace(q)// Check for identifier pattern like "MUL-123"diff --git a/server/internal/handler/search_identifier_test.go b/server/internal/handler/search_identifier_test.gonew file mode 100644index 0000000000..8beb0fd4af--- /dev/null+++ b/server/internal/handler/search_identifier_test.go@@ -0,0 +1,97 @@+package handler++import (+ "fmt"+ "net/http"+ "net/url"+ "testing"++ "github.com/google/uuid"+ "github.com/multica-ai/multica/server/internal/testutil"+)++func TestParseQueryNumber(t *testing.T) {+ for _, tc := range []struct {+ query string+ want int+ }{+ {"MUL-123", 123},+ {"mul-123", 123},+ {" 123 ", 123},+ {"V2-12", 12},+ {" v2-12 ", 12},+ {"A1-7", 7},+ {"a1b2-42", 42},+ {"12-3", 0},+ {"2FAS-1", 0},+ {"V2-0", 0},+ {"V2--12", 0},+ {"V2-12x", 0},+ {"V_2-12", 0},+ {"MUL-", 0},+ {"search", 0},+ {"0", 0},+ {"", 0},+ } {+ t.Run(tc.query, func(t *testing.T) {+ got, ok := parseQueryNumber(tc.query)+ if got != tc.want || ok != (tc.want > 0) {+ t.Fatalf("parseQueryNumber(%q) = (%d, %t), want (%d, %t)", tc.query, got, ok, tc.want, tc.want > 0)+ }+ })+ }+}++func TestIssueSearch_DigitPrefix(t *testing.T) {+ workspaceID := dbfx.Workspace(t, "Digit prefix search", "digit-search-"+uuid.NewString(), testutil.Cols{"issue_prefix": "V2"})+ dbfx.Member(t, workspaceID, testUserID, "owner")+ targetID := dbfx.Issue(t, "Abandoned plan", testutil.Cols{+ "workspace_id": workspaceID, "number": 12, "status": "cancelled",+ })+ liveID := dbfx.Issue(t, "Notes about V2-12", testutil.Cols{"workspace_id": workspaceID})+ foreignWorkspaceID := dbfx.Workspace(t, "Other search workspace", "other-search-"+uuid.NewString())+ dbfx.Issue(t, "V2-12", testutil.Cols{"workspace_id": foreignWorkspaceID, "number": 12})++ for _, query := range []string{"V2-12", "v2-12", "12"} {+ t.Run(query, func(t *testing.T) {+ // The fallback API must retain the exact cancelled hit ahead of live+ // text matches, even when the result window has only one slot.+ for _, includeClosed := range []bool{true, false} {+ path := fmt.Sprintf("/api/issues/search?q=%s&include_closed=%t&limit=1", url.QueryEscape(query), includeClosed)+ req := newRequest(http.MethodGet, path, nil)+ req.Header.Set("X-Workspace-ID", workspaceID)+ var response struct {+ Issues []SearchIssueResponse `json:"issues"`+ }+ testutil.Call(t, testHandler.SearchIssues, req).Want(http.StatusOK).JSON(&response)+ wantID := liveID+ if includeClosed {+ wantID = targetID+ }+ if len(response.Issues) != 1 || response.Issues[0].ID != wantID {+ t.Fatalf("search include_closed=%t: got %+v, want issue %s", includeClosed, response.Issues, wantID)+ }+ }++ // List search uses the same parser while preserving active filters+ // and the total for the filtered result set.+ for _, status := range []string{"cancelled", "todo"} {+ path := fmt.Sprintf("/api/issues?q=%s&status=%s&limit=1", url.QueryEscape(query), status)+ req := newRequest(http.MethodGet, path, nil)+ req.Header.Set("X-Workspace-ID", workspaceID)+ var response struct {+ Issues []IssueResponse `json:"issues"`+ Total int64 `json:"total"`+ }+ testutil.Call(t, testHandler.ListIssues, req).Want(http.StatusOK).JSON(&response)+ wantID := liveID+ if status == "cancelled" {+ wantID = targetID+ }+ if response.Total != 1 || len(response.Issues) != 1 || response.Issues[0].ID != wantID {+ t.Fatalf("list status=%s: got %+v, want only issue %s", status, response, wantID)+ }+ }+ })+ }+}