@buildanagent/harness 0.0.0-stage → 0.1.0-alpha.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (397) hide show
  1. package/LICENSE +54 -0
  2. package/LICENSE-APACHE +202 -0
  3. package/LICENSE-MIT +21 -0
  4. package/README.md +822 -2
  5. package/dist/ablation.d.ts +2 -0
  6. package/dist/ablation.js +3 -0
  7. package/dist/ablation.js.map +1 -0
  8. package/dist/completion/check.d.ts +64 -0
  9. package/dist/completion/check.js +152 -0
  10. package/dist/completion/check.js.map +1 -0
  11. package/dist/completion/checks.d.ts +45 -0
  12. package/dist/completion/checks.js +173 -0
  13. package/dist/completion/checks.js.map +1 -0
  14. package/dist/completion/flags.d.ts +25 -0
  15. package/dist/completion/flags.js +87 -0
  16. package/dist/completion/flags.js.map +1 -0
  17. package/dist/completion/index.d.ts +8 -0
  18. package/dist/completion/index.js +9 -0
  19. package/dist/completion/index.js.map +1 -0
  20. package/dist/completion/snapshot.d.ts +33 -0
  21. package/dist/completion/snapshot.js +83 -0
  22. package/dist/completion/snapshot.js.map +1 -0
  23. package/dist/context/cap.d.ts +32 -0
  24. package/dist/context/cap.js +50 -0
  25. package/dist/context/cap.js.map +1 -0
  26. package/dist/context/estimate.d.ts +18 -0
  27. package/dist/context/estimate.js +20 -0
  28. package/dist/context/estimate.js.map +1 -0
  29. package/dist/context/file-spill.d.ts +15 -0
  30. package/dist/context/file-spill.js +40 -0
  31. package/dist/context/file-spill.js.map +1 -0
  32. package/dist/context/index.d.ts +10 -0
  33. package/dist/context/index.js +10 -0
  34. package/dist/context/index.js.map +1 -0
  35. package/dist/context/mask.d.ts +27 -0
  36. package/dist/context/mask.js +71 -0
  37. package/dist/context/mask.js.map +1 -0
  38. package/dist/context/mid-turn.d.ts +40 -0
  39. package/dist/context/mid-turn.js +82 -0
  40. package/dist/context/mid-turn.js.map +1 -0
  41. package/dist/context/policy.d.ts +9 -0
  42. package/dist/context/policy.js +140 -0
  43. package/dist/context/policy.js.map +1 -0
  44. package/dist/context/spill-ledger.d.ts +25 -0
  45. package/dist/context/spill-ledger.js +54 -0
  46. package/dist/context/spill-ledger.js.map +1 -0
  47. package/dist/context/spill.d.ts +10 -0
  48. package/dist/context/spill.js +18 -0
  49. package/dist/context/spill.js.map +1 -0
  50. package/dist/context/summarize.d.ts +53 -0
  51. package/dist/context/summarize.js +204 -0
  52. package/dist/context/summarize.js.map +1 -0
  53. package/dist/context/summary-template.d.ts +29 -0
  54. package/dist/context/summary-template.js +69 -0
  55. package/dist/context/summary-template.js.map +1 -0
  56. package/dist/context/types.d.ts +150 -0
  57. package/dist/context/types.js +2 -0
  58. package/dist/context/types.js.map +1 -0
  59. package/dist/context/write-cap.d.ts +19 -0
  60. package/dist/context/write-cap.js +41 -0
  61. package/dist/context/write-cap.js.map +1 -0
  62. package/dist/create-harness.d.ts +7 -0
  63. package/dist/create-harness.js +21 -0
  64. package/dist/create-harness.js.map +1 -0
  65. package/dist/credentials/addresses.d.ts +14 -0
  66. package/dist/credentials/addresses.js +144 -0
  67. package/dist/credentials/addresses.js.map +1 -0
  68. package/dist/credentials/allowlist.d.ts +54 -0
  69. package/dist/credentials/allowlist.js +134 -0
  70. package/dist/credentials/allowlist.js.map +1 -0
  71. package/dist/credentials/egress-policy.d.ts +69 -0
  72. package/dist/credentials/egress-policy.js +170 -0
  73. package/dist/credentials/egress-policy.js.map +1 -0
  74. package/dist/credentials/egress-proxy.d.ts +82 -0
  75. package/dist/credentials/egress-proxy.js +650 -0
  76. package/dist/credentials/egress-proxy.js.map +1 -0
  77. package/dist/credentials/git-route.d.ts +68 -0
  78. package/dist/credentials/git-route.js +288 -0
  79. package/dist/credentials/git-route.js.map +1 -0
  80. package/dist/credentials/index.d.ts +13 -0
  81. package/dist/credentials/index.js +14 -0
  82. package/dist/credentials/index.js.map +1 -0
  83. package/dist/credentials/scrub.d.ts +23 -0
  84. package/dist/credentials/scrub.js +115 -0
  85. package/dist/credentials/scrub.js.map +1 -0
  86. package/dist/errors.d.ts +60 -0
  87. package/dist/errors.js +67 -0
  88. package/dist/errors.js.map +1 -0
  89. package/dist/extensions/compose.d.ts +27 -0
  90. package/dist/extensions/compose.js +83 -0
  91. package/dist/extensions/compose.js.map +1 -0
  92. package/dist/extensions/context-files-node.d.ts +28 -0
  93. package/dist/extensions/context-files-node.js +74 -0
  94. package/dist/extensions/context-files-node.js.map +1 -0
  95. package/dist/extensions/context-files.d.ts +68 -0
  96. package/dist/extensions/context-files.js +214 -0
  97. package/dist/extensions/context-files.js.map +1 -0
  98. package/dist/extensions/digest.d.ts +6 -0
  99. package/dist/extensions/digest.js +68 -0
  100. package/dist/extensions/digest.js.map +1 -0
  101. package/dist/extensions/index.d.ts +10 -0
  102. package/dist/extensions/index.js +10 -0
  103. package/dist/extensions/index.js.map +1 -0
  104. package/dist/extensions/load.d.ts +42 -0
  105. package/dist/extensions/load.js +211 -0
  106. package/dist/extensions/load.js.map +1 -0
  107. package/dist/extensions/lock.d.ts +8 -0
  108. package/dist/extensions/lock.js +95 -0
  109. package/dist/extensions/lock.js.map +1 -0
  110. package/dist/extensions/node.d.ts +10 -0
  111. package/dist/extensions/node.js +11 -0
  112. package/dist/extensions/node.js.map +1 -0
  113. package/dist/extensions/project-dirs.d.ts +24 -0
  114. package/dist/extensions/project-dirs.js +97 -0
  115. package/dist/extensions/project-dirs.js.map +1 -0
  116. package/dist/extensions/skills-node.d.ts +34 -0
  117. package/dist/extensions/skills-node.js +123 -0
  118. package/dist/extensions/skills-node.js.map +1 -0
  119. package/dist/extensions/skills.d.ts +51 -0
  120. package/dist/extensions/skills.js +175 -0
  121. package/dist/extensions/skills.js.map +1 -0
  122. package/dist/extensions/trust-file.d.ts +3 -0
  123. package/dist/extensions/trust-file.js +62 -0
  124. package/dist/extensions/trust-file.js.map +1 -0
  125. package/dist/extensions/trust-store-node.d.ts +10 -0
  126. package/dist/extensions/trust-store-node.js +33 -0
  127. package/dist/extensions/trust-store-node.js.map +1 -0
  128. package/dist/extensions/types.d.ts +42 -0
  129. package/dist/extensions/types.js +2 -0
  130. package/dist/extensions/types.js.map +1 -0
  131. package/dist/harness.d.ts +156 -0
  132. package/dist/harness.js +2 -0
  133. package/dist/harness.js.map +1 -0
  134. package/dist/index.d.ts +4 -0
  135. package/dist/index.js +5 -0
  136. package/dist/index.js.map +1 -0
  137. package/dist/mcp/connection.d.ts +22 -0
  138. package/dist/mcp/connection.js +267 -0
  139. package/dist/mcp/connection.js.map +1 -0
  140. package/dist/mcp/content.d.ts +27 -0
  141. package/dist/mcp/content.js +177 -0
  142. package/dist/mcp/content.js.map +1 -0
  143. package/dist/mcp/errors.d.ts +19 -0
  144. package/dist/mcp/errors.js +21 -0
  145. package/dist/mcp/errors.js.map +1 -0
  146. package/dist/mcp/index.d.ts +10 -0
  147. package/dist/mcp/index.js +10 -0
  148. package/dist/mcp/index.js.map +1 -0
  149. package/dist/mcp/manager.d.ts +7 -0
  150. package/dist/mcp/manager.js +173 -0
  151. package/dist/mcp/manager.js.map +1 -0
  152. package/dist/mcp/record.d.ts +7 -0
  153. package/dist/mcp/record.js +20 -0
  154. package/dist/mcp/record.js.map +1 -0
  155. package/dist/mcp/stdio.d.ts +39 -0
  156. package/dist/mcp/stdio.js +382 -0
  157. package/dist/mcp/stdio.js.map +1 -0
  158. package/dist/mcp/types.d.ts +172 -0
  159. package/dist/mcp/types.js +2 -0
  160. package/dist/mcp/types.js.map +1 -0
  161. package/dist/memory/index.d.ts +2 -0
  162. package/dist/memory/index.js +3 -0
  163. package/dist/memory/index.js.map +1 -0
  164. package/dist/permissions/default-rules.d.ts +7 -0
  165. package/dist/permissions/default-rules.js +42 -0
  166. package/dist/permissions/default-rules.js.map +1 -0
  167. package/dist/permissions/errors.d.ts +11 -0
  168. package/dist/permissions/errors.js +14 -0
  169. package/dist/permissions/errors.js.map +1 -0
  170. package/dist/permissions/index.d.ts +9 -0
  171. package/dist/permissions/index.js +9 -0
  172. package/dist/permissions/index.js.map +1 -0
  173. package/dist/permissions/match.d.ts +33 -0
  174. package/dist/permissions/match.js +287 -0
  175. package/dist/permissions/match.js.map +1 -0
  176. package/dist/permissions/pipeline.d.ts +9 -0
  177. package/dist/permissions/pipeline.js +235 -0
  178. package/dist/permissions/pipeline.js.map +1 -0
  179. package/dist/permissions/rules.d.ts +22 -0
  180. package/dist/permissions/rules.js +74 -0
  181. package/dist/permissions/rules.js.map +1 -0
  182. package/dist/permissions/shadow.d.ts +5 -0
  183. package/dist/permissions/shadow.js +22 -0
  184. package/dist/permissions/shadow.js.map +1 -0
  185. package/dist/permissions/types.d.ts +104 -0
  186. package/dist/permissions/types.js +2 -0
  187. package/dist/permissions/types.js.map +1 -0
  188. package/dist/sandbox/base.d.ts +45 -0
  189. package/dist/sandbox/base.js +74 -0
  190. package/dist/sandbox/base.js.map +1 -0
  191. package/dist/sandbox/docker/index.d.ts +41 -0
  192. package/dist/sandbox/docker/index.js +497 -0
  193. package/dist/sandbox/docker/index.js.map +1 -0
  194. package/dist/sandbox/errors.d.ts +44 -0
  195. package/dist/sandbox/errors.js +57 -0
  196. package/dist/sandbox/errors.js.map +1 -0
  197. package/dist/sandbox/host-files.d.ts +65 -0
  198. package/dist/sandbox/host-files.js +258 -0
  199. package/dist/sandbox/host-files.js.map +1 -0
  200. package/dist/sandbox/index.d.ts +10 -0
  201. package/dist/sandbox/index.js +10 -0
  202. package/dist/sandbox/index.js.map +1 -0
  203. package/dist/sandbox/none.d.ts +17 -0
  204. package/dist/sandbox/none.js +108 -0
  205. package/dist/sandbox/none.js.map +1 -0
  206. package/dist/sandbox/policy.d.ts +49 -0
  207. package/dist/sandbox/policy.js +149 -0
  208. package/dist/sandbox/policy.js.map +1 -0
  209. package/dist/sandbox/process.d.ts +61 -0
  210. package/dist/sandbox/process.js +253 -0
  211. package/dist/sandbox/process.js.map +1 -0
  212. package/dist/sandbox/spawn-env.d.ts +20 -0
  213. package/dist/sandbox/spawn-env.js +128 -0
  214. package/dist/sandbox/spawn-env.js.map +1 -0
  215. package/dist/sandbox/srt/index.d.ts +38 -0
  216. package/dist/sandbox/srt/index.js +283 -0
  217. package/dist/sandbox/srt/index.js.map +1 -0
  218. package/dist/sandbox/srt/settings.d.ts +60 -0
  219. package/dist/sandbox/srt/settings.js +84 -0
  220. package/dist/sandbox/srt/settings.js.map +1 -0
  221. package/dist/sandbox/types.d.ts +125 -0
  222. package/dist/sandbox/types.js +6 -0
  223. package/dist/sandbox/types.js.map +1 -0
  224. package/dist/server/answers.d.ts +16 -0
  225. package/dist/server/answers.js +43 -0
  226. package/dist/server/answers.js.map +1 -0
  227. package/dist/server/connection.d.ts +99 -0
  228. package/dist/server/connection.js +309 -0
  229. package/dist/server/connection.js.map +1 -0
  230. package/dist/server/dispatcher.d.ts +86 -0
  231. package/dist/server/dispatcher.js +800 -0
  232. package/dist/server/dispatcher.js.map +1 -0
  233. package/dist/server/index.d.ts +13 -0
  234. package/dist/server/index.js +12 -0
  235. package/dist/server/index.js.map +1 -0
  236. package/dist/server/local-transport.d.ts +44 -0
  237. package/dist/server/local-transport.js +103 -0
  238. package/dist/server/local-transport.js.map +1 -0
  239. package/dist/server/outbox.d.ts +31 -0
  240. package/dist/server/outbox.js +130 -0
  241. package/dist/server/outbox.js.map +1 -0
  242. package/dist/server/params.d.ts +25 -0
  243. package/dist/server/params.js +112 -0
  244. package/dist/server/params.js.map +1 -0
  245. package/dist/server/protocol.schema.json +2448 -0
  246. package/dist/server/rpc-session.d.ts +43 -0
  247. package/dist/server/rpc-session.js +167 -0
  248. package/dist/server/rpc-session.js.map +1 -0
  249. package/dist/server/stdio-streams.d.ts +67 -0
  250. package/dist/server/stdio-streams.js +218 -0
  251. package/dist/server/stdio-streams.js.map +1 -0
  252. package/dist/server/stdio.d.ts +59 -0
  253. package/dist/server/stdio.js +189 -0
  254. package/dist/server/stdio.js.map +1 -0
  255. package/dist/server/websocket.d.ts +106 -0
  256. package/dist/server/websocket.js +327 -0
  257. package/dist/server/websocket.js.map +1 -0
  258. package/dist/session/approvals.d.ts +81 -0
  259. package/dist/session/approvals.js +217 -0
  260. package/dist/session/approvals.js.map +1 -0
  261. package/dist/session/code-call-log.d.ts +42 -0
  262. package/dist/session/code-call-log.js +63 -0
  263. package/dist/session/code-call-log.js.map +1 -0
  264. package/dist/session/code-call-result.d.ts +19 -0
  265. package/dist/session/code-call-result.js +95 -0
  266. package/dist/session/code-call-result.js.map +1 -0
  267. package/dist/session/code-call.d.ts +49 -0
  268. package/dist/session/code-call.js +345 -0
  269. package/dist/session/code-call.js.map +1 -0
  270. package/dist/session/effect-scope.d.ts +11 -0
  271. package/dist/session/effect-scope.js +10 -0
  272. package/dist/session/effect-scope.js.map +1 -0
  273. package/dist/session/errors.d.ts +19 -0
  274. package/dist/session/errors.js +27 -0
  275. package/dist/session/errors.js.map +1 -0
  276. package/dist/session/file-index.d.ts +8 -0
  277. package/dist/session/file-index.js +70 -0
  278. package/dist/session/file-index.js.map +1 -0
  279. package/dist/session/file-key-store.d.ts +16 -0
  280. package/dist/session/file-key-store.js +169 -0
  281. package/dist/session/file-key-store.js.map +1 -0
  282. package/dist/session/file-lock.d.ts +52 -0
  283. package/dist/session/file-lock.js +324 -0
  284. package/dist/session/file-lock.js.map +1 -0
  285. package/dist/session/index.d.ts +22 -0
  286. package/dist/session/index.js +20 -0
  287. package/dist/session/index.js.map +1 -0
  288. package/dist/session/jsonl-store.d.ts +37 -0
  289. package/dist/session/jsonl-store.js +386 -0
  290. package/dist/session/jsonl-store.js.map +1 -0
  291. package/dist/session/jsonl.d.ts +9 -0
  292. package/dist/session/jsonl.js +10 -0
  293. package/dist/session/jsonl.js.map +1 -0
  294. package/dist/session/lock.d.ts +19 -0
  295. package/dist/session/lock.js +2 -0
  296. package/dist/session/lock.js.map +1 -0
  297. package/dist/session/memory-store.d.ts +12 -0
  298. package/dist/session/memory-store.js +60 -0
  299. package/dist/session/memory-store.js.map +1 -0
  300. package/dist/session/migrate.d.ts +41 -0
  301. package/dist/session/migrate.js +86 -0
  302. package/dist/session/migrate.js.map +1 -0
  303. package/dist/session/pointer.d.ts +15 -0
  304. package/dist/session/pointer.js +22 -0
  305. package/dist/session/pointer.js.map +1 -0
  306. package/dist/session/rebuild.d.ts +53 -0
  307. package/dist/session/rebuild.js +230 -0
  308. package/dist/session/rebuild.js.map +1 -0
  309. package/dist/session/resume.d.ts +26 -0
  310. package/dist/session/resume.js +128 -0
  311. package/dist/session/resume.js.map +1 -0
  312. package/dist/session/retention.d.ts +97 -0
  313. package/dist/session/retention.js +702 -0
  314. package/dist/session/retention.js.map +1 -0
  315. package/dist/session/runner.d.ts +156 -0
  316. package/dist/session/runner.js +656 -0
  317. package/dist/session/runner.js.map +1 -0
  318. package/dist/session/scheduler.d.ts +47 -0
  319. package/dist/session/scheduler.js +85 -0
  320. package/dist/session/scheduler.js.map +1 -0
  321. package/dist/session/secret-key-store.d.ts +47 -0
  322. package/dist/session/secret-key-store.js +79 -0
  323. package/dist/session/secret-key-store.js.map +1 -0
  324. package/dist/session/session.d.ts +106 -0
  325. package/dist/session/session.js +353 -0
  326. package/dist/session/session.js.map +1 -0
  327. package/dist/session/sticky.d.ts +48 -0
  328. package/dist/session/sticky.js +232 -0
  329. package/dist/session/sticky.js.map +1 -0
  330. package/dist/session/store.d.ts +108 -0
  331. package/dist/session/store.js +163 -0
  332. package/dist/session/store.js.map +1 -0
  333. package/dist/telemetry/index.d.ts +2 -0
  334. package/dist/telemetry/index.js +3 -0
  335. package/dist/telemetry/index.js.map +1 -0
  336. package/dist/testing/fake-sandbox.d.ts +52 -0
  337. package/dist/testing/fake-sandbox.js +370 -0
  338. package/dist/testing/fake-sandbox.js.map +1 -0
  339. package/dist/testing/index.d.ts +10 -0
  340. package/dist/testing/index.js +11 -0
  341. package/dist/testing/index.js.map +1 -0
  342. package/dist/testing/key-store-conformance.d.ts +22 -0
  343. package/dist/testing/key-store-conformance.js +97 -0
  344. package/dist/testing/key-store-conformance.js.map +1 -0
  345. package/dist/testing/run-cases.d.ts +21 -0
  346. package/dist/testing/run-cases.js +20 -0
  347. package/dist/testing/run-cases.js.map +1 -0
  348. package/dist/testing/sandbox-conformance.d.ts +64 -0
  349. package/dist/testing/sandbox-conformance.js +468 -0
  350. package/dist/testing/sandbox-conformance.js.map +1 -0
  351. package/dist/testing/scheduler-conformance.d.ts +32 -0
  352. package/dist/testing/scheduler-conformance.js +72 -0
  353. package/dist/testing/scheduler-conformance.js.map +1 -0
  354. package/dist/testing/store-conformance.d.ts +21 -0
  355. package/dist/testing/store-conformance.js +320 -0
  356. package/dist/testing/store-conformance.js.map +1 -0
  357. package/dist/tools/builtins/bash.d.ts +9 -0
  358. package/dist/tools/builtins/bash.js +75 -0
  359. package/dist/tools/builtins/bash.js.map +1 -0
  360. package/dist/tools/builtins/builtins.d.ts +38 -0
  361. package/dist/tools/builtins/builtins.js +48 -0
  362. package/dist/tools/builtins/builtins.js.map +1 -0
  363. package/dist/tools/builtins/descriptions.d.ts +69 -0
  364. package/dist/tools/builtins/descriptions.js +94 -0
  365. package/dist/tools/builtins/descriptions.js.map +1 -0
  366. package/dist/tools/builtins/fetch.d.ts +12 -0
  367. package/dist/tools/builtins/fetch.js +157 -0
  368. package/dist/tools/builtins/fetch.js.map +1 -0
  369. package/dist/tools/builtins/files.d.ts +27 -0
  370. package/dist/tools/builtins/files.js +274 -0
  371. package/dist/tools/builtins/files.js.map +1 -0
  372. package/dist/tools/builtins/paths.d.ts +30 -0
  373. package/dist/tools/builtins/paths.js +62 -0
  374. package/dist/tools/builtins/paths.js.map +1 -0
  375. package/dist/tools/builtins/results.d.ts +15 -0
  376. package/dist/tools/builtins/results.js +31 -0
  377. package/dist/tools/builtins/results.js.map +1 -0
  378. package/dist/tools/builtins/search.d.ts +18 -0
  379. package/dist/tools/builtins/search.js +217 -0
  380. package/dist/tools/builtins/search.js.map +1 -0
  381. package/dist/tools/errors.d.ts +13 -0
  382. package/dist/tools/errors.js +17 -0
  383. package/dist/tools/errors.js.map +1 -0
  384. package/dist/tools/index.d.ts +12 -0
  385. package/dist/tools/index.js +11 -0
  386. package/dist/tools/index.js.map +1 -0
  387. package/dist/tools/registry.d.ts +3 -0
  388. package/dist/tools/registry.js +234 -0
  389. package/dist/tools/registry.js.map +1 -0
  390. package/dist/tools/tool-search.d.ts +30 -0
  391. package/dist/tools/tool-search.js +118 -0
  392. package/dist/tools/tool-search.js.map +1 -0
  393. package/dist/tools/types.d.ts +106 -0
  394. package/dist/tools/types.js +2 -0
  395. package/dist/tools/types.js.map +1 -0
  396. package/llms.txt +469 -0
  397. package/package.json +118 -3
