pi-harness-runtime 1.1.439 → 1.1.441

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 (359) hide show
  1. package/harness/e2e/auto-test-loop.ts +8 -2
  2. package/harness/e2e/browser-scrapers/base-browser-scraper.ts +2 -0
  3. package/harness/e2e/browser-scrapers/chrome-profile-manager.ts +2 -0
  4. package/harness/e2e/browser-scrapers/codex-browser-scraper.ts +2 -0
  5. package/harness/e2e/tools-detector.ts +2 -0
  6. package/harness/index.ts +2 -1
  7. package/harness/key-loader.ts +2 -0
  8. package/harness/langchain/checkpointer.ts +2 -0
  9. package/harness/langchain/cron-cli.ts +2 -0
  10. package/harness/langchain/graph.ts +2 -0
  11. package/harness/master-planner.ts +1 -1
  12. package/harness/notification-center.ts +2 -0
  13. package/harness/output-limit-handler.ts +1 -1
  14. package/harness/project-detector/detector.ts +2 -4
  15. package/harness/secret-provider.ts +2 -0
  16. package/harness/task-graph.ts +460 -113
  17. package/index.ts +16 -7
  18. package/package.json +7 -1
  19. package/packages/a2a-adapter/package.json +1 -1
  20. package/packages/agent-policy/dist/extension.d.ts.map +1 -1
  21. package/packages/agent-policy/dist/extension.js +2 -0
  22. package/packages/agent-policy/dist/extension.js.map +1 -1
  23. package/packages/agent-policy/package.json +1 -1
  24. package/packages/agent-policy/src/extension.ts +2 -0
  25. package/packages/architecture-generator/package.json +1 -1
  26. package/packages/auth/dist/minimax-browser-auth.d.ts.map +1 -1
  27. package/packages/auth/dist/minimax-browser-auth.js +23 -1
  28. package/packages/auth/dist/minimax-browser-auth.js.map +1 -1
  29. package/packages/auth/package.json +1 -1
  30. package/packages/auth/src/minimax-browser-auth.ts +30 -5
  31. package/packages/autonomous-refactor/package.json +1 -1
  32. package/packages/autonomous-runtime/dist/inbox.d.ts.map +1 -1
  33. package/packages/autonomous-runtime/dist/inbox.js +2 -0
  34. package/packages/autonomous-runtime/dist/inbox.js.map +1 -1
  35. package/packages/autonomous-runtime/package.json +1 -1
  36. package/packages/autonomous-runtime/src/inbox.ts +2 -0
  37. package/packages/cache-strategy/package.json +1 -1
  38. package/packages/capability-registry/package.json +1 -1
  39. package/packages/checkpoint/package.json +1 -1
  40. package/packages/cli-plugin-sdk/package.json +1 -1
  41. package/packages/clipboard/dist/src/clipboard.d.ts.map +1 -1
  42. package/packages/clipboard/dist/src/clipboard.js +2 -0
  43. package/packages/clipboard/dist/src/clipboard.js.map +1 -1
  44. package/packages/clipboard/dist/src/copy-sync.d.ts.map +1 -1
  45. package/packages/clipboard/dist/src/copy-sync.js +2 -0
  46. package/packages/clipboard/dist/src/copy-sync.js.map +1 -1
  47. package/packages/clipboard/dist/src/gist-relay.d.ts.map +1 -1
  48. package/packages/clipboard/dist/src/gist-relay.js +2 -0
  49. package/packages/clipboard/dist/src/gist-relay.js.map +1 -1
  50. package/packages/clipboard/package.json +1 -1
  51. package/packages/clipboard/src/clipboard.ts +2 -0
  52. package/packages/clipboard/src/copy-sync.ts +2 -0
  53. package/packages/clipboard/src/gist-relay.ts +2 -0
  54. package/packages/clipboard-plugin/dist/types.d.ts +9 -2
  55. package/packages/clipboard-plugin/dist/types.d.ts.map +1 -1
  56. package/packages/clipboard-plugin/package.json +1 -1
  57. package/packages/clipboard-plugin/src/types.ts +9 -2
  58. package/packages/code-generation/package.json +1 -1
  59. package/packages/code-review/package.json +1 -1
  60. package/packages/codex-adapter/package.json +1 -1
  61. package/packages/codex-watcher/package.json +1 -1
  62. package/packages/config-capture/package.json +1 -1
  63. package/packages/connection-runtime/package.json +1 -1
  64. package/packages/context-compiler/package.json +1 -1
  65. package/packages/context-discovery/package.json +1 -1
  66. package/packages/context-manager/package.json +1 -1
  67. package/packages/contracts/dist/delegation-store.js +1 -4
  68. package/packages/contracts/dist/workspace-env.js +28 -1
  69. package/packages/contracts/package.json +1 -1
  70. package/packages/contracts/src/delegation-store.ts +9 -4
  71. package/packages/contracts/src/workspace-env.ts +29 -4
  72. package/packages/cookie-sanitizer/package.json +1 -1
  73. package/packages/cost-optimizer/package.json +1 -1
  74. package/packages/dependency-analyzer/package.json +1 -1
  75. package/packages/django-plugin/package.json +1 -1
  76. package/packages/doc-generator/package.json +1 -1
  77. package/packages/durable-review/package.json +1 -1
  78. package/packages/e2e-tester/package.json +1 -1
  79. package/packages/evaluation-engine/package.json +1 -1
  80. package/packages/evaluation-runner/package.json +1 -1
  81. package/packages/event-bus/package.json +1 -1
  82. package/packages/event-sink/package.json +1 -1
  83. package/packages/event-store/dist/src/store.d.ts.map +1 -1
  84. package/packages/event-store/dist/src/store.js +2 -0
  85. package/packages/event-store/dist/src/store.js.map +1 -1
  86. package/packages/event-store/package.json +1 -1
  87. package/packages/event-store/src/store.ts +3 -0
  88. package/packages/experience-replay/package.json +1 -1
  89. package/packages/feedback-collector/package.json +1 -1
  90. package/packages/file-copy-helper/package.json +1 -1
  91. package/packages/framework-detector/package.json +1 -1
  92. package/packages/framework-plugin-sdk/package.json +1 -1
  93. package/packages/frappe-plugin/package.json +1 -1
  94. package/packages/generic-web-plugin/dist/analyzer.d.ts.map +1 -1
  95. package/packages/generic-web-plugin/dist/analyzer.js +2 -0
  96. package/packages/generic-web-plugin/dist/analyzer.js.map +1 -1
  97. package/packages/generic-web-plugin/package.json +1 -1
  98. package/packages/generic-web-plugin/src/analyzer.ts +3 -0
  99. package/packages/health-monitor/package.json +1 -1
  100. package/packages/intent-analyzer/package.json +1 -1
  101. package/packages/jev-judge/package.json +1 -1
  102. package/packages/knowledge-graph/package.json +1 -1
  103. package/packages/knowledge-retrieval/dist/mcp-client.d.ts.map +1 -1
  104. package/packages/knowledge-retrieval/dist/mcp-client.js +0 -1
  105. package/packages/knowledge-retrieval/dist/mcp-client.js.map +1 -1
  106. package/packages/knowledge-retrieval/package.json +1 -4
  107. package/packages/knowledge-retrieval/src/mcp-client.ts +0 -1
  108. package/packages/laravel-plugin/package.json +1 -1
  109. package/packages/learning-engine/package.json +1 -1
  110. package/packages/logging/package.json +1 -1
  111. package/packages/mcp-adapter/dist/server.d.ts.map +1 -1
  112. package/packages/mcp-adapter/dist/server.js +2 -0
  113. package/packages/mcp-adapter/dist/server.js.map +1 -1
  114. package/packages/mcp-adapter/package.json +1 -1
  115. package/packages/mcp-adapter/src/server.ts +3 -0
  116. package/packages/memory-engine/package.json +1 -1
  117. package/packages/milestone-manager/package.json +1 -1
  118. package/packages/model-registry/package.json +1 -1
  119. package/packages/nextjs-plugin/package.json +1 -1
  120. package/packages/notification/package.json +1 -1
  121. package/packages/observability/package.json +1 -1
  122. package/packages/okf-indexer/package.json +1 -1
  123. package/packages/paperclip-integration/dist/index.d.ts.map +1 -1
  124. package/packages/paperclip-integration/dist/index.js +2 -0
  125. package/packages/paperclip-integration/dist/index.js.map +1 -1
  126. package/packages/paperclip-integration/package.json +1 -1
  127. package/packages/paperclip-integration/src/index.ts +2 -0
  128. package/packages/performance-optimizer/package.json +1 -1
  129. package/packages/permission-mode/package.json +1 -1
  130. package/packages/privilege-broker/dist/audit.d.ts.map +1 -1
  131. package/packages/privilege-broker/dist/audit.js +2 -0
  132. package/packages/privilege-broker/dist/audit.js.map +1 -1
  133. package/packages/privilege-broker/package.json +1 -1
  134. package/packages/privilege-broker/src/audit.ts +2 -0
  135. package/packages/project-analyzer/package.json +1 -1
  136. package/packages/project-bootstrap/package.json +1 -1
  137. package/packages/projection-engine/package.json +1 -1
  138. package/packages/prompt-compiler/dist/compiler.d.ts.map +1 -1
  139. package/packages/prompt-compiler/dist/compiler.js +2 -0
  140. package/packages/prompt-compiler/dist/compiler.js.map +1 -1
  141. package/packages/prompt-compiler/package.json +1 -1
  142. package/packages/prompt-compiler/src/compiler.ts +2 -0
  143. package/packages/prompt-versioning/package.json +1 -1
  144. package/packages/provider-adapter-sdk/package.json +1 -1
  145. package/packages/provider-router/package.json +1 -1
  146. package/packages/provider-selector/package.json +1 -1
  147. package/packages/providers/package.json +1 -1
  148. package/packages/qdrant-skills/package.json +1 -1
  149. package/packages/quota-manager/package.json +1 -1
  150. package/packages/rate-limiter/package.json +1 -1
  151. package/packages/react-vite-plugin/package.json +1 -1
  152. package/packages/relay/package.json +1 -1
  153. package/packages/release-manager/package.json +1 -1
  154. package/packages/requirement-compiler/package.json +1 -1
  155. package/packages/runtime/package.json +1 -1
  156. package/packages/scheduler/package.json +1 -1
  157. package/packages/scheduler-adapter/package.json +1 -1
  158. package/packages/session/package.json +1 -1
  159. package/packages/session-api/package.json +1 -1
  160. package/packages/session-export/package.json +1 -1
  161. package/packages/shared-context/package.json +1 -1
  162. package/packages/skill-mcp-client/dist/client.d.ts.map +1 -1
  163. package/packages/skill-mcp-client/dist/client.js +0 -1
  164. package/packages/skill-mcp-client/dist/client.js.map +1 -1
  165. package/packages/skill-mcp-client/package.json +1 -4
  166. package/packages/skill-mcp-client/src/client.ts +0 -1
  167. package/packages/skill-registry/package.json +1 -1
  168. package/packages/skills/dist/parser.d.ts.map +1 -1
  169. package/packages/skills/dist/parser.js +2 -0
  170. package/packages/skills/dist/parser.js.map +1 -1
  171. package/packages/skills/dist/skill-versioning.d.ts.map +1 -1
  172. package/packages/skills/dist/skill-versioning.js +2 -0
  173. package/packages/skills/dist/skill-versioning.js.map +1 -1
  174. package/packages/skills/package.json +1 -1
  175. package/packages/skills/src/parser.ts +3 -0
  176. package/packages/skills/src/skill-versioning.ts +2 -0
  177. package/packages/sprint-planner/package.json +1 -1
  178. package/packages/subscription-engine/package.json +1 -1
  179. package/packages/task-compiler/package.json +1 -1
  180. package/packages/tencentdb-memory/package.json +1 -1
  181. package/packages/tencentdb-sync/package.json +1 -1
  182. package/packages/test-data-generator/package.json +1 -1
  183. package/packages/test-generator/package.json +1 -1
  184. package/packages/todo-bd-sync/package.json +1 -1
  185. package/packages/token-estimation/package.json +1 -1
  186. package/packages/token-optimizer/package.json +1 -1
  187. package/packages/tooling-preference/package.json +1 -1
  188. package/packages/trajectory/package.json +1 -1
  189. package/packages/tui/package.json +1 -1
  190. package/packages/two-phase-review/package.json +1 -1
  191. package/packages/types/package.json +1 -1
  192. package/packages/voice-api/package.json +1 -1
  193. package/packages/webmcp-tester/dist/index.js +0 -2
  194. package/packages/webmcp-tester/package.json +1 -1
  195. package/packages/webmcp-tester/src/index.ts +0 -3
  196. package/packages/wiki/package.json +1 -1
  197. package/packages/workflow-events/package.json +1 -1
  198. package/packages/workspace-scanner/package.json +1 -1
  199. package/packages/worktree/package.json +1 -1
  200. package/packages/write-review/dist/trigger.d.ts.map +1 -1
  201. package/packages/write-review/dist/trigger.js +1 -2
  202. package/packages/write-review/dist/trigger.js.map +1 -1
  203. package/packages/write-review/package.json +1 -1
  204. package/packages/write-review/src/trigger.ts +1 -2
  205. package/scripts/lib/runtime-imports.ts +189 -3
  206. package/scripts/release-all.ts +5 -3
  207. package/scripts/telegram-webhook-server.ts +2 -0
  208. package/scripts/typecheck-packages.mjs +7 -4
  209. package/scripts/verify-package-contents.ts +161 -2
  210. package/harness/e2e/tools-detector.test.ts +0 -156
  211. package/harness/glm-quota-countdown.test.ts +0 -323
  212. package/harness/langchain/agents.test.ts +0 -39
  213. package/harness/langchain/checkpointer.test.ts +0 -243
  214. package/harness/langchain/daemon.test.ts +0 -459
  215. package/harness/langchain/model-router.test.ts +0 -191
  216. package/harness/langchain/ping-pong-middleware.test.ts +0 -69
  217. package/harness/langchain/scoreboard.test.ts +0 -245
  218. package/harness/langchain/status-line.test.ts +0 -106
  219. package/harness/langchain/surge.test.ts +0 -467
  220. package/harness/langchain/widget.test.ts +0 -251
  221. package/harness/skill-sync.test.ts +0 -57
  222. package/harness/ssh-detach-interceptor.test.ts +0 -263
  223. package/harness/ssh-hang-recovery.test.ts +0 -86
  224. package/packages/a2a-adapter/test/a2a.test.ts +0 -151
  225. package/packages/agent-policy/test/interlock.test.ts +0 -101
  226. package/packages/agent-policy/test/policy-retention.test.ts +0 -380
  227. package/packages/agent-policy/test/policy.test.ts +0 -387
  228. package/packages/auth/test/auth.test.ts +0 -238
  229. package/packages/autonomous-refactor/test/refactor.test.ts +0 -202
  230. package/packages/autonomous-runtime/test/types.test.ts +0 -95
  231. package/packages/cache-strategy/test/cache.test.ts +0 -137
  232. package/packages/capability-registry/test/registry.test.ts +0 -204
  233. package/packages/checkpoint/test/engine.test.ts +0 -265
  234. package/packages/cli-plugin-sdk/test/cli.test.ts +0 -45
  235. package/packages/code-generation/test/generator.test.ts +0 -238
  236. package/packages/code-review/test/engine.test.ts +0 -302
  237. package/packages/codex-adapter/test/provider.test.ts +0 -142
  238. package/packages/codex-watcher/test/watch.test.ts +0 -453
  239. package/packages/context-compiler/test/context-compiler.test.ts +0 -746
  240. package/packages/context-manager/test/context.test.ts +0 -198
  241. package/packages/contracts/test/delegation.test.ts +0 -350
  242. package/packages/contracts/test/workspace-env.test.ts +0 -802
  243. package/packages/cookie-sanitizer/test/infer.test.ts +0 -110
  244. package/packages/cookie-sanitizer/test/normalize.test.ts +0 -113
  245. package/packages/cookie-sanitizer/test/parse.test.ts +0 -204
  246. package/packages/cookie-sanitizer/test/sync.test.ts +0 -237
  247. package/packages/cookie-sanitizer/test/watcher.test.ts +0 -27
  248. package/packages/cost-optimizer/test/cost-optimizer.test.ts +0 -438
  249. package/packages/dependency-analyzer/test/analyzer.test.ts +0 -49
  250. package/packages/django-plugin/test/analyzer.test.ts +0 -195
  251. package/packages/doc-generator/test/docs.test.ts +0 -168
  252. package/packages/durable-review/test/acceptance.test.ts +0 -357
  253. package/packages/durable-review/test/smoke.test.ts +0 -107
  254. package/packages/evaluation-engine/test/engine.test.ts +0 -277
  255. package/packages/evaluation-runner/test/runner.test.ts +0 -168
  256. package/packages/event-bus/test/bus.test.ts +0 -100
  257. package/packages/event-store/test/store.test.ts +0 -115
  258. package/packages/experience-replay/test/replay.test.ts +0 -267
  259. package/packages/feedback-collector/test/collector.test.ts +0 -142
  260. package/packages/framework-detector/test/detector.test.ts +0 -75
  261. package/packages/framework-plugin-sdk/test/manager.test.ts +0 -320
  262. package/packages/frappe-plugin/test/analyzer.test.ts +0 -250
  263. package/packages/generic-web-plugin/test/analyzer.test.ts +0 -134
  264. package/packages/health-monitor/test/health.test.ts +0 -231
  265. package/packages/intent-analyzer/test/analyzer.test.ts +0 -72
  266. package/packages/intent-analyzer/test/ping-pong.test.ts +0 -96
  267. package/packages/jev-judge/tests/auto-continue-context.test.ts +0 -280
  268. package/packages/jev-judge/tests/continuation-controller.test.ts +0 -1396
  269. package/packages/jev-judge/tests/jev-provider-chain.test.ts +0 -536
  270. package/packages/jev-judge/tests/outcome-application.test.ts +0 -132
  271. package/packages/jev-judge/tests/question-risk.test.ts +0 -129
  272. package/packages/jev-judge/tests/typesafe-provider.test.ts +0 -640
  273. package/packages/jev-judge/tests/validation-ledger.test.ts +0 -181
  274. package/packages/jev-judge/tests/validation-plan.test.ts +0 -170
  275. package/packages/jev-judge/tests/validation-tie-breaker.test.ts +0 -88
  276. package/packages/laravel-plugin/test/analyzer.test.ts +0 -220
  277. package/packages/learning-engine/test/engine.test.ts +0 -331
  278. package/packages/logging/test/buffer.test.ts +0 -44
  279. package/packages/logging/test/classification.test.ts +0 -137
  280. package/packages/logging/test/config.test.ts +0 -97
  281. package/packages/logging/test/fanout.test.ts +0 -186
  282. package/packages/logging/test/identity-transport.test.ts +0 -197
  283. package/packages/logging/test/incidents.test.ts +0 -404
  284. package/packages/logging/test/ingest-schema.test.ts +0 -184
  285. package/packages/logging/test/integration.test.ts +0 -140
  286. package/packages/logging/test/log-http.test.ts +0 -246
  287. package/packages/logging/test/redact.test.ts +0 -109
  288. package/packages/logging/test/sampler.test.ts +0 -57
  289. package/packages/logging/test/server.test.ts +0 -444
  290. package/packages/logging/test/shipper.test.ts +0 -152
  291. package/packages/logging/test/spool.test.ts +0 -96
  292. package/packages/mcp-adapter/test/server.test.ts +0 -91
  293. package/packages/memory-engine/test/engine.test.ts +0 -456
  294. package/packages/model-registry/test/registry.test.ts +0 -342
  295. package/packages/nextjs-plugin/test/analyzer.test.ts +0 -149
  296. package/packages/notification/test/approval-payload.test.ts +0 -269
  297. package/packages/notification/test/detail-format.test.ts +0 -106
  298. package/packages/notification/test/notification.test.ts +0 -375
  299. package/packages/notification/test/pending-question-lifecycle.test.ts +0 -195
  300. package/packages/notification/test/pending-question.test.ts +0 -331
  301. package/packages/notification/test/tooling-proposal-payload.test.ts +0 -212
  302. package/packages/observability/test/observability.test.ts +0 -1350
  303. package/packages/performance-optimizer/test/optimizer.test.ts +0 -267
  304. package/packages/project-analyzer/test/index.test.ts +0 -1719
  305. package/packages/prompt-compiler/test/prompt-compiler.test.ts +0 -813
  306. package/packages/prompt-versioning/test/versioning.test.ts +0 -112
  307. package/packages/provider-adapter-sdk/test/sdk.test.ts +0 -220
  308. package/packages/provider-router/test/provider-router.test.ts +0 -405
  309. package/packages/provider-selector/test/selector.test.ts +0 -192
  310. package/packages/providers/test/providers.test.ts +0 -225
  311. package/packages/qdrant-skills/test/collection-info.test.ts +0 -165
  312. package/packages/qdrant-skills/test/embedder-batch.test.ts +0 -184
  313. package/packages/qdrant-skills/test/embedder.test.ts +0 -97
  314. package/packages/quota-manager/test/quota.test.ts +0 -432
  315. package/packages/rate-limiter/test/limiter.test.ts +0 -128
  316. package/packages/react-vite-plugin/test/analyzer.test.ts +0 -139
  317. package/packages/relay/test/client.test.ts +0 -446
  318. package/packages/relay/test/relay-e2e.test.ts +0 -299
  319. package/packages/relay/test/relay-endpoint.test.ts +0 -278
  320. package/packages/release-manager/test/release.test.ts +0 -215
  321. package/packages/requirement-compiler/test/requirement-compiler.test.ts +0 -743
  322. package/packages/runtime/test/runtime-api.test.ts +0 -169
  323. package/packages/runtime/test/runtime.test.ts +0 -297
  324. package/packages/scheduler/test/scheduler.test.ts +0 -125
  325. package/packages/session/test/manager.test.ts +0 -233
  326. package/packages/shared-context/test/shared-context.test.ts +0 -114
  327. package/packages/skill-registry/test/registry.test.ts +0 -508
  328. package/packages/skills/test/init-skills.test.ts +0 -114
  329. package/packages/skills/test/remote-skills.test.ts +0 -360
  330. package/packages/skills/test/remote-source.test.ts +0 -248
  331. package/packages/skills/test/sanitize.test.ts +0 -250
  332. package/packages/skills/test/vector-indexing.test.ts +0 -205
  333. package/packages/skills/test/vector-schema.test.ts +0 -180
  334. package/packages/skills/test/vector-threshold.test.ts +0 -108
  335. package/packages/sprint-planner/test/planner.test.ts +0 -187
  336. package/packages/task-compiler/test/task-compiler.test.ts +0 -628
  337. package/packages/test-data-generator/test/generator.test.ts +0 -265
  338. package/packages/test-generator/test/generator.test.ts +0 -156
  339. package/packages/token-estimation/test/token-estimation.test.ts +0 -207
  340. package/packages/token-optimizer/test/optimizer.test.ts +0 -141
  341. package/packages/tooling-preference/tests/changed-files.test.ts +0 -124
  342. package/packages/tooling-preference/tests/detect.test.ts +0 -188
  343. package/packages/tooling-preference/tests/proposal.test.ts +0 -107
  344. package/packages/tooling-preference/tests/quality-check.test.ts +0 -272
  345. package/packages/tooling-preference/tests/registry.test.ts +0 -51
  346. package/packages/tooling-preference/tests/store.test.ts +0 -99
  347. package/packages/trajectory/test/store.test.ts +0 -250
  348. package/packages/tui/test/harness-footer.test.ts +0 -559
  349. package/packages/tui/test/harness-header.test.ts +0 -590
  350. package/packages/two-phase-review/test/classify.test.ts +0 -102
  351. package/packages/two-phase-review/test/helpers.ts +0 -72
  352. package/packages/two-phase-review/test/rules.test.ts +0 -150
  353. package/packages/two-phase-review/test/runtime.test.ts +0 -362
  354. package/packages/two-phase-review/test/scope.test.ts +0 -186
  355. package/packages/two-phase-review/test/signals.test.ts +0 -183
  356. package/packages/two-phase-review/test/state.test.ts +0 -201
  357. package/packages/wiki/test/basic.test.ts +0 -242
  358. package/packages/workspace-scanner/test/scanner.test.ts +0 -43
  359. package/packages/worktree/test/worktree.test.ts +0 -163
