@cachly-dev/mcp-server 0.10.64 → 0.10.66

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 (270) hide show
  1. package/dist/src/handlers/brain.js +1 -1
  2. package/dist/src/index.js +1 -1
  3. package/package.json +7 -1
  4. package/server.json +2 -2
  5. package/.env.test.example +0 -23
  6. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -50
  7. package/.github/ISSUE_TEMPLATE/config.yml +0 -8
  8. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -25
  9. package/.github/workflows/eas-build-android.yml +0 -58
  10. package/.github/workflows/eas-update.yml +0 -55
  11. package/.github/workflows/publish.yml +0 -72
  12. package/BENCH.md +0 -91
  13. package/CHANGELOG.md +0 -604
  14. package/CHANGELOG.md.tmp +0 -0
  15. package/Dockerfile +0 -16
  16. package/LAUNCH_TEXTS.md +0 -182
  17. package/PROGRESS.md +0 -137
  18. package/STRATEGY.md +0 -228
  19. package/VISION_10X.md +0 -133
  20. package/apps/travel-chaos-organizer/.env.example +0 -49
  21. package/apps/travel-chaos-organizer/DEPLOY.md +0 -328
  22. package/apps/travel-chaos-organizer/Makefile +0 -57
  23. package/apps/travel-chaos-organizer/README.md +0 -159
  24. package/apps/travel-chaos-organizer/backend/.env.example +0 -10
  25. package/apps/travel-chaos-organizer/backend/Dockerfile +0 -25
  26. package/apps/travel-chaos-organizer/backend/alembic/env.py +0 -56
  27. package/apps/travel-chaos-organizer/backend/alembic/script.py.mako +0 -24
  28. package/apps/travel-chaos-organizer/backend/alembic/versions/.gitkeep +0 -0
  29. package/apps/travel-chaos-organizer/backend/alembic/versions/0001_stripe_customer_id.py +0 -24
  30. package/apps/travel-chaos-organizer/backend/alembic/versions/0002_telegram_chat_id.py +0 -24
  31. package/apps/travel-chaos-organizer/backend/alembic.ini +0 -39
  32. package/apps/travel-chaos-organizer/backend/app/__init__.py +0 -0
  33. package/apps/travel-chaos-organizer/backend/app/auth/__init__.py +0 -0
  34. package/apps/travel-chaos-organizer/backend/app/auth/keycloak.py +0 -81
  35. package/apps/travel-chaos-organizer/backend/app/config.py +0 -66
  36. package/apps/travel-chaos-organizer/backend/app/db/__init__.py +0 -0
  37. package/apps/travel-chaos-organizer/backend/app/db/database.py +0 -20
  38. package/apps/travel-chaos-organizer/backend/app/db/migrations/001_init.sql +0 -71
  39. package/apps/travel-chaos-organizer/backend/app/db/migrations/002_telemetry_freemium.sql +0 -31
  40. package/apps/travel-chaos-organizer/backend/app/db/migrations/003_telegram_chat_id.sql +0 -4
  41. package/apps/travel-chaos-organizer/backend/app/db/migrations/004_stripe_and_email.sql +0 -5
  42. package/apps/travel-chaos-organizer/backend/app/limiter.py +0 -4
  43. package/apps/travel-chaos-organizer/backend/app/logging_config.py +0 -25
  44. package/apps/travel-chaos-organizer/backend/app/main.py +0 -77
  45. package/apps/travel-chaos-organizer/backend/app/models/__init__.py +0 -0
  46. package/apps/travel-chaos-organizer/backend/app/models/schemas.py +0 -142
  47. package/apps/travel-chaos-organizer/backend/app/routers/__init__.py +0 -0
  48. package/apps/travel-chaos-organizer/backend/app/routers/admin.py +0 -237
  49. package/apps/travel-chaos-organizer/backend/app/routers/cache.py +0 -13
  50. package/apps/travel-chaos-organizer/backend/app/routers/events.py +0 -29
  51. package/apps/travel-chaos-organizer/backend/app/routers/export.py +0 -122
  52. package/apps/travel-chaos-organizer/backend/app/routers/inbox.py +0 -122
  53. package/apps/travel-chaos-organizer/backend/app/routers/items.py +0 -130
  54. package/apps/travel-chaos-organizer/backend/app/routers/mail.py +0 -108
  55. package/apps/travel-chaos-organizer/backend/app/routers/parse.py +0 -303
  56. package/apps/travel-chaos-organizer/backend/app/routers/payments.py +0 -179
  57. package/apps/travel-chaos-organizer/backend/app/routers/trips.py +0 -134
  58. package/apps/travel-chaos-organizer/backend/app/routers/users.py +0 -169
  59. package/apps/travel-chaos-organizer/backend/app/routers/waitlist.py +0 -37
  60. package/apps/travel-chaos-organizer/backend/app/services/__init__.py +0 -0
  61. package/apps/travel-chaos-organizer/backend/app/services/cache.py +0 -131
  62. package/apps/travel-chaos-organizer/backend/app/services/drip.py +0 -128
  63. package/apps/travel-chaos-organizer/backend/app/services/email.py +0 -61
  64. package/apps/travel-chaos-organizer/backend/app/services/errors.py +0 -44
  65. package/apps/travel-chaos-organizer/backend/app/services/notifier.py +0 -10
  66. package/apps/travel-chaos-organizer/backend/app/services/ollama.py +0 -101
  67. package/apps/travel-chaos-organizer/backend/app/services/parser.py +0 -22
  68. package/apps/travel-chaos-organizer/backend/app/services/quota.py +0 -85
  69. package/apps/travel-chaos-organizer/backend/app/services/sentry.py +0 -11
  70. package/apps/travel-chaos-organizer/backend/app/services/telemetry.py +0 -35
  71. package/apps/travel-chaos-organizer/backend/pytest.ini +0 -4
  72. package/apps/travel-chaos-organizer/backend/requirements-dev.txt +0 -6
  73. package/apps/travel-chaos-organizer/backend/requirements.txt +0 -25
  74. package/apps/travel-chaos-organizer/backend/tests/__init__.py +0 -0
  75. package/apps/travel-chaos-organizer/backend/tests/conftest.py +0 -223
  76. package/apps/travel-chaos-organizer/backend/tests/test_admin.py +0 -99
  77. package/apps/travel-chaos-organizer/backend/tests/test_cache.py +0 -142
  78. package/apps/travel-chaos-organizer/backend/tests/test_drip.py +0 -32
  79. package/apps/travel-chaos-organizer/backend/tests/test_e2e_chain.py +0 -121
  80. package/apps/travel-chaos-organizer/backend/tests/test_export.py +0 -48
  81. package/apps/travel-chaos-organizer/backend/tests/test_inbox.py +0 -107
  82. package/apps/travel-chaos-organizer/backend/tests/test_items.py +0 -138
  83. package/apps/travel-chaos-organizer/backend/tests/test_mail.py +0 -113
  84. package/apps/travel-chaos-organizer/backend/tests/test_ollama.py +0 -145
  85. package/apps/travel-chaos-organizer/backend/tests/test_parse_url.py +0 -98
  86. package/apps/travel-chaos-organizer/backend/tests/test_parser.py +0 -72
  87. package/apps/travel-chaos-organizer/backend/tests/test_payments.py +0 -163
  88. package/apps/travel-chaos-organizer/backend/tests/test_quota.py +0 -46
  89. package/apps/travel-chaos-organizer/backend/tests/test_search.py +0 -67
  90. package/apps/travel-chaos-organizer/backend/tests/test_trips.py +0 -123
  91. package/apps/travel-chaos-organizer/backend/tests/test_users.py +0 -52
  92. package/apps/travel-chaos-organizer/backups/.gitkeep +0 -0
  93. package/apps/travel-chaos-organizer/caddy/Caddyfile +0 -27
  94. package/apps/travel-chaos-organizer/docker-compose.node1.yml +0 -31
  95. package/apps/travel-chaos-organizer/docker-compose.override.yml +0 -14
  96. package/apps/travel-chaos-organizer/docker-compose.yml +0 -128
  97. package/apps/travel-chaos-organizer/frontend/.env.example +0 -13
  98. package/apps/travel-chaos-organizer/frontend/app/(app)/_layout.tsx +0 -80
  99. package/apps/travel-chaos-organizer/frontend/app/(app)/inbox.tsx +0 -166
  100. package/apps/travel-chaos-organizer/frontend/app/(app)/search.tsx +0 -130
  101. package/apps/travel-chaos-organizer/frontend/app/(app)/settings.tsx +0 -381
  102. package/apps/travel-chaos-organizer/frontend/app/(app)/trips/[id].tsx +0 -346
  103. package/apps/travel-chaos-organizer/frontend/app/(app)/trips.tsx +0 -363
  104. package/apps/travel-chaos-organizer/frontend/app/(app)/upgrade/cancel.tsx +0 -34
  105. package/apps/travel-chaos-organizer/frontend/app/(app)/upgrade/success.tsx +0 -35
  106. package/apps/travel-chaos-organizer/frontend/app/(auth)/login.tsx +0 -91
  107. package/apps/travel-chaos-organizer/frontend/app/_layout.tsx +0 -71
  108. package/apps/travel-chaos-organizer/frontend/app/auth.tsx +0 -29
  109. package/apps/travel-chaos-organizer/frontend/app/index.tsx +0 -16
  110. package/apps/travel-chaos-organizer/frontend/app/onboarding.tsx +0 -119
  111. package/apps/travel-chaos-organizer/frontend/app.config.ts +0 -54
  112. package/apps/travel-chaos-organizer/frontend/assets/adaptive-icon.svg +0 -66
  113. package/apps/travel-chaos-organizer/frontend/assets/icon.svg +0 -79
  114. package/apps/travel-chaos-organizer/frontend/assets/splash.svg +0 -15
  115. package/apps/travel-chaos-organizer/frontend/components/BottomSheet.tsx +0 -102
  116. package/apps/travel-chaos-organizer/frontend/components/ConfettiCannon.tsx +0 -107
  117. package/apps/travel-chaos-organizer/frontend/components/ConfirmDialog.tsx +0 -109
  118. package/apps/travel-chaos-organizer/frontend/components/ErrorBoundary.tsx +0 -45
  119. package/apps/travel-chaos-organizer/frontend/components/FileUploadButton.tsx +0 -19
  120. package/apps/travel-chaos-organizer/frontend/components/ImportSheet.tsx +0 -155
  121. package/apps/travel-chaos-organizer/frontend/components/OfflineBadge.tsx +0 -55
  122. package/apps/travel-chaos-organizer/frontend/components/QRCodeViewer.tsx +0 -80
  123. package/apps/travel-chaos-organizer/frontend/components/ScoreRing.tsx +0 -39
  124. package/apps/travel-chaos-organizer/frontend/components/Screen.tsx +0 -39
  125. package/apps/travel-chaos-organizer/frontend/components/Skeleton.tsx +0 -70
  126. package/apps/travel-chaos-organizer/frontend/components/SwipeableInboxItem.tsx +0 -121
  127. package/apps/travel-chaos-organizer/frontend/components/SwipeableTimelineItem.tsx +0 -70
  128. package/apps/travel-chaos-organizer/frontend/components/TimelineItem.tsx +0 -73
  129. package/apps/travel-chaos-organizer/frontend/components/TimelineItemDetail.tsx +0 -130
  130. package/apps/travel-chaos-organizer/frontend/components/Toast.tsx +0 -60
  131. package/apps/travel-chaos-organizer/frontend/components/ToastContext.tsx +0 -42
  132. package/apps/travel-chaos-organizer/frontend/components/TripCard.tsx +0 -146
  133. package/apps/travel-chaos-organizer/frontend/components/TripQRModal.tsx +0 -70
  134. package/apps/travel-chaos-organizer/frontend/components/UpgradeBanner.tsx +0 -44
  135. package/apps/travel-chaos-organizer/frontend/eas.json +0 -22
  136. package/apps/travel-chaos-organizer/frontend/hooks/useInbox.ts +0 -24
  137. package/apps/travel-chaos-organizer/frontend/hooks/useNetworkSync.ts +0 -60
  138. package/apps/travel-chaos-organizer/frontend/hooks/useTrips.ts +0 -112
  139. package/apps/travel-chaos-organizer/frontend/lib/api.ts +0 -223
  140. package/apps/travel-chaos-organizer/frontend/lib/auth.ts +0 -93
  141. package/apps/travel-chaos-organizer/frontend/lib/db.ts +0 -86
  142. package/apps/travel-chaos-organizer/frontend/lib/fileCache.ts +0 -54
  143. package/apps/travel-chaos-organizer/frontend/lib/haptics.ts +0 -13
  144. package/apps/travel-chaos-organizer/frontend/lib/notifications.ts +0 -112
  145. package/apps/travel-chaos-organizer/frontend/lib/offlineQueue.ts +0 -145
  146. package/apps/travel-chaos-organizer/frontend/lib/quota.tsx +0 -43
  147. package/apps/travel-chaos-organizer/frontend/lib/sentry.ts +0 -28
  148. package/apps/travel-chaos-organizer/frontend/lib/shareIntent.ts +0 -44
  149. package/apps/travel-chaos-organizer/frontend/package-lock.json +0 -13221
  150. package/apps/travel-chaos-organizer/frontend/package.json +0 -44
  151. package/apps/travel-chaos-organizer/frontend/tsconfig.json +0 -23
  152. package/apps/travel-chaos-organizer/keycloak/realm-export.json +0 -59
  153. package/apps/travel-chaos-organizer/landing/index.html +0 -773
  154. package/apps/travel-chaos-organizer/scripts/backup.sh +0 -14
  155. package/apps/travel-chaos-organizer/scripts/configure-env.sh +0 -82
  156. package/apps/travel-chaos-organizer/scripts/deploy.sh +0 -54
  157. package/apps/travel-chaos-organizer/scripts/health-check.sh +0 -36
  158. package/apps/travel-chaos-organizer/scripts/migrate.sh +0 -7
  159. package/apps/travel-chaos-organizer/scripts/server-setup.sh +0 -85
  160. package/apps/travel-chaos-organizer/scripts/smoke-test.sh +0 -29
  161. package/apps/travel-chaos-organizer/scripts/verify-tracking.sh +0 -71
  162. package/apps/travel-chaos-organizer/telegram-bot/.env.example +0 -3
  163. package/apps/travel-chaos-organizer/telegram-bot/Dockerfile +0 -6
  164. package/apps/travel-chaos-organizer/telegram-bot/bot.py +0 -504
  165. package/apps/travel-chaos-organizer/telegram-bot/requirements.txt +0 -3
  166. package/dist/src/__tests__/auth.test.d.ts +0 -1
  167. package/dist/src/__tests__/auth.test.js +0 -107
  168. package/dist/src/__tests__/auth.test.js.map +0 -1
  169. package/dist/src/__tests__/brain-flow.test.d.ts +0 -12
  170. package/dist/src/__tests__/brain-flow.test.js +0 -1241
  171. package/dist/src/__tests__/brain-flow.test.js.map +0 -1
  172. package/dist/src/__tests__/confidence.test.d.ts +0 -13
  173. package/dist/src/__tests__/confidence.test.js +0 -233
  174. package/dist/src/__tests__/confidence.test.js.map +0 -1
  175. package/dist/src/__tests__/e2e/api-auth.test.d.ts +0 -7
  176. package/dist/src/__tests__/e2e/api-auth.test.js +0 -162
  177. package/dist/src/__tests__/e2e/api-auth.test.js.map +0 -1
  178. package/dist/src/__tests__/e2e/api-health.test.d.ts +0 -7
  179. package/dist/src/__tests__/e2e/api-health.test.js +0 -95
  180. package/dist/src/__tests__/e2e/api-health.test.js.map +0 -1
  181. package/dist/src/__tests__/e2e/cli.test.d.ts +0 -10
  182. package/dist/src/__tests__/e2e/cli.test.js +0 -204
  183. package/dist/src/__tests__/e2e/cli.test.js.map +0 -1
  184. package/dist/src/__tests__/e2e/config.d.ts +0 -35
  185. package/dist/src/__tests__/e2e/config.js +0 -53
  186. package/dist/src/__tests__/e2e/config.js.map +0 -1
  187. package/dist/src/__tests__/e2e/funnel.test.d.ts +0 -13
  188. package/dist/src/__tests__/e2e/funnel.test.js +0 -90
  189. package/dist/src/__tests__/e2e/funnel.test.js.map +0 -1
  190. package/dist/src/__tests__/e2e/mcp-tools.test.d.ts +0 -7
  191. package/dist/src/__tests__/e2e/mcp-tools.test.js +0 -129
  192. package/dist/src/__tests__/e2e/mcp-tools.test.js.map +0 -1
  193. package/dist/src/__tests__/e2e/provisioning.test.d.ts +0 -15
  194. package/dist/src/__tests__/e2e/provisioning.test.js +0 -123
  195. package/dist/src/__tests__/e2e/provisioning.test.js.map +0 -1
  196. package/dist/src/__tests__/handlers-unit.test.d.ts +0 -12
  197. package/dist/src/__tests__/handlers-unit.test.js +0 -505
  198. package/dist/src/__tests__/handlers-unit.test.js.map +0 -1
  199. package/dist/src/__tests__/namespace.test.d.ts +0 -1
  200. package/dist/src/__tests__/namespace.test.js +0 -114
  201. package/dist/src/__tests__/namespace.test.js.map +0 -1
  202. package/dist/src/__tests__/rerank.test.d.ts +0 -1
  203. package/dist/src/__tests__/rerank.test.js +0 -115
  204. package/dist/src/__tests__/rerank.test.js.map +0 -1
  205. package/dist/src/__tests__/utils.test.d.ts +0 -1
  206. package/dist/src/__tests__/utils.test.js +0 -83
  207. package/dist/src/__tests__/utils.test.js.map +0 -1
  208. package/dist/src/bench/cachly-bench.d.ts +0 -35
  209. package/dist/src/bench/cachly-bench.js +0 -182
  210. package/dist/src/bench/cachly-bench.js.map +0 -1
  211. package/dist/src/bench/fixtures.d.ts +0 -37
  212. package/dist/src/bench/fixtures.js +0 -225
  213. package/dist/src/bench/fixtures.js.map +0 -1
  214. package/dist/src/search.test.d.ts +0 -1
  215. package/dist/src/search.test.js +0 -713
  216. package/dist/src/search.test.js.map +0 -1
  217. package/eslint.config.js +0 -16
  218. package/glama.json +0 -36
  219. package/llms.txt +0 -155
  220. package/packages/telegram-notify/SPLIT_PLAN.md +0 -106
  221. package/packages/telegram-notify/client.ts +0 -88
  222. package/packages/telegram-notify/emojis.json +0 -22
  223. package/packages/telegram-notify/pyproject.toml +0 -17
  224. package/packages/telegram-notify/telegram_notify/__init__.py +0 -3
  225. package/packages/telegram-notify/telegram_notify/client.py +0 -87
  226. package/packages/telegram-notify/telegram_notify/emojis.json +0 -22
  227. package/scripts/e2e-run.sh +0 -160
  228. package/scripts/generate-icons.js +0 -28
  229. package/smithery.yaml +0 -45
  230. package/src/__tests__/auth.test.ts +0 -147
  231. package/src/__tests__/brain-flow.test.ts +0 -1472
  232. package/src/__tests__/confidence.test.ts +0 -285
  233. package/src/__tests__/e2e/api-auth.test.ts +0 -182
  234. package/src/__tests__/e2e/api-health.test.ts +0 -103
  235. package/src/__tests__/e2e/cli.test.ts +0 -228
  236. package/src/__tests__/e2e/config.ts +0 -53
  237. package/src/__tests__/e2e/funnel.test.ts +0 -99
  238. package/src/__tests__/e2e/mcp-tools.test.ts +0 -191
  239. package/src/__tests__/e2e/provisioning.test.ts +0 -128
  240. package/src/__tests__/handlers-unit.test.ts +0 -677
  241. package/src/__tests__/namespace.test.ts +0 -126
  242. package/src/__tests__/rerank.test.ts +0 -130
  243. package/src/__tests__/utils.test.ts +0 -81
  244. package/src/auth.ts +0 -46
  245. package/src/bench/cachly-bench.ts +0 -217
  246. package/src/bench/fixtures.ts +0 -256
  247. package/src/ckg.ts +0 -103
  248. package/src/confidence.ts +0 -38
  249. package/src/embeddings.ts +0 -217
  250. package/src/handlers/advanced.ts +0 -647
  251. package/src/handlers/brain.ts +0 -2622
  252. package/src/handlers/cache.ts +0 -633
  253. package/src/handlers/context.ts +0 -222
  254. package/src/handlers/fedbrain.ts +0 -1232
  255. package/src/handlers/instances.ts +0 -180
  256. package/src/handlers/roadmap.ts +0 -201
  257. package/src/handlers/syndicate.ts +0 -460
  258. package/src/handlers/tco.ts +0 -345
  259. package/src/handlers/team.ts +0 -1249
  260. package/src/index.ts +0 -2815
  261. package/src/namespace.ts +0 -128
  262. package/src/notifier.ts +0 -5
  263. package/src/rerank.ts +0 -148
  264. package/src/search.test.ts +0 -848
  265. package/src/search.ts +0 -1781
  266. package/src/tools.ts +0 -2056
  267. package/src/utils.ts +0 -90
  268. package/test-features.cjs +0 -23
  269. package/tsconfig.json +0 -16
  270. package/vitest.config.ts +0 -14
