@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,104 @@
|
|
|
1
|
+
// #2596 —— 空白 node 行的清理:只删「三身份字段全空 + 无 session + 够旧」的行。
|
|
2
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
3
|
+
import { db } from "./db.js";
|
|
4
|
+
import { readEmptyNodeAgeDays, sweepEmptyNodeRows } from "./empty-node-sweeper.js";
|
|
5
|
+
|
|
6
|
+
let networkId = "";
|
|
7
|
+
|
|
8
|
+
function insertNode(
|
|
9
|
+
nodeId: string,
|
|
10
|
+
alias: string,
|
|
11
|
+
opts: { identity?: boolean; updatedDaysAgo?: number; createdDaysAgo?: number } = {},
|
|
12
|
+
) {
|
|
13
|
+
const { identity = false, updatedDaysAgo = 10, createdDaysAgo = 30 } = opts;
|
|
14
|
+
db.run(
|
|
15
|
+
`INSERT INTO nodes (node_id, node_name, alias, runtime, hostname, config_path, network_id, created_at, updated_at)
|
|
16
|
+
VALUES (?1, ?2, ?2, ?3, ?4, ?5, ?6, datetime('now', ?8), datetime('now', ?7))`,
|
|
17
|
+
[
|
|
18
|
+
nodeId,
|
|
19
|
+
alias,
|
|
20
|
+
identity ? "codex-app-server-sdk" : null,
|
|
21
|
+
identity ? "host-a" : null,
|
|
22
|
+
identity ? "/data/x" : null,
|
|
23
|
+
networkId,
|
|
24
|
+
`-${updatedDaysAgo} days`,
|
|
25
|
+
`-${createdDaysAgo} days`,
|
|
26
|
+
],
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function exists(nodeId: string): boolean {
|
|
31
|
+
return !!db.get<{ node_id: string }>("SELECT node_id FROM nodes WHERE node_id = ?1", [nodeId]);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
beforeAll(async () => {
|
|
35
|
+
const { register } = await import("./auth.js");
|
|
36
|
+
const auth = register(`empty_gc_${Date.now()}`, "EmptyGc-Str0ng-1!", undefined, "watcher");
|
|
37
|
+
expect(auth.ok).toBe(true);
|
|
38
|
+
networkId = auth.network_id!;
|
|
39
|
+
|
|
40
|
+
insertNode("gc-empty-old", "ghost-a"); // 该删
|
|
41
|
+
insertNode("gc-empty-fresh", "ghost-b", { createdDaysAgo: 0, updatedDaysAgo: 0 }); // 太新:可能正在注册
|
|
42
|
+
insertNode("gc-real", "real-node", { identity: true }); // 有身份:绝不删
|
|
43
|
+
insertNode("gc-real-alias-2", "real-node", { identity: true }); // 不同机器同 alias:也绝不删
|
|
44
|
+
// 空壳但有 session(在线但还没上报身份)⇒ 不删
|
|
45
|
+
insertNode("gc-empty-with-session", "ghost-c");
|
|
46
|
+
db.run(
|
|
47
|
+
`INSERT INTO sessions (resume_id, alias, node_id, network_id, status, registered_at)
|
|
48
|
+
VALUES ('res_gc', 'ghost-c', 'gc-empty-with-session', ?1, 'offline', '2026-10-01 00:00:00')`,
|
|
49
|
+
[networkId],
|
|
50
|
+
);
|
|
51
|
+
}, 30_000);
|
|
52
|
+
|
|
53
|
+
afterAll(() => {
|
|
54
|
+
delete process.env.COMMHUB_EMPTY_NODE_GC_DAYS;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe("sweepEmptyNodeRows (#2596)", () => {
|
|
58
|
+
test("dry run reports the target but deletes nothing", () => {
|
|
59
|
+
const r = sweepEmptyNodeRows({ dryRun: true });
|
|
60
|
+
expect(r.ids).toContain("gc-empty-old");
|
|
61
|
+
expect(r.deleted).toBe(0);
|
|
62
|
+
expect(exists("gc-empty-old")).toBe(true);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test("deletes only the old, identity-less, session-less placeholder", () => {
|
|
66
|
+
const r = sweepEmptyNodeRows();
|
|
67
|
+
expect(exists("gc-empty-old")).toBe(false);
|
|
68
|
+
expect(r.deleted).toBeGreaterThanOrEqual(1);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
test("keeps fresh placeholders (they may be mid-registration)", () => {
|
|
72
|
+
sweepEmptyNodeRows();
|
|
73
|
+
expect(exists("gc-empty-fresh")).toBe(true);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("keeps rows with an identity, even when two nodes share an alias", () => {
|
|
77
|
+
sweepEmptyNodeRows();
|
|
78
|
+
expect(exists("gc-real")).toBe(true);
|
|
79
|
+
expect(exists("gc-real-alias-2")).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
test("keeps a placeholder that still has a session", () => {
|
|
83
|
+
sweepEmptyNodeRows();
|
|
84
|
+
expect(exists("gc-empty-with-session")).toBe(true);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test("a fresh bulk update does NOT protect an old empty row (created_at is the clock)", () => {
|
|
88
|
+
// 生产实测:2026-10-26 的一次批量更新把 08/09 月建的空壳 updated_at 全刷成 10-26,
|
|
89
|
+
// 若按 updated_at 判龄,2 天阈值永远删不掉它们。
|
|
90
|
+
insertNode("gc-empty-bulk-touched", "ghost-d", { createdDaysAgo: 40, updatedDaysAgo: 0 });
|
|
91
|
+
sweepEmptyNodeRows();
|
|
92
|
+
expect(exists("gc-empty-bulk-touched")).toBe(false);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("env <= 0 disables the sweep", () => {
|
|
96
|
+
process.env.COMMHUB_EMPTY_NODE_GC_DAYS = "0";
|
|
97
|
+
try {
|
|
98
|
+
expect(readEmptyNodeAgeDays()).toBe(0);
|
|
99
|
+
expect(sweepEmptyNodeRows().deleted).toBe(0);
|
|
100
|
+
} finally {
|
|
101
|
+
delete process.env.COMMHUB_EMPTY_NODE_GC_DAYS;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// #2596 —— 组织架构页那些“重复名字”的真身:**注册失败留下的空白 node 行**。
|
|
2
|
+
//
|
|
3
|
+
// 生产实测(2026-10-27,只读):
|
|
4
|
+
// ```
|
|
5
|
+
// nodes 总数 312
|
|
6
|
+
// runtime / hostname / config_path 全为空、且没有任何 session 的行 = 12
|
|
7
|
+
// 形态高度一致:同一 alias 在几分钟内连着出现,最后一个才被填上真实身份
|
|
8
|
+
// TMA门户鲸2号 ×5 09-17 15:47:52 → 16:03:05 (6 分钟注册 5 次,第 6 次成功)
|
|
9
|
+
// ```
|
|
10
|
+
// ⇒ 注册流程先建行、节点再补身份;补不上的尝试留下永久空壳,被组织架构页当成 node 渲染。
|
|
11
|
+
//
|
|
12
|
+
// 这里只做**清理**,不动注册流程:
|
|
13
|
+
// · 只删「三个身份字段全空 + 没有任何 session」的行 —— 这种行不可能提供任何功能;
|
|
14
|
+
// · 只删 `created_at` 早于 N 天(默认 2 天)的行 —— 正在注册中的行自然不会被误删;
|
|
15
|
+
// (用 created_at 不用 updated_at:后者会被无关的批量更新刷新,见下方注释里的生产实例)
|
|
16
|
+
// · 删除前把整行导成 JSON 到日志(可人工恢复),并返回被删的 id 列表。
|
|
17
|
+
//
|
|
18
|
+
// 为什么不用「同 alias 只留一条」这种规则:不同机器共用 alias 是**数据问题不是脏数据**
|
|
19
|
+
// (Mac打包狗 / TM微软牛 / TM汇报牛 这类),删了会丢真实节点。空壳判据才安全。
|
|
20
|
+
|
|
21
|
+
import { db } from "./db.js";
|
|
22
|
+
|
|
23
|
+
export const EMPTY_NODE_AGE_DAYS_ENV = "COMMHUB_EMPTY_NODE_GC_DAYS";
|
|
24
|
+
export const EMPTY_NODE_AGE_DAYS_DEFAULT = 2;
|
|
25
|
+
|
|
26
|
+
export type EmptyNodeSweepResult = {
|
|
27
|
+
deleted: number;
|
|
28
|
+
ids: string[];
|
|
29
|
+
ageDays: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function readEmptyNodeAgeDays(raw = process.env[EMPTY_NODE_AGE_DAYS_ENV]): number {
|
|
33
|
+
if (raw === undefined || raw === "") return EMPTY_NODE_AGE_DAYS_DEFAULT;
|
|
34
|
+
const n = Number(raw);
|
|
35
|
+
if (!Number.isFinite(n)) return EMPTY_NODE_AGE_DAYS_DEFAULT;
|
|
36
|
+
return Math.floor(n);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const IDENTITY_EMPTY = `COALESCE(runtime, '') = '' AND COALESCE(hostname, '') = '' AND COALESCE(config_path, '') = ''`;
|
|
40
|
+
|
|
41
|
+
export function sweepEmptyNodeRows(
|
|
42
|
+
opts: { olderThanDays?: number; dryRun?: boolean } = {},
|
|
43
|
+
): EmptyNodeSweepResult {
|
|
44
|
+
const ageDays = opts.olderThanDays ?? readEmptyNodeAgeDays();
|
|
45
|
+
// <=0 关闭(运维可以彻底停掉这个清理)
|
|
46
|
+
if (ageDays <= 0) return { deleted: 0, ids: [], ageDays: 0 };
|
|
47
|
+
|
|
48
|
+
const rows = db.all<{ node_id: string }>(
|
|
49
|
+
`SELECT n.node_id
|
|
50
|
+
FROM nodes n
|
|
51
|
+
WHERE ${IDENTITY_EMPTY.replace(/\b(runtime|hostname|config_path)\b/g, "n.$1")}
|
|
52
|
+
-- #2596 —— 用 created_at 而不是 updated_at:空壳行会被无关的批量更新
|
|
53
|
+
-- 把 updated_at 顶到「今天」(生产实测:2026-10-26 的一次批量更新把 08/09 月
|
|
54
|
+
-- 建的空壳全部刷成 10-26),那样 2 天的阈值就永远删不掉它们。
|
|
55
|
+
-- created_at 才是“这行空了多久”的稳定量;在注册中的行 created_at 必然是新的。
|
|
56
|
+
AND n.created_at < datetime('now', ?1)
|
|
57
|
+
AND NOT EXISTS (SELECT 1 FROM sessions s WHERE s.node_id = n.node_id)
|
|
58
|
+
LIMIT 500`,
|
|
59
|
+
`-${ageDays} days`,
|
|
60
|
+
);
|
|
61
|
+
if (rows.length === 0) return { deleted: 0, ids: [], ageDays };
|
|
62
|
+
|
|
63
|
+
const ids = rows.map((r) => r.node_id);
|
|
64
|
+
if (opts.dryRun) return { deleted: 0, ids, ageDays };
|
|
65
|
+
|
|
66
|
+
// 删前留证:整行 JSON 打到日志里(运维可据此恢复),再逐条删。
|
|
67
|
+
try {
|
|
68
|
+
const full = db.all<Record<string, unknown>>(
|
|
69
|
+
`SELECT * FROM nodes WHERE node_id IN (${ids.map((_, i) => `?${i + 1}`).join(",")})`,
|
|
70
|
+
ids,
|
|
71
|
+
);
|
|
72
|
+
console.log(`[commhub empty-node-gc] deleting ${ids.length} placeholder node row(s): ${JSON.stringify(full)}`);
|
|
73
|
+
} catch (e: any) {
|
|
74
|
+
console.log(`[commhub empty-node-gc] backup dump failed, aborting: ${e?.message ?? e}`);
|
|
75
|
+
return { deleted: 0, ids: [], ageDays };
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
let deleted = 0;
|
|
79
|
+
for (const id of ids) {
|
|
80
|
+
try {
|
|
81
|
+
const res = db.run(`DELETE FROM nodes WHERE node_id = ?1 AND ${IDENTITY_EMPTY}`, [id]);
|
|
82
|
+
deleted += res.changes ?? 0;
|
|
83
|
+
} catch (e: any) {
|
|
84
|
+
console.log(`[commhub empty-node-gc] delete ${id} failed: ${e?.message ?? e}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return { deleted, ids, ageDays };
|
|
88
|
+
}
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
// #1510 — the secret-transport gate, shipped as log-only first.
|
|
2
|
+
//
|
|
3
|
+
// The load-bearing property is symmetric: with the gate in log mode a write to a
|
|
4
|
+
// `plain` node MUST still succeed (nobody's workflow breaks on upgrade) but MUST
|
|
5
|
+
// leave a hit behind, and with `enforce` the same write MUST be refused. A
|
|
6
|
+
// half-implemented gate that logs but also refuses would break every plain-HTTP
|
|
7
|
+
// node on the next deploy; one that refuses but never logs leaves nothing to
|
|
8
|
+
// decide with.
|
|
9
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
|
|
10
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
|
|
14
|
+
const PRIVATE_DB_DIR = mkdtempSync(join(tmpdir(), "anet-transport-gate-"));
|
|
15
|
+
process.env.COMMHUB_DB ||= join(PRIVATE_DB_DIR, "hub.db");
|
|
16
|
+
|
|
17
|
+
let net = "", ownerId = "", ownerToken = "";
|
|
18
|
+
let server: ReturnType<typeof Bun.serve>;
|
|
19
|
+
let base = "";
|
|
20
|
+
const PLAIN = "n_gate_plain";
|
|
21
|
+
const TLS = "n_gate_tls";
|
|
22
|
+
// #1510 acceptance names three transports: loopback passes, https passes, plain
|
|
23
|
+
// public is refused. log/enforce only ever *special-case* `plain`, so loopback
|
|
24
|
+
// could rot without anyone noticing it is still accepted — seed it as its own
|
|
25
|
+
// node rather than folding it in with TLS, so a regression reads by name.
|
|
26
|
+
const LOOPBACK = "n_gate_loopback";
|
|
27
|
+
const UNKNOWN = "n_gate_unknown";
|
|
28
|
+
// #1510 补档 —— 生产里占绝大多数的是「从未上报」:2026-10-29 只读统计 373 个会话,
|
|
29
|
+
// env_transport = NULL 有 332 个(89%)。原实现是拒绝名单(只拒 plain),
|
|
30
|
+
// null 一路放行;卡里的口径是允许名单(只许 loopback/https)。这两者只在 null 上分歧,
|
|
31
|
+
// 所以这里把 null 当成一等公民单独种一个节点。
|
|
32
|
+
|
|
33
|
+
const post = async (path: string, token: string, body: unknown) => {
|
|
34
|
+
const r = await fetch(`${base}${path}`, {
|
|
35
|
+
method: "POST",
|
|
36
|
+
headers: { Authorization: `Bearer ${token}`, "Content-Type": "application/json" },
|
|
37
|
+
body: JSON.stringify(body),
|
|
38
|
+
});
|
|
39
|
+
return { status: r.status, body: await r.json() as any };
|
|
40
|
+
};
|
|
41
|
+
const get = async (path: string, token: string) => {
|
|
42
|
+
const r = await fetch(`${base}${path}`, { headers: { Authorization: `Bearer ${token}` } });
|
|
43
|
+
return { status: r.status, body: await r.json() as any };
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
beforeAll(async () => {
|
|
47
|
+
const { db } = await import("./db.js");
|
|
48
|
+
const { register } = await import("./auth.js");
|
|
49
|
+
const stamp = Date.now();
|
|
50
|
+
const owner = register(`gate_owner_${stamp}`, "GateOwner-Strong-1!");
|
|
51
|
+
expect(owner.ok).toBe(true);
|
|
52
|
+
ownerToken = owner.token!;
|
|
53
|
+
net = owner.network_id!;
|
|
54
|
+
ownerId = db.get<{ user_id: string }>("SELECT user_id FROM users WHERE username = ?1", `gate_owner_${stamp}`)!.user_id;
|
|
55
|
+
|
|
56
|
+
const seed = (nodeId: string, transport: string | null) => db.run(
|
|
57
|
+
`INSERT INTO nodes (node_id, node_name, alias, network_id, lifecycle_state, config_snapshot)
|
|
58
|
+
VALUES (?1, ?1, ?1, ?2, 'active', ?3)`,
|
|
59
|
+
[nodeId, net, JSON.stringify({ node_secrets_capable: true })],
|
|
60
|
+
);
|
|
61
|
+
seed(PLAIN, "plain");
|
|
62
|
+
seed(TLS, "https");
|
|
63
|
+
seed(LOOPBACK, "loopback");
|
|
64
|
+
seed(UNKNOWN, null);
|
|
65
|
+
// The transport is reported on the session row (that is where report_status
|
|
66
|
+
// writes it).
|
|
67
|
+
const session = (nodeId: string, transport: string | null) => db.run(
|
|
68
|
+
`INSERT INTO sessions (resume_id, alias, status, node_id, network_id, env_transport, updated_at, last_seen_at)
|
|
69
|
+
VALUES (?1, ?1, 'idle', ?1, ?2, ?3, datetime('now'), datetime('now'))`,
|
|
70
|
+
[nodeId, net, transport],
|
|
71
|
+
);
|
|
72
|
+
session(PLAIN, "plain");
|
|
73
|
+
session(TLS, "https");
|
|
74
|
+
session(LOOPBACK, "loopback");
|
|
75
|
+
session(UNKNOWN, null); // 从未上报 transport
|
|
76
|
+
|
|
77
|
+
const mod = await import("./server.js");
|
|
78
|
+
server = mod.bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
79
|
+
base = `http://127.0.0.1:${server.port}`;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
afterAll(() => {
|
|
83
|
+
try { server?.stop(true); } catch {}
|
|
84
|
+
try { rmSync(PRIVATE_DB_DIR, { recursive: true, force: true }); } catch {}
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
beforeEach(async () => {
|
|
88
|
+
// The lane allows one pending request per node; drain whatever the previous
|
|
89
|
+
// case left so the next one starts clean.
|
|
90
|
+
const { pullNodeSecrets, ackNodeSecrets } = await import("./scoped-secrets.js");
|
|
91
|
+
for (const nodeId of [PLAIN, TLS, LOOPBACK, UNKNOWN]) {
|
|
92
|
+
const daemon = { ok: true as const, networkId: net, daemonNodeId: nodeId, daemonAlias: nodeId };
|
|
93
|
+
const pulled = pullNodeSecrets(daemon) as any;
|
|
94
|
+
for (const r of (pulled?.requests ?? [])) ackNodeSecrets(daemon, r.request_id, null, true);
|
|
95
|
+
}
|
|
96
|
+
process.env.ANET_SECRET_TRANSPORT_GATE = "log";
|
|
97
|
+
delete process.env.ANET_SECRET_TRANSPORT_GATE_STRICT;
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("log mode (default)", () => {
|
|
101
|
+
test("a put to a plain node still succeeds AND leaves a hit", async () => {
|
|
102
|
+
const r = await post(`/api/nodes/${PLAIN}/secrets?network_id=${net}`, ownerToken, { action: "put", key: "A_KEY", value: "v", revision: 1 });
|
|
103
|
+
expect(r.status).toBe(200);
|
|
104
|
+
expect(r.body.ok).toBe(true); // not refused: that is the whole point of log mode
|
|
105
|
+
|
|
106
|
+
const log = await get(`/api/networks/${net}/env-transport-log`, ownerToken);
|
|
107
|
+
expect(log.status).toBe(200);
|
|
108
|
+
expect(log.body.total).toBe(1);
|
|
109
|
+
expect(log.body.rows[0]).toMatchObject({ node_id: PLAIN, route: "node_secret_put", hits: 1 });
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("a put to a TLS node leaves no hit", async () => {
|
|
113
|
+
const before = (await get(`/api/networks/${net}/env-transport-log`, ownerToken)).body.total;
|
|
114
|
+
const r = await post(`/api/nodes/${TLS}/secrets?network_id=${net}`, ownerToken, { action: "put", key: "B_KEY", value: "v", revision: 1 });
|
|
115
|
+
expect(r.status).toBe(200);
|
|
116
|
+
const after = (await get(`/api/networks/${net}/env-transport-log`, ownerToken)).body.total;
|
|
117
|
+
expect(after).toBe(before);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// #1510 acceptance leg 1: loopback is an allowed transport, so it must neither
|
|
121
|
+
// be refused nor pollute the would-refuse log (the log is the decision input
|
|
122
|
+
// for turning enforce on — a loopback hit in it would read as "something to
|
|
123
|
+
// block" when nothing is).
|
|
124
|
+
test("a put to a loopback node succeeds AND leaves no hit", async () => {
|
|
125
|
+
const before = (await get(`/api/networks/${net}/env-transport-log`, ownerToken)).body.total;
|
|
126
|
+
const r = await post(`/api/nodes/${LOOPBACK}/secrets?network_id=${net}`, ownerToken, { action: "put", key: "LB_KEY", value: "v", revision: 1 });
|
|
127
|
+
expect(r.status).toBe(200);
|
|
128
|
+
expect(r.body.ok).toBe(true);
|
|
129
|
+
const after = (await get(`/api/networks/${net}/env-transport-log`, ownerToken)).body.total;
|
|
130
|
+
expect(after).toBe(before);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test("list is not observed (it carries no secret)", async () => {
|
|
134
|
+
const before = (await get(`/api/networks/${net}/env-transport-log`, ownerToken)).body.total;
|
|
135
|
+
await post(`/api/nodes/${PLAIN}/secrets?network_id=${net}`, ownerToken, { action: "list" });
|
|
136
|
+
const after = (await get(`/api/networks/${net}/env-transport-log`, ownerToken)).body.total;
|
|
137
|
+
expect(after).toBe(before);
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
describe("enforce mode", () => {
|
|
142
|
+
test("the same put is refused, and nothing is queued", async () => {
|
|
143
|
+
process.env.ANET_SECRET_TRANSPORT_GATE = "enforce";
|
|
144
|
+
const r = await post(`/api/nodes/${PLAIN}/secrets?network_id=${net}`, ownerToken, { action: "put", key: "C_KEY", value: "v", revision: 1 });
|
|
145
|
+
expect(r.status).toBe(400);
|
|
146
|
+
expect(r.body.error).toBe("secret_transport_plain");
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
test("a TLS node is unaffected", async () => {
|
|
150
|
+
process.env.ANET_SECRET_TRANSPORT_GATE = "enforce";
|
|
151
|
+
const r = await post(`/api/nodes/${TLS}/secrets?network_id=${net}`, ownerToken, { action: "put", key: "D_KEY", value: "v", revision: 1 });
|
|
152
|
+
expect(r.status).toBe(200);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
// #1510 acceptance: "loopback 通过 / https 通过 / 明文公网被拒". enforce is
|
|
156
|
+
// defined as *refuse plain* — loopback is a local link and must keep working
|
|
157
|
+
// under enforce, otherwise turning the gate on would break the one transport
|
|
158
|
+
// it exists to protect.
|
|
159
|
+
test("a loopback node passes enforce too", async () => {
|
|
160
|
+
process.env.ANET_SECRET_TRANSPORT_GATE = "enforce";
|
|
161
|
+
const r = await post(`/api/nodes/${LOOPBACK}/secrets?network_id=${net}`, ownerToken, { action: "put", key: "LB2_KEY", value: "v", revision: 1 });
|
|
162
|
+
expect(r.status).toBe(200);
|
|
163
|
+
expect(r.body.ok).toBe(true);
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
describe("off mode", () => {
|
|
168
|
+
test("records nothing at all", async () => {
|
|
169
|
+
process.env.ANET_SECRET_TRANSPORT_GATE = "off";
|
|
170
|
+
const before = (await get(`/api/networks/${net}/env-transport-log`, ownerToken)).body.total;
|
|
171
|
+
const r = await post(`/api/nodes/${PLAIN}/secrets?network_id=${net}`, ownerToken, { action: "put", key: "E_KEY", value: "v", revision: 1 });
|
|
172
|
+
expect(r.status).toBe(200);
|
|
173
|
+
const after = (await get(`/api/networks/${net}/env-transport-log`, ownerToken)).body.total;
|
|
174
|
+
expect(after).toBe(before);
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
describe("the log endpoint is owner/admin only", () => {
|
|
179
|
+
test("an unrelated user gets 403", async () => {
|
|
180
|
+
const { register } = await import("./auth.js");
|
|
181
|
+
const other = register(`gate_other_${Date.now()}`, "GateOther-Strong-1!");
|
|
182
|
+
const r = await get(`/api/networks/${net}/env-transport-log`, other.token!);
|
|
183
|
+
expect(r.status).toBe(403);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
// #1510 补档 —— 「未知 transport」必须有名字,而且默认不能被当成「不安全」。
|
|
188
|
+
//
|
|
189
|
+
// 生产数据(2026-10-29 只读):373 个会话里 332 个 env_transport = NULL。
|
|
190
|
+
// 如果 enforce 默认就把 null 拒掉,打开开关当天就会拦掉近九成节点 —— 那不是收紧,
|
|
191
|
+
// 那是一次不在计划内的下线。所以:
|
|
192
|
+
// · 默认(strict 关):null 放行,且不进 would-refuse 表(不制造噪声)
|
|
193
|
+
// · 显式 ANET_SECRET_TRANSPORT_GATE_STRICT=1:null 拒,原因码单独叫
|
|
194
|
+
// secret_transport_unknown —— 运维看到这个码,知道要去做的是「让节点上报」,
|
|
195
|
+
// 而不是去查某台机器的网络链路
|
|
196
|
+
describe("#1510 未知 transport(未上报)", () => {
|
|
197
|
+
const putTo = (nodeId: string, key: string) =>
|
|
198
|
+
post(`/api/nodes/${nodeId}/secrets?network_id=${net}`, ownerToken, { action: "put", key, value: "v", revision: 1 });
|
|
199
|
+
|
|
200
|
+
test("log 模式:未上报的节点不受影响,也不进 would-refuse 表", async () => {
|
|
201
|
+
const before = (await get(`/api/networks/${net}/env-transport-log`, ownerToken)).body.total;
|
|
202
|
+
const r = await putTo(UNKNOWN, "U1_KEY");
|
|
203
|
+
expect(r.status).toBe(200);
|
|
204
|
+
expect(r.body.ok).toBe(true);
|
|
205
|
+
const after = (await get(`/api/networks/${net}/env-transport-log`, ownerToken)).body.total;
|
|
206
|
+
expect(after).toBe(before);
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
test("enforce 但 strict 关:未上报仍然放行(默认不收紧到「未知即拒」)", async () => {
|
|
210
|
+
process.env.ANET_SECRET_TRANSPORT_GATE = "enforce";
|
|
211
|
+
const r = await putTo(UNKNOWN, "U2_KEY");
|
|
212
|
+
expect(r.status).toBe(200);
|
|
213
|
+
expect(r.body.ok).toBe(true);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
test("enforce + strict:未上报被拒,原因码是 secret_transport_unknown(不是 plain)", async () => {
|
|
217
|
+
process.env.ANET_SECRET_TRANSPORT_GATE = "enforce";
|
|
218
|
+
process.env.ANET_SECRET_TRANSPORT_GATE_STRICT = "1";
|
|
219
|
+
const r = await putTo(UNKNOWN, "U3_KEY");
|
|
220
|
+
expect(r.status).toBe(400);
|
|
221
|
+
expect(r.body.error).toBe("secret_transport_unknown");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
test("enforce + strict:明确 plain 的原因码不受影响,仍是 secret_transport_plain", async () => {
|
|
225
|
+
process.env.ANET_SECRET_TRANSPORT_GATE = "enforce";
|
|
226
|
+
process.env.ANET_SECRET_TRANSPORT_GATE_STRICT = "1";
|
|
227
|
+
const r = await putTo(PLAIN, "U4_KEY");
|
|
228
|
+
expect(r.status).toBe(400);
|
|
229
|
+
expect(r.body.error).toBe("secret_transport_plain");
|
|
230
|
+
});
|
|
231
|
+
|
|
232
|
+
test("enforce + strict:loopback / https 仍然放行(收紧不能倒向坏另一边)", async () => {
|
|
233
|
+
process.env.ANET_SECRET_TRANSPORT_GATE = "enforce";
|
|
234
|
+
process.env.ANET_SECRET_TRANSPORT_GATE_STRICT = "1";
|
|
235
|
+
for (const [node, key] of [[LOOPBACK, "U5_KEY"], [TLS, "U6_KEY"]] as const) {
|
|
236
|
+
const r = await putTo(node, key);
|
|
237
|
+
expect(r.body.ok).toBe(true);
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// #1510 (log-only) — record the secret writes that a future transport gate would
|
|
2
|
+
// have refused, without refusing any of them.
|
|
3
|
+
//
|
|
4
|
+
// Why log-only first: refusing makes an existing workflow fail on upgrade, and
|
|
5
|
+
// the nodes that talk plain HTTP today are exactly the ones we cannot see from
|
|
6
|
+
// the Hub. This table answers "how many writes would have been blocked, on which
|
|
7
|
+
// node" *before* anyone decides to turn the gate on — the same rollout shape as
|
|
8
|
+
// #519's stale-open sweep and #525's human_only log mode.
|
|
9
|
+
//
|
|
10
|
+
// Hourly aggregation, like node_permission_log: a chatty node must not turn this
|
|
11
|
+
// into one row per write.
|
|
12
|
+
import { db } from "./db.js";
|
|
13
|
+
import { getEnvTransportMode, secretTransportVerdict } from "./env-transport-policy.js";
|
|
14
|
+
|
|
15
|
+
const HOURS_RETAINED = 30 * 24;
|
|
16
|
+
const MAX_ROWS = 20_000;
|
|
17
|
+
|
|
18
|
+
function hourOf(now = new Date()): string {
|
|
19
|
+
return now.toISOString().slice(0, 13);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Record one would-refuse hit. Never throws: logging must not break a write. */
|
|
23
|
+
export function noteEnvTransportWouldRefuse(networkId: string, nodeId: string, route: string, sample?: string): void {
|
|
24
|
+
try {
|
|
25
|
+
const now = new Date();
|
|
26
|
+
if (Math.random() < 0.02) {
|
|
27
|
+
db.run("DELETE FROM env_transport_would_refuse WHERE hour < ?1",
|
|
28
|
+
[hourOf(new Date(now.getTime() - HOURS_RETAINED * 86_400_000))]);
|
|
29
|
+
}
|
|
30
|
+
const count = Number(db.get<{ n: number | string }>("SELECT COUNT(*) AS n FROM env_transport_would_refuse")?.n ?? 0);
|
|
31
|
+
const hour = hourOf(now);
|
|
32
|
+
const s = sample ? sample.slice(0, 120) : null;
|
|
33
|
+
if (count >= MAX_ROWS) {
|
|
34
|
+
db.run(
|
|
35
|
+
"UPDATE env_transport_would_refuse SET hits = hits + 1, sample = COALESCE(sample, ?5) WHERE network_id = ?1 AND node_id = ?2 AND route = ?3 AND hour = ?4",
|
|
36
|
+
[networkId, nodeId, route, hour, s],
|
|
37
|
+
);
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
db.run(
|
|
41
|
+
`INSERT INTO env_transport_would_refuse (network_id, node_id, route, hour, hits, sample) VALUES (?1, ?2, ?3, ?4, 1, ?5)
|
|
42
|
+
ON CONFLICT(network_id, node_id, route, hour) DO UPDATE SET hits = env_transport_would_refuse.hits + 1`,
|
|
43
|
+
[networkId, nodeId, route, hour, s],
|
|
44
|
+
);
|
|
45
|
+
} catch (e) {
|
|
46
|
+
console.error(`[env-transport] would-refuse log failed: ${(e as Error).message}`);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Where a secret write is aimed: the node's own row, or a daemon's. Returns the
|
|
51
|
+
* transport the node last reported, or null when it is unknown. */
|
|
52
|
+
export function transportOf(networkId: string, nodeId: string): string | null {
|
|
53
|
+
const row = db.get<{ env_transport: string | null }>(
|
|
54
|
+
"SELECT env_transport FROM sessions WHERE network_id = ?1 AND (node_id = ?2 OR alias = ?2) ORDER BY updated_at DESC LIMIT 1",
|
|
55
|
+
[networkId, nodeId],
|
|
56
|
+
);
|
|
57
|
+
return row?.env_transport ?? null;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Called from the write lanes. Logs when the current policy would refuse.
|
|
61
|
+
*
|
|
62
|
+
* #1510 补丁:以前这里写死了「只有 plain 才记」,于是日得表**永远只反映一种原因**。
|
|
63
|
+
* 现在改成问 `secretTransportVerdict`(把模式仮定为 enforce):
|
|
64
|
+
* 「如果现在打开 enforce,这一笔会不会被拒、原因是什么」—— 表格才是决策输入。
|
|
65
|
+
* 默认 strict 关闭时结果与以前完全一致(只记 plain)。 */
|
|
66
|
+
export function observeSecretWrite(networkId: string, nodeId: string, route: string): void {
|
|
67
|
+
if (getEnvTransportMode() !== "log") return;
|
|
68
|
+
const transport = transportOf(networkId, nodeId);
|
|
69
|
+
const would = secretTransportVerdict(transport, { ...process.env, ANET_SECRET_TRANSPORT_GATE: "enforce" });
|
|
70
|
+
if (!would) return;
|
|
71
|
+
noteEnvTransportWouldRefuse(networkId, nodeId, route, `${would} transport=${transport ?? "unknown"}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function readEnvTransportLog(networkId: string, sinceHour: string) {
|
|
75
|
+
return db.all<{ node_id: string; route: string; hour: string; hits: number | string; sample: string | null }>(
|
|
76
|
+
`SELECT node_id, route, hour, hits, sample FROM env_transport_would_refuse
|
|
77
|
+
WHERE network_id = ?1 AND hour >= ?2 ORDER BY hour DESC, node_id, route`,
|
|
78
|
+
[networkId, sinceHour],
|
|
79
|
+
).map(r => ({ ...r, hits: Number(r.hits) }));
|
|
80
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// #1510 — the switch for the secret-transport gate.
|
|
2
|
+
//
|
|
3
|
+
// (unset) / "log" — record what a gate WOULD refuse; refuse nothing.
|
|
4
|
+
// "enforce" — refuse secret writes to nodes that report `plain`.
|
|
5
|
+
// "off" — do nothing at all (no recording either).
|
|
6
|
+
//
|
|
7
|
+
// Reading the env on every call (like the stale-open sweep) means an operator can
|
|
8
|
+
// change the mode without a code change and tests can flip it per case.
|
|
9
|
+
export type EnvTransportMode = "off" | "log" | "enforce";
|
|
10
|
+
|
|
11
|
+
export function getEnvTransportMode(env: Record<string, string | undefined> = process.env): EnvTransportMode {
|
|
12
|
+
const raw = (env.ANET_SECRET_TRANSPORT_GATE ?? "").trim().toLowerCase();
|
|
13
|
+
if (raw === "off") return "off";
|
|
14
|
+
if (raw === "enforce") return "enforce";
|
|
15
|
+
return "log";
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* #1510(补「未知」这一档)—— enforce 到底拒什么。
|
|
21
|
+
*
|
|
22
|
+
* 原实现是**拒绝名单**:只拒 `plain`,其余(含 `null` = 从未上报)一律放行。
|
|
23
|
+
* 卡里的口径是**允许名单**:「只有 loopback 或 https 才允许把密钥转发给节点」。
|
|
24
|
+
* 两者在 `null` 上分歧最大,而生产现状是(2026-10-29 只读统计,373 个会话):
|
|
25
|
+
*
|
|
26
|
+
* env_transport = NULL 332 ← 89% 从未上报
|
|
27
|
+
* plain 33
|
|
28
|
+
* loopback 7
|
|
29
|
+
* https 1
|
|
30
|
+
*
|
|
31
|
+
* 所以「未知即拒」不能直接当成默认:一打开 enforce 就会拦掉近九成节点。
|
|
32
|
+
* 它必须是一个**额外显式打开**的开关(`ANET_SECRET_TRANSPORT_GATE_STRICT=1`),
|
|
33
|
+
* 让运维在看清「未知有多少」之后自己决定什么时候收紧。
|
|
34
|
+
*
|
|
35
|
+
* 返回值直接就是拒绝原因码,避免调用方各自拼自符串:
|
|
36
|
+
* "secret_transport_plain" — 明确是明文公网
|
|
37
|
+
* "secret_transport_unknown" — 从未上报(仅 strict 下拒)
|
|
38
|
+
* null — 允许
|
|
39
|
+
*/
|
|
40
|
+
export type SecretTransportVerdict = "secret_transport_plain" | "secret_transport_unknown" | null;
|
|
41
|
+
|
|
42
|
+
/** 「未知即拒」的显式开关。默认关。 */
|
|
43
|
+
export function getEnvTransportStrict(env: Record<string, string | undefined> = process.env): boolean {
|
|
44
|
+
const raw = (env.ANET_SECRET_TRANSPORT_GATE_STRICT ?? "").trim().toLowerCase();
|
|
45
|
+
return raw === "1" || raw === "true" || raw === "on" || raw === "yes";
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function secretTransportVerdict(
|
|
49
|
+
transport: string | null,
|
|
50
|
+
env: Record<string, string | undefined> = process.env,
|
|
51
|
+
): SecretTransportVerdict {
|
|
52
|
+
if (getEnvTransportMode(env) !== "enforce") return null;
|
|
53
|
+
if (transport === "plain") return "secret_transport_plain";
|
|
54
|
+
if (transport === "loopback" || transport === "https") return null;
|
|
55
|
+
return getEnvTransportStrict(env) ? "secret_transport_unknown" : null;
|
|
56
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// 2026-10-31 —— ETag 函数的两个方向。
|
|
2
|
+
//
|
|
3
|
+
// 只测「内容变 ⇒ ETag 变」是不够的:那一条挡的是「退化得更松」(按长度、按份数、按前缀)。
|
|
4
|
+
// 还要一条「内容不变 ⇒ ETag 不变」,它挡的是「退化得更严」(改成随机数、加时间戳、加自增)——
|
|
5
|
+
// 后者会让每个响应都「变了」,304 永远不命中,而现象是「客户端还是能收到 200」,没人会报错。
|
|
6
|
+
//
|
|
7
|
+
// ⚠️ 口径(2026-10-31 自查后修正):本文件共 5 条断言,但**独立维度只有 4 个** ——
|
|
8
|
+
// 「只差末位」与「只差首位」同属「内容差」这一维,它们不是两种独立输入。
|
|
9
|
+
// 所以对外只说「4 个维度」,不说「5 种输入」:断言数好数,独立输入数要靠「删掉一个维度是否仍有覆盖」来判。
|
|
10
|
+
//
|
|
11
|
+
// 差异的位置也有讲究:必须有一条把差异放在**最后一个字符**,
|
|
12
|
+
// 因为任何截断式比较(前缀 / 前 N 位 hash)在差异靠后时仍然判等。
|
|
13
|
+
import { describe, expect, test } from "bun:test";
|
|
14
|
+
import { etagOf } from "./status-read-cache.js";
|
|
15
|
+
|
|
16
|
+
describe("etagOf: 两个方向 + 差异位置", () => {
|
|
17
|
+
test("内容不变 ⇒ ETag 不变(纯函数;否则 304 永远不命中)", () => {
|
|
18
|
+
const body = JSON.stringify({ sessions: [{ alias: "a" }], n: 1 });
|
|
19
|
+
expect(etagOf(body)).toBe(etagOf(body));
|
|
20
|
+
// 逐字节相同的两个字符串(构造方式不同)也必须同值
|
|
21
|
+
expect(etagOf("x" + "y")).toBe(etagOf("xy"));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test("只差**最后一个字符** ⇒ ETag 必须不同(挡前缀 / 短 hash 比较)", () => {
|
|
25
|
+
const a = `{"sessions":[{"alias":"node-a"}],"total":10}`;
|
|
26
|
+
const b = `{"sessions":[{"alias":"node-b"}],"total":11}`; // 长度相同、末位不同
|
|
27
|
+
expect(a.length).toBe(b.length);
|
|
28
|
+
expect(a.slice(0, -1)).not.toBe(b.slice(0, -1)); // 中部也有差,先声明
|
|
29
|
+
expect(etagOf(a)).not.toBe(etagOf(b));
|
|
30
|
+
// 更严格的一条:**只有**最后一个字符不同。
|
|
31
|
+
// ⚠️ 我第一版写成 `{"x":"aaaaaaa1"}` vs `{"x":"aaaaaaa2"}` —— 那是倒数第二个字符不同
|
|
32
|
+
// (最后一个是 `}`),而 `slice(0,-1)` 当场把这件事说出来。断言写的是「只差末位」,
|
|
33
|
+
// 样本却不是「只差末位」—— 这类样本错误比断言错误更难发现,因为它照样是绿的。
|
|
34
|
+
const c = "aaaaaaa1";
|
|
35
|
+
const d = "aaaaaaa2";
|
|
36
|
+
expect(c.slice(0, -1)).toBe(d.slice(0, -1));
|
|
37
|
+
expect(etagOf(c)).not.toBe(etagOf(d));
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test("只差第一个字符 ⇒ ETag 也必须不同(方向对称,防「只比后缀」)", () => {
|
|
41
|
+
expect(etagOf("1abcdefg")).not.toBe(etagOf("2abcdefg"));
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("长度写进 ETag 不该让「同长度不同内容」判等", () => {
|
|
45
|
+
const a = "abcdefgh";
|
|
46
|
+
const b = "abcdefgi";
|
|
47
|
+
expect(a.length).toBe(b.length);
|
|
48
|
+
expect(etagOf(a)).not.toBe(etagOf(b));
|
|
49
|
+
// 反向:相同内容、不同长度 ⇒ 必然不同(长度是 ETag 的一部分,这是有意的)
|
|
50
|
+
expect(etagOf("ab")).not.toBe(etagOf("ab "));
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test("形状:带引号的强 ETag(If-None-Match 才能按原样回送)", () => {
|
|
54
|
+
expect(etagOf("{}")).toMatch(/^"s-[0-9a-z]+-[0-9a-z]+"$/);
|
|
55
|
+
expect(etagOf("")).toMatch(/^"s-[0-9a-z]+-0"$/);
|
|
56
|
+
});
|
|
57
|
+
});
|