@sleep2agi/commhub-server 0.9.0-preview.21 → 0.9.0-preview.211

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.
Files changed (397) hide show
  1. package/README.md +130 -10
  2. package/bin/commhub.ts +99 -11
  3. package/package.json +7 -7
  4. package/src/ack-create-request-transport.test.ts +182 -0
  5. package/src/ack-create-request.test.ts +50 -7
  6. package/src/admin-delete-network-http.test.ts +228 -0
  7. package/src/admin-networks-http.test.ts +88 -0
  8. package/src/adoption-candidates-http.test.ts +137 -0
  9. package/src/adoption-candidates.ts +158 -0
  10. package/src/agent-access-batch.test.ts +210 -0
  11. package/src/agent-access.ts +487 -0
  12. package/src/agent-acl-groups-http.test.ts +247 -0
  13. package/src/agent-acl-http.test.ts +659 -0
  14. package/src/agent-acl-slice3-http.test.ts +267 -0
  15. package/src/agent-department-http.test.ts +215 -0
  16. package/src/agent-groups-perf.test.ts +223 -0
  17. package/src/agent-notice.ts +48 -0
  18. package/src/agent-team-whoami-http.test.ts +98 -0
  19. package/src/agent-teams-http.test.ts +330 -0
  20. package/src/agent-teams.ts +244 -0
  21. package/src/alias-baseline-2571.test.ts +162 -0
  22. package/src/alias-baseline.ts +113 -0
  23. package/src/alias-filter.test.ts +72 -0
  24. package/src/alias-filter.ts +42 -0
  25. package/src/api-host-supervisors-can-create-nodes.test.ts +350 -0
  26. package/src/api-host-supervisors-fallback.test.ts +21 -12
  27. package/src/api-host-supervisors-runtime-readiness.test.ts +195 -0
  28. package/src/api-nodes-shape.test.ts +120 -13
  29. package/src/auth-password-change-cli-tokens-http.test.ts +423 -0
  30. package/src/auth-sessions-http.test.ts +250 -0
  31. package/src/auth-validate.test.ts +5 -1
  32. package/src/auth-weak-password-login.test.ts +176 -0
  33. package/src/auth.ts +609 -51
  34. package/src/avatar-validate.test.ts +163 -0
  35. package/src/avatar-validate.ts +103 -0
  36. package/src/backfill-node-ids-2664.test.ts +128 -0
  37. package/src/binding-generation-http.test.ts +121 -0
  38. package/src/blocked-exit-on-reply.test.ts +122 -0
  39. package/src/boot-side-effect.test.ts +124 -0
  40. package/src/broadcast-fanout-2721.test.ts +118 -0
  41. package/src/broadcast-fanout.ts +98 -0
  42. package/src/chain-attempt-dedup.test.ts +447 -0
  43. package/src/clone-node.test.ts +248 -0
  44. package/src/clone-node.ts +289 -0
  45. package/src/codex-config-flags.ts +77 -0
  46. package/src/codex-fork-contract.ts +23 -0
  47. package/src/codex-fork-migration.test.ts +38 -0
  48. package/src/commhub-bin-args.test.ts +85 -0
  49. package/src/config-apply-validate.test.ts +42 -1
  50. package/src/config-apply-validate.ts +30 -2
  51. package/src/create-node-blocked-gate.test.ts +356 -0
  52. package/src/create-node-network-id.test.ts +79 -0
  53. package/src/create-node-tool-schema.test.ts +49 -0
  54. package/src/create-node-unicode-name.test.ts +120 -0
  55. package/src/create-node-validate.test.ts +199 -7
  56. package/src/create-node-validate.ts +232 -15
  57. package/src/create-node-workdir.test.ts +289 -0
  58. package/src/create-node.ts +88 -23
  59. package/src/daemon-provider-snapshots.test.ts +421 -0
  60. package/src/daemon-provider-snapshots.ts +327 -0
  61. package/src/daemon-token-owner-http.test.ts +236 -0
  62. package/src/dashboard-slash-routing-http.test.ts +109 -0
  63. package/src/db-adapter-guard.test.ts +148 -0
  64. package/src/db-adapter-translate.test.ts +128 -0
  65. package/src/db-adapter.ts +377 -91
  66. package/src/db-timestamp.test.ts +38 -0
  67. package/src/db-timestamp.ts +15 -0
  68. package/src/db.ts +1306 -153
  69. package/src/delivered-without-push.test.ts +140 -0
  70. package/src/department-groups-http.test.ts +209 -0
  71. package/src/department-groups-sync-http.test.ts +328 -0
  72. package/src/department-groups.ts +434 -0
  73. package/src/department-heads-http.test.ts +330 -0
  74. package/src/department-heads.ts +226 -0
  75. package/src/departments-agent-count.test.ts +129 -0
  76. package/src/departments-http.test.ts +185 -0
  77. package/src/departments-mcp.test.ts +128 -0
  78. package/src/departments.ts +318 -0
  79. package/src/desktop-message-seam.test.ts +150 -0
  80. package/src/desktop-message.test.ts +368 -0
  81. package/src/dm-file-scope-http.test.ts +178 -0
  82. package/src/empty-node-sweeper.test.ts +104 -0
  83. package/src/empty-node-sweeper.ts +88 -0
  84. package/src/env-transport-gate-http.test.ts +240 -0
  85. package/src/env-transport-gate.ts +80 -0
  86. package/src/env-transport-policy.ts +56 -0
  87. package/src/event-loop-lag.test.ts +180 -0
  88. package/src/event-loop-lag.ts +181 -0
  89. package/src/ext-token-shared.test.ts +60 -0
  90. package/src/ext-validation-regression.test.ts +131 -0
  91. package/src/external-schedule-edits-http.test.ts +321 -0
  92. package/src/external-schedule-edits-timestamps.test.ts +64 -0
  93. package/src/external-schedule-edits.ts +327 -0
  94. package/src/file-download-authz-dev-open.test.ts +135 -0
  95. package/src/file-download-authz.test.ts +404 -0
  96. package/src/file-download-date-bucket.test.ts +436 -0
  97. package/src/file-network-scope-dev-open.test.ts +97 -0
  98. package/src/file-network-scope.test.ts +732 -0
  99. package/src/group-membership-events-http.test.ts +264 -0
  100. package/src/group-messages-http.test.ts +482 -0
  101. package/src/group-messages.ts +297 -0
  102. package/src/health-host-disk-2756.test.ts +49 -0
  103. package/src/health-redaction.test.ts +685 -0
  104. package/src/host-supervisor-identity-http.test.ts +152 -0
  105. package/src/host-supervisor-identity.ts +92 -0
  106. package/src/host-supervisors-daemon-version.test.ts +137 -0
  107. package/src/http-gzip.test.ts +94 -0
  108. package/src/http-gzip.ts +112 -0
  109. package/src/hub-catalog-read-http.test.ts +187 -0
  110. package/src/hub-provider-config.test.ts +139 -0
  111. package/src/hub-provider-config.ts +105 -0
  112. package/src/hub-timestamp.test.ts +38 -0
  113. package/src/hub-timestamp.ts +27 -0
  114. package/src/human-dm.ts +215 -0
  115. package/src/human-inbox.ts +42 -0
  116. package/src/inbox-caller.ts +49 -0
  117. package/src/inbox-count-sse.test.ts +310 -0
  118. package/src/inbox-count.ts +29 -0
  119. package/src/index.ts +15 -2385
  120. package/src/list-host-supervisors.test.ts +5 -4
  121. package/src/mcp-context-cost-http.test.ts +127 -0
  122. package/src/mcp-inflight.test.ts +92 -0
  123. package/src/mcp-inflight.ts +38 -0
  124. package/src/mcp-projects-events-http.test.ts +162 -0
  125. package/src/mcp-route-label-http.test.ts +120 -0
  126. package/src/mcp-write-network-resolution.test.ts +432 -0
  127. package/src/member-audit-network-id-http.test.ts +93 -0
  128. package/src/member-presence-http.test.ts +210 -0
  129. package/src/messages-ack-by-agent-http.test.ts +142 -0
  130. package/src/migrate-sqlite-to-pg.test.ts +47 -0
  131. package/src/migrate-sqlite-to-pg.ts +263 -0
  132. package/src/model-auth-notify-http.test.ts +181 -0
  133. package/src/model-auth-notify.ts +116 -0
  134. package/src/network-name-http.test.ts +75 -0
  135. package/src/network-rules-http.test.ts +169 -0
  136. package/src/network-rules.ts +129 -0
  137. package/src/network-scope.ts +276 -0
  138. package/src/network-token-membership-http.test.ts +139 -0
  139. package/src/node-alias-control.ts +12 -0
  140. package/src/node-attrs-validate.ts +88 -0
  141. package/src/node-attrs.test.ts +258 -0
  142. package/src/node-caller-identity-http.test.ts +1083 -0
  143. package/src/node-create-request-status-http.test.ts +105 -0
  144. package/src/node-daemon-bindings.test.ts +132 -0
  145. package/src/node-daemon-bindings.ts +135 -0
  146. package/src/node-failure-alert.test.ts +150 -0
  147. package/src/node-failure-alert.ts +177 -0
  148. package/src/node-files-transport.test.ts +344 -0
  149. package/src/node-health-codex-login.test.ts +120 -0
  150. package/src/node-health-dispatch-http.test.ts +279 -0
  151. package/src/node-health-guard.ts +105 -0
  152. package/src/node-health-passthrough.test.ts +115 -0
  153. package/src/node-health-store.ts +101 -0
  154. package/src/node-id-alias.test.ts +190 -0
  155. package/src/node-identity-conflict-http.test.ts +269 -0
  156. package/src/node-identity-conflict.ts +142 -0
  157. package/src/node-identity-mismatch.test.ts +74 -0
  158. package/src/node-in-flight-tasks.ts +31 -0
  159. package/src/node-lifecycle-controllable.test.ts +64 -0
  160. package/src/node-lifecycle-controllable.ts +53 -0
  161. package/src/node-lifecycle-read-http.test.ts +250 -0
  162. package/src/node-lifecycle-read.ts +124 -0
  163. package/src/node-logs-transport.test.ts +263 -0
  164. package/src/node-peer-allowlist.test.ts +114 -0
  165. package/src/node-permissions-http.test.ts +648 -0
  166. package/src/node-permissions.ts +494 -0
  167. package/src/node-request-retention.test.ts +281 -0
  168. package/src/node-request-retention.ts +120 -0
  169. package/src/node-secret-rest-http.test.ts +190 -0
  170. package/src/node-serviceability.test.ts +86 -0
  171. package/src/node-serviceability.ts +124 -0
  172. package/src/node-session-control-http.test.ts +310 -0
  173. package/src/node-session-control.ts +258 -0
  174. package/src/node-skills-transport.test.ts +209 -0
  175. package/src/node-token-identity.ts +35 -0
  176. package/src/node-token-ownership.ts +51 -0
  177. package/src/node-token-privilege-http.test.ts +158 -0
  178. package/src/not-found-api-http.test.ts +67 -0
  179. package/src/observer-avatar-http.test.ts +442 -0
  180. package/src/observer-push.test.ts +252 -0
  181. package/src/opencode-catalog-report-http.test.ts +139 -0
  182. package/src/opencode-v2-catalog.test.ts +268 -0
  183. package/src/opencode-v2-catalog.ts +352 -0
  184. package/src/package-version-consistency.test.ts +25 -0
  185. package/src/parent-source-marker.test.ts +50 -0
  186. package/src/password-network-tokens.ts +25 -0
  187. package/src/peer-reply-atomic.test.ts +455 -0
  188. package/src/peer-reply-capability.test.ts +70 -0
  189. package/src/pg-worker.ts +87 -0
  190. package/src/project-dir-warn-clear-http.test.ts +132 -0
  191. package/src/project-viewer-can-http.test.ts +116 -0
  192. package/src/push.test.ts +20 -10
  193. package/src/push.ts +466 -13
  194. package/src/redact-tokens.test.ts +65 -0
  195. package/src/redact-tokens.ts +40 -0
  196. package/src/rename.ts +38 -10
  197. package/src/reply-target-derivation.test.ts +96 -0
  198. package/src/report-status-handover-capabilities-http.test.ts +124 -0
  199. package/src/report-status-host-schema.test.ts +235 -0
  200. package/src/report-status-resume-id-handover.test.ts +184 -0
  201. package/src/report-status-secret-keys.test.ts +140 -0
  202. package/src/require-explicit-test-db.ts +9 -0
  203. package/src/requirement-due-reminders-http.test.ts +620 -0
  204. package/src/requirement-due-reminders.ts +416 -0
  205. package/src/requirement-events-http.test.ts +268 -0
  206. package/src/requirement-events.test.ts +45 -0
  207. package/src/requirement-events.ts +144 -0
  208. package/src/requirement-notify.ts +165 -0
  209. package/src/requirement-participant-notify-http.test.ts +309 -0
  210. package/src/requirement-tag-ops-http.test.ts +425 -0
  211. package/src/requirement-tag-tree-http.test.ts +275 -0
  212. package/src/requirement-tag-tree.ts +127 -0
  213. package/src/requirement-tags.ts +102 -0
  214. package/src/requirements-abandoned-http.test.ts +236 -0
  215. package/src/requirements-comment-http.test.ts +167 -0
  216. package/src/requirements-completed-at-migration.test.ts +70 -0
  217. package/src/requirements-errors-mcp-http.test.ts +164 -0
  218. package/src/requirements-errors.ts +158 -0
  219. package/src/requirements-etag-http.test.ts +91 -0
  220. package/src/requirements-http.test.ts +709 -0
  221. package/src/requirements-last-event-http.test.ts +349 -0
  222. package/src/requirements-list-mcp-slim-http.test.ts +155 -0
  223. package/src/requirements-list-slim-http.test.ts +324 -0
  224. package/src/requirements-mcp.test.ts +163 -0
  225. package/src/requirements-migrate.ts +283 -0
  226. package/src/requirements-owner-strict-mcp-http.test.ts +145 -0
  227. package/src/requirements-people-http.test.ts +114 -0
  228. package/src/requirements-people-mcp-http.test.ts +231 -0
  229. package/src/requirements-people.ts +196 -0
  230. package/src/requirements-priority-lowest.test.ts +114 -0
  231. package/src/requirements-projects-parent-http.test.ts +123 -0
  232. package/src/requirements-search-http.test.ts +182 -0
  233. package/src/requirements-search.test.ts +32 -0
  234. package/src/requirements-search.ts +145 -0
  235. package/src/requirements-seq-http.test.ts +193 -0
  236. package/src/requirements-seq-migration.test.ts +63 -0
  237. package/src/requirements-start-date.test.ts +125 -0
  238. package/src/requirements-stats-http.test.ts +357 -0
  239. package/src/requirements-stats.ts +195 -0
  240. package/src/requirements-status-participants-http.test.ts +222 -0
  241. package/src/requirements-upgrade-e2e.test.ts +126 -0
  242. package/src/requirements-upgrade-migration.test.ts +98 -0
  243. package/src/requirements.ts +2027 -0
  244. package/src/resolve-port.test.ts +57 -0
  245. package/src/resolve-port.ts +44 -0
  246. package/src/response-charset.test.ts +130 -0
  247. package/src/rest-alias-network-fallback-http.test.ts +123 -0
  248. package/src/rest-alias-network-fallback.test.ts +60 -0
  249. package/src/rest-alias-network-fallback.ts +65 -0
  250. package/src/rest-explicit-columns-http.test.ts +266 -0
  251. package/src/rest-identity.test.ts +130 -0
  252. package/src/rest-identity.ts +141 -0
  253. package/src/rest-projections.ts +72 -0
  254. package/src/rest-read-network-real-chain.test.ts +97 -0
  255. package/src/rest-write-network-resolution.test.ts +133 -0
  256. package/src/restart-readiness-http.test.ts +121 -0
  257. package/src/restricted-files.ts +76 -0
  258. package/src/retention-first-sweep-quiet.test.ts +31 -0
  259. package/src/retention.test.ts +100 -40
  260. package/src/retention.ts +423 -104
  261. package/src/route-callers-http.test.ts +120 -0
  262. package/src/route-timing.test.ts +218 -0
  263. package/src/route-timing.ts +262 -0
  264. package/src/rules-file-duplicate-alias.test.ts +234 -0
  265. package/src/rules-file-session-target.test.ts +207 -0
  266. package/src/rules-file-transport.test.ts +237 -0
  267. package/src/runtime-label.test.ts +22 -0
  268. package/src/runtime-label.ts +21 -0
  269. package/src/runtime-readiness.ts +90 -0
  270. package/src/schedule-agent-mcp-http.test.ts +432 -0
  271. package/src/schedule-agent.ts +252 -0
  272. package/src/schedule-starved.test.ts +92 -0
  273. package/src/schedule-starved.ts +114 -0
  274. package/src/scheduled-backoff-http.test.ts +193 -0
  275. package/src/scheduled-backoff.ts +64 -0
  276. package/src/scheduled-doorbell-nodeless-session.test.ts +134 -0
  277. package/src/scheduled-failure-backoff-2622.test.ts +145 -0
  278. package/src/scheduled-failure-code.test.ts +73 -0
  279. package/src/scheduled-failure-code.ts +105 -0
  280. package/src/scheduled-failures-http.test.ts +279 -0
  281. package/src/scheduled-failures.ts +425 -0
  282. package/src/scheduled-noprogress-backoff-2622.test.ts +163 -0
  283. package/src/scheduled-offline-backoff-probe.test.ts +56 -0
  284. package/src/scheduled-offline.test.ts +131 -0
  285. package/src/scheduled-offline.ts +66 -0
  286. package/src/scheduled-outcome-guidance-http.test.ts +139 -0
  287. package/src/scheduled-outcome-guidance.ts +9 -0
  288. package/src/scheduled-reply-unread-http.test.ts +212 -0
  289. package/src/scheduled-requirement-wake-http.test.ts +279 -0
  290. package/src/scheduled-requirement-wake.ts +125 -0
  291. package/src/scheduled-run-terminal.test.ts +268 -0
  292. package/src/scheduled-skip-blocking-task.test.ts +120 -0
  293. package/src/scheduled-skip-path-backoff-2622.test.ts +98 -0
  294. package/src/scheduled-stuck-http.test.ts +312 -0
  295. package/src/scheduled-stuck-notice-cap.test.ts +80 -0
  296. package/src/scheduled-stuck.ts +219 -0
  297. package/src/scheduled-tasks-http.test.ts +679 -0
  298. package/src/scheduled-tasks.ts +959 -0
  299. package/src/scheduled-work-outcome-http.test.ts +154 -0
  300. package/src/scheduled-work-outcome.ts +50 -0
  301. package/src/scoped-secrets.ts +141 -0
  302. package/src/send-dedup-request-id.test.ts +229 -0
  303. package/src/send-reply-agent-warning.test.ts +202 -0
  304. package/src/send-reply-alias-optional.test.ts +131 -0
  305. package/src/send-reply-attachments.test.ts +458 -0
  306. package/src/send_dedup.test.ts +54 -0
  307. package/src/send_dedup.ts +52 -6
  308. package/src/serve-error.test.ts +38 -0
  309. package/src/serve-error.ts +27 -0
  310. package/src/server.ts +6220 -0
  311. package/src/session-task-on-dispatch.ts +14 -0
  312. package/src/session-token-ownership-http.test.ts +122 -0
  313. package/src/shared/codex-inventory.ts +41 -0
  314. package/src/shared/daemon-provider-login.ts +31 -0
  315. package/src/shared/daemon-provider-snapshot.ts +52 -0
  316. package/src/shared/external-schedule-contract.ts +60 -0
  317. package/src/shared/node-name.test.ts +62 -0
  318. package/src/shared/node-name.ts +161 -0
  319. package/src/shared/provider-application.ts +29 -0
  320. package/src/shared/provider-collection.ts +14 -0
  321. package/src/shared/provider-initialization.ts +8 -0
  322. package/src/shared/reserved-env-drift.test.ts +10 -0
  323. package/src/shared/scoped-secret-contract.ts +5 -0
  324. package/src/shared/task-content-limit-drift.test.ts +28 -0
  325. package/src/shared/task-content-limit.ts +25 -0
  326. package/src/side-thread-command-transport.test.ts +312 -0
  327. package/src/side-thread-command-transport.ts +318 -0
  328. package/src/side-thread-http-integration.test.ts +233 -0
  329. package/src/side-thread-http.ts +504 -0
  330. package/src/side-thread-production.test.ts +72 -0
  331. package/src/side-thread-production.ts +118 -0
  332. package/src/side-thread.test.ts +1067 -0
  333. package/src/side-thread.ts +2499 -0
  334. package/src/skillhub-http.test.ts +108 -0
  335. package/src/sqlite-close-checkpoint.test.ts +78 -0
  336. package/src/start-node.test.ts +264 -0
  337. package/src/status-alias-filter-http.test.ts +106 -0
  338. package/src/status-alias-resolver-http.test.ts +163 -0
  339. package/src/status-alias-resolver.ts +19 -0
  340. package/src/status-node-id-filter-http.test.ts +161 -0
  341. package/src/status-read-cache-http.test.ts +229 -0
  342. package/src/status-read-cache.ts +122 -0
  343. package/src/stop-delete-node.test.ts +567 -1
  344. package/src/task-access-http.test.ts +402 -0
  345. package/src/task-access.ts +420 -0
  346. package/src/task-activity.ts +60 -0
  347. package/src/task-auth-origin-http.test.ts +93 -0
  348. package/src/task-auth-origin.test.ts +24 -0
  349. package/src/task-auth-origin.ts +7 -0
  350. package/src/task-consumption.test.ts +490 -0
  351. package/src/task-diagnostic-http.test.ts +149 -0
  352. package/src/task-diagnostic.test.ts +115 -0
  353. package/src/task-diagnostic.ts +118 -0
  354. package/src/task-expiry-notice-http.test.ts +287 -0
  355. package/src/task-expiry-notice.ts +315 -0
  356. package/src/task-idempotency-mcp.test.ts +142 -0
  357. package/src/task-idempotency.test.ts +76 -0
  358. package/src/task-idempotency.ts +81 -0
  359. package/src/task-late-replies.ts +54 -0
  360. package/src/task-late-reply-http.test.ts +152 -0
  361. package/src/task-lifecycle-watcher-busy.test.ts +114 -0
  362. package/src/task-lifecycle-watcher.test.ts +204 -0
  363. package/src/task-lifecycle-watcher.ts +109 -0
  364. package/src/task-network-resolution-http.test.ts +140 -0
  365. package/src/task-offline-delivery-2668.test.ts +119 -0
  366. package/src/task-offline-delivery.ts +81 -0
  367. package/src/task-orphan-http.test.ts +287 -0
  368. package/src/task-orphan.ts +119 -0
  369. package/src/task-queue-ahead-http.test.ts +309 -0
  370. package/src/task-queue-ahead-scale.test.ts +236 -0
  371. package/src/task-queue-ahead.ts +186 -0
  372. package/src/task-rejection-log-http.test.ts +160 -0
  373. package/src/task-rejection-log.ts +49 -0
  374. package/src/task-sender-http.test.ts +143 -0
  375. package/src/task-stale-open-http.test.ts +290 -0
  376. package/src/task-stale-open.ts +103 -0
  377. package/src/tasks-pagination-http.test.ts +141 -0
  378. package/src/team-rules-status-http.test.ts +90 -0
  379. package/src/team-rules-status.test.ts +59 -0
  380. package/src/team-rules-status.ts +72 -0
  381. package/src/tool-audience-http.test.ts +230 -0
  382. package/src/tool-audience.ts +120 -0
  383. package/src/tools-list-json-schema.test.ts +94 -0
  384. package/src/tools.ts +4130 -391
  385. package/src/upload-early-reject-guard.test.ts +155 -0
  386. package/src/uploads-http.test.ts +97 -15
  387. package/src/uploads.ts +103 -6
  388. package/src/user-avatar-http.test.ts +74 -0
  389. package/src/user-avatar-image.ts +160 -0
  390. package/src/user-avatar-migration.test.ts +25 -0
  391. package/src/user-avatar-upload-http.test.ts +348 -0
  392. package/src/user-inbox-by-agent-http.test.ts +161 -0
  393. package/src/user-inbox-netid-notnull.test.ts +122 -0
  394. package/src/user-inbox-read-http.test.ts +223 -0
  395. package/src/user-inbox-schema.test.ts +54 -0
  396. package/src/version-stats.test.ts +66 -0
  397. package/src/version-stats.ts +109 -0
