comisai 1.0.11 → 1.0.12

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 (247) hide show
  1. package/node_modules/@comis/agent/dist/executor/pi-executor.d.ts +1 -4
  2. package/node_modules/@comis/agent/package.json +1 -1
  3. package/node_modules/@comis/channels/package.json +1 -1
  4. package/node_modules/@comis/cli/package.json +1 -1
  5. package/node_modules/@comis/core/package.json +1 -1
  6. package/node_modules/@comis/daemon/package.json +1 -1
  7. package/node_modules/@comis/gateway/package.json +1 -1
  8. package/node_modules/@comis/infra/package.json +1 -1
  9. package/node_modules/@comis/memory/package.json +1 -1
  10. package/node_modules/@comis/scheduler/package.json +1 -1
  11. package/node_modules/@comis/shared/package.json +1 -1
  12. package/node_modules/@comis/skills/package.json +1 -1
  13. package/package.json +18 -18
  14. package/node_modules/@comis/core/dist/approval/approval-gate.test.d.ts +0 -1
  15. package/node_modules/@comis/core/dist/approval/approval-gate.test.js +0 -1003
  16. package/node_modules/@comis/core/dist/bootstrap.test.d.ts +0 -1
  17. package/node_modules/@comis/core/dist/bootstrap.test.js +0 -150
  18. package/node_modules/@comis/core/dist/config/backup.test.d.ts +0 -1
  19. package/node_modules/@comis/core/dist/config/backup.test.js +0 -160
  20. package/node_modules/@comis/core/dist/config/env-substitution.test.d.ts +0 -1
  21. package/node_modules/@comis/core/dist/config/env-substitution.test.js +0 -259
  22. package/node_modules/@comis/core/dist/config/field-metadata.test.d.ts +0 -1
  23. package/node_modules/@comis/core/dist/config/field-metadata.test.js +0 -72
  24. package/node_modules/@comis/core/dist/config/git-manager.test.d.ts +0 -1
  25. package/node_modules/@comis/core/dist/config/git-manager.test.js +0 -1042
  26. package/node_modules/@comis/core/dist/config/immutable-keys.test.d.ts +0 -1
  27. package/node_modules/@comis/core/dist/config/immutable-keys.test.js +0 -283
  28. package/node_modules/@comis/core/dist/config/include-resolver.test.d.ts +0 -1
  29. package/node_modules/@comis/core/dist/config/include-resolver.test.js +0 -292
  30. package/node_modules/@comis/core/dist/config/layered.test.d.ts +0 -1
  31. package/node_modules/@comis/core/dist/config/layered.test.js +0 -211
  32. package/node_modules/@comis/core/dist/config/loader.test.d.ts +0 -1
  33. package/node_modules/@comis/core/dist/config/loader.test.js +0 -300
  34. package/node_modules/@comis/core/dist/config/migrate.test.d.ts +0 -1
  35. package/node_modules/@comis/core/dist/config/migrate.test.js +0 -244
  36. package/node_modules/@comis/core/dist/config/partial-validator.test.d.ts +0 -1
  37. package/node_modules/@comis/core/dist/config/partial-validator.test.js +0 -98
  38. package/node_modules/@comis/core/dist/config/schema-agent-model.test.d.ts +0 -1
  39. package/node_modules/@comis/core/dist/config/schema-agent-model.test.js +0 -279
  40. package/node_modules/@comis/core/dist/config/schema-agent-session.test.d.ts +0 -1
  41. package/node_modules/@comis/core/dist/config/schema-agent-session.test.js +0 -242
  42. package/node_modules/@comis/core/dist/config/schema-agent.test.d.ts +0 -1
  43. package/node_modules/@comis/core/dist/config/schema-agent.test.js +0 -645
  44. package/node_modules/@comis/core/dist/config/schema-channel.test.d.ts +0 -1
  45. package/node_modules/@comis/core/dist/config/schema-channel.test.js +0 -341
  46. package/node_modules/@comis/core/dist/config/schema-coalescer.test.d.ts +0 -1
  47. package/node_modules/@comis/core/dist/config/schema-coalescer.test.js +0 -51
  48. package/node_modules/@comis/core/dist/config/schema-context-engine.test.d.ts +0 -1
  49. package/node_modules/@comis/core/dist/config/schema-context-engine.test.js +0 -797
  50. package/node_modules/@comis/core/dist/config/schema-context-guard.test.d.ts +0 -1
  51. package/node_modules/@comis/core/dist/config/schema-context-guard.test.js +0 -111
  52. package/node_modules/@comis/core/dist/config/schema-daemon.test.d.ts +0 -1
  53. package/node_modules/@comis/core/dist/config/schema-daemon.test.js +0 -107
  54. package/node_modules/@comis/core/dist/config/schema-delivery-timing.test.d.ts +0 -1
  55. package/node_modules/@comis/core/dist/config/schema-delivery-timing.test.js +0 -51
  56. package/node_modules/@comis/core/dist/config/schema-documentation.test.d.ts +0 -1
  57. package/node_modules/@comis/core/dist/config/schema-documentation.test.js +0 -63
  58. package/node_modules/@comis/core/dist/config/schema-gateway.test.d.ts +0 -1
  59. package/node_modules/@comis/core/dist/config/schema-gateway.test.js +0 -219
  60. package/node_modules/@comis/core/dist/config/schema-gemini-cache.test.d.ts +0 -1
  61. package/node_modules/@comis/core/dist/config/schema-gemini-cache.test.js +0 -41
  62. package/node_modules/@comis/core/dist/config/schema-integrations.test.d.ts +0 -1
  63. package/node_modules/@comis/core/dist/config/schema-integrations.test.js +0 -92
  64. package/node_modules/@comis/core/dist/config/schema-lifecycle-reactions.test.d.ts +0 -1
  65. package/node_modules/@comis/core/dist/config/schema-lifecycle-reactions.test.js +0 -61
  66. package/node_modules/@comis/core/dist/config/schema-misc.test.d.ts +0 -1
  67. package/node_modules/@comis/core/dist/config/schema-misc.test.js +0 -394
  68. package/node_modules/@comis/core/dist/config/schema-observability.test.d.ts +0 -1
  69. package/node_modules/@comis/core/dist/config/schema-observability.test.js +0 -76
  70. package/node_modules/@comis/core/dist/config/schema-providers.test.d.ts +0 -1
  71. package/node_modules/@comis/core/dist/config/schema-providers.test.js +0 -294
  72. package/node_modules/@comis/core/dist/config/schema-queue.test.d.ts +0 -1
  73. package/node_modules/@comis/core/dist/config/schema-queue.test.js +0 -234
  74. package/node_modules/@comis/core/dist/config/schema-response-prefix.test.d.ts +0 -1
  75. package/node_modules/@comis/core/dist/config/schema-response-prefix.test.js +0 -36
  76. package/node_modules/@comis/core/dist/config/schema-security.test.d.ts +0 -1
  77. package/node_modules/@comis/core/dist/config/schema-security.test.js +0 -54
  78. package/node_modules/@comis/core/dist/config/schema-sender-trust-display.test.d.ts +0 -1
  79. package/node_modules/@comis/core/dist/config/schema-sender-trust-display.test.js +0 -60
  80. package/node_modules/@comis/core/dist/config/schema-serializer.test.d.ts +0 -1
  81. package/node_modules/@comis/core/dist/config/schema-serializer.test.js +0 -73
  82. package/node_modules/@comis/core/dist/config/schema-telegram-file-guard.test.d.ts +0 -1
  83. package/node_modules/@comis/core/dist/config/schema-telegram-file-guard.test.js +0 -39
  84. package/node_modules/@comis/core/dist/context/context.test.d.ts +0 -1
  85. package/node_modules/@comis/core/dist/context/context.test.js +0 -276
  86. package/node_modules/@comis/core/dist/domain/agent-response.test.d.ts +0 -1
  87. package/node_modules/@comis/core/dist/domain/agent-response.test.js +0 -159
  88. package/node_modules/@comis/core/dist/domain/credential-mapping.test.d.ts +0 -1
  89. package/node_modules/@comis/core/dist/domain/credential-mapping.test.js +0 -135
  90. package/node_modules/@comis/core/dist/domain/delivery-origin.test.d.ts +0 -1
  91. package/node_modules/@comis/core/dist/domain/delivery-origin.test.js +0 -68
  92. package/node_modules/@comis/core/dist/domain/execution-graph.test.d.ts +0 -1
  93. package/node_modules/@comis/core/dist/domain/execution-graph.test.js +0 -441
  94. package/node_modules/@comis/core/dist/domain/memory-entry.test.d.ts +0 -1
  95. package/node_modules/@comis/core/dist/domain/memory-entry.test.js +0 -193
  96. package/node_modules/@comis/core/dist/domain/normalized-message.test.d.ts +0 -1
  97. package/node_modules/@comis/core/dist/domain/normalized-message.test.js +0 -255
  98. package/node_modules/@comis/core/dist/domain/session-key.test.d.ts +0 -1
  99. package/node_modules/@comis/core/dist/domain/session-key.test.js +0 -291
  100. package/node_modules/@comis/core/dist/domain/subagent-context-config.test.d.ts +0 -1
  101. package/node_modules/@comis/core/dist/domain/subagent-context-config.test.js +0 -131
  102. package/node_modules/@comis/core/dist/domain/subagent-context-types.test.d.ts +0 -1
  103. package/node_modules/@comis/core/dist/domain/subagent-context-types.test.js +0 -182
  104. package/node_modules/@comis/core/dist/event-bus/bus.test.d.ts +0 -1
  105. package/node_modules/@comis/core/dist/event-bus/bus.test.js +0 -152
  106. package/node_modules/@comis/core/dist/event-bus/events-agent.test.d.ts +0 -1
  107. package/node_modules/@comis/core/dist/event-bus/events-agent.test.js +0 -409
  108. package/node_modules/@comis/core/dist/event-bus/events-channel.test.d.ts +0 -1
  109. package/node_modules/@comis/core/dist/event-bus/events-channel.test.js +0 -240
  110. package/node_modules/@comis/core/dist/event-bus/events-infra.test.d.ts +0 -1
  111. package/node_modules/@comis/core/dist/event-bus/events-infra.test.js +0 -416
  112. package/node_modules/@comis/core/dist/event-bus/events-messaging.test.d.ts +0 -1
  113. package/node_modules/@comis/core/dist/event-bus/events-messaging.test.js +0 -433
  114. package/node_modules/@comis/core/dist/event-bus/events.test.d.ts +0 -1
  115. package/node_modules/@comis/core/dist/event-bus/events.test.js +0 -93
  116. package/node_modules/@comis/core/dist/hooks/hook-runner-global.test.d.ts +0 -1
  117. package/node_modules/@comis/core/dist/hooks/hook-runner-global.test.js +0 -29
  118. package/node_modules/@comis/core/dist/hooks/hook-runner.test.d.ts +0 -1
  119. package/node_modules/@comis/core/dist/hooks/hook-runner.test.js +0 -490
  120. package/node_modules/@comis/core/dist/hooks/hook-strategies.test.d.ts +0 -1
  121. package/node_modules/@comis/core/dist/hooks/hook-strategies.test.js +0 -209
  122. package/node_modules/@comis/core/dist/hooks/integration.test.d.ts +0 -1
  123. package/node_modules/@comis/core/dist/hooks/integration.test.js +0 -235
  124. package/node_modules/@comis/core/dist/hooks/plugin-registry.test.d.ts +0 -1
  125. package/node_modules/@comis/core/dist/hooks/plugin-registry.test.js +0 -470
  126. package/node_modules/@comis/core/dist/load-env.test.d.ts +0 -1
  127. package/node_modules/@comis/core/dist/load-env.test.js +0 -21
  128. package/node_modules/@comis/core/dist/security/action-classifier.test.d.ts +0 -1
  129. package/node_modules/@comis/core/dist/security/action-classifier.test.js +0 -298
  130. package/node_modules/@comis/core/dist/security/audit-aggregator.test.d.ts +0 -1
  131. package/node_modules/@comis/core/dist/security/audit-aggregator.test.js +0 -128
  132. package/node_modules/@comis/core/dist/security/audit.test.d.ts +0 -1
  133. package/node_modules/@comis/core/dist/security/audit.test.js +0 -154
  134. package/node_modules/@comis/core/dist/security/canary-token.test.d.ts +0 -1
  135. package/node_modules/@comis/core/dist/security/canary-token.test.js +0 -45
  136. package/node_modules/@comis/core/dist/security/config-redaction.test.d.ts +0 -1
  137. package/node_modules/@comis/core/dist/security/config-redaction.test.js +0 -107
  138. package/node_modules/@comis/core/dist/security/external-content.test.d.ts +0 -1
  139. package/node_modules/@comis/core/dist/security/external-content.test.js +0 -210
  140. package/node_modules/@comis/core/dist/security/injection-patterns.test.d.ts +0 -1
  141. package/node_modules/@comis/core/dist/security/injection-patterns.test.js +0 -213
  142. package/node_modules/@comis/core/dist/security/injection-rate-limiter.test.d.ts +0 -1
  143. package/node_modules/@comis/core/dist/security/injection-rate-limiter.test.js +0 -194
  144. package/node_modules/@comis/core/dist/security/input-guard.test.d.ts +0 -1
  145. package/node_modules/@comis/core/dist/security/input-guard.test.js +0 -215
  146. package/node_modules/@comis/core/dist/security/input-security-guard.test.d.ts +0 -1
  147. package/node_modules/@comis/core/dist/security/input-security-guard.test.js +0 -215
  148. package/node_modules/@comis/core/dist/security/input-validator.test.d.ts +0 -1
  149. package/node_modules/@comis/core/dist/security/input-validator.test.js +0 -133
  150. package/node_modules/@comis/core/dist/security/log-sanitizer.test.d.ts +0 -1
  151. package/node_modules/@comis/core/dist/security/log-sanitizer.test.js +0 -260
  152. package/node_modules/@comis/core/dist/security/memory-write-validator.test.d.ts +0 -1
  153. package/node_modules/@comis/core/dist/security/memory-write-validator.test.js +0 -62
  154. package/node_modules/@comis/core/dist/security/output-guard.test.d.ts +0 -1
  155. package/node_modules/@comis/core/dist/security/output-guard.test.js +0 -397
  156. package/node_modules/@comis/core/dist/security/safe-path.test.d.ts +0 -1
  157. package/node_modules/@comis/core/dist/security/safe-path.test.js +0 -95
  158. package/node_modules/@comis/core/dist/security/scoped-secret-manager.test.d.ts +0 -1
  159. package/node_modules/@comis/core/dist/security/scoped-secret-manager.test.js +0 -231
  160. package/node_modules/@comis/core/dist/security/secret-access.test.d.ts +0 -1
  161. package/node_modules/@comis/core/dist/security/secret-access.test.js +0 -41
  162. package/node_modules/@comis/core/dist/security/secret-crypto.test.d.ts +0 -1
  163. package/node_modules/@comis/core/dist/security/secret-crypto.test.js +0 -113
  164. package/node_modules/@comis/core/dist/security/secret-manager.test.d.ts +0 -1
  165. package/node_modules/@comis/core/dist/security/secret-manager.test.js +0 -394
  166. package/node_modules/@comis/core/dist/security/secret-ref-resolver.test.d.ts +0 -1
  167. package/node_modules/@comis/core/dist/security/secret-ref-resolver.test.js +0 -268
  168. package/node_modules/@comis/core/dist/security/secrets-audit.test.d.ts +0 -10
  169. package/node_modules/@comis/core/dist/security/secrets-audit.test.js +0 -295
  170. package/node_modules/@comis/core/dist/security/ssrf-guard.test.d.ts +0 -1
  171. package/node_modules/@comis/core/dist/security/ssrf-guard.test.js +0 -127
  172. package/node_modules/@comis/core/dist/security/token-generator.test.d.ts +0 -1
  173. package/node_modules/@comis/core/dist/security/token-generator.test.js +0 -35
  174. package/node_modules/@comis/core/dist/tool-metadata.test.d.ts +0 -1
  175. package/node_modules/@comis/core/dist/tool-metadata.test.js +0 -112
  176. package/node_modules/@comis/memory/dist/compaction.test.d.ts +0 -1
  177. package/node_modules/@comis/memory/dist/compaction.test.js +0 -298
  178. package/node_modules/@comis/memory/dist/context-schema.test.d.ts +0 -1
  179. package/node_modules/@comis/memory/dist/context-schema.test.js +0 -246
  180. package/node_modules/@comis/memory/dist/context-store.test.d.ts +0 -1
  181. package/node_modules/@comis/memory/dist/context-store.test.js +0 -708
  182. package/node_modules/@comis/memory/dist/credential-mapping-schema.test.d.ts +0 -7
  183. package/node_modules/@comis/memory/dist/credential-mapping-schema.test.js +0 -73
  184. package/node_modules/@comis/memory/dist/credential-mapping-store.test.d.ts +0 -8
  185. package/node_modules/@comis/memory/dist/credential-mapping-store.test.js +0 -340
  186. package/node_modules/@comis/memory/dist/delivery-mirror-adapter.test.d.ts +0 -1
  187. package/node_modules/@comis/memory/dist/delivery-mirror-adapter.test.js +0 -165
  188. package/node_modules/@comis/memory/dist/delivery-queue-adapter.test.d.ts +0 -1
  189. package/node_modules/@comis/memory/dist/delivery-queue-adapter.test.js +0 -263
  190. package/node_modules/@comis/memory/dist/embedding-batch-indexer.test.d.ts +0 -1
  191. package/node_modules/@comis/memory/dist/embedding-batch-indexer.test.js +0 -202
  192. package/node_modules/@comis/memory/dist/embedding-cache-lru.test.d.ts +0 -1
  193. package/node_modules/@comis/memory/dist/embedding-cache-lru.test.js +0 -241
  194. package/node_modules/@comis/memory/dist/embedding-cache-sqlite.test.d.ts +0 -8
  195. package/node_modules/@comis/memory/dist/embedding-cache-sqlite.test.js +0 -678
  196. package/node_modules/@comis/memory/dist/embedding-cache.test.d.ts +0 -1
  197. package/node_modules/@comis/memory/dist/embedding-cache.test.js +0 -213
  198. package/node_modules/@comis/memory/dist/embedding-fingerprint.test.d.ts +0 -1
  199. package/node_modules/@comis/memory/dist/embedding-fingerprint.test.js +0 -87
  200. package/node_modules/@comis/memory/dist/embedding-hash.test.d.ts +0 -1
  201. package/node_modules/@comis/memory/dist/embedding-hash.test.js +0 -31
  202. package/node_modules/@comis/memory/dist/embedding-integration.test.d.ts +0 -8
  203. package/node_modules/@comis/memory/dist/embedding-integration.test.js +0 -232
  204. package/node_modules/@comis/memory/dist/embedding-provider-factory.test.d.ts +0 -1
  205. package/node_modules/@comis/memory/dist/embedding-provider-factory.test.js +0 -176
  206. package/node_modules/@comis/memory/dist/embedding-provider-local.test.d.ts +0 -8
  207. package/node_modules/@comis/memory/dist/embedding-provider-local.test.js +0 -76
  208. package/node_modules/@comis/memory/dist/embedding-provider-openai.test.d.ts +0 -8
  209. package/node_modules/@comis/memory/dist/embedding-provider-openai.test.js +0 -100
  210. package/node_modules/@comis/memory/dist/embedding-queue.test.d.ts +0 -1
  211. package/node_modules/@comis/memory/dist/embedding-queue.test.js +0 -236
  212. package/node_modules/@comis/memory/dist/hybrid-search.test.d.ts +0 -1
  213. package/node_modules/@comis/memory/dist/hybrid-search.test.js +0 -476
  214. package/node_modules/@comis/memory/dist/identity-link-store.test.d.ts +0 -1
  215. package/node_modules/@comis/memory/dist/identity-link-store.test.js +0 -88
  216. package/node_modules/@comis/memory/dist/memory-api.test.d.ts +0 -1
  217. package/node_modules/@comis/memory/dist/memory-api.test.js +0 -495
  218. package/node_modules/@comis/memory/dist/memory-concurrency.test.d.ts +0 -20
  219. package/node_modules/@comis/memory/dist/memory-concurrency.test.js +0 -222
  220. package/node_modules/@comis/memory/dist/named-graph-store.test.d.ts +0 -1
  221. package/node_modules/@comis/memory/dist/named-graph-store.test.js +0 -227
  222. package/node_modules/@comis/memory/dist/observability-store.test.d.ts +0 -1
  223. package/node_modules/@comis/memory/dist/observability-store.test.js +0 -704
  224. package/node_modules/@comis/memory/dist/row-mapper.test.d.ts +0 -1
  225. package/node_modules/@comis/memory/dist/row-mapper.test.js +0 -409
  226. package/node_modules/@comis/memory/dist/schema.test.d.ts +0 -1
  227. package/node_modules/@comis/memory/dist/schema.test.js +0 -240
  228. package/node_modules/@comis/memory/dist/secret-store-schema.test.d.ts +0 -7
  229. package/node_modules/@comis/memory/dist/secret-store-schema.test.js +0 -90
  230. package/node_modules/@comis/memory/dist/session-store.test.d.ts +0 -1
  231. package/node_modules/@comis/memory/dist/session-store.test.js +0 -262
  232. package/node_modules/@comis/memory/dist/setup-secrets.test.d.ts +0 -1
  233. package/node_modules/@comis/memory/dist/setup-secrets.test.js +0 -140
  234. package/node_modules/@comis/memory/dist/sqlite-memory-adapter.test.d.ts +0 -1
  235. package/node_modules/@comis/memory/dist/sqlite-memory-adapter.test.js +0 -888
  236. package/node_modules/@comis/memory/dist/sqlite-secret-store.test.d.ts +0 -8
  237. package/node_modules/@comis/memory/dist/sqlite-secret-store.test.js +0 -245
  238. package/node_modules/@comis/shared/dist/abort.test.d.ts +0 -1
  239. package/node_modules/@comis/shared/dist/abort.test.js +0 -71
  240. package/node_modules/@comis/shared/dist/result.test.d.ts +0 -1
  241. package/node_modules/@comis/shared/dist/result.test.js +0 -178
  242. package/node_modules/@comis/shared/dist/suppress-error.test.d.ts +0 -1
  243. package/node_modules/@comis/shared/dist/suppress-error.test.js +0 -50
  244. package/node_modules/@comis/shared/dist/timeout.test.d.ts +0 -1
  245. package/node_modules/@comis/shared/dist/timeout.test.js +0 -75
  246. package/node_modules/@comis/shared/dist/ttl-cache.test.d.ts +0 -1
  247. package/node_modules/@comis/shared/dist/ttl-cache.test.js +0 -81
