@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,282 @@
|
|
|
1
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import "./require-explicit-test-db.js";
|
|
3
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join, resolve } from "node:path";
|
|
6
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
7
|
+
import { db } from "./db.js";
|
|
8
|
+
import { registerTools } from "./tools.js";
|
|
9
|
+
import {
|
|
10
|
+
ackOpenCodeCatalog,
|
|
11
|
+
expireOpenCodeCatalogForTest,
|
|
12
|
+
getOpenCodeCatalogResult,
|
|
13
|
+
queueOpenCodeCatalogRead,
|
|
14
|
+
resetOpenCodeCatalogForTest,
|
|
15
|
+
takeOpenCodeCatalogRequest,
|
|
16
|
+
} from "./opencode-v2-catalog.js";
|
|
17
|
+
import { readOwnedOpenCodeV2Catalog } from "../../agent-node/src/runtime/opencode-v2-catalog-daemon.ts";
|
|
18
|
+
import { readOpenCodeV2CatalogEndpoint, writeOpenCodeV2CatalogEndpoint } from "../../agent-node/src/runtime/opencode-v2-catalog-endpoint.ts";
|
|
19
|
+
|
|
20
|
+
const NET = "net_oc_catalog";
|
|
21
|
+
const OTHER = "net_oc_catalog_other";
|
|
22
|
+
const USER = "u_oc_catalog";
|
|
23
|
+
const VIEWER = "u_oc_catalog_viewer";
|
|
24
|
+
const OUTSIDER = "u_oc_catalog_out";
|
|
25
|
+
const DAEMON = "node_oc_daemon";
|
|
26
|
+
const DAEMON_ALIAS = "oc-daemon";
|
|
27
|
+
const DAEMON_TOK = "tok_oc_daemon";
|
|
28
|
+
const V2_REQ = "cr_ocv2child";
|
|
29
|
+
const V2 = "node_ocv2child";
|
|
30
|
+
const V1 = "node_ocv1child";
|
|
31
|
+
const UNSAFE = "node_ocunsafechild";
|
|
32
|
+
const NULLDIR = "node_ocnullchild";
|
|
33
|
+
const PROJECT = resolve(mkdtempSync(join(tmpdir(), "oc-hub-proj-")));
|
|
34
|
+
|
|
35
|
+
function cleanup() {
|
|
36
|
+
resetOpenCodeCatalogForTest();
|
|
37
|
+
for (const net of [NET, OTHER]) {
|
|
38
|
+
for (const table of ["node_create_requests", "audit_log", "nodes", "sessions", "api_tokens", "network_members"]) {
|
|
39
|
+
try { db.run(`DELETE FROM ${table} WHERE network_id = ?1`, [net]); } catch {}
|
|
40
|
+
}
|
|
41
|
+
try { db.run("DELETE FROM networks WHERE network_id = ?1", [net]); } catch {}
|
|
42
|
+
}
|
|
43
|
+
for (const user of [USER, VIEWER, OUTSIDER]) {
|
|
44
|
+
try { db.run("DELETE FROM users WHERE user_id = ?1", [user]); } catch {}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
beforeEach(cleanup);
|
|
48
|
+
afterAll(() => { cleanup(); rmSync(PROJECT, { recursive: true, force: true }); });
|
|
49
|
+
|
|
50
|
+
function userRow(id: string) {
|
|
51
|
+
db.run(`INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?1, 'x', 'user', datetime('now'))`, [id]);
|
|
52
|
+
}
|
|
53
|
+
function member(id: string, net: string, role: string) {
|
|
54
|
+
db.run(`INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, ?3, datetime('now'))`, [id, net, role]);
|
|
55
|
+
}
|
|
56
|
+
function node(id: string, alias: string, snapshot: unknown) {
|
|
57
|
+
db.run(
|
|
58
|
+
`INSERT INTO nodes (node_id, node_name, alias, network_id, config_snapshot, hostname, created_at, updated_at, lifecycle_state)
|
|
59
|
+
VALUES (?1, ?2, ?2, ?3, ?4, 'host-x', datetime('now'), datetime('now'), 'active')`,
|
|
60
|
+
[id, alias, NET, JSON.stringify(snapshot)],
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
function created(requestId: string, nodeId: string, flags: unknown, workdir: string | null) {
|
|
64
|
+
node(nodeId, nodeId, {});
|
|
65
|
+
db.run(
|
|
66
|
+
`INSERT INTO node_create_requests
|
|
67
|
+
(request_id, daemon_node_id, child_name, network_id, runtime, model, flags_json, env_keys, status, created_at, created_by_token, workdir)
|
|
68
|
+
VALUES (?1, ?2, ?3, ?4, 'opencode-cli', 'fixture/fixture-model', ?5, '[]', 'succeeded', ?6, 'tok', ?7)`,
|
|
69
|
+
[requestId, DAEMON, nodeId, NET, JSON.stringify(flags), Date.now(), workdir],
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function seed() {
|
|
74
|
+
userRow(USER); userRow(VIEWER); userRow(OUTSIDER);
|
|
75
|
+
db.run(`INSERT OR REPLACE INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?1, ?2, datetime('now'))`, [NET, USER]);
|
|
76
|
+
db.run(`INSERT OR REPLACE INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?1, ?2, datetime('now'))`, [OTHER, OUTSIDER]);
|
|
77
|
+
member(USER, NET, "admin");
|
|
78
|
+
member(VIEWER, NET, "viewer");
|
|
79
|
+
member(OUTSIDER, OTHER, "admin");
|
|
80
|
+
node(DAEMON, DAEMON_ALIAS, { role: "host_supervisor" });
|
|
81
|
+
db.run(
|
|
82
|
+
`INSERT INTO api_tokens (token_id, user_id, network_id, scope, name, token_hash, expires_at, revoked_at)
|
|
83
|
+
VALUES (?1, ?2, ?3, 'network', ?4, ?5, NULL, NULL)`,
|
|
84
|
+
[DAEMON_TOK, USER, NET, `node:${DAEMON_ALIAS}`, `hash_${DAEMON_TOK}`],
|
|
85
|
+
);
|
|
86
|
+
created(V2_REQ, V2, { opencodeGeneration: "v2", opencodeUnsafeTools: true }, PROJECT);
|
|
87
|
+
created("cr_ocv1child", V1, { opencodeGeneration: "v1" }, PROJECT);
|
|
88
|
+
created("cr_ocunsafechild", UNSAFE, { opencodeGeneration: "v2", opencodeUnsafeTools: false }, PROJECT);
|
|
89
|
+
created("cr_ocnullchild", NULLDIR, { opencodeGeneration: "v2", opencodeUnsafeTools: true }, null);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function queue(userId: string, nodeId: string, networkId: string | null = NET, callerIsNode = false) {
|
|
93
|
+
return queueOpenCodeCatalogRead({ callerUserId: userId, callerIsNode, networkId, daemonNodeId: DAEMON, nodeId });
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function handlers(userId: string, isNode: boolean, tokenId: string | null) {
|
|
97
|
+
const server = new McpServer({ name: "oc-catalog-test", version: "0" }) as any;
|
|
98
|
+
const out: Record<string, (args: any) => Promise<{ content: Array<{ text: string }> }>> = {};
|
|
99
|
+
const origTool = server.tool.bind(server);
|
|
100
|
+
server.tool = (name: string, d: string, schema: any, handler: any) => { out[name] = handler; return origTool(name, d, schema, handler); };
|
|
101
|
+
const origRegister = server.registerTool.bind(server);
|
|
102
|
+
server.registerTool = (name: string, cfg: any, handler: any) => { out[name] = handler; return origRegister(name, cfg, handler); };
|
|
103
|
+
registerTools(server, undefined, NET, userId, isNode ? DAEMON_ALIAS : null, isNode, tokenId);
|
|
104
|
+
return { out, server };
|
|
105
|
+
}
|
|
106
|
+
async function call(handler: (args: any) => Promise<{ content: Array<{ text: string }> }>, args: any) {
|
|
107
|
+
return JSON.parse((await handler(args)).content[0]!.text);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function snapshot(directory = PROJECT, overrides: Record<string, unknown> = {}) {
|
|
111
|
+
return {
|
|
112
|
+
scope: { networkId: NET, daemonId: DAEMON, directory },
|
|
113
|
+
source: "opencode-v2-api",
|
|
114
|
+
state: "snapshot",
|
|
115
|
+
invocationVerified: false,
|
|
116
|
+
completeness: "unknown",
|
|
117
|
+
observedAt: "2026-10-11T00:00:00.000Z",
|
|
118
|
+
providers: [{ id: "custom", activation: "enabled" }],
|
|
119
|
+
models: [{ providerId: "custom", id: "nested/model" }],
|
|
120
|
+
defaultModel: { providerId: "custom", id: "nested/model" },
|
|
121
|
+
...overrides,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
describe("hub authorizes an owned OpenCode V2 catalog read", () => {
|
|
126
|
+
test("session model write is denied by default and requires human admin", async () => {
|
|
127
|
+
seed();
|
|
128
|
+
const args = { daemon_node_id: DAEMON, node_id: V2, session_id: "ses_synthetic", model: { providerID: "stub", id: "model", variant: "high" } };
|
|
129
|
+
const admin = handlers(USER, false, null);
|
|
130
|
+
expect(await call(admin.out.select_opencode_session_model!, args)).toEqual({ ok: false, status: "rejected", reason: "unsupported" });
|
|
131
|
+
const viewer = handlers(VIEWER, false, null);
|
|
132
|
+
expect(await call(viewer.out.select_opencode_session_model!, args)).toEqual({ ok: false, error: "access_denied" });
|
|
133
|
+
const outsider = handlers(OUTSIDER, false, null);
|
|
134
|
+
expect(await call(outsider.out.select_opencode_session_model!, args)).toEqual({ ok: false, error: "access_denied" });
|
|
135
|
+
const node = handlers(USER, true, DAEMON_TOK);
|
|
136
|
+
expect(await call(node.out.select_opencode_session_model!, args)).toEqual({ ok: false, error: "user_token_required" });
|
|
137
|
+
const schema = (admin.server as any)._registeredTools.select_opencode_session_model.inputSchema;
|
|
138
|
+
expect((await schema.safeParseAsync({ ...args, model: { ...args.model, headers: { token: "fixture" } } })).success).toBe(false);
|
|
139
|
+
});
|
|
140
|
+
test("member queues, daemon reads the owned loopback, ready snapshot stays unverified", async () => {
|
|
141
|
+
seed();
|
|
142
|
+
const user = handlers(USER, false, null);
|
|
143
|
+
const queued = await call(user.out.read_opencode_catalog!, { daemon_node_id: DAEMON, node_id: V2 });
|
|
144
|
+
expect(queued).toEqual({ ok: true, status: "pending", request_id: queued.request_id });
|
|
145
|
+
expect(JSON.stringify(queued)).not.toContain("daemon_alias");
|
|
146
|
+
const strict = await (user.server as any)._registeredTools.read_opencode_catalog.inputSchema.safeParseAsync({
|
|
147
|
+
daemon_node_id: DAEMON, node_id: V2, settings: { apiKey: "sk-FAKE" }, headers: {}, body: {},
|
|
148
|
+
});
|
|
149
|
+
expect(strict.success).toBe(false);
|
|
150
|
+
|
|
151
|
+
expect(takeOpenCodeCatalogRequest(queued.request_id, "node_other")).toEqual({ ok: false, error: "catalog_request_unavailable" });
|
|
152
|
+
const daemon = handlers(USER, true, DAEMON_TOK);
|
|
153
|
+
const pulled = await call(daemon.out.get_opencode_catalog_request!, { request_id: queued.request_id });
|
|
154
|
+
expect(pulled.ok).toBe(true);
|
|
155
|
+
expect(pulled.directory).toBe(PROJECT);
|
|
156
|
+
for (const key of ["url", "authorization", "settings", "headers", "body"]) expect(pulled[key]).toBeUndefined();
|
|
157
|
+
|
|
158
|
+
let requests = 0;
|
|
159
|
+
const server = Bun.serve({ port: 0, hostname: "127.0.0.1", fetch(req) {
|
|
160
|
+
requests++;
|
|
161
|
+
const url = new URL(req.url);
|
|
162
|
+
const row = url.pathname === "/api/provider"
|
|
163
|
+
? [{ id: "custom", activation: "enabled", settings: { apiKey: "sk-FAKE" } }]
|
|
164
|
+
: [{ providerID: "custom", id: "nested/model", headers: { Authorization: "sk-FAKE" } }];
|
|
165
|
+
return Response.json({ location: { directory: PROJECT }, data: url.pathname === "/api/model/default" ? row[0] : row });
|
|
166
|
+
} });
|
|
167
|
+
const nodeDir = mkdtempSync(join(tmpdir(), "oc-hub-node-"));
|
|
168
|
+
try {
|
|
169
|
+
writeOpenCodeV2CatalogEndpoint(nodeDir, { url: `http://127.0.0.1:${server.port}`, authorization: "Basic fake", directory: PROJECT });
|
|
170
|
+
const read = await readOwnedOpenCodeV2Catalog({
|
|
171
|
+
networkId: NET, daemonId: DAEMON, authorizedDirectory: pulled.directory,
|
|
172
|
+
ownedProjectDirectory: PROJECT, endpoint: readOpenCodeV2CatalogEndpoint(nodeDir),
|
|
173
|
+
});
|
|
174
|
+
expect(read.ok).toBe(true);
|
|
175
|
+
if (!read.ok) return;
|
|
176
|
+
const acked = await call(daemon.out.ack_opencode_catalog!, { request_id: queued.request_id, snapshot: read.snapshot });
|
|
177
|
+
expect(acked).toEqual({ ok: true, status: "ready" });
|
|
178
|
+
const got = await call(user.out.get_opencode_catalog!, { request_id: queued.request_id });
|
|
179
|
+
expect(got.status).toBe("ready");
|
|
180
|
+
expect(got.snapshot.invocationVerified).toBe(false);
|
|
181
|
+
expect(got.snapshot.completeness).toBe("unknown");
|
|
182
|
+
expect(JSON.stringify(got.snapshot)).not.toContain("sk-FAKE");
|
|
183
|
+
expect(requests).toBe(3);
|
|
184
|
+
} finally {
|
|
185
|
+
server.stop(true);
|
|
186
|
+
rmSync(nodeDir, { recursive: true, force: true });
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
test("viewer may queue; outsider, node token, and non-v2 children may not", () => {
|
|
191
|
+
seed();
|
|
192
|
+
expect(queue(VIEWER, V2).ok).toBe(true);
|
|
193
|
+
expect(queue(OUTSIDER, V2, NET)).toEqual({ ok: false, error: "access_denied" });
|
|
194
|
+
expect(queue(OUTSIDER, V2, OTHER)).toEqual({ ok: false, error: "daemon_not_found" });
|
|
195
|
+
expect(queue(USER, V2, NET, true)).toEqual({ ok: false, error: "user_token_required" });
|
|
196
|
+
expect(queue(USER, V1)).toEqual({ ok: false, error: "not_opencode_v2" });
|
|
197
|
+
expect(queue(USER, UNSAFE)).toEqual({ ok: false, error: "not_opencode_v2" });
|
|
198
|
+
expect(queue(USER, "node_missing")).toEqual({ ok: false, error: "node_not_found" });
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
test("pending is not a snapshot; expiry, bad acks, and a missing endpoint stay closed", async () => {
|
|
202
|
+
seed();
|
|
203
|
+
const queued = queue(USER, V2);
|
|
204
|
+
expect(queued.ok).toBe(true);
|
|
205
|
+
if (!queued.ok) return;
|
|
206
|
+
expect(getOpenCodeCatalogResult({ callerUserId: USER, callerIsNode: false, networkId: NET, requestId: queued.request_id })).toEqual({
|
|
207
|
+
ok: true, status: "pending", request_id: queued.request_id,
|
|
208
|
+
});
|
|
209
|
+
const pulled = takeOpenCodeCatalogRequest(queued.request_id, DAEMON);
|
|
210
|
+
expect(pulled.ok).toBe(true);
|
|
211
|
+
|
|
212
|
+
expect(ackOpenCodeCatalog(DAEMON, { request_id: queued.request_id, snapshot: snapshot(), settings: { apiKey: "sk-FAKE" } })).toEqual({ ok: false, error: "invalid_ack" });
|
|
213
|
+
expect(ackOpenCodeCatalog(DAEMON, { request_id: queued.request_id, snapshot: snapshot(PROJECT, { invocationVerified: true }) })).toEqual({ ok: false, error: "invalid_ack" });
|
|
214
|
+
expect(getOpenCodeCatalogResult({ callerUserId: USER, callerIsNode: false, networkId: NET, requestId: queued.request_id }).status).toBe("pending");
|
|
215
|
+
|
|
216
|
+
const wrongDir = ackOpenCodeCatalog(DAEMON, { request_id: queued.request_id, snapshot: snapshot("/tmp/other-project") });
|
|
217
|
+
expect(wrongDir).toEqual({ ok: true, status: "failed", error: "invalid_response" });
|
|
218
|
+
expect(getOpenCodeCatalogResult({ callerUserId: USER, callerIsNode: false, networkId: NET, requestId: queued.request_id })).toMatchObject({
|
|
219
|
+
ok: false, status: "failed", error: "invalid_response",
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const again = queue(USER, V2);
|
|
223
|
+
expect(again.ok).toBe(true);
|
|
224
|
+
if (!again.ok) return;
|
|
225
|
+
takeOpenCodeCatalogRequest(again.request_id, DAEMON);
|
|
226
|
+
expect(ackOpenCodeCatalog(DAEMON, { request_id: again.request_id, error: "unavailable" })).toEqual({ ok: true, status: "failed", error: "unavailable" });
|
|
227
|
+
expect(getOpenCodeCatalogResult({ callerUserId: USER, callerIsNode: false, networkId: NET, requestId: again.request_id })).toMatchObject({
|
|
228
|
+
ok: false, status: "failed", error: "unavailable",
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
const waiting = queue(USER, NULLDIR);
|
|
232
|
+
expect(waiting.ok).toBe(true);
|
|
233
|
+
if (!waiting.ok) return;
|
|
234
|
+
expireOpenCodeCatalogForTest(waiting.request_id);
|
|
235
|
+
expect(getOpenCodeCatalogResult({ callerUserId: USER, callerIsNode: false, networkId: NET, requestId: waiting.request_id })).toMatchObject({
|
|
236
|
+
ok: false, status: "expired", error: "unavailable",
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
test("acks a Windows absolute directory without Hub path.resolve", () => {
|
|
241
|
+
seed();
|
|
242
|
+
db.run(`UPDATE node_create_requests SET workdir = ?1 WHERE request_id = ?2`, ["C:\\project", V2_REQ]);
|
|
243
|
+
const queued = queue(USER, V2);
|
|
244
|
+
expect(queued.ok).toBe(true);
|
|
245
|
+
if (!queued.ok) return;
|
|
246
|
+
takeOpenCodeCatalogRequest(queued.request_id, DAEMON);
|
|
247
|
+
expect(ackOpenCodeCatalog(DAEMON, { request_id: queued.request_id, snapshot: snapshot("project") })).toEqual({ ok: false, error: "invalid_ack" });
|
|
248
|
+
expect(ackOpenCodeCatalog(DAEMON, { request_id: queued.request_id, snapshot: snapshot("C:relative") })).toEqual({ ok: false, error: "invalid_ack" });
|
|
249
|
+
expect(getOpenCodeCatalogResult({ callerUserId: USER, callerIsNode: false, networkId: NET, requestId: queued.request_id }).status).toBe("pending");
|
|
250
|
+
expect(ackOpenCodeCatalog(DAEMON, { request_id: queued.request_id, snapshot: snapshot("C:/project") })).toEqual({ ok: true, status: "ready" });
|
|
251
|
+
const got = getOpenCodeCatalogResult({ callerUserId: USER, callerIsNode: false, networkId: NET, requestId: queued.request_id });
|
|
252
|
+
expect(got.ok).toBe(true);
|
|
253
|
+
if (!got.ok || got.status !== "ready") return;
|
|
254
|
+
expect(got.snapshot.scope.directory).toBe("C:/project");
|
|
255
|
+
|
|
256
|
+
const other = queue(USER, V2);
|
|
257
|
+
expect(other.ok).toBe(true);
|
|
258
|
+
if (!other.ok) return;
|
|
259
|
+
takeOpenCodeCatalogRequest(other.request_id, DAEMON);
|
|
260
|
+
expect(ackOpenCodeCatalog(DAEMON, { request_id: other.request_id, snapshot: snapshot("D:\\other") })).toEqual({
|
|
261
|
+
ok: true, status: "failed", error: "invalid_response",
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
test("a tilde workdir matches a native absolute report, and lexical .. collapses", () => {
|
|
266
|
+
seed();
|
|
267
|
+
db.run(`UPDATE node_create_requests SET workdir = ?1 WHERE request_id = ?2`, ["~/project", V2_REQ]);
|
|
268
|
+
const queued = queue(USER, V2);
|
|
269
|
+
expect(queued.ok).toBe(true);
|
|
270
|
+
if (!queued.ok) return;
|
|
271
|
+
takeOpenCodeCatalogRequest(queued.request_id, DAEMON);
|
|
272
|
+
expect(ackOpenCodeCatalog(DAEMON, { request_id: queued.request_id, snapshot: snapshot("/home/user/project") })).toEqual({ ok: true, status: "ready" });
|
|
273
|
+
|
|
274
|
+
db.run(`UPDATE node_create_requests SET workdir = ?1 WHERE request_id = ?2`, ["/tmp/foo/../bar", V2_REQ]);
|
|
275
|
+
const lexical = queue(USER, V2);
|
|
276
|
+
expect(lexical.ok).toBe(true);
|
|
277
|
+
if (!lexical.ok) return;
|
|
278
|
+
takeOpenCodeCatalogRequest(lexical.request_id, DAEMON);
|
|
279
|
+
expect(ackOpenCodeCatalog(DAEMON, { request_id: lexical.request_id, snapshot: snapshot("/tmp/foo/../bar") })).toEqual({ ok: false, error: "invalid_ack" });
|
|
280
|
+
expect(ackOpenCodeCatalog(DAEMON, { request_id: lexical.request_id, snapshot: snapshot("/tmp/bar") })).toEqual({ ok: true, status: "ready" });
|
|
281
|
+
});
|
|
282
|
+
});
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
// Hub authorization for a native OpenCode V2 catalog read.
|
|
2
|
+
//
|
|
3
|
+
// The caller names a daemon and a child node. Identity, generation, and the
|
|
4
|
+
// project directory come from Hub rows. The queued payload has no URL,
|
|
5
|
+
// authorization, settings, headers, or body. The daemon reads its own
|
|
6
|
+
// already-running loopback and acks a whitelist snapshot.
|
|
7
|
+
//
|
|
8
|
+
// `status: "pending"` means the read was authorized and stored. It does not
|
|
9
|
+
// mean a daemon received the doorbell or produced a snapshot. Only
|
|
10
|
+
// `status: "ready"` is a snapshot, and that snapshot stays completeness
|
|
11
|
+
// unknown / invocation unverified.
|
|
12
|
+
|
|
13
|
+
import { posix, win32 } from "node:path";
|
|
14
|
+
import { z } from "zod/v4";
|
|
15
|
+
import { db, uuidv4 } from "./db.js";
|
|
16
|
+
import { getUserNetworkRole } from "./auth.js";
|
|
17
|
+
|
|
18
|
+
const TTL_MS = 60_000;
|
|
19
|
+
const MAX_PENDING = 100;
|
|
20
|
+
const SECRET = /^(sk-|gh[pousr]_|github_pat_|xox[baprs]-|AKIA|AIza|ya29\.|glpat-)/i;
|
|
21
|
+
|
|
22
|
+
export const CATALOG_ERROR_CODES = [
|
|
23
|
+
"invalid_target", "unauthorized", "unavailable", "invalid_response", "scope_mismatch", "too_large",
|
|
24
|
+
// 2026-10-31 —— 两格新增,都要与 agent-node 侧的手工联合类型同步:
|
|
25
|
+
// "unexpected" 兜底不许点名因果(原先把非目录错误一律报 "unavailable")
|
|
26
|
+
// "directory_not_ascii" 传输层结构性限制:OpenCode 只认 header,而 header 运不了非 ASCII
|
|
27
|
+
"unexpected", "directory_not_ascii",
|
|
28
|
+
] as const;
|
|
29
|
+
export type CatalogErrorCode = (typeof CATALOG_ERROR_CODES)[number];
|
|
30
|
+
|
|
31
|
+
const identifier = z.string().min(1).max(512).refine(value => !/[\s\u0000-\u001f\u007f]/.test(value) && !SECRET.test(value));
|
|
32
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
33
|
+
const WINDOWS_DRIVE = /^[A-Za-z]:[\\/]/;
|
|
34
|
+
|
|
35
|
+
/** Absolute in the path's own format. Hub `path.resolve` is not used: on a
|
|
36
|
+
* POSIX Hub it treats `C:\project` as a relative path under the process cwd. */
|
|
37
|
+
function windowsStrictAbsolute(value: string): boolean {
|
|
38
|
+
if (!WINDOWS_DRIVE.test(value)) return false;
|
|
39
|
+
const parts = value.slice(2).split(/[\\/]/);
|
|
40
|
+
if (parts[0] !== "" || parts.length < 2) return false;
|
|
41
|
+
return parts.slice(1).every(part => part !== "" && part !== "." && part !== "..");
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function strictNativeAbsoluteDirectory(value: string): boolean {
|
|
45
|
+
if (value.length < 1 || value.length > 1024 || CONTROL.test(value)) return false;
|
|
46
|
+
if (WINDOWS_DRIVE.test(value)) return windowsStrictAbsolute(value);
|
|
47
|
+
if (value.startsWith("/")) return posix.resolve(value) === value;
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function tildeWorkdir(value: string): boolean {
|
|
52
|
+
const trimmed = value.trim();
|
|
53
|
+
return trimmed === "~" || trimmed.startsWith("~/") || trimmed.startsWith("~\\");
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Compare a stored create workdir with the directory the daemon reported.
|
|
57
|
+
* Windows keys ignore slash style and case. POSIX keys are lexical (`..` and
|
|
58
|
+
* a trailing slash collapse) and are not realpath'd — Hub does not see the
|
|
59
|
+
* daemon disk. A `~` / `~/…` workdir has no Hub-side home to expand; a
|
|
60
|
+
* native-absolute report is accepted because the daemon already refused the
|
|
61
|
+
* read unless that path is the endpoint it owns. A compromised daemon can
|
|
62
|
+
* name another absolute path for a tilde row, same as a null workdir. */
|
|
63
|
+
export function catalogDirectoriesMatch(stored: string, reported: string): boolean {
|
|
64
|
+
if (!strictNativeAbsoluteDirectory(reported)) return false;
|
|
65
|
+
const storedTrim = stored.trim();
|
|
66
|
+
if (tildeWorkdir(storedTrim)) return true;
|
|
67
|
+
const storedWindows = WINDOWS_DRIVE.test(storedTrim);
|
|
68
|
+
const reportedWindows = WINDOWS_DRIVE.test(reported);
|
|
69
|
+
if (storedWindows !== reportedWindows) return false;
|
|
70
|
+
if (storedWindows) {
|
|
71
|
+
const left = win32.resolve(storedTrim);
|
|
72
|
+
const right = win32.resolve(reported);
|
|
73
|
+
return /^[A-Za-z]:\\/.test(left) && left.toLowerCase() === right.toLowerCase();
|
|
74
|
+
}
|
|
75
|
+
if (storedTrim.startsWith("/") && reported.startsWith("/")) return posix.resolve(storedTrim) === posix.resolve(reported);
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const directoryText = z.string().min(1).max(1024).refine(strictNativeAbsoluteDirectory);
|
|
80
|
+
|
|
81
|
+
export const opencodeCatalogSnapshotSchema = z.object({
|
|
82
|
+
scope: z.object({
|
|
83
|
+
networkId: z.string().min(1).max(200),
|
|
84
|
+
daemonId: z.string().min(1).max(200),
|
|
85
|
+
directory: directoryText,
|
|
86
|
+
}).strict(),
|
|
87
|
+
source: z.literal("opencode-v2-api"),
|
|
88
|
+
state: z.literal("snapshot"),
|
|
89
|
+
invocationVerified: z.literal(false),
|
|
90
|
+
completeness: z.literal("unknown"),
|
|
91
|
+
observedAt: z.string().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?Z$/),
|
|
92
|
+
providers: z.array(z.object({
|
|
93
|
+
id: identifier,
|
|
94
|
+
activation: z.enum(["auto", "enabled", "disabled"]),
|
|
95
|
+
}).strict()).max(20_000),
|
|
96
|
+
models: z.array(z.object({
|
|
97
|
+
providerId: identifier,
|
|
98
|
+
id: identifier,
|
|
99
|
+
variants: z.array(identifier).max(200).refine(values => new Set(values).size === values.length).optional(),
|
|
100
|
+
}).strict()).max(20_000),
|
|
101
|
+
defaultModel: z.object({ providerId: identifier, id: identifier }).strict().nullable(),
|
|
102
|
+
}).strict();
|
|
103
|
+
|
|
104
|
+
export type OpenCodeCatalogSnapshotWire = z.infer<typeof opencodeCatalogSnapshotSchema>;
|
|
105
|
+
|
|
106
|
+
export const opencodeCatalogAckSchema = z.object({
|
|
107
|
+
request_id: z.string().min(1).max(200),
|
|
108
|
+
error: z.enum(CATALOG_ERROR_CODES).optional(),
|
|
109
|
+
snapshot: opencodeCatalogSnapshotSchema.optional(),
|
|
110
|
+
}).strict();
|
|
111
|
+
|
|
112
|
+
interface PendingCatalogRead {
|
|
113
|
+
requestId: string;
|
|
114
|
+
daemonNodeId: string;
|
|
115
|
+
daemonAlias: string;
|
|
116
|
+
networkId: string;
|
|
117
|
+
nodeId: string;
|
|
118
|
+
alias: string;
|
|
119
|
+
directory: string | null;
|
|
120
|
+
expiresAt: number;
|
|
121
|
+
taken: boolean;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
export interface StoredCatalogRead {
|
|
125
|
+
requestId: string;
|
|
126
|
+
networkId: string;
|
|
127
|
+
daemonNodeId: string;
|
|
128
|
+
nodeId: string;
|
|
129
|
+
status: "pending" | "ready" | "failed" | "expired";
|
|
130
|
+
error?: CatalogErrorCode;
|
|
131
|
+
snapshot?: OpenCodeCatalogSnapshotWire;
|
|
132
|
+
expiresAt: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const pending = new Map<string, PendingCatalogRead>();
|
|
136
|
+
const stored = new Map<string, StoredCatalogRead>();
|
|
137
|
+
|
|
138
|
+
export function resetOpenCodeCatalogForTest(): void {
|
|
139
|
+
pending.clear();
|
|
140
|
+
stored.clear();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export function expireOpenCodeCatalogForTest(requestId: string): void {
|
|
144
|
+
// Just past the read deadline, still inside the retention window. Setting
|
|
145
|
+
// the deadline to 0 would also drop the stored row and look like not_found.
|
|
146
|
+
const expiredAt = Date.now() - 1;
|
|
147
|
+
const row = pending.get(requestId);
|
|
148
|
+
if (row) row.expiresAt = expiredAt;
|
|
149
|
+
const result = stored.get(requestId);
|
|
150
|
+
if (result) result.expiresAt = expiredAt;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function childNodeId(requestId: string): string | null {
|
|
154
|
+
return requestId.startsWith("cr_") ? `node_${requestId.slice(3)}` : null;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function supervisorRole(snapshot: string | null): boolean {
|
|
158
|
+
if (!snapshot) return false;
|
|
159
|
+
try {
|
|
160
|
+
const parsed = JSON.parse(snapshot) as { role?: unknown };
|
|
161
|
+
return parsed.role === "host_supervisor";
|
|
162
|
+
} catch {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
function v2Flags(flagsJson: string): boolean {
|
|
168
|
+
try {
|
|
169
|
+
const flags = JSON.parse(flagsJson) as { opencodeGeneration?: unknown; opencodeUnsafeTools?: unknown };
|
|
170
|
+
return flags.opencodeGeneration === "v2" && flags.opencodeUnsafeTools === true;
|
|
171
|
+
} catch {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export interface QueueCatalogInput {
|
|
177
|
+
callerUserId: string | null;
|
|
178
|
+
callerIsNode: boolean;
|
|
179
|
+
networkId: string | null;
|
|
180
|
+
daemonNodeId: string;
|
|
181
|
+
nodeId: string;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function evictExpired(now = Date.now()): void {
|
|
185
|
+
for (const [id, row] of pending) {
|
|
186
|
+
if (now > row.expiresAt) pending.delete(id);
|
|
187
|
+
}
|
|
188
|
+
for (const [id, row] of stored) {
|
|
189
|
+
if (row.status === "pending" && now > row.expiresAt) row.status = "expired";
|
|
190
|
+
if (now > row.expiresAt + TTL_MS) stored.delete(id);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function queueOpenCodeCatalogRead(input: QueueCatalogInput):
|
|
195
|
+
| { ok: true; request_id: string; status: "pending"; daemon_alias: string; network_id: string }
|
|
196
|
+
| { ok: false; error: string } {
|
|
197
|
+
evictExpired();
|
|
198
|
+
if (input.callerIsNode) return { ok: false, error: "user_token_required" };
|
|
199
|
+
if (!input.callerUserId) return { ok: false, error: "auth_required" };
|
|
200
|
+
if (!input.networkId) return { ok: false, error: "network_id_required" };
|
|
201
|
+
const role = getUserNetworkRole(input.callerUserId, input.networkId);
|
|
202
|
+
if (!role) return { ok: false, error: "access_denied" };
|
|
203
|
+
if (pending.size >= MAX_PENDING) return { ok: false, error: "catalog_busy" };
|
|
204
|
+
|
|
205
|
+
const daemon = db.get<{ node_id: string; alias: string; config_snapshot: string | null }>(
|
|
206
|
+
`SELECT node_id, alias, config_snapshot FROM nodes WHERE node_id = ?1 AND network_id = ?2`,
|
|
207
|
+
input.daemonNodeId, input.networkId,
|
|
208
|
+
);
|
|
209
|
+
if (!daemon) return { ok: false, error: "daemon_not_found" };
|
|
210
|
+
if (!supervisorRole(daemon.config_snapshot)) return { ok: false, error: "daemon_not_supervisor" };
|
|
211
|
+
|
|
212
|
+
const child = db.get<{ node_id: string }>(
|
|
213
|
+
`SELECT node_id FROM nodes WHERE node_id = ?1 AND network_id = ?2`,
|
|
214
|
+
input.nodeId, input.networkId,
|
|
215
|
+
);
|
|
216
|
+
if (!child) return { ok: false, error: "node_not_found" };
|
|
217
|
+
|
|
218
|
+
const creates = db.all<{
|
|
219
|
+
request_id: string; daemon_node_id: string; child_name: string; runtime: string;
|
|
220
|
+
flags_json: string; workdir: string | null; status: string;
|
|
221
|
+
}>(
|
|
222
|
+
`SELECT request_id, daemon_node_id, child_name, runtime, flags_json, workdir, status
|
|
223
|
+
FROM node_create_requests
|
|
224
|
+
WHERE network_id = ?1 AND daemon_node_id = ?2 AND status IN ('succeeded', 'delivered')`,
|
|
225
|
+
input.networkId, input.daemonNodeId,
|
|
226
|
+
);
|
|
227
|
+
const owned = creates.filter(row => childNodeId(row.request_id) === input.nodeId && row.daemon_node_id === input.daemonNodeId);
|
|
228
|
+
if (owned.length !== 1) return { ok: false, error: "node_not_found" };
|
|
229
|
+
const row = owned[0]!;
|
|
230
|
+
if (row.runtime !== "opencode-cli" || !v2Flags(row.flags_json)) return { ok: false, error: "not_opencode_v2" };
|
|
231
|
+
|
|
232
|
+
const requestId = `cat_${uuidv4()}`;
|
|
233
|
+
const directory = typeof row.workdir === "string" && row.workdir.length > 0 ? row.workdir : null;
|
|
234
|
+
const record: PendingCatalogRead = {
|
|
235
|
+
requestId,
|
|
236
|
+
daemonNodeId: daemon.node_id,
|
|
237
|
+
daemonAlias: daemon.alias,
|
|
238
|
+
networkId: input.networkId,
|
|
239
|
+
nodeId: input.nodeId,
|
|
240
|
+
alias: row.child_name,
|
|
241
|
+
directory,
|
|
242
|
+
expiresAt: Date.now() + TTL_MS,
|
|
243
|
+
taken: false,
|
|
244
|
+
};
|
|
245
|
+
pending.set(requestId, record);
|
|
246
|
+
stored.set(requestId, {
|
|
247
|
+
requestId,
|
|
248
|
+
networkId: input.networkId,
|
|
249
|
+
daemonNodeId: daemon.node_id,
|
|
250
|
+
nodeId: input.nodeId,
|
|
251
|
+
status: "pending",
|
|
252
|
+
expiresAt: record.expiresAt,
|
|
253
|
+
});
|
|
254
|
+
return { ok: true, request_id: requestId, status: "pending", daemon_alias: daemon.alias, network_id: input.networkId };
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export function takeOpenCodeCatalogRequest(requestId: string, daemonNodeId: string):
|
|
258
|
+
| { ok: true; request_id: string; node_id: string; alias: string; directory: string | null; scope: { networkId: string; daemonId: string } }
|
|
259
|
+
| { ok: false; error: "catalog_request_unavailable" } {
|
|
260
|
+
const row = pending.get(requestId);
|
|
261
|
+
if (!row || row.daemonNodeId !== daemonNodeId || row.taken) return { ok: false, error: "catalog_request_unavailable" };
|
|
262
|
+
if (Date.now() > row.expiresAt) {
|
|
263
|
+
row.taken = true;
|
|
264
|
+
const result = stored.get(requestId);
|
|
265
|
+
if (result && result.status === "pending") result.status = "expired";
|
|
266
|
+
return { ok: false, error: "catalog_request_unavailable" };
|
|
267
|
+
}
|
|
268
|
+
row.taken = true;
|
|
269
|
+
return {
|
|
270
|
+
ok: true,
|
|
271
|
+
request_id: row.requestId,
|
|
272
|
+
node_id: row.nodeId,
|
|
273
|
+
alias: row.alias,
|
|
274
|
+
directory: row.directory,
|
|
275
|
+
scope: { networkId: row.networkId, daemonId: row.daemonNodeId },
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
function consistent(snapshot: OpenCodeCatalogSnapshotWire): boolean {
|
|
280
|
+
const providers = new Set<string>();
|
|
281
|
+
for (const row of snapshot.providers) {
|
|
282
|
+
if (providers.has(row.id)) return false;
|
|
283
|
+
providers.add(row.id);
|
|
284
|
+
}
|
|
285
|
+
const models = new Set<string>();
|
|
286
|
+
for (const row of snapshot.models) {
|
|
287
|
+
if (!providers.has(row.providerId)) return false;
|
|
288
|
+
const key = JSON.stringify([row.providerId, row.id]);
|
|
289
|
+
if (models.has(key)) return false;
|
|
290
|
+
models.add(key);
|
|
291
|
+
}
|
|
292
|
+
if (snapshot.defaultModel && !models.has(JSON.stringify([snapshot.defaultModel.providerId, snapshot.defaultModel.id]))) return false;
|
|
293
|
+
return Buffer.byteLength(JSON.stringify(snapshot), "utf8") <= 2 * 1024 * 1024;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
export function ackOpenCodeCatalog(daemonNodeId: string, body: unknown):
|
|
297
|
+
| { ok: true; status: "ready" | "failed"; error?: CatalogErrorCode }
|
|
298
|
+
| { ok: false; error: "catalog_request_unavailable" | "invalid_ack" } {
|
|
299
|
+
const parsed = opencodeCatalogAckSchema.safeParse(body);
|
|
300
|
+
if (!parsed.success) return { ok: false, error: "invalid_ack" };
|
|
301
|
+
const ack = parsed.data;
|
|
302
|
+
const hasSnapshot = ack.snapshot !== undefined;
|
|
303
|
+
const hasError = ack.error !== undefined;
|
|
304
|
+
if (hasSnapshot === hasError) return { ok: false, error: "invalid_ack" };
|
|
305
|
+
const row = pending.get(ack.request_id);
|
|
306
|
+
const result = stored.get(ack.request_id);
|
|
307
|
+
if (!row || !result || row.daemonNodeId !== daemonNodeId || !row.taken) {
|
|
308
|
+
return { ok: false, error: "catalog_request_unavailable" };
|
|
309
|
+
}
|
|
310
|
+
if (Date.now() > row.expiresAt || result.status !== "pending") {
|
|
311
|
+
if (result.status === "pending") result.status = "expired";
|
|
312
|
+
return { ok: false, error: "catalog_request_unavailable" };
|
|
313
|
+
}
|
|
314
|
+
if (ack.error) {
|
|
315
|
+
result.status = "failed";
|
|
316
|
+
result.error = ack.error;
|
|
317
|
+
return { ok: true, status: "failed", error: ack.error };
|
|
318
|
+
}
|
|
319
|
+
const snapshot = ack.snapshot!;
|
|
320
|
+
// A stored workdir must match. A null workdir (legacy create) has no
|
|
321
|
+
// hub-side path to compare; the daemon binds that read to the project
|
|
322
|
+
// directory it already owns. Hub does not see that filesystem.
|
|
323
|
+
const directoryOk = row.directory ? catalogDirectoriesMatch(row.directory, snapshot.scope.directory) : true;
|
|
324
|
+
if (snapshot.scope.networkId !== row.networkId || snapshot.scope.daemonId !== row.daemonNodeId || !directoryOk || !consistent(snapshot)) {
|
|
325
|
+
result.status = "failed";
|
|
326
|
+
result.error = "invalid_response";
|
|
327
|
+
return { ok: true, status: "failed", error: "invalid_response" };
|
|
328
|
+
}
|
|
329
|
+
result.status = "ready";
|
|
330
|
+
result.snapshot = snapshot;
|
|
331
|
+
return { ok: true, status: "ready" };
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
export function getOpenCodeCatalogResult(input: {
|
|
335
|
+
callerUserId: string | null;
|
|
336
|
+
callerIsNode: boolean;
|
|
337
|
+
networkId: string | null;
|
|
338
|
+
requestId: string;
|
|
339
|
+
}):
|
|
340
|
+
| { ok: true; status: "pending"; request_id: string }
|
|
341
|
+
| { ok: true; status: "ready"; request_id: string; snapshot: OpenCodeCatalogSnapshotWire }
|
|
342
|
+
| { ok: false; status?: "failed" | "expired"; error: string; request_id?: string } {
|
|
343
|
+
if (input.callerIsNode) return { ok: false, error: "user_token_required" };
|
|
344
|
+
if (!input.callerUserId) return { ok: false, error: "auth_required" };
|
|
345
|
+
if (!input.networkId) return { ok: false, error: "network_id_required" };
|
|
346
|
+
if (!getUserNetworkRole(input.callerUserId, input.networkId)) return { ok: false, error: "access_denied" };
|
|
347
|
+
evictExpired();
|
|
348
|
+
const result = stored.get(input.requestId);
|
|
349
|
+
if (!result || result.networkId !== input.networkId) return { ok: false, error: "not_found" };
|
|
350
|
+
if (result.status === "pending" && Date.now() > result.expiresAt) result.status = "expired";
|
|
351
|
+
if (result.status === "pending") return { ok: true, status: "pending", request_id: result.requestId };
|
|
352
|
+
if (result.status === "ready" && result.snapshot) {
|
|
353
|
+
return { ok: true, status: "ready", request_id: result.requestId, snapshot: result.snapshot };
|
|
354
|
+
}
|
|
355
|
+
if (result.status === "expired") return { ok: false, status: "expired", error: "unavailable", request_id: result.requestId };
|
|
356
|
+
return { ok: false, status: "failed", error: result.error || "unavailable", request_id: result.requestId };
|
|
357
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// commhub-server ships only `src/`, `bin/` and build-info.json (package.json "files").
|
|
2
|
+
// A non-test module that imports a path outside this package works in the repo but
|
|
3
|
+
// makes the published Hub crash at startup ("Cannot find module ../../contracts/…",
|
|
4
|
+
// seen in the e2e npm-pack suite). Pin it: every relative import from shipped code
|
|
5
|
+
// must resolve inside server/.
|
|
6
|
+
import { expect, test } from "bun:test";
|
|
7
|
+
import { readdirSync, readFileSync, statSync } from "node:fs";
|
|
8
|
+
import { dirname, join, resolve, sep } from "node:path";
|
|
9
|
+
|
|
10
|
+
const root = resolve(import.meta.dir, "..");
|
|
11
|
+
const IMPORT_RE = /(?:from|import\(|require\()\s*["'](\.{1,2}\/[^"']+)["']/g;
|
|
12
|
+
|
|
13
|
+
function shipped(dir: string): string[] {
|
|
14
|
+
const out: string[] = [];
|
|
15
|
+
for (const name of readdirSync(dir)) {
|
|
16
|
+
const p = join(dir, name);
|
|
17
|
+
if (statSync(p).isDirectory()) { if (name !== "node_modules" && name !== "fixtures") out.push(...shipped(p)); }
|
|
18
|
+
else if (/\.(ts|js|mjs)$/.test(name) && !/\.test\.(ts|js)$/.test(name)) out.push(p);
|
|
19
|
+
}
|
|
20
|
+
return out;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
test("shipped server code never imports outside the commhub-server package", () => {
|
|
24
|
+
const escapes: string[] = [];
|
|
25
|
+
for (const file of [...shipped(join(root, "src")), ...shipped(join(root, "bin"))]) {
|
|
26
|
+
for (const m of readFileSync(file, "utf8").matchAll(IMPORT_RE)) {
|
|
27
|
+
const target = resolve(dirname(file), m[1]);
|
|
28
|
+
if (!target.startsWith(root + sep)) escapes.push(`${file.slice(root.length + 1)} → ${m[1]}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
expect(escapes).toEqual([]);
|
|
32
|
+
});
|