@@ -0,0 +1,72 @@
1
+ import { runCases } from "./run-cases.js";
2
+ function check(condition, message) {
3
+ if (!condition)
4
+ throw new Error(`Scheduler conformance: ${message}`);
5
+ }
6
+ const later = (from, ms) => new Date(from.getTime() + ms);
7
+ /** The cases, each run against a scheduler from `factory`. */
8
+ export function schedulerConformanceCases(factory) {
9
+ const named = (name, body) => ({
10
+ name,
11
+ run: async () => {
12
+ await body(await factory());
13
+ return undefined;
14
+ },
15
+ });
16
+ return [
17
+ named("a wake arrives at its time and not before", async ({ scheduler, now, advanceTo, delivered }) => {
18
+ const at = later(now(), 10_000);
19
+ await scheduler.wake(at, "s1");
20
+ await advanceTo(later(now(), 9_999));
21
+ check(delivered().length === 0, "a wake arrived before its time");
22
+ await advanceTo(at);
23
+ const wakes = delivered();
24
+ // At-least-once allows a repeat, so the case asks for one or more wakes, all of them the wake that was asked for.
25
+ check(wakes.length >= 1, "the wake did not arrive at its time");
26
+ check(wakes.every((wake) => wake.sessionId === "s1" && wake.at.getTime() === at.getTime()), "a wake named another id or time");
27
+ }),
28
+ named("a wake that arrives late is still delivered", async ({ scheduler, now, advanceTo, delivered }) => {
29
+ const at = later(now(), 1_000);
30
+ await scheduler.wake(at, "s1");
31
+ await advanceTo(later(now(), 60_000));
32
+ check(delivered().length >= 1, "a late wake was lost");
33
+ }),
34
+ named("a wake in the past is delivered at once", async ({ scheduler, now, advanceTo, delivered }) => {
35
+ await scheduler.wake(later(now(), -5_000), "s1");
36
+ await advanceTo(now());
37
+ check(delivered().length >= 1, "a past wake was not delivered");
38
+ }),
39
+ named("a duplicate wake is harmless", async ({ scheduler, now, advanceTo, delivered }) => {
40
+ const at = later(now(), 1_000);
41
+ await scheduler.wake(at, "s1");
42
+ await scheduler.wake(at, "s1");
43
+ await advanceTo(later(at, 1_000));
44
+ const wakes = delivered();
45
+ // At-least-once allows a second delivery, and the caller must be idempotent, but every delivery is a real wake.
46
+ check(wakes.length >= 1, "no wake arrived");
47
+ check(wakes.every((wake) => wake.sessionId === "s1" && wake.at.getTime() === at.getTime()), "a duplicate carried another id or time");
48
+ }),
49
+ named("wakes for different sessions each arrive", async ({ scheduler, now, advanceTo, delivered }) => {
50
+ await scheduler.wake(later(now(), 2_000), "b");
51
+ await scheduler.wake(later(now(), 1_000), "a");
52
+ await advanceTo(later(now(), 3_000));
53
+ const ids = new Set(delivered().map((wake) => wake.sessionId));
54
+ check(ids.size === 2 && ids.has("a") && ids.has("b"), "each session's wake did not arrive");
55
+ }),
56
+ named("a cancel drops a pending wake and only that session's", async ({ scheduler, now, advanceTo, delivered }) => {
57
+ await scheduler.wake(later(now(), 1_000), "gone");
58
+ await scheduler.wake(later(now(), 1_000), "kept");
59
+ await scheduler.cancel("gone");
60
+ await advanceTo(later(now(), 2_000));
61
+ check(delivered().every((wake) => wake.sessionId === "kept") && delivered().length >= 1, "a cancelled wake arrived, or another session's was dropped");
62
+ }),
63
+ named("a cancel of an id with no wake is fine", async ({ scheduler }) => {
64
+ await scheduler.cancel("never-asked");
65
+ }),
66
+ ];
67
+ }
68
+ /** Runs every case and reports which passed, which skipped and which failed. */
69
+ export function runSchedulerConformance(factory) {
70
+ return runCases(schedulerConformanceCases(factory));
71
+ }
72
+ //# sourceMappingURL=scheduler-conformance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scheduler-conformance.js","sourceRoot":"","sources":["../../src/testing/scheduler-conformance.ts"],"names":[],"mappings":"AAMA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AAuD,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,EAAE;YAChH,MAAM,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;YAClD,MAAM,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;YAClD,MAAM,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC/B,MAAM,SAAS,CAAC,KAAK,CAAC,GAAG,EAAE,EAAE,KAAK,CAAC,CAAC,CAAC;YACrC,KAAK,CACH,SAAS,EAAE,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC,MAAM,IAAI,CAAC,EACjF,4DAA4D,CAC7D,CAAC;QACJ,CAAC,CAAC;QACF,KAAK,CAAC,wCAAwC,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,EAAE,EAAE;YACtE,MAAM,SAAS,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;QACxC,CAAC,CAAC;KACH,CAAC;AACJ,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,uBAAuB,CAAC,OAAyB;IAC/D,OAAO,QAAQ,CAAC,yBAAyB,CAAC,OAAO,CAAC,CAAC,CAAC;AACtD,CAAC","sourcesContent":["/**\n * The scheduler conformance suite: what every `Scheduler` must do. A wake arrives at or after its time, never before;\n * a duplicate wake is allowed but carries the right id and time; a cancel drops only the id it names. The cases import\n * no test runner and no Node module, so any runner can call them, in workerd too.\n */\nimport type { Scheduler } from \"../session/scheduler.js\";\nimport { type CaseReport, type RunnableCase, runCases } from \"./run-cases.js\";\n\n/** One wake a scheduler delivered. */\nexport interface DeliveredWake {\n readonly sessionId: string;\n readonly at: Date;\n}\n\n/** What a factory returns: the scheduler, and the means to move its clock and read what it delivered. */\nexport interface SchedulerUnderTest {\n readonly scheduler: Scheduler;\n /** The scheduler's clock now. */\n readonly now: () => Date;\n /** Moves the clock to `to` and lets every wake that has come due by then be delivered before it resolves. */\n readonly advanceTo: (to: Date) => Promise<void>;\n /** Every wake delivered so far, in the order delivered. */\n readonly delivered: () => readonly DeliveredWake[];\n}\n\n/** Makes a fresh scheduler for each case. */\nexport type SchedulerFactory = () => SchedulerUnderTest | Promise<SchedulerUnderTest>;\n\n/** One case of the scheduler conformance suite, which a runner can register as a test of its own. */\nexport type SchedulerCase = RunnableCase;\n\n/** The report the scheduler conformance suite returns: which cases passed, which skipped with a reason and which failed. */\nexport type SchedulerConformanceReport = CaseReport;\n\nfunction check(condition: boolean, message: string): asserts condition {\n if (!condition) throw new Error(`Scheduler conformance: ${message}`);\n}\n\nconst later = (from: Date, ms: number) => new Date(from.getTime() + ms);\n\n/** The cases, each run against a scheduler from `factory`. */\nexport function schedulerConformanceCases(factory: SchedulerFactory): readonly SchedulerCase[] {\n const named = (name: string, body: (under: SchedulerUnderTest) => Promise<void>): SchedulerCase => ({\n name,\n run: async () => {\n await body(await factory());\n return undefined;\n },\n });\n return [\n named(\"a wake arrives at its time and not before\", async ({ scheduler, now, advanceTo, delivered }) => {\n const at = later(now(), 10_000);\n await scheduler.wake(at, \"s1\");\n await advanceTo(later(now(), 9_999));\n check(delivered().length === 0, \"a wake arrived before its time\");\n await advanceTo(at);\n const wakes = delivered();\n // At-least-once allows a repeat, so the case asks for one or more wakes, all of them the wake that was asked for.\n check(wakes.length >= 1, \"the wake did not arrive at its time\");\n check(\n wakes.every((wake) => wake.sessionId === \"s1\" && wake.at.getTime() === at.getTime()),\n \"a wake named another id or time\",\n );\n }),\n named(\"a wake that arrives late is still delivered\", async ({ scheduler, now, advanceTo, delivered }) => {\n const at = later(now(), 1_000);\n await scheduler.wake(at, \"s1\");\n await advanceTo(later(now(), 60_000));\n check(delivered().length >= 1, \"a late wake was lost\");\n }),\n named(\"a wake in the past is delivered at once\", async ({ scheduler, now, advanceTo, delivered }) => {\n await scheduler.wake(later(now(), -5_000), \"s1\");\n await advanceTo(now());\n check(delivered().length >= 1, \"a past wake was not delivered\");\n }),\n named(\"a duplicate wake is harmless\", async ({ scheduler, now, advanceTo, delivered }) => {\n const at = later(now(), 1_000);\n await scheduler.wake(at, \"s1\");\n await scheduler.wake(at, \"s1\");\n await advanceTo(later(at, 1_000));\n const wakes = delivered();\n // At-least-once allows a second delivery, and the caller must be idempotent, but every delivery is a real wake.\n check(wakes.length >= 1, \"no wake arrived\");\n check(\n wakes.every((wake) => wake.sessionId === \"s1\" && wake.at.getTime() === at.getTime()),\n \"a duplicate carried another id or time\",\n );\n }),\n named(\"wakes for different sessions each arrive\", async ({ scheduler, now, advanceTo, delivered }) => {\n await scheduler.wake(later(now(), 2_000), \"b\");\n await scheduler.wake(later(now(), 1_000), \"a\");\n await advanceTo(later(now(), 3_000));\n const ids = new Set(delivered().map((wake) => wake.sessionId));\n check(ids.size === 2 && ids.has(\"a\") && ids.has(\"b\"), \"each session's wake did not arrive\");\n }),\n named(\"a cancel drops a pending wake and only that session's\", async ({ scheduler, now, advanceTo, delivered }) => {\n await scheduler.wake(later(now(), 1_000), \"gone\");\n await scheduler.wake(later(now(), 1_000), \"kept\");\n await scheduler.cancel(\"gone\");\n await advanceTo(later(now(), 2_000));\n check(\n delivered().every((wake) => wake.sessionId === \"kept\") && delivered().length >= 1,\n \"a cancelled wake arrived, or another session's was dropped\",\n );\n }),\n named(\"a cancel of an id with no wake is fine\", async ({ scheduler }) => {\n await scheduler.cancel(\"never-asked\");\n }),\n ];\n}\n\n/** Runs every case and reports which passed, which skipped and which failed. */\nexport function runSchedulerConformance(factory: SchedulerFactory): Promise<SchedulerConformanceReport> {\n return runCases(schedulerConformanceCases(factory));\n}\n"]}
@@ -0,0 +1,21 @@
1
+ import type { SessionKey, SessionStore } from "../session/store.js";
2
+ import { type CaseReport, type RunnableCase } from "./run-cases.js";
3
+ /** What a factory returns: a fresh, empty store, and optionally a way to tear a log's last line. */
4
+ export interface StoreUnderTest {
5
+ readonly store: SessionStore;
6
+ /**
7
+ * Leaves the session's log ending in a line that was never completed, as a crash in the middle of a write would, by
8
+ * appending partial JSON with no newline. Without it the torn-line cases skip, because a store need not be a file.
9
+ */
10
+ readonly tearLastLine?: (key: SessionKey) => void | Promise<void>;
11
+ }
12
+ /** Makes a fresh store for each case. */
13
+ export type StoreFactory = () => StoreUnderTest | Promise<StoreUnderTest>;
14
+ /** One case of the store conformance suite, which a runner can register as a test of its own. */
15
+ export type StoreCase = RunnableCase;
16
+ /** The report the store conformance suite returns: which cases passed, which skipped with a reason and which failed. */
17
+ export type StoreConformanceReport = CaseReport;
18
+ /** Every conformance case, each against a store from `factory`. */
19
+ export declare function storeConformanceCases(factory: StoreFactory): readonly StoreCase[];
20
+ /** Runs every case and reports which passed, which skipped with a reason and which failed. */
21
+ export declare function runStoreConformance(factory: StoreFactory): Promise<StoreConformanceReport>;
@@ -0,0 +1,320 @@
1
+ import { isHarnessError } from "../errors.js";
2
+ import { ConflictError, EntryTooLargeError } from "../session/errors.js";
3
+ import { runCases } from "./run-cases.js";
4
+ const ADA = { userId: "ada", sessionId: "s1" };
5
+ const BOB = { userId: "bob", sessionId: "s1" };
6
+ function check(condition, message) {
7
+ if (!condition)
8
+ throw new Error(`Session store conformance: ${message}`);
9
+ }
10
+ const header = (id = "h1", timestamp = "2026-01-01T00:00:00.000Z") => ({
11
+ id,
12
+ parentId: null,
13
+ timestamp,
14
+ origin: "harness",
15
+ type: "session_header",
16
+ formatVersion: 1,
17
+ harnessVersion: "0.0.0",
18
+ sdkVersion: "0.0.0",
19
+ defaultsHash: "d",
20
+ capabilities: [],
21
+ ablationHash: "a",
22
+ });
23
+ const record = (id, parentId, data = {}) => ({
24
+ id,
25
+ parentId,
26
+ timestamp: "2026-01-01T00:00:01.000Z",
27
+ origin: "harness",
28
+ type: "product_record",
29
+ name: "test.record",
30
+ data,
31
+ });
32
+ async function collect(source) {
33
+ const found = [];
34
+ for await (const entry of source)
35
+ found.push(entry);
36
+ return found;
37
+ }
38
+ const ids = (entries) => entries.map((entry) => entry.id);
39
+ async function rejects(run, test, message) {
40
+ try {
41
+ await run();
42
+ }
43
+ catch (error) {
44
+ check(test(error), `${message}, but it threw ${String(error)}`);
45
+ return;
46
+ }
47
+ check(false, `${message}, but it did not throw`);
48
+ }
49
+ const hasCode = (code) => (error) => isHarnessError(error) && error.code === code;
50
+ function appendCases(open) {
51
+ const cases = [
52
+ [
53
+ "append assigns seq from 0 and load returns the entries in order",
54
+ async ({ store }) => {
55
+ const written = await store.append(ADA, [header(), record("r1", "h1"), record("r2", "r1")]);
56
+ check(written.map((entry) => entry.seq).join() === "0,1,2", "append returns each entry with its seq");
57
+ const loaded = await collect(store.load(ADA));
58
+ check(ids(loaded).join() === "h1,r1,r2", "load returns the entries in order");
59
+ const more = await store.append(ADA, [record("r3", "r2")]);
60
+ check(more[0]?.seq === 3, "a later append goes on from the last seq");
61
+ },
62
+ ],
63
+ [
64
+ "appending the same entry twice stores it once",
65
+ async ({ store }) => {
66
+ await store.append(ADA, [header(), record("r1", "h1")]);
67
+ const again = await store.append(ADA, [record("r1", "h1")]);
68
+ check(again.length === 1 && again[0]?.seq === 1, "the retry returns the stored entry");
69
+ check((await collect(store.load(ADA))).length === 2, "the entry is in the log once");
70
+ },
71
+ ],
72
+ [
73
+ "an entry id stored with different content is a ConflictError",
74
+ async ({ store }) => {
75
+ await store.append(ADA, [header(), record("r1", "h1", { a: 1 })]);
76
+ await rejects(() => store.append(ADA, [record("r1", "h1", { a: 2 })]), (error) => error instanceof ConflictError && isHarnessError(error) && error.code === "session_conflict", "reusing an id with other content must throw a ConflictError");
77
+ const same = await store.append(ADA, [record("r1", "h1", { a: 1 })]);
78
+ check(same.length === 1, "the same content under that id is still a retry");
79
+ },
80
+ ],
81
+ [
82
+ "a batch that is partly stored finishes on a retry, and one stored out of order conflicts",
83
+ async ({ store }) => {
84
+ await store.append(ADA, [header(), record("r1", "h1")]);
85
+ const finished = await store.append(ADA, [record("r1", "h1"), record("r2", "r1")]);
86
+ check(ids(finished).join() === "r1,r2" && finished[1]?.seq === 2, "the stored prefix is kept and the rest written");
87
+ await rejects(() => store.append(ADA, [record("r3", "r2"), record("r1", "h1")]), (error) => error instanceof ConflictError, "a stored entry after a new one must conflict");
88
+ check((await collect(store.load(ADA))).length === 3, "the failed batch wrote nothing");
89
+ },
90
+ ],
91
+ ];
92
+ return cases.map(([name, body]) => ({ name, run: () => open(body) }));
93
+ }
94
+ function conflictCases(open) {
95
+ const cases = [
96
+ [
97
+ "a retry of a partly stored batch conflicts once another writer has extended the log",
98
+ async ({ store }) => {
99
+ await store.append(ADA, [header()]);
100
+ await store.append(ADA, [record("a1", "h1")], { expectedLastId: "h1" });
101
+ await store.append(ADA, [record("b1", "a1")], { expectedLastId: "a1" });
102
+ await rejects(() => store.append(ADA, [record("a1", "h1"), record("a2", "a1")], { expectedLastId: "h1" }), (error) => error instanceof ConflictError, "a1 is stored but is no longer the end of the log, so a2 must not be written after b1");
103
+ check(ids(await collect(store.load(ADA))).join() === "h1,a1,b1", "the retry wrote nothing");
104
+ },
105
+ ],
106
+ [
107
+ "a stale expectedLastId is a ConflictError and writes nothing",
108
+ async ({ store }) => {
109
+ await rejects(() => store.append(ADA, [header()], { expectedLastId: "x" }), (error) => error instanceof ConflictError, "a new session expects null, not an id");
110
+ await store.append(ADA, [header()], { expectedLastId: null });
111
+ await store.append(ADA, [record("r1", "h1")], { expectedLastId: "h1" });
112
+ await rejects(() => store.append(ADA, [record("r2", "r1")], { expectedLastId: "h1" }), (error) => error instanceof ConflictError, "an old tail must conflict");
113
+ await rejects(() => store.append(ADA, [record("r2", "r1")], { expectedLastId: null }), (error) => error instanceof ConflictError, "null on a session that exists must conflict");
114
+ check(ids(await collect(store.load(ADA))).join() === "h1,r1", "the failed appends wrote nothing");
115
+ },
116
+ ],
117
+ [
118
+ "a load yields the entries present when it began, even if the caller appends while it iterates",
119
+ async ({ store }) => {
120
+ await store.append(ADA, [header(), record("r1", "h1")]);
121
+ const seen = [];
122
+ for await (const entry of store.load(ADA)) {
123
+ seen.push(entry.id);
124
+ if (seen.length < 5)
125
+ await store.append(ADA, [record(`n${seen.length}`, entry.id)]);
126
+ }
127
+ check(seen.join() === "h1,r1", "the loop saw the two entries that existed, and ended");
128
+ check((await collect(store.load(ADA))).length === 4, "the two appends made during it were stored");
129
+ },
130
+ ],
131
+ [
132
+ "load from a sequence skips the earlier entries",
133
+ async ({ store }) => {
134
+ await store.append(ADA, [header(), record("r1", "h1"), record("r2", "r1")]);
135
+ check(ids(await collect(store.load(ADA, { fromSeq: 1 }))).join() === "r1,r2", "fromSeq 1 starts at seq 1");
136
+ check((await collect(store.load(ADA, { fromSeq: 9 }))).length === 0, "past the end yields nothing");
137
+ },
138
+ ],
139
+ ];
140
+ return cases.map(([name, body]) => ({ name, run: () => open(body) }));
141
+ }
142
+ function validationCases(open) {
143
+ const cases = [
144
+ [
145
+ "a first entry that is not a header, a second header and an invalid entry are refused",
146
+ async ({ store }) => {
147
+ const invalid = hasCode("invalid_session_entry");
148
+ await rejects(() => store.append(ADA, [record("r1", "h1")]), invalid, "a log must start with a header");
149
+ await store.append(ADA, [header()]);
150
+ await rejects(() => store.append(ADA, [header("h2")]), invalid, "only the first entry may be a header");
151
+ await rejects(() => store.append(ADA, [{ ...record("r1", "h1"), timestamp: "yesterday" }]), invalid, "an entry the protocol rejects must be refused");
152
+ await rejects(() => store.append(ADA, [record("r1", "h1"), record("r1", "h1")]), invalid, "a batch repeating an id must be refused");
153
+ check((await collect(store.load(ADA))).length === 1, "refused appends wrote nothing");
154
+ },
155
+ ],
156
+ [
157
+ "an entry over 64 KiB is an EntryTooLargeError, and a batch with one writes none of it",
158
+ async ({ store }) => {
159
+ const big = record("big", "h1", { text: "x".repeat(64 * 1024) });
160
+ await store.append(ADA, [header()]);
161
+ await rejects(() => store.append(ADA, [record("ok", "h1"), big]), (error) => error instanceof EntryTooLargeError && error.entryId === "big" && error.maxBytes === 64 * 1024, "an oversize entry must throw an EntryTooLargeError");
162
+ check((await collect(store.load(ADA))).length === 1, "the small entry before it was not written either");
163
+ await store.append(ADA, [record("small", "h1", { text: "x".repeat(60 * 1024) })]);
164
+ },
165
+ ],
166
+ ];
167
+ return cases.map(([name, body]) => ({ name, run: () => open(body) }));
168
+ }
169
+ function identityCases(open) {
170
+ const cases = [
171
+ [
172
+ "a caller that changes an entry after appending it does not change the stored one",
173
+ async ({ store }) => {
174
+ const data = { a: 1 };
175
+ await store.append(ADA, [header(), record("r1", "h1", data)]);
176
+ data.a = 2;
177
+ const again = await store.append(ADA, [record("r1", "h1", { a: 1 })]);
178
+ check(again.length === 1, "a retry with the original content is still a retry");
179
+ await rejects(() => store.append(ADA, [record("r1", "h1", { a: 2 })]), (error) => error instanceof ConflictError, "the changed content must conflict, because the stored entry did not change");
180
+ const [, stored] = await collect(store.load(ADA));
181
+ stored.data.a = 9;
182
+ check((await collect(store.load(ADA)))[1].data.a === 1, "a loaded entry is a copy");
183
+ },
184
+ ],
185
+ [
186
+ "ids that differ only in letter case are different users and sessions",
187
+ async ({ store }) => {
188
+ await store.append({ userId: "Ada", sessionId: "S1" }, [header("upper")]);
189
+ await store.append({ userId: "ada", sessionId: "s1" }, [header("lower")]);
190
+ check(ids(await collect(store.load({ userId: "Ada", sessionId: "S1" }))).join() === "upper", "Ada's S1 holds its own entries");
191
+ check(ids(await collect(store.load({ userId: "ada", sessionId: "s1" }))).join() === "lower", "and ada's s1 holds its own");
192
+ check((await collect(store.list("Ada"))).length === 1, "each user lists one session");
193
+ },
194
+ ],
195
+ ];
196
+ return cases.map(([name, body]) => ({ name, run: () => open(body) }));
197
+ }
198
+ function keyCases(open) {
199
+ const cases = [
200
+ [
201
+ "append rejects, and does not throw, for a key it can't use, and every store agrees on which keys those are",
202
+ async ({ store }) => {
203
+ const invalid = hasCode("invalid_session_key");
204
+ await rejects(() => store.append({ userId: "", sessionId: "s" }, [header()]), invalid, "an empty user is refused");
205
+ await rejects(() => store.append({ userId: "u", sessionId: "é".repeat(64) }, [header()]), invalid, "a name that encodes to over 200 bytes is refused by every store");
206
+ await rejects(() => store.append({ userId: "\ud800", sessionId: "s" }, [header()]), invalid, "a lone surrogate would encode like another id, so it is refused");
207
+ await store.append({ userId: "u", sessionId: "e".repeat(64) }, [header()]);
208
+ },
209
+ ],
210
+ [
211
+ "a user id or session id that is empty or has a control character is refused",
212
+ async ({ store }) => {
213
+ const invalid = hasCode("invalid_session_key");
214
+ for (const key of [
215
+ { userId: "", sessionId: "s" },
216
+ { userId: "u", sessionId: "" },
217
+ { userId: "u", sessionId: "a\nb" },
218
+ ]) {
219
+ await rejects(() => store.append(key, [header()]), invalid, `${JSON.stringify(key)} must be refused`);
220
+ }
221
+ await store.append({ userId: "u/../x", sessionId: "../../y" }, [header()]);
222
+ check((await collect(store.load({ userId: "u/../x", sessionId: "../../y" }))).length === 1, "an id that looks like a path is a name, and works");
223
+ },
224
+ ],
225
+ ];
226
+ return cases.map(([name, body]) => ({ name, run: () => open(body) }));
227
+ }
228
+ function listAndOwnerCases(open) {
229
+ const cases = [
230
+ [
231
+ "list returns the user's sessions from their headers, oldest first, and delete removes one",
232
+ async ({ store }) => {
233
+ await store.append({ userId: "ada", sessionId: "late" }, [
234
+ header("h", "2026-01-02T00:00:00.000Z"),
235
+ record("r", "h"),
236
+ ]);
237
+ await store.append({ userId: "ada", sessionId: "early" }, [header("h", "2026-01-01T00:00:00.000Z")]);
238
+ const listed = await collect(store.list("ada"));
239
+ check(listed.map((summary) => summary.sessionId).join() === "early,late", "list is oldest first");
240
+ const late = listed[1];
241
+ check(late?.entryCount === 2 && late.startedAt === "2026-01-02T00:00:00.000Z", "the summary comes from the entries");
242
+ await store.delete({ userId: "ada", sessionId: "early" });
243
+ check((await collect(store.list("ada"))).length === 1, "delete removes the session");
244
+ await store.delete({ userId: "ada", sessionId: "early" });
245
+ },
246
+ ],
247
+ [
248
+ "another user's session looks the same as one that was never created",
249
+ async ({ store }) => {
250
+ await store.append(ADA, [header(), record("r1", "h1")]);
251
+ const neverMade = await collect(store.load({ userId: "bob", sessionId: "never" }));
252
+ const adasUnderBob = await collect(store.load(BOB));
253
+ check(neverMade.length === 0 && adasUnderBob.length === 0, "loading under another user yields nothing, as for a missing id");
254
+ check((await collect(store.list("bob"))).length === 0, "list under another user leaves it out");
255
+ await store.delete(BOB);
256
+ check((await collect(store.load(ADA))).length === 2, "delete under another user changed nothing");
257
+ await store.append(BOB, [header("hb")]);
258
+ check(ids(await collect(store.load(ADA))).join() === "h1,r1", "bob's session with the same id is a separate session");
259
+ check(ids(await collect(store.load(BOB))).join() === "hb", "and it holds only bob's entries");
260
+ },
261
+ ],
262
+ ];
263
+ return cases.map(([name, body]) => ({ name, run: () => open(body) }));
264
+ }
265
+ function tornCases(open) {
266
+ const needsTear = "the store gave no way to tear a log's last line";
267
+ const cases = [
268
+ [
269
+ "a torn last line is skipped by load and reported once, with every complete entry kept",
270
+ async ({ store, tearLastLine }) => {
271
+ if (tearLastLine === undefined)
272
+ return { skipped: needsTear };
273
+ await store.append(ADA, [header(), record("r1", "h1")]);
274
+ await tearLastLine(ADA);
275
+ const reports = [];
276
+ const loaded = await collect(store.load(ADA, { onTornLine: (line) => reports.push(line.bytes) }));
277
+ check(ids(loaded).join() === "h1,r1", "the complete entries load");
278
+ check(reports.length === 1 && (reports[0] ?? 0) > 0, "the torn line is reported once");
279
+ const clean = await collect(store.load({ userId: "ada", sessionId: "other" }, { onTornLine: () => check(false, "a clean log reports nothing") }));
280
+ check(clean.length === 0, "a missing session yields nothing");
281
+ },
282
+ ],
283
+ [
284
+ "an append after a torn line cuts it off, so the next entry is not glued to it",
285
+ async ({ store, tearLastLine }) => {
286
+ if (tearLastLine === undefined)
287
+ return { skipped: needsTear };
288
+ await store.append(ADA, [header(), record("r1", "h1")]);
289
+ await tearLastLine(ADA);
290
+ const written = await store.append(ADA, [record("r2", "r1")], { expectedLastId: "r1" });
291
+ check(written[0]?.seq === 2, "the new entry follows the last complete one");
292
+ const reports = [];
293
+ const loaded = await collect(store.load(ADA, { onTornLine: (line) => reports.push(line.bytes) }));
294
+ check(ids(loaded).join() === "h1,r1,r2" && reports.length === 0, "the log is whole again");
295
+ },
296
+ ],
297
+ ];
298
+ return cases.map(([name, body]) => ({ name, run: () => open(body) }));
299
+ }
300
+ /** Every conformance case, each against a store from `factory`. */
301
+ export function storeConformanceCases(factory) {
302
+ const open = async (body) => {
303
+ const outcome = await body(await factory());
304
+ return typeof outcome === "object" && outcome !== null && "skipped" in outcome ? outcome : undefined;
305
+ };
306
+ return [
307
+ ...appendCases(open),
308
+ ...conflictCases(open),
309
+ ...validationCases(open),
310
+ ...identityCases(open),
311
+ ...keyCases(open),
312
+ ...listAndOwnerCases(open),
313
+ ...tornCases(open),
314
+ ];
315
+ }
316
+ /** Runs every case and reports which passed, which skipped with a reason and which failed. */
317
+ export async function runStoreConformance(factory) {
318
+ return runCases(storeConformanceCases(factory));
319
+ }
320
+ //# sourceMappingURL=store-conformance.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store-conformance.js","sourceRoot":"","sources":["../../src/testing/store-conformance.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,EAAsC,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAqB9E,MAAM,GAAG,GAAe,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC3D,MAAM,GAAG,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAE/C,SAAS,KAAK,CAAC,SAAkB,EAAE,OAAe;IAChD,IAAI,CAAC,SAAS;QAAE,MAAM,IAAI,KAAK,CAAC,8BAA8B,OAAO,EAAE,C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AAM,IAAI,CAAC,MAAM,OAAO,EAAE,CAAC,CAAC;QAC5C,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,IAAI,SAAS,IAAI,OAAO,CAAC,CAAC,CAAE,OAAgB,CAAC,CAAC,CAAC,SAAS,CAAC;IACjH,CAAC,CAAC;IACF,OAAO;QACL,GAAG,WAAW,CAAC,IAAI,CAAC;QACpB,GAAG,aAAa,CAAC,IAAI,CAAC;QACtB,GAAG,eAAe,CAAC,IAAI,CAAC;QACxB,GAAG,aAAa,CAAC,IAAI,CAAC;QACtB,GAAG,QAAQ,CAAC,IAAI,CAAC;QACjB,GAAG,iBAAiB,CAAC,IAAI,CAAC;QAC1B,GAAG,SAAS,CAAC,IAAI,CAAC;KACnB,CAAC;AACJ,CAAC;AAED,8FAA8F;AAC9F,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAC,OAAqB;IAC7D,OAAO,QAAQ,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC;AAClD,CAAC","sourcesContent":["/**\n * The session store conformance suite: what every `SessionStore` must do. The cases import no test runner and no Node\n * module, so any runner can call them, in workerd too. A case that needs a backend to expose a file skips, and\n * reports why, when the factory gives it no `tearLastLine`.\n */\nimport type { SessionEntry } from \"@buildanagent/protocol\";\nimport { isHarnessError } from \"../errors.js\";\nimport { ConflictError, EntryTooLargeError } from \"../session/errors.js\";\nimport type { EntryInput, SessionKey, SessionStore } from \"../session/store.js\";\nimport { type CaseReport, type RunnableCase, runCases } from \"./run-cases.js\";\n\n/** What a factory returns: a fresh, empty store, and optionally a way to tear a log's last line. */\nexport interface StoreUnderTest {\n readonly store: SessionStore;\n /**\n * Leaves the session's log ending in a line that was never completed, as a crash in the middle of a write would, by\n * appending partial JSON with no newline. Without it the torn-line cases skip, because a store need not be a file.\n */\n readonly tearLastLine?: (key: SessionKey) => void | Promise<void>;\n}\n\n/** Makes a fresh store for each case. */\nexport type StoreFactory = () => StoreUnderTest | Promise<StoreUnderTest>;\n\n/** One case of the store conformance suite, which a runner can register as a test of its own. */\nexport type StoreCase = RunnableCase;\n\n/** The report the store conformance suite returns: which cases passed, which skipped with a reason and which failed. */\nexport type StoreConformanceReport = CaseReport;\n\nconst ADA: SessionKey = { userId: \"ada\", sessionId: \"s1\" };\nconst BOB = { userId: \"bob\", sessionId: \"s1\" };\n\nfunction check(condition: boolean, message: string): asserts condition {\n if (!condition) throw new Error(`Session store conformance: ${message}`);\n}\n\nconst header = (id = \"h1\", timestamp = \"2026-01-01T00:00:00.000Z\"): EntryInput => ({\n id,\n parentId: null,\n timestamp,\n origin: \"harness\",\n type: \"session_header\",\n formatVersion: 1,\n harnessVersion: \"0.0.0\",\n sdkVersion: \"0.0.0\",\n defaultsHash: \"d\",\n capabilities: [],\n ablationHash: \"a\",\n});\n\nconst record = (id: string, parentId: string, data: unknown = {}): EntryInput => ({\n id,\n parentId,\n timestamp: \"2026-01-01T00:00:01.000Z\",\n origin: \"harness\",\n type: \"product_record\",\n name: \"test.record\",\n data,\n});\n\nasync function collect<T>(source: AsyncIterable<T>): Promise<T[]> {\n const found: T[] = [];\n for await (const entry of source) found.push(entry);\n return found;\n}\n\nconst ids = (entries: readonly SessionEntry[]) => entries.map((entry) => entry.id);\n\nasync function rejects(run: () => Promise<unknown>, test: (error: unknown) => boolean, message: string) {\n try {\n await run();\n } catch (error) {\n check(test(error), `${message}, but it threw ${String(error)}`);\n return;\n }\n check(false, `${message}, but it did not throw`);\n}\n\nconst hasCode = (code: string) => (error: unknown) => isHarnessError(error) && error.code === code;\n\ntype Skip = { readonly skipped: string };\ntype Body = (under: StoreUnderTest) => Promise<Skip | undefined | unknown>;\n\nfunction appendCases(open: (body: Body) => Promise<{ skipped: string } | undefined>): StoreCase[] {\n const cases: [string, Body][] = [\n [\n \"append assigns seq from 0 and load returns the entries in order\",\n async ({ store }) => {\n const written = await store.append(ADA, [header(), record(\"r1\", \"h1\"), record(\"r2\", \"r1\")]);\n check(written.map((entry) => entry.seq).join() === \"0,1,2\", \"append returns each entry with its seq\");\n const loaded = await collect(store.load(ADA));\n check(ids(loaded).join() === \"h1,r1,r2\", \"load returns the entries in order\");\n const more = await store.append(ADA, [record(\"r3\", \"r2\")]);\n check(more[0]?.seq === 3, \"a later append goes on from the last seq\");\n },\n ],\n [\n \"appending the same entry twice stores it once\",\n async ({ store }) => {\n await store.append(ADA, [header(), record(\"r1\", \"h1\")]);\n const again = await store.append(ADA, [record(\"r1\", \"h1\")]);\n check(again.length === 1 && again[0]?.seq === 1, \"the retry returns the stored entry\");\n check((await collect(store.load(ADA))).length === 2, \"the entry is in the log once\");\n },\n ],\n [\n \"an entry id stored with different content is a ConflictError\",\n async ({ store }) => {\n await store.append(ADA, [header(), record(\"r1\", \"h1\", { a: 1 })]);\n await rejects(\n () => store.append(ADA, [record(\"r1\", \"h1\", { a: 2 })]),\n (error) => error instanceof ConflictError && isHarnessError(error) && error.code === \"session_conflict\",\n \"reusing an id with other content must throw a ConflictError\",\n );\n const same = await store.append(ADA, [record(\"r1\", \"h1\", { a: 1 })]);\n check(same.length === 1, \"the same content under that id is still a retry\");\n },\n ],\n [\n \"a batch that is partly stored finishes on a retry, and one stored out of order conflicts\",\n async ({ store }) => {\n await store.append(ADA, [header(), record(\"r1\", \"h1\")]);\n const finished = await store.append(ADA, [record(\"r1\", \"h1\"), record(\"r2\", \"r1\")]);\n check(\n ids(finished).join() === \"r1,r2\" && finished[1]?.seq === 2,\n \"the stored prefix is kept and the rest written\",\n );\n await rejects(\n () => store.append(ADA, [record(\"r3\", \"r2\"), record(\"r1\", \"h1\")]),\n (error) => error instanceof ConflictError,\n \"a stored entry after a new one must conflict\",\n );\n check((await collect(store.load(ADA))).length === 3, \"the failed batch wrote nothing\");\n },\n ],\n ];\n return cases.map(([name, body]) => ({ name, run: () => open(body) }));\n}\n\nfunction conflictCases(open: (body: Body) => Promise<{ skipped: string } | undefined>): StoreCase[] {\n const cases: [string, Body][] = [\n [\n \"a retry of a partly stored batch conflicts once another writer has extended the log\",\n async ({ store }) => {\n await store.append(ADA, [header()]);\n await store.append(ADA, [record(\"a1\", \"h1\")], { expectedLastId: \"h1\" });\n await store.append(ADA, [record(\"b1\", \"a1\")], { expectedLastId: \"a1\" });\n await rejects(\n () => store.append(ADA, [record(\"a1\", \"h1\"), record(\"a2\", \"a1\")], { expectedLastId: \"h1\" }),\n (error) => error instanceof ConflictError,\n \"a1 is stored but is no longer the end of the log, so a2 must not be written after b1\",\n );\n check(ids(await collect(store.load(ADA))).join() === \"h1,a1,b1\", \"the retry wrote nothing\");\n },\n ],\n [\n \"a stale expectedLastId is a ConflictError and writes nothing\",\n async ({ store }) => {\n await rejects(\n () => store.append(ADA, [header()], { expectedLastId: \"x\" }),\n (error) => error instanceof ConflictError,\n \"a new session expects null, not an id\",\n );\n await store.append(ADA, [header()], { expectedLastId: null });\n await store.append(ADA, [record(\"r1\", \"h1\")], { expectedLastId: \"h1\" });\n await rejects(\n () => store.append(ADA, [record(\"r2\", \"r1\")], { expectedLastId: \"h1\" }),\n (error) => error instanceof ConflictError,\n \"an old tail must conflict\",\n );\n await rejects(\n () => store.append(ADA, [record(\"r2\", \"r1\")], { expectedLastId: null }),\n (error) => error instanceof ConflictError,\n \"null on a session that exists must conflict\",\n );\n check(ids(await collect(store.load(ADA))).join() === \"h1,r1\", \"the failed appends wrote nothing\");\n },\n ],\n [\n \"a load yields the entries present when it began, even if the caller appends while it iterates\",\n async ({ store }) => {\n await store.append(ADA, [header(), record(\"r1\", \"h1\")]);\n const seen: string[] = [];\n for await (const entry of store.load(ADA)) {\n seen.push(entry.id);\n if (seen.length < 5) await store.append(ADA, [record(`n${seen.length}`, entry.id)]);\n }\n check(seen.join() === \"h1,r1\", \"the loop saw the two entries that existed, and ended\");\n check((await collect(store.load(ADA))).length === 4, \"the two appends made during it were stored\");\n },\n ],\n [\n \"load from a sequence skips the earlier entries\",\n async ({ store }) => {\n await store.append(ADA, [header(), record(\"r1\", \"h1\"), record(\"r2\", \"r1\")]);\n check(ids(await collect(store.load(ADA, { fromSeq: 1 }))).join() === \"r1,r2\", \"fromSeq 1 starts at seq 1\");\n check((await collect(store.load(ADA, { fromSeq: 9 }))).length === 0, \"past the end yields nothing\");\n },\n ],\n ];\n return cases.map(([name, body]) => ({ name, run: () => open(body) }));\n}\n\nfunction validationCases(open: (body: Body) => Promise<{ skipped: string } | undefined>): StoreCase[] {\n const cases: [string, Body][] = [\n [\n \"a first entry that is not a header, a second header and an invalid entry are refused\",\n async ({ store }) => {\n const invalid = hasCode(\"invalid_session_entry\");\n await rejects(() => store.append(ADA, [record(\"r1\", \"h1\")]), invalid, \"a log must start with a header\");\n await store.append(ADA, [header()]);\n await rejects(() => store.append(ADA, [header(\"h2\")]), invalid, \"only the first entry may be a header\");\n await rejects(\n () => store.append(ADA, [{ ...record(\"r1\", \"h1\"), timestamp: \"yesterday\" }]),\n invalid,\n \"an entry the protocol rejects must be refused\",\n );\n await rejects(\n () => store.append(ADA, [record(\"r1\", \"h1\"), record(\"r1\", \"h1\")]),\n invalid,\n \"a batch repeating an id must be refused\",\n );\n check((await collect(store.load(ADA))).length === 1, \"refused appends wrote nothing\");\n },\n ],\n [\n \"an entry over 64 KiB is an EntryTooLargeError, and a batch with one writes none of it\",\n async ({ store }) => {\n const big = record(\"big\", \"h1\", { text: \"x\".repeat(64 * 1024) });\n await store.append(ADA, [header()]);\n await rejects(\n () => store.append(ADA, [record(\"ok\", \"h1\"), big]),\n (error) => error instanceof EntryTooLargeError && error.entryId === \"big\" && error.maxBytes === 64 * 1024,\n \"an oversize entry must throw an EntryTooLargeError\",\n );\n check((await collect(store.load(ADA))).length === 1, \"the small entry before it was not written either\");\n await store.append(ADA, [record(\"small\", \"h1\", { text: \"x\".repeat(60 * 1024) })]);\n },\n ],\n ];\n return cases.map(([name, body]) => ({ name, run: () => open(body) }));\n}\n\nfunction identityCases(open: (body: Body) => Promise<{ skipped: string } | undefined>): StoreCase[] {\n const cases: [string, Body][] = [\n [\n \"a caller that changes an entry after appending it does not change the stored one\",\n async ({ store }) => {\n const data = { a: 1 };\n await store.append(ADA, [header(), record(\"r1\", \"h1\", data)]);\n data.a = 2;\n const again = await store.append(ADA, [record(\"r1\", \"h1\", { a: 1 })]);\n check(again.length === 1, \"a retry with the original content is still a retry\");\n await rejects(\n () => store.append(ADA, [record(\"r1\", \"h1\", { a: 2 })]),\n (error) => error instanceof ConflictError,\n \"the changed content must conflict, because the stored entry did not change\",\n );\n const [, stored] = await collect(store.load(ADA));\n (stored as { data: { a: number } }).data.a = 9;\n check(\n ((await collect(store.load(ADA)))[1] as unknown as { data: { a: number } }).data.a === 1,\n \"a loaded entry is a copy\",\n );\n },\n ],\n [\n \"ids that differ only in letter case are different users and sessions\",\n async ({ store }) => {\n await store.append({ userId: \"Ada\", sessionId: \"S1\" }, [header(\"upper\")]);\n await store.append({ userId: \"ada\", sessionId: \"s1\" }, [header(\"lower\")]);\n check(\n ids(await collect(store.load({ userId: \"Ada\", sessionId: \"S1\" }))).join() === \"upper\",\n \"Ada's S1 holds its own entries\",\n );\n check(\n ids(await collect(store.load({ userId: \"ada\", sessionId: \"s1\" }))).join() === \"lower\",\n \"and ada's s1 holds its own\",\n );\n check((await collect(store.list(\"Ada\"))).length === 1, \"each user lists one session\");\n },\n ],\n ];\n return cases.map(([name, body]) => ({ name, run: () => open(body) }));\n}\n\nfunction keyCases(open: (body: Body) => Promise<{ skipped: string } | undefined>): StoreCase[] {\n const cases: [string, Body][] = [\n [\n \"append rejects, and does not throw, for a key it can't use, and every store agrees on which keys those are\",\n async ({ store }) => {\n const invalid = hasCode(\"invalid_session_key\");\n await rejects(\n () => store.append({ userId: \"\", sessionId: \"s\" }, [header()]),\n invalid,\n \"an empty user is refused\",\n );\n await rejects(\n () => store.append({ userId: \"u\", sessionId: \"é\".repeat(64) }, [header()]),\n invalid,\n \"a name that encodes to over 200 bytes is refused by every store\",\n );\n await rejects(\n () => store.append({ userId: \"\\ud800\", sessionId: \"s\" }, [header()]),\n invalid,\n \"a lone surrogate would encode like another id, so it is refused\",\n );\n await store.append({ userId: \"u\", sessionId: \"e\".repeat(64) }, [header()]);\n },\n ],\n [\n \"a user id or session id that is empty or has a control character is refused\",\n async ({ store }) => {\n const invalid = hasCode(\"invalid_session_key\");\n for (const key of [\n { userId: \"\", sessionId: \"s\" },\n { userId: \"u\", sessionId: \"\" },\n { userId: \"u\", sessionId: \"a\\nb\" },\n ]) {\n await rejects(() => store.append(key, [header()]), invalid, `${JSON.stringify(key)} must be refused`);\n }\n await store.append({ userId: \"u/../x\", sessionId: \"../../y\" }, [header()]);\n check(\n (await collect(store.load({ userId: \"u/../x\", sessionId: \"../../y\" }))).length === 1,\n \"an id that looks like a path is a name, and works\",\n );\n },\n ],\n ];\n return cases.map(([name, body]) => ({ name, run: () => open(body) }));\n}\n\nfunction listAndOwnerCases(open: (body: Body) => Promise<{ skipped: string } | undefined>): StoreCase[] {\n const cases: [string, Body][] = [\n [\n \"list returns the user's sessions from their headers, oldest first, and delete removes one\",\n async ({ store }) => {\n await store.append({ userId: \"ada\", sessionId: \"late\" }, [\n header(\"h\", \"2026-01-02T00:00:00.000Z\"),\n record(\"r\", \"h\"),\n ]);\n await store.append({ userId: \"ada\", sessionId: \"early\" }, [header(\"h\", \"2026-01-01T00:00:00.000Z\")]);\n const listed = await collect(store.list(\"ada\"));\n check(listed.map((summary) => summary.sessionId).join() === \"early,late\", \"list is oldest first\");\n const late = listed[1];\n check(\n late?.entryCount === 2 && late.startedAt === \"2026-01-02T00:00:00.000Z\",\n \"the summary comes from the entries\",\n );\n await store.delete({ userId: \"ada\", sessionId: \"early\" });\n check((await collect(store.list(\"ada\"))).length === 1, \"delete removes the session\");\n await store.delete({ userId: \"ada\", sessionId: \"early\" });\n },\n ],\n [\n \"another user's session looks the same as one that was never created\",\n async ({ store }) => {\n await store.append(ADA, [header(), record(\"r1\", \"h1\")]);\n const neverMade = await collect(store.load({ userId: \"bob\", sessionId: \"never\" }));\n const adasUnderBob = await collect(store.load(BOB));\n check(\n neverMade.length === 0 && adasUnderBob.length === 0,\n \"loading under another user yields nothing, as for a missing id\",\n );\n check((await collect(store.list(\"bob\"))).length === 0, \"list under another user leaves it out\");\n await store.delete(BOB);\n check((await collect(store.load(ADA))).length === 2, \"delete under another user changed nothing\");\n await store.append(BOB, [header(\"hb\")]);\n check(\n ids(await collect(store.load(ADA))).join() === \"h1,r1\",\n \"bob's session with the same id is a separate session\",\n );\n check(ids(await collect(store.load(BOB))).join() === \"hb\", \"and it holds only bob's entries\");\n },\n ],\n ];\n return cases.map(([name, body]) => ({ name, run: () => open(body) }));\n}\n\nfunction tornCases(open: (body: Body) => Promise<{ skipped: string } | undefined>): StoreCase[] {\n const needsTear = \"the store gave no way to tear a log's last line\";\n const cases: [string, Body][] = [\n [\n \"a torn last line is skipped by load and reported once, with every complete entry kept\",\n async ({ store, tearLastLine }) => {\n if (tearLastLine === undefined) return { skipped: needsTear };\n await store.append(ADA, [header(), record(\"r1\", \"h1\")]);\n await tearLastLine(ADA);\n const reports: number[] = [];\n const loaded = await collect(store.load(ADA, { onTornLine: (line) => reports.push(line.bytes) }));\n check(ids(loaded).join() === \"h1,r1\", \"the complete entries load\");\n check(reports.length === 1 && (reports[0] ?? 0) > 0, \"the torn line is reported once\");\n const clean = await collect(\n store.load(\n { userId: \"ada\", sessionId: \"other\" },\n { onTornLine: () => check(false, \"a clean log reports nothing\") },\n ),\n );\n check(clean.length === 0, \"a missing session yields nothing\");\n },\n ],\n [\n \"an append after a torn line cuts it off, so the next entry is not glued to it\",\n async ({ store, tearLastLine }) => {\n if (tearLastLine === undefined) return { skipped: needsTear };\n await store.append(ADA, [header(), record(\"r1\", \"h1\")]);\n await tearLastLine(ADA);\n const written = await store.append(ADA, [record(\"r2\", \"r1\")], { expectedLastId: \"r1\" });\n check(written[0]?.seq === 2, \"the new entry follows the last complete one\");\n const reports: number[] = [];\n const loaded = await collect(store.load(ADA, { onTornLine: (line) => reports.push(line.bytes) }));\n check(ids(loaded).join() === \"h1,r1,r2\" && reports.length === 0, \"the log is whole again\");\n },\n ],\n ];\n return cases.map(([name, body]) => ({ name, run: () => open(body) }));\n}\n\n/** Every conformance case, each against a store from `factory`. */\nexport function storeConformanceCases(factory: StoreFactory): readonly StoreCase[] {\n const open = async (body: Body) => {\n const outcome = await body(await factory());\n return typeof outcome === \"object\" && outcome !== null && \"skipped\" in outcome ? (outcome as Skip) : undefined;\n };\n return [\n ...appendCases(open),\n ...conflictCases(open),\n ...validationCases(open),\n ...identityCases(open),\n ...keyCases(open),\n ...listAndOwnerCases(open),\n ...tornCases(open),\n ];\n}\n\n/** Runs every case and reports which passed, which skipped with a reason and which failed. */\nexport async function runStoreConformance(factory: StoreFactory): Promise<StoreConformanceReport> {\n return runCases(storeConformanceCases(factory));\n}\n"]}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * `bash`: runs a shell command through `Sandbox.exec()` only, never on the host, with the environment the host chose
3
+ * and a timeout. Its output reaches the model through the context policy's write cap like every tool result, and the
4
+ * sandbox drops what passes the per-stream bound first, so one command can't hold the host's memory.
5
+ */
6
+ import { type ToolDefinition } from "@buildanagent/sdk";
7
+ import type { Sandbox } from "../../sandbox/types.js";
8
+ /** The `bash` tool, which runs each command with `env` as its whole environment. */
9
+ export declare function bashTool(sandbox: Sandbox, env: Readonly<Record<string, string>>): ToolDefinition<unknown, unknown, unknown>;
@@ -0,0 +1,75 @@
1
+ /**
2
+ * `bash`: runs a shell command through `Sandbox.exec()` only, never on the host, with the environment the host chose
3
+ * and a timeout. Its output reaches the model through the context policy's write cap like every tool result, and the
4
+ * sandbox drops what passes the per-stream bound first, so one command can't hold the host's memory.
5
+ */
6
+ import { defineTool } from "@buildanagent/sdk";
7
+ import { BUILTIN_TOOL_DEFAULTS } from "./descriptions.js";
8
+ import { deniedResult, errorResult, failureResult, textResult } from "./results.js";
9
+ /** The text the model reads for a command that ran: its output, its standard error and how it ended. */
10
+ function report(result, timeoutMs) {
11
+ const { maxOutputBytes } = BUILTIN_TOOL_DEFAULTS.bash;
12
+ const parts = [result.stdout];
13
+ if (result.stderr !== "")
14
+ parts.push(`[stderr]\n${result.stderr}`);
15
+ if (result.truncated === true)
16
+ parts.push(`[output past ${maxOutputBytes} bytes per stream was dropped]`);
17
+ // Only the sandbox's flag means the timeout stopped it: a command may exit with 124 itself, as `timeout` does.
18
+ const timedOut = result.timedOut === true;
19
+ const ending = timedOut
20
+ ? `[timed out after ${timeoutMs} ms]`
21
+ : `[exit code ${result.exitCode}${result.signal === undefined ? "" : `, killed by ${result.signal}`}]`;
22
+ parts.push(ending);
23
+ const text = parts.filter((part) => part !== "").join("\n");
24
+ const details = {
25
+ exitCode: result.exitCode,
26
+ ...(result.signal === undefined ? {} : { signal: result.signal }),
27
+ ...(timedOut ? { timedOut } : {}),
28
+ };
29
+ return timedOut ? { ...errorResult(text), details } : textResult(text, details);
30
+ }
31
+ /** The `bash` tool, which runs each command with `env` as its whole environment. */
32
+ export function bashTool(sandbox, env) {
33
+ const { defaultTimeoutMs, maxTimeoutMs, maxOutputBytes, description } = BUILTIN_TOOL_DEFAULTS.bash;
34
+ return defineTool({
35
+ name: "bash",
36
+ description,
37
+ inputSchema: {
38
+ type: "object",
39
+ properties: {
40
+ command: { type: "string", minLength: 1, description: "The command to run, as bash reads it." },
41
+ timeout_ms: {
42
+ type: "integer",
43
+ minimum: 1,
44
+ maximum: maxTimeoutMs,
45
+ description: `Milliseconds before the command is stopped. Default ${defaultTimeoutMs}.`,
46
+ },
47
+ },
48
+ required: ["command"],
49
+ additionalProperties: false,
50
+ },
51
+ firstParty: true,
52
+ effect: { kind: "write" },
53
+ // A command may read or change anything in the workspace, so the calls around it wait their turn.
54
+ executionMode: "sequential",
55
+ async execute(input, ctx) {
56
+ const timeoutMs = Math.min(input.timeout_ms ?? defaultTimeoutMs, maxTimeoutMs);
57
+ let result;
58
+ try {
59
+ result = await sandbox.exec(["bash", "-c", input.command], {
60
+ env,
61
+ signal: ctx.signal,
62
+ timeoutMs,
63
+ maxOutputBytes,
64
+ });
65
+ }
66
+ catch (error) {
67
+ return failureResult(error);
68
+ }
69
+ if ("denied" in result)
70
+ return deniedResult(result.denied);
71
+ return report(result, timeoutMs);
72
+ },
73
+ });
74
+ }
75
+ //# sourceMappingURL=bash.js.map