@@ -1,241 +0,0 @@
1
- import { ok, err } from "@comis/shared";
2
- import { describe, it, expect, vi } from "vitest";
3
- import { createCachedEmbeddingPort } from "./embedding-cache-lru.js";
4
- const DIMS = 4;
5
- /** Create a mock EmbeddingPort with vi.fn() methods for call tracking. */
6
- function createMockPort() {
7
- const embedFn = vi.fn(async (text) => {
8
- const vec = new Array(DIMS).fill(0);
9
- for (let i = 0; i < text.length && i < DIMS; i++) {
10
- vec[i] = text.charCodeAt(i) / 256;
11
- }
12
- return ok(vec);
13
- });
14
- const embedBatchFn = vi.fn(async (texts) => {
15
- const vecs = [];
16
- for (const t of texts) {
17
- const vec = new Array(DIMS).fill(0);
18
- for (let i = 0; i < t.length && i < DIMS; i++) {
19
- vec[i] = t.charCodeAt(i) / 256;
20
- }
21
- vecs.push(vec);
22
- }
23
- return ok(vecs);
24
- });
25
- return {
26
- provider: "test",
27
- dimensions: DIMS,
28
- modelId: "test-model",
29
- embed: embedFn,
30
- embedBatch: embedBatchFn,
31
- embedFn,
32
- embedBatchFn,
33
- };
34
- }
35
- describe("createCachedEmbeddingPort", () => {
36
- it("first embed call hits inner, second returns from cache", async () => {
37
- const mock = createMockPort();
38
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
39
- const r1 = await cached.embed("hello");
40
- expect(r1.ok).toBe(true);
41
- expect(mock.embedFn).toHaveBeenCalledTimes(1);
42
- const r2 = await cached.embed("hello");
43
- expect(r2.ok).toBe(true);
44
- // Inner should NOT be called again
45
- expect(mock.embedFn).toHaveBeenCalledTimes(1);
46
- // Both results should be identical
47
- if (r1.ok && r2.ok) {
48
- expect(r1.value).toEqual(r2.value);
49
- }
50
- });
51
- it("embedBatch with mix of cached and uncached only sends misses to inner", async () => {
52
- const mock = createMockPort();
53
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
54
- // Pre-cache "alpha" via single embed
55
- await cached.embed("alpha");
56
- expect(mock.embedFn).toHaveBeenCalledTimes(1);
57
- // Now embedBatch with alpha (cached) + beta (uncached) + gamma (uncached)
58
- const result = await cached.embedBatch(["alpha", "beta", "gamma"]);
59
- expect(result.ok).toBe(true);
60
- // Inner embedBatch should only receive the uncached texts
61
- expect(mock.embedBatchFn).toHaveBeenCalledTimes(1);
62
- expect(mock.embedBatchFn).toHaveBeenCalledWith(["beta", "gamma"]);
63
- // Result should have 3 vectors
64
- if (result.ok) {
65
- expect(result.value).toHaveLength(3);
66
- }
67
- });
68
- it("embedBatch with all cached returns immediately without calling inner", async () => {
69
- const mock = createMockPort();
70
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
71
- // Pre-cache all texts via single embeds
72
- await cached.embed("one");
73
- await cached.embed("two");
74
- mock.embedFn.mockClear();
75
- mock.embedBatchFn.mockClear();
76
- const result = await cached.embedBatch(["one", "two"]);
77
- expect(result.ok).toBe(true);
78
- // Neither embed nor embedBatch should be called
79
- expect(mock.embedFn).not.toHaveBeenCalled();
80
- expect(mock.embedBatchFn).not.toHaveBeenCalled();
81
- if (result.ok) {
82
- expect(result.value).toHaveLength(2);
83
- }
84
- });
85
- it("cache respects maxEntries (oldest evicted)", async () => {
86
- const mock = createMockPort();
87
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 2 });
88
- // Fill cache to max
89
- await cached.embed("first");
90
- await cached.embed("second");
91
- expect(mock.embedFn).toHaveBeenCalledTimes(2);
92
- // Add a third entry, which should evict "first"
93
- await cached.embed("third");
94
- expect(mock.embedFn).toHaveBeenCalledTimes(3);
95
- // "second" and "third" should be cached
96
- mock.embedFn.mockClear();
97
- await cached.embed("second");
98
- await cached.embed("third");
99
- expect(mock.embedFn).not.toHaveBeenCalled();
100
- // "first" should have been evicted -- must call inner again
101
- await cached.embed("first");
102
- expect(mock.embedFn).toHaveBeenCalledTimes(1);
103
- });
104
- it("embed error is not cached", async () => {
105
- const mock = createMockPort();
106
- // Make first call fail
107
- mock.embedFn.mockResolvedValueOnce(err(new Error("provider down")));
108
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
109
- const r1 = await cached.embed("failing");
110
- expect(r1.ok).toBe(false);
111
- expect(mock.embedFn).toHaveBeenCalledTimes(1);
112
- // Now make inner succeed
113
- mock.embedFn.mockResolvedValueOnce(ok([1, 2, 3, 4]));
114
- const r2 = await cached.embed("failing");
115
- expect(r2.ok).toBe(true);
116
- // Inner should be called again since error was not cached
117
- expect(mock.embedFn).toHaveBeenCalledTimes(2);
118
- });
119
- it("preserves dimensions and modelId from inner port", () => {
120
- const mock = createMockPort();
121
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
122
- expect(cached.dimensions).toBe(DIMS);
123
- expect(cached.modelId).toBe("test-model");
124
- });
125
- it("embedBatch propagates inner error", async () => {
126
- const mock = createMockPort();
127
- mock.embedBatchFn.mockResolvedValueOnce(err(new Error("batch failure")));
128
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
129
- const result = await cached.embedBatch(["a", "b"]);
130
- expect(result.ok).toBe(false);
131
- if (!result.ok) {
132
- expect(result.error.message).toBe("batch failure");
133
- }
134
- });
135
- it("dispose() forwards to inner port", async () => {
136
- const mock = createMockPort();
137
- const disposeFn = vi.fn(async () => { });
138
- mock.dispose = disposeFn;
139
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
140
- await cached.dispose();
141
- expect(disposeFn).toHaveBeenCalledTimes(1);
142
- });
143
- it("dispose() handles inner without dispose method", async () => {
144
- const mock = createMockPort();
145
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
146
- // Should not throw when inner has no dispose
147
- await expect(cached.dispose()).resolves.toBeUndefined();
148
- });
149
- it("embedBatch does not rehash texts on cache store (INFRA-08)", async () => {
150
- const mock = createMockPort();
151
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
152
- // First call: all misses, inner called
153
- const result = await cached.embedBatch(["x", "y", "z"]);
154
- expect(result.ok).toBe(true);
155
- if (result.ok)
156
- expect(result.value).toHaveLength(3);
157
- // Second call: all cached, inner NOT called
158
- mock.embedBatchFn.mockClear();
159
- const result2 = await cached.embedBatch(["x", "y", "z"]);
160
- expect(result2.ok).toBe(true);
161
- expect(mock.embedBatchFn).not.toHaveBeenCalled();
162
- });
163
- describe("getCacheStats", () => {
164
- it("returns zeroed stats on fresh cache", () => {
165
- const mock = createMockPort();
166
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
167
- const stats = cached.getCacheStats();
168
- expect(stats).toEqual({
169
- entries: 0,
170
- maxEntries: 100,
171
- hitRate: 0,
172
- hits: 0,
173
- misses: 0,
174
- provider: "test",
175
- });
176
- });
177
- it("tracks miss on first embed and hit on second", async () => {
178
- const mock = createMockPort();
179
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
180
- await cached.embed("hello");
181
- let stats = cached.getCacheStats();
182
- expect(stats.misses).toBe(1);
183
- expect(stats.hits).toBe(0);
184
- expect(stats.entries).toBe(1);
185
- await cached.embed("hello");
186
- stats = cached.getCacheStats();
187
- expect(stats.hits).toBe(1);
188
- expect(stats.misses).toBe(1);
189
- expect(stats.hitRate).toBe(0.5);
190
- expect(stats.entries).toBe(1);
191
- });
192
- it("tracks hits and misses in embedBatch", async () => {
193
- const mock = createMockPort();
194
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
195
- // Pre-cache "alpha"
196
- await cached.embed("alpha");
197
- // stats: 1 miss, 0 hits
198
- // embedBatch with alpha (hit) + beta (miss) + gamma (miss)
199
- await cached.embedBatch(["alpha", "beta", "gamma"]);
200
- const stats = cached.getCacheStats();
201
- // embed: 1 miss
202
- // embedBatch: 1 hit + 2 misses
203
- expect(stats.hits).toBe(1);
204
- expect(stats.misses).toBe(3);
205
- expect(stats.entries).toBe(3);
206
- expect(stats.hitRate).toBe(1 / 4);
207
- });
208
- });
209
- describe("TTL support", () => {
210
- it("expires entries after ttlMs", async () => {
211
- const mock = createMockPort();
212
- const cached = createCachedEmbeddingPort(mock, {
213
- maxEntries: 100,
214
- ttlMs: 100,
215
- });
216
- // First call -- inner called
217
- await cached.embed("hello");
218
- expect(mock.embedFn).toHaveBeenCalledTimes(1);
219
- // Immediate second call -- cache hit, inner NOT called
220
- await cached.embed("hello");
221
- expect(mock.embedFn).toHaveBeenCalledTimes(1);
222
- // Wait for TTL to expire
223
- await new Promise((r) => setTimeout(r, 150));
224
- // After TTL -- inner called again
225
- await cached.embed("hello");
226
- expect(mock.embedFn).toHaveBeenCalledTimes(2);
227
- });
228
- it("entries persist without TTL (LRU only)", async () => {
229
- const mock = createMockPort();
230
- const cached = createCachedEmbeddingPort(mock, { maxEntries: 100 });
231
- // First call -- inner called
232
- await cached.embed("hello");
233
- expect(mock.embedFn).toHaveBeenCalledTimes(1);
234
- // Wait longer than the TTL test above
235
- await new Promise((r) => setTimeout(r, 200));
236
- // Still cached -- inner NOT called (no TTL, pure LRU)
237
- await cached.embed("hello");
238
- expect(mock.embedFn).toHaveBeenCalledTimes(1);
239
- });
240
- });
241
- });
@@ -1,8 +0,0 @@
1
- /**
2
- * Tests for SQLite L2 embedding cache adapter (Phase 513).
3
- *
4
- * Uses in-memory SQLite database with initSchema() to create all tables.
5
- * Verifies DDL, BLOB round-trip, cache hit/miss, UPSERT, composite key
6
- * isolation, embedBatch delegation, and dispose forwarding.
7
- */
8
- export {};