@jam-overture/loom 0.1.0 → 0.3.0

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 (414) hide show
  1. package/README.md +3 -1
  2. package/dist/application/application.d.ts +109 -0
  3. package/dist/application/application.js +97 -0
  4. package/dist/application/memory.d.ts +20 -0
  5. package/dist/application/memory.js +79 -0
  6. package/dist/application/store.d.ts +101 -0
  7. package/dist/application/store.js +25 -0
  8. package/dist/audience/audience.d.ts +36 -0
  9. package/dist/audience/audience.js +41 -0
  10. package/dist/audience/compose.d.ts +112 -0
  11. package/dist/audience/compose.js +134 -0
  12. package/dist/audience/memory.d.ts +14 -0
  13. package/dist/audience/memory.js +71 -0
  14. package/dist/audience/overlay-store.d.ts +343 -0
  15. package/dist/audience/overlay-store.js +217 -0
  16. package/dist/audience/rule.d.ts +121 -0
  17. package/dist/audience/rule.js +78 -0
  18. package/dist/cli/index.d.ts +3 -4
  19. package/dist/cli/index.js +3 -4
  20. package/dist/cli/templates.js +19 -0
  21. package/dist/data/adapter.d.ts +9 -1
  22. package/dist/data/adapter.js +2 -0
  23. package/dist/data/plan.js +0 -0
  24. package/dist/data/resolution.d.ts +23 -1
  25. package/dist/data/resolve.d.ts +31 -4
  26. package/dist/data/resolve.js +11 -3
  27. package/dist/ids.d.ts +10 -0
  28. package/dist/ids.js +11 -1
  29. package/dist/index.d.ts +1 -0
  30. package/dist/index.js +1 -0
  31. package/dist/interpretation/anthropic.d.ts +1 -1
  32. package/dist/interpretation/anthropic.js +2 -22
  33. package/dist/interpretation/client.d.ts +1 -1
  34. package/dist/interpretation/materialize.js +67 -22
  35. package/dist/interpretation/openai-compatible.d.ts +36 -0
  36. package/dist/interpretation/openai-compatible.js +79 -0
  37. package/dist/interpretation/status.d.ts +19 -0
  38. package/dist/interpretation/status.js +26 -0
  39. package/dist/live/index.d.ts +73 -0
  40. package/dist/live/index.js +73 -0
  41. package/dist/live/pages.d.ts +187 -0
  42. package/dist/live/pages.js +161 -0
  43. package/dist/live/pull.d.ts +147 -0
  44. package/dist/live/pull.js +398 -0
  45. package/dist/live/pulling.d.ts +79 -0
  46. package/dist/live/pulling.js +117 -0
  47. package/dist/live/window.d.ts +129 -0
  48. package/dist/live/window.js +132 -0
  49. package/dist/patch.d.ts +54 -0
  50. package/dist/patch.js +44 -0
  51. package/dist/project/closing.d.ts +51 -0
  52. package/dist/project/closing.js +53 -0
  53. package/dist/project/memory.d.ts +20 -0
  54. package/dist/project/memory.js +97 -0
  55. package/dist/project/project.d.ts +90 -0
  56. package/dist/project/project.js +91 -0
  57. package/dist/project/store.d.ts +135 -0
  58. package/dist/project/store.js +41 -0
  59. package/dist/registered.d.ts +64 -0
  60. package/dist/registered.js +118 -0
  61. package/dist/render/addressed.d.ts +35 -0
  62. package/dist/render/addressed.js +79 -0
  63. package/dist/render/behaviour-adjust.d.ts +11 -19
  64. package/dist/render/behaviour-adjust.js +75 -21
  65. package/dist/render/behaviour-present.d.ts +8 -0
  66. package/dist/render/behaviour-present.js +57 -6
  67. package/dist/render/behaviour.d.ts +98 -17
  68. package/dist/render/behaviour.js +91 -26
  69. package/dist/render/control-name.d.ts +68 -0
  70. package/dist/render/control-name.js +37 -0
  71. package/dist/render/diagnostics.d.ts +72 -0
  72. package/dist/render/diagnostics.js +7 -0
  73. package/dist/render/document-theme.d.ts +70 -0
  74. package/dist/render/document-theme.js +139 -0
  75. package/dist/render/editable.d.ts +15 -1
  76. package/dist/render/editable.js +13 -1
  77. package/dist/render/expected.d.ts +98 -0
  78. package/dist/render/expected.js +88 -0
  79. package/dist/render/index.d.ts +4 -0
  80. package/dist/render/index.js +4 -0
  81. package/dist/render/reads.d.ts +11 -0
  82. package/dist/render/reads.js +12 -1
  83. package/dist/render/render.d.ts +11 -0
  84. package/dist/render/render.js +294 -53
  85. package/dist/render/request.d.ts +8 -1
  86. package/dist/render/request.js +1 -0
  87. package/dist/render/slots.d.ts +52 -0
  88. package/dist/render/slots.js +24 -0
  89. package/dist/render/theme.d.ts +54 -1
  90. package/dist/render/theme.js +23 -1
  91. package/dist/render/unshown.d.ts +152 -0
  92. package/dist/render/unshown.js +80 -0
  93. package/dist/runtime/analysis.d.ts +94 -9
  94. package/dist/runtime/analysis.js +54 -9
  95. package/dist/runtime/assessment.d.ts +36 -2
  96. package/dist/runtime/assessment.js +27 -2
  97. package/dist/runtime/auto-apply-ceiling.d.ts +54 -0
  98. package/dist/runtime/auto-apply-ceiling.js +66 -0
  99. package/dist/runtime/checks.d.ts +148 -0
  100. package/dist/runtime/checks.js +112 -0
  101. package/dist/runtime/disposition.d.ts +96 -0
  102. package/dist/runtime/disposition.js +46 -0
  103. package/dist/runtime/gate.js +91 -10
  104. package/dist/runtime/index.d.ts +4 -0
  105. package/dist/runtime/index.js +4 -0
  106. package/dist/runtime/irreversibility.d.ts +64 -0
  107. package/dist/runtime/irreversibility.js +45 -0
  108. package/dist/runtime/nesting.d.ts +13 -1
  109. package/dist/runtime/nesting.js +41 -24
  110. package/dist/runtime/pipeline.d.ts +43 -0
  111. package/dist/runtime/pipeline.js +10 -2
  112. package/dist/runtime/policy-change.d.ts +93 -0
  113. package/dist/runtime/policy-change.js +305 -0
  114. package/dist/runtime/policy-log.d.ts +406 -0
  115. package/dist/runtime/policy-log.js +285 -0
  116. package/dist/runtime/policy.d.ts +8 -6
  117. package/dist/runtime/policy.js +5 -2
  118. package/dist/runtime/repointing.js +0 -0
  119. package/dist/runtime/reversibility.d.ts +11 -9
  120. package/dist/runtime/stakes.d.ts +129 -1
  121. package/dist/runtime/stakes.js +240 -26
  122. package/dist/runtime/vocabulary.d.ts +164 -7
  123. package/dist/runtime/vocabulary.js +181 -8
  124. package/dist/sdk/audit.d.ts +174 -3
  125. package/dist/sdk/audit.js +176 -17
  126. package/dist/sdk/catalogue.d.ts +9 -1
  127. package/dist/sdk/conformance.d.ts +37 -3
  128. package/dist/sdk/conformance.js +25 -4
  129. package/dist/sdk/definition.d.ts +129 -5
  130. package/dist/sdk/definition.js +66 -0
  131. package/dist/sdk/registry.d.ts +45 -2
  132. package/dist/sdk/registry.js +102 -1
  133. package/dist/signals/acted.contract.d.ts +21 -0
  134. package/dist/signals/acted.contract.js +236 -0
  135. package/dist/signals/acted.d.ts +359 -0
  136. package/dist/signals/acted.js +135 -0
  137. package/dist/signals/action-change.d.ts +507 -0
  138. package/dist/signals/action-change.js +265 -0
  139. package/dist/signals/action.d.ts +331 -0
  140. package/dist/signals/action.js +182 -0
  141. package/dist/signals/agenda.d.ts +585 -0
  142. package/dist/signals/agenda.js +295 -0
  143. package/dist/signals/applied-window.contract.d.ts +23 -0
  144. package/dist/signals/applied-window.contract.js +160 -0
  145. package/dist/signals/arrivals.contract.d.ts +21 -0
  146. package/dist/signals/arrivals.contract.js +180 -0
  147. package/dist/signals/arrivals.d.ts +375 -0
  148. package/dist/signals/arrivals.js +254 -0
  149. package/dist/signals/arriving.d.ts +210 -0
  150. package/dist/signals/arriving.js +133 -0
  151. package/dist/signals/audiences.d.ts +528 -0
  152. package/dist/signals/audiences.js +255 -0
  153. package/dist/signals/broadcast.d.ts +33 -17
  154. package/dist/signals/broadcast.js +255 -32
  155. package/dist/signals/change.d.ts +378 -0
  156. package/dist/signals/change.js +327 -0
  157. package/dist/signals/collect.d.ts +169 -34
  158. package/dist/signals/collect.js +186 -38
  159. package/dist/signals/conversion.d.ts +348 -0
  160. package/dist/signals/conversion.js +235 -0
  161. package/dist/signals/copy-change.d.ts +553 -0
  162. package/dist/signals/copy-change.js +377 -0
  163. package/dist/signals/copy.d.ts +337 -0
  164. package/dist/signals/copy.js +211 -0
  165. package/dist/signals/correlated.contract.d.ts +24 -0
  166. package/dist/signals/correlated.contract.js +94 -0
  167. package/dist/signals/counters.d.ts +97 -0
  168. package/dist/signals/counters.js +160 -0
  169. package/dist/signals/deliver.d.ts +23 -4
  170. package/dist/signals/deliver.js +34 -6
  171. package/dist/signals/deployment-change.d.ts +395 -0
  172. package/dist/signals/deployment-change.js +309 -0
  173. package/dist/signals/deployment.d.ts +278 -0
  174. package/dist/signals/deployment.js +178 -0
  175. package/dist/signals/door.d.ts +114 -0
  176. package/dist/signals/door.js +77 -0
  177. package/dist/signals/expire.d.ts +192 -0
  178. package/dist/signals/expire.js +213 -0
  179. package/dist/signals/fold.d.ts +10 -0
  180. package/dist/signals/fold.js +5 -1
  181. package/dist/signals/form-action.d.ts +302 -0
  182. package/dist/signals/form-action.js +169 -0
  183. package/dist/signals/form-copy.d.ts +523 -0
  184. package/dist/signals/form-copy.js +346 -0
  185. package/dist/signals/forms.d.ts +247 -0
  186. package/dist/signals/forms.js +147 -0
  187. package/dist/signals/frontier.d.ts +268 -0
  188. package/dist/signals/frontier.js +145 -0
  189. package/dist/signals/funnel-change.d.ts +548 -0
  190. package/dist/signals/funnel-change.js +361 -0
  191. package/dist/signals/funnel-hours.contract.d.ts +21 -0
  192. package/dist/signals/funnel-hours.contract.js +221 -0
  193. package/dist/signals/funnel-hours.d.ts +293 -0
  194. package/dist/signals/funnel-hours.js +99 -0
  195. package/dist/signals/funnel.d.ts +592 -0
  196. package/dist/signals/funnel.js +231 -0
  197. package/dist/signals/health.d.ts +694 -0
  198. package/dist/signals/health.js +573 -0
  199. package/dist/signals/index.d.ts +60 -0
  200. package/dist/signals/index.js +60 -0
  201. package/dist/signals/ingest.d.ts +56 -1
  202. package/dist/signals/ingest.js +91 -1
  203. package/dist/signals/inside.d.ts +190 -0
  204. package/dist/signals/inside.js +263 -0
  205. package/dist/signals/join.d.ts +56 -0
  206. package/dist/signals/join.js +60 -0
  207. package/dist/signals/journal.d.ts +123 -9
  208. package/dist/signals/kept.contract.d.ts +22 -0
  209. package/dist/signals/kept.contract.js +111 -0
  210. package/dist/signals/kinds.d.ts +8 -6
  211. package/dist/signals/kinds.js +14 -6
  212. package/dist/signals/library-action.d.ts +430 -0
  213. package/dist/signals/library-action.js +336 -0
  214. package/dist/signals/library-agenda-change.d.ts +324 -0
  215. package/dist/signals/library-agenda-change.js +199 -0
  216. package/dist/signals/library-agenda.d.ts +258 -0
  217. package/dist/signals/library-agenda.js +167 -0
  218. package/dist/signals/library-change.d.ts +477 -0
  219. package/dist/signals/library-change.js +335 -0
  220. package/dist/signals/library-copy-change.d.ts +498 -0
  221. package/dist/signals/library-copy-change.js +476 -0
  222. package/dist/signals/library-pace.d.ts +319 -0
  223. package/dist/signals/library-pace.js +305 -0
  224. package/dist/signals/library-reach-change.d.ts +646 -0
  225. package/dist/signals/library-reach-change.js +542 -0
  226. package/dist/signals/library-reach.d.ts +377 -0
  227. package/dist/signals/library-reach.js +227 -0
  228. package/dist/signals/library-senders-change.d.ts +457 -0
  229. package/dist/signals/library-senders-change.js +367 -0
  230. package/dist/signals/library-senders-reach-change.d.ts +486 -0
  231. package/dist/signals/library-senders-reach-change.js +538 -0
  232. package/dist/signals/library-senders-reach.d.ts +340 -0
  233. package/dist/signals/library-senders-reach.js +252 -0
  234. package/dist/signals/library-senders.d.ts +271 -0
  235. package/dist/signals/library-senders.js +180 -0
  236. package/dist/signals/library-word-reach-change.d.ts +567 -0
  237. package/dist/signals/library-word-reach-change.js +564 -0
  238. package/dist/signals/library.d.ts +306 -0
  239. package/dist/signals/library.js +178 -0
  240. package/dist/signals/memory.d.ts +9 -0
  241. package/dist/signals/memory.js +246 -14
  242. package/dist/signals/migrate.d.ts +20 -4
  243. package/dist/signals/migrate.js +269 -8
  244. package/dist/signals/notice.d.ts +389 -0
  245. package/dist/signals/notice.js +250 -0
  246. package/dist/signals/pace-change.d.ts +501 -0
  247. package/dist/signals/pace-change.js +310 -0
  248. package/dist/signals/pace.d.ts +296 -0
  249. package/dist/signals/pace.js +291 -0
  250. package/dist/signals/page-views.d.ts +365 -0
  251. package/dist/signals/page-views.js +218 -0
  252. package/dist/signals/part-pace.d.ts +378 -0
  253. package/dist/signals/part-pace.js +333 -0
  254. package/dist/signals/parts.d.ts +354 -0
  255. package/dist/signals/parts.js +232 -0
  256. package/dist/signals/postgres.d.ts +16 -2
  257. package/dist/signals/postgres.js +753 -76
  258. package/dist/signals/progress.d.ts +212 -0
  259. package/dist/signals/progress.js +150 -0
  260. package/dist/signals/ratios.d.ts +108 -0
  261. package/dist/signals/ratios.js +40 -0
  262. package/dist/signals/reach.d.ts +309 -0
  263. package/dist/signals/reach.js +93 -0
  264. package/dist/signals/readable.d.ts +34 -0
  265. package/dist/signals/readable.js +34 -0
  266. package/dist/signals/readership.d.ts +381 -0
  267. package/dist/signals/readership.js +308 -0
  268. package/dist/signals/region-pages.d.ts +173 -0
  269. package/dist/signals/region-pages.js +62 -0
  270. package/dist/signals/region.d.ts +287 -0
  271. package/dist/signals/region.js +198 -0
  272. package/dist/signals/retention.d.ts +163 -0
  273. package/dist/signals/retention.js +75 -0
  274. package/dist/signals/rhythm.d.ts +302 -0
  275. package/dist/signals/rhythm.js +262 -0
  276. package/dist/signals/rollup.d.ts +194 -4
  277. package/dist/signals/rollup.js +0 -0
  278. package/dist/signals/schema.d.ts +1069 -1
  279. package/dist/signals/schema.js +393 -3
  280. package/dist/signals/signal.d.ts +237 -11
  281. package/dist/signals/signal.js +70 -10
  282. package/dist/signals/silence-census.d.ts +205 -0
  283. package/dist/signals/silence-census.js +87 -0
  284. package/dist/signals/silences.d.ts +1147 -0
  285. package/dist/signals/silences.js +996 -0
  286. package/dist/signals/subtrees.d.ts +123 -0
  287. package/dist/signals/subtrees.js +102 -0
  288. package/dist/signals/tally.d.ts +262 -12
  289. package/dist/signals/unread.d.ts +292 -0
  290. package/dist/signals/unread.js +137 -0
  291. package/dist/signals/window-agenda.d.ts +276 -0
  292. package/dist/signals/window-agenda.js +83 -0
  293. package/dist/signals/window-figures.d.ts +148 -0
  294. package/dist/signals/window-figures.js +42 -0
  295. package/dist/signals/window-funnels.d.ts +88 -0
  296. package/dist/signals/window-funnels.js +47 -0
  297. package/dist/signals/window.d.ts +866 -0
  298. package/dist/signals/window.js +693 -0
  299. package/dist/signals/words.d.ts +24 -0
  300. package/dist/signals/words.js +24 -0
  301. package/dist/store/cache.d.ts +101 -0
  302. package/dist/store/cache.js +149 -0
  303. package/dist/store/history.d.ts +82 -0
  304. package/dist/store/history.js +36 -0
  305. package/dist/store/index.d.ts +30 -0
  306. package/dist/store/index.js +30 -0
  307. package/dist/store/memory.d.ts +2 -1
  308. package/dist/store/memory.js +48 -12
  309. package/dist/store/migrate.d.ts +106 -0
  310. package/dist/store/migrate.js +323 -7
  311. package/dist/store/postgres-applications.d.ts +4 -0
  312. package/dist/store/postgres-applications.js +197 -0
  313. package/dist/store/postgres-audience.d.ts +14 -0
  314. package/dist/store/postgres-audience.js +272 -0
  315. package/dist/store/postgres-holds.d.ts +10 -1
  316. package/dist/store/postgres-holds.js +116 -101
  317. package/dist/store/postgres-policy-log.d.ts +14 -0
  318. package/dist/store/postgres-policy-log.js +240 -0
  319. package/dist/store/postgres-projects.d.ts +4 -0
  320. package/dist/store/postgres-projects.js +217 -0
  321. package/dist/store/postgres.d.ts +17 -1
  322. package/dist/store/postgres.js +60 -9
  323. package/dist/store/replay.d.ts +102 -1
  324. package/dist/store/replay.js +190 -19
  325. package/dist/store/reseed.d.ts +238 -0
  326. package/dist/store/reseed.js +308 -0
  327. package/dist/store/schema.d.ts +762 -2
  328. package/dist/store/schema.js +218 -5
  329. package/dist/store/source.d.ts +57 -1
  330. package/dist/store/source.js +65 -1
  331. package/dist/store/store.d.ts +29 -6
  332. package/dist/submit/resolve.d.ts +1 -1
  333. package/dist/submit/resolve.js +2 -1
  334. package/dist/telemetry/calibration.d.ts +25 -0
  335. package/dist/telemetry/calibration.js +27 -1
  336. package/dist/telemetry/event.d.ts +391 -33
  337. package/dist/telemetry/event.js +84 -20
  338. package/dist/telemetry/index.d.ts +2 -0
  339. package/dist/telemetry/index.js +2 -0
  340. package/dist/telemetry/journal.d.ts +104 -3
  341. package/dist/telemetry/journal.js +9 -0
  342. package/dist/telemetry/lookup.d.ts +27 -0
  343. package/dist/telemetry/lookup.js +18 -0
  344. package/dist/telemetry/memory.js +33 -1
  345. package/dist/telemetry/migrate.js +22 -1
  346. package/dist/telemetry/postgres.d.ts +10 -1
  347. package/dist/telemetry/postgres.js +188 -90
  348. package/dist/telemetry/remeasure.d.ts +78 -0
  349. package/dist/telemetry/remeasure.js +83 -0
  350. package/dist/telemetry/retention.d.ts +2 -2
  351. package/dist/telemetry/schema.d.ts +17 -0
  352. package/dist/telemetry/schema.js +27 -1
  353. package/dist/telemetry/sink.d.ts +2 -2
  354. package/dist/telemetry/window.d.ts +135 -0
  355. package/dist/telemetry/window.js +101 -0
  356. package/dist/testing/application-contract.d.ts +14 -0
  357. package/dist/testing/application-contract.js +270 -0
  358. package/dist/testing/audience-overlay-contract.d.ts +31 -0
  359. package/dist/testing/audience-overlay-contract.js +354 -0
  360. package/dist/testing/contracts.d.ts +13 -7
  361. package/dist/testing/contracts.js +13 -7
  362. package/dist/testing/definitions.d.ts +78 -0
  363. package/dist/testing/definitions.js +134 -9
  364. package/dist/testing/doubles.d.ts +103 -0
  365. package/dist/testing/doubles.js +143 -0
  366. package/dist/testing/index.d.ts +2 -2
  367. package/dist/testing/index.js +2 -2
  368. package/dist/testing/journal-contract.js +297 -6
  369. package/dist/testing/model-contract.d.ts +110 -0
  370. package/dist/testing/model-contract.js +150 -0
  371. package/dist/testing/policy-log-contract.d.ts +26 -0
  372. package/dist/testing/policy-log-contract.js +344 -0
  373. package/dist/testing/project-contract.d.ts +14 -0
  374. package/dist/testing/project-contract.js +266 -0
  375. package/dist/testing/reader-signal-contract.d.ts +27 -2
  376. package/dist/testing/reader-signal-contract.js +475 -5
  377. package/dist/testing/store-contract.d.ts +7 -1
  378. package/dist/testing/store-contract.js +84 -3
  379. package/dist/theme/apply.d.ts +20 -1
  380. package/dist/theme/apply.js +5 -3
  381. package/dist/theme/contrast.d.ts +19 -14
  382. package/dist/theme/contrast.js +181 -17
  383. package/dist/theme/derive.d.ts +22 -0
  384. package/dist/theme/derive.js +54 -1
  385. package/dist/theme/library.js +1 -1
  386. package/dist/theme/measure.d.ts +34 -0
  387. package/dist/theme/measure.js +30 -1
  388. package/dist/theme/palettes.js +7 -7
  389. package/dist/theme/ramp.d.ts +64 -0
  390. package/dist/theme/ramp.js +114 -0
  391. package/dist/theme/registry.d.ts +9 -0
  392. package/dist/theme/registry.js +11 -1
  393. package/dist/theme/separation.d.ts +97 -3
  394. package/dist/theme/separation.js +75 -0
  395. package/dist/tree/apply.js +13 -0
  396. package/dist/tree/compare.d.ts +9 -0
  397. package/dist/tree/compare.js +18 -0
  398. package/dist/tree/mutation.d.ts +18 -0
  399. package/dist/tree/mutation.js +24 -12
  400. package/dist/tree/navigation.d.ts +5 -0
  401. package/dist/tree/navigation.js +32 -10
  402. package/dist/tree/outline.d.ts +7 -0
  403. package/dist/tree/outline.js +9 -5
  404. package/dist/write/computed.d.ts +60 -0
  405. package/dist/write/computed.js +61 -0
  406. package/dist/write/held.d.ts +59 -0
  407. package/dist/write/index.d.ts +5 -2
  408. package/dist/write/index.js +5 -2
  409. package/dist/write/reseed.d.ts +151 -0
  410. package/dist/write/reseed.js +184 -0
  411. package/dist/write/revert.js +2 -16
  412. package/package.json +25 -3
  413. package/dist/runtime/inverse-interpreter.d.ts +0 -90
  414. package/dist/runtime/inverse-interpreter.js +0 -56
