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,152 +0,0 @@
1
- import { describe, it, expect, vi } from "vitest";
2
- import { TypedEventBus } from "./bus.js";
3
- describe("TypedEventBus", () => {
4
- it("emit triggers on handler with correct payload", () => {
5
- const bus = new TypedEventBus();
6
- const handler = vi.fn();
7
- bus.on("system:shutdown", handler);
8
- bus.emit("system:shutdown", { reason: "test", graceful: true });
9
- expect(handler).toHaveBeenCalledOnce();
10
- expect(handler).toHaveBeenCalledWith({ reason: "test", graceful: true });
11
- });
12
- it("once fires only once", () => {
13
- const bus = new TypedEventBus();
14
- const handler = vi.fn();
15
- bus.once("system:shutdown", handler);
16
- bus.emit("system:shutdown", { reason: "first", graceful: true });
17
- bus.emit("system:shutdown", { reason: "second", graceful: false });
18
- expect(handler).toHaveBeenCalledOnce();
19
- expect(handler).toHaveBeenCalledWith({ reason: "first", graceful: true });
20
- });
21
- it("off removes handler", () => {
22
- const bus = new TypedEventBus();
23
- const handler = vi.fn();
24
- bus.on("config:patched", handler);
25
- bus.off("config:patched", handler);
26
- bus.emit("config:patched", { section: "test", patchedBy: "admin", timestamp: Date.now() });
27
- expect(handler).not.toHaveBeenCalled();
28
- });
29
- it("removeAllListeners works for specific event", () => {
30
- const bus = new TypedEventBus();
31
- const handler1 = vi.fn();
32
- const handler2 = vi.fn();
33
- const otherHandler = vi.fn();
34
- bus.on("system:shutdown", handler1);
35
- bus.on("system:shutdown", handler2);
36
- bus.on("system:error", otherHandler);
37
- bus.removeAllListeners("system:shutdown");
38
- bus.emit("system:shutdown", { reason: "test", graceful: true });
39
- bus.emit("system:error", { error: new Error("test"), source: "unit-test" });
40
- expect(handler1).not.toHaveBeenCalled();
41
- expect(handler2).not.toHaveBeenCalled();
42
- expect(otherHandler).toHaveBeenCalledOnce();
43
- });
44
- it("removeAllListeners without argument removes all", () => {
45
- const bus = new TypedEventBus();
46
- const handler1 = vi.fn();
47
- const handler2 = vi.fn();
48
- bus.on("system:shutdown", handler1);
49
- bus.on("system:error", handler2);
50
- bus.removeAllListeners();
51
- bus.emit("system:shutdown", { reason: "test", graceful: true });
52
- bus.emit("system:error", { error: new Error("test"), source: "unit-test" });
53
- expect(handler1).not.toHaveBeenCalled();
54
- expect(handler2).not.toHaveBeenCalled();
55
- });
56
- it("listenerCount returns correct count", () => {
57
- const bus = new TypedEventBus();
58
- expect(bus.listenerCount("session:created")).toBe(0);
59
- const h1 = vi.fn();
60
- const h2 = vi.fn();
61
- const h3 = vi.fn();
62
- bus.on("session:created", h1);
63
- expect(bus.listenerCount("session:created")).toBe(1);
64
- bus.on("session:created", h2);
65
- bus.on("session:created", h3);
66
- expect(bus.listenerCount("session:created")).toBe(3);
67
- bus.off("session:created", h2);
68
- expect(bus.listenerCount("session:created")).toBe(2);
69
- });
70
- it("multiple handlers all fire for same event", () => {
71
- const bus = new TypedEventBus();
72
- const handler1 = vi.fn();
73
- const handler2 = vi.fn();
74
- const handler3 = vi.fn();
75
- bus.on("system:shutdown", handler1);
76
- bus.on("system:shutdown", handler2);
77
- bus.on("system:shutdown", handler3);
78
- bus.emit("system:shutdown", { reason: "multi", graceful: false });
79
- expect(handler1).toHaveBeenCalledOnce();
80
- expect(handler2).toHaveBeenCalledOnce();
81
- expect(handler3).toHaveBeenCalledOnce();
82
- });
83
- it("handler receives correct typed payload for message:received", () => {
84
- const bus = new TypedEventBus();
85
- const handler = vi.fn();
86
- const sessionKey = {
87
- tenantId: "tenant-1",
88
- userId: "user-1",
89
- channelId: "chan-1",
90
- };
91
- const message = {
92
- id: "550e8400-e29b-41d4-a716-446655440000",
93
- channelId: "chan-1",
94
- channelType: "telegram",
95
- senderId: "user-1",
96
- text: "Hello, world!",
97
- timestamp: Date.now(),
98
- attachments: [],
99
- metadata: {},
100
- };
101
- bus.on("message:received", handler);
102
- bus.emit("message:received", { message, sessionKey });
103
- expect(handler).toHaveBeenCalledWith({ message, sessionKey });
104
- const received = handler.mock.calls[0][0];
105
- expect(received.message.text).toBe("Hello, world!");
106
- expect(received.sessionKey.tenantId).toBe("tenant-1");
107
- });
108
- it("handler receives correct typed payload for audit:event", () => {
109
- const bus = new TypedEventBus();
110
- const handler = vi.fn();
111
- const auditPayload = {
112
- timestamp: Date.now(),
113
- agentId: "agent-1",
114
- tenantId: "tenant-1",
115
- actionType: "tool:execute",
116
- classification: "high-risk",
117
- outcome: "denied",
118
- metadata: { tool: "shell:exec", reason: "sandbox violation" },
119
- };
120
- bus.on("audit:event", handler);
121
- bus.emit("audit:event", auditPayload);
122
- expect(handler).toHaveBeenCalledWith(auditPayload);
123
- const received = handler.mock.calls[0][0];
124
- expect(received.outcome).toBe("denied");
125
- expect(received.metadata?.tool).toBe("shell:exec");
126
- });
127
- it("type safety: @ts-expect-error for wrong payload types", () => {
128
- const bus = new TypedEventBus();
129
- // Correct usage compiles fine
130
- bus.emit("system:shutdown", { reason: "ok", graceful: true });
131
- // @ts-expect-error - missing required "graceful" field
132
- bus.emit("system:shutdown", { reason: "missing-field" });
133
- // @ts-expect-error - wrong type for "graceful" (string instead of boolean)
134
- bus.emit("system:shutdown", { reason: "wrong-type", graceful: "yes" });
135
- // @ts-expect-error - nonexistent event name
136
- bus.emit("nonexistent:event", { foo: "bar" });
137
- });
138
- it("methods return this for chaining", () => {
139
- const bus = new TypedEventBus();
140
- const handler = vi.fn();
141
- const result = bus.on("system:shutdown", handler);
142
- expect(result).toBe(bus);
143
- const result2 = bus.off("system:shutdown", handler);
144
- expect(result2).toBe(bus);
145
- const result3 = bus.once("system:shutdown", handler);
146
- expect(result3).toBe(bus);
147
- const result4 = bus.removeAllListeners("system:shutdown");
148
- expect(result4).toBe(bus);
149
- const result5 = bus.setMaxListeners(20);
150
- expect(result5).toBe(bus);
151
- });
152
- });
@@ -1,409 +0,0 @@
1
- import { describe, it, expect, vi } from "vitest";
2
- import { TypedEventBus } from "./bus.js";
3
- describe("AgentEvents payload structure", () => {
4
- it("skill:loaded delivers skillName, source, timestamp", () => {
5
- const bus = new TypedEventBus();
6
- const handler = vi.fn();
7
- const payload = {
8
- skillName: "greet",
9
- source: "/skills/greet.md",
10
- timestamp: Date.now(),
11
- };
12
- bus.on("skill:loaded", handler);
13
- bus.emit("skill:loaded", payload);
14
- expect(handler).toHaveBeenCalledWith(payload);
15
- const received = handler.mock.calls[0][0];
16
- expect(received.skillName).toBe("greet");
17
- expect(received.source).toBe("/skills/greet.md");
18
- });
19
- it("skill:executed delivers durationMs and success boolean", () => {
20
- const bus = new TypedEventBus();
21
- const handler = vi.fn();
22
- const payload = {
23
- skillName: "summarize",
24
- durationMs: 42,
25
- success: true,
26
- timestamp: Date.now(),
27
- };
28
- bus.on("skill:executed", handler);
29
- bus.emit("skill:executed", payload);
30
- expect(handler).toHaveBeenCalledWith(payload);
31
- const received = handler.mock.calls[0][0];
32
- expect(received.durationMs).toBe(42);
33
- expect(received.success).toBe(true);
34
- });
35
- it("skill:rejected delivers violations string array", () => {
36
- const bus = new TypedEventBus();
37
- const handler = vi.fn();
38
- const payload = {
39
- skillName: "exploit",
40
- reason: "security scan failed",
41
- violations: ["eval() usage", "network access"],
42
- timestamp: Date.now(),
43
- };
44
- bus.on("skill:rejected", handler);
45
- bus.emit("skill:rejected", payload);
46
- expect(handler).toHaveBeenCalledWith(payload);
47
- const received = handler.mock.calls[0][0];
48
- expect(received.violations).toEqual(["eval() usage", "network access"]);
49
- });
50
- it("skill:prompt_invoked delivers invokedBy union", () => {
51
- const bus = new TypedEventBus();
52
- const handler = vi.fn();
53
- for (const invokedBy of ["user", "model"]) {
54
- const payload = {
55
- skillName: "translate",
56
- invokedBy,
57
- args: "--lang=fr",
58
- timestamp: Date.now(),
59
- };
60
- bus.on("skill:prompt_invoked", handler);
61
- bus.emit("skill:prompt_invoked", payload);
62
- bus.removeAllListeners("skill:prompt_invoked");
63
- }
64
- expect(handler).toHaveBeenCalledTimes(2);
65
- expect(handler.mock.calls[0][0].invokedBy).toBe("user");
66
- expect(handler.mock.calls[1][0].invokedBy).toBe("model");
67
- });
68
- it("tool:executed delivers required and optional fields", () => {
69
- const bus = new TypedEventBus();
70
- const handler = vi.fn();
71
- // With all optional fields
72
- const fullPayload = {
73
- toolName: "bash",
74
- durationMs: 350,
75
- success: false,
76
- timestamp: Date.now(),
77
- userId: "user-1",
78
- traceId: "trace-abc",
79
- agentId: "agent-1",
80
- sessionKey: "t1:u1:c1",
81
- params: { command: "ls" },
82
- errorMessage: "Permission denied",
83
- errorKind: "internal",
84
- description: "Test run",
85
- };
86
- bus.on("tool:executed", handler);
87
- bus.emit("tool:executed", fullPayload);
88
- expect(handler).toHaveBeenCalledWith(fullPayload);
89
- const received = handler.mock.calls[0][0];
90
- expect(received.toolName).toBe("bash");
91
- expect(received.success).toBe(false);
92
- expect(received.errorMessage).toBe("Permission denied");
93
- expect(received.errorKind).toBe("internal");
94
- expect(received.userId).toBe("user-1");
95
- expect(received.traceId).toBe("trace-abc");
96
- expect(received.description).toBe("Test run");
97
- // With only required fields
98
- const minPayload = {
99
- toolName: "file_ops",
100
- durationMs: 5,
101
- success: true,
102
- timestamp: Date.now(),
103
- };
104
- bus.emit("tool:executed", minPayload);
105
- expect(handler).toHaveBeenCalledTimes(2);
106
- expect(handler.mock.calls[1][0].errorMessage).toBeUndefined();
107
- });
108
- it("tool:executed delivers truncation metadata fields (Phase 558)", () => {
109
- const bus = new TypedEventBus();
110
- const handler = vi.fn();
111
- // With truncation metadata (per-tool or per-turn budget truncation)
112
- const truncatedPayload = {
113
- toolName: "bash",
114
- durationMs: 150,
115
- success: true,
116
- timestamp: Date.now(),
117
- truncated: true,
118
- fullChars: 500_000,
119
- returnedChars: 200_000,
120
- };
121
- bus.on("tool:executed", handler);
122
- bus.emit("tool:executed", truncatedPayload);
123
- const received = handler.mock.calls[0][0];
124
- expect(received.truncated).toBe(true);
125
- expect(received.fullChars).toBe(500_000);
126
- expect(received.returnedChars).toBe(200_000);
127
- // Without truncation metadata (normal execution)
128
- const normalPayload = {
129
- toolName: "read",
130
- durationMs: 10,
131
- success: true,
132
- timestamp: Date.now(),
133
- };
134
- bus.emit("tool:executed", normalPayload);
135
- expect(handler).toHaveBeenCalledTimes(2);
136
- const normalReceived = handler.mock.calls[1][0];
137
- expect(normalReceived.truncated).toBeUndefined();
138
- expect(normalReceived.fullChars).toBeUndefined();
139
- expect(normalReceived.returnedChars).toBeUndefined();
140
- });
141
- it("tool:started delivers description field", () => {
142
- const bus = new TypedEventBus();
143
- const handler = vi.fn();
144
- const payload = {
145
- toolName: "exec",
146
- toolCallId: "tc-desc",
147
- timestamp: Date.now(),
148
- agentId: "agent-1",
149
- description: "Installing packages",
150
- };
151
- bus.on("tool:started", handler);
152
- bus.emit("tool:started", payload);
153
- expect(handler).toHaveBeenCalledWith(payload);
154
- const received = handler.mock.calls[0][0];
155
- expect(received.description).toBe("Installing packages");
156
- });
157
- it("audit:event delivers outcome union and optional metadata", () => {
158
- const bus = new TypedEventBus();
159
- const handler = vi.fn();
160
- for (const outcome of ["success", "failure", "denied"]) {
161
- const payload = {
162
- timestamp: Date.now(),
163
- agentId: "agent-1",
164
- tenantId: "tenant-1",
165
- actionType: "tool:execute",
166
- classification: "high-risk",
167
- outcome,
168
- metadata: outcome === "denied" ? { reason: "sandbox violation" } : undefined,
169
- };
170
- bus.on("audit:event", handler);
171
- bus.emit("audit:event", payload);
172
- bus.removeAllListeners("audit:event");
173
- }
174
- expect(handler).toHaveBeenCalledTimes(3);
175
- expect(handler.mock.calls[0][0].outcome).toBe("success");
176
- expect(handler.mock.calls[2][0].outcome).toBe("denied");
177
- expect(handler.mock.calls[2][0].metadata).toEqual({ reason: "sandbox violation" });
178
- });
179
- it("observability:token_usage delivers nested tokens and cost objects", () => {
180
- const bus = new TypedEventBus();
181
- const handler = vi.fn();
182
- const payload = {
183
- timestamp: Date.now(),
184
- traceId: "trace-xyz",
185
- agentId: "agent-1",
186
- channelId: "c1",
187
- executionId: "exec-001",
188
- provider: "anthropic",
189
- model: "claude-sonnet-4-20250514",
190
- tokens: { prompt: 1000, completion: 500, total: 1500 },
191
- cost: { input: 0.003, output: 0.015, cacheRead: 0, cacheWrite: 0, total: 0.018 },
192
- latencyMs: 2500,
193
- cacheReadTokens: 0,
194
- cacheWriteTokens: 0,
195
- sessionKey: "test-session",
196
- savedVsUncached: 0,
197
- cacheEligible: true,
198
- };
199
- bus.on("observability:token_usage", handler);
200
- bus.emit("observability:token_usage", payload);
201
- expect(handler).toHaveBeenCalledWith(payload);
202
- const received = handler.mock.calls[0][0];
203
- expect(received.tokens.prompt).toBe(1000);
204
- expect(received.tokens.completion).toBe(500);
205
- expect(received.tokens.total).toBe(1500);
206
- expect(received.cost.input).toBe(0.003);
207
- expect(received.cost.total).toBe(0.018);
208
- });
209
- it("observability:latency delivers operation union", () => {
210
- const bus = new TypedEventBus();
211
- const handler = vi.fn();
212
- for (const operation of ["llm_call", "tool_execution", "memory_search"]) {
213
- const payload = {
214
- operation,
215
- durationMs: 100,
216
- timestamp: Date.now(),
217
- };
218
- bus.on("observability:latency", handler);
219
- bus.emit("observability:latency", payload);
220
- bus.removeAllListeners("observability:latency");
221
- }
222
- expect(handler).toHaveBeenCalledTimes(3);
223
- expect(handler.mock.calls[0][0].operation).toBe("llm_call");
224
- expect(handler.mock.calls[1][0].operation).toBe("tool_execution");
225
- expect(handler.mock.calls[2][0].operation).toBe("memory_search");
226
- });
227
- it("model:fallback_attempt delivers fromProvider/toProvider and attemptNumber", () => {
228
- const bus = new TypedEventBus();
229
- const handler = vi.fn();
230
- const payload = {
231
- fromProvider: "anthropic",
232
- fromModel: "claude-sonnet-4-20250514",
233
- toProvider: "openai",
234
- toModel: "gpt-4",
235
- error: "Rate limit exceeded",
236
- attemptNumber: 2,
237
- timestamp: Date.now(),
238
- };
239
- bus.on("model:fallback_attempt", handler);
240
- bus.emit("model:fallback_attempt", payload);
241
- expect(handler).toHaveBeenCalledWith(payload);
242
- const received = handler.mock.calls[0][0];
243
- expect(received.fromProvider).toBe("anthropic");
244
- expect(received.toProvider).toBe("openai");
245
- expect(received.attemptNumber).toBe(2);
246
- });
247
- it("security:injection_detected delivers source union, patterns array, riskLevel union", () => {
248
- const bus = new TypedEventBus();
249
- const handler = vi.fn();
250
- const payload = {
251
- timestamp: Date.now(),
252
- source: "user_input",
253
- patterns: ["ignore previous instructions", "system prompt override"],
254
- riskLevel: "high",
255
- agentId: "agent-1",
256
- sessionKey: "t1:u1:c1",
257
- traceId: "trace-sec",
258
- };
259
- bus.on("security:injection_detected", handler);
260
- bus.emit("security:injection_detected", payload);
261
- expect(handler).toHaveBeenCalledWith(payload);
262
- const received = handler.mock.calls[0][0];
263
- expect(received.source).toBe("user_input");
264
- expect(received.patterns).toEqual(["ignore previous instructions", "system prompt override"]);
265
- expect(received.riskLevel).toBe("high");
266
- });
267
- it("security:injection_detected accepts workspace_file source", () => {
268
- const bus = new TypedEventBus();
269
- const handler = vi.fn();
270
- const payload = {
271
- timestamp: Date.now(),
272
- source: "workspace_file",
273
- patterns: ["HTML_COMMENT_INJECTION"],
274
- riskLevel: "high",
275
- agentId: "agent-ws",
276
- };
277
- bus.on("security:injection_detected", handler);
278
- bus.emit("security:injection_detected", payload);
279
- expect(handler).toHaveBeenCalledWith(payload);
280
- const received = handler.mock.calls[0][0];
281
- expect(received.source).toBe("workspace_file");
282
- });
283
- it("graph:started delivers graphId, nodeCount, optional label", () => {
284
- const bus = new TypedEventBus();
285
- const handler = vi.fn();
286
- // With label
287
- const fullPayload = {
288
- graphId: "g-001",
289
- label: "My Pipeline",
290
- nodeCount: 5,
291
- timestamp: Date.now(),
292
- };
293
- bus.on("graph:started", handler);
294
- bus.emit("graph:started", fullPayload);
295
- expect(handler).toHaveBeenCalledWith(fullPayload);
296
- const received = handler.mock.calls[0][0];
297
- expect(received.graphId).toBe("g-001");
298
- expect(received.label).toBe("My Pipeline");
299
- expect(received.nodeCount).toBe(5);
300
- // Without label
301
- const minPayload = {
302
- graphId: "g-002",
303
- nodeCount: 1,
304
- timestamp: Date.now(),
305
- };
306
- bus.emit("graph:started", minPayload);
307
- expect(handler).toHaveBeenCalledTimes(2);
308
- expect(handler.mock.calls[1][0].label).toBeUndefined();
309
- });
310
- it("graph:node_updated delivers nodeId, status, optional durationMs and error", () => {
311
- const bus = new TypedEventBus();
312
- const handler = vi.fn();
313
- // Completed case (with durationMs)
314
- const completedPayload = {
315
- graphId: "g-001",
316
- nodeId: "A",
317
- status: "completed",
318
- durationMs: 250,
319
- timestamp: Date.now(),
320
- };
321
- bus.on("graph:node_updated", handler);
322
- bus.emit("graph:node_updated", completedPayload);
323
- expect(handler).toHaveBeenCalledWith(completedPayload);
324
- const received = handler.mock.calls[0][0];
325
- expect(received.nodeId).toBe("A");
326
- expect(received.status).toBe("completed");
327
- expect(received.durationMs).toBe(250);
328
- expect(received.error).toBeUndefined();
329
- // Failed case (with error + durationMs)
330
- const failedPayload = {
331
- graphId: "g-001",
332
- nodeId: "B",
333
- status: "failed",
334
- durationMs: 100,
335
- error: "Execution timeout",
336
- timestamp: Date.now(),
337
- };
338
- bus.emit("graph:node_updated", failedPayload);
339
- expect(handler).toHaveBeenCalledTimes(2);
340
- const failedReceived = handler.mock.calls[1][0];
341
- expect(failedReceived.status).toBe("failed");
342
- expect(failedReceived.error).toBe("Execution timeout");
343
- expect(failedReceived.durationMs).toBe(100);
344
- });
345
- it("graph:completed delivers status, durationMs, and node count breakdown", () => {
346
- const bus = new TypedEventBus();
347
- const handler = vi.fn();
348
- const payload = {
349
- graphId: "g-001",
350
- status: "completed",
351
- durationMs: 5000,
352
- nodeCount: 4,
353
- nodesCompleted: 3,
354
- nodesFailed: 0,
355
- nodesSkipped: 1,
356
- timestamp: Date.now(),
357
- };
358
- bus.on("graph:completed", handler);
359
- bus.emit("graph:completed", payload);
360
- expect(handler).toHaveBeenCalledWith(payload);
361
- const received = handler.mock.calls[0][0];
362
- expect(received.graphId).toBe("g-001");
363
- expect(received.status).toBe("completed");
364
- expect(received.durationMs).toBe(5000);
365
- expect(received.nodeCount).toBe(4);
366
- expect(received.nodesCompleted).toBe(3);
367
- expect(received.nodesFailed).toBe(0);
368
- expect(received.nodesSkipped).toBe(1);
369
- });
370
- it("type safety: @ts-expect-error for missing required fields", () => {
371
- const bus = new TypedEventBus();
372
- // @ts-expect-error - missing success in skill:executed
373
- bus.emit("skill:executed", { skillName: "x", durationMs: 10, timestamp: 1 });
374
- // @ts-expect-error - missing tokens, sessionKey, savedVsUncached, cacheEligible, cacheReadTokens, cacheWriteTokens
375
- bus.emit("observability:token_usage", {
376
- timestamp: 1, traceId: "t", agentId: "a", channelId: "c",
377
- executionId: "e", provider: "p", model: "m",
378
- cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 }, latencyMs: 0,
379
- });
380
- });
381
- it("provider:degraded delivers provider, failingAgents, timestamp", () => {
382
- const bus = new TypedEventBus();
383
- const handler = vi.fn();
384
- const payload = {
385
- provider: "anthropic",
386
- failingAgents: 2,
387
- timestamp: Date.now(),
388
- };
389
- bus.on("provider:degraded", handler);
390
- bus.emit("provider:degraded", payload);
391
- expect(handler).toHaveBeenCalledWith(payload);
392
- const received = handler.mock.calls[0][0];
393
- expect(received.provider).toBe("anthropic");
394
- expect(received.failingAgents).toBe(2);
395
- });
396
- it("provider:recovered delivers provider, timestamp", () => {
397
- const bus = new TypedEventBus();
398
- const handler = vi.fn();
399
- const payload = {
400
- provider: "anthropic",
401
- timestamp: Date.now(),
402
- };
403
- bus.on("provider:recovered", handler);
404
- bus.emit("provider:recovered", payload);
405
- expect(handler).toHaveBeenCalledWith(payload);
406
- const received = handler.mock.calls[0][0];
407
- expect(received.provider).toBe("anthropic");
408
- });
409
- });