@sleep2agi/commhub-server 0.9.0-preview.27 → 0.9.0-preview.271
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 +496 -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/node-token-usage.test.ts +90 -0
- package/src/node-token-usage.ts +164 -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 +4963 -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 +130 -0
- package/src/tools-list-json-schema.test.ts +94 -0
- package/src/tools.ts +4340 -386
- 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,350 @@
|
|
|
1
|
+
// #1353 Fix ② — /api/host-supervisors surfaces daemon's self-reported
|
|
2
|
+
// can_create_nodes + create_nodes_blocked_reason so dashboard's
|
|
3
|
+
// "选服务器" picker can filter or dim broken daemons.
|
|
4
|
+
//
|
|
5
|
+
// Fix ① (PR #1510) added the hub-side dispatch gate — daemon that
|
|
6
|
+
// reports can_create_nodes=false gets refused with the reason. But
|
|
7
|
+
// the dashboard picker still LISTS the daemon and the user finds out
|
|
8
|
+
// only after clicking. This exposes the fact one layer earlier so the
|
|
9
|
+
// picker never surfaces the daemon in the first place.
|
|
10
|
+
//
|
|
11
|
+
// 🔴 Pre-#1371 compat is the same shape as Fix ①: only include the
|
|
12
|
+
// two keys when the daemon actually reported them. Old daemons (that
|
|
13
|
+
// never report) get the same undefined-passthrough dashboard sees a
|
|
14
|
+
// row WITHOUT the keys, not a row with can_create_nodes:false, so
|
|
15
|
+
// the dashboard's own default UI doesn't silently dim every legacy
|
|
16
|
+
// daemon.
|
|
17
|
+
|
|
18
|
+
import { describe, expect, test, beforeAll, afterAll } from "bun:test";
|
|
19
|
+
import "./require-explicit-test-db.js";
|
|
20
|
+
import { register, login } from "./auth.js";
|
|
21
|
+
import { db } from "./db.js";
|
|
22
|
+
|
|
23
|
+
let BASE = "";
|
|
24
|
+
let server: any = null;
|
|
25
|
+
|
|
26
|
+
let userToken = "";
|
|
27
|
+
let userNetworkId = "";
|
|
28
|
+
let userId = "";
|
|
29
|
+
|
|
30
|
+
beforeAll(async () => {
|
|
31
|
+
process.env.HOST = "127.0.0.1";
|
|
32
|
+
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1000)}`;
|
|
33
|
+
const password = "BootstrapPw123Aa!";
|
|
34
|
+
|
|
35
|
+
// Seed admin so subsequent registrations aren't auto-admin (admin
|
|
36
|
+
// path skips resolveRestNetworkScope's default-network fallback —
|
|
37
|
+
// that would change our fixture's role/scope in ways unrelated to
|
|
38
|
+
// this fix).
|
|
39
|
+
const seed = register(`hsc_seed_${suffix}`, password, undefined, "seed");
|
|
40
|
+
if (!seed.ok) throw new Error("seed failed");
|
|
41
|
+
db.run("UPDATE users SET role = 'admin' WHERE username = ?1", [`hsc_seed_${suffix}`]);
|
|
42
|
+
|
|
43
|
+
const u = register(`hsc_u_${suffix}`, password, undefined, "seed");
|
|
44
|
+
if (!u.ok || !u.token) throw new Error("user register failed");
|
|
45
|
+
userToken = u.token;
|
|
46
|
+
userNetworkId = u.network_id ?? "";
|
|
47
|
+
userId = login(`hsc_u_${suffix}`, password).user!.user_id;
|
|
48
|
+
|
|
49
|
+
const { bootServer } = await import("./server.js");
|
|
50
|
+
server = bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
51
|
+
BASE = `http://127.0.0.1:${server.port}`;
|
|
52
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
afterAll(() => {
|
|
56
|
+
try { server?.stop?.(true); } catch {}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
function seedDaemon(alias: string, snapshotOverride: object | null): void {
|
|
60
|
+
const nodeId = `hsc_n_${alias}`;
|
|
61
|
+
const snap = snapshotOverride === null
|
|
62
|
+
? null
|
|
63
|
+
: JSON.stringify(snapshotOverride);
|
|
64
|
+
db.run(
|
|
65
|
+
`INSERT OR REPLACE INTO nodes (
|
|
66
|
+
node_id, node_name, alias, runtime, model, config_path,
|
|
67
|
+
channels, server, hostname, network_id,
|
|
68
|
+
config_revision, config_snapshot
|
|
69
|
+
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)`,
|
|
70
|
+
[nodeId, alias, alias, "claude-agent-sdk", "claude-sonnet-4-5",
|
|
71
|
+
"/tmp/cfg.json", "[]", "test-host", "test-host", userNetworkId,
|
|
72
|
+
0, snap],
|
|
73
|
+
);
|
|
74
|
+
db.run(
|
|
75
|
+
`INSERT OR REPLACE INTO api_tokens (
|
|
76
|
+
token_id, token_hash, user_id, network_id, name, scope
|
|
77
|
+
) VALUES (?1, ?2, ?3, ?4, ?5, ?6)`,
|
|
78
|
+
[`hsc_t_${alias}`, `hash_${alias}`, userId, userNetworkId, `node:${alias}`, "network"],
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function clearDaemons(): void {
|
|
83
|
+
db.run("DELETE FROM nodes WHERE network_id = ?1", [userNetworkId]);
|
|
84
|
+
db.run("DELETE FROM api_tokens WHERE network_id = ?1 AND name LIKE 'node:%'", [userNetworkId]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
async function listDaemons(): Promise<any[]> {
|
|
88
|
+
const res = await fetch(`${BASE}/api/host-supervisors`, {
|
|
89
|
+
headers: { "Authorization": `Bearer ${userToken}` },
|
|
90
|
+
});
|
|
91
|
+
const body = await res.json();
|
|
92
|
+
if (!body.ok) throw new Error("list failed: " + JSON.stringify(body));
|
|
93
|
+
return body.daemons;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function findDaemon(rows: any[], alias: string): any {
|
|
97
|
+
const d = rows.find(r => r.alias === alias);
|
|
98
|
+
if (!d) throw new Error(`daemon ${alias} not in response`);
|
|
99
|
+
return d;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
describe("#1353 Fix ② — /api/host-supervisors surfaces can_create_nodes + blocked_reason", () => {
|
|
103
|
+
test("🔴 witnessed-red: blocked daemon → response carries can_create_nodes:false + blocked_reason", async () => {
|
|
104
|
+
clearDaemons();
|
|
105
|
+
seedDaemon("blocked-a", {
|
|
106
|
+
role: "host_supervisor",
|
|
107
|
+
daemon_capabilities: {
|
|
108
|
+
runtimes_supported: ["claude-agent-sdk"],
|
|
109
|
+
can_create_nodes: false,
|
|
110
|
+
create_nodes_blocked_reason: "anet_bin_permission",
|
|
111
|
+
},
|
|
112
|
+
});
|
|
113
|
+
const d = findDaemon(await listDaemons(), "blocked-a");
|
|
114
|
+
expect(d.can_create_nodes).toBe(false);
|
|
115
|
+
expect(d.create_nodes_blocked_reason).toBe("anet_bin_permission");
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
test("healthy daemon (can_create_nodes:true) → can_create_nodes:true, NO blocked_reason", async () => {
|
|
119
|
+
clearDaemons();
|
|
120
|
+
seedDaemon("healthy-a", {
|
|
121
|
+
role: "host_supervisor",
|
|
122
|
+
daemon_capabilities: {
|
|
123
|
+
runtimes_supported: ["claude-agent-sdk"],
|
|
124
|
+
can_create_nodes: true,
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
const d = findDaemon(await listDaemons(), "healthy-a");
|
|
128
|
+
expect(d.can_create_nodes).toBe(true);
|
|
129
|
+
// 🔴 defensive: dashboard's picker likely renders blocked_reason
|
|
130
|
+
// when present regardless of can_create_nodes value. Don't
|
|
131
|
+
// confuse it by shipping a stale reason on a healthy daemon.
|
|
132
|
+
expect(d.create_nodes_blocked_reason).toBeUndefined();
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
test("healthy daemon that ALSO reports stale blocked_reason → reason NOT emitted (defensive)", async () => {
|
|
136
|
+
// Belt-and-braces: even if a future daemon shape bug leaves a
|
|
137
|
+
// stale reason string in the snapshot after recovering, the REST
|
|
138
|
+
// response should not surface it when the daemon is currently OK.
|
|
139
|
+
clearDaemons();
|
|
140
|
+
seedDaemon("healthy-b", {
|
|
141
|
+
role: "host_supervisor",
|
|
142
|
+
daemon_capabilities: {
|
|
143
|
+
runtimes_supported: ["claude-agent-sdk"],
|
|
144
|
+
can_create_nodes: true,
|
|
145
|
+
create_nodes_blocked_reason: "anet_bin_permission", // stale
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
const d = findDaemon(await listDaemons(), "healthy-b");
|
|
149
|
+
expect(d.can_create_nodes).toBe(true);
|
|
150
|
+
expect(d.create_nodes_blocked_reason).toBeUndefined();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
test("🔴 pre-#1371 compat: daemon that never reports can_create_nodes → BOTH keys absent from response", async () => {
|
|
154
|
+
// Same "known-blocked, NOT unknown-treated-as-blocked" rule as
|
|
155
|
+
// Fix ①. A pre-#1371 daemon (preview.10 through ~preview.55) never
|
|
156
|
+
// reports these fields. The response for it must not fabricate a
|
|
157
|
+
// false value — the dashboard could reasonably render an
|
|
158
|
+
// explicit `false` as "dim / hide" which would silently start
|
|
159
|
+
// hiding every daemon that hasn't upgraded.
|
|
160
|
+
clearDaemons();
|
|
161
|
+
seedDaemon("legacy-a", {
|
|
162
|
+
role: "host_supervisor",
|
|
163
|
+
daemon_capabilities: {
|
|
164
|
+
runtimes_supported: ["claude-agent-sdk"],
|
|
165
|
+
// no can_create_nodes / create_nodes_blocked_reason
|
|
166
|
+
},
|
|
167
|
+
});
|
|
168
|
+
const d = findDaemon(await listDaemons(), "legacy-a");
|
|
169
|
+
expect("can_create_nodes" in d).toBe(false);
|
|
170
|
+
expect("create_nodes_blocked_reason" in d).toBe(false);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
test("pre-#1371 compat: daemon with no daemon_capabilities at all → BOTH keys absent", async () => {
|
|
174
|
+
clearDaemons();
|
|
175
|
+
seedDaemon("legacy-b", { role: "host_supervisor" });
|
|
176
|
+
const d = findDaemon(await listDaemons(), "legacy-b");
|
|
177
|
+
expect("can_create_nodes" in d).toBe(false);
|
|
178
|
+
expect("create_nodes_blocked_reason" in d).toBe(false);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
test("pre-#1371 compat: NULL config_snapshot (very old daemon) → BOTH keys absent, daemon does NOT crash the listing", async () => {
|
|
182
|
+
// A daemon that never called report_status leaves config_snapshot NULL.
|
|
183
|
+
// /api/host-supervisors filters by role from the snapshot, so a NULL
|
|
184
|
+
// snapshot drops from the list entirely — but if it did surface (via
|
|
185
|
+
// any future path), it must not crash the reducer.
|
|
186
|
+
clearDaemons();
|
|
187
|
+
seedDaemon("legacy-c", { role: "host_supervisor" }); // seed with something to be listable
|
|
188
|
+
const rows = await listDaemons();
|
|
189
|
+
// Just prove the list doesn't throw and the daemon is present with
|
|
190
|
+
// no capability keys.
|
|
191
|
+
const d = findDaemon(rows, "legacy-c");
|
|
192
|
+
expect("can_create_nodes" in d).toBe(false);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
test("all 4 categorized reason codes round-trip through the REST response", async () => {
|
|
196
|
+
const codes = ["anet_bin_identity", "anet_bin_source", "anet_bin_shape", "anet_bin_permission"];
|
|
197
|
+
for (const code of codes) {
|
|
198
|
+
clearDaemons();
|
|
199
|
+
seedDaemon(`blocked-${code}`, {
|
|
200
|
+
role: "host_supervisor",
|
|
201
|
+
daemon_capabilities: {
|
|
202
|
+
runtimes_supported: ["claude-agent-sdk"],
|
|
203
|
+
can_create_nodes: false,
|
|
204
|
+
create_nodes_blocked_reason: code,
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
const d = findDaemon(await listDaemons(), `blocked-${code}`);
|
|
208
|
+
expect(d.can_create_nodes).toBe(false);
|
|
209
|
+
expect(d.create_nodes_blocked_reason).toBe(code);
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
test(".40-shape 'anet_bin_pin_unresolved' pre-#1377 code also passes through the REST response", async () => {
|
|
214
|
+
// The Zod enum still accepts this coarse pre-#1377 code (agent-node
|
|
215
|
+
// @2.5.0-preview.40 daemons in the wild emit it), and Fix ① surfaces
|
|
216
|
+
// it verbatim to callers; the REST surface must too, otherwise
|
|
217
|
+
// dashboard sees the daemon as "blocked with no reason".
|
|
218
|
+
clearDaemons();
|
|
219
|
+
seedDaemon("blocked-40shape", {
|
|
220
|
+
role: "host_supervisor",
|
|
221
|
+
daemon_capabilities: {
|
|
222
|
+
runtimes_supported: ["claude-agent-sdk"],
|
|
223
|
+
can_create_nodes: false,
|
|
224
|
+
create_nodes_blocked_reason: "anet_bin_pin_unresolved",
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
const d = findDaemon(await listDaemons(), "blocked-40shape");
|
|
228
|
+
expect(d.create_nodes_blocked_reason).toBe("anet_bin_pin_unresolved");
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
test("malformed config_snapshot: existing behavior (daemon drops from list due to role-filter) unchanged", async () => {
|
|
232
|
+
// The parse is wrapped in try/catch (existing behavior). A malformed
|
|
233
|
+
// snapshot means snapRole stays null → filter drops it. This just
|
|
234
|
+
// pins that our added parsing doesn't turn a malformed snapshot
|
|
235
|
+
// into a crash.
|
|
236
|
+
clearDaemons();
|
|
237
|
+
// Seed a legit daemon so the list has SOMETHING to prove no crash.
|
|
238
|
+
seedDaemon("healthy-c", {
|
|
239
|
+
role: "host_supervisor",
|
|
240
|
+
daemon_capabilities: { runtimes_supported: [] },
|
|
241
|
+
});
|
|
242
|
+
// Seed the malformed one — should be filtered out silently.
|
|
243
|
+
const nodeId = "hsc_n_malformed";
|
|
244
|
+
db.run(
|
|
245
|
+
`INSERT OR REPLACE INTO nodes (
|
|
246
|
+
node_id, node_name, alias, runtime, model, config_path,
|
|
247
|
+
channels, server, hostname, network_id,
|
|
248
|
+
config_revision, config_snapshot
|
|
249
|
+
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)`,
|
|
250
|
+
[nodeId, "malformed", "malformed", "claude-agent-sdk", "claude-sonnet-4-5",
|
|
251
|
+
"/tmp/cfg.json", "[]", "test-host", "test-host", userNetworkId,
|
|
252
|
+
0, "{not json"],
|
|
253
|
+
);
|
|
254
|
+
db.run(
|
|
255
|
+
`INSERT OR REPLACE INTO api_tokens (
|
|
256
|
+
token_id, token_hash, user_id, network_id, name, scope
|
|
257
|
+
) VALUES (?1, ?2, ?3, ?4, ?5, ?6)`,
|
|
258
|
+
["hsc_t_malformed", "hash_malformed", userId, userNetworkId, "node:malformed", "network"],
|
|
259
|
+
);
|
|
260
|
+
const rows = await listDaemons();
|
|
261
|
+
// healthy-c is present; malformed is filtered out because
|
|
262
|
+
// snapRole stayed null.
|
|
263
|
+
expect(rows.find((r: any) => r.alias === "healthy-c")).toBeDefined();
|
|
264
|
+
expect(rows.find((r: any) => r.alias === "malformed")).toBeUndefined();
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
/* #1545 —— `can_create_nodes` 说的是「能不能」,这一组说的是「**那是什么时候测的**」。
|
|
269
|
+
*
|
|
270
|
+
* 为什么非要分开:agent-node ≤ 2.5.0-preview.54 用一个进程级缓存只算一次
|
|
271
|
+
* (`cli.ts` 的 `_createCapCache`)。开机时二进制好、之后被 chmod 掉 ⇒ 它会
|
|
272
|
+
* **永远上报 ready**。hub 这边,那条记录和一个 3 秒前刚测出来的 ready
|
|
273
|
+
* 在 `last_seen_at` 上一模一样 —— 心跳是新的,那一格不是。
|
|
274
|
+
*
|
|
275
|
+
* 🔴 缺席**不得**当成 0。把「没报」渲染成「刚测的」,正好朝「没问题」方向说谎,
|
|
276
|
+
* 而这正是 #1545 里比沉默更糟的那一半。
|
|
277
|
+
*/
|
|
278
|
+
describe("#1545 /api/host-supervisors —— can_create_nodes 的年龄", () => {
|
|
279
|
+
test("daemon 报了年龄 → 原样带出", async () => {
|
|
280
|
+
clearDaemons();
|
|
281
|
+
seedDaemon("age-fresh", {
|
|
282
|
+
role: "host_supervisor",
|
|
283
|
+
daemon_capabilities: {
|
|
284
|
+
can_create_nodes: false,
|
|
285
|
+
create_nodes_blocked_reason: "anet_bin_source",
|
|
286
|
+
create_capability_observed_ms_ago: 12,
|
|
287
|
+
},
|
|
288
|
+
});
|
|
289
|
+
const d = findDaemon(await listDaemons(), "age-fresh");
|
|
290
|
+
expect(d.create_capability_observed_ms_ago).toBe(12);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
test("🔴 daemon 没报年龄 → 这一格必须**缺席**,不能是 0/null", async () => {
|
|
294
|
+
clearDaemons();
|
|
295
|
+
seedDaemon("age-absent", {
|
|
296
|
+
role: "host_supervisor",
|
|
297
|
+
daemon_capabilities: { can_create_nodes: true },
|
|
298
|
+
});
|
|
299
|
+
const d = findDaemon(await listDaemons(), "age-absent");
|
|
300
|
+
// 能力本身照常带出 —— 加年龄这一格不许把旧 daemon 的既有信息弄丢。
|
|
301
|
+
expect(d.can_create_nodes).toBe(true);
|
|
302
|
+
expect("create_capability_observed_ms_ago" in d).toBe(false);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
/* 🔴 消毒**不是 clamp**:clamp 会把一个坏值变成一个看起来正常的年龄,
|
|
306
|
+
* 而这一格存在的全部意义就是让人分辨新鲜和陈旧。坏值一律当作「没报」。 */
|
|
307
|
+
test.each([
|
|
308
|
+
["负数", -1],
|
|
309
|
+
["超过一年", 400 * 24 * 60 * 60 * 1000],
|
|
310
|
+
["null(schema 的 .catch 兜底值)", null],
|
|
311
|
+
["字符串(直接写库,绕过 schema)", "12"],
|
|
312
|
+
])("坏值当作没报,而不是 clamp 成边界:%s", async (label, value) => {
|
|
313
|
+
clearDaemons();
|
|
314
|
+
const alias = `age-bad-${String(label).slice(0, 4)}`;
|
|
315
|
+
seedDaemon(alias, {
|
|
316
|
+
role: "host_supervisor",
|
|
317
|
+
daemon_capabilities: {
|
|
318
|
+
can_create_nodes: true,
|
|
319
|
+
create_capability_observed_ms_ago: value,
|
|
320
|
+
},
|
|
321
|
+
});
|
|
322
|
+
const d = findDaemon(await listDaemons(), alias);
|
|
323
|
+
expect(d.can_create_nodes).toBe(true); // 能力仍在
|
|
324
|
+
expect("create_capability_observed_ms_ago" in d).toBe(false); // 年龄不在
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
/* 边界校准:上面用 400 天证明「太旧被丢」,这里用**刚好一年**证明门不是恒丢。
|
|
328
|
+
* 只验被丢那一侧的话,一个恒丢的实现能全绿通过。 */
|
|
329
|
+
test("边界:恰好一年被接受 ⇒ 上面那条不是因为恒丢才绿", async () => {
|
|
330
|
+
clearDaemons();
|
|
331
|
+
const oneYear = 365 * 24 * 60 * 60 * 1000;
|
|
332
|
+
seedDaemon("age-boundary", {
|
|
333
|
+
role: "host_supervisor",
|
|
334
|
+
daemon_capabilities: { can_create_nodes: true, create_capability_observed_ms_ago: oneYear },
|
|
335
|
+
});
|
|
336
|
+
const d = findDaemon(await listDaemons(), "age-boundary");
|
|
337
|
+
expect(d.create_capability_observed_ms_ago).toBe(oneYear);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
test("年龄只在 can_create_nodes 存在时出现(旧 daemon 两格都没有)", async () => {
|
|
341
|
+
clearDaemons();
|
|
342
|
+
seedDaemon("age-legacy", {
|
|
343
|
+
role: "host_supervisor",
|
|
344
|
+
daemon_capabilities: { runtimes_supported: ["claude-agent-sdk"] },
|
|
345
|
+
});
|
|
346
|
+
const d = findDaemon(await listDaemons(), "age-legacy");
|
|
347
|
+
expect("can_create_nodes" in d).toBe(false);
|
|
348
|
+
expect("create_capability_observed_ms_ago" in d).toBe(false);
|
|
349
|
+
});
|
|
350
|
+
});
|
|
@@ -20,13 +20,10 @@
|
|
|
20
20
|
// server on an ephemeral port with a temp DB, hit it with fetch().
|
|
21
21
|
|
|
22
22
|
import { describe, expect, test, beforeAll, afterAll } from "bun:test";
|
|
23
|
-
import
|
|
24
|
-
import { join } from "path";
|
|
25
|
-
import { tmpdir } from "os";
|
|
23
|
+
import "./require-explicit-test-db.js";
|
|
26
24
|
import { register, login, createNetwork } from "./auth.js";
|
|
27
25
|
import { db } from "./db.js";
|
|
28
26
|
|
|
29
|
-
const SERVER_DB = mkdtempSync(join(tmpdir(), "anet-hs-fallback-db-")) + "/commhub.db";
|
|
30
27
|
// #438 corrective: private bootServer({ port: 0 }) instance (see
|
|
31
28
|
// uploads-http.test.ts for rationale).
|
|
32
29
|
let BASE = "";
|
|
@@ -41,8 +38,11 @@ let soloNetworkId = "";
|
|
|
41
38
|
let multiNetworkA = "", multiNetworkB = "";
|
|
42
39
|
let soloDaemonAlias = "";
|
|
43
40
|
|
|
41
|
+
// 30s 而不是 bun 默认的 5s:这个 hook 跑 register()(KDF)+bootServer(),
|
|
42
|
+
// 本机空载基线 ~620ms,而 2026-08-17 与 2026-08-31 两次 CI 上它被 5s 上限打死
|
|
43
|
+
// (0 pass / 1 fail / Ran 1 test —— 见 #928、#1627)。5247ms 是**被截断的下界**,
|
|
44
|
+
// 不是测量值,所以余量按基线的 ~48x 取,而不是按那个数取。
|
|
44
45
|
beforeAll(async () => {
|
|
45
|
-
process.env.COMMHUB_DB = SERVER_DB;
|
|
46
46
|
process.env.HOST = "127.0.0.1";
|
|
47
47
|
|
|
48
48
|
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1000)}`;
|
|
@@ -120,7 +120,7 @@ beforeAll(async () => {
|
|
|
120
120
|
server = bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
121
121
|
BASE = `http://127.0.0.1:${server.port}`;
|
|
122
122
|
await new Promise((r) => setTimeout(r, 100));
|
|
123
|
-
});
|
|
123
|
+
}, 30_000);
|
|
124
124
|
|
|
125
125
|
// Insert a minimal `nodes` row + `api_tokens` row so the daemon shows up
|
|
126
126
|
// in /api/host-supervisors' JOIN-then-role-filter query (index.ts
|
|
@@ -155,7 +155,6 @@ function seedHostSupervisorDaemon(opts: {
|
|
|
155
155
|
|
|
156
156
|
afterAll(() => {
|
|
157
157
|
try { server?.stop?.(true); } catch {}
|
|
158
|
-
try { rmSync(SERVER_DB, { recursive: true, force: true }); } catch {}
|
|
159
158
|
});
|
|
160
159
|
|
|
161
160
|
async function get(path: string, token: string): Promise<{ status: number; body: any }> {
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
// #622 —— daemon 逐 runtime 自检(runtime_readiness)从 report_status 一路走到
|
|
2
|
+
// /api/host-supervisors。三件事:
|
|
3
|
+
// 1. report_status 的 zod 形状收得宽:坏的 runtime_readiness 只丢它自己,
|
|
4
|
+
// 绝不拒掉整份 report(否则一台 daemon 发了个奇怪的诊断字段就在 hub 上失联);
|
|
5
|
+
// 2. 新字段会被**保留**(daemon_capabilities 不是 strict,schema 里没声明的键会被
|
|
6
|
+
// 静默剥掉 —— 不加 schema 就永远到不了 REST);
|
|
7
|
+
// 3. REST 只在 daemon 报了时输出,旧 daemon 的行里**没有**这个键;
|
|
8
|
+
// can_create_nodes 语义不变。
|
|
9
|
+
|
|
10
|
+
import { describe, expect, test, beforeAll, afterAll } from "bun:test";
|
|
11
|
+
import "./require-explicit-test-db.js";
|
|
12
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
13
|
+
import { register, login } from "./auth.js";
|
|
14
|
+
import { db } from "./db.js";
|
|
15
|
+
import { registerTools } from "./tools.js";
|
|
16
|
+
import { sanitizeRuntimeReadiness } from "./runtime-readiness.js";
|
|
17
|
+
|
|
18
|
+
function captureToolSchemas(): Record<string, any> {
|
|
19
|
+
const mcp = new McpServer({ name: "schema-probe", version: "0" }) as any;
|
|
20
|
+
const schemas: Record<string, any> = {};
|
|
21
|
+
const origTool = mcp.tool.bind(mcp);
|
|
22
|
+
mcp.tool = (name: string, desc: string, schema: any, handler: any) => {
|
|
23
|
+
schemas[name] = schema;
|
|
24
|
+
return origTool(name, desc, schema, handler);
|
|
25
|
+
};
|
|
26
|
+
registerTools(mcp, undefined, null, null, null, false, "tok_schema_probe");
|
|
27
|
+
return schemas;
|
|
28
|
+
}
|
|
29
|
+
const schemas = captureToolSchemas();
|
|
30
|
+
const snapSchema = () => schemas.report_status.config_snapshot;
|
|
31
|
+
const base = { flags: {}, config_update_capable: false, peer_reply_inbox_capable: true };
|
|
32
|
+
|
|
33
|
+
const READY = {
|
|
34
|
+
ok: true, state: "ready", reason: "可以创建", version: "2.1.290",
|
|
35
|
+
checked_at: "2026-10-06T03:00:00.000Z", cli: "found", auth: "present", network: "reachable",
|
|
36
|
+
};
|
|
37
|
+
const MISSING = {
|
|
38
|
+
ok: false, state: "missing_cli", reason: "新节点的 PATH 上找不到可用的 grok 命令", checked_at: "2026-10-06T03:00:00.000Z",
|
|
39
|
+
cli: "missing", auth: "present", network: "skipped",
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
describe("#622 report_status schema —— runtime_readiness", () => {
|
|
43
|
+
test("合法值透传(没被 daemon_capabilities 的非 strict 剥掉)", () => {
|
|
44
|
+
const parsed = snapSchema().parse({ ...base, daemon_capabilities: {
|
|
45
|
+
can_create_nodes: true,
|
|
46
|
+
runtime_readiness: { "claude-code-cli": READY, "grok-build-acp": MISSING, "codex-sdk": { ...READY, shared_login_count: 27 } },
|
|
47
|
+
} });
|
|
48
|
+
expect(parsed.daemon_capabilities.runtime_readiness["claude-code-cli"].state).toBe("ready");
|
|
49
|
+
expect(parsed.daemon_capabilities.runtime_readiness["grok-build-acp"].state).toBe("missing_cli");
|
|
50
|
+
expect(parsed.daemon_capabilities.runtime_readiness["codex-sdk"].shared_login_count).toBe(27);
|
|
51
|
+
expect(parsed.daemon_capabilities.can_create_nodes).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
test("🔴 坏形状绝不拒整份 report —— 只丢这一格", () => {
|
|
55
|
+
for (const bad of [
|
|
56
|
+
"string", 42, null, [], { x: "notobj" },
|
|
57
|
+
Object.fromEntries(Array.from({ length: 40 }, (_, i) => [`rt${i}`, READY])),
|
|
58
|
+
]) {
|
|
59
|
+
const parsed = snapSchema().parse({ ...base, daemon_capabilities: { can_create_nodes: true, runtime_readiness: bad } });
|
|
60
|
+
expect(parsed.daemon_capabilities.can_create_nodes).toBe(true);
|
|
61
|
+
expect(parsed.daemon_capabilities.runtime_readiness).toBeUndefined();
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("单个字段坏:schema 不拒整份;读取侧消毒把它兜成 unknown", () => {
|
|
66
|
+
const parsed = snapSchema().parse({ ...base, daemon_capabilities: {
|
|
67
|
+
can_create_nodes: true,
|
|
68
|
+
runtime_readiness: { a: { ok: "yes", state: 7, reason: "x".repeat(5000), shared_login_count: -3 } },
|
|
69
|
+
} });
|
|
70
|
+
expect(parsed.daemon_capabilities.can_create_nodes).toBe(true);
|
|
71
|
+
const a = sanitizeRuntimeReadiness(parsed.daemon_capabilities.runtime_readiness)!.a;
|
|
72
|
+
expect(a.ok).toBe(false);
|
|
73
|
+
expect(a.state).toBe("unknown");
|
|
74
|
+
expect(a.reason.length).toBe(600);
|
|
75
|
+
expect(a.shared_login_count).toBeUndefined();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
test("总字节超 16 KB:整格丢掉(异常 daemon 不能往库里塞大对象)", () => {
|
|
79
|
+
const big = { a: { ...READY, reason: "x".repeat(20_000) } };
|
|
80
|
+
const parsed = snapSchema().parse({ ...base, daemon_capabilities: { can_create_nodes: true, runtime_readiness: big } });
|
|
81
|
+
expect(parsed.daemon_capabilities.runtime_readiness).toBeUndefined();
|
|
82
|
+
expect(parsed.daemon_capabilities.can_create_nodes).toBe(true);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("#622 sanitizeRuntimeReadiness(读取侧)", () => {
|
|
87
|
+
test("不认识的 state → unknown;ok 只有 ready 时才可能为真", () => {
|
|
88
|
+
const s = sanitizeRuntimeReadiness({
|
|
89
|
+
a: { ok: true, state: "something_new", reason: "r" },
|
|
90
|
+
b: { ok: true, state: "no_network", reason: "r" },
|
|
91
|
+
})!;
|
|
92
|
+
expect(s.a.state).toBe("unknown");
|
|
93
|
+
expect(s.a.ok).toBe(false);
|
|
94
|
+
expect(s.b.ok).toBe(false);
|
|
95
|
+
});
|
|
96
|
+
test("没报 / 空 → undefined(调用方据此不输出键)", () => {
|
|
97
|
+
expect(sanitizeRuntimeReadiness(undefined)).toBeUndefined();
|
|
98
|
+
expect(sanitizeRuntimeReadiness({})).toBeUndefined();
|
|
99
|
+
expect(sanitizeRuntimeReadiness([])).toBeUndefined();
|
|
100
|
+
});
|
|
101
|
+
test("未知枚举值的 cli/auth/network 被丢掉", () => {
|
|
102
|
+
const s = sanitizeRuntimeReadiness({ a: { ...READY, cli: "/home/x/bin/claude", network: "maybe" } })!;
|
|
103
|
+
expect(s.a.cli).toBeUndefined();
|
|
104
|
+
expect(s.a.network).toBeUndefined();
|
|
105
|
+
expect(s.a.auth).toBe("present");
|
|
106
|
+
});
|
|
107
|
+
test("generation and accepted stay only on opencode-cli", () => {
|
|
108
|
+
const s = sanitizeRuntimeReadiness({
|
|
109
|
+
"opencode-cli": { ...READY, state: "unknown", ok: false, generation: "v2", accepted: false },
|
|
110
|
+
"claude-code-cli": { ...READY, generation: "v2", accepted: true },
|
|
111
|
+
})!;
|
|
112
|
+
expect(s["opencode-cli"].generation).toBe("v2");
|
|
113
|
+
expect(s["opencode-cli"].accepted).toBe(false);
|
|
114
|
+
expect(s["claude-code-cli"].generation).toBeUndefined();
|
|
115
|
+
expect(s["claude-code-cli"].accepted).toBeUndefined();
|
|
116
|
+
const lone = sanitizeRuntimeReadiness({ "opencode-cli": { ...READY, accepted: true, generation: "nope" } })!;
|
|
117
|
+
expect(lone["opencode-cli"].generation).toBeUndefined();
|
|
118
|
+
expect(lone["opencode-cli"].accepted).toBeUndefined();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
let BASE = "";
|
|
123
|
+
let server: any = null;
|
|
124
|
+
let userToken = "";
|
|
125
|
+
let userNetworkId = "";
|
|
126
|
+
let userId = "";
|
|
127
|
+
|
|
128
|
+
beforeAll(async () => {
|
|
129
|
+
process.env.HOST = "127.0.0.1";
|
|
130
|
+
const suffix = `${Date.now()}_${Math.floor(Math.random() * 1000)}`;
|
|
131
|
+
const password = "BootstrapPw123Aa!";
|
|
132
|
+
const seed = register(`rr_seed_${suffix}`, password, undefined, "seed");
|
|
133
|
+
if (!seed.ok) throw new Error("seed failed");
|
|
134
|
+
db.run("UPDATE users SET role = 'admin' WHERE username = ?1", [`rr_seed_${suffix}`]);
|
|
135
|
+
const u = register(`rr_u_${suffix}`, password, undefined, "seed");
|
|
136
|
+
if (!u.ok || !u.token) throw new Error("user register failed");
|
|
137
|
+
userToken = u.token;
|
|
138
|
+
userNetworkId = u.network_id ?? "";
|
|
139
|
+
userId = login(`rr_u_${suffix}`, password).user!.user_id;
|
|
140
|
+
const { bootServer } = await import("./server.js");
|
|
141
|
+
server = bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
142
|
+
BASE = `http://127.0.0.1:${server.port}`;
|
|
143
|
+
await new Promise((r) => setTimeout(r, 100));
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
afterAll(() => {
|
|
147
|
+
try { server?.stop?.(true); } catch {}
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
function seedDaemon(alias: string, snapshot: object): void {
|
|
151
|
+
db.run(
|
|
152
|
+
`INSERT OR REPLACE INTO nodes (
|
|
153
|
+
node_id, node_name, alias, runtime, model, config_path,
|
|
154
|
+
channels, server, hostname, network_id, config_revision, config_snapshot
|
|
155
|
+
) VALUES (?1, ?2, ?3, ?4, ?5, ?6, ?7, ?8, ?9, ?10, ?11, ?12)`,
|
|
156
|
+
[`rr_n_${alias}`, alias, alias, "claude-agent-sdk", null, "/tmp/cfg.json", "[]", "test-host", "test-host",
|
|
157
|
+
userNetworkId, 0, JSON.stringify(snapshot)],
|
|
158
|
+
);
|
|
159
|
+
db.run(
|
|
160
|
+
`INSERT OR REPLACE INTO api_tokens (token_id, token_hash, user_id, network_id, name, scope)
|
|
161
|
+
VALUES (?1, ?2, ?3, ?4, ?5, ?6)`,
|
|
162
|
+
[`rr_t_${alias}`, `hash_rr_${alias}`, userId, userNetworkId, `node:${alias}`, "network"],
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
async function listDaemons(): Promise<any[]> {
|
|
167
|
+
const res = await fetch(`${BASE}/api/host-supervisors`, { headers: { Authorization: `Bearer ${userToken}` } });
|
|
168
|
+
const body = await res.json();
|
|
169
|
+
if (!body.ok) throw new Error("list failed: " + JSON.stringify(body));
|
|
170
|
+
return body.daemons;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
describe("#622 /api/host-supervisors 输出 runtime_readiness", () => {
|
|
174
|
+
test("新 daemon:逐 runtime 透传;can_create_nodes 不受影响", async () => {
|
|
175
|
+
db.run("DELETE FROM nodes WHERE network_id = ?1", [userNetworkId]);
|
|
176
|
+
seedDaemon("rr-new", { role: "host_supervisor", daemon_capabilities: {
|
|
177
|
+
runtimes_supported: ["claude-code-cli", "grok-build-acp"],
|
|
178
|
+
can_create_nodes: true,
|
|
179
|
+
runtime_readiness: { "claude-code-cli": READY, "grok-build-acp": MISSING },
|
|
180
|
+
} });
|
|
181
|
+
const d = (await listDaemons()).find((x) => x.alias === "rr-new");
|
|
182
|
+
expect(d.can_create_nodes).toBe(true);
|
|
183
|
+
expect(d.runtime_readiness["claude-code-cli"]).toEqual(READY);
|
|
184
|
+
expect(d.runtime_readiness["grok-build-acp"].state).toBe("missing_cli");
|
|
185
|
+
expect(d.runtime_readiness["grok-build-acp"].ok).toBe(false);
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
test("🔴 旧 daemon(不报):响应里没有这个键 —— 不是 {}、不是 null", async () => {
|
|
189
|
+
db.run("DELETE FROM nodes WHERE network_id = ?1", [userNetworkId]);
|
|
190
|
+
seedDaemon("rr-old", { role: "host_supervisor", daemon_capabilities: { runtimes_supported: ["claude-agent-sdk"], can_create_nodes: true } });
|
|
191
|
+
const d = (await listDaemons()).find((x) => x.alias === "rr-old");
|
|
192
|
+
expect(d.can_create_nodes).toBe(true);
|
|
193
|
+
expect("runtime_readiness" in d).toBe(false);
|
|
194
|
+
});
|
|
195
|
+
});
|