@@ -1,9 +1,9 @@
1
1
  import { describe, expect, it } from "vitest";
2
2
  import { sequentialIdFactory, treeIdSchema } from "../ids.js";
3
- import { recordOf } from "../telemetry/index.js";
3
+ import { describeTelemetryWindowFault, MAX_ASSESSMENT_LOOKUP, MAX_TELEMETRY_LIMIT, recordOf, telemetryWindow, } from "../telemetry/index.js";
4
4
  import { buildElement } from "../tree/builders.js";
5
5
  import { createTree } from "../tree/tree.js";
6
- import { buildIntent, buildProposal, FIXED_INSTANT } from "./doubles.js";
6
+ import { buildAssessment, buildIntent, buildProposal, FIXED_INSTANT } from "./doubles.js";
7
7
  /**
8
8
  * One suite, run against every `TelemetryJournal`.
9
9
  *
@@ -60,6 +60,32 @@ const recordsFor = (treeId, count) => Array.from({ length: count }, (_, index) =
60
60
  },
61
61
  }));
62
62
  const typesOf = (records) => records.map((record) => record.event.type);
63
+ /**
64
+ * One `change-assessed` record, narrowed the way a host's would be.
65
+ *
66
+ * Through `buildAssessment` and `recordOf` rather than written out as a literal,
67
+ * so the suite is asserting against a record a real run of Loom could produce —
68
+ * the rule the 3 October fixture entry was filed about.
69
+ */
70
+ const assessedRecord = (treeId, namespace, options = {}) => {
71
+ const ids = sequentialIdFactory(namespace);
72
+ const proposal = buildProposal(ids, {
73
+ intentId: ids.intentId(),
74
+ delta: { deltaId: ids.deltaId(), treeId, baseRevision: 0, operations: [] },
75
+ });
76
+ const assessment = buildAssessment(ids, {
77
+ proposal,
78
+ analysis: { removedNodeCount: options.removedNodeCount ?? 0 },
79
+ });
80
+ return {
81
+ record: recordOf({
82
+ treeId,
83
+ occurredAt: FIXED_INSTANT,
84
+ event: { type: "change-assessed", assessment },
85
+ }),
86
+ proposalId: proposal.proposalId,
87
+ };
88
+ };
63
89
  export const describeTelemetryJournalContract = (name, makeJournal) => {
64
90
  const freshJournal = async () => await makeJournal();
65
91
  describe(`${name} — TelemetryJournal contract`, () => {
@@ -77,7 +103,7 @@ export const describeTelemetryJournalContract = (name, makeJournal) => {
77
103
  const journal = await freshJournal();
78
104
  expect(await journal.read({ treeId: treeIdSchema.parse("t_absent") })).toEqual({
79
105
  ok: true,
80
- value: { records: [], older: null, newer: null },
106
+ value: { records: [], older: null, newer: null, span: null },
81
107
  });
82
108
  });
83
109
  it("accepts an empty batch", async () => {
@@ -85,7 +111,7 @@ export const describeTelemetryJournalContract = (name, makeJournal) => {
85
111
  expect(await journal.record([])).toEqual({ ok: true, value: undefined });
86
112
  expect(await journal.read()).toEqual({
87
113
  ok: true,
88
- value: { records: [], older: null, newer: null },
114
+ value: { records: [], older: null, newer: null, span: null },
89
115
  });
90
116
  });
91
117
  it("survives the round trip with the proposal intact", async () => {
@@ -178,7 +204,119 @@ export const describeTelemetryJournalContract = (name, makeJournal) => {
178
204
  const all = await journal.read();
179
205
  const last = all.ok ? all.value.records.at(-1) : undefined;
180
206
  const past = await journal.read({ cursor: String(last?.seq ?? 0) });
181
- expect(past).toEqual({ ok: true, value: { records: [], older: null, newer: null } });
207
+ expect(past).toEqual({ ok: true, value: { records: [], older: null, newer: null, span: null } });
208
+ });
209
+ });
210
+ /**
211
+ * The join, not a page.
212
+ *
213
+ * A revision log holds a `proposalId` and no judgment (0016, 0225), so the
214
+ * only way a screen can say *undoing this will not undo everything* is to
215
+ * ask the journal about the proposals it is already holding. What a journal
216
+ * owes is that both implementations answer the same way about an id it has
217
+ * never heard of, about an id narrated twice, and about more ids than one
218
+ * lookup reaches.
219
+ */
220
+ describe("looking an assessment up by proposal", () => {
221
+ it("answers about the proposals it was asked about and no others", async () => {
222
+ const journal = await freshJournal();
223
+ const treeId = treeIdSchema.parse("t_lookup");
224
+ const wanted = assessedRecord(treeId, "want", { removedNodeCount: 3 });
225
+ const other = assessedRecord(treeId, "other");
226
+ await journal.record([wanted.record, other.record]);
227
+ const found = await journal.assessments({ proposalIds: [wanted.proposalId] });
228
+ expect(found.ok && [...found.value.assessments.keys()]).toEqual([wanted.proposalId]);
229
+ expect(found.ok && found.value.assessments.get(wanted.proposalId)?.removedNodeCount).toBe(3);
230
+ expect(found.ok && found.value.unasked).toEqual([]);
231
+ });
232
+ /** The same reason there is no `not-found`: a journal claims nothing exists. */
233
+ it("leaves a proposal it has never heard of out of the map rather than failing", async () => {
234
+ const journal = await freshJournal();
235
+ const treeId = treeIdSchema.parse("t_absentlookup");
236
+ const known = assessedRecord(treeId, "known");
237
+ const stranger = assessedRecord(treeId, "stranger");
238
+ await journal.record([known.record]);
239
+ const found = await journal.assessments({
240
+ proposalIds: [known.proposalId, stranger.proposalId],
241
+ });
242
+ expect(found.ok && found.value.assessments.has(known.proposalId)).toBe(true);
243
+ expect(found.ok && found.value.assessments.has(stranger.proposalId)).toBe(false);
244
+ expect(found.ok && found.value.unasked).toEqual([]);
245
+ });
246
+ it("asks nothing and answers emptily for an empty lookup", async () => {
247
+ const journal = await freshJournal();
248
+ expect(await journal.assessments({ proposalIds: [] })).toEqual({
249
+ ok: true,
250
+ value: { assessments: new Map(), unasked: [] },
251
+ });
252
+ });
253
+ /**
254
+ * A journal is append-only, so a proposal narrated twice is a history
255
+ * rather than a fault — and the later record is the one that describes
256
+ * what the Gate last read.
257
+ */
258
+ it("answers with the latest assessment when a proposal was narrated twice", async () => {
259
+ const journal = await freshJournal();
260
+ const treeId = treeIdSchema.parse("t_twice");
261
+ const first = assessedRecord(treeId, "twice", { removedNodeCount: 1 });
262
+ const second = assessedRecord(treeId, "twice", { removedNodeCount: 9 });
263
+ await journal.record([first.record, second.record]);
264
+ const found = await journal.assessments({ proposalIds: [first.proposalId] });
265
+ expect(first.proposalId).toEqual(second.proposalId);
266
+ expect(found.ok && found.value.assessments.get(first.proposalId)?.removedNodeCount).toBe(9);
267
+ });
268
+ it("counts a repeated id once rather than spending the lookup on it", async () => {
269
+ const journal = await freshJournal();
270
+ const treeId = treeIdSchema.parse("t_repeat");
271
+ const one = assessedRecord(treeId, "repeat");
272
+ await journal.record([one.record]);
273
+ const found = await journal.assessments({
274
+ proposalIds: Array.from({ length: MAX_ASSESSMENT_LOOKUP + 1 }, () => one.proposalId),
275
+ });
276
+ expect(found.ok && found.value.assessments.size).toBe(1);
277
+ expect(found.ok && found.value.unasked).toEqual([]);
278
+ });
279
+ /**
280
+ * Every read in Loom is bounded. What this pins is that going over the
281
+ * bound is *said* rather than silently dropped: on the screen this exists
282
+ * for, "nothing was recorded" and "nobody looked" would otherwise be the
283
+ * same blank.
284
+ */
285
+ it("names the ids beyond the cap instead of dropping them", async () => {
286
+ const journal = await freshJournal();
287
+ const treeId = treeIdSchema.parse("t_cap");
288
+ const asked = Array.from({ length: MAX_ASSESSMENT_LOOKUP + 2 }, (_, index) => assessedRecord(treeId, `cap${index}`).proposalId);
289
+ const found = await journal.assessments({ proposalIds: asked });
290
+ expect(found.ok && found.value.unasked).toEqual(asked.slice(MAX_ASSESSMENT_LOOKUP));
291
+ });
292
+ it("keeps trees apart when a lookup names one", async () => {
293
+ const journal = await freshJournal();
294
+ const mine = treeIdSchema.parse("t_minelookup");
295
+ const yours = treeIdSchema.parse("t_yourslookup");
296
+ const ours = assessedRecord(yours, "ours");
297
+ await journal.record([ours.record]);
298
+ const wrongTree = await journal.assessments({
299
+ proposalIds: [ours.proposalId],
300
+ treeId: mine,
301
+ });
302
+ const rightTree = await journal.assessments({
303
+ proposalIds: [ours.proposalId],
304
+ treeId: yours,
305
+ });
306
+ expect(wrongTree.ok && wrongTree.value.assessments.size).toBe(0);
307
+ expect(rightTree.ok && rightTree.value.assessments.size).toBe(1);
308
+ });
309
+ /** A record a prune has forgotten is a record nothing can join against. */
310
+ it("stops answering about a proposal whose record was forgotten", async () => {
311
+ const journal = await freshJournal();
312
+ const treeId = treeIdSchema.parse("t_forgotten");
313
+ const gone = assessedRecord(treeId, "gone");
314
+ await journal.record([gone.record]);
315
+ const page = await journal.read();
316
+ const last = page.ok ? page.value.records.at(-1) : undefined;
317
+ await journal.forget({ before: (last?.seq ?? 0) + 1 });
318
+ const found = await journal.assessments({ proposalIds: [gone.proposalId] });
319
+ expect(found.ok && found.value.assessments.size).toBe(0);
182
320
  });
183
321
  });
184
322
  /**
@@ -268,7 +406,7 @@ export const describeTelemetryJournalContract = (name, makeJournal) => {
268
406
  });
269
407
  expect(await journal.read()).toEqual({
270
408
  ok: true,
271
- value: { records: [], older: null, newer: null },
409
+ value: { records: [], older: null, newer: null, span: null },
272
410
  });
273
411
  });
274
412
  it("accepts a position an empty journal has nothing below", async () => {
@@ -348,6 +486,159 @@ export const describeTelemetryJournalContract = (name, makeJournal) => {
348
486
  expect(page.ok && page.value.records).toHaveLength(2);
349
487
  });
350
488
  });
489
+ /**
490
+ * The read a person actually asks for, and the one a journal paged by
491
+ * arrival could not answer.
492
+ *
493
+ * Every bound here is taken off the journal's own stamps rather than off the
494
+ * clock in this process. A journal in memory stamps from a clock it was
495
+ * handed; a journal in Postgres stamps from `now()` on the database server,
496
+ * whose reading of the hour is its own. A suite that composed a bound
497
+ * locally would be asserting that two machines agree about the time, which
498
+ * is the one thing a `recordedAt` exists because they do not.
499
+ */
500
+ describe("asking for a stretch of time", () => {
501
+ const spanOrThrow = async (journal) => {
502
+ const page = await journal.read({ limit: MAX_TELEMETRY_LIMIT });
503
+ if (!page.ok)
504
+ throw new Error("the journal could not be read");
505
+ if (page.value.span === null)
506
+ throw new Error("the journal reported no span to bound by");
507
+ return page.value.span;
508
+ };
509
+ const windowOrThrow = (request) => {
510
+ const built = telemetryWindow(request);
511
+ if (!built.ok)
512
+ throw new Error(describeTelemetryWindowFault(built.error));
513
+ return built.value;
514
+ };
515
+ /** One millisecond past a stamp, which is the smallest exclusive upper bound that holds it. */
516
+ const justAfter = (stamp) => new Date(Date.parse(stamp) + 1).toISOString();
517
+ it("reports the stretch a page covers, and reports nothing for a page with no records", async () => {
518
+ const journal = await freshJournal();
519
+ expect(await journal.read()).toMatchObject({ ok: true, value: { span: null } });
520
+ await journal.record(sampleEpisode("span"));
521
+ const page = await journal.read();
522
+ if (!page.ok)
523
+ throw new Error("the journal could not be read");
524
+ const span = page.value.span;
525
+ expect(span).not.toBeNull();
526
+ expect(page.value.records.every((record) => Date.parse(record.recordedAt) >= Date.parse(span?.from ?? "") &&
527
+ Date.parse(record.recordedAt) <= Date.parse(span?.to ?? ""))).toBe(true);
528
+ });
529
+ it("holds every record when the window spans the journal's own ends", async () => {
530
+ const journal = await freshJournal();
531
+ const episode = sampleEpisode("whole");
532
+ await journal.record(episode);
533
+ const span = await spanOrThrow(journal);
534
+ const page = await journal.read({
535
+ window: windowOrThrow({ since: span.from, until: justAfter(span.to) }),
536
+ });
537
+ expect(page.ok && typesOf(page.value.records)).toEqual(typesOf(episode));
538
+ });
539
+ /**
540
+ * `since` is inclusive and `until` is not, which is what lets two
541
+ * consecutive windows tile. The two assertions are the two ends of that
542
+ * one claim: the earliest stamp is in a window that begins on it, and out
543
+ * of a window that ends on it.
544
+ */
545
+ it("includes a record on its since and excludes one on its until", async () => {
546
+ const journal = await freshJournal();
547
+ await journal.record(sampleEpisode("ends"));
548
+ const span = await spanOrThrow(journal);
549
+ const from = await journal.read({ window: windowOrThrow({ since: span.from }) });
550
+ const upTo = await journal.read({ window: windowOrThrow({ until: span.from }) });
551
+ expect(from.ok && from.value.records.length).toBeGreaterThan(0);
552
+ expect(upTo.ok && upTo.value.records).toEqual([]);
553
+ expect(upTo.ok && upTo.value.span).toBeNull();
554
+ });
555
+ /**
556
+ * The property the half-open shape exists for: a boundary cuts the
557
+ * journal in two and loses nothing and counts nothing twice. An
558
+ * implementation that made `until` inclusive passes every other test here
559
+ * and fails this one, because the record stamped exactly on the boundary
560
+ * turns up on both sides.
561
+ */
562
+ it("tiles: a boundary splits the journal with nothing lost and nothing counted twice", async () => {
563
+ const journal = await freshJournal();
564
+ await journal.record(sampleEpisode("tilea"));
565
+ await journal.record(sampleEpisode("tileb"));
566
+ const span = await spanOrThrow(journal);
567
+ const everything = await journal.read({ limit: MAX_TELEMETRY_LIMIT });
568
+ const before = await journal.read({
569
+ window: windowOrThrow({ until: span.to }),
570
+ limit: MAX_TELEMETRY_LIMIT,
571
+ });
572
+ const after = await journal.read({
573
+ window: windowOrThrow({ since: span.to }),
574
+ limit: MAX_TELEMETRY_LIMIT,
575
+ });
576
+ const seqsIn = (page) => page.ok ? page.value.records.map((record) => record.seq) : [];
577
+ const split = [...seqsIn(before), ...seqsIn(after)].sort((a, b) => a - b);
578
+ expect(split).toEqual(seqsIn(everything));
579
+ expect(new Set(split).size).toBe(split.length);
580
+ });
581
+ /**
582
+ * A window is measured against `recordedAt` and never against
583
+ * `occurredAt`, and this is the test that can tell. Every record in the
584
+ * fixture carries an `occurredAt` months in the past, so a window bounded
585
+ * at the journal's own stamps holds them all — and an implementation that
586
+ * bounded on what the host said would answer with nothing at all.
587
+ */
588
+ it("measures the window against when it learned of a record, not against what the host said", async () => {
589
+ const journal = await freshJournal();
590
+ const episode = sampleEpisode("stamped");
591
+ await journal.record(episode);
592
+ const span = await spanOrThrow(journal);
593
+ const page = await journal.read({ window: windowOrThrow({ since: span.from }) });
594
+ expect(page.ok && page.value.records).toHaveLength(episode.length);
595
+ expect(page.ok && page.value.records.every((record) => record.occurredAt === FIXED_INSTANT)).toBe(true);
596
+ expect(Date.parse(span.from)).toBeGreaterThan(Date.parse(FIXED_INSTANT));
597
+ });
598
+ it("reads a window nothing landed in as an empty page rather than an error", async () => {
599
+ const journal = await freshJournal();
600
+ await journal.record(sampleEpisode("after"));
601
+ const span = await spanOrThrow(journal);
602
+ expect(await journal.read({ window: windowOrThrow({ since: justAfter(span.to) }) })).toEqual({ ok: true, value: { records: [], older: null, newer: null, span: null } });
603
+ });
604
+ /**
605
+ * The cursors a windowed page names stay inside the window. A `beyond`
606
+ * probe that ignored the bound would hand back a cursor pointing at a
607
+ * record the window excludes, and a reader paging to the end of *last
608
+ * week* would walk out of it without being told.
609
+ */
610
+ it("pages within the window and never out of it", async () => {
611
+ const journal = await freshJournal();
612
+ const treeId = treeIdSchema.parse("t_windowpage");
613
+ await journal.record(recordsFor(treeId, 5));
614
+ const span = await spanOrThrow(journal);
615
+ const bounded = windowOrThrow({ since: span.from, until: justAfter(span.to) });
616
+ const collected = [];
617
+ let cursor;
618
+ do {
619
+ const page = await journal.read({ window: bounded, limit: 2, ...(cursor ? { cursor } : {}) });
620
+ if (!page.ok)
621
+ throw new Error("the journal could not be read");
622
+ collected.push(...page.value.records.map((record) => record.seq));
623
+ cursor = page.value.newer;
624
+ } while (cursor);
625
+ expect(collected).toHaveLength(5);
626
+ expect(new Set(collected).size).toBe(5);
627
+ });
628
+ it("narrows by tree and by window together", async () => {
629
+ const journal = await freshJournal();
630
+ const mine = treeIdSchema.parse("t_wmine");
631
+ const yours = treeIdSchema.parse("t_wyours");
632
+ await journal.record([...recordsFor(mine, 2), ...recordsFor(yours, 3)]);
633
+ const span = await spanOrThrow(journal);
634
+ const page = await journal.read({
635
+ treeId: yours,
636
+ window: windowOrThrow({ since: span.from, until: justAfter(span.to) }),
637
+ });
638
+ expect(page.ok && page.value.records).toHaveLength(3);
639
+ expect(page.ok && page.value.records.every((record) => record.treeId === yours)).toBe(true);
640
+ });
641
+ });
351
642
  });
