@cohortapp/agent-sdk 2.17.0 → 2.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (526) hide show
  1. package/.claude/settings.json +18 -0
  2. package/.env.example +18 -5
  3. package/README.md +1 -0
  4. package/bin/maestro.mjs +62 -0
  5. package/docs/guides/billing-console-keys.md +60 -0
  6. package/docs/guides/front-door-session.md +54 -9
  7. package/docs/guides/mac-mini.md +20 -25
  8. package/docs/guides/setup-wizard.md +1 -1
  9. package/docs/runbooks/fleet-rollout.md +156 -0
  10. package/docs/runbooks/mac-mini-bootstrap.md +12 -14
  11. package/lib/action-executor.js +19 -3
  12. package/lib/budget-guard.mjs +279 -3
  13. package/lib/channels/base-adapter.mjs +3 -1
  14. package/lib/channels/contract.mjs +2 -1
  15. package/lib/channels/inbox-item.mjs +8 -0
  16. package/lib/claude-bin.mjs +5 -6
  17. package/lib/cli/doctor-checks.mjs +141 -10
  18. package/lib/cli/global-setup-extras.mjs +5 -1
  19. package/lib/cli/inbox.mjs +100 -15
  20. package/lib/cli/seat-auth.mjs +463 -0
  21. package/lib/cli/session.mjs +80 -12
  22. package/lib/collective/capture.mjs +8 -6
  23. package/lib/collective/global-config.mjs +63 -1
  24. package/lib/collective/presence.mjs +142 -5
  25. package/lib/comms/send-gate.mjs +559 -1
  26. package/lib/diagnostics/alerts.mjs +49 -0
  27. package/lib/diagnostics/cadence-output-freshness.mjs +288 -0
  28. package/lib/engine/agents/definitions.mjs +343 -0
  29. package/lib/engine/agents/persist.mjs +275 -0
  30. package/lib/engine/agents/runtime.mjs +748 -0
  31. package/lib/engine/agents/usage.mjs +95 -0
  32. package/lib/engine/auth-status.mjs +139 -0
  33. package/lib/engine/budget.mjs +194 -0
  34. package/lib/engine/cli.mjs +1204 -0
  35. package/lib/engine/commands/index.mjs +269 -0
  36. package/lib/engine/context/budget.mjs +219 -0
  37. package/lib/engine/context/cache.mjs +125 -0
  38. package/lib/engine/context/child-env.mjs +215 -0
  39. package/lib/engine/context/compaction.mjs +342 -0
  40. package/lib/engine/context/images.mjs +90 -0
  41. package/lib/engine/context/instructions.mjs +327 -0
  42. package/lib/engine/context/lazy-instructions.mjs +169 -0
  43. package/lib/engine/context/manager.mjs +182 -0
  44. package/lib/engine/context/real-path.mjs +91 -0
  45. package/lib/engine/context/secret-values.mjs +163 -0
  46. package/lib/engine/context/settings.mjs +274 -0
  47. package/lib/engine/context/stream-input.mjs +159 -0
  48. package/lib/engine/guard.mjs +152 -0
  49. package/lib/engine/hooks.mjs +713 -0
  50. package/lib/engine/loop.mjs +560 -0
  51. package/lib/engine/mcp/client.mjs +254 -0
  52. package/lib/engine/mcp/config.mjs +301 -0
  53. package/lib/engine/mcp/http.mjs +201 -0
  54. package/lib/engine/mcp/index.mjs +146 -0
  55. package/lib/engine/mcp/jsonrpc.mjs +147 -0
  56. package/lib/engine/mcp/naming.mjs +66 -0
  57. package/lib/engine/mcp/resources.mjs +89 -0
  58. package/lib/engine/mcp/results.mjs +133 -0
  59. package/lib/engine/mcp/stdio.mjs +137 -0
  60. package/lib/engine/mcp/supervisor.mjs +116 -0
  61. package/lib/engine/messages.mjs +104 -0
  62. package/lib/engine/output/json.mjs +164 -0
  63. package/lib/engine/output/stream-json.mjs +266 -0
  64. package/lib/engine/permissions.mjs +845 -0
  65. package/lib/engine/process-identity.mjs +164 -0
  66. package/lib/engine/process-tree.mjs +551 -0
  67. package/lib/engine/prompt.mjs +60 -0
  68. package/lib/engine/session/store.mjs +299 -0
  69. package/lib/engine/session-runtime/args.mjs +97 -0
  70. package/lib/engine/session-runtime/host.mjs +143 -0
  71. package/lib/engine/session-runtime/inbox.mjs +122 -0
  72. package/lib/engine/session-runtime/notifications.mjs +129 -0
  73. package/lib/engine/session-runtime/registry.mjs +328 -0
  74. package/lib/engine/session-runtime/runner.mjs +344 -0
  75. package/lib/engine/session-runtime/socket.mjs +212 -0
  76. package/lib/engine/session-runtime/wakeup.mjs +115 -0
  77. package/lib/engine/skills/index.mjs +321 -0
  78. package/lib/engine/tools/bash-background.mjs +533 -0
  79. package/lib/engine/tools/bash.mjs +216 -0
  80. package/lib/engine/tools/edit.mjs +97 -0
  81. package/lib/engine/tools/glob.mjs +81 -0
  82. package/lib/engine/tools/grep.mjs +224 -0
  83. package/lib/engine/tools/index.mjs +84 -0
  84. package/lib/engine/tools/list-agents.mjs +32 -0
  85. package/lib/engine/tools/ls.mjs +127 -0
  86. package/lib/engine/tools/monitor.mjs +82 -0
  87. package/lib/engine/tools/notebook-edit.mjs +218 -0
  88. package/lib/engine/tools/read.mjs +103 -0
  89. package/lib/engine/tools/schedule-wakeup.mjs +45 -0
  90. package/lib/engine/tools/schema.mjs +144 -0
  91. package/lib/engine/tools/send-message.mjs +77 -0
  92. package/lib/engine/tools/session.mjs +70 -0
  93. package/lib/engine/tools/todo.mjs +144 -0
  94. package/lib/engine/tools/toolsearch.mjs +217 -0
  95. package/lib/engine/tools/walk.mjs +193 -0
  96. package/lib/engine/tools/web-switch.mjs +31 -0
  97. package/lib/engine/tools/webfetch-html.mjs +387 -0
  98. package/lib/engine/tools/webfetch-net.mjs +340 -0
  99. package/lib/engine/tools/webfetch.mjs +198 -0
  100. package/lib/engine/tools/websearch.mjs +91 -0
  101. package/lib/engine/tools/workflow.mjs +95 -0
  102. package/lib/engine/tools/write.mjs +76 -0
  103. package/lib/engine/tui/line-editor.mjs +137 -0
  104. package/lib/engine/tui/render.mjs +86 -0
  105. package/lib/engine/tui/tui.mjs +274 -0
  106. package/lib/engine/wire/anthropic-messages.mjs +263 -0
  107. package/lib/engine/wire/effort.mjs +36 -0
  108. package/lib/engine/wire/errors.mjs +496 -0
  109. package/lib/engine/wire/http.mjs +441 -0
  110. package/lib/engine/wire/index.mjs +76 -0
  111. package/lib/engine/wire/openai-chat.mjs +332 -0
  112. package/lib/engine/wire/prompt-cache.mjs +79 -0
  113. package/lib/engine/wire/search.mjs +140 -0
  114. package/lib/engine/wire/sse.mjs +114 -0
  115. package/lib/engine/wire/stall.mjs +349 -0
  116. package/lib/engine/wire/token-provider.mjs +175 -0
  117. package/lib/engine/wire/usage.mjs +192 -0
  118. package/lib/engine/workflow/host.mjs +524 -0
  119. package/lib/engine/workflow/journal.mjs +188 -0
  120. package/lib/engine/workflow/json-schema.mjs +171 -0
  121. package/lib/engine/workflow/meta.mjs +329 -0
  122. package/lib/engine/workflow/notifications.mjs +52 -0
  123. package/lib/engine/workflow/runtime.mjs +447 -0
  124. package/lib/engine/workflow/sandbox.mjs +534 -0
  125. package/lib/engine/workflow/worker.mjs +141 -0
  126. package/lib/engine/workflow/worktree.mjs +74 -0
  127. package/lib/execution/disposition.mjs +1 -1
  128. package/lib/execution/intake.mjs +10 -0
  129. package/lib/execution/surface-policy.mjs +15 -0
  130. package/lib/learning/curator.mjs +8 -6
  131. package/lib/learning/reflect.mjs +8 -6
  132. package/lib/model-router/catalog/cohort.yaml +137 -0
  133. package/lib/model-router/catalog.mjs +118 -1
  134. package/lib/model-router/failover.mjs +67 -16
  135. package/lib/model-router/llm-task.mjs +39 -3
  136. package/lib/model-router/resolve.mjs +89 -3
  137. package/lib/model-router/spawn.mjs +46 -47
  138. package/lib/model-router/taxonomy.mjs +126 -4
  139. package/lib/org/cost-sync.mjs +141 -11
  140. package/lib/org/inbound/broadcast.mjs +289 -0
  141. package/lib/org/inbound/collective.mjs +375 -0
  142. package/lib/org/inbound/directedness.mjs +96 -8
  143. package/lib/org/inbound/facts.mjs +78 -2
  144. package/lib/org/inbound/project.mjs +22 -0
  145. package/lib/org/inbound/surfaces.mjs +14 -0
  146. package/lib/org/llm-token.mjs +879 -0
  147. package/lib/org/mesh.mjs +61 -0
  148. package/lib/org/messaging.mjs +3 -1
  149. package/lib/org/protocol.checksum +1 -1
  150. package/lib/org/protocol.mjs +15 -0
  151. package/lib/org/quota.mjs +520 -0
  152. package/lib/org/tool-surface.mjs +104 -16
  153. package/lib/org/ui-parity.mjs +16 -1
  154. package/lib/org/work-ledger.mjs +37 -6
  155. package/lib/rate-guard.mjs +114 -1
  156. package/lib/resource-governor.mjs +41 -6
  157. package/lib/runtime/adapter.mjs +823 -0
  158. package/lib/runtime/child-env.mjs +191 -0
  159. package/lib/runtime/legacy-shell-guard.mjs +97 -0
  160. package/lib/runtime/seat-engine.mjs +162 -0
  161. package/lib/session/ask-ledger.mjs +271 -0
  162. package/lib/session/current-work.mjs +676 -0
  163. package/lib/session/feed-core.mjs +40 -3
  164. package/lib/session/launch-args.mjs +56 -4
  165. package/lib/session/status-summary.mjs +26 -9
  166. package/lib/session/upgrade-notice.mjs +42 -0
  167. package/lib/setup/claude-probe.mjs +117 -13
  168. package/lib/setup/enrich.mjs +13 -10
  169. package/lib/setup/sections/model.mjs +39 -13
  170. package/lib/telemetry/collect.mjs +208 -9
  171. package/lib/upgrade/ignored-drift.mjs +105 -0
  172. package/lib/voice/post-call-brief.mjs +30 -17
  173. package/package.json +13 -3
  174. package/plugins/maestro-skills/skills/board-work.md +5 -0
  175. package/plugins/maestro-skills/skills/inbound-triage.md +56 -15
  176. package/plugins/maestro-skills/skills/main-session.md +18 -7
  177. package/scripts/ci/check-tarball-fidelity.mjs +126 -2
  178. package/scripts/ci/run-tests.mjs +47 -19
  179. package/scripts/cohort-llm/api-key-helper.mjs +92 -0
  180. package/scripts/collective/hook-runner.mjs +29 -2
  181. package/scripts/continuous-monitor.sh +13 -0
  182. package/scripts/cost/track-claude-usage.mjs +15 -0
  183. package/scripts/daemon/agent-daemon.mjs +408 -20
  184. package/scripts/daemon/assurance.mjs +48 -12
  185. package/scripts/daemon/cadence-consumer.mjs +218 -68
  186. package/scripts/daemon/cadence-handlers.mjs +73 -4
  187. package/scripts/daemon/classifier.mjs +75 -26
  188. package/scripts/daemon/context-compiler.mjs +51 -37
  189. package/scripts/daemon/deliver.mjs +30 -1
  190. package/scripts/daemon/dispatcher.mjs +595 -149
  191. package/scripts/daemon/health.mjs +14 -1
  192. package/scripts/daemon/maestro-daemon.mjs +11 -0
  193. package/scripts/daemon/prompt-builder.mjs +24 -0
  194. package/scripts/daemon/responder.mjs +246 -79
  195. package/scripts/daemon/sdk-version.mjs +98 -16
  196. package/scripts/eval/probe-gateway.mjs +635 -0
  197. package/scripts/eval/replay/extract.mjs +270 -0
  198. package/scripts/eval/replay/grade.mjs +260 -0
  199. package/scripts/eval/replay/lib/config.mjs +50 -0
  200. package/scripts/eval/replay/lib/effects.mjs +65 -0
  201. package/scripts/eval/replay/lib/fixture.mjs +188 -0
  202. package/scripts/eval/replay/lib/judge.mjs +72 -0
  203. package/scripts/eval/replay/lib/redact.mjs +136 -0
  204. package/scripts/eval/replay/lib/sandbox.mjs +170 -0
  205. package/scripts/eval/replay/lib/schema-check.mjs +63 -0
  206. package/scripts/eval/replay/lib/transcript.mjs +76 -0
  207. package/scripts/eval/replay/mcp-replay-stub.mjs +101 -0
  208. package/scripts/eval/replay/report.mjs +185 -0
  209. package/scripts/eval/replay/run.mjs +404 -0
  210. package/scripts/fleet/rollout.mjs +1094 -0
  211. package/scripts/hooks/pre-send-audit.sh +36 -245
  212. package/scripts/hooks/pre-write-yaml-validate.mjs +275 -0
  213. package/scripts/hooks/validate-state-yaml.sh +190 -0
  214. package/scripts/huddle/huddle-llm.mjs +361 -0
  215. package/scripts/huddle/huddle-server.mjs +46 -121
  216. package/scripts/local-triggers/autoupdate.sh +448 -78
  217. package/scripts/local-triggers/run-trigger.sh +13 -0
  218. package/scripts/maintenance/pin-integrity.mjs +364 -0
  219. package/scripts/poll-slack-events.sh +41 -9
  220. package/scripts/poller/slack-socket-mode.mjs +28 -3
  221. package/scripts/session/supervisor.mjs +80 -13
  222. package/scripts/spawn-session.sh +13 -0
  223. package/bin/maestro.test.mjs +0 -1574
  224. package/lib/action-executor.test.mjs +0 -871
  225. package/lib/archetype.test.mjs +0 -132
  226. package/lib/assurance/plan-note.test.mjs +0 -234
  227. package/lib/assurance/room-budget.test.mjs +0 -486
  228. package/lib/assurance/tier.test.mjs +0 -174
  229. package/lib/autonomy.test.mjs +0 -66
  230. package/lib/backlog.test.mjs +0 -302
  231. package/lib/backup/policy.test.mjs +0 -305
  232. package/lib/budget-escalate.test.mjs +0 -232
  233. package/lib/budget-guard.envelope.test.mjs +0 -476
  234. package/lib/budget-guard.test.mjs +0 -427
  235. package/lib/cadence-bus-requeue.test.mjs +0 -83
  236. package/lib/cadence-bus-schedule.test.mjs +0 -194
  237. package/lib/cadence-bus.test.mjs +0 -720
  238. package/lib/cadences.test.mjs +0 -230
  239. package/lib/capability/inventory.test.mjs +0 -232
  240. package/lib/capability.test.mjs +0 -78
  241. package/lib/channels/base-adapter.test.mjs +0 -590
  242. package/lib/channels/channels.test.mjs +0 -371
  243. package/lib/channels/contract.test.mjs +0 -162
  244. package/lib/channels/inbox-item.test.mjs +0 -368
  245. package/lib/channels/orgmail/adapter.test.mjs +0 -448
  246. package/lib/channels/pairing.test.mjs +0 -270
  247. package/lib/channels/repeat-suppressor.test.mjs +0 -134
  248. package/lib/channels/slack-adapter.test.mjs +0 -212
  249. package/lib/channels/telegram-adapter.test.mjs +0 -306
  250. package/lib/channels/voice/adapter.test.mjs +0 -278
  251. package/lib/channels/whatsapp/adapter-baileys.test.mjs +0 -359
  252. package/lib/channels/whatsapp/baileys-typing.test.mjs +0 -154
  253. package/lib/charter.test.mjs +0 -89
  254. package/lib/claude-bin.test.mjs +0 -131
  255. package/lib/cli/board.test.mjs +0 -227
  256. package/lib/cli/design.test.mjs +0 -270
  257. package/lib/cli/doctor-checks.test.mjs +0 -336
  258. package/lib/cli/global-setup-extras.test.mjs +0 -462
  259. package/lib/cli/inbox.test.mjs +0 -230
  260. package/lib/cli/session-ack.test.mjs +0 -63
  261. package/lib/cli/session.test.mjs +0 -613
  262. package/lib/collective/capture.test.mjs +0 -121
  263. package/lib/collective/cards.test.mjs +0 -114
  264. package/lib/collective/config.test.mjs +0 -123
  265. package/lib/collective/global-config.test.mjs +0 -220
  266. package/lib/collective/global-skills.test.mjs +0 -126
  267. package/lib/collective/presence.test.mjs +0 -95
  268. package/lib/collective/recall.test.mjs +0 -116
  269. package/lib/collective/vendor-skills.test.mjs +0 -306
  270. package/lib/comms/send-gate.test.mjs +0 -770
  271. package/lib/comms.test.mjs +0 -41
  272. package/lib/context/budget.test.mjs +0 -252
  273. package/lib/context/history-scope.test.mjs +0 -79
  274. package/lib/cost/ledger-row.test.mjs +0 -183
  275. package/lib/design/design-md.test.mjs +0 -318
  276. package/lib/design/fixtures/DESIGN.golden.md +0 -238
  277. package/lib/design/fixtures/PRODUCT.golden.md +0 -67
  278. package/lib/design/fixtures/foundation.json +0 -133
  279. package/lib/design/refresh-gate.test.mjs +0 -144
  280. package/lib/design/write.test.mjs +0 -241
  281. package/lib/diagnostics/alerts.test.mjs +0 -318
  282. package/lib/diagnostics/backup-freshness.test.mjs +0 -185
  283. package/lib/diagnostics/counters.test.mjs +0 -206
  284. package/lib/diagnostics/events.test.mjs +0 -290
  285. package/lib/diagnostics/otel.test.mjs +0 -196
  286. package/lib/diagnostics/trace.test.mjs +0 -251
  287. package/lib/env-compat.test.mjs +0 -104
  288. package/lib/execution/disposition.test.mjs +0 -553
  289. package/lib/execution/drive.test.mjs +0 -270
  290. package/lib/execution/effects.test.mjs +0 -344
  291. package/lib/execution/intake.test.mjs +0 -389
  292. package/lib/execution/journal.test.mjs +0 -261
  293. package/lib/execution/match.test.mjs +0 -235
  294. package/lib/execution/pipeline.test.mjs +0 -392
  295. package/lib/execution/route.test.mjs +0 -186
  296. package/lib/execution/surface-policy.test.mjs +0 -162
  297. package/lib/fs-atomic.test.mjs +0 -72
  298. package/lib/fs-ownership.test.mjs +0 -158
  299. package/lib/goals/admission.test.mjs +0 -164
  300. package/lib/goals/classify.test.mjs +0 -167
  301. package/lib/goals/collaborate.test.mjs +0 -336
  302. package/lib/goals/gaps.test.mjs +0 -284
  303. package/lib/goals/loop.test.mjs +0 -845
  304. package/lib/hooks/bus.test.mjs +0 -387
  305. package/lib/identity/persona.test.mjs +0 -142
  306. package/lib/kpi-sensors.test.mjs +0 -278
  307. package/lib/kpi.test.mjs +0 -244
  308. package/lib/learning/config.test.mjs +0 -75
  309. package/lib/learning/counters.test.mjs +0 -69
  310. package/lib/learning/curator-consolidate.test.mjs +0 -238
  311. package/lib/learning/curator.test.mjs +0 -106
  312. package/lib/learning/reflect.test.mjs +0 -0
  313. package/lib/learning/session-index.test.mjs +0 -125
  314. package/lib/learning/skill-writer.test.mjs +0 -210
  315. package/lib/mandate/audit.test.mjs +0 -195
  316. package/lib/mandate/contract.test.mjs +0 -185
  317. package/lib/mandate/derive.test.mjs +0 -274
  318. package/lib/mandate/model.test.mjs +0 -164
  319. package/lib/mandate/refresh.test.mjs +0 -389
  320. package/lib/mcp/server.test.mjs +0 -426
  321. package/lib/model-router/auth-profiles.test.mjs +0 -580
  322. package/lib/model-router/catalog.test.mjs +0 -385
  323. package/lib/model-router/economics.test.mjs +0 -438
  324. package/lib/model-router/failover.test.mjs +0 -439
  325. package/lib/model-router/health.test.mjs +0 -338
  326. package/lib/model-router/integration-coverage.test.mjs +0 -831
  327. package/lib/model-router/integration.test.mjs +0 -564
  328. package/lib/model-router/ledger.test.mjs +0 -415
  329. package/lib/model-router/llm-task.test.mjs +0 -392
  330. package/lib/model-router/org-credentials.test.mjs +0 -265
  331. package/lib/model-router/pricing-refresh.test.mjs +0 -286
  332. package/lib/model-router/reconcile.test.mjs +0 -316
  333. package/lib/model-router/repair.test.mjs +0 -180
  334. package/lib/model-router/spawn.test.mjs +0 -446
  335. package/lib/model-router/taxonomy.test.mjs +0 -410
  336. package/lib/model-router.test.mjs +0 -1207
  337. package/lib/org/activity.test.mjs +0 -134
  338. package/lib/org/approvals.test.mjs +0 -216
  339. package/lib/org/awareness.test.mjs +0 -159
  340. package/lib/org/board-mine-cache.test.mjs +0 -53
  341. package/lib/org/board.test.mjs +0 -187
  342. package/lib/org/bootstrap-context.test.mjs +0 -153
  343. package/lib/org/client.test.mjs +0 -1206
  344. package/lib/org/cohort-client.test.mjs +0 -126
  345. package/lib/org/cost-sync.test.mjs +0 -153
  346. package/lib/org/doctor.test.mjs +0 -346
  347. package/lib/org/engagement-ledger.test.mjs +0 -112
  348. package/lib/org/engagement.test.mjs +0 -739
  349. package/lib/org/handoff.test.mjs +0 -269
  350. package/lib/org/inbound/directedness.test.mjs +0 -668
  351. package/lib/org/inbound/facts.test.mjs +0 -471
  352. package/lib/org/inbound/hydrate.test.mjs +0 -908
  353. package/lib/org/inbound/index.test.mjs +0 -429
  354. package/lib/org/inbound/project.test.mjs +0 -287
  355. package/lib/org/integration-tools.test.mjs +0 -160
  356. package/lib/org/keys.test.mjs +0 -92
  357. package/lib/org/knowledge.test.mjs +0 -326
  358. package/lib/org/leases.test.mjs +0 -235
  359. package/lib/org/mesh-directives.test.mjs +0 -110
  360. package/lib/org/mesh-integration.test.mjs +0 -127
  361. package/lib/org/mesh.test.mjs +0 -400
  362. package/lib/org/messaging.test.mjs +0 -471
  363. package/lib/org/param-contract.test.mjs +0 -477
  364. package/lib/org/policy.test.mjs +0 -237
  365. package/lib/org/protocol.checksum.test.mjs +0 -90
  366. package/lib/org/protocol.test.mjs +0 -323
  367. package/lib/org/push.test.mjs +0 -792
  368. package/lib/org/registry.test.mjs +0 -100
  369. package/lib/org/resource-tools.test.mjs +0 -361
  370. package/lib/org/tool-access.test.mjs +0 -144
  371. package/lib/org/tool-surface-integration.test.mjs +0 -120
  372. package/lib/org/tool-surface.test.mjs +0 -1268
  373. package/lib/org/typing.test.mjs +0 -291
  374. package/lib/org/ui-parity.test.mjs +0 -560
  375. package/lib/org/verify.test.mjs +0 -194
  376. package/lib/org/work-ledger.test.mjs +0 -273
  377. package/lib/plan/adoption-e2e.test.mjs +0 -366
  378. package/lib/plan/budget-enforcement.test.mjs +0 -400
  379. package/lib/plan/compile.test.mjs +0 -382
  380. package/lib/plan/emit.test.mjs +0 -269
  381. package/lib/plan/explain.test.mjs +0 -188
  382. package/lib/prompts/parallelism.test.mjs +0 -177
  383. package/lib/rag/rag.test.mjs +0 -505
  384. package/lib/rate-guard.test.mjs +0 -272
  385. package/lib/reactive-gate.test.mjs +0 -57
  386. package/lib/render.test.mjs +0 -68
  387. package/lib/resource-governor.test.mjs +0 -488
  388. package/lib/scheduling/dynamic-jobs.test.mjs +0 -344
  389. package/lib/scheduling/jitter.test.mjs +0 -140
  390. package/lib/secrets/broker.test.mjs +0 -280
  391. package/lib/secrets/providers.test.mjs +0 -274
  392. package/lib/security/audit-engine.test.mjs +0 -424
  393. package/lib/security/coerce-args.test.mjs +0 -281
  394. package/lib/security/dangerous-tools.test.mjs +0 -68
  395. package/lib/security/external-content.test.mjs +0 -84
  396. package/lib/security/redact.test.mjs +0 -441
  397. package/lib/security/secret-equal.test.mjs +0 -55
  398. package/lib/session/config.test.mjs +0 -92
  399. package/lib/session/feed-core.test.mjs +0 -198
  400. package/lib/session/first-run.test.mjs +0 -121
  401. package/lib/session/frontdoor.test.mjs +0 -205
  402. package/lib/session/handoffs.test.mjs +0 -183
  403. package/lib/session/identity.test.mjs +0 -180
  404. package/lib/session/inbox-claims.test.mjs +0 -286
  405. package/lib/session/launch-args.test.mjs +0 -157
  406. package/lib/session/liveness.test.mjs +0 -100
  407. package/lib/session/status-summary.test.mjs +0 -118
  408. package/lib/session-permissions.test.mjs +0 -120
  409. package/lib/setup/claude-probe.test.mjs +0 -187
  410. package/lib/setup/completeness.test.mjs +0 -110
  411. package/lib/setup/context-pack.test.mjs +0 -89
  412. package/lib/setup/enrich.test.mjs +0 -115
  413. package/lib/setup/enroll-from-cohort.test.mjs +0 -300
  414. package/lib/setup/integration.test.mjs +0 -162
  415. package/lib/setup/io.test.mjs +0 -77
  416. package/lib/setup/runner.test.mjs +0 -132
  417. package/lib/setup/sections/identity.test.mjs +0 -234
  418. package/lib/setup/sections/inventory.test.mjs +0 -198
  419. package/lib/setup/sections/learning.test.mjs +0 -81
  420. package/lib/setup/sections/mandate.test.mjs +0 -388
  421. package/lib/setup/sections/messaging.test.mjs +0 -127
  422. package/lib/setup/sections/model.test.mjs +0 -240
  423. package/lib/setup/sections/org.test.mjs +0 -346
  424. package/lib/setup/sections/orgmail.test.mjs +0 -118
  425. package/lib/setup/sections/recovery.test.mjs +0 -98
  426. package/lib/setup/sections/subagents.test.mjs +0 -429
  427. package/lib/setup/sections/verify.test.mjs +0 -175
  428. package/lib/setup/sot.test.mjs +0 -81
  429. package/lib/setup/state.test.mjs +0 -115
  430. package/lib/singleton.test.mjs +0 -151
  431. package/lib/subagents/cli.test.mjs +0 -389
  432. package/lib/subagents/client.test.mjs +0 -309
  433. package/lib/subagents/gap.test.mjs +0 -234
  434. package/lib/subagents/lock.test.mjs +0 -248
  435. package/lib/subagents/manifest.test.mjs +0 -175
  436. package/lib/subagents/refs.test.mjs +0 -204
  437. package/lib/subagents/resolve.test.mjs +0 -422
  438. package/lib/subagents/schema.test.mjs +0 -328
  439. package/lib/telemetry/alerts.test.mjs +0 -109
  440. package/lib/telemetry/collect.test.mjs +0 -1274
  441. package/lib/tool-definitions-integration.test.mjs +0 -83
  442. package/lib/tool-definitions.test.mjs +0 -437
  443. package/lib/upgrade/global-refresh.test.mjs +0 -65
  444. package/lib/upgrade/launchd-reconcile.test.mjs +0 -272
  445. package/lib/upgrade/post-steps.test.mjs +0 -200
  446. package/lib/upgrade/verify.test.mjs +0 -164
  447. package/lib/util/fetch-timeout.test.mjs +0 -202
  448. package/lib/util/reconnect.test.mjs +0 -369
  449. package/lib/util/unhandled.test.mjs +0 -216
  450. package/lib/voice/outbound.test.mjs +0 -69
  451. package/lib/voice/session-rotation.test.mjs +0 -114
  452. package/lib/voice/stt.test.mjs +0 -226
  453. package/lib/voice/voice.test.mjs +0 -990
  454. package/scripts/cadence/enqueue-cadence-tick.test.mjs +0 -187
  455. package/scripts/ci/check-docs-accuracy.test.mjs +0 -409
  456. package/scripts/ci/check-durable-write-seam.test.mjs +0 -90
  457. package/scripts/ci/check-no-build-artifacts.test.mjs +0 -71
  458. package/scripts/ci/check-no-residual-identity.test.mjs +0 -202
  459. package/scripts/ci/check-skill-packs.test.mjs +0 -495
  460. package/scripts/ci/check-subagent-frontmatter.test.mjs +0 -124
  461. package/scripts/ci/check.test.mjs +0 -194
  462. package/scripts/ci/conformance-org-api.test.mjs +0 -425
  463. package/scripts/cloud-relay/voice/relay-identity.test.mjs +0 -96
  464. package/scripts/collective/hook-runner.test.mjs +0 -173
  465. package/scripts/cost/fleet-digest.test.mjs +0 -207
  466. package/scripts/cost/track-claude-usage-pricing.test.mjs +0 -183
  467. package/scripts/cost/track-claude-usage.test.mjs +0 -148
  468. package/scripts/daemon/agent-daemon-board-mine.test.mjs +0 -96
  469. package/scripts/daemon/agent-daemon-design.test.mjs +0 -238
  470. package/scripts/daemon/agent-daemon-frontdoor.test.mjs +0 -60
  471. package/scripts/daemon/agent-daemon.test.mjs +0 -995
  472. package/scripts/daemon/assurance-e2e.test.mjs +0 -613
  473. package/scripts/daemon/assurance.test.mjs +0 -1791
  474. package/scripts/daemon/board-mirror.test.mjs +0 -165
  475. package/scripts/daemon/cadence-consumer-frontdoor.test.mjs +0 -393
  476. package/scripts/daemon/cadence-consumer-governance.test.mjs +0 -276
  477. package/scripts/daemon/cadence-consumer.test.mjs +0 -776
  478. package/scripts/daemon/cadence-handlers.test.mjs +0 -837
  479. package/scripts/daemon/classifier-identity.test.mjs +0 -137
  480. package/scripts/daemon/classifier.test.mjs +0 -266
  481. package/scripts/daemon/classify-kind.test.mjs +0 -40
  482. package/scripts/daemon/context-compiler.test.mjs +0 -406
  483. package/scripts/daemon/deliver.test.mjs +0 -564
  484. package/scripts/daemon/dispatcher-cooldown.test.mjs +0 -122
  485. package/scripts/daemon/dispatcher-governance.test.mjs +0 -1013
  486. package/scripts/daemon/dispatcher-resume.test.mjs +0 -166
  487. package/scripts/daemon/dispatcher-session-continuity.test.mjs +0 -365
  488. package/scripts/daemon/execution-ladder.test.mjs +0 -470
  489. package/scripts/daemon/goal-steward-cadence.test.mjs +0 -312
  490. package/scripts/daemon/inbox-deferral-session.test.mjs +0 -49
  491. package/scripts/daemon/inbox-deferral.test.mjs +0 -336
  492. package/scripts/daemon/inbox-wake.test.mjs +0 -199
  493. package/scripts/daemon/integration.test.mjs +0 -149
  494. package/scripts/daemon/lib/self-echo.test.mjs +0 -153
  495. package/scripts/daemon/lib/session-router.test.mjs +0 -554
  496. package/scripts/daemon/prompt-builder-preamble.test.mjs +0 -210
  497. package/scripts/daemon/prompt-builder.test.mjs +0 -556
  498. package/scripts/daemon/responder-cost.test.mjs +0 -68
  499. package/scripts/daemon/responder-history.test.mjs +0 -221
  500. package/scripts/daemon/sdk-version.test.mjs +0 -31
  501. package/scripts/daemon/session-lock.test.mjs +0 -252
  502. package/scripts/daemon/session-outcomes.test.mjs +0 -533
  503. package/scripts/daemon/typing-registry.test.mjs +0 -102
  504. package/scripts/hooks/pre-send-audit.test.mjs +0 -354
  505. package/scripts/huddle/huddle-prompt.test.mjs +0 -176
  506. package/scripts/local-triggers/autoupdate.test.mjs +0 -518
  507. package/scripts/local-triggers/generate-plists.test.mjs +0 -456
  508. package/scripts/media-generation/brand-clause.test.mjs +0 -135
  509. package/scripts/org/send-orgmail.first-contact.test.mjs +0 -102
  510. package/scripts/poller/inbox-privilege-injection.test.mjs +0 -167
  511. package/scripts/poller/inbox-scan-poller.test.mjs +0 -295
  512. package/scripts/poller/lib/cloud-relay-dedup.test.mjs +0 -133
  513. package/scripts/poller/slack-socket-mode.test.mjs +0 -805
  514. package/scripts/poller-launchd/install.test.mjs +0 -243
  515. package/scripts/restore-from-backup.test.mjs +0 -181
  516. package/scripts/session/feed.test.mjs +0 -196
  517. package/scripts/session/supervisor-sh.test.mjs +0 -218
  518. package/scripts/session/supervisor.test.mjs +0 -482
  519. package/scripts/setup/configure-macos.test.mjs +0 -306
  520. package/scripts/setup/gen-subagent-manifest.test.mjs +0 -124
  521. package/scripts/setup/generate-agent-package-json.test.mjs +0 -143
  522. package/scripts/setup/generate-capability.test.mjs +0 -134
  523. package/scripts/setup/init-agent.test.mjs +0 -370
  524. package/scripts/setup/init-skill-marketplace.test.mjs +0 -193
  525. package/scripts/vendor/sync-skill-packs.test.mjs +0 -103
  526. package/scripts/watchdog/memory-watchdog.test.mjs +0 -64
