fix(completion): add contains fallback for first fuzzy input
This commit is contained in:
5 files changed
+106
-12
No files matched your search
@@ -374,7 +374,8 @@ describe("connectionStore completion assistant", () => {
|
||||
|
||||
const [first, second] = await Promise.all([store.listCompletionTables("pg-1", "app", "acc", 20, "public"), store.listCompletionTables("pg-1", "app", "acc", 20, "public")]);
|
||||
|
||||
expect(completionAssistantSearch).toHaveBeenCalledTimes(1);
|
||||
// Both callers share one in-flight prefix lookup plus its widened substring lookup.
|
||||
expect(completionAssistantSearch.mock.calls.map(([request]) => (request as { match_mode?: string }).match_mode)).toEqual(["prefix", "contains"]);
|
||||
expect(first).toEqual(second);
|
||||
expect(first[0]).toMatchObject({ name: "accounts", schema: "public", type: "table" });
|
||||
});
|
||||
@@ -426,11 +427,62 @@ describe("connectionStore completion assistant", () => {
|
||||
|
||||
const tables = await store.listCompletionTables("pg-1", "app", "accounts", 200, "reporting", false, "reporting", undefined, { verifySchemaMetadata: true });
|
||||
|
||||
expect(completionAssistantSearch).toHaveBeenCalledOnce();
|
||||
expect(completionAssistantSearch.mock.calls.map(([request]) => (request as { match_mode?: string }).match_mode)).toEqual(["prefix", "contains"]);
|
||||
expect(listTables).toHaveBeenCalledWith("pg-1", "app", "reporting", "accounts", 200);
|
||||
expect(tables).toEqual([{ name: "accounts", schema: "reporting", type: "table", detail: "→ Customer accounts" }]);
|
||||
});
|
||||
|
||||
it("widens a sparse prefix search with substring matches", async () => {
|
||||
const completionAssistantSearch = vi.fn(async (request: { match_mode?: string }) =>
|
||||
request.match_mode === "contains" ? { candidates: [{ name: "YY_SFXXMK", kind: "view", schema: "public" }], incomplete: false, fallback_used: false } : { candidates: [{ name: "SFXXMK", kind: "table", schema: "public" }], incomplete: false, fallback_used: false },
|
||||
);
|
||||
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({
|
||||
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
|
||||
completionAssistantSearch,
|
||||
listSchemas: vi.fn().mockResolvedValue(["public"]),
|
||||
listTables: vi.fn().mockResolvedValue([]),
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
store.connections = [postgresConnection()];
|
||||
store.connectedIds.add("pg-1");
|
||||
|
||||
const tables = await store.listCompletionTables("pg-1", "app", "sfxxm", 200, "public");
|
||||
|
||||
expect(completionAssistantSearch.mock.calls.map(([request]) => (request as { match_mode?: string }).match_mode)).toEqual(["prefix", "contains"]);
|
||||
expect(tables.map((table) => table.name)).toEqual(["SFXXMK", "YY_SFXXMK"]);
|
||||
});
|
||||
|
||||
it("skips the substring lookup when the prefix search fills the result budget or the filter is short", async () => {
|
||||
const completionAssistantSearch = vi.fn().mockResolvedValue({
|
||||
candidates: [{ name: "accounts", kind: "table", schema: "public" }],
|
||||
incomplete: false,
|
||||
fallback_used: false,
|
||||
});
|
||||
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({
|
||||
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
|
||||
completionAssistantSearch,
|
||||
listSchemas: vi.fn().mockResolvedValue(["public"]),
|
||||
listTables: vi.fn().mockResolvedValue([]),
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
store.connections = [postgresConnection()];
|
||||
store.connectedIds.add("pg-1");
|
||||
|
||||
await store.listCompletionTables("pg-1", "app", "acc", 1, "public");
|
||||
expect(completionAssistantSearch).toHaveBeenCalledTimes(1);
|
||||
|
||||
await store.listCompletionTables("pg-1", "app", "ac", 200, "public");
|
||||
expect(completionAssistantSearch).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("keeps schema-qualified local table completion scoped to the selected schema", async () => {
|
||||
const completionAssistantSearch = vi.fn().mockRejectedValue(new Error("assistant unavailable"));
|
||||
const listTables = vi.fn(async (_connectionId: string, _database: string, schema: string, filter: string) => {
|
||||
@@ -1386,8 +1438,11 @@ describe("connectionStore completion assistant", () => {
|
||||
await store.listCompletionObjects("pg-1", "app", "Order", 20, undefined, undefined, false, undefined, ["sequence"]);
|
||||
await store.listCompletionObjects("pg-1", "app", "order", 20, "App", undefined, false, undefined, ["sequence"], true);
|
||||
|
||||
expect(completionAssistantSearch).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
// Each lookup issues a prefix search plus a widened substring search; the prefix
|
||||
// requests carry the scoping and case sensitivity under test here.
|
||||
const prefixRequests = completionAssistantSearch.mock.calls.map(([request]) => request as { match_mode?: string }).filter((request) => request.match_mode === "prefix");
|
||||
expect(prefixRequests).toHaveLength(3);
|
||||
expect(prefixRequests[0]).toEqual(
|
||||
expect.objectContaining({
|
||||
object_kinds: ["sequence"],
|
||||
mask: "Order",
|
||||
@@ -1396,8 +1451,7 @@ describe("connectionStore completion assistant", () => {
|
||||
parent_schema: null,
|
||||
}),
|
||||
);
|
||||
expect(completionAssistantSearch).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
expect(prefixRequests[1]).toEqual(
|
||||
expect.objectContaining({
|
||||
object_kinds: ["sequence"],
|
||||
mask: "Order",
|
||||
@@ -1406,8 +1460,7 @@ describe("connectionStore completion assistant", () => {
|
||||
parent_schema: null,
|
||||
}),
|
||||
);
|
||||
expect(completionAssistantSearch).toHaveBeenNthCalledWith(
|
||||
3,
|
||||
expect(prefixRequests[2]).toEqual(
|
||||
expect.objectContaining({
|
||||
object_kinds: ["sequence"],
|
||||
mask: "order",
|
||||
|
||||
Reference in new issue
Block a user