@@ -1,713 +0,0 @@
1
- /**
2
- * Tests for the BM25+ search engine components.
3
- *
4
- * Run: npx vitest run src/search.test.ts
5
- */
6
- import { describe, it, expect } from 'vitest';
7
- import { tokenize, splitMultiQuery, levenshtein, recencyBoost, extractTimestamp, STOPWORDS, katakanaToRomaji, arabicLightStem, expandCrossLingual, CROSS_LINGUAL_MAP } from './index.js';
8
- // ── Tokenizer ─────────────────────────────────────────────────────────────────
9
- describe('tokenize', () => {
10
- it('lowercases and splits on whitespace', () => {
11
- const result = tokenize('Deploy API');
12
- expect(result).toContain('deploy');
13
- expect(result).toContain('api');
14
- });
15
- it('filters English stopwords', () => {
16
- const result = tokenize('the quick brown fox is a dog');
17
- expect(result).not.toContain('the');
18
- expect(result).not.toContain('is');
19
- expect(result).not.toContain('a');
20
- expect(result).toContain('quick');
21
- expect(result).toContain('brown');
22
- expect(result).toContain('fox');
23
- expect(result).toContain('dog');
24
- });
25
- it('filters German stopwords', () => {
26
- const result = tokenize('der schnelle braune Fuchs ist ein Hund');
27
- expect(result).not.toContain('der');
28
- expect(result).not.toContain('ist');
29
- expect(result).not.toContain('ein');
30
- expect(result).toContain('schnelle');
31
- expect(result).toContain('fuchs');
32
- expect(result).toContain('hund');
33
- });
34
- it('filters French stopwords', () => {
35
- const result = tokenize('le chat est sur la table');
36
- expect(result).not.toContain('le');
37
- expect(result).not.toContain('est');
38
- expect(result).not.toContain('sur');
39
- expect(result).not.toContain('la');
40
- expect(result).toContain('chat');
41
- expect(result).toContain('table');
42
- });
43
- it('filters Spanish stopwords', () => {
44
- const result = tokenize('el gato está en la mesa');
45
- expect(result).not.toContain('el');
46
- expect(result).not.toContain('en');
47
- expect(result).not.toContain('la');
48
- expect(result).toContain('gato');
49
- expect(result).toContain('mesa');
50
- });
51
- it('filters Italian stopwords', () => {
52
- const result = tokenize('il gatto è sul tavolo');
53
- expect(result).not.toContain('il');
54
- expect(result).not.toContain('sul');
55
- expect(result).toContain('gatto');
56
- expect(result).toContain('tavolo');
57
- });
58
- it('filters Portuguese stopwords', () => {
59
- const result = tokenize('o gato está na mesa');
60
- expect(result).not.toContain('na');
61
- expect(result).toContain('gato');
62
- expect(result).toContain('mesa');
63
- });
64
- it('removes single-char tokens', () => {
65
- const result = tokenize('a b c deploy');
66
- expect(result).toContain('deploy');
67
- // single chars a, b, c must not appear
68
- expect(result).not.toContain('a');
69
- expect(result).not.toContain('b');
70
- expect(result).not.toContain('c');
71
- });
72
- it('preserves colons and dots in tokens (topic slugs)', () => {
73
- const result = tokenize('deploy:api fix:routing-bug v1.2.3');
74
- expect(result).toContain('deploy:api');
75
- expect(result).toContain('fix:routing-bug');
76
- expect(result).toContain('v1.2.3');
77
- });
78
- it('handles accented characters', () => {
79
- const result = tokenize('résumé café naïve über straße');
80
- expect(result).toContain('résumé');
81
- expect(result).toContain('café');
82
- expect(result).toContain('naïve');
83
- expect(result).toContain('straße');
84
- });
85
- it('returns empty array for all-stopwords input', () => {
86
- expect(tokenize('the is a an')).toEqual([]);
87
- expect(tokenize('der die das ist ein')).toEqual([]);
88
- });
89
- });
90
- // ── Stopwords completeness ────────────────────────────────────────────────────
91
- describe('STOPWORDS', () => {
92
- it('has English equivalents of German stopwords', () => {
93
- // These are conceptual equivalents that should both be present
94
- const pairs = [
95
- ['the', 'der'], ['the', 'die'], ['the', 'das'],
96
- ['and', 'und'], ['or', 'oder'], ['but', 'aber'],
97
- ['is', 'ist'], ['are', 'sind'], ['was', 'war'],
98
- ['have', 'haben'], ['has', 'hat'], ['will', 'wird'],
99
- ['can', 'kann'], ['with', 'mit'], ['for', 'für'],
100
- ['on', 'auf'], ['from', 'von'], ['at', 'bei'],
101
- ['after', 'nach'], ['not', 'nicht'], ['also', 'auch'],
102
- ['how', 'wie'], ['what', 'was'], ['who', 'wer'],
103
- ['where', 'wo'], ['when', 'wann'], ['why', 'warum'],
104
- ['my', 'mein'], ['your', 'dein'], ['his', 'sein'],
105
- ];
106
- for (const [en, de] of pairs) {
107
- expect(STOPWORDS.has(en), `Missing EN: "${en}"`).toBe(true);
108
- expect(STOPWORDS.has(de), `Missing DE: "${de}"`).toBe(true);
109
- }
110
- });
111
- it('contains at least 50 words per major language', () => {
112
- // Sample words unique to each language
113
- const enSample = ['the', 'would', 'could', 'should', 'through', 'between'];
114
- const deSample = ['der', 'werden', 'können', 'zwischen', 'während', 'wegen'];
115
- const frSample = ['le', 'avec', 'dans', 'pour', 'être', 'avoir'];
116
- const esSample = ['el', 'para', 'como', 'pero', 'cuando', 'porque'];
117
- const itSample = ['che', 'sono', 'questo', 'perché', 'ancora', 'sempre'];
118
- const ptSample = ['são', 'fazer', 'estar', 'você', 'também', 'ainda'];
119
- for (const w of [...enSample, ...deSample, ...frSample, ...esSample, ...itSample, ...ptSample]) {
120
- expect(STOPWORDS.has(w), `Missing: "${w}"`).toBe(true);
121
- }
122
- });
123
- });
124
- // ── Multi-Query Splitting ─────────────────────────────────────────────────────
125
- describe('splitMultiQuery', () => {
126
- it('splits numbered lists', () => {
127
- const result = splitMultiQuery('1. deploy API 2. fix routing 3. check auth');
128
- expect(result).toHaveLength(3);
129
- expect(result[0]).toBe('deploy API');
130
- expect(result[1]).toBe('fix routing');
131
- expect(result[2]).toBe('check auth');
132
- });
133
- it('splits semicolons', () => {
134
- const result = splitMultiQuery('deploy API; fix routing; check auth');
135
- expect(result).toHaveLength(3);
136
- expect(result[0]).toBe('deploy API');
137
- });
138
- it('splits "and also"', () => {
139
- const result = splitMultiQuery('deploy API and also fix routing');
140
- expect(result).toHaveLength(2);
141
- });
142
- it('splits "außerdem"', () => {
143
- const result = splitMultiQuery('deploy API außerdem routing fixen');
144
- expect(result).toHaveLength(2);
145
- });
146
- it('splits "de plus" (French)', () => {
147
- const result = splitMultiQuery('déployer API de plus corriger routing');
148
- expect(result).toHaveLength(2);
149
- });
150
- it('splits "además" (Spanish)', () => {
151
- const result = splitMultiQuery('desplegar API además corregir routing');
152
- expect(result).toHaveLength(2);
153
- });
154
- it('splits comma-separated with 3+ items', () => {
155
- const result = splitMultiQuery('deploy, routing, auth, redis');
156
- expect(result).toHaveLength(4);
157
- });
158
- it('keeps single query intact', () => {
159
- expect(splitMultiQuery('deploy API')).toEqual(['deploy API']);
160
- });
161
- it('handles 12 numbered items', () => {
162
- const q = Array.from({ length: 12 }, (_, i) => `${i + 1}. task number ${i + 1}`).join(' ');
163
- const result = splitMultiQuery(q);
164
- expect(result.length).toBe(12);
165
- });
166
- it('filters out too-short fragments from numbered lists', () => {
167
- // With short items filtered (≤2 chars), may not split at all
168
- const result = splitMultiQuery('1. deploy API 2. fix routing 3. ab');
169
- // "ab" is too short, but "deploy API" and "fix routing" should remain
170
- expect(result.length).toBeGreaterThanOrEqual(2);
171
- expect(result[0]).toBe('deploy API');
172
- expect(result[1]).toBe('fix routing');
173
- });
174
- });
175
- // ── Levenshtein Distance ──────────────────────────────────────────────────────
176
- describe('levenshtein', () => {
177
- it('returns 0 for identical strings', () => {
178
- expect(levenshtein('deploy', 'deploy')).toBe(0);
179
- });
180
- it('returns correct distance for single edit', () => {
181
- expect(levenshtein('deploy', 'deploi')).toBe(1); // substitution
182
- expect(levenshtein('deploy', 'deplo')).toBe(1); // deletion
183
- expect(levenshtein('deploy', 'deployy')).toBe(1); // insertion
184
- });
185
- it('returns 2 for two edits', () => {
186
- expect(levenshtein('deploy', 'dploi')).toBe(2);
187
- });
188
- it('returns 3+ for distant strings (early exit)', () => {
189
- expect(levenshtein('deploy', 'abc')).toBeGreaterThanOrEqual(3);
190
- expect(levenshtein('a', 'abcde')).toBeGreaterThanOrEqual(3);
191
- });
192
- it('handles empty strings', () => {
193
- expect(levenshtein('', '')).toBe(0);
194
- expect(levenshtein('abc', '')).toBe(3);
195
- expect(levenshtein('', 'abc')).toBe(3);
196
- });
197
- });
198
- // ── Recency Boost ─────────────────────────────────────────────────────────────
199
- describe('recencyBoost', () => {
200
- it('returns 1.0 for undefined timestamp', () => {
201
- expect(recencyBoost(undefined)).toBe(1.0);
202
- });
203
- it('returns max boost for very recent entries', () => {
204
- const boost = recencyBoost(Date.now());
205
- expect(boost).toBeGreaterThan(1.4);
206
- expect(boost).toBeLessThanOrEqual(1.5);
207
- });
208
- it('decays over time', () => {
209
- const now = Date.now();
210
- const oneDay = recencyBoost(now - 1 * 24 * 60 * 60 * 1000);
211
- const sevenDays = recencyBoost(now - 7 * 24 * 60 * 60 * 1000);
212
- const thirtyDays = recencyBoost(now - 30 * 24 * 60 * 60 * 1000);
213
- expect(oneDay).toBeGreaterThan(sevenDays);
214
- expect(sevenDays).toBeGreaterThan(thirtyDays);
215
- });
216
- it('never goes below 0.5', () => {
217
- const ancient = recencyBoost(Date.now() - 365 * 24 * 60 * 60 * 1000);
218
- expect(ancient).toBeGreaterThanOrEqual(0.5);
219
- });
220
- it('at half-life (7 days), boost is approximately 1.0', () => {
221
- const atHalfLife = recencyBoost(Date.now() - 7 * 24 * 60 * 60 * 1000);
222
- // 0.5^1 + 0.5 = 1.0
223
- expect(atHalfLife).toBeCloseTo(1.0, 1);
224
- });
225
- });
226
- // ── Timestamp Extraction ──────────────────────────────────────────────────────
227
- describe('extractTimestamp', () => {
228
- it('extracts "ts" field from JSON', () => {
229
- const content = '{"topic":"deploy:api","ts":"2026-04-17T12:00:00Z","what_worked":"rsync"}';
230
- const ts = extractTimestamp(content);
231
- expect(ts).toBeDefined();
232
- expect(new Date(ts).getFullYear()).toBe(2026);
233
- });
234
- it('extracts "created" field', () => {
235
- const content = '{"key":"test","created":"2026-01-01T00:00:00Z"}';
236
- expect(extractTimestamp(content)).toBeDefined();
237
- });
238
- it('returns undefined for non-JSON content', () => {
239
- expect(extractTimestamp('just plain text about deploy')).toBeUndefined();
240
- });
241
- it('returns undefined for invalid dates', () => {
242
- expect(extractTimestamp('{"ts":"not-a-date"}')).toBeUndefined();
243
- });
244
- });
245
- // ── Katakana → Romaji ──────────────────────────────────────────────────────────
246
- describe('katakanaToRomaji', () => {
247
- it('converts basic katakana vowels', () => {
248
- expect(katakanaToRomaji('アイウエオ')).toBe('aiueo');
249
- });
250
- it('converts コンテナ (container)', () => {
251
- expect(katakanaToRomaji('コンテナ')).toBe('kontena');
252
- });
253
- it('converts デプロイ (deploy)', () => {
254
- expect(katakanaToRomaji('デプロイ')).toBe('depuroi');
255
- });
256
- it('converts サーバー (server) — long vowel stripped', () => {
257
- const r = katakanaToRomaji('サーバー');
258
- expect(r).toContain('sa');
259
- expect(r).toContain('ba');
260
- });
261
- it('converts digraph チェック (check)', () => {
262
- const r = katakanaToRomaji('チェック');
263
- expect(r).toContain('che');
264
- });
265
- it('converts ファイル (file)', () => {
266
- const r = katakanaToRomaji('ファイル');
267
- expect(r).toContain('fa');
268
- });
269
- it('handles empty string', () => {
270
- expect(katakanaToRomaji('')).toBe('');
271
- });
272
- });
273
- // ── Arabic Light Stemmer ───────────────────────────────────────────────────────
274
- describe('arabicLightStem', () => {
275
- it('strips definite article ال (al-)', () => {
276
- // الخطأ (al-khata = the error) → خطأ (khata)
277
- expect(arabicLightStem('الخطأ')).toBe('خطأ');
278
- });
279
- it('strips و (wa-) prefix from long words', () => {
280
- // وخطأ → خطأ (and error → error)
281
- expect(arabicLightStem('وخطأ')).toBe('خطأ');
282
- });
283
- it('strips ب (bi-) prefix', () => {
284
- expect(arabicLightStem('بسرعة')).toBe('سرعة');
285
- });
286
- it('does not strip from short words (≤3 chars)', () => {
287
- // بلد (3 chars) should not be stripped
288
- expect(arabicLightStem('بلد')).toBe('بلد');
289
- });
290
- it('returns unchanged for Latin input', () => {
291
- expect(arabicLightStem('deploy')).toBe('deploy');
292
- });
293
- });
294
- // ── Cross-lingual Expansion ────────────────────────────────────────────────────
295
- describe('expandCrossLingual', () => {
296
- it('returns Japanese katakana for "deploy"', () => {
297
- const syns = expandCrossLingual('deploy');
298
- expect(syns).toContain('デプロイ');
299
- });
300
- it('returns Chinese for "deploy"', () => {
301
- expect(expandCrossLingual('deploy')).toContain('部署');
302
- });
303
- it('returns Korean for "deploy"', () => {
304
- expect(expandCrossLingual('deploy')).toContain('배포');
305
- });
306
- it('returns English for Japanese デプロイ', () => {
307
- expect(expandCrossLingual('デプロイ')).toContain('deploy');
308
- });
309
- it('returns English for Chinese 部署', () => {
310
- expect(expandCrossLingual('部署')).toContain('deploy');
311
- });
312
- it('returns English for Korean 배포', () => {
313
- expect(expandCrossLingual('배포')).toContain('deploy');
314
- });
315
- it('returns English for Arabic خطأ (error)', () => {
316
- expect(expandCrossLingual('خطأ')).toContain('error');
317
- });
318
- it('returns English for Hebrew שגיאה (error)', () => {
319
- expect(expandCrossLingual('שגיאה')).toContain('error');
320
- });
321
- it('returns empty array for unknown tokens', () => {
322
- expect(expandCrossLingual('foobar')).toEqual([]);
323
- });
324
- it('covers all major languages for "server"', () => {
325
- const syns = expandCrossLingual('server');
326
- expect(syns).toContain('サーバー');
327
- expect(syns).toContain('服务器');
328
- expect(syns).toContain('서버');
329
- });
330
- it('has at least 50 tech terms in the map', () => {
331
- expect(CROSS_LINGUAL_MAP.size).toBeGreaterThanOrEqual(50);
332
- });
333
- });
334
- // ── RTL Tokenization ───────────────────────────────────────────────────────────
335
- describe('tokenize — RTL (Arabic/Hebrew)', () => {
336
- it('tokenizes Arabic text into words', () => {
337
- // "خطأ في النظام" = error in the system
338
- const tokens = tokenize('خطأ في النظام');
339
- expect(tokens.length).toBeGreaterThan(0);
340
- // خطأ = error, not a stopword
341
- const hasError = tokens.some(t => t === 'خطأ' || t === 'error');
342
- expect(hasError).toBe(true);
343
- });
344
- it('strips Arabic definite article via light stemmer', () => {
345
- // النظام → نظام (the system → system)
346
- const tokens = tokenize('النظام');
347
- expect(tokens).toContain('نظام');
348
- });
349
- it('filters Arabic stopwords', () => {
350
- const tokens = tokenize('في على من');
351
- // All three are stopwords
352
- expect(tokens.filter(t => RTL_RE_TEST(t)).length).toBe(0);
353
- });
354
- it('tokenizes Hebrew text', () => {
355
- // שגיאה = error
356
- const tokens = tokenize('שגיאה בשרת');
357
- expect(tokens.length).toBeGreaterThan(0);
358
- const hasErr = tokens.some(t => t === 'שגיאה' || t === 'error');
359
- expect(hasErr).toBe(true);
360
- });
361
- it('handles mixed Arabic + English text', () => {
362
- const tokens = tokenize('deploy خطأ error');
363
- expect(tokens).toContain('deploy');
364
- expect(tokens.some(t => t === 'خطأ' || t === 'error')).toBe(true);
365
- });
366
- });
367
- // Helper: test if a string contains RTL characters
368
- function RTL_RE_TEST(s) {
369
- return /[\u0590-\u05ff\u0600-\u06ff]/.test(s);
370
- }
371
- // ── Cross-lingual Search Integration ──────────────────────────────────────────
372
- describe('tokenize — cross-lingual expansion', () => {
373
- it('English "deploy" expands to Japanese bigrams', () => {
374
- const tokens = tokenize('deploy');
375
- // デプロイ bigrams: デプ, プロ, ロイ
376
- expect(tokens.some(t => t === 'デプ' || t === 'プロ' || t === 'ロイ')).toBe(true);
377
- });
378
- it('Japanese デプロイ expands to include "deploy"', () => {
379
- const tokens = tokenize('デプロイ');
380
- expect(tokens).toContain('deploy');
381
- });
382
- it('Chinese 部署 expands to "deploy"', () => {
383
- const tokens = tokenize('部署');
384
- expect(tokens).toContain('deploy');
385
- });
386
- it('Korean 배포 expands to "deploy"', () => {
387
- const tokens = tokenize('배포');
388
- expect(tokens).toContain('deploy');
389
- });
390
- it('Arabic خطأ expands to "error"', () => {
391
- const tokens = tokenize('خطأ');
392
- expect(tokens).toContain('error');
393
- });
394
- it('Hebrew שגיאה expands to "error"', () => {
395
- const tokens = tokenize('שגיאה');
396
- expect(tokens).toContain('error');
397
- });
398
- it('English "container" expands to all CJK variants', () => {
399
- const tokens = tokenize('container');
400
- // コンテナ bigrams should be present
401
- expect(tokens.some(t => t === 'コン' || t === 'ンテ' || t === 'テナ')).toBe(true);
402
- });
403
- it('katakana コンテナ generates romaji "kontena"', () => {
404
- const tokens = tokenize('コンテナ');
405
- expect(tokens).toContain('kontena');
406
- });
407
- });
408
- // ── Language-specific tokenizer + stemmer tests ───────────────────────────────
409
- describe('multilingual tokenizer', () => {
410
- // Russian
411
- it('Russian: токенизирует слово и стемит суффикс', () => {
412
- const tokens = tokenize('развёртывание сервера');
413
- expect(tokens.some(t => t.startsWith('развёрт') || t === 'deploy' || t === 'deployment')).toBe(true);
414
- });
415
- it('Russian: развёртывание expands to "deploy"', () => {
416
- const tokens = tokenize('развёртывание');
417
- expect(tokens).toContain('deploy');
418
- });
419
- it('Russian: ошибка expands to "error"', () => {
420
- const tokens = tokenize('ошибка');
421
- expect(tokens).toContain('error');
422
- });
423
- // Turkish
424
- it('Turkish: sunucu expands to "server"', () => {
425
- const tokens = tokenize('sunucu');
426
- expect(tokens).toContain('server');
427
- });
428
- it('Turkish: hata expands to "error"', () => {
429
- const tokens = tokenize('hata');
430
- expect(tokens).toContain('error');
431
- });
432
- // Bengali
433
- it('Bengali: tokenizes words with Bengali script', () => {
434
- const tokens = tokenize('সার্ভার ডেটাবেস');
435
- expect(tokens.length).toBeGreaterThan(0);
436
- });
437
- it('Bengali: strips -গুলো plural suffix', () => {
438
- // সার্ভারগুলো → সার্ভার
439
- const tokens = tokenize('সার্ভারগুলো');
440
- expect(tokens.some(t => t.startsWith('\u09b8\u09be\u09b0') || t.length > 0)).toBe(true);
441
- });
442
- // Vietnamese
443
- it('Vietnamese: tokenizes tone-marked words', () => {
444
- const tokens = tokenize('triển khai máy chủ');
445
- expect(tokens.some(t => t === 'tri\u1ec3n' || t === 'khai' || t === 'm\u00e1y' || t === 'ch\u1ee7')).toBe(true);
446
- });
447
- it('Vietnamese: triển khai expands to "deploy"', () => {
448
- const tokens = tokenize('triển khai');
449
- expect(tokens).toContain('deploy');
450
- });
451
- it('Vietnamese: lỗi expands to "error"', () => {
452
- const tokens = tokenize('lỗi');
453
- expect(tokens).toContain('error');
454
- });
455
- it('Vietnamese: stopwords filtered out', () => {
456
- const tokens = tokenize('không tôi và');
457
- expect(tokens).not.toContain('t\u00f4i');
458
- expect(tokens).not.toContain('v\u00e0');
459
- });
460
- // Hindi
461
- it('Hindi: तैनाती expands to "deploy"', () => {
462
- const tokens = tokenize('तैनाती');
463
- expect(tokens).toContain('deploy');
464
- });
465
- it('Hindi: त्रुटि expands to "error"', () => {
466
- const tokens = tokenize('त्रुटि');
467
- expect(tokens).toContain('error');
468
- });
469
- // Farsi
470
- it('Farsi: استقرار expands to "deploy"', () => {
471
- const tokens = tokenize('استقرار');
472
- expect(tokens).toContain('deploy');
473
- });
474
- // camelCase splitting
475
- it('preprocessText splits camelCase', () => {
476
- const tokens = tokenize('deployServer');
477
- expect(tokens).toContain('deploy');
478
- expect(tokens).toContain('server');
479
- });
480
- it('preprocessText splits snake_case', () => {
481
- const tokens = tokenize('my_api_key');
482
- expect(tokens).toContain('api');
483
- expect(tokens).toContain('key');
484
- });
485
- it('preprocessText splits PascalCase HTMLParser', () => {
486
- const tokens = tokenize('HTMLParser');
487
- expect(tokens).toContain('html');
488
- expect(tokens).toContain('parser');
489
- });
490
- // Tech synonyms
491
- it('tech synonym: k8s expands to include kubernetes', () => {
492
- const tokens = tokenize('k8s');
493
- expect(tokens).toContain('kubernetes');
494
- });
495
- it('tech synonym: postgres expands to postgresql', () => {
496
- const tokens = tokenize('postgres');
497
- expect(tokens).toContain('postgresql');
498
- });
499
- });
500
- // ── Prefix-Matching tests ─────────────────────────────────────────────────────
501
- describe('keywordSearch prefix-matching', () => {
502
- it('English "deploy" matches forward entries for 17 languages in cross-lingual map', () => {
503
- const result = CROSS_LINGUAL_MAP.get('deploy');
504
- expect(result).toBeDefined();
505
- // Should include at least Vietnamese, Russian, Turkish entries
506
- expect(result).toContain('triển khai');
507
- expect(result).toContain('развёртывание');
508
- expect(result).toContain('dağıtım');
509
- });
510
- });
511
- // ── tokenize edge cases ───────────────────────────────────────────────────────
512
- describe('tokenize — edge cases', () => {
513
- it('handles pure numbers', () => {
514
- const tokens = tokenize('404 500 200');
515
- // Numbers are preserved as tokens if length > 1
516
- expect(tokens.some(t => /\d/.test(t))).toBe(true);
517
- });
518
- it('handles URLs — strips protocol and splits on slashes', () => {
519
- const tokens = tokenize('https://api.cachly.dev/v1/instances');
520
- expect(tokens.some(t => t.includes('cachly') || t.includes('api') || t.includes('instances'))).toBe(true);
521
- });
522
- it('handles markdown formatting — strips asterisks and backticks', () => {
523
- const tokens = tokenize('**Deploy** the `server` now');
524
- expect(tokens).toContain('deploy');
525
- expect(tokens).toContain('server');
526
- });
527
- it('deduplicates identical tokens (from cross-lingual expansion)', () => {
528
- const tokens = tokenize('deploy deploy');
529
- const counts = {};
530
- for (const t of tokens)
531
- counts[t] = (counts[t] ?? 0) + 1;
532
- // Exact duplicates are deduplicated
533
- expect(counts['deploy'] ?? 0).toBeLessThanOrEqual(2);
534
- });
535
- it('handles very long single words (hashed to bigram)', () => {
536
- const longWord = 'a'.repeat(50);
537
- const tokens = tokenize(longWord);
538
- // Should not crash and should produce at least one token
539
- expect(tokens.length).toBeGreaterThanOrEqual(0);
540
- });
541
- it('handles emoji in text gracefully', () => {
542
- const tokens = tokenize('🚀 deploy 🔥 server');
543
- expect(tokens).toContain('deploy');
544
- expect(tokens).toContain('server');
545
- });
546
- it('handles mixed script in single sentence', () => {
547
- const tokens = tokenize('deploy サーバー to production 서버');
548
- expect(tokens).toContain('deploy');
549
- expect(tokens.some(t => t === 'server' || t.includes('sa') || t.includes('ba'))).toBe(true);
550
- });
551
- });
552
- // ── levenshtein edge cases ────────────────────────────────────────────────────
553
- describe('levenshtein — additional cases', () => {
554
- it('single character strings', () => {
555
- expect(levenshtein('a', 'a')).toBe(0);
556
- expect(levenshtein('a', 'b')).toBe(1);
557
- expect(levenshtein('a', 'ab')).toBe(1);
558
- });
559
- it('symmetric property: d(a,b) === d(b,a)', () => {
560
- const pairs = [
561
- ['deploy', 'deploi'],
562
- ['hello', 'world'],
563
- ['abc', ''],
564
- ['redis', 'reds'],
565
- ];
566
- for (const [a, b] of pairs) {
567
- expect(levenshtein(a, b)).toBe(levenshtein(b, a));
568
- }
569
- });
570
- it('triangle inequality: d(a,c) ≤ d(a,b) + d(b,c)', () => {
571
- const a = 'docker';
572
- const b = 'doker'; // 1 edit from docker
573
- const c = 'dcker'; // 1 edit from docker, 2 from doker
574
- expect(levenshtein(a, c)).toBeLessThanOrEqual(levenshtein(a, b) + levenshtein(b, c));
575
- });
576
- it('common tech term typos are within distance 2', () => {
577
- const typos = [
578
- ['docker', 'docekr'],
579
- ['redis', 'redsi'],
580
- ['nginx', 'nigx'],
581
- ['postgres', 'posgres'],
582
- ];
583
- for (const [correct, typo] of typos) {
584
- expect(levenshtein(correct, typo)).toBeLessThanOrEqual(2);
585
- }
586
- });
587
- });
588
- // ── recencyBoost edge cases ───────────────────────────────────────────────────
589
- describe('recencyBoost — additional cases', () => {
590
- it('returns 1.0 for null/undefined', () => {
591
- expect(recencyBoost(undefined)).toBe(1.0);
592
- expect(recencyBoost(null)).toBe(1.0);
593
- });
594
- it('returns max boost (1.5) for timestamps in the future', () => {
595
- const future = Date.now() + 60_000; // 1 minute ahead
596
- const boost = recencyBoost(future);
597
- expect(boost).toBeCloseTo(1.5, 1);
598
- });
599
- it('boost is consistent for same age', () => {
600
- const ts = Date.now() - 2 * 86400000;
601
- expect(recencyBoost(ts)).toBeCloseTo(recencyBoost(ts), 5);
602
- });
603
- it('boost values bracket correctly for known ages', () => {
604
- const now = Date.now();
605
- const fresh = recencyBoost(now); // 0d
606
- const oneDay = recencyBoost(now - 86400000); // 1d
607
- const fourDay = recencyBoost(now - 4 * 86400000); // 4d
608
- const weekOld = recencyBoost(now - 7 * 86400000); // 7d
609
- const monthOld = recencyBoost(now - 30 * 86400000); // 30d
610
- const yearOld = recencyBoost(now - 365 * 86400000); // 1y
611
- expect(fresh).toBeGreaterThan(1.4);
612
- expect(oneDay).toBeGreaterThan(1.2);
613
- expect(fourDay).toBeGreaterThan(1.0);
614
- expect(weekOld).toBeCloseTo(1.0, 1);
615
- expect(monthOld).toBeLessThan(0.9);
616
- expect(yearOld).toBeGreaterThanOrEqual(0.5);
617
- });
618
- });
619
- // ── extractTimestamp edge cases ───────────────────────────────────────────────
620
- describe('extractTimestamp — additional cases', () => {
621
- it('handles updated_at field', () => {
622
- const content = '{"updated_at":"2026-05-01T10:00:00Z","key":"value"}';
623
- const ts = extractTimestamp(content);
624
- // Should find a valid date (updated_at or fall through to ts)
625
- if (ts) {
626
- expect(new Date(ts).getFullYear()).toBeGreaterThanOrEqual(2026);
627
- }
628
- });
629
- it('extracts from nested JSON objects', () => {
630
- const content = JSON.stringify({ meta: { ts: '2026-03-15T08:00:00Z' }, value: 'test' });
631
- // ts is at top-level via regex so this might not match nested — just no crash
632
- expect(() => extractTimestamp(content)).not.toThrow();
633
- });
634
- it('handles array-valued ts field gracefully', () => {
635
- const content = '{"ts":[1,2,3],"data":"test"}';
636
- expect(() => extractTimestamp(content)).not.toThrow();
637
- });
638
- it('handles partial JSON (truncated)', () => {
639
- const content = '{"ts":"2026-01-01T00:00:00Z","data":"tr';
640
- expect(() => extractTimestamp(content)).not.toThrow();
641
- });
642
- it('returns undefined for plain text with no JSON', () => {
643
- expect(extractTimestamp('just a sentence with no dates')).toBeUndefined();
644
- });
645
- });
646
- // ── splitMultiQuery completeness ──────────────────────────────────────────────
647
- describe('splitMultiQuery — additional splitters', () => {
648
- it('splits "furthermore" (English)', () => {
649
- const r = splitMultiQuery('fix timeout furthermore increase heap');
650
- expect(r.length).toBe(2);
651
- });
652
- it('splits "additionally" (English)', () => {
653
- const r = splitMultiQuery('deploy api additionally update config');
654
- expect(r.length).toBe(2);
655
- });
656
- it('splits "de plus" (French)', () => {
657
- const r = splitMultiQuery('déployer API de plus corriger timeout');
658
- expect(r.length).toBe(2);
659
- });
660
- it('splits "und außerdem" (German)', () => {
661
- const r = splitMultiQuery('API deployen und außerdem Timeout erhöhen');
662
- expect(r.length).toBe(2);
663
- });
664
- it('handles input with only separators gracefully', () => {
665
- const r = splitMultiQuery(';;;');
666
- // Should not crash; may return empty or single element
667
- expect(Array.isArray(r)).toBe(true);
668
- });
669
- it('does not split on comma inside brackets', () => {
670
- // "1 item" shouldn't produce garbage splits
671
- const r = splitMultiQuery('deploy API');
672
- expect(r).toEqual(['deploy API']);
673
- });
674
- it('preserves query with no splitter', () => {
675
- const q = 'find the best way to deploy docker containers';
676
- expect(splitMultiQuery(q)).toEqual([q]);
677
- });
678
- });
679
- // ── CROSS_LINGUAL_MAP completeness ────────────────────────────────────────────
680
- describe('CROSS_LINGUAL_MAP — coverage', () => {
681
- const REQUIRED_EN_TERMS = [
682
- 'deploy', 'error', 'server', 'database', 'container',
683
- 'cache', 'authentication', 'timeout', 'memory', 'network',
684
- ];
685
- it.each(REQUIRED_EN_TERMS)('"%s" has cross-lingual entries', (term) => {
686
- const entries = CROSS_LINGUAL_MAP.get(term);
687
- expect(entries, `"${term}" missing from CROSS_LINGUAL_MAP`).toBeDefined();
688
- expect(entries.length).toBeGreaterThan(0);
689
- });
690
- it('all values are non-empty arrays of strings', () => {
691
- for (const [key, values] of CROSS_LINGUAL_MAP.entries()) {
692
- expect(Array.isArray(values), `Values for "${key}" are not an array`).toBe(true);
693
- for (const v of values) {
694
- expect(typeof v, `Value "${v}" for key "${key}" is not a string`).toBe('string');
695
- expect(v.length, `Empty string in values for "${key}"`).toBeGreaterThan(0);
696
- }
697
- }
698
- });
699
- it('bi-directional entries exist (reverse lookups)', () => {
700
- // For each forward entry, the reverse should also exist
701
- let reverseCount = 0;
702
- for (const [, values] of CROSS_LINGUAL_MAP.entries()) {
703
- for (const v of values) {
704
- if (CROSS_LINGUAL_MAP.has(v)) {
705
- reverseCount++;
706
- }
707
- }
708
- }
709
- // A healthy map has substantial bidirectionality
710
- expect(reverseCount).toBeGreaterThan(20);
711
- });
712
- });
713
- //# sourceMappingURL=search.test.js.map