@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,885 @@
|
|
|
1
|
+
// 多用户账号与 Agent 权限 —— slice 3:剩下的面向 Agent 的路径。
|
|
2
|
+
//
|
|
3
|
+
// slice 1(agent-acl-http.test.ts)把默认作用域做成 fail-closed,并对核心路径逐条放行。
|
|
4
|
+
// 这里补:授权后 task_events 跟随授权 Agent 的时间线(#563)、messages 的「只看自己往来」、改名广播不外泄 alias、
|
|
5
|
+
// 排程在建的人被收权后不再代派、用户名与后注册的 Agent alias 撞名、以及
|
|
6
|
+
// rules / skills / files / logs 对受限成员(即使授权了)仍然拒绝 —— 这是一个明确的产品决定:
|
|
7
|
+
// 授权 = 能看见、能对话;不等于能管理这个 Agent。
|
|
8
|
+
|
|
9
|
+
import { describe, expect, test, beforeAll, afterAll } from "bun:test";
|
|
10
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
11
|
+
import { join } from "path";
|
|
12
|
+
import { tmpdir } from "os";
|
|
13
|
+
import { register, addNetworkMember, createNetworkTokenForNode } from "./auth.js";
|
|
14
|
+
import { db } from "./db.js";
|
|
15
|
+
import { replaceAgentGrants } from "./agent-access.js";
|
|
16
|
+
import { dispatchScheduledOccurrence } from "./scheduled-tasks.js";
|
|
17
|
+
|
|
18
|
+
const DIR = mkdtempSync(join(tmpdir(), "anet-agent-acl3-"));
|
|
19
|
+
let BASE = "";
|
|
20
|
+
let hub: any = null;
|
|
21
|
+
const PW = "AclSlice3Passw0rd!";
|
|
22
|
+
let adminToken = "", adminId = "", adminName = "", NET = "";
|
|
23
|
+
let carolToken = "", carolId = "";
|
|
24
|
+
|
|
25
|
+
const X = { alias: "acl3-agent-x", node: "node_acl3_x" };
|
|
26
|
+
const Z = { alias: "acl3-agent-z", node: "node_acl3_z" };
|
|
27
|
+
const auth = (t: string) => ({ Authorization: `Bearer ${t}` });
|
|
28
|
+
|
|
29
|
+
async function get(token: string, path: string) {
|
|
30
|
+
const res = await fetch(`${BASE}${path}`, { headers: auth(token) });
|
|
31
|
+
return { status: res.status, body: await res.json().catch(() => null) as any };
|
|
32
|
+
}
|
|
33
|
+
async function send(token: string, method: string, path: string, payload?: unknown) {
|
|
34
|
+
const res = await fetch(`${BASE}${path}`, { method, headers: { ...auth(token), "Content-Type": "application/json" }, body: payload === undefined ? undefined : JSON.stringify(payload) });
|
|
35
|
+
return { status: res.status, body: await res.json().catch(() => null) as any };
|
|
36
|
+
}
|
|
37
|
+
async function tool(token: string, name: string, args: Record<string, unknown>) {
|
|
38
|
+
const res = await fetch(`${BASE}/mcp`, {
|
|
39
|
+
method: "POST",
|
|
40
|
+
headers: { ...auth(token), "Content-Type": "application/json", Accept: "application/json, text/event-stream", "MCP-Protocol-Version": "2025-03-26" },
|
|
41
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/call", params: { name, arguments: args } }),
|
|
42
|
+
});
|
|
43
|
+
const raw = await res.text();
|
|
44
|
+
const data = raw.split("\n").filter(x => x.startsWith("data:"));
|
|
45
|
+
const payload = data.length ? JSON.parse(data.at(-1)!.slice(5).trim()) : JSON.parse(raw);
|
|
46
|
+
const text = payload.result.content[0].text;
|
|
47
|
+
// 参数没过 zod 的调用根本没进到处理函数(也就没进到权限判定),当成测试写错了而不是「被拒」。
|
|
48
|
+
if (!text.startsWith("{")) throw new Error(`${name}: ${text}`);
|
|
49
|
+
return JSON.parse(text);
|
|
50
|
+
}
|
|
51
|
+
function seedAgent(a: { alias: string; node: string }) {
|
|
52
|
+
db.run(`INSERT INTO nodes (node_id, node_name, alias, network_id, owner_user_id) VALUES (?1, ?2, ?2, ?3, ?4)`, [a.node, a.alias, NET, adminId]);
|
|
53
|
+
db.run(`INSERT INTO sessions (resume_id, alias, node_id, status, network_id, updated_at, last_seen_at) VALUES (?1, ?2, ?3, 'idle', ?4, datetime('now'), datetime('now'))`, [`r_${a.node}`, a.alias, a.node, NET]);
|
|
54
|
+
}
|
|
55
|
+
function seedTask(id: string, from: string, to: string, content: string) {
|
|
56
|
+
db.run(`INSERT INTO tasks (task_id, from_name, to_name, status, content, network_id) VALUES (?1, ?2, ?3, 'replied', ?4, ?5)`, [id, from, to, content, NET]);
|
|
57
|
+
db.run(`INSERT INTO inbox (id, task_id, session_name, type, priority, content, from_session, network_id) VALUES (?1, ?2, ?3, 'task', 'normal', ?4, ?5, ?6)`, [`ib_${id}`, id, to, content, from, NET]);
|
|
58
|
+
db.run(`INSERT INTO task_events (task_id, to_status, actor, network_id) VALUES (?1, 'replied', 'test', ?2)`, [id, NET]);
|
|
59
|
+
}
|
|
60
|
+
async function openStream(path: string, token: string) {
|
|
61
|
+
const ctrl = new AbortController();
|
|
62
|
+
const res = await fetch(`${BASE}${path}`, { headers: auth(token), signal: ctrl.signal });
|
|
63
|
+
const reader = res.body!.getReader();
|
|
64
|
+
const decoder = new TextDecoder();
|
|
65
|
+
let buf = "";
|
|
66
|
+
let pending: ReturnType<typeof reader.read> | null = null;
|
|
67
|
+
const readFor = async (ms: number) => {
|
|
68
|
+
const until = Date.now() + ms;
|
|
69
|
+
while (Date.now() < until) {
|
|
70
|
+
pending ??= reader.read();
|
|
71
|
+
const chunk = await Promise.race([pending, new Promise<null>(r => setTimeout(() => r(null), until - Date.now()))]);
|
|
72
|
+
if (!chunk) break;
|
|
73
|
+
pending = null;
|
|
74
|
+
if (chunk.done) break;
|
|
75
|
+
buf += decoder.decode(chunk.value);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
return { status: res.status, readFor, events: () => buf.split("\n").filter(l => l.startsWith("data:")).map(l => JSON.parse(l.slice(5))), close: () => ctrl.abort() };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
beforeAll(async () => {
|
|
82
|
+
process.env.COMMHUB_DB ||= join(DIR, "hub.db");
|
|
83
|
+
process.env.COMMHUB_UPLOADS_DIR = join(DIR, "uploads");
|
|
84
|
+
process.env.HOST = "127.0.0.1";
|
|
85
|
+
adminName = `acl3_admin_${Date.now()}`;
|
|
86
|
+
const admin = register(adminName, PW);
|
|
87
|
+
adminToken = admin.token!; adminId = admin.user!.user_id; NET = admin.network_id!;
|
|
88
|
+
db.run("UPDATE users SET role = 'admin' WHERE user_id = ?1", [adminId]);
|
|
89
|
+
seedAgent(X); seedAgent(Z);
|
|
90
|
+
const carol = register("acl3_carol", PW);
|
|
91
|
+
carolToken = carol.token!; carolId = carol.user!.user_id;
|
|
92
|
+
expect(addNetworkMember(NET, carolId, "member", adminId).ok).toBe(true);
|
|
93
|
+
expect(replaceAgentGrants({ networkId: NET, userId: carolId, grants: [{ node_id: X.node }], actorUserId: adminId }).ok).toBe(true);
|
|
94
|
+
seedTask("t3_admin_x", adminName, X.alias, "admin to X");
|
|
95
|
+
seedTask("t3_carol_x", "acl3_carol", X.alias, "carol to X");
|
|
96
|
+
seedTask("t3_x_carol", X.alias, "acl3_carol", "X to carol");
|
|
97
|
+
const mod: any = await import("./server.js");
|
|
98
|
+
hub = mod.bootServer({ port: 0, hostname: "127.0.0.1" });
|
|
99
|
+
BASE = `http://127.0.0.1:${hub.port}`;
|
|
100
|
+
}, 30_000);
|
|
101
|
+
|
|
102
|
+
afterAll(() => {
|
|
103
|
+
try { hub?.stop?.(true); } catch {}
|
|
104
|
+
try { rmSync(DIR, { recursive: true, force: true }); } catch {}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe("granted member: task_events follow X's timeline (#563); messages stay own traffic", () => {
|
|
108
|
+
test("task_events: every task on granted X's timeline is visible, including admin's (#563)", async () => {
|
|
109
|
+
const mine = await get(carolToken, `/api/task_events?task_id=t3_carol_x`);
|
|
110
|
+
expect(mine.body.events.length).toBe(1);
|
|
111
|
+
expect((await get(carolToken, `/api/task_events?task_id=t3_x_carol`)).body.events.length).toBe(1);
|
|
112
|
+
expect((await get(carolToken, `/api/task_events?task_id=t3_admin_x`)).body.events.length).toBe(1);
|
|
113
|
+
const all = await get(carolToken, `/api/task_events?network_id=${NET}`);
|
|
114
|
+
expect(all.body.events.map((e: any) => e.task_id).sort()).toEqual(["t3_admin_x", "t3_carol_x", "t3_x_carol"]);
|
|
115
|
+
});
|
|
116
|
+
test("messages (alias branch): own inbox rows with X only; admin's never", async () => {
|
|
117
|
+
const r = await get(carolToken, `/api/messages?network_id=${NET}&since=2000-01-01`);
|
|
118
|
+
expect(r.body.messages.map((m: any) => m.content).sort()).toEqual(["X to carol", "carol to X"].sort());
|
|
119
|
+
const x = await get(carolToken, `/api/messages?alias=${X.alias}&since=2000-01-01`);
|
|
120
|
+
expect(x.body.messages.map((m: any) => m.content)).toEqual(["carol to X"]);
|
|
121
|
+
expect(x.body.pending_count).toBe(1);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe("decision: granted ≠ administer — rules / skills / files / logs / config stay refused", () => {
|
|
126
|
+
test("every read and write admin op on the GRANTED agent is refused", async () => {
|
|
127
|
+
for (const [name, args] of [
|
|
128
|
+
["read_node_rules_file", { alias: X.alias, network_id: NET }],
|
|
129
|
+
["write_node_rules_file", { alias: X.alias, content: "x", network_id: NET }],
|
|
130
|
+
["list_node_skills", { alias: X.alias, network_id: NET }],
|
|
131
|
+
["list_node_files", { alias: X.alias, network_id: NET }],
|
|
132
|
+
["tail_node_logs", { alias: X.alias, network_id: NET }],
|
|
133
|
+
["update_node_config", { node_id: X.node, base_revision: 0, patch: { model: "m" }, network_id: NET }],
|
|
134
|
+
["restart_node", { node_id: X.node, network_id: NET }],
|
|
135
|
+
] as const) {
|
|
136
|
+
expect((await tool(carolToken, name, args as any)).error).toBe("agent_access_restricted");
|
|
137
|
+
}
|
|
138
|
+
expect((await send(carolToken, "PUT", `/api/nodes/${X.node}/attrs?network_id=${NET}`, { display_name: "pwned" })).status).toBeGreaterThanOrEqual(403);
|
|
139
|
+
expect(db.get<{ display_name: string | null }>("SELECT display_name FROM nodes WHERE node_id = ?1", X.node)?.display_name ?? null).toBeNull();
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("rename broadcast does not leak aliases to restricted members", () => {
|
|
144
|
+
test("renaming Z (not granted) sends nothing to carol; renaming X (granted) does", async () => {
|
|
145
|
+
const s = await openStream(`/events/acl3_carol?network_id=${NET}`, carolToken);
|
|
146
|
+
expect(s.status).toBe(200);
|
|
147
|
+
await s.readFor(100);
|
|
148
|
+
const renameTo = async (oldAlias: string, newAlias: string) => {
|
|
149
|
+
const p = await send(adminToken, "POST", "/api/node-rename/prepare", { network_id: NET, old_alias: oldAlias, new_alias: newAlias });
|
|
150
|
+
expect(p.body.ok).toBe(true);
|
|
151
|
+
// 2026-10-31 —— #3214:rename 的两个端点此前只断言 ok,形状从未被钉。
|
|
152
|
+
// 形状由**真实调用**给出(我先写了一版「按 in body 过滤」的断言 —— 那是恒真的,等于没写)。
|
|
153
|
+
// prepare ⇒ {ok, txn_id} 两阶段的第一步:客户端必须拿到 txn_id 才能 commit
|
|
154
|
+
// commit ⇒ {ok, txn_id} 回执同样只这两键
|
|
155
|
+
expect(Object.keys(p.body).sort()).toEqual(["ok", "txn_id"]);
|
|
156
|
+
expect(typeof p.body.txn_id).toBe("string");
|
|
157
|
+
const c = await send(adminToken, "POST", "/api/node-rename/commit", { txn_id: p.body.txn_id });
|
|
158
|
+
expect(c.body.ok).toBe(true);
|
|
159
|
+
expect(Object.keys(c.body).sort()).toEqual(["ok", "txn_id"]);
|
|
160
|
+
};
|
|
161
|
+
await renameTo(Z.alias, "acl3-agent-z2");
|
|
162
|
+
await renameTo(X.alias, "acl3-agent-x2");
|
|
163
|
+
await s.readFor(400);
|
|
164
|
+
s.close();
|
|
165
|
+
const renamed = s.events().filter(e => e.type === "node.renamed").map(e => e.data.new_alias);
|
|
166
|
+
expect(renamed).toEqual(["acl3-agent-x2"]);
|
|
167
|
+
// 改名后授权(按 node_id)仍然有效。
|
|
168
|
+
expect((await get(carolToken, `/api/status?network_id=${NET}`)).body.sessions.map((r: any) => r.alias)).toEqual(["acl3-agent-x2"]);
|
|
169
|
+
await renameTo("acl3-agent-z2", Z.alias);
|
|
170
|
+
await renameTo("acl3-agent-x2", X.alias);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe("schedules created before a restriction stop dispatching", () => {
|
|
175
|
+
function schedule(createdBy: string, target: { alias: string; node: string }) {
|
|
176
|
+
const id = `sched_acl3_${createdBy}_${target.node}`;
|
|
177
|
+
db.run(
|
|
178
|
+
`INSERT INTO scheduled_tasks (schedule_id, network_id, created_by, name, target_node_id, target_alias, task_content, schedule_type, schedule_json, next_run_at)
|
|
179
|
+
VALUES (?1, ?2, ?3, 'n', ?4, ?5, 'scheduled work', 'interval', '{"type":"interval","minutes":60}', datetime('now'))`,
|
|
180
|
+
[id, NET, createdBy, target.node, target.alias],
|
|
181
|
+
);
|
|
182
|
+
return db.get<any>("SELECT * FROM scheduled_tasks WHERE schedule_id = ?1", id);
|
|
183
|
+
}
|
|
184
|
+
test("carol (restricted) → Z (not granted): run fails creator_access_revoked, no task created", () => {
|
|
185
|
+
const row = schedule(carolId, Z);
|
|
186
|
+
const r = dispatchScheduledOccurrence(row, new Date().toISOString(), false);
|
|
187
|
+
expect(r.status).toBe("failed");
|
|
188
|
+
expect(r.taskId).toBeUndefined();
|
|
189
|
+
expect(db.get<{ error_code: string }>("SELECT error_code FROM scheduled_task_runs WHERE run_id = ?1", r.runId)?.error_code).toBe("creator_access_revoked");
|
|
190
|
+
});
|
|
191
|
+
test("carol → X (granted, can_message): dispatches", () => {
|
|
192
|
+
const r = dispatchScheduledOccurrence(schedule(carolId, X), new Date(Date.now() + 1000).toISOString(), false);
|
|
193
|
+
expect(r.taskId).toBeTruthy();
|
|
194
|
+
});
|
|
195
|
+
test("owner-created schedules are unaffected", () => {
|
|
196
|
+
const r = dispatchScheduledOccurrence(schedule(adminId, Z), new Date(Date.now() + 2000).toISOString(), false);
|
|
197
|
+
expect(r.taskId).toBeTruthy();
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe("username collides with an agent alias registered later", () => {
|
|
202
|
+
test("carol's own channel and own traffic close for that network", async () => {
|
|
203
|
+
expect((await get(carolToken, `/api/tasks?network_id=${NET}`)).body.tasks.length).toBeGreaterThan(0);
|
|
204
|
+
db.run(`INSERT INTO sessions (resume_id, alias, status, network_id, updated_at, last_seen_at) VALUES ('r_collide', 'acl3_carol', 'idle', ?1, datetime('now'), datetime('now'))`, [NET]);
|
|
205
|
+
const s = await fetch(`${BASE}/events/acl3_carol?network_id=${NET}`, { headers: auth(carolToken) });
|
|
206
|
+
expect(s.status).toBe(403);
|
|
207
|
+
await s.body?.cancel();
|
|
208
|
+
expect((await get(carolToken, `/api/tasks?network_id=${NET}`)).body.tasks).toEqual([]);
|
|
209
|
+
expect((await get(carolToken, `/api/messages?network_id=${NET}&since=2000-01-01`)).body.messages).toEqual([]);
|
|
210
|
+
db.run("DELETE FROM sessions WHERE resume_id = 'r_collide'");
|
|
211
|
+
expect((await get(carolToken, `/api/tasks?network_id=${NET}`)).body.tasks.length).toBeGreaterThan(0);
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe("human ↔ human DM (/api/dm): restricted members can talk to people", () => {
|
|
216
|
+
let daveToken = "", daveId = "";
|
|
217
|
+
test("carol (restricted) DMs dave; dave sees it in thread + threads + user inbox and replies", async () => {
|
|
218
|
+
const dave = register("acl3_dave", PW);
|
|
219
|
+
daveToken = dave.token!; daveId = dave.user!.user_id;
|
|
220
|
+
expect(addNetworkMember(NET, daveId, "member", adminId).ok).toBe(true);
|
|
221
|
+
const sent = await send(carolToken, "POST", "/api/dm", { network_id: NET, to_user_id: daveId, message: "hi dave", client_request_id: "c1" });
|
|
222
|
+
expect(sent.status).toBe(200);
|
|
223
|
+
expect(sent.body.message.sender_user_id).toBe(carolId);
|
|
224
|
+
// 重试同一个气泡不产生第二条。
|
|
225
|
+
expect((await send(carolToken, "POST", "/api/dm", { network_id: NET, to_user_id: daveId, message: "hi dave", client_request_id: "c1" })).body.message.message_id).toBe(sent.body.message.message_id);
|
|
226
|
+
const threads = await get(daveToken, `/api/dm/threads?network_id=${NET}`);
|
|
227
|
+
expect(threads.body.threads).toEqual([expect.objectContaining({ other_user_id: carolId, unread: 1 })]);
|
|
228
|
+
expect((await get(daveToken, `/api/messages?scope=user&network_id=${NET}`)).body.messages.map((m: any) => m.content)).toContain("hi dave");
|
|
229
|
+
// 2026-10-31 —— **顺序承载语义**的行为对照(#3214)。
|
|
230
|
+
// `/api/messages` 在 server.ts 里有两处::5581 是 `?scope=user`,:5648 是通用(inbox,按 Agent)。
|
|
231
|
+
// 若有人把通用分支挪到前面,这一句带 scope 的请求会被它吃掉 —— 而响应仍是合法 200,
|
|
232
|
+
// 只是形状从 user_inbox 变成 inbox。两组断言必须同时在场,才能把这件事钉住。
|
|
233
|
+
const withScope = await get(daveToken, `/api/messages?scope=user&network_id=${NET}`);
|
|
234
|
+
const withoutScope = await get(daveToken, `/api/messages?network_id=${NET}`);
|
|
235
|
+
// user 视角:来自 user_inbox,字段是 message_id / acked_at
|
|
236
|
+
expect(withScope.body.messages[0]).toHaveProperty("message_id");
|
|
237
|
+
// 通用视角:来自 inbox,字段是 id / to_alias / from_alias
|
|
238
|
+
expect(withoutScope.body.messages[0] ?? {}).not.toHaveProperty("message_id");
|
|
239
|
+
expect(withScope.body.messages.map((m: any) => m.content)).toContain("hi dave");
|
|
240
|
+
expect((withoutScope.body.messages ?? []).map((m: any) => m.content)).not.toContain("hi dave");
|
|
241
|
+
expect((await send(daveToken, "POST", "/api/dm", { network_id: NET, to_username: "acl3_carol", message: "hi carol" })).status).toBe(200);
|
|
242
|
+
const thread = await get(carolToken, `/api/dm?network_id=${NET}&with=${daveId}`);
|
|
243
|
+
expect(thread.body.messages.map((m: any) => [m.direction, m.content])).toEqual([["in", "hi carol"], ["out", "hi dave"]]);
|
|
244
|
+
// 私信不进按 Agent 的未读(发信人不是 Agent)。
|
|
245
|
+
const inbox = await get(daveToken, `/api/messages?scope=user&network_id=${NET}`);
|
|
246
|
+
expect(inbox.body.unread_by_agent["acl3_carol"]).toBeUndefined();
|
|
247
|
+
const daveThread = await get(daveToken, `/api/dm?network_id=${NET}&with=${carolId}`);
|
|
248
|
+
expect(daveThread.body.messages.map((m: any) => m.direction)).toEqual(["out", "in"]);
|
|
249
|
+
});
|
|
250
|
+
test("sender identity comes from the token, not from the body", async () => {
|
|
251
|
+
await send(carolToken, "POST", "/api/dm", { network_id: NET, to_user_id: daveId, message: "who am i", from: adminName, sender_user_id: adminId });
|
|
252
|
+
const row = db.get<{ sender_user_id: string; from_session: string }>("SELECT sender_user_id, from_session FROM user_inbox WHERE content = 'who am i'");
|
|
253
|
+
expect(row).toEqual({ sender_user_id: carolId, from_session: "acl3_carol" });
|
|
254
|
+
});
|
|
255
|
+
test("a third party cannot read someone else's thread", async () => {
|
|
256
|
+
const eve = register("acl3_eve", PW);
|
|
257
|
+
expect(addNetworkMember(NET, eve.user!.user_id, "member", adminId).ok).toBe(true);
|
|
258
|
+
// eve 查「她和 dave」的会话:空(carol↔dave 的不会出现)。
|
|
259
|
+
expect((await get(eve.token!, `/api/dm?network_id=${NET}&with=${daveId}`)).body.messages).toEqual([]);
|
|
260
|
+
expect((await get(eve.token!, `/api/dm/threads?network_id=${NET}`)).body.threads).toEqual([]);
|
|
261
|
+
});
|
|
262
|
+
test("non-members and outsiders are refused; unknown and outside users look the same", async () => {
|
|
263
|
+
const out = register("acl3_out", PW);
|
|
264
|
+
expect((await send(out.token!, "POST", "/api/dm", { network_id: NET, to_user_id: daveId, message: "x" })).status).toBe(403);
|
|
265
|
+
expect((await get(out.token!, `/api/dm/threads?network_id=${NET}`)).status).toBe(403);
|
|
266
|
+
const a = await send(carolToken, "POST", "/api/dm", { network_id: NET, to_user_id: out.user!.user_id, message: "x" });
|
|
267
|
+
const b = await send(carolToken, "POST", "/api/dm", { network_id: NET, to_user_id: "u_nobody", message: "x" });
|
|
268
|
+
expect(a).toEqual(b);
|
|
269
|
+
expect(a.status).toBe(404);
|
|
270
|
+
});
|
|
271
|
+
test("a restricted member cannot smuggle a file they cannot see into a DM", async () => {
|
|
272
|
+
const form = new FormData();
|
|
273
|
+
form.append("file", new Blob([new Uint8Array([1, 2, 3])]), "a.bin");
|
|
274
|
+
const up = await fetch(`${BASE}/api/upload?network_id=${NET}`, { method: "POST", body: form, headers: auth(adminToken) });
|
|
275
|
+
const fid = (await up.json()).file_id;
|
|
276
|
+
const r = await send(carolToken, "POST", "/api/dm", { network_id: NET, to_user_id: daveId, message: "f", attachments: [{ type: "file", file_id: fid }] });
|
|
277
|
+
expect(r.status).toBe(403);
|
|
278
|
+
expect(r.body.error).toBe("attachment_not_accessible");
|
|
279
|
+
// 管理员(不受限)可以附带本网络文件发给 carol;carol 因此能下载它。
|
|
280
|
+
expect((await send(adminToken, "POST", "/api/dm", { network_id: NET, to_user_id: carolId, message: "file for you", attachments: [{ type: "file", file_id: fid }] })).status).toBe(200);
|
|
281
|
+
expect((await fetch(`${BASE}/api/files/${fid}`, { headers: auth(carolToken) })).status).toBe(200);
|
|
282
|
+
});
|
|
283
|
+
test("node tokens cannot use the DM API", async () => {
|
|
284
|
+
const r = await fetch(`${BASE}/api/dm/threads?network_id=${NET}`, { headers: { Authorization: "Bearer ntok_x" } });
|
|
285
|
+
expect(r.status).toBeGreaterThanOrEqual(401);
|
|
286
|
+
});
|
|
287
|
+
});
|
|
288
|
+
|
|
289
|
+
// 响应体是契约:update_node_config 的成功体被客户端按字段名读取,
|
|
290
|
+
// 任何「多加一栏」都应当是一次**有意识的**决定,而不是顺手。
|
|
291
|
+
// 这条测试钉住当前的键集(顺序无关,sorted 后比较),
|
|
292
|
+
// 让下一次加字段必须先让它变红、再明确决定要不要更新契约。
|
|
293
|
+
// 2026-10-31 —— #3275:list_node_files 的**成功体**只有三键 {ok, op, request_id}
|
|
294
|
+
// (形状由一次真实调用给出:它是「下发一个读请求」而不是「返回文件列表」,
|
|
295
|
+
// 列表在 op 里/后续拉取 —— 名字与载荷不是一回事,这是本卡第 6 次「按名字猜」被打回)。
|
|
296
|
+
describe("list_node_files: pinned success shape", () => {
|
|
297
|
+
test("⇒ {ok, op, request_id}", async () => {
|
|
298
|
+
const r = await tool(adminToken, "list_node_files", { alias: "acl3-agent-x", network_id: NET });
|
|
299
|
+
expect(Object.keys(r).sort()).toEqual(["ok", "op", "request_id"]);
|
|
300
|
+
// 2026-10-31 —— #3214 收尾:`typeof === "string"` 换成**这次到底是什么操作**。
|
|
301
|
+
// list_node_files 只是工具名;它下发的是 `files_list` 请求(列表在 get_rules_file_result 里取)。
|
|
302
|
+
// 名字与载荷不是一回事 —— 钉住 op 就是为了让「工具改了但 op 没跟上」立刻变红。
|
|
303
|
+
expect(r.op).toBe("files_list");
|
|
304
|
+
expect(r.request_id.length).toBeGreaterThan(0);
|
|
305
|
+
});
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
describe("update_node_config 响应键集(exact key set)", () => {
|
|
309
|
+
test("成功体恰好 {apply_mode, ok, update_id},不多不少", async () => {
|
|
310
|
+
const r = await tool(adminToken, "update_node_config", {
|
|
311
|
+
node_id: X.node, base_revision: 0, patch: { model: "exact-keys-model" }, network_id: NET,
|
|
312
|
+
});
|
|
313
|
+
expect(r.ok).toBe(true);
|
|
314
|
+
expect(Object.keys(r).sort()).toEqual(["apply_mode", "ok", "update_id"]);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
test("在途冲突恰好 {age_ms, error, existing_update_id, ok}", async () => {
|
|
318
|
+
const r = await tool(adminToken, "update_node_config", {
|
|
319
|
+
node_id: X.node, base_revision: 0, patch: { model: "again" }, network_id: NET,
|
|
320
|
+
});
|
|
321
|
+
expect(r.ok).toBe(false);
|
|
322
|
+
expect(r.error).toBe("update_in_flight");
|
|
323
|
+
expect(Object.keys(r).sort()).toEqual(["age_ms", "error", "existing_update_id", "ok"]);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
// 2026-10-31 —— 「意图」与「能力」两份不一致时,冲突必须被说出来。
|
|
327
|
+
// 否则 restart_supervised=true 会被读成「已验证」,而观测说没人拉它。
|
|
328
|
+
test("declared restart_supervised=true + observed not_supervised ⇒ the warning names the conflict", async () => {
|
|
329
|
+
const C = { alias: "acl3-conflict-c", node: "node_acl3_conflict_c" };
|
|
330
|
+
db.run(`INSERT INTO nodes (node_id, node_name, alias, network_id, owner_user_id, config_snapshot)
|
|
331
|
+
VALUES (?1, ?2, ?2, ?3, ?4, ?5)`,
|
|
332
|
+
[C.node, C.alias, NET, adminId,
|
|
333
|
+
JSON.stringify({ restart_supervised: true, systemd_supervision: "not_supervised" })]);
|
|
334
|
+
db.run(`INSERT INTO sessions (resume_id, alias, node_id, status, network_id, updated_at, last_seen_at)
|
|
335
|
+
VALUES (?1, ?2, ?3, 'idle', ?4, datetime('now'), datetime('now'))`,
|
|
336
|
+
[`r_${C.node}`, C.alias, C.node, NET]);
|
|
337
|
+
|
|
338
|
+
const r = await tool(adminToken, "update_node_config", {
|
|
339
|
+
node_id: C.node, base_revision: 0, patch: { channels: [] }, network_id: NET,
|
|
340
|
+
});
|
|
341
|
+
expect(r.ok).toBe(true);
|
|
342
|
+
const w = (r.warnings || []).find((x: any) => x.code === "restart_requires_manual_respawn");
|
|
343
|
+
expect(w).toBeTruthy();
|
|
344
|
+
expect(w.message).toContain("DECLARES restart_supervised=true");
|
|
345
|
+
expect(w.message).toContain("the observation wins");
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// 2026-10-31 —— #3171:剩下两个待核(get_all_status / list_node_skills)。
|
|
349
|
+
describe("get_all_status pinned (list_node_skills needs a live node → covered elsewhere)", () => {
|
|
350
|
+
test("⇒ {ok, sessions, sessions_returned, summary, summary_scope}; sessions 与 sessions_returned 同源", async () => {
|
|
351
|
+
const g = await tool(adminToken, "get_all_status", { network_id: NET });
|
|
352
|
+
expect(Object.keys(g).sort()).toEqual(["ok", "sessions", "sessions_returned", "summary", "summary_scope"]);
|
|
353
|
+
expect(Array.isArray(g.sessions)).toBe(true);
|
|
354
|
+
expect(g.sessions_returned).toBe(g.sessions.length); // 计数与数组同源
|
|
355
|
+
expect(typeof g.summary_scope).toBe("string");
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// 2026-10-31 —— #3171:再补两个「文件级算过、邻近级没有」的工具。
|
|
360
|
+
describe("projects_list / get_session_status: pinned key sets next to the call", () => {
|
|
361
|
+
test("projects_list ⇒ {network_id, ok, projects}; get_session_status ⇒ {inbox_pending, ok, recent_completions, session}", async () => {
|
|
362
|
+
const pl = await tool(adminToken, "projects_list", { network_id: NET });
|
|
363
|
+
expect(Object.keys(pl).sort()).toEqual(["network_id", "ok", "projects"]);
|
|
364
|
+
expect(Array.isArray(pl.projects)).toBe(true);
|
|
365
|
+
|
|
366
|
+
const gs = await tool(adminToken, "get_session_status", { alias: "acl3-agent-x", network_id: NET });
|
|
367
|
+
expect(Object.keys(gs).sort()).toEqual(["inbox_pending", "ok", "recent_completions", "session"]);
|
|
368
|
+
expect(Number.isInteger(gs.inbox_pending)).toBe(true);
|
|
369
|
+
expect(gs.inbox_pending).toBeGreaterThanOrEqual(0); // 2026-10-31:类型不是断言
|
|
370
|
+
expect(Array.isArray(gs.recent_completions)).toBe(true);
|
|
371
|
+
});
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
// 2026-10-31 —— #3171:补一个「文件级算过、邻近级没有」的工具(list_tasks)。
|
|
375
|
+
// 之前该文件里唯一的 Object.keys 断言测的是 humans[0],与本工具无关 —— 这正是「测空气」。
|
|
376
|
+
describe("list_tasks: pinned key set next to the call", () => {
|
|
377
|
+
test("⇒ {count, next_cursor, ok, stats, tasks} and count === tasks.length", async () => {
|
|
378
|
+
const r = await tool(adminToken, "list_tasks", { network_id: NET });
|
|
379
|
+
// ⚠️ 我从源码里读到的形状(capability / next_terminal_seq)与实际返回不同 ——
|
|
380
|
+
// 这一条断言当场纠正了我:**读码得到的形状必须由一次真实调用确认**。
|
|
381
|
+
expect(Object.keys(r).sort()).toEqual(["count", "next_cursor", "ok", "stats", "tasks"]);
|
|
382
|
+
expect(Array.isArray(r.tasks)).toBe(true);
|
|
383
|
+
expect(r.count).toBe(r.tasks.length); // 计数与数组同源
|
|
384
|
+
});
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
// 2026-10-31 —— #3171 续:再一个节点侧读面(count/counts 同源的那类)。
|
|
388
|
+
describe("list_my_pending_create_requests: pinned key set", () => {
|
|
389
|
+
test("⇒ {clone_count, clone_requests, count, ok, requests}, and count === requests.length", async () => {
|
|
390
|
+
const N3 = { alias: "acl3-pend-n", node: "node_acl3_pend_n" };
|
|
391
|
+
seedAgent({ alias: N3.alias, node: N3.node });
|
|
392
|
+
const minted = createNetworkTokenForNode(adminId, NET, N3.alias, N3.node);
|
|
393
|
+
expect(minted.ok).toBe(true);
|
|
394
|
+
const r = await tool(minted.token!, "list_my_pending_create_requests", {});
|
|
395
|
+
expect(Object.keys(r).sort()).toEqual(["clone_count", "clone_requests", "count", "ok", "requests"]);
|
|
396
|
+
expect(Array.isArray(r.requests)).toBe(true);
|
|
397
|
+
expect(Array.isArray(r.clone_requests)).toBe(true);
|
|
398
|
+
expect(r.count).toBe(r.requests.length); // 计数与数组同源
|
|
399
|
+
expect(r.clone_count).toBe(r.clone_requests.length);
|
|
400
|
+
});
|
|
401
|
+
});
|
|
402
|
+
|
|
403
|
+
// 2026-10-31 —— #3171 续:两个节点侧只读工具的键集(有 ntok 夹具后成本很低)。
|
|
404
|
+
describe("node-side read tools: pinned key sets", () => {
|
|
405
|
+
test("list_my_children ⇒ {children, count, ok}; get_completions ⇒ {completions, ok}", async () => {
|
|
406
|
+
const N2 = { alias: "acl3-node-read-n", node: "node_acl3_node_read_n" };
|
|
407
|
+
seedAgent({ alias: N2.alias, node: N2.node });
|
|
408
|
+
const minted = createNetworkTokenForNode(adminId, NET, N2.alias, N2.node);
|
|
409
|
+
expect(minted.ok).toBe(true);
|
|
410
|
+
const ntok = minted.token!;
|
|
411
|
+
|
|
412
|
+
const children = await tool(ntok, "list_my_children", {});
|
|
413
|
+
expect(Object.keys(children).sort()).toEqual(["children", "count", "ok"]);
|
|
414
|
+
expect(Array.isArray(children.children)).toBe(true);
|
|
415
|
+
expect(children.count).toBe(children.children.length); // 计数与数组同源
|
|
416
|
+
|
|
417
|
+
const completions = await tool(ntok, "get_completions", {});
|
|
418
|
+
expect(Object.keys(completions).sort()).toEqual(["completions", "ok"]);
|
|
419
|
+
expect(Array.isArray(completions.completions)).toBe(true);
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// 2026-10-31 —— #3171 续:org_whoami 也是**两支**(第二支多一个 pacing)。
|
|
424
|
+
// 它同时是「工具自带节流提示」的唯一一处,所以顺便把节流也钉住。
|
|
425
|
+
describe("org_whoami: base shape + the conditional pacing key", () => {
|
|
426
|
+
test("first call ⇒ no pacing; after the pacer trips ⇒ pacing appears (keys still pinned)", async () => {
|
|
427
|
+
const O = { alias: "acl3-whoami-o", node: "node_acl3_whoami_o" };
|
|
428
|
+
seedAgent({ alias: O.alias, node: O.node });
|
|
429
|
+
const minted = createNetworkTokenForNode(adminId, NET, O.alias, O.node);
|
|
430
|
+
expect(minted.ok).toBe(true);
|
|
431
|
+
const ntok = minted.token!;
|
|
432
|
+
|
|
433
|
+
const first = await tool(ntok, "org_whoami", {});
|
|
434
|
+
expect(first.ok).toBe(true);
|
|
435
|
+
expect(Object.keys(first)).not.toContain("pacing"); // 基线:第一次不该被提示
|
|
436
|
+
|
|
437
|
+
// 节流阈值 8 次/60 秒 ⇒ 连续调用后最后一条必须带 pacing
|
|
438
|
+
let last: any = null;
|
|
439
|
+
for (let i = 0; i < 10; i++) last = await tool(ntok, "org_whoami", {});
|
|
440
|
+
expect(Object.keys(last)).toContain("pacing");
|
|
441
|
+
// 2026-10-31 —— #3214 收尾:`typeof === "object"` 换成键集(PollPacing 恰好三键)。
|
|
442
|
+
// 「有个对象」不能证明这个提示可用:客户端要读 recommended_interval_seconds 才停得下来。
|
|
443
|
+
expect(Object.keys(last.pacing).sort()).toEqual([
|
|
444
|
+
"calls_last_60s", "note", "recommended_interval_seconds",
|
|
445
|
+
]);
|
|
446
|
+
expect(last.pacing.calls_last_60s).toBeGreaterThanOrEqual(8); // 阈值 8 次/60 秒
|
|
447
|
+
expect(last.pacing.recommended_interval_seconds).toBeGreaterThan(0);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
// 2026-10-31 —— #3171 续:**条件出现的键**(与 update_node_config 的 warnings 同族)。
|
|
452
|
+
// get_inbox 在 human 模式下多带一个 human_inbox —— 只钉无 flag 那一支,
|
|
453
|
+
// 等于允许另一支任意变形。
|
|
454
|
+
describe("get_inbox: both shapes are pinned (the second key is conditional)", () => {
|
|
455
|
+
test("default ⇒ {messages, ok}; human ⇒ {human_inbox, messages, ok} and human_inbox is {examined, mode, version}", async () => {
|
|
456
|
+
const I = { alias: "acl3-inbox-i", node: "node_acl3_inbox_i" };
|
|
457
|
+
seedAgent({ alias: I.alias, node: I.node });
|
|
458
|
+
const minted = createNetworkTokenForNode(adminId, NET, I.alias, I.node);
|
|
459
|
+
expect(minted.ok).toBe(true);
|
|
460
|
+
const ntok = minted.token!;
|
|
461
|
+
|
|
462
|
+
const plain = await tool(ntok, "get_inbox", { alias: I.alias, limit: 5 });
|
|
463
|
+
expect(Object.keys(plain).sort()).toEqual(["messages", "ok"]);
|
|
464
|
+
expect(Array.isArray(plain.messages)).toBe(true);
|
|
465
|
+
|
|
466
|
+
const human = await tool(ntok, "get_inbox", { alias: I.alias, limit: 5, human_first: true });
|
|
467
|
+
|
|
468
|
+
// 2026-10-31 —— **先证两份夹具彼此不同,再各自断言**(外部复核 (c):
|
|
469
|
+
// 「若四份夹具序列化出的字节相同,它只有一种形状 —— 后面的『各自断言』就是四次自拍」)。
|
|
470
|
+
// 这里两态也一样:若 human_first 其实没生效,下面两条键集断言会变成「同一个形状断两次」。
|
|
471
|
+
expect(JSON.stringify(Object.keys(plain).sort())).not.toBe(JSON.stringify(Object.keys(human).sort()));
|
|
472
|
+
expect(Object.keys(human).sort()).toEqual(["human_inbox", "messages", "ok"]);
|
|
473
|
+
expect(Object.keys(human.human_inbox).sort()).toEqual(["examined", "mode", "version"]);
|
|
474
|
+
expect(human.human_inbox.mode).toBe("metadata-keyset");
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
// 2026-10-31 —— #3171 续:两个「读面」工具的键集。
|
|
479
|
+
// 选它们的理由:这两个是**客户端会按字段名逐个读**的(provider 列表 / 密钥名列表),
|
|
480
|
+
// 而它们此前没有任何精确键集断言 —— 覆盖率脚本把它们列在 59 个未覆盖里。
|
|
481
|
+
describe("read-surface tools have pinned key sets", () => {
|
|
482
|
+
test("list_providers ⇒ exactly {ok, providers}; list_network_secrets ⇒ exactly {keys, ok}", async () => {
|
|
483
|
+
const providers = await tool(adminToken, "list_providers", { network_id: NET });
|
|
484
|
+
// 2026-10-31 —— 载荷扩容:`[]` 有四种含义(未配 / 全停用 / 配了没模型 / 查询失败),
|
|
485
|
+
// 所以 `state` 与 `counts` 必须与 providers 同载荷;否则客户端只能显示「没有」。
|
|
486
|
+
// 键集有**两种合法形状**(不是放宽成数组包含):configured 时不给 hint,其余状态必须给 ——
|
|
487
|
+
// 「有理由」和「没理由」在载荷上必须可区分,否则客户端只能说「没有」。
|
|
488
|
+
const baseKeys = ["counts", "ok", "providers", "state"];
|
|
489
|
+
expect(Object.keys(providers).sort()).toEqual(
|
|
490
|
+
providers.state === "configured" ? baseKeys : [...baseKeys, "hint"].sort(),
|
|
491
|
+
);
|
|
492
|
+
if (providers.state !== "configured") expect(String(providers.hint).length).toBeGreaterThan(10);
|
|
493
|
+
expect(Object.keys(providers.counts).sort()).toEqual(
|
|
494
|
+
["models_enabled", "providers_disabled", "providers_enabled", "providers_without_models"],
|
|
495
|
+
);
|
|
496
|
+
expect(["configured", "all_disabled", "unconfigured"]).toContain(providers.state);
|
|
497
|
+
// 唯一一条跨字段不变量:state 与 providers 数组必须自洽
|
|
498
|
+
expect(providers.state === "configured").toBe(providers.providers.length > 0);
|
|
499
|
+
expect(Array.isArray(providers.providers)).toBe(true);
|
|
500
|
+
|
|
501
|
+
const secrets = await tool(adminToken, "list_network_secrets", { network_id: NET });
|
|
502
|
+
expect(Object.keys(secrets).sort()).toEqual(["keys", "ok"]);
|
|
503
|
+
expect(Array.isArray(secrets.keys)).toBe(true);
|
|
504
|
+
// 值永远不出来:这是 RFC-028 的承诺,键集测试顺手把它钉住
|
|
505
|
+
for (const k of secrets.keys) expect(typeof k).toBe("string");
|
|
506
|
+
});
|
|
507
|
+
});
|
|
508
|
+
|
|
509
|
+
// 2026-10-31 —— **空的 providers 数组有四种含义**(外部复核「兜底值必须说出自己是兜底」)。
|
|
510
|
+
// 这条测试把 ①②③ 三种状态逐个造出来,断言 state 与 hint 各自不同 ——
|
|
511
|
+
// 只测「空 == 空」的话,三种状态在载荷里长得一样,客户端的空状态就只能显示「没有」。
|
|
512
|
+
test("list_providers: an empty registry says WHY it is empty (unconfigured / all_disabled / no models)", async () => {
|
|
513
|
+
const pid = `acl3-probe-${Date.now()}`;
|
|
514
|
+
const readState = async () => await tool(adminToken, "list_providers", { network_id: NET });
|
|
515
|
+
const cleanup = () => {
|
|
516
|
+
db.run(`DELETE FROM provider_models WHERE provider_id = ?1`, [pid]);
|
|
517
|
+
db.run(`DELETE FROM providers WHERE provider_id = ?1`, [pid]);
|
|
518
|
+
};
|
|
519
|
+
try {
|
|
520
|
+
// ① 未配置
|
|
521
|
+
const a = await readState();
|
|
522
|
+
expect(a.providers.length).toBe(0);
|
|
523
|
+
expect(a.state).toBe("unconfigured");
|
|
524
|
+
expect(String(a.hint)).toContain("还没有任何 provider");
|
|
525
|
+
|
|
526
|
+
// ② 配过但停用
|
|
527
|
+
db.run(
|
|
528
|
+
`INSERT INTO providers (provider_id, network_id, name, vendor, base_url, secret_key_ref, created_at, created_by, enabled)
|
|
529
|
+
VALUES (?1, ?2, ?3, 'openai', 'https://api.example.com', 'K', ?4, 'test', 0)`,
|
|
530
|
+
[pid, NET, pid, Date.now()],
|
|
531
|
+
);
|
|
532
|
+
const b = await readState();
|
|
533
|
+
expect(b.providers.length).toBe(0);
|
|
534
|
+
expect(b.state).toBe("all_disabled");
|
|
535
|
+
expect(b.counts.providers_disabled).toBe(1);
|
|
536
|
+
expect(String(b.hint)).toContain("停用");
|
|
537
|
+
|
|
538
|
+
// ③ 启用但一条模型都没有
|
|
539
|
+
db.run(`UPDATE providers SET enabled = 1 WHERE provider_id = ?1`, [pid]);
|
|
540
|
+
const c = await readState();
|
|
541
|
+
expect(c.state).toBe("configured");
|
|
542
|
+
expect(c.providers.length).toBe(1);
|
|
543
|
+
expect(c.providers[0].models.length).toBe(0);
|
|
544
|
+
expect(c.providers[0].models_state).toBe("none_configured");
|
|
545
|
+
expect(c.counts.providers_without_models).toBe(1);
|
|
546
|
+
expect("hint" in c).toBe(false); // configured 时不带 hint(载荷不变胖)
|
|
547
|
+
|
|
548
|
+
// 2026-10-31 —— **键集变化必须是结构性可枚举的,不是「测到哪算哪」**(外部复核 (b):
|
|
549
|
+
// 「不造业务上限,改成结构性证明:键集对任意 n 恒定,不再依赖枚举」)。
|
|
550
|
+
// 本载荷的 n 是「provider 条数」,键集必须与 n 无关;唯一的条件字段是 `hint`,
|
|
551
|
+
// 且它只由 `state` 决定 ⇒ 用「所有 state 的键集集合」把这条结构钉死:
|
|
552
|
+
// 不同的键集恰好 2 种,且它们的差恰好是 {"hint"}。
|
|
553
|
+
// 这样新增第三个条件字段时会红 —— 而不是「反正测试里的 n 只有 0 和 1,没测到」。
|
|
554
|
+
// ④ 有模型但不启用 ⇒ all_disabled(不是 none_configured)
|
|
555
|
+
db.run(
|
|
556
|
+
`INSERT INTO provider_models (model_id, provider_id, model_name, enabled, created_at)
|
|
557
|
+
VALUES (?1, ?2, 'm1', 0, ?3)`,
|
|
558
|
+
[`${pid}-m1`, pid, Date.now()],
|
|
559
|
+
);
|
|
560
|
+
const d = await readState();
|
|
561
|
+
expect(d.providers[0].models_state).toBe("all_disabled");
|
|
562
|
+
|
|
563
|
+
// 结构性键集:四次读数覆盖 4 种 state,键集只允许有 2 种,且差恰好 {"hint"}
|
|
564
|
+
const keySets = new Map<string, string[]>();
|
|
565
|
+
for (const [label, payload] of [["unconfigured", a], ["all_disabled", b], ["configured", c], ["models disabled", d]] as const) {
|
|
566
|
+
keySets.set(label, Object.keys(payload).sort());
|
|
567
|
+
}
|
|
568
|
+
const distinct = [...new Set([...keySets.values()].map((k) => k.join(",")))];
|
|
569
|
+
expect(distinct.length).toBe(2);
|
|
570
|
+
const withHint = distinct.find((k) => k.includes("hint"))!;
|
|
571
|
+
const withoutHint = distinct.find((k) => !k.includes("hint"))!;
|
|
572
|
+
expect(withHint.split(",").filter((k) => !withoutHint.split(",").includes(k))).toEqual(["hint"]);
|
|
573
|
+
expect(withoutHint.split(",").filter((k) => !withHint.split(",").includes(k))).toEqual([]);
|
|
574
|
+
} finally {
|
|
575
|
+
cleanup();
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
// 2026-10-31 —— **#3168 的核心分支此前没有任何测试**:
|
|
580
|
+
// 「节点没声明 supervisor(config_update_capable=false)、也没报 systemd_supervision」,
|
|
581
|
+
// 这条分支会给出 `restart_supervision_unknown` 警告 —— 而它正是「手工起的节点被一次
|
|
582
|
+
// restart-tier 下发弄死」的那一格。警告不是拒绝:Hub 不替调用方判断安全性,但必须说出来。
|
|
583
|
+
describe("#3168: a node that declares no supervisor gets a warning, not silence", () => {
|
|
584
|
+
test("restart-tier patch ⇒ warnings 含 restart_supervision_unknown(且 message 给出两种处置)", async () => {
|
|
585
|
+
const U = { alias: "acl3-nosup-u", node: "node_acl3_nosup_u" };
|
|
586
|
+
db.run(`INSERT INTO nodes (node_id, node_name, alias, network_id, owner_user_id, config_snapshot)
|
|
587
|
+
VALUES (?1, ?2, ?2, ?3, ?4, ?5)`,
|
|
588
|
+
[U.node, U.alias, NET, adminId, JSON.stringify({ config_update_capable: false })]);
|
|
589
|
+
const r = await tool(adminToken, "update_node_config", {
|
|
590
|
+
node_id: U.node, base_revision: 0, patch: { channels: [] }, network_id: NET,
|
|
591
|
+
});
|
|
592
|
+
expect(r.ok).toBe(true);
|
|
593
|
+
const w = (r.warnings || []).find((x: any) => x.code === "restart_supervision_unknown");
|
|
594
|
+
expect(w).toBeTruthy();
|
|
595
|
+
// 警告必须带**可执行的处置**(否则它只是把风险念了一遍)。
|
|
596
|
+
// 实测这一支给的是「先确认它是怎么被拉起的(anet start / pm2 / systemd)」,
|
|
597
|
+
// 而 Stop→Start 那句在**另一支**(systemd_supervision=not_supervised 已报告)里。
|
|
598
|
+
expect(String(w.message)).toContain("anet start / pm2 / systemd");
|
|
599
|
+
expect(String(w.message)).toContain("restart-tier");
|
|
600
|
+
// 2026-10-31 —— **「存在」不是断言,「存在且值等于 X」才是**(外部复核 (b):
|
|
601
|
+
// 「写『存在』⇒ 它被改成任何值都绿」)。这一条把 warning 的形状也钉住:
|
|
602
|
+
// 多一个键 = 又一处没人读的字段;少一个键 = 客户端拿不到处置。
|
|
603
|
+
expect(Object.keys(w).sort()).toEqual(["code", "message"]);
|
|
604
|
+
});
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
// 2026-10-31 —— #3171 第 2 项:restart_node 的成功体与 update_node_config 同构。
|
|
608
|
+
describe("restart_node success body", () => {
|
|
609
|
+
test("pinned key set (same shape family as update_node_config)", async () => {
|
|
610
|
+
const R = { alias: "acl3-restart-r", node: "node_acl3_restart_r" };
|
|
611
|
+
seedAgent({ alias: R.alias, node: R.node });
|
|
612
|
+
const r = await tool(adminToken, "restart_node", { node_id: R.node, network_id: NET });
|
|
613
|
+
// 与 update_node_config 同构(不含 warnings:restart 不带 patch,分档固定为 restart_only)
|
|
614
|
+
expect(Object.keys(r).sort()).toEqual(["apply_mode", "ok", "update_id"]);
|
|
615
|
+
expect(r.ok).toBe(true);
|
|
616
|
+
expect(r.apply_mode).toBe("restart_only");
|
|
617
|
+
});
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
// 2026-10-31 —— #3171 第 3 项:get_config_update 的两态。
|
|
621
|
+
// 「有 pending」与「无 pending」是**两条不同形状**,而旧测试只在 SQL 层模拟过它们,
|
|
622
|
+
// 从没有一条断言钉住工具真正返回的那两个 JSON。
|
|
623
|
+
describe("get_config_update: both states have pinned shapes", () => {
|
|
624
|
+
test("no pending ⇒ exactly {ok, update:null}; with pending ⇒ exactly {ok, update:{apply_mode,base_revision,patch,update_id}}", async () => {
|
|
625
|
+
const N = { alias: "acl3-puller-n", node: "node_acl3_puller_n" };
|
|
626
|
+
seedAgent({ alias: N.alias, node: N.node });
|
|
627
|
+
const minted = createNetworkTokenForNode(adminId, NET, N.alias, N.node);
|
|
628
|
+
expect(minted.ok).toBe(true);
|
|
629
|
+
const ntok = minted.token!;
|
|
630
|
+
|
|
631
|
+
// ① 无 pending
|
|
632
|
+
const empty = await tool(ntok, "get_config_update", {});
|
|
633
|
+
expect(Object.keys(empty).sort()).toEqual(["ok", "update"]);
|
|
634
|
+
expect(empty.ok).toBe(true);
|
|
635
|
+
expect(empty.update).toBeNull();
|
|
636
|
+
|
|
637
|
+
// ② 有 pending
|
|
638
|
+
db.run(`INSERT INTO node_config_updates (update_id, node_id, network_id, patch_json, apply_mode, base_revision, status, created_at, created_by_token)
|
|
639
|
+
VALUES (?1, ?2, ?3, ?4, 'hot', 0, 'pending', ?5, 'test')`,
|
|
640
|
+
["u_acl3_pending", N.node, NET, JSON.stringify({ model: "m" }), Date.now()]);
|
|
641
|
+
const one = await tool(ntok, "get_config_update", {});
|
|
642
|
+
expect(Object.keys(one).sort()).toEqual(["ok", "update"]);
|
|
643
|
+
expect(Object.keys(one.update).sort()).toEqual(["apply_mode", "base_revision", "patch", "update_id"]);
|
|
644
|
+
expect(one.update.update_id).toBe("u_acl3_pending");
|
|
645
|
+
expect(one.update.apply_mode).toBe("hot");
|
|
646
|
+
|
|
647
|
+
// ③ #3171 第 4 项:ack 成功回执恰好 {ok, status}
|
|
648
|
+
const ack = await tool(ntok, "ack_config_update", {
|
|
649
|
+
update_id: "u_acl3_pending", status: "applied", new_revision: 1,
|
|
650
|
+
});
|
|
651
|
+
expect(Object.keys(ack).sort()).toEqual(["ok", "status"]);
|
|
652
|
+
expect(ack.ok).toBe(true);
|
|
653
|
+
expect(ack.status).toBe("applied");
|
|
654
|
+
|
|
655
|
+
// ④ #3275 批次 1·b —— **ignored 三个分支的左端不是同一个形状**:
|
|
656
|
+
// `{ok, ignored}` / `{ok, ignored, current_status}`。
|
|
657
|
+
// 只钉主分支时,「顺手把 current_status 加到另外两个分支」不会有任何东西变红。
|
|
658
|
+
const again = await tool(ntok, "ack_config_update", {
|
|
659
|
+
update_id: "u_acl3_pending", status: "applied", new_revision: 1,
|
|
660
|
+
});
|
|
661
|
+
expect(Object.keys(again).sort()).toEqual(["current_status", "ignored", "ok"]);
|
|
662
|
+
expect(again).toMatchObject({ ok: true, ignored: "already_terminal", current_status: "applied" });
|
|
663
|
+
|
|
664
|
+
const foreign = await tool(ntok, "ack_config_update", { update_id: "u_not_mine", status: "applied" });
|
|
665
|
+
expect(Object.keys(foreign).sort()).toEqual(["ignored", "ok"]);
|
|
666
|
+
expect(foreign).toEqual({ ok: true, ignored: "unknown_or_foreign_update" });
|
|
667
|
+
|
|
668
|
+
// ⑤ 「令牌在、node 没了」时**到不了** `ignored: "alias_unknown"`:
|
|
669
|
+
// 实测返回 {"ok":false,"error":"alias_required"} —— 因为 callerAlias 本身是从
|
|
670
|
+
// resolveNodeCaller(令牌) 解析出来的:node 行一删,alias 就是空,
|
|
671
|
+
// 于是**更早的** `if (!callerAlias)` 守卫先拒。
|
|
672
|
+
// ⇒ 这个出口要可达,需要「alias 解析得到、但工具内 resolveCallerNode() 解析不到」,
|
|
673
|
+
// 即一种跨网络的错配状态 —— 本夹具构造不出来,所以**今天不声称它被钉住**。
|
|
674
|
+
// 先把现在这条行为钉住(它同样是契约:残留令牌不该被当成隐式放行)。
|
|
675
|
+
const ghost = createNetworkTokenForNode(adminId, NET, "acl3-ghost-alias", "node_acl3_ghost");
|
|
676
|
+
expect(ghost.ok).toBe(true);
|
|
677
|
+
db.run("DELETE FROM nodes WHERE node_id = ?1", ["node_acl3_ghost"]);
|
|
678
|
+
db.run("DELETE FROM sessions WHERE alias = ?1", ["acl3-ghost-alias"]);
|
|
679
|
+
const staleTokenAck = await tool(ghost.token!, "ack_config_update", { update_id: "u_acl3_pending", status: "applied" });
|
|
680
|
+
expect(Object.keys(staleTokenAck).sort()).toEqual(["error", "ok"]);
|
|
681
|
+
expect(staleTokenAck).toEqual({ ok: false, error: "alias_required" });
|
|
682
|
+
});
|
|
683
|
+
});
|
|
684
|
+
|
|
685
|
+
// #3275 批次 1·c 的先决条件:**daemon 绑定 + MCP 可用**的凭证。
|
|
686
|
+
// 前面试过两条走不通的路(owner 令牌 ⇒ caller_not_a_daemon;REST 用的 bound 令牌 ⇒ 非 200),
|
|
687
|
+
// 正解是:种子一个 node + 用 createNetworkTokenForNode 铸一把网络令牌(它同时是 MCP 凭证)。
|
|
688
|
+
describe("daemon-shaped caller: existence branches are reachable", () => {
|
|
689
|
+
test("ack_start_request / ack_stop_request 不存在 ⇒ 恰好 {error:'request_not_found', ok:false}", async () => {
|
|
690
|
+
const D = { alias: "acl3-ack-daemon", node: "node_acl3_ack_daemon" };
|
|
691
|
+
seedAgent({ alias: D.alias, node: D.node });
|
|
692
|
+
const minted = createNetworkTokenForNode(adminId, NET, D.alias, D.node);
|
|
693
|
+
expect(minted.ok).toBe(true);
|
|
694
|
+
for (const [name, args] of [
|
|
695
|
+
["ack_start_request", { request_id: "start_absent", status: "started" }],
|
|
696
|
+
["ack_stop_request", { request_id: "stop_absent", status: "stopped" }],
|
|
697
|
+
] as [string, Record<string, unknown>][]) {
|
|
698
|
+
const r = await tool(minted.token!, name, args);
|
|
699
|
+
expect(Object.keys(r).sort()).toEqual(["error", "ok"]);
|
|
700
|
+
expect(r).toEqual({ ok: false, error: "request_not_found" });
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// 「存在,但不是我的」是**另一档**:这两档对调用方的下一步完全不同
|
|
704
|
+
// (前者去查 ID,后者去查令牌归属)。只钉其中一档时,把两档合并成一个错误码不会有东西变红。
|
|
705
|
+
db.run(`INSERT INTO node_start_requests
|
|
706
|
+
(request_id, network_id, daemon_node_id, child_node_id, child_alias, created_by_token, status, created_at)
|
|
707
|
+
VALUES (?1, ?2, ?3, ?4, ?5, 'test', 'pending', ?6)`,
|
|
708
|
+
["start_someone_else", NET, "node_acl3_other_daemon", "node_acl3_other_child", "acl3-other-child", Date.now()]);
|
|
709
|
+
const foreign = await tool(minted.token!, "ack_start_request", { request_id: "start_someone_else", status: "started" });
|
|
710
|
+
expect(Object.keys(foreign).sort()).toEqual(["error", "ok"]);
|
|
711
|
+
expect(foreign).toEqual({ ok: false, error: "not_your_request" });
|
|
712
|
+
|
|
713
|
+
// 第三档:请求在**别的网络**里。它与「不是你的」同样是拒绝,但成因不同
|
|
714
|
+
// (一个跨租户,一个同租户不同节点)—— 合并成一个码就会把跨租户的信号抹掉。
|
|
715
|
+
db.run(`INSERT INTO node_start_requests
|
|
716
|
+
(request_id, network_id, daemon_node_id, child_node_id, child_alias, created_by_token, status, created_at)
|
|
717
|
+
VALUES (?1, ?2, ?3, ?4, ?5, 'test', 'pending', ?6)`,
|
|
718
|
+
// ⚠️ 判定顺序是:not_found → **not_your_request(daemon_node_id)** → cross_network_request(network_id)。
|
|
719
|
+
// 所以要让第三档可达,这一行的 daemon_node_id 必须**是我**,只有 network 不同 ——
|
|
720
|
+
// 我第一次填了别的 daemon,于是只到得了第二档(实测 not_your_request)。
|
|
721
|
+
["start_other_network", "net_acl3_other_network", D.node, "node_x_child", "x-child", Date.now()]);
|
|
722
|
+
const cross = await tool(minted.token!, "ack_start_request", { request_id: "start_other_network", status: "started" });
|
|
723
|
+
expect(Object.keys(cross).sort()).toEqual(["error", "ok"]);
|
|
724
|
+
expect(cross).toEqual({ ok: false, error: "cross_network_request" });
|
|
725
|
+
});
|
|
726
|
+
});
|
|
727
|
+
|
|
728
|
+
// #3309 顺序维度 —— `get_*_request` 三条共用同一套判定顺序:
|
|
729
|
+
// not_found → not_your_request(daemon_node_id)→ cross_network_request(network_id)
|
|
730
|
+
// 顺序本身是安全属性:先答「在别的网络」会把「这个 id 属于另一个租户」告诉尚未确认身份的人。
|
|
731
|
+
describe("get_*_request: rejection order is the security property", () => {
|
|
732
|
+
test("别人的请求 ⇒ not_your_request;我的 daemon 但别的网络 ⇒ cross_network_request", async () => {
|
|
733
|
+
const D = { alias: "acl3-order-daemon", node: "node_acl3_order_daemon" };
|
|
734
|
+
seedAgent({ alias: D.alias, node: D.node });
|
|
735
|
+
const minted = createNetworkTokenForNode(adminId, NET, D.alias, D.node);
|
|
736
|
+
expect(minted.ok).toBe(true);
|
|
737
|
+
const now = Date.now();
|
|
738
|
+
// 唯一后缀:同一个 describe 里可能被多次执行(或与别的用例撞 id),主键冲突会掩盖真正的断言。
|
|
739
|
+
const U = Math.random().toString(36).slice(2, 8);
|
|
740
|
+
const cases: [string, string][] = [
|
|
741
|
+
["get_start_request", "node_start_requests"],
|
|
742
|
+
["get_stop_request", "node_stop_requests"],
|
|
743
|
+
];
|
|
744
|
+
for (const [toolName, table] of cases) {
|
|
745
|
+
// 两张表的列**不完全是同一套**(node_stop_requests 多一个 NOT NULL 的 `action`)。
|
|
746
|
+
// ⇒ 按表分别构造列,而不是假设它们同形(实测:NOT NULL constraint failed: action)。
|
|
747
|
+
const extraCols = table === "node_stop_requests" ? ", action" : "";
|
|
748
|
+
const extraVals = table === "node_stop_requests" ? ", 'stop'" : "";
|
|
749
|
+
db.run(`INSERT INTO ${table}
|
|
750
|
+
(request_id, network_id, daemon_node_id, child_node_id, child_alias, created_by_token, status, created_at${extraCols})
|
|
751
|
+
VALUES (?1, ?2, ?3, ?4, ?5, 'test', 'pending', ?6${extraVals})`,
|
|
752
|
+
// ⚠️ 表上有 UNIQUE(child_node_id)(同一子节点只能有一条未结请求)⇒ 两行必须用不同子节点,
|
|
753
|
+
// 否则主键冲突会把断言掩盖成 db 报错(实测踩到:UNIQUE constraint failed: child_node_id)。
|
|
754
|
+
[`${toolName}_other_daemon_${U}`, NET, "node_acl3_other_daemon", `node_other_child_${U}`, "other-child", now]);
|
|
755
|
+
db.run(`INSERT INTO ${table}
|
|
756
|
+
(request_id, network_id, daemon_node_id, child_node_id, child_alias, created_by_token, status, created_at${extraCols})
|
|
757
|
+
VALUES (?1, ?2, ?3, ?4, ?5, 'test', 'pending', ?6${extraVals})`,
|
|
758
|
+
[`${toolName}_other_network_${U}`, "net_acl3_other_network", D.node, `node_cross_child_${U}`, "cross-child", now]);
|
|
759
|
+
const foreign = await tool(minted.token!, toolName, { request_id: `${toolName}_other_daemon_${U}` });
|
|
760
|
+
expect(foreign).toEqual({ ok: false, error: "not_your_request" });
|
|
761
|
+
const cross = await tool(minted.token!, toolName, { request_id: `${toolName}_other_network_${U}` });
|
|
762
|
+
expect(cross).toEqual({ ok: false, error: "cross_network_request" });
|
|
763
|
+
}
|
|
764
|
+
});
|
|
765
|
+
});
|
|
766
|
+
|
|
767
|
+
// #3309 顺序维度余 2 —— `node_create_requests` 的两条读/写面同样「归属先于租户」:
|
|
768
|
+
// not_found → not_your_request(daemon_node_id)→ cross_network_request(network_id)
|
|
769
|
+
describe("create-request reads/writes: same rejection order", () => {
|
|
770
|
+
test("get_create_request / ack_create_request:别人的 ⇒ not_your_request;别的网络 ⇒ cross_network_request", async () => {
|
|
771
|
+
const D = { alias: "acl3-cr-daemon", node: "node_acl3_cr_daemon" };
|
|
772
|
+
seedAgent({ alias: D.alias, node: D.node });
|
|
773
|
+
const minted = createNetworkTokenForNode(adminId, NET, D.alias, D.node);
|
|
774
|
+
expect(minted.ok).toBe(true);
|
|
775
|
+
const U = Math.random().toString(36).slice(2, 8);
|
|
776
|
+
const now = Date.now();
|
|
777
|
+
const ins = (id: string, net: string, daemon: string) =>
|
|
778
|
+
db.run(`INSERT INTO node_create_requests
|
|
779
|
+
(request_id, daemon_node_id, child_name, network_id, runtime, flags_json, env_keys, status, created_at, created_by_token)
|
|
780
|
+
VALUES (?1, ?2, ?3, ?4, 'opencode', '{}', '[]', 'awaiting_register', ?5, 'test')`,
|
|
781
|
+
[id, daemon, `child_${U}`, net, now]);
|
|
782
|
+
ins(`cr_other_daemon_${U}`, NET, "node_acl3_other_daemon");
|
|
783
|
+
ins(`cr_other_network_${U}`, "net_acl3_other_network", D.node);
|
|
784
|
+
|
|
785
|
+
for (const [toolName, extra] of [
|
|
786
|
+
["get_create_request", {}],
|
|
787
|
+
["ack_create_request", { status: "started" }],
|
|
788
|
+
] as [string, Record<string, unknown>][]) {
|
|
789
|
+
const foreign = await tool(minted.token!, toolName, { request_id: `cr_other_daemon_${U}`, ...extra });
|
|
790
|
+
expect(foreign).toEqual({ ok: false, error: "not_your_request" });
|
|
791
|
+
const cross = await tool(minted.token!, toolName, { request_id: `cr_other_network_${U}`, ...extra });
|
|
792
|
+
expect(cross).toEqual({ ok: false, error: "cross_network_request" });
|
|
793
|
+
}
|
|
794
|
+
});
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
// #3309 分支 —— ack_create_request 的**两个成功出口**:键集相同 {ok,status},
|
|
798
|
+
// 但 status 的取值不同(started ⇒ "awaiting_register";failed ⇒ "failed")。
|
|
799
|
+
// 只钉键集时,「把两个分支合并成一个 status」不会有东西变红。
|
|
800
|
+
describe("ack_create_request: two success exits share keys, differ in value", () => {
|
|
801
|
+
test("started ⇒ awaiting_register;failed ⇒ failed", async () => {
|
|
802
|
+
const D = { alias: "acl3-ackcr-daemon", node: "node_acl3_ackcr_daemon" };
|
|
803
|
+
seedAgent({ alias: D.alias, node: D.node });
|
|
804
|
+
const minted = createNetworkTokenForNode(adminId, NET, D.alias, D.node);
|
|
805
|
+
expect(minted.ok).toBe(true);
|
|
806
|
+
const U = Math.random().toString(36).slice(2, 8);
|
|
807
|
+
// ⚠️ UNIQUE(daemon_node_id, child_name) ⇒ 两行必须用**不同子名**,
|
|
808
|
+
// 否则冲突会以「主键冲突」的样子出现,把断言掩盖成 db 报错。
|
|
809
|
+
const ins = (id: string, suffix: string) =>
|
|
810
|
+
db.run(`INSERT INTO node_create_requests
|
|
811
|
+
(request_id, daemon_node_id, child_name, network_id, runtime, flags_json, env_keys, status, created_at, created_by_token)
|
|
812
|
+
VALUES (?1, ?2, ?3, ?4, 'opencode', '{}', '[]', 'delivered', ?5, 'test')`,
|
|
813
|
+
[id, D.node, `child_${U}_${suffix}`, NET, Date.now()]);
|
|
814
|
+
ins(`cr_ackcr_started_${U}`, "s");
|
|
815
|
+
const started = await tool(minted.token!, "ack_create_request", { request_id: `cr_ackcr_started_${U}`, status: "started" });
|
|
816
|
+
expect(Object.keys(started).sort()).toEqual(["ok", "status"]);
|
|
817
|
+
expect(started).toEqual({ ok: true, status: "awaiting_register" });
|
|
818
|
+
ins(`cr_ackcr_failed_${U}`, "f");
|
|
819
|
+
const failed = await tool(minted.token!, "ack_create_request", { request_id: `cr_ackcr_failed_${U}`, status: "failed" });
|
|
820
|
+
expect(Object.keys(failed).sort()).toEqual(["ok", "status"]);
|
|
821
|
+
expect(failed).toEqual({ ok: true, status: "failed" });
|
|
822
|
+
});
|
|
823
|
+
});
|
|
824
|
+
|
|
825
|
+
// 2026-10-31 —— #3171 第 5 项:错误信封的形状也要钉住。
|
|
826
|
+
// 今天它们是「约定俗成」:每个出口手写 {ok:false,error},
|
|
827
|
+
// 于是谁顺手多塞一个字段,客户端的分支就多一个没人知道的键。
|
|
828
|
+
describe("error envelope: exactly {ok, error} unless the error carries its own fields", () => {
|
|
829
|
+
test("get_config_update without a node token ⇒ exactly {error, ok}", async () => {
|
|
830
|
+
const r = await tool(adminToken, "get_config_update", {});
|
|
831
|
+
expect(r.ok).toBe(false);
|
|
832
|
+
expect(r.error).toBe("network_token_required");
|
|
833
|
+
expect(Object.keys(r).sort()).toEqual(["error", "ok"]);
|
|
834
|
+
});
|
|
835
|
+
|
|
836
|
+
test("ack_config_update without a node token ⇒ exactly {error, ok}", async () => {
|
|
837
|
+
const r = await tool(adminToken, "ack_config_update", {
|
|
838
|
+
update_id: "u_missing", status: "applied", network_id: NET,
|
|
839
|
+
});
|
|
840
|
+
expect(r.ok).toBe(false);
|
|
841
|
+
expect(r.error).toBe("network_token_required");
|
|
842
|
+
expect(Object.keys(r).sort()).toEqual(["error", "ok"]);
|
|
843
|
+
});
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
// 2026-10-31 —— #3171:warnings 出现时的成功体也必须被钉住。
|
|
847
|
+
// 上面那条钉的是「没有 warning」的形状;而 warnings 是**条件出现**的 ⇒
|
|
848
|
+
// 只断言前者,等于允许后者任意变形(今天它没出事,靠的是客户端宽松解析)。
|
|
849
|
+
test("带 warning 的成功体恰好 {apply_mode, ok, update_id, warnings},且 warning 项恰好 {code, message}", async () => {
|
|
850
|
+
const W = { alias: "acl3-agent-w", node: "node_acl3_w" };
|
|
851
|
+
db.run(`INSERT INTO nodes (node_id, node_name, alias, network_id, owner_user_id, config_snapshot)
|
|
852
|
+
VALUES (?1, ?2, ?2, ?3, ?4, ?5)`,
|
|
853
|
+
[W.node, W.alias, NET, adminId, JSON.stringify({ systemd_supervision: "not_supervised" })]);
|
|
854
|
+
db.run(`INSERT INTO sessions (resume_id, alias, node_id, status, network_id, updated_at, last_seen_at)
|
|
855
|
+
VALUES (?1, ?2, ?3, 'idle', ?4, datetime('now'), datetime('now'))`,
|
|
856
|
+
[`r_${W.node}`, W.alias, W.node, NET]);
|
|
857
|
+
|
|
858
|
+
const r = await tool(adminToken, "update_node_config", {
|
|
859
|
+
node_id: W.node, base_revision: 0, patch: { channels: [] }, network_id: NET,
|
|
860
|
+
});
|
|
861
|
+
|
|
862
|
+
expect(r.ok).toBe(true);
|
|
863
|
+
expect(r.apply_mode).not.toBe("hot"); // restart-tier:这正是危险的那一档
|
|
864
|
+
// 两个方向都钉:少一个键红,多一个键也红
|
|
865
|
+
expect(Object.keys(r).sort()).toEqual(["apply_mode", "ok", "update_id", "warnings"]);
|
|
866
|
+
expect(Array.isArray(r.warnings)).toBe(true);
|
|
867
|
+
expect(r.warnings.length).toBe(1);
|
|
868
|
+
expect(Object.keys(r.warnings[0]).sort()).toEqual(["code", "message"]);
|
|
869
|
+
// code 是稳定枚举,不是自由文本 —— 客户端要靠它分支
|
|
870
|
+
expect(r.warnings[0].code).toBe("restart_requires_manual_respawn");
|
|
871
|
+
expect(typeof r.warnings[0].message).toBe("string");
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
test("revision 冲突恰好 {current_revision, error, ok}", async () => {
|
|
875
|
+
// 用另一台干净节点,避开上面那条的在途状态
|
|
876
|
+
const r = await tool(adminToken, "update_node_config", {
|
|
877
|
+
node_id: Z.node, base_revision: 99, patch: { model: "stale" }, network_id: NET,
|
|
878
|
+
});
|
|
879
|
+
expect(r.ok).toBe(false);
|
|
880
|
+
// 实际契约:code 是 revision_conflict(不是 config_revision_conflict),
|
|
881
|
+
// 且带 base_revision —— 顺手纠正了卡上写错的错误名。
|
|
882
|
+
expect(r.error).toBe("revision_conflict");
|
|
883
|
+
expect(Object.keys(r).sort()).toEqual(["base_revision", "current_revision", "error", "ok"]);
|
|
884
|
+
});
|
|
885
|
+
});
|