@sleep2agi/commhub-server 0.9.0-preview.13 → 0.9.0-preview.130
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 +130 -10
- package/bin/commhub.ts +99 -11
- package/package.json +7 -7
- package/src/ack-create-request-transport.test.ts +182 -0
- package/src/ack-create-request.test.ts +50 -7
- 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 +137 -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 +659 -0
- package/src/agent-acl-slice3-http.test.ts +267 -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 +323 -0
- package/src/agent-teams.ts +244 -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 +271 -0
- package/src/api-host-supervisors-runtime-readiness.test.ts +195 -0
- package/src/api-nodes-shape.test.ts +26 -10
- package/src/auth-password-change-cli-tokens-http.test.ts +294 -0
- package/src/auth-sessions-http.test.ts +250 -0
- package/src/auth-validate.test.ts +5 -1
- package/src/auth-weak-password-login.test.ts +176 -0
- package/src/auth.ts +598 -49
- package/src/avatar-validate.test.ts +163 -0
- package/src/avatar-validate.ts +103 -0
- package/src/binding-generation-http.test.ts +121 -0
- package/src/blocked-exit-on-reply.test.ts +122 -0
- package/src/boot-side-effect.test.ts +124 -0
- package/src/clone-node.test.ts +248 -0
- package/src/clone-node.ts +289 -0
- package/src/codex-config-flags.ts +77 -0
- package/src/codex-fork-contract.ts +23 -0
- package/src/codex-fork-migration.test.ts +38 -0
- package/src/commhub-bin-args.test.ts +85 -0
- package/src/config-apply-sec1.test.ts +107 -0
- package/src/config-apply-validate.test.ts +134 -1
- package/src/config-apply-validate.ts +111 -5
- package/src/create-node-blocked-gate.test.ts +356 -0
- package/src/create-node-network-id.test.ts +79 -0
- package/src/create-node-tool-schema.test.ts +48 -0
- package/src/create-node-unicode-name.test.ts +120 -0
- package/src/create-node-validate.test.ts +193 -7
- package/src/create-node-validate.ts +227 -15
- package/src/create-node-workdir.test.ts +289 -0
- package/src/create-node.ts +77 -23
- package/src/daemon-provider-snapshots.test.ts +421 -0
- package/src/daemon-provider-snapshots.ts +327 -0
- package/src/daemon-token-owner-http.test.ts +236 -0
- package/src/dashboard-slash-routing-http.test.ts +107 -0
- package/src/db-adapter-guard.test.ts +148 -0
- package/src/db-adapter-translate.test.ts +128 -0
- package/src/db-adapter.ts +323 -87
- package/src/db-timestamp.test.ts +38 -0
- package/src/db-timestamp.ts +15 -0
- package/src/db.ts +930 -35
- 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 +330 -0
- package/src/department-heads.ts +226 -0
- package/src/departments-http.test.ts +185 -0
- package/src/departments.ts +260 -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/ext-token-shared.test.ts +60 -0
- package/src/ext-validation-regression.test.ts +131 -0
- 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 +135 -0
- package/src/file-download-authz.test.ts +404 -0
- package/src/file-download-date-bucket.test.ts +436 -0
- package/src/file-network-scope-dev-open.test.ts +97 -0
- package/src/file-network-scope.test.ts +732 -0
- package/src/group-membership-events-http.test.ts +264 -0
- package/src/group-messages-http.test.ts +482 -0
- package/src/group-messages.ts +297 -0
- package/src/health-redaction.test.ts +642 -0
- package/src/http-gzip.test.ts +94 -0
- package/src/http-gzip.ts +112 -0
- package/src/hub-provider-config.test.ts +139 -0
- package/src/hub-provider-config.ts +105 -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/inbox-caller.ts +49 -0
- package/src/inbox-count-sse.test.ts +310 -0
- package/src/inbox-count.ts +29 -0
- package/src/index.ts +15 -2362
- package/src/lifecycle-guard.ts +1 -1
- package/src/mcp-context-cost-http.test.ts +123 -0
- package/src/mcp-projects-events-http.test.ts +162 -0
- package/src/mcp-route-label-http.test.ts +120 -0
- package/src/mcp-write-network-resolution.test.ts +432 -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-scope.ts +276 -0
- package/src/network-token-membership-http.test.ts +139 -0
- package/src/node-alias-control.ts +12 -0
- package/src/node-attrs-validate.ts +88 -0
- package/src/node-attrs.test.ts +217 -0
- package/src/node-caller-identity-http.test.ts +781 -0
- package/src/node-create-request-status-http.test.ts +105 -0
- package/src/node-daemon-bindings.test.ts +132 -0
- package/src/node-daemon-bindings.ts +130 -0
- package/src/node-files-transport.test.ts +344 -0
- package/src/node-health-codex-login.test.ts +120 -0
- package/src/node-health-dispatch-http.test.ts +279 -0
- package/src/node-health-guard.ts +105 -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-lifecycle-controllable.test.ts +64 -0
- package/src/node-lifecycle-controllable.ts +53 -0
- package/src/node-lifecycle-read-http.test.ts +245 -0
- package/src/node-lifecycle-read.ts +121 -0
- package/src/node-logs-transport.test.ts +263 -0
- package/src/node-permissions-http.test.ts +276 -0
- package/src/node-permissions.ts +285 -0
- package/src/node-request-retention.test.ts +281 -0
- package/src/node-request-retention.ts +120 -0
- package/src/node-skills-transport.test.ts +209 -0
- package/src/node-token-ownership.ts +51 -0
- package/src/node-token-privilege-http.test.ts +158 -0
- package/src/observer-avatar-http.test.ts +431 -0
- package/src/observer-push.test.ts +252 -0
- package/src/opencode-v2-catalog.test.ts +268 -0
- package/src/opencode-v2-catalog.ts +352 -0
- package/src/package-version-consistency.test.ts +25 -0
- package/src/peer-reply-atomic.test.ts +455 -0
- package/src/peer-reply-capability.test.ts +70 -0
- package/src/pg-worker.ts +87 -0
- package/src/project-dir-warn-clear-http.test.ts +132 -0
- package/src/project-viewer-can-http.test.ts +114 -0
- package/src/push.ts +429 -10
- package/src/redact-tokens.test.ts +65 -0
- package/src/redact-tokens.ts +40 -0
- package/src/rename.ts +22 -2
- 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 +150 -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 +268 -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 +309 -0
- package/src/requirement-tag-ops-http.test.ts +266 -0
- package/src/requirement-tags.ts +89 -0
- package/src/requirements-abandoned-http.test.ts +236 -0
- package/src/requirements-comment-http.test.ts +167 -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 +143 -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 +319 -0
- package/src/requirements-mcp.test.ts +163 -0
- package/src/requirements-migrate.ts +259 -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 +225 -0
- package/src/requirements-people.ts +127 -0
- package/src/requirements-priority-lowest.test.ts +114 -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 +288 -0
- package/src/requirements-stats.ts +167 -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 +1806 -0
- package/src/resolve-port.test.ts +57 -0
- package/src/resolve-port.ts +44 -0
- package/src/response-charset.test.ts +130 -0
- package/src/rest-explicit-columns-http.test.ts +222 -0
- package/src/rest-identity.test.ts +129 -0
- package/src/rest-identity.ts +125 -0
- package/src/rest-projections.ts +68 -0
- package/src/rest-write-network-resolution.test.ts +133 -0
- package/src/restricted-files.ts +76 -0
- package/src/retention.ts +15 -3
- package/src/route-callers-http.test.ts +120 -0
- package/src/route-timing.test.ts +211 -0
- package/src/route-timing.ts +258 -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 +237 -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 +381 -0
- package/src/schedule-agent.ts +192 -0
- package/src/scheduled-doorbell-nodeless-session.test.ts +134 -0
- package/src/scheduled-failures-http.test.ts +233 -0
- package/src/scheduled-failures.ts +179 -0
- package/src/scheduled-offline.test.ts +131 -0
- package/src/scheduled-offline.ts +66 -0
- package/src/scheduled-reply-unread-http.test.ts +212 -0
- package/src/scheduled-run-terminal.test.ts +268 -0
- package/src/scheduled-skip-blocking-task.test.ts +120 -0
- package/src/scheduled-stuck-http.test.ts +238 -0
- package/src/scheduled-stuck.ts +153 -0
- package/src/scheduled-tasks-http.test.ts +638 -0
- package/src/scheduled-tasks.ts +766 -0
- package/src/scoped-secrets.ts +124 -0
- package/src/send-dedup-request-id.test.ts +229 -0
- package/src/send-reply-agent-warning.test.ts +202 -0
- package/src/send-reply-alias-optional.test.ts +131 -0
- package/src/send-reply-attachments.test.ts +458 -0
- package/src/send_dedup.test.ts +54 -0
- package/src/send_dedup.ts +52 -6
- package/src/serve-error.test.ts +38 -0
- package/src/serve-error.ts +27 -0
- package/src/server.ts +5257 -0
- package/src/session-task-on-dispatch.ts +14 -0
- package/src/session-token-ownership-http.test.ts +122 -0
- package/src/shared/codex-inventory.ts +41 -0
- package/src/shared/daemon-provider-login.ts +31 -0
- package/src/shared/daemon-provider-snapshot.ts +52 -0
- package/src/shared/external-schedule-contract.ts +60 -0
- package/src/shared/node-name.test.ts +62 -0
- package/src/shared/node-name.ts +161 -0
- package/src/shared/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 +108 -0
- package/src/sqlite-close-checkpoint.test.ts +78 -0
- package/src/start-node.test.ts +264 -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 +122 -0
- package/src/stop-delete-node.test.ts +509 -1
- package/src/task-access-http.test.ts +402 -0
- package/src/task-access.ts +420 -0
- package/src/task-auth-origin-http.test.ts +91 -0
- package/src/task-auth-origin.test.ts +24 -0
- package/src/task-auth-origin.ts +7 -0
- package/src/task-consumption.test.ts +482 -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 +287 -0
- package/src/task-expiry-notice.ts +315 -0
- package/src/task-idempotency-mcp.test.ts +142 -0
- package/src/task-idempotency.test.ts +60 -0
- package/src/task-idempotency.ts +75 -0
- package/src/task-late-replies.ts +54 -0
- package/src/task-late-reply-http.test.ts +152 -0
- package/src/task-lifecycle-watcher.test.ts +204 -0
- package/src/task-lifecycle-watcher.ts +49 -0
- package/src/task-network-resolution-http.test.ts +141 -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 +49 -0
- package/src/task-stale-open-http.test.ts +290 -0
- package/src/task-stale-open.ts +103 -0
- package/src/tasks-pagination-http.test.ts +141 -0
- package/src/tool-audience-http.test.ts +220 -0
- package/src/tool-audience.ts +118 -0
- package/src/tools-list-json-schema.test.ts +67 -0
- package/src/tools.ts +3927 -323
- package/src/upload-early-reject-guard.test.ts +155 -0
- package/src/uploads-http.test.ts +97 -15
- package/src/uploads.ts +103 -6
- package/src/user-avatar-http.test.ts +74 -0
- package/src/user-avatar-migration.test.ts +25 -0
- package/src/user-inbox-by-agent-http.test.ts +161 -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
|
@@ -0,0 +1,344 @@
|
|
|
1
|
+
// Project folder view — list_node_files / read_node_file ride the rules-file
|
|
2
|
+
// queue + doorbell (ops files_list / file_read).
|
|
3
|
+
//
|
|
4
|
+
// Hub-side contract verified here:
|
|
5
|
+
// 1. report_status { files_capable: true } is sticky and set only by the
|
|
6
|
+
// session's own node token (bound or legacy-unbound, same rule as skills).
|
|
7
|
+
// 2. Both tools reach a session with no nodes row by alias; the pulled
|
|
8
|
+
// request carries the normalized RELATIVE path; results come back through
|
|
9
|
+
// get_rules_file_result.
|
|
10
|
+
// 3. Absolute paths, `..`, `~`, drive letters, backslashes and NUL are refused
|
|
11
|
+
// before any request row exists (the node re-checks; this is the first wall).
|
|
12
|
+
// 4. A node token may not enqueue a files op (it would read another node's
|
|
13
|
+
// disk), and only the token that asked may read a files result.
|
|
14
|
+
// 5. A token bound to node A never pulls or acks node B's files request; an
|
|
15
|
+
// unbound legacy token falls back to its alias exactly as it does for skills.
|
|
16
|
+
// 6. Its own single-flight lane; rules-capable-only sessions are refused.
|
|
17
|
+
// 7. Files acks may carry up to 1 MiB (escaped JSON of a 256 KiB file); rules
|
|
18
|
+
// acks keep their 256 KiB cap.
|
|
19
|
+
//
|
|
20
|
+
// 跑法:cd server && COMMHUB_DB=/tmp/files-transport.db bun test src/node-files-transport.test.ts
|
|
21
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
22
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
23
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
24
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
25
|
+
import { db } from "./db.js";
|
|
26
|
+
import { registerTools } from "./tools.js";
|
|
27
|
+
|
|
28
|
+
const NET = "net_files_session";
|
|
29
|
+
const OTHER_NET = "net_files_session_other";
|
|
30
|
+
const USER = "u_files_session_owner";
|
|
31
|
+
const SESSION_ALIAS = "files-session-cc";
|
|
32
|
+
const SESSION_RESUME = "cc-files-session-1";
|
|
33
|
+
const PEER_ALIAS = "files-session-peer";
|
|
34
|
+
const NODE_A = "files-node-a";
|
|
35
|
+
const NODE_B = "files-node-b";
|
|
36
|
+
const NODE_A_ID = "node_files_a";
|
|
37
|
+
const NODE_B_ID = "node_files_b";
|
|
38
|
+
const LEGACY_ALIAS = "files-node-legacy";
|
|
39
|
+
const LEGACY_ID = "node_files_legacy";
|
|
40
|
+
const T_SESSION = "tok_files_session_cc";
|
|
41
|
+
const T_PEER = "tok_files_session_peer";
|
|
42
|
+
const T_OTHER_NET_SAME_ALIAS = "tok_files_session_other_net";
|
|
43
|
+
const T_A = "tok_files_node_a";
|
|
44
|
+
const T_B = "tok_files_node_b";
|
|
45
|
+
const T_LEGACY = "tok_files_node_legacy";
|
|
46
|
+
|
|
47
|
+
function cleanup() {
|
|
48
|
+
for (const net of [NET, OTHER_NET]) {
|
|
49
|
+
try { db.run("DELETE FROM node_rules_requests WHERE network_id = ?1", [net]); } catch {}
|
|
50
|
+
try { db.run("DELETE FROM rename_txn WHERE network_id = ?1", [net]); } catch {}
|
|
51
|
+
try { db.run("DELETE FROM sessions WHERE network_id = ?1", [net]); } catch {}
|
|
52
|
+
try { db.run("DELETE FROM nodes WHERE network_id = ?1", [net]); } catch {}
|
|
53
|
+
try { db.run("DELETE FROM api_tokens WHERE network_id = ?1", [net]); } catch {}
|
|
54
|
+
try { db.run("DELETE FROM network_members WHERE network_id = ?1", [net]); } catch {}
|
|
55
|
+
try { db.run("DELETE FROM networks WHERE network_id = ?1", [net]); } catch {}
|
|
56
|
+
}
|
|
57
|
+
try { db.run("DELETE FROM users WHERE user_id = ?1", [USER]); } catch {}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function seedWorld() {
|
|
61
|
+
db.run(`INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?2, 'x', 'user', datetime('now'))`, [USER, USER]);
|
|
62
|
+
for (const net of [NET, OTHER_NET]) {
|
|
63
|
+
db.run(`INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?2, ?3, datetime('now'))`, [net, net, USER]);
|
|
64
|
+
db.run(`INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'owner', datetime('now'))`, [USER, net]);
|
|
65
|
+
}
|
|
66
|
+
const tok = (id: string, net: string, alias: string, bound: string | null = null) => db.run(
|
|
67
|
+
`INSERT INTO api_tokens (token_id, user_id, network_id, scope, name, token_hash, expires_at, revoked_at, bound_node_id) VALUES (?1, ?2, ?3, 'network', ?4, ?5, NULL, NULL, ?6)`,
|
|
68
|
+
[id, USER, net, `node:${alias}`, `hash_${id}`, bound],
|
|
69
|
+
);
|
|
70
|
+
const node = (id: string, alias: string) => db.run(
|
|
71
|
+
`INSERT INTO nodes (node_id, node_name, alias, network_id, created_at, updated_at) VALUES (?1, ?2, ?3, ?4, datetime('now'), datetime('now'))`,
|
|
72
|
+
[id, alias, alias, NET],
|
|
73
|
+
);
|
|
74
|
+
node(NODE_A_ID, NODE_A);
|
|
75
|
+
node(NODE_B_ID, NODE_B);
|
|
76
|
+
node(LEGACY_ID, LEGACY_ALIAS);
|
|
77
|
+
tok(T_SESSION, NET, SESSION_ALIAS);
|
|
78
|
+
tok(T_PEER, NET, PEER_ALIAS);
|
|
79
|
+
tok(T_OTHER_NET_SAME_ALIAS, OTHER_NET, SESSION_ALIAS);
|
|
80
|
+
tok(T_A, NET, NODE_A, NODE_A_ID);
|
|
81
|
+
tok(T_B, NET, NODE_B, NODE_B_ID);
|
|
82
|
+
tok(T_LEGACY, NET, LEGACY_ALIAS, null);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
type Identity = { net: string; alias: string; isNetworkToken: boolean; tokenId: string };
|
|
86
|
+
const asUser: Identity = { net: NET, alias: USER, isNetworkToken: false, tokenId: "tok_files_session_user" };
|
|
87
|
+
const asUserOtherLogin: Identity = { net: NET, alias: USER, isNetworkToken: false, tokenId: "tok_files_session_user_other_login" };
|
|
88
|
+
const asSession: Identity = { net: NET, alias: SESSION_ALIAS, isNetworkToken: true, tokenId: T_SESSION };
|
|
89
|
+
const asPeer: Identity = { net: NET, alias: PEER_ALIAS, isNetworkToken: true, tokenId: T_PEER };
|
|
90
|
+
const asOtherNetSameAlias: Identity = { net: OTHER_NET, alias: SESSION_ALIAS, isNetworkToken: true, tokenId: T_OTHER_NET_SAME_ALIAS };
|
|
91
|
+
const asA: Identity = { net: NET, alias: NODE_A, isNetworkToken: true, tokenId: T_A };
|
|
92
|
+
const asB: Identity = { net: NET, alias: NODE_B, isNetworkToken: true, tokenId: T_B };
|
|
93
|
+
const asLegacy: Identity = { net: NET, alias: LEGACY_ALIAS, isNetworkToken: true, tokenId: T_LEGACY };
|
|
94
|
+
|
|
95
|
+
async function connect(id: Identity) {
|
|
96
|
+
const server = new McpServer({ name: "files-session-test", version: "1" });
|
|
97
|
+
registerTools(server, undefined, id.net, USER, id.alias, id.isNetworkToken, id.tokenId);
|
|
98
|
+
const client = new Client({ name: "files-session-client", version: "1" });
|
|
99
|
+
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
100
|
+
await server.connect(st);
|
|
101
|
+
await client.connect(ct);
|
|
102
|
+
const call = async (name: string, args: Record<string, unknown>) => {
|
|
103
|
+
const r: any = await client.callTool({ name, arguments: args });
|
|
104
|
+
const first = r.content?.[0];
|
|
105
|
+
if (!first || first.type !== "text") throw new Error(`no text result from ${name}: ${JSON.stringify(r).slice(0, 300)}`);
|
|
106
|
+
try { return JSON.parse(first.text); } catch { return { raw: first.text, isError: r.isError === true }; }
|
|
107
|
+
};
|
|
108
|
+
const close = async () => { await client.close(); await server.close(); };
|
|
109
|
+
return { call, close };
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const capable = (alias: string, net = NET) =>
|
|
113
|
+
db.get<{ c: number }>("SELECT files_capable AS c FROM sessions WHERE alias = ?1 AND network_id = ?2", alias, net)?.c;
|
|
114
|
+
const rowCount = () => db.get<{ n: number }>("SELECT COUNT(*) AS n FROM node_rules_requests WHERE network_id = ?1", NET)!.n;
|
|
115
|
+
|
|
116
|
+
async function report(id: Identity, alias: string, resume: string, flags: Record<string, true>) {
|
|
117
|
+
const c = await connect(id);
|
|
118
|
+
try { return await c.call("report_status", { resume_id: resume, alias, status: "idle", agent: "claude-code", ...flags }); }
|
|
119
|
+
finally { await c.close(); }
|
|
120
|
+
}
|
|
121
|
+
const ALL_FLAGS = { rules_file_capable: true, skills_capable: true, files_capable: true } as const;
|
|
122
|
+
|
|
123
|
+
beforeEach(() => { cleanup(); seedWorld(); });
|
|
124
|
+
afterAll(cleanup);
|
|
125
|
+
|
|
126
|
+
describe("files_capable is set only by the session's own node token", () => {
|
|
127
|
+
test("own token sets it; a later report without it does not clear it; a peer cannot set it", async () => {
|
|
128
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
129
|
+
expect(capable(SESSION_ALIAS)).toBe(1);
|
|
130
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, {});
|
|
131
|
+
expect(capable(SESSION_ALIAS)).toBe(1);
|
|
132
|
+
const r = await report(asPeer, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
133
|
+
expect(r).toMatchObject({ ok: false });
|
|
134
|
+
// A user login cannot set it either.
|
|
135
|
+
await report(asUser, PEER_ALIAS, "cc-files-user-report", ALL_FLAGS);
|
|
136
|
+
expect(capable(PEER_ALIAS) ?? 0).toBe(0);
|
|
137
|
+
}, 20_000);
|
|
138
|
+
|
|
139
|
+
test("a stale process whose report is rewritten to a renamed alias does not grant that alias the flag", async () => {
|
|
140
|
+
const NEW_ALIAS = "files-session-renamed";
|
|
141
|
+
db.run(
|
|
142
|
+
`INSERT INTO rename_txn (txn_id, network_id, old_alias, new_alias, status, committed_at) VALUES ('txn_files_rename', ?1, ?2, ?3, 'committed', datetime('now'))`,
|
|
143
|
+
[NET, PEER_ALIAS, NEW_ALIAS],
|
|
144
|
+
);
|
|
145
|
+
// Token still carries the old alias; the hub rewrites the report to NEW_ALIAS.
|
|
146
|
+
const r = await report(asPeer, PEER_ALIAS, "cc-files-renamed", ALL_FLAGS);
|
|
147
|
+
expect(r.ok).toBe(true);
|
|
148
|
+
expect(db.get<{ n: number }>("SELECT COUNT(*) AS n FROM sessions WHERE alias = ?1 AND network_id = ?2", NEW_ALIAS, NET)!.n).toBe(1);
|
|
149
|
+
expect(capable(NEW_ALIAS)).toBe(0);
|
|
150
|
+
}, 20_000);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe("list / read by alias reach a session with no nodes row", () => {
|
|
154
|
+
test("list: pulled request carries the normalized relative path; result comes back", async () => {
|
|
155
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
156
|
+
const u = await connect(asUser);
|
|
157
|
+
const s = await connect(asSession);
|
|
158
|
+
try {
|
|
159
|
+
const enq = await u.call("list_node_files", { alias: SESSION_ALIAS, path: "./src//lib/" });
|
|
160
|
+
expect(enq).toMatchObject({ ok: true, op: "files_list" });
|
|
161
|
+
const pulled = await s.call("get_rules_file_request", {});
|
|
162
|
+
expect(pulled.request).toEqual({ request_id: enq.request_id, op: "files_list", content: "src/lib" });
|
|
163
|
+
const payload = JSON.stringify({ path: "src/lib", entries: [{ name: "a.ts", type: "file", size: 3, mtime: 1 }], truncated: false, total: 1 });
|
|
164
|
+
expect(await s.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", file_name: "files", exists: true, content: payload })).toMatchObject({ ok: true, status: "done" });
|
|
165
|
+
expect(await u.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: true, op: "files_list", status: "done", content: payload });
|
|
166
|
+
} finally { await u.close(); await s.close(); }
|
|
167
|
+
}, 20_000);
|
|
168
|
+
|
|
169
|
+
test("list with no path targets the root (empty content)", async () => {
|
|
170
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
171
|
+
const u = await connect(asUser);
|
|
172
|
+
const s = await connect(asSession);
|
|
173
|
+
try {
|
|
174
|
+
const enq = await u.call("list_node_files", { alias: SESSION_ALIAS });
|
|
175
|
+
expect((await s.call("get_rules_file_request", {})).request).toEqual({ request_id: enq.request_id, op: "files_list", content: "" });
|
|
176
|
+
} finally { await u.close(); await s.close(); }
|
|
177
|
+
}, 20_000);
|
|
178
|
+
|
|
179
|
+
test("read round trip", async () => {
|
|
180
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
181
|
+
const u = await connect(asUser);
|
|
182
|
+
const s = await connect(asSession);
|
|
183
|
+
try {
|
|
184
|
+
const enq = await u.call("read_node_file", { alias: SESSION_ALIAS, path: "docs/README.md" });
|
|
185
|
+
expect(enq).toMatchObject({ ok: true, op: "file_read" });
|
|
186
|
+
expect((await s.call("get_rules_file_request", {})).request).toEqual({ request_id: enq.request_id, op: "file_read", content: "docs/README.md" });
|
|
187
|
+
const payload = JSON.stringify({ path: "docs/README.md", name: "README.md", kind: "text", size: 6, content: "# hi\n" });
|
|
188
|
+
await s.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", file_name: "README.md", exists: true, content: payload });
|
|
189
|
+
expect(await u.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ status: "done", content: payload });
|
|
190
|
+
} finally { await u.close(); await s.close(); }
|
|
191
|
+
}, 20_000);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("path validation happens before any row is written", () => {
|
|
195
|
+
test("absolute, .., ~, drive letters, backslashes, NUL, and an empty read path are refused", async () => {
|
|
196
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
197
|
+
const u = await connect(asUser);
|
|
198
|
+
try {
|
|
199
|
+
const bad = ["/etc/passwd", "../outside", "a/../../b", "src/..", "~/.ssh/id_rsa", "C:/Windows", "a\\b", "..\\x", "a\u0000b", "x".repeat(1025)];
|
|
200
|
+
for (const path of bad) {
|
|
201
|
+
// Over-long paths are stopped by the zod schema (an MCP input error); the rest by invalid_path.
|
|
202
|
+
const r = await u.call("read_node_file", { alias: SESSION_ALIAS, path });
|
|
203
|
+
expect(r.ok).not.toBe(true);
|
|
204
|
+
if (path.length <= 1024) expect(r).toMatchObject({ ok: false, error: "invalid_path" });
|
|
205
|
+
const l = await u.call("list_node_files", { alias: SESSION_ALIAS, path });
|
|
206
|
+
expect(l.ok).not.toBe(true);
|
|
207
|
+
}
|
|
208
|
+
expect(await u.call("read_node_file", { alias: SESSION_ALIAS, path: "/" })).toMatchObject({ ok: false, error: "invalid_path" });
|
|
209
|
+
expect(await u.call("read_node_file", { alias: SESSION_ALIAS, path: "./" })).toMatchObject({ ok: false, error: "invalid_path" });
|
|
210
|
+
expect(rowCount()).toBe(0);
|
|
211
|
+
} finally { await u.close(); }
|
|
212
|
+
}, 20_000);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
describe("who may ask, and who may read the answer", () => {
|
|
216
|
+
test("a node token cannot enqueue a files op on another node (or itself)", async () => {
|
|
217
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
218
|
+
const a = await connect(asA);
|
|
219
|
+
try {
|
|
220
|
+
expect(await a.call("list_node_files", { alias: SESSION_ALIAS })).toMatchObject({ ok: false, error: "node_token_cannot_browse_files" });
|
|
221
|
+
expect(await a.call("read_node_file", { node_id: NODE_B_ID, path: ".env" })).toMatchObject({ ok: false, error: "node_token_cannot_browse_files" });
|
|
222
|
+
expect(await a.call("list_node_files", { node_id: NODE_A_ID })).toMatchObject({ ok: false, error: "node_token_cannot_browse_files" });
|
|
223
|
+
expect(rowCount()).toBe(0);
|
|
224
|
+
} finally { await a.close(); }
|
|
225
|
+
}, 20_000);
|
|
226
|
+
|
|
227
|
+
test("only the token that asked can read a files result; node tokens never can", async () => {
|
|
228
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
229
|
+
const u = await connect(asUser);
|
|
230
|
+
const other = await connect(asUserOtherLogin);
|
|
231
|
+
const s = await connect(asSession);
|
|
232
|
+
const a = await connect(asA);
|
|
233
|
+
try {
|
|
234
|
+
const enq = await u.call("read_node_file", { alias: SESSION_ALIAS, path: "notes.txt" });
|
|
235
|
+
await s.call("get_rules_file_request", {});
|
|
236
|
+
await s.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: JSON.stringify({ path: "notes.txt", kind: "text", content: "x" }) });
|
|
237
|
+
expect(await u.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: true, status: "done" });
|
|
238
|
+
expect(await other.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: false, error: "request_not_found" });
|
|
239
|
+
expect(await a.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: false, error: "request_not_found" });
|
|
240
|
+
// The serving session itself cannot read the stored result back through the client tool either.
|
|
241
|
+
expect(await s.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: false, error: "request_not_found" });
|
|
242
|
+
} finally { await u.close(); await other.close(); await s.close(); await a.close(); }
|
|
243
|
+
}, 20_000);
|
|
244
|
+
|
|
245
|
+
test("rules/skills results stay readable by any writer of the network (unchanged)", async () => {
|
|
246
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
247
|
+
const u = await connect(asUser);
|
|
248
|
+
const other = await connect(asUserOtherLogin);
|
|
249
|
+
try {
|
|
250
|
+
const enq = await u.call("list_node_skills", { alias: SESSION_ALIAS });
|
|
251
|
+
expect(await other.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ ok: true, status: "pending" });
|
|
252
|
+
} finally { await u.close(); await other.close(); }
|
|
253
|
+
}, 20_000);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
describe("a token bound to node A cannot touch node B's files request", () => {
|
|
257
|
+
test("B's request: A pulls nothing, A's ack is ignored, B pulls and acks it", async () => {
|
|
258
|
+
const u = await connect(asUser);
|
|
259
|
+
const a = await connect(asA);
|
|
260
|
+
const b = await connect(asB);
|
|
261
|
+
try {
|
|
262
|
+
const enq = await u.call("read_node_file", { node_id: NODE_B_ID, path: "secret-plan.md" });
|
|
263
|
+
expect(enq).toMatchObject({ ok: true });
|
|
264
|
+
expect((await a.call("get_rules_file_request", {})).request).toBeNull();
|
|
265
|
+
expect(await a.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: "{\"forged\":true}" })).toMatchObject({ ok: true, ignored: "unknown_or_foreign_request" });
|
|
266
|
+
expect(await u.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ status: "pending" });
|
|
267
|
+
expect((await b.call("get_rules_file_request", {})).request).toEqual({ request_id: enq.request_id, op: "file_read", content: "secret-plan.md" });
|
|
268
|
+
expect(await b.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: "{}" })).toMatchObject({ ok: true, status: "done" });
|
|
269
|
+
} finally { await u.close(); await a.close(); await b.close(); }
|
|
270
|
+
}, 20_000);
|
|
271
|
+
|
|
272
|
+
test("same alias in another network neither pulls nor acks; a peer's ack is ignored", async () => {
|
|
273
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
274
|
+
const u = await connect(asUser);
|
|
275
|
+
const other = await connect(asOtherNetSameAlias);
|
|
276
|
+
const peer = await connect(asPeer);
|
|
277
|
+
try {
|
|
278
|
+
const enq = await u.call("list_node_files", { alias: SESSION_ALIAS });
|
|
279
|
+
expect((await other.call("get_rules_file_request", {})).request).toBeNull();
|
|
280
|
+
expect(await other.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: "{}" })).toMatchObject({ ignored: "unknown_or_foreign_request" });
|
|
281
|
+
expect(await peer.call("ack_rules_file_request", { request_id: enq.request_id, status: "done", content: "{}" })).toMatchObject({ ignored: "unknown_or_foreign_request" });
|
|
282
|
+
expect(await u.call("get_rules_file_result", { request_id: enq.request_id })).toMatchObject({ status: "pending" });
|
|
283
|
+
} finally { await u.close(); await other.close(); await peer.close(); }
|
|
284
|
+
}, 20_000);
|
|
285
|
+
|
|
286
|
+
test("an unbound legacy token gets what skills gives it: alias fallback pull + ack, and it can set its own flag", async () => {
|
|
287
|
+
const u = await connect(asUser);
|
|
288
|
+
const legacy = await connect(asLegacy);
|
|
289
|
+
try {
|
|
290
|
+
await report(asLegacy, LEGACY_ALIAS, `sdk-${LEGACY_ID}`, ALL_FLAGS);
|
|
291
|
+
expect(capable(LEGACY_ALIAS)).toBe(1);
|
|
292
|
+
const skills = await u.call("list_node_skills", { node_id: LEGACY_ID });
|
|
293
|
+
const files = await u.call("list_node_files", { node_id: LEGACY_ID, path: "src" });
|
|
294
|
+
expect(skills).toMatchObject({ ok: true });
|
|
295
|
+
expect(files).toMatchObject({ ok: true });
|
|
296
|
+
const first = (await legacy.call("get_rules_file_request", {})).request;
|
|
297
|
+
const second = (await legacy.call("get_rules_file_request", {})).request;
|
|
298
|
+
expect([first.request_id, second.request_id].sort()).toEqual([skills.request_id, files.request_id].sort());
|
|
299
|
+
expect(await legacy.call("ack_rules_file_request", { request_id: files.request_id, status: "done", content: "{}" })).toMatchObject({ ok: true, status: "done" });
|
|
300
|
+
expect(await legacy.call("ack_rules_file_request", { request_id: skills.request_id, status: "done", content: "{}" })).toMatchObject({ ok: true, status: "done" });
|
|
301
|
+
} finally { await u.close(); await legacy.close(); }
|
|
302
|
+
}, 20_000);
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
describe("lanes, capability gate and ack size", () => {
|
|
306
|
+
test("files has its own single-flight lane", async () => {
|
|
307
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
308
|
+
const u = await connect(asUser);
|
|
309
|
+
try {
|
|
310
|
+
expect(await u.call("read_node_rules_file", { alias: SESSION_ALIAS })).toMatchObject({ ok: true });
|
|
311
|
+
expect(await u.call("list_node_skills", { alias: SESSION_ALIAS })).toMatchObject({ ok: true });
|
|
312
|
+
const list = await u.call("list_node_files", { alias: SESSION_ALIAS });
|
|
313
|
+
expect(list).toMatchObject({ ok: true });
|
|
314
|
+
expect(await u.call("read_node_file", { alias: SESSION_ALIAS, path: "a.txt" })).toMatchObject({ ok: false, error: "request_in_flight", existing_request_id: list.request_id });
|
|
315
|
+
} finally { await u.close(); }
|
|
316
|
+
}, 20_000);
|
|
317
|
+
|
|
318
|
+
test("rules+skills capable but not files capable → files_target_not_found, no row", async () => {
|
|
319
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, { rules_file_capable: true, skills_capable: true });
|
|
320
|
+
const u = await connect(asUser);
|
|
321
|
+
try {
|
|
322
|
+
expect(await u.call("list_node_files", { alias: SESSION_ALIAS })).toMatchObject({ ok: false, error: "files_target_not_found" });
|
|
323
|
+
expect(rowCount()).toBe(0);
|
|
324
|
+
} finally { await u.close(); }
|
|
325
|
+
}, 20_000);
|
|
326
|
+
|
|
327
|
+
test("a files ack may carry up to 1 MiB; a rules ack keeps its 256 KiB cap", async () => {
|
|
328
|
+
await report(asSession, SESSION_ALIAS, SESSION_RESUME, ALL_FLAGS);
|
|
329
|
+
const u = await connect(asUser);
|
|
330
|
+
const s = await connect(asSession);
|
|
331
|
+
try {
|
|
332
|
+
const big = JSON.stringify({ path: "big.txt", kind: "text", content: "\n".repeat(256 * 1024) });
|
|
333
|
+
expect(big.length).toBeGreaterThan(256 * 1024);
|
|
334
|
+
const f = await u.call("read_node_file", { alias: SESSION_ALIAS, path: "big.txt" });
|
|
335
|
+
const r = await u.call("read_node_rules_file", { alias: SESSION_ALIAS });
|
|
336
|
+
await s.call("get_rules_file_request", {});
|
|
337
|
+
await s.call("get_rules_file_request", {});
|
|
338
|
+
expect(await s.call("ack_rules_file_request", { request_id: f.request_id, status: "done", content: big })).toMatchObject({ ok: true, status: "done" });
|
|
339
|
+
expect(await s.call("ack_rules_file_request", { request_id: r.request_id, status: "done", content: "x".repeat(256 * 1024 + 1) })).toMatchObject({ ok: false, error: "content_too_large" });
|
|
340
|
+
const tooBig = await s.call("ack_rules_file_request", { request_id: r.request_id, status: "done", content: "x".repeat(1024 * 1024 + 1) });
|
|
341
|
+
expect(tooBig.ok).not.toBe(true);
|
|
342
|
+
} finally { await u.close(); await s.close(); }
|
|
343
|
+
}, 20_000);
|
|
344
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
// #594 step 1 — report_status.health.codex_login (non-secret codex login fingerprint +
|
|
2
|
+
// "shared with N other nodes on this host"). Additive on the #448 health channel.
|
|
3
|
+
//
|
|
4
|
+
// 跑法:cd server && COMMHUB_DB=/tmp/node-health-codex-login.db bun test src/node-health-codex-login.test.ts
|
|
5
|
+
import { afterAll, beforeEach, describe, expect, test } from "bun:test";
|
|
6
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
7
|
+
import { InMemoryTransport } from "@modelcontextprotocol/sdk/inMemory.js";
|
|
8
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
9
|
+
import { db } from "./db.js";
|
|
10
|
+
import { registerTools } from "./tools.js";
|
|
11
|
+
import { clearNodeHealthStore, readNodeHealth } from "./node-health-store.js";
|
|
12
|
+
import { degradedLayers } from "./node-health-guard.js";
|
|
13
|
+
|
|
14
|
+
const NET = "net_health_codex_login_t";
|
|
15
|
+
const OWNER = "u_hcl_owner";
|
|
16
|
+
const NODE_A = "hcl-node-a";
|
|
17
|
+
const NODE_B = "hcl-node-b";
|
|
18
|
+
const NODE_A_ID = "node_hcl_a";
|
|
19
|
+
const NODE_B_ID = "node_hcl_b";
|
|
20
|
+
const T_A = "tok_hcl_node_a";
|
|
21
|
+
const T_B = "tok_hcl_node_b";
|
|
22
|
+
|
|
23
|
+
function cleanup() {
|
|
24
|
+
for (const t of ["sessions", "nodes", "api_tokens", "network_members", "networks"]) {
|
|
25
|
+
try { db.run(`DELETE FROM ${t} WHERE network_id = ?1`, [NET]); } catch {}
|
|
26
|
+
}
|
|
27
|
+
try { db.run("DELETE FROM users WHERE user_id = ?1", [OWNER]); } catch {}
|
|
28
|
+
clearNodeHealthStore();
|
|
29
|
+
}
|
|
30
|
+
function seed() {
|
|
31
|
+
db.run(`INSERT INTO users (user_id, username, password_hash, role, created_at) VALUES (?1, ?2, 'x', 'user', datetime('now'))`, [OWNER, OWNER]);
|
|
32
|
+
db.run(`INSERT INTO networks (network_id, network_name, owner_id, created_at) VALUES (?1, ?2, ?3, datetime('now'))`, [NET, NET, OWNER]);
|
|
33
|
+
db.run(`INSERT INTO network_members (user_id, network_id, role, joined_at) VALUES (?1, ?2, 'owner', datetime('now'))`, [OWNER, NET]);
|
|
34
|
+
for (const [id, alias, tok] of [[NODE_A_ID, NODE_A, T_A], [NODE_B_ID, NODE_B, T_B]]) {
|
|
35
|
+
db.run(`INSERT INTO nodes (node_id, node_name, alias, network_id, owner_user_id, created_at, updated_at) VALUES (?1, ?2, ?3, ?4, ?5, datetime('now'), datetime('now'))`, [id, alias, alias, NET, OWNER]);
|
|
36
|
+
db.run(`INSERT INTO api_tokens (token_id, user_id, network_id, scope, name, token_hash, expires_at, revoked_at, bound_node_id) VALUES (?1, ?2, ?3, 'network', ?4, ?5, NULL, NULL, ?6)`, [tok, OWNER, NET, `node:${alias}`, `hash_${tok}`, id]);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async function connectAs(alias: string, tokenId: string) {
|
|
41
|
+
const server = new McpServer({ name: "health-test", version: "1" });
|
|
42
|
+
registerTools(server, undefined, NET, OWNER, alias, true, tokenId);
|
|
43
|
+
const client = new Client({ name: "health-client", version: "1" });
|
|
44
|
+
const [ct, st] = InMemoryTransport.createLinkedPair();
|
|
45
|
+
await server.connect(st);
|
|
46
|
+
await client.connect(ct);
|
|
47
|
+
const call = async (args: Record<string, unknown>) => {
|
|
48
|
+
const r: any = await client.callTool({ name: "report_status", arguments: args });
|
|
49
|
+
return { isError: r.isError === true, body: JSON.parse(r.content?.[0]?.text ?? "null") };
|
|
50
|
+
};
|
|
51
|
+
return { call, close: async () => { await client.close(); await server.close(); } };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const LOGIN = { fingerprint: "1a2b3c4d", shared_with: 2, shared_home_with: 1, codex_home: "/srv/ws/.anet/nodes/a/codex-home" };
|
|
55
|
+
|
|
56
|
+
beforeEach(() => { cleanup(); seed(); });
|
|
57
|
+
afterAll(cleanup);
|
|
58
|
+
|
|
59
|
+
describe("#594 report_status.health.codex_login passthrough", () => {
|
|
60
|
+
test("well-formed codex_login is kept next to the #448 layers and readable", async () => {
|
|
61
|
+
const a = await connectAs(NODE_A, T_A);
|
|
62
|
+
try {
|
|
63
|
+
const r = await a.call({ resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID, health: { bridge: "ok", model_auth: "ok", codex_login: LOGIN } });
|
|
64
|
+
expect(r.isError).toBe(false);
|
|
65
|
+
} finally { await a.close(); }
|
|
66
|
+
expect(readNodeHealth(NET, NODE_A)?.health.codex_login).toEqual(LOGIN);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("codex_login alone (codex-sdk runtime, no #448 monitor) is accepted", async () => {
|
|
70
|
+
const a = await connectAs(NODE_A, T_A);
|
|
71
|
+
try {
|
|
72
|
+
await a.call({ resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID, health: { codex_login: { fingerprint: "deadbeef", shared_with: 0 } } });
|
|
73
|
+
} finally { await a.close(); }
|
|
74
|
+
expect(readNodeHealth(NET, NODE_A)?.health.codex_login).toEqual({ fingerprint: "deadbeef", shared_with: 0 });
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test("🔴 a shared login is NOT a degraded layer — dispatch must not refuse because of it", () => {
|
|
78
|
+
expect(degradedLayers({ bridge: "ok", model_auth: "ok", codex_login: LOGIN } as any)).toEqual([]);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
test("🔴 anything that is not an 8-hex fingerprint is dropped (a token pasted there never gets stored), report still accepted", async () => {
|
|
82
|
+
const a = await connectAs(NODE_A, T_A);
|
|
83
|
+
const bads = [
|
|
84
|
+
{ fingerprint: "FAKE-REFRESH-TOKEN-should-never-be-stored", shared_with: 1 },
|
|
85
|
+
{ fingerprint: "a".repeat(64), shared_with: 1 },
|
|
86
|
+
{ fingerprint: "1A2B3C4D", shared_with: 1 },
|
|
87
|
+
{ fingerprint: "1a2b3c4d", shared_with: -1 },
|
|
88
|
+
{ fingerprint: "1a2b3c4d", shared_with: 1.5 },
|
|
89
|
+
{ fingerprint: "1a2b3c4d" },
|
|
90
|
+
"1a2b3c4d",
|
|
91
|
+
];
|
|
92
|
+
try {
|
|
93
|
+
for (const bad of bads) {
|
|
94
|
+
const r = await a.call({ resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID, health: { bridge: "ok", model_auth: "ok", codex_login: bad } });
|
|
95
|
+
expect(r.isError).toBe(false);
|
|
96
|
+
const h = readNodeHealth(NET, NODE_A)?.health;
|
|
97
|
+
expect(h?.model_auth).toBe("ok");
|
|
98
|
+
expect(h?.codex_login).toBeUndefined();
|
|
99
|
+
expect(JSON.stringify(h)).not.toContain("FAKE-REFRESH-TOKEN");
|
|
100
|
+
}
|
|
101
|
+
} finally { await a.close(); }
|
|
102
|
+
expect(db.get<{ s: string }>("SELECT status AS s FROM sessions WHERE alias = ?1 AND network_id = ?2", NODE_A, NET)?.s).toBe("idle");
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
test("bad optional sub-fields degrade alone: control characters in codex_home are dropped, the rest kept", async () => {
|
|
106
|
+
const a = await connectAs(NODE_A, T_A);
|
|
107
|
+
try {
|
|
108
|
+
await a.call({ resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID, health: { codex_login: { fingerprint: "1a2b3c4d", shared_with: 1, shared_home_with: "x", codex_home: "/x\n; rm -rf /" } } });
|
|
109
|
+
} finally { await a.close(); }
|
|
110
|
+
expect(readNodeHealth(NET, NODE_A)?.health.codex_login).toEqual({ fingerprint: "1a2b3c4d", shared_with: 1 });
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
test("another node's token cannot set this node's codex_login", async () => {
|
|
114
|
+
const b = await connectAs(NODE_B, T_B);
|
|
115
|
+
try {
|
|
116
|
+
await b.call({ resume_id: `sdk-${NODE_A_ID}`, alias: NODE_A, status: "idle", node_id: NODE_A_ID, health: { codex_login: LOGIN } });
|
|
117
|
+
} finally { await b.close(); }
|
|
118
|
+
expect(readNodeHealth(NET, NODE_A)).toBeNull();
|
|
119
|
+
});
|
|
120
|
+
});
|