@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,408 @@
|
|
|
1
|
+
import { afterAll, afterEach, beforeAll, beforeEach, expect, setSystemTime, test } from "bun:test";
|
|
2
|
+
import { testWorkRoot } from "./test-work-root";
|
|
3
|
+
import { mkdtempSync, mkdirSync, writeFileSync, readFileSync, rmSync, symlinkSync, readdirSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { tmpdir } from "node:os";
|
|
6
|
+
import { randomUUID } from "node:crypto";
|
|
7
|
+
import { SOURCE_DIRECTORY_CAPABILITY as DIR_CAP } from "../../contracts/session-source-directory";
|
|
8
|
+
import { PROJECT_CREATE_ROOT as P, PROJECT_CREATE_CAPABILITY as CAP, SESSION_ATTACH_CAPABILITY as ACAP } from "../../contracts/session-project-create";
|
|
9
|
+
import { observeHostSharedServe } from "../../agent-node/src/runtime/opencode-host-shared-observer";
|
|
10
|
+
import { createSourceDirectoryReader } from "../../agent-node/src/runtime/session-source-directory";
|
|
11
|
+
import { createSessionControlPin } from "../../agent-node/src/runtime/session-control-bridge";
|
|
12
|
+
import { createSessionSourceTransportWorker } from "../../agent-node/src/runtime/session-source-transport";
|
|
13
|
+
|
|
14
|
+
const root = mkdtempSync(join(testWorkRoot(), "project-create-http-")); process.env.COMMHUB_DB ||= join(root, "hub.db");
|
|
15
|
+
const gates = ["COMMHUB_SOURCE_DIRECTORY_PREVIEW", "COMMHUB_PROJECT_NEW_SESSION_PREVIEW", "COMMHUB_SESSION_ATTACH_PREVIEW"];
|
|
16
|
+
const previous = gates.map(g => process.env[g]);
|
|
17
|
+
const D = "/api/node-session-control/source/directory", serverId = `osrv_${randomUUID()}`;
|
|
18
|
+
const home = join(root, "home"), daemonDir = join(root, "daemon"), project = join(root, "project");
|
|
19
|
+
let db: any, human: any, outsider: any, daemon: any, source: any, net: string, boot: any, hub: any, base: string;
|
|
20
|
+
let worker: ReturnType<typeof createSessionSourceTransportWorker>, proxy: ReturnType<typeof Bun.serve>, posts = 0, registrations = 0, serial = 0;
|
|
21
|
+
let mode = "ok", nativeCalls: string[] = [], postBodies: any[] = [], fetchOverride: typeof fetch | undefined;
|
|
22
|
+
let sessions = new Set<string>(), workerEnabled = true, currentEpoch = 0, cliFixtureRoot: string | null = null;
|
|
23
|
+
let nativeLaunchOverride: Parameters<typeof createSessionSourceTransportWorker>[0]["nativeLaunch"];
|
|
24
|
+
const native = Bun.serve({ hostname: "127.0.0.1", port: 0, async fetch(r) {
|
|
25
|
+
const u = new URL(r.url); nativeCalls.push(`${r.method} ${u.pathname}`);
|
|
26
|
+
if (r.headers.get("authorization") !== `Basic ${Buffer.from("opencode:synthetic-project-password").toString("base64")}`) return new Response("", { status: 401 });
|
|
27
|
+
if (u.pathname === "/api/info") return Response.json({ version: "2.0.22", pid: process.pid });
|
|
28
|
+
if (u.pathname === "/api/project") return Response.json([{ id: "prj_Selected", canonical: project, name: "Existing project", sandboxes: [], time: { created: 1, updated: 1, active: 1 } }]);
|
|
29
|
+
if (["/api/provider", "/api/model", "/api/model/default"].includes(u.pathname)) {
|
|
30
|
+
if (r.headers.get("x-opencode-directory") !== project) return new Response("", { status: 400 });
|
|
31
|
+
return Response.json({ location: { directory: project }, data: u.pathname === "/api/provider" ? [{ id: "stub", activation: "enabled" }]
|
|
32
|
+
: u.pathname === "/api/model" ? [{ id: "model", providerID: "stub" }] : mode === "no-default-model" ? null : { id: "model", providerID: "stub" } });
|
|
33
|
+
}
|
|
34
|
+
if (u.pathname === "/api/session/active") return Response.json({ data: {} });
|
|
35
|
+
if (u.pathname === "/api/session" && r.method === "GET") return Response.json({ data: [...sessions].map(id => ({ id, projectID: "prj_Selected", location: { directory: project } })), cursor: {} });
|
|
36
|
+
if (u.pathname === "/api/session" && r.method === "POST") {
|
|
37
|
+
posts++; postBodies.push(await r.json()); const id = `ses_New${serial}_${posts}`.replace(/_/g, "").replace(/^ses/, "ses_"); sessions.add(id);
|
|
38
|
+
if (mode === "lost-create") return new Response("");
|
|
39
|
+
return Response.json({ data: { id, projectID: "prj_Selected", location: { directory: project } } });
|
|
40
|
+
}
|
|
41
|
+
if (u.pathname.startsWith("/api/session/")) {
|
|
42
|
+
const id = u.pathname.slice("/api/session/".length);
|
|
43
|
+
if (!sessions.has(id)) return new Response("", { status: 404 });
|
|
44
|
+
return Response.json({ data: { id, projectID: "prj_Selected", location: { directory: mode === "delegate-foreign-session" ? root : project }, model: { providerID: "stub", id: "model" } } });
|
|
45
|
+
}
|
|
46
|
+
return Response.json({ data: {} });
|
|
47
|
+
} });
|
|
48
|
+
async function registerChild(token: string, body: any) {
|
|
49
|
+
const { resolveToken } = await import("./auth"), a = resolveToken(token);
|
|
50
|
+
if (!a?.tokenId || mode === "refuse-register") return false;
|
|
51
|
+
const { McpServer } = await import("@modelcontextprotocol/sdk/server/mcp.js"), { registerTools } = await import("./tools");
|
|
52
|
+
const handlers: Record<string, any> = {}, mcp = new McpServer({ name: "project-registration-fixture", version: "0" }), tool = mcp.tool.bind(mcp);
|
|
53
|
+
(mcp as any).tool = (name: string, desc: string, schema: any, handler: any) => { handlers[name] = handler; return tool(name, desc, schema, handler); };
|
|
54
|
+
registerTools(mcp, undefined, net, a.user.user_id, body.alias, true, a.tokenId);
|
|
55
|
+
try {
|
|
56
|
+
const response = await handlers.report_status({ resume_id: `project_${body.node_id}`, alias: body.alias, node_id: body.node_id,
|
|
57
|
+
session_id: body.session_id, status: "idle", agent: "synthetic-project-child" });
|
|
58
|
+
const ok = JSON.parse(response.content[0].text).ok !== false;
|
|
59
|
+
// Match the fixture receipt clock to Bun's virtual clock in the long-human-
|
|
60
|
+
// selection test. SQLite datetime('now') otherwise uses a different clock.
|
|
61
|
+
if (ok && mode === "virtual-time") db.run("UPDATE sessions SET last_seen_at=?1 WHERE node_id=?2 AND session_id=?3",
|
|
62
|
+
[new Date(Date.now()).toISOString(), body.node_id, body.session_id]);
|
|
63
|
+
if (ok) registrations++; return ok;
|
|
64
|
+
} finally { await mcp.close(); }
|
|
65
|
+
}
|
|
66
|
+
const api = async (token: string, path: string, value?: any) => {
|
|
67
|
+
const r = await fetch(`${base}${path}`, { method: value === undefined ? "GET" : "POST", headers: { authorization: `Bearer ${token}`, "content-type": "application/json" },
|
|
68
|
+
...(value === undefined ? {} : { body: JSON.stringify(value) }) }); return { status: r.status, body: await r.json() as any };
|
|
69
|
+
};
|
|
70
|
+
const poll = (id: string, token = human.token, network = net) => api(token, `${P}/${id}?network_id=${network}`);
|
|
71
|
+
const selection = () => ({ network_id: net, source_node_id: "p_source", daemon_node_id: "p_daemon" });
|
|
72
|
+
const authorityPath = join(daemonDir, ".anet", "opencode-directory-authorities.json");
|
|
73
|
+
function grant(allow = true) { writeFileSync(authorityPath, JSON.stringify({ version: 1, grants: [{ server_id: serverId, network_id: net, source_node_id: "p_source",
|
|
74
|
+
directories: [project], allow_new_session: allow, opencode_unsafe_tools: allow }] }), { mode: 0o600 }); }
|
|
75
|
+
function makeWorker() {
|
|
76
|
+
const hubUrl = `http://127.0.0.1:${proxy.port}`;
|
|
77
|
+
return createSessionSourceTransportWorker({ hubUrl, home, daemonWorkDir: daemonDir, directoryEnabled: true, projectEnabled: workerEnabled, attachEnabled: workerEnabled, forkEnabled: false,
|
|
78
|
+
nativeLaunch: nativeLaunchOverride ?? { command: process.execPath, argsPrefix: [join(import.meta.dir, "../../agent-node/src/runtime/fixtures/source-resume-child.ts")],
|
|
79
|
+
env: { HOME: home, PATH: "/usr/local/bin:/usr/bin:/bin", ...(mode === "lost-health" ? { SOURCE_TEST_DROP_HEALTH: "1" } : {}) }, timeoutMs: 1500 },
|
|
80
|
+
pin: createSessionControlPin({ hubUrl, token: daemon.token, nodeId: "p_daemon", networkId: net, epoch: 0, currentEpoch: () => currentEpoch,
|
|
81
|
+
currentToken: () => daemon.token, signal: new AbortController().signal, fetch: (async (...args: any[]) => (fetchOverride ?? fetch)(...args)) as typeof fetch }) });
|
|
82
|
+
}
|
|
83
|
+
beforeAll(async () => {
|
|
84
|
+
({ db } = await import("./db")); const { register, createNetworkTokenForNode } = await import("./auth");
|
|
85
|
+
register("project_bootstrap", "Fixture-Project-4150!"); human = register("project_owner", "Fixture-Project-4150!"); outsider = register("project_outsider", "Fixture-Project-4150!");
|
|
86
|
+
net = human.network_id; daemon = createNetworkTokenForNode(human.user.user_id, net, "project-daemon", "p_daemon"); source = createNetworkTokenForNode(human.user.user_id, net, "project-source", "p_source");
|
|
87
|
+
expect(daemon.ok && source.ok).toBe(true);
|
|
88
|
+
db.run("UPDATE nodes SET runtime='opencode-cli',config_snapshot=?1 WHERE node_id='p_source'", [JSON.stringify({ flags: { opencodeGeneration: "v2", opencodeMode: "copresence" } })]);
|
|
89
|
+
db.run("INSERT INTO sessions (resume_id,alias,node_id,network_id,env_transport,last_seen_at) VALUES ('project_daemon','project-daemon','p_daemon',?1,'loopback',datetime('now'))", [net]);
|
|
90
|
+
for (const d of [home, daemonDir, project, join(home, ".anet"), join(daemonDir, ".anet"), join(project, ".anet"), join(project, ".anet", "nodes"), join(project, ".anet", "nodes", "source")]) mkdirSync(d, { mode: 0o700 });
|
|
91
|
+
writeFileSync(join(project, ".anet", "nodes", "source", "opencode-launch-health.json"), JSON.stringify({ generation: "ses_Source", bridge: { pid: process.pid } }), { mode: 0o600 });
|
|
92
|
+
writeFileSync(join(home, ".anet", "password"), "synthetic-project-password", { mode: 0o600 });
|
|
93
|
+
writeFileSync(join(home, ".anet", "opencode-shared-server.json"), JSON.stringify({ url: `http://127.0.0.1:${native.port}`, passwordFile: join(home, ".anet", "password") }), { mode: 0o600 });
|
|
94
|
+
for (const g of gates) process.env[g] = "1"; ({ bootServer: boot } = await import("./server"));
|
|
95
|
+
});
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
setSystemTime(); posts = 0; registrations = 0; serial++; mode = "ok"; nativeCalls = []; postBodies = []; sessions = new Set(); fetchOverride = undefined; workerEnabled = true; currentEpoch = 0;
|
|
98
|
+
nativeLaunchOverride = undefined;
|
|
99
|
+
db.run("UPDATE network_members SET role='owner' WHERE user_id=?1 AND network_id=?2", [human.user.user_id, net]);
|
|
100
|
+
db.run("UPDATE nodes SET config_snapshot=?1 WHERE node_id='p_daemon'", [JSON.stringify({ role: "host_supervisor", daemon_capabilities: { source_directory_read: DIR_CAP, project_new_session: CAP, session_attach: ACAP } })]);
|
|
101
|
+
grant(); hub = boot({ port: 0, hostname: "127.0.0.1" }); base = `http://127.0.0.1:${hub.port}`;
|
|
102
|
+
proxy = Bun.serve({ hostname: "127.0.0.1", port: 0, async fetch(r) {
|
|
103
|
+
const u = new URL(r.url);
|
|
104
|
+
if (u.pathname === "/fixture-register") {
|
|
105
|
+
const ok = await registerChild(r.headers.get("authorization")?.replace(/^Bearer /, "") ?? "", await r.json()); return Response.json({ ok }, { status: ok ? 200 : 403 });
|
|
106
|
+
}
|
|
107
|
+
return fetch(`${base}${u.pathname}${u.search}`, { method: r.method, headers: r.headers, ...(r.method === "GET" ? {} : { body: await r.text() }), redirect: "error" });
|
|
108
|
+
} }); worker = makeWorker();
|
|
109
|
+
});
|
|
110
|
+
afterEach(async () => { setSystemTime(); await worker.stop(); proxy.stop(true); hub.stop(true); if (cliFixtureRoot) { rmSync(cliFixtureRoot, { recursive: true, force: true }); cliFixtureRoot = null; } });
|
|
111
|
+
afterAll(() => { native.stop(true); db.close(); rmSync(root, { recursive: true, force: true }); gates.forEach((g, i) => { if (previous[i] === undefined) delete process.env[g]; else process.env[g] = previous[i]; }); });
|
|
112
|
+
async function directory() {
|
|
113
|
+
await worker.tick(); const q = await api(human.token, D, selection()); expect(q.status).toBe(200); await worker.tick();
|
|
114
|
+
const first = (await api(human.token, `${D}/${q.body.request_id}?network_id=${net}`)).body;
|
|
115
|
+
const q2 = await api(human.token, D, { ...selection(), server_id: serverId, selection_scope: first.request_id }); expect(q2.status).toBe(200); await worker.tick();
|
|
116
|
+
const s = (await api(human.token, `${D}/${q2.body.request_id}?network_id=${net}`)).body; expect(s.status).toBe("ready"); expect(s.snapshot.projects).toHaveLength(1); return s;
|
|
117
|
+
}
|
|
118
|
+
const value = (s: any, intent = `new-${serial}`) => ({ selection_scope: s.request_id, snapshot_id: s.snapshot.snapshot_id,
|
|
119
|
+
project_id: s.snapshot.projects[0].project_id, child_name: `project-child-${serial}`, intent_id: intent });
|
|
120
|
+
function delegateGrant(override = {}) {
|
|
121
|
+
writeFileSync(authorityPath, JSON.stringify({ version: 1, grants: [{ server_id: serverId, network_id: net, source_node_id: "p_source",
|
|
122
|
+
directories: [project], opencode_unsafe_tools: true, allow_attach_existing: { enabled: true, policy_id: randomUUID(), daemon_id: "p_daemon",
|
|
123
|
+
directories: [project], expires_at: Date.now() + 86400000, grant_ttl_ms: 120000, ...override } }] }), { mode: 0o600 });
|
|
124
|
+
}
|
|
125
|
+
test("delegated existing-directory policy derives exact one-shot grant from real GET/OS pin, concurrent children share one bridge, unknown never regenerates", async () => {
|
|
126
|
+
const id = `ses_Delegate${serial}`; sessions.add(id); delegateGrant(); const s = await directory();
|
|
127
|
+
const value = (n: number) => ({ selection_scope: s.request_id, snapshot_id: s.snapshot.snapshot_id, session_id: s.snapshot.sessions[0].session_id,
|
|
128
|
+
child_name: `delegated-${serial}-${n}`, intent_id: `delegated-${serial}-${n}` });
|
|
129
|
+
const [a, b] = await Promise.all([api(human.token, P, value(1)), api(human.token, P, value(2))]); expect(a.status).toBe(200); expect(b.status).toBe(200);
|
|
130
|
+
const tokensBefore = db.get("SELECT COUNT(*) n FROM api_tokens").n; await worker.tick();
|
|
131
|
+
const receipts = await Promise.all([poll(a.body.request_id), poll(b.body.request_id)]);
|
|
132
|
+
expect(receipts.map(r => r.body.status).sort()).toEqual(["registration_confirmed", "unknown_rotation_required"]);
|
|
133
|
+
expect(db.get("SELECT COUNT(*) n FROM api_tokens").n).toBe(tokensBefore + 1); expect(registrations).toBe(1);
|
|
134
|
+
const dir = join(project, ".anet", "session-attach-grants"), paths = readdirSync(dir);
|
|
135
|
+
const records = paths.map(p => readFileSync(join(dir, p), "utf8")).filter(t => JSON.parse(t).derived_grant?.intent_id?.startsWith(`delegated-${serial}-`));
|
|
136
|
+
expect(records).toHaveLength(2);
|
|
137
|
+
for (const text of records) { const c = JSON.parse(text), row = db.get("SELECT * FROM session_project_creates WHERE request_id=?1", c.request_id);
|
|
138
|
+
expect(c.session_id).toBe(id); expect(c.derived_grant.server_pid).toBe(process.pid); expect(c.derived_grant.expires_at).toBe(row.accepted_at + 120000);
|
|
139
|
+
expect(c.derived_grant.intent_id).toBe(row.intent_id); expect(text).not.toContain("synthetic-project-password"); }
|
|
140
|
+
await worker.tick(); for (const n of [1, 2]) expect((await api(human.token, P, value(n))).body.request_id).toBe([a, b][n - 1].body.request_id);
|
|
141
|
+
expect(readdirSync(dir)).toEqual(paths); expect(registrations).toBe(1); expect(nativeCalls.filter(x => x.startsWith("POST "))).toEqual([]);
|
|
142
|
+
const accepted = db.get("SELECT accepted_at FROM session_project_creates WHERE request_id=?1", a.body.request_id).accepted_at;
|
|
143
|
+
setSystemTime(accepted + 120001); await worker.tick();
|
|
144
|
+
expect(readdirSync(dir)).toEqual(paths); expect(registrations).toBe(1); expect(db.get("SELECT COUNT(*) n FROM api_tokens").n).toBe(tokensBefore + 1);
|
|
145
|
+
}, 15000);
|
|
146
|
+
for (const invalid of ["disabled", "expired", "wrong-daemon", "out-of-scope-directory", "unbounded-ttl", "foreign-native-session"]) test(`delegated policy ${invalid} cannot authorize or enlarge scope`, async () => {
|
|
147
|
+
const id = `ses_BadDelegate${serial}`; sessions.add(id);
|
|
148
|
+
delegateGrant(invalid === "disabled" ? { enabled: false } : invalid === "expired" ? { expires_at: Date.now() - 1 }
|
|
149
|
+
: invalid === "wrong-daemon" ? { daemon_id: "other" } : invalid === "out-of-scope-directory" ? { directories: [root] }
|
|
150
|
+
: invalid === "unbounded-ttl" ? { grant_ttl_ms: 300001 } : {});
|
|
151
|
+
const s = await directory(); if (invalid === "foreign-native-session") mode = "delegate-foreign-session";
|
|
152
|
+
const tokens = db.get("SELECT COUNT(*) n FROM api_tokens").n, q = await api(human.token, P, { selection_scope: s.request_id,
|
|
153
|
+
snapshot_id: s.snapshot.snapshot_id, session_id: s.snapshot.sessions[0].session_id, child_name: `bad-delegate-${serial}`, intent_id: `bad-delegate-${serial}` });
|
|
154
|
+
await worker.tick(); expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required");
|
|
155
|
+
expect(registrations).toBe(0); expect(db.get("SELECT COUNT(*) n FROM api_tokens").n).toBe(tokens); expect(nativeCalls.filter(x => x.startsWith("POST "))).toEqual([]);
|
|
156
|
+
});
|
|
157
|
+
for (const permission of ["read_only", "new_only"]) test(`${permission} private directory permission cannot implicitly delegate attach`, async () => {
|
|
158
|
+
sessions.add(`ses_NoDelegate${serial}`);
|
|
159
|
+
writeFileSync(authorityPath, JSON.stringify({ version: 1, grants: [{ server_id: serverId, network_id: net, source_node_id: "p_source",
|
|
160
|
+
directories: [project], opencode_unsafe_tools: true, ...(permission === "new_only" ? { allow_new_session: true } : {}) }] }), { mode: 0o600 });
|
|
161
|
+
const s = await directory(), tokens = db.get("SELECT COUNT(*) n FROM api_tokens").n;
|
|
162
|
+
const value = { selection_scope: s.request_id, snapshot_id: s.snapshot.snapshot_id, session_id: s.snapshot.sessions[0].session_id,
|
|
163
|
+
child_name: `not-delegated-${serial}`, intent_id: `not-delegated-${serial}` };
|
|
164
|
+
expect((await api(human.token, P, { ...value, allow_attach_existing: { enabled: true } })).status).toBe(400);
|
|
165
|
+
const q = await api(human.token, P, value); await worker.tick();
|
|
166
|
+
expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required"); expect(registrations).toBe(0);
|
|
167
|
+
expect(db.get("SELECT COUNT(*) n FROM api_tokens").n).toBe(tokens); expect(nativeCalls.filter(x => x.startsWith("POST "))).toEqual([]);
|
|
168
|
+
});
|
|
169
|
+
function attachGrant(id: string, override = {}) {
|
|
170
|
+
const observed = observeHostSharedServe(`http://127.0.0.1:${native.port}`);
|
|
171
|
+
expect(observed.ok).toBe(true); if (!observed.ok) throw Error("fixture_observation_failed");
|
|
172
|
+
writeFileSync(authorityPath, JSON.stringify({ version: 1, grants: [{ server_id: serverId, network_id: net, source_node_id: "p_source",
|
|
173
|
+
directories: [project], opencode_unsafe_tools: true, attach_sessions: [{ grant_id: randomUUID(), daemon_id: "p_daemon", directory: project,
|
|
174
|
+
session_id: id, server_pid: observed.processEvidence.pid, server_start_ticks: observed.processEvidence.startTicks, expires_at: Date.now() + 120000, ...override }] }] }), { mode: 0o600 });
|
|
175
|
+
}
|
|
176
|
+
test("HTTP attach five-field opaque intent -> existing exact child registration; zero native writes and single mint/launch", async () => {
|
|
177
|
+
const id = `ses_Attach${serial}`; sessions.add(id); attachGrant(id);
|
|
178
|
+
const s = await directory(), v = { selection_scope: s.request_id, snapshot_id: s.snapshot.snapshot_id,
|
|
179
|
+
session_id: s.snapshot.sessions[0].session_id, child_name: `attach-child-${serial}`, intent_id: `attach-${serial}` };
|
|
180
|
+
const q = await api(human.token, P, v); expect(q.status).toBe(200); expect(q.body.session_creation).toBe("not_performed");
|
|
181
|
+
expect(q.body.operation_kind).toBe("attach_existing_session"); await worker.tick();
|
|
182
|
+
expect((await poll(q.body.request_id)).body.status).toBe("registration_confirmed");
|
|
183
|
+
expect(registrations).toBe(1); const count = db.get("SELECT COUNT(*) n FROM api_tokens").n;
|
|
184
|
+
expect((await api(human.token, P, v)).body.request_id).toBe(q.body.request_id); await worker.tick();
|
|
185
|
+
expect(db.get("SELECT COUNT(*) n FROM api_tokens").n).toBe(count); expect(registrations).toBe(1);
|
|
186
|
+
expect(nativeCalls.filter(x => x.startsWith("POST "))).toEqual([]);
|
|
187
|
+
const row = db.get("SELECT * FROM session_project_creates WHERE request_id=?1", q.body.request_id);
|
|
188
|
+
expect(row.session_id).toBe(id); expect(row.selected_session_id).toBe(v.session_id); expect(row.project_id).toStartWith("oprj_");
|
|
189
|
+
expect((await api(outsider.token, P, v)).status).toBe(403);
|
|
190
|
+
expect((await api(human.token, P, { ...v, session_id: id })).status).toBe(400);
|
|
191
|
+
expect((await api(human.token, P, { ...v, project_id: row.project_id })).status).toBe(400);
|
|
192
|
+
const copiedDaemon = join(root, `copied-daemon-${serial}`); mkdirSync(copiedDaemon, { mode: 0o700 }); mkdirSync(join(copiedDaemon, ".anet"), { mode: 0o700 });
|
|
193
|
+
writeFileSync(join(copiedDaemon, ".anet", "opencode-directory-authorities.json"), readFileSync(authorityPath), { mode: 0o600 });
|
|
194
|
+
const copiedReader = createSourceDirectoryReader({ home, daemonWorkDir: copiedDaemon, networkId: net, daemonId: "p_daemon", attachSelectionEnabled: true });
|
|
195
|
+
const readTask = { request_id: `srcdir_${randomUUID()}`, network_id: net, source_node_id: "p_source", daemon_node_id: "p_daemon", server_id: serverId, expires_at: Date.now() + 30000 };
|
|
196
|
+
const copiedSnapshot = await copiedReader.read(readTask), accepted = Date.now();
|
|
197
|
+
await expect(copiedReader.selectProject({ request_id: `prjc_${randomUUID()}`, network_id: net, source_node_id: "p_source", daemon_node_id: "p_daemon",
|
|
198
|
+
operation_kind: "attach_existing_session", selection_scope: readTask.request_id, snapshot_id: copiedSnapshot.snapshot_id,
|
|
199
|
+
project_id: copiedSnapshot.projects[0].project_id, selected_session_id: copiedSnapshot.sessions[0].session_id,
|
|
200
|
+
child_name: "copied-grant-child", intent_id: "copied-grant", accepted_at: accepted, expires_at: accepted + 300000 })).rejects.toThrow("project_attach_grant_consumed");
|
|
201
|
+
}, 15000);
|
|
202
|
+
test("read/new-session grant cannot authorize attach; consumed exact grant cannot assign another child; occupied legacy bridge refuses", async () => {
|
|
203
|
+
const id = `ses_Denied${serial}`; sessions.add(id);
|
|
204
|
+
const submit = async (suffix: string) => { const s = await directory(); return api(human.token, P, { selection_scope: s.request_id,
|
|
205
|
+
snapshot_id: s.snapshot.snapshot_id, session_id: s.snapshot.sessions[0].session_id, child_name: `denied-${serial}-${suffix}`, intent_id: `deny-${serial}-${suffix}` }); };
|
|
206
|
+
let q = await submit("read"); await worker.tick(); expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required");
|
|
207
|
+
attachGrant(id); q = await submit("first"); await worker.tick(); expect((await poll(q.body.request_id)).body.status).toBe("registration_confirmed");
|
|
208
|
+
q = await submit("second"); await worker.tick(); expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required");
|
|
209
|
+
sessions.clear(); sessions.add("ses_Source"); attachGrant("ses_Source");
|
|
210
|
+
q = await submit("occupied"); await worker.tick(); expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required");
|
|
211
|
+
expect(nativeCalls.filter(x => x.startsWith("POST "))).toEqual([]); expect(registrations).toBe(1);
|
|
212
|
+
}, 15000);
|
|
213
|
+
for (const invalid of ["expired", "wrong-daemon", "wrong-incarnation", "wrong-directory"]) test(`HTTP attach ${invalid} finite grant refuses before mint/launch, zero native writes`, async () => {
|
|
214
|
+
const id = `ses_Grant${serial}`; sessions.add(id);
|
|
215
|
+
attachGrant(id, invalid === "expired" ? { expires_at: Date.now() - 1 } : invalid === "wrong-daemon" ? { daemon_id: "other" }
|
|
216
|
+
: invalid === "wrong-incarnation" ? { server_start_ticks: -1 } : { directory: root });
|
|
217
|
+
const s = await directory(), v = { selection_scope: s.request_id, snapshot_id: s.snapshot.snapshot_id, session_id: s.snapshot.sessions[0].session_id,
|
|
218
|
+
child_name: `bad-grant-${serial}`, intent_id: `bad-grant-${serial}` };
|
|
219
|
+
const tokens = db.get("SELECT COUNT(*) n FROM api_tokens").n, q = await api(human.token, P, v); expect(q.status).toBe(200);
|
|
220
|
+
await worker.tick(); expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required");
|
|
221
|
+
expect(db.get("SELECT COUNT(*) n FROM api_tokens").n).toBe(tokens); expect(registrations).toBe(0); expect(nativeCalls.filter(x => x.startsWith("POST "))).toEqual([]);
|
|
222
|
+
});
|
|
223
|
+
test("HTTP attach default gate, strict fields, current create/visibility and daemon declaration fail closed", async () => {
|
|
224
|
+
const id = `ses_Permissions${serial}`; sessions.add(id); attachGrant(id); const s = await directory();
|
|
225
|
+
const v = { selection_scope: s.request_id, snapshot_id: s.snapshot.snapshot_id, session_id: s.snapshot.sessions[0].session_id, child_name: `permission-${serial}`, intent_id: `permission-${serial}` };
|
|
226
|
+
for (const token of [daemon.token, source.token, outsider.token]) expect((await api(token, P, v)).status).not.toBe(200);
|
|
227
|
+
for (const extra of [{ session_id: id }, { path: project }, { token: "fake" }, { url: "http://127.0.0.1:1" }, { daemon_node_id: "p_daemon" }, { session_id: `oses_${randomUUID()}` }])
|
|
228
|
+
expect((await api(human.token, P, { ...v, ...extra })).status).not.toBe(200);
|
|
229
|
+
db.run("UPDATE network_members SET role='viewer' WHERE user_id=?1 AND network_id=?2", [human.user.user_id, net]);
|
|
230
|
+
expect((await api(human.token, P, v)).status).toBe(403);
|
|
231
|
+
db.run("UPDATE network_members SET role='owner' WHERE user_id=?1 AND network_id=?2", [human.user.user_id, net]);
|
|
232
|
+
db.run("UPDATE nodes SET config_snapshot=?1 WHERE node_id='p_daemon'", [JSON.stringify({ role: "host_supervisor", daemon_capabilities: { source_directory_read: DIR_CAP, project_new_session: CAP } })]);
|
|
233
|
+
expect((await api(human.token, P, v)).status).toBe(403);
|
|
234
|
+
delete process.env.COMMHUB_SESSION_ATTACH_PREVIEW; const gated = boot({ hostname: "127.0.0.1", port: 0 });
|
|
235
|
+
try { expect((await fetch(`http://127.0.0.1:${gated.port}${P}`, { method: "POST", headers: { authorization: `Bearer ${human.token}`, "content-type": "application/json" }, body: JSON.stringify(v) })).status).toBe(404); }
|
|
236
|
+
finally { gated.stop(true); process.env.COMMHUB_SESSION_ATTACH_PREVIEW = "1"; }
|
|
237
|
+
expect(nativeCalls.filter(x => x.startsWith("POST "))).toEqual([]);
|
|
238
|
+
});
|
|
239
|
+
for (const delegated of [false, true]) test(`HTTP ${delegated ? "delegated" : "manual"} attach lost one-shot delivery + worker/Hub reconstruction stays unknown, no remint/relaunch or native mutation`, async () => {
|
|
240
|
+
const id = `ses_Lost${serial}`; sessions.add(id); if (delegated) delegateGrant(); else attachGrant(id); const s = await directory();
|
|
241
|
+
const v = { selection_scope: s.request_id, snapshot_id: s.snapshot.snapshot_id, session_id: s.snapshot.sessions[0].session_id, child_name: `lost-attach-${serial}`, intent_id: `lost-attach-${serial}` };
|
|
242
|
+
const q = await api(human.token, P, v); let dropped = false;
|
|
243
|
+
fetchOverride = (async (input: any, init: any) => { const response = await fetch(input, init);
|
|
244
|
+
if (!dropped && String(input).endsWith(`${P}/pull`) && (await response.clone().json()).task?.phase === "deliver") { dropped = true; throw Error("synthetic_attach_delivery_lost"); } return response; }) as typeof fetch;
|
|
245
|
+
await expect(worker.tick()).rejects.toThrow(); const count = db.get("SELECT COUNT(*) n FROM api_tokens").n;
|
|
246
|
+
const grantDir = join(project, ".anet", "session-attach-grants"), grantFiles = readdirSync(grantDir);
|
|
247
|
+
await worker.stop(); worker = makeWorker(); hub.stop(true); hub = boot({ hostname: "127.0.0.1", port: 0 }); base = `http://127.0.0.1:${hub.port}`;
|
|
248
|
+
expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required"); expect((await api(human.token, P, v)).body.request_id).toBe(q.body.request_id);
|
|
249
|
+
await worker.tick(); expect(db.get("SELECT COUNT(*) n FROM api_tokens").n).toBe(count); expect(registrations).toBe(0); expect(nativeCalls.filter(x => x.startsWith("POST "))).toEqual([]);
|
|
250
|
+
expect(readdirSync(grantDir)).toEqual(grantFiles);
|
|
251
|
+
});
|
|
252
|
+
test("actual HTTP directory -> project intent -> one native empty create -> exact shared resume child -> real registration confirmation; same intent stays single", async () => {
|
|
253
|
+
const s = await directory(), v = value(s), q = await api(human.token, P, v); expect(q.status).toBe(200);
|
|
254
|
+
expect((await api(human.token, P, v)).body.request_id).toBe(q.body.request_id);
|
|
255
|
+
await worker.tick(); const r = await poll(q.body.request_id); expect(r.body.status).toBe("registration_confirmed");
|
|
256
|
+
expect(r.body.registration_is_health).toBe(false); expect(r.body.native_acceptance).toBe("not_verified"); expect(posts).toBe(1); expect(registrations).toBe(1);
|
|
257
|
+
expect(postBodies).toEqual([{ location: { directory: project } }]);
|
|
258
|
+
expect(nativeCalls.filter(x => x.startsWith("POST "))).toEqual(["POST /api/session"]);
|
|
259
|
+
expect((await api(human.token, P, v)).body.request_id).toBe(q.body.request_id); await worker.tick(); expect(posts).toBe(1);
|
|
260
|
+
const row = db.get("SELECT * FROM session_project_creates WHERE request_id=?1", q.body.request_id);
|
|
261
|
+
const config = JSON.parse(readFileSync(join(project, ".anet", "nodes", v.child_name, "config.json"), "utf8"));
|
|
262
|
+
expect(config.sessionId).toBe(row.session_id); expect(config.sourceDelivery.operation_kind).toBe("project_new_session");
|
|
263
|
+
expect(db.get("SELECT expires_at FROM api_tokens WHERE token_id=?1", row.child_token_id).expires_at).toBeNull();
|
|
264
|
+
expect(JSON.stringify(row)).not.toContain(config.token); expect(JSON.stringify(r.body)).not.toContain("ses_"); expect(JSON.stringify(r.body)).not.toContain(project);
|
|
265
|
+
const health = JSON.parse(readFileSync(join(project, ".anet", "nodes", v.child_name, "source-resume-health.json"), "utf8"));
|
|
266
|
+
await worker.stop(); expect(() => process.kill(health.pid, 0)).toThrow(); expect(() => process.kill(process.pid, 0)).not.toThrow();
|
|
267
|
+
expect(JSON.parse(readFileSync(join(project, ".anet", "nodes", "source", "opencode-launch-health.json"), "utf8")).generation).toBe("ses_Source");
|
|
268
|
+
expect((await poll(q.body.request_id)).body.status).toBe("registration_confirmed"); // receipt, NOT ongoing online
|
|
269
|
+
}, 15000);
|
|
270
|
+
for (const operation of ["new", "manual", "delegated"]) test(`${operation} HTTP chain uses actual anet CLI -> paired agent-node CLI -> exact shared resume -> actual Hub registration with synthetic native package`, async () => {
|
|
271
|
+
const attach = operation !== "new";
|
|
272
|
+
await worker.stop(); const prefix = mkdtempSync(join(testWorkRoot(), "project-cli-fixture-")); cliFixtureRoot = prefix;
|
|
273
|
+
const pkg = join(prefix, "node_modules", "@opencode", "cli"); mkdirSync(join(pkg, "bin"), { recursive: true, mode: 0o700 });
|
|
274
|
+
mkdirSync(join(prefix, "bin"), { mode: 0o700 }); mkdirSync(join(prefix, "safe"), { mode: 0o700 });
|
|
275
|
+
writeFileSync(join(pkg, "package.json"), JSON.stringify({ name: "@opencode/cli", version: "2.0.22", bin: { opencode: "bin/opencode.exe" } }));
|
|
276
|
+
writeFileSync(join(pkg, "bin", "opencode.exe"), "#!/bin/sh\nif [ \"$1\" = \"--version\" ]; then echo 'opencode v2.0.22'; exit 0; fi\nexit 77\n", { mode: 0o700 });
|
|
277
|
+
symlinkSync(join(pkg, "bin", "opencode.exe"), join(prefix, "bin", "opencode"));
|
|
278
|
+
const nodePackage = join(prefix, "node_modules", "@sleep2agi", "agent-node"); mkdirSync(nodePackage, { recursive: true, mode: 0o700 });
|
|
279
|
+
writeFileSync(join(nodePackage, "package.json"), readFileSync(join(import.meta.dir, "../../agent-node/package.json")));
|
|
280
|
+
for (const dep of ["@anthropic-ai", "@openai", "node-pty"]) symlinkSync(join(import.meta.dir, "../../agent-node/node_modules", dep), join(prefix, "node_modules", dep));
|
|
281
|
+
const dist = join(nodePackage, "dist"), built = await Bun.build({ entrypoints: [join(import.meta.dir, "../../agent-node/src/cli.ts")], outdir: dist, target: "bun",
|
|
282
|
+
external: ["@anthropic-ai/claude-agent-sdk", "@openai/codex-sdk", "node-pty"] }); expect(built.success).toBe(true);
|
|
283
|
+
nativeLaunchOverride = { command: process.execPath, argsPrefix: [join(import.meta.dir, "../../agent-network/bin/cli.ts")],
|
|
284
|
+
env: { PATH: `${join(prefix, "bin")}:/usr/local/bin:/usr/bin:/bin`, HOME: home, ANET_AGENT_NODE_BIN: join(dist, "cli.js"), ANET_OPENCODE_SAFE_BASE: join(prefix, "safe") }, timeoutMs: 7000 };
|
|
285
|
+
const existing = `ses_ActualAttach${serial}`;
|
|
286
|
+
if (attach) { sessions.add(existing); if (operation === "delegated") delegateGrant(); else attachGrant(existing); }
|
|
287
|
+
worker = makeWorker(); const s = await directory(), v = attach ? { selection_scope: s.request_id, snapshot_id: s.snapshot.snapshot_id,
|
|
288
|
+
session_id: s.snapshot.sessions[0].session_id, child_name: `actual-attach-${serial}`, intent_id: `actual-attach-${serial}` } : value(s);
|
|
289
|
+
const q = await api(human.token, P, v); expect(q.status).toBe(200);
|
|
290
|
+
await worker.tick(); const r = await poll(q.body.request_id); expect(r.body.status).toBe("registration_confirmed"); expect(posts).toBe(attach ? 0 : 1);
|
|
291
|
+
const row = db.get("SELECT * FROM session_project_creates WHERE request_id=?1", q.body.request_id);
|
|
292
|
+
expect(db.get("SELECT session_id FROM sessions WHERE node_id=?1 ORDER BY last_seen_at DESC LIMIT 1", row.child_node_id).session_id).toBe(row.session_id);
|
|
293
|
+
expect(nativeCalls.filter(x => x.startsWith("POST "))).toEqual(attach ? [] : ["POST /api/session"]);
|
|
294
|
+
if (attach) {
|
|
295
|
+
expect(row.session_id).toBe(existing); const count = db.get("SELECT COUNT(*) n FROM api_tokens").n;
|
|
296
|
+
expect((await api(human.token, P, v)).body.request_id).toBe(q.body.request_id); await worker.tick();
|
|
297
|
+
expect(db.get("SELECT COUNT(*) n FROM api_tokens").n).toBe(count);
|
|
298
|
+
const healthPath = join(project, ".anet", "nodes", v.child_name, "source-resume-health.json");
|
|
299
|
+
const h = JSON.parse(readFileSync(healthPath, "utf8")); expect(h.session_id).toBe(existing);
|
|
300
|
+
await worker.stop(); expect(() => process.kill(h.pid, 0)).toThrow(); expect(sessions.has(existing)).toBe(true);
|
|
301
|
+
}
|
|
302
|
+
}, 20000);
|
|
303
|
+
test("HTTP raw inputs, foreign caller/network, wrong snapshot/project/daemon, node caller, intent conflict and stale selection fail closed", async () => {
|
|
304
|
+
const s = await directory(), v = value(s);
|
|
305
|
+
for (const token of [daemon.token, source.token, outsider.token]) expect((await api(token, P, v)).status).not.toBe(200);
|
|
306
|
+
for (const extra of [{ path: project }, { url: "http://127.0.0.1:1" }, { token: "forged" }, { network_id: "other" }, { daemon_node_id: "p_source" },
|
|
307
|
+
{ snapshot_id: `snap_${randomUUID()}` }, { project_id: `oprj_${randomUUID()}` }, { project_id: `oses_${randomUUID()}` }, { selection_scope: `srcdir_${randomUUID()}` }]) {
|
|
308
|
+
expect((await api(human.token, P, { ...v, ...extra })).status).not.toBe(200);
|
|
309
|
+
}
|
|
310
|
+
const q = await api(human.token, P, v); expect(q.status).toBe(200);
|
|
311
|
+
expect((await api(human.token, P, { ...v, child_name: "different" })).status).not.toBe(200);
|
|
312
|
+
expect((await poll(q.body.request_id, outsider.token)).status).toBe(403); expect((await poll(q.body.request_id, human.token, "other")).status).toBe(403);
|
|
313
|
+
db.run("UPDATE nodes SET config_snapshot='{}' WHERE node_id='p_daemon'");
|
|
314
|
+
expect((await api(human.token, P, { ...v, intent_id: "wrong-daemon" })).status).toBe(403); expect(posts).toBe(0);
|
|
315
|
+
});
|
|
316
|
+
test("project selection remains usable for ten minutes, not thirty seconds; accepted operation has its own five-minute deadline", async () => {
|
|
317
|
+
const s = await directory(), v = value(s), at = s.expires_at + 120000; setSystemTime(at);
|
|
318
|
+
// Refresh the SAME process declaration; no native writes or user re-selection.
|
|
319
|
+
await worker.tick(); expect((await api(human.token, `${D}/${s.request_id}?network_id=${net}`)).status).toBe(403);
|
|
320
|
+
const q = await api(human.token, P, v); expect(q.status).toBe(200); expect(q.body.accepted_at).toBe(at); expect(q.body.expires_at).toBe(at + 300000);
|
|
321
|
+
setSystemTime(s.snapshot.selection_expires_at + 1); await worker.tick();
|
|
322
|
+
expect((await api(human.token, P, { ...v, intent_id: "expired-new" })).status).toBe(403);
|
|
323
|
+
expect((await api(human.token, P, v)).body.request_id).toBe(q.body.request_id);
|
|
324
|
+
expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required"); expect(posts).toBe(0);
|
|
325
|
+
});
|
|
326
|
+
test("lost native create response persists unknown; same intent, worker reconstruction and Hub reconstruction never POST or mint again", async () => {
|
|
327
|
+
const s = await directory(), v = value(s), q = await api(human.token, P, v); mode = "lost-create";
|
|
328
|
+
const tokensBefore = db.get("SELECT count(*) n FROM api_tokens").n;
|
|
329
|
+
await worker.tick(); expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required"); expect(posts).toBe(1);
|
|
330
|
+
expect((await poll(q.body.request_id)).body.session_creation).toBe("unknown");
|
|
331
|
+
expect(db.get("SELECT count(*) n FROM api_tokens").n).toBe(tokensBefore);
|
|
332
|
+
expect((await api(human.token, P, v)).body.status).toBe("unknown_rotation_required");
|
|
333
|
+
await worker.stop(); worker = makeWorker(); await worker.tick(); hub.stop(true); hub = boot({ port: 0, hostname: "127.0.0.1" }); base = `http://127.0.0.1:${hub.port}`;
|
|
334
|
+
expect((await api(human.token, P, v)).body.status).toBe("unknown_rotation_required"); await worker.tick(); expect(posts).toBe(1);
|
|
335
|
+
expect(db.get("SELECT count(*) n FROM api_tokens").n).toBe(tokensBefore);
|
|
336
|
+
});
|
|
337
|
+
test("accepted near ten-minute selection deadline finishes after selection/read expiry under a separate workflow deadline", async () => {
|
|
338
|
+
const s = await directory(), v = value(s); mode = "virtual-time";
|
|
339
|
+
setSystemTime(s.snapshot.selection_expires_at - 1000); await worker.tick();
|
|
340
|
+
const q = await api(human.token, P, v); expect(q.status).toBe(200);
|
|
341
|
+
setSystemTime(s.snapshot.selection_expires_at + 60000); await worker.tick();
|
|
342
|
+
const r = await poll(q.body.request_id); expect(r.body.status).toBe("registration_confirmed"); expect(posts).toBe(1); expect(registrations).toBe(1);
|
|
343
|
+
expect((await api(human.token, P, v)).body.request_id).toBe(q.body.request_id);
|
|
344
|
+
}, 15000);
|
|
345
|
+
test("lost create ACK body can only continue original delivery, never POST or mint twice", async () => {
|
|
346
|
+
const s = await directory(), v = value(s), q = await api(human.token, P, v); let dropped = false;
|
|
347
|
+
fetchOverride = (async (input: any, init: any) => {
|
|
348
|
+
const response = await fetch(input, init);
|
|
349
|
+
if (!dropped && String(input).endsWith(`${P}/ack`) && JSON.parse(init.body).result.status === "session_ready") { dropped = true; throw Error("synthetic_ack_lost"); }
|
|
350
|
+
return response;
|
|
351
|
+
}) as typeof fetch;
|
|
352
|
+
await expect(worker.tick()).rejects.toThrow(); expect(posts).toBe(1); const tokens = db.get("SELECT count(*) n FROM api_tokens").n;
|
|
353
|
+
expect((await api(human.token, P, v)).body.status).toBe("delivery_pending"); await worker.tick();
|
|
354
|
+
expect((await poll(q.body.request_id)).body.status).toBe("registration_confirmed"); expect(posts).toBe(1); expect(db.get("SELECT count(*) n FROM api_tokens").n).toBe(tokens);
|
|
355
|
+
}, 15000);
|
|
356
|
+
test("missing native project default model fails before Session POST or credential mint, never guesses a model", async () => {
|
|
357
|
+
const s = await directory(), q = await api(human.token, P, value(s)); mode = "no-default-model";
|
|
358
|
+
const tokens = db.get("SELECT count(*) n FROM api_tokens").n; await worker.tick();
|
|
359
|
+
expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required"); expect(posts).toBe(0); expect(registrations).toBe(0);
|
|
360
|
+
expect(db.get("SELECT count(*) n FROM api_tokens").n).toBe(tokens);
|
|
361
|
+
});
|
|
362
|
+
test("lost one-shot delivery and Hub reconstruction revoke unknown credential, not remint/relaunch", async () => {
|
|
363
|
+
const s = await directory(), v = value(s), q = await api(human.token, P, v); let dropped = false;
|
|
364
|
+
fetchOverride = (async (input: any, init: any) => {
|
|
365
|
+
const response = await fetch(input, init);
|
|
366
|
+
if (!dropped && String(input).endsWith(`${P}/pull`)) { const body = await response.clone().json(); if (body.task?.phase === "deliver") { dropped = true; throw Error("synthetic_delivery_lost"); } }
|
|
367
|
+
return response;
|
|
368
|
+
}) as typeof fetch;
|
|
369
|
+
await expect(worker.tick()).rejects.toThrow(); expect(posts).toBe(1); const tokens = db.get("SELECT count(*) n FROM api_tokens").n;
|
|
370
|
+
hub.stop(true); hub = boot({ port: 0, hostname: "127.0.0.1" }); base = `http://127.0.0.1:${hub.port}`;
|
|
371
|
+
const r = await poll(q.body.request_id); expect(r.body.status).toBe("unknown_rotation_required");
|
|
372
|
+
const row = db.get("SELECT * FROM session_project_creates WHERE request_id=?1", q.body.request_id); expect(db.get("SELECT revoked_at FROM api_tokens WHERE token_id=?1", row.child_token_id).revoked_at).not.toBeNull();
|
|
373
|
+
await worker.tick(); expect(posts).toBe(1); expect(registrations).toBe(0); expect(db.get("SELECT count(*) n FROM api_tokens").n).toBe(tokens);
|
|
374
|
+
});
|
|
375
|
+
for (const invalid of ["revoked", "expired"]) test(`${invalid} initial child credential cannot launch, remint or recreate`, async () => {
|
|
376
|
+
const s = await directory(), v = value(s), q = await api(human.token, P, v); let held = false;
|
|
377
|
+
fetchOverride = (async (input: any, init: any) => {
|
|
378
|
+
const response = await fetch(input, init);
|
|
379
|
+
if (!held && String(input).endsWith(`${P}/ack`) && JSON.parse(init.body).result.status === "session_ready") { held = true; throw Error("synthetic_hold_after_create"); }
|
|
380
|
+
return response;
|
|
381
|
+
}) as typeof fetch;
|
|
382
|
+
await expect(worker.tick()).rejects.toThrow(); const row = db.get("SELECT * FROM session_project_creates WHERE request_id=?1", q.body.request_id);
|
|
383
|
+
const tokens = db.get("SELECT count(*) n FROM api_tokens").n;
|
|
384
|
+
if (invalid === "revoked") db.run("UPDATE api_tokens SET revoked_at=datetime('now') WHERE token_id=?1", [row.child_token_id]);
|
|
385
|
+
else setSystemTime(row.credential_expires_at + 1);
|
|
386
|
+
await worker.tick(); expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required"); expect(registrations).toBe(0);
|
|
387
|
+
expect(posts).toBe(1); expect(db.get("SELECT count(*) n FROM api_tokens").n).toBe(tokens);
|
|
388
|
+
});
|
|
389
|
+
test("directory/read capability alone, absent local write policy, demotion, wrong-daemon ACK and default gate cannot create", async () => {
|
|
390
|
+
workerEnabled = false; await worker.stop(); worker = makeWorker(); const s = await directory(), v = value(s);
|
|
391
|
+
expect((await api(human.token, P, v)).status).toBe(403);
|
|
392
|
+
workerEnabled = true; await worker.stop(); worker = makeWorker(); const s2 = await directory(), v2 = value(s2); grant(false);
|
|
393
|
+
const q = await api(human.token, P, v2); expect(q.status).toBe(200); await worker.tick(); expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required"); expect(posts).toBe(0);
|
|
394
|
+
grant(); const s3 = await directory(), q3 = await api(human.token, P, { ...value(s3), intent_id: "demoted", child_name: `demoted-${serial}` });
|
|
395
|
+
expect(q3.status).toBe(200); db.run("UPDATE network_members SET role='viewer' WHERE user_id=?1 AND network_id=?2", [human.user.user_id, net]);
|
|
396
|
+
expect((await poll(q3.body.request_id)).status).toBe(403); await worker.tick(); expect(posts).toBe(0);
|
|
397
|
+
expect((await api(source.token, `${P}/ack`, { expected: { node_id: "p_daemon", network_id: net }, instance_id: randomUUID(), capability: CAP,
|
|
398
|
+
request_id: q3.body.request_id, result: { status: "session_ready", session_id: "ses_Forged" } })).status).toBe(403);
|
|
399
|
+
delete process.env.COMMHUB_PROJECT_NEW_SESSION_PREVIEW; const gated = boot({ port: 0, hostname: "127.0.0.1" });
|
|
400
|
+
try { const response = await fetch(`http://127.0.0.1:${gated.port}${P}`, { method: "POST", headers: { authorization: `Bearer ${human.token}` }, body: "{}" }); expect(response.status).toBe(404); }
|
|
401
|
+
finally { gated.stop(true); process.env.COMMHUB_PROJECT_NEW_SESSION_PREVIEW = "1"; }
|
|
402
|
+
});
|
|
403
|
+
test("failed child registration stops only new child; no Session DELETE, source stop or ordinary fallback", async () => {
|
|
404
|
+
const s = await directory(), q = await api(human.token, P, value(s)); mode = "refuse-register";
|
|
405
|
+
await worker.tick(); expect((await poll(q.body.request_id)).body.status).toBe("unknown_rotation_required"); expect(posts).toBe(1); expect(registrations).toBe(0);
|
|
406
|
+
expect(nativeCalls.filter(x => !x.startsWith("GET ") && x !== "POST /api/session")).toEqual([]);
|
|
407
|
+
expect(() => process.kill(process.pid, 0)).not.toThrow(); expect(sessions.size).toBe(1);
|
|
408
|
+
}, 15000);
|