@@ -0,0 +1,258 @@
1
+ // Node display attributes — team / tags / display_name (Vincent 目标第 3 条).
2
+ //
3
+ // These are HUB-SIDE DISPLAY attributes. Following the `avatar_url` (#462)
4
+ // precedent they are deliberately NOT part of the RFC-024 config-apply
5
+ // pipeline: agent-node has nothing to consume, so pushing them through
6
+ // config revision/ack would ring a doorbell for a field the node does not
7
+ // understand and could wedge the config revision.
8
+ //
9
+ // They DO need concurrency protection (two dashboards editing the same
10
+ // node), which `avatar_url` lacks. Hence a dedicated `attrs_revision` CAS
11
+ // that is independent of `config_revision` — editing a tag must never bump
12
+ // the node's *config* revision.
13
+ //
14
+ // Every test drives the REAL HTTP endpoint against a booted server, not a
15
+ // helper: the contract under test is the wire shape + status codes.
16
+ //
17
+ // NOTE (test isolation): this file boots its own Bun.serve, same pattern as
18
+ // uploads-http.test.ts / api-host-supervisors-fallback.test.ts. Those files
19
+ // are per-file runs by design (single-process module-singleton conflict,
20
+ // tracked in #434) — run this file on its own.
21
+
22
+ import { afterAll, beforeAll, describe, expect, test } from "bun:test";
23
+ import { mkdtempSync } from "fs";
24
+ import { tmpdir } from "os";
25
+ import { join } from "path";
26
+
27
+ const tmpDb = join(mkdtempSync(join(tmpdir(), "anet-attrs-")), "commhub.db");
28
+ process.env.COMMHUB_DB ||= tmpDb;
29
+ const PORT = 23000 + Math.floor(Math.random() * 1500);
30
+ process.env.PORT = String(PORT);
31
+ process.env.HOST = "127.0.0.1";
32
+
33
+ const { db } = await import("./db.js");
34
+ const { issueUserToken } = await import("./auth.js");
35
+ const { bootServer } = await import("./server.js");
36
+
37
+ const BASE = `http://127.0.0.1:${PORT}`;
38
+ const NET = "net_attrs";
39
+ const USER = "u_attrs";
40
+ /** A node row seeded the way a PRE-MIGRATION row looks: none of the new
41
+ * columns are written, so they are NULL / default at read time. */
42
+ const LEGACY_NODE = "node_attrs_legacy";
43
+ const LEGACY_ALIAS = "attrs-legacy-node";
44
+
45
+ let token = "";
46
+ let server: { stop: (force?: boolean) => void } | null = null;
47
+
48
+ // 30s 而不是 bun 默认的 5s:这个 hook 跑 register()(KDF)+bootServer(),
49
+ // 本机空载基线 ~620ms,而 2026-08-17 与 2026-08-31 两次 CI 上它被 5s 上限打死
50
+ // (0 pass / 1 fail / Ran 1 test —— 见 #928、#1627)。5247ms 是**被截断的下界**,
51
+ // 不是测量值,所以余量按基线的 ~48x 取,而不是按那个数取。
52
+ beforeAll(async () => {
53
+ db.run(`INSERT INTO users (user_id, username, password_hash, role) VALUES (?1, 'attrs-user', 'x', 'user')`, [USER]);
54
+ db.run(`INSERT INTO networks (network_id, network_name, owner_id) VALUES (?1, 'attrs-net', ?2)`, [NET, USER]);
55
+ db.run(`INSERT INTO network_members (network_id, user_id, role) VALUES (?1, ?2, 'owner')`, [NET, USER]);
56
+ // Legacy row: only the columns that existed before this change.
57
+ db.run(
58
+ `INSERT INTO nodes (node_id, node_name, alias, runtime, model, network_id)
59
+ VALUES (?1, 'attrs-legacy', ?2, 'claude-agent-sdk', 'claude-sonnet-4-6', ?3)`,
60
+ [LEGACY_NODE, LEGACY_ALIAS, NET],
61
+ );
62
+ token = issueUserToken(USER, "attrs-test").token;
63
+ server = bootServer({ port: PORT, hostname: "127.0.0.1" }) as never;
64
+ await new Promise((r) => setTimeout(r, 120));
65
+ }, 30_000);
66
+
67
+ afterAll(() => {
68
+ try { server?.stop(true); } catch { /* already down */ }
69
+ });
70
+
71
+ async function putAttrs(ref: string, body: unknown) {
72
+ const res = await fetch(`${BASE}/api/nodes/${encodeURIComponent(ref)}/attrs?network_id=${NET}`, {
73
+ method: "PUT",
74
+ headers: { "Content-Type": "application/json", Authorization: `Bearer ${token}` },
75
+ body: JSON.stringify(body),
76
+ });
77
+ return { status: res.status, json: (await res.json()) as Record<string, unknown> };
78
+ }
79
+
80
+ async function listNodes() {
81
+ const res = await fetch(`${BASE}/api/nodes?network_id=${NET}`, {
82
+ headers: { Authorization: `Bearer ${token}` },
83
+ });
84
+ const j = (await res.json()) as { nodes?: Array<Record<string, unknown>> };
85
+ return j.nodes ?? [];
86
+ }
87
+
88
+ describe("node display attrs — backward compatibility with existing rows", () => {
89
+ test("a pre-migration node row still lists fine; new fields read as empty, not missing/throwing", async () => {
90
+ const rows = await listNodes();
91
+ const row = rows.find((r) => r.node_id === LEGACY_NODE);
92
+ expect(row).toBeDefined();
93
+ // Must not blow up and must not omit the keys — the dashboard reads
94
+ // them unconditionally.
95
+ expect(row!).toHaveProperty("display_name");
96
+ expect(row!).toHaveProperty("team");
97
+ expect(row!).toHaveProperty("tags");
98
+ expect(row!.display_name ?? null).toBeNull();
99
+ expect(row!.team ?? null).toBeNull();
100
+ // tags normalises to an empty array rather than null/undefined so the
101
+ // dashboard can `.map()` without a guard.
102
+ expect(row!.tags).toEqual([]);
103
+ expect(row!.attrs_revision).toBe(0);
104
+ });
105
+ });
106
+
107
+ describe("node display attrs — write then read back", () => {
108
+ test("PUT sets display_name/team/tags, bumps attrs_revision, and GET /api/nodes reflects it", async () => {
109
+ const w = await putAttrs(LEGACY_ALIAS, {
110
+ base_attrs_revision: 0,
111
+ display_name: "研发一号机",
112
+ team: "platform",
113
+ tags: ["prod", "gpu"],
114
+ });
115
+ expect(w.status).toBe(200);
116
+ expect(w.json.ok).toBe(true);
117
+ expect(w.json.attrs_revision).toBe(1);
118
+
119
+ const row = (await listNodes()).find((r) => r.node_id === LEGACY_NODE)!;
120
+ expect(row.display_name).toBe("研发一号机");
121
+ expect(row.team).toBe("platform");
122
+ expect(row.tags).toEqual(["prod", "gpu"]);
123
+ expect(row.attrs_revision).toBe(1);
124
+ });
125
+
126
+ test("editing attrs does NOT touch config_revision (display vs config are separate revisions)", async () => {
127
+ const before = db.get<{ config_revision: number }>(
128
+ "SELECT config_revision FROM nodes WHERE node_id = ?1", LEGACY_NODE)!.config_revision ?? 0;
129
+ const w = await putAttrs(LEGACY_ALIAS, { base_attrs_revision: 1, team: "infra" });
130
+ expect(w.status).toBe(200);
131
+ const after = db.get<{ config_revision: number }>(
132
+ "SELECT config_revision FROM nodes WHERE node_id = ?1", LEGACY_NODE)!.config_revision ?? 0;
133
+ expect(after).toBe(before);
134
+ });
135
+
136
+ test("partial patch leaves untouched fields alone", async () => {
137
+ const row = (await listNodes()).find((r) => r.node_id === LEGACY_NODE)!;
138
+ // team was just changed to 'infra'; display_name/tags must survive.
139
+ expect(row.team).toBe("infra");
140
+ expect(row.display_name).toBe("研发一号机");
141
+ expect(row.tags).toEqual(["prod", "gpu"]);
142
+ });
143
+ });
144
+
145
+ describe("node display attrs — CAS concurrency guard", () => {
146
+ test("stale base_attrs_revision → 409 with the current revision, and NO write happens", async () => {
147
+ const before = (await listNodes()).find((r) => r.node_id === LEGACY_NODE)!;
148
+ const stale = await putAttrs(LEGACY_ALIAS, {
149
+ base_attrs_revision: 0, // deliberately stale
150
+ team: "should-not-land",
151
+ });
152
+ expect(stale.status).toBe(409);
153
+ expect(stale.json.ok).toBe(false);
154
+ expect(stale.json.error).toBe("attrs_revision_conflict");
155
+ expect(stale.json.current_attrs_revision).toBe(before.attrs_revision);
156
+
157
+ const after = (await listNodes()).find((r) => r.node_id === LEGACY_NODE)!;
158
+ expect(after.team).toBe(before.team); // unchanged
159
+ expect(after.attrs_revision).toBe(before.attrs_revision);
160
+ });
161
+ });
162
+
163
+ describe("node display attrs — untrusted input is narrowed at the boundary", () => {
164
+ test("tags: non-strings dropped, blanks dropped, duplicates folded, count + length capped", async () => {
165
+ const cur = (await listNodes()).find((r) => r.node_id === LEGACY_NODE)!.attrs_revision as number;
166
+ const w = await putAttrs(LEGACY_ALIAS, {
167
+ base_attrs_revision: cur,
168
+ tags: [
169
+ "keep",
170
+ "keep", // duplicate
171
+ " spaced ", // trimmed
172
+ "",
173
+ " ",
174
+ 42,
175
+ null,
176
+ { evil: true },
177
+ ["nested"],
178
+ "x".repeat(200), // over-long → dropped or truncated, never stored raw
179
+ ],
180
+ });
181
+ expect(w.status).toBe(200);
182
+ const tags = (await listNodes()).find((r) => r.node_id === LEGACY_NODE)!.tags as string[];
183
+ expect(Array.isArray(tags)).toBe(true);
184
+ expect(tags).toContain("keep");
185
+ expect(tags).toContain("spaced");
186
+ // one "keep", no junk, nothing absurdly long
187
+ expect(tags.filter((t) => t === "keep")).toHaveLength(1);
188
+ expect(tags.every((t) => typeof t === "string" && t.length > 0 && t.length <= 64)).toBe(true);
189
+ expect(tags.some((t) => t.includes("evil") || t.includes("nested"))).toBe(false);
190
+ });
191
+
192
+ test("display_name/team: non-string values are rejected, not coerced", async () => {
193
+ const cur = (await listNodes()).find((r) => r.node_id === LEGACY_NODE)!.attrs_revision as number;
194
+ const bad = await putAttrs(LEGACY_ALIAS, { base_attrs_revision: cur, team: { not: "a string" } });
195
+ expect(bad.status).toBe(400);
196
+ expect(bad.json.ok).toBe(false);
197
+ });
198
+ });
199
+
200
+ describe("node display attrs — auth + scope", () => {
201
+ test("no token → 401, and the row is untouched", async () => {
202
+ const before = (await listNodes()).find((r) => r.node_id === LEGACY_NODE)!;
203
+ const res = await fetch(`${BASE}/api/nodes/${LEGACY_ALIAS}/attrs?network_id=${NET}`, {
204
+ method: "PUT",
205
+ headers: { "Content-Type": "application/json" },
206
+ body: JSON.stringify({ base_attrs_revision: before.attrs_revision, team: "hijack" }),
207
+ });
208
+ expect(res.status).toBe(401);
209
+ const after = (await listNodes()).find((r) => r.node_id === LEGACY_NODE)!;
210
+ expect(after.team).toBe(before.team);
211
+ });
212
+
213
+ test("unknown node ref → 404", async () => {
214
+ const r = await putAttrs("no-such-node-ref", { base_attrs_revision: 0, team: "x" });
215
+ expect(r.status).toBe(404);
216
+ });
217
+ });
218
+
219
+ // #2293(admin 2026-10-25)—— 走**真正**的 HTTP,不镜像 handler:
220
+ // 客户端「Runtime · V2」「OpenCode Server」和「模型可选列表」要的三样东西
221
+ // (代际 / 模式 / loopback 端点)与「这台机器上报的模型 id 清单」都在 /api/nodes 上,
222
+ // 而整个 config_snapshot 仍然不外泄(终端 #312 的约定)。
223
+ describe("#2293 opencode bits on GET /api/nodes (real HTTP)", () => {
224
+ const OC_NODE = "node_attrs_opencode";
225
+ const OC_ALIAS = "attrs-opencode-node";
226
+
227
+ test("generation / mode / server / catalog are projected; config_snapshot is not", async () => {
228
+ db.run(`DELETE FROM nodes WHERE node_id = ?1`, [OC_NODE]);
229
+ db.run(
230
+ `INSERT INTO nodes (node_id, node_name, alias, runtime, model, network_id, config_snapshot)
231
+ VALUES (?1, 'attrs-oc', ?2, 'opencode-sdk', 'deepseek/deepseek-flash', ?3, ?4)`,
232
+ [OC_NODE, OC_ALIAS, NET, JSON.stringify({
233
+ model: "deepseek/deepseek-flash",
234
+ flags: { opencodeGeneration: "v2", opencodeMode: "copresence", daemonSideSecret: "must-not-leak" },
235
+ opencode_server: "http://127.0.0.1:4096",
236
+ opencode_catalog: ["deepseek/deepseek-flash", "opencode/mimo-v2.6-flash-free"],
237
+ })],
238
+ );
239
+ const row = (await listNodes()).find((r) => r.node_id === OC_NODE)!;
240
+ expect(row).toBeDefined();
241
+ expect(row.opencode_generation).toBe("v2");
242
+ expect(row.opencode_mode).toBe("copresence");
243
+ expect(row.opencode_server).toBe("http://127.0.0.1:4096");
244
+ expect(row.opencode_catalog).toEqual(["deepseek/deepseek-flash", "opencode/mimo-v2.6-flash-free"]);
245
+ // 整个快照仍然不出现,且 flags 里的其它键不外泄。
246
+ expect(row).not.toHaveProperty("config_snapshot");
247
+ expect(JSON.stringify(row)).not.toContain("must-not-leak");
248
+ db.run(`DELETE FROM nodes WHERE node_id = ?1`, [OC_NODE]);
249
+ });
250
+
251
+ test("a node that never reported them reads as null / [] (old node, no invented values)", async () => {
252
+ const row = (await listNodes()).find((r) => r.node_id === LEGACY_NODE)!;
253
+ expect(row.opencode_generation ?? null).toBeNull();
254
+ expect(row.opencode_mode ?? null).toBeNull();
255
+ expect(row.opencode_server ?? null).toBeNull();
256
+ expect(row.opencode_catalog ?? null).toBeNull();
257
+ });
258
+ });