@open-mercato/search 0.6.4-develop.4371.1.8f3030407e → 0.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/dist/lib/merger.js +5 -2
  3. package/dist/lib/merger.js.map +2 -2
  4. package/dist/modules/search/__integration__/TC-SEARCH-003.spec.js +64 -0
  5. package/dist/modules/search/__integration__/TC-SEARCH-003.spec.js.map +7 -0
  6. package/dist/modules/search/__integration__/TC-SEARCH-004.spec.js +97 -0
  7. package/dist/modules/search/__integration__/TC-SEARCH-004.spec.js.map +7 -0
  8. package/dist/modules/search/__integration__/TC-SEARCH-005.spec.js +28 -0
  9. package/dist/modules/search/__integration__/TC-SEARCH-005.spec.js.map +7 -0
  10. package/dist/modules/search/__integration__/TC-SEARCH-006.spec.js +48 -0
  11. package/dist/modules/search/__integration__/TC-SEARCH-006.spec.js.map +7 -0
  12. package/dist/modules/search/__integration__/TC-SEARCH-007.spec.js +38 -0
  13. package/dist/modules/search/__integration__/TC-SEARCH-007.spec.js.map +7 -0
  14. package/dist/modules/search/__integration__/TC-SEARCH-008.spec.js +77 -0
  15. package/dist/modules/search/__integration__/TC-SEARCH-008.spec.js.map +7 -0
  16. package/dist/modules/search/__integration__/TC-SEARCH-009.spec.js +54 -0
  17. package/dist/modules/search/__integration__/TC-SEARCH-009.spec.js.map +7 -0
  18. package/dist/modules/search/ai-tools.js +61 -2
  19. package/dist/modules/search/ai-tools.js.map +2 -2
  20. package/dist/vector/services/vector-index.service.js +45 -25
  21. package/dist/vector/services/vector-index.service.js.map +2 -2
  22. package/package.json +9 -10
  23. package/src/__tests__/merger.test.ts +50 -0
  24. package/src/__tests__/vector-index-security.test.ts +230 -0
  25. package/src/lib/merger.ts +16 -2
  26. package/src/modules/search/README.md +1 -1
  27. package/src/modules/search/__integration__/TC-SEARCH-003.spec.ts +102 -0
  28. package/src/modules/search/__integration__/TC-SEARCH-004.spec.ts +135 -0
  29. package/src/modules/search/__integration__/TC-SEARCH-005.spec.ts +45 -0
  30. package/src/modules/search/__integration__/TC-SEARCH-006.spec.ts +74 -0
  31. package/src/modules/search/__integration__/TC-SEARCH-007.spec.ts +72 -0
  32. package/src/modules/search/__integration__/TC-SEARCH-008.spec.ts +124 -0
  33. package/src/modules/search/__integration__/TC-SEARCH-009.spec.ts +85 -0
  34. package/src/modules/search/__tests__/ai-tools.aggregate.test.ts +89 -4
  35. package/src/modules/search/__tests__/ai-tools.get.test.ts +118 -0
  36. package/src/modules/search/ai-tools.ts +111 -3
  37. package/src/vector/services/vector-index.service.ts +57 -25
@@ -1,2 +1,2 @@
1
- [build:search] found 81 entry points
1
+ [build:search] found 88 entry points
2
2
  [build:search] built successfully
@@ -1,4 +1,7 @@
1
1
  const RRF_K = 60;