@@ -1,792 +0,0 @@
1
- /**
2
- * push.test.mjs — the agent's PUSH channel onto the org event ledger.
3
- *
4
- * Drives connectOrgPush over an injected org client + injected fetch + injected
5
- * timers + a tmp agentRoot, asserting the things that actually matter:
6
- * - the LADDER falls stream → longpoll → cadence and probes back up;
7
- * - an hq without the endpoint (404) demotes INSTANTLY, without retries;
8
- * - resume after a disconnect loses nothing and re-delivers nothing (the
9
- * cursor is persisted, sent back, and enforced as an exclusive watermark);
10
- * - reconnect backs off with jitter, bounded, never hammering a down server;
11
- * - a malformed frame is skipped fail-open and the connection survives it;
12
- * - a burst is coalesced into one wake, with a trailing wake for the tail;
13
- * - nothing here ever throws past the boundary.
14
- * No network, no real time.
15
- *
16
- * Run: node --test lib/org/push.test.mjs
17
- */
18
- "use strict";
19
-
20
- import { test } from "node:test";
21
- import assert from "node:assert/strict";
22
- import { mkdtempSync, mkdirSync, writeFileSync, existsSync, readFileSync, rmSync } from "node:fs";
23
- import { tmpdir } from "node:os";
24
- import { join } from "node:path";
25
-
26
- import {
27
- connectOrgPush,
28
- decodeFrameLine,
29
- readCursor,
30
- writeCursor,
31
- PUSH_RUNG,
32
- CURSOR_RELATIVE,
33
- STATUS_RELATIVE,
34
- _internals,
35
- } from "./push.mjs";
36
-
37
- const BASE = "https://org.cohortapp.com";
38
-
39
- function tmpRepo() {
40
- const root = mkdtempSync(join(tmpdir(), "org-push-"));
41
- mkdirSync(join(root, "config"), { recursive: true });
42
- return root;
43
- }
44
-
45
- function cfgEnabled() {
46
- return { org: { cohort: { enabled: true, base: BASE, token: "tok" } } };
47
- }
48
- function cfgDisabled() {
49
- return { org: { cohort: { enabled: false, base: BASE, token: "tok" } } };
50
- }
51
-
52
- /**
53
- * A fake org client: only what push.mjs uses.
54
- *
55
- * `call` is the LONG-POLL seam. `agent.wait` is a POST METHOD on hq's
56
- * dispatcher, not a GET read — it is absent from `reads.ts#HANDLED_READS`, so
57
- * the GET this suite used to assert would have 404'd against every hq that has
58
- * ever existed. The ok-frame shape below (`{ok:true, result:{cursor, items}}`)
59
- * is hq `methods/agent/wait.ts`'s documented return contract.
60
- */
61
- function fakeClient(opts = {}) {
62
- const c = {
63
- isEnabled: (cfg) => !!(cfg && cfg.org && cfg.org.cohort && cfg.org.cohort.enabled),
64
- configFromAgent: () => ({ base: BASE, token: "tok", orgId: "acme", enabled: true }),
65
- readCalls: [],
66
- callCalls: [],
67
- _reads: opts.reads ? opts.reads.slice() : [],
68
- _calls: opts.calls ? opts.calls.slice() : [],
69
- read(path, o) {
70
- c.readCalls.push({ path, o });
71
- const next = c._reads.length ? c._reads.shift() : { ok: true, payload: { events: [] }, status: 200 };
72
- return Promise.resolve(typeof next === "function" ? next(path, o) : next);
73
- },
74
- call(method, params, o) {
75
- c.callCalls.push({ method, params, o });
76
- const next = c._calls.length ? c._calls.shift() : { ok: true, status: 200, result: { items: [], cursor: null, timedOut: true } };
77
- return Promise.resolve(typeof next === "function" ? next(method, params, o) : next);
78
- },
79
- };
80
- return c;
81
- }
82
-
83
- /** Build an NDJSON/SSE stream response from a list of raw wire lines. */
84
- function streamResponse(lines, { status = 200, chunkAll = false } = {}) {
85
- return {
86
- status,
87
- body: (async function* () {
88
- if (chunkAll) { yield `${lines.join("\n")}\n`; return; }
89
- for (const l of lines) yield `${l}\n`;
90
- })(),
91
- };
92
- }
93
-
94
- /** A fetch that serves a queue of responses (or throws when told to). */
95
- function fakeFetch(queue) {
96
- const calls = [];
97
- const f = async (url, init) => {
98
- calls.push({ url: String(url), init });
99
- const next = queue.length ? queue.shift() : streamResponse([]);
100
- if (next instanceof Error) throw next;
101
- return typeof next === "function" ? next(String(url), init) : next;
102
- };
103
- f.calls = calls;
104
- return f;
105
- }
106
-
107
- /**
108
- * Wake handlers are invoked off a microtask (dispatch must never block on a
109
- * handler), so a test that counts wakes has to let the microtask queue drain.
110
- */
111
- const flush = () => new Promise((r) => setImmediate(r));
112
-
113
- /** Timers that never fire on their own — the test drives every step by hand. */
114
- function inertTimers() {
115
- const scheduled = [];
116
- return {
117
- setTimeout: (fn, ms) => { const h = { fn, ms, unref() {} }; scheduled.push(h); return h; },
118
- clearTimeout: (h) => { const i = scheduled.indexOf(h); if (i >= 0) scheduled.splice(i, 1); },
119
- scheduled,
120
- };
121
- }
122
-
123
- /** Build a live-but-idle handle whose ladder we step manually. */
124
- async function mkHandle(root, extra = {}) {
125
- const timers = inertTimers();
126
- const client = extra.client || fakeClient();
127
- const handle = await connectOrgPush({
128
- agentRoot: root,
129
- cfg: cfgEnabled(),
130
- client,
131
- setTimeout: timers.setTimeout,
132
- clearTimeout: timers.clearTimeout,
133
- now: extra.now,
134
- ...extra,
135
- });
136
- return { handle, ctx: handle._ctx, client, timers };
137
- }
138
-
139
- const EV = (seq, family = "messaging", kind = "send") =>
140
- JSON.stringify({ seq, family, kind, entityId: `m${seq}`, actor: "u1", at: "2026-08-11T00:00:00Z", payload: { recipientCount: 2 } });
141
-
142
- // ---------------------------------------------------------------------------
143
- // Gate + wiring basics
144
- // ---------------------------------------------------------------------------
145
-
146
- test("disabled org → inert handle, zero network, cadence rung", async () => {
147
- const root = tmpRepo();
148
- const fetchImpl = fakeFetch([]);
149
- const handle = await connectOrgPush({ agentRoot: root, cfg: cfgDisabled(), client: fakeClient(), fetchImpl });
150
- assert.equal(handle.isEnabled, false);
151
- assert.equal(handle.rung(), PUSH_RUNG.CADENCE);
152
- assert.equal(fetchImpl.calls.length, 0, "a disabled org must never touch the wire");
153
- assert.doesNotThrow(() => handle.stop(), "inert stop is safe");
154
- });
155
-
156
- test("COHORT_PUSH_DISABLED=1 is an operator kill switch back to pure cadence", async () => {
157
- const root = tmpRepo();
158
- process.env.COHORT_PUSH_DISABLED = "1";
159
- try {
160
- const handle = await connectOrgPush({ agentRoot: root, cfg: cfgEnabled(), client: fakeClient() });
161
- assert.equal(handle.isEnabled, false);
162
- } finally {
163
- delete process.env.COHORT_PUSH_DISABLED;
164
- }
165
- });
166
-
167
- test("boot does not run a step inline — the first step is scheduled", async () => {
168
- const root = tmpRepo();
169
- const fetchImpl = fakeFetch([]);
170
- const { handle, timers } = await mkHandle(root, { fetchImpl });
171
- assert.equal(fetchImpl.calls.length, 0, "no request before the scheduled first step runs");
172
- assert.equal(timers.scheduled.length, 1, "exactly one pump scheduled");
173
- assert.equal(timers.scheduled[0].ms, 0);
174
- handle.stop();
175
- });
176
-
177
- // ---------------------------------------------------------------------------
178
- // Rung 1 — the stream
179
- // ---------------------------------------------------------------------------
180
-
181
- test("stream rung: events wake the messaging target and advance the persisted cursor", async () => {
182
- const root = tmpRepo();
183
- const woke = [];
184
- const fetchImpl = fakeFetch([streamResponse([":ok", EV(11), EV(12), EV(13)])]);
185
- const { handle, ctx } = await mkHandle(root, {
186
- fetchImpl,
187
- wakeCoalesceMs: 0, // every event fires its own wake, so we can count them
188
- minHealthyMs: 0, // and don't apply the short-stream backoff floor here
189
- enqueueTick: (t) => woke.push(t),
190
- });
191
-
192
- const delay = await _internals.ladderStep(ctx);
193
- await flush();
194
-
195
- assert.equal(ctx.rung, PUSH_RUNG.STREAM, "a healthy stream stays on the preferred rung");
196
- assert.equal(ctx.cursor, 13, "the watermark advanced to the last seq");
197
- assert.equal(delay, 0, "a clean EOF reconnects immediately");
198
- assert.equal(readCursor(root), 13, "the cursor is durable across a restart");
199
- assert.equal(woke.length, 3);
200
- assert.equal(woke[0].cadence, "messaging-inbound", "the wake nudges the EXISTING authoritative fetch");
201
- assert.equal(woke[0].source, "org-push");
202
- assert.equal(woke[0].priority, "high");
203
- handle.stop();
204
- });
205
-
206
- test("stream rung: SSE framing, NDJSON framing and keepalives all parse", async () => {
207
- const root = tmpRepo();
208
- const woke = [];
209
- const fetchImpl = fakeFetch([
210
- streamResponse([
211
- ": keepalive",
212
- "event: message",
213
- `data: ${EV(5)}`,
214
- "",
215
- EV(6), // bare NDJSON on the same connection
216
- JSON.stringify({ type: "heartbeat" }),
217
- ]),
218
- ]);
219
- const { handle, ctx } = await mkHandle(root, { fetchImpl, wakeCoalesceMs: 0, enqueueTick: (t) => woke.push(t) });
220
- await _internals.ladderStep(ctx);
221
- await flush();
222
- assert.equal(ctx.cursor, 6, "both framings delivered");
223
- assert.equal(woke.length, 2);
224
- handle.stop();
225
- });
226
-
227
- test("stream rung: a malformed frame is skipped fail-open and the stream keeps reading", async () => {
228
- const root = tmpRepo();
229
- const woke = [];
230
- const fetchImpl = fakeFetch([
231
- streamResponse([
232
- EV(20),
233
- "{not json at all", // unparseable
234
- JSON.stringify({ seq: "banana", family: "messaging" }), // non-numeric seq
235
- JSON.stringify({ type: "event", nope: true }), // claims event, isn't
236
- "[1,2,3]", // array, not a frame
237
- EV(21),
238
- ]),
239
- ]);
240
- const { handle, ctx } = await mkHandle(root, { fetchImpl, wakeCoalesceMs: 0, minHealthyMs: 0, enqueueTick: (t) => woke.push(t) });
241
-
242
- let delay;
243
- await assert.doesNotReject(async () => { delay = await _internals.ladderStep(ctx); });
244
- await flush();
245
-
246
- assert.equal(ctx.cursor, 21, "the good frame AFTER the garbage was still delivered");
247
- assert.equal(woke.length, 2, "exactly the two valid events woke anything");
248
- assert.ok(ctx.stats.malformed >= 3, `malformed frames were counted, not thrown (${ctx.stats.malformed})`);
249
- assert.equal(ctx.rung, PUSH_RUNG.STREAM, "garbage does not cost us the rung");
250
- assert.equal(delay, 0, "and does not cost us the connection either — we reconnect at once");
251
- handle.stop();
252
- });
253
-
254
- test("stream rung: a throwing wake handler never breaks the loop or the cursor", async () => {
255
- const root = tmpRepo();
256
- const fetchImpl = fakeFetch([streamResponse([EV(30), EV(31)])]);
257
- const { handle, ctx } = await mkHandle(root, {
258
- fetchImpl,
259
- wakeCoalesceMs: 0,
260
- wake: { "org-messaging": () => { throw new Error("boom"); } },
261
- });
262
- await assert.doesNotReject(async () => { await _internals.ladderStep(ctx); });
263
- assert.equal(ctx.cursor, 31, "hints advance even when the wake fails — the cadence is the backstop");
264
- handle.stop();
265
- });
266
-
267
- // ---------------------------------------------------------------------------
268
- // Resume — the whole point of keying off CohortEvent.seq
269
- // ---------------------------------------------------------------------------
270
-
271
- test("resume after a disconnect loses nothing and re-delivers nothing", async () => {
272
- const root = tmpRepo();
273
- const woke = [];
274
- const fetchImpl = fakeFetch([
275
- // Connection 1 dies after seq 7.
276
- streamResponse([EV(5), EV(6), EV(7)]),
277
- // Connection 2: hq replays 6 and 7 (overlap is by design), then 8, 9, 10.
278
- streamResponse([EV(6), EV(7), EV(8), EV(9), EV(10)]),
279
- ]);
280
- const { handle, ctx } = await mkHandle(root, { fetchImpl, wakeCoalesceMs: 0, enqueueTick: (t) => woke.push(t) });
281
-
282
- await _internals.ladderStep(ctx);
283
- await flush();
284
- assert.equal(ctx.cursor, 7);
285
- assert.equal(readCursor(root), 7, "the cursor is on disk before the reconnect");
286
-
287
- await _internals.ladderStep(ctx);
288
- await flush();
289
-
290
- const url2 = fetchImpl.calls[1].url;
291
- assert.match(url2, /cursor=7/, "the reconnect resumes FROM the persisted watermark");
292
- assert.equal(ctx.cursor, 10, "nothing after the drop was lost");
293
- const seqs = woke.map((w) => w.metadata.pushSeq);
294
- assert.deepEqual(seqs, [5, 6, 7, 8, 9, 10], "the overlap was deduped: every seq woke exactly once");
295
- assert.ok(ctx.stats.duplicate >= 2, "the replayed frames were counted as duplicates, not delivered twice");
296
- handle.stop();
297
- });
298
-
299
- test("a fresh agent bootstraps at HEAD — it never asks for cursor=0", async () => {
300
- const root = tmpRepo();
301
- const fetchImpl = fakeFetch([streamResponse([])]);
302
- const { handle, ctx } = await mkHandle(root, { fetchImpl });
303
- await _internals.ladderStep(ctx);
304
- assert.equal(fetchImpl.calls[0].url.includes("cursor="), false,
305
- "no cursor param on a first run — cursor=0 would replay the whole org ledger");
306
- handle.stop();
307
- });
308
-
309
- test("a corrupt cursor file reads as absent (bootstrap at head), never throws", () => {
310
- const root = tmpRepo();
311
- mkdirSync(join(root, "state", "org"), { recursive: true });
312
- writeFileSync(join(root, CURSOR_RELATIVE), "{{{ not json");
313
- assert.equal(readCursor(root), null);
314
- writeFileSync(join(root, CURSOR_RELATIVE), JSON.stringify({ cursor: 0 }));
315
- assert.equal(readCursor(root), null, "0 is corrupt, not a cursor");
316
- writeCursor(root, 42);
317
- assert.equal(readCursor(root), 42);
318
- });
319
-
320
- // ---------------------------------------------------------------------------
321
- // The ladder
322
- // ---------------------------------------------------------------------------
323
-
324
- test("ladder: repeated stream failures demote to the long-poll, which then delivers", async () => {
325
- const root = tmpRepo();
326
- const woke = [];
327
- const fetchImpl = fakeFetch([
328
- new Error("ECONNRESET"),
329
- new Error("ECONNRESET"),
330
- new Error("ECONNRESET"),
331
- ]);
332
- const client = fakeClient({
333
- calls: [{ ok: true, status: 200, result: { items: [JSON.parse(EV(100)), JSON.parse(EV(101))], cursor: 101, timedOut: false } }],
334
- });
335
- const { handle, ctx } = await mkHandle(root, {
336
- fetchImpl, client, wakeCoalesceMs: 0, enqueueTick: (t) => woke.push(t),
337
- demoteAfter: 3, baseBackoffMs: 10, maxBackoffMs: 100,
338
- });
339
-
340
- const d1 = await _internals.ladderStep(ctx);
341
- assert.equal(ctx.rung, PUSH_RUNG.STREAM, "one failure is not a demotion");
342
- assert.ok(d1 > 0, "a failed attempt backs off before retrying");
343
- await _internals.ladderStep(ctx);
344
- assert.equal(ctx.rung, PUSH_RUNG.STREAM);
345
- const d3 = await _internals.ladderStep(ctx);
346
- assert.equal(ctx.rung, PUSH_RUNG.LONGPOLL, "3 consecutive failures demote one rung");
347
- assert.equal(d3, 0, "a demotion retries on the new rung at once");
348
-
349
- await _internals.ladderStep(ctx);
350
- await flush();
351
- assert.equal(client.callCalls.length, 1, "the long-poll lane took over");
352
- assert.equal(client.readCalls.length, 0, "agent.wait is a POST method — the GET read lane has no handler for it and 404s");
353
- assert.equal(client.callCalls[0].method, "agent.wait");
354
- assert.equal(client.callCalls[0].params.timeoutMs, 25_000, "hq caps agent.wait at 25s (MAX_WAIT_MS); asking for 55s only makes our abort budget wrong");
355
- assert.equal(ctx.cursor, 101);
356
- assert.deepEqual(woke.map((w) => w.metadata.pushSeq), [100, 101]);
357
- handle.stop();
358
- });
359
-
360
- test("ladder: repeated long-poll failures demote to CADENCE, which idles instead of hammering", async () => {
361
- const root = tmpRepo();
362
- const client = fakeClient({
363
- calls: [
364
- { ok: false, status: 500, error: { code: "INTERNAL" } },
365
- { ok: false, status: 500, error: { code: "INTERNAL" } },
366
- { ok: false, status: 0, error: { code: "INTERNAL" } },
367
- ],
368
- });
369
- let clock = 1_000;
370
- const { handle, ctx } = await mkHandle(root, {
371
- client, now: () => clock, startRung: PUSH_RUNG.LONGPOLL,
372
- demoteAfter: 3, baseBackoffMs: 10, maxBackoffMs: 50, promoteAfterMs: 60_000,
373
- });
374
-
375
- await _internals.ladderStep(ctx);
376
- await _internals.ladderStep(ctx);
377
- await _internals.ladderStep(ctx);
378
- assert.equal(ctx.rung, PUSH_RUNG.CADENCE, "the floor of the ladder");
379
-
380
- const before = client.callCalls.length;
381
- const delay = await _internals.ladderStep(ctx);
382
- assert.equal(client.callCalls.length, before, "the cadence rung issues NO requests — it is the 45s poll doing the work");
383
- assert.ok(delay >= 1_000, "it sleeps out the dwell rather than spinning");
384
-
385
- // The status file must say, out loud, which lane the agent is on.
386
- const status = JSON.parse(readFileSync(join(root, STATUS_RELATIVE), "utf8"));
387
- assert.equal(status.rung, PUSH_RUNG.CADENCE);
388
- assert.equal(status.cadenceFallbackActive, true, "the safety net is never switched off");
389
- handle.stop();
390
- });
391
-
392
- test("ladder: a lower rung is probed back up to the stream after the dwell period", async () => {
393
- const root = tmpRepo();
394
- let clock = 1_000;
395
- const fetchImpl = fakeFetch([streamResponse([EV(70)])]);
396
- const { handle, ctx } = await mkHandle(root, {
397
- fetchImpl, now: () => clock, startRung: PUSH_RUNG.CADENCE, promoteAfterMs: 60_000, wakeCoalesceMs: 0,
398
- enqueueTick: () => {},
399
- });
400
- ctx.rungSinceMs = clock;
401
-
402
- await _internals.ladderStep(ctx);
403
- assert.equal(ctx.rung, PUSH_RUNG.CADENCE, "still inside the dwell window");
404
-
405
- clock += 60_001;
406
- await _internals.ladderStep(ctx);
407
- assert.equal(ctx.rung, PUSH_RUNG.STREAM, "an hq deploy must not strand the agent on the slow lane forever");
408
- assert.equal(ctx.cursor, 70, "and the probe immediately delivered");
409
- handle.stop();
410
- });
411
-
412
- test("ladder: a 404 (hq has no such endpoint) demotes INSTANTLY, with no retries and no backoff", async () => {
413
- const root = tmpRepo();
414
- const fetchImpl = fakeFetch([{ status: 404, body: null }]);
415
- const client = fakeClient({ calls: [{ ok: false, status: 404, error: { code: "NOT_FOUND" } }] });
416
- const { handle, ctx } = await mkHandle(root, { fetchImpl, client, demoteAfter: 3 });
417
-
418
- const d1 = await _internals.ladderStep(ctx);
419
- assert.equal(ctx.rung, PUSH_RUNG.LONGPOLL, "one 404 is enough — retrying an absent endpoint is pointless");
420
- assert.equal(d1, 0);
421
- assert.equal(fetchImpl.calls.length, 1, "an SDK ahead of the server must not hammer it");
422
-
423
- const d2 = await _internals.ladderStep(ctx);
424
- assert.equal(ctx.rung, PUSH_RUNG.CADENCE, "no wait lane either → straight to the cadence backstop");
425
- assert.equal(d2, 0);
426
- handle.stop();
427
- });
428
-
429
- test("ladder: a 401 is reported as a credential problem, not a transport blip", async () => {
430
- const root = tmpRepo();
431
- const fetchImpl = fakeFetch([{ status: 401, body: null }]);
432
- const warnings = [];
433
- const realWarn = console.warn;
434
- console.warn = (...a) => warnings.push(a.join(" "));
435
- try {
436
- const { handle, ctx } = await mkHandle(root, { fetchImpl, baseBackoffMs: 5 });
437
- await _internals.ladderStep(ctx);
438
- handle.stop();
439
- } finally {
440
- console.warn = realWarn;
441
- }
442
- const warned = warnings.join("\n");
443
- assert.match(warned, /http 401/);
444
- assert.match(warned, /COHORT_API_KEY/, "an auth failure must name the likely cause");
445
- assert.match(warned, /45s messaging-inbound cadence/, "and must say the agent is still covered");
446
- });
447
-
448
- test("a scheduled stream recycle is a success, not a failure (it must not demote us)", async () => {
449
- const root = tmpRepo();
450
- const ref = {};
451
- let clock = 1_000;
452
- // The 15-minute recycle aborts the read, which surfaces as a THROW out of the
453
- // body iterator — exactly how a real failure surfaces. Classifying the two
454
- // apart is the difference between "healthy long-lived channel" and "an agent
455
- // that demotes itself to the slow lane every quarter of an hour".
456
- const fetchImpl = fakeFetch([
457
- () => ({
458
- status: 200,
459
- body: (async function* () {
460
- yield `${EV(200)}\n`;
461
- clock += 15 * 60_000;
462
- ref.ctx.streamAbortReason = "max-hold";
463
- throw new Error("The operation was aborted");
464
- })(),
465
- }),
466
- ]);
467
- const { handle, ctx } = await mkHandle(root, { fetchImpl, now: () => clock, wakeCoalesceMs: 0, enqueueTick: () => {}, demoteAfter: 2 });
468
- ref.ctx = ctx;
469
-
470
- const delay = await _internals.ladderStep(ctx);
471
- assert.equal(ctx.rung, PUSH_RUNG.STREAM, "a recycle keeps the preferred rung");
472
- assert.equal(ctx.failures, 0, "and spends none of the failure budget");
473
- assert.equal(ctx.cursor, 200, "everything read before the recycle still counted");
474
- assert.equal(delay, 0, "reconnect immediately");
475
- handle.stop();
476
- });
477
-
478
- // ---------------------------------------------------------------------------
479
- // Backoff
480
- // ---------------------------------------------------------------------------
481
-
482
- test("backoff: jittered, growing, bounded — and never zero against a down server", async () => {
483
- const root = tmpRepo();
484
- const fetchImpl = fakeFetch([
485
- new Error("down"), new Error("down"), new Error("down"), new Error("down"),
486
- new Error("down"), new Error("down"), new Error("down"), new Error("down"),
487
- ]);
488
- // rng() = 1 picks the top of each decorrelated window → the growth is visible
489
- // and deterministic; the module still uses Math.random in production.
490
- const { handle, ctx } = await mkHandle(root, {
491
- fetchImpl, rng: () => 0.999999, demoteAfter: 99, baseBackoffMs: 100, maxBackoffMs: 1_000, backoffFactor: 3,
492
- });
493
-
494
- const delays = [];
495
- for (let i = 0; i < 6; i += 1) delays.push(await _internals.ladderStep(ctx));
496
-
497
- assert.ok(delays.every((d) => d >= 100), `never hammers: every delay >= base (${delays})`);
498
- assert.ok(delays.every((d) => d <= 1_000), `bounded by max (${delays})`);
499
- assert.ok(delays[1] > delays[0], `backs off progressively (${delays})`);
500
- assert.equal(delays[delays.length - 1], 1_000, "and saturates at the ceiling rather than growing forever");
501
-
502
- // Same failures, a different RNG → different delays. That is the anti-lockstep
503
- // property: a fleet of agents must not all retry a struggling hq in unison.
504
- const root2 = tmpRepo();
505
- const f2 = fakeFetch([new Error("down"), new Error("down"), new Error("down")]);
506
- const { handle: h2, ctx: c2 } = await mkHandle(root2, {
507
- fetchImpl: f2, rng: () => 0.0, demoteAfter: 99, baseBackoffMs: 100, maxBackoffMs: 1_000, backoffFactor: 3,
508
- });
509
- const lowJitter = [];
510
- for (let i = 0; i < 3; i += 1) lowJitter.push(await _internals.ladderStep(c2));
511
- assert.notDeepEqual(lowJitter, delays.slice(0, 3), "jitter actually varies the schedule");
512
-
513
- handle.stop();
514
- h2.stop();
515
- });
516
-
517
- test("a stream that dies instantly is rate-limited by the base backoff (no hot spin)", async () => {
518
- const root = tmpRepo();
519
- let clock = 5_000;
520
- // A 200 that closes at once: 'ok' (clean EOF) but suspiciously short-lived.
521
- const fetchImpl = fakeFetch([streamResponse([])]);
522
- const { handle, ctx } = await mkHandle(root, { fetchImpl, now: () => clock, baseBackoffMs: 250, minHealthyMs: 2_000 });
523
- const delay = await _internals.ladderStep(ctx);
524
- assert.equal(delay, 250, "an instantly-closing stream must not become a reconnect storm");
525
- handle.stop();
526
- });
527
-
528
- test("a long-poll that answers INSTANTLY with nothing is floored, not spun", async () => {
529
- const root = tmpRepo();
530
- // A half-implemented (or proxy-terminated) agent.wait that returns at once
531
- // instead of holding would otherwise re-arm at wire speed against hq.
532
- let clock = 7_000;
533
- const client = fakeClient({ calls: [{ ok: true, status: 200, result: { items: [], cursor: null, timedOut: true } }] });
534
- const { handle, ctx } = await mkHandle(root, {
535
- client, now: () => clock, startRung: PUSH_RUNG.LONGPOLL, baseBackoffMs: 750, minHealthyMs: 2_000,
536
- });
537
- const delay = await _internals.ladderStep(ctx);
538
- assert.equal(delay, 750, "an instant empty answer is rate-limited");
539
- assert.equal(ctx.rung, PUSH_RUNG.LONGPOLL, "but it is a SUCCESS, not a failure — no demotion");
540
- handle.stop();
541
- });
542
-
543
- // ---------------------------------------------------------------------------
544
- // Wake semantics
545
- // ---------------------------------------------------------------------------
546
-
547
- test("a burst is coalesced into one wake, with a trailing wake for the tail", async () => {
548
- const root = tmpRepo();
549
- const woke = [];
550
- const timers = inertTimers();
551
- let clock = 10_000;
552
- const fetchImpl = fakeFetch([streamResponse([EV(1), EV(2), EV(3), EV(4)])]);
553
- const handle = await connectOrgPush({
554
- agentRoot: root, cfg: cfgEnabled(), client: fakeClient(), fetchImpl,
555
- setTimeout: timers.setTimeout, clearTimeout: timers.clearTimeout, now: () => clock,
556
- wakeCoalesceMs: 1_500, enqueueTick: (t) => woke.push(t),
557
- });
558
- const ctx = handle._ctx;
559
-
560
- await _internals.ladderStep(ctx);
561
- await flush(); // wake handlers resolve on a microtask
562
-
563
- assert.equal(woke.length, 1, "40 messages in a channel are ONE thing to go look at");
564
- assert.equal(woke[0].metadata.pushSeq, 1, "the leading edge fires instantly — that is the product promise");
565
-
566
- // The trailing wake was scheduled for the end of the window; fire it.
567
- const trailing = timers.scheduled.filter((t) => t.ms > 0 && t.ms <= 1_500);
568
- assert.equal(trailing.length, 1, "exactly one trailing timer, not one per event");
569
- clock += 1_500;
570
- trailing[0].fn();
571
- await flush();
572
-
573
- assert.equal(woke.length, 2, "the tail of the burst is never stranded until the 45s cadence");
574
- assert.equal(woke[1].metadata.pushSeq, 4, "the trailing wake carries the newest seq");
575
- handle.stop();
576
- });
577
-
578
- test("relevance: unknown families are consumed (cursor advances) but wake nothing", async () => {
579
- const root = tmpRepo();
580
- const woke = [];
581
- const fetchImpl = fakeFetch([
582
- streamResponse([
583
- JSON.stringify({ seq: 50, family: "cost", kind: "report" }),
584
- JSON.stringify({ seq: 51, family: "policy", kind: "publish" }),
585
- EV(52),
586
- ]),
587
- ]);
588
- const { handle, ctx } = await mkHandle(root, { fetchImpl, wakeCoalesceMs: 0, enqueueTick: (t) => woke.push(t) });
589
- await _internals.ladderStep(ctx);
590
- await flush();
591
- assert.equal(ctx.cursor, 52, "irrelevant events are still consumed — otherwise they replay forever");
592
- assert.equal(woke.length, 1);
593
- assert.equal(woke[0].metadata.pushSeq, 52);
594
- handle.stop();
595
- });
596
-
597
- test("relevance: our own action echoing back does not wake us; an unproven event still does", async () => {
598
- const root = tmpRepo();
599
- const woke = [];
600
- const fetchImpl = fakeFetch([
601
- streamResponse([
602
- JSON.stringify({ seq: 60, family: "messaging", kind: "send", actor: "alex-ai" }), // us
603
- JSON.stringify({ seq: 61, family: "email", kind: "received", payload: { memberId: "someone-else" } }),
604
- JSON.stringify({ seq: 62, family: "messaging", kind: "send", actor: "human-1" }),
605
- ]),
606
- ]);
607
- const { handle, ctx } = await mkHandle(root, {
608
- fetchImpl, wakeCoalesceMs: 0, selfIds: ["alex-ai"], enqueueTick: (t) => woke.push(t),
609
- });
610
- await _internals.ladderStep(ctx);
611
- await flush();
612
- assert.deepEqual(woke.map((w) => w.metadata.pushSeq), [62],
613
- "only the event we cannot rule out — the frame can never PROVE an event is ours");
614
- handle.stop();
615
- });
616
-
617
- test("a target with no default fetcher degrades quietly to its own poll (no throw, no tick)", async () => {
618
- const root = tmpRepo();
619
- const woke = [];
620
- const fetchImpl = fakeFetch([streamResponse([JSON.stringify({ seq: 80, family: "email", kind: "received" })])]);
621
- const { handle, ctx } = await mkHandle(root, { fetchImpl, wakeCoalesceMs: 0, enqueueTick: (t) => woke.push(t) });
622
- await assert.doesNotReject(async () => { await _internals.ladderStep(ctx); });
623
- await flush();
624
- assert.equal(woke.length, 0, "no cadence exists for orgmail — its adapter's own 45s poll stays the fetcher");
625
- assert.equal(ctx.cursor, 80);
626
- handle.stop();
627
- });
628
-
629
- test("onEvent observer sees every accepted event and cannot break the channel", async () => {
630
- const root = tmpRepo();
631
- const seen = [];
632
- const fetchImpl = fakeFetch([streamResponse([EV(90), EV(91)])]);
633
- const { handle, ctx } = await mkHandle(root, {
634
- fetchImpl, wakeCoalesceMs: 0, enqueueTick: () => {},
635
- onEvent: (e) => { seen.push(e.seq); throw new Error("observer boom"); },
636
- });
637
- await assert.doesNotReject(async () => { await _internals.ladderStep(ctx); });
638
- assert.deepEqual(seen, [90, 91]);
639
- assert.equal(ctx.cursor, 91);
640
- handle.stop();
641
- });
642
-
643
- // ---------------------------------------------------------------------------
644
- // Lifecycle + parsing units
645
- // ---------------------------------------------------------------------------
646
-
647
- test("stop() aborts the in-flight stream, clears timers and is idempotent", async () => {
648
- const root = tmpRepo();
649
- const cleared = [];
650
- let aborted = 0;
651
- const handle = await connectOrgPush({
652
- agentRoot: root, cfg: cfgEnabled(), client: fakeClient(),
653
- setTimeout: (fn, ms) => ({ fn, ms, unref() {} }),
654
- clearTimeout: (h) => cleared.push(h),
655
- });
656
- handle._ctx.abort = { abort: () => { aborted += 1; } };
657
- handle.stop();
658
- handle.stop();
659
- assert.equal(aborted, 1, "the held connection is torn down exactly once");
660
- assert.equal(cleared.length, 1, "the pump timer is cleared exactly once");
661
- assert.equal(handle._ctx.stopped, true);
662
- });
663
-
664
- test("decodeFrameLine: the wire vocabulary", () => {
665
- assert.equal(decodeFrameLine("").kind, "ignore");
666
- assert.equal(decodeFrameLine(": ping").kind, "heartbeat");
667
- assert.equal(decodeFrameLine("event: message").kind, "ignore");
668
- assert.equal(decodeFrameLine("id: 7").kind, "ignore");
669
- assert.equal(decodeFrameLine('{"type":"heartbeat"}').kind, "heartbeat");
670
- assert.equal(decodeFrameLine('{"type":"ready","cursor":9}').cursor, 9);
671
- assert.equal(decodeFrameLine("garbage").kind, "ignore");
672
- assert.equal(decodeFrameLine("{oops").kind, "malformed");
673
- assert.equal(decodeFrameLine('{"type":"event"}').kind, "malformed");
674
- const ev = decodeFrameLine(`data: ${EV(3)}`);
675
- assert.equal(ev.kind, "event");
676
- assert.equal(ev.event.seq, 3);
677
- // hq's own fan-out frame carries no `type` at all — it must still parse.
678
- const bare = decodeFrameLine(JSON.stringify({ seq: 4, family: "artifact", kind: "created" }));
679
- assert.equal(bare.kind, "event");
680
- });
681
-
682
- test("v1Url matches the client's binding rules (bare origin vs /v1-suffixed base)", () => {
683
- assert.equal(_internals.v1Url("https://x.dev", "agent.stream"), "https://x.dev/api/v1/agent.stream");
684
- assert.equal(_internals.v1Url("https://x.dev/api/v1", "agent.stream"), "https://x.dev/api/v1/agent.stream");
685
- assert.equal(_internals.v1Url("https://x.dev/v1/", "agent.wait"), "https://x.dev/v1/agent.wait");
686
- });
687
-
688
- test("the stream carries Bearer auth + the protocol header + the org pin", async () => {
689
- const root = tmpRepo();
690
- const fetchImpl = fakeFetch([streamResponse([])]);
691
- const { handle, ctx } = await mkHandle(root, { fetchImpl });
692
- await _internals.ladderStep(ctx);
693
- const h = fetchImpl.calls[0].init.headers;
694
- assert.equal(h.authorization, "Bearer tok");
695
- assert.equal(h["x-org-id"], "acme");
696
- assert.ok(String(h.accept).includes("text/event-stream"));
697
- assert.ok(String(h.accept).includes("application/x-ndjson"), "both framings are acceptable to us");
698
- handle.stop();
699
- });
700
-
701
- test("housekeeping: tmp roots are removable (no lingering handles)", () => {
702
- const root = tmpRepo();
703
- assert.ok(existsSync(root));
704
- rmSync(root, { recursive: true, force: true });
705
- assert.equal(existsSync(root), false);
706
- });
707
-
708
- // ---------------------------------------------------------------------------
709
- // JOINT 3 — the wire contract, corrected against the DEPLOYED hq
710
- // ---------------------------------------------------------------------------
711
-
712
- test("JOINT 3: the stream path is /api/v1/stream, not /api/v1/agent.stream", async () => {
713
- const root = tmpRepo();
714
- const fetchImpl = fakeFetch([streamResponse([EV(5)])]);
715
- const { handle, ctx } = await mkHandle(root, { fetchImpl, wakeCoalesceMs: 0, minHealthyMs: 0, enqueueTick: () => {} });
716
- await _internals.ladderStep(ctx);
717
- // `agent.stream` resolves to hq's [...method] catch-all, which answers 404 for
718
- // an unknown read — read by the ladder as "endpoint absent" and demoted
719
- // instantly, forever. hq serves the stream as a STATIC route at /api/v1/stream.
720
- assert.match(fetchImpl.calls[0].url, /\/api\/v1\/stream(\?|$)/);
721
- assert.ok(!/agent\.stream/.test(fetchImpl.calls[0].url), "agent.stream is a path that has never existed on hq");
722
- handle.stop();
723
- });
724
-
725
- test("JOINT 3: hq's untyped `cursor` watermark frame advances the resume point", () => {
726
- // These are hq's REAL frames (src/server/agent-stream/sse.ts): no `type`, no
727
- // `seq`, no `family` — the old decoder returned "ignore" for all three, so a
728
- // reconnect re-asked hq to rescan every event that was not this seat's.
729
- assert.deepEqual(decodeFrameLine('data: {"cursor":12766}'), { kind: "cursor", cursor: 12766 });
730
- assert.deepEqual(
731
- decodeFrameLine('data: {"orgId":"o","memberId":"m","cursor":12600,"heartbeatMs":20000,"lifetimeMs":900000}'),
732
- { kind: "cursor", cursor: 12600 },
733
- );
734
- assert.deepEqual(decodeFrameLine('data: {"reason":"lifetime","cursor":13000,"message":"reconnect"}'), { kind: "cursor", cursor: 13000 });
735
- // An event frame is still an event frame — the watermark branch must not eat it.
736
- assert.equal(decodeFrameLine(`data: ${EV(9)}`).kind, "event");
737
- });
738
-
739
- test("JOINT 3: a watermark frame moves the persisted cursor FORWARD ONLY", async () => {
740
- const root = tmpRepo();
741
- const fetchImpl = fakeFetch([
742
- streamResponse([
743
- 'data: {"orgId":"o","memberId":"m","cursor":500}',
744
- EV(501),
745
- 'data: {"cursor":900}', // 399 events that were NOT ours
746
- 'data: {"cursor":400}', // a stale/mis-ordered frame must not rewind us
747
- ]),
748
- ]);
749
- const { handle, ctx } = await mkHandle(root, { fetchImpl, wakeCoalesceMs: 0, minHealthyMs: 0, enqueueTick: () => {} });
750
- await _internals.ladderStep(ctx);
751
- await flush();
752
- assert.equal(ctx.cursor, 900, "the checkpoint past other members' business is honoured");
753
- assert.equal(readCursor(root), 900, "and persisted, so a restart does not rescan it");
754
- handle.stop();
755
- });
756
-
757
- test("JOINT 3: every inbound family wakes the authoritative pull — board included", async () => {
758
- const root = tmpRepo();
759
- const woke = [];
760
- const families = ["messaging", "board", "calendar", "escalation", "approval", "decision", "files", "handoff", "calling"];
761
- const lines = families.map((f, i) => EV(200 + i, f, "x"));
762
- const fetchImpl = fakeFetch([streamResponse(lines)]);
763
- const { handle, ctx } = await mkHandle(root, {
764
- fetchImpl, wakeCoalesceMs: 0, minHealthyMs: 0, enqueueTick: (t) => woke.push(t),
765
- });
766
- await _internals.ladderStep(ctx);
767
- await flush();
768
- assert.equal(woke.length, families.length, `every inbound family must wake something; got ${woke.length}/${families.length}`);
769
- assert.ok(woke.every((w) => w.cadence === "messaging-inbound"), "one nudge, one authoritative ACL'd pull, one cursor");
770
- handle.stop();
771
- });
772
-
773
- test("JOINT 3: a family hq proved is ours but nothing consumes is dropped LOUDLY", async () => {
774
- const root = tmpRepo();
775
- const warns = [];
776
- const realWarn = console.warn;
777
- console.warn = (...a) => warns.push(a.join(" "));
778
- try {
779
- const fetchImpl = fakeFetch([streamResponse([EV(300, "artifact", "action")])]);
780
- const { handle, ctx } = await mkHandle(root, { fetchImpl, wakeCoalesceMs: 0, minHealthyMs: 0, enqueueTick: () => {} });
781
- await _internals.ladderStep(ctx);
782
- await flush();
783
- assert.equal(ctx.cursor, 300, "it is still consumed — not advancing would re-deliver it forever");
784
- assert.ok(
785
- warns.some((w) => /"artifact" frame it had already resolved as THIS SEAT'S/.test(w)),
786
- `a dropped for-me frame must be visible; got ${JSON.stringify(warns)}`,
787
- );
788
- handle.stop();
789
- } finally {
790
- console.warn = realWarn;
791
- }
792
- });