pi-harness-runtime 1.1.440 → 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 (349) hide show
  1. package/harness/e2e/auto-test-loop.ts +2 -0
  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/key-loader.ts +2 -0
  7. package/harness/langchain/checkpointer.ts +2 -0
  8. package/harness/langchain/cron-cli.ts +2 -0
  9. package/harness/langchain/graph.ts +2 -0
  10. package/harness/notification-center.ts +2 -0
  11. package/harness/secret-provider.ts +2 -0
  12. package/index.ts +2 -0
  13. package/package.json +7 -1
  14. package/packages/a2a-adapter/package.json +1 -1
  15. package/packages/agent-policy/dist/extension.d.ts.map +1 -1
  16. package/packages/agent-policy/dist/extension.js +2 -0
  17. package/packages/agent-policy/dist/extension.js.map +1 -1
  18. package/packages/agent-policy/package.json +1 -1
  19. package/packages/agent-policy/src/extension.ts +2 -0
  20. package/packages/architecture-generator/package.json +1 -1
  21. package/packages/auth/dist/minimax-browser-auth.d.ts.map +1 -1
  22. package/packages/auth/dist/minimax-browser-auth.js +23 -1
  23. package/packages/auth/dist/minimax-browser-auth.js.map +1 -1
  24. package/packages/auth/package.json +1 -1
  25. package/packages/auth/src/minimax-browser-auth.ts +30 -5
  26. package/packages/autonomous-refactor/package.json +1 -1
  27. package/packages/autonomous-runtime/dist/inbox.d.ts.map +1 -1
  28. package/packages/autonomous-runtime/dist/inbox.js +2 -0
  29. package/packages/autonomous-runtime/dist/inbox.js.map +1 -1
  30. package/packages/autonomous-runtime/package.json +1 -1
  31. package/packages/autonomous-runtime/src/inbox.ts +2 -0
  32. package/packages/cache-strategy/package.json +1 -1
  33. package/packages/capability-registry/package.json +1 -1
  34. package/packages/checkpoint/package.json +1 -1
  35. package/packages/cli-plugin-sdk/package.json +1 -1
  36. package/packages/clipboard/dist/src/clipboard.d.ts.map +1 -1
  37. package/packages/clipboard/dist/src/clipboard.js +2 -0
  38. package/packages/clipboard/dist/src/clipboard.js.map +1 -1
  39. package/packages/clipboard/dist/src/copy-sync.d.ts.map +1 -1
  40. package/packages/clipboard/dist/src/copy-sync.js +2 -0
  41. package/packages/clipboard/dist/src/copy-sync.js.map +1 -1
  42. package/packages/clipboard/dist/src/gist-relay.d.ts.map +1 -1
  43. package/packages/clipboard/dist/src/gist-relay.js +2 -0
  44. package/packages/clipboard/dist/src/gist-relay.js.map +1 -1
  45. package/packages/clipboard/package.json +1 -1
  46. package/packages/clipboard/src/clipboard.ts +2 -0
  47. package/packages/clipboard/src/copy-sync.ts +2 -0
  48. package/packages/clipboard/src/gist-relay.ts +2 -0
  49. package/packages/clipboard-plugin/package.json +1 -1
  50. package/packages/code-generation/package.json +1 -1
  51. package/packages/code-review/package.json +1 -1
  52. package/packages/codex-adapter/package.json +1 -1
  53. package/packages/codex-watcher/package.json +1 -1
  54. package/packages/config-capture/package.json +1 -1
  55. package/packages/connection-runtime/package.json +1 -1
  56. package/packages/context-compiler/package.json +1 -1
  57. package/packages/context-discovery/package.json +1 -1
  58. package/packages/context-manager/package.json +1 -1
  59. package/packages/contracts/dist/delegation-store.js +1 -4
  60. package/packages/contracts/dist/workspace-env.js +28 -1
  61. package/packages/contracts/package.json +1 -1
  62. package/packages/contracts/src/delegation-store.ts +9 -4
  63. package/packages/contracts/src/workspace-env.ts +29 -4
  64. package/packages/cookie-sanitizer/package.json +1 -1
  65. package/packages/cost-optimizer/package.json +1 -1
  66. package/packages/dependency-analyzer/package.json +1 -1
  67. package/packages/django-plugin/package.json +1 -1
  68. package/packages/doc-generator/package.json +1 -1
  69. package/packages/durable-review/package.json +1 -1
  70. package/packages/e2e-tester/package.json +1 -1
  71. package/packages/evaluation-engine/package.json +1 -1
  72. package/packages/evaluation-runner/package.json +1 -1
  73. package/packages/event-bus/package.json +1 -1
  74. package/packages/event-sink/package.json +1 -1
  75. package/packages/event-store/dist/src/store.d.ts.map +1 -1
  76. package/packages/event-store/dist/src/store.js +2 -0
  77. package/packages/event-store/dist/src/store.js.map +1 -1
  78. package/packages/event-store/package.json +1 -1
  79. package/packages/event-store/src/store.ts +3 -0
  80. package/packages/experience-replay/package.json +1 -1
  81. package/packages/feedback-collector/package.json +1 -1
  82. package/packages/file-copy-helper/package.json +1 -1
  83. package/packages/framework-detector/package.json +1 -1
  84. package/packages/framework-plugin-sdk/package.json +1 -1
  85. package/packages/frappe-plugin/package.json +1 -1
  86. package/packages/generic-web-plugin/dist/analyzer.d.ts.map +1 -1
  87. package/packages/generic-web-plugin/dist/analyzer.js +2 -0
  88. package/packages/generic-web-plugin/dist/analyzer.js.map +1 -1
  89. package/packages/generic-web-plugin/package.json +1 -1
  90. package/packages/generic-web-plugin/src/analyzer.ts +3 -0
  91. package/packages/health-monitor/package.json +1 -1
  92. package/packages/intent-analyzer/package.json +1 -1
  93. package/packages/jev-judge/package.json +1 -1
  94. package/packages/knowledge-graph/package.json +1 -1
  95. package/packages/knowledge-retrieval/dist/mcp-client.d.ts.map +1 -1
  96. package/packages/knowledge-retrieval/dist/mcp-client.js +0 -1
  97. package/packages/knowledge-retrieval/dist/mcp-client.js.map +1 -1
  98. package/packages/knowledge-retrieval/package.json +1 -4
  99. package/packages/knowledge-retrieval/src/mcp-client.ts +0 -1
  100. package/packages/laravel-plugin/package.json +1 -1
  101. package/packages/learning-engine/package.json +1 -1
  102. package/packages/logging/package.json +1 -1
  103. package/packages/mcp-adapter/dist/server.d.ts.map +1 -1
  104. package/packages/mcp-adapter/dist/server.js +2 -0
  105. package/packages/mcp-adapter/dist/server.js.map +1 -1
  106. package/packages/mcp-adapter/package.json +1 -1
  107. package/packages/mcp-adapter/src/server.ts +3 -0
  108. package/packages/memory-engine/package.json +1 -1
  109. package/packages/milestone-manager/package.json +1 -1
  110. package/packages/model-registry/package.json +1 -1
  111. package/packages/nextjs-plugin/package.json +1 -1
  112. package/packages/notification/package.json +1 -1
  113. package/packages/observability/package.json +1 -1
  114. package/packages/okf-indexer/package.json +1 -1
  115. package/packages/paperclip-integration/dist/index.d.ts.map +1 -1
  116. package/packages/paperclip-integration/dist/index.js +2 -0
  117. package/packages/paperclip-integration/dist/index.js.map +1 -1
  118. package/packages/paperclip-integration/package.json +1 -1
  119. package/packages/paperclip-integration/src/index.ts +2 -0
  120. package/packages/performance-optimizer/package.json +1 -1
  121. package/packages/permission-mode/package.json +1 -1
  122. package/packages/privilege-broker/dist/audit.d.ts.map +1 -1
  123. package/packages/privilege-broker/dist/audit.js +2 -0
  124. package/packages/privilege-broker/dist/audit.js.map +1 -1
  125. package/packages/privilege-broker/package.json +1 -1
  126. package/packages/privilege-broker/src/audit.ts +2 -0
  127. package/packages/project-analyzer/package.json +1 -1
  128. package/packages/project-bootstrap/package.json +1 -1
  129. package/packages/projection-engine/package.json +1 -1
  130. package/packages/prompt-compiler/dist/compiler.d.ts.map +1 -1
  131. package/packages/prompt-compiler/dist/compiler.js +2 -0
  132. package/packages/prompt-compiler/dist/compiler.js.map +1 -1
  133. package/packages/prompt-compiler/package.json +1 -1
  134. package/packages/prompt-compiler/src/compiler.ts +2 -0
  135. package/packages/prompt-versioning/package.json +1 -1
  136. package/packages/provider-adapter-sdk/package.json +1 -1
  137. package/packages/provider-router/package.json +1 -1
  138. package/packages/provider-selector/package.json +1 -1
  139. package/packages/providers/package.json +1 -1
  140. package/packages/qdrant-skills/package.json +1 -1
  141. package/packages/quota-manager/package.json +1 -1
  142. package/packages/rate-limiter/package.json +1 -1
  143. package/packages/react-vite-plugin/package.json +1 -1
  144. package/packages/relay/package.json +1 -1
  145. package/packages/release-manager/package.json +1 -1
  146. package/packages/requirement-compiler/package.json +1 -1
  147. package/packages/runtime/package.json +1 -1
  148. package/packages/scheduler/package.json +1 -1
  149. package/packages/scheduler-adapter/package.json +1 -1
  150. package/packages/session/package.json +1 -1
  151. package/packages/session-api/package.json +1 -1
  152. package/packages/session-export/package.json +1 -1
  153. package/packages/shared-context/package.json +1 -1
  154. package/packages/skill-mcp-client/dist/client.d.ts.map +1 -1
  155. package/packages/skill-mcp-client/dist/client.js +0 -1
  156. package/packages/skill-mcp-client/dist/client.js.map +1 -1
  157. package/packages/skill-mcp-client/package.json +1 -4
  158. package/packages/skill-mcp-client/src/client.ts +0 -1
  159. package/packages/skill-registry/package.json +1 -1
  160. package/packages/skills/dist/parser.d.ts.map +1 -1
  161. package/packages/skills/dist/parser.js +2 -0
  162. package/packages/skills/dist/parser.js.map +1 -1
  163. package/packages/skills/dist/skill-versioning.d.ts.map +1 -1
  164. package/packages/skills/dist/skill-versioning.js +2 -0
  165. package/packages/skills/dist/skill-versioning.js.map +1 -1
  166. package/packages/skills/package.json +1 -1
  167. package/packages/skills/src/parser.ts +3 -0
  168. package/packages/skills/src/skill-versioning.ts +2 -0
  169. package/packages/sprint-planner/package.json +1 -1
  170. package/packages/subscription-engine/package.json +1 -1
  171. package/packages/task-compiler/package.json +1 -1
  172. package/packages/tencentdb-memory/package.json +1 -1
  173. package/packages/tencentdb-sync/package.json +1 -1
  174. package/packages/test-data-generator/package.json +1 -1
  175. package/packages/test-generator/package.json +1 -1
  176. package/packages/todo-bd-sync/package.json +1 -1
  177. package/packages/token-estimation/package.json +1 -1
  178. package/packages/token-optimizer/package.json +1 -1
  179. package/packages/tooling-preference/package.json +1 -1
  180. package/packages/trajectory/package.json +1 -1
  181. package/packages/tui/package.json +1 -1
  182. package/packages/two-phase-review/package.json +1 -1
  183. package/packages/types/package.json +1 -1
  184. package/packages/voice-api/package.json +1 -1
  185. package/packages/webmcp-tester/dist/index.js +0 -2
  186. package/packages/webmcp-tester/package.json +1 -1
  187. package/packages/webmcp-tester/src/index.ts +0 -3
  188. package/packages/wiki/package.json +1 -1
  189. package/packages/workflow-events/package.json +1 -1
  190. package/packages/workspace-scanner/package.json +1 -1
  191. package/packages/worktree/package.json +1 -1
  192. package/packages/write-review/dist/trigger.d.ts.map +1 -1
  193. package/packages/write-review/dist/trigger.js +1 -2
  194. package/packages/write-review/dist/trigger.js.map +1 -1
  195. package/packages/write-review/package.json +1 -1
  196. package/packages/write-review/src/trigger.ts +1 -2
  197. package/scripts/lib/runtime-imports.ts +189 -3
  198. package/scripts/telegram-webhook-server.ts +2 -0
  199. package/scripts/verify-package-contents.ts +148 -1
  200. package/harness/e2e/tools-detector.test.ts +0 -155
  201. package/harness/glm-quota-countdown.test.ts +0 -323
  202. package/harness/langchain/agents.test.ts +0 -39
  203. package/harness/langchain/checkpointer.test.ts +0 -243
  204. package/harness/langchain/daemon.test.ts +0 -459
  205. package/harness/langchain/model-router.test.ts +0 -191
  206. package/harness/langchain/ping-pong-middleware.test.ts +0 -69
  207. package/harness/langchain/scoreboard.test.ts +0 -267
  208. package/harness/langchain/status-line.test.ts +0 -106
  209. package/harness/langchain/surge.test.ts +0 -467
  210. package/harness/langchain/widget.test.ts +0 -251
  211. package/harness/skill-sync.test.ts +0 -57
  212. package/harness/ssh-detach-interceptor.test.ts +0 -263
  213. package/harness/ssh-hang-recovery.test.ts +0 -86
  214. package/packages/a2a-adapter/test/a2a.test.ts +0 -151
  215. package/packages/agent-policy/test/interlock.test.ts +0 -101
  216. package/packages/agent-policy/test/policy-retention.test.ts +0 -380
  217. package/packages/agent-policy/test/policy.test.ts +0 -387
  218. package/packages/auth/test/auth.test.ts +0 -238
  219. package/packages/autonomous-refactor/test/refactor.test.ts +0 -202
  220. package/packages/autonomous-runtime/test/types.test.ts +0 -95
  221. package/packages/cache-strategy/test/cache.test.ts +0 -137
  222. package/packages/capability-registry/test/registry.test.ts +0 -204
  223. package/packages/checkpoint/test/engine.test.ts +0 -265
  224. package/packages/cli-plugin-sdk/test/cli.test.ts +0 -45
  225. package/packages/code-generation/test/generator.test.ts +0 -238
  226. package/packages/code-review/test/engine.test.ts +0 -302
  227. package/packages/codex-adapter/test/provider.test.ts +0 -142
  228. package/packages/codex-watcher/test/watch.test.ts +0 -453
  229. package/packages/context-compiler/test/context-compiler.test.ts +0 -746
  230. package/packages/context-manager/test/context.test.ts +0 -198
  231. package/packages/contracts/test/delegation.test.ts +0 -350
  232. package/packages/contracts/test/workspace-env.test.ts +0 -802
  233. package/packages/cookie-sanitizer/test/infer.test.ts +0 -110
  234. package/packages/cookie-sanitizer/test/normalize.test.ts +0 -113
  235. package/packages/cookie-sanitizer/test/parse.test.ts +0 -204
  236. package/packages/cookie-sanitizer/test/sync.test.ts +0 -237
  237. package/packages/cookie-sanitizer/test/watcher.test.ts +0 -27
  238. package/packages/cost-optimizer/test/cost-optimizer.test.ts +0 -438
  239. package/packages/dependency-analyzer/test/analyzer.test.ts +0 -49
  240. package/packages/django-plugin/test/analyzer.test.ts +0 -195
  241. package/packages/doc-generator/test/docs.test.ts +0 -168
  242. package/packages/durable-review/test/acceptance.test.ts +0 -357
  243. package/packages/durable-review/test/smoke.test.ts +0 -107
  244. package/packages/evaluation-engine/test/engine.test.ts +0 -277
  245. package/packages/evaluation-runner/test/runner.test.ts +0 -168
  246. package/packages/event-bus/test/bus.test.ts +0 -100
  247. package/packages/event-store/test/store.test.ts +0 -115
  248. package/packages/experience-replay/test/replay.test.ts +0 -267
  249. package/packages/feedback-collector/test/collector.test.ts +0 -142
  250. package/packages/framework-detector/test/detector.test.ts +0 -75
  251. package/packages/framework-plugin-sdk/test/manager.test.ts +0 -320
  252. package/packages/frappe-plugin/test/analyzer.test.ts +0 -250
  253. package/packages/generic-web-plugin/test/analyzer.test.ts +0 -134
  254. package/packages/health-monitor/test/health.test.ts +0 -231
  255. package/packages/intent-analyzer/test/analyzer.test.ts +0 -72
  256. package/packages/intent-analyzer/test/ping-pong.test.ts +0 -96
  257. package/packages/jev-judge/tests/auto-continue-context.test.ts +0 -280
  258. package/packages/jev-judge/tests/continuation-controller.test.ts +0 -1396
  259. package/packages/jev-judge/tests/jev-provider-chain.test.ts +0 -536
  260. package/packages/jev-judge/tests/outcome-application.test.ts +0 -132
  261. package/packages/jev-judge/tests/question-risk.test.ts +0 -129
  262. package/packages/jev-judge/tests/typesafe-provider.test.ts +0 -640
  263. package/packages/jev-judge/tests/validation-ledger.test.ts +0 -181
  264. package/packages/jev-judge/tests/validation-plan.test.ts +0 -170
  265. package/packages/jev-judge/tests/validation-tie-breaker.test.ts +0 -88
  266. package/packages/laravel-plugin/test/analyzer.test.ts +0 -220
  267. package/packages/learning-engine/test/engine.test.ts +0 -331
  268. package/packages/logging/test/buffer.test.ts +0 -44
  269. package/packages/logging/test/classification.test.ts +0 -137
  270. package/packages/logging/test/config.test.ts +0 -97
  271. package/packages/logging/test/fanout.test.ts +0 -186
  272. package/packages/logging/test/identity-transport.test.ts +0 -197
  273. package/packages/logging/test/incidents.test.ts +0 -404
  274. package/packages/logging/test/ingest-schema.test.ts +0 -184
  275. package/packages/logging/test/integration.test.ts +0 -140
  276. package/packages/logging/test/log-http.test.ts +0 -246
  277. package/packages/logging/test/redact.test.ts +0 -109
  278. package/packages/logging/test/sampler.test.ts +0 -57
  279. package/packages/logging/test/server.test.ts +0 -444
  280. package/packages/logging/test/shipper.test.ts +0 -152
  281. package/packages/logging/test/spool.test.ts +0 -96
  282. package/packages/mcp-adapter/test/server.test.ts +0 -91
  283. package/packages/memory-engine/test/engine.test.ts +0 -456
  284. package/packages/model-registry/test/registry.test.ts +0 -342
  285. package/packages/nextjs-plugin/test/analyzer.test.ts +0 -149
  286. package/packages/notification/test/approval-payload.test.ts +0 -269
  287. package/packages/notification/test/detail-format.test.ts +0 -106
  288. package/packages/notification/test/notification.test.ts +0 -375
  289. package/packages/notification/test/pending-question-lifecycle.test.ts +0 -195
  290. package/packages/notification/test/pending-question.test.ts +0 -331
  291. package/packages/notification/test/tooling-proposal-payload.test.ts +0 -212
  292. package/packages/observability/test/observability.test.ts +0 -1350
  293. package/packages/performance-optimizer/test/optimizer.test.ts +0 -267
  294. package/packages/project-analyzer/test/index.test.ts +0 -1719
  295. package/packages/prompt-compiler/test/prompt-compiler.test.ts +0 -813
  296. package/packages/prompt-versioning/test/versioning.test.ts +0 -112
  297. package/packages/provider-adapter-sdk/test/sdk.test.ts +0 -220
  298. package/packages/provider-router/test/provider-router.test.ts +0 -405
  299. package/packages/provider-selector/test/selector.test.ts +0 -192
  300. package/packages/providers/test/providers.test.ts +0 -225
  301. package/packages/qdrant-skills/test/collection-info.test.ts +0 -165
  302. package/packages/qdrant-skills/test/embedder-batch.test.ts +0 -184
  303. package/packages/qdrant-skills/test/embedder.test.ts +0 -97
  304. package/packages/quota-manager/test/quota.test.ts +0 -432
  305. package/packages/rate-limiter/test/limiter.test.ts +0 -128
  306. package/packages/react-vite-plugin/test/analyzer.test.ts +0 -139
  307. package/packages/relay/test/client.test.ts +0 -446
  308. package/packages/relay/test/relay-e2e.test.ts +0 -299
  309. package/packages/relay/test/relay-endpoint.test.ts +0 -278
  310. package/packages/release-manager/test/release.test.ts +0 -215
  311. package/packages/requirement-compiler/test/requirement-compiler.test.ts +0 -743
  312. package/packages/runtime/test/runtime-api.test.ts +0 -169
  313. package/packages/runtime/test/runtime.test.ts +0 -297
  314. package/packages/scheduler/test/scheduler.test.ts +0 -125
  315. package/packages/session/test/manager.test.ts +0 -233
  316. package/packages/shared-context/test/shared-context.test.ts +0 -114
  317. package/packages/skill-registry/test/registry.test.ts +0 -508
  318. package/packages/skills/test/init-skills.test.ts +0 -114
  319. package/packages/skills/test/remote-skills.test.ts +0 -360
  320. package/packages/skills/test/remote-source.test.ts +0 -248
  321. package/packages/skills/test/sanitize.test.ts +0 -250
  322. package/packages/skills/test/vector-indexing.test.ts +0 -205
  323. package/packages/skills/test/vector-schema.test.ts +0 -180
  324. package/packages/skills/test/vector-threshold.test.ts +0 -108
  325. package/packages/sprint-planner/test/planner.test.ts +0 -187
  326. package/packages/task-compiler/test/task-compiler.test.ts +0 -628
  327. package/packages/test-data-generator/test/generator.test.ts +0 -265
  328. package/packages/test-generator/test/generator.test.ts +0 -156
  329. package/packages/token-estimation/test/token-estimation.test.ts +0 -207
  330. package/packages/token-optimizer/test/optimizer.test.ts +0 -141
  331. package/packages/tooling-preference/tests/changed-files.test.ts +0 -124
  332. package/packages/tooling-preference/tests/detect.test.ts +0 -188
  333. package/packages/tooling-preference/tests/proposal.test.ts +0 -107
  334. package/packages/tooling-preference/tests/quality-check.test.ts +0 -272
  335. package/packages/tooling-preference/tests/registry.test.ts +0 -51
  336. package/packages/tooling-preference/tests/store.test.ts +0 -99
  337. package/packages/trajectory/test/store.test.ts +0 -250
  338. package/packages/tui/test/harness-footer.test.ts +0 -559
  339. package/packages/tui/test/harness-header.test.ts +0 -590
  340. package/packages/two-phase-review/test/classify.test.ts +0 -102
  341. package/packages/two-phase-review/test/helpers.ts +0 -72
  342. package/packages/two-phase-review/test/rules.test.ts +0 -150
  343. package/packages/two-phase-review/test/runtime.test.ts +0 -362
  344. package/packages/two-phase-review/test/scope.test.ts +0 -186
  345. package/packages/two-phase-review/test/signals.test.ts +0 -183
  346. package/packages/two-phase-review/test/state.test.ts +0 -201
  347. package/packages/wiki/test/basic.test.ts +0 -242
  348. package/packages/workspace-scanner/test/scanner.test.ts +0 -43
  349. package/packages/worktree/test/worktree.test.ts +0 -163
