@sleep2agi/commhub-server 0.9.0-preview.28 → 0.9.0-preview.281
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 +215 -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 +888 -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 +228 -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/all-status-cache.test.ts +31 -0
- package/src/all-status-cache.ts +37 -0
- package/src/anet-variant-real-daemon-http.test.ts +185 -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 +219 -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-sec1.test.ts +37 -0
- package/src/config-apply-validate.test.ts +188 -1
- package/src/config-apply-validate.ts +226 -3
- package/src/contracts/session-project-create.ts +14 -0
- package/src/contracts/session-source-delivery.ts +16 -0
- package/src/contracts/session-source-directory.ts +54 -0
- package/src/contracts/session-source-evidence.ts +72 -0
- package/src/contracts/session-source-execution.ts +24 -0
- package/src/contracts/session-source-transport.ts +18 -0
- 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 +59 -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 +1334 -154
- 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 +1603 -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/launched-by-cli-report-http.test.ts +155 -0
- 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-inbox-allowlist-http.test.ts +320 -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 +126 -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 +627 -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 +398 -0
- package/src/node-session-control.ts +316 -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 +128 -0
- package/src/node-token-usage.ts +228 -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 +282 -0
- package/src/opencode-v2-catalog.ts +357 -0
- package/src/package-self-contained.test.ts +32 -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 +272 -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 +280 -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 +980 -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 +5103 -377
- package/src/session-fork-store.test.ts +43 -0
- package/src/session-fork-store.ts +51 -0
- package/src/session-project-attach-migration.test.ts +23 -0
- package/src/session-project-attach-native.test.ts +123 -0
- package/src/session-project-create-http.test.ts +408 -0
- package/src/session-project-create-native.test.ts +292 -0
- package/src/session-project-create.ts +159 -0
- package/src/session-source-admission-store.ts +58 -0
- package/src/session-source-create.test.ts +155 -0
- package/src/session-source-create.ts +97 -0
- package/src/session-source-delivery.ts +114 -0
- package/src/session-source-directory-http.test.ts +196 -0
- package/src/session-source-evidence.test.ts +905 -0
- package/src/session-source-evidence.ts +191 -0
- package/src/session-source-execution.ts +87 -0
- package/src/session-source-grant.test.ts +117 -0
- package/src/session-source-grant.ts +78 -0
- package/src/session-source-issuer.test.ts +250 -0
- package/src/session-source-issuer.ts +164 -0
- package/src/session-source-transport.ts +381 -0
- 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-node-secrets-capable-http.test.ts +44 -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 +512 -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 +117 -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/test-work-root.ts +18 -0
- package/src/tmux-allowlist.test.ts +48 -0
- package/src/token-usage-http.test.ts +156 -0
- package/src/tool-audience-http.test.ts +266 -0
- package/src/tool-audience.ts +130 -0
- package/src/tools-list-json-schema.test.ts +94 -0
- package/src/tools.ts +4557 -472
- 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,219 @@
|
|
|
1
|
+
// #3294 —— 节点侧的**字节标识**:report_status 收 build_commit ⇒ /api/nodes 投影可见。
|
|
2
|
+
//
|
|
3
|
+
// 为什么不是「加一列就完了」:Hub 的 report_status schema 对**不认识的键是静默丢弃**的
|
|
4
|
+
// (源码里那段 #1545 注释写得很清楚)。所以这条链路必须三处同时成立:
|
|
5
|
+
// ① schema 里有这个键(否则 zod 丢掉)
|
|
6
|
+
// ② 写路径把它落库(否则写不进去)
|
|
7
|
+
// ③ 读路径把它投影出来(否则界面上看不见)
|
|
8
|
+
// 少任何一处,现场表现都是「节点明明发了、hub 上没有」,与 daemon 侧 bug 一模一样。
|
|
9
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
10
|
+
import { existsSync, mkdtempSync, rmSync } from "node:fs";
|
|
11
|
+
import { tmpdir } from "node:os";
|
|
12
|
+
import { join } from "node:path";
|
|
13
|
+
import { register, createNetworkTokenForNode } from "./auth.js";
|
|
14
|
+
import { db } from "./db.js";
|
|
15
|
+
|
|
16
|
+
const DIR = mkdtempSync(join(tmpdir(), "anet-build-commit-"));
|
|
17
|
+
const STAMP = Date.now();
|
|
18
|
+
let BASE = "";
|
|
19
|
+
let hub: any = null;
|
|
20
|
+
let USER = "";
|
|
21
|
+
let NET = "";
|
|
22
|
+
let ntok = "";
|
|
23
|
+
let utok = "";
|
|
24
|
+
let ALIAS = "";
|
|
25
|
+
const PW = "BuildCommitPassw0rd!x";
|
|
26
|
+
const COMMIT = "0123456789abcdef0123456789abcdef01234567"; // 40 hex,固定值便于断言
|
|
27
|
+
|
|
28
|
+
const auth = (t: string) => ({ Authorization: `Bearer ${t}` });
|
|
29
|
+
|
|
30
|
+
async function rpc(method: string, params: any, token = ntok) {
|
|
31
|
+
const res = await fetch(`${BASE}/mcp`, {
|
|
32
|
+
method: "POST",
|
|
33
|
+
headers: { ...auth(token), "Content-Type": "application/json", Accept: "application/json, text/event-stream" },
|
|
34
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name: method, arguments: params } }),
|
|
35
|
+
});
|
|
36
|
+
const raw = await res.text();
|
|
37
|
+
const line = raw.split("\n").find((l) => l.startsWith("data: "));
|
|
38
|
+
const env = JSON.parse(line ? line.slice(6) : raw);
|
|
39
|
+
try { return JSON.parse(env.result.content[0].text); } catch { return { ok: false, raw }; }
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async function nodes(token = ntok) {
|
|
43
|
+
const res = await fetch(`${BASE}/api/nodes?network_id=${NET}`, { headers: auth(token) });
|
|
44
|
+
return (await res.json()) as any;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
beforeAll(async () => {
|
|
48
|
+
process.env.COMMHUB_DB ||= join(DIR, "hub.db");
|
|
49
|
+
process.env.COMMHUB_UPLOADS_DIR = join(DIR, "uploads");
|
|
50
|
+
process.env.HOST = "127.0.0.1";
|
|
51
|
+
USER = `bc_user_${STAMP}`;
|
|
52
|
+
ALIAS = `bc-node-${STAMP}`;
|
|
53
|
+
const reg = register(USER, PW);
|
|
54
|
+
utok = reg.token!;
|
|
55
|
+
NET = reg.network_id!;
|
|
56
|
+
const minted = createNetworkTokenForNode(reg.user!.user_id, NET, ALIAS, `node_bc_${STAMP}`);
|
|
57
|
+
expect(minted.ok).toBe(true);
|
|
58
|
+
ntok = minted.token!;
|
|
59
|
+
const mod: any = await import("./server.js");
|
|
60
|
+
hub = mod.bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
61
|
+
BASE = `http://127.0.0.1:${hub.port}`;
|
|
62
|
+
}, 30_000);
|
|
63
|
+
|
|
64
|
+
afterAll(() => {
|
|
65
|
+
try { hub?.stop?.(true); } catch {}
|
|
66
|
+
try { rmSync(DIR, { recursive: true, force: true }); } catch {}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
function report(extra: Record<string, unknown> = {}) {
|
|
70
|
+
return rpc("report_status", {
|
|
71
|
+
resume_id: `resume_bc_${STAMP}`, alias: ALIAS, status: "idle",
|
|
72
|
+
version: "2.5.0-preview.169", node_id: `node_bc_${STAMP}`, network_id: NET, ...extra,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
describe("#3294 节点上报 build_commit 的三段链路", () => {
|
|
77
|
+
// 顺序是有意的:先没有、再有、再坏。同一行节点,三个阶段各读一次。
|
|
78
|
+
test("① 没报 ⇒ null,且 note 说明「这不是缺陷」", async () => {
|
|
79
|
+
// 老节点不报这个字段;把「没报」与「没有标识」压成同一个 null 会让人去查错方向,
|
|
80
|
+
// 所以投影里同时给一个 note。
|
|
81
|
+
expect((await report()).ok).toBe(true);
|
|
82
|
+
const row = (await nodes()).nodes.find((n: any) => n.alias === ALIAS);
|
|
83
|
+
expect(row).toBeDefined();
|
|
84
|
+
expect(row.build_commit).toBeNull();
|
|
85
|
+
expect(typeof row.build_note).toBe("string");
|
|
86
|
+
expect(row.build_note).toContain("没有上报");
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test("② 🔴 报了 ⇒ 落库 ⇒ /api/nodes 投影里读得到,且与 version 是两个东西", async () => {
|
|
90
|
+
expect((await report({ build_commit: COMMIT })).ok).toBe(true);
|
|
91
|
+
const row = (await nodes()).nodes.find((n: any) => n.alias === ALIAS);
|
|
92
|
+
expect(row.build_commit).toBe(COMMIT);
|
|
93
|
+
// ⚠️ `/api/nodes` 的投影里**没有** version 这一列(实测:拿到的 row.version 是 undefined)。
|
|
94
|
+
// 所以「两个东西」这句不能靠对比 row.version 来断言 —— 那会变成在测一个不存在的字段。
|
|
95
|
+
// 用上报时的字面量比:字节标识不可能是版本标签。
|
|
96
|
+
expect(row.build_commit).not.toBe("2.5.0-preview.169");
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("③ 形状不对的 build_commit 被 schema 拒(不是静默丢弃)", async () => {
|
|
100
|
+
// 与「静默丢弃」相反的那一半:**已知键但值不合规**必须报错,
|
|
101
|
+
// 否则「发了个坏值」会和「没发」同形。
|
|
102
|
+
const r = await report({ resume_id: `resume_bc3_${STAMP}`, build_commit: "NOT-HEX" });
|
|
103
|
+
expect(r.ok).toBeFalsy();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
// #3144 —— 与 build_commit 同一个坑:**schema 里没有的键会被 zod 静默丢掉**。
|
|
108
|
+
// 所以「/api/nodes 能读到 opencode_catalog_seen_at」必须走一次真实的
|
|
109
|
+
// report_status → 落库 → 投影,而不是读一个镜像映射(镜像永远不会红)。
|
|
110
|
+
describe("#3144 opencode_catalog_seen_at 的三段链路(真 HTTP)", () => {
|
|
111
|
+
test("报了两个字段 ⇒ 投影里都读得到", async () => {
|
|
112
|
+
expect((await report({
|
|
113
|
+
config_snapshot: {
|
|
114
|
+
opencode_catalog: ["openai/gpt-6.1-terra", "kimi-code-plan-cn/k3.1-pro"],
|
|
115
|
+
opencode_catalog_seen_at: "2026-11-01T02:00:00Z",
|
|
116
|
+
},
|
|
117
|
+
})).ok).toBe(true);
|
|
118
|
+
const row = (await nodes()).nodes.find((n: any) => n.alias === ALIAS);
|
|
119
|
+
expect(row.opencode_catalog).toEqual(["openai/gpt-6.1-terra", "kimi-code-plan-cn/k3.1-pro"]);
|
|
120
|
+
expect(row.opencode_catalog_seen_at).toBe("2026-11-01T02:00:00Z");
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test("只报目录、不报时刻 ⇒ 时刻是 null(不是空串、不是当前时间)", async () => {
|
|
124
|
+
expect((await report({ config_snapshot: { opencode_catalog: ["a/b"] } })).ok).toBe(true);
|
|
125
|
+
const row = (await nodes()).nodes.find((n: any) => n.alias === ALIAS);
|
|
126
|
+
expect(row.opencode_catalog).toEqual(["a/b"]);
|
|
127
|
+
expect(row.opencode_catalog_seen_at).toBeNull();
|
|
128
|
+
expect(row.opencode_catalog_seen_at).not.toBe("");
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
test("variant capability survives authenticated report_status schema and storage", async () => {
|
|
133
|
+
expect((await report({ config_snapshot: { opencode_variant_config_capable: true, model_effective: "fixture/model", modelVariant: "high" } })).ok).toBe(true);
|
|
134
|
+
const row = db.get<{ config_snapshot: string }>("SELECT config_snapshot FROM nodes WHERE node_id = ?1", `node_bc_${STAMP}`);
|
|
135
|
+
expect(JSON.parse(row!.config_snapshot).opencode_variant_config_capable).toBe(true);
|
|
136
|
+
expect(JSON.parse(row!.config_snapshot)).toMatchObject({ model_effective: "fixture/model", modelVariant: "high" });
|
|
137
|
+
const configResponse = await fetch(`${BASE}/api/nodes/node_bc_${STAMP}/config?network_id=${NET}`, { headers: auth(ntok) });
|
|
138
|
+
expect(configResponse.status).toBe(200);
|
|
139
|
+
expect(await configResponse.json()).toMatchObject({ model_effective: "fixture/model", modelVariant: "high", opencode_variant_config_capable: true });
|
|
140
|
+
expect((await report({ config_snapshot: { opencode_variant_config_capable: "true" } })).ok).toBe(true);
|
|
141
|
+
const bad = db.get<{ config_snapshot: string }>("SELECT config_snapshot FROM nodes WHERE node_id = ?1", `node_bc_${STAMP}`);
|
|
142
|
+
expect(JSON.parse(bad!.config_snapshot).opencode_variant_config_capable).toBeUndefined();
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
test("variant-capable model update persists private ack policy across lost capability", async () => {
|
|
146
|
+
const nodeId = `node_bc_${STAMP}`;
|
|
147
|
+
expect((await report({ config_snapshot: { model: "fixture/model", opencode_variant_config_capable: true, flags: { opencodeGeneration: "v2", opencodeMode: "copresence" } } })).ok).toBe(true);
|
|
148
|
+
db.run("UPDATE nodes SET runtime = ?1 WHERE node_id = ?2", ["opencode", nodeId]);
|
|
149
|
+
const queued = await rpc("update_node_config", { node_id: nodeId, base_revision: 0, patch: { model: "fixture/model" } }, utok);
|
|
150
|
+
expect(queued.ok).toBe(true);
|
|
151
|
+
expect(JSON.parse(db.get<any>("SELECT patch_json FROM node_config_updates WHERE update_id = ?1", queued.update_id).patch_json)._anet_variant_ack_required).toBe(true);
|
|
152
|
+
const pulled = await rpc("get_config_update", {});
|
|
153
|
+
expect(pulled.update.patch._anet_variant_ack_required).toBeUndefined();
|
|
154
|
+
expect((await report({ config_snapshot: { model: "fixture/model", flags: {} } })).ok).toBe(true);
|
|
155
|
+
expect(db.get<any>("SELECT status FROM node_config_updates WHERE update_id = ?1", queued.update_id).status).toBe("pending");
|
|
156
|
+
expect((await rpc("ack_config_update", { update_id: queued.update_id, status: "rejected", error: "test_complete" })).ok).toBe(true);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
// Needs the TEST-ONLY OpenCode build at /tool/opencode (only in the V2 test image).
|
|
160
|
+
test.skipIf(!existsSync("/tool/opencode"))("TEST-ONLY real Hub HTTP and owned runtime variant via explicit node dispatch", async () => {
|
|
161
|
+
const { openVettedOpenCodeCopresence } = await import("../../agent-node/src/runtime/opencode-copresence/runtime.js");
|
|
162
|
+
const { OPENCODE_V2_BACKEND } = await import("../../agent-node/src/runtime/opencode-backend.js");
|
|
163
|
+
const { applyVariantConfig } = await import("../../agent-node/src/runtime/opencode-copresence/variant-config-apply.js");
|
|
164
|
+
const { readOpenCodeV2CatalogEndpoint } = await import("../../agent-node/src/runtime/opencode-v2-catalog-endpoint.js");
|
|
165
|
+
const root = mkdtempSync(join(tmpdir(), "anet-hub-variant-"));
|
|
166
|
+
const config = { model: "fixture/model", enabled_providers: ["fixture"], provider: { fixture: {
|
|
167
|
+
name: "fixture", npm: "@ai-sdk/openai-compatible", options: { baseURL: "http://127.0.0.1:1/v1", apiKey: "synthetic" },
|
|
168
|
+
models: { model: { name: "model", limit: { context: 128000, output: 16000 }, variants: { high: {}, low: {} } } },
|
|
169
|
+
} } };
|
|
170
|
+
const noTmux = () => { throw Error("unexpected tmux"); };
|
|
171
|
+
const session = await openVettedOpenCodeCopresence({ backend: OPENCODE_V2_BACKEND, binary: "/tool/opencode", cwd: root, workDir: root,
|
|
172
|
+
env: { PATH: process.env.PATH, HOME: root, XDG_CONFIG_HOME: join(root, "config"), XDG_DATA_HOME: join(root, "data"), XDG_CACHE_HOME: join(root, "cache"), XDG_STATE_HOME: join(root, "state"), ANET_VARIANT_TEST_ONLY: "1", OPENCODE_CONFIG_CONTENT: JSON.stringify(config) },
|
|
173
|
+
model: "fixture/model", startupTimeoutMs: 20000, tmuxRunner: noTmux, tmuxRespawn: noTmux });
|
|
174
|
+
try {
|
|
175
|
+
expect(session.variantConfigCapable).toBe(true);
|
|
176
|
+
const endpoint = readOpenCodeV2CatalogEndpoint(root)!;
|
|
177
|
+
let ready = false;
|
|
178
|
+
for (let i = 0; i < 60 && !ready; i++) {
|
|
179
|
+
const r = await fetch(`${endpoint.url}/api/model`, { headers: { authorization: endpoint.authorization, "x-opencode-directory": endpoint.directory } });
|
|
180
|
+
const body = await r.json() as any;
|
|
181
|
+
ready = body.location?.directory === root && body.data?.some((row: any) => row.providerID === "fixture" && row.id === "model" && row.variants?.some((v: any) => v.id === "high"));
|
|
182
|
+
}
|
|
183
|
+
expect(ready).toBe(true);
|
|
184
|
+
expect(await session.variantConfigReadback!()).toMatchObject({ providerID: "fixture", id: "model" });
|
|
185
|
+
expect((await report({ config_snapshot: { opencode_variant_config_capable: true, model: "fixture/model" } })).ok).toBe(true);
|
|
186
|
+
const nodeId = `node_bc_${STAMP}`;
|
|
187
|
+
const queued = await rpc("update_node_config", { node_id: nodeId, base_revision: 0, patch: { modelVariant: "high" } }, utok);
|
|
188
|
+
expect(queued.ok).toBe(true);
|
|
189
|
+
const pulled = await rpc("get_config_update", {});
|
|
190
|
+
expect(pulled.update).toMatchObject({ update_id: queued.update_id, patch: { modelVariant: "high" }, apply_mode: "hot" });
|
|
191
|
+
const applied = await applyVariantConfig(session, pulled.update.patch);
|
|
192
|
+
expect(applied).toMatchObject({ status: "applied", model: { providerID: "fixture", id: "model", variant: "high" } });
|
|
193
|
+
// A matching heartbeat must not finalize the pending write.
|
|
194
|
+
const observed = await session.variantConfigReadback!();
|
|
195
|
+
expect(observed).toMatchObject({ providerID: "fixture", id: "model", variant: "high" });
|
|
196
|
+
expect((await report({ config_snapshot: { opencode_variant_config_capable: true, model_effective: `${observed!.providerID}/${observed!.id}`, modelVariant: observed!.variant } })).ok).toBe(true);
|
|
197
|
+
expect(db.get<any>("SELECT status FROM node_config_updates WHERE update_id = ?1", queued.update_id)?.status).toBe("pending");
|
|
198
|
+
expect((await rpc("ack_config_update", { update_id: queued.update_id, status: "applied", new_revision: 1 })).ok).toBe(true);
|
|
199
|
+
const read = await fetch(`${BASE}/api/nodes/${nodeId}/config?network_id=${NET}`, { headers: auth(utok) });
|
|
200
|
+
expect(await read.json()).toMatchObject({ model_effective: "fixture/model", modelVariant: "high", last_update: { status: "applied" } });
|
|
201
|
+
const invalid = await rpc("update_node_config", { node_id: nodeId, base_revision: 1, patch: { modelVariant: "not-listed" } }, utok);
|
|
202
|
+
expect(invalid.ok).toBe(true);
|
|
203
|
+
const invalidPull = await rpc("get_config_update", {});
|
|
204
|
+
expect(await applyVariantConfig(session, invalidPull.update.patch)).toEqual({ status: "rejected", reason: "catalog" });
|
|
205
|
+
expect(await session.selectedSessionModel!(session.sessionId)).toMatchObject({ variant: "high" });
|
|
206
|
+
expect((await rpc("ack_config_update", { update_id: invalid.update_id, status: "rejected", error: "variant_catalog" })).ok).toBe(true);
|
|
207
|
+
const clear = await rpc("update_node_config", { node_id: nodeId, base_revision: 1, patch: { modelVariant: null } }, utok);
|
|
208
|
+
expect(clear.ok).toBe(true);
|
|
209
|
+
const clearPull = await rpc("get_config_update", {});
|
|
210
|
+
expect(clearPull.update.patch).toMatchObject({ modelVariant: null });
|
|
211
|
+
expect(await applyVariantConfig(session, clearPull.update.patch)).toMatchObject({ status: "applied", model: { providerID: "fixture", id: "model", variant: "default" } });
|
|
212
|
+
expect((await rpc("ack_config_update", { update_id: clear.update_id, status: "applied", new_revision: 2 })).ok).toBe(true);
|
|
213
|
+
const actual = await session.variantConfigReadback!();
|
|
214
|
+
expect(actual).toMatchObject({ providerID: "fixture", id: "model", variant: "default" });
|
|
215
|
+
expect((await report({ config_snapshot: { opencode_variant_config_capable: true, model_effective: `${actual!.providerID}/${actual!.id}`, modelVariant: actual!.variant === "default" ? null : actual!.variant } })).ok).toBe(true);
|
|
216
|
+
const clearRead = await fetch(`${BASE}/api/nodes/${nodeId}/config?network_id=${NET}`, { headers: auth(utok) });
|
|
217
|
+
expect(await clearRead.json()).toMatchObject({ model_effective: "fixture/model", modelVariant: null, last_update: { status: "applied" } });
|
|
218
|
+
} finally { await session.close(); }
|
|
219
|
+
}, 40000);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// #3177 —— 构建期注入的构建标识:**读取三态**(present / absent / invalid)。
|
|
2
|
+
//
|
|
3
|
+
// 为什么这三态必须分开(这是本文件存在的理由):
|
|
4
|
+
// 部署形态(npm install 出来的 runtime)里没有 .git ⇒ 运行期 git rev-parse 拿不到东西 ⇒
|
|
5
|
+
// 生产 /health 的 build_identified 恒为 false(实测:部署 .246 之后仍为 false)。
|
|
6
|
+
// 于是「注入写坏了」与「还没注入」会读成同一个东西 —— 而后者是正常状态、前者是缺陷。
|
|
7
|
+
// ⇒ absent 是正常的;invalid 必须能被单独看见。
|
|
8
|
+
import { describe, expect, test } from "bun:test";
|
|
9
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { BUILD_INFO_FILE, readBuildInfo, validateBuildInfo } from "./build-info";
|
|
13
|
+
|
|
14
|
+
const SHA = "a".repeat(40);
|
|
15
|
+
const GOOD = { schema: 1, commit: SHA, dirty: false, built_at: "2026-10-31T17:00:00Z" };
|
|
16
|
+
|
|
17
|
+
function inTemp(fn: (dir: string) => void): void {
|
|
18
|
+
const dir = mkdtempSync(join(tmpdir(), "build-info-"));
|
|
19
|
+
try { fn(dir); } finally { rmSync(dir, { recursive: true, force: true }); }
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe("#3177 build-info 读取", () => {
|
|
23
|
+
test("absent:目录里没有文件 —— 这是**正常状态**(部署形态没注入),不是缺陷", () => {
|
|
24
|
+
inTemp((dir) => expect(readBuildInfo(dir)).toEqual({ kind: "absent" }));
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("present:格式正确就原样读出(含可选 source)", () => {
|
|
28
|
+
inTemp((dir) => {
|
|
29
|
+
writeFileSync(join(dir, BUILD_INFO_FILE), JSON.stringify({ ...GOOD, source: "release.yml" }));
|
|
30
|
+
expect(readBuildInfo(dir)).toEqual({ kind: "present", info: { ...GOOD, source: "release.yml" } });
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("invalid:文件在但形状不对 ⇒ 与 absent **分开报**", () => {
|
|
35
|
+
inTemp((dir) => {
|
|
36
|
+
writeFileSync(join(dir, BUILD_INFO_FILE), "{ not json");
|
|
37
|
+
expect(readBuildInfo(dir)).toEqual({ kind: "invalid", error: "invalid_json" });
|
|
38
|
+
writeFileSync(join(dir, BUILD_INFO_FILE), JSON.stringify({ ...GOOD, commit: "short" }));
|
|
39
|
+
expect(readBuildInfo(dir)).toEqual({ kind: "invalid", error: "invalid_shape" });
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test("严格校验:这几个都不接受(每一个都是真实会写错的形态)", () => {
|
|
44
|
+
expect(validateBuildInfo(null)).toBeNull();
|
|
45
|
+
expect(validateBuildInfo([])).toBeNull();
|
|
46
|
+
expect(validateBuildInfo({ ...GOOD, schema: "1" })).toBeNull(); // 字符串 schema
|
|
47
|
+
expect(validateBuildInfo({ ...GOOD, commit: "A".repeat(40) })).toBeNull(); // 大写 hex
|
|
48
|
+
expect(validateBuildInfo({ ...GOOD, commit: "a".repeat(39) })).toBeNull();
|
|
49
|
+
expect(validateBuildInfo({ ...GOOD, dirty: "false" })).toBeNull(); // 字符串布尔
|
|
50
|
+
expect(validateBuildInfo({ ...GOOD, built_at: "2026-10-31 17:00:00" })).toBeNull(); // 非 ISO-Z
|
|
51
|
+
expect(validateBuildInfo({ ...GOOD, built_at: "yesterday" })).toBeNull();
|
|
52
|
+
expect(validateBuildInfo({ ...GOOD, source: 42 })).toBeNull();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("脏树可以注入,但读数里必须看得见 dirty —— 否则「脏树构建」会被当成提交", () => {
|
|
56
|
+
const dirty = validateBuildInfo({ ...GOOD, dirty: true });
|
|
57
|
+
expect(dirty?.dirty).toBe(true);
|
|
58
|
+
expect(dirty?.commit).toBe(SHA);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 2026-10-31 —— **构建期注入的构建标识**(#3177)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么需要它:`detectBootGitIdentity()` 是**运行期** `git rev-parse` 从 module_dir 向上找 `.git`。
|
|
5
|
+
* 而生产的部署形态是 `npm install --prefix ~/.commhub/runtime-…` 的产物 —— **没有 .git**。
|
|
6
|
+
* 实测(部署 .246 之后):`/health` 的 `build_identified = false`。
|
|
7
|
+
* ⇒ 同一版本号、不同字节,在生产上**无法分辨**;而 runtime 读 git 这条路在部署形态上不存在。
|
|
8
|
+
*
|
|
9
|
+
* 所以标识必须由**构建时**写下来,运行期只负责读,并且**读不到要能与「没有标识」区分**。
|
|
10
|
+
*
|
|
11
|
+
* 本模块只做读取与**严格校验**:形状不对就返回 null,绝不猜、绝不抛。
|
|
12
|
+
* 判据:一个坏掉的 build-info.json 与「没有这个文件」是两件事,
|
|
13
|
+
* 但两者都不能变成「看起来有标识」—— 所以校验失败一律 null,由调用方的 reason 去说明。
|
|
14
|
+
*/
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
import { join } from "node:path";
|
|
17
|
+
|
|
18
|
+
export type BuildInfo = {
|
|
19
|
+
schema: 1;
|
|
20
|
+
/** 40 位小写十六进制;构建时的 HEAD。 */
|
|
21
|
+
commit: string;
|
|
22
|
+
/** 构建时工作树是否脏。脏的 commit 只能当「自称」用。 */
|
|
23
|
+
dirty: boolean;
|
|
24
|
+
/** 构建时刻(ISO 8601,UTC)。 */
|
|
25
|
+
built_at: string;
|
|
26
|
+
/** 可选:谁写的(例如 "release.yml")。仅用于人读。 */
|
|
27
|
+
source?: string;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export const BUILD_INFO_FILE = "build-info.json";
|
|
31
|
+
|
|
32
|
+
const SHA40 = /^[0-9a-f]{40}$/;
|
|
33
|
+
|
|
34
|
+
function isIsoUtc(s: unknown): s is string {
|
|
35
|
+
if (typeof s !== "string" || s.length < 20) return false;
|
|
36
|
+
const ms = Date.parse(s);
|
|
37
|
+
return Number.isFinite(ms) && /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/.test(s);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** 校验一份 build-info 载荷;形状不对返回 null(不抛)。 */
|
|
41
|
+
export function validateBuildInfo(raw: unknown): BuildInfo | null {
|
|
42
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
43
|
+
const o = raw as Record<string, unknown>;
|
|
44
|
+
if (o.schema !== 1) return null;
|
|
45
|
+
if (typeof o.commit !== "string" || !SHA40.test(o.commit)) return null;
|
|
46
|
+
if (typeof o.dirty !== "boolean") return null;
|
|
47
|
+
if (!isIsoUtc(o.built_at)) return null;
|
|
48
|
+
if (o.source !== undefined && typeof o.source !== "string") return null;
|
|
49
|
+
const out: BuildInfo = { schema: 1, commit: o.commit, dirty: o.dirty, built_at: o.built_at };
|
|
50
|
+
if (typeof o.source === "string") out.source = o.source;
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 从某个目录读 build-info.json。
|
|
56
|
+
*
|
|
57
|
+
* 返回**两态**而不是一态:
|
|
58
|
+
* `{ kind: "present", info }` —— 读到且通过校验
|
|
59
|
+
* `{ kind: "absent" }` —— 文件不存在(部署形态没注入)
|
|
60
|
+
* `{ kind: "invalid", error }` —— 文件在但形状不对(这是**缺陷**,不是「没有」)
|
|
61
|
+
* 第三种必须与第二种分开:否则「注入写坏了」会读成「还没注入」,而后者是正常状态。
|
|
62
|
+
*/
|
|
63
|
+
export type BuildInfoRead =
|
|
64
|
+
| { kind: "present"; info: BuildInfo }
|
|
65
|
+
| { kind: "absent" }
|
|
66
|
+
| { kind: "invalid"; error: string };
|
|
67
|
+
|
|
68
|
+
export function readBuildInfo(dir: string): BuildInfoRead {
|
|
69
|
+
const path = join(dir, BUILD_INFO_FILE);
|
|
70
|
+
let text: string;
|
|
71
|
+
try {
|
|
72
|
+
text = readFileSync(path, "utf8");
|
|
73
|
+
} catch (e: any) {
|
|
74
|
+
if (e && (e.code === "ENOENT" || e.code === "ENOTDIR")) return { kind: "absent" };
|
|
75
|
+
return { kind: "invalid", error: `unreadable:${e?.code ?? "unknown"}` };
|
|
76
|
+
}
|
|
77
|
+
let parsed: unknown;
|
|
78
|
+
try {
|
|
79
|
+
parsed = JSON.parse(text);
|
|
80
|
+
} catch {
|
|
81
|
+
return { kind: "invalid", error: "invalid_json" };
|
|
82
|
+
}
|
|
83
|
+
const info = validateBuildInfo(parsed);
|
|
84
|
+
return info ? { kind: "present", info } : { kind: "invalid", error: "invalid_shape" };
|
|
85
|
+
}
|