@@ -1,251 +0,0 @@
1
- /**
2
- * LoopWidget tests — T14
3
- *
4
- * Run:
5
- * bun test harness/langchain/widget.test.ts
6
- */
7
-
8
- import { describe, it, beforeEach } from "node:test";
9
- import assert from "node:assert";
10
- import { LoopWidget } from "./widget.js";
11
-
12
- // ─── Fixtures ────────────────────────────────────────────────────────────────
13
-
14
- const stubTheme = {
15
- fg: (color: string, s: string): string => {
16
- const codes: Record<string, string> = {
17
- dim: `\x1b[2m${s}\x1b[0m`,
18
- error: `\x1b[31m${s}\x1b[0m`,
19
- warning: `\x1b[33m${s}\x1b[0m`,
20
- success: `\x1b[32m${s}\x1b[0m`,
21
- accent: `\x1b[36m${s}\x1b[0m`,
22
- };
23
- return codes[color] ?? s;
24
- },
25
- };
26
-
27
- describe("T14 — LoopWidget", () => {
28
- let widget: LoopWidget;
29
-
30
- beforeEach(() => {
31
- widget = new LoopWidget();
32
- });
33
-
34
- // ─── Idle state ────────────────────────────────────────────────────────
35
-
36
- it("starts in idle phase", () => {
37
- const lines = widget.renderWidget(80, stubTheme);
38
- assert.match(lines[0], /idle/);
39
- assert.match(lines[0], /harness/);
40
- });
41
-
42
- // ─── Phase transitions ──────────────────────────────────────────────────
43
-
44
- it("setPhase changes the phase label", () => {
45
- widget.setPhase("writing");
46
- const lines = widget.renderWidget(80, stubTheme);
47
- assert.match(lines[0], /coding/);
48
- });
49
-
50
- it("setPhase with custom label uses the label", () => {
51
- widget.setPhase("planning", "GPT planning");
52
- const lines = widget.renderWidget(80, stubTheme);
53
- assert.match(lines[0], /GPT planning/);
54
- });
55
-
56
- it("surge-pause shows detail line", () => {
57
- widget.setSurgePause(new Date(Date.now() + 30 * 60_000)); // 30 min
58
- const lines = widget.renderWidget(80, stubTheme);
59
- // Label is "surge (in 30m)"
60
- assert.ok(lines.some((l) => l.includes("surge") && l.includes("in 30m")));
61
- });
62
-
63
- it("setError shows error detail", () => {
64
- widget.setError("model timeout");
65
- const lines = widget.renderWidget(80, stubTheme);
66
- assert.ok(lines.some((l) => l.includes("error")));
67
- assert.ok(lines.some((l) => l.includes("model timeout")));
68
- });
69
-
70
- it("setComplete approved shows ✓ loop complete", () => {
71
- widget.setComplete("approved");
72
- const lines = widget.renderWidget(80, stubTheme);
73
- assert.match(lines[0], /loop complete/);
74
- });
75
-
76
- it("setComplete rejected shows ✗ loop rejected", () => {
77
- widget.setComplete("rejected");
78
- const lines = widget.renderWidget(80, stubTheme);
79
- assert.match(lines[0], /loop rejected/);
80
- });
81
-
82
- it("setComplete max_iterations shows iteration count", () => {
83
- widget.setComplete("max_iterations");
84
- const lines = widget.renderWidget(80, stubTheme);
85
- assert.match(lines[0], /max iterations/);
86
- });
87
-
88
- // ─── Iteration tracking ────────────────────────────────────────────────
89
-
90
- it("startIteration sets iteration and max", () => {
91
- widget.startIteration(3, 5);
92
- const lines = widget.renderWidget(80, stubTheme);
93
- assert.match(lines[0], /iter 3\/5/);
94
- });
95
-
96
- it("startIteration resets per-file counters but keeps file records", () => {
97
- widget.recordWrite("src/a.ts");
98
- widget.recordBlockers("src/a.ts", 2);
99
- widget.startIteration(2, 5);
100
- // Files accumulate across iterations (same codebase); only counters reset.
101
- // After reset, a.ts shows with 0 write steps and 0 blockers.
102
- const lines = widget.renderWidget(80, stubTheme);
103
- const fileLines = lines.filter((l) => l.includes("a.ts"));
104
- assert.ok(fileLines.length > 0, "file should still appear");
105
- // No blocker count in the file row (reset to 0)
106
- assert.ok(
107
- !fileLines.some((l) => l.includes("!2")),
108
- "blocker count should be reset",
109
- );
110
- });
111
-
112
- // ─── File record tracking ──────────────────────────────────────────────
113
-
114
- it("recordWrite shows file in widget", () => {
115
- widget.recordWrite("src/foo.ts");
116
- const lines = widget.renderWidget(80, stubTheme);
117
- assert.ok(lines.some((l) => l.includes("foo.ts")));
118
- });
119
-
120
- it("recordWrite accumulates across calls", () => {
121
- widget.recordWrite("src/bar.ts");
122
- widget.recordWrite("src/bar.ts");
123
- const lines = widget.renderWidget(80, stubTheme);
124
- assert.ok(lines.some((l) => l.includes("bar.ts") && l.includes("✍2")));
125
- });
126
-
127
- it("recordBlockers shows blocker count", () => {
128
- widget.recordBlockers("src/bad.ts", 2);
129
- const lines = widget.renderWidget(80, stubTheme);
130
- assert.ok(lines.some((l) => l.includes("bad.ts") && l.includes("!2")));
131
- });
132
-
133
- it("recordReviewPass clears blockers and increments passes", () => {
134
- widget.recordBlockers("src/ok.ts", 1);
135
- widget.recordReviewPass("src/ok.ts");
136
- const lines = widget.renderWidget(80, stubTheme);
137
- assert.ok(lines.some((l) => l.includes("ok.ts") && l.includes("🔍1")));
138
- // No blocker count
139
- assert.ok(
140
- !lines.some(
141
- (l) => l.includes("ok.ts") && l.includes("!") && !l.includes("🔍"),
142
- ),
143
- );
144
- });
145
-
146
- // ─── Summary counts ────────────────────────────────────────────────────
147
-
148
- it("no errors/warnings shows ✓", () => {
149
- const lines = widget.renderWidget(80, stubTheme);
150
- assert.ok(lines[0].includes("✓") || lines[0].includes("harness"));
151
- });
152
-
153
- it("errors shown as ●NE", () => {
154
- widget.recordBlockers("src/err.ts", 3);
155
- const lines = widget.renderWidget(80, stubTheme);
156
- assert.ok(lines.some((l) => l.includes("●3E")));
157
- });
158
-
159
- // ─── Surge pause ──────────────────────────────────────────────────────
160
-
161
- it("setSurgePause shows reset time in minutes/hours", () => {
162
- const resetAt = new Date(Date.now() + 90 * 60_000); // 90 minutes → "in 1h 30m"
163
- widget.setSurgePause(resetAt);
164
- const lines = widget.renderWidget(80, stubTheme);
165
- const surgeLine = lines.find((l) => l.includes("surge"));
166
- assert.ok(surgeLine !== undefined);
167
- assert.match(surgeLine, /\(in \d+h/); // "in 1h 30m" matches
168
- });
169
-
170
- it("setSurgePause shows 'now' for past dates", () => {
171
- const resetAt = new Date(Date.now() - 1000);
172
- widget.setSurgePause(resetAt);
173
- const lines = widget.renderWidget(80, stubTheme);
174
- // Label format: "surge (now)"
175
- assert.ok(lines.some((l) => l.includes("surge") && l.includes("(now)")));
176
- });
177
-
178
- // ─── Console fallback ─────────────────────────────────────────────────
179
-
180
- it("toConsoleString returns human-readable output", () => {
181
- widget.startIteration(2, 5);
182
- widget.setPhase("writing", "coding");
183
- widget.recordWrite("src/test.ts");
184
- const output = widget.toConsoleString();
185
- assert.match(output, /harness/);
186
- assert.match(output, /iter 2\/5/);
187
- assert.match(output, /coding/);
188
- assert.match(output, /test\.ts/);
189
- });
190
-
191
- // ─── Width / truncation ───────────────────────────────────────────────
192
-
193
- it("truncates long file names with …", () => {
194
- widget.recordWrite(
195
- "/very/long/path/to/a/very/long/file/name/that/exceeds/width.ts",
196
- );
197
- const lines = widget.renderWidget(40, stubTheme);
198
- for (const line of lines) {
199
- const stripped = line.replace(/\x1b\[[0-9;]*m/g, "");
200
- assert.ok(stripped.length <= 41, `line too long: ${stripped}`);
201
- }
202
- });
203
-
204
- // ─── reset() ─────────────────────────────────────────────────────────
205
-
206
- it("reset() clears all state", () => {
207
- widget.startIteration(2, 5);
208
- widget.setPhase("writing");
209
- widget.recordWrite("src/a.ts");
210
- widget.reset();
211
- const lines = widget.renderWidget(80, stubTheme);
212
- assert.match(lines[0], /idle/);
213
- assert.ok(!lines.some((l) => l.includes("a.ts")));
214
- });
215
-
216
- // ─── makeRenderer ─────────────────────────────────────────────────────
217
-
218
- it("makeRenderer returns factory and invalidate", () => {
219
- const { factory, invalidate } = widget.makeRenderer();
220
- assert.equal(typeof factory, "function");
221
- assert.equal(typeof invalidate, "function");
222
- });
223
-
224
- it("factory returns render + invalidate + dispose", () => {
225
- const { factory } = widget.makeRenderer();
226
- const comp = factory({} as any, stubTheme as any);
227
- assert.equal(typeof comp.render, "function");
228
- assert.equal(typeof comp.invalidate, "function");
229
- assert.equal(typeof comp.dispose, "function");
230
- });
231
-
232
- it("factory render() returns widget lines", () => {
233
- widget.setPhase("planning");
234
- const { factory } = widget.makeRenderer();
235
- const comp = factory({} as any, stubTheme as any);
236
- const lines = comp.render(80);
237
- assert.ok(Array.isArray(lines));
238
- assert.ok(lines.length > 0);
239
- });
240
-
241
- // ─── getLoopWidget singleton ────────────────────────────────────────────
242
-
243
- it("getLoopWidget returns the same instance", () => {
244
- // Dynamic import to avoid module caching issues
245
- import("./widget.js").then((m) => {
246
- const a = m.getLoopWidget();
247
- const b = m.getLoopWidget();
248
- assert.strictEqual(a, b);
249
- });
250
- });
251
- });
@@ -1,57 +0,0 @@
1
- /**
2
- * Skill Sync Tests
3
- */
4
-
5
- // @ts-ignore - bun:test types
6
- import { describe, test, expect, beforeEach, afterEach } from "bun:test";
7
- import { tmpdir } from "node:os";
8
- import { mkdirSync, rmSync } from "node:fs";
9
- import { join } from "node:path";
10
-
11
- // Mock the environment
12
- const originalApiKey = process.env.SKILLS_SAAS_API_KEY;
13
-
14
- describe("Skill Sync", () => {
15
- let tempCacheDir: string;
16
-
17
- beforeEach(() => {
18
- tempCacheDir = join(tmpdir(), `skill-sync-test-${Date.now()}`);
19
- mkdirSync(tempCacheDir, { recursive: true });
20
- });
21
-
22
- afterEach(() => {
23
- // Restore env
24
- if (originalApiKey === undefined) {
25
- delete process.env.SKILLS_SAAS_API_KEY;
26
- } else {
27
- process.env.SKILLS_SAAS_API_KEY = originalApiKey;
28
- }
29
- // Cleanup
30
- try {
31
- rmSync(tempCacheDir, { recursive: true });
32
- } catch {
33
- // Ignore
34
- }
35
- });
36
-
37
- describe("isSkillSyncConfigured", () => {
38
- test("returns false when API key not set", () => {
39
- delete process.env.SKILLS_SAAS_API_KEY;
40
- // Import dynamically to test
41
- expect(process.env.SKILLS_SAAS_API_KEY).toBeUndefined();
42
- });
43
-
44
- test("returns true when API key is set", () => {
45
- process.env.SKILLS_SAAS_API_KEY = "sk_test_xxx";
46
- expect(process.env.SKILLS_SAAS_API_KEY).toBe("sk_test_xxx");
47
- });
48
- });
49
-
50
- describe("getSyncStatus", () => {
51
- test("returns correct status when not configured", () => {
52
- delete process.env.SKILLS_SAAS_API_KEY;
53
- // Status should show not configured
54
- expect(process.env.SKILLS_SAAS_API_KEY).toBeUndefined();
55
- });
56
- });
57
- });
@@ -1,263 +0,0 @@
1
- /**
2
- * SSH Detach Interceptor — Tests
3
- *
4
- * Key insight on quoting:
5
- * - `ssh user@host 'cmd &'` — & is INSIDE quotes → safe, SSH completes normally
6
- * - `ssh user@host "cmd" &` — & is OUTSIDE quotes → risky, backgrounds SSH itself
7
- * - `ssh user@host 'kill ... &' "2>/dev/null"` — & inside quotes, redirect outside → risky
8
- */
9
- import { describe, it } from "node:test";
10
- import assert from "node:assert";
11
- import {
12
- isSshCommand,
13
- isDetachedPattern,
14
- hasBareAmpersand,
15
- transformToDetached,
16
- detectSsh,
17
- isForegroundDaemonSsh,
18
- addSshTimeoutGuard,
19
- getDefaultSshTimeoutSeconds,
20
- } from "./ssh-detach-interceptor.js";
21
-
22
- describe("isSshCommand", () => {
23
- const cases: Array<[string, boolean]> = [
24
- ["ssh user@host ls", true],
25
- ["ssh -o StrictHostKeyChecking=no user@host ls", true],
26
- ["echo 'pass' | ssh user@host ls", true],
27
- ["curl https://example.com", false],
28
- ["cd /home && ls", false],
29
- ["ssh user@host 'echo test &'", true],
30
- ["docker exec container ls", false],
31
- ];
32
- cases.forEach(([cmd, expected]) => {
33
- it(`${cmd.slice(0, 50)} → ${expected}`, () => {
34
- assert.strictEqual(isSshCommand(cmd), expected);
35
- });
36
- });
37
- });
38
-
39
- describe("isDetachedPattern", () => {
40
- const cases: Array<[string, boolean]> = [
41
- // & is inside quotes → not detached (no nohup locally visible)
42
- ["ssh user@host 'cmd > /tmp/log 2>&1 & echo DONE'", false],
43
- // bare & inside quotes → not detached
44
- ["ssh user@host 'cmd &'", false],
45
- // nohup + redirect + echo DONE → detached
46
- ["ssh user@host 'nohup cmd > /tmp/log 2>&1 & echo DONE'", true],
47
- // missing echo DONE → not detached
48
- ["ssh user@host 'cmd > /tmp/log &'", false],
49
- // missing redirect → not detached
50
- ["ssh user@host 'nohup cmd &'", false],
51
- // non-SSH → not detached
52
- ["curl https://example.com", false],
53
- ];
54
- cases.forEach(([cmd, expected]) => {
55
- it(`${cmd.slice(0, 55)} → ${expected}`, () => {
56
- assert.strictEqual(isDetachedPattern(cmd), expected);
57
- });
58
- });
59
- });
60
-
61
- describe("hasBareAmpersand", () => {
62
- // & outside quotes = risky (backgrounds SSH itself)
63
- const risky: Array<[string, boolean]> = [
64
- ["ssh user@host 'cmd' &", true],
65
- ["ssh user@host 'kill 123' &", true],
66
- ["echo 'pass' | ssh user@host 'kill 123' &", true],
67
- ["ssh user@host 'cmd > /tmp/log 2>&1' &", true],
68
- ];
69
- // & inside quotes = safe (SSH completes, remote side backgrounds)
70
- const safe: Array<[string, boolean]> = [
71
- ["ssh user@host 'cmd &'", false],
72
- ["ssh user@host 'kill -9 123 && uvicorn &'", false],
73
- ["ssh user@host 'nohup cmd &'", false],
74
- ["ssh user@host 'cmd'", false],
75
- ["curl https://example.com", false],
76
- ];
77
- [...risky, ...safe].forEach(([cmd, expected]) => {
78
- it(`${cmd.slice(0, 50)} → ${expected}`, () => {
79
- assert.strictEqual(hasBareAmpersand(cmd), expected);
80
- });
81
- });
82
- });
83
-
84
- describe("transformToDetached", () => {
85
- it("leaves non-SSH commands unchanged", () => {
86
- const cmd = "curl https://example.com";
87
- assert.strictEqual(transformToDetached(cmd), cmd);
88
- });
89
-
90
- it("leaves already-detached SSH commands unchanged", () => {
91
- const cmd = "ssh user@host 'cmd > /tmp/log 2>&1 & echo DONE'";
92
- assert.strictEqual(transformToDetached(cmd), cmd);
93
- });
94
-
95
- it("transforms bare ssh 'cmd' & (risky: & outside quotes)", () => {
96
- const cmd = "ssh user@host 'kill -9 123; sleep 2; uvicorn' &";
97
- const result = transformToDetached(cmd);
98
- assert.notStrictEqual(result, cmd);
99
- assert.ok(result.includes("nohup"), "should add nohup");
100
- assert.ok(result.includes("/tmp/herdr-ssh.log"), "should add log redirect");
101
- assert.ok(result.includes("2>&1"), "should add stderr redirect");
102
- assert.ok(result.includes("echo 'SSH_DETACHED'"), "should add DONE echo");
103
- });
104
-
105
- it("transforms pipelined ssh with bare & (risky: & outside quotes)", () => {
106
- const cmd = "echo 'pass' | ssh user@host 'kill -9 123' &";
107
- const result = transformToDetached(cmd);
108
- assert.notStrictEqual(result, cmd);
109
- assert.ok(result.includes("nohup"));
110
- assert.ok(result.includes("echo 'SSH_DETACHED'"));
111
- });
112
-
113
- it("leaves & inside quotes unchanged (safe: SSH completes)", () => {
114
- const cmd = "ssh user@host 'kill -9 123; uvicorn &'";
115
- const result = transformToDetached(cmd);
116
- assert.strictEqual(result, cmd); // no transform needed
117
- });
118
-
119
- it("uses custom log file", () => {
120
- const cmd = "ssh user@host 'cmd' &";
121
- const result = transformToDetached(cmd, { logFile: "/var/log/my-ssh.log" });
122
- assert.ok(result.includes("/var/log/my-ssh.log"));
123
- });
124
- });
125
-
126
- describe("detectSsh", () => {
127
- it("warns on SSH with bare & outside quotes", () => {
128
- const result = detectSsh("ssh user@host 'cmd' &");
129
- assert.strictEqual(result.isSsh, true);
130
- assert.strictEqual(result.hasBareAmpersand, true);
131
- assert.strictEqual(result.isDetached, false);
132
- assert.ok(result.suggestion.includes("nohup"));
133
- });
134
-
135
- it("no warning for & inside quotes (SSH completes normally)", () => {
136
- const result = detectSsh("ssh user@host 'kill 123 && uvicorn &'");
137
- assert.strictEqual(result.isSsh, true);
138
- assert.strictEqual(result.isDetached, false);
139
- assert.strictEqual(result.hasBareAmpersand, false);
140
- assert.strictEqual(result.suggestion, "");
141
- });
142
-
143
- it("no detection for non-SSH", () => {
144
- const result = detectSsh("curl https://example.com");
145
- assert.strictEqual(result.isSsh, false);
146
- assert.strictEqual(result.suggestion, "");
147
- });
148
- });
149
-
150
- describe("isForegroundDaemonSsh", () => {
151
- // A synthetic stand-in for the foreground SSH command that used to hang
152
- const HANG_CMD =
153
- "echo 'synthetic-test-password' | ssh -tt worker@worker.example.com \"cd /srv/app/backend/services/worker && AMOS_API_URL=https://api.example.com AMOS_WORKER_API_KEY=test /srv/app/backend/.venv/bin/python -m amos_worker --video 2>&1 | head -10\"";
154
-
155
- const risky: Array<[string, string]> = [
156
- [
157
- HANG_CMD,
158
- "foreground ssh -tt running amos_worker poller",
159
- ],
160
- [
161
- 'ssh host "uvicorn main:app --host 0.0.0.0 --port 8100"',
162
- "foreground uvicorn",
163
- ],
164
- ["ssh host 'python -m celery worker'", "celery worker"],
165
- ['ssh host "tail -f /var/log/app.log"', "tail -f"],
166
- ['ssh host "npm run dev"', "npm run dev"],
167
- [
168
- 'ssh host "python -m my_package.daemon --poll"',
169
- "python -m with daemon in module path",
170
- ],
171
- ];
172
- risky.forEach(([cmd, label]) => {
173
- it(`RISKY: ${label}`, () => {
174
- assert.strictEqual(isForegroundDaemonSsh(cmd), true, cmd.slice(0, 80));
175
- });
176
- });
177
-
178
- const safe: Array<[string, string]> = [
179
- ["ssh host 'ls -la'", "plain remote command"],
180
- [
181
- "timeout 60s ssh -o BatchMode=yes host 'uvicorn main:app'",
182
- "local timeout guard",
183
- ],
184
- [
185
- "ssh host 'timeout 30 python -m amos_worker --video'",
186
- "remote timeout guard",
187
- ],
188
- [
189
- "ssh host 'nohup python -m amos_worker --video > /tmp/w.log 2>&1 & echo DONE'",
190
- "nohup detached",
191
- ],
192
- ["ssh -f host 'uvicorn main:app'", "ssh -f backgrounds itself"],
193
- [
194
- "python -m amos_worker --video",
195
- "local (non-ssh) daemon command — not our scope",
196
- ],
197
- ["curl https://example.com", "not ssh"],
198
- ];
199
- safe.forEach(([cmd, label]) => {
200
- it(`SAFE: ${label}`, () => {
201
- assert.strictEqual(isForegroundDaemonSsh(cmd), false, cmd.slice(0, 80));
202
- });
203
- });
204
- });
205
-
206
- describe("addSshTimeoutGuard", () => {
207
- it("prefixes the ssh segment with timeout, preserving pipeline prefix", () => {
208
- const cmd = "echo 'x' | ssh -tt host \"python -m amos_worker --video\"";
209
- assert.strictEqual(
210
- addSshTimeoutGuard(cmd, 300),
211
- "echo 'x' | timeout 300s ssh -tt host \"python -m amos_worker --video\"",
212
- );
213
- });
214
-
215
- it("uses default seconds when omitted", () => {
216
- const cmd = "ssh host 'uvicorn main:app'";
217
- assert.ok(addSshTimeoutGuard(cmd).startsWith("timeout "));
218
- assert.ok(addSshTimeoutGuard(cmd).includes("s ssh host"));
219
- });
220
-
221
- it("invalid seconds returns command unchanged", () => {
222
- const cmd = "ssh host 'uvicorn main:app'";
223
- assert.strictEqual(addSshTimeoutGuard(cmd, 0), cmd);
224
- assert.strictEqual(addSshTimeoutGuard(cmd, NaN), cmd);
225
- });
226
-
227
- it("non-ssh command returns unchanged", () => {
228
- assert.strictEqual(addSshTimeoutGuard("ls -la"), "ls -la");
229
- });
230
- });
231
-
232
- describe("getDefaultSshTimeoutSeconds", () => {
233
- it("defaults to 300", () => {
234
- delete process.env.PI_HARNESS_SSH_TIMEOUT_S;
235
- assert.strictEqual(getDefaultSshTimeoutSeconds(), 300);
236
- });
237
-
238
- it("honours PI_HARNESS_SSH_TIMEOUT_S", () => {
239
- const prev = process.env.PI_HARNESS_SSH_TIMEOUT_S;
240
- try {
241
- process.env.PI_HARNESS_SSH_TIMEOUT_S = "120";
242
- assert.strictEqual(getDefaultSshTimeoutSeconds(), 120);
243
- process.env.PI_HARNESS_SSH_TIMEOUT_S = "bogus";
244
- assert.strictEqual(getDefaultSshTimeoutSeconds(), 300);
245
- } finally {
246
- if (prev === undefined) delete process.env.PI_HARNESS_SSH_TIMEOUT_S;
247
- else process.env.PI_HARNESS_SSH_TIMEOUT_S = prev;
248
- }
249
- });
250
- });
251
-
252
- describe("detectSsh (timeout guard)", () => {
253
- it("flags foreground daemon ssh with timeout suggestion", () => {
254
- const result = detectSsh("ssh -tt host 'python -m amos_worker --video'");
255
- assert.strictEqual(result.needsTimeoutGuard, true);
256
- assert.ok(result.suggestion.includes("timeout"));
257
- });
258
-
259
- it("no timeout flag for plain ssh", () => {
260
- const result = detectSsh("ssh host 'ls -la'");
261
- assert.strictEqual(result.needsTimeoutGuard, false);
262
- });
263
- });
@@ -1,86 +0,0 @@
1
- /**
2
- * SSH Hang Recovery — tests for the shell-safety helpers.
3
- *
4
- * The host, the user and the command all reach a shell. A value that is
5
- * quoted cannot end the quote, and a value that does not look like a host
6
- * is rejected before it is ever passed on.
7
- */
8
- import { describe, it } from "node:test";
9
- import assert from "node:assert";
10
- import { shellQuote, assertSafeSshTarget } from "./ssh-hang-recovery.js";
11
-
12
- describe("shellQuote", () => {
13
- it("wraps a plain value in single quotes", () => {
14
- assert.strictEqual(shellQuote("pm2 status"), "'pm2 status'");
15
- });
16
-
17
- it("neutralizes a value that would close the quote", () => {
18
- // The classic breakout: ' ; rm -rf / ; '
19
- const payload = "'; rm -rf / ; '";
20
- const quoted = shellQuote(payload);
21
- // Every ' of the payload is closed, escaped and reopened, so the
22
- // payload can never leave the quoted string.
23
- assert.strictEqual(quoted, "''\\''; rm -rf / ; '\\'''");
24
- // The quoted form has an even number of quotes: it parses as one
25
- // literal string, whatever the payload was.
26
- assert.strictEqual((quoted.match(/'/g) || []).length % 2, 0);
27
- });
28
-
29
- it("neutralizes a command substitution", () => {
30
- const quoted = shellQuote("$(whoami)");
31
- assert.strictEqual(quoted, "'$(whoami)'");
32
- });
33
-
34
- it("neutralizes a backtick substitution", () => {
35
- const quoted = shellQuote("`id`");
36
- assert.strictEqual(quoted, "'`id`'");
37
- });
38
-
39
- it("keeps a newline inside the quotes", () => {
40
- const quoted = shellQuote("a\nb");
41
- assert.strictEqual(quoted, "'a\nb'");
42
- });
43
- });
44
-
45
- describe("assertSafeSshTarget", () => {
46
- it("accepts a DNS name", () => {
47
- assert.doesNotThrow(() => assertSafeSshTarget("example.com", "deploy"));
48
- });
49
-
50
- it("accepts an IPv4 address", () => {
51
- assert.doesNotThrow(() => assertSafeSshTarget("203.0.113.10", "deploy"));
52
- });
53
-
54
- it("accepts a bracketed IPv6 address", () => {
55
- assert.doesNotThrow(() => assertSafeSshTarget("[2001:db8::1]", "deploy"));
56
- });
57
-
58
- it("rejects a host that carries a command", () => {
59
- assert.throws(
60
- () => assertSafeSshTarget("example.com; rm -rf /", "deploy"),
61
- /invalid ssh host/,
62
- );
63
- });
64
-
65
- it("rejects a host that carries a substitution", () => {
66
- assert.throws(
67
- () => assertSafeSshTarget("$(whoami).example.com", "deploy"),
68
- /invalid ssh host/,
69
- );
70
- });
71
-
72
- it("rejects a host with a space", () => {
73
- assert.throws(() => assertSafeSshTarget("a b", "deploy"), /invalid ssh host/);
74
- });
75
-
76
- it("rejects a user that carries a command", () => {
77
- assert.throws(
78
- () => assertSafeSshTarget("example.com", "root; rm -rf /"),
79
- /invalid ssh user/,
80
- );
81
- });
82
-
83
- it("rejects a user with a shell metacharacter", () => {
84
- assert.throws(() => assertSafeSshTarget("example.com", "a$b"), /invalid ssh user/);
85
- });
86
- });