@sleep2agi/commhub-server 0.9.0-preview.26 → 0.9.0-preview.261
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 +228 -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 +487 -0
- package/src/agent-acl-groups-http.test.ts +247 -0
- package/src/agent-acl-http.test.ts +680 -0
- package/src/agent-acl-slice3-http.test.ts +885 -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-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 +609 -56
- 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 +1269 -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 +178 -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-redaction.test.ts +1576 -7
- 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 +641 -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 +56 -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/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-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-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.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 +728 -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-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 +158 -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/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 +141 -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 +4846 -325
- 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 +402 -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 +4229 -397
- 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 +348 -0
- package/src/user-inbox-by-agent-http.test.ts +165 -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,177 @@
|
|
|
1
|
+
// #2840 —— 节点「假活」告警:连续确定性失败 → 一条人类可见的通知。
|
|
2
|
+
//
|
|
3
|
+
// 现场(2026-10-28 只读统计):TMA客户端鲸 因为缺 `DEEPSEEK_KEY`,在 **9 天里失败 1433 次**,
|
|
4
|
+
// 期间没有任何告警。节点在线、进程在、版本正常、`get_session_status` 返回 idle,
|
|
5
|
+
// 失败只写在任务回执的 result 文本里 —— 巡检若只看状态就会判「没回复 = 没在做」。
|
|
6
|
+
//
|
|
7
|
+
// 设计约束(用近 7 天生产数据回放校准过,见 #2840):
|
|
8
|
+
// · **只对确定性错误告警**:缺环境变量 / 二进制缺失 / 登录失效 —— 这类不会自愈,必须人处理。
|
|
9
|
+
// 把 `timeout` 也算进去会让 7 天出现 35 条告警(其中 29 条是 timeout),等于制造新噪音源。
|
|
10
|
+
// · 阈值 5 次连续(同节点 + 同类别)。校准结果:只算确定性错误时 7 天 6 条(0.9/天),
|
|
11
|
+
// 而 TMA客户端鲸 那 1433 次会被压缩成 5 条 —— 压缩比 287:1。
|
|
12
|
+
// · 同一次故障只告一次:按 (节点, 类别, 首现时刻) 去重;彻底恢复(出现一条成功)后才重新武装。
|
|
13
|
+
// · 走已有 user_inbox 通道(与 schedule_stuck 同一套),不新造通知面。
|
|
14
|
+
import { db } from "./db.js";
|
|
15
|
+
import { sendAgentNotice } from "./agent-notice.js";
|
|
16
|
+
|
|
17
|
+
export const NODE_FAILURE_ALERT_KIND = "node_failure_alert";
|
|
18
|
+
/** 连续多少次确定性失败才告警。 */
|
|
19
|
+
export const ALERT_STREAK_THRESHOLD = 5;
|
|
20
|
+
/** 只看这么久以内的任务(更早的失败已经不可操作)。 */
|
|
21
|
+
export const SCAN_WINDOW_HOURS = 24;
|
|
22
|
+
|
|
23
|
+
type Category = "missing_env" | "binary_missing" | "login_required" | "quota_exhausted";
|
|
24
|
+
|
|
25
|
+
const PATTERNS: Array<{ category: Category; re: RegExp; label: string; hint: string }> = [
|
|
26
|
+
{ category: "missing_env", re: /Missing environment variable/i, label: "缺环境变量",
|
|
27
|
+
hint: "在节点所在机器补上该变量后重启节点(anet node start <alias>)" },
|
|
28
|
+
{ category: "binary_missing", re: /ENOENT|No such file or directory/i, label: "二进制/文件缺失",
|
|
29
|
+
hint: "检查该节点的运行时是否安装完整,必要时重装后重启节点" },
|
|
30
|
+
// #2964 —— 真实的登录失效文案长这样(agent-node/src/runtime/codex-health.ts 生成):
|
|
31
|
+
// "model login expired: this node's CODEX_HOME (/…/codex-home) needs a fresh login — log in again there: …"
|
|
32
|
+
// 原来的 /login required|Unauthorized|\b401\b/ **匹配不到这一句**:它写的是
|
|
33
|
+
// "needs a fresh login",不是 "login required"。实测 2026-10-29 一个凭据过期的节点
|
|
34
|
+
// 启动后每轮都以这句话失败,而 #2840 的告警一条都不会发 —— 分类器看不见它。
|
|
35
|
+
// 补两种状态词(expired / revoked)与那句固定结尾,仍然只认登录态,不扩大到泛化的 auth 字样。
|
|
36
|
+
{ category: "login_required", re: /login required|Unauthorized|\b401\b|model login (?:expired|revoked)|needs a fresh login/i, label: "凭据/登录失效",
|
|
37
|
+
hint: "重新登录该节点(anet node codex login-status 可先自检)" },
|
|
38
|
+
// #2891 —— 额度耗尽:与前三类同性质(不会自愈、必须人处理),但**必须与「限流」分开**。
|
|
39
|
+
//
|
|
40
|
+
// 校准(2026-10-28,近 7 天 2825 条失败):
|
|
41
|
+
// provider.quota / usage limit has been reached → 507 条(占全部失败 18%)
|
|
42
|
+
// 限流类文案(rate limit / 429 / too many requests) → 2 条
|
|
43
|
+
// ⇒ 宽泛匹配「额度|limit|quota」会到 513,多出来的 6 条是**任务正文在讨论额度**(假阳性),
|
|
44
|
+
// 所以这里只认 provider.quota / usage limit has been reached 这两句原文。
|
|
45
|
+
//
|
|
46
|
+
// 为什么不能把限流并进来:限流会自愈(等几秒重试即可),额度不会。
|
|
47
|
+
// 混成一类会让告警失去「必须人处理」这个唯一有用的性质。
|
|
48
|
+
{ category: "quota_exhausted", re: /provider\.quota:\s|usage limit has been reached/i, label: "模型额度耗尽",
|
|
49
|
+
hint: "该节点的上游额度已用完:换 key / 充值 / 换 provider 后重启节点;限流(rate limit)不属此类,会自愈" },
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
/** #2964 后半 —— 节点完全不接活时的告警类别(与「连续失败」区分开)。 */
|
|
53
|
+
export const MODEL_AUTH_BLOCKED_CATEGORY = "login_expired";
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* #2964 后半 —— 扫「在线但干不了活」的节点。
|
|
57
|
+
*
|
|
58
|
+
* 前一半(分类器认得出登录文案)只覆盖「节点产生了失败」的情况。
|
|
59
|
+
* 还有一种更安静的状态:节点启动后登录已失效,**一条任务都不接**,
|
|
60
|
+
* 于是 `#2840` 的「连续失败」永远不会触发 —— 但它同样干不了活。
|
|
61
|
+
*
|
|
62
|
+
* hub 侧的事实来源:agent-node 的 `gateStatusOnModelAuth` 会把这种节点的状态报成
|
|
63
|
+
* `error`,并把原因写进 `sessions.task`。这里直接读它,不做任何推断。
|
|
64
|
+
*
|
|
65
|
+
* 去重粒度:每节点每天最多一条(`first_seen` 用日期),因为这不是「某一次失败」,
|
|
66
|
+
* 而是一个需要人处理的状态;每隔 5 分钟提醒一次只会变成噪音。
|
|
67
|
+
*/
|
|
68
|
+
export function scanModelAuthBlockedNodes(now = new Date()): AlertScanResult {
|
|
69
|
+
const day = now.toISOString().slice(0, 10);
|
|
70
|
+
const rows = db.all<{ alias: string | null; network_id: string | null; task: string | null }>(
|
|
71
|
+
`SELECT alias, network_id, task FROM sessions WHERE status = 'error' AND task IS NOT NULL`,
|
|
72
|
+
);
|
|
73
|
+
const out: string[] = [];
|
|
74
|
+
for (const r of rows) {
|
|
75
|
+
const node = r.alias;
|
|
76
|
+
if (!node || !r.network_id) continue;
|
|
77
|
+
if (classifyDeterministicFailure(r.task) !== "login_required") continue;
|
|
78
|
+
const dup = db.get<{ n: number }>(
|
|
79
|
+
`SELECT COUNT(*) AS n FROM user_inbox WHERE kind = ?1 AND from_session = ?2
|
|
80
|
+
AND json_extract(meta_json, '$.node_failure_alert.category') = ?3
|
|
81
|
+
AND json_extract(meta_json, '$.node_failure_alert.first_seen') = ?4`,
|
|
82
|
+
NODE_FAILURE_ALERT_KIND, node, MODEL_AUTH_BLOCKED_CATEGORY, day,
|
|
83
|
+
)?.n ?? 0;
|
|
84
|
+
if (dup > 0) continue;
|
|
85
|
+
const owner = db.get<{ owner_user_id: string | null }>(
|
|
86
|
+
"SELECT owner_user_id FROM nodes WHERE alias = ?1 AND network_id = ?2", node, r.network_id,
|
|
87
|
+
)?.owner_user_id;
|
|
88
|
+
if (!owner) continue;
|
|
89
|
+
const sent = sendAgentNotice({
|
|
90
|
+
networkId: r.network_id,
|
|
91
|
+
userId: owner,
|
|
92
|
+
fromAlias: node,
|
|
93
|
+
kind: NODE_FAILURE_ALERT_KIND,
|
|
94
|
+
title: "节点在线但不会接活:登录失效",
|
|
95
|
+
text: `${node} 当前状态是 error,原因是登录失效。它不会接任何任务(不是慢,是干不了)。\n\n`
|
|
96
|
+
+ `节点自述:\n${String(r.task).slice(0, 300)}\n\n`
|
|
97
|
+
+ `处理建议:在该节点自己的 CODEX_HOME 里重新登录(不要拷贝别的节点的 auth.json),然后重启节点。`,
|
|
98
|
+
severity: "error",
|
|
99
|
+
meta: { node_failure_alert: { node, category: MODEL_AUTH_BLOCKED_CATEGORY, first_seen: day } },
|
|
100
|
+
idPrefix: "dm_nfa_",
|
|
101
|
+
});
|
|
102
|
+
if (sent) out.push(node);
|
|
103
|
+
}
|
|
104
|
+
return { alerts: out.length, nodes: out };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** 只认确定性错误;timeout / 任务内容错误一律返回 null(那类会自愈或与节点无关)。 */
|
|
108
|
+
export function classifyDeterministicFailure(result: string | null | undefined): Category | null {
|
|
109
|
+
if (!result) return null;
|
|
110
|
+
for (const p of PATTERNS) if (p.re.test(result)) return p.category;
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type AlertScanResult = { alerts: number; nodes: string[] };
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 扫一遍最近的失败,给「连续确定性失败」的节点发一次性告警。
|
|
118
|
+
* 纯读 + 发通知;不改任何任务/排程状态。
|
|
119
|
+
*/
|
|
120
|
+
export function scanNodeFailureAlerts(now = new Date()): AlertScanResult {
|
|
121
|
+
const since = new Date(now.getTime() - SCAN_WINDOW_HOURS * 3_600_000).toISOString().slice(0, 19).replace("T", " ");
|
|
122
|
+
const rows = db.all<{ to_name: string; network_id: string | null; created_at: string; status: string; result: string | null }>(
|
|
123
|
+
`SELECT to_name, network_id, created_at, status, result FROM tasks
|
|
124
|
+
WHERE created_at >= ?1 AND to_name IS NOT NULL
|
|
125
|
+
ORDER BY to_name, created_at`,
|
|
126
|
+
since,
|
|
127
|
+
);
|
|
128
|
+
// 按节点切段:streak 只数「连续」——中间出现任何非该类失败的成功/失败都要断开。
|
|
129
|
+
const streaks = new Map<string, { category: Category; count: number; firstAt: string; networkId: string | null; sample: string }>();
|
|
130
|
+
const cur = new Map<string, { category: Category; count: number; firstAt: string }>();
|
|
131
|
+
for (const r of rows) {
|
|
132
|
+
const cat = r.status === "failed" ? classifyDeterministicFailure(r.result) : null;
|
|
133
|
+
const node = r.to_name;
|
|
134
|
+
const prev = cur.get(node);
|
|
135
|
+
if (!cat) {
|
|
136
|
+
// 序列断了:连续计数和「已完成段落」都要清,否则一条成功之后旧段落仍会被告警。
|
|
137
|
+
cur.delete(node);
|
|
138
|
+
streaks.delete(node);
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (prev && prev.category === cat) {
|
|
142
|
+
prev.count += 1;
|
|
143
|
+
streaks.set(node, { category: cat, count: prev.count, firstAt: prev.firstAt, networkId: r.network_id, sample: String(r.result ?? "").slice(0, 200) });
|
|
144
|
+
} else {
|
|
145
|
+
cur.set(node, { category: cat, count: 1, firstAt: r.created_at });
|
|
146
|
+
streaks.delete(node);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
const out: string[] = [];
|
|
150
|
+
for (const [node, s] of streaks) {
|
|
151
|
+
if (s.count < ALERT_STREAK_THRESHOLD) continue;
|
|
152
|
+
const meta = { node, category: s.category, first_seen: s.firstAt };
|
|
153
|
+
const dup = db.get<{ n: number }>(
|
|
154
|
+
`SELECT COUNT(*) AS n FROM user_inbox WHERE kind = ?1 AND from_session = ?2
|
|
155
|
+
AND json_extract(meta_json, '$.node_failure_alert.category') = ?3
|
|
156
|
+
AND json_extract(meta_json, '$.node_failure_alert.first_seen') = ?4`,
|
|
157
|
+
NODE_FAILURE_ALERT_KIND, node, s.category, s.firstAt,
|
|
158
|
+
)?.n ?? 0;
|
|
159
|
+
if (dup > 0) continue;
|
|
160
|
+
const owner = db.get<{ owner_user_id: string | null }>("SELECT owner_user_id FROM nodes WHERE alias = ?1 AND network_id = ?2", node, s.networkId)?.owner_user_id;
|
|
161
|
+
if (!owner || !s.networkId) continue;
|
|
162
|
+
const label = PATTERNS.find((p) => p.category === s.category)!;
|
|
163
|
+
const sent = sendAgentNotice({
|
|
164
|
+
networkId: s.networkId,
|
|
165
|
+
userId: owner,
|
|
166
|
+
fromAlias: node,
|
|
167
|
+
kind: NODE_FAILURE_ALERT_KIND,
|
|
168
|
+
title: `节点连续失败:${label.label}`,
|
|
169
|
+
text: `${node} 连续 ${s.count} 次以「${label.label}」失败(自 ${s.firstAt} 起)。\n\n最近一次回执节选:\n${s.sample}\n\n处理建议:${label.hint}`,
|
|
170
|
+
severity: "error",
|
|
171
|
+
meta: { node_failure_alert: meta },
|
|
172
|
+
idPrefix: "dm_nfa_",
|
|
173
|
+
});
|
|
174
|
+
if (sent) out.push(node);
|
|
175
|
+
}
|
|
176
|
+
return { alerts: out.length, nodes: out };
|
|
177
|
+
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
// Project folder view — list_node_files / read_node_file ride the rules-file
|
|
2
|
+
// queue + doorbell (ops files_list / file_read).
|
|
3
|
+
//
|
|
4
|
+
// Hub-side contract verified here:
|
|
5
|
+
// 1. report_status { files_capable: true } is sticky and set only by the
|
|
6
|
+
// session's own node token (bound or legacy-unbound, same rule as skills).
|
|
7
|
+
// 2. Both tools reach a session with no nodes row by alias; the pulled
|
|
8
|
+
// request carries the normalized RELATIVE path; results come back through
|
|
9
|
+
// get_rules_file_result.
|
|
10
|
+
// 3. Absolute paths, `..`, `~`, drive letters, backslashes and NUL are refused
|
|
11
|
+
// before any request row exists (the node re-checks; this is the first wall).
|
|
12
|
+
// 4. A node token may not enqueue a files op (it would read another node's
|
|
13
|
+
// disk), and only the token that asked may read a files result.
|
|
14
|
+
// 5. A token bound to node A never pulls or acks node B's files request; an
|
|
15
|
+
// unbound legacy token falls back to its alias exactly as it does for skills.
|
|
16
|
+
// 6. Its own single-flight lane; rules-capable-only sessions are refused.
|
|
17
|
+
// 7. Files acks may carry up to 1 MiB (escaped JSON of a 256 KiB file); rules
|
|
18
|
+
// acks keep their 256 KiB cap.
|
|
19
|
+
//
|
|
20
|
+
// 跑法:cd server && COMMHUB_DB=/tmp/files-transport.db bun test src/node-files-transport.test.ts
|
|
21
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
22
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
23
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
24
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
25
|
+
import { db } from "./db.js";
|
|
26
|
+
import { registerTools } from "./tools.js";
|
|
27
|
+
|
|
28
|
+
const NET = "net_files_session";
|
|
29
|
+
const OTHER_NET = "net_files_session_other";
|
|
30
|
+
const USER = "u_files_session_owner";
|
|
31
|
+
const SESSION_ALIAS = "files-session-cc";
|
|
32
|
+
const SESSION_RESUME = "cc-files-session-1";
|
|
33
|
+
const PEER_ALIAS = "files-session-peer";
|
|
34
|
+
const NODE_A = "files-node-a";
|
|
35
|
+
const NODE_B = "files-node-b";
|
|
36
|
+
const NODE_A_ID = "node_files_a";
|
|
37
|
+
const NODE_B_ID = "node_files_b";
|
|
38
|
+
const LEGACY_ALIAS = "files-node-legacy";
|
|
39
|
+
const LEGACY_ID = "node_files_legacy";
|
|
40
|
+
const T_SESSION = "tok_files_session_cc";
|
|
41
|
+
const T_PEER = "tok_files_session_peer";
|
|
42
|
+
const T_OTHER_NET_SAME_ALIAS = "tok_files_session_other_net";
|
|
43
|
+
const T_A = "tok_files_node_a";
|
|
44
|
+
const T_B = "tok_files_node_b";
|
|
45
|
+
const T_LEGACY = "tok_files_node_legacy";
|
|
46
|
+
|
|
47
|
+
function cleanup() {
|
|
48
|
+
for (const net of [NET, OTHER_NET]) {
|
|
49
|
+
try { db.run("DELETE FROM node_rules_requests WHERE network_id = ?1", [net]); } catch {}
|
|
50
|
+
try { db.run("DELETE FROM rename_txn WHERE network_id = ?1", [net]); } catch {}
|
|
51
|
+
try { db.run("DELETE FROM sessions WHERE network_id = ?1", [net]); } catch {}
|
|
52
|
+
try { db.run("DELETE FROM nodes WHERE network_id = ?1", [net]); } catch {}
|
|
53
|
+
try { db.run("DELETE FROM api_tokens WHERE network_id = ?1", [net]); } catch {}
|
|
54
|
+
try { db.run("DELETE FROM network_members WHERE network_id = ?1", [net]); } catch {}
|
|
55
|
+
try { db.run("DELETE FROM networks WHERE network_id = ?1", [net]); } catch {}
|
|
56
|
+
}
|
|
57
|
+
try { db.run("DELETE FROM users WHERE user_id = ?1", [USER]); } catch {}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function seedWorld() {
|
|
61
|
+
db.run(`INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?2, 'x', 'user', datetime('now'))`, [USER, USER]);
|
|
62
|
+
for (const net of [NET, OTHER_NET]) {
|
|
63
|
+
db.run(`INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?2, ?3, datetime('now'))`, [net, net, USER]);
|
|
64
|
+
db.run(`INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'owner', datetime('now'))`, [USER, net]);
|
|
65
|
+
}
|
|
66
|
+
const tok = (id: string, net: string, alias: string, bound: string | null = null) => db.run(
|
|
67
|
+
`INSERT INTO api_tokens (token_id, user_id, network_id, scope, name, token_hash, expires_at, revoked_at, bound_node_id) VALUES (?1, ?2, ?3, 'network', ?4, ?5, NULL, NULL, ?6)`,
|
|
68
|
+
[id, USER, net, `node:${alias}`, `hash_${id}`, bound],
|
|
69
|
+
);
|
|
70
|
+
const node = (id: string, alias: string) => db.run(
|
|
71
|
+
`INSERT INTO nodes (node_id, node_name, alias, network_id, created_at, updated_at) VALUES (?1, ?2, ?3, ?4, datetime('now'), datetime('now'))`,
|
|
72
|
+
[id, alias, alias, NET],
|
|
73
|
+
);
|
|
74
|
+
node(NODE_A_ID, NODE_A);
|
|
75
|
+
node(NODE_B_ID, NODE_B);
|
|
76
|
+
node(LEGACY_ID, LEGACY_ALIAS);
|
|
77
|
+
tok(T_SESSION, NET, SESSION_ALIAS);
|
|
78
|
+
tok(T_PEER, NET, PEER_ALIAS);
|
|
79
|
+
tok(T_OTHER_NET_SAME_ALIAS, OTHER_NET, SESSION_ALIAS);
|
|
80
|
+
tok(T_A, NET, NODE_A, NODE_A_ID);
|
|
81
|
+
tok(T_B, NET, NODE_B, NODE_B_ID);
|
|
82
|
+
tok(T_LEGACY, NET, LEGACY_ALIAS, null);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type Identity = { net: string; alias: string; isNetworkToken: boolean; tokenId: string };
|
|
86
|
+
const asUser: Identity = { net: NET, alias: USER, isNetworkToken: false, tokenId: "tok_files_session_user" };
|
|
87
|
+
const asUserOtherLogin: Identity = { net: NET, alias: USER, isNetworkToken: false, tokenId: "tok_files_session_user_other_login" };
|
|
88
|
+
const asSession: Identity = { net: NET, alias: SESSION_ALIAS, isNetworkToken: true, tokenId: T_SESSION };
|
|
89
|
+
const asPeer: Identity = { net: NET, alias: PEER_ALIAS, isNetworkToken: true, tokenId: T_PEER };
|
|
90
|
+
const asOtherNetSameAlias: Identity = { net: OTHER_NET, alias: SESSION_ALIAS, isNetworkToken: true, tokenId: T_OTHER_NET_SAME_ALIAS };
|
|
91
|
+
const asA: Identity = { net: NET, alias: NODE_A, isNetworkToken: true, tokenId: T_A };
|
|
92
|
+
const asB: Identity = { net: NET, alias: NODE_B, isNetworkToken: true, tokenId: T_B };
|
|
93
|
+
const asLegacy: Identity = { net: NET, alias: LEGACY_ALIAS, isNetworkToken: true, tokenId: T_LEGACY };
|
|
94
|
+
|
|
95
|
+
async function connect(id: Identity) {
|
|
96
|
+
const server = new McpServer({ name: "files-session-test", version: "1" });
|
|
97
|
+
registerTools(server, undefined, id.net, USER, id.alias, id.isNetworkToken, id.tokenId);
|
|
98
|
+
const client = new Client({ name: "files-session-client", version: "1" });
|
|
99
|
+
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
100
|
+
await server.connect(st);
|
|
101
|
+
await client.connect(ct);
|
|
102
|
+
const call = async (name: string, args: Record<string, unknown>) => {
|
|
103
|
+
const r: any = await client.callTool({ name, arguments: args });
|
|
104
|
+
const first = r.content?.[0];
|
|
105
|
+
if (!first || first.type !== "text") throw new Error(`no text result from ${name}: ${JSON.stringify(r).slice(0, 300)}`);
|
|
106
|
+
try { return JSON.parse(first.text); } catch { return { raw: first.text, isError: r.isError === true }; }
|
|
107
|
+
};
|
|
108
|
+
const close = async () => { await client.close(); await server.close(); };
|
|
109
|
+
return { call, close };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const capable = (alias: string, net = NET) =>
|
|
113
|
+
db.get<{ c: number }>("SELECT files_capable AS c FROM sessions WHERE alias = ?1 AND network_id = ?2", alias, net)?.c;
|
|
114
|
+
const rowCount = () => db.get<{ n: number }>("SELECT COUNT(*) AS n FROM node_rules_requests WHERE network_id = ?1", NET)!.n;
|
|
115
|
+
|
|
116
|
+
async function report(id: Identity, alias: string, resume: string, flags: Record<string, true>) {
|
|
117
|
+
const c = await connect(id);
|
|
118
|
+
try { return await c.call("report_status", { resume_id: resume, alias, status: "idle", agent: "claude-code", ...flags }); }
|
|
119
|
+
finally { await c.close(); }
|
|
120
|
+
}
|
|
121
|
+
const ALL_FLAGS = { rules_file_capable: true, skills_capable: true, files_capable: true } as const;
|
|
122
|
+
|
|
123
|
+
beforeEach(() => { cleanup(); seedWorld(); });
|
|
124
|
+
afterAll(cleanup);
|
|
125
|
+
|
|
126
|
+
describe("files_capable is set only by the session's own node token", () => {
|
|
127
|
+
test("own token sets it; a later report without it does not clear it; a peer cannot set it", async () => {
|
|
128
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
129
|
+
expect(capable(SESSION_ALIAS)).toBe(1);
|
|
130
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, {});
|
|
131
|
+
expect(capable(SESSION_ALIAS)).toBe(1);
|
|
132
|
+
const r = await report(asPeer, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
133
|
+
expect(r).toMatchObject({ ok: false });
|
|
134
|
+
// A user login cannot set it either.
|
|
135
|
+
await report(asUser, PEER_ALIAS, "cc-files-user-report", ALL_FLAGS);
|
|
136
|
+
expect(capable(PEER_ALIAS) ?? 0).toBe(0);
|
|
137
|
+
}, 20_000);
|
|
138
|
+
|
|
139
|
+
test("a stale process whose report is rewritten to a renamed alias does not grant that alias the flag", async () => {
|
|
140
|
+
const NEW_ALIAS = "files-session-renamed";
|
|
141
|
+
db.run(
|
|
142
|
+
`INSERT INTO rename_txn (txn_id, network_id, old_alias, new_alias, status, committed_at) VALUES ('txn_files_rename', ?1, ?2, ?3, 'committed', datetime('now'))`,
|
|
143
|
+
[NET, PEER_ALIAS, NEW_ALIAS],
|
|
144
|
+
);
|
|
145
|
+
// Token still carries the old alias; the hub rewrites the report to NEW_ALIAS.
|
|
146
|
+
const r = await report(asPeer, PEER_ALIAS, "cc-files-renamed", ALL_FLAGS);
|
|
147
|
+
expect(r.ok).toBe(true);
|
|
148
|
+
expect(db.get<{ n: number }>("SELECT COUNT(*) AS n FROM sessions WHERE alias = ?1 AND network_id = ?2", NEW_ALIAS, NET)!.n).toBe(1);
|
|
149
|
+
expect(capable(NEW_ALIAS)).toBe(0);
|
|
150
|
+
}, 20_000);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe("list / read by alias reach a session with no nodes row", () => {
|
|
154
|
+
test("list: pulled request carries the normalized relative path; result comes back", async () => {
|
|
155
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
156
|
+
const u = await connect(asUser);
|
|
157
|
+
const s = await connect(asSession);
|
|
158
|
+
try {
|
|
159
|
+
const enq = await u.call("list_node_files", { alias: SESSION_ALIAS, path: "./src//lib/" });
|
|
160
|
+
expect(enq).toMatchObject({ ok: true, op: "files_list" });
|
|
161
|
+
const pulled = await s.call("get_rules_file_request", {});
|
|
162
|
+
expect(pulled.request).toEqual({ request_id: enq.request_id, op: "files_list", content: "src/lib" });
|
|
163
|
+
const payload = JSON.stringify({ path: "src/lib", entries: [{ name: "a.ts", type: "file", size: 3, mtime: 1 }], truncated: false, total: 1 });
|
|
164
|
+
expect(await s.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", file_name: "files", exists: true, content: payload })).toMatchObject({ ok: true, status: "done" });
|
|
165
|
+
expect(await u.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: true, op: "files_list", status: "done", content: payload });
|
|
166
|
+
} finally { await u.close(); await s.close(); }
|
|
167
|
+
}, 20_000);
|
|
168
|
+
|
|
169
|
+
test("list with no path targets the root (empty content)", async () => {
|
|
170
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
171
|
+
const u = await connect(asUser);
|
|
172
|
+
const s = await connect(asSession);
|
|
173
|
+
try {
|
|
174
|
+
const enq = await u.call("list_node_files", { alias: SESSION_ALIAS });
|
|
175
|
+
expect((await s.call("get_rules_file_request", {})).request).toEqual({ request_id: enq.request_id, op: "files_list", content: "" });
|
|
176
|
+
} finally { await u.close(); await s.close(); }
|
|
177
|
+
}, 20_000);
|
|
178
|
+
|
|
179
|
+
test("read round trip", async () => {
|
|
180
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
181
|
+
const u = await connect(asUser);
|
|
182
|
+
const s = await connect(asSession);
|
|
183
|
+
try {
|
|
184
|
+
const enq = await u.call("read_node_file", { alias: SESSION_ALIAS, path: "docs/README.md" });
|
|
185
|
+
// 2026-10-31 —— #3275:read_node_file 与 list_node_files 是**同一族**(都只是下发请求),
|
|
186
|
+
// 所以形状也应当一样:{ok, op, request_id}。钉住它,顺带钉住「两个工具不能长成两种形状」。
|
|
187
|
+
expect(Object.keys(enq).sort()).toEqual(["ok", "op", "request_id"]);
|
|
188
|
+
expect(enq).toMatchObject({ ok: true, op: "file_read" });
|
|
189
|
+
expect((await s.call("get_rules_file_request", {})).request).toEqual({ request_id: enq.request_id, op: "file_read", content: "docs/README.md" });
|
|
190
|
+
const payload = JSON.stringify({ path: "docs/README.md", name: "README.md", kind: "text", size: 6, content: "# hi\n" });
|
|
191
|
+
await s.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", file_name: "README.md", exists: true, content: payload });
|
|
192
|
+
expect(await u.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ status: "done", content: payload });
|
|
193
|
+
} finally { await u.close(); await s.close(); }
|
|
194
|
+
}, 20_000);
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
describe("path validation happens before any row is written", () => {
|
|
198
|
+
test("absolute, .., ~, drive letters, backslashes, NUL, and an empty read path are refused", async () => {
|
|
199
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
200
|
+
const u = await connect(asUser);
|
|
201
|
+
try {
|
|
202
|
+
const bad = ["/etc/passwd", "../outside", "a/../../b", "src/..", "~/.ssh/id_rsa", "C:/Windows", "a\\b", "..\\x", "a\u0000b", "x".repeat(1025)];
|
|
203
|
+
for (const path of bad) {
|
|
204
|
+
// Over-long paths are stopped by the zod schema (an MCP input error); the rest by invalid_path.
|
|
205
|
+
const r = await u.call("read_node_file", { alias: SESSION_ALIAS, path });
|
|
206
|
+
expect(r.ok).not.toBe(true);
|
|
207
|
+
if (path.length <= 1024) expect(r).toMatchObject({ ok: false, error: "invalid_path" });
|
|
208
|
+
const l = await u.call("list_node_files", { alias: SESSION_ALIAS, path });
|
|
209
|
+
expect(l.ok).not.toBe(true);
|
|
210
|
+
}
|
|
211
|
+
expect(await u.call("read_node_file", { alias: SESSION_ALIAS, path: "/" })).toMatchObject({ ok: false, error: "invalid_path" });
|
|
212
|
+
expect(await u.call("read_node_file", { alias: SESSION_ALIAS, path: "./" })).toMatchObject({ ok: false, error: "invalid_path" });
|
|
213
|
+
expect(rowCount()).toBe(0);
|
|
214
|
+
} finally { await u.close(); }
|
|
215
|
+
}, 20_000);
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
describe("who may ask, and who may read the answer", () => {
|
|
219
|
+
test("a node token cannot enqueue a files op on another node (or itself)", async () => {
|
|
220
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
221
|
+
const a = await connect(asA);
|
|
222
|
+
try {
|
|
223
|
+
expect(await a.call("list_node_files", { alias: SESSION_ALIAS })).toMatchObject({ ok: false, error: "node_token_cannot_browse_files" });
|
|
224
|
+
expect(await a.call("read_node_file", { node_id: NODE_B_ID, path: ".env" })).toMatchObject({ ok: false, error: "node_token_cannot_browse_files" });
|
|
225
|
+
expect(await a.call("list_node_files", { node_id: NODE_A_ID })).toMatchObject({ ok: false, error: "node_token_cannot_browse_files" });
|
|
226
|
+
expect(rowCount()).toBe(0);
|
|
227
|
+
} finally { await a.close(); }
|
|
228
|
+
}, 20_000);
|
|
229
|
+
|
|
230
|
+
test("only the token that asked can read a files result; node tokens never can", async () => {
|
|
231
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
232
|
+
const u = await connect(asUser);
|
|
233
|
+
const other = await connect(asUserOtherLogin);
|
|
234
|
+
const s = await connect(asSession);
|
|
235
|
+
const a = await connect(asA);
|
|
236
|
+
try {
|
|
237
|
+
const enq = await u.call("read_node_file", { alias: SESSION_ALIAS, path: "notes.txt" });
|
|
238
|
+
await s.call("get_rules_file_request", {});
|
|
239
|
+
await s.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: JSON.stringify({ path: "notes.txt", kind: "text", content: "x" }) });
|
|
240
|
+
expect(await u.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: true, status: "done" });
|
|
241
|
+
expect(await other.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: false, error: "request_not_found" });
|
|
242
|
+
expect(await a.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: false, error: "request_not_found" });
|
|
243
|
+
// The serving session itself cannot read the stored result back through the client tool either.
|
|
244
|
+
expect(await s.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: false, error: "request_not_found" });
|
|
245
|
+
} finally { await u.close(); await other.close(); await s.close(); await a.close(); }
|
|
246
|
+
}, 20_000);
|
|
247
|
+
|
|
248
|
+
test("rules/skills results stay readable by any writer of the network (unchanged)", async () => {
|
|
249
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
250
|
+
const u = await connect(asUser);
|
|
251
|
+
const other = await connect(asUserOtherLogin);
|
|
252
|
+
try {
|
|
253
|
+
const enq = await u.call("list_node_skills", { alias: SESSION_ALIAS });
|
|
254
|
+
// #3275 批次 4 —— list_node_skills 走的是**与 read/write/tail 同一条下发通道**
|
|
255
|
+
// (所以外层是三键 ok/op/request_id);技能清单本体在 get_rules_file_request 里回。
|
|
256
|
+
expect(Object.keys(enq).sort()).toEqual(["ok", "op", "request_id"]);
|
|
257
|
+
expect(await other.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: true, status: "pending" });
|
|
258
|
+
} finally { await u.close(); await other.close(); }
|
|
259
|
+
}, 20_000);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
describe("a token bound to node A cannot touch node B's files request", () => {
|
|
263
|
+
test("B's request: A pulls nothing, A's ack is ignored, B pulls and acks it", async () => {
|
|
264
|
+
const u = await connect(asUser);
|
|
265
|
+
const a = await connect(asA);
|
|
266
|
+
const b = await connect(asB);
|
|
267
|
+
try {
|
|
268
|
+
const enq = await u.call("read_node_file", { node_id: NODE_B_ID, path: "secret-plan.md" });
|
|
269
|
+
expect(enq).toMatchObject({ ok: true });
|
|
270
|
+
expect((await a.call("get_rules_file_request", {})).request).toBeNull();
|
|
271
|
+
expect(await a.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: "{\"forged\":true}" })).toMatchObject({ ok: true, ignored: "unknown_or_foreign_request" });
|
|
272
|
+
expect(await u.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ status: "pending" });
|
|
273
|
+
expect((await b.call("get_rules_file_request", {})).request).toEqual({ request_id: enq.request_id, op: "file_read", content: "secret-plan.md" });
|
|
274
|
+
expect(await b.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: "{}" })).toMatchObject({ ok: true, status: "done" });
|
|
275
|
+
} finally { await u.close(); await a.close(); await b.close(); }
|
|
276
|
+
}, 20_000);
|
|
277
|
+
|
|
278
|
+
test("same alias in another network neither pulls nor acks; a peer's ack is ignored", async () => {
|
|
279
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
280
|
+
const u = await connect(asUser);
|
|
281
|
+
const other = await connect(asOtherNetSameAlias);
|
|
282
|
+
const peer = await connect(asPeer);
|
|
283
|
+
try {
|
|
284
|
+
const enq = await u.call("list_node_files", { alias: SESSION_ALIAS });
|
|
285
|
+
expect((await other.call("get_rules_file_request", {})).request).toBeNull();
|
|
286
|
+
expect(await other.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: "{}" })).toMatchObject({ ignored: "unknown_or_foreign_request" });
|
|
287
|
+
expect(await peer.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: "{}" })).toMatchObject({ ignored: "unknown_or_foreign_request" });
|
|
288
|
+
expect(await u.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ status: "pending" });
|
|
289
|
+
} finally { await u.close(); await other.close(); await peer.close(); }
|
|
290
|
+
}, 20_000);
|
|
291
|
+
|
|
292
|
+
test("an unbound legacy token gets what skills gives it: alias fallback pull + ack, and it can set its own flag", async () => {
|
|
293
|
+
const u = await connect(asUser);
|
|
294
|
+
const legacy = await connect(asLegacy);
|
|
295
|
+
try {
|
|
296
|
+
await report(asLegacy, LEGACY_ALIAS, `sdk-${LEGACY_ID}`, ALL_FLAGS);
|
|
297
|
+
expect(capable(LEGACY_ALIAS)).toBe(1);
|
|
298
|
+
const skills = await u.call("list_node_skills", { node_id: LEGACY_ID });
|
|
299
|
+
const files = await u.call("list_node_files", { node_id: LEGACY_ID, path: "src" });
|
|
300
|
+
expect(skills).toMatchObject({ ok: true });
|
|
301
|
+
expect(files).toMatchObject({ ok: true });
|
|
302
|
+
const first = (await legacy.call("get_rules_file_request", {})).request;
|
|
303
|
+
const second = (await legacy.call("get_rules_file_request", {})).request;
|
|
304
|
+
expect([first.request_id, second.request_id].sort()).toEqual([skills.request_id, files.request_id].sort());
|
|
305
|
+
expect(await legacy.call("ack_rules_file_request", { request_id: files.request_id, status: "done", content: "{}" })).toMatchObject({ ok: true, status: "done" });
|
|
306
|
+
expect(await legacy.call("ack_rules_file_request", { request_id: skills.request_id, status: "done", content: "{}" })).toMatchObject({ ok: true, status: "done" });
|
|
307
|
+
} finally { await u.close(); await legacy.close(); }
|
|
308
|
+
}, 20_000);
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
describe("lanes, capability gate and ack size", () => {
|
|
312
|
+
test("files has its own single-flight lane", async () => {
|
|
313
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
314
|
+
const u = await connect(asUser);
|
|
315
|
+
try {
|
|
316
|
+
expect(await u.call("read_node_rules_file", { alias: SESSION_ALIAS })).toMatchObject({ ok: true });
|
|
317
|
+
expect(await u.call("list_node_skills", { alias: SESSION_ALIAS })).toMatchObject({ ok: true });
|
|
318
|
+
const list = await u.call("list_node_files", { alias: SESSION_ALIAS });
|
|
319
|
+
expect(list).toMatchObject({ ok: true });
|
|
320
|
+
expect(await u.call("read_node_file", { alias: SESSION_ALIAS, path: "a.txt" })).toMatchObject({ ok: false, error: "request_in_flight", existing_request_id: list.request_id });
|
|
321
|
+
} finally { await u.close(); }
|
|
322
|
+
}, 20_000);
|
|
323
|
+
|
|
324
|
+
test("rules+skills capable but not files capable → files_target_not_found, no row", async () => {
|
|
325
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, { rules_file_capable: true, skills_capable: true });
|
|
326
|
+
const u = await connect(asUser);
|
|
327
|
+
try {
|
|
328
|
+
expect(await u.call("list_node_files", { alias: SESSION_ALIAS })).toMatchObject({ ok: false, error: "files_target_not_found" });
|
|
329
|
+
expect(rowCount()).toBe(0);
|
|
330
|
+
} finally { await u.close(); }
|
|
331
|
+
}, 20_000);
|
|
332
|
+
|
|
333
|
+
test("a files ack may carry up to 1 MiB; a rules ack keeps its 256 KiB cap", async () => {
|
|
334
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
335
|
+
const u = await connect(asUser);
|
|
336
|
+
const s = await connect(asSession);
|
|
337
|
+
try {
|
|
338
|
+
const big = JSON.stringify({ path: "big.txt", kind: "text", content: "\n".repeat(256 * 1024) });
|
|
339
|
+
expect(big.length).toBeGreaterThan(256 * 1024);
|
|
340
|
+
const f = await u.call("read_node_file", { alias: SESSION_ALIAS, path: "big.txt" });
|
|
341
|
+
const r = await u.call("read_node_rules_file", { alias: SESSION_ALIAS });
|
|
342
|
+
await s.call("get_rules_file_request", {});
|
|
343
|
+
await s.call("get_rules_file_request", {});
|
|
344
|
+
expect(await s.call("ack_rules_file_request", { request_id: f.request_id, status: "done", content: big })).toMatchObject({ ok: true, status: "done" });
|
|
345
|
+
expect(await s.call("ack_rules_file_request", { request_id: r.request_id, status: "done", content: "x".repeat(256 * 1024 + 1) })).toMatchObject({ ok: false, error: "content_too_large" });
|
|
346
|
+
const tooBig = await s.call("ack_rules_file_request", { request_id: r.request_id, status: "done", content: "x".repeat(1024 * 1024 + 1) });
|
|
347
|
+
expect(tooBig.ok).not.toBe(true);
|
|
348
|
+
} finally { await u.close(); await s.close(); }
|
|
349
|
+
}, 20_000);
|
|
350
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// #594 step 1 — report_status.health.codex_login (non-secret codex login fingerprint +
|
|
2
|
+
// "shared with N other nodes on this host"). Additive on the #448 health channel.
|
|
3
|
+
//
|
|
4
|
+
// 跑法:cd server && COMMHUB_DB=/tmp/node-health-codex-login.db bun test src/node-health-codex-login.test.ts
|
|
5
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
6
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
7
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
8
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
9
|
+
import { db } from "./db.js";
|
|
10
|
+
import { registerTools } from "./tools.js";
|
|
11
|
+
import { clearNodeHealthStore, readNodeHealth } from "./node-health-store.js";
|
|
12
|
+
import { degradedLayers } from "./node-health-guard.js";
|
|
13
|
+
|
|
14
|
+
const NET = "net_health_codex_login_t";
|
|
15
|
+
const OWNER = "u_hcl_owner";
|
|
16
|
+
const NODE_A = "hcl-node-a";
|
|
17
|
+
const NODE_B = "hcl-node-b";
|
|
18
|
+
const NODE_A_ID = "node_hcl_a";
|
|
19
|
+
const NODE_B_ID = "node_hcl_b";
|
|
20
|
+
const T_A = "tok_hcl_node_a";
|
|
21
|
+
const T_B = "tok_hcl_node_b";
|
|
22
|
+
|
|
23
|
+
function cleanup() {
|
|
24
|
+
for (const t of ["sessions", "nodes", "api_tokens", "network_members", "networks"]) {
|
|
25
|
+
try { db.run(`DELETE FROM ${t} WHERE network_id = ?1`, [NET]); } catch {}
|
|
26
|
+
}
|
|
27
|
+
try { db.run("DELETE FROM users WHERE user_id = ?1", [OWNER]); } catch {}
|
|
28
|
+
clearNodeHealthStore();
|
|
29
|
+
}
|
|
30
|
+
function seed() {
|
|
31
|
+
db.run(`INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?2, 'x', 'user', datetime('now'))`, [OWNER, OWNER]);
|
|
32
|
+
db.run(`INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?2, ?3, datetime('now'))`, [NET, NET, OWNER]);
|
|
33
|
+
db.run(`INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'owner', datetime('now'))`, [OWNER, NET]);
|
|
34
|
+
for (const [id, alias, tok] of [[NODE_A_ID, NODE_A, T_A], [NODE_B_ID, NODE_B, T_B]]) {
|
|
35
|
+
db.run(`INSERT INTO nodes (node_id, node_name, alias, network_id, owner_user_id, created_at, updated_at) VALUES (?1, ?2, ?3, ?4, ?5, datetime('now'), datetime('now'))`, [id, alias, alias, NET, OWNER]);
|
|
36
|
+
db.run(`INSERT INTO api_tokens (token_id, user_id, network_id, scope, name, token_hash, expires_at, revoked_at, bound_node_id) VALUES (?1, ?2, ?3, 'network', ?4, ?5, NULL, NULL, ?6)`, [tok, OWNER, NET, `node:${alias}`, `hash_${tok}`, id]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function connectAs(alias: string, tokenId: string) {
|
|
41
|
+
const server = new McpServer({ name: "health-test", version: "1" });
|
|
42
|
+
registerTools(server, undefined, NET, OWNER, alias, true, tokenId);
|
|
43
|
+
const client = new Client({ name: "health-client", version: "1" });
|
|
44
|
+
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
45
|
+
await server.connect(st);
|
|
46
|
+
await client.connect(ct);
|
|
47
|
+
const call = async (args: Record<string, unknown>) => {
|
|
48
|
+
const r: any = await client.callTool({ name: "report_status", arguments: args });
|
|
49
|
+
return { isError: r.isError === true, body: JSON.parse(r.content?.[0]?.text ?? "null") };
|
|
50
|
+
};
|
|
51
|
+
return { call, close: async () => { await client.close(); await server.close(); } };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const LOGIN = { fingerprint: "1a2b3c4d", shared_with: 2, shared_home_with: 1, codex_home: "/srv/ws/.anet/nodes/a/codex-home" };
|
|
55
|
+
|
|
56
|
+
beforeEach(() => { cleanup(); seed(); });
|
|
57
|
+
afterAll(cleanup);
|
|
58
|
+
|
|
59
|
+
describe("#594 report_status.health.codex_login passthrough", () => {
|
|
60
|
+
test("well-formed codex_login is kept next to the #448 layers and readable", async () => {
|
|
61
|
+
const a = await connectAs(NODE_A, T_A);
|
|
62
|
+
try {
|
|
63
|
+
const r = await a.call({ resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID, health: { bridge: "ok", model_auth: "ok", codex_login: LOGIN } });
|
|
64
|
+
expect(r.isError).toBe(false);
|
|
65
|
+
} finally { await a.close(); }
|
|
66
|
+
expect(readNodeHealth(NET, NODE_A)?.health.codex_login).toEqual(LOGIN);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("codex_login alone (codex-sdk runtime, no #448 monitor) is accepted", async () => {
|
|
70
|
+
const a = await connectAs(NODE_A, T_A);
|
|
71
|
+
try {
|
|
72
|
+
await a.call({ resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID, health: { codex_login: { fingerprint: "deadbeef", shared_with: 0 } } });
|
|
73
|
+
} finally { await a.close(); }
|
|
74
|
+
expect(readNodeHealth(NET, NODE_A)?.health.codex_login).toEqual({ fingerprint: "deadbeef", shared_with: 0 });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("🔴 a shared login is NOT a degraded layer — dispatch must not refuse because of it", () => {
|
|
78
|
+
expect(degradedLayers({ bridge: "ok", model_auth: "ok", codex_login: LOGIN } as any)).toEqual([]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("🔴 anything that is not an 8-hex fingerprint is dropped (a token pasted there never gets stored), report still accepted", async () => {
|
|
82
|
+
const a = await connectAs(NODE_A, T_A);
|
|
83
|
+
const bads = [
|
|
84
|
+
{ fingerprint: "FAKE-REFRESH-TOKEN-should-never-be-stored", shared_with: 1 },
|
|
85
|
+
{ fingerprint: "a".repeat(64), shared_with: 1 },
|
|
86
|
+
{ fingerprint: "1A2B3C4D", shared_with: 1 },
|
|
87
|
+
{ fingerprint: "1a2b3c4d", shared_with: -1 },
|
|
88
|
+
{ fingerprint: "1a2b3c4d", shared_with: 1.5 },
|
|
89
|
+
{ fingerprint: "1a2b3c4d" },
|
|
90
|
+
"1a2b3c4d",
|
|
91
|
+
];
|
|
92
|
+
try {
|
|
93
|
+
for (const bad of bads) {
|
|
94
|
+
const r = await a.call({ resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID, health: { bridge: "ok", model_auth: "ok", codex_login: bad } });
|
|
95
|
+
expect(r.isError).toBe(false);
|
|
96
|
+
const h = readNodeHealth(NET, NODE_A)?.health;
|
|
97
|
+
expect(h?.model_auth).toBe("ok");
|
|
98
|
+
expect(h?.codex_login).toBeUndefined();
|
|
99
|
+
expect(JSON.stringify(h)).not.toContain("FAKE-REFRESH-TOKEN");
|
|
100
|
+
}
|
|
101
|
+
} finally { await a.close(); }
|
|
102
|
+
expect(db.get<{ s: string }>("SELECT status AS s FROM sessions WHERE alias = ?1 AND network_id = ?2", NODE_A, NET)?.s).toBe("idle");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("bad optional sub-fields degrade alone: control characters in codex_home are dropped, the rest kept", async () => {
|
|
106
|
+
const a = await connectAs(NODE_A, T_A);
|
|
107
|
+
try {
|
|
108
|
+
await a.call({ resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID, health: { codex_login: { fingerprint: "1a2b3c4d", shared_with: 1, shared_home_with: "x", codex_home: "/x\n; rm -rf /" } } });
|
|
109
|
+
} finally { await a.close(); }
|
|
110
|
+
expect(readNodeHealth(NET, NODE_A)?.health.codex_login).toEqual({ fingerprint: "1a2b3c4d", shared_with: 1 });
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("another node's token cannot set this node's codex_login", async () => {
|
|
114
|
+
const b = await connectAs(NODE_B, T_B);
|
|
115
|
+
try {
|
|
116
|
+
await b.call({ resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID, health: { codex_login: LOGIN } });
|
|
117
|
+
} finally { await b.close(); }
|
|
118
|
+
expect(readNodeHealth(NET, NODE_A)).toBeNull();
|
|
119
|
+
});
|
|
120
|
+
});
|