@sleep2agi/commhub-server 0.9.0-preview.27 → 0.9.0-preview.270
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/README.md +120 -3
- package/bin/commhub.ts +93 -9
- package/build-info.json +7 -0
- package/package.json +10 -8
- package/src/ack-create-request-transport.test.ts +182 -0
- package/src/ack-create-request.test.ts +52 -8
- package/src/admin-delete-network-http.test.ts +229 -0
- package/src/admin-networks-http.test.ts +88 -0
- package/src/adoption-candidates-http.test.ts +140 -0
- package/src/adoption-candidates.ts +158 -0
- package/src/agent-access-batch.test.ts +210 -0
- package/src/agent-access.ts +585 -0
- package/src/agent-acl-groups-http.test.ts +247 -0
- package/src/agent-acl-http.test.ts +691 -0
- package/src/agent-acl-slice3-http.test.ts +885 -0
- package/src/agent-department-grants.test.ts +129 -0
- package/src/agent-department-http.test.ts +215 -0
- package/src/agent-groups-perf.test.ts +223 -0
- package/src/agent-notice.ts +48 -0
- package/src/agent-team-whoami-http.test.ts +98 -0
- package/src/agent-teams-http.test.ts +330 -0
- package/src/agent-teams.ts +244 -0
- package/src/alias-baseline-2571.test.ts +162 -0
- package/src/alias-baseline.ts +113 -0
- package/src/alias-filter.test.ts +72 -0
- package/src/alias-filter.ts +42 -0
- package/src/api-host-supervisors-can-create-nodes.test.ts +350 -0
- package/src/api-host-supervisors-fallback.test.ts +6 -7
- package/src/api-host-supervisors-runtime-readiness.test.ts +195 -0
- package/src/api-nodes-shape.test.ts +131 -4
- package/src/auth-abuse-counters.test.ts +144 -0
- package/src/auth-abuse-counters.ts +122 -0
- package/src/auth-layer-shape.test.ts +105 -0
- package/src/auth-password-change-cli-tokens-http.test.ts +423 -0
- package/src/auth-sessions-http.test.ts +260 -0
- package/src/auth-validate.test.ts +5 -1
- package/src/auth-weak-password-login.test.ts +176 -0
- package/src/auth.ts +641 -68
- package/src/backfill-node-ids-2664.test.ts +128 -0
- package/src/binding-generation-http.test.ts +141 -0
- package/src/blocked-exit-on-reply.test.ts +122 -0
- package/src/broadcast-fanout-2721.test.ts +149 -0
- package/src/broadcast-fanout.ts +117 -0
- package/src/build-commit-report-http.test.ts +128 -0
- package/src/build-info.test.ts +60 -0
- package/src/build-info.ts +85 -0
- package/src/chain-attempt-dedup.test.ts +447 -0
- package/src/clip.test.ts +36 -0
- package/src/clip.ts +48 -0
- package/src/clone-node.test.ts +269 -0
- package/src/clone-node.ts +289 -0
- package/src/codex-config-flags.ts +77 -0
- package/src/codex-fork-contract.ts +23 -0
- package/src/codex-fork-migration.test.ts +38 -0
- package/src/commhub-bin-args.test.ts +85 -0
- package/src/config-apply-validate.test.ts +188 -1
- package/src/config-apply-validate.ts +222 -3
- package/src/cors-origins.test.ts +73 -0
- package/src/create-node-blocked-gate.test.ts +365 -0
- package/src/create-node-error-domain.test.ts +127 -0
- package/src/create-node-network-id.test.ts +91 -0
- package/src/create-node-tool-schema.test.ts +49 -0
- package/src/create-node-unicode-name.test.ts +126 -0
- package/src/create-node-validate.test.ts +199 -7
- package/src/create-node-validate.ts +232 -15
- package/src/create-node-workdir.test.ts +298 -0
- package/src/create-node.ts +88 -23
- package/src/daemon-provider-snapshots.test.ts +453 -0
- package/src/daemon-provider-snapshots.ts +327 -0
- package/src/daemon-token-owner-http.test.ts +346 -0
- package/src/dashboard-slash-routing-http.test.ts +109 -0
- package/src/db-adapter-guard.test.ts +148 -0
- package/src/db-adapter-translate.test.ts +128 -0
- package/src/db-adapter.ts +377 -91
- package/src/db-timestamp.test.ts +38 -0
- package/src/db-timestamp.ts +15 -0
- package/src/db.ts +1298 -153
- package/src/delivered-without-push.test.ts +140 -0
- package/src/department-groups-http.test.ts +209 -0
- package/src/department-groups-sync-http.test.ts +328 -0
- package/src/department-groups.ts +434 -0
- package/src/department-heads-http.test.ts +350 -0
- package/src/department-heads.ts +226 -0
- package/src/departments-agent-count.test.ts +139 -0
- package/src/departments-http.test.ts +185 -0
- package/src/departments-mcp-error-domain.test.ts +135 -0
- package/src/departments-mcp.test.ts +128 -0
- package/src/departments.ts +318 -0
- package/src/desktop-message-seam.test.ts +150 -0
- package/src/desktop-message.test.ts +368 -0
- package/src/dm-file-scope-http.test.ts +227 -0
- package/src/empty-node-sweeper.test.ts +104 -0
- package/src/empty-node-sweeper.ts +88 -0
- package/src/env-transport-gate-http.test.ts +240 -0
- package/src/env-transport-gate.ts +80 -0
- package/src/env-transport-policy.ts +56 -0
- package/src/etag-of.test.ts +57 -0
- package/src/event-loop-lag.test.ts +180 -0
- package/src/event-loop-lag.ts +201 -0
- package/src/expiry-counters.test.ts +187 -0
- package/src/expiry-counters.ts +227 -0
- package/src/expiry-evidence-db.test.ts +103 -0
- package/src/ext-token-shared.test.ts +60 -0
- package/src/ext-validation-regression.test.ts +10 -17
- package/src/external-schedule-edits-http.test.ts +321 -0
- package/src/external-schedule-edits-timestamps.test.ts +64 -0
- package/src/external-schedule-edits.ts +327 -0
- package/src/file-download-authz-dev-open.test.ts +1 -1
- package/src/file-download-authz.test.ts +25 -4
- package/src/file-download-date-bucket.test.ts +1 -1
- package/src/file-network-scope-dev-open.test.ts +1 -1
- package/src/file-network-scope.test.ts +7 -6
- package/src/group-membership-events-http.test.ts +264 -0
- package/src/group-messages-http.test.ts +483 -0
- package/src/group-messages.ts +297 -0
- package/src/health-anon-readers.ts +67 -0
- package/src/health-host-disk-2756.test.ts +71 -0
- package/src/health-identity-root.test.ts +98 -0
- package/src/health-redaction.test.ts +1599 -7
- package/src/health-status-reasons.test.ts +84 -0
- package/src/host-supervisor-identity-http.test.ts +152 -0
- package/src/host-supervisor-identity.ts +92 -0
- package/src/host-supervisors-daemon-version.test.ts +137 -0
- package/src/http-gzip.test.ts +94 -0
- package/src/http-gzip.ts +112 -0
- package/src/hub-catalog-read-http.test.ts +664 -0
- package/src/hub-provider-config.test.ts +166 -0
- package/src/hub-provider-config.ts +202 -0
- package/src/hub-timestamp.test.ts +38 -0
- package/src/hub-timestamp.ts +27 -0
- package/src/human-dm.ts +215 -0
- package/src/human-inbox.ts +42 -0
- package/src/inbox-caller.ts +49 -0
- package/src/inbox-count-sse.test.ts +318 -0
- package/src/inbox-count.ts +29 -0
- package/src/index.ts +6 -2
- package/src/license-state.test.ts +105 -0
- package/src/license-state.ts +48 -0
- package/src/lifecycle-error-domain.test.ts +149 -0
- package/src/list-ack-error-domain.test.ts +108 -0
- package/src/list-host-supervisors.test.ts +15 -4
- package/src/list-tasks-omit-default.test.ts +84 -0
- package/src/list-tasks-since-last.test.ts +100 -0
- package/src/list-tasks-since.test.ts +104 -0
- package/src/mcp-context-cost-http.test.ts +127 -0
- package/src/mcp-inflight.test.ts +92 -0
- package/src/mcp-inflight.ts +38 -0
- package/src/mcp-projects-events-http.test.ts +168 -0
- package/src/mcp-route-label-http.test.ts +120 -0
- package/src/mcp-write-network-resolution.test.ts +21 -0
- package/src/member-audit-network-id-http.test.ts +93 -0
- package/src/member-presence-http.test.ts +210 -0
- package/src/messages-ack-by-agent-http.test.ts +142 -0
- package/src/migrate-sqlite-to-pg.test.ts +47 -0
- package/src/migrate-sqlite-to-pg.ts +263 -0
- package/src/model-auth-notify-http.test.ts +181 -0
- package/src/model-auth-notify.ts +116 -0
- package/src/network-name-http.test.ts +75 -0
- package/src/network-quota-config.test.ts +100 -0
- package/src/network-rules-http.test.ts +169 -0
- package/src/network-rules.ts +129 -0
- package/src/network-scope.ts +222 -3
- package/src/network-token-membership-http.test.ts +186 -0
- package/src/node-alias-control.ts +12 -0
- package/src/node-attrs.test.ts +47 -2
- package/src/node-caller-identity-http.test.ts +1108 -0
- package/src/node-config-last-update.test.ts +126 -0
- package/src/node-config-last-update.ts +107 -0
- package/src/node-create-request-status-http.test.ts +105 -0
- package/src/node-daemon-bindings.test.ts +142 -0
- package/src/node-daemon-bindings.ts +135 -0
- package/src/node-failure-alert.test.ts +150 -0
- package/src/node-failure-alert.ts +177 -0
- package/src/node-files-transport.test.ts +350 -0
- package/src/node-health-codex-login.test.ts +120 -0
- package/src/node-health-dispatch-http.test.ts +373 -0
- package/src/node-health-guard-origin.test.ts +98 -0
- package/src/node-health-guard.ts +121 -0
- package/src/node-health-passthrough.test.ts +115 -0
- package/src/node-health-store.ts +101 -0
- package/src/node-id-alias.test.ts +190 -0
- package/src/node-identity-conflict-http.test.ts +269 -0
- package/src/node-identity-conflict.ts +142 -0
- package/src/node-identity-mismatch.test.ts +74 -0
- package/src/node-in-flight-tasks.ts +31 -0
- package/src/node-lifecycle-controllable.test.ts +64 -0
- package/src/node-lifecycle-controllable.ts +53 -0
- package/src/node-lifecycle-read-http.test.ts +257 -0
- package/src/node-lifecycle-read.ts +124 -0
- package/src/node-logs-transport.test.ts +266 -0
- package/src/node-peer-allowlist.test.ts +114 -0
- package/src/node-permissions-http.test.ts +901 -0
- package/src/node-permissions.ts +494 -0
- package/src/node-request-retention.test.ts +281 -0
- package/src/node-request-retention.ts +120 -0
- package/src/node-secret-rest-http.test.ts +190 -0
- package/src/node-secret-vault-inject.test.ts +132 -0
- package/src/node-security-write-gate.test.ts +72 -0
- package/src/node-serviceability.test.ts +86 -0
- package/src/node-serviceability.ts +124 -0
- package/src/node-session-control-http.test.ts +310 -0
- package/src/node-session-control.ts +258 -0
- package/src/node-skills-transport.test.ts +212 -0
- package/src/node-token-identity.ts +35 -0
- package/src/node-token-ownership.ts +51 -0
- package/src/node-token-privilege-http.test.ts +224 -0
- package/src/not-found-api-http.test.ts +67 -0
- package/src/observer-avatar-http.test.ts +103 -10
- package/src/observer-push.test.ts +76 -0
- package/src/opencode-catalog-report-http.test.ts +139 -0
- package/src/opencode-v2-catalog.test.ts +268 -0
- package/src/opencode-v2-catalog.ts +356 -0
- package/src/package-version-consistency.test.ts +25 -0
- package/src/parent-infer.test.ts +82 -0
- package/src/parent-infer.ts +110 -0
- package/src/parent-source-marker.test.ts +70 -0
- package/src/parent-source-orphan.test.ts +121 -0
- package/src/password-network-tokens.ts +25 -0
- package/src/peer-reply-atomic.test.ts +462 -0
- package/src/peer-reply-capability.test.ts +70 -0
- package/src/pg-worker.ts +87 -0
- package/src/poll-pacing.test.ts +74 -0
- package/src/poll-pacing.ts +123 -0
- package/src/probe-provider-error-domain.test.ts +145 -0
- package/src/project-dir-warn-clear-http.test.ts +132 -0
- package/src/project-viewer-can-http.test.ts +116 -0
- package/src/provider-skill-error-domain.test.ts +130 -0
- package/src/provider-tools-shape.test.ts +165 -0
- package/src/push.test.ts +20 -10
- package/src/push.ts +373 -9
- package/src/redact-tokens.test.ts +86 -0
- package/src/redact-tokens.ts +43 -0
- package/src/rejection-counters.test.ts +72 -0
- package/src/rejection-counters.ts +173 -0
- package/src/rename.ts +38 -10
- package/src/reply-target-derivation.test.ts +96 -0
- package/src/report-status-handover-capabilities-http.test.ts +124 -0
- package/src/report-status-host-schema.test.ts +235 -0
- package/src/report-status-resume-id-handover.test.ts +184 -0
- package/src/report-status-secret-keys.test.ts +140 -0
- package/src/require-explicit-test-db.ts +9 -0
- package/src/requirement-due-reminders-http.test.ts +620 -0
- package/src/requirement-due-reminders.ts +416 -0
- package/src/requirement-events-http.test.ts +318 -0
- package/src/requirement-events.test.ts +45 -0
- package/src/requirement-events.ts +144 -0
- package/src/requirement-notify.ts +165 -0
- package/src/requirement-participant-notify-http.test.ts +313 -0
- package/src/requirement-tag-ops-http.test.ts +454 -0
- package/src/requirement-tag-tree-http.test.ts +275 -0
- package/src/requirement-tag-tree.ts +127 -0
- package/src/requirement-tags.ts +102 -0
- package/src/requirements-abandoned-http.test.ts +236 -0
- package/src/requirements-assignee-drift.test.ts +154 -0
- package/src/requirements-comment-http.test.ts +174 -0
- package/src/requirements-completed-at-migration.test.ts +70 -0
- package/src/requirements-errors-mcp-http.test.ts +164 -0
- package/src/requirements-errors.ts +158 -0
- package/src/requirements-etag-http.test.ts +91 -0
- package/src/requirements-http.test.ts +709 -0
- package/src/requirements-last-event-http.test.ts +349 -0
- package/src/requirements-list-mcp-slim-http.test.ts +155 -0
- package/src/requirements-list-slim-http.test.ts +324 -0
- package/src/requirements-mcp.test.ts +180 -0
- package/src/requirements-migrate.ts +283 -0
- package/src/requirements-owner-strict-mcp-http.test.ts +145 -0
- package/src/requirements-people-http.test.ts +114 -0
- package/src/requirements-people-mcp-http.test.ts +231 -0
- package/src/requirements-people.ts +196 -0
- package/src/requirements-priority-lowest.test.ts +114 -0
- package/src/requirements-projects-network-echo.test.ts +57 -0
- package/src/requirements-projects-parent-http.test.ts +123 -0
- package/src/requirements-search-http.test.ts +182 -0
- package/src/requirements-search.test.ts +32 -0
- package/src/requirements-search.ts +145 -0
- package/src/requirements-seq-http.test.ts +193 -0
- package/src/requirements-seq-migration.test.ts +63 -0
- package/src/requirements-start-date.test.ts +125 -0
- package/src/requirements-stats-http.test.ts +357 -0
- package/src/requirements-stats.ts +195 -0
- package/src/requirements-status-participants-http.test.ts +222 -0
- package/src/requirements-upgrade-e2e.test.ts +126 -0
- package/src/requirements-upgrade-migration.test.ts +98 -0
- package/src/requirements.ts +2205 -0
- package/src/resolve-port.test.ts +57 -0
- package/src/resolve-port.ts +44 -0
- package/src/rest-alias-network-fallback-http.test.ts +123 -0
- package/src/rest-alias-network-fallback.test.ts +60 -0
- package/src/rest-alias-network-fallback.ts +65 -0
- package/src/rest-explicit-columns-http.test.ts +266 -0
- package/src/rest-identity.test.ts +130 -0
- package/src/rest-identity.ts +141 -0
- package/src/rest-projections.ts +72 -0
- package/src/rest-read-network-real-chain.test.ts +97 -0
- package/src/rest-write-network-resolution.test.ts +133 -0
- package/src/restart-readiness-http.test.ts +121 -0
- package/src/restricted-files.ts +76 -0
- package/src/retention-first-sweep-quiet.test.ts +31 -0
- package/src/retention.test.ts +100 -40
- package/src/retention.ts +423 -104
- package/src/route-callers-http.test.ts +120 -0
- package/src/route-timing.test.ts +218 -0
- package/src/route-timing.ts +262 -0
- package/src/rules-file-duplicate-alias.test.ts +234 -0
- package/src/rules-file-session-target.test.ts +207 -0
- package/src/rules-file-transport.test.ts +271 -0
- package/src/runtime-label.test.ts +22 -0
- package/src/runtime-label.ts +21 -0
- package/src/runtime-readiness.ts +90 -0
- package/src/schedule-agent-mcp-http.test.ts +486 -0
- package/src/schedule-agent.ts +252 -0
- package/src/schedule-starved.test.ts +92 -0
- package/src/schedule-starved.ts +114 -0
- package/src/scheduled-backoff-http.test.ts +203 -0
- package/src/scheduled-backoff.ts +64 -0
- package/src/scheduled-doorbell-nodeless-session.test.ts +134 -0
- package/src/scheduled-failure-backoff-2622.test.ts +145 -0
- package/src/scheduled-failure-code.test.ts +73 -0
- package/src/scheduled-failure-code.ts +105 -0
- package/src/scheduled-failures-http.test.ts +279 -0
- package/src/scheduled-failures.ts +425 -0
- package/src/scheduled-noprogress-backoff-2622.test.ts +163 -0
- package/src/scheduled-offline-backoff-probe.test.ts +56 -0
- package/src/scheduled-offline.test.ts +131 -0
- package/src/scheduled-offline.ts +66 -0
- package/src/scheduled-outcome-guidance-http.test.ts +139 -0
- package/src/scheduled-outcome-guidance.ts +9 -0
- package/src/scheduled-reply-unread-http.test.ts +212 -0
- package/src/scheduled-requirement-wake-http.test.ts +289 -0
- package/src/scheduled-requirement-wake.ts +125 -0
- package/src/scheduled-run-terminal.test.ts +290 -0
- package/src/scheduled-skip-blocking-task.test.ts +120 -0
- package/src/scheduled-skip-path-backoff-2622.test.ts +98 -0
- package/src/scheduled-stuck-http.test.ts +316 -0
- package/src/scheduled-stuck-notice-cap.test.ts +80 -0
- package/src/scheduled-stuck.ts +219 -0
- package/src/scheduled-tasks-http.test.ts +679 -0
- package/src/scheduled-tasks.ts +959 -0
- package/src/scheduled-work-outcome-http.test.ts +154 -0
- package/src/scheduled-work-outcome.ts +50 -0
- package/src/scoped-secrets.ts +167 -0
- package/src/secret-echo-negative-control.test.ts +118 -0
- package/src/send-dedup-request-id.test.ts +229 -0
- package/src/send-reply-agent-warning.test.ts +38 -38
- package/src/send-reply-alias-optional.test.ts +131 -0
- package/src/send-reply-attachments.test.ts +28 -7
- package/src/send_dedup.test.ts +54 -0
- package/src/send_dedup.ts +52 -6
- package/src/serve-error.test.ts +73 -0
- package/src/serve-error.ts +56 -0
- package/src/server.ts +4930 -377
- package/src/session-task-on-dispatch.ts +14 -0
- package/src/session-token-ownership-http.test.ts +122 -0
- package/src/shared/codex-inventory.ts +41 -0
- package/src/shared/daemon-provider-login.ts +31 -0
- package/src/shared/daemon-provider-snapshot.ts +52 -0
- package/src/shared/external-schedule-contract.ts +60 -0
- package/src/shared/node-name.test.ts +62 -0
- package/src/shared/node-name.ts +161 -0
- package/src/shared/probe-host-allowlist-drift.test.ts +45 -0
- package/src/shared/provider-application.ts +29 -0
- package/src/shared/provider-collection.ts +14 -0
- package/src/shared/provider-initialization.ts +8 -0
- package/src/shared/reserved-env-drift.test.ts +10 -0
- package/src/shared/scoped-secret-contract.ts +5 -0
- package/src/shared/task-content-limit-drift.test.ts +28 -0
- package/src/shared/task-content-limit.ts +25 -0
- package/src/side-thread-command-transport.test.ts +312 -0
- package/src/side-thread-command-transport.ts +318 -0
- package/src/side-thread-http-integration.test.ts +233 -0
- package/src/side-thread-http.ts +504 -0
- package/src/side-thread-production.test.ts +72 -0
- package/src/side-thread-production.ts +118 -0
- package/src/side-thread.test.ts +1067 -0
- package/src/side-thread.ts +2499 -0
- package/src/skillhub-http.test.ts +144 -0
- package/src/sqlite-close-checkpoint.test.ts +78 -0
- package/src/start-node.test.ts +265 -0
- package/src/start-request-error-domain.test.ts +182 -0
- package/src/start-skill-error-domain.test.ts +122 -0
- package/src/stats-versions-http.test.ts +65 -0
- package/src/status-alias-filter-http.test.ts +106 -0
- package/src/status-alias-resolver-http.test.ts +163 -0
- package/src/status-alias-resolver.ts +19 -0
- package/src/status-node-id-filter-http.test.ts +161 -0
- package/src/status-read-cache-http.test.ts +229 -0
- package/src/status-read-cache.ts +129 -0
- package/src/stop-delete-node.test.ts +567 -1
- package/src/task-access-http.test.ts +407 -0
- package/src/task-access.ts +420 -0
- package/src/task-activity.ts +60 -0
- package/src/task-auth-origin-http.test.ts +93 -0
- package/src/task-auth-origin.test.ts +24 -0
- package/src/task-auth-origin.ts +7 -0
- package/src/task-consumption.test.ts +508 -0
- package/src/task-diagnostic-http.test.ts +149 -0
- package/src/task-diagnostic.test.ts +115 -0
- package/src/task-diagnostic.ts +118 -0
- package/src/task-expiry-notice-http.test.ts +298 -0
- package/src/task-expiry-notice.ts +318 -0
- package/src/task-idempotency-mcp.test.ts +148 -0
- package/src/task-idempotency.test.ts +76 -0
- package/src/task-idempotency.ts +81 -0
- package/src/task-late-replies.ts +54 -0
- package/src/task-late-reply-http.test.ts +227 -0
- package/src/task-lifecycle-watcher-busy.test.ts +114 -0
- package/src/task-lifecycle-watcher.test.ts +209 -0
- package/src/task-lifecycle-watcher.ts +109 -0
- package/src/task-network-resolution-http.test.ts +140 -0
- package/src/task-not-found-error-domain.test.ts +114 -0
- package/src/task-offline-delivery-2668.test.ts +119 -0
- package/src/task-offline-delivery.ts +81 -0
- package/src/task-orphan-http.test.ts +287 -0
- package/src/task-orphan.ts +119 -0
- package/src/task-queue-ahead-http.test.ts +309 -0
- package/src/task-queue-ahead-scale.test.ts +236 -0
- package/src/task-queue-ahead.ts +186 -0
- package/src/task-rejection-log-http.test.ts +160 -0
- package/src/task-rejection-log.ts +61 -0
- package/src/task-sender-http.test.ts +143 -0
- package/src/task-stale-open-http.test.ts +292 -0
- package/src/task-stale-open.ts +103 -0
- package/src/tasks-pagination-http.test.ts +141 -0
- package/src/team-rules-status-http.test.ts +90 -0
- package/src/team-rules-status.test.ts +59 -0
- package/src/team-rules-status.ts +72 -0
- package/src/tmux-allowlist.test.ts +48 -0
- package/src/tool-audience-http.test.ts +248 -0
- package/src/tool-audience.ts +127 -0
- package/src/tools-list-json-schema.test.ts +94 -0
- package/src/tools.ts +4314 -392
- package/src/update-node-config-error-domain.test.ts +107 -0
- package/src/uploads-http.test.ts +6 -4
- package/src/uploads.ts +23 -4
- package/src/user-avatar-http.test.ts +74 -0
- package/src/user-avatar-image.ts +160 -0
- package/src/user-avatar-migration.test.ts +25 -0
- package/src/user-avatar-upload-http.test.ts +353 -0
- package/src/user-inbox-by-agent-http.test.ts +189 -0
- package/src/user-inbox-netid-notnull.test.ts +122 -0
- package/src/user-inbox-read-http.test.ts +223 -0
- package/src/user-inbox-schema.test.ts +54 -0
- package/src/version-stats.test.ts +66 -0
- package/src/version-stats.ts +109 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// #3348 —— 父被丢弃时,**来源必须一起丢弃**。
|
|
2
|
+
//
|
|
3
|
+
// ## 生产读数(修之前)
|
|
4
|
+
//
|
|
5
|
+
// tasks 131684 行里 2 条:
|
|
6
|
+
// meta = {"parent_source":"explicit"},parent_task_id / in_reply_to / thread_id 全空
|
|
7
|
+
// 5bc82d72 2026-10-30 16:08:38 · d002b739 2026-10-31 02:23:09
|
|
8
|
+
//
|
|
9
|
+
// ## 为什么会出现
|
|
10
|
+
//
|
|
11
|
+
// `send_task` 里的顺序是:
|
|
12
|
+
//
|
|
13
|
+
// ① `if (parentSource && parentTaskId) { meta.parent_source = parentSource }` ← 拼 meta
|
|
14
|
+
// ② 校验显式父是否存在;不存在 ⇒ `parentTaskId = null` ← 丢父
|
|
15
|
+
// ③ INSERT(meta 用 ①,父用 ② 之后的值)
|
|
16
|
+
//
|
|
17
|
+
// ⇒ ② 与 ① 之间没有连线。`meta` 里保留了「有一个 explicit 父」这个陈述,
|
|
18
|
+
// 而那一行本身没有父。
|
|
19
|
+
//
|
|
20
|
+
// ## 为什么这条不变式的正向断言抓不到它
|
|
21
|
+
//
|
|
22
|
+
// `#669` 的不变式是「父有值 ⇒ 来源有值」。这一格是「来源有值 ⇒ 父有值」的反面,
|
|
23
|
+
// 两个方向各自都合理,合起来留了一个空格 —— 而空格里正好能站下一行坏数据。
|
|
24
|
+
// `scripts/report-parent-source-coverage.py` 现在把这一格单列成 `source, no parent` 并报数。
|
|
25
|
+
//
|
|
26
|
+
// ## 这里测什么
|
|
27
|
+
//
|
|
28
|
+
// 走**真 handler**(不是镜像映射):派一条带不存在父的任务,断言
|
|
29
|
+
// ① 任务照样建成(丢父是「不阻塞派发」的决定,不是错误)
|
|
30
|
+
// ② parent_task_id 落库为 NULL
|
|
31
|
+
// ③ meta_json 里**没有** parent_source —— 这一条是本次修的
|
|
32
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
33
|
+
import { mkdtempSync } from "fs";
|
|
34
|
+
import { join } from "path";
|
|
35
|
+
import { tmpdir } from "os";
|
|
36
|
+
|
|
37
|
+
process.env.COMMHUB_DB = join(mkdtempSync(join(tmpdir(), "anet-orphan-source-")), "commhub.db");
|
|
38
|
+
|
|
39
|
+
const { McpServer } = await import("@modelcontextprotocol/sdk/server/mcp.js");
|
|
40
|
+
const { db } = await import("./db.js");
|
|
41
|
+
const { registerTools } = await import("./tools.js");
|
|
42
|
+
|
|
43
|
+
const NET = "net_orphan_src";
|
|
44
|
+
const USER = "u_orphan_src";
|
|
45
|
+
const PEER = "osp-peer";
|
|
46
|
+
const TARGET = "osp-target";
|
|
47
|
+
|
|
48
|
+
type Handler = (args: any, extra?: any) => Promise<{ content: Array<{ type: "text"; text: string }> }>;
|
|
49
|
+
|
|
50
|
+
function cleanup(): void {
|
|
51
|
+
for (const table of ["task_events", "inbox", "tasks", "sessions", "nodes", "network_members", "networks"]) {
|
|
52
|
+
try { db.run(`DELETE FROM ${table} WHERE network_id = ?1`, [NET]); } catch {}
|
|
53
|
+
}
|
|
54
|
+
try { db.run("DELETE FROM users WHERE user_id = ?1", [USER]); } catch {}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function seed(): void {
|
|
58
|
+
db.run("INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?2, 'x', 'user', datetime('now'))", [USER, USER]);
|
|
59
|
+
db.run("INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?1, ?2, datetime('now'))", [NET, USER]);
|
|
60
|
+
db.run("INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'owner', datetime('now'))", [USER, NET]);
|
|
61
|
+
for (const alias of [PEER, TARGET]) {
|
|
62
|
+
db.run(
|
|
63
|
+
`INSERT INTO nodes (node_id, node_name, alias, network_id, lifecycle_state)
|
|
64
|
+
VALUES (?1, ?2, ?2, ?3, 'active')`,
|
|
65
|
+
[`n_${alias}`, alias, NET],
|
|
66
|
+
);
|
|
67
|
+
db.run(
|
|
68
|
+
`INSERT INTO sessions (resume_id, alias, status, node_id, network_id, updated_at, last_seen_at)
|
|
69
|
+
VALUES (?1, ?2, 'idle', ?3, ?4, datetime('now'), datetime('now'))`,
|
|
70
|
+
[`r_${alias}`, alias, `n_${alias}`, NET],
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function handlers(): Record<string, Handler> {
|
|
76
|
+
const server = new McpServer({ name: "test-orphan-source", version: "0" }) as any;
|
|
77
|
+
const out: Record<string, Handler> = {};
|
|
78
|
+
const original = server.tool.bind(server);
|
|
79
|
+
server.tool = (name: string, ...args: any[]) => {
|
|
80
|
+
const h = args.at(-1);
|
|
81
|
+
if (typeof h === "function") out[name] = h;
|
|
82
|
+
return original(name, ...args);
|
|
83
|
+
};
|
|
84
|
+
registerTools(server, undefined, NET, USER, PEER, false, null);
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function call(handler: Handler, args: any): Promise<any> {
|
|
89
|
+
const r = await handler(args);
|
|
90
|
+
return JSON.parse(r.content[0].text);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
beforeEach(() => { cleanup(); seed(); });
|
|
94
|
+
afterAll(() => { cleanup(); });
|
|
95
|
+
|
|
96
|
+
describe("#3348 不存在的显式父:父与来源一起丢", () => {
|
|
97
|
+
test("父不存在 ⇒ 任务照样建成,但 parent_task_id 为 NULL 且 meta 里没有 parent_source", async () => {
|
|
98
|
+
const ghost = "00000000-0000-4000-8000-000000000000"; // 不存在的父
|
|
99
|
+
const r = await call(handlers().send_task, {
|
|
100
|
+
alias: TARGET,
|
|
101
|
+
task: "osp dispatch with a ghost parent",
|
|
102
|
+
priority: "normal",
|
|
103
|
+
from_session: PEER,
|
|
104
|
+
network_id: NET,
|
|
105
|
+
parent_task_id: ghost,
|
|
106
|
+
});
|
|
107
|
+
// 丢父是「不阻塞派发」的决定:这条**不能**变成错误,否则一个幻觉 id 会挡掉整条任务。
|
|
108
|
+
expect(r.ok).toBe(true);
|
|
109
|
+
|
|
110
|
+
const row = db.get<{ task_id: string; parent_task_id: string | null; meta_json: string | null }>(
|
|
111
|
+
"SELECT task_id, parent_task_id, meta_json FROM tasks WHERE content = ?1",
|
|
112
|
+
["osp dispatch with a ghost parent"],
|
|
113
|
+
);
|
|
114
|
+
expect(row).toBeTruthy();
|
|
115
|
+
expect(row!.parent_task_id).toBeNull();
|
|
116
|
+
// 关键断言:来源不许单独留下。
|
|
117
|
+
// 留着的后果是库里出现「有来源、没父」这一格 —— #669 的不变式两个方向都放过它,
|
|
118
|
+
// 于是它既不被算作 explicit 也不被算作无父,只在有人专门数「source 无 parent」时才看得见。
|
|
119
|
+
expect(String(row!.meta_json ?? "")).not.toContain("parent_source");
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { db } from "./db.js";
|
|
2
|
+
|
|
3
|
+
export type KeptNetworkToken = {
|
|
4
|
+
token_id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
network_id: string;
|
|
7
|
+
created_at: string;
|
|
8
|
+
last_used_at: string | null;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** Only user-created named network tokens. Node credentials have a different scope or binding. */
|
|
12
|
+
export function passwordNetworkTokens(userId: string, currentTokenId: string | null | undefined, revoke: boolean) {
|
|
13
|
+
const where = `user_id = ?1 AND network_id IS NOT NULL AND scope = 'full'
|
|
14
|
+
AND bound_node_id IS NULL AND revoked_at IS NULL
|
|
15
|
+
AND (expires_at IS NULL OR expires_at > datetime('now'))${currentTokenId ? " AND token_id != ?2" : ""}`;
|
|
16
|
+
const params = currentTokenId ? [userId, currentTokenId] : [userId];
|
|
17
|
+
if (revoke) {
|
|
18
|
+
return { revoked: db.run(`DELETE FROM api_tokens WHERE ${where}`, params).changes, kept: [] as KeptNetworkToken[] };
|
|
19
|
+
}
|
|
20
|
+
const kept = db.all<KeptNetworkToken>(
|
|
21
|
+
`SELECT token_id, name, network_id, created_at, last_used_at FROM api_tokens WHERE ${where} ORDER BY created_at DESC, token_id`,
|
|
22
|
+
...params,
|
|
23
|
+
);
|
|
24
|
+
return { revoked: 0, kept };
|
|
25
|
+
}
|
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { db } from "./db.js";
|
|
4
|
+
import { registerTools } from "./tools.js";
|
|
5
|
+
import { CommHubError } from "../../agent-node/src/reply-reliability.js";
|
|
6
|
+
import { sendPeerReplyCompatible } from "../../agent-node/src/peer-reply-send.js";
|
|
7
|
+
import { __resetSSEClientsForTest, createSSEStream } from "./push.js";
|
|
8
|
+
import { eventBus } from "./event_bus.js";
|
|
9
|
+
|
|
10
|
+
const NET = "net_peer_reply_698";
|
|
11
|
+
const USER = "user_peer_reply_698";
|
|
12
|
+
const A = "peer-a-698";
|
|
13
|
+
const B = "peer-b-698";
|
|
14
|
+
const A_ID = "node-peer-a-698";
|
|
15
|
+
const B_ID = "node-peer-b-698";
|
|
16
|
+
|
|
17
|
+
type ToolHandler = (args: any) => Promise<{ content: Array<{ type: "text"; text: string }> }>;
|
|
18
|
+
|
|
19
|
+
function cleanup() {
|
|
20
|
+
__resetSSEClientsForTest();
|
|
21
|
+
try { db.exec("DROP TRIGGER IF EXISTS test698_abort_terminal"); } catch {}
|
|
22
|
+
try { db.exec("DROP TRIGGER IF EXISTS test698_abort_run"); } catch {}
|
|
23
|
+
for (const table of ["scheduled_task_runs", "scheduled_tasks", "tasks", "inbox", "task_events", "sessions", "api_tokens", "nodes", "rename_txn"]) {
|
|
24
|
+
try { db.run(`DELETE FROM ${table} WHERE network_id = ?1`, [NET]); } catch {}
|
|
25
|
+
}
|
|
26
|
+
try { db.run("DELETE FROM network_members WHERE network_id = ?1", [NET]); } catch {}
|
|
27
|
+
try { db.run("DELETE FROM networks WHERE network_id = ?1", [NET]); } catch {}
|
|
28
|
+
try { db.run("DELETE FROM users WHERE user_id = ?1", [USER]); } catch {}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function seed() {
|
|
32
|
+
db.run("INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?1, 'x', 'user', datetime('now'))", [USER]);
|
|
33
|
+
db.run("INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?1, ?2, datetime('now'))", [NET, USER]);
|
|
34
|
+
db.run("INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'owner', datetime('now'))", [USER, NET]);
|
|
35
|
+
for (const [alias, nodeId] of [[A, A_ID], [B, B_ID]] as const) {
|
|
36
|
+
db.run(
|
|
37
|
+
"INSERT INTO nodes (node_id, node_name, alias, network_id, hostname, config_snapshot, created_at, updated_at, lifecycle_state) VALUES (?1, ?2, ?2, ?3, 'host', ?4, datetime('now'), datetime('now'), 'active')",
|
|
38
|
+
[nodeId, alias, NET, JSON.stringify({ peer_reply_inbox_capable: true })],
|
|
39
|
+
);
|
|
40
|
+
db.run(
|
|
41
|
+
"INSERT INTO sessions (resume_id, alias, status, node_id, network_id, peer_reply_inbox_capable, updated_at, last_seen_at) VALUES (?1, ?2, 'idle', ?3, ?4, 1, datetime('now'), datetime('now'))",
|
|
42
|
+
[`resume-${alias}`, alias, nodeId, NET],
|
|
43
|
+
);
|
|
44
|
+
createSSEStream(alias, NET);
|
|
45
|
+
db.run(
|
|
46
|
+
"INSERT INTO api_tokens (token_id, token_hash, user_id, network_id, name, scope, bound_node_id) VALUES (?1, ?2, ?3, ?4, ?5, 'network', ?6)",
|
|
47
|
+
[`token-${alias}`, `hash-token-${alias}`, USER, NET, `node:${alias}`, nodeId],
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function toolsFor(alias: string): Record<string, ToolHandler> {
|
|
53
|
+
const server = new McpServer({ name: "peer-reply-698", version: "0" }) as any;
|
|
54
|
+
const tools: Record<string, ToolHandler> = {};
|
|
55
|
+
const original = server.tool.bind(server);
|
|
56
|
+
server.tool = (name: string, description: string, schema: any, handler: ToolHandler) => {
|
|
57
|
+
tools[name] = handler;
|
|
58
|
+
return original(name, description, schema, handler);
|
|
59
|
+
};
|
|
60
|
+
registerTools(server, undefined, NET, USER, alias, true, `token-${alias}`);
|
|
61
|
+
return tools;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function call(handler: ToolHandler, args: any) {
|
|
65
|
+
const result = await handler(args);
|
|
66
|
+
return JSON.parse(result.content[0].text);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async function callOrThrow(handler: ToolHandler, args: any) {
|
|
70
|
+
const payload = await call(handler, args);
|
|
71
|
+
if (payload?.ok === false) {
|
|
72
|
+
throw new CommHubError(`app-level rejection: ${payload.error}`, {
|
|
73
|
+
code: payload.error,
|
|
74
|
+
payload,
|
|
75
|
+
appLevel: true,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return payload;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function dispatch(from: string, to: string, content: string): Promise<string> {
|
|
82
|
+
const sent = await call(toolsFor(from).send_task, { alias: to, task: content, priority: "normal" });
|
|
83
|
+
expect(sent.ok).toBe(true);
|
|
84
|
+
return sent.task_id ?? sent.message_id;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function task(taskId: string) {
|
|
88
|
+
return db.get<any>("SELECT * FROM tasks WHERE task_id = ?1", taskId);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function replies(taskId: string) {
|
|
92
|
+
return db.all<any>("SELECT * FROM inbox WHERE in_reply_to = ?1 ORDER BY rowid", taskId);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function bindScheduledRun(taskId: string): { runId: string; scheduleId: string } {
|
|
96
|
+
const suffix = crypto.randomUUID();
|
|
97
|
+
const runId = `srun_${suffix}`;
|
|
98
|
+
const scheduleId = `sched_${suffix}`;
|
|
99
|
+
db.run(
|
|
100
|
+
`INSERT INTO scheduled_tasks
|
|
101
|
+
(schedule_id, network_id, name, target_node_id, target_alias, task_content, priority,
|
|
102
|
+
schedule_type, schedule_json, timezone, status, next_run_at)
|
|
103
|
+
VALUES (?1, ?2, 'peer reply schedule', ?3, ?4, 'scheduled peer task', 'normal',
|
|
104
|
+
'interval', '{"type":"interval","every_seconds":3600}', 'UTC', 'active', datetime('now', '+1 hour'))`,
|
|
105
|
+
[scheduleId, NET, B_ID, B],
|
|
106
|
+
);
|
|
107
|
+
db.run(
|
|
108
|
+
`INSERT INTO scheduled_task_runs
|
|
109
|
+
(run_id, schedule_id, network_id, scheduled_for, task_id, status, completed_at)
|
|
110
|
+
VALUES (?1, ?2, ?3, datetime('now'), ?4, 'delivered', NULL)`,
|
|
111
|
+
[runId, scheduleId, NET, taskId],
|
|
112
|
+
);
|
|
113
|
+
return { runId, scheduleId };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
beforeEach(() => { cleanup(); seed(); });
|
|
117
|
+
afterAll(cleanup);
|
|
118
|
+
|
|
119
|
+
describe("#698 atomic peer reply", () => {
|
|
120
|
+
test("exact bound token works even when sessions.node_id is NULL", async () => {
|
|
121
|
+
const taskId = await dispatch(A, B, "session row is not identity");
|
|
122
|
+
db.run("UPDATE sessions SET node_id = NULL WHERE alias = ?1 AND network_id = ?2", [B, NET]);
|
|
123
|
+
const result = await call(toolsFor(B).send_peer_reply, {
|
|
124
|
+
alias: A, text: "bound-token wins", in_reply_to: taskId, status: "replied",
|
|
125
|
+
});
|
|
126
|
+
// 2026-10-31 —— #3275:send_peer_reply 的形状(此前只断言 ok)。
|
|
127
|
+
// 三键各有用处:message_id 是这条回复的收据;session_status 让调用方不必再查一次
|
|
128
|
+
// 「我这边的会话现在是什么状态」——原子性就体现在这里:回复落库与会话状态是同一次写。
|
|
129
|
+
expect(Object.keys(result).sort()).toEqual(["message_id", "ok", "session_status"]);
|
|
130
|
+
expect(result.session_status).toBe("idle");
|
|
131
|
+
expect(result.ok).toBe(true);
|
|
132
|
+
expect(task(taskId).status).toBe("replied");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("a rollback heartbeat clears the current-session capability before any peer write", async () => {
|
|
136
|
+
const tools = toolsFor(A);
|
|
137
|
+
await call(tools.report_status, {
|
|
138
|
+
resume_id: `resume-${A}`, alias: A, status: "idle", node_id: A_ID,
|
|
139
|
+
config_snapshot: { config_update_capable: true, peer_reply_inbox_capable: true },
|
|
140
|
+
});
|
|
141
|
+
expect(db.get<any>(
|
|
142
|
+
"SELECT peer_reply_inbox_capable FROM sessions WHERE alias = ?1 AND network_id = ?2",
|
|
143
|
+
A, NET,
|
|
144
|
+
).peer_reply_inbox_capable).toBe(1);
|
|
145
|
+
await call(tools.report_status, {
|
|
146
|
+
resume_id: `resume-${A}`, alias: A, status: "idle", node_id: A_ID,
|
|
147
|
+
config_snapshot: { config_update_capable: true },
|
|
148
|
+
});
|
|
149
|
+
expect(db.get<any>(
|
|
150
|
+
"SELECT peer_reply_inbox_capable FROM sessions WHERE alias = ?1 AND network_id = ?2",
|
|
151
|
+
A, NET,
|
|
152
|
+
).peer_reply_inbox_capable).toBe(0);
|
|
153
|
+
|
|
154
|
+
const taskId = await dispatch(A, B, "recipient rolled back");
|
|
155
|
+
const result = await call(toolsFor(B).send_peer_reply, {
|
|
156
|
+
alias: A, text: "must use legacy", in_reply_to: taskId, status: "replied",
|
|
157
|
+
});
|
|
158
|
+
expect(result).toEqual(expect.objectContaining({ ok: false, error: "peer_reply_unsupported" }));
|
|
159
|
+
expect(task(taskId).status).toBe("delivered");
|
|
160
|
+
expect(replies(taskId)).toHaveLength(0);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
test("a capable but disconnected recipient commits atomically for reconnect drain", async () => {
|
|
164
|
+
const taskId = await dispatch(A, B, "recipient disconnected");
|
|
165
|
+
__resetSSEClientsForTest();
|
|
166
|
+
const result = await call(toolsFor(B).send_peer_reply, {
|
|
167
|
+
alias: A, text: "stored for reconnect", in_reply_to: taskId, status: "replied",
|
|
168
|
+
});
|
|
169
|
+
expect(result).toEqual(expect.objectContaining({ ok: true }));
|
|
170
|
+
expect(task(taskId)).toEqual(expect.objectContaining({ status: "replied", result: "stored for reconnect" }));
|
|
171
|
+
expect(replies(taskId)).toHaveLength(1);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("recipient capability is bound to the exact canonical alias, not another session on the same node", async () => {
|
|
175
|
+
const taskId = await dispatch(A, B, "same node must not lend capability across aliases");
|
|
176
|
+
db.run(
|
|
177
|
+
"UPDATE sessions SET peer_reply_inbox_capable = 0 WHERE alias = ?1 AND network_id = ?2",
|
|
178
|
+
[A, NET],
|
|
179
|
+
);
|
|
180
|
+
db.run(
|
|
181
|
+
`INSERT INTO sessions
|
|
182
|
+
(resume_id, alias, status, node_id, network_id, peer_reply_inbox_capable, updated_at, last_seen_at)
|
|
183
|
+
VALUES ('resume-wrong-alias-698', 'wrong-alias-698', 'idle', ?1, ?2, 1,
|
|
184
|
+
datetime('now', '+1 minute'), datetime('now', '+1 minute'))`,
|
|
185
|
+
[A_ID, NET],
|
|
186
|
+
);
|
|
187
|
+
const result = await call(toolsFor(B).send_peer_reply, {
|
|
188
|
+
alias: A, text: "must not borrow wrong alias capability", in_reply_to: taskId, status: "replied",
|
|
189
|
+
});
|
|
190
|
+
expect(result).toEqual(expect.objectContaining({ ok: false, error: "peer_reply_unsupported" }));
|
|
191
|
+
expect(task(taskId)).toEqual(expect.objectContaining({ status: "delivered", result: null }));
|
|
192
|
+
expect(replies(taskId)).toHaveLength(0);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("origin rename during work routes the terminal reply to the canonical alias and stable node", async () => {
|
|
196
|
+
const taskId = await dispatch(A, B, "origin will rename");
|
|
197
|
+
const renamed = `${A}-renamed`;
|
|
198
|
+
db.run(
|
|
199
|
+
`INSERT INTO rename_txn (txn_id, network_id, old_alias, new_alias, status, committed_at)
|
|
200
|
+
VALUES (?1, ?2, ?3, ?4, 'committed', datetime('now'))`,
|
|
201
|
+
[`rtxn-${crypto.randomUUID()}`, NET, A, renamed],
|
|
202
|
+
);
|
|
203
|
+
db.run("UPDATE nodes SET alias = ?1 WHERE node_id = ?2 AND network_id = ?3", [renamed, A_ID, NET]);
|
|
204
|
+
db.run("UPDATE sessions SET alias = ?1 WHERE node_id = ?2 AND network_id = ?3", [renamed, A_ID, NET]);
|
|
205
|
+
eventBus.emit("rename-committed", {
|
|
206
|
+
networkId: NET, old_alias: A, new_alias: renamed, node_id: A_ID,
|
|
207
|
+
});
|
|
208
|
+
const result = await call(toolsFor(B).send_peer_reply, {
|
|
209
|
+
alias: A, text: "reply after rename", in_reply_to: taskId, status: "replied",
|
|
210
|
+
});
|
|
211
|
+
expect(result.ok).toBe(true);
|
|
212
|
+
expect(task(taskId).status).toBe("replied");
|
|
213
|
+
expect(replies(taskId)).toEqual([
|
|
214
|
+
expect.objectContaining({ session_name: renamed, node_id: A_ID, requires_response: "none" }),
|
|
215
|
+
]);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
test("legacy caller or recipient capability downgrade returns unsupported with zero writes", async () => {
|
|
219
|
+
for (const mode of ["caller-unbound", "recipient-downgraded", "legacy-task-origin"] as const) {
|
|
220
|
+
cleanup(); seed();
|
|
221
|
+
const taskId = await dispatch(A, B, `compat-${mode}`);
|
|
222
|
+
if (mode === "caller-unbound") {
|
|
223
|
+
db.run("UPDATE api_tokens SET bound_node_id = NULL WHERE token_id = ?1", `token-${B}`);
|
|
224
|
+
} else if (mode === "recipient-downgraded") {
|
|
225
|
+
db.run("UPDATE sessions SET peer_reply_inbox_capable = 0 WHERE node_id = ?1 AND network_id = ?2", [A_ID, NET]);
|
|
226
|
+
} else {
|
|
227
|
+
db.run("UPDATE tasks SET from_node_id = NULL WHERE task_id = ?1", taskId);
|
|
228
|
+
}
|
|
229
|
+
const result = await call(toolsFor(B).send_peer_reply, {
|
|
230
|
+
alias: A, text: "must fall back", in_reply_to: taskId, status: "replied",
|
|
231
|
+
});
|
|
232
|
+
expect(result).toEqual(expect.objectContaining({
|
|
233
|
+
ok: false,
|
|
234
|
+
error: mode === "legacy-task-origin" ? "peer_reply_origin_not_node" : "peer_reply_unsupported",
|
|
235
|
+
reply_queued: false,
|
|
236
|
+
}));
|
|
237
|
+
expect(task(taskId)).toEqual(expect.objectContaining({ status: "delivered", result: null }));
|
|
238
|
+
expect(replies(taskId)).toHaveLength(0);
|
|
239
|
+
}
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test("old Hub or legacy recipient falls back once and terminalizes the original", async () => {
|
|
243
|
+
for (const mode of ["old-hub", "legacy-recipient"] as const) {
|
|
244
|
+
cleanup(); seed();
|
|
245
|
+
const taskId = await dispatch(A, B, `mixed-${mode}`);
|
|
246
|
+
if (mode === "legacy-recipient") {
|
|
247
|
+
db.run("UPDATE sessions SET peer_reply_inbox_capable = 0 WHERE node_id = ?1 AND network_id = ?2", [A_ID, NET]);
|
|
248
|
+
}
|
|
249
|
+
const tools = toolsFor(B);
|
|
250
|
+
let atomicCalls = 0;
|
|
251
|
+
let legacyReplyCalls = 0;
|
|
252
|
+
const routed = await sendPeerReplyCompatible({
|
|
253
|
+
target: A, text: `fallback-${mode}`, taskId, failed: false, fromAlias: B,
|
|
254
|
+
}, {
|
|
255
|
+
sendAtomic: async (args) => {
|
|
256
|
+
atomicCalls++;
|
|
257
|
+
if (mode === "old-hub") {
|
|
258
|
+
throw new CommHubError("JSON-RPC error: -32601: unknown tool send_peer_reply", { code: -32601 });
|
|
259
|
+
}
|
|
260
|
+
return callOrThrow(tools.send_peer_reply, {
|
|
261
|
+
alias: args.target, text: args.text, in_reply_to: args.taskId, status: "replied",
|
|
262
|
+
});
|
|
263
|
+
},
|
|
264
|
+
sendLegacyReply: async (args) => {
|
|
265
|
+
legacyReplyCalls++;
|
|
266
|
+
return callOrThrow(tools.send_reply, {
|
|
267
|
+
alias: args.target, text: args.text, in_reply_to: args.taskId, status: "replied",
|
|
268
|
+
});
|
|
269
|
+
},
|
|
270
|
+
});
|
|
271
|
+
expect(routed.route).toBe("legacy-reply");
|
|
272
|
+
expect([atomicCalls, legacyReplyCalls]).toEqual([1, 1]);
|
|
273
|
+
expect(task(taskId)).toEqual(expect.objectContaining({ status: "replied", result: `fallback-${mode}` }));
|
|
274
|
+
expect(replies(taskId)).toHaveLength(1);
|
|
275
|
+
expect(db.get<{ n: number }>(
|
|
276
|
+
"SELECT COUNT(*) AS n FROM tasks WHERE parent_task_id = ?1 AND requires_response = 'reply'",
|
|
277
|
+
taskId,
|
|
278
|
+
)?.n).toBe(0);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
test("node-id rotation falls back to alias-bound terminal send_reply", async () => {
|
|
283
|
+
const taskId = await dispatch(A, B, "rotate B after dispatch");
|
|
284
|
+
const rotatedNodeId = `${B_ID}-rotated`;
|
|
285
|
+
db.run(
|
|
286
|
+
"INSERT INTO nodes (node_id, node_name, alias, network_id, hostname, config_snapshot, created_at, updated_at, lifecycle_state) VALUES (?1, ?2, ?2, ?3, 'host-rotated', ?4, datetime('now'), datetime('now'), 'active')",
|
|
287
|
+
[rotatedNodeId, B, NET, JSON.stringify({ peer_reply_inbox_capable: true })],
|
|
288
|
+
);
|
|
289
|
+
db.run("UPDATE api_tokens SET bound_node_id = ?1 WHERE token_id = ?2", [rotatedNodeId, `token-${B}`]);
|
|
290
|
+
db.run("UPDATE sessions SET node_id = ?1 WHERE alias = ?2 AND network_id = ?3", [rotatedNodeId, B, NET]);
|
|
291
|
+
|
|
292
|
+
const tools = toolsFor(B);
|
|
293
|
+
let atomicCalls = 0;
|
|
294
|
+
let legacyReplyCalls = 0;
|
|
295
|
+
const routed = await sendPeerReplyCompatible({
|
|
296
|
+
target: A, text: "result after identity rotation", taskId, failed: false, fromAlias: B,
|
|
297
|
+
}, {
|
|
298
|
+
sendAtomic: async (args) => {
|
|
299
|
+
atomicCalls++;
|
|
300
|
+
return callOrThrow(tools.send_peer_reply, {
|
|
301
|
+
alias: args.target, text: args.text, in_reply_to: args.taskId, status: "replied",
|
|
302
|
+
});
|
|
303
|
+
},
|
|
304
|
+
sendLegacyReply: async (args) => {
|
|
305
|
+
legacyReplyCalls++;
|
|
306
|
+
return callOrThrow(tools.send_reply, {
|
|
307
|
+
alias: args.target, text: args.text, in_reply_to: args.taskId, status: "replied",
|
|
308
|
+
});
|
|
309
|
+
},
|
|
310
|
+
});
|
|
311
|
+
|
|
312
|
+
expect(routed.route).toBe("legacy-reply");
|
|
313
|
+
expect([atomicCalls, legacyReplyCalls]).toEqual([1, 1]);
|
|
314
|
+
expect(task(taskId)).toEqual(expect.objectContaining({ status: "replied", result: "result after identity rotation" }));
|
|
315
|
+
expect(replies(taskId)).toHaveLength(1);
|
|
316
|
+
expect(db.get<{ n: number }>("SELECT COUNT(*) AS n FROM tasks WHERE parent_task_id = ?1", taskId)?.n).toBe(0);
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
test("compatibility send_reply cannot terminalize another node's task or target a third party", async () => {
|
|
320
|
+
const taskId = await dispatch(A, B, "compatibility ownership boundary");
|
|
321
|
+
|
|
322
|
+
const foreign = await call(toolsFor(A).send_reply, {
|
|
323
|
+
alias: A, text: "foreign close attempt", in_reply_to: taskId, status: "replied",
|
|
324
|
+
});
|
|
325
|
+
expect(foreign).toEqual(expect.objectContaining({ ok: false, error: "reply_task_not_owned" }));
|
|
326
|
+
expect(task(taskId)).toEqual(expect.objectContaining({ status: "delivered", result: null }));
|
|
327
|
+
expect(replies(taskId)).toHaveLength(0);
|
|
328
|
+
|
|
329
|
+
const wrongTarget = await call(toolsFor(B).send_reply, {
|
|
330
|
+
alias: B, text: "wrong target attempt", in_reply_to: taskId, status: "replied",
|
|
331
|
+
});
|
|
332
|
+
expect(wrongTarget).toEqual(expect.objectContaining({ ok: false, error: "reply_target_mismatch" }));
|
|
333
|
+
expect(task(taskId)).toEqual(expect.objectContaining({ status: "delivered", result: null }));
|
|
334
|
+
expect(replies(taskId)).toHaveLength(0);
|
|
335
|
+
|
|
336
|
+
const valid = await call(toolsFor(B).send_reply, {
|
|
337
|
+
alias: A, text: "valid compatibility close", in_reply_to: taskId, status: "replied",
|
|
338
|
+
});
|
|
339
|
+
expect(valid.ok).toBe(true);
|
|
340
|
+
expect(task(taskId)).toEqual(expect.objectContaining({ status: "replied", result: "valid compatibility close" }));
|
|
341
|
+
expect(replies(taskId)).toHaveLength(1);
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
test("owner node terminalizes exact original and emits one no-response reply without a task row", async () => {
|
|
345
|
+
const taskId = await dispatch(A, B, "do work");
|
|
346
|
+
const result = await call(toolsFor(B).send_peer_reply, {
|
|
347
|
+
alias: A,
|
|
348
|
+
text: "done exactly once",
|
|
349
|
+
in_reply_to: taskId,
|
|
350
|
+
status: "replied",
|
|
351
|
+
});
|
|
352
|
+
expect(result.ok).toBe(true);
|
|
353
|
+
expect(task(taskId)).toEqual(expect.objectContaining({ status: "replied", result: "done exactly once" }));
|
|
354
|
+
expect(task(taskId).completed_at).toBeTruthy();
|
|
355
|
+
expect(replies(taskId)).toHaveLength(1);
|
|
356
|
+
expect(replies(taskId)[0]).toEqual(expect.objectContaining({
|
|
357
|
+
session_name: A,
|
|
358
|
+
node_id: A_ID,
|
|
359
|
+
type: "reply",
|
|
360
|
+
requires_response: "none",
|
|
361
|
+
content: "done exactly once",
|
|
362
|
+
}));
|
|
363
|
+
expect(db.get<{ n: number }>("SELECT COUNT(*) AS n FROM tasks WHERE parent_task_id = ?1", taskId)?.n).toBe(0);
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// #3259 收口 —— 迟到通道只对「终态但没成功交付过回复」的任务开放;
|
|
367
|
+
// `replied` 的任务再补就是重复投递,仍然必须以 reply_task_terminal 拒绝。
|
|
368
|
+
test("terminal replay is rejected and cannot deliver twice", async () => {
|
|
369
|
+
const taskId = await dispatch(A, B, "idempotent work");
|
|
370
|
+
const handler = toolsFor(B).send_peer_reply;
|
|
371
|
+
expect((await call(handler, { alias: A, text: "first", in_reply_to: taskId, status: "replied" })).ok).toBe(true);
|
|
372
|
+
const replay = await call(handler, { alias: A, text: "second", in_reply_to: taskId, status: "replied" });
|
|
373
|
+
expect(replay).toEqual(expect.objectContaining({ ok: false, error: "reply_task_terminal", reply_queued: false }));
|
|
374
|
+
expect(task(taskId).result).toBe("first");
|
|
375
|
+
expect(replies(taskId)).toHaveLength(1);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
test("all declared peer reply outcomes become exact terminal task states", async () => {
|
|
379
|
+
for (const status of ["replied", "failed", "cancelled"] as const) {
|
|
380
|
+
const taskId = await dispatch(A, B, `terminal-${status}`);
|
|
381
|
+
const result = await call(toolsFor(B).send_peer_reply, {
|
|
382
|
+
alias: A,
|
|
383
|
+
text: `result-${status}`,
|
|
384
|
+
in_reply_to: taskId,
|
|
385
|
+
status,
|
|
386
|
+
});
|
|
387
|
+
expect(result.ok).toBe(true);
|
|
388
|
+
expect(task(taskId)).toEqual(expect.objectContaining({
|
|
389
|
+
status,
|
|
390
|
+
result: `result-${status}`,
|
|
391
|
+
}));
|
|
392
|
+
expect(task(taskId).completed_at).toBeTruthy();
|
|
393
|
+
expect(replies(taskId)).toHaveLength(1);
|
|
394
|
+
expect(replies(taskId)[0].requires_response).toBe("none");
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
|
|
398
|
+
test("foreign node and wrong origin target are rejected with zero writes", async () => {
|
|
399
|
+
const taskId = await dispatch(A, B, "owned by B");
|
|
400
|
+
const foreign = await call(toolsFor(A).send_peer_reply, { alias: A, text: "forge", in_reply_to: taskId, status: "replied" });
|
|
401
|
+
expect(foreign).toEqual(expect.objectContaining({ ok: false, error: "reply_task_not_owned" }));
|
|
402
|
+
const wrongTarget = await call(toolsFor(B).send_peer_reply, { alias: B, text: "misroute", in_reply_to: taskId, status: "replied" });
|
|
403
|
+
expect(wrongTarget).toEqual(expect.objectContaining({ ok: false, error: "reply_target_mismatch" }));
|
|
404
|
+
expect(task(taskId).status).toBe("delivered");
|
|
405
|
+
expect(replies(taskId)).toHaveLength(0);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
test("task update failure rolls back the reply inbox insert", async () => {
|
|
409
|
+
const taskId = await dispatch(A, B, "atomic failure");
|
|
410
|
+
db.exec(`CREATE TRIGGER test698_abort_terminal BEFORE UPDATE OF status ON tasks
|
|
411
|
+
WHEN OLD.task_id = '${taskId}' BEGIN SELECT RAISE(ABORT, 'test698 injected'); END`);
|
|
412
|
+
await expect(call(toolsFor(B).send_peer_reply, {
|
|
413
|
+
alias: A,
|
|
414
|
+
text: "must rollback",
|
|
415
|
+
in_reply_to: taskId,
|
|
416
|
+
status: "replied",
|
|
417
|
+
})).rejects.toThrow("test698 injected");
|
|
418
|
+
expect(task(taskId).status).toBe("delivered");
|
|
419
|
+
expect(task(taskId).result).toBeNull();
|
|
420
|
+
expect(replies(taskId)).toHaveLength(0);
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
test("node-token peer reply terminalizes the exact scheduled run in the same transaction", async () => {
|
|
424
|
+
const taskId = await dispatch(A, B, "scheduled work");
|
|
425
|
+
const { runId } = bindScheduledRun(taskId);
|
|
426
|
+
const result = await call(toolsFor(B).send_peer_reply, {
|
|
427
|
+
alias: A, text: "scheduled done", in_reply_to: taskId, status: "replied",
|
|
428
|
+
});
|
|
429
|
+
expect(result.ok).toBe(true);
|
|
430
|
+
expect(task(taskId).status).toBe("replied");
|
|
431
|
+
expect(db.get<any>("SELECT status, completed_at FROM scheduled_task_runs WHERE run_id = ?1", runId))
|
|
432
|
+
.toEqual(expect.objectContaining({ status: "replied" }));
|
|
433
|
+
});
|
|
434
|
+
|
|
435
|
+
test("scheduled-run write failure rolls back task and reply inbox together", async () => {
|
|
436
|
+
const taskId = await dispatch(A, B, "scheduled rollback");
|
|
437
|
+
const { runId } = bindScheduledRun(taskId);
|
|
438
|
+
db.exec(`CREATE TRIGGER test698_abort_run BEFORE UPDATE OF status ON scheduled_task_runs
|
|
439
|
+
WHEN OLD.run_id = '${runId}' BEGIN SELECT RAISE(ABORT, 'test698 injected run'); END`);
|
|
440
|
+
await expect(call(toolsFor(B).send_peer_reply, {
|
|
441
|
+
alias: A, text: "must all roll back", in_reply_to: taskId, status: "replied",
|
|
442
|
+
})).rejects.toThrow("test698 injected run");
|
|
443
|
+
expect(task(taskId).status).toBe("delivered");
|
|
444
|
+
expect(db.get<any>("SELECT status FROM scheduled_task_runs WHERE run_id = ?1", runId)?.status).toBe("delivered");
|
|
445
|
+
expect(replies(taskId)).toHaveLength(0);
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
test("three exchanges leave only dispatched work rows and no open tasks", async () => {
|
|
449
|
+
for (let i = 0; i < 3; i++) {
|
|
450
|
+
const taskId = await dispatch(A, B, `work-${i}`);
|
|
451
|
+
expect((await call(toolsFor(B).send_peer_reply, {
|
|
452
|
+
alias: A,
|
|
453
|
+
text: `result-${i}`,
|
|
454
|
+
in_reply_to: taskId,
|
|
455
|
+
status: "replied",
|
|
456
|
+
})).ok).toBe(true);
|
|
457
|
+
}
|
|
458
|
+
expect(db.get<{ n: number }>("SELECT COUNT(*) AS n FROM tasks WHERE network_id = ?1", NET)?.n).toBe(3);
|
|
459
|
+
expect(db.get<{ n: number }>("SELECT COUNT(*) AS n FROM tasks WHERE network_id = ?1 AND status IN ('created','delivered','acked','running')", NET)?.n).toBe(0);
|
|
460
|
+
expect(db.get<{ n: number }>("SELECT COUNT(*) AS n FROM inbox WHERE network_id = ?1 AND type = 'reply' AND requires_response = 'none'", NET)?.n).toBe(3);
|
|
461
|
+
});
|
|
462
|
+
});
|