2
+ function dedupeKey(result) {
3
+ return `${result.organizationId ?? ""}:${result.entityId}:${result.recordId}`;
4
+ }
2
5
  function mergeAndRankResults(results, config) {
3
6
  if (results.length === 0) return [];
4
7
  const bySource = /* @__PURE__ */ new Map();
@@ -12,7 +15,7 @@ function mergeAndRankResults(results, config) {
12
15
  const weight = config.strategyWeights?.[source] ?? 1;
13
16
  for (let rank = 0; rank < sourceResults.length; rank++) {
14
17
  const result = sourceResults[rank];
15
- const key = `${result.entityId}:${result.recordId}`;
18
+ const key = dedupeKey(result);
16
19
  const rrfScore = weight / (RRF_K + rank + 1);
17
20
  const existing = seen.get(key);
18
21
  if (existing) {
@@ -70,7 +73,7 @@ function mergeAndRankResults(results, config) {
70
73
  function deduplicateResults(results) {
71
74
  const seen = /* @__PURE__ */ new Map();
72
75
  for (const result of results) {
73
- const key = `${result.entityId}:${result.recordId}`;
76
+ const key = dedupeKey(result);
74
77
  const existing = seen.get(key);
75
78
  if (!existing || result.score > existing.score) {
76
79
  seen.set(key, result);
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/lib/merger.ts"],
4
- "sourcesContent": ["import type { SearchResult, ResultMergeConfig, SearchStrategyId } from '../types'\n\n/**\n * Default RRF constant (k=60 is standard in literature).\n * Higher values reduce the influence of ranking position.\n */\nconst RRF_K = 60\n\n/**\n * Reciprocal Rank Fusion (RRF) algorithm for combining results from multiple search strategies.\n *\n * RRF is a simple but effective method for combining ranked lists. For each result,\n * it computes: score = sum(weight / (k + rank)) across all lists containing that result.\n *\n * Reference: Cormack, G.V., Clarke, C.L.A., & Buettcher, S. (2009).\n * \"Reciprocal rank fusion outperforms condorcet and individual rank learning methods\"\n * https://plg.uwaterloo.ca/~gvcormac/cormacksigir09-rrf.pdf\n *\n * @param results - Array of search results from multiple strategies\n * @param config - Merge configuration with weights and thresholds\n * @returns Merged and ranked results\n */\nexport function mergeAndRankResults(\n results: SearchResult[],\n config: ResultMergeConfig,\n): SearchResult[] {\n if (results.length === 0) return []\n\n // Group results by source strategy for rank calculation\n const bySource = new Map<SearchStrategyId, SearchResult[]>()\n for (const result of results) {\n const list = bySource.get(result.source) ?? []\n list.push(result)\n bySource.set(result.source, list)\n }\n\n // Track seen results with their RRF scores\n // bestContribution tracks the highest single RRF contribution for the kept result object\n const seen = new Map<string, { result: SearchResult; rrf: number; sources: Set<SearchStrategyId>; bestContribution: number }>()\n\n // Calculate RRF score for each result\n for (const [source, sourceResults] of bySource) {\n const weight = config.strategyWeights?.[source] ?? 1.0\n\n for (let rank = 0; rank < sourceResults.length; rank++) {\n const result = sourceResults[rank]\n const key = `${result.entityId}:${result.recordId}`\n const rrfScore = weight / (RRF_K + rank + 1)\n\n const existing = seen.get(key)\n if (existing) {\n // Combine RRF scores for duplicates found in multiple strategies\n existing.rrf += rrfScore\n existing.sources.add(source)\n\n // Merge presenter data - prefer result that has it\n // This ensures token results get enriched with presenter from meilisearch/vector\n const hasExistingPresenter = existing.result.presenter?.title != null\n const hasNewPresenter = result.presenter?.title != null\n\n if (!hasExistingPresenter && hasNewPresenter) {\n // Current result has no presenter, new one does - take new one's presenter\n existing.result = {\n ...existing.result,\n presenter: result.presenter,\n url: existing.result.url ?? result.url,\n links: existing.result.links ?? result.links,\n organizationId: existing.result.organizationId ?? result.organizationId,\n }\n existing.bestContribution = Math.max(existing.bestContribution, rrfScore)\n } else if (hasExistingPresenter && hasNewPresenter && rrfScore > existing.bestContribution) {\n // Both have presenter, keep the one with better RRF contribution (not raw score)\n existing.result = {\n ...result,\n organizationId: result.organizationId ?? existing.result.organizationId,\n }\n existing.bestContribution = rrfScore\n } else if (!hasExistingPresenter && !hasNewPresenter && rrfScore > existing.bestContribution) {\n // Neither has presenter, keep result with better RRF contribution\n existing.result = {\n ...result,\n organizationId: result.organizationId ?? existing.result.organizationId,\n }\n existing.bestContribution = rrfScore\n }\n // If existing has presenter and new doesn't, keep existing (do nothing)\n } else {\n seen.set(key, {\n result: { ...result },\n rrf: rrfScore,\n sources: new Set([source]),\n bestContribution: rrfScore,\n })\n }\n }\n }\n\n // Convert to array with final RRF scores\n let merged = Array.from(seen.values()).map(({ result, rrf, sources }) => ({\n ...result,\n score: rrf,\n metadata: {\n ...result.metadata,\n _sources: Array.from(sources),\n _rrfScore: rrf,\n },\n }))\n\n // Apply minimum score threshold\n if (config.minScore != null) {\n merged = merged.filter((r) => r.score >= config.minScore!)\n }\n\n // Sort by RRF score descending\n merged.sort((a, b) => b.score - a.score)\n\n return merged\n}\n\n/**\n * Simple deduplication without RRF scoring.\n * Keeps the highest-scored result for each entity+record pair.\n *\n * @param results - Array of search results\n * @returns Deduplicated results sorted by score\n */\nexport function deduplicateResults(results: SearchResult[]): SearchResult[] {\n const seen = new Map<string, SearchResult>()\n\n for (const result of results) {\n const key = `${result.entityId}:${result.recordId}`\n const existing = seen.get(key)\n\n if (!existing || result.score > existing.score) {\n seen.set(key, result)\n }\n }\n\n return Array.from(seen.values()).sort((a, b) => b.score - a.score)\n}\n\n/**\n * Normalize scores to 0-1 range using min-max normalization.\n * Useful when combining strategies with different score scales.\n *\n * @param results - Array of search results\n * @returns Results with normalized scores\n */\nexport function normalizeScores(results: SearchResult[]): SearchResult[] {\n if (results.length === 0) return []\n\n const scores = results.map((r) => r.score)\n const minScore = Math.min(...scores)\n const maxScore = Math.max(...scores)\n const range = maxScore - minScore\n\n if (range === 0) {\n // All scores are the same, normalize to 1.0\n return results.map((r) => ({ ...r, score: 1.0 }))\n }\n\n return results.map((r) => ({\n ...r,\n score: (r.score - minScore) / range,\n }))\n}\n"],
5
- "mappings": "AAMA,MAAM,QAAQ;AAgBP,SAAS,oBACd,SACA,QACgB;AAChB,MAAI,QAAQ,WAAW,EAAG,QAAO,CAAC;AAGlC,QAAM,WAAW,oBAAI,IAAsC;AAC3D,aAAW,UAAU,SAAS;AAC5B,UAAM,OAAO,SAAS,IAAI,OAAO,MAAM,KAAK,CAAC;AAC7C,SAAK,KAAK,MAAM;AAChB,aAAS,IAAI,OAAO,QAAQ,IAAI;AAAA,EAClC;AAIA,QAAM,OAAO,oBAAI,IAA6G;AAG9H,aAAW,CAAC,QAAQ,aAAa,KAAK,UAAU;AAC9C,UAAM,SAAS,OAAO,kBAAkB,MAAM,KAAK;AAEnD,aAAS,OAAO,GAAG,OAAO,cAAc,QAAQ,QAAQ;AACtD,YAAM,SAAS,cAAc,IAAI;AACjC,YAAM,MAAM,GAAG,OAAO,QAAQ,IAAI,OAAO,QAAQ;AACjD,YAAM,WAAW,UAAU,QAAQ,OAAO;AAE1C,YAAM,WAAW,KAAK,IAAI,GAAG;AAC7B,UAAI,UAAU;AAEZ,iBAAS,OAAO;AAChB,iBAAS,QAAQ,IAAI,MAAM;AAI3B,cAAM,uBAAuB,SAAS,OAAO,WAAW,SAAS;AACjE,cAAM,kBAAkB,OAAO,WAAW,SAAS;AAEnD,YAAI,CAAC,wBAAwB,iBAAiB;AAE5C,mBAAS,SAAS;AAAA,YAChB,GAAG,SAAS;AAAA,YACZ,WAAW,OAAO;AAAA,YAClB,KAAK,SAAS,OAAO,OAAO,OAAO;AAAA,YACnC,OAAO,SAAS,OAAO,SAAS,OAAO;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5B,UAAM,MAAM,GAAG,OAAO,QAAQ,IAAI,OAAO,QAAQ;AACjD,UAAM,WAAW,KAAK,IAAI,GAAG;AAE7B,QAAI,CAAC,YAAY,OAAO,QAAQ,SAAS,OAAO;AAC9C,WAAK,IAAI,KAAK,MAAM;AAAA,IACtB;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,KAAK,OAAO,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AACnE;AASO,SAAS,gBAAgB,SAAyC;AACvE,MAAI,QAAQ,WAAW,EAAG,QAAO,CAAC;AAElC,QAAM,SAAS,QAAQ,IAAI,CAAC,MAAM,EAAE,KAAK;AACzC,QAAM,WAAW,KAAK,IAAI,GAAG,MAAM;AACnC,QAAM,WAAW,KAAK,IAAI,GAAG,MAAM;AACnC,QAAM,QAAQ,WAAW;AAEzB,MAAI,UAAU,GAAG;AAEf,WAAO,QAAQ,IAAI,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,EAAI,EAAE;AAAA,EAClD;AAEA,SAAO,QAAQ,IAAI,CAAC,OAAO;AAAA,IACzB,GAAG;AAAA,IACH,QAAQ,EAAE,QAAQ,YAAY;AAAA,EAChC,EAAE;AACJ;",
4
+ "sourcesContent": ["import type { SearchResult, ResultMergeConfig, SearchStrategyId } from '../types'\n\n/**\n * Default RRF constant (k=60 is standard in literature).\n * Higher values reduce the influence of ranking position.\n */\nconst RRF_K = 60\n\n/**\n * Build the deduplication key for a search result.\n *\n * The key includes `organizationId` so the same `entityId:recordId` surfaced\n * for different organizations (for example from a stale index) never collides\n * into a single merged entry. This is a defense-in-depth guard: the per-strategy\n * `filterResultsByOrganizationScope()` already drops foreign-org results before\n * merging, but keying on org here ensures the merger can never silently coalesce\n * results across tenants if that upstream filter is bypassed.\n */\nfunction dedupeKey(result: SearchResult): string {\n return `${result.organizationId ?? ''}:${result.entityId}:${result.recordId}`\n}\n\n/**\n * Reciprocal Rank Fusion (RRF) algorithm for combining results from multiple search strategies.\n *\n * RRF is a simple but effective method for combining ranked lists. For each result,\n * it computes: score = sum(weight / (k + rank)) across all lists containing that result.\n *\n * Reference: Cormack, G.V., Clarke, C.L.A., & Buettcher, S. (2009).\n * \"Reciprocal rank fusion outperforms condorcet and individual rank learning methods\"\n * https://plg.uwaterloo.ca/~gvcormac/cormacksigir09-rrf.pdf\n *\n * @param results - Array of search results from multiple strategies\n * @param config - Merge configuration with weights and thresholds\n * @returns Merged and ranked results\n */\nexport function mergeAndRankResults(\n results: SearchResult[],\n config: ResultMergeConfig,\n): SearchResult[] {\n if (results.length === 0) return []\n\n // Group results by source strategy for rank calculation\n const bySource = new Map<SearchStrategyId, SearchResult[]>()\n for (const result of results) {\n const list = bySource.get(result.source) ?? []\n list.push(result)\n bySource.set(result.source, list)\n }\n\n // Track seen results with their RRF scores\n // bestContribution tracks the highest single RRF contribution for the kept result object\n const seen = new Map<string, { result: SearchResult; rrf: number; sources: Set<SearchStrategyId>; bestContribution: number }>()\n\n // Calculate RRF score for each result\n for (const [source, sourceResults] of bySource) {\n const weight = config.strategyWeights?.[source] ?? 1.0\n\n for (let rank = 0; rank < sourceResults.length; rank++) {\n const result = sourceResults[rank]\n const key = dedupeKey(result)\n const rrfScore = weight / (RRF_K + rank + 1)\n\n const existing = seen.get(key)\n if (existing) {\n // Combine RRF scores for duplicates found in multiple strategies\n existing.rrf += rrfScore\n existing.sources.add(source)\n\n // Merge presenter data - prefer result that has it\n // This ensures token results get enriched with presenter from meilisearch/vector\n const hasExistingPresenter = existing.result.presenter?.title != null\n const hasNewPresenter = result.presenter?.title != null\n\n if (!hasExistingPresenter && hasNewPresenter) {\n // Current result has no presenter, new one does - take new one's presenter\n existing.result = {\n ...existing.result,\n presenter: result.presenter,\n url: existing.result.url ?? result.url,\n links: existing.result.links ?? result.links,\n organizationId: existing.result.organizationId ?? result.organizationId,\n }\n existing.bestContribution = Math.max(existing.bestContribution, rrfScore)\n } else if (hasExistingPresenter && hasNewPresenter && rrfScore > existing.bestContribution) {\n // Both have presenter, keep the one with better RRF contribution (not raw score)\n existing.result = {\n ...result,\n organizationId: result.organizationId ?? existing.result.organizationId,\n }\n existing.bestContribution = rrfScore\n } else if (!hasExistingPresenter && !hasNewPresenter && rrfScore > existing.bestContribution) {\n // Neither has presenter, keep result with better RRF contribution\n existing.result = {\n ...result,\n organizationId: result.organizationId ?? existing.result.organizationId,\n }\n existing.bestContribution = rrfScore\n }\n // If existing has presenter and new doesn't, keep existing (do nothing)\n } else {\n seen.set(key, {\n result: { ...result },\n rrf: rrfScore,\n sources: new Set([source]),\n bestContribution: rrfScore,\n })\n }\n }\n }\n\n // Convert to array with final RRF scores\n let merged = Array.from(seen.values()).map(({ result, rrf, sources }) => ({\n ...result,\n score: rrf,\n metadata: {\n ...result.metadata,\n _sources: Array.from(sources),\n _rrfScore: rrf,\n },\n }))\n\n // Apply minimum score threshold\n if (config.minScore != null) {\n merged = merged.filter((r) => r.score >= config.minScore!)\n }\n\n // Sort by RRF score descending\n merged.sort((a, b) => b.score - a.score)\n\n return merged\n}\n\n/**\n * Simple deduplication without RRF scoring.\n * Keeps the highest-scored result for each entity+record pair.\n *\n * @param results - Array of search results\n * @returns Deduplicated results sorted by score\n */\nexport function deduplicateResults(results: SearchResult[]): SearchResult[] {\n const seen = new Map<string, SearchResult>()\n\n for (const result of results) {\n const key = dedupeKey(result)\n const existing = seen.get(key)\n\n if (!existing || result.score > existing.score) {\n seen.set(key, result)\n }\n }\n\n return Array.from(seen.values()).sort((a, b) => b.score - a.score)\n}\n\n/**\n * Normalize scores to 0-1 range using min-max normalization.\n * Useful when combining strategies with different score scales.\n *\n * @param results - Array of search results\n * @returns Results with normalized scores\n */\nexport function normalizeScores(results: SearchResult[]): SearchResult[] {\n if (results.length === 0) return []\n\n const scores = results.map((r) => r.score)\n const minScore = Math.min(...scores)\n const maxScore = Math.max(...scores)\n const range = maxScore - minScore\n\n if (range === 0) {\n // All scores are the same, normalize to 1.0\n return results.map((r) => ({ ...r, score: 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SAAS,OAAO;AAC9C,WAAK,IAAI,KAAK,MAAM;AAAA,IACtB;AAAA,EACF;AAEA,SAAO,MAAM,KAAK,KAAK,OAAO,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM,EAAE,QAAQ,EAAE,KAAK;AACnE;AASO,SAAS,gBAAgB,SAAyC;AACvE,MAAI,QAAQ,WAAW,EAAG,QAAO,CAAC;AAElC,QAAM,SAAS,QAAQ,IAAI,CAAC,MAAM,EAAE,KAAK;AACzC,QAAM,WAAW,KAAK,IAAI,GAAG,MAAM;AACnC,QAAM,WAAW,KAAK,IAAI,GAAG,MAAM;AACnC,QAAM,QAAQ,WAAW;AAEzB,MAAI,UAAU,GAAG;AAEf,WAAO,QAAQ,IAAI,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,EAAI,EAAE;AAAA,EAClD;AAEA,SAAO,QAAQ,IAAI,CAAC,OAAO;AAAA,IACzB,GAAG;AAAA,IACH,QAAQ,EAAE,QAAQ,YAAY;AAAA,EAChC,EAAE;AACJ;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,64 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { apiRequest, getAuthToken } from "@open-mercato/core/helpers/integration/api";
3
+ import { getTokenScope } from "@open-mercato/core/helpers/integration/generalFixtures";
4
+ import {
5
+ createRoleFixture,
6
+ createUserFixture,
7
+ deleteRoleIfExists,
8
+ deleteUserIfExists,
9
+ setRoleAclFeatures
10
+ } from "@open-mercato/core/helpers/integration/authFixtures";
11
+ const VALID_PASSWORD = "Valid1!Pass";
12
+ test.describe("TC-SEARCH-003: search API auth & feature gates (401/403)", () => {
13
+ test("gates search.view and search.reindex by authentication and feature", async ({ request }) => {
14
+ test.slow();
15
+ const stamp = Date.now();
16
+ let adminToken = null;
17
+ let superToken = null;
18
+ let roleId = null;
19
+ let viewerUserId = null;
20
+ const roleName = `qa-search-003-viewer-${stamp}`;
21
+ const viewerEmail = `qa-search-003-viewer-${stamp}@acme.com`;
22
+ try {
23
+ const unauthSearch = await request.get("/api/search/search?q=test");
24
+ expect(unauthSearch.status(), "unauthenticated GET /api/search/search must be 401").toBe(401);
25
+ const unauthReindex = await request.post("/api/search/reindex", { data: {} });
26
+ expect(unauthReindex.status(), "unauthenticated POST /api/search/reindex must be 401").toBe(401);
27
+ adminToken = await getAuthToken(request, "admin");
28
+ const scope = getTokenScope(adminToken);
29
+ roleId = await createRoleFixture(request, adminToken, { name: roleName, tenantId: scope.tenantId });
30
+ await setRoleAclFeatures(request, adminToken, { roleId, features: ["search.view"] });
31
+ viewerUserId = await createUserFixture(request, adminToken, {
32
+ email: viewerEmail,
33
+ password: VALID_PASSWORD,
34
+ organizationId: scope.organizationId,
35
+ roles: [roleName],
36
+ name: "QA Search 003 Viewer"
37
+ });
38
+ const viewerToken = await getAuthToken(request, viewerEmail, VALID_PASSWORD);
39
+ const viewerSearch = await apiRequest(request, "GET", "/api/search/search?q=qa-search-003", { token: viewerToken });
40
+ expect(viewerSearch.status(), "viewer with search.view must not be unauthorized on search").not.toBe(401);
41
+ expect(viewerSearch.status(), "viewer with search.view must not be forbidden on search").not.toBe(403);
42
+ expect(viewerSearch.status(), "search.view passes the gate, so the search succeeds with 200").toBe(200);
43
+ const viewerReindex = await apiRequest(request, "POST", "/api/search/reindex", { token: viewerToken, data: {} });
44
+ expect(viewerReindex.status(), "viewer lacking search.reindex must be forbidden on reindex").toBe(403);
45
+ superToken = await getAuthToken(request, "superadmin");
46
+ const superReindex = await apiRequest(request, "POST", "/api/search/reindex", {
47
+ token: superToken,
48
+ data: { entityId: "customers:customer_company_profile", useQueue: false }
49
+ });
50
+ expect(superReindex.status(), "superadmin reindex must not be unauthorized").not.toBe(401);
51
+ expect(superReindex.status(), "superadmin reindex must not be forbidden").not.toBe(403);
52
+ expect([200, 503], "superadmin reindex returns ok (200) or service-unavailable (503)").toContain(
53
+ superReindex.status()
54
+ );
55
+ } finally {
56
+ if (superToken) {
57
+ await apiRequest(request, "POST", "/api/search/reindex/cancel", { token: superToken }).catch(() => void 0);
58
+ }
59
+ await deleteUserIfExists(request, adminToken, viewerUserId);
60
+ await deleteRoleIfExists(request, adminToken, roleId);
61
+ }
62
+ });
63
+ });
64
+ //# sourceMappingURL=TC-SEARCH-003.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/search/__integration__/TC-SEARCH-003.spec.ts"],
4
+ "sourcesContent": ["import { expect, test } from '@playwright/test'\nimport { apiRequest, getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport { getTokenScope, readJsonSafe } from '@open-mercato/core/helpers/integration/generalFixtures'\nimport {\n createRoleFixture,\n createUserFixture,\n deleteRoleIfExists,\n deleteUserIfExists,\n setRoleAclFeatures,\n} from '@open-mercato/core/helpers/integration/authFixtures'\n\n/**\n * TC-SEARCH-003: Search API requires authentication and feature gates (401/403)\n * Source: issue #2483 (expand `search` integration coverage)\n *\n * Real routes (the `search` module id prefixes every route under /api/search):\n * - GET /api/search/search requireAuth + requireFeatures ['search.view']\n * - POST /api/search/reindex requireAuth + requireFeatures ['search.reindex']\n *\n * The framework route wrapper enforces requireAuth (401) and requireFeatures\n * (403) BEFORE the handler body runs, so these gates hold independently of each\n * route's own inline checks. Seeded role features: admin => search.* ,\n * employee => vector.* only, superadmin => all. A user that holds search.view\n * but NOT search.reindex must therefore be provisioned explicitly to prove the\n * granular reindex gate (employee cannot stand in \u2014 it lacks search.view too).\n */\nconst VALID_PASSWORD = 'Valid1!Pass'\n\ntest.describe('TC-SEARCH-003: search API auth & feature gates (401/403)', () => {\n test('gates search.view and search.reindex by authentication and feature', async ({ request }) => {\n test.slow()\n\n const stamp = Date.now()\n let adminToken: string | null = null\n let superToken: string | null = null\n let roleId: string | null = null\n let viewerUserId: string | null = null\n const roleName = `qa-search-003-viewer-${stamp}`\n const viewerEmail = `qa-search-003-viewer-${stamp}@acme.com`\n\n try {\n // 1. Unauthenticated search => 401. q is non-empty, so only the auth gate\n // can produce a 401 here (the handler's empty-query 400 is unreachable\n // because the framework wrapper denies first).\n const unauthSearch = await request.get('/api/search/search?q=test')\n expect(unauthSearch.status(), 'unauthenticated GET /api/search/search must be 401').toBe(401)\n\n // 2. Unauthenticated reindex => 401.\n const unauthReindex = await request.post('/api/search/reindex', { data: {} })\n expect(unauthReindex.status(), 'unauthenticated POST /api/search/reindex must be 401').toBe(401)\n\n adminToken = await getAuthToken(request, 'admin')\n const scope = getTokenScope(adminToken)\n\n // 3. A user with search.view but NOT search.reindex: search is allowed\n // (never 401/403), reindex is forbidden (403).\n roleId = await createRoleFixture(request, adminToken, { name: roleName, tenantId: scope.tenantId })\n await setRoleAclFeatures(request, adminToken, { roleId, features: ['search.view'] })\n viewerUserId = await createUserFixture(request, adminToken, {\n email: viewerEmail,\n password: VALID_PASSWORD,\n organizationId: scope.organizationId,\n roles: [roleName],\n name: 'QA Search 003 Viewer',\n })\n const viewerToken = await getAuthToken(request, viewerEmail, VALID_PASSWORD)\n\n const viewerSearch = await apiRequest(request, 'GET', '/api/search/search?q=qa-search-003', { token: viewerToken })\n expect(viewerSearch.status(), 'viewer with search.view must not be unauthorized on search').not.toBe(401)\n expect(viewerSearch.status(), 'viewer with search.view must not be forbidden on search').not.toBe(403)\n // The search route resolves searchService and returns 200 with results\n // (empty when no strategy returns hits) \u2014 it does not 503 here \u2014 so a passing\n // gate yields 200.\n expect(viewerSearch.status(), 'search.view passes the gate, so the search succeeds with 200').toBe(200)\n\n const viewerReindex = await apiRequest(request, 'POST', '/api/search/reindex', { token: viewerToken, data: {} })\n expect(viewerReindex.status(), 'viewer lacking search.reindex must be forbidden on reindex').toBe(403)\n\n // 4. Superadmin can initiate reindex \u2014 never blocked by auth/feature gates.\n // useQueue:false makes the route clear its own lock in `finally`, so this\n // leaves no lingering fulltext lock for other tests; scoping to a single\n // entity keeps the synchronous reindex cheap.\n superToken = await getAuthToken(request, 'superadmin')\n const superReindex = await apiRequest(request, 'POST', '/api/search/reindex', {\n token: superToken,\n data: { entityId: 'customers:customer_company_profile', useQueue: false },\n })\n expect(superReindex.status(), 'superadmin reindex must not be unauthorized').not.toBe(401)\n expect(superReindex.status(), 'superadmin reindex must not be forbidden').not.toBe(403)\n expect([200, 503], 'superadmin reindex returns ok (200) or service-unavailable (503)').toContain(\n superReindex.status(),\n )\n } finally {\n // Best-effort: release any fulltext lock, then tear down fixtures.\n if (superToken) {\n await apiRequest(request, 'POST', '/api/search/reindex/cancel', { token: superToken }).catch(() => undefined)\n }\n await deleteUserIfExists(request, adminToken, viewerUserId)\n await deleteRoleIfExists(request, adminToken, roleId)\n }\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAY;AAC7B,SAAS,YAAY,oBAAoB;AACzC,SAAS,qBAAmC;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAiBP,MAAM,iBAAiB;AAEvB,KAAK,SAAS,4DAA4D,MAAM;AAC9E,OAAK,sEAAsE,OAAO,EAAE,QAAQ,MAAM;AAChG,SAAK,KAAK;AAEV,UAAM,QAAQ,KAAK,IAAI;AACvB,QAAI,aAA4B;AAChC,QAAI,aAA4B;AAChC,QAAI,SAAwB;AAC5B,QAAI,eAA8B;AAClC,UAAM,WAAW,wBAAwB,KAAK;AAC9C,UAAM,cAAc,wBAAwB,KAAK;AAEjD,QAAI;AAIF,YAAM,eAAe,MAAM,QAAQ,IAAI,2BAA2B;AAClE,aAAO,aAAa,OAAO,GAAG,oDAAoD,EAAE,KAAK,GAAG;AAG5F,YAAM,gBAAgB,MAAM,QAAQ,KAAK,uBAAuB,EAAE,MAAM,CAAC,EAAE,CAAC;AAC5E,aAAO,cAAc,OAAO,GAAG,sDAAsD,EAAE,KAAK,GAAG;AAE/F,mBAAa,MAAM,aAAa,SAAS,OAAO;AAChD,YAAM,QAAQ,cAAc,UAAU;AAItC,eAAS,MAAM,kBAAkB,SAAS,YAAY,EAAE,MAAM,UAAU,UAAU,MAAM,SAAS,CAAC;AAClG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,mBAAmB,SAAS,YAAY,YAAY;AAC1D,YAAM,mBAAmB,SAAS,YAAY,MAAM;AAAA,IACtD;AAAA,EACF,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,97 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { apiRequest, getAuthToken } from "@open-mercato/core/helpers/integration/api";
3
+ import { expectId, getTokenScope, readJsonSafe } from "@open-mercato/core/helpers/integration/generalFixtures";
4
+ import {
5
+ apiRequestWithSelectedOrg,
6
+ createRoleFixture,
7
+ createUserFixture,
8
+ deleteOrganizationIfExists,
9
+ deleteRoleIfExists,
10
+ deleteUserIfExists,
11
+ setRoleAclFeatures,
12
+ setUserAclVisibility
13
+ } from "@open-mercato/core/helpers/integration/authFixtures";
14
+ import { createCompanyFixture, deleteEntityIfExists } from "@open-mercato/core/helpers/integration/crmFixtures";
15
+ const COMPANY_ENTITY = "customers:customer_company_profile";
16
+ const VALID_PASSWORD = "Valid1!Pass";
17
+ function titleOf(item) {
18
+ const presenter = item?.presenter;
19
+ const title = presenter && typeof presenter === "object" ? presenter.title : void 0;
20
+ return typeof title === "string" ? title : "";
21
+ }
22
+ async function searchTitles(request, token, query) {
23
+ const params = new URLSearchParams({ q: query, limit: "20", entityTypes: COMPANY_ENTITY });
24
+ const res = await apiRequest(request, "GET", `/api/search/search?${params.toString()}`, { token });
25
+ if (!res.ok()) return [];
26
+ const body = await readJsonSafe(res) ?? {};
27
+ return (Array.isArray(body.results) ? body.results : []).map(titleOf);
28
+ }
29
+ test.describe("TC-SEARCH-004: search results are organization-scoped", () => {
30
+ test("a restricted org-B user cannot see org-A companies via search", async ({ request }) => {
31
+ test.slow();
32
+ const stamp = Date.now();
33
+ const unique = `QASRCH004${stamp}`;
34
+ let adminToken = null;
35
+ let superToken = null;
36
+ let orgBId = null;
37
+ let roleId = null;
38
+ let userBId = null;
39
+ let companyAId = null;
40
+ let companyBId = null;
41
+ const roleName = `qa-search-004-${stamp}`;
42
+ const userBEmail = `qa-search-004-${stamp}@acme.com`;
43
+ try {
44
+ adminToken = await getAuthToken(request, "admin");
45
+ superToken = await getAuthToken(request, "superadmin");
46
+ const adminScope = getTokenScope(adminToken);
47
+ const orgResp = await apiRequest(request, "POST", "/api/directory/organizations", {
48
+ token: superToken,
49
+ data: { name: `QA Search 004 OrgB ${stamp}`, tenantId: adminScope.tenantId }
50
+ });
51
+ if (orgResp.status() !== 201) {
52
+ test.skip(true, `cannot provision a second organization in this environment (status ${orgResp.status()})`);
53
+ return;
54
+ }
55
+ orgBId = expectId((await readJsonSafe(orgResp))?.id, "organization create returns an id");
56
+ companyAId = await createCompanyFixture(request, adminToken, `${unique} A`);
57
+ const companyBResp = await apiRequestWithSelectedOrg(request, "POST", "/api/customers/companies", {
58
+ token: superToken,
59
+ selectedOrgId: orgBId,
60
+ data: { displayName: `${unique} B` }
61
+ });
62
+ expect(companyBResp.status(), "create company in orgB should return 201").toBe(201);
63
+ companyBId = expectId((await readJsonSafe(companyBResp))?.id, "company B returns an id");
64
+ roleId = await createRoleFixture(request, adminToken, { name: roleName, tenantId: adminScope.tenantId });
65
+ await setRoleAclFeatures(request, adminToken, { roleId, features: ["search.view", "customers.*"] });
66
+ userBId = await createUserFixture(request, superToken, {
67
+ email: userBEmail,
68
+ password: VALID_PASSWORD,
69
+ organizationId: orgBId,
70
+ roles: [roleName],
71
+ name: "QA Search 004 OrgB User"
72
+ });
73
+ await setUserAclVisibility(request, superToken, {
74
+ userId: userBId,
75
+ organizations: [orgBId],
76
+ features: ["search.view", "customers.*"]
77
+ });
78
+ const userBToken = await getAuthToken(request, userBEmail, VALID_PASSWORD);
79
+ expect(getTokenScope(userBToken).organizationId, "org-B user is scoped to orgB").toBe(orgBId);
80
+ await expect.poll(async () => (await searchTitles(request, adminToken, unique)).includes(`${unique} A`), {
81
+ timeout: 15e3
82
+ }).toBe(true);
83
+ await expect.poll(async () => (await searchTitles(request, userBToken, unique)).includes(`${unique} B`), {
84
+ timeout: 15e3
85
+ }).toBe(true);
86
+ const orgBTitles = await searchTitles(request, userBToken, unique);
87
+ expect(orgBTitles, "org-B user must not see the org-A company").not.toContain(`${unique} A`);
88
+ } finally {
89
+ await deleteEntityIfExists(request, superToken, "/api/customers/companies", companyAId);
90
+ await deleteEntityIfExists(request, superToken, "/api/customers/companies", companyBId);
91
+ await deleteUserIfExists(request, superToken, userBId);
92
+ await deleteRoleIfExists(request, adminToken, roleId);
93
+ await deleteOrganizationIfExists(request, superToken, orgBId);
94
+ }
95
+ });
96
+ });
97
+ //# sourceMappingURL=TC-SEARCH-004.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/search/__integration__/TC-SEARCH-004.spec.ts"],
4
+ "sourcesContent": ["import { expect, test, type APIRequestContext } from '@playwright/test'\nimport { apiRequest, getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport { expectId, getTokenScope, readJsonSafe } from '@open-mercato/core/helpers/integration/generalFixtures'\nimport {\n apiRequestWithSelectedOrg,\n createRoleFixture,\n createUserFixture,\n deleteOrganizationIfExists,\n deleteRoleIfExists,\n deleteUserIfExists,\n setRoleAclFeatures,\n setUserAclVisibility,\n} from '@open-mercato/core/helpers/integration/authFixtures'\nimport { createCompanyFixture, deleteEntityIfExists } from '@open-mercato/core/helpers/integration/crmFixtures'\n\ntype SearchResultItem = { entityId?: string; presenter?: { title?: string } | null }\ntype SearchResponse = { results?: SearchResultItem[] }\n\nconst COMPANY_ENTITY = 'customers:customer_company_profile'\nconst VALID_PASSWORD = 'Valid1!Pass'\n\nfunction titleOf(item: SearchResultItem): string {\n const presenter = item?.presenter\n const title = presenter && typeof presenter === 'object' ? (presenter as { title?: unknown }).title : undefined\n return typeof title === 'string' ? title : ''\n}\n\nasync function searchTitles(request: APIRequestContext, token: string, query: string): Promise<string[]> {\n const params = new URLSearchParams({ q: query, limit: '20', entityTypes: COMPANY_ENTITY })\n const res = await apiRequest(request, 'GET', `/api/search/search?${params.toString()}`, { token })\n if (!res.ok()) return []\n const body = (await readJsonSafe<SearchResponse>(res)) ?? {}\n return (Array.isArray(body.results) ? body.results : []).map(titleOf)\n}\n\n/**\n * TC-SEARCH-004: search results are organization-scoped.\n * Source: issue #2483 (P0 \u2014 cross-tenant/org isolation).\n *\n * A company created in the admin's home org (orgA) must be invisible to a user\n * confined to a second organization (orgB) in the same tenant, while that user\n * still sees a company that lives in their own org. This exercises the\n * organization scope filter the search route applies. orgB, its scoped user, and\n * orgB's company are provisioned via API as superadmin; the test skips if a\n * second organization cannot be provisioned in this environment.\n */\ntest.describe('TC-SEARCH-004: search results are organization-scoped', () => {\n test('a restricted org-B user cannot see org-A companies via search', async ({ request }) => {\n test.slow()\n\n const stamp = Date.now()\n const unique = `QASRCH004${stamp}`\n let adminToken: string | null = null\n let superToken: string | null = null\n let orgBId: string | null = null\n let roleId: string | null = null\n let userBId: string | null = null\n let companyAId: string | null = null\n let companyBId: string | null = null\n const roleName = `qa-search-004-${stamp}`\n const userBEmail = `qa-search-004-${stamp}@acme.com`\n\n try {\n adminToken = await getAuthToken(request, 'admin')\n superToken = await getAuthToken(request, 'superadmin')\n const adminScope = getTokenScope(adminToken)\n\n // Provision a second organization in the admin's tenant (superadmin bypasses\n // the directory create command's tenant-selection enforcement).\n const orgResp = await apiRequest(request, 'POST', '/api/directory/organizations', {\n token: superToken,\n data: { name: `QA Search 004 OrgB ${stamp}`, tenantId: adminScope.tenantId },\n })\n if (orgResp.status() !== 201) {\n test.skip(true, `cannot provision a second organization in this environment (status ${orgResp.status()})`)\n return\n }\n orgBId = expectId((await readJsonSafe<{ id?: string }>(orgResp))?.id, 'organization create returns an id')\n\n // Company A in the admin's home org (orgA).\n companyAId = await createCompanyFixture(request, adminToken, `${unique} A`)\n\n // Company B placed into orgB via the selected-org cookie (superadmin).\n const companyBResp = await apiRequestWithSelectedOrg(request, 'POST', '/api/customers/companies', {\n token: superToken,\n selectedOrgId: orgBId,\n data: { displayName: `${unique} B` },\n })\n expect(companyBResp.status(), 'create company in orgB should return 201').toBe(201)\n companyBId = expectId((await readJsonSafe<{ id?: string }>(companyBResp))?.id, 'company B returns an id')\n\n // A user confined to orgB with search + customers read access.\n roleId = await createRoleFixture(request, adminToken, { name: roleName, tenantId: adminScope.tenantId })\n await setRoleAclFeatures(request, adminToken, { roleId, features: ['search.view', 'customers.*'] })\n userBId = await createUserFixture(request, superToken, {\n email: userBEmail,\n password: VALID_PASSWORD,\n organizationId: orgBId,\n roles: [roleName],\n name: 'QA Search 004 OrgB User',\n })\n await setUserAclVisibility(request, superToken, {\n userId: userBId,\n organizations: [orgBId],\n features: ['search.view', 'customers.*'],\n })\n const userBToken = await getAuthToken(request, userBEmail, VALID_PASSWORD)\n expect(getTokenScope(userBToken).organizationId, 'org-B user is scoped to orgB').toBe(orgBId)\n\n // Admin (orgA) can find company A \u2014 confirms it is indexed and searchable.\n await expect\n .poll(async () => (await searchTitles(request, adminToken!, unique)).includes(`${unique} A`), {\n timeout: 15_000,\n })\n .toBe(true)\n\n // Org-B user can find company B (their own org) \u2014 confirms their search works.\n await expect\n .poll(async () => (await searchTitles(request, userBToken, unique)).includes(`${unique} B`), {\n timeout: 15_000,\n })\n .toBe(true)\n\n // Org-B user must NOT see company A (cross-org isolation \u2014 the P0 assertion).\n const orgBTitles = await searchTitles(request, userBToken, unique)\n expect(orgBTitles, 'org-B user must not see the org-A company').not.toContain(`${unique} A`)\n } finally {\n await deleteEntityIfExists(request, superToken, '/api/customers/companies', companyAId)\n await deleteEntityIfExists(request, superToken, '/api/customers/companies', companyBId)\n await deleteUserIfExists(request, superToken, userBId)\n await deleteRoleIfExists(request, adminToken, roleId)\n await deleteOrganizationIfExists(request, superToken, orgBId)\n }\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAoC;AACrD,SAAS,YAAY,oBAAoB;AACzC,SAAS,UAAU,eAAe,oBAAoB;AACtD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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AA,QAC5F,SAAS;AAAA,MACX,CAAC,EACA,KAAK,IAAI;AAGZ,YAAM,OACH,KAAK,aAAa,MAAM,aAAa,SAAS,YAAY,MAAM,GAAG,SAAS,GAAG,MAAM,IAAI,GAAG;AAAA,QAC3F,SAAS;AAAA,MACX,CAAC,EACA,KAAK,IAAI;AAGZ,YAAM,aAAa,MAAM,aAAa,SAAS,YAAY,MAAM;AACjE,aAAO,YAAY,2CAA2C,EAAE,IAAI,UAAU,GAAG,MAAM,IAAI;AAAA,IAC7F,UAAE;AACA,YAAM,qBAAqB,SAAS,YAAY,4BAA4B,UAAU;AACtF,YAAM,qBAAqB,SAAS,YAAY,4BAA4B,UAAU;AACtF,YAAM,mBAAmB,SAAS,YAAY,OAAO;AACrD,YAAM,mBAAmB,SAAS,YAAY,MAAM;AACpD,YAAM,2BAA2B,SAAS,YAAY,MAAM;AAAA,IAC9D;AAAA,EACF,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,28 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { apiRequest, getAuthToken } from "@open-mercato/core/helpers/integration/api";
3
+ import { readJsonSafe } from "@open-mercato/core/helpers/integration/generalFixtures";
4
+ test.describe("TC-SEARCH-005: search validates the query parameter (400)", () => {
5
+ let token = "";
6
+ test.beforeAll(async ({ request }) => {
7
+ token = await getAuthToken(request, "admin");
8
+ });
9
+ test("missing q returns 400", async ({ request }) => {
10
+ const res = await apiRequest(request, "GET", "/api/search/search", { token });
11
+ expect(res.status()).toBe(400);
12
+ const body = await readJsonSafe(res);
13
+ expect(typeof body?.error, "a 400 response carries an error message").toBe("string");
14
+ });
15
+ test("empty q returns 400", async ({ request }) => {
16
+ const res = await apiRequest(request, "GET", "/api/search/search?q=", { token });
17
+ expect(res.status()).toBe(400);
18
+ });
19
+ test("whitespace-only q returns 400", async ({ request }) => {
20
+ const res = await apiRequest(request, "GET", "/api/search/search?q=%20%20%20", { token });
21
+ expect(res.status()).toBe(400);
22
+ });
23
+ test("non-empty q is accepted with 200 (not rejected as 400)", async ({ request }) => {
24
+ const res = await apiRequest(request, "GET", `/api/search/search?q=qa-search-005-${Date.now()}`, { token });
25
+ expect(res.status(), "a valid query is accepted with 200").toBe(200);
26
+ });
27
+ });
28
+ //# sourceMappingURL=TC-SEARCH-005.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/search/__integration__/TC-SEARCH-005.spec.ts"],
4
+ "sourcesContent": ["import { expect, test } from '@playwright/test'\nimport { apiRequest, getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport { readJsonSafe } from '@open-mercato/core/helpers/integration/generalFixtures'\n\n/**\n * TC-SEARCH-005: Search validates the query parameter (400)\n * Source: issue #2483.\n *\n * Route: GET /api/search/search (requireFeatures ['search.view']). The handler\n * trims `q` and returns 400 { error: 'Missing query' } when it is empty; a\n * non-empty query is accepted with 200 (empty results when no strategy matches),\n * never 400. All cases authenticate as `admin`, which holds search.view, so the\n * empty-query 400 is produced by the handler rather than the framework gate.\n */\ntest.describe('TC-SEARCH-005: search validates the query parameter (400)', () => {\n let token = ''\n\n test.beforeAll(async ({ request }) => {\n token = await getAuthToken(request, 'admin')\n })\n\n test('missing q returns 400', async ({ request }) => {\n const res = await apiRequest(request, 'GET', '/api/search/search', { token })\n expect(res.status()).toBe(400)\n const body = await readJsonSafe<{ error?: string }>(res)\n expect(typeof body?.error, 'a 400 response carries an error message').toBe('string')\n })\n\n test('empty q returns 400', async ({ request }) => {\n const res = await apiRequest(request, 'GET', '/api/search/search?q=', { token })\n expect(res.status()).toBe(400)\n })\n\n test('whitespace-only q returns 400', async ({ request }) => {\n const res = await apiRequest(request, 'GET', '/api/search/search?q=%20%20%20', { token })\n expect(res.status()).toBe(400)\n })\n\n test('non-empty q is accepted with 200 (not rejected as 400)', async ({ request }) => {\n const res = await apiRequest(request, 'GET', `/api/search/search?q=qa-search-005-${Date.now()}`, { token })\n // The route resolves searchService and returns 200 (empty results when no\n // strategy matches); it does not 503 on this path. So a valid query is a 200.\n expect(res.status(), 'a valid query is accepted with 200').toBe(200)\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAY;AAC7B,SAAS,YAAY,oBAAoB;AACzC,SAAS,oBAAoB;AAY7B,KAAK,SAAS,6DAA6D,MAAM;AAC/E,MAAI,QAAQ;AAEZ,OAAK,UAAU,OAAO,EAAE,QAAQ,MAAM;AACpC,YAAQ,MAAM,aAAa,SAAS,OAAO;AAAA,EAC7C,CAAC;AAED,OAAK,yBAAyB,OAAO,EAAE,QAAQ,MAAM;AACnD,UAAM,MAAM,MAAM,WAAW,SAAS,OAAO,sBAAsB,EAAE,MAAM,CAAC;AAC5E,WAAO,IAAI,OAAO,CAAC,EAAE,KAAK,GAAG;AAC7B,UAAM,OAAO,MAAM,aAAiC,GAAG;AACvD,WAAO,OAAO,MAAM,OAAO,yCAAyC,EAAE,KAAK,QAAQ;AAAA,EACrF,CAAC;AAED,OAAK,uBAAuB,OAAO,EAAE,QAAQ,MAAM;AACjD,UAAM,MAAM,MAAM,WAAW,SAAS,OAAO,yBAAyB,EAAE,MAAM,CAAC;AAC/E,WAAO,IAAI,OAAO,CAAC,EAAE,KAAK,GAAG;AAAA,EAC/B,CAAC;AAED,OAAK,iCAAiC,OAAO,EAAE,QAAQ,MAAM;AAC3D,UAAM,MAAM,MAAM,WAAW,SAAS,OAAO,kCAAkC,EAAE,MAAM,CAAC;AACxF,WAAO,IAAI,OAAO,CAAC,EAAE,KAAK,GAAG;AAAA,EAC/B,CAAC;AAED,OAAK,0DAA0D,OAAO,EAAE,QAAQ,MAAM;AACpF,UAAM,MAAM,MAAM,WAAW,SAAS,OAAO,sCAAsC,KAAK,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC;AAG1G,WAAO,IAAI,OAAO,GAAG,oCAAoC,EAAE,KAAK,GAAG;AAAA,EACrE,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,48 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { apiRequest, getAuthToken } from "@open-mercato/core/helpers/integration/api";
3
+ import { readJsonSafe } from "@open-mercato/core/helpers/integration/generalFixtures";
4
+ const DEFAULT_STRATEGIES = ["fulltext", "vector", "tokens"];
5
+ test.describe("TC-SEARCH-006: global search honors saved strategy config over URL override", () => {
6
+ test("persisted enabledStrategies wins over the strategies URL parameter", async ({ request }) => {
7
+ test.slow();
8
+ test.setTimeout(12e4);
9
+ let token = null;
10
+ let originalStrategies = DEFAULT_STRATEGIES;
11
+ try {
12
+ token = await getAuthToken(request, "admin");
13
+ const currentRes = await apiRequest(request, "GET", "/api/search/settings/global-search", { token });
14
+ expect(currentRes.ok(), "GET global-search settings should succeed").toBeTruthy();
15
+ const current = await readJsonSafe(currentRes) ?? {};
16
+ expect(Array.isArray(current.enabledStrategies), "settings expose an enabledStrategies array").toBe(true);
17
+ originalStrategies = Array.isArray(current.enabledStrategies) && current.enabledStrategies.length > 0 ? current.enabledStrategies : DEFAULT_STRATEGIES;
18
+ const updateRes = await apiRequest(request, "POST", "/api/search/settings/global-search", {
19
+ token,
20
+ data: { enabledStrategies: ["tokens"] }
21
+ });
22
+ expect(updateRes.status(), "POST global-search settings should return 200").toBe(200);
23
+ const updated = await readJsonSafe(updateRes) ?? {};
24
+ expect(updated.ok, "update reports ok").toBe(true);
25
+ expect(updated.enabledStrategies, "update echoes the saved strategies").toEqual(["tokens"]);
26
+ const globalRes = await apiRequest(
27
+ request,
28
+ "GET",
29
+ `/api/search/search/global?q=qa-search-006-${Date.now()}&strategies=fulltext,vector`,
30
+ { token }
31
+ );
32
+ expect(globalRes.ok(), "GET global search should succeed").toBeTruthy();
33
+ const globalBody = await readJsonSafe(globalRes) ?? {};
34
+ expect(
35
+ globalBody.strategiesEnabled,
36
+ "global search must use the saved config (tokens), ignoring the strategies URL override"
37
+ ).toEqual(["tokens"]);
38
+ } finally {
39
+ if (token && originalStrategies) {
40
+ await apiRequest(request, "POST", "/api/search/settings/global-search", {
41
+ token,
42
+ data: { enabledStrategies: originalStrategies }
43
+ }).catch(() => void 0);
44
+ }
45
+ }
46
+ });
47
+ });
48
+ //# sourceMappingURL=TC-SEARCH-006.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/search/__integration__/TC-SEARCH-006.spec.ts"],
4
+ "sourcesContent": ["import { expect, test } from '@playwright/test'\nimport { apiRequest, getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport { readJsonSafe } from '@open-mercato/core/helpers/integration/generalFixtures'\n\ntype GlobalSearchSettings = { enabledStrategies?: string[] }\ntype GlobalSearchUpdate = { ok?: boolean; enabledStrategies?: string[] }\ntype GlobalSearchResponse = { strategiesEnabled?: string[] }\n\nconst DEFAULT_STRATEGIES = ['fulltext', 'vector', 'tokens']\n\n/**\n * TC-SEARCH-006: global (Cmd+K) search honors the saved strategy config over a\n * URL override. Source: issue #2483.\n *\n * Routes:\n * - GET/POST /api/search/settings/global-search (POST requires search.manage)\n * - GET /api/search/search/global (ignores any `strategies` URL param)\n *\n * Saves enabledStrategies = ['tokens'], then calls global search with a\n * conflicting ?strategies=fulltext,vector and asserts the response's\n * strategiesEnabled reflects the SAVED config, not the URL. The original config\n * is restored in `finally`. `admin` holds both search.view and search.manage.\n */\ntest.describe('TC-SEARCH-006: global search honors saved strategy config over URL override', () => {\n test('persisted enabledStrategies wins over the strategies URL parameter', async ({ request }) => {\n test.slow()\n test.setTimeout(120_000)\n\n let token: string | null = null\n let originalStrategies: string[] | null = DEFAULT_STRATEGIES\n\n try {\n token = await getAuthToken(request, 'admin')\n\n const currentRes = await apiRequest(request, 'GET', '/api/search/settings/global-search', { token })\n expect(currentRes.ok(), 'GET global-search settings should succeed').toBeTruthy()\n const current = (await readJsonSafe<GlobalSearchSettings>(currentRes)) ?? {}\n expect(Array.isArray(current.enabledStrategies), 'settings expose an enabledStrategies array').toBe(true)\n originalStrategies =\n Array.isArray(current.enabledStrategies) && current.enabledStrategies.length > 0\n ? current.enabledStrategies\n : DEFAULT_STRATEGIES\n\n const updateRes = await apiRequest(request, 'POST', '/api/search/settings/global-search', {\n token,\n data: { enabledStrategies: ['tokens'] },\n })\n expect(updateRes.status(), 'POST global-search settings should return 200').toBe(200)\n const updated = (await readJsonSafe<GlobalSearchUpdate>(updateRes)) ?? {}\n expect(updated.ok, 'update reports ok').toBe(true)\n expect(updated.enabledStrategies, 'update echoes the saved strategies').toEqual(['tokens'])\n\n const globalRes = await apiRequest(\n request,\n 'GET',\n `/api/search/search/global?q=qa-search-006-${Date.now()}&strategies=fulltext,vector`,\n { token },\n )\n expect(globalRes.ok(), 'GET global search should succeed').toBeTruthy()\n const globalBody = (await readJsonSafe<GlobalSearchResponse>(globalRes)) ?? {}\n expect(\n globalBody.strategiesEnabled,\n 'global search must use the saved config (tokens), ignoring the strategies URL override',\n ).toEqual(['tokens'])\n } finally {\n if (token && originalStrategies) {\n await apiRequest(request, 'POST', '/api/search/settings/global-search', {\n token,\n data: { enabledStrategies: originalStrategies },\n }).catch(() => undefined)\n }\n }\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAY;AAC7B,SAAS,YAAY,oBAAoB;AACzC,SAAS,oBAAoB;AAM7B,MAAM,qBAAqB,CAAC,YAAY,UAAU,QAAQ;AAe1D,KAAK,SAAS,+EAA+E,MAAM;AACjG,OAAK,sEAAsE,OAAO,EAAE,QAAQ,MAAM;AAChG,SAAK,KAAK;AACV,SAAK,WAAW,IAAO;AAEvB,QAAI,QAAuB;AAC3B,QAAI,qBAAsC;AAE1C,QAAI;AACF,cAAQ,MAAM,aAAa,SAAS,OAAO;AAE3C,YAAM,aAAa,MAAM,WAAW,SAAS,OAAO,sCAAsC,EAAE,MAAM,CAAC;AACnG,aAAO,WAAW,GAAG,GAAG,2CAA2C,EAAE,WAAW;AAChF,YAAM,UAAW,MAAM,aAAmC,UAAU,KAAM,CAAC;AAC3E,aAAO,MAAM,QAAQ,QAAQ,iBAAiB,GAAG,4CAA4C,EAAE,KAAK,IAAI;AACxG,2BACE,MAAM,QAAQ,QAAQ,iBAAiB,KAAK,QAAQ,kBAAkB,SAAS,IAC3E,QAAQ,oBACR;AAEN,YAAM,YAAY,MAAM,WAAW,SAAS,QAAQ,sCAAsC;AAAA,QACxF;AAAA,QACA,MAAM,EAAE,mBAAmB,CAAC,QAAQ,EAAE;AAAA,MACxC,CAAC;AACD,aAAO,UAAU,OAAO,GAAG,+CAA+C,EAAE,KAAK,GAAG;AACpF,YAAM,UAAW,MAAM,aAAiC,SAAS,KAAM,CAAC;AACxE,aAAO,QAAQ,IAAI,mBAAmB,EAAE,KAAK,IAAI;AACjD,aAAO,QAAQ,mBAAmB,oCAAoC,EAAE,QAAQ,CAAC,QAAQ,CAAC;AAE1F,YAAM,YAAY,MAAM;AAAA,QACtB;AAAA,QACA;AAAA,QACA,6CAA6C,KAAK,IAAI,CAAC;AAAA,QACvD,EAAE,MAAM;AAAA,MACV;AACA,aAAO,UAAU,GAAG,GAAG,kCAAkC,EAAE,WAAW;AACtE,YAAM,aAAc,MAAM,aAAmC,SAAS,KAAM,CAAC;AAC7E;AAAA,QACE,WAAW;AAAA,QACX;AAAA,MACF,EAAE,QAAQ,CAAC,QAAQ,CAAC;AAAA,IACtB,UAAE;AACA,UAAI,SAAS,oBAAoB;AAC/B,cAAM,WAAW,SAAS,QAAQ,sCAAsC;AAAA,UACtE;AAAA,UACA,MAAM,EAAE,mBAAmB,mBAAmB;AAAA,QAChD,CAAC,EAAE,MAAM,MAAM,MAAS;AAAA,MAC1B;AAAA,IACF;AAAA,EACF,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,38 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { apiRequest, getAuthToken } from "@open-mercato/core/helpers/integration/api";
3
+ import { readJsonSafe } from "@open-mercato/core/helpers/integration/generalFixtures";
4
+ const DEFAULT_STRATEGIES = ["fulltext", "vector", "tokens"];
5
+ test.describe("TC-SEARCH-007: concurrent fulltext reindex returns 409 with lock info", () => {
6
+ test("a second reindex while one is active is rejected with 409", async ({ request }) => {
7
+ test.slow();
8
+ test.setTimeout(12e4);
9
+ let token = null;
10
+ try {
11
+ token = await getAuthToken(request, "admin");
12
+ await apiRequest(request, "POST", "/api/search/reindex/cancel", { token }).catch(() => void 0);
13
+ await apiRequest(request, "POST", "/api/search/settings/global-search", {
14
+ token,
15
+ data: { enabledStrategies: DEFAULT_STRATEGIES }
16
+ }).catch(() => void 0);
17
+ const first = await apiRequest(request, "POST", "/api/search/reindex", { token, data: { useQueue: true } });
18
+ expect(first.status(), "first reindex must not hit a pre-existing lock").not.toBe(409);
19
+ expect([200, 503], "first reindex starts (200) or reports backend unavailable (503)").toContain(first.status());
20
+ const settings = await apiRequest(request, "GET", "/api/search/settings", { token });
21
+ expect(settings.ok(), "search settings should be readable after starting reindex").toBeTruthy();
22
+ const settingsBody = await readJsonSafe(settings) ?? {};
23
+ expect(settingsBody.settings?.fulltextReindexLock?.type, "first reindex should leave an observable fulltext lock").toBe("fulltext");
24
+ const second = await apiRequest(request, "POST", "/api/search/reindex", { token, data: { useQueue: true } });
25
+ expect(second.status(), "a concurrent reindex must be rejected with 409").toBe(409);
26
+ const body = await readJsonSafe(second) ?? {};
27
+ expect(body.lock?.type, "the 409 lock descriptor identifies the fulltext lock").toBe("fulltext");
28
+ expect(typeof body.lock?.action, "the lock reports its action").toBe("string");
29
+ expect(typeof body.lock?.startedAt, "the lock reports when it started").toBe("string");
30
+ expect(typeof body.lock?.elapsedMinutes, "the lock reports elapsed minutes").toBe("number");
31
+ } finally {
32
+ if (token) {
33
+ await apiRequest(request, "POST", "/api/search/reindex/cancel", { token }).catch(() => void 0);
34
+ }
35
+ }
36
+ });
37
+ });
38
+ //# sourceMappingURL=TC-SEARCH-007.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/search/__integration__/TC-SEARCH-007.spec.ts"],
4
+ "sourcesContent": ["import { expect, test } from '@playwright/test'\nimport { apiRequest, getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport { readJsonSafe } from '@open-mercato/core/helpers/integration/generalFixtures'\n\ntype ReindexLock = {\n type?: string\n action?: string\n startedAt?: string\n elapsedMinutes?: number\n processedCount?: number | null\n totalCount?: number | null\n}\ntype ConflictBody = { error?: string; lock?: ReindexLock }\ntype SearchSettingsResponse = { settings?: { fulltextReindexLock?: ReindexLock | null } }\n\nconst DEFAULT_STRATEGIES = ['fulltext', 'vector', 'tokens']\n\n/**\n * TC-SEARCH-007: concurrent fulltext reindex returns 409 with lock info.\n * Source: issue #2483.\n *\n * Route: POST /api/search/reindex (requireFeatures ['search.reindex']). The route\n * acquires a per-tenant DB lock BEFORE any indexing work and, in queue mode\n * (useQueue:true \u2014 the default), does NOT release it in `finally` (workers and\n * the heartbeat own it). So a first call holds the lock and a second call returns\n * 409 with the lock descriptor \u2014 independent of whether a fulltext backend is\n * configured, because the lock is taken before the strategy-availability check.\n * Integration specs run serially (workers:1), so no other test contends for the\n * shared lock; it is released in `finally` via the cancel endpoint.\n */\ntest.describe('TC-SEARCH-007: concurrent fulltext reindex returns 409 with lock info', () => {\n test('a second reindex while one is active is rejected with 409', async ({ request }) => {\n test.slow()\n test.setTimeout(120_000)\n\n let token: string | null = null\n\n try {\n token = await getAuthToken(request, 'admin')\n\n // Start from a clean lock state.\n await apiRequest(request, 'POST', '/api/search/reindex/cancel', { token }).catch(() => undefined)\n await apiRequest(request, 'POST', '/api/search/settings/global-search', {\n token,\n data: { enabledStrategies: DEFAULT_STRATEGIES },\n }).catch(() => undefined)\n\n // First reindex acquires (and, in queue mode, holds) the fulltext lock.\n const first = await apiRequest(request, 'POST', '/api/search/reindex', { token, data: { useQueue: true } })\n expect(first.status(), 'first reindex must not hit a pre-existing lock').not.toBe(409)\n expect([200, 503], 'first reindex starts (200) or reports backend unavailable (503)').toContain(first.status())\n\n const settings = await apiRequest(request, 'GET', '/api/search/settings', { token })\n expect(settings.ok(), 'search settings should be readable after starting reindex').toBeTruthy()\n const settingsBody = (await readJsonSafe<SearchSettingsResponse>(settings)) ?? {}\n expect(settingsBody.settings?.fulltextReindexLock?.type, 'first reindex should leave an observable fulltext lock').toBe('fulltext')\n\n // Second reindex is rejected while the first holds the lock.\n const second = await apiRequest(request, 'POST', '/api/search/reindex', { token, data: { useQueue: true } })\n expect(second.status(), 'a concurrent reindex must be rejected with 409').toBe(409)\n const body = (await readJsonSafe<ConflictBody>(second)) ?? {}\n expect(body.lock?.type, 'the 409 lock descriptor identifies the fulltext lock').toBe('fulltext')\n expect(typeof body.lock?.action, 'the lock reports its action').toBe('string')\n expect(typeof body.lock?.startedAt, 'the lock reports when it started').toBe('string')\n expect(typeof body.lock?.elapsedMinutes, 'the lock reports elapsed minutes').toBe('number')\n } finally {\n if (token) {\n await apiRequest(request, 'POST', '/api/search/reindex/cancel', { token }).catch(() => undefined)\n }\n }\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAY;AAC7B,SAAS,YAAY,oBAAoB;AACzC,SAAS,oBAAoB;AAa7B,MAAM,qBAAqB,CAAC,YAAY,UAAU,QAAQ;AAe1D,KAAK,SAAS,yEAAyE,MAAM;AAC3F,OAAK,6DAA6D,OAAO,EAAE,QAAQ,MAAM;AACvF,SAAK,KAAK;AACV,SAAK,WAAW,IAAO;AAEvB,QAAI,QAAuB;AAE3B,QAAI;AACF,cAAQ,MAAM,aAAa,SAAS,OAAO;AAG3C,YAAM,WAAW,SAAS,QAAQ,8BAA8B,EAAE,MAAM,CAAC,EAAE,MAAM,MAAM,MAAS;AAChG,YAAM,WAAW,SAAS,QAAQ,sCAAsC;AAAA,QACtE;AAAA,QACA,MAAM,EAAE,mBAAmB,mBAAmB;AAAA,MAChD,CAAC,EAAE,MAAM,MAAM,MAAS;AAGxB,YAAM,QAAQ,MAAM,WAAW,SAAS,QAAQ,uBAAuB,EAAE,OAAO,MAAM,EAAE,UAAU,KAAK,EAAE,CAAC;AAC1G,aAAO,MAAM,OAAO,GAAG,gDAAgD,EAAE,IAAI,KAAK,GAAG;AACrF,aAAO,CAAC,KAAK,GAAG,GAAG,iEAAiE,EAAE,UAAU,MAAM,OAAO,CAAC;AAE9G,YAAM,WAAW,MAAM,WAAW,SAAS,OAAO,wBAAwB,EAAE,MAAM,CAAC;AACnF,aAAO,SAAS,GAAG,GAAG,2DAA2D,EAAE,WAAW;AAC9F,YAAM,eAAgB,MAAM,aAAqC,QAAQ,KAAM,CAAC;AAChF,aAAO,aAAa,UAAU,qBAAqB,MAAM,wDAAwD,EAAE,KAAK,UAAU;AAGlI,YAAM,SAAS,MAAM,WAAW,SAAS,QAAQ,uBAAuB,EAAE,OAAO,MAAM,EAAE,UAAU,KAAK,EAAE,CAAC;AAC3G,aAAO,OAAO,OAAO,GAAG,gDAAgD,EAAE,KAAK,GAAG;AAClF,YAAM,OAAQ,MAAM,aAA2B,MAAM,KAAM,CAAC;AAC5D,aAAO,KAAK,MAAM,MAAM,sDAAsD,EAAE,KAAK,UAAU;AAC/F,aAAO,OAAO,KAAK,MAAM,QAAQ,6BAA6B,EAAE,KAAK,QAAQ;AAC7E,aAAO,OAAO,KAAK,MAAM,WAAW,kCAAkC,EAAE,KAAK,QAAQ;AACrF,aAAO,OAAO,KAAK,MAAM,gBAAgB,kCAAkC,EAAE,KAAK,QAAQ;AAAA,IAC5F,UAAE;AACA,UAAI,OAAO;AACT,cAAM,WAAW,SAAS,QAAQ,8BAA8B,EAAE,MAAM,CAAC,EAAE,MAAM,MAAM,MAAS;AAAA,MAClG;AAAA,IACF;AAAA,EACF,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,77 @@
1
+ import { expect, test } from "@playwright/test";
2
+ import { apiRequest, getAuthToken } from "@open-mercato/core/helpers/integration/api";
3
+ import { readJsonSafe } from "@open-mercato/core/helpers/integration/generalFixtures";
4
+ import { createCompanyFixture, deleteEntityIfExists } from "@open-mercato/core/helpers/integration/crmFixtures";
5
+ const COMPANY_ENTITY = "customers:customer_company_profile";
6
+ async function getIndex(request, token, params) {
7
+ const qs = new URLSearchParams(params).toString();
8
+ const res = await apiRequest(request, "GET", `/api/search/index${qs ? `?${qs}` : ""}`, { token });
9
+ const body = res.ok() ? await readJsonSafe(res) ?? {} : {};
10
+ return { status: res.status(), body };
11
+ }
12
+ test.describe("TC-SEARCH-008: vector index list pagination & entityId filter", () => {
13
+ test("paginates entries and filters by entityId", async ({ request }) => {
14
+ test.slow();
15
+ let token = null;
16
+ const companyIds = [];
17
+ const stamp = Date.now();
18
+ try {
19
+ token = await getAuthToken(request, "admin");
20
+ const probe = await getIndex(request, token, {});
21
+ if (probe.status !== 200) {
22
+ test.skip(true, `vector index is not listable in this environment (status ${probe.status})`);
23
+ return;
24
+ }
25
+ for (let i = 0; i < 3; i += 1) {
26
+ companyIds.push(await createCompanyFixture(request, token, `QASRCH008-${stamp}-${i}`));
27
+ }
28
+ await apiRequest(request, "POST", "/api/search/embeddings/reindex", {
29
+ token,
30
+ data: { entityId: COMPANY_ENTITY }
31
+ }).catch(() => void 0);
32
+ let entries = [];
33
+ for (let attempt = 0; attempt < 20; attempt += 1) {
34
+ entries = (await getIndex(request, token, {})).body.entries ?? [];
35
+ if (entries.length >= 2) break;
36
+ await new Promise((resolve) => setTimeout(resolve, 1e3));
37
+ }
38
+ if (entries.length < 2) {
39
+ test.skip(true, "vector index did not reach 2 entries; the embedding pipeline does not produce rows here");
40
+ return;
41
+ }
42
+ const base = await getIndex(request, token, {});
43
+ expect(base.body.limit, "default limit is 50").toBe(50);
44
+ expect(base.body.offset, "default offset is 0").toBe(0);
45
+ expect((base.body.entries ?? []).length, "index has at least two entries to page over").toBeGreaterThanOrEqual(2);
46
+ const limited = await getIndex(request, token, { limit: "1", offset: "0" });
47
+ expect(limited.body.limit, "response echoes the requested limit").toBe(1);
48
+ expect(limited.body.entries?.length ?? 0, "limit=1 returns at most one entry").toBeLessThanOrEqual(1);
49
+ const pageOfTwo = await getIndex(request, token, { limit: "2", offset: "0" });
50
+ const twoIds = (pageOfTwo.body.entries ?? []).map((entry) => entry.recordId);
51
+ expect(twoIds.length, "a limit=2 page returns two rows").toBe(2);
52
+ expect(twoIds[0], "each paged entry exposes a recordId").toBeTruthy();
53
+ expect(twoIds[1], "the two paged entries are distinct records").not.toBe(twoIds[0]);
54
+ const page2 = await getIndex(request, token, { limit: "1", offset: "1" });
55
+ expect(page2.body.offset, "response echoes the requested offset").toBe(1);
56
+ const offset0Id = limited.body.entries?.[0]?.recordId;
57
+ const offset1Id = page2.body.entries?.[0]?.recordId;
58
+ expect(offset1Id, "offset=1 returns a record").toBeTruthy();
59
+ expect(offset1Id, "offset=1 returns a different record than offset=0").not.toBe(offset0Id);
60
+ const filtered = await getIndex(request, token, { entityId: COMPANY_ENTITY, limit: "50" });
61
+ expect((filtered.body.entries ?? []).length, "company entityId filter returns at least our fixtures").toBeGreaterThan(
62
+ 0
63
+ );
64
+ for (const entry of filtered.body.entries ?? []) {
65
+ expect(entry.entityId, "entityId filter returns only that entity type").toBe(COMPANY_ENTITY);
66
+ }
67
+ } finally {
68
+ if (token) {
69
+ await apiRequest(request, "POST", "/api/search/embeddings/reindex/cancel", { token }).catch(() => void 0);
70
+ }
71
+ for (const id of companyIds) {
72
+ await deleteEntityIfExists(request, token, "/api/customers/companies", id);
73
+ }
74
+ }
75
+ });
76
+ });
77
+ //# sourceMappingURL=TC-SEARCH-008.spec.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/modules/search/__integration__/TC-SEARCH-008.spec.ts"],
4
+ "sourcesContent": ["import { expect, test, type APIRequestContext } from '@playwright/test'\nimport { apiRequest, getAuthToken } from '@open-mercato/core/helpers/integration/api'\nimport { readJsonSafe } from '@open-mercato/core/helpers/integration/generalFixtures'\nimport { createCompanyFixture, deleteEntityIfExists } from '@open-mercato/core/helpers/integration/crmFixtures'\n\ntype IndexEntry = { entityId?: string; recordId?: string }\ntype IndexResponse = { entries?: IndexEntry[]; limit?: number; offset?: number }\n\nconst COMPANY_ENTITY = 'customers:customer_company_profile'\n\nasync function getIndex(\n request: APIRequestContext,\n token: string,\n params: Record<string, string>,\n): Promise<{ status: number; body: IndexResponse }> {\n const qs = new URLSearchParams(params).toString()\n const res = await apiRequest(request, 'GET', `/api/search/index${qs ? `?${qs}` : ''}`, { token })\n const body = res.ok() ? ((await readJsonSafe<IndexResponse>(res)) ?? {}) : {}\n return { status: res.status(), body }\n}\n\n/**\n * TC-SEARCH-008: vector index list pagination & entityId filter.\n * Source: issue #2483.\n *\n * Route: GET /api/search/index (requireFeatures ['search.view']) returns the\n * vector-store entries (VectorIndexEntry: entityId, recordId, \u2026 \u2014 there is no\n * surrogate `id`) with limit/offset paging and an optional entityId filter.\n * Exercising it requires a working embedding pipeline (a provider key AND an\n * applied embedding config that produces indexed rows). When the index is not\n * listable \u2014 the endpoint returns 503 (vector strategy unavailable) or 500 (no\n * embedding config / vector table) \u2014 this test skips, mirroring how the\n * fulltext-dependent specs skip when Meilisearch is absent. The full pagination\n * contract runs only when the vector index is queryable and rows materialize.\n */\ntest.describe('TC-SEARCH-008: vector index list pagination & entityId filter', () => {\n test('paginates entries and filters by entityId', async ({ request }) => {\n test.slow()\n\n let token: string | null = null\n const companyIds: string[] = []\n const stamp = Date.now()\n\n try {\n token = await getAuthToken(request, 'admin')\n\n // The endpoint must be queryable (200). A 503 (vector strategy unavailable)\n // or 500 (no embedding config / vector table) means the index cannot be\n // paginated in this environment \u2014 skip rather than fail.\n const probe = await getIndex(request, token, {})\n if (probe.status !== 200) {\n test.skip(true, `vector index is not listable in this environment (status ${probe.status})`)\n return\n }\n\n for (let i = 0; i < 3; i += 1) {\n companyIds.push(await createCompanyFixture(request, token, `QASRCH008-${stamp}-${i}`))\n }\n\n // Trigger a (queued) vector reindex and wait for rows to materialize.\n await apiRequest(request, 'POST', '/api/search/embeddings/reindex', {\n token,\n data: { entityId: COMPANY_ENTITY },\n }).catch(() => undefined)\n\n let entries: IndexEntry[] = []\n for (let attempt = 0; attempt < 20; attempt += 1) {\n entries = (await getIndex(request, token, {})).body.entries ?? []\n if (entries.length >= 2) break\n await new Promise((resolve) => setTimeout(resolve, 1_000))\n }\n if (entries.length < 2) {\n test.skip(true, 'vector index did not reach 2 entries; the embedding pipeline does not produce rows here')\n return\n }\n\n // Default paging metadata, with enough rows to page over.\n const base = await getIndex(request, token, {})\n expect(base.body.limit, 'default limit is 50').toBe(50)\n expect(base.body.offset, 'default offset is 0').toBe(0)\n expect((base.body.entries ?? []).length, 'index has at least two entries to page over').toBeGreaterThanOrEqual(2)\n\n // limit caps the page size and is echoed back.\n const limited = await getIndex(request, token, { limit: '1', offset: '0' })\n expect(limited.body.limit, 'response echoes the requested limit').toBe(1)\n expect(limited.body.entries?.length ?? 0, 'limit=1 returns at most one entry').toBeLessThanOrEqual(1)\n\n // A two-row page returns two DISTINCT records \u2014 proves paging yields\n // distinct rows (keyed on recordId, the stable per-record identifier).\n const pageOfTwo = await getIndex(request, token, { limit: '2', offset: '0' })\n const twoIds = (pageOfTwo.body.entries ?? []).map((entry) => entry.recordId)\n expect(twoIds.length, 'a limit=2 page returns two rows').toBe(2)\n expect(twoIds[0], 'each paged entry exposes a recordId').toBeTruthy()\n expect(twoIds[1], 'the two paged entries are distinct records').not.toBe(twoIds[0])\n\n // offset advances the window to a different record and is echoed back.\n const page2 = await getIndex(request, token, { limit: '1', offset: '1' })\n expect(page2.body.offset, 'response echoes the requested offset').toBe(1)\n const offset0Id = limited.body.entries?.[0]?.recordId\n const offset1Id = page2.body.entries?.[0]?.recordId\n expect(offset1Id, 'offset=1 returns a record').toBeTruthy()\n expect(offset1Id, 'offset=1 returns a different record than offset=0').not.toBe(offset0Id)\n\n // entityId filter narrows to the requested entity type (and is non-empty,\n // so the uniformity assertion is not vacuous).\n const filtered = await getIndex(request, token, { entityId: COMPANY_ENTITY, limit: '50' })\n expect((filtered.body.entries ?? []).length, 'company entityId filter returns at least our fixtures').toBeGreaterThan(\n 0,\n )\n for (const entry of filtered.body.entries ?? []) {\n expect(entry.entityId, 'entityId filter returns only that entity type').toBe(COMPANY_ENTITY)\n }\n } finally {\n // Vector reindex acquires a lock that its route does NOT release (workers\n // own it), so explicitly cancel to avoid leaving a lock behind.\n if (token) {\n await apiRequest(request, 'POST', '/api/search/embeddings/reindex/cancel', { token }).catch(() => undefined)\n }\n for (const id of companyIds) {\n await deleteEntityIfExists(request, token, '/api/customers/companies', id)\n }\n }\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,QAAQ,YAAoC;AACrD,SAAS,YAAY,oBAAoB;AACzC,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB,4BAA4B;AAK3D,MAAM,iBAAiB;AAEvB,eAAe,SACb,SACA,OACA,QACkD;AAClD,QAAM,KAAK,IAAI,gBAAgB,MAAM,EAAE,SAAS;AAChD,QAAM,MAAM,MAAM,WAAW,SAAS,OAAO,oBAAoB,KAAK,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,CAAC;AAChG,QAAM,OAAO,IAAI,GAAG,IAAM,MAAM,aAA4B,GAAG,KAAM,CAAC,IAAK,CAAC;AAC5E,SAAO,EAAE,QAAQ,IAAI,OAAO,GAAG,KAAK;AACtC;AAgBA,KAAK,SAAS,iEAAiE,MAAM;AACnF,OAAK,6CAA6C,OAAO,EAAE,QAAQ,MAAM;AACvE,SAAK,KAAK;AAEV,QAAI,QAAuB;AAC3B,UAAM,aAAuB,CAAC;AAC9B,UAAM,QAAQ,KAAK,IAAI;AAEvB,QAAI;AACF,cAAQ,MAAM,aAAa,SAAS,OAAO;AAK3C,YAAM,QAAQ,MAAM,SAAS,SAAS,OAAO,CAAC,CAAC;AAC/C,UAAI,MAAM,WAAW,KAAK;AACxB,aAAK,KAAK,MAAM,4DAA4D,MAAM,MAAM,GAAG;AAC3F;AAAA,MACF;AAEA,eAAS,IAAI,GAAG,IAAI,GAAG,KAAK,GAAG;AAC7B,mBAAW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