@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,25 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
|
|
5
|
+
type PackageManifest = { version: string };
|
|
6
|
+
type PackageLock = {
|
|
7
|
+
version: string;
|
|
8
|
+
packages: { "": { version: string } };
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const readJson = <T>(name: string): T =>
|
|
12
|
+
JSON.parse(readFileSync(join(import.meta.dir, "..", name), "utf8")) as T;
|
|
13
|
+
|
|
14
|
+
describe("server package version consistency", () => {
|
|
15
|
+
const manifest = readJson<PackageManifest>("package.json");
|
|
16
|
+
const lock = readJson<PackageLock>("package-lock.json");
|
|
17
|
+
|
|
18
|
+
test("package-lock top-level version matches package.json", () => {
|
|
19
|
+
expect(lock.version).toBe(manifest.version);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("package-lock root package version matches package.json", () => {
|
|
23
|
+
expect(lock.packages[""].version).toBe(manifest.version);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
// #669 —— 父任务推断收窄的判据:**候选唯一 + 在窗口内**,且每一种拒绝都要能被数出来。
|
|
2
|
+
//
|
|
3
|
+
// 为什么这三件事要一起测:
|
|
4
|
+
// 收窄是「减少推断」,而减少在派发日志里不留痕(任务照常派出,只是没有父)。
|
|
5
|
+
// 没有 rejected 计数时,「收窄生效」与「收窄没写对」同形——两者的 7 天失败率都会降。
|
|
6
|
+
//
|
|
7
|
+
// 为什么「年龄未知」要算拒绝而不是放行:
|
|
8
|
+
// 这条约束的全部价值是「刚派不久」,而 age 未知时无法证明它成立。
|
|
9
|
+
// 放行会让这一条在最需要它的输入上失效。
|
|
10
|
+
import { test, beforeEach } from "node:test";
|
|
11
|
+
import assert from "node:assert/strict";
|
|
12
|
+
import {
|
|
13
|
+
INFER_WINDOW_MS,
|
|
14
|
+
__resetParentInferForTest,
|
|
15
|
+
decideParentInference,
|
|
16
|
+
noteInferAccepted,
|
|
17
|
+
noteInferRejected,
|
|
18
|
+
parentInferCounters,
|
|
19
|
+
} from "./parent-infer.js";
|
|
20
|
+
|
|
21
|
+
const NOW = 1_800_000_000_000;
|
|
22
|
+
|
|
23
|
+
beforeEach(() => __resetParentInferForTest());
|
|
24
|
+
|
|
25
|
+
test("唯一候选且在窗口内 ⇒ 推断到它", () => {
|
|
26
|
+
const r = decideParentInference([{ task_id: "t1", created_at_ms: NOW - 60_000 }], NOW);
|
|
27
|
+
assert.equal(r.ok, true);
|
|
28
|
+
assert.equal(r.ok && r.task_id, "t1");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("多个候选 ⇒ 不推断(挑最近一条正是挂错的来源)", () => {
|
|
32
|
+
const r = decideParentInference([
|
|
33
|
+
{ task_id: "new", created_at_ms: NOW - 10_000 },
|
|
34
|
+
{ task_id: "old", created_at_ms: NOW - 500_000 },
|
|
35
|
+
], NOW);
|
|
36
|
+
assert.equal(r.ok, false);
|
|
37
|
+
// 关键:**不是**退化成「取最新那条」
|
|
38
|
+
assert.equal(!r.ok && r.rejection.reason, "ambiguous_candidates");
|
|
39
|
+
assert.equal(!r.ok && r.rejection.candidates, 2);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
test("唯一候选但太旧 ⇒ 不推断(那是排在后面还没轮到的)", () => {
|
|
43
|
+
const r = decideParentInference(
|
|
44
|
+
[{ task_id: "t1", created_at_ms: NOW - INFER_WINDOW_MS - 1 }], NOW);
|
|
45
|
+
assert.equal(r.ok, false);
|
|
46
|
+
assert.equal(!r.ok && r.rejection.reason, "candidate_too_old");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("窗口边界:正好等于窗口 ⇒ 仍然推断(<= 而非 <)", () => {
|
|
50
|
+
const r = decideParentInference(
|
|
51
|
+
[{ task_id: "t1", created_at_ms: NOW - INFER_WINDOW_MS }], NOW);
|
|
52
|
+
assert.equal(r.ok, true);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test("年龄未知 ⇒ 不推断(无法证明「刚派不久」,而那是这条约束的全部价值)", () => {
|
|
56
|
+
const r = decideParentInference([{ task_id: "t1", created_at_ms: null }], NOW);
|
|
57
|
+
assert.equal(r.ok, false);
|
|
58
|
+
assert.equal(!r.ok && r.rejection.reason, "candidate_too_old");
|
|
59
|
+
assert.equal(!r.ok && r.rejection.age_ms, null);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("没有候选 ⇒ 也是 ok:false,但 candidates=0(调用方据此决定不计数)", () => {
|
|
63
|
+
const r = decideParentInference([], NOW);
|
|
64
|
+
assert.equal(r.ok, false);
|
|
65
|
+
assert.equal(!r.ok && r.rejection.candidates, 0);
|
|
66
|
+
// 「没有要接的任务」是常态,不是拒绝;把它记成拒绝会让分母虚高。
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("计数:accepted 与两种 rejected 分开,且窗口值随快照给出", () => {
|
|
70
|
+
noteInferAccepted();
|
|
71
|
+
noteInferRejected({ reason: "ambiguous_candidates", candidates: 2, age_ms: 1000 });
|
|
72
|
+
noteInferRejected({ reason: "candidate_too_old", candidates: 1, age_ms: 999999 });
|
|
73
|
+
noteInferRejected({ reason: "candidate_too_old", candidates: 1, age_ms: 999999 });
|
|
74
|
+
const c = parentInferCounters();
|
|
75
|
+
assert.equal(c.accepted, 1);
|
|
76
|
+
assert.equal(c.rejected_ambiguous, 1);
|
|
77
|
+
assert.equal(c.rejected_too_old, 2);
|
|
78
|
+
assert.equal(c.window_ms, INFER_WINDOW_MS);
|
|
79
|
+
assert.deepEqual(Object.keys(c).sort(), [
|
|
80
|
+
"accepted", "rejected_ambiguous", "rejected_too_old", "since", "window_ms",
|
|
81
|
+
]);
|
|
82
|
+
});
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// #669 —— 父任务**推断**的收窄:从「取最近一条 delivered」改成「候选唯一且在窗口内」。
|
|
2
|
+
//
|
|
3
|
+
// ## 为什么收窄,而不是取消
|
|
4
|
+
//
|
|
5
|
+
// 生产实测(近 7 天,`meta_json.parent_source`):
|
|
6
|
+
//
|
|
7
|
+
// inferred 795 条(78% 的有父任务派发靠推断)
|
|
8
|
+
// explicit 222 条
|
|
9
|
+
//
|
|
10
|
+
// inferred 非正常收尾 48/795 = **6.0%**(expired 43 + failed 17 + cancelled 5 里与 expired 合并计)
|
|
11
|
+
// explicit 非正常收尾 1/222 = **0.5%**
|
|
12
|
+
//
|
|
13
|
+
// ⇒ 取消会让 795 条/周失去父链(不可接受);但 12 倍的失败率说明它确实在挂错父任务
|
|
14
|
+
// (子任务回复提前关掉那条还没开始的 delivered)。
|
|
15
|
+
//
|
|
16
|
+
// ## 收窄的两条约束
|
|
17
|
+
//
|
|
18
|
+
// ① **候选必须唯一**:该节点名下 `delivered` 的条数 == 1。多于一条时无法判断
|
|
19
|
+
// 「你要接的是哪一条」,而挑最近一条正是挂错的来源。
|
|
20
|
+
// ② **必须在窗口内**:那条 delivered 的 `created_at` 距今 ≤ INFER_WINDOW_MS。
|
|
21
|
+
// 太旧的 delivered 更可能是「排在后面还没轮到」的,而不是「刚派给我、我正在做」的。
|
|
22
|
+
//
|
|
23
|
+
// 两个常量都可改;改完的效果由 `inferred_rejected` 计数与 7 天后的失败率对比来读。
|
|
24
|
+
//
|
|
25
|
+
// ## 为什么每一条拒绝都要计数
|
|
26
|
+
//
|
|
27
|
+
// 收窄是**减少**推断,而「减少」在派发日志里不留痕:任务照常派出,只是没有父。
|
|
28
|
+
// 没有计数时,「收窄了多少」与「收窄没生效」同形——两者的 7 天失败率都会下降。
|
|
29
|
+
|
|
30
|
+
export const INFER_WINDOW_MS = 10 * 60_000;
|
|
31
|
+
|
|
32
|
+
export interface InferRejection {
|
|
33
|
+
/** 被拒绝的原因:候选不唯一 / 候选太旧 */
|
|
34
|
+
reason: "ambiguous_candidates" | "candidate_too_old";
|
|
35
|
+
/** 候选条数(不唯一时 >1;太旧时 ==1) */
|
|
36
|
+
candidates: number;
|
|
37
|
+
/** 最近那条候选的年龄(毫秒,未知时 null) */
|
|
38
|
+
age_ms: number | null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const counters = {
|
|
42
|
+
accepted: 0,
|
|
43
|
+
rejected_ambiguous: 0,
|
|
44
|
+
rejected_too_old: 0,
|
|
45
|
+
since: new Date().toISOString(),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export function noteInferAccepted(): void {
|
|
49
|
+
counters.accepted += 1;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function noteInferRejected(r: InferRejection): void {
|
|
53
|
+
if (r.reason === "ambiguous_candidates") counters.rejected_ambiguous += 1;
|
|
54
|
+
else counters.rejected_too_old += 1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface InferCounters {
|
|
58
|
+
since: string;
|
|
59
|
+
/** 推断成功挂上父任务的次数 */
|
|
60
|
+
accepted: number;
|
|
61
|
+
/** 因候选不唯一而放弃推断 */
|
|
62
|
+
rejected_ambiguous: number;
|
|
63
|
+
/** 因候选太旧而放弃推断 */
|
|
64
|
+
rejected_too_old: number;
|
|
65
|
+
window_ms: number;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export function parentInferCounters(): InferCounters {
|
|
69
|
+
return {
|
|
70
|
+
since: counters.since,
|
|
71
|
+
accepted: counters.accepted,
|
|
72
|
+
rejected_ambiguous: counters.rejected_ambiguous,
|
|
73
|
+
rejected_too_old: counters.rejected_too_old,
|
|
74
|
+
window_ms: INFER_WINDOW_MS,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** 裁定:候选列表(按 created_at DESC 排好)+ 现在的时间 ⇒ 是否推断、以及为什么。 */
|
|
79
|
+
export function decideParentInference(
|
|
80
|
+
candidates: Array<{ task_id: string; created_at_ms: number | null }>,
|
|
81
|
+
now: number,
|
|
82
|
+
windowMs: number = INFER_WINDOW_MS,
|
|
83
|
+
): { ok: true; task_id: string } | { ok: false; rejection: InferRejection } {
|
|
84
|
+
if (candidates.length === 0) {
|
|
85
|
+
// 没有候选不是「拒绝」,是「本来就不该推断」—— 由调用方决定要不要记。
|
|
86
|
+
return { ok: false, rejection: { reason: "ambiguous_candidates", candidates: 0, age_ms: null } };
|
|
87
|
+
}
|
|
88
|
+
if (candidates.length > 1) {
|
|
89
|
+
const newest = candidates[0]?.created_at_ms ?? null;
|
|
90
|
+
return { ok: false, rejection: {
|
|
91
|
+
reason: "ambiguous_candidates", candidates: candidates.length,
|
|
92
|
+
age_ms: newest === null ? null : Math.max(0, now - newest),
|
|
93
|
+
} };
|
|
94
|
+
}
|
|
95
|
+
const only = candidates[0]!;
|
|
96
|
+
const age = only.created_at_ms === null ? null : Math.max(0, now - only.created_at_ms);
|
|
97
|
+
// 年龄未知时**不推断**:无法证明它「刚派不久」,而正是这个条件在防挂错。
|
|
98
|
+
if (age === null || age > windowMs) {
|
|
99
|
+
return { ok: false, rejection: { reason: "candidate_too_old", candidates: 1, age_ms: age } };
|
|
100
|
+
}
|
|
101
|
+
return { ok: true, task_id: only.task_id };
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** 只在测试里用。 */
|
|
105
|
+
export function __resetParentInferForTest(): void {
|
|
106
|
+
counters.accepted = 0;
|
|
107
|
+
counters.rejected_ambiguous = 0;
|
|
108
|
+
counters.rejected_too_old = 0;
|
|
109
|
+
counters.since = new Date().toISOString();
|
|
110
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// #669 —— parent_task_id 的来源必须可区分(显式 / 推断)。
|
|
2
|
+
//
|
|
3
|
+
// 没有这个标记时,那张卡要求的前置统计做不出来:tasks 表只存 parent_task_id,
|
|
4
|
+
// 不记它是怎么来的(实测近 7 天 949 条里 0 条可区分)。
|
|
5
|
+
//
|
|
6
|
+
// 这里不测完整派发链路,只钉住「来源判定 + 写进 meta」这一段的行为:
|
|
7
|
+
// · 显式带了 parent_task_id → parent_source = "explicit"
|
|
8
|
+
// · 没带但被推断命中最近 delivered → parent_source = "inferred"
|
|
9
|
+
// · 两者都没有 → meta 里没有 parent_source
|
|
10
|
+
import { describe, expect, test } from "bun:test";
|
|
11
|
+
import { readFileSync } from "node:fs";
|
|
12
|
+
|
|
13
|
+
const src = readFileSync(new URL("./tools.ts", import.meta.url), "utf8");
|
|
14
|
+
|
|
15
|
+
describe("#669 parent source marker", () => {
|
|
16
|
+
test("显式 parent 记为 explicit,推断命中时改写为 inferred", () => {
|
|
17
|
+
expect(src).toContain('let parentSource: "explicit" | "inferred" | null = parentIn ? "explicit" : null;');
|
|
18
|
+
// #669 收窄之后,推断不再是「取最近一条」,而是「裁定通过才认」。
|
|
19
|
+
// 断言从「命中最近一条就改写」改成「裁定 ok 才改写」,并且配一条否定断言:
|
|
20
|
+
// 那条 SQL 不能退回 `LIMIT 1` —— 退回之后裁定拿不到候选条数,
|
|
21
|
+
// 「候选唯一」这条约束会静默失效,而它失效时测试仍然全绿(拿到的永远是一条)。
|
|
22
|
+
const block = src.slice(src.indexOf("const verdict = decideParentInference("),
|
|
23
|
+
src.indexOf("// #669 —— 把来源写进 meta"));
|
|
24
|
+
expect(block).toContain("if (verdict.ok)");
|
|
25
|
+
expect(block).toContain('parentSource = "inferred"');
|
|
26
|
+
expect(block).toContain("noteInferAccepted()");
|
|
27
|
+
expect(block).toContain("noteInferRejected(verdict.rejection)");
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
// 分成独立一条,而不是塞进上一条:「候选唯一」这条约束的见证是 LIMIT,
|
|
31
|
+
// 「裁定通过才改写」的见证是 verdict.ok。两者放在同一个 test 里时,
|
|
32
|
+
// 任一被破都只让同一条红 —— 红的集合相同,归因就得靠读行号。
|
|
33
|
+
// 独立成条之后,「只破 LIMIT」只红这一条,「只破 verdict」只红上一条。
|
|
34
|
+
test("取候选必须看得到「不止一条」—— LIMIT 1 会让「候选唯一」静默失效", () => {
|
|
35
|
+
const sqlBlock = src.slice(src.indexOf("SELECT task_id, created_at FROM tasks WHERE to_name"),
|
|
36
|
+
src.indexOf("const cands = db.all"));
|
|
37
|
+
expect(sqlBlock).toContain("LIMIT 5");
|
|
38
|
+
expect(sqlBlock).not.toContain("LIMIT 1");
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("来源只在确实有 parent 时写进 meta,且序列化失败不影响派发", () => {
|
|
42
|
+
const block = src.slice(src.indexOf("let metaJsonWithParent = metaJson;"), src.indexOf("// round5 F2 fix"));
|
|
43
|
+
expect(block).toContain("if (parentSource && parentTaskId)");
|
|
44
|
+
expect(block).toContain("try {");
|
|
45
|
+
expect(block).toContain("parent_source: parentSource");
|
|
46
|
+
expect(block).toContain("catch {}");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
test("两条 INSERT(inbox / tasks)都用合并后的 meta", () => {
|
|
50
|
+
const inserts = src.split("\n").filter((l) => l.includes("targetAlias, priority, task") || l.includes("effectiveNetId ?? null, parentTaskId"));
|
|
51
|
+
expect(inserts.some((l) => l.includes("metaJsonWithParent"))).toBe(true);
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
// 这条原本断言「REST 里根本没有 parent_source」——理由是「REST 不走推断,
|
|
55
|
+
// 不要造第二真相」。方向对,但结论错了一半:REST 确实**不该推断**,
|
|
56
|
+
// 可它建的子任务同样是显式父子关系,不标就会被统计漏掉。
|
|
57
|
+
//
|
|
58
|
+
// 实测(2026-10-29,.195 上线后 90 分钟):3 条带 parent 的任务全部走 REST、
|
|
59
|
+
// 全部没有 parent_source。而 MCP 那条路是标的 ⇒ 分母只含 MCP,
|
|
60
|
+
// explicit 占比会被系统性压低。#669 要统计的正是这个比例。
|
|
61
|
+
test("REST /api/task 标「显式」,但不推断", () => {
|
|
62
|
+
const rest = readFileSync(new URL("./server.ts", import.meta.url), "utf8");
|
|
63
|
+
expect(rest).toContain("body.parent_task_id ?? null");
|
|
64
|
+
expect(rest).toContain('parent_source: "explicit"');
|
|
65
|
+
// 不能出现第二份推断:REST 里没有「找最近 delivered」这种 SQL。
|
|
66
|
+
const restBlock = rest.slice(rest.indexOf("const metaWithParent"), rest.indexOf("const metaWithParent") + 400);
|
|
67
|
+
expect(restBlock.toLowerCase()).not.toContain("delivered");
|
|
68
|
+
expect(rest).not.toContain('parentSource = "inferred"');
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
// #3348 —— 父被丢弃时,**来源必须一起丢弃**。
|
|
2
|
+
//
|
|
3
|
+
// ## 生产读数(修之前)
|
|
4
|
+
//
|
|
5
|
+
// tasks 131684 行里 2 条:
|
|
6
|
+
// meta = {"parent_source":"explicit"},parent_task_id / in_reply_to / thread_id 全空
|
|
7
|
+
// 5bc82d72 2026-10-30 16:08:38 · d002b739 2026-10-31 02:23:09
|
|
8
|
+
//
|
|
9
|
+
// ## 为什么会出现
|
|
10
|
+
//
|
|
11
|
+
// `send_task` 里的顺序是:
|
|
12
|
+
//
|
|
13
|
+
// ① `if (parentSource && parentTaskId) { meta.parent_source = parentSource }` ← 拼 meta
|
|
14
|
+
// ② 校验显式父是否存在;不存在 ⇒ `parentTaskId = null` ← 丢父
|
|
15
|
+
// ③ INSERT(meta 用 ①,父用 ② 之后的值)
|
|
16
|
+
//
|
|
17
|
+
// ⇒ ② 与 ① 之间没有连线。`meta` 里保留了「有一个 explicit 父」这个陈述,
|
|
18
|
+
// 而那一行本身没有父。
|
|
19
|
+
//
|
|
20
|
+
// ## 为什么这条不变式的正向断言抓不到它
|
|
21
|
+
//
|
|
22
|
+
// `#669` 的不变式是「父有值 ⇒ 来源有值」。这一格是「来源有值 ⇒ 父有值」的反面,
|
|
23
|
+
// 两个方向各自都合理,合起来留了一个空格 —— 而空格里正好能站下一行坏数据。
|
|
24
|
+
// `scripts/report-parent-source-coverage.py` 现在把这一格单列成 `source, no parent` 并报数。
|
|
25
|
+
//
|
|
26
|
+
// ## 这里测什么
|
|
27
|
+
//
|
|
28
|
+
// 走**真 handler**(不是镜像映射):派一条带不存在父的任务,断言
|
|
29
|
+
// ① 任务照样建成(丢父是「不阻塞派发」的决定,不是错误)
|
|
30
|
+
// ② parent_task_id 落库为 NULL
|
|
31
|
+
// ③ meta_json 里**没有** parent_source —— 这一条是本次修的
|
|
32
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
33
|
+
import { mkdtempSync } from "fs";
|
|
34
|
+
import { join } from "path";
|
|
35
|
+
import { tmpdir } from "os";
|
|
36
|
+
|
|
37
|
+
process.env.COMMHUB_DB = join(mkdtempSync(join(tmpdir(), "anet-orphan-source-")), "commhub.db");
|
|
38
|
+
|
|
39
|
+
const { McpServer } = await import("@modelcontextprotocol/sdk/server/mcp.js");
|
|
40
|
+
const { db } = await import("./db.js");
|
|
41
|
+
const { registerTools } = await import("./tools.js");
|
|
42
|
+
|
|
43
|
+
const NET = "net_orphan_src";
|
|
44
|
+
const USER = "u_orphan_src";
|
|
45
|
+
const PEER = "osp-peer";
|
|
46
|
+
const TARGET = "osp-target";
|
|
47
|
+
|
|
48
|
+
type Handler = (args: any, extra?: any) => Promise<{ content: Array<{ type: "text"; text: string }> }>;
|
|
49
|
+
|
|
50
|
+
function cleanup(): void {
|
|
51
|
+
for (const table of ["task_events", "inbox", "tasks", "sessions", "nodes", "network_members", "networks"]) {
|
|
52
|
+
try { db.run(`DELETE FROM ${table} WHERE network_id = ?1`, [NET]); } catch {}
|
|
53
|
+
}
|
|
54
|
+
try { db.run("DELETE FROM users WHERE user_id = ?1", [USER]); } catch {}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function seed(): void {
|
|
58
|
+
db.run("INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?2, 'x', 'user', datetime('now'))", [USER, USER]);
|
|
59
|
+
db.run("INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?1, ?2, datetime('now'))", [NET, USER]);
|
|
60
|
+
db.run("INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'owner', datetime('now'))", [USER, NET]);
|
|
61
|
+
for (const alias of [PEER, TARGET]) {
|
|
62
|
+
db.run(
|
|
63
|
+
`INSERT INTO nodes (node_id, node_name, alias, network_id, lifecycle_state)
|
|
64
|
+
VALUES (?1, ?2, ?2, ?3, 'active')`,
|
|
65
|
+
[`n_${alias}`, alias, NET],
|
|
66
|
+
);
|
|
67
|
+
db.run(
|
|
68
|
+
`INSERT INTO sessions (resume_id, alias, status, node_id, network_id, updated_at, last_seen_at)
|
|
69
|
+
VALUES (?1, ?2, 'idle', ?3, ?4, datetime('now'), datetime('now'))`,
|
|
70
|
+
[`r_${alias}`, alias, `n_${alias}`, NET],
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function handlers(): Record<string, Handler> {
|
|
76
|
+
const server = new McpServer({ name: "test-orphan-source", version: "0" }) as any;
|
|
77
|
+
const out: Record<string, Handler> = {};
|
|
78
|
+
const original = server.tool.bind(server);
|
|
79
|
+
server.tool = (name: string, ...args: any[]) => {
|
|
80
|
+
const h = args.at(-1);
|
|
81
|
+
if (typeof h === "function") out[name] = h;
|
|
82
|
+
return original(name, ...args);
|
|
83
|
+
};
|
|
84
|
+
registerTools(server, undefined, NET, USER, PEER, false, null);
|
|
85
|
+
return out;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
async function call(handler: Handler, args: any): Promise<any> {
|
|
89
|
+
const r = await handler(args);
|
|
90
|
+
return JSON.parse(r.content[0].text);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
beforeEach(() => { cleanup(); seed(); });
|
|
94
|
+
afterAll(() => { cleanup(); });
|
|
95
|
+
|
|
96
|
+
describe("#3348 不存在的显式父:父与来源一起丢", () => {
|
|
97
|
+
test("父不存在 ⇒ 任务照样建成,但 parent_task_id 为 NULL 且 meta 里没有 parent_source", async () => {
|
|
98
|
+
const ghost = "00000000-0000-4000-8000-000000000000"; // 不存在的父
|
|
99
|
+
const r = await call(handlers().send_task, {
|
|
100
|
+
alias: TARGET,
|
|
101
|
+
task: "osp dispatch with a ghost parent",
|
|
102
|
+
priority: "normal",
|
|
103
|
+
from_session: PEER,
|
|
104
|
+
network_id: NET,
|
|
105
|
+
parent_task_id: ghost,
|
|
106
|
+
});
|
|
107
|
+
// 丢父是「不阻塞派发」的决定:这条**不能**变成错误,否则一个幻觉 id 会挡掉整条任务。
|
|
108
|
+
expect(r.ok).toBe(true);
|
|
109
|
+
|
|
110
|
+
const row = db.get<{ task_id: string; parent_task_id: string | null; meta_json: string | null }>(
|
|
111
|
+
"SELECT task_id, parent_task_id, meta_json FROM tasks WHERE content = ?1",
|
|
112
|
+
["osp dispatch with a ghost parent"],
|
|
113
|
+
);
|
|
114
|
+
expect(row).toBeTruthy();
|
|
115
|
+
expect(row!.parent_task_id).toBeNull();
|
|
116
|
+
// 关键断言:来源不许单独留下。
|
|
117
|
+
// 留着的后果是库里出现「有来源、没父」这一格 —— #669 的不变式两个方向都放过它,
|
|
118
|
+
// 于是它既不被算作 explicit 也不被算作无父,只在有人专门数「source 无 parent」时才看得见。
|
|
119
|
+
expect(String(row!.meta_json ?? "")).not.toContain("parent_source");
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { db } from "./db.js";
|
|
2
|
+
|
|
3
|
+
export type KeptNetworkToken = {
|
|
4
|
+
token_id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
network_id: string;
|
|
7
|
+
created_at: string;
|
|
8
|
+
last_used_at: string | null;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/** Only user-created named network tokens. Node credentials have a different scope or binding. */
|
|
12
|
+
export function passwordNetworkTokens(userId: string, currentTokenId: string | null | undefined, revoke: boolean) {
|
|
13
|
+
const where = `user_id = ?1 AND network_id IS NOT NULL AND scope = 'full'
|
|
14
|
+
AND bound_node_id IS NULL AND revoked_at IS NULL
|
|
15
|
+
AND (expires_at IS NULL OR expires_at > datetime('now'))${currentTokenId ? " AND token_id != ?2" : ""}`;
|
|
16
|
+
const params = currentTokenId ? [userId, currentTokenId] : [userId];
|
|
17
|
+
if (revoke) {
|
|
18
|
+
return { revoked: db.run(`DELETE FROM api_tokens WHERE ${where}`, params).changes, kept: [] as KeptNetworkToken[] };
|
|
19
|
+
}
|
|
20
|
+
const kept = db.all<KeptNetworkToken>(
|
|
21
|
+
`SELECT token_id, name, network_id, created_at, last_used_at FROM api_tokens WHERE ${where} ORDER BY created_at DESC, token_id`,
|
|
22
|
+
...params,
|
|
23
|
+
);
|
|
24
|
+
return { revoked: 0, kept };
|
|
25
|
+
}
|