352
643
  };
353
644
  //# sourceMappingURL=journal-contract.js.map
@@ -0,0 +1,110 @@
1
+ import type { ModelClient } from "../interpretation/client.js";
2
+ import type { ModelRequest } from "../interpretation/client.js";
3
+ /**
4
+ * One suite, run against every `ModelClient`.
5
+ *
6
+ * `ModelClient` is the seam a host is likeliest to implement — 0005 made the
7
+ * vendor adapter opt-in precisely so a host could bring its own — and it is the
8
+ * only published seam that had no suite. The three stores and the journal each
9
+ * got one as soon as there were two implementations; this one has had exactly
10
+ * one implementation since day 37, so the promises it makes have been held by
11
+ * `anthropic.test.ts` and by nothing a host can run.
12
+ *
13
+ * **The promises are not in the type, and they are not obvious.** `complete`
14
+ * returns `Promise<Result<…>>` on paper whatever an implementation does with a
15
+ * socket that closes; what the runtime needs is narrower, and all of it is
16
+ * invisible to the compiler:
17
+ *
18
+ * - The five error codes name *who must act*, not what went wrong. A key the
19
+ * service rejects and a rate limit are both "it did not answer"; one needs an
20
+ * operator and the other needs a wait, and an implementation that collapses
21
+ * them tells a host to stop trying something that would have worked. They
22
+ * were one code until day 37, and the merge was a lie downstream could not
23
+ * detect.
24
+ * - The reply text crosses **unchanged**. Parsing, validating and deciding what
25
+ * a bad answer means live above this seam (0005), so an adapter that trims,
26
+ * unwraps a fence or parses on the way through has moved a decision below the
27
+ * line and taken it away from the tests that cover it.
28
+ * - Nothing throws. The interpreter reads a `Result`; a rejected promise from
29
+ * this call is an exception on a path that has no handler.
30
+ *
31
+ * ## What a host supplies
32
+ *
33
+ * Not a client — a **situation**, answered for every member of `ModelSituation`.
34
+ * A suite that took one client could check that a success is a success and
35
+ * nothing else, because nobody can make a real service return a 402 on demand.
36
+ * So the host wires each situation to whatever their vendor does in it, the
37
+ * same way `anthropic.test.ts` stubs `messages.create`, and this suite says
38
+ * what the answer has to be.
39
+ *
40
+ * It is a record keyed by every situation rather than a list of the ones a host
41
+ * felt like covering, and `everyMemberOf` makes that a compile-time fact: a
42
+ * situation added here stops every host's call compiling until they have
43
+ * answered it. A list would have gone quietly out of date on the first one.
44
+ */
45
+ /**
46
+ * What happened, in terms every vendor has rather than one vendor's.
47
+ *
48
+ * Each member is a thing that demonstrably occurs on a real service and that an
49
+ * adapter has to turn into one of the five codes. The HTTP statuses are grouped
50
+ * by the answer they require rather than listed, because the question this suite
51
+ * asks is never "is 402 handled" — it is "does this implementation know that
52
+ * only an operator can clear a 402".
53
+ */
54
+ export type ModelSituation =
55
+ /** The service answered, with this text, served by this model. */
56
+ "answers"
57
+ /** The service answered, and there was nothing in the reply that was text. */
58
+ | "answers-without-text"
59
+ /** The answer stopped at the output ceiling, mid-sentence. */
60
+ | "truncates"
61
+ /** The model declined to answer this content. */
62
+ | "refuses"
63
+ /** A credential, entitlement or billing problem: 401, 402, 403. */
64
+ | "refuses-the-caller"
65
+ /** The request itself is wrong and would fail again unchanged: 400, 404, 413, 422. */
66
+ | "refuses-the-request"
67
+ /** Busy now, fine later: 408, 409, 429, 500, 503. */
68
+ | "asks-for-later"
69
+ /** No response at all — a closed socket, a DNS failure, a TLS error. */
70
+ | "never-answers";
71
+ export declare const MODEL_SITUATIONS: readonly ModelSituation[];
72
+ /**
73
+ * The text this suite sends through, and the model it says served it.
74
+ *
75
+ * **Deliberately dirty, and that is the whole value of it.** A real reply
76
+ * sometimes arrives wrapped in a code fence with whitespace around it, and an
77
+ * adapter is *not* allowed to clean that up: what a malformed answer means is
78
+ * the interpreter's decision and is covered by the interpreter's own tests
79
+ * (0005). An adapter that trims has moved that decision below the seam, where
80
+ * nothing watches it.
81
+ *
82
+ * This was found by breaking it. The first version of this constant was the
83
+ * bare reply, and an adapter mutated to `text.trim().replace(/^```json/, "")`
84
+ * passed all twenty-five cases — because a no-op on clean input is
85
+ * indistinguishable from doing nothing. The fence and the newlines are what
86
+ * make the assertion an assertion.
87
+ *
88
+ * `INSERT_NOTE_REPLY` inside it rather than a lorem string, so an adapter that
89
+ * parses and re-serialises produces valid JSON that still fails the comparison.
90
+ */
91
+ export declare const CONTRACT_REPLY: string;
92
+ export declare const CONTRACT_SERVED_BY = "a-model-that-served-it";
93
+ /**
94
+ * A client wired to behave as one situation does, or a statement that this
95
+ * vendor has no such situation.
96
+ *
97
+ * `"not-expressible"` is a claim, not a skip, and the difference is the whole
98
+ * reason it is spelled out. A vendor with no distinct refusal signal reports a
99
+ * declined answer some other way, and an adapter that invented a `refused` for
100
+ * it would be worse than one that said so. What the suite then checks is the
101
+ * honest remainder: that the situation really cannot be produced is the host's
102
+ * word, and the suite holds them to using one of the five codes for whatever
103
+ * they *do* produce instead.
104
+ */
105
+ export type ModelSituationClient = (() => ModelClient | Promise<ModelClient>) | "not-expressible";
106
+ export type ModelClientContract = Readonly<Record<ModelSituation, ModelSituationClient>>;
107
+ /** The request every case sends. Fixed, because none of these turn on its content. */
108
+ export declare const contractRequest: () => ModelRequest;
109
+ export declare const describeModelClientContract: (name: string, contract: ModelClientContract) => void;
110
+ //# sourceMappingURL=model-contract.d.ts.map
@@ -0,0 +1,150 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { everyMemberOf } from "../closed-set.js";
3
+ import { interpretationReplyJsonSchema } from "../interpretation/schema.js";
4
+ import { INSERT_NOTE_REPLY } from "./model-replies.js";
5
+ export const MODEL_SITUATIONS = everyMemberOf()([
6
+ "answers",
7
+ "answers-without-text",
8
+ "truncates",
9
+ "refuses",
10
+ "refuses-the-caller",
11
+ "refuses-the-request",
12
+ "asks-for-later",
13
+ "never-answers",
14
+ ]);
15
+ /**
16
+ * The text this suite sends through, and the model it says served it.
17
+ *
18
+ * **Deliberately dirty, and that is the whole value of it.** A real reply
19
+ * sometimes arrives wrapped in a code fence with whitespace around it, and an
20
+ * adapter is *not* allowed to clean that up: what a malformed answer means is
21
+ * the interpreter's decision and is covered by the interpreter's own tests
22
+ * (0005). An adapter that trims has moved that decision below the seam, where
23
+ * nothing watches it.
24
+ *
25
+ * This was found by breaking it. The first version of this constant was the
26
+ * bare reply, and an adapter mutated to `text.trim().replace(/^```json/, "")`
27
+ * passed all twenty-five cases — because a no-op on clean input is
28
+ * indistinguishable from doing nothing. The fence and the newlines are what
29
+ * make the assertion an assertion.
30
+ *
31
+ * `INSERT_NOTE_REPLY` inside it rather than a lorem string, so an adapter that
32
+ * parses and re-serialises produces valid JSON that still fails the comparison.
33
+ */
34
+ export const CONTRACT_REPLY = `\n\`\`\`json\n${INSERT_NOTE_REPLY}\n\`\`\`\n`;
35
+ export const CONTRACT_SERVED_BY = "a-model-that-served-it";
36
+ /** The request every case sends. Fixed, because none of these turn on its content. */
37
+ export const contractRequest = () => ({
38
+ model: "a-model",
39
+ maxTokens: 16000,
40
+ effort: "high",
41
+ system: "you translate requests into edits",
42
+ userMessage: "add a footer note",
43
+ outputSchema: interpretationReplyJsonSchema(),
44
+ });
45
+ /**
46
+ * Calls the client and reports what came back, including a throw.
47
+ *
48
+ * The throw is caught here rather than left to fail the test by itself, because
49
+ * "this implementation throws" is a *finding* this suite reports in the same
50
+ * vocabulary as a wrong code — and a rejected promise that escaped would
51
+ * otherwise fail whichever assertion ran next, naming the wrong thing.
52
+ */
53
+ const answered = async (client) => {
54
+ try {
55
+ const completion = await client.complete(contractRequest());
56
+ return completion.ok
57
+ ? { ok: true, text: completion.value.text, servedBy: completion.value.servedBy }
58
+ : { ok: false, error: completion.error };
59
+ }
60
+ catch (cause) {
61
+ return { ok: false, threw: cause instanceof Error ? cause.message : String(cause) };
62
+ }
63
+ };
64
+ const EXPECTED = {
65
+ answers: "ok",
66
+ "answers-without-text": "incomplete",
67
+ truncates: "incomplete",
68
+ refuses: "refused",
69
+ "refuses-the-caller": "misconfigured",
70
+ "refuses-the-request": "rejected",
71
+ "asks-for-later": "unavailable",
72
+ "never-answers": "unavailable",
73
+ };
74
+ export const describeModelClientContract = (name, contract) => {
75
+ describe(`${name} — ModelClient contract`, () => {
76
+ /**
77
+ * The invariant with no exceptions and no `not-expressible`: whatever the
78
+ * situation, the caller gets a value. `modelInterpreter` reads a `Result`
79
+ * and has nowhere to catch, so a rejected promise here is an exception on a
80
+ * path with no handler — a page that never finishes rather than a proposal
81
+ * that failed.
82
+ */
83
+ describe("answers rather than throwing, in every situation it has", () => {
84
+ for (const situation of MODEL_SITUATIONS) {
85
+ const make = contract[situation];
86
+ if (make === "not-expressible")
87
+ continue;
88
+ it(`returns a result when the service ${situation}`, async () => {
89
+ const result = await answered(await make());
90
+ expect(result).not.toHaveProperty("threw");
91
+ });
92
+ }
93
+ });
94
+ describe("names who must act", () => {
95
+ for (const situation of MODEL_SITUATIONS) {
96
+ const make = contract[situation];
97
+ if (make === "not-expressible")
98
+ continue;
99
+ it(`reports ${situation} as ${EXPECTED[situation]}`, async () => {
100
+ const result = await answered(await make());
101
+ expect(result.ok ? "ok" : "error" in result ? result.error.code : "threw").toBe(EXPECTED[situation]);
102
+ });
103
+ }
104
+ });
105
+ /**
106
+ * A detail is what an operator reads at three in the morning. An empty one
107
+ * is the difference between "your key is not accepted" and "something went
108
+ * wrong", and nothing above this seam can recover what the service said.
109
+ */
110
+ describe("says what happened, not that something happened", () => {
111
+ for (const situation of MODEL_SITUATIONS) {
112
+ const make = contract[situation];
113
+ if (make === "not-expressible" || EXPECTED[situation] === "ok")
114
+ continue;
115
+ it(`carries a detail for ${situation}`, async () => {
116
+ const result = await answered(await make());
117
+ expect(result.ok === false && "error" in result && result.error.detail.length > 0).toBe(true);
118
+ });
119
+ }
120
+ });
121
+ /**
122
+ * The seam's own line, and the one an adapter is most tempted to cross. The
123
+ * reply is handed up as text so that parsing, validating and deciding what a
124
+ * malformed answer means stay testable without a network (0005). An adapter
125
+ * that trims whitespace, unwraps a code fence or parses and re-serialises has
126
+ * moved one of those decisions below the line, where nothing covers it.
127
+ */
128
+ describe("hands the reply up unchanged", () => {
129
+ const make = contract.answers;
130
+ if (make === "not-expressible") {
131
+ throw new Error("loom: a ModelClient that cannot answer is not a ModelClient — 'answers' may not be not-expressible");
132
+ }
133
+ it("passes the text through byte for byte", async () => {
134
+ const result = await answered(await make());
135
+ expect(result.ok && result.text).toBe(CONTRACT_REPLY);
136
+ });
137
+ /**
138
+ * Which model served the request is provenance, and it is recorded
139
+ * rather than assumed (0005) — a service may answer with something other
140
+ * than what was asked for, and a client that echoed the request's model
141
+ * back would make that invisible exactly when it mattered.
142
+ */
143
+ it("reports the model that served the request, not the one asked for", async () => {
144
+ const result = await answered(await make());
145
+ expect(result.ok && result.servedBy).toBe(CONTRACT_SERVED_BY);
146
+ });
147
+ });
148
+ });
149
+ };
150
+ //# sourceMappingURL=model-contract.js.map
@@ -0,0 +1,26 @@
1
+ import { type PolicyLog, type RecordPolicyRequest } from "../runtime/index.js";
2
+ import { type GatePolicy } from "../runtime/policy.js";
3
+ /**
4
+ * One suite, run against every `PolicyLog`.
5
+ *
6
+ * The same argument as `store-contract.ts` and `journal-contract.ts`: the
7
+ * promises are not in the type. That a policy's revisions are dense and
8
+ * ascending, that recording what is already current appends nothing, that a
9
+ * digest naming two revisions is reported as naming two — a host discovering any
10
+ * of those from a production incident is the seam being offered without the
11
+ * thing that makes it safe to take.
12
+ *
13
+ * The outcome rules themselves live in `recordOutcomeOf`, shared by both
14
+ * implementations, so this suite is checking that a backend *applies* them: that
15
+ * it finds the right head, writes when told to and not when not, and reads back
16
+ * what it wrote.
17
+ */
18
+ export declare const policyNamed: (policyId: string, overrides?: Record<string, unknown>) => GatePolicy;
19
+ /**
20
+ * A recording, with the two fields a caller always has to supply already filled
21
+ * in. `actor` is required by the type and is spelled out in every fixture rather
22
+ * than defaulted somewhere a test could forget it.
23
+ */
24
+ export declare const recordingOf: (policy: GatePolicy, overrides?: Partial<RecordPolicyRequest>) => RecordPolicyRequest;
25
+ export declare const describePolicyLogContract: (name: string, build: () => PolicyLog | Promise<PolicyLog>) => void;
26
+ //# sourceMappingURL=policy-log-contract.d.ts.map