@@ -1,743 +0,0 @@
1
- /**
2
- * Requirement Compiler - Tests
3
- *
4
- * Tests for all 10 acceptance criteria:
5
- * 1. Explicit requirement remains explicit.
6
- * 2. Preference is not promoted to mandatory constraint.
7
- * 3. Contradictory statements create ambiguity.
8
- * 4. Acceptance criteria become Given/When/Then.
9
- * 5. Thai terminology remains in the glossary.
10
- * 6. Financial requirement receives risk tag.
11
- * 7. Empty requirement is rejected.
12
- * 8. Source references remain traceable.
13
- */
14
-
15
- import { describe, it } from "node:test";
16
- import assert from "node:assert";
17
- import {
18
- compileRequirement,
19
- extractStatements,
20
- classifyStatements,
21
- detectAmbiguities,
22
- normalizeAcceptanceCriteria,
23
- RequirementCompileError,
24
- RequirementCompileErrorCodes,
25
- DEFAULT_COMPILER_CONFIG,
26
- } from "../src/index.js";
27
- import type { RawRequirement, ExtractedStatement } from "../src/types.js";
28
-
29
- // --- Test utilities ------------------------------------------------------
30
-
31
- function makeRaw(
32
- text: string,
33
- overrides?: Partial<RawRequirement>,
34
- ): RawRequirement {
35
- return {
36
- id: "TEST-001",
37
- title: "Test Requirement",
38
- text,
39
- source: "tui",
40
- submittedBy: "test-user",
41
- submittedAt: "2026-07-11T00:00:00.000Z",
42
- ...overrides,
43
- };
44
- }
45
-
46
- async function compile(text: string, overrides?: Partial<RawRequirement>) {
47
- return compileRequirement(makeRaw(text, overrides));
48
- }
49
-
50
- // --- Test 1: Explicit requirement remains explicit ---------------------
51
-
52
- describe("Explicit requirement remains explicit", () => {
53
- it("goal statement becomes a goal", async () => {
54
- const result = await compile("The system must send an email notification");
55
- assert.ok(result.goals.length > 0, "Should have at least one goal");
56
- assert.strictEqual(
57
- result.goals[0].description.toLowerCase(),
58
- "the system must send an email notification",
59
- );
60
- });
61
-
62
- it("must-statement is classified as explicit behavior", () => {
63
- const stmt: ExtractedStatement = {
64
- id: "test",
65
- kind: "explicit_behavior",
66
- originalText: "The system must validate input",
67
- normalizedText: "the system must validate input",
68
- sourceRef: { source: "test", text: "The system must validate input" },
69
- };
70
- assert.strictEqual(stmt.kind, "explicit_behavior");
71
- });
72
- });
73
-
74
- // --- Test 2: Preference is NOT promoted to mandatory -------------------
75
-
76
- describe("Preference is not promoted to mandatory", () => {
77
- it("preference becomes non-blocking constraint", async () => {
78
- const result = await compile("We prefer to use React for the frontend");
79
- const prefConstraints = result.constraints.filter(
80
- (c) => c.kind === "preferable",
81
- );
82
- assert.ok(
83
- prefConstraints.length > 0,
84
- "Should have at least one preferable constraint",
85
- );
86
- assert.strictEqual(prefConstraints[0].blocking, false);
87
- });
88
-
89
- it("should-statement is classified as preference", async () => {
90
- const result = await compile("The button should be blue");
91
- assert.ok(
92
- result.constraints.some((c) => c.kind === "preferable"),
93
- "Should have a preference constraint",
94
- );
95
- });
96
- });
97
-
98
- // --- Test 3: Contradictory statements create ambiguity -----------------
99
-
100
- describe("Contradictory statements create ambiguity", () => {
101
- it("opposing must/must not creates contradiction ambiguity", async () => {
102
- // Contradictions are blocking → compiler throws UNRESOLVABLE_CONTRADICTION
103
- await assert.rejects(
104
- () =>
105
- compile(
106
- "The system must allow anonymous access.\nThe system must not allow anonymous access.",
107
- ),
108
- (error: unknown) => {
109
- if (error instanceof RequirementCompileError) {
110
- assert.strictEqual(
111
- error.code,
112
- RequirementCompileErrorCodes.UNRESOLVABLE_CONTRADICTION,
113
- );
114
- return true;
115
- }
116
- return false;
117
- },
118
- );
119
- });
120
-
121
- it("detectContradictions returns ambiguity for inverse statements", () => {
122
- const goals = [
123
- {
124
- id: "g1",
125
- originalText: "Allow anonymous users",
126
- normalizedText: "allow anonymous users",
127
- sourceRef: { source: "test", text: "Allow anonymous users" },
128
- },
129
- ] as unknown as ExtractedStatement[];
130
- const constraints = [
131
- {
132
- id: "c1",
133
- originalText: "Do not allow anonymous users",
134
- normalizedText: "do not allow anonymous users",
135
- sourceRef: { source: "test", text: "Do not allow anonymous users" },
136
- },
137
- ] as unknown as ExtractedStatement[];
138
-
139
- const ambiguities = detectAmbiguities(
140
- {
141
- statements: [...goals, ...constraints],
142
- goals,
143
- constraints,
144
- preferences: [],
145
- implementationSuggestions: [],
146
- terminologyMentions: [],
147
- actorMentions: [],
148
- acceptanceCriterionStatements: [],
149
- assumptions: [],
150
- unknown: [],
151
- },
152
- DEFAULT_COMPILER_CONFIG,
153
- );
154
-
155
- const contradictions = ambiguities.filter(
156
- (a) => a.category === "contradiction",
157
- );
158
- assert.ok(contradictions.length > 0);
159
- });
160
- });
161
-
162
- // --- Test 4: Acceptance criteria normalize to Given/When/Then -----------
163
-
164
- describe("Acceptance criteria normalize to Given/When/Then", () => {
165
- it("Given/When/Then statement parses correctly", () => {
166
- const stmts: ExtractedStatement[] = [
167
- {
168
- id: "test",
169
- kind: "acceptance_criterion",
170
- originalText:
171
- "Given a logged-in user, when they click Save, then the form is saved",
172
- normalizedText:
173
- "given a logged-in user, when they click save, then the form is saved",
174
- sourceRef: {
175
- source: "test",
176
- text: "Given a logged-in user, when they click Save, then the form is saved",
177
- },
178
- },
179
- ];
180
-
181
- const criteria = normalizeAcceptanceCriteria(stmts);
182
- assert.strictEqual(criteria.length, 1);
183
- assert.strictEqual(criteria[0].given.toLowerCase(), "a logged-in user");
184
- assert.ok(criteria[0].when.toLowerCase().includes("click"));
185
- assert.ok(criteria[0].outcome.length > 0);
186
- });
187
-
188
- it("Natural language statement is inferred to Given/When/Then", () => {
189
- const stmts: ExtractedStatement[] = [
190
- {
191
- id: "test",
192
- kind: "explicit_behavior",
193
- originalText: "The system must save the form data",
194
- normalizedText: "the system must save the form data",
195
- sourceRef: {
196
- source: "test",
197
- text: "The system must save the form data",
198
- },
199
- },
200
- ];
201
-
202
- const criteria = normalizeAcceptanceCriteria(stmts);
203
- assert.strictEqual(criteria.length, 1);
204
- assert.ok(criteria[0].given.length > 0);
205
- assert.ok(criteria[0].when.length > 0);
206
- assert.ok(criteria[0].outcome.length > 0);
207
- });
208
-
209
- it("automatable flag is set based on content", () => {
210
- const stmts: ExtractedStatement[] = [
211
- {
212
- id: "test1",
213
- kind: "acceptance_criterion",
214
- originalText: "Then the API returns HTTP 200",
215
- normalizedText: "then the api returns http 200",
216
- sourceRef: { source: "test", text: "Then the API returns HTTP 200" },
217
- },
218
- {
219
- id: "test2",
220
- kind: "acceptance_criterion",
221
- originalText: "Then the UI looks good",
222
- normalizedText: "then the ui looks good",
223
- sourceRef: { source: "test", text: "Then the UI looks good" },
224
- },
225
- ];
226
-
227
- const criteria = normalizeAcceptanceCriteria(stmts);
228
- const apiCriterion = criteria.find((c) =>
229
- c.originalText?.includes("HTTP 200"),
230
- );
231
- const uiCriterion = criteria.find((c) =>
232
- c.originalText?.includes("looks good"),
233
- );
234
- assert.strictEqual(apiCriterion?.automatable, true);
235
- assert.strictEqual(uiCriterion?.automatable, false);
236
- });
237
- });
238
-
239
- // --- Test 5: Thai terminology preserved in glossary --------------------
240
-
241
- describe("Thai terminology remains in glossary", () => {
242
- it("Thai term is preserved in terminology", async () => {
243
- const result = await compile(
244
- "ระบบต้องสร้างใบแจ้งหนี้\nThe invoice must include the tax amount",
245
- );
246
- assert.ok(
247
- result.terminology.length > 0,
248
- "Should have at least one terminology entry",
249
- );
250
- const thaiEntry = result.terminology.find((t) => t.language === "th");
251
- assert.ok(thaiEntry, "Should have a Thai-language terminology entry");
252
- });
253
-
254
- it("Thai detection works correctly", () => {
255
- const stmts: ExtractedStatement[] = [
256
- {
257
- id: "test",
258
- kind: "terminology",
259
- originalText: "ใบกำกับภาษี",
260
- normalizedText: "ใบกำกับภาษี",
261
- sourceRef: { source: "test", text: "ใบกำกับภาษี" },
262
- },
263
- ];
264
- const [stmt] = stmts;
265
- const hasThai = /[ก-๙]/.test(stmt.originalText);
266
- assert.strictEqual(hasThai, true);
267
- });
268
- });
269
-
270
- // --- Test 6: Financial requirement receives risk tag ------------------
271
-
272
- describe("Financial requirement receives risk tag", () => {
273
- it("payment keyword triggers financial risk", async () => {
274
- const result = await compile(
275
- "The system must process payment via credit card",
276
- );
277
- const financialRisks = result.riskTags.filter(
278
- (r) => r.risk === "financial",
279
- );
280
- assert.ok(financialRisks.length > 0, "Should have financial risk tag");
281
- assert.ok(result.riskTags.some((r) => r.description.includes("payment")));
282
- });
283
-
284
- it("tax-related keyword triggers financial risk", async () => {
285
- const result = await compile(
286
- "Calculate the ภาษีมูลค่าเพิ่ม for each transaction",
287
- );
288
- assert.ok(
289
- result.riskTags.some((r) => r.risk === "financial"),
290
- "Should detect financial risk from Thai tax term",
291
- );
292
- });
293
-
294
- it("authentication keyword triggers auth risk", async () => {
295
- const result = await compile("Users must login with OAuth credentials");
296
- assert.ok(
297
- result.riskTags.some((r) => r.risk === "authentication"),
298
- "Should have authentication risk tag",
299
- );
300
- });
301
- });
302
-
303
- // --- Test 7: Empty requirement is rejected ---------------------------
304
-
305
- describe("Empty requirement is rejected", () => {
306
- it("rejects empty text requirement", async () => {
307
- await assert.rejects(
308
- () => compile(" ", { text: "" }),
309
- (error: unknown) => {
310
- if (error instanceof RequirementCompileError) {
311
- assert.strictEqual(
312
- error.code,
313
- RequirementCompileErrorCodes.EMPTY_REQUIREMENT,
314
- );
315
- return true;
316
- }
317
- return false;
318
- },
319
- );
320
- });
321
-
322
- it("rejects requirement with no goals or constraints", async () => {
323
- // Just whitespace or nothing useful
324
- await assert.rejects(
325
- () => compile("maybe perhaps possibly"),
326
- (error: unknown) => {
327
- if (error instanceof RequirementCompileError) {
328
- assert.strictEqual(
329
- error.code,
330
- RequirementCompileErrorCodes.EMPTY_REQUIREMENT,
331
- );
332
- return true;
333
- }
334
- return false;
335
- },
336
- );
337
- });
338
-
339
- it("accepts requirement with at least a title but no text", async () => {
340
- const result = await compile("Process user data", {
341
- text: "",
342
- title: "Process user data",
343
- });
344
- assert.strictEqual(result.goals.length, 1);
345
- });
346
- });
347
-
348
- // --- Test 8: Source references remain traceable -------------------------
349
-
350
- describe("Source references remain traceable", () => {
351
- it("every goal has a source reference", async () => {
352
- const result = await compile("Add a login form to the page");
353
- for (const goal of result.goals) {
354
- assert.ok(
355
- goal.sourceRefs.length > 0,
356
- `Goal "${goal.description}" should have source refs`,
357
- );
358
- assert.strictEqual(
359
- goal.sourceRefs[0].source,
360
- "tui",
361
- "Source should be 'tui'",
362
- );
363
- }
364
- });
365
-
366
- it("every constraint has a source reference", async () => {
367
- const result = await compile("Do not allow SQL injection");
368
- for (const constraint of result.constraints) {
369
- assert.ok(
370
- constraint.sourceRefs.length > 0,
371
- "Constraint should have source refs",
372
- );
373
- }
374
- });
375
-
376
- it("every ambiguity has evidence source references", async () => {
377
- // Use a text that creates vagueness ambiguity (not contradiction) so
378
- // the compiler returns normally instead of throwing
379
- const result = await compile(
380
- "The page should be maybe good.\nUsers can access the maybe system.",
381
- );
382
- for (const ambiguity of result.ambiguities) {
383
- assert.ok(
384
- ambiguity.evidence.length > 0,
385
- `Ambiguity "${ambiguity.question}" should have evidence`,
386
- );
387
- }
388
- });
389
-
390
- it("acceptance criteria preserve original text", async () => {
391
- const stmts: ExtractedStatement[] = [
392
- {
393
- id: "test",
394
- kind: "acceptance_criterion",
395
- originalText:
396
- "Given admin, when they delete user, then confirmation appears",
397
- normalizedText:
398
- "given admin, when they delete user, then confirmation appears",
399
- sourceRef: { source: "test", text: "Given admin..." },
400
- },
401
- ];
402
-
403
- const criteria = normalizeAcceptanceCriteria(stmts);
404
- assert.strictEqual(
405
- criteria[0].originalText,
406
- "Given admin, when they delete user, then confirmation appears",
407
- );
408
- });
409
- });
410
-
411
- // --- Extractor tests -----------------------------------------------------
412
-
413
- describe("Statement extraction", () => {
414
- it("extracts numbered list items", () => {
415
- const raw = makeRaw("1. Add user\n2. Delete user\n3. Edit user");
416
- const result = extractStatements(raw);
417
- assert.ok(result.statements.length >= 3);
418
- });
419
-
420
- it("extracts bullet points", () => {
421
- const raw = makeRaw("- First item\n- Second item\n- Third item");
422
- const result = extractStatements(raw);
423
- assert.ok(result.statements.length >= 3);
424
- });
425
-
426
- it("includes title as first statement", () => {
427
- const raw = makeRaw("The system must work", {
428
- title: "My Custom Title",
429
- });
430
- const result = extractStatements(raw);
431
- assert.strictEqual(result.statements[0]?.id, "stmt-title");
432
- assert.strictEqual(result.statements[0]?.originalText, "My Custom Title");
433
- });
434
- });
435
-
436
- // --- Classifier tests ---------------------------------------------------
437
-
438
- describe("Statement classification", () => {
439
- it("classifies must statements as explicit_behavior", () => {
440
- const stmt: ExtractedStatement = {
441
- id: "test",
442
- kind: "unknown",
443
- originalText: "The system must validate input",
444
- normalizedText: "the system must validate input",
445
- sourceRef: { source: "test", text: "The system must validate input" },
446
- };
447
-
448
- const result = classifyStatements([stmt], DEFAULT_COMPILER_CONFIG);
449
- assert.strictEqual(result.goals.length, 1);
450
- });
451
-
452
- it("classifies do not statements as constraints", () => {
453
- const stmt: ExtractedStatement = {
454
- id: "test",
455
- kind: "unknown",
456
- originalText: "Do not expose API keys",
457
- normalizedText: "do not expose api keys",
458
- sourceRef: { source: "test", text: "Do not expose API keys" },
459
- };
460
-
461
- const result = classifyStatements([stmt], DEFAULT_COMPILER_CONFIG);
462
- assert.strictEqual(result.constraints.length, 1);
463
- });
464
-
465
- it("classifies assumption statements", () => {
466
- const stmt: ExtractedStatement = {
467
- id: "test",
468
- kind: "unknown",
469
- originalText: "Assume the user is authenticated",
470
- normalizedText: "assume the user is authenticated",
471
- sourceRef: { source: "test", text: "Assume the user is authenticated" },
472
- };
473
-
474
- const result = classifyStatements([stmt], DEFAULT_COMPILER_CONFIG);
475
- assert.strictEqual(result.assumptions.length, 1);
476
- });
477
-
478
- it("classifies Given/When/Then as acceptance criteria", () => {
479
- const stmt: ExtractedStatement = {
480
- id: "test",
481
- kind: "unknown",
482
- originalText: "Given a user, when they submit, then it saves",
483
- normalizedText: "given a user, when they submit, then it saves",
484
- sourceRef: {
485
- source: "test",
486
- text: "Given a user, when they submit, then it saves",
487
- },
488
- };
489
-
490
- const result = classifyStatements([stmt], DEFAULT_COMPILER_CONFIG);
491
- assert.strictEqual(result.acceptanceCriterionStatements.length, 1);
492
- });
493
- });
494
-
495
- // --- Risk detection tests ------------------------------------------------
496
-
497
- describe("Risk detection", () => {
498
- it("detects destructive operation risk", async () => {
499
- const result = await compile("The system must delete all user data");
500
- assert.ok(result.riskTags.some((r) => r.risk === "destructive_operation"));
501
- });
502
-
503
- it("detects privacy risk", async () => {
504
- const result = await compile(
505
- "Collect personal data from users for analysis",
506
- );
507
- assert.ok(result.riskTags.some((r) => r.risk === "privacy"));
508
- });
509
-
510
- it("detects regulatory risk", async () => {
511
- const result = await compile(
512
- "Ensure compliance with Thai PDPA regulations",
513
- );
514
- assert.ok(result.riskTags.some((r) => r.risk === "regulatory"));
515
- });
516
-
517
- it("deduplicates risk tags for same statement", async () => {
518
- const result = await compile(
519
- "Payment data must be encrypted and stored securely",
520
- );
521
- const paymentRisks = result.riskTags.filter(
522
- (r) => r.affectedId === result.riskTags[0]?.affectedId,
523
- );
524
- // Should not have duplicate entries for same statement
525
- const uniqueRisks = new Set(paymentRisks.map((r) => r.risk));
526
- assert.ok(uniqueRisks.size <= 2); // financial + privacy
527
- });
528
- });
529
-
530
- // --- Ambiguity detection tests -------------------------------------------
531
-
532
- describe("Ambiguity detection", () => {
533
- it("detects vague terms", () => {
534
- const stmts: ExtractedStatement[] = [
535
- {
536
- id: "test",
537
- kind: "unknown",
538
- originalText: "The system must be fast and reliable",
539
- normalizedText: "the system must be fast and reliable",
540
- sourceRef: {
541
- source: "test",
542
- text: "The system must be fast and reliable",
543
- },
544
- },
545
- ];
546
-
547
- const ambiguities = detectAmbiguities(
548
- {
549
- statements: stmts,
550
- goals: stmts,
551
- constraints: [],
552
- preferences: [],
553
- implementationSuggestions: [],
554
- terminologyMentions: [],
555
- actorMentions: [],
556
- acceptanceCriterionStatements: [],
557
- assumptions: [],
558
- unknown: [],
559
- },
560
- DEFAULT_COMPILER_CONFIG,
561
- );
562
-
563
- assert.ok(
564
- ambiguities.some((a) => a.category === "vague_term"),
565
- "Should detect vague term",
566
- );
567
- });
568
-
569
- it("detects missing actor", () => {
570
- const stmts: ExtractedStatement[] = [
571
- {
572
- id: "test",
573
- kind: "goal",
574
- originalText: "Who should approve the request?",
575
- normalizedText: "who should approve the request?",
576
- sourceRef: {
577
- source: "test",
578
- text: "Who should approve the request?",
579
- },
580
- },
581
- ];
582
-
583
- const ambiguities = detectAmbiguities(
584
- {
585
- statements: stmts,
586
- goals: stmts,
587
- constraints: [],
588
- preferences: [],
589
- implementationSuggestions: [],
590
- terminologyMentions: [],
591
- actorMentions: [],
592
- acceptanceCriterionStatements: [],
593
- assumptions: [],
594
- unknown: [],
595
- },
596
- DEFAULT_COMPILER_CONFIG,
597
- );
598
-
599
- assert.ok(
600
- ambiguities.some(
601
- (a) => a.category === "missing_actor" && a.blocking === true,
602
- ),
603
- "Should detect missing actor",
604
- );
605
- });
606
-
607
- it("deduplicates ambiguities by question text", () => {
608
- const stmts: ExtractedStatement[] = [
609
- {
610
- id: "test1",
611
- kind: "unknown",
612
- originalText: "The system should be secure",
613
- normalizedText: "the system should be secure",
614
- sourceRef: { source: "test", text: "The system should be secure" },
615
- },
616
- {
617
- id: "test2",
618
- kind: "unknown",
619
- originalText: "The system should be secure",
620
- normalizedText: "the system should be secure",
621
- sourceRef: { source: "test", text: "The system should be secure" },
622
- },
623
- ];
624
-
625
- const ambiguities = detectAmbiguities(
626
- {
627
- statements: stmts,
628
- goals: [],
629
- constraints: [],
630
- preferences: [],
631
- implementationSuggestions: [],
632
- terminologyMentions: [],
633
- actorMentions: [],
634
- acceptanceCriterionStatements: [],
635
- assumptions: [],
636
- unknown: stmts,
637
- },
638
- DEFAULT_COMPILER_CONFIG,
639
- );
640
-
641
- // Should de-duplicate
642
- const secureAmbiguities = ambiguities.filter((a) =>
643
- a.question.includes("secure"),
644
- );
645
- assert.ok(secureAmbiguities.length <= 1, "Should deduplicate");
646
- });
647
- });
648
-
649
- // --- Workflow tests ------------------------------------------------------
650
-
651
- describe("Workflow extraction", () => {
652
- it("groups multiple goals into a workflow", async () => {
653
- const result = await compile(
654
- "1. Create user account\n2. Send verification email\n3. Display user dashboard",
655
- );
656
- assert.ok(result.workflows.length > 0, "Should have at least one workflow");
657
- assert.ok(
658
- result.workflows[0].steps.length >= 2,
659
- "Workflow should have multiple steps",
660
- );
661
- });
662
- });
663
-
664
- // --- Actor extraction tests ---------------------------------------------
665
-
666
- describe("Actor extraction", () => {
667
- it("extracts actors from statements", async () => {
668
- const result = await compile(
669
- "The admin can delete any user account.\nThe user can edit their own profile.",
670
- );
671
- assert.ok(result.actors.length > 0, "Should detect at least one actor");
672
- const actorNames = result.actors.map((a) => a.name.toLowerCase());
673
- assert.ok(
674
- actorNames.some((n) => n.includes("admin") || n.includes("user")),
675
- "Should detect admin or user actor",
676
- );
677
- });
678
- });
679
-
680
- // --- Error handling tests ----------------------------------------------
681
-
682
- describe("Error handling", () => {
683
- it("RequirementCompileError has correct properties", () => {
684
- const error = new RequirementCompileError(
685
- RequirementCompileErrorCodes.EMPTY_REQUIREMENT,
686
- "Test error message",
687
- { extra: "info" },
688
- );
689
- assert.strictEqual(error.code, "EMPTY_REQUIREMENT");
690
- assert.strictEqual(error.message, "Test error message");
691
- assert.strictEqual(error.details?.extra, "info");
692
- assert.strictEqual(error.name, "RequirementCompileError");
693
- });
694
-
695
- it("unresolvable contradiction throws error", async () => {
696
- await assert.rejects(
697
- () =>
698
- compile(
699
- "The system must allow public access.\nThe system must not allow public access.",
700
- ),
701
- (error: unknown) => {
702
- if (error instanceof RequirementCompileError) {
703
- assert.strictEqual(
704
- error.code,
705
- RequirementCompileErrorCodes.UNRESOLVABLE_CONTRADICTION,
706
- );
707
- return true;
708
- }
709
- return false;
710
- },
711
- );
712
- });
713
- });
714
-
715
- // --- Multilingual tests -------------------------------------------------
716
-
717
- describe("Multilingual handling", () => {
718
- it("preserves Thai business terms", async () => {
719
- const result = await compile(
720
- "ระบบต้องสร้างใบเสร็จรับเงิน\nThe receipt must include ยอดเงินรวม",
721
- );
722
- assert.ok(
723
- result.terminology.length > 0,
724
- "Should preserve Thai terms in glossary",
725
- );
726
- });
727
-
728
- it("status is 'ready' for non-blocking ambiguities", async () => {
729
- const result = await compile(
730
- "The system should be fast.\nThe system should be secure.",
731
- );
732
- // Vague terms create non-blocking ambiguities
733
- assert.ok(
734
- result.status === "ready" || result.status === "needs_human",
735
- "Status should be ready or needs_human",
736
- );
737
- });
738
-
739
- it("status is 'needs_human' for blocking ambiguities", async () => {
740
- const result = await compile("Who should access the admin panel?");
741
- assert.strictEqual(result.status, "needs_human");
742
- });
743
- });