@sleep2agi/commhub-server 0.9.0-preview.26 → 0.9.0-preview.261
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 +228 -0
- package/src/admin-networks-http.test.ts +88 -0
- package/src/adoption-candidates-http.test.ts +140 -0
- package/src/adoption-candidates.ts +158 -0
- package/src/agent-access-batch.test.ts +210 -0
- package/src/agent-access.ts +487 -0
- package/src/agent-acl-groups-http.test.ts +247 -0
- package/src/agent-acl-http.test.ts +680 -0
- package/src/agent-acl-slice3-http.test.ts +885 -0
- package/src/agent-department-http.test.ts +215 -0
- package/src/agent-groups-perf.test.ts +223 -0
- package/src/agent-notice.ts +48 -0
- package/src/agent-team-whoami-http.test.ts +98 -0
- package/src/agent-teams-http.test.ts +330 -0
- package/src/agent-teams.ts +244 -0
- package/src/alias-baseline-2571.test.ts +162 -0
- package/src/alias-baseline.ts +113 -0
- package/src/alias-filter.test.ts +72 -0
- package/src/alias-filter.ts +42 -0
- package/src/api-host-supervisors-can-create-nodes.test.ts +350 -0
- package/src/api-host-supervisors-fallback.test.ts +6 -7
- package/src/api-host-supervisors-runtime-readiness.test.ts +195 -0
- package/src/api-nodes-shape.test.ts +131 -4
- package/src/auth-abuse-counters.test.ts +144 -0
- package/src/auth-abuse-counters.ts +122 -0
- package/src/auth-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 +609 -56
- package/src/backfill-node-ids-2664.test.ts +128 -0
- package/src/binding-generation-http.test.ts +141 -0
- package/src/blocked-exit-on-reply.test.ts +122 -0
- package/src/broadcast-fanout-2721.test.ts +149 -0
- package/src/broadcast-fanout.ts +117 -0
- package/src/build-commit-report-http.test.ts +128 -0
- package/src/build-info.test.ts +60 -0
- package/src/build-info.ts +85 -0
- package/src/chain-attempt-dedup.test.ts +447 -0
- package/src/clip.test.ts +36 -0
- package/src/clip.ts +48 -0
- package/src/clone-node.test.ts +269 -0
- package/src/clone-node.ts +289 -0
- package/src/codex-config-flags.ts +77 -0
- package/src/codex-fork-contract.ts +23 -0
- package/src/codex-fork-migration.test.ts +38 -0
- package/src/commhub-bin-args.test.ts +85 -0
- package/src/config-apply-validate.test.ts +188 -1
- package/src/config-apply-validate.ts +222 -3
- package/src/cors-origins.test.ts +73 -0
- package/src/create-node-blocked-gate.test.ts +365 -0
- package/src/create-node-error-domain.test.ts +127 -0
- package/src/create-node-network-id.test.ts +91 -0
- package/src/create-node-tool-schema.test.ts +49 -0
- package/src/create-node-unicode-name.test.ts +126 -0
- package/src/create-node-validate.test.ts +199 -7
- package/src/create-node-validate.ts +232 -15
- package/src/create-node-workdir.test.ts +298 -0
- package/src/create-node.ts +88 -23
- package/src/daemon-provider-snapshots.test.ts +453 -0
- package/src/daemon-provider-snapshots.ts +327 -0
- package/src/daemon-token-owner-http.test.ts +346 -0
- package/src/dashboard-slash-routing-http.test.ts +109 -0
- package/src/db-adapter-guard.test.ts +148 -0
- package/src/db-adapter-translate.test.ts +128 -0
- package/src/db-adapter.ts +377 -91
- package/src/db-timestamp.test.ts +38 -0
- package/src/db-timestamp.ts +15 -0
- package/src/db.ts +1269 -153
- package/src/delivered-without-push.test.ts +140 -0
- package/src/department-groups-http.test.ts +209 -0
- package/src/department-groups-sync-http.test.ts +328 -0
- package/src/department-groups.ts +434 -0
- package/src/department-heads-http.test.ts +350 -0
- package/src/department-heads.ts +226 -0
- package/src/departments-agent-count.test.ts +139 -0
- package/src/departments-http.test.ts +185 -0
- package/src/departments-mcp-error-domain.test.ts +135 -0
- package/src/departments-mcp.test.ts +128 -0
- package/src/departments.ts +318 -0
- package/src/desktop-message-seam.test.ts +150 -0
- package/src/desktop-message.test.ts +368 -0
- package/src/dm-file-scope-http.test.ts +178 -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-redaction.test.ts +1576 -7
- 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 +641 -0
- package/src/hub-provider-config.test.ts +166 -0
- package/src/hub-provider-config.ts +202 -0
- package/src/hub-timestamp.test.ts +38 -0
- package/src/hub-timestamp.ts +27 -0
- package/src/human-dm.ts +215 -0
- package/src/human-inbox.ts +42 -0
- package/src/inbox-caller.ts +49 -0
- package/src/inbox-count-sse.test.ts +318 -0
- package/src/inbox-count.ts +29 -0
- package/src/index.ts +6 -2
- package/src/license-state.test.ts +56 -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/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-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-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.ts +121 -0
- package/src/node-health-passthrough.test.ts +115 -0
- package/src/node-health-store.ts +101 -0
- package/src/node-id-alias.test.ts +190 -0
- package/src/node-identity-conflict-http.test.ts +269 -0
- package/src/node-identity-conflict.ts +142 -0
- package/src/node-identity-mismatch.test.ts +74 -0
- package/src/node-in-flight-tasks.ts +31 -0
- package/src/node-lifecycle-controllable.test.ts +64 -0
- package/src/node-lifecycle-controllable.ts +53 -0
- package/src/node-lifecycle-read-http.test.ts +257 -0
- package/src/node-lifecycle-read.ts +124 -0
- package/src/node-logs-transport.test.ts +266 -0
- package/src/node-peer-allowlist.test.ts +114 -0
- package/src/node-permissions-http.test.ts +728 -0
- package/src/node-permissions.ts +494 -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-security-write-gate.test.ts +72 -0
- package/src/node-serviceability.test.ts +86 -0
- package/src/node-serviceability.ts +124 -0
- package/src/node-session-control-http.test.ts +310 -0
- package/src/node-session-control.ts +258 -0
- package/src/node-skills-transport.test.ts +212 -0
- package/src/node-token-identity.ts +35 -0
- package/src/node-token-ownership.ts +51 -0
- package/src/node-token-privilege-http.test.ts +158 -0
- package/src/not-found-api-http.test.ts +67 -0
- package/src/observer-avatar-http.test.ts +103 -10
- package/src/observer-push.test.ts +76 -0
- package/src/opencode-catalog-report-http.test.ts +139 -0
- package/src/opencode-v2-catalog.test.ts +268 -0
- package/src/opencode-v2-catalog.ts +356 -0
- package/src/package-version-consistency.test.ts +25 -0
- package/src/parent-infer.test.ts +82 -0
- package/src/parent-infer.ts +110 -0
- package/src/parent-source-marker.test.ts +70 -0
- package/src/password-network-tokens.ts +25 -0
- package/src/peer-reply-atomic.test.ts +462 -0
- package/src/peer-reply-capability.test.ts +70 -0
- package/src/pg-worker.ts +87 -0
- package/src/poll-pacing.test.ts +74 -0
- package/src/poll-pacing.ts +123 -0
- package/src/probe-provider-error-domain.test.ts +145 -0
- package/src/project-dir-warn-clear-http.test.ts +132 -0
- package/src/project-viewer-can-http.test.ts +116 -0
- package/src/provider-skill-error-domain.test.ts +130 -0
- package/src/provider-tools-shape.test.ts +165 -0
- package/src/push.test.ts +20 -10
- package/src/push.ts +373 -9
- package/src/redact-tokens.test.ts +86 -0
- package/src/redact-tokens.ts +43 -0
- package/src/rejection-counters.test.ts +72 -0
- package/src/rejection-counters.ts +173 -0
- package/src/rename.ts +38 -10
- package/src/reply-target-derivation.test.ts +96 -0
- package/src/report-status-handover-capabilities-http.test.ts +124 -0
- package/src/report-status-host-schema.test.ts +235 -0
- package/src/report-status-resume-id-handover.test.ts +184 -0
- package/src/report-status-secret-keys.test.ts +140 -0
- package/src/require-explicit-test-db.ts +9 -0
- package/src/requirement-due-reminders-http.test.ts +620 -0
- package/src/requirement-due-reminders.ts +416 -0
- package/src/requirement-events-http.test.ts +318 -0
- package/src/requirement-events.test.ts +45 -0
- package/src/requirement-events.ts +144 -0
- package/src/requirement-notify.ts +165 -0
- package/src/requirement-participant-notify-http.test.ts +313 -0
- package/src/requirement-tag-ops-http.test.ts +454 -0
- package/src/requirement-tag-tree-http.test.ts +275 -0
- package/src/requirement-tag-tree.ts +127 -0
- package/src/requirement-tags.ts +102 -0
- package/src/requirements-abandoned-http.test.ts +236 -0
- package/src/requirements-assignee-drift.test.ts +154 -0
- package/src/requirements-comment-http.test.ts +174 -0
- package/src/requirements-completed-at-migration.test.ts +70 -0
- package/src/requirements-errors-mcp-http.test.ts +164 -0
- package/src/requirements-errors.ts +158 -0
- package/src/requirements-etag-http.test.ts +91 -0
- package/src/requirements-http.test.ts +709 -0
- package/src/requirements-last-event-http.test.ts +349 -0
- package/src/requirements-list-mcp-slim-http.test.ts +155 -0
- package/src/requirements-list-slim-http.test.ts +324 -0
- package/src/requirements-mcp.test.ts +180 -0
- package/src/requirements-migrate.ts +283 -0
- package/src/requirements-owner-strict-mcp-http.test.ts +145 -0
- package/src/requirements-people-http.test.ts +114 -0
- package/src/requirements-people-mcp-http.test.ts +231 -0
- package/src/requirements-people.ts +196 -0
- package/src/requirements-priority-lowest.test.ts +114 -0
- package/src/requirements-projects-network-echo.test.ts +57 -0
- package/src/requirements-projects-parent-http.test.ts +123 -0
- package/src/requirements-search-http.test.ts +182 -0
- package/src/requirements-search.test.ts +32 -0
- package/src/requirements-search.ts +145 -0
- package/src/requirements-seq-http.test.ts +193 -0
- package/src/requirements-seq-migration.test.ts +63 -0
- package/src/requirements-start-date.test.ts +125 -0
- package/src/requirements-stats-http.test.ts +357 -0
- package/src/requirements-stats.ts +195 -0
- package/src/requirements-status-participants-http.test.ts +222 -0
- package/src/requirements-upgrade-e2e.test.ts +126 -0
- package/src/requirements-upgrade-migration.test.ts +98 -0
- package/src/requirements.ts +2205 -0
- package/src/resolve-port.test.ts +57 -0
- package/src/resolve-port.ts +44 -0
- package/src/rest-alias-network-fallback-http.test.ts +123 -0
- package/src/rest-alias-network-fallback.test.ts +60 -0
- package/src/rest-alias-network-fallback.ts +65 -0
- package/src/rest-explicit-columns-http.test.ts +266 -0
- package/src/rest-identity.test.ts +130 -0
- package/src/rest-identity.ts +141 -0
- package/src/rest-projections.ts +72 -0
- package/src/rest-read-network-real-chain.test.ts +97 -0
- package/src/rest-write-network-resolution.test.ts +133 -0
- package/src/restart-readiness-http.test.ts +121 -0
- package/src/restricted-files.ts +76 -0
- package/src/retention-first-sweep-quiet.test.ts +31 -0
- package/src/retention.test.ts +100 -40
- package/src/retention.ts +423 -104
- package/src/route-callers-http.test.ts +120 -0
- package/src/route-timing.test.ts +218 -0
- package/src/route-timing.ts +262 -0
- package/src/rules-file-duplicate-alias.test.ts +234 -0
- package/src/rules-file-session-target.test.ts +207 -0
- package/src/rules-file-transport.test.ts +271 -0
- package/src/runtime-label.test.ts +22 -0
- package/src/runtime-label.ts +21 -0
- package/src/runtime-readiness.ts +90 -0
- package/src/schedule-agent-mcp-http.test.ts +486 -0
- package/src/schedule-agent.ts +252 -0
- package/src/schedule-starved.test.ts +92 -0
- package/src/schedule-starved.ts +114 -0
- package/src/scheduled-backoff-http.test.ts +203 -0
- package/src/scheduled-backoff.ts +64 -0
- package/src/scheduled-doorbell-nodeless-session.test.ts +134 -0
- package/src/scheduled-failure-backoff-2622.test.ts +145 -0
- package/src/scheduled-failure-code.test.ts +73 -0
- package/src/scheduled-failure-code.ts +105 -0
- package/src/scheduled-failures-http.test.ts +279 -0
- package/src/scheduled-failures.ts +425 -0
- package/src/scheduled-noprogress-backoff-2622.test.ts +163 -0
- package/src/scheduled-offline-backoff-probe.test.ts +56 -0
- package/src/scheduled-offline.test.ts +131 -0
- package/src/scheduled-offline.ts +66 -0
- package/src/scheduled-outcome-guidance-http.test.ts +139 -0
- package/src/scheduled-outcome-guidance.ts +9 -0
- package/src/scheduled-reply-unread-http.test.ts +212 -0
- package/src/scheduled-requirement-wake-http.test.ts +289 -0
- package/src/scheduled-requirement-wake.ts +125 -0
- package/src/scheduled-run-terminal.test.ts +290 -0
- package/src/scheduled-skip-blocking-task.test.ts +120 -0
- package/src/scheduled-skip-path-backoff-2622.test.ts +98 -0
- package/src/scheduled-stuck-http.test.ts +316 -0
- package/src/scheduled-stuck-notice-cap.test.ts +80 -0
- package/src/scheduled-stuck.ts +219 -0
- package/src/scheduled-tasks-http.test.ts +679 -0
- package/src/scheduled-tasks.ts +959 -0
- package/src/scheduled-work-outcome-http.test.ts +154 -0
- package/src/scheduled-work-outcome.ts +50 -0
- package/src/scoped-secrets.ts +141 -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 +4846 -325
- package/src/session-task-on-dispatch.ts +14 -0
- package/src/session-token-ownership-http.test.ts +122 -0
- package/src/shared/codex-inventory.ts +41 -0
- package/src/shared/daemon-provider-login.ts +31 -0
- package/src/shared/daemon-provider-snapshot.ts +52 -0
- package/src/shared/external-schedule-contract.ts +60 -0
- package/src/shared/node-name.test.ts +62 -0
- package/src/shared/node-name.ts +161 -0
- package/src/shared/probe-host-allowlist-drift.test.ts +45 -0
- package/src/shared/provider-application.ts +29 -0
- package/src/shared/provider-collection.ts +14 -0
- package/src/shared/provider-initialization.ts +8 -0
- package/src/shared/reserved-env-drift.test.ts +10 -0
- package/src/shared/scoped-secret-contract.ts +5 -0
- package/src/shared/task-content-limit-drift.test.ts +28 -0
- package/src/shared/task-content-limit.ts +25 -0
- package/src/side-thread-command-transport.test.ts +312 -0
- package/src/side-thread-command-transport.ts +318 -0
- package/src/side-thread-http-integration.test.ts +233 -0
- package/src/side-thread-http.ts +504 -0
- package/src/side-thread-production.test.ts +72 -0
- package/src/side-thread-production.ts +118 -0
- package/src/side-thread.test.ts +1067 -0
- package/src/side-thread.ts +2499 -0
- package/src/skillhub-http.test.ts +144 -0
- package/src/sqlite-close-checkpoint.test.ts +78 -0
- package/src/start-node.test.ts +265 -0
- package/src/start-request-error-domain.test.ts +182 -0
- package/src/start-skill-error-domain.test.ts +122 -0
- package/src/stats-versions-http.test.ts +65 -0
- package/src/status-alias-filter-http.test.ts +106 -0
- package/src/status-alias-resolver-http.test.ts +163 -0
- package/src/status-alias-resolver.ts +19 -0
- package/src/status-node-id-filter-http.test.ts +161 -0
- package/src/status-read-cache-http.test.ts +229 -0
- package/src/status-read-cache.ts +129 -0
- package/src/stop-delete-node.test.ts +567 -1
- package/src/task-access-http.test.ts +402 -0
- package/src/task-access.ts +420 -0
- package/src/task-activity.ts +60 -0
- package/src/task-auth-origin-http.test.ts +93 -0
- package/src/task-auth-origin.test.ts +24 -0
- package/src/task-auth-origin.ts +7 -0
- package/src/task-consumption.test.ts +508 -0
- package/src/task-diagnostic-http.test.ts +149 -0
- package/src/task-diagnostic.test.ts +115 -0
- package/src/task-diagnostic.ts +118 -0
- package/src/task-expiry-notice-http.test.ts +298 -0
- package/src/task-expiry-notice.ts +318 -0
- package/src/task-idempotency-mcp.test.ts +148 -0
- package/src/task-idempotency.test.ts +76 -0
- package/src/task-idempotency.ts +81 -0
- package/src/task-late-replies.ts +54 -0
- package/src/task-late-reply-http.test.ts +227 -0
- package/src/task-lifecycle-watcher-busy.test.ts +114 -0
- package/src/task-lifecycle-watcher.test.ts +209 -0
- package/src/task-lifecycle-watcher.ts +109 -0
- package/src/task-network-resolution-http.test.ts +140 -0
- package/src/task-not-found-error-domain.test.ts +114 -0
- package/src/task-offline-delivery-2668.test.ts +119 -0
- package/src/task-offline-delivery.ts +81 -0
- package/src/task-orphan-http.test.ts +287 -0
- package/src/task-orphan.ts +119 -0
- package/src/task-queue-ahead-http.test.ts +309 -0
- package/src/task-queue-ahead-scale.test.ts +236 -0
- package/src/task-queue-ahead.ts +186 -0
- package/src/task-rejection-log-http.test.ts +160 -0
- package/src/task-rejection-log.ts +61 -0
- package/src/task-sender-http.test.ts +143 -0
- package/src/task-stale-open-http.test.ts +292 -0
- package/src/task-stale-open.ts +103 -0
- package/src/tasks-pagination-http.test.ts +141 -0
- package/src/team-rules-status-http.test.ts +90 -0
- package/src/team-rules-status.test.ts +59 -0
- package/src/team-rules-status.ts +72 -0
- package/src/tmux-allowlist.test.ts +48 -0
- package/src/tool-audience-http.test.ts +248 -0
- package/src/tool-audience.ts +127 -0
- package/src/tools-list-json-schema.test.ts +94 -0
- package/src/tools.ts +4229 -397
- 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 +348 -0
- package/src/user-inbox-by-agent-http.test.ts +165 -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,74 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { POLL_PACING_NOTE, POLL_NUDGE_THRESHOLD, POLL_RECOMMENDED_SECONDS, createPollPacer } from "./poll-pacing";
|
|
3
|
+
|
|
4
|
+
// #3001 —— Hub 侧的轮询节奏提示。
|
|
5
|
+
// 现场:一个节点在空闲等待里以约 13 次/分钟连续拉了 8 小时 get_task(约 6000 次),
|
|
6
|
+
// 每次都是一整轮 LLM。这里钉住三件事:什么时候提示、什么时候**不**提示、提示里说了什么。
|
|
7
|
+
describe("#3001 get_task 轮询节奏提示", () => {
|
|
8
|
+
function pacerWithClock() {
|
|
9
|
+
let t = 1_000_000;
|
|
10
|
+
const pacer = createPollPacer({ now: () => t });
|
|
11
|
+
return { pacer, advance: (ms: number) => { t += ms; } };
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
test("偶发查询不提示(正常等子任务不会被这句打扰)", () => {
|
|
15
|
+
const { pacer, advance } = pacerWithClock();
|
|
16
|
+
for (let i = 0; i < POLL_NUDGE_THRESHOLD; i++) {
|
|
17
|
+
expect(pacer.record("tok:t1:task-a")).toBeNull();
|
|
18
|
+
advance(3_000);
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test("60 秒内超过阈值才提示,且带次数与建议间隔", () => {
|
|
23
|
+
const { pacer, advance } = pacerWithClock();
|
|
24
|
+
let pacing = null as ReturnType<typeof pacer.record>;
|
|
25
|
+
for (let i = 0; i <= POLL_NUDGE_THRESHOLD; i++) {
|
|
26
|
+
pacing = pacer.record("tok:t1:task-a");
|
|
27
|
+
advance(4_600); // 约 13 次/分钟:实测的失控频率
|
|
28
|
+
}
|
|
29
|
+
expect(pacing).not.toBeNull();
|
|
30
|
+
expect(pacing!.calls_last_60s).toBeGreaterThan(POLL_NUDGE_THRESHOLD);
|
|
31
|
+
expect(pacing!.recommended_interval_seconds).toBe(POLL_RECOMMENDED_SECONDS);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
test("隔一分钟以上再看,计数清零、不再提示(纪律生效后自动安静)", () => {
|
|
35
|
+
const { pacer, advance } = pacerWithClock();
|
|
36
|
+
for (let i = 0; i <= POLL_NUDGE_THRESHOLD; i++) {
|
|
37
|
+
pacer.record("tok:t1:task-a");
|
|
38
|
+
advance(500);
|
|
39
|
+
}
|
|
40
|
+
advance(POLL_RECOMMENDED_SECONDS * 1000 + 1);
|
|
41
|
+
expect(pacer.record("tok:t1:task-a")).toBeNull();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("不同 task_id 互不累加(同时等多个子任务不算连环打)", () => {
|
|
45
|
+
const { pacer, advance } = pacerWithClock();
|
|
46
|
+
for (let i = 0; i <= POLL_NUDGE_THRESHOLD; i++) {
|
|
47
|
+
expect(pacer.record(`tok:t1:task-${i}`)).toBeNull();
|
|
48
|
+
advance(500);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
test("身份查询用更宽的阈值(p50 约 2.3 次/分钟是设计频率,不该被提示打扰)", () => {
|
|
53
|
+
const { pacer } = pacerWithClock();
|
|
54
|
+
// 同一个 60 秒窗口内:task_poll 第 5 次就提示,identity_poll 要到第 9 次
|
|
55
|
+
for (let i = 1; i <= 8; i++) expect(pacer.record("whoami:x", "identity_poll")).toBeNull();
|
|
56
|
+
const pacing = pacer.record("whoami:x", "identity_poll");
|
|
57
|
+
expect(pacing).not.toBeNull();
|
|
58
|
+
expect(pacing!.calls_last_60s).toBe(9);
|
|
59
|
+
expect(pacing!.note).toContain("org_whoami");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("提示文案必须说明「结果会自动 chain」——否则 agent 仍会紧盯", () => {
|
|
63
|
+
expect(POLL_PACING_NOTE).toContain("60 秒");
|
|
64
|
+
expect(POLL_PACING_NOTE).toContain("chain 回上游");
|
|
65
|
+
expect(POLL_PACING_NOTE).toContain("一整轮 LLM");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("key 数量有上限(调用方是外部输入,不能当它只查自己的任务)", () => {
|
|
69
|
+
const pacer = createPollPacer({ maxKeys: 10, windowMs: 1, now: () => 1_000_000 });
|
|
70
|
+
for (let i = 0; i < 500; i++) pacer.record(`tok:t1:task-${i}`);
|
|
71
|
+
// 窗口 1ms,每次 record 时旧条目都已过期,应被回收
|
|
72
|
+
expect(pacer.size()).toBeLessThanOrEqual(11);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* #3001 —— get_task 的轮询节奏提示(Hub 侧)。
|
|
3
|
+
*
|
|
4
|
+
* 为什么放在 Hub 而不是只改 agent-node 的提示词:
|
|
5
|
+
* 提示词在 `agent-node/src/cli.ts` 里,改完要发 agent-node + CLI 配对版本,
|
|
6
|
+
* 而且**只有升级过的节点才会变**。而 `get_task` 是 Hub 提供的 MCP 工具 ——
|
|
7
|
+
* 在响应里加一句话,所有节点下一次调用就能看到,不需要任何客户端升级。
|
|
8
|
+
*
|
|
9
|
+
* 现场(TMW微软欧,2026-10-29 16:00Z → 10-30 01:00Z):
|
|
10
|
+
*
|
|
11
|
+
* 每小时 get_task:256 / 565 / 647 / 703 / 770 / 855 / 893 / 972 / 736
|
|
12
|
+
* ⇒ 约 13 次/分钟、连续 8 小时、合计约 6000 次
|
|
13
|
+
*
|
|
14
|
+
* 每次 `get_task` 都是一整轮 LLM 调用。这 6000 次没有推进任何工作,
|
|
15
|
+
* 只是在问「好没好」。而子任务的最终结果本来就会通过 parent_task_id 自动 chain 回上游。
|
|
16
|
+
*
|
|
17
|
+
* 设计取舍:
|
|
18
|
+
* · **不返回错误、不改状态**,只在同一个响应里多一个 `pacing` 字段 ——
|
|
19
|
+
* 调用方即使完全忽略它也照常工作(信息不缺,行为不破)。
|
|
20
|
+
* · 阈值 4 次/60 秒:正常的「隔几分钟看一眼」永远碰不到;
|
|
21
|
+
* 只有真正在连环打的才会看到这句提示。
|
|
22
|
+
* · 计数按 (调用方, task_id) 分开,避免把「同时等多个子任务」误判成连环打。
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
export type PollPacing = {
|
|
26
|
+
calls_last_60s: number;
|
|
27
|
+
recommended_interval_seconds: number;
|
|
28
|
+
note: string;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const WHOAMI_PACING_NOTE =
|
|
32
|
+
"org_whoami 只需要在「不确定自己是谁/团队变了」时查。实测有节点以约 4–6 次/分钟连续查询、" +
|
|
33
|
+
"同时窗口内没接到任何任务 —— 这些调用没有推进工作。建议隔 60 秒以上再看。";
|
|
34
|
+
|
|
35
|
+
export const POLL_PACING_NOTE =
|
|
36
|
+
"每次 get_task 都是一整轮 LLM 调用。子任务的最终结果会通过 parent_task_id 自动 chain 回上游," +
|
|
37
|
+
"所以不必连续轮询 —— 建议隔 60 秒以上再看。";
|
|
38
|
+
|
|
39
|
+
export const POLL_WINDOW_MS = 60_000;
|
|
40
|
+
export const POLL_NUDGE_THRESHOLD = 4;
|
|
41
|
+
export const POLL_RECOMMENDED_SECONDS = 60;
|
|
42
|
+
|
|
43
|
+
/** 两类轮询的阈值与文案。分开是因为「正常频率」差一个数量级。 */
|
|
44
|
+
export const PACE_KINDS = {
|
|
45
|
+
/** 等子任务:正常是「隔几分钟看一眼」,1 分钟内 4 次以上基本就是连环打。 */
|
|
46
|
+
task_poll: { threshold: POLL_NUDGE_THRESHOLD, note: POLL_PACING_NOTE },
|
|
47
|
+
/** 身份查询:p50 约 2.3 次/分钟是设计频率,1 分钟内 8 次以上才提示。 */
|
|
48
|
+
identity_poll: { threshold: 8, note: WHOAMI_PACING_NOTE },
|
|
49
|
+
} as const;
|
|
50
|
+
|
|
51
|
+
export type PaceKind = keyof typeof PACE_KINDS;
|
|
52
|
+
|
|
53
|
+
export type PollPacer = {
|
|
54
|
+
/** 记一次调用;超过阈值时返回提示,否则返回 null。 */
|
|
55
|
+
record(key: string, kind?: PaceKind): PollPacing | null;
|
|
56
|
+
/** 仅测试用:当前记录的 key 数。 */
|
|
57
|
+
size(): number;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
export function createPollPacer(opts: {
|
|
61
|
+
windowMs?: number;
|
|
62
|
+
threshold?: number;
|
|
63
|
+
maxKeys?: number;
|
|
64
|
+
now?: () => number;
|
|
65
|
+
} = {}): PollPacer {
|
|
66
|
+
const windowMs = opts.windowMs ?? POLL_WINDOW_MS;
|
|
67
|
+
const defaultThreshold = opts.threshold ?? POLL_NUDGE_THRESHOLD;
|
|
68
|
+
const maxKeys = opts.maxKeys ?? 2000;
|
|
69
|
+
const now = opts.now ?? Date.now;
|
|
70
|
+
const seen = new Map<string, number[]>();
|
|
71
|
+
|
|
72
|
+
function prune(ts: number[], cutoff: number): number[] {
|
|
73
|
+
// 时间戳按升序追加,从头部删到窗口内为止。
|
|
74
|
+
let i = 0;
|
|
75
|
+
while (i < ts.length && ts[i] <= cutoff) i++;
|
|
76
|
+
return i === 0 ? ts : ts.slice(i);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
record(key: string, kind: PaceKind = "task_poll"): PollPacing | null {
|
|
81
|
+
// 显式传了 threshold(测试用)就压过 kind 表
|
|
82
|
+
const spec = opts.threshold !== undefined
|
|
83
|
+
? { threshold: defaultThreshold, note: PACE_KINDS[kind].note }
|
|
84
|
+
: PACE_KINDS[kind];
|
|
85
|
+
const t = now();
|
|
86
|
+
const cutoff = t - windowMs;
|
|
87
|
+
const prev = seen.get(key);
|
|
88
|
+
const ts = prune(prev ?? [], cutoff);
|
|
89
|
+
ts.push(t);
|
|
90
|
+
seen.set(key, ts);
|
|
91
|
+
|
|
92
|
+
// 无上限的 Map 就是一条内存泄漏 —— 调用方是外部输入,不能假设它只查自己的任务。
|
|
93
|
+
if (seen.size > maxKeys) {
|
|
94
|
+
for (const k of seen.keys()) {
|
|
95
|
+
if (seen.size <= maxKeys) break;
|
|
96
|
+
const keep = prune(seen.get(k) ?? [], cutoff);
|
|
97
|
+
if (keep.length === 0) seen.delete(k);
|
|
98
|
+
else seen.set(k, keep);
|
|
99
|
+
}
|
|
100
|
+
// 光靠过期回收不够:如果所有 key 都在窗口内(例如有人用几百个 task_id 乱打),
|
|
101
|
+
// 过期一条也删不掉,长度仍然无界 —— 这里再按插入顺序硬砍到上限。
|
|
102
|
+
while (seen.size > maxKeys) {
|
|
103
|
+
const oldest = seen.keys().next();
|
|
104
|
+
if (oldest.done) break;
|
|
105
|
+
seen.delete(oldest.value);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (ts.length <= spec.threshold) return null;
|
|
110
|
+
return {
|
|
111
|
+
calls_last_60s: ts.length,
|
|
112
|
+
recommended_interval_seconds: POLL_RECOMMENDED_SECONDS,
|
|
113
|
+
note: spec.note,
|
|
114
|
+
};
|
|
115
|
+
},
|
|
116
|
+
size(): number {
|
|
117
|
+
return seen.size;
|
|
118
|
+
},
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** 进程级单例:Hub 只需要看「最近一分钟这位调用方问了多少次」。 */
|
|
123
|
+
export const pollPacer = createPollPacer();
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// #3309 第四条口径 —— `probe_provider_model` 的 4 个 error 字面量此前在测试里**一次都没出现过**:
|
|
2
|
+
//
|
|
3
|
+
// insufficient_role_for_probe / provider_not_found / provider_disabled / secret_not_in_vault
|
|
4
|
+
//
|
|
5
|
+
// 现有的 provider-tools-shape.test.ts 覆盖的是**成功路径**(provider 存在、model 存在、
|
|
6
|
+
// daemon 存在、vault 里有 key)—— 于是这四条拒绝分支从来没被走过。
|
|
7
|
+
//
|
|
8
|
+
// 这里逐个真的触发一次,并断言 `error` 的**确切值**。特别钉住相邻两条不能混:
|
|
9
|
+
//
|
|
10
|
+
// provider 不存在 ⇒ provider_not_found
|
|
11
|
+
// provider 存在但停用 ⇒ provider_disabled
|
|
12
|
+
//
|
|
13
|
+
// 只断言 ok===false 时两者同形,而处置相反(前者要建,后者只要启用)。
|
|
14
|
+
// 代码注释里也写了这条意图("Distinguish not found from disabled so the dashboard
|
|
15
|
+
// can render the right error")—— 注释没有读数,断言才有。
|
|
16
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
17
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
18
|
+
import { db } from "./db.js";
|
|
19
|
+
import { registerTools } from "./tools.js";
|
|
20
|
+
import { stopBackgroundProbeTimersForTest } from "./probe.js";
|
|
21
|
+
|
|
22
|
+
// vault 根密钥存在时 vaultGet 才会「查而不得」(返回 null),否则它自己抛错走另一个分支。
|
|
23
|
+
process.env.ANET_HUB_SECRET_VAULT_KEY ||= "43".repeat(32);
|
|
24
|
+
|
|
25
|
+
const NET = "net_probe_err";
|
|
26
|
+
const ADMIN = "u_probe_err_admin";
|
|
27
|
+
const MEMBER = "u_probe_err_member";
|
|
28
|
+
const PROVIDER = "prov_err";
|
|
29
|
+
const DAEMON = "node_probe_err_daemon";
|
|
30
|
+
|
|
31
|
+
type ToolHandler = (args: any) => Promise<any>;
|
|
32
|
+
|
|
33
|
+
function handlers(userId: string): Record<string, ToolHandler> {
|
|
34
|
+
const server = new McpServer({ name: "t", version: "0" }) as any;
|
|
35
|
+
const tools: Record<string, ToolHandler> = {};
|
|
36
|
+
const orig = server.tool.bind(server);
|
|
37
|
+
server.tool = (name: string, desc: string, schema: any, handler: ToolHandler) => {
|
|
38
|
+
tools[name] = handler;
|
|
39
|
+
return orig(name, desc, schema, handler);
|
|
40
|
+
};
|
|
41
|
+
registerTools(server, undefined, NET, userId, null, false, null);
|
|
42
|
+
return tools;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
async function callProbe(userId: string, args: Record<string, unknown>) {
|
|
46
|
+
const r = await handlers(userId).probe_provider_model(args);
|
|
47
|
+
return JSON.parse(r.content[0].text);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const base = { provider_id: PROVIDER, model_name: "probe-model", daemon_node_id: DAEMON };
|
|
51
|
+
|
|
52
|
+
// 2026-11-01 —— **精确键集,写成集合相等**(不是计数、也不是「有这几个字段」)。
|
|
53
|
+
// 计数可以被换名满足;字段级断言放过多给的键。两者都放过「换名 + 少给」这种最常见的结构变动。
|
|
54
|
+
// 🔴 basis: impl —— 下面这些键集**取自真实调用的响应**,因此它是**变更探测器**,不是契约读数。
|
|
55
|
+
// 红的意思是「实现变了,去看是不是故意的」;而「实现错了」这一类它测不出来
|
|
56
|
+
// (若实现多返回一个字段,断言会红,但那可能是正确的修复)。
|
|
57
|
+
// 要不要升级成 spec 列:需要一处**独立于实现**的书面来源;指不出来时,它就只能留在这里。
|
|
58
|
+
function expectKeys(obj: Record<string, unknown>, want: string[]) {
|
|
59
|
+
expect(Object.keys(obj).sort(), "键集合必须完全等于期望").toEqual([...want].sort());
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function cleanup() {
|
|
63
|
+
db.run("DELETE FROM provider_models WHERE provider_id = ?1", [PROVIDER]);
|
|
64
|
+
db.run("DELETE FROM providers WHERE network_id = ?1", [NET]);
|
|
65
|
+
db.run("DELETE FROM network_members WHERE network_id = ?1", [NET]);
|
|
66
|
+
db.run("DELETE FROM nodes WHERE network_id = ?1", [NET]);
|
|
67
|
+
db.run("DELETE FROM networks WHERE network_id = ?1", [NET]);
|
|
68
|
+
db.run("DELETE FROM users WHERE user_id IN (?1, ?2)", [ADMIN, MEMBER]);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function seed(opts: { enabled: number; secretKey: string }) {
|
|
72
|
+
cleanup();
|
|
73
|
+
db.run("INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?1, 'x', 'user', datetime('now'))", [ADMIN]);
|
|
74
|
+
db.run("INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?1, 'x', 'user', datetime('now'))", [MEMBER]);
|
|
75
|
+
db.run("INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?1, ?2, datetime('now'))", [NET, ADMIN]);
|
|
76
|
+
db.run("INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'owner', datetime('now'))", [ADMIN, NET]);
|
|
77
|
+
db.run("INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'member', datetime('now'))", [MEMBER, NET]);
|
|
78
|
+
db.run(`INSERT INTO nodes (node_id, node_name, alias, network_id, runtime, model, channels, config_snapshot,
|
|
79
|
+
hostname, created_at, updated_at, lifecycle_state)
|
|
80
|
+
VALUES (?1, 'probe-err-daemon', 'probe-err-daemon', ?2, 'claude-agent-sdk', 'm', '[]', '{}', 'host-e',
|
|
81
|
+
datetime('now'), datetime('now'), 'active')`, [DAEMON, NET]);
|
|
82
|
+
db.run(`INSERT INTO providers (provider_id, network_id, name, vendor, base_url, secret_key_ref, created_at, created_by, enabled)
|
|
83
|
+
VALUES (?1, ?2, 'err-provider', 'anthropic', 'https://api.anthropic.com', ?3, ?4, ?5, ?6)`,
|
|
84
|
+
[PROVIDER, NET, opts.secretKey, Date.now(), ADMIN, opts.enabled]);
|
|
85
|
+
db.run(`INSERT INTO provider_models (model_id, provider_id, model_name, display_name, created_at)
|
|
86
|
+
VALUES ('pm_err', ?1, 'probe-model', 'Probe Model', ?2)`, [PROVIDER, Date.now()]);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
beforeEach(() => seed({ enabled: 1, secretKey: "PROBE_ERR_ABSENT" }));
|
|
90
|
+
afterAll(() => { stopBackgroundProbeTimersForTest(); cleanup(); });
|
|
91
|
+
|
|
92
|
+
describe("#3309 probe_provider_model 错误值域:四条拒绝各有一条会红的断言", () => {
|
|
93
|
+
test("成员(非 owner/admin)⇒ error === insufficient_role_for_probe", async () => {
|
|
94
|
+
const r = await callProbe(MEMBER, base);
|
|
95
|
+
expect(r.ok).toBe(false);
|
|
96
|
+
expect(r.error).toBe("insufficient_role_for_probe");
|
|
97
|
+
// 拒绝体还带着「需要什么角色 / 调用者是什么角色」—— 否则读的人只知道被拒,不知道为什么。
|
|
98
|
+
expect(r.required_role).toBe("admin");
|
|
99
|
+
expect(r.caller_role).toBe("member");
|
|
100
|
+
expectKeys(r, ["ok", "error", "required_role", "caller_role"]);
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("provider 不存在 ⇒ error === provider_not_found", async () => {
|
|
104
|
+
const r = await callProbe(ADMIN, { ...base, provider_id: "prov_does_not_exist" });
|
|
105
|
+
expect(r.ok).toBe(false);
|
|
106
|
+
expect(r.error).toBe("provider_not_found");
|
|
107
|
+
expect(r.provider_id).toBe("prov_does_not_exist");
|
|
108
|
+
expectKeys(r, ["ok", "error", "provider_id"]);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
test("provider 存在但停用 ⇒ error === provider_disabled(**不是** provider_not_found)", async () => {
|
|
112
|
+
seed({ enabled: 0, secretKey: "PROBE_ERR_ABSENT" });
|
|
113
|
+
const r = await callProbe(ADMIN, base);
|
|
114
|
+
expect(r.ok).toBe(false);
|
|
115
|
+
expect(r.error).toBe("provider_disabled");
|
|
116
|
+
// 这两条的区别就是这张测试存在的理由:一个要建、一个只要启用。
|
|
117
|
+
expect(r.error).not.toBe("provider_not_found");
|
|
118
|
+
expect(r.hint).toContain("enabled:true");
|
|
119
|
+
expectKeys(r, ["ok", "error", "provider_id", "hint"]);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
test("provider 引用的密钥不在 vault ⇒ error === secret_not_in_vault,且带上键名", async () => {
|
|
123
|
+
const r = await callProbe(ADMIN, base);
|
|
124
|
+
expect(r.ok).toBe(false);
|
|
125
|
+
expect(r.error).toBe("secret_not_in_vault");
|
|
126
|
+
expect(r.key).toBe("PROBE_ERR_ABSENT");
|
|
127
|
+
expectKeys(r, ["ok", "error", "key"]);
|
|
128
|
+
// 键名是标识不是凭据:报出来才能让人去补哪一把。
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
test("四条的形状都**没有** code 字段(现状,不是契约)", async () => {
|
|
132
|
+
const cases = [
|
|
133
|
+
await callProbe(MEMBER, base),
|
|
134
|
+
await callProbe(ADMIN, { ...base, provider_id: "prov_does_not_exist" }),
|
|
135
|
+
];
|
|
136
|
+
seed({ enabled: 0, secretKey: "PROBE_ERR_ABSENT" });
|
|
137
|
+
cases.push(await callProbe(ADMIN, base));
|
|
138
|
+
seed({ enabled: 1, secretKey: "PROBE_ERR_ABSENT" });
|
|
139
|
+
cases.push(await callProbe(ADMIN, base));
|
|
140
|
+
for (const r of cases) {
|
|
141
|
+
expect(r.ok).toBe(false);
|
|
142
|
+
expect(Object.prototype.hasOwnProperty.call(r, "code")).toBe(false);
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
});
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// #667 — a restart from the right directory must clear the cwd warning the
|
|
2
|
+
// previous process left on the same resume_id. Hub stores
|
|
3
|
+
// `task = COALESCE(?11, sessions.task)`, so omitting task keeps the warning.
|
|
4
|
+
// Register sends task: "" once. Later idle reports omit task, so the
|
|
5
|
+
// description of a finished task stays. This boots a throwaway hub on
|
|
6
|
+
// port 0 (never 9200).
|
|
7
|
+
|
|
8
|
+
import { afterAll, beforeAll, describe, expect, test } from "bun:test";
|
|
9
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
10
|
+
import { tmpdir } from "node:os";
|
|
11
|
+
import { join } from "node:path";
|
|
12
|
+
import { reportedTask } from "../../agent-node/src/project-dir-mismatch.ts";
|
|
13
|
+
|
|
14
|
+
const DIR = mkdtempSync(join(tmpdir(), "anet-667-clear-"));
|
|
15
|
+
process.env.COMMHUB_DB = join(DIR, "hub.db");
|
|
16
|
+
process.env.COMMHUB_UPLOADS_DIR = join(DIR, "uploads");
|
|
17
|
+
process.env.HOST = "127.0.0.1";
|
|
18
|
+
|
|
19
|
+
const PW = "ProjectDirWarn123!x";
|
|
20
|
+
const stamp = Date.now();
|
|
21
|
+
const ROOT = "/work";
|
|
22
|
+
const NODE_DIR = "/work/.anet/nodes/demo-node";
|
|
23
|
+
const CONFIG = `${NODE_DIR}/config.json`;
|
|
24
|
+
|
|
25
|
+
let db: { get: (sql: string, ...params: unknown[]) => { task: string | null } | null };
|
|
26
|
+
let hub: { port: number; stop: (close?: boolean) => void } | null = null;
|
|
27
|
+
let BASE = "";
|
|
28
|
+
let NET = "";
|
|
29
|
+
let node: { alias: string; nodeId: string; token: string };
|
|
30
|
+
|
|
31
|
+
async function tool(token: string, name: string, args: Record<string, unknown>) {
|
|
32
|
+
const res = await fetch(`${BASE}/mcp`, {
|
|
33
|
+
method: "POST",
|
|
34
|
+
headers: {
|
|
35
|
+
Authorization: `Bearer ${token}`,
|
|
36
|
+
"Content-Type": "application/json",
|
|
37
|
+
Accept: "application/json, text/event-stream",
|
|
38
|
+
"MCP-Protocol-Version": "2025-03-26",
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: args } }),
|
|
41
|
+
});
|
|
42
|
+
const raw = await res.text();
|
|
43
|
+
const data = raw.split("\n").filter((line) => line.startsWith("data:"));
|
|
44
|
+
const payload = data.length ? JSON.parse(data.at(-1)!.slice(5).trim()) : JSON.parse(raw);
|
|
45
|
+
return JSON.parse(payload.result.content[0].text);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function sessionTask(): string | null {
|
|
49
|
+
return db.get("SELECT task FROM sessions WHERE resume_id = ?1", `sdk-${node.nodeId}`)?.task ?? null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
beforeAll(async () => {
|
|
53
|
+
({ db } = await import("./db.js"));
|
|
54
|
+
const { createNetworkTokenForNode, register } = await import("./auth.js");
|
|
55
|
+
const boss = register(`cwd_boss_${stamp}`, PW);
|
|
56
|
+
expect(boss.ok).toBe(true);
|
|
57
|
+
NET = boss.network_id!;
|
|
58
|
+
const alias = `demo-node-${stamp}`;
|
|
59
|
+
const nodeId = `n_cwd_${stamp}`;
|
|
60
|
+
const minted = createNetworkTokenForNode(boss.user!.user_id, NET, alias, nodeId);
|
|
61
|
+
expect(minted.ok).toBe(true);
|
|
62
|
+
node = { alias, nodeId, token: minted.token! };
|
|
63
|
+
const mod = await import("./server.js");
|
|
64
|
+
hub = mod.bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
65
|
+
expect(hub.port).not.toBe(9200);
|
|
66
|
+
expect(hub.port).toBeGreaterThan(0);
|
|
67
|
+
BASE = `http://127.0.0.1:${hub.port}`;
|
|
68
|
+
}, 30_000);
|
|
69
|
+
|
|
70
|
+
afterAll(() => {
|
|
71
|
+
try { hub?.stop(true); } catch { /* already stopped */ }
|
|
72
|
+
try { rmSync(DIR, { recursive: true, force: true }); } catch { /* temp dir */ }
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
describe("#667 restart from the workspace root clears the cwd warning", () => {
|
|
76
|
+
test("wrong directory writes the warning; the right directory sends \"\" and the hub row is empty", async () => {
|
|
77
|
+
const resume = `sdk-${node.nodeId}`;
|
|
78
|
+
const wrong = reportedTask({ configPath: CONFIG, cwd: NODE_DIR, inFlight: 0, status: "idle" });
|
|
79
|
+
expect(wrong).toContain("目录不一致");
|
|
80
|
+
const started = await tool(node.token, "report_status", {
|
|
81
|
+
resume_id: resume, alias: node.alias, status: "idle", node_id: node.nodeId, network_id: NET, task: wrong,
|
|
82
|
+
});
|
|
83
|
+
expect(started.ok).toBe(true);
|
|
84
|
+
expect(sessionTask()).toBe(wrong);
|
|
85
|
+
|
|
86
|
+
const kept = await tool(node.token, "report_status", {
|
|
87
|
+
resume_id: resume, alias: node.alias, status: "idle", node_id: node.nodeId, network_id: NET,
|
|
88
|
+
});
|
|
89
|
+
expect(kept.ok).toBe(true);
|
|
90
|
+
expect(sessionTask()).toBe(wrong);
|
|
91
|
+
|
|
92
|
+
const idle = reportedTask({ configPath: CONFIG, cwd: ROOT, inFlight: 0, status: "idle" });
|
|
93
|
+
expect(idle).toBeUndefined();
|
|
94
|
+
const cleared = idle ?? "";
|
|
95
|
+
expect(cleared).toBe("");
|
|
96
|
+
const fixed = await tool(node.token, "report_status", {
|
|
97
|
+
resume_id: resume, alias: node.alias, status: "idle", node_id: node.nodeId, network_id: NET, task: cleared,
|
|
98
|
+
});
|
|
99
|
+
expect(fixed.ok).toBe(true);
|
|
100
|
+
expect(sessionTask()).toBe("");
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
test("after startup, a finished task's description stays on the hub", async () => {
|
|
104
|
+
const resume = `sdk-${node.nodeId}`;
|
|
105
|
+
const description = "BOARD667-FINISHED-TASK";
|
|
106
|
+
const startup = reportedTask({ configPath: CONFIG, cwd: ROOT, inFlight: 0, status: "idle" }) ?? "";
|
|
107
|
+
expect(startup).toBe("");
|
|
108
|
+
const registered = await tool(node.token, "report_status", {
|
|
109
|
+
resume_id: resume, alias: node.alias, status: "idle", node_id: node.nodeId, network_id: NET, task: startup,
|
|
110
|
+
});
|
|
111
|
+
expect(registered.ok).toBe(true);
|
|
112
|
+
expect(sessionTask()).toBe("");
|
|
113
|
+
|
|
114
|
+
const working = reportedTask({
|
|
115
|
+
configPath: CONFIG, cwd: ROOT, inFlight: 1, status: "working", task: description,
|
|
116
|
+
});
|
|
117
|
+
expect(working).toBe(description);
|
|
118
|
+
const ran = await tool(node.token, "report_status", {
|
|
119
|
+
resume_id: resume, alias: node.alias, status: "working", node_id: node.nodeId, network_id: NET, task: working,
|
|
120
|
+
});
|
|
121
|
+
expect(ran.ok).toBe(true);
|
|
122
|
+
expect(sessionTask()).toBe(description);
|
|
123
|
+
|
|
124
|
+
const finished = reportedTask({ configPath: CONFIG, cwd: ROOT, inFlight: 0, status: "idle" });
|
|
125
|
+
expect(finished).toBeUndefined();
|
|
126
|
+
const done = await tool(node.token, "report_status", {
|
|
127
|
+
resume_id: resume, alias: node.alias, status: "idle", node_id: node.nodeId, network_id: NET,
|
|
128
|
+
});
|
|
129
|
+
expect(done.ok).toBe(true);
|
|
130
|
+
expect(sessionTask()).toBe(description);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// GET /api/requirements/projects 的每行 viewer_can.edit(app 任务页审计 L13)—— HTTP 集成测试(真实 Bun.serve,私有端口,临时库)。
|
|
2
|
+
//
|
|
3
|
+
// 客户端据此只在新建 / 挪卡的项目下拉里列「能编辑」的项目。判据必须与真写卡时一致,所以这里对每个项目
|
|
4
|
+
// 都真建一张卡,断言「viewer_can.edit === 建卡成功」,而不是另抄一份规则来比。
|
|
5
|
+
// admin —— Hub 管理员 + 网络 owner:未归档项目全 true,归档的 false(projectRef 拒归档)
|
|
6
|
+
// alice —— scoped 成员:P1 只看 → false,P2 可改 → true(只列得到这两个)
|
|
7
|
+
// carol —— task_access='all' 的成员:未归档全 true
|
|
8
|
+
// vic —— scoped viewer,P3 只看:false(viewer 本来就不能写卡)
|
|
9
|
+
|
|
10
|
+
import { describe, expect, test, beforeAll, afterAll } from "bun:test";
|
|
11
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
12
|
+
import { join } from "path";
|
|
13
|
+
import { tmpdir } from "os";
|
|
14
|
+
import { register } from "./auth.js";
|
|
15
|
+
import { db } from "./db.js";
|
|
16
|
+
|
|
17
|
+
const DIR = mkdtempSync(join(tmpdir(), "anet-project-viewer-can-"));
|
|
18
|
+
let BASE = "";
|
|
19
|
+
let hub: any = null;
|
|
20
|
+
const PW = "ProjViewerCanPassw0rd!x";
|
|
21
|
+
let NET = "";
|
|
22
|
+
const U: Record<string, { token: string; id: string }> = {};
|
|
23
|
+
const P: Record<string, string> = {};
|
|
24
|
+
|
|
25
|
+
type R = { status: number; body: any };
|
|
26
|
+
async function send(token: string, method: string, path: string, payload?: unknown): Promise<R> {
|
|
27
|
+
const res = await fetch(`${BASE}${path}`, {
|
|
28
|
+
method,
|
|
29
|
+
headers: { ...(token ? { Authorization: `Bearer ${token}` } : {}), "Content-Type": "application/json" },
|
|
30
|
+
body: payload === undefined ? undefined : JSON.stringify(payload),
|
|
31
|
+
});
|
|
32
|
+
const text = await res.text();
|
|
33
|
+
let body: any = null;
|
|
34
|
+
try { body = JSON.parse(text); } catch {}
|
|
35
|
+
return { status: res.status, body };
|
|
36
|
+
}
|
|
37
|
+
const projects = async (who: string) => {
|
|
38
|
+
const r = await send(U[who].token, "GET", `/api/requirements/projects?network_id=${NET}`);
|
|
39
|
+
expect(r.status).toBe(200);
|
|
40
|
+
return Object.fromEntries((r.body.projects as any[]).map((p) => [p.name, p]));
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
beforeAll(async () => {
|
|
44
|
+
process.env.COMMHUB_DB ||= join(DIR, "hub.db");
|
|
45
|
+
process.env.COMMHUB_UPLOADS_DIR = join(DIR, "uploads");
|
|
46
|
+
process.env.HOST = "127.0.0.1";
|
|
47
|
+
const a = register(`pvc_admin_${Date.now()}`, PW, undefined, "Admin");
|
|
48
|
+
expect(a.ok).toBe(true);
|
|
49
|
+
U.admin = { token: a.token!, id: a.user!.user_id };
|
|
50
|
+
NET = a.network_id!;
|
|
51
|
+
db.run("UPDATE users SET role = 'admin' WHERE user_id = ?1", [U.admin.id]);
|
|
52
|
+
const mod: any = await import("./server.js");
|
|
53
|
+
hub = mod.bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
54
|
+
BASE = `http://127.0.0.1:${hub.port}`;
|
|
55
|
+
|
|
56
|
+
const mk = async (username: string, role: string) => {
|
|
57
|
+
expect((await send(U.admin.token, "POST", "/api/admin/users", { username, password: PW, network_id: NET, role })).status).toBe(200);
|
|
58
|
+
const login = await send("", "POST", "/api/auth/login", { username, password: PW });
|
|
59
|
+
expect(login.status).toBe(200);
|
|
60
|
+
return { token: login.body.token as string, id: login.body.user.user_id as string };
|
|
61
|
+
};
|
|
62
|
+
const stamp = Date.now();
|
|
63
|
+
U.alice = await mk(`pvc_alice_${stamp}`, "member");
|
|
64
|
+
U.carol = await mk(`pvc_carol_${stamp}`, "member");
|
|
65
|
+
U.vic = await mk(`pvc_vic_${stamp}`, "viewer");
|
|
66
|
+
db.run("UPDATE network_members SET task_access = 'all' WHERE network_id = ?1 AND user_id = ?2", [NET, U.carol.id]);
|
|
67
|
+
|
|
68
|
+
for (const name of ["pvc-P1", "pvc-P2", "pvc-P3", "pvc-P4"]) {
|
|
69
|
+
const r = await send(U.admin.token, "POST", "/api/requirements/projects", { network_id: NET, name });
|
|
70
|
+
expect(r.status).toBe(201);
|
|
71
|
+
P[name] = r.body.project.id;
|
|
72
|
+
}
|
|
73
|
+
expect((await send(U.admin.token, "PATCH", `/api/requirements/projects/${P["pvc-P4"]}?network_id=${NET}`, { archived: true })).status).toBe(200);
|
|
74
|
+
expect((await send(U.admin.token, "PUT", `/api/networks/${NET}/members/${U.alice.id}/task-grants`, { task_access: "scoped", project_grants: [{ project_id: P["pvc-P1"] }, { project_id: P["pvc-P2"], can_edit: true }] })).status).toBe(200);
|
|
75
|
+
expect((await send(U.admin.token, "PUT", `/api/networks/${NET}/members/${U.vic.id}/task-grants`, { task_access: "scoped", project_grants: [P["pvc-P3"]] })).status).toBe(200);
|
|
76
|
+
}, 30_000);
|
|
77
|
+
|
|
78
|
+
afterAll(() => {
|
|
79
|
+
try { hub?.stop?.(true); } catch {}
|
|
80
|
+
try { rmSync(DIR, { recursive: true, force: true }); } catch {}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe("GET /api/requirements/projects 的 viewer_can.edit", () => {
|
|
84
|
+
test("每个调用者的取值", async () => {
|
|
85
|
+
const edit = (rows: Record<string, any>) => Object.fromEntries(Object.entries(rows).map(([n, p]) => [n, p.viewer_can?.edit]));
|
|
86
|
+
expect(edit(await projects("admin"))).toEqual({ "pvc-P1": true, "pvc-P2": true, "pvc-P3": true, "pvc-P4": false });
|
|
87
|
+
expect(edit(await projects("carol"))).toEqual({ "pvc-P1": true, "pvc-P2": true, "pvc-P3": true, "pvc-P4": false });
|
|
88
|
+
expect(edit(await projects("alice"))).toEqual({ "pvc-P1": false, "pvc-P2": true });
|
|
89
|
+
expect(edit(await projects("vic"))).toEqual({ "pvc-P3": false });
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("只加字段:其余键与之前逐字相同", async () => {
|
|
93
|
+
const row = (await projects("alice"))["pvc-P2"];
|
|
94
|
+
// parentId 是 2026-10-24 加的「子项目」字段(admin:管理项目里看不到层级);
|
|
95
|
+
// 它同样是加法式的:这里钉的是「已知键一个不多一个不少」,新键必须显式加进这个清单。
|
|
96
|
+
expect(Object.keys(row).sort()).toEqual(["archived", "color", "createdAt", "id", "name", "parentId", "sort", "viewer_can"]);
|
|
97
|
+
expect(Object.keys(row.viewer_can)).toEqual(["edit"]);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("与真写卡一致:edit === 往这个项目建卡成功", async () => {
|
|
101
|
+
let checked = 0;
|
|
102
|
+
for (const who of ["admin", "carol", "alice", "vic"]) {
|
|
103
|
+
for (const [name, p] of Object.entries(await projects(who))) {
|
|
104
|
+
const r = await send(U[who].token, "POST", "/api/requirements", { network_id: NET, name: `pvc-card-${who}-${name}`, project_id: p.id });
|
|
105
|
+
expect({ who, name, created: r.status === 201 }).toEqual({ who, name, created: p.viewer_can.edit });
|
|
106
|
+
checked++;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
expect(checked).toBe(11);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
test("授权改成可编辑后立即反映", async () => {
|
|
113
|
+
expect((await send(U.admin.token, "PUT", `/api/networks/${NET}/members/${U.alice.id}/task-grants`, { project_grants: [{ project_id: P["pvc-P1"], can_edit: true }, { project_id: P["pvc-P2"], can_edit: true }] })).status).toBe(200);
|
|
114
|
+
expect((await projects("alice"))["pvc-P1"].viewer_can.edit).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
});
|