@cohortapp/agent-sdk 2.17.0 → 2.18.5
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.
- package/.claude/settings.json +18 -0
- package/.env.example +18 -5
- package/README.md +1 -0
- package/bin/maestro.mjs +62 -0
- package/docs/guides/billing-console-keys.md +60 -0
- package/docs/guides/front-door-session.md +54 -9
- package/docs/guides/mac-mini.md +20 -25
- package/docs/guides/setup-wizard.md +1 -1
- package/docs/runbooks/fleet-rollout.md +156 -0
- package/docs/runbooks/mac-mini-bootstrap.md +12 -14
- package/lib/action-executor.js +19 -3
- package/lib/budget-guard.mjs +279 -3
- package/lib/channels/base-adapter.mjs +3 -1
- package/lib/channels/contract.mjs +2 -1
- package/lib/channels/inbox-item.mjs +8 -0
- package/lib/claude-bin.mjs +5 -6
- package/lib/cli/doctor-checks.mjs +141 -10
- package/lib/cli/global-setup-extras.mjs +5 -1
- package/lib/cli/inbox.mjs +100 -15
- package/lib/cli/seat-auth.mjs +463 -0
- package/lib/cli/session.mjs +80 -12
- package/lib/collective/capture-slots.mjs +234 -0
- package/lib/collective/capture.mjs +8 -6
- package/lib/collective/config.mjs +2 -0
- package/lib/collective/global-config.mjs +63 -1
- package/lib/collective/loop-guard.mjs +155 -0
- package/lib/collective/presence.mjs +142 -5
- package/lib/comms/send-gate.mjs +559 -1
- package/lib/diagnostics/alerts.mjs +49 -0
- package/lib/diagnostics/cadence-output-freshness.mjs +288 -0
- package/lib/engine/agents/definitions.mjs +343 -0
- package/lib/engine/agents/persist.mjs +275 -0
- package/lib/engine/agents/runtime.mjs +748 -0
- package/lib/engine/agents/usage.mjs +95 -0
- package/lib/engine/auth-status.mjs +139 -0
- package/lib/engine/budget.mjs +194 -0
- package/lib/engine/cli.mjs +1204 -0
- package/lib/engine/commands/index.mjs +269 -0
- package/lib/engine/context/budget.mjs +219 -0
- package/lib/engine/context/cache.mjs +125 -0
- package/lib/engine/context/child-env.mjs +215 -0
- package/lib/engine/context/compaction.mjs +342 -0
- package/lib/engine/context/images.mjs +90 -0
- package/lib/engine/context/instructions.mjs +327 -0
- package/lib/engine/context/lazy-instructions.mjs +169 -0
- package/lib/engine/context/manager.mjs +182 -0
- package/lib/engine/context/real-path.mjs +91 -0
- package/lib/engine/context/secret-values.mjs +163 -0
- package/lib/engine/context/settings.mjs +274 -0
- package/lib/engine/context/stream-input.mjs +159 -0
- package/lib/engine/guard.mjs +152 -0
- package/lib/engine/hooks.mjs +713 -0
- package/lib/engine/loop.mjs +560 -0
- package/lib/engine/mcp/client.mjs +254 -0
- package/lib/engine/mcp/config.mjs +301 -0
- package/lib/engine/mcp/http.mjs +201 -0
- package/lib/engine/mcp/index.mjs +146 -0
- package/lib/engine/mcp/jsonrpc.mjs +147 -0
- package/lib/engine/mcp/naming.mjs +66 -0
- package/lib/engine/mcp/resources.mjs +89 -0
- package/lib/engine/mcp/results.mjs +133 -0
- package/lib/engine/mcp/stdio.mjs +137 -0
- package/lib/engine/mcp/supervisor.mjs +116 -0
- package/lib/engine/messages.mjs +104 -0
- package/lib/engine/output/json.mjs +164 -0
- package/lib/engine/output/stream-json.mjs +266 -0
- package/lib/engine/permissions.mjs +845 -0
- package/lib/engine/process-identity.mjs +164 -0
- package/lib/engine/process-tree.mjs +551 -0
- package/lib/engine/prompt.mjs +60 -0
- package/lib/engine/session/store.mjs +299 -0
- package/lib/engine/session-runtime/args.mjs +97 -0
- package/lib/engine/session-runtime/host.mjs +143 -0
- package/lib/engine/session-runtime/inbox.mjs +122 -0
- package/lib/engine/session-runtime/notifications.mjs +129 -0
- package/lib/engine/session-runtime/registry.mjs +328 -0
- package/lib/engine/session-runtime/runner.mjs +344 -0
- package/lib/engine/session-runtime/socket.mjs +212 -0
- package/lib/engine/session-runtime/wakeup.mjs +115 -0
- package/lib/engine/skills/index.mjs +321 -0
- package/lib/engine/tools/bash-background.mjs +533 -0
- package/lib/engine/tools/bash.mjs +216 -0
- package/lib/engine/tools/edit.mjs +97 -0
- package/lib/engine/tools/glob.mjs +81 -0
- package/lib/engine/tools/grep.mjs +224 -0
- package/lib/engine/tools/index.mjs +84 -0
- package/lib/engine/tools/list-agents.mjs +32 -0
- package/lib/engine/tools/ls.mjs +127 -0
- package/lib/engine/tools/monitor.mjs +82 -0
- package/lib/engine/tools/notebook-edit.mjs +218 -0
- package/lib/engine/tools/read.mjs +103 -0
- package/lib/engine/tools/schedule-wakeup.mjs +45 -0
- package/lib/engine/tools/schema.mjs +144 -0
- package/lib/engine/tools/send-message.mjs +77 -0
- package/lib/engine/tools/session.mjs +70 -0
- package/lib/engine/tools/todo.mjs +144 -0
- package/lib/engine/tools/toolsearch.mjs +217 -0
- package/lib/engine/tools/walk.mjs +193 -0
- package/lib/engine/tools/web-switch.mjs +31 -0
- package/lib/engine/tools/webfetch-html.mjs +387 -0
- package/lib/engine/tools/webfetch-net.mjs +340 -0
- package/lib/engine/tools/webfetch.mjs +198 -0
- package/lib/engine/tools/websearch.mjs +91 -0
- package/lib/engine/tools/workflow.mjs +95 -0
- package/lib/engine/tools/write.mjs +76 -0
- package/lib/engine/tui/line-editor.mjs +137 -0
- package/lib/engine/tui/render.mjs +86 -0
- package/lib/engine/tui/tui.mjs +274 -0
- package/lib/engine/wire/anthropic-messages.mjs +263 -0
- package/lib/engine/wire/effort.mjs +36 -0
- package/lib/engine/wire/errors.mjs +496 -0
- package/lib/engine/wire/http.mjs +441 -0
- package/lib/engine/wire/index.mjs +76 -0
- package/lib/engine/wire/openai-chat.mjs +332 -0
- package/lib/engine/wire/prompt-cache.mjs +79 -0
- package/lib/engine/wire/search.mjs +140 -0
- package/lib/engine/wire/sse.mjs +114 -0
- package/lib/engine/wire/stall.mjs +349 -0
- package/lib/engine/wire/token-provider.mjs +175 -0
- package/lib/engine/wire/usage.mjs +192 -0
- package/lib/engine/workflow/host.mjs +524 -0
- package/lib/engine/workflow/journal.mjs +188 -0
- package/lib/engine/workflow/json-schema.mjs +171 -0
- package/lib/engine/workflow/meta.mjs +329 -0
- package/lib/engine/workflow/notifications.mjs +52 -0
- package/lib/engine/workflow/runtime.mjs +447 -0
- package/lib/engine/workflow/sandbox.mjs +534 -0
- package/lib/engine/workflow/worker.mjs +141 -0
- package/lib/engine/workflow/worktree.mjs +74 -0
- package/lib/execution/disposition.mjs +1 -1
- package/lib/execution/intake.mjs +10 -0
- package/lib/execution/surface-policy.mjs +15 -0
- package/lib/learning/curator.mjs +8 -6
- package/lib/learning/reflect.mjs +8 -6
- package/lib/model-router/catalog/cohort.yaml +137 -0
- package/lib/model-router/catalog.mjs +118 -1
- package/lib/model-router/failover.mjs +67 -16
- package/lib/model-router/llm-task.mjs +39 -3
- package/lib/model-router/resolve.mjs +89 -3
- package/lib/model-router/spawn.mjs +46 -47
- package/lib/model-router/taxonomy.mjs +126 -4
- package/lib/org/cost-sync.mjs +141 -11
- package/lib/org/inbound/broadcast.mjs +289 -0
- package/lib/org/inbound/collective.mjs +375 -0
- package/lib/org/inbound/directedness.mjs +96 -8
- package/lib/org/inbound/facts.mjs +78 -2
- package/lib/org/inbound/project.mjs +22 -0
- package/lib/org/inbound/surfaces.mjs +14 -0
- package/lib/org/llm-token.mjs +879 -0
- package/lib/org/mesh.mjs +61 -0
- package/lib/org/messaging.mjs +3 -1
- package/lib/org/protocol.checksum +1 -1
- package/lib/org/protocol.mjs +15 -0
- package/lib/org/quota.mjs +520 -0
- package/lib/org/tool-surface.mjs +104 -16
- package/lib/org/ui-parity.mjs +16 -1
- package/lib/org/work-ledger.mjs +37 -6
- package/lib/rate-guard.mjs +114 -1
- package/lib/resource-governor.mjs +41 -6
- package/lib/runtime/adapter.mjs +833 -0
- package/lib/runtime/child-env.mjs +191 -0
- package/lib/runtime/legacy-shell-guard.mjs +97 -0
- package/lib/runtime/seat-engine.mjs +162 -0
- package/lib/session/ask-ledger.mjs +271 -0
- package/lib/session/current-work.mjs +676 -0
- package/lib/session/feed-core.mjs +40 -3
- package/lib/session/launch-args.mjs +56 -4
- package/lib/session/status-summary.mjs +26 -9
- package/lib/session/upgrade-notice.mjs +42 -0
- package/lib/setup/claude-probe.mjs +117 -13
- package/lib/setup/enrich.mjs +13 -10
- package/lib/setup/sections/model.mjs +39 -13
- package/lib/telemetry/collect.mjs +229 -11
- package/lib/upgrade/ignored-drift.mjs +105 -0
- package/lib/voice/post-call-brief.mjs +30 -17
- package/package.json +13 -3
- package/plugins/maestro-skills/skills/board-work.md +5 -0
- package/plugins/maestro-skills/skills/inbound-triage.md +56 -15
- package/plugins/maestro-skills/skills/main-session.md +18 -7
- package/scaffold/config/collective.yaml +7 -0
- package/scripts/ci/check-durable-write-seam.mjs +3 -1
- package/scripts/ci/check-tarball-fidelity.mjs +126 -2
- package/scripts/ci/run-tests.mjs +47 -19
- package/scripts/cohort-llm/api-key-helper.mjs +92 -0
- package/scripts/collective/hook-runner.mjs +142 -19
- package/scripts/continuous-monitor.sh +13 -0
- package/scripts/cost/track-claude-usage.mjs +15 -0
- package/scripts/daemon/agent-daemon.mjs +408 -20
- package/scripts/daemon/assurance.mjs +48 -12
- package/scripts/daemon/cadence-consumer.mjs +218 -68
- package/scripts/daemon/cadence-handlers.mjs +73 -4
- package/scripts/daemon/classifier.mjs +75 -26
- package/scripts/daemon/context-compiler.mjs +51 -37
- package/scripts/daemon/deliver.mjs +30 -1
- package/scripts/daemon/dispatcher.mjs +595 -149
- package/scripts/daemon/health.mjs +14 -1
- package/scripts/daemon/maestro-daemon.mjs +11 -0
- package/scripts/daemon/prompt-builder.mjs +24 -0
- package/scripts/daemon/responder.mjs +246 -79
- package/scripts/daemon/sdk-version.mjs +98 -16
- package/scripts/eval/probe-gateway.mjs +635 -0
- package/scripts/eval/replay/extract.mjs +270 -0
- package/scripts/eval/replay/grade.mjs +260 -0
- package/scripts/eval/replay/lib/config.mjs +50 -0
- package/scripts/eval/replay/lib/effects.mjs +65 -0
- package/scripts/eval/replay/lib/fixture.mjs +188 -0
- package/scripts/eval/replay/lib/judge.mjs +72 -0
- package/scripts/eval/replay/lib/redact.mjs +136 -0
- package/scripts/eval/replay/lib/sandbox.mjs +170 -0
- package/scripts/eval/replay/lib/schema-check.mjs +63 -0
- package/scripts/eval/replay/lib/transcript.mjs +76 -0
- package/scripts/eval/replay/mcp-replay-stub.mjs +101 -0
- package/scripts/eval/replay/report.mjs +185 -0
- package/scripts/eval/replay/run.mjs +404 -0
- package/scripts/fleet/rollout.mjs +1151 -0
- package/scripts/hooks/pre-send-audit.sh +36 -245
- package/scripts/hooks/pre-write-yaml-validate.mjs +275 -0
- package/scripts/hooks/validate-state-yaml.sh +190 -0
- package/scripts/huddle/huddle-llm.mjs +361 -0
- package/scripts/huddle/huddle-server.mjs +46 -121
- package/scripts/local-triggers/autoupdate.sh +465 -81
- package/scripts/local-triggers/run-trigger.sh +13 -0
- package/scripts/maintenance/pin-integrity.mjs +364 -0
- package/scripts/poll-slack-events.sh +41 -9
- package/scripts/poller/slack-socket-mode.mjs +28 -3
- package/scripts/session/supervisor.mjs +80 -13
- package/scripts/spawn-session.sh +13 -0
- package/bin/maestro.test.mjs +0 -1574
- package/lib/action-executor.test.mjs +0 -871
- package/lib/archetype.test.mjs +0 -132
- package/lib/assurance/plan-note.test.mjs +0 -234
- package/lib/assurance/room-budget.test.mjs +0 -486
- package/lib/assurance/tier.test.mjs +0 -174
- package/lib/autonomy.test.mjs +0 -66
- package/lib/backlog.test.mjs +0 -302
- package/lib/backup/policy.test.mjs +0 -305
- package/lib/budget-escalate.test.mjs +0 -232
- package/lib/budget-guard.envelope.test.mjs +0 -476
- package/lib/budget-guard.test.mjs +0 -427
- package/lib/cadence-bus-requeue.test.mjs +0 -83
- package/lib/cadence-bus-schedule.test.mjs +0 -194
- package/lib/cadence-bus.test.mjs +0 -720
- package/lib/cadences.test.mjs +0 -230
- package/lib/capability/inventory.test.mjs +0 -232
- package/lib/capability.test.mjs +0 -78
- package/lib/channels/base-adapter.test.mjs +0 -590
- package/lib/channels/channels.test.mjs +0 -371
- package/lib/channels/contract.test.mjs +0 -162
- package/lib/channels/inbox-item.test.mjs +0 -368
- package/lib/channels/orgmail/adapter.test.mjs +0 -448
- package/lib/channels/pairing.test.mjs +0 -270
- package/lib/channels/repeat-suppressor.test.mjs +0 -134
- package/lib/channels/slack-adapter.test.mjs +0 -212
- package/lib/channels/telegram-adapter.test.mjs +0 -306
- package/lib/channels/voice/adapter.test.mjs +0 -278
- package/lib/channels/whatsapp/adapter-baileys.test.mjs +0 -359
- package/lib/channels/whatsapp/baileys-typing.test.mjs +0 -154
- package/lib/charter.test.mjs +0 -89
- package/lib/claude-bin.test.mjs +0 -131
- package/lib/cli/board.test.mjs +0 -227
- package/lib/cli/design.test.mjs +0 -270
- package/lib/cli/doctor-checks.test.mjs +0 -336
- package/lib/cli/global-setup-extras.test.mjs +0 -462
- package/lib/cli/inbox.test.mjs +0 -230
- package/lib/cli/session-ack.test.mjs +0 -63
- package/lib/cli/session.test.mjs +0 -613
- package/lib/collective/capture.test.mjs +0 -121
- package/lib/collective/cards.test.mjs +0 -114
- package/lib/collective/config.test.mjs +0 -123
- package/lib/collective/global-config.test.mjs +0 -220
- package/lib/collective/global-skills.test.mjs +0 -126
- package/lib/collective/presence.test.mjs +0 -95
- package/lib/collective/recall.test.mjs +0 -116
- package/lib/collective/vendor-skills.test.mjs +0 -306
- package/lib/comms/send-gate.test.mjs +0 -770
- package/lib/comms.test.mjs +0 -41
- package/lib/context/budget.test.mjs +0 -252
- package/lib/context/history-scope.test.mjs +0 -79
- package/lib/cost/ledger-row.test.mjs +0 -183
- package/lib/design/design-md.test.mjs +0 -318
- package/lib/design/fixtures/DESIGN.golden.md +0 -238
- package/lib/design/fixtures/PRODUCT.golden.md +0 -67
- package/lib/design/fixtures/foundation.json +0 -133
- package/lib/design/refresh-gate.test.mjs +0 -144
- package/lib/design/write.test.mjs +0 -241
- package/lib/diagnostics/alerts.test.mjs +0 -318
- package/lib/diagnostics/backup-freshness.test.mjs +0 -185
- package/lib/diagnostics/counters.test.mjs +0 -206
- package/lib/diagnostics/events.test.mjs +0 -290
- package/lib/diagnostics/otel.test.mjs +0 -196
- package/lib/diagnostics/trace.test.mjs +0 -251
- package/lib/env-compat.test.mjs +0 -104
- package/lib/execution/disposition.test.mjs +0 -553
- package/lib/execution/drive.test.mjs +0 -270
- package/lib/execution/effects.test.mjs +0 -344
- package/lib/execution/intake.test.mjs +0 -389
- package/lib/execution/journal.test.mjs +0 -261
- package/lib/execution/match.test.mjs +0 -235
- package/lib/execution/pipeline.test.mjs +0 -392
- package/lib/execution/route.test.mjs +0 -186
- package/lib/execution/surface-policy.test.mjs +0 -162
- package/lib/fs-atomic.test.mjs +0 -72
- package/lib/fs-ownership.test.mjs +0 -158
- package/lib/goals/admission.test.mjs +0 -164
- package/lib/goals/classify.test.mjs +0 -167
- package/lib/goals/collaborate.test.mjs +0 -336
- package/lib/goals/gaps.test.mjs +0 -284
- package/lib/goals/loop.test.mjs +0 -845
- package/lib/hooks/bus.test.mjs +0 -387
- package/lib/identity/persona.test.mjs +0 -142
- package/lib/kpi-sensors.test.mjs +0 -278
- package/lib/kpi.test.mjs +0 -244
- package/lib/learning/config.test.mjs +0 -75
- package/lib/learning/counters.test.mjs +0 -69
- package/lib/learning/curator-consolidate.test.mjs +0 -238
- package/lib/learning/curator.test.mjs +0 -106
- package/lib/learning/reflect.test.mjs +0 -0
- package/lib/learning/session-index.test.mjs +0 -125
- package/lib/learning/skill-writer.test.mjs +0 -210
- package/lib/mandate/audit.test.mjs +0 -195
- package/lib/mandate/contract.test.mjs +0 -185
- package/lib/mandate/derive.test.mjs +0 -274
- package/lib/mandate/model.test.mjs +0 -164
- package/lib/mandate/refresh.test.mjs +0 -389
- package/lib/mcp/server.test.mjs +0 -426
- package/lib/model-router/auth-profiles.test.mjs +0 -580
- package/lib/model-router/catalog.test.mjs +0 -385
- package/lib/model-router/economics.test.mjs +0 -438
- package/lib/model-router/failover.test.mjs +0 -439
- package/lib/model-router/health.test.mjs +0 -338
- package/lib/model-router/integration-coverage.test.mjs +0 -831
- package/lib/model-router/integration.test.mjs +0 -564
- package/lib/model-router/ledger.test.mjs +0 -415
- package/lib/model-router/llm-task.test.mjs +0 -392
- package/lib/model-router/org-credentials.test.mjs +0 -265
- package/lib/model-router/pricing-refresh.test.mjs +0 -286
- package/lib/model-router/reconcile.test.mjs +0 -316
- package/lib/model-router/repair.test.mjs +0 -180
- package/lib/model-router/spawn.test.mjs +0 -446
- package/lib/model-router/taxonomy.test.mjs +0 -410
- package/lib/model-router.test.mjs +0 -1207
- package/lib/org/activity.test.mjs +0 -134
- package/lib/org/approvals.test.mjs +0 -216
- package/lib/org/awareness.test.mjs +0 -159
- package/lib/org/board-mine-cache.test.mjs +0 -53
- package/lib/org/board.test.mjs +0 -187
- package/lib/org/bootstrap-context.test.mjs +0 -153
- package/lib/org/client.test.mjs +0 -1206
- package/lib/org/cohort-client.test.mjs +0 -126
- package/lib/org/cost-sync.test.mjs +0 -153
- package/lib/org/doctor.test.mjs +0 -346
- package/lib/org/engagement-ledger.test.mjs +0 -112
- package/lib/org/engagement.test.mjs +0 -739
- package/lib/org/handoff.test.mjs +0 -269
- package/lib/org/inbound/directedness.test.mjs +0 -668
- package/lib/org/inbound/facts.test.mjs +0 -471
- package/lib/org/inbound/hydrate.test.mjs +0 -908
- package/lib/org/inbound/index.test.mjs +0 -429
- package/lib/org/inbound/project.test.mjs +0 -287
- package/lib/org/integration-tools.test.mjs +0 -160
- package/lib/org/keys.test.mjs +0 -92
- package/lib/org/knowledge.test.mjs +0 -326
- package/lib/org/leases.test.mjs +0 -235
- package/lib/org/mesh-directives.test.mjs +0 -110
- package/lib/org/mesh-integration.test.mjs +0 -127
- package/lib/org/mesh.test.mjs +0 -400
- package/lib/org/messaging.test.mjs +0 -471
- package/lib/org/param-contract.test.mjs +0 -477
- package/lib/org/policy.test.mjs +0 -237
- package/lib/org/protocol.checksum.test.mjs +0 -90
- package/lib/org/protocol.test.mjs +0 -323
- package/lib/org/push.test.mjs +0 -792
- package/lib/org/registry.test.mjs +0 -100
- package/lib/org/resource-tools.test.mjs +0 -361
- package/lib/org/tool-access.test.mjs +0 -144
- package/lib/org/tool-surface-integration.test.mjs +0 -120
- package/lib/org/tool-surface.test.mjs +0 -1268
- package/lib/org/typing.test.mjs +0 -291
- package/lib/org/ui-parity.test.mjs +0 -560
- package/lib/org/verify.test.mjs +0 -194
- package/lib/org/work-ledger.test.mjs +0 -273
- package/lib/plan/adoption-e2e.test.mjs +0 -366
- package/lib/plan/budget-enforcement.test.mjs +0 -400
- package/lib/plan/compile.test.mjs +0 -382
- package/lib/plan/emit.test.mjs +0 -269
- package/lib/plan/explain.test.mjs +0 -188
- package/lib/prompts/parallelism.test.mjs +0 -177
- package/lib/rag/rag.test.mjs +0 -505
- package/lib/rate-guard.test.mjs +0 -272
- package/lib/reactive-gate.test.mjs +0 -57
- package/lib/render.test.mjs +0 -68
- package/lib/resource-governor.test.mjs +0 -488
- package/lib/scheduling/dynamic-jobs.test.mjs +0 -344
- package/lib/scheduling/jitter.test.mjs +0 -140
- package/lib/secrets/broker.test.mjs +0 -280
- package/lib/secrets/providers.test.mjs +0 -274
- package/lib/security/audit-engine.test.mjs +0 -424
- package/lib/security/coerce-args.test.mjs +0 -281
- package/lib/security/dangerous-tools.test.mjs +0 -68
- package/lib/security/external-content.test.mjs +0 -84
- package/lib/security/redact.test.mjs +0 -441
- package/lib/security/secret-equal.test.mjs +0 -55
- package/lib/session/config.test.mjs +0 -92
- package/lib/session/feed-core.test.mjs +0 -198
- package/lib/session/first-run.test.mjs +0 -121
- package/lib/session/frontdoor.test.mjs +0 -205
- package/lib/session/handoffs.test.mjs +0 -183
- package/lib/session/identity.test.mjs +0 -180
- package/lib/session/inbox-claims.test.mjs +0 -286
- package/lib/session/launch-args.test.mjs +0 -157
- package/lib/session/liveness.test.mjs +0 -100
- package/lib/session/status-summary.test.mjs +0 -118
- package/lib/session-permissions.test.mjs +0 -120
- package/lib/setup/claude-probe.test.mjs +0 -187
- package/lib/setup/completeness.test.mjs +0 -110
- package/lib/setup/context-pack.test.mjs +0 -89
- package/lib/setup/enrich.test.mjs +0 -115
- package/lib/setup/enroll-from-cohort.test.mjs +0 -300
- package/lib/setup/integration.test.mjs +0 -162
- package/lib/setup/io.test.mjs +0 -77
- package/lib/setup/runner.test.mjs +0 -132
- package/lib/setup/sections/identity.test.mjs +0 -234
- package/lib/setup/sections/inventory.test.mjs +0 -198
- package/lib/setup/sections/learning.test.mjs +0 -81
- package/lib/setup/sections/mandate.test.mjs +0 -388
- package/lib/setup/sections/messaging.test.mjs +0 -127
- package/lib/setup/sections/model.test.mjs +0 -240
- package/lib/setup/sections/org.test.mjs +0 -346
- package/lib/setup/sections/orgmail.test.mjs +0 -118
- package/lib/setup/sections/recovery.test.mjs +0 -98
- package/lib/setup/sections/subagents.test.mjs +0 -429
- package/lib/setup/sections/verify.test.mjs +0 -175
- package/lib/setup/sot.test.mjs +0 -81
- package/lib/setup/state.test.mjs +0 -115
- package/lib/singleton.test.mjs +0 -151
- package/lib/subagents/cli.test.mjs +0 -389
- package/lib/subagents/client.test.mjs +0 -309
- package/lib/subagents/gap.test.mjs +0 -234
- package/lib/subagents/lock.test.mjs +0 -248
- package/lib/subagents/manifest.test.mjs +0 -175
- package/lib/subagents/refs.test.mjs +0 -204
- package/lib/subagents/resolve.test.mjs +0 -422
- package/lib/subagents/schema.test.mjs +0 -328
- package/lib/telemetry/alerts.test.mjs +0 -109
- package/lib/telemetry/collect.test.mjs +0 -1274
- package/lib/tool-definitions-integration.test.mjs +0 -83
- package/lib/tool-definitions.test.mjs +0 -437
- package/lib/upgrade/global-refresh.test.mjs +0 -65
- package/lib/upgrade/launchd-reconcile.test.mjs +0 -272
- package/lib/upgrade/post-steps.test.mjs +0 -200
- package/lib/upgrade/verify.test.mjs +0 -164
- package/lib/util/fetch-timeout.test.mjs +0 -202
- package/lib/util/reconnect.test.mjs +0 -369
- package/lib/util/unhandled.test.mjs +0 -216
- package/lib/voice/outbound.test.mjs +0 -69
- package/lib/voice/session-rotation.test.mjs +0 -114
- package/lib/voice/stt.test.mjs +0 -226
- package/lib/voice/voice.test.mjs +0 -990
- package/scripts/cadence/enqueue-cadence-tick.test.mjs +0 -187
- package/scripts/ci/check-docs-accuracy.test.mjs +0 -409
- package/scripts/ci/check-durable-write-seam.test.mjs +0 -90
- package/scripts/ci/check-no-build-artifacts.test.mjs +0 -71
- package/scripts/ci/check-no-residual-identity.test.mjs +0 -202
- package/scripts/ci/check-skill-packs.test.mjs +0 -495
- package/scripts/ci/check-subagent-frontmatter.test.mjs +0 -124
- package/scripts/ci/check.test.mjs +0 -194
- package/scripts/ci/conformance-org-api.test.mjs +0 -425
- package/scripts/cloud-relay/voice/relay-identity.test.mjs +0 -96
- package/scripts/collective/hook-runner.test.mjs +0 -173
- package/scripts/cost/fleet-digest.test.mjs +0 -207
- package/scripts/cost/track-claude-usage-pricing.test.mjs +0 -183
- package/scripts/cost/track-claude-usage.test.mjs +0 -148
- package/scripts/daemon/agent-daemon-board-mine.test.mjs +0 -96
- package/scripts/daemon/agent-daemon-design.test.mjs +0 -238
- package/scripts/daemon/agent-daemon-frontdoor.test.mjs +0 -60
- package/scripts/daemon/agent-daemon.test.mjs +0 -995
- package/scripts/daemon/assurance-e2e.test.mjs +0 -613
- package/scripts/daemon/assurance.test.mjs +0 -1791
- package/scripts/daemon/board-mirror.test.mjs +0 -165
- package/scripts/daemon/cadence-consumer-frontdoor.test.mjs +0 -393
- package/scripts/daemon/cadence-consumer-governance.test.mjs +0 -276
- package/scripts/daemon/cadence-consumer.test.mjs +0 -776
- package/scripts/daemon/cadence-handlers.test.mjs +0 -837
- package/scripts/daemon/classifier-identity.test.mjs +0 -137
- package/scripts/daemon/classifier.test.mjs +0 -266
- package/scripts/daemon/classify-kind.test.mjs +0 -40
- package/scripts/daemon/context-compiler.test.mjs +0 -406
- package/scripts/daemon/deliver.test.mjs +0 -564
- package/scripts/daemon/dispatcher-cooldown.test.mjs +0 -122
- package/scripts/daemon/dispatcher-governance.test.mjs +0 -1013
- package/scripts/daemon/dispatcher-resume.test.mjs +0 -166
- package/scripts/daemon/dispatcher-session-continuity.test.mjs +0 -365
- package/scripts/daemon/execution-ladder.test.mjs +0 -470
- package/scripts/daemon/goal-steward-cadence.test.mjs +0 -312
- package/scripts/daemon/inbox-deferral-session.test.mjs +0 -49
- package/scripts/daemon/inbox-deferral.test.mjs +0 -336
- package/scripts/daemon/inbox-wake.test.mjs +0 -199
- package/scripts/daemon/integration.test.mjs +0 -149
- package/scripts/daemon/lib/self-echo.test.mjs +0 -153
- package/scripts/daemon/lib/session-router.test.mjs +0 -554
- package/scripts/daemon/prompt-builder-preamble.test.mjs +0 -210
- package/scripts/daemon/prompt-builder.test.mjs +0 -556
- package/scripts/daemon/responder-cost.test.mjs +0 -68
- package/scripts/daemon/responder-history.test.mjs +0 -221
- package/scripts/daemon/sdk-version.test.mjs +0 -31
- package/scripts/daemon/session-lock.test.mjs +0 -252
- package/scripts/daemon/session-outcomes.test.mjs +0 -533
- package/scripts/daemon/typing-registry.test.mjs +0 -102
- package/scripts/hooks/pre-send-audit.test.mjs +0 -354
- package/scripts/huddle/huddle-prompt.test.mjs +0 -176
- package/scripts/local-triggers/autoupdate.test.mjs +0 -518
- package/scripts/local-triggers/generate-plists.test.mjs +0 -456
- package/scripts/media-generation/brand-clause.test.mjs +0 -135
- package/scripts/org/send-orgmail.first-contact.test.mjs +0 -102
- package/scripts/poller/inbox-privilege-injection.test.mjs +0 -167
- package/scripts/poller/inbox-scan-poller.test.mjs +0 -295
- package/scripts/poller/lib/cloud-relay-dedup.test.mjs +0 -133
- package/scripts/poller/slack-socket-mode.test.mjs +0 -805
- package/scripts/poller-launchd/install.test.mjs +0 -243
- package/scripts/restore-from-backup.test.mjs +0 -181
- package/scripts/session/feed.test.mjs +0 -196
- package/scripts/session/supervisor-sh.test.mjs +0 -218
- package/scripts/session/supervisor.test.mjs +0 -482
- package/scripts/setup/configure-macos.test.mjs +0 -306
- package/scripts/setup/gen-subagent-manifest.test.mjs +0 -124
- package/scripts/setup/generate-agent-package-json.test.mjs +0 -143
- package/scripts/setup/generate-capability.test.mjs +0 -134
- package/scripts/setup/init-agent.test.mjs +0 -370
- package/scripts/setup/init-skill-marketplace.test.mjs +0 -193
- package/scripts/vendor/sync-skill-packs.test.mjs +0 -103
- package/scripts/watchdog/memory-watchdog.test.mjs +0 -64
package/lib/cadence-bus.test.mjs
DELETED
|
@@ -1,720 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* cadence-bus.test.mjs — node:test coverage for the cadence bus primitive.
|
|
3
|
-
*
|
|
4
|
-
* Every test creates its own AGENT_ROOT under tmpdir() and cleans up.
|
|
5
|
-
* No real network, no real Claude. Time is injectable via `now` arguments
|
|
6
|
-
* where the API supports it; otherwise tests use real wall-clock with
|
|
7
|
-
* generous epsilons.
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import { test } from "node:test";
|
|
11
|
-
import assert from "node:assert/strict";
|
|
12
|
-
import { promises as fsp } from "fs";
|
|
13
|
-
import { readFileSync, writeFileSync, existsSync, readdirSync, mkdirSync, statSync } from "node:fs";
|
|
14
|
-
import { tmpdir } from "os";
|
|
15
|
-
import { join } from "path";
|
|
16
|
-
|
|
17
|
-
import {
|
|
18
|
-
enqueueTick,
|
|
19
|
-
claimNextTick,
|
|
20
|
-
completeTick,
|
|
21
|
-
failTick,
|
|
22
|
-
requeueTick,
|
|
23
|
-
recoverStaleClaims,
|
|
24
|
-
sweepRetention,
|
|
25
|
-
writeJsonAtomic,
|
|
26
|
-
writeHealth,
|
|
27
|
-
readHealth,
|
|
28
|
-
busDepth,
|
|
29
|
-
ensureBusDirs,
|
|
30
|
-
bootstrapBus,
|
|
31
|
-
getBusPaths,
|
|
32
|
-
nextEventId,
|
|
33
|
-
listInbox,
|
|
34
|
-
listClaimed,
|
|
35
|
-
isProcessedId,
|
|
36
|
-
logBusEvent,
|
|
37
|
-
BUS_VERSION,
|
|
38
|
-
} from "./cadence-bus.mjs";
|
|
39
|
-
|
|
40
|
-
async function makeAgentRoot() {
|
|
41
|
-
const path = join(
|
|
42
|
-
tmpdir(),
|
|
43
|
-
`cadence-bus-test-${process.pid}-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`
|
|
44
|
-
);
|
|
45
|
-
await fsp.mkdir(path, { recursive: true });
|
|
46
|
-
return path;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async function rmRoot(path) {
|
|
50
|
-
try { await fsp.rm(path, { recursive: true, force: true }); } catch { /* */ }
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// ---------------------------------------------------------------------------
|
|
54
|
-
// Path resolution + bootstrap
|
|
55
|
-
// ---------------------------------------------------------------------------
|
|
56
|
-
|
|
57
|
-
test("getBusPaths derives every path under state/cadence-bus/", async () => {
|
|
58
|
-
const root = await makeAgentRoot();
|
|
59
|
-
try {
|
|
60
|
-
const p = getBusPaths(root);
|
|
61
|
-
assert.equal(p.agentRoot, root);
|
|
62
|
-
assert.equal(p.base, join(root, "state/cadence-bus"));
|
|
63
|
-
assert.equal(p.inbox, join(root, "state/cadence-bus/inbox"));
|
|
64
|
-
assert.equal(p.claimed, join(root, "state/cadence-bus/claimed"));
|
|
65
|
-
assert.equal(p.processed, join(root, "state/cadence-bus/processed"));
|
|
66
|
-
assert.equal(p.dlq, join(root, "state/cadence-bus/dlq"));
|
|
67
|
-
assert.equal(p.queueJsonl, join(root, "state/cadence-bus/queue.jsonl"));
|
|
68
|
-
assert.equal(p.health, join(root, "state/cadence-bus/health.json"));
|
|
69
|
-
assert.equal(p.logsDir, join(root, "logs/cadence-bus"));
|
|
70
|
-
} finally { await rmRoot(root); }
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
test("ensureBusDirs is idempotent and writes VERSION marker", async () => {
|
|
74
|
-
const root = await makeAgentRoot();
|
|
75
|
-
try {
|
|
76
|
-
const p = ensureBusDirs(root);
|
|
77
|
-
assert.ok(existsSync(p.inbox));
|
|
78
|
-
assert.ok(existsSync(p.claimed));
|
|
79
|
-
assert.ok(existsSync(p.processed));
|
|
80
|
-
assert.ok(existsSync(p.failed));
|
|
81
|
-
assert.ok(existsSync(p.dlq));
|
|
82
|
-
assert.ok(existsSync(p.logsDir));
|
|
83
|
-
assert.equal(readFileSync(p.version, "utf-8").trim(), BUS_VERSION);
|
|
84
|
-
// Calling again must not throw and must not duplicate the VERSION file.
|
|
85
|
-
ensureBusDirs(root);
|
|
86
|
-
ensureBusDirs(root);
|
|
87
|
-
assert.equal(readFileSync(p.version, "utf-8").trim(), BUS_VERSION);
|
|
88
|
-
} finally { await rmRoot(root); }
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
test("bootstrapBus writes .gitkeep stubs in every bus dir", async () => {
|
|
92
|
-
const root = await makeAgentRoot();
|
|
93
|
-
try {
|
|
94
|
-
const p = bootstrapBus(root);
|
|
95
|
-
for (const d of [p.inbox, p.claimed, p.processed, p.failed, p.dlq, p.logsDir]) {
|
|
96
|
-
assert.ok(existsSync(join(d, ".gitkeep")), `.gitkeep missing in ${d}`);
|
|
97
|
-
}
|
|
98
|
-
} finally { await rmRoot(root); }
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
// ---------------------------------------------------------------------------
|
|
102
|
-
// Event ids
|
|
103
|
-
// ---------------------------------------------------------------------------
|
|
104
|
-
|
|
105
|
-
test("nextEventId yields unique sortable ids", () => {
|
|
106
|
-
const ids = new Set();
|
|
107
|
-
for (let i = 0; i < 200; i++) ids.add(nextEventId());
|
|
108
|
-
assert.equal(ids.size, 200);
|
|
109
|
-
// Sortability: with a fixed clock, the ISO prefix is identical so the
|
|
110
|
-
// hex suffix breaks ties — pass an explicit clock to check.
|
|
111
|
-
const a = nextEventId(new Date(0));
|
|
112
|
-
const b = nextEventId(new Date(0));
|
|
113
|
-
assert.notEqual(a, b);
|
|
114
|
-
assert.match(a, /^evt-1970-01-01T00:00:00\.000Z-[0-9a-f]{8}$/);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
// ---------------------------------------------------------------------------
|
|
118
|
-
// Enqueue
|
|
119
|
-
// ---------------------------------------------------------------------------
|
|
120
|
-
|
|
121
|
-
test("enqueueTick rejects missing cadence", async () => {
|
|
122
|
-
const root = await makeAgentRoot();
|
|
123
|
-
try {
|
|
124
|
-
assert.throws(() => enqueueTick({ agentRoot: root }), /cadence is required/);
|
|
125
|
-
} finally { await rmRoot(root); }
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
test("enqueueTick writes inbox JSON + queue.jsonl audit row", async () => {
|
|
129
|
-
const root = await makeAgentRoot();
|
|
130
|
-
try {
|
|
131
|
-
const out = enqueueTick({
|
|
132
|
-
cadence: "inbox-processor",
|
|
133
|
-
source: "launchd",
|
|
134
|
-
metadata: { note: "smoke" },
|
|
135
|
-
agentRoot: root,
|
|
136
|
-
});
|
|
137
|
-
assert.equal(out.fallbackOnly, false);
|
|
138
|
-
assert.ok(out.path);
|
|
139
|
-
const event = JSON.parse(readFileSync(out.path, "utf-8"));
|
|
140
|
-
assert.equal(event.cadence, "inbox-processor");
|
|
141
|
-
assert.equal(event.source, "launchd");
|
|
142
|
-
assert.equal(event.metadata.note, "smoke");
|
|
143
|
-
assert.equal(event.priority, "normal");
|
|
144
|
-
assert.equal(event.attempts, 0);
|
|
145
|
-
// queue.jsonl mirror
|
|
146
|
-
const paths = getBusPaths(root);
|
|
147
|
-
const audit = readFileSync(paths.queueJsonl, "utf-8").trim();
|
|
148
|
-
const rec = JSON.parse(audit);
|
|
149
|
-
assert.equal(rec.id, out.id);
|
|
150
|
-
} finally { await rmRoot(root); }
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
test("enqueueTick suppresses when .emergency-stop exists but still audits", async () => {
|
|
154
|
-
const root = await makeAgentRoot();
|
|
155
|
-
try {
|
|
156
|
-
writeFileSync(join(root, ".emergency-stop"), new Date().toISOString());
|
|
157
|
-
const out = enqueueTick({
|
|
158
|
-
cadence: "weekly-strategic-memo",
|
|
159
|
-
source: "launchd",
|
|
160
|
-
agentRoot: root,
|
|
161
|
-
});
|
|
162
|
-
assert.equal(out.skipped, "emergency-stop");
|
|
163
|
-
assert.equal(out.fallbackOnly, true);
|
|
164
|
-
assert.equal(listInbox(root).length, 0);
|
|
165
|
-
const paths = getBusPaths(root);
|
|
166
|
-
const audit = readFileSync(paths.queueJsonl, "utf-8").trim();
|
|
167
|
-
const rec = JSON.parse(audit);
|
|
168
|
-
assert.equal(rec._suppressed, "emergency-stop");
|
|
169
|
-
} finally { await rmRoot(root); }
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
test("enqueueTick coerces unknown priority to 'normal'", async () => {
|
|
173
|
-
const root = await makeAgentRoot();
|
|
174
|
-
try {
|
|
175
|
-
const out = enqueueTick({ cadence: "x", priority: "BOGUS", agentRoot: root });
|
|
176
|
-
const event = JSON.parse(readFileSync(out.path, "utf-8"));
|
|
177
|
-
assert.equal(event.priority, "normal");
|
|
178
|
-
} finally { await rmRoot(root); }
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// ---------------------------------------------------------------------------
|
|
182
|
-
// Claim / complete / fail / DLQ
|
|
183
|
-
// ---------------------------------------------------------------------------
|
|
184
|
-
|
|
185
|
-
test("claimNextTick is atomic — only one claimer wins per event", async () => {
|
|
186
|
-
const root = await makeAgentRoot();
|
|
187
|
-
try {
|
|
188
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
189
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
190
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
191
|
-
assert.equal(listInbox(root).length, 3);
|
|
192
|
-
|
|
193
|
-
const seen = new Set();
|
|
194
|
-
let c;
|
|
195
|
-
while ((c = claimNextTick(root)) !== null) {
|
|
196
|
-
assert.ok(!seen.has(c.event.id), "duplicate claim");
|
|
197
|
-
seen.add(c.event.id);
|
|
198
|
-
}
|
|
199
|
-
assert.equal(seen.size, 3);
|
|
200
|
-
assert.equal(listInbox(root).length, 0);
|
|
201
|
-
assert.equal(listClaimed(root).length, 3);
|
|
202
|
-
} finally { await rmRoot(root); }
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
test("claimNextTick does NOT bump attempts (single-sourced in failTick, M5)", async () => {
|
|
206
|
-
const root = await makeAgentRoot();
|
|
207
|
-
try {
|
|
208
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
209
|
-
const { event, claimedPath } = claimNextTick(root);
|
|
210
|
-
// Claiming is not a failed attempt — attempts must stay 0 so a
|
|
211
|
-
// successful first run never burns retry budget and a crash-recover
|
|
212
|
-
// can't double-count. Attempt accounting lives solely in failTick.
|
|
213
|
-
assert.equal(event.attempts, 0);
|
|
214
|
-
const reloaded = JSON.parse(readFileSync(claimedPath, "utf-8"));
|
|
215
|
-
assert.equal(reloaded.attempts, 0);
|
|
216
|
-
} finally { await rmRoot(root); }
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
test("claimNextTick returns null on empty inbox", async () => {
|
|
220
|
-
const root = await makeAgentRoot();
|
|
221
|
-
try {
|
|
222
|
-
assert.equal(claimNextTick(root), null);
|
|
223
|
-
} finally { await rmRoot(root); }
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
test("completeTick archives the claim under processed/<utc-date>/", async () => {
|
|
227
|
-
const root = await makeAgentRoot();
|
|
228
|
-
try {
|
|
229
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
230
|
-
const { event } = claimNextTick(root);
|
|
231
|
-
const dst = completeTick(root, event.id, { decision: "inline", duration_ms: 42 });
|
|
232
|
-
assert.ok(dst);
|
|
233
|
-
const archived = JSON.parse(readFileSync(dst, "utf-8"));
|
|
234
|
-
assert.equal(archived.result.decision, "inline");
|
|
235
|
-
assert.equal(archived.result.duration_ms, 42);
|
|
236
|
-
assert.ok(archived.completed_at);
|
|
237
|
-
assert.equal(listClaimed(root).length, 0);
|
|
238
|
-
} finally { await rmRoot(root); }
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
test("failTick re-queues to inbox while under retry budget", async () => {
|
|
242
|
-
const root = await makeAgentRoot();
|
|
243
|
-
try {
|
|
244
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
245
|
-
const { event } = claimNextTick(root);
|
|
246
|
-
const out = failTick(root, event.id, "transient");
|
|
247
|
-
assert.equal(out.destination, "inbox");
|
|
248
|
-
assert.equal(listInbox(root).length, 1);
|
|
249
|
-
assert.equal(listClaimed(root).length, 0);
|
|
250
|
-
// Reload and confirm last_error set.
|
|
251
|
-
const requeued = JSON.parse(readFileSync(join(getBusPaths(root).inbox, `${event.id}.json`), "utf-8"));
|
|
252
|
-
assert.equal(requeued.last_error, "transient");
|
|
253
|
-
} finally { await rmRoot(root); }
|
|
254
|
-
});
|
|
255
|
-
|
|
256
|
-
test("failTick routes to dlq once attempts hit the budget", async () => {
|
|
257
|
-
const root = await makeAgentRoot();
|
|
258
|
-
try {
|
|
259
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
260
|
-
// Cycle claim/fail until the event lands in dlq.
|
|
261
|
-
let last;
|
|
262
|
-
for (let i = 0; i < 10; i++) {
|
|
263
|
-
const c = claimNextTick(root);
|
|
264
|
-
if (!c) break;
|
|
265
|
-
last = failTick(root, c.event.id, `attempt-${i}`);
|
|
266
|
-
if (last?.destination === "dlq") break;
|
|
267
|
-
}
|
|
268
|
-
assert.equal(last.destination, "dlq");
|
|
269
|
-
assert.equal(listInbox(root).length, 0);
|
|
270
|
-
assert.equal(listClaimed(root).length, 0);
|
|
271
|
-
const dlqDir = getBusPaths(root).dlq;
|
|
272
|
-
assert.ok(readdirSync(dlqDir).length >= 1);
|
|
273
|
-
} finally { await rmRoot(root); }
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
test("failTick { terminal: true } sends straight to dlq", async () => {
|
|
277
|
-
const root = await makeAgentRoot();
|
|
278
|
-
try {
|
|
279
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
280
|
-
const { event } = claimNextTick(root);
|
|
281
|
-
const out = failTick(root, event.id, "no-prompt", { terminal: true });
|
|
282
|
-
assert.equal(out.destination, "dlq");
|
|
283
|
-
} finally { await rmRoot(root); }
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
// ---------------------------------------------------------------------------
|
|
287
|
-
// Stale claim recovery
|
|
288
|
-
// ---------------------------------------------------------------------------
|
|
289
|
-
|
|
290
|
-
test("recoverStaleClaims returns aging claims to inbox", async () => {
|
|
291
|
-
const root = await makeAgentRoot();
|
|
292
|
-
try {
|
|
293
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
294
|
-
const { event, claimedPath } = claimNextTick(root);
|
|
295
|
-
// Backdate the claim's mtime by 2 hours.
|
|
296
|
-
const oldMs = Date.now() - 2 * 60 * 60 * 1000;
|
|
297
|
-
await fsp.utimes(claimedPath, new Date(oldMs), new Date(oldMs));
|
|
298
|
-
|
|
299
|
-
const stats = recoverStaleClaims(root, 60 * 60 * 1000); // 1 hour threshold
|
|
300
|
-
assert.equal(stats.scanned, 1);
|
|
301
|
-
assert.equal(stats.recovered, 1);
|
|
302
|
-
assert.equal(listInbox(root).length, 1);
|
|
303
|
-
assert.equal(listClaimed(root).length, 0);
|
|
304
|
-
// The recovered event retains its bumped attempts.
|
|
305
|
-
const requeued = JSON.parse(readFileSync(join(getBusPaths(root).inbox, `${event.id}.json`), "utf-8"));
|
|
306
|
-
assert.ok(requeued.attempts >= 1);
|
|
307
|
-
} finally { await rmRoot(root); }
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
test("recoverStaleClaims leaves fresh claims alone", async () => {
|
|
311
|
-
const root = await makeAgentRoot();
|
|
312
|
-
try {
|
|
313
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
314
|
-
claimNextTick(root);
|
|
315
|
-
const stats = recoverStaleClaims(root, 60 * 60 * 1000);
|
|
316
|
-
assert.equal(stats.scanned, 1);
|
|
317
|
-
assert.equal(stats.recovered, 0);
|
|
318
|
-
} finally { await rmRoot(root); }
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
// ---------------------------------------------------------------------------
|
|
322
|
-
// Health
|
|
323
|
-
// ---------------------------------------------------------------------------
|
|
324
|
-
|
|
325
|
-
test("writeHealth + readHealth round-trip", async () => {
|
|
326
|
-
const root = await makeAgentRoot();
|
|
327
|
-
try {
|
|
328
|
-
writeHealth(root, { stats: { foo: 1 } });
|
|
329
|
-
const h = readHealth(root);
|
|
330
|
-
assert.ok(h);
|
|
331
|
-
assert.equal(h.version, BUS_VERSION);
|
|
332
|
-
assert.equal(h.stats.foo, 1);
|
|
333
|
-
assert.ok(h.ts);
|
|
334
|
-
} finally { await rmRoot(root); }
|
|
335
|
-
});
|
|
336
|
-
|
|
337
|
-
test("readHealth returns null when missing or corrupt", async () => {
|
|
338
|
-
const root = await makeAgentRoot();
|
|
339
|
-
try {
|
|
340
|
-
assert.equal(readHealth(root), null);
|
|
341
|
-
ensureBusDirs(root);
|
|
342
|
-
writeFileSync(join(root, "state/cadence-bus/health.json"), "{not json");
|
|
343
|
-
assert.equal(readHealth(root), null);
|
|
344
|
-
} finally { await rmRoot(root); }
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
// ---------------------------------------------------------------------------
|
|
348
|
-
// Depth
|
|
349
|
-
// ---------------------------------------------------------------------------
|
|
350
|
-
|
|
351
|
-
test("busDepth reports counts per stage", async () => {
|
|
352
|
-
const root = await makeAgentRoot();
|
|
353
|
-
try {
|
|
354
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
355
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
356
|
-
claimNextTick(root);
|
|
357
|
-
const d = busDepth(root);
|
|
358
|
-
assert.equal(d.inbox, 1);
|
|
359
|
-
assert.equal(d.claimed, 1);
|
|
360
|
-
assert.equal(d.dlq, 0);
|
|
361
|
-
} finally { await rmRoot(root); }
|
|
362
|
-
});
|
|
363
|
-
|
|
364
|
-
test("enqueueTick dedups a replayed explicit id but always writes auto ids (H12)", async () => {
|
|
365
|
-
const root = await makeAgentRoot();
|
|
366
|
-
try {
|
|
367
|
-
// First write with an explicit id lands in inbox.
|
|
368
|
-
const r1 = enqueueTick({ cadence: "inbox-processor", id: "replay-1", agentRoot: root });
|
|
369
|
-
assert.ok(r1.path && existsSync(r1.path));
|
|
370
|
-
assert.ok(!r1.deduped);
|
|
371
|
-
|
|
372
|
-
// Replaying the same explicit id is deduped — no second inbox file, no clobber.
|
|
373
|
-
const r2 = enqueueTick({ cadence: "inbox-processor", id: "replay-1", agentRoot: root });
|
|
374
|
-
assert.equal(r2.deduped, "inbox");
|
|
375
|
-
assert.equal(r2.path, null);
|
|
376
|
-
assert.equal(busDepth(root).inbox, 1);
|
|
377
|
-
|
|
378
|
-
// Auto-generated ids never dedup against each other.
|
|
379
|
-
const r3 = enqueueTick({ cadence: "inbox-processor", agentRoot: root });
|
|
380
|
-
assert.ok(r3.path && !r3.deduped);
|
|
381
|
-
assert.equal(busDepth(root).inbox, 2);
|
|
382
|
-
} finally { await rmRoot(root); }
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
test("enqueueTick dedups an explicit id already processed (H12)", async () => {
|
|
386
|
-
const root = await makeAgentRoot();
|
|
387
|
-
try {
|
|
388
|
-
enqueueTick({ cadence: "inbox-processor", id: "done-1", agentRoot: root });
|
|
389
|
-
const claimed = claimNextTick(root);
|
|
390
|
-
assert.equal(claimed.event.id, "done-1");
|
|
391
|
-
completeTick(root, claimed.event.id, {});
|
|
392
|
-
assert.equal(isProcessedId(root, "done-1"), true);
|
|
393
|
-
// Re-enqueue of an already-processed explicit id is suppressed.
|
|
394
|
-
const r2 = enqueueTick({ cadence: "inbox-processor", id: "done-1", agentRoot: root });
|
|
395
|
-
assert.equal(r2.deduped, "processed");
|
|
396
|
-
assert.equal(busDepth(root).inbox, 0);
|
|
397
|
-
} finally { await rmRoot(root); }
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
// ---------------------------------------------------------------------------
|
|
401
|
-
// Attempt accounting (audit M5/M6/M7) — increment once, never decrement
|
|
402
|
-
// ---------------------------------------------------------------------------
|
|
403
|
-
|
|
404
|
-
test("attempts increments exactly once per failed attempt and reaches dlq at maxAttempts", async () => {
|
|
405
|
-
const root = await makeAgentRoot();
|
|
406
|
-
try {
|
|
407
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
408
|
-
// maxAttempts=3: fail #1 → attempts 1 (inbox), #2 → 2 (inbox), #3 → 3 (dlq).
|
|
409
|
-
const expected = [
|
|
410
|
-
{ dest: "inbox", attempts: 1 },
|
|
411
|
-
{ dest: "inbox", attempts: 2 },
|
|
412
|
-
{ dest: "dlq", attempts: 3 },
|
|
413
|
-
];
|
|
414
|
-
for (const step of expected) {
|
|
415
|
-
const c = claimNextTick(root);
|
|
416
|
-
assert.ok(c, "expected a claimable event");
|
|
417
|
-
// Claim never bumps — count only moves inside failTick.
|
|
418
|
-
const beforeFail = c.event.attempts;
|
|
419
|
-
const out = failTick(root, c.event.id, "boom", { maxAttempts: 3 });
|
|
420
|
-
assert.equal(out.destination, step.dest, `destination for attempts=${step.attempts}`);
|
|
421
|
-
if (step.dest === "inbox") {
|
|
422
|
-
const requeued = JSON.parse(
|
|
423
|
-
readFileSync(join(getBusPaths(root).inbox, `${c.event.id}.json`), "utf-8")
|
|
424
|
-
);
|
|
425
|
-
assert.equal(requeued.attempts, step.attempts, "requeued attempts");
|
|
426
|
-
// Exactly +1 over what claim handed us — no double-count, no drift.
|
|
427
|
-
assert.equal(requeued.attempts, beforeFail + 1);
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
// Final: exactly one file in dlq, with attempts === maxAttempts (no overshoot).
|
|
431
|
-
const dlqFiles = readdirSync(getBusPaths(root).dlq).filter((n) => n.endsWith(".json"));
|
|
432
|
-
assert.equal(dlqFiles.length, 1);
|
|
433
|
-
const dlqEvent = JSON.parse(readFileSync(join(getBusPaths(root).dlq, dlqFiles[0]), "utf-8"));
|
|
434
|
-
assert.equal(dlqEvent.attempts, 3);
|
|
435
|
-
assert.equal(listInbox(root).length, 0);
|
|
436
|
-
assert.equal(listClaimed(root).length, 0);
|
|
437
|
-
} finally { await rmRoot(root); }
|
|
438
|
-
});
|
|
439
|
-
|
|
440
|
-
test("requeueTick atomically returns an event to inbox without touching attempts (M6)", async () => {
|
|
441
|
-
const root = await makeAgentRoot();
|
|
442
|
-
try {
|
|
443
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
444
|
-
const { event } = claimNextTick(root);
|
|
445
|
-
assert.equal(listClaimed(root).length, 1);
|
|
446
|
-
// Simulate a circuit-open re-queue: same event, attempts unchanged.
|
|
447
|
-
const ok = requeueTick(root, event);
|
|
448
|
-
assert.equal(ok, true);
|
|
449
|
-
assert.equal(listInbox(root).length, 1);
|
|
450
|
-
assert.equal(listClaimed(root).length, 0);
|
|
451
|
-
const requeued = JSON.parse(
|
|
452
|
-
readFileSync(join(getBusPaths(root).inbox, `${event.id}.json`), "utf-8")
|
|
453
|
-
);
|
|
454
|
-
assert.equal(requeued.attempts, event.attempts); // no drift
|
|
455
|
-
} finally { await rmRoot(root); }
|
|
456
|
-
});
|
|
457
|
-
|
|
458
|
-
test("requeueTick rejects an event without an id", async () => {
|
|
459
|
-
const root = await makeAgentRoot();
|
|
460
|
-
try {
|
|
461
|
-
assert.throws(() => requeueTick(root, {}), /id is required/);
|
|
462
|
-
} finally { await rmRoot(root); }
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
test("writeJsonAtomic is exported and writes valid JSON via temp+rename", async () => {
|
|
466
|
-
const root = await makeAgentRoot();
|
|
467
|
-
try {
|
|
468
|
-
const target = join(root, "atomic-probe.json");
|
|
469
|
-
writeJsonAtomic(target, { a: 1, nested: { b: 2 } });
|
|
470
|
-
const parsed = JSON.parse(readFileSync(target, "utf-8"));
|
|
471
|
-
assert.equal(parsed.a, 1);
|
|
472
|
-
assert.equal(parsed.nested.b, 2);
|
|
473
|
-
} finally { await rmRoot(root); }
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
test("writeJsonAtomic round-trips, leaves no .tmp sibling, and overwrites atomically (L3)", async () => {
|
|
477
|
-
const root = await makeAgentRoot();
|
|
478
|
-
try {
|
|
479
|
-
const dir = join(root, "atomic-dir");
|
|
480
|
-
mkdirSync(dir, { recursive: true });
|
|
481
|
-
const target = join(dir, "probe.json");
|
|
482
|
-
|
|
483
|
-
// First write — fsync-before-rename path runs on a normal fs.
|
|
484
|
-
writeJsonAtomic(target, { v: 1, s: "first" });
|
|
485
|
-
assert.deepEqual(JSON.parse(readFileSync(target, "utf-8")), { v: 1, s: "first" });
|
|
486
|
-
|
|
487
|
-
// Overwrite — must replace contents wholesale, still valid JSON.
|
|
488
|
-
writeJsonAtomic(target, { v: 2, s: "second" });
|
|
489
|
-
assert.deepEqual(JSON.parse(readFileSync(target, "utf-8")), { v: 2, s: "second" });
|
|
490
|
-
|
|
491
|
-
// Atomicity hygiene: no orphaned temp file is left behind in the dir.
|
|
492
|
-
const leftover = readdirSync(dir).filter((n) => n.includes(".tmp."));
|
|
493
|
-
assert.deepEqual(leftover, [], `unexpected temp leftovers: ${leftover.join(", ")}`);
|
|
494
|
-
// Exactly one durable file remains.
|
|
495
|
-
assert.deepEqual(readdirSync(dir).sort(), ["probe.json"]);
|
|
496
|
-
} finally { await rmRoot(root); }
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
test("writeJsonAtomic cleans up the temp file when the write/rename cannot complete (L3)", async () => {
|
|
500
|
-
const root = await makeAgentRoot();
|
|
501
|
-
try {
|
|
502
|
-
// A target whose parent path component is a FILE (not a dir) makes the
|
|
503
|
-
// open/write of the sibling temp fail; writeJsonAtomic must throw and
|
|
504
|
-
// leave nothing behind under root.
|
|
505
|
-
const blocker = join(root, "as-file");
|
|
506
|
-
writeFileSync(blocker, "x");
|
|
507
|
-
const target = join(blocker, "child.json"); // parent is a file
|
|
508
|
-
assert.throws(() => writeJsonAtomic(target, { a: 1 }));
|
|
509
|
-
// No stray .tmp file should survive at root level.
|
|
510
|
-
const leftover = readdirSync(root).filter((n) => n.includes(".tmp."));
|
|
511
|
-
assert.deepEqual(leftover, []);
|
|
512
|
-
} finally { await rmRoot(root); }
|
|
513
|
-
});
|
|
514
|
-
|
|
515
|
-
// ---------------------------------------------------------------------------
|
|
516
|
-
// Observable best-effort write failures (L4)
|
|
517
|
-
// ---------------------------------------------------------------------------
|
|
518
|
-
|
|
519
|
-
// Read every structured log line the bus has written for a root.
|
|
520
|
-
function readBusLogs(root) {
|
|
521
|
-
const dir = join(root, "logs/cadence-bus");
|
|
522
|
-
if (!existsSync(dir)) return [];
|
|
523
|
-
const lines = [];
|
|
524
|
-
for (const n of readdirSync(dir).filter((f) => f.endsWith(".jsonl"))) {
|
|
525
|
-
const body = readFileSync(join(dir, n), "utf-8");
|
|
526
|
-
for (const line of body.split("\n").filter(Boolean)) {
|
|
527
|
-
try { lines.push(JSON.parse(line)); } catch { /* skip partials */ }
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
return lines;
|
|
531
|
-
}
|
|
532
|
-
|
|
533
|
-
test("completeTick logs best_effort_write_failed when annotation read-back is corrupt, control flow preserved (L4)", async () => {
|
|
534
|
-
const root = await makeAgentRoot();
|
|
535
|
-
try {
|
|
536
|
-
enqueueTick({ cadence: "x", agentRoot: root });
|
|
537
|
-
const { event } = claimNextTick(root);
|
|
538
|
-
|
|
539
|
-
// Corrupt the claimed payload so that after completeTick moves it to
|
|
540
|
-
// processed/, the annotate read/JSON.parse throws inside the best-effort
|
|
541
|
-
// block. completeTick must still return the dst (control flow preserved)
|
|
542
|
-
// and emit a warn instead of silently swallowing.
|
|
543
|
-
const paths = getBusPaths(root);
|
|
544
|
-
writeFileSync(join(paths.claimed, `${event.id}.json`), "{ this is not json");
|
|
545
|
-
|
|
546
|
-
const dst = completeTick(root, event.id, { decision: "inline" });
|
|
547
|
-
assert.ok(dst, "completeTick must still return a destination");
|
|
548
|
-
|
|
549
|
-
const warned = readBusLogs(root).filter(
|
|
550
|
-
(l) => l.stage === "best_effort_write_failed" && l.op === "complete_annotate"
|
|
551
|
-
);
|
|
552
|
-
assert.ok(warned.length >= 1, "expected a complete_annotate best_effort_write_failed warn");
|
|
553
|
-
assert.equal(warned[0].level, "warn");
|
|
554
|
-
assert.equal(warned[0].id, event.id);
|
|
555
|
-
assert.ok(warned[0].error, "warn must carry the error message");
|
|
556
|
-
} finally { await rmRoot(root); }
|
|
557
|
-
});
|
|
558
|
-
|
|
559
|
-
test("failTick still reaches dlq and persists the bumped attempt count (L4 control-flow guard)", async () => {
|
|
560
|
-
const root = await makeAgentRoot();
|
|
561
|
-
try {
|
|
562
|
-
// maxAttempts=1 makes the first fail terminal. Even if the in-place persist
|
|
563
|
-
// of the bumped count were to fail, the L4 change only ADDS a warn log and
|
|
564
|
-
// never alters control flow — the event must still land in dlq.
|
|
565
|
-
enqueueTick({ cadence: "x", id: "dlq-1", agentRoot: root });
|
|
566
|
-
const claimed = claimNextTick(root);
|
|
567
|
-
assert.equal(claimed.event.id, "dlq-1");
|
|
568
|
-
|
|
569
|
-
const out = failTick(root, "dlq-1", "boom", { maxAttempts: 1 });
|
|
570
|
-
assert.equal(out.destination, "dlq");
|
|
571
|
-
assert.equal(busDepth(root).dlq, 1);
|
|
572
|
-
|
|
573
|
-
const paths = getBusPaths(root);
|
|
574
|
-
const dlqFiles = readdirSync(paths.dlq).filter((n) => n.endsWith(".json"));
|
|
575
|
-
assert.equal(dlqFiles.length, 1);
|
|
576
|
-
const dlqEvent = JSON.parse(readFileSync(join(paths.dlq, dlqFiles[0]), "utf-8"));
|
|
577
|
-
assert.equal(dlqEvent.attempts, 1);
|
|
578
|
-
} finally { await rmRoot(root); }
|
|
579
|
-
});
|
|
580
|
-
|
|
581
|
-
test("logBusEvent returns false (never throws) when its target is unwritable — L4 observability primitive", async () => {
|
|
582
|
-
const root = await makeAgentRoot();
|
|
583
|
-
try {
|
|
584
|
-
// logBusEvent is the primitive the L4 catch blocks call. It must never
|
|
585
|
-
// throw; a failure to log is swallowed and surfaced via the boolean return.
|
|
586
|
-
ensureBusDirs(root);
|
|
587
|
-
await rmRoot(join(root, "logs"));
|
|
588
|
-
writeFileSync(join(root, "logs"), "blocker"); // logs/ is now a file → mkdir/append fail
|
|
589
|
-
const ok = logBusEvent(root, { level: "warn", stage: "probe" });
|
|
590
|
-
assert.equal(ok, false, "logBusEvent must return false on I/O failure, never throw");
|
|
591
|
-
} finally { await rmRoot(root); }
|
|
592
|
-
});
|
|
593
|
-
|
|
594
|
-
// ---------------------------------------------------------------------------
|
|
595
|
-
// Retention sweep (audit M8)
|
|
596
|
-
// ---------------------------------------------------------------------------
|
|
597
|
-
|
|
598
|
-
test("sweepRetention deletes old processed/ dirs but keeps recent ones", async () => {
|
|
599
|
-
const root = await makeAgentRoot();
|
|
600
|
-
try {
|
|
601
|
-
const paths = ensureBusDirs(root);
|
|
602
|
-
const dayMs = 24 * 60 * 60 * 1000;
|
|
603
|
-
const now = Date.UTC(2026, 4, 31); // 2026-05-31 UTC midnight
|
|
604
|
-
const dateName = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
605
|
-
|
|
606
|
-
const oldDir = join(paths.processed, dateName(now - 30 * dayMs)); // 30d old → delete
|
|
607
|
-
const edgeDir = join(paths.processed, dateName(now - 13 * dayMs)); // 13d old → keep (<14)
|
|
608
|
-
const freshDir = join(paths.processed, dateName(now - 1 * dayMs)); // 1d old → keep
|
|
609
|
-
for (const d of [oldDir, edgeDir, freshDir]) {
|
|
610
|
-
mkdirSync(d, { recursive: true });
|
|
611
|
-
writeFileSync(join(d, "evt.json"), "{}");
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
const stats = sweepRetention(root, { now, processedDays: 14 });
|
|
615
|
-
assert.equal(stats.processedDirsDeleted, 1);
|
|
616
|
-
assert.equal(existsSync(oldDir), false, "old dir should be deleted");
|
|
617
|
-
assert.equal(existsSync(edgeDir), true, "13-day dir should be kept");
|
|
618
|
-
assert.equal(existsSync(freshDir), true, "fresh dir should be kept");
|
|
619
|
-
} finally { await rmRoot(root); }
|
|
620
|
-
});
|
|
621
|
-
|
|
622
|
-
test("sweepRetention caps dlq/ to the newest terminalKeep files", async () => {
|
|
623
|
-
const root = await makeAgentRoot();
|
|
624
|
-
try {
|
|
625
|
-
const paths = ensureBusDirs(root);
|
|
626
|
-
// Create 10 dlq files with increasing mtimes so ordering is deterministic.
|
|
627
|
-
const base = Date.now() - 10 * 60 * 1000;
|
|
628
|
-
for (let i = 0; i < 10; i++) {
|
|
629
|
-
const name = `evt-${String(i).padStart(2, "0")}.json`;
|
|
630
|
-
const full = join(paths.dlq, name);
|
|
631
|
-
writeFileSync(full, JSON.stringify({ i }));
|
|
632
|
-
const t = new Date(base + i * 60 * 1000);
|
|
633
|
-
await fsp.utimes(full, t, t);
|
|
634
|
-
}
|
|
635
|
-
const stats = sweepRetention(root, { terminalKeep: 3 });
|
|
636
|
-
assert.equal(stats.dlqDeleted, 7);
|
|
637
|
-
const remaining = readdirSync(paths.dlq).filter((n) => n.endsWith(".json")).sort();
|
|
638
|
-
assert.equal(remaining.length, 3);
|
|
639
|
-
// Newest three (07, 08, 09) survive; oldest are gone.
|
|
640
|
-
assert.deepEqual(remaining, ["evt-07.json", "evt-08.json", "evt-09.json"]);
|
|
641
|
-
} finally { await rmRoot(root); }
|
|
642
|
-
});
|
|
643
|
-
|
|
644
|
-
test("sweepRetention rotates an oversized queue.jsonl keeping the tail", async () => {
|
|
645
|
-
const root = await makeAgentRoot();
|
|
646
|
-
try {
|
|
647
|
-
const paths = ensureBusDirs(root);
|
|
648
|
-
// Write many rows; mark the last one so we can confirm the tail survives.
|
|
649
|
-
const rows = [];
|
|
650
|
-
for (let i = 0; i < 5000; i++) rows.push(JSON.stringify({ id: `evt-${i}`, pad: "x".repeat(50) }));
|
|
651
|
-
rows.push(JSON.stringify({ id: "LAST-ROW" }));
|
|
652
|
-
writeFileSync(paths.queueJsonl, rows.join("\n") + "\n");
|
|
653
|
-
const before = statSync(paths.queueJsonl).size;
|
|
654
|
-
|
|
655
|
-
const stats = sweepRetention(root, { queueMaxBytes: 4096 });
|
|
656
|
-
assert.equal(stats.queueRotated, true);
|
|
657
|
-
const after = statSync(paths.queueJsonl).size;
|
|
658
|
-
assert.ok(after < before, "queue.jsonl should shrink");
|
|
659
|
-
assert.ok(after <= 4096, "queue.jsonl should be at/under the cap after rotation");
|
|
660
|
-
const tail = readFileSync(paths.queueJsonl, "utf-8");
|
|
661
|
-
assert.ok(tail.includes("LAST-ROW"), "most recent row must survive rotation");
|
|
662
|
-
// Every retained line must be valid JSON (no partial leading line).
|
|
663
|
-
for (const line of tail.split("\n").filter(Boolean)) {
|
|
664
|
-
JSON.parse(line);
|
|
665
|
-
}
|
|
666
|
-
} finally { await rmRoot(root); }
|
|
667
|
-
});
|
|
668
|
-
|
|
669
|
-
test("sweepRetention deletes stale log files older than logDays", async () => {
|
|
670
|
-
const root = await makeAgentRoot();
|
|
671
|
-
try {
|
|
672
|
-
const paths = ensureBusDirs(root);
|
|
673
|
-
const dayMs = 24 * 60 * 60 * 1000;
|
|
674
|
-
const now = Date.UTC(2026, 4, 31);
|
|
675
|
-
const dateName = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
676
|
-
const oldLog = join(paths.logsDir, `${dateName(now - 40 * dayMs)}.jsonl`);
|
|
677
|
-
const freshLog = join(paths.logsDir, `${dateName(now - 2 * dayMs)}.jsonl`);
|
|
678
|
-
writeFileSync(oldLog, '{"x":1}\n');
|
|
679
|
-
writeFileSync(freshLog, '{"x":2}\n');
|
|
680
|
-
|
|
681
|
-
const stats = sweepRetention(root, { now, logDays: 14 });
|
|
682
|
-
assert.equal(stats.logsDeleted, 1);
|
|
683
|
-
assert.equal(existsSync(oldLog), false);
|
|
684
|
-
assert.equal(existsSync(freshLog), true);
|
|
685
|
-
} finally { await rmRoot(root); }
|
|
686
|
-
});
|
|
687
|
-
|
|
688
|
-
test("sweepRetention is a no-op (no throw) on an empty/missing bus", async () => {
|
|
689
|
-
const root = await makeAgentRoot();
|
|
690
|
-
try {
|
|
691
|
-
const stats = sweepRetention(root);
|
|
692
|
-
assert.equal(stats.processedDirsDeleted, 0);
|
|
693
|
-
assert.equal(stats.dlqDeleted, 0);
|
|
694
|
-
assert.equal(stats.queueRotated, false);
|
|
695
|
-
assert.equal(stats.logsDeleted, 0);
|
|
696
|
-
} finally { await rmRoot(root); }
|
|
697
|
-
});
|
|
698
|
-
|
|
699
|
-
test("sweepRetention honours MAESTRO_RETENTION_DAYS env for processed dirs", async () => {
|
|
700
|
-
const root = await makeAgentRoot();
|
|
701
|
-
const prev = process.env.MAESTRO_RETENTION_DAYS;
|
|
702
|
-
try {
|
|
703
|
-
const paths = ensureBusDirs(root);
|
|
704
|
-
const dayMs = 24 * 60 * 60 * 1000;
|
|
705
|
-
const now = Date.UTC(2026, 4, 31);
|
|
706
|
-
const dateName = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
707
|
-
const dir = join(paths.processed, dateName(now - 5 * dayMs)); // 5 days old
|
|
708
|
-
mkdirSync(dir, { recursive: true });
|
|
709
|
-
writeFileSync(join(dir, "evt.json"), "{}");
|
|
710
|
-
|
|
711
|
-
process.env.MAESTRO_RETENTION_DAYS = "3"; // 5d > 3d → delete
|
|
712
|
-
const stats = sweepRetention(root, { now });
|
|
713
|
-
assert.equal(stats.processedDirsDeleted, 1);
|
|
714
|
-
assert.equal(existsSync(dir), false);
|
|
715
|
-
} finally {
|
|
716
|
-
if (prev === undefined) delete process.env.MAESTRO_RETENTION_DAYS;
|
|
717
|
-
else process.env.MAESTRO_RETENTION_DAYS = prev;
|
|
718
|
-
await rmRoot(root);
|
|
719
|
-
}
|
|
720
|
-
});
|