@copilotkit/aimock 1.42.1 → 1.44.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 (442) hide show
  1. package/.claude-plugin/marketplace.json +1 -1
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +65 -0
  4. package/README.md +108 -16
  5. package/dist/agui-handler.d.ts.map +1 -1
  6. package/dist/agui-mock.cjs +1 -1
  7. package/dist/agui-mock.cjs.map +1 -1
  8. package/dist/agui-mock.d.cts.map +1 -1
  9. package/dist/agui-mock.d.ts.map +1 -1
  10. package/dist/agui-mock.js +1 -1
  11. package/dist/agui-mock.js.map +1 -1
  12. package/dist/agui-recorder.cjs +33 -11
  13. package/dist/agui-recorder.cjs.map +1 -1
  14. package/dist/agui-recorder.d.cts +10 -1
  15. package/dist/agui-recorder.d.cts.map +1 -1
  16. package/dist/agui-recorder.d.ts +10 -1
  17. package/dist/agui-recorder.d.ts.map +1 -1
  18. package/dist/agui-recorder.js +33 -11
  19. package/dist/agui-recorder.js.map +1 -1
  20. package/dist/agui-types.d.cts +1 -0
  21. package/dist/agui-types.d.cts.map +1 -1
  22. package/dist/agui-types.d.ts +1 -0
  23. package/dist/agui-types.d.ts.map +1 -1
  24. package/dist/aimock-cli.cjs +38 -10
  25. package/dist/aimock-cli.cjs.map +1 -1
  26. package/dist/aimock-cli.d.cts +5 -0
  27. package/dist/aimock-cli.d.cts.map +1 -1
  28. package/dist/aimock-cli.d.ts +5 -0
  29. package/dist/aimock-cli.d.ts.map +1 -1
  30. package/dist/aimock-cli.js +38 -10
  31. package/dist/aimock-cli.js.map +1 -1
  32. package/dist/batches.cjs +458 -0
  33. package/dist/batches.cjs.map +1 -0
  34. package/dist/batches.d.cts +57 -0
  35. package/dist/batches.d.cts.map +1 -0
  36. package/dist/batches.d.ts +57 -0
  37. package/dist/batches.d.ts.map +1 -0
  38. package/dist/batches.js +453 -0
  39. package/dist/batches.js.map +1 -0
  40. package/dist/bedrock-converse.cjs +44 -12
  41. package/dist/bedrock-converse.cjs.map +1 -1
  42. package/dist/bedrock-converse.d.cts.map +1 -1
  43. package/dist/bedrock-converse.d.ts.map +1 -1
  44. package/dist/bedrock-converse.js +46 -14
  45. package/dist/bedrock-converse.js.map +1 -1
  46. package/dist/bedrock.cjs +10 -8
  47. package/dist/bedrock.cjs.map +1 -1
  48. package/dist/bedrock.d.cts.map +1 -1
  49. package/dist/bedrock.d.ts.map +1 -1
  50. package/dist/bedrock.js +12 -10
  51. package/dist/bedrock.js.map +1 -1
  52. package/dist/byteplus-video.cjs +3 -3
  53. package/dist/byteplus-video.cjs.map +1 -1
  54. package/dist/byteplus-video.js +4 -4
  55. package/dist/byteplus-video.js.map +1 -1
  56. package/dist/chaos.cjs +625 -72
  57. package/dist/chaos.cjs.map +1 -1
  58. package/dist/chaos.d.cts +164 -7
  59. package/dist/chaos.d.cts.map +1 -1
  60. package/dist/chaos.d.ts +164 -7
  61. package/dist/chaos.d.ts.map +1 -1
  62. package/dist/chaos.js +616 -74
  63. package/dist/chaos.js.map +1 -1
  64. package/dist/cli.cjs +131 -30
  65. package/dist/cli.cjs.map +1 -1
  66. package/dist/cli.js +132 -31
  67. package/dist/cli.js.map +1 -1
  68. package/dist/cohere.cjs +37 -9
  69. package/dist/cohere.cjs.map +1 -1
  70. package/dist/cohere.d.cts.map +1 -1
  71. package/dist/cohere.d.ts.map +1 -1
  72. package/dist/cohere.js +39 -11
  73. package/dist/cohere.js.map +1 -1
  74. package/dist/config-loader.cjs +1 -1
  75. package/dist/config-loader.js +1 -1
  76. package/dist/constants.cjs +8 -0
  77. package/dist/constants.cjs.map +1 -1
  78. package/dist/constants.d.cts +6 -2
  79. package/dist/constants.d.ts +6 -2
  80. package/dist/constants.js +8 -1
  81. package/dist/constants.js.map +1 -1
  82. package/dist/convert.cjs +1 -1
  83. package/dist/convert.cjs.map +1 -1
  84. package/dist/convert.js +1 -1
  85. package/dist/convert.js.map +1 -1
  86. package/dist/echo-text.cjs +65 -0
  87. package/dist/echo-text.cjs.map +1 -0
  88. package/dist/echo-text.d.cts +22 -0
  89. package/dist/echo-text.d.cts.map +1 -0
  90. package/dist/echo-text.d.ts +22 -0
  91. package/dist/echo-text.d.ts.map +1 -0
  92. package/dist/echo-text.js +65 -0
  93. package/dist/echo-text.js.map +1 -0
  94. package/dist/elevenlabs-audio.cjs +3 -3
  95. package/dist/elevenlabs-audio.cjs.map +1 -1
  96. package/dist/elevenlabs-audio.js +4 -4
  97. package/dist/elevenlabs-audio.js.map +1 -1
  98. package/dist/elevenlabs-voice.cjs +1053 -0
  99. package/dist/elevenlabs-voice.cjs.map +1 -0
  100. package/dist/elevenlabs-voice.d.cts +72 -0
  101. package/dist/elevenlabs-voice.d.cts.map +1 -0
  102. package/dist/elevenlabs-voice.d.ts +72 -0
  103. package/dist/elevenlabs-voice.d.ts.map +1 -0
  104. package/dist/elevenlabs-voice.js +1048 -0
  105. package/dist/elevenlabs-voice.js.map +1 -0
  106. package/dist/embeddings.cjs +26 -5
  107. package/dist/embeddings.cjs.map +1 -1
  108. package/dist/embeddings.d.cts +1 -1
  109. package/dist/embeddings.d.cts.map +1 -1
  110. package/dist/embeddings.d.ts +1 -1
  111. package/dist/embeddings.d.ts.map +1 -1
  112. package/dist/embeddings.js +27 -6
  113. package/dist/embeddings.js.map +1 -1
  114. package/dist/fal-audio.cjs +3 -3
  115. package/dist/fal-audio.cjs.map +1 -1
  116. package/dist/fal-audio.js +4 -4
  117. package/dist/fal-audio.js.map +1 -1
  118. package/dist/fal.cjs +28 -4
  119. package/dist/fal.cjs.map +1 -1
  120. package/dist/fal.d.cts +16 -1
  121. package/dist/fal.d.cts.map +1 -1
  122. package/dist/fal.d.ts +16 -1
  123. package/dist/fal.d.ts.map +1 -1
  124. package/dist/fal.js +28 -5
  125. package/dist/fal.js.map +1 -1
  126. package/dist/files.cjs +1069 -0
  127. package/dist/files.cjs.map +1 -0
  128. package/dist/files.d.cts +68 -0
  129. package/dist/files.d.cts.map +1 -0
  130. package/dist/files.d.ts +68 -0
  131. package/dist/files.d.ts.map +1 -0
  132. package/dist/files.js +1056 -0
  133. package/dist/files.js.map +1 -0
  134. package/dist/fine-tuning.cjs +1033 -0
  135. package/dist/fine-tuning.cjs.map +1 -0
  136. package/dist/fine-tuning.d.cts +96 -0
  137. package/dist/fine-tuning.d.cts.map +1 -0
  138. package/dist/fine-tuning.d.ts +96 -0
  139. package/dist/fine-tuning.d.ts.map +1 -0
  140. package/dist/fine-tuning.js +1026 -0
  141. package/dist/fine-tuning.js.map +1 -0
  142. package/dist/fixture-loader-services.cjs +116 -0
  143. package/dist/fixture-loader-services.cjs.map +1 -0
  144. package/dist/fixture-loader-services.d.cts +48 -0
  145. package/dist/fixture-loader-services.d.cts.map +1 -0
  146. package/dist/fixture-loader-services.d.ts +48 -0
  147. package/dist/fixture-loader-services.d.ts.map +1 -0
  148. package/dist/fixture-loader-services.js +114 -0
  149. package/dist/fixture-loader-services.js.map +1 -0
  150. package/dist/fixture-loader.cjs +0 -0
  151. package/dist/fixture-loader.cjs.map +1 -1
  152. package/dist/fixture-loader.d.cts +131 -5
  153. package/dist/fixture-loader.d.cts.map +1 -1
  154. package/dist/fixture-loader.d.ts +131 -5
  155. package/dist/fixture-loader.d.ts.map +1 -1
  156. package/dist/fixture-loader.js +0 -0
  157. package/dist/fixture-loader.js.map +1 -1
  158. package/dist/gemini-embeddings.cjs +44 -4
  159. package/dist/gemini-embeddings.cjs.map +1 -1
  160. package/dist/gemini-embeddings.js +46 -6
  161. package/dist/gemini-embeddings.js.map +1 -1
  162. package/dist/gemini-interactions.cjs +51 -7
  163. package/dist/gemini-interactions.cjs.map +1 -1
  164. package/dist/gemini-interactions.d.cts.map +1 -1
  165. package/dist/gemini-interactions.d.ts.map +1 -1
  166. package/dist/gemini-interactions.js +53 -9
  167. package/dist/gemini-interactions.js.map +1 -1
  168. package/dist/gemini.cjs +19 -8
  169. package/dist/gemini.cjs.map +1 -1
  170. package/dist/gemini.d.cts.map +1 -1
  171. package/dist/gemini.d.ts.map +1 -1
  172. package/dist/gemini.js +21 -10
  173. package/dist/gemini.js.map +1 -1
  174. package/dist/grok-video.cjs +14 -14
  175. package/dist/grok-video.cjs.map +1 -1
  176. package/dist/grok-video.js +15 -15
  177. package/dist/grok-video.js.map +1 -1
  178. package/dist/helpers.cjs +497 -10
  179. package/dist/helpers.cjs.map +1 -1
  180. package/dist/helpers.d.cts +38 -2
  181. package/dist/helpers.d.cts.map +1 -1
  182. package/dist/helpers.d.ts +38 -2
  183. package/dist/helpers.d.ts.map +1 -1
  184. package/dist/helpers.js +487 -12
  185. package/dist/helpers.js.map +1 -1
  186. package/dist/images.cjs +57 -125
  187. package/dist/images.cjs.map +1 -1
  188. package/dist/images.d.cts.map +1 -1
  189. package/dist/images.d.ts.map +1 -1
  190. package/dist/images.js +58 -126
  191. package/dist/images.js.map +1 -1
  192. package/dist/index.cjs +71 -9
  193. package/dist/index.d.cts +17 -7
  194. package/dist/index.d.ts +17 -7
  195. package/dist/index.js +21 -11
  196. package/dist/jest.cjs +24 -12
  197. package/dist/jest.cjs.map +1 -1
  198. package/dist/jest.d.cts +6 -3
  199. package/dist/jest.d.cts.map +1 -1
  200. package/dist/jest.d.ts +6 -3
  201. package/dist/jest.d.ts.map +1 -1
  202. package/dist/jest.js +25 -13
  203. package/dist/jest.js.map +1 -1
  204. package/dist/journal.cjs +61 -4
  205. package/dist/journal.cjs.map +1 -1
  206. package/dist/journal.d.cts +60 -3
  207. package/dist/journal.d.cts.map +1 -1
  208. package/dist/journal.d.ts +60 -3
  209. package/dist/journal.d.ts.map +1 -1
  210. package/dist/journal.js +61 -5
  211. package/dist/journal.js.map +1 -1
  212. package/dist/live-fixture.cjs +1192 -0
  213. package/dist/live-fixture.cjs.map +1 -0
  214. package/dist/live-fixture.js +1187 -0
  215. package/dist/live-fixture.js.map +1 -0
  216. package/dist/live-recorder.cjs +256 -0
  217. package/dist/live-recorder.cjs.map +1 -0
  218. package/dist/live-recorder.js +254 -0
  219. package/dist/live-recorder.js.map +1 -0
  220. package/dist/live-replay.cjs +286 -0
  221. package/dist/live-replay.cjs.map +1 -0
  222. package/dist/live-replay.js +285 -0
  223. package/dist/live-replay.js.map +1 -0
  224. package/dist/live-sanitize.cjs +196 -0
  225. package/dist/live-sanitize.cjs.map +1 -0
  226. package/dist/live-sanitize.js +196 -0
  227. package/dist/live-sanitize.js.map +1 -0
  228. package/dist/live-types.d.cts +71 -0
  229. package/dist/live-types.d.cts.map +1 -0
  230. package/dist/live-types.d.ts +71 -0
  231. package/dist/live-types.d.ts.map +1 -0
  232. package/dist/llmock.cjs +132 -49
  233. package/dist/llmock.cjs.map +1 -1
  234. package/dist/llmock.d.cts +51 -5
  235. package/dist/llmock.d.cts.map +1 -1
  236. package/dist/llmock.d.ts +51 -5
  237. package/dist/llmock.d.ts.map +1 -1
  238. package/dist/llmock.js +133 -50
  239. package/dist/llmock.js.map +1 -1
  240. package/dist/mcp-fakes-mount.cjs +216 -0
  241. package/dist/mcp-fakes-mount.cjs.map +1 -0
  242. package/dist/mcp-fakes-mount.js +210 -0
  243. package/dist/mcp-fakes-mount.js.map +1 -0
  244. package/dist/mcp-fakes.cjs +1619 -0
  245. package/dist/mcp-fakes.cjs.map +1 -0
  246. package/dist/mcp-fakes.d.cts +101 -0
  247. package/dist/mcp-fakes.d.cts.map +1 -0
  248. package/dist/mcp-fakes.d.ts +101 -0
  249. package/dist/mcp-fakes.d.ts.map +1 -0
  250. package/dist/mcp-fakes.js +1614 -0
  251. package/dist/mcp-fakes.js.map +1 -0
  252. package/dist/mcp-handler.cjs +331 -17
  253. package/dist/mcp-handler.cjs.map +1 -1
  254. package/dist/mcp-handler.js +330 -18
  255. package/dist/mcp-handler.js.map +1 -1
  256. package/dist/mcp-mock.cjs +217 -49
  257. package/dist/mcp-mock.cjs.map +1 -1
  258. package/dist/mcp-mock.d.cts +66 -1
  259. package/dist/mcp-mock.d.cts.map +1 -1
  260. package/dist/mcp-mock.d.ts +66 -1
  261. package/dist/mcp-mock.d.ts.map +1 -1
  262. package/dist/mcp-mock.js +218 -50
  263. package/dist/mcp-mock.js.map +1 -1
  264. package/dist/mcp-stub.cjs +5 -1
  265. package/dist/mcp-stub.d.cts +3 -1
  266. package/dist/mcp-stub.d.ts +3 -1
  267. package/dist/mcp-stub.js +3 -1
  268. package/dist/mcp-types.d.cts +6 -0
  269. package/dist/mcp-types.d.ts +6 -0
  270. package/dist/message-text.cjs +192 -0
  271. package/dist/message-text.cjs.map +1 -0
  272. package/dist/message-text.d.cts +31 -0
  273. package/dist/message-text.d.cts.map +1 -0
  274. package/dist/message-text.d.ts +31 -0
  275. package/dist/message-text.d.ts.map +1 -0
  276. package/dist/message-text.js +184 -0
  277. package/dist/message-text.js.map +1 -0
  278. package/dist/messages.cjs +49 -7
  279. package/dist/messages.cjs.map +1 -1
  280. package/dist/messages.d.cts.map +1 -1
  281. package/dist/messages.d.ts.map +1 -1
  282. package/dist/messages.js +51 -9
  283. package/dist/messages.js.map +1 -1
  284. package/dist/metrics.cjs +278 -45
  285. package/dist/metrics.cjs.map +1 -1
  286. package/dist/metrics.d.cts +17 -7
  287. package/dist/metrics.d.cts.map +1 -1
  288. package/dist/metrics.d.ts +17 -7
  289. package/dist/metrics.d.ts.map +1 -1
  290. package/dist/metrics.js +270 -29
  291. package/dist/metrics.js.map +1 -1
  292. package/dist/moderation.cjs +10 -1
  293. package/dist/moderation.cjs.map +1 -1
  294. package/dist/moderation.d.cts.map +1 -1
  295. package/dist/moderation.d.ts.map +1 -1
  296. package/dist/moderation.js +10 -1
  297. package/dist/moderation.js.map +1 -1
  298. package/dist/ollama.cjs +10 -6
  299. package/dist/ollama.cjs.map +1 -1
  300. package/dist/ollama.d.cts.map +1 -1
  301. package/dist/ollama.d.ts.map +1 -1
  302. package/dist/ollama.js +11 -7
  303. package/dist/ollama.js.map +1 -1
  304. package/dist/openapi.cjs +3405 -0
  305. package/dist/openapi.cjs.map +1 -0
  306. package/dist/openapi.d.cts +30 -0
  307. package/dist/openapi.d.cts.map +1 -0
  308. package/dist/openapi.d.ts +30 -0
  309. package/dist/openapi.d.ts.map +1 -0
  310. package/dist/openapi.js +3404 -0
  311. package/dist/openapi.js.map +1 -0
  312. package/dist/openrouter-video.cjs +9 -9
  313. package/dist/openrouter-video.cjs.map +1 -1
  314. package/dist/openrouter-video.d.cts.map +1 -1
  315. package/dist/openrouter-video.d.ts.map +1 -1
  316. package/dist/openrouter-video.js +10 -10
  317. package/dist/openrouter-video.js.map +1 -1
  318. package/dist/recorder.cjs +54 -10
  319. package/dist/recorder.cjs.map +1 -1
  320. package/dist/recorder.d.cts.map +1 -1
  321. package/dist/recorder.d.ts.map +1 -1
  322. package/dist/recorder.js +52 -12
  323. package/dist/recorder.js.map +1 -1
  324. package/dist/responses.cjs +47 -7
  325. package/dist/responses.cjs.map +1 -1
  326. package/dist/responses.d.cts.map +1 -1
  327. package/dist/responses.d.ts.map +1 -1
  328. package/dist/responses.js +48 -9
  329. package/dist/responses.js.map +1 -1
  330. package/dist/route-registry.cjs +951 -0
  331. package/dist/route-registry.cjs.map +1 -0
  332. package/dist/route-registry.d.cts +33 -0
  333. package/dist/route-registry.d.cts.map +1 -0
  334. package/dist/route-registry.d.ts +33 -0
  335. package/dist/route-registry.d.ts.map +1 -0
  336. package/dist/route-registry.js +866 -0
  337. package/dist/route-registry.js.map +1 -0
  338. package/dist/router.cjs +21 -34
  339. package/dist/router.cjs.map +1 -1
  340. package/dist/router.d.cts +4 -1
  341. package/dist/router.d.cts.map +1 -1
  342. package/dist/router.d.ts +4 -1
  343. package/dist/router.d.ts.map +1 -1
  344. package/dist/router.js +21 -35
  345. package/dist/router.js.map +1 -1
  346. package/dist/server.cjs +1252 -777
  347. package/dist/server.cjs.map +1 -1
  348. package/dist/server.d.cts +5 -1
  349. package/dist/server.d.cts.map +1 -1
  350. package/dist/server.d.ts +5 -1
  351. package/dist/server.d.ts.map +1 -1
  352. package/dist/server.js +1185 -710
  353. package/dist/server.js.map +1 -1
  354. package/dist/speech.cjs +6 -4
  355. package/dist/speech.cjs.map +1 -1
  356. package/dist/speech.js +7 -5
  357. package/dist/speech.js.map +1 -1
  358. package/dist/suite.cjs +1 -1
  359. package/dist/suite.js +1 -1
  360. package/dist/transcription.cjs +6 -6
  361. package/dist/transcription.cjs.map +1 -1
  362. package/dist/transcription.d.cts.map +1 -1
  363. package/dist/transcription.d.ts.map +1 -1
  364. package/dist/transcription.js +7 -7
  365. package/dist/transcription.js.map +1 -1
  366. package/dist/types.cjs +18 -0
  367. package/dist/types.cjs.map +1 -0
  368. package/dist/types.d.cts +320 -17
  369. package/dist/types.d.cts.map +1 -1
  370. package/dist/types.d.ts +320 -17
  371. package/dist/types.d.ts.map +1 -1
  372. package/dist/types.js +17 -0
  373. package/dist/types.js.map +1 -0
  374. package/dist/validate-cli.cjs +983 -0
  375. package/dist/validate-cli.cjs.map +1 -0
  376. package/dist/validate-cli.js +982 -0
  377. package/dist/validate-cli.js.map +1 -0
  378. package/dist/vector-stores.cjs +1180 -0
  379. package/dist/vector-stores.cjs.map +1 -0
  380. package/dist/vector-stores.d.cts +106 -0
  381. package/dist/vector-stores.d.cts.map +1 -0
  382. package/dist/vector-stores.d.ts +106 -0
  383. package/dist/vector-stores.d.ts.map +1 -0
  384. package/dist/vector-stores.js +1164 -0
  385. package/dist/vector-stores.js.map +1 -0
  386. package/dist/vector-types.d.cts.map +1 -1
  387. package/dist/vector-types.d.ts.map +1 -1
  388. package/dist/veo-video.cjs +13 -13
  389. package/dist/veo-video.cjs.map +1 -1
  390. package/dist/veo-video.js +14 -14
  391. package/dist/veo-video.js.map +1 -1
  392. package/dist/video.cjs +23 -4
  393. package/dist/video.cjs.map +1 -1
  394. package/dist/video.d.cts +1 -1
  395. package/dist/video.d.cts.map +1 -1
  396. package/dist/video.d.ts +1 -1
  397. package/dist/video.d.ts.map +1 -1
  398. package/dist/video.js +24 -5
  399. package/dist/video.js.map +1 -1
  400. package/dist/vitest.cjs +23 -11
  401. package/dist/vitest.cjs.map +1 -1
  402. package/dist/vitest.d.cts +5 -2
  403. package/dist/vitest.d.cts.map +1 -1
  404. package/dist/vitest.d.ts +5 -2
  405. package/dist/vitest.d.ts.map +1 -1
  406. package/dist/vitest.js +25 -13
  407. package/dist/vitest.js.map +1 -1
  408. package/dist/watcher.cjs +2 -1
  409. package/dist/watcher.cjs.map +1 -1
  410. package/dist/watcher.js +2 -1
  411. package/dist/watcher.js.map +1 -1
  412. package/dist/ws-framing.cjs +150 -35
  413. package/dist/ws-framing.cjs.map +1 -1
  414. package/dist/ws-framing.d.cts +18 -3
  415. package/dist/ws-framing.d.cts.map +1 -1
  416. package/dist/ws-framing.d.ts +18 -3
  417. package/dist/ws-framing.d.ts.map +1 -1
  418. package/dist/ws-framing.js +151 -36
  419. package/dist/ws-framing.js.map +1 -1
  420. package/dist/ws-gemini-live.cjs +2 -2
  421. package/dist/ws-gemini-live.js +2 -2
  422. package/dist/ws-live.cjs +401 -0
  423. package/dist/ws-live.cjs.map +1 -0
  424. package/dist/ws-live.js +400 -0
  425. package/dist/ws-live.js.map +1 -0
  426. package/dist/ws-realtime.cjs +46 -2
  427. package/dist/ws-realtime.cjs.map +1 -1
  428. package/dist/ws-realtime.d.cts.map +1 -1
  429. package/dist/ws-realtime.d.ts.map +1 -1
  430. package/dist/ws-realtime.js +46 -2
  431. package/dist/ws-realtime.js.map +1 -1
  432. package/dist/ws-responses.cjs +16 -4
  433. package/dist/ws-responses.cjs.map +1 -1
  434. package/dist/ws-responses.js +16 -4
  435. package/dist/ws-responses.js.map +1 -1
  436. package/dist/ws-upstream.cjs +118 -0
  437. package/dist/ws-upstream.cjs.map +1 -0
  438. package/dist/ws-upstream.js +115 -0
  439. package/dist/ws-upstream.js.map +1 -0
  440. package/fixtures/openai-live-client.json +390 -0
  441. package/fixtures/openai-live-managed.json +709 -0
  442. package/package.json +4 -1
@@ -1 +1 @@
1
- {"version":3,"file":"fixture-loader.cjs","names":["isContentWithToolCallsResponse","isTextResponse","isToolCallResponse","isErrorResponse","isEmbeddingResponse","isImageResponse","isAudioResponse","isTranscriptionResponse","isVideoResponse","isJSONResponse"],"sources":["../src/fixture-loader.ts"],"sourcesContent":["import { readFileSync, readdirSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type {\n Fixture,\n FixtureFile,\n FixtureFileEntry,\n FixtureFileResponse,\n FixtureResponse,\n ResponseOverrides,\n} from \"./types.js\";\nimport {\n isTextResponse,\n isToolCallResponse,\n isContentWithToolCallsResponse,\n isErrorResponse,\n isEmbeddingResponse,\n isImageResponse,\n isAudioResponse,\n isTranscriptionResponse,\n isVideoResponse,\n isJSONResponse,\n} from \"./helpers.js\";\nimport type { Logger } from \"./logger.js\";\n\n/**\n * Auto-stringify object-valued `content` and `toolCalls[].arguments` fields.\n * This lets fixture authors write plain JSON objects instead of escaped strings.\n * All other fields (including ResponseOverrides, and the ErrorResponse\n * `fallthrough` OpenRouter-failover flag) pass through unmodified via the\n * shallow clone below.\n */\nexport function normalizeResponse(raw: FixtureFileResponse): FixtureResponse {\n // Shallow-clone so we don't mutate the parsed JSON input.\n const response = { ...raw } as Record<string, unknown>;\n\n // Auto-stringify object content (e.g. structured output)\n if (typeof response.content === \"object\" && response.content !== null) {\n response.content = JSON.stringify(response.content);\n }\n\n // Auto-stringify object arguments in toolCalls\n if (Array.isArray(response.toolCalls)) {\n response.toolCalls = (response.toolCalls as Array<Record<string, unknown>>).map((tc) => {\n if (typeof tc.arguments === \"object\" && tc.arguments !== null) {\n return { ...tc, arguments: JSON.stringify(tc.arguments) };\n }\n return tc;\n });\n }\n\n // Carry the optional ordered `blocks` array through, mirroring the\n // toolCalls[].arguments idiom above: auto-stringify object `arguments` on\n // each `toolCall` block. Gated on Array.isArray so a malformed (non-array)\n // `blocks` value passes through untouched rather than crashing — downstream\n // validation/builders own shape rejection. Absent `blocks` → key absent.\n if (Array.isArray(response.blocks)) {\n response.blocks = (response.blocks as Array<Record<string, unknown>>).map((block) => {\n if (\n block != null &&\n block.type === \"toolCall\" &&\n typeof block.arguments === \"object\" &&\n block.arguments !== null\n ) {\n return { ...block, arguments: JSON.stringify(block.arguments) };\n }\n return block;\n });\n }\n\n return response as unknown as FixtureResponse;\n}\n\nexport function entryToFixture(entry: FixtureFileEntry, logger?: Logger): Fixture {\n const fixture: Fixture = {\n match: {\n userMessage: entry.match.userMessage,\n systemMessage: entry.match.systemMessage,\n inputText: entry.match.inputText,\n toolCallId: entry.match.toolCallId,\n toolResultContains: entry.match.toolResultContains,\n toolName: entry.match.toolName,\n model: entry.match.model,\n responseFormat: entry.match.responseFormat,\n endpoint: entry.match.endpoint,\n ...(entry.match.sequenceIndex !== undefined && { sequenceIndex: entry.match.sequenceIndex }),\n ...(entry.match.turnIndex !== undefined && {\n turnIndex: entry.match.turnIndex,\n }),\n ...(entry.match.hasToolResult !== undefined && {\n hasToolResult: entry.match.hasToolResult,\n }),\n ...(entry.match.context !== undefined && { context: entry.match.context }),\n },\n response: normalizeResponse(entry.response),\n ...(entry.latency !== undefined && { latency: entry.latency }),\n ...(entry.chunkSize !== undefined && { chunkSize: entry.chunkSize }),\n ...(entry.truncateAfterChunks !== undefined && {\n truncateAfterChunks: entry.truncateAfterChunks,\n }),\n ...(entry.disconnectAfterMs !== undefined && { disconnectAfterMs: entry.disconnectAfterMs }),\n ...(entry.streamingProfile !== undefined && { streamingProfile: entry.streamingProfile }),\n ...(entry.recordedTimings !== undefined && { recordedTimings: entry.recordedTimings }),\n ...(entry.replaySpeed != null && { replaySpeed: entry.replaySpeed }),\n ...(entry.chaos !== undefined && { chaos: entry.chaos }),\n ...(entry.openRouterProcessing !== undefined && {\n openRouterProcessing: entry.openRouterProcessing,\n }),\n ...(entry.metadata !== undefined && { metadata: entry.metadata }),\n };\n\n // Sanitize recordedTimings to guard against NaN or negative values that\n // would silently degrade replay timing calculations.\n if (fixture.recordedTimings) {\n const rt = fixture.recordedTimings;\n if (!Number.isFinite(rt.ttftMs) || rt.ttftMs < 0) rt.ttftMs = 0;\n rt.interChunkDelaysMs = Array.isArray(rt.interChunkDelaysMs)\n ? rt.interChunkDelaysMs.filter((d) => Number.isFinite(d) && d >= 0)\n : [];\n if (!Number.isFinite(rt.totalDurationMs) || rt.totalDurationMs < 0) rt.totalDurationMs = 0;\n }\n\n if (fixture.replaySpeed != null && fixture.replaySpeed <= 0) {\n logger?.warn(`Fixture replaySpeed must be positive, got ${fixture.replaySpeed}. Ignoring.`);\n delete fixture.replaySpeed;\n }\n\n return fixture;\n}\n\n/**\n * Serialise a match value (string | string[] | RegExp | undefined) into a\n * dedup-key fragment that is kind-aware, so a string, a RegExp with the same\n * source, and an array containing that string do not collide. A plain template\n * literal would coerce `/foo/` and `\"foo\"` to the same text and join `[\"foo\"]`\n * to `\"foo\"`, wrongly deduping fixtures that the router would treat as distinct.\n * Used by the duplicate-userMessage dedup key in validateFixtures.\n */\nfunction serializeMatcher(value: string | string[] | RegExp | undefined): string {\n if (value === undefined) return \"\";\n if (value instanceof RegExp) return `re:${value.source}\u0000${value.flags}`;\n if (Array.isArray(value)) return `arr:${JSON.stringify(value)}`;\n return `str:${value}`;\n}\n\n// Logging helper — uses logger if provided, falls back to console.warn.\nfunction warn(logger: Logger | undefined, msg: string, ...rest: unknown[]): void {\n if (logger) {\n logger.warn(msg, ...rest);\n } else {\n console.warn(`[fixture-loader] ${msg}`, ...rest);\n }\n}\n\nexport function loadFixtureFile(filePath: string, logger?: Logger): Fixture[] {\n let raw: string;\n try {\n raw = readFileSync(filePath, \"utf-8\");\n } catch (err) {\n warn(logger, `Could not read file ${filePath}:`, err);\n return [];\n }\n\n let parsed: unknown;\n try {\n parsed = JSON.parse(raw);\n } catch (err) {\n warn(logger, `Invalid JSON in ${filePath}:`, err);\n return [];\n }\n\n if (\n typeof parsed !== \"object\" ||\n parsed === null ||\n !Array.isArray((parsed as FixtureFile).fixtures)\n ) {\n warn(logger, `Missing or invalid \"fixtures\" array in ${filePath}`);\n return [];\n }\n\n return (parsed as FixtureFile).fixtures.map((e) => entryToFixture(e, logger));\n}\n\nexport function loadFixturesFromDir(dirPath: string, logger?: Logger): Fixture[] {\n let entries: string[];\n try {\n entries = readdirSync(dirPath);\n } catch (err) {\n warn(logger, `Could not read directory ${dirPath}:`, err);\n return [];\n }\n\n const jsonFiles: string[] = [];\n const subdirs: string[] = [];\n for (const name of entries) {\n const fullPath = join(dirPath, name);\n try {\n if (statSync(fullPath).isDirectory()) {\n subdirs.push(name);\n continue;\n }\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code !== \"ENOENT\") {\n warn(logger, `Could not stat ${fullPath}:`, err);\n }\n continue;\n }\n if (name.endsWith(\".json\")) {\n jsonFiles.push(name);\n }\n }\n jsonFiles.sort();\n\n const fixtures: Fixture[] = [];\n for (const name of jsonFiles) {\n const filePath = join(dirPath, name);\n fixtures.push(...loadFixtureFile(filePath, logger));\n }\n\n // Recurse into all subdirectories (full depth) to support nested layouts\n // like showcase/aimock/d6/<integration>/<feature>.json.\n subdirs.sort();\n for (const sub of subdirs) {\n fixtures.push(...loadFixturesFromDir(join(dirPath, sub), logger));\n }\n\n return fixtures;\n}\n\n// ---------------------------------------------------------------------------\n// Fixture validation\n// ---------------------------------------------------------------------------\n\nexport interface ValidationResult {\n severity: \"error\" | \"warning\";\n fixtureIndex: number;\n message: string;\n}\n\nfunction validateReasoning(\n response: { reasoning?: unknown },\n fixtureIndex: number,\n results: ValidationResult[],\n): void {\n if (response.reasoning !== undefined) {\n if (typeof response.reasoning !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: \"reasoning must be a string\",\n });\n } else if (response.reasoning === \"\") {\n results.push({\n severity: \"warning\",\n fixtureIndex,\n message: \"reasoning is empty string — no reasoning events will be emitted\",\n });\n }\n }\n}\n\nfunction validateWebSearches(\n response: { webSearches?: unknown },\n fixtureIndex: number,\n results: ValidationResult[],\n): void {\n if (response.webSearches !== undefined) {\n if (!Array.isArray(response.webSearches)) {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: \"webSearches must be an array of strings\",\n });\n } else if (response.webSearches.length === 0) {\n results.push({\n severity: \"warning\",\n fixtureIndex,\n message: \"webSearches is empty array — no web search events will be emitted\",\n });\n } else {\n for (let j = 0; j < response.webSearches.length; j++) {\n if (typeof response.webSearches[j] !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `webSearches[${j}] is not a string`,\n });\n break;\n }\n if (response.webSearches[j] === \"\") {\n results.push({\n severity: \"warning\",\n fixtureIndex,\n message: `webSearches[${j}] is empty string`,\n });\n }\n }\n }\n }\n}\n\nfunction validateBlocks(\n response: { blocks?: unknown; content?: unknown; toolCalls?: unknown },\n fixtureIndex: number,\n results: ValidationResult[],\n): void {\n if (response.blocks === undefined) return;\n\n // Mirrors the toolCalls checks: reject malformed `blocks` at LOAD time so a\n // bad blocks array never reaches the dispatch/builder (where\n // resolveFixtureBlocks throws AFTER the journal has already recorded\n // status:200, yielding a journal-200/client-500 mismatch). #274 F3+F8.\n if (!Array.isArray(response.blocks)) {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks must be an array, got ${typeof response.blocks}`,\n });\n return;\n }\n\n for (let j = 0; j < response.blocks.length; j++) {\n const block = response.blocks[j] as Record<string, unknown> | null | undefined;\n if (typeof block !== \"object\" || block === null) {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}] must be an object`,\n });\n continue;\n }\n if (block.type !== \"text\" && block.type !== \"toolCall\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].type must be \"text\" or \"toolCall\", got ${JSON.stringify(block.type)}`,\n });\n continue;\n }\n if (block.type === \"text\") {\n if (typeof block.text !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].text must be a string, got ${typeof block.text}`,\n });\n } else if (block.text === \"\") {\n // Mirror the content/toolCalls \"empty string\" rejection: an empty-text\n // block produces a meaningless/spurious wire chunk on replay.\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].text is empty string`,\n });\n }\n } else {\n // toolCall block — mirror toolCalls[] name + arguments checks.\n if (typeof block.name !== \"string\" || block.name === \"\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].name must be a non-empty string`,\n });\n }\n // `arguments` is JSON-string in runtime form (normalizeResponse already\n // stringified object/array args); accept a valid-JSON string or an object.\n if (typeof block.arguments === \"string\") {\n try {\n JSON.parse(block.arguments);\n } catch {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].arguments is not valid JSON: ${block.arguments}`,\n });\n }\n } else if (typeof block.arguments !== \"object\" || block.arguments === null) {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].arguments must be a JSON string or object, got ${typeof block.arguments}`,\n });\n }\n if (block.id !== undefined && typeof block.id !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].id must be a string, got ${typeof block.id}`,\n });\n }\n }\n }\n\n // blocks-vs-content/toolCalls divergence (#274 P2). When a fixture carries\n // BOTH `blocks` AND legacy `content`/`toolCalls` (allowed but unusual now\n // that blocks-only is first-class), builders stream `blocks` and IGNORE the\n // redundant `content`/`toolCalls`. If those disagree it is a silent footgun,\n // so WARN (not a hard error). Stay silent on the clean blocks-only path\n // (neither legacy field present) — that is the intended shape.\n const hasLegacyContent = typeof response.content === \"string\";\n const hasLegacyToolCalls = Array.isArray(response.toolCalls);\n if ((hasLegacyContent || hasLegacyToolCalls) && Array.isArray(response.blocks)) {\n const textBlocks = response.blocks.filter(\n (b): b is { type: \"text\"; text: string } =>\n b != null &&\n typeof b === \"object\" &&\n (b as { type?: unknown }).type === \"text\" &&\n typeof (b as { text?: unknown }).text === \"string\",\n );\n const toolCallBlockNames = response.blocks\n .filter(\n (b): b is { type: \"toolCall\"; name: string } =>\n b != null &&\n typeof b === \"object\" &&\n (b as { type?: unknown }).type === \"toolCall\" &&\n typeof (b as { name?: unknown }).name === \"string\",\n )\n .map((b) => b.name);\n\n // Text divergence: blocks' concatenated text vs legacy `content`.\n if (hasLegacyContent) {\n const blocksText = textBlocks.map((b) => b.text).join(\"\");\n if (blocksText !== response.content) {\n results.push({\n severity: \"warning\",\n fixtureIndex,\n message:\n \"blocks text diverges from content — builders stream blocks and ignore the redundant content field\",\n });\n }\n }\n\n // ToolCall divergence: blocks' ordered toolCall names vs legacy `toolCalls`.\n if (hasLegacyToolCalls) {\n const legacyNames = (response.toolCalls as Array<{ name?: unknown }>).map((tc) =>\n typeof tc?.name === \"string\" ? tc.name : undefined,\n );\n const sameNames =\n legacyNames.length === toolCallBlockNames.length &&\n legacyNames.every((n, k) => n === toolCallBlockNames[k]);\n if (!sameNames) {\n results.push({\n severity: \"warning\",\n fixtureIndex,\n message:\n \"blocks toolCalls diverge from toolCalls — builders stream blocks and ignore the redundant toolCalls field\",\n });\n }\n }\n }\n}\n\n/**\n * Human-readable form of the status range an injected error may carry.\n * Measured on Node v26: `res.writeHead` throws outside 100-999 (the injected\n * error is then lost and the caller sees a generic 500), and a 1xx status is\n * accepted but cannot terminate a response, so it hangs the request until the\n * client times out. 600-999 is unassigned, NOT invalid — Node sends it and a\n * client sees it — so a mock server allows it.\n */\nexport const INJECTED_STATUS_RANGE =\n \"an integer between 200 and 999 (1xx cannot terminate a response and would hang the client)\";\n\n/**\n * Shared by the three doors that queue an error whose `status` reaches\n * `res.writeHead`: a fixture's `response.status` (below), `POST\n * /__aimock/error`, and `LLMock.nextRequestError`.\n */\nexport function isInjectableStatus(status: unknown): status is number {\n // The typeof is for the COMPILER — it narrows `unknown` so the comparisons\n // below type-check. At runtime `Number.isInteger` already excludes every\n // non-number, so mutating it away fails nothing.\n if (typeof status !== \"number\") return false;\n return Number.isInteger(status) && status >= 200 && status <= 999;\n}\n\nexport function validateFixtures(fixtures: Fixture[]): ValidationResult[] {\n const results: ValidationResult[] = [];\n\n const seenUserMessages = new Map<string, number>();\n\n for (let i = 0; i < fixtures.length; i++) {\n const f = fixtures[i];\n const response = f.response;\n\n // Skip response-shape validation for function responses — they are\n // evaluated at runtime so we cannot statically inspect them.\n if (typeof response === \"function\") {\n // Still validate match fields and numeric options below.\n } else {\n // --- Error checks ---\n\n // Response type recognition\n // Note: isContentWithToolCallsResponse must be checked before isTextResponse\n // and isToolCallResponse since it is a structural superset of both.\n if (\n !isContentWithToolCallsResponse(response) &&\n !isTextResponse(response) &&\n !isToolCallResponse(response) &&\n !isErrorResponse(response) &&\n !isEmbeddingResponse(response) &&\n !isImageResponse(response) &&\n !isAudioResponse(response) &&\n !isTranscriptionResponse(response) &&\n !isVideoResponse(response) &&\n !isJSONResponse(response)\n ) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message:\n \"response is not a recognized type (must have content, toolCalls, error, embedding, image, audio, transcription, video, or json)\",\n });\n }\n\n // When a non-empty ordered `blocks` array is present, the builders stream\n // `blocks` and IGNORE the legacy `content` mirror (see validateBlocks's\n // divergence note + isContentWithToolCallsResponse's BLOCKS-ONLY clause).\n // So an empty-string `content` is harmless in that case and must NOT raise\n // the \"content is empty string\" hard error. Fixtures WITHOUT blocks keep\n // the error (an empty content with no blocks produces no output).\n const hasNonEmptyBlocks =\n Array.isArray((response as { blocks?: unknown }).blocks) &&\n (response as { blocks: unknown[] }).blocks.length > 0;\n\n // Text response checks\n if (isTextResponse(response)) {\n if (response.content === \"\" && !hasNonEmptyBlocks) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"content is empty string\",\n });\n }\n validateReasoning(response, i, results);\n validateWebSearches(response, i, results);\n }\n\n // ContentWithToolCalls response checks\n if (isContentWithToolCallsResponse(response)) {\n // The guard now also matches a BLOCKS-ONLY fixture (non-empty `blocks`,\n // no `content`/`toolCalls`). For that shape the content/toolCalls checks\n // below don't apply (and `content`/`toolCalls` are undefined) — the\n // ordered `blocks` array is validated separately by `validateBlocks`\n // immediately after this block. So gate the legacy field checks on the\n // fields actually being present, mirroring the builders' branch-on-blocks.\n if (typeof response.content === \"string\") {\n if (response.content === \"\" && !hasNonEmptyBlocks) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"content is empty string\",\n });\n }\n }\n if (Array.isArray(response.toolCalls)) {\n if (response.toolCalls.length === 0) {\n results.push({\n severity: \"warning\",\n fixtureIndex: i,\n message: \"toolCalls array is empty — fixture will never produce tool calls\",\n });\n }\n for (let j = 0; j < response.toolCalls.length; j++) {\n const tc = response.toolCalls[j];\n if (!tc.name) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `toolCalls[${j}].name is empty`,\n });\n }\n try {\n JSON.parse(tc.arguments);\n } catch {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `toolCalls[${j}].arguments is not valid JSON: ${tc.arguments}`,\n });\n }\n }\n }\n validateReasoning(response, i, results);\n validateWebSearches(response, i, results);\n }\n\n // Optional ordered `blocks` checks — validated whenever present on the\n // response, regardless of which content/toolCalls guard matched, so a\n // malformed blocks array is rejected at LOAD rather than at dispatch.\n validateBlocks(\n response as { blocks?: unknown; content?: unknown; toolCalls?: unknown },\n i,\n results,\n );\n\n // Tool call response checks\n if (isToolCallResponse(response)) {\n if (response.toolCalls.length === 0) {\n results.push({\n severity: \"warning\",\n fixtureIndex: i,\n message: \"toolCalls array is empty — fixture will never produce tool calls\",\n });\n }\n for (let j = 0; j < response.toolCalls.length; j++) {\n const tc = response.toolCalls[j];\n if (!tc.name) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `toolCalls[${j}].name is empty`,\n });\n }\n try {\n JSON.parse(tc.arguments);\n } catch {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `toolCalls[${j}].arguments is not valid JSON: ${tc.arguments}`,\n });\n }\n }\n validateWebSearches(response, i, results);\n }\n\n // Error response checks\n if (isErrorResponse(response)) {\n if (!response.error.message) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"error.message is empty\",\n });\n }\n // Shared with `POST /__aimock/error` and `LLMock.nextRequestError`\n // (see `isInjectableStatus` above): a fixture's status lands on the same\n // `res.writeHead`, so it is accepted or rejected identically.\n if (response.status !== undefined && !isInjectableStatus(response.status)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `error status ${response.status} is not a valid HTTP status code — must be ${INJECTED_STATUS_RANGE}`,\n });\n }\n // `fallthrough` gates OpenRouter `models[]` failover and is read as\n // `!== false`, so a non-boolean (`\"false\"`, 0, null) would silently\n // fall through — the OPPOSITE of the intended terminal behavior. Reject\n // it at load so the fail-closed half cannot quietly fail open.\n if (response.fallthrough !== undefined && typeof response.fallthrough !== \"boolean\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `error.fallthrough must be a boolean, got ${typeof response.fallthrough}`,\n });\n }\n }\n\n // Embedding response checks\n if (isEmbeddingResponse(response)) {\n if (response.embedding.length === 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"embedding array is empty\",\n });\n }\n for (let j = 0; j < response.embedding.length; j++) {\n if (typeof response.embedding[j] !== \"number\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `embedding[${j}] is not a number`,\n });\n break; // one error is enough\n }\n }\n }\n\n // Audio response checks — validate object-form audio\n if (isAudioResponse(response) && typeof response.audio === \"object\") {\n const audioObj = response.audio;\n if (typeof audioObj.b64Json !== \"string\" || audioObj.b64Json === \"\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"audio.b64Json must be a non-empty string\",\n });\n }\n if (audioObj.contentType !== undefined && typeof audioObj.contentType !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `audio.contentType must be a string, got ${typeof audioObj.contentType}`,\n });\n }\n }\n\n // Validate ResponseOverrides fields\n if (\n isTextResponse(response) ||\n isToolCallResponse(response) ||\n isContentWithToolCallsResponse(response)\n ) {\n const r = response as ResponseOverrides;\n if (r.id !== undefined && typeof r.id !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"id\" must be a string, got ${typeof r.id}`,\n });\n }\n if (r.created !== undefined && (typeof r.created !== \"number\" || r.created < 0)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"created\" must be a non-negative number`,\n });\n }\n if (r.model !== undefined && typeof r.model !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"model\" must be a string, got ${typeof r.model}`,\n });\n }\n if (r.finishReason !== undefined && typeof r.finishReason !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"finishReason\" must be a string, got ${typeof r.finishReason}`,\n });\n }\n if (r.role !== undefined && typeof r.role !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"role\" must be a string, got ${typeof r.role}`,\n });\n }\n if (r.systemFingerprint !== undefined && typeof r.systemFingerprint !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"systemFingerprint\" must be a string, got ${typeof r.systemFingerprint}`,\n });\n }\n if (r.usage !== undefined) {\n if (typeof r.usage !== \"object\" || r.usage === null || Array.isArray(r.usage)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"usage\" must be an object`,\n });\n } else {\n // Numeric token fields must be numbers, but the OpenRouter cost\n // sub-fields carry non-numeric shapes (see ResponseOverrides.usage\n // in types.ts): cost_details / prompt_tokens_details /\n // completion_tokens_details are objects and is_byok is a boolean.\n // Validate each per its documented type so cost-scripting fixtures\n // are not rejected with a misleading \"must be a number\" error.\n // Known numeric inner scalars per object field (see\n // OpenRouterUsageExtras in types.ts). Validating only these keeps\n // the index-signature ([key: string]: unknown) escape hatch open\n // for forward-compat fields while still catching malformed values\n // on the documented ones — otherwise a bad inner scalar (e.g.\n // cost_details.upstream_inference_cost: \"abc\") passes load-time\n // validation and only blows up at replay in the canonical SDK.\n const numericInnerFields: Record<string, readonly string[]> = {\n cost_details: [\n \"upstream_inference_cost\",\n \"upstream_inference_prompt_cost\",\n \"upstream_inference_completions_cost\",\n ],\n prompt_tokens_details: [\"cached_tokens\", \"cache_write_tokens\", \"audio_tokens\"],\n completion_tokens_details: [\"reasoning_tokens\"],\n };\n const objectUsageFields = new Set(Object.keys(numericInnerFields));\n for (const key of Object.keys(r.usage)) {\n const val = (r.usage as Record<string, unknown>)[key];\n if (val === undefined) continue;\n if (objectUsageFields.has(key)) {\n if (typeof val !== \"object\" || val === null || Array.isArray(val)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"usage.${key}\" must be an object, got ${\n Array.isArray(val) ? \"array\" : typeof val\n }`,\n });\n } else {\n // Type-check the documented inner scalars; each is optional\n // (required-if-present), so only validate keys that are set.\n const inner = val as Record<string, unknown>;\n for (const innerKey of numericInnerFields[key]) {\n const innerVal = inner[innerKey];\n if (innerVal !== undefined && typeof innerVal !== \"number\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"usage.${key}.${innerKey}\" must be a number, got ${typeof innerVal}`,\n });\n }\n }\n }\n } else if (key === \"is_byok\") {\n if (typeof val !== \"boolean\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"usage.is_byok\" must be a boolean, got ${typeof val}`,\n });\n }\n } else if (typeof val !== \"number\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"usage.${key}\" must be a number, got ${typeof val}`,\n });\n }\n }\n }\n }\n }\n } // end: skip response-shape validation for function responses\n\n // Numeric sanity checks\n if (f.latency !== undefined && f.latency < 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"latency must be >= 0\",\n });\n }\n if (f.chunkSize !== undefined && f.chunkSize < 1) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"chunkSize must be >= 1\",\n });\n }\n if (f.truncateAfterChunks !== undefined && f.truncateAfterChunks < 1) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"truncateAfterChunks must be >= 1\",\n });\n }\n if (f.disconnectAfterMs !== undefined && f.disconnectAfterMs < 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"disconnectAfterMs must be >= 0\",\n });\n }\n if (f.streamingProfile !== undefined) {\n const sp = f.streamingProfile;\n if (sp.ttft !== undefined && sp.ttft < 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"streamingProfile.ttft must be >= 0\",\n });\n }\n if (sp.tps !== undefined && sp.tps <= 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"streamingProfile.tps must be > 0\",\n });\n }\n if (sp.jitter !== undefined && (sp.jitter < 0 || sp.jitter > 1)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"streamingProfile.jitter must be between 0 and 1\",\n });\n }\n }\n if (f.chaos !== undefined) {\n const ch = f.chaos;\n if (ch.dropRate !== undefined && (ch.dropRate < 0 || ch.dropRate > 1)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"chaos.dropRate must be between 0 and 1\",\n });\n }\n if (ch.malformedRate !== undefined && (ch.malformedRate < 0 || ch.malformedRate > 1)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"chaos.malformedRate must be between 0 and 1\",\n });\n }\n if (ch.disconnectRate !== undefined && (ch.disconnectRate < 0 || ch.disconnectRate > 1)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"chaos.disconnectRate must be between 0 and 1\",\n });\n }\n }\n\n // Match field type checks\n if (f.match.turnIndex !== undefined) {\n if (\n typeof f.match.turnIndex !== \"number\" ||\n f.match.turnIndex < 0 ||\n !Number.isInteger(f.match.turnIndex)\n ) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"match.turnIndex must be a non-negative integer\",\n });\n }\n }\n if (f.match.sequenceIndex !== undefined) {\n if (\n typeof f.match.sequenceIndex !== \"number\" ||\n f.match.sequenceIndex < 0 ||\n !Number.isInteger(f.match.sequenceIndex)\n ) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"match.sequenceIndex must be a non-negative integer\",\n });\n }\n }\n if (f.match.hasToolResult !== undefined && typeof f.match.hasToolResult !== \"boolean\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.hasToolResult must be a boolean, got ${typeof f.match.hasToolResult}`,\n });\n }\n if (f.match.toolResultContains !== undefined) {\n if (typeof f.match.toolResultContains !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.toolResultContains must be a string, got ${typeof f.match.toolResultContains}`,\n });\n } else if (f.match.toolResultContains.length === 0) {\n // An empty substring is always contained, so the gate would silently\n // act as \"last message is any tool result\" — reject it as an authoring\n // mistake rather than let it shadow later fixtures.\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"match.toolResultContains must be a non-empty string\",\n });\n }\n }\n if (f.match.systemMessage !== undefined) {\n const sm = f.match.systemMessage;\n if (typeof sm === \"string\") {\n // ok\n } else if (Array.isArray(sm)) {\n if (sm.length === 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.systemMessage array must contain at least one substring`,\n });\n } else {\n for (let j = 0; j < sm.length; j++) {\n if (typeof sm[j] !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.systemMessage[${j}] must be a string, got ${typeof sm[j]}`,\n });\n }\n }\n }\n } else {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.systemMessage must be a string or string[], got ${typeof sm}`,\n });\n }\n }\n if (f.match.context !== undefined && typeof f.match.context !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.context must be a string, got ${typeof f.match.context}`,\n });\n }\n\n // --- Warning checks ---\n\n // Duplicate userMessage shadowing — two fixtures are only genuine\n // duplicates when they would match the SAME requests, so the dedup key must\n // include EVERY match discriminator the router (matchFixtureDiagnostic in\n // router.ts) actually gates on: userMessage, systemMessage, inputText,\n // toolCallId, toolResultContains, toolName, model, responseFormat, endpoint,\n // context, sequenceIndex, turnIndex, and hasToolResult. Omitting any of these\n // (the old key only carried turnIndex/hasToolResult/toolResultContains/\n // sequenceIndex/context) flags two legitimately-distinct fixtures — e.g. two\n // that differ ONLY in toolCallId or model — as false duplicates.\n //\n // `predicate` is a function and cannot be compared for equivalence, so it is\n // never folded into a shared key: a fixture carrying a predicate is treated\n // as unconditionally distinct (keyed by its own index) so it neither shadows\n // nor is shadowed by another fixture on the userMessage axis.\n //\n // Values are serialised kind-aware so RegExp / string[] matchers do not\n // collide (a template literal would coerce a RegExp to its source and an\n // array via join, losing the distinction) — mirroring describeMatch in\n // router.ts.\n const um = f.match.userMessage;\n if (typeof um === \"string\" && um) {\n const m = f.match;\n const dedupKey =\n m.predicate !== undefined\n ? `predicate:${i}`\n : [\n serializeMatcher(m.userMessage),\n serializeMatcher(m.systemMessage),\n serializeMatcher(m.inputText),\n m.toolCallId,\n m.toolResultContains,\n m.toolName,\n serializeMatcher(m.model),\n m.responseFormat,\n m.endpoint,\n m.context,\n m.sequenceIndex,\n m.turnIndex,\n m.hasToolResult,\n ]\n .map((v) => (v === undefined ? \"\" : String(v)))\n .join(\"|\");\n const prev = seenUserMessages.get(dedupKey);\n if (prev !== undefined) {\n results.push({\n severity: \"warning\",\n fixtureIndex: i,\n message: `duplicate userMessage '${um}' — shadows fixture ${prev}`,\n });\n } else {\n seenUserMessages.set(dedupKey, i);\n }\n }\n\n // Catch-all not in last position\n const match = f.match;\n const hasDiscriminator =\n match.endpoint !== undefined ||\n match.context !== undefined ||\n match.userMessage !== undefined ||\n match.systemMessage !== undefined ||\n match.inputText !== undefined ||\n match.responseFormat !== undefined ||\n match.toolCallId !== undefined ||\n match.toolResultContains !== undefined ||\n match.toolName !== undefined ||\n match.model !== undefined ||\n match.predicate !== undefined ||\n match.turnIndex !== undefined ||\n match.sequenceIndex !== undefined ||\n match.hasToolResult !== undefined;\n\n if (!hasDiscriminator && i < fixtures.length - 1) {\n results.push({\n severity: \"warning\",\n fixtureIndex: i,\n message: `empty match acts as catch-all but is not the last fixture — shadows fixtures ${i + 1}+`,\n });\n }\n }\n\n return results;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cjs","names":["isLiveResponse","normalizeLiveFixture","isContentWithToolCallsResponse","isTextResponse","isToolCallResponse","isErrorResponse","isEmbeddingResponse","isImageResponse","isAudioResponse","isTranscriptionResponse","isVideoResponse","isJSONResponse","CHAOS_FIELD_NAMES","parseChaosField","CHAOS_FIELDS","within","MCP_FAKES_ECHO_LIMIT","jsonText","quote","build","fixed"],"sources":["../src/fixture-loader.ts"],"sourcesContent":["import type { LiveOptions } from \"./live-types.js\";\nimport { normalizeLiveFixture } from \"./live-fixture.js\";\nimport { readFileSync, readdirSync, statSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport type {\n ChatCompletionRequest,\n Fixture,\n FixtureFile,\n FixtureFileEntry,\n FixtureFileResponse,\n FixtureResponse,\n ResponseOverrides,\n} from \"./types.js\";\nimport {\n isLiveResponse,\n isTextResponse,\n isToolCallResponse,\n isContentWithToolCallsResponse,\n isErrorResponse,\n isEmbeddingResponse,\n isImageResponse,\n isAudioResponse,\n isTranscriptionResponse,\n isVideoResponse,\n isJSONResponse,\n} from \"./helpers.js\";\nimport type { Logger } from \"./logger.js\";\nimport { CHAOS_FIELDS, CHAOS_FIELD_NAMES, parseChaosField } from \"./chaos.js\";\nimport { Message, build, fixed, jsonText, msg, quote, within } from \"./message-text.js\";\nimport { MCP_FAKES_ECHO_LIMIT } from \"./constants.js\";\n\n/**\n * Auto-stringify object-valued `content` and `toolCalls[].arguments` fields.\n * This lets fixture authors write plain JSON objects instead of escaped strings.\n * All other fields (including ResponseOverrides, and the ErrorResponse\n * `fallthrough` OpenRouter-failover flag) pass through unmodified via the\n * shallow clone below.\n */\nexport function normalizeResponse(\n raw: FixtureFileResponse,\n liveOptions?: LiveOptions,\n): FixtureResponse {\n if (isLiveResponse(raw)) return normalizeLiveFixture(raw, liveOptions);\n // Shallow-clone so we don't mutate the parsed JSON input.\n const response = { ...raw } as Record<string, unknown>;\n\n // Auto-stringify object content (e.g. structured output)\n if (typeof response.content === \"object\" && response.content !== null) {\n response.content = JSON.stringify(response.content);\n }\n\n // Auto-stringify object arguments in toolCalls\n if (Array.isArray(response.toolCalls)) {\n response.toolCalls = (response.toolCalls as Array<Record<string, unknown>>).map((tc) => {\n if (typeof tc.arguments === \"object\" && tc.arguments !== null) {\n return { ...tc, arguments: JSON.stringify(tc.arguments) };\n }\n return tc;\n });\n }\n\n // Carry the optional ordered `blocks` array through, mirroring the\n // toolCalls[].arguments idiom above: auto-stringify object `arguments` on\n // each `toolCall` block. Gated on Array.isArray so a malformed (non-array)\n // `blocks` value passes through untouched rather than crashing — downstream\n // validation/builders own shape rejection. Absent `blocks` → key absent.\n if (Array.isArray(response.blocks)) {\n response.blocks = (response.blocks as Array<Record<string, unknown>>).map((block) => {\n if (\n block != null &&\n block.type === \"toolCall\" &&\n typeof block.arguments === \"object\" &&\n block.arguments !== null\n ) {\n return { ...block, arguments: JSON.stringify(block.arguments) };\n }\n return block;\n });\n }\n\n return response as unknown as FixtureResponse;\n}\n\nclass InvalidFixtureMatchError extends TypeError {}\n\nexport function entryToFixture(\n entry: FixtureFileEntry,\n logger?: Logger,\n liveOptions?: LiveOptions,\n): Fixture {\n if (entry === null || typeof entry !== \"object\" || Array.isArray(entry)) {\n throw new TypeError(\"Fixture entry must be an object\");\n }\n if (entry.match == null) {\n throw new TypeError(\"Fixture match must be an object\");\n }\n if (typeof entry.match !== \"object\" || Array.isArray(entry.match)) {\n throw new InvalidFixtureMatchError(\"Fixture match must be an object\");\n }\n const fixture: Fixture = {\n match: {\n userMessage: entry.match.userMessage,\n systemMessage: entry.match.systemMessage,\n inputText: entry.match.inputText,\n toolCallId: entry.match.toolCallId,\n toolResultContains: entry.match.toolResultContains,\n toolName: entry.match.toolName,\n model: entry.match.model,\n responseFormat: entry.match.responseFormat,\n endpoint: entry.match.endpoint,\n ...(entry.match.sequenceIndex !== undefined && { sequenceIndex: entry.match.sequenceIndex }),\n ...(entry.match.turnIndex !== undefined && {\n turnIndex: entry.match.turnIndex,\n }),\n ...(entry.match.hasToolResult !== undefined && {\n hasToolResult: entry.match.hasToolResult,\n }),\n ...(entry.match.context !== undefined && { context: entry.match.context }),\n },\n response:\n entry.match.endpoint === \"openai-live\"\n ? normalizeLiveFixture(entry.response, liveOptions)\n : normalizeResponse(entry.response, liveOptions),\n ...(entry.latency !== undefined && { latency: entry.latency }),\n ...(entry.chunkSize !== undefined && { chunkSize: entry.chunkSize }),\n ...(entry.truncateAfterChunks !== undefined && {\n truncateAfterChunks: entry.truncateAfterChunks,\n }),\n ...(entry.disconnectAfterMs !== undefined && { disconnectAfterMs: entry.disconnectAfterMs }),\n ...(entry.streamingProfile !== undefined && { streamingProfile: entry.streamingProfile }),\n ...(entry.recordedTimings !== undefined && { recordedTimings: entry.recordedTimings }),\n ...(entry.replaySpeed != null && { replaySpeed: entry.replaySpeed }),\n ...(entry.chaos !== undefined && { chaos: entry.chaos }),\n ...(entry.openRouterProcessing !== undefined && {\n openRouterProcessing: entry.openRouterProcessing,\n }),\n ...(entry.metadata !== undefined && { metadata: entry.metadata }),\n };\n\n // Sanitize recordedTimings to guard against NaN or negative values that\n // would silently degrade replay timing calculations.\n if (fixture.recordedTimings) {\n const rt = fixture.recordedTimings;\n if (!Number.isFinite(rt.ttftMs) || rt.ttftMs < 0) rt.ttftMs = 0;\n rt.interChunkDelaysMs = Array.isArray(rt.interChunkDelaysMs)\n ? rt.interChunkDelaysMs.filter((d) => Number.isFinite(d) && d >= 0)\n : [];\n if (!Number.isFinite(rt.totalDurationMs) || rt.totalDurationMs < 0) rt.totalDurationMs = 0;\n }\n\n if (fixture.replaySpeed != null && fixture.replaySpeed <= 0) {\n logger?.warn(`Fixture replaySpeed must be positive, got ${fixture.replaySpeed}. Ignoring.`);\n delete fixture.replaySpeed;\n }\n\n return fixture;\n}\n\n/**\n * Serialise a match value (string | string[] | RegExp | undefined) into a\n * dedup-key fragment that is kind-aware, so a string, a RegExp with the same\n * source, and an array containing that string do not collide. A plain template\n * literal would coerce `/foo/` and `\"foo\"` to the same text and join `[\"foo\"]`\n * to `\"foo\"`, wrongly deduping fixtures that the router would treat as distinct.\n * Used by the duplicate-userMessage dedup key in validateFixtures.\n */\nfunction serializeMatcher(value: string | string[] | RegExp | undefined): string {\n if (value === undefined) return \"\";\n if (value instanceof RegExp) return `re:${value.source}\\u0000${value.flags}`;\n if (Array.isArray(value)) return `arr:${JSON.stringify(value)}`;\n return `str:${value}`;\n}\n\n// Logging helper — uses logger if provided, falls back to console.warn.\nfunction warn(logger: Logger | undefined, msg: string, ...rest: unknown[]): void {\n if (logger) {\n logger.warn(msg, ...rest);\n } else {\n console.warn(`[fixture-loader] ${msg}`, ...rest);\n }\n}\n\n/**\n * A parsed JSON value, or `null` when the file could not be read or parsed (warned).\n *\n * @internal Shared with fixture-loader-services.ts.\n */\nexport function readFixtureJson(\n filePath: string,\n logger: Logger | undefined,\n): { value: unknown } | null {\n let raw: string;\n try {\n raw = readFileSync(filePath, \"utf-8\");\n } catch (err) {\n warn(logger, `Could not read file ${filePath}:`, err);\n return null;\n }\n\n try {\n return { value: JSON.parse(raw) };\n } catch (err) {\n warn(logger, `Invalid JSON in ${filePath}:`, err);\n return null;\n }\n}\n\n/**\n * `parsed` is a JSON object with an own top-level `mcpFakes` key.\n *\n * @internal Shared with fixture-loader-services.ts.\n */\nexport function hasMcpFakesKey(parsed: unknown): parsed is Record<string, unknown> {\n return (\n typeof parsed === \"object\" &&\n parsed !== null &&\n !Array.isArray(parsed) &&\n Object.prototype.hasOwnProperty.call(parsed, \"mcpFakes\")\n );\n}\n\n/**\n * The LLM fixtures of a parsed file. A missing or non-array `fixtures` is\n * warned and gives none, except that a file with `mcpFakes` may leave\n * `fixtures` out (`fixturesOptional`, spec 5.4). An entry whose `match` is\n * not an object is skipped with a warning; any other bad entry throws.\n *\n * @internal Shared with fixture-loader-services.ts.\n */\nexport function fixturesOf(\n parsed: unknown,\n filePath: string,\n logger: Logger | undefined,\n liveOptions: LiveOptions | undefined,\n fixturesOptional: boolean,\n): Fixture[] {\n if (\n fixturesOptional &&\n typeof parsed === \"object\" &&\n parsed !== null &&\n !Object.prototype.hasOwnProperty.call(parsed, \"fixtures\")\n ) {\n return [];\n }\n if (\n typeof parsed !== \"object\" ||\n parsed === null ||\n !Array.isArray((parsed as FixtureFile).fixtures)\n ) {\n warn(logger, `Missing or invalid \"fixtures\" array in ${filePath}`);\n return [];\n }\n\n const fixtures: Fixture[] = [];\n for (const [index, entry] of (parsed as FixtureFile).fixtures.entries()) {\n try {\n fixtures.push(entryToFixture(entry, logger, liveOptions));\n } catch (error) {\n if (!(error instanceof InvalidFixtureMatchError)) throw error;\n warn(logger, `Skipping fixture at index ${index} in ${filePath}: ${error.message}`);\n }\n }\n return fixtures;\n}\n\n/**\n * B13: the old loaders return LLM fixtures only, so a file with `mcpFakes`\n * fails loud instead of losing its fakes.\n */\nfunction cannotCarryFakes(filePath: string): FixtureLoadError {\n return new FixtureLoadError({\n rule: \"mcp-fakes/loader-cannot-carry-fakes\",\n file: filePath,\n blockId: null,\n entryId: null,\n detail: msg`top-level \"mcpFakes\" key: loadFixtureFile and loadFixturesFromDir cannot carry MCP fakes; use loadFixtureFileWithServices or loadFixturesFromDirWithServices, or LLMock.loadFixtureFile or LLMock.loadFixtureDir`,\n });\n}\n\n/**\n * Load the LLM fixtures of one file. Throws a `FixtureLoadError` (rule\n * `mcp-fakes/loader-cannot-carry-fakes`) when the file has a top-level\n * `mcpFakes` key; use `loadFixtureFileWithServices` (fixture-loader-services.ts) for such files.\n */\nexport function loadFixtureFile(\n filePath: string,\n logger?: Logger,\n liveOptions?: LiveOptions,\n): Fixture[] {\n const read = readFixtureJson(filePath, logger);\n if (read === null) return [];\n if (hasMcpFakesKey(read.value)) throw cannotCarryFakes(filePath);\n return fixturesOf(read.value, filePath, logger, liveOptions, false);\n}\n\n/**\n * The `.json` files (sorted) and the subdirectories (sorted) of `dirPath`,\n * or `null` when it cannot be read (warned).\n *\n * @internal Shared with fixture-loader-services.ts.\n */\nexport function listFixtureDir(\n dirPath: string,\n logger: Logger | undefined,\n): { jsonFiles: string[]; subdirs: string[] } | null {\n let entries: string[];\n try {\n entries = readdirSync(dirPath);\n } catch (err) {\n warn(logger, `Could not read directory ${dirPath}:`, err);\n return null;\n }\n\n const jsonFiles: string[] = [];\n const subdirs: string[] = [];\n for (const name of entries) {\n const fullPath = join(dirPath, name);\n try {\n if (statSync(fullPath).isDirectory()) {\n subdirs.push(name);\n continue;\n }\n } catch (err) {\n const code = (err as NodeJS.ErrnoException).code;\n if (code !== \"ENOENT\") {\n warn(logger, `Could not stat ${fullPath}:`, err);\n }\n continue;\n }\n if (name.endsWith(\".json\")) {\n jsonFiles.push(name);\n }\n }\n jsonFiles.sort();\n subdirs.sort();\n return { jsonFiles, subdirs };\n}\n\n/**\n * Load the LLM fixtures of every `.json` file under `dirPath`. Throws a\n * `FixtureLoadError` (rule `mcp-fakes/loader-cannot-carry-fakes`) on the\n * first file with a top-level `mcpFakes` key; use\n * `loadFixturesFromDirWithServices` (fixture-loader-services.ts) for such\n * directories.\n */\nexport function loadFixturesFromDir(\n dirPath: string,\n logger?: Logger,\n liveOptions?: LiveOptions,\n): Fixture[] {\n const listing = listFixtureDir(dirPath, logger);\n if (listing === null) return [];\n\n const fixtures: Fixture[] = [];\n for (const name of listing.jsonFiles) {\n const filePath = join(dirPath, name);\n fixtures.push(...loadFixtureFile(filePath, logger, liveOptions));\n }\n\n // Recurse into all subdirectories (full depth) to support nested layouts\n // like showcase/aimock/d6/<integration>/<feature>.json.\n for (const sub of listing.subdirs) {\n fixtures.push(...loadFixturesFromDir(join(dirPath, sub), logger, liveOptions));\n }\n\n return fixtures;\n}\n\n// ---------------------------------------------------------------------------\n// Fixture validation\n// ---------------------------------------------------------------------------\n\n/**\n * The fixture indices a finding's message NAMES, carried as data.\n *\n * Two rules (`duplicate userMessage` and the catch-all ordering check) name\n * OTHER fixtures in the array they were given, so their message text embeds an\n * index. A consumer that validates a different array than the one the reader\n * sees — `aimock validate` runs the rules per file and then over the union of\n * every file — has to renumber those indices, and the only safe way to do that\n * is to re-render from the numbers rather than to rewrite the rendered prose:\n * `duplicate userMessage` interpolates the fixture's OWN `userMessage`, so a\n * regex over the message corrupts user-authored text that happens to read\n * \"fixture 3\".\n */\nexport type ValidationRef =\n | { rule: \"duplicate-user-message\"; userMessage: string; shadows: number }\n | { rule: \"catch-all-not-last\"; shadowsFrom: number; shadowsThrough: number };\n\nexport interface ValidationResult {\n severity: \"error\" | \"warning\";\n fixtureIndex: number;\n message: string;\n /** Present only on the rules whose message names other fixtures. */\n ref?: ValidationRef;\n}\n\n/**\n * Render a ref-carrying finding's message with each named index passed through\n * `renderIndex`. With `String` it reproduces the message `validateFixtures`\n * itself emits; `aimock validate` passes a renderer that resolves a union\n * index to `<file> #<index-in-that-file>`.\n */\nexport function renderValidationRef(\n ref: ValidationRef,\n renderIndex: (fixtureIndex: number) => string,\n): string {\n return ref.rule === \"duplicate-user-message\"\n ? `duplicate userMessage '${ref.userMessage}' — shadows fixture ${renderIndex(ref.shadows)}`\n : `empty match acts as catch-all but is not the last fixture — shadows fixtures ${renderIndex(\n ref.shadowsFrom,\n )}+`;\n}\n\nfunction validateReasoning(\n response: { reasoning?: unknown },\n fixtureIndex: number,\n results: ValidationResult[],\n): void {\n if (response.reasoning !== undefined) {\n if (typeof response.reasoning !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: \"reasoning must be a string\",\n });\n } else if (response.reasoning === \"\") {\n results.push({\n severity: \"warning\",\n fixtureIndex,\n message: \"reasoning is empty string — no reasoning events will be emitted\",\n });\n }\n }\n}\n\nfunction validateWebSearches(\n response: { webSearches?: unknown },\n fixtureIndex: number,\n results: ValidationResult[],\n): void {\n if (response.webSearches !== undefined) {\n if (!Array.isArray(response.webSearches)) {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: \"webSearches must be an array of strings\",\n });\n } else if (response.webSearches.length === 0) {\n results.push({\n severity: \"warning\",\n fixtureIndex,\n message: \"webSearches is empty array — no web search events will be emitted\",\n });\n } else {\n for (let j = 0; j < response.webSearches.length; j++) {\n if (typeof response.webSearches[j] !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `webSearches[${j}] is not a string`,\n });\n break;\n }\n if (response.webSearches[j] === \"\") {\n results.push({\n severity: \"warning\",\n fixtureIndex,\n message: `webSearches[${j}] is empty string`,\n });\n }\n }\n }\n }\n}\n\nfunction validateBlocks(\n response: { blocks?: unknown; content?: unknown; toolCalls?: unknown },\n fixtureIndex: number,\n results: ValidationResult[],\n): void {\n if (response.blocks === undefined) return;\n\n // Mirrors the toolCalls checks: reject malformed `blocks` at LOAD time so a\n // bad blocks array never reaches the dispatch/builder (where\n // resolveFixtureBlocks throws AFTER the journal has already recorded\n // status:200, yielding a journal-200/client-500 mismatch). #274 F3+F8.\n if (!Array.isArray(response.blocks)) {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks must be an array, got ${typeof response.blocks}`,\n });\n return;\n }\n\n for (let j = 0; j < response.blocks.length; j++) {\n const block = response.blocks[j] as Record<string, unknown> | null | undefined;\n if (typeof block !== \"object\" || block === null) {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}] must be an object`,\n });\n continue;\n }\n if (block.type !== \"text\" && block.type !== \"toolCall\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].type must be \"text\" or \"toolCall\", got ${JSON.stringify(block.type)}`,\n });\n continue;\n }\n if (block.type === \"text\") {\n if (typeof block.text !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].text must be a string, got ${typeof block.text}`,\n });\n } else if (block.text === \"\") {\n // Mirror the content/toolCalls \"empty string\" rejection: an empty-text\n // block produces a meaningless/spurious wire chunk on replay.\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].text is empty string`,\n });\n }\n } else {\n // toolCall block — mirror toolCalls[] name + arguments checks.\n if (typeof block.name !== \"string\" || block.name === \"\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].name must be a non-empty string`,\n });\n }\n // `arguments` is JSON-string in runtime form (normalizeResponse already\n // stringified object/array args); accept a valid-JSON string or an object.\n if (typeof block.arguments === \"string\") {\n try {\n JSON.parse(block.arguments);\n } catch {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].arguments is not valid JSON: ${block.arguments}`,\n });\n }\n } else if (typeof block.arguments !== \"object\" || block.arguments === null) {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].arguments must be a JSON string or object, got ${typeof block.arguments}`,\n });\n }\n if (block.id !== undefined && typeof block.id !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex,\n message: `blocks[${j}].id must be a string, got ${typeof block.id}`,\n });\n }\n }\n }\n\n // blocks-vs-content/toolCalls divergence (#274 P2). When a fixture carries\n // BOTH `blocks` AND legacy `content`/`toolCalls` (allowed but unusual now\n // that blocks-only is first-class), builders stream `blocks` and IGNORE the\n // redundant `content`/`toolCalls`. If those disagree it is a silent footgun,\n // so WARN (not a hard error). Stay silent on the clean blocks-only path\n // (neither legacy field present) — that is the intended shape.\n const hasLegacyContent = typeof response.content === \"string\";\n const hasLegacyToolCalls = Array.isArray(response.toolCalls);\n if ((hasLegacyContent || hasLegacyToolCalls) && Array.isArray(response.blocks)) {\n const textBlocks = response.blocks.filter(\n (b): b is { type: \"text\"; text: string } =>\n b != null &&\n typeof b === \"object\" &&\n (b as { type?: unknown }).type === \"text\" &&\n typeof (b as { text?: unknown }).text === \"string\",\n );\n const toolCallBlockNames = response.blocks\n .filter(\n (b): b is { type: \"toolCall\"; name: string } =>\n b != null &&\n typeof b === \"object\" &&\n (b as { type?: unknown }).type === \"toolCall\" &&\n typeof (b as { name?: unknown }).name === \"string\",\n )\n .map((b) => b.name);\n\n // Text divergence: blocks' concatenated text vs legacy `content`.\n if (hasLegacyContent) {\n const blocksText = textBlocks.map((b) => b.text).join(\"\");\n if (blocksText !== response.content) {\n results.push({\n severity: \"warning\",\n fixtureIndex,\n message:\n \"blocks text diverges from content — builders stream blocks and ignore the redundant content field\",\n });\n }\n }\n\n // ToolCall divergence: blocks' ordered toolCall names vs legacy `toolCalls`.\n if (hasLegacyToolCalls) {\n const legacyNames = (response.toolCalls as Array<{ name?: unknown }>).map((tc) =>\n typeof tc?.name === \"string\" ? tc.name : undefined,\n );\n const sameNames =\n legacyNames.length === toolCallBlockNames.length &&\n legacyNames.every((n, k) => n === toolCallBlockNames[k]);\n if (!sameNames) {\n results.push({\n severity: \"warning\",\n fixtureIndex,\n message:\n \"blocks toolCalls diverge from toolCalls — builders stream blocks and ignore the redundant toolCalls field\",\n });\n }\n }\n }\n}\n\n/**\n * Human-readable form of the status range an injected error may carry.\n * Measured on Node v26: `res.writeHead` throws outside 100-999 (the injected\n * error is then lost and the caller sees a generic 500), and a 1xx status is\n * accepted but cannot terminate a response, so it hangs the request until the\n * client times out. 600-999 is unassigned, NOT invalid — Node sends it and a\n * client sees it — so a mock server allows it.\n */\nexport const INJECTED_STATUS_RANGE =\n \"an integer between 200 and 999 (1xx cannot terminate a response and would hang the client)\";\n\n/**\n * Shared by the three doors that queue an error whose `status` reaches\n * `res.writeHead`: a fixture's `response.status` (below), `POST\n * /__aimock/error`, and `LLMock.nextRequestError`.\n */\nexport function isInjectableStatus(status: unknown): status is number {\n // The typeof is for the COMPILER — it narrows `unknown` so the comparisons\n // below type-check. At runtime `Number.isInteger` already excludes every\n // non-number, so mutating it away fails nothing.\n if (typeof status !== \"number\") return false;\n return Number.isInteger(status) && status >= 200 && status <= 999;\n}\n\n/**\n * An injected error is only a valid response for endpoints that can carry an\n * error envelope. Mirrors the router's endpoint-compat table\n * (matchFixtureDiagnostic in router.ts): error responses are compatible with\n * chat / embedding / realtime* / fal / the four elevenlabs-voice* slots and\n * with requests that carry no endpoint type, but NOT with multimedia endpoints\n * (image, speech, video, transcription, …). Whether files / fine-tuning /\n * batches belong here is an open design question — not widened yet.\n */\nfunction isErrorEndpointCompatible(req: ChatCompletionRequest): boolean {\n const reqEndpoint = req._endpointType as string | undefined;\n return (\n reqEndpoint === undefined ||\n reqEndpoint === \"chat\" ||\n reqEndpoint === \"embedding\" ||\n reqEndpoint.startsWith(\"realtime\") ||\n reqEndpoint === \"fal\" ||\n reqEndpoint === \"elevenlabs-voice-design\" ||\n reqEndpoint === \"elevenlabs-voice\" ||\n reqEndpoint === \"elevenlabs-voice-get\" ||\n reqEndpoint === \"elevenlabs-voice-delete\"\n );\n}\n\n/**\n * Queue a one-shot injected error at the FRONT of `fixtures` — shared by\n * `LLMock.nextRequestError` and `POST /__aimock/error` so both doors gate and\n * consume identically. The caller validates `status` (`isInjectableStatus`).\n *\n * The fixture is consumed exactly when its error body is actually WRITTEN to a\n * client, not when its predicate is evaluated and not when its factory happens\n * to run. Handlers that await chaos claim it synchronously at selection\n * (`claimOneShotError`) so two concurrent requests cannot both pick it across\n * the chaos-latency await, and RELEASES the claim (`releaseOneShotError`) on\n * every exit that ends the request without writing that body — a terminal\n * chaos action, or a client that left during the chaos-latency delay — unless\n * the queue was cleared (`clearFixtureQueue`) in between, in which case the\n * stale claim is dropped rather than re-armed into the reset queue. The\n * claim cannot simply be deferred past the chaos gate instead: the chaos\n * config is resolved FROM the selected fixture, and a claim taken after the\n * latency await re-opens the concurrency race the claim-at-selection closes.\n * The OpenRouter `models[]` loop cannot burn it by resolving a candidate it\n * then fails past — the error is `fallthrough: false` (terminal) so the\n * candidate that selects it serves it. The factory still performs the same\n * idempotent claim for handlers that only reach the fixture via\n * `resolveResponse` without an intervening await (realtime and fal). Consuming at\n * predicate time burned the error unserved whenever a later fixture won\n * selection (e.g. a behind-the-count `turnIndex` fixture) and spliced the\n * array while the router was still iterating it, skipping the very fixture\n * that then won. The predicate gate keeps an incompatible request (an image\n * call) from selecting it at all, so the error stays pending for its intended\n * endpoint.\n */\nconst oneShotErrorFixtures = new WeakSet<Fixture>();\n\n/** True for a fixture queued by `queueOneShotError` (still armed or not). */\nexport function isOneShotError(fixture: Fixture): boolean {\n return oneShotErrorFixtures.has(fixture);\n}\n\n/**\n * Claim (consume) a one-shot error fixture. Returns true when this call\n * removed it from `fixtures`; false when another request already claimed it,\n * in which case the caller must NOT serve it and must re-select.\n */\nexport function claimOneShotError(fixtures: Fixture[], fixture: Fixture): boolean {\n const idx = fixtures.indexOf(fixture);\n if (idx === -1) return false;\n fixtures.splice(idx, 1);\n oneShotClaimGeneration.set(fixture, queueGeneration(fixtures));\n return true;\n}\n\n/**\n * Generation of each fixture queue, bumped by `clearFixtureQueue`. A one-shot\n * claim records the generation it was taken under; a release under a LATER\n * generation means the queue was cleared or reset while the claim was parked\n * (in the chaos-latency await) and the claim is stale — re-arming it would\n * plant the previous test's injection in the next test's freshly reset queue.\n * Keyed by array identity: every clear path preserves the array reference\n * (`length = 0`), so the counter follows the live queue.\n */\nconst fixtureQueueGeneration = new WeakMap<Fixture[], number>();\nconst oneShotClaimGeneration = new WeakMap<Fixture, number>();\n\nfunction queueGeneration(fixtures: Fixture[]): number {\n return fixtureQueueGeneration.get(fixtures) ?? 0;\n}\n\n/**\n * Empty a fixture queue in place (array identity preserved — the running\n * server reads this same array on every request) and invalidate every\n * outstanding one-shot claim against it, so a release that lands after the\n * clear is a no-op instead of re-arming into the emptied queue. The ONE door\n * for `POST /__aimock/reset`, `DELETE /__aimock/fixtures` and\n * `LLMock.clearFixtures`; a bare `fixtures.length = 0` misses the second half.\n */\nexport function clearFixtureQueue(fixtures: Fixture[]): void {\n fixtures.length = 0;\n fixtureQueueGeneration.set(fixtures, queueGeneration(fixtures) + 1);\n}\n\n/**\n * Re-arm a one-shot error that was claimed for a request which then ended\n * WITHOUT writing the error body — a terminal chaos action (drop / disconnect\n * / rateLimit / malformed) or a client that hung up during the chaos-latency\n * delay. Without this the injection is burned unserved and the NEXT request\n * gets a 200, which is exactly the outcome `nextRequestError` promises not to\n * produce. A no-op for a fixture that is not a one-shot, and for one still\n * present in `fixtures` (never claimed, or already re-armed) so a double\n * release cannot duplicate the injection — and for a claim taken before the\n * queue was last cleared, so a reset that raced the request stays a reset.\n */\nexport function releaseOneShotError(fixtures: Fixture[], fixture: Fixture | null): void {\n if (fixture === null || !oneShotErrorFixtures.has(fixture)) return;\n if (fixtures.includes(fixture)) return;\n // Claimed under an earlier generation: the queue was cleared/reset while\n // this request was parked. The clear disarmed the injection — stay cleared.\n if (oneShotClaimGeneration.get(fixture) !== queueGeneration(fixtures)) return;\n // Front, matching `queueOneShotError`: the one-shot wins registration-order\n // ties against everything else, exactly as it did before it was claimed.\n fixtures.unshift(fixture);\n}\n\nexport function queueOneShotError(\n fixtures: Fixture[],\n status: number,\n errorBody?: { message?: string; type?: string; code?: string },\n): Fixture {\n const errorResponse: FixtureResponse = {\n error: {\n message: errorBody?.message ?? \"Injected error\",\n type: errorBody?.type ?? \"server_error\",\n code: errorBody?.code,\n },\n status,\n // Terminal in the OpenRouter `models[]` loop: the candidate that selects\n // (and thereby claims) the one-shot serves it instead of failing past it.\n fallthrough: false,\n };\n const fixture: Fixture = {\n match: { predicate: isErrorEndpointCompatible },\n response: () => {\n // Idempotent: a no-op when the handler already claimed at selection.\n claimOneShotError(fixtures, fixture);\n return errorResponse;\n },\n };\n oneShotErrorFixtures.add(fixture);\n // Insert at front so it wins registration-order ties against everything else.\n fixtures.unshift(fixture);\n return fixture;\n}\n\nexport function validateFixtures(\n fixtures: Fixture[],\n liveOptions?: LiveOptions,\n): ValidationResult[] {\n const results: ValidationResult[] = [];\n\n const seenUserMessages = new Map<string, number>();\n\n for (let i = 0; i < fixtures.length; i++) {\n const f = fixtures[i];\n const response = f.response;\n\n if (\n typeof response !== \"function\" &&\n (isLiveResponse(response) || f.match.endpoint === \"openai-live\")\n ) {\n try {\n normalizeLiveFixture(response, liveOptions);\n } catch (error) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: error instanceof Error ? error.message : String(error),\n });\n }\n }\n\n // Skip response-shape validation for function responses — they are\n // evaluated at runtime so we cannot statically inspect them.\n if (typeof response === \"function\") {\n // Still validate match fields and numeric options below.\n } else {\n // --- Error checks ---\n\n // Response type recognition\n // Note: isContentWithToolCallsResponse must be checked before isTextResponse\n // and isToolCallResponse since it is a structural superset of both.\n if (\n !isContentWithToolCallsResponse(response) &&\n !isTextResponse(response) &&\n !isToolCallResponse(response) &&\n !isErrorResponse(response) &&\n !isEmbeddingResponse(response) &&\n !isImageResponse(response) &&\n !isAudioResponse(response) &&\n !isTranscriptionResponse(response) &&\n !isVideoResponse(response) &&\n !isJSONResponse(response) &&\n !isLiveResponse(response)\n ) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message:\n \"response is not a recognized type (must have content, toolCalls, error, embedding, image, audio, transcription, video, json, or live)\",\n });\n }\n\n // When a non-empty ordered `blocks` array is present, the builders stream\n // `blocks` and IGNORE the legacy `content` mirror (see validateBlocks's\n // divergence note + isContentWithToolCallsResponse's BLOCKS-ONLY clause).\n // So an empty-string `content` is harmless in that case and must NOT raise\n // the \"content is empty string\" hard error. Fixtures WITHOUT blocks keep\n // the error (an empty content with no blocks produces no output).\n const hasNonEmptyBlocks =\n Array.isArray((response as { blocks?: unknown }).blocks) &&\n (response as { blocks: unknown[] }).blocks.length > 0;\n\n // Text response checks\n if (isTextResponse(response)) {\n if (response.content === \"\" && !hasNonEmptyBlocks) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"content is empty string\",\n });\n }\n validateReasoning(response, i, results);\n validateWebSearches(response, i, results);\n }\n\n // ContentWithToolCalls response checks\n if (isContentWithToolCallsResponse(response)) {\n // The guard now also matches a BLOCKS-ONLY fixture (non-empty `blocks`,\n // no `content`/`toolCalls`). For that shape the content/toolCalls checks\n // below don't apply (and `content`/`toolCalls` are undefined) — the\n // ordered `blocks` array is validated separately by `validateBlocks`\n // immediately after this block. So gate the legacy field checks on the\n // fields actually being present, mirroring the builders' branch-on-blocks.\n if (typeof response.content === \"string\") {\n if (response.content === \"\" && !hasNonEmptyBlocks) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"content is empty string\",\n });\n }\n }\n if (Array.isArray(response.toolCalls)) {\n if (response.toolCalls.length === 0) {\n results.push({\n severity: \"warning\",\n fixtureIndex: i,\n message: \"toolCalls array is empty — fixture will never produce tool calls\",\n });\n }\n for (let j = 0; j < response.toolCalls.length; j++) {\n const tc = response.toolCalls[j];\n if (!tc.name) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `toolCalls[${j}].name is empty`,\n });\n }\n try {\n JSON.parse(tc.arguments);\n } catch {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `toolCalls[${j}].arguments is not valid JSON: ${tc.arguments}`,\n });\n }\n }\n }\n validateReasoning(response, i, results);\n validateWebSearches(response, i, results);\n }\n\n // Optional ordered `blocks` checks — validated whenever present on the\n // response, regardless of which content/toolCalls guard matched, so a\n // malformed blocks array is rejected at LOAD rather than at dispatch.\n validateBlocks(\n response as { blocks?: unknown; content?: unknown; toolCalls?: unknown },\n i,\n results,\n );\n\n // Tool call response checks\n if (isToolCallResponse(response)) {\n if (response.toolCalls.length === 0) {\n results.push({\n severity: \"warning\",\n fixtureIndex: i,\n message: \"toolCalls array is empty — fixture will never produce tool calls\",\n });\n }\n for (let j = 0; j < response.toolCalls.length; j++) {\n const tc = response.toolCalls[j];\n if (!tc.name) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `toolCalls[${j}].name is empty`,\n });\n }\n try {\n JSON.parse(tc.arguments);\n } catch {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `toolCalls[${j}].arguments is not valid JSON: ${tc.arguments}`,\n });\n }\n }\n validateWebSearches(response, i, results);\n }\n\n // Error response checks\n if (isErrorResponse(response)) {\n if (!response.error.message) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"error.message is empty\",\n });\n }\n // Shared with `POST /__aimock/error` and `LLMock.nextRequestError`\n // (see `isInjectableStatus` above): a fixture's status lands on the same\n // `res.writeHead`, so it is accepted or rejected identically.\n if (response.status !== undefined && !isInjectableStatus(response.status)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `error status ${response.status} is not a valid HTTP status code — must be ${INJECTED_STATUS_RANGE}`,\n });\n }\n // `fallthrough` gates OpenRouter `models[]` failover and is read as\n // `!== false`, so a non-boolean (`\"false\"`, 0, null) would silently\n // fall through — the OPPOSITE of the intended terminal behavior. Reject\n // it at load so the fail-closed half cannot quietly fail open.\n if (response.fallthrough !== undefined && typeof response.fallthrough !== \"boolean\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `error.fallthrough must be a boolean, got ${typeof response.fallthrough}`,\n });\n }\n }\n\n // Embedding response checks\n if (isEmbeddingResponse(response)) {\n if (response.embedding.length === 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"embedding array is empty\",\n });\n }\n for (let j = 0; j < response.embedding.length; j++) {\n if (typeof response.embedding[j] !== \"number\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `embedding[${j}] is not a number`,\n });\n break; // one error is enough\n }\n }\n }\n\n // Audio response checks — validate object-form audio\n if (isAudioResponse(response) && typeof response.audio === \"object\") {\n const audioObj = response.audio;\n if (typeof audioObj.b64Json !== \"string\" || audioObj.b64Json === \"\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"audio.b64Json must be a non-empty string\",\n });\n }\n if (audioObj.contentType !== undefined && typeof audioObj.contentType !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `audio.contentType must be a string, got ${typeof audioObj.contentType}`,\n });\n }\n }\n\n // Validate ResponseOverrides fields\n if (\n isTextResponse(response) ||\n isToolCallResponse(response) ||\n isContentWithToolCallsResponse(response)\n ) {\n const r = response as ResponseOverrides;\n if (r.id !== undefined && typeof r.id !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"id\" must be a string, got ${typeof r.id}`,\n });\n }\n if (r.created !== undefined && (typeof r.created !== \"number\" || r.created < 0)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"created\" must be a non-negative number`,\n });\n }\n if (r.model !== undefined && typeof r.model !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"model\" must be a string, got ${typeof r.model}`,\n });\n }\n if (r.finishReason !== undefined && typeof r.finishReason !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"finishReason\" must be a string, got ${typeof r.finishReason}`,\n });\n }\n if (r.role !== undefined && typeof r.role !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"role\" must be a string, got ${typeof r.role}`,\n });\n }\n if (r.systemFingerprint !== undefined && typeof r.systemFingerprint !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"systemFingerprint\" must be a string, got ${typeof r.systemFingerprint}`,\n });\n }\n if (r.usage !== undefined) {\n if (typeof r.usage !== \"object\" || r.usage === null || Array.isArray(r.usage)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"usage\" must be an object`,\n });\n } else {\n // Numeric token fields must be numbers, but the OpenRouter cost\n // sub-fields carry non-numeric shapes (see ResponseOverrides.usage\n // in types.ts): cost_details / prompt_tokens_details /\n // completion_tokens_details are objects and is_byok is a boolean.\n // Validate each per its documented type so cost-scripting fixtures\n // are not rejected with a misleading \"must be a number\" error.\n // Known numeric inner scalars per object field (see\n // OpenRouterUsageExtras in types.ts). Validating only these keeps\n // the index-signature ([key: string]: unknown) escape hatch open\n // for forward-compat fields while still catching malformed values\n // on the documented ones — otherwise a bad inner scalar (e.g.\n // cost_details.upstream_inference_cost: \"abc\") passes load-time\n // validation and only blows up at replay in the canonical SDK.\n const numericInnerFields: Record<string, readonly string[]> = {\n cost_details: [\n \"upstream_inference_cost\",\n \"upstream_inference_prompt_cost\",\n \"upstream_inference_completions_cost\",\n ],\n prompt_tokens_details: [\"cached_tokens\", \"cache_write_tokens\", \"audio_tokens\"],\n completion_tokens_details: [\"reasoning_tokens\"],\n };\n const objectUsageFields = new Set(Object.keys(numericInnerFields));\n for (const key of Object.keys(r.usage)) {\n const val = (r.usage as Record<string, unknown>)[key];\n if (val === undefined) continue;\n if (objectUsageFields.has(key)) {\n if (typeof val !== \"object\" || val === null || Array.isArray(val)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"usage.${key}\" must be an object, got ${\n Array.isArray(val) ? \"array\" : typeof val\n }`,\n });\n } else {\n // Type-check the documented inner scalars; each is optional\n // (required-if-present), so only validate keys that are set.\n const inner = val as Record<string, unknown>;\n for (const innerKey of numericInnerFields[key]) {\n const innerVal = inner[innerKey];\n if (innerVal !== undefined && typeof innerVal !== \"number\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"usage.${key}.${innerKey}\" must be a number, got ${typeof innerVal}`,\n });\n }\n }\n }\n } else if (key === \"is_byok\") {\n if (typeof val !== \"boolean\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"usage.is_byok\" must be a boolean, got ${typeof val}`,\n });\n }\n } else if (typeof val !== \"number\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `override \"usage.${key}\" must be a number, got ${typeof val}`,\n });\n }\n }\n }\n }\n }\n } // end: skip response-shape validation for function responses\n\n // Numeric sanity checks\n if (f.latency !== undefined && f.latency < 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"latency must be >= 0\",\n });\n }\n if (f.chunkSize !== undefined && f.chunkSize < 1) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"chunkSize must be >= 1\",\n });\n }\n if (f.truncateAfterChunks !== undefined && f.truncateAfterChunks < 1) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"truncateAfterChunks must be >= 1\",\n });\n }\n if (f.disconnectAfterMs !== undefined && f.disconnectAfterMs < 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"disconnectAfterMs must be >= 0\",\n });\n }\n if (f.streamingProfile !== undefined) {\n const sp = f.streamingProfile;\n if (sp.ttft !== undefined && sp.ttft < 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"streamingProfile.ttft must be >= 0\",\n });\n }\n if (sp.tps !== undefined && sp.tps <= 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"streamingProfile.tps must be > 0\",\n });\n }\n if (sp.jitter !== undefined && (sp.jitter < 0 || sp.jitter > 1)) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"streamingProfile.jitter must be between 0 and 1\",\n });\n }\n }\n if (f.chaos !== undefined) {\n // EVERY chaos field is routed through the ONE chaos table, so a fixture\n // cannot accept a value the CLI, the header and the runtime reject. The\n // hand-rolled `< 0 || > 1` checks this replaces let `NaN`, `-0` and a\n // numeric string (`dropRate: \"0.5\"`) validate clean, and `latencyMs: 1.5`\n // through; the runtime then rejected the fixture value on every request.\n // A fixture is typed data, like the control API's JSON body: the field\n // must be a number. A numeric STRING is a type error here, not a wire\n // spelling to be parsed — the header API is the surface that takes text.\n const ch = f.chaos as Record<string, unknown>;\n for (const field of CHAOS_FIELD_NAMES) {\n const value = ch[field];\n if (value === undefined) continue;\n const accepted = typeof value === \"number\" ? parseChaosField(field, value) : undefined;\n if (accepted === undefined) {\n const shape = CHAOS_FIELDS[field].integer ? \"a whole number of ms\" : \"a number\";\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `chaos.${field} must be ${shape} between 0 and ${CHAOS_FIELDS[field].max}`,\n });\n }\n }\n }\n\n // Match field type checks\n if (f.match.turnIndex !== undefined) {\n if (\n typeof f.match.turnIndex !== \"number\" ||\n f.match.turnIndex < 0 ||\n !Number.isInteger(f.match.turnIndex)\n ) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"match.turnIndex must be a non-negative integer\",\n });\n }\n }\n if (f.match.sequenceIndex !== undefined) {\n if (\n typeof f.match.sequenceIndex !== \"number\" ||\n f.match.sequenceIndex < 0 ||\n !Number.isInteger(f.match.sequenceIndex)\n ) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"match.sequenceIndex must be a non-negative integer\",\n });\n }\n }\n if (f.match.hasToolResult !== undefined && typeof f.match.hasToolResult !== \"boolean\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.hasToolResult must be a boolean, got ${typeof f.match.hasToolResult}`,\n });\n }\n if (f.match.toolResultContains !== undefined) {\n if (typeof f.match.toolResultContains !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.toolResultContains must be a string, got ${typeof f.match.toolResultContains}`,\n });\n } else if (f.match.toolResultContains.length === 0) {\n // An empty substring is always contained, so the gate would silently\n // act as \"last message is any tool result\" — reject it as an authoring\n // mistake rather than let it shadow later fixtures.\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: \"match.toolResultContains must be a non-empty string\",\n });\n }\n }\n if (f.match.systemMessage !== undefined) {\n const sm = f.match.systemMessage;\n if (typeof sm === \"string\") {\n // ok\n } else if (Array.isArray(sm)) {\n if (sm.length === 0) {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.systemMessage array must contain at least one substring`,\n });\n } else {\n for (let j = 0; j < sm.length; j++) {\n if (typeof sm[j] !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.systemMessage[${j}] must be a string, got ${typeof sm[j]}`,\n });\n }\n }\n }\n } else {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.systemMessage must be a string or string[], got ${typeof sm}`,\n });\n }\n }\n if (f.match.context !== undefined && typeof f.match.context !== \"string\") {\n results.push({\n severity: \"error\",\n fixtureIndex: i,\n message: `match.context must be a string, got ${typeof f.match.context}`,\n });\n }\n\n // --- Warning checks ---\n\n // Duplicate userMessage shadowing — two fixtures are only genuine\n // duplicates when they would match the SAME requests, so the dedup key must\n // include EVERY match discriminator the router (matchFixtureDiagnostic in\n // router.ts) actually gates on: userMessage, systemMessage, inputText,\n // toolCallId, toolResultContains, toolName, model, responseFormat, endpoint,\n // context, sequenceIndex, turnIndex, and hasToolResult. Omitting any of these\n // (the old key only carried turnIndex/hasToolResult/toolResultContains/\n // sequenceIndex/context) flags two legitimately-distinct fixtures — e.g. two\n // that differ ONLY in toolCallId or model — as false duplicates.\n //\n // `predicate` is a function and cannot be compared for equivalence, so it is\n // never folded into a shared key: a fixture carrying a predicate is treated\n // as unconditionally distinct (keyed by its own index) so it neither shadows\n // nor is shadowed by another fixture on the userMessage axis.\n //\n // Values are serialised kind-aware so RegExp / string[] matchers do not\n // collide (a template literal would coerce a RegExp to its source and an\n // array via join, losing the distinction) — mirroring describeMatch in\n // router.ts.\n const um = f.match.userMessage;\n if (typeof um === \"string\" && um) {\n const m = f.match;\n const dedupKey =\n m.predicate !== undefined\n ? `predicate:${i}`\n : [\n serializeMatcher(m.userMessage),\n serializeMatcher(m.systemMessage),\n serializeMatcher(m.inputText),\n m.toolCallId,\n m.toolResultContains,\n m.toolName,\n serializeMatcher(m.model),\n m.responseFormat,\n m.endpoint,\n m.context,\n m.sequenceIndex,\n m.turnIndex,\n m.hasToolResult,\n ]\n .map((v) => (v === undefined ? \"\" : String(v)))\n .join(\"|\");\n const prev = seenUserMessages.get(dedupKey);\n if (prev !== undefined) {\n const ref: ValidationRef = {\n rule: \"duplicate-user-message\",\n userMessage: um,\n shadows: prev,\n };\n results.push({\n severity: \"warning\",\n fixtureIndex: i,\n message: renderValidationRef(ref, String),\n ref,\n });\n } else {\n seenUserMessages.set(dedupKey, i);\n }\n }\n\n // Catch-all not in last position\n const match = f.match;\n const hasDiscriminator =\n match.endpoint !== undefined ||\n match.context !== undefined ||\n match.userMessage !== undefined ||\n match.systemMessage !== undefined ||\n match.inputText !== undefined ||\n match.responseFormat !== undefined ||\n match.toolCallId !== undefined ||\n match.toolResultContains !== undefined ||\n match.toolName !== undefined ||\n match.model !== undefined ||\n match.predicate !== undefined ||\n match.turnIndex !== undefined ||\n match.sequenceIndex !== undefined ||\n match.hasToolResult !== undefined;\n\n if (!hasDiscriminator && i < fixtures.length - 1) {\n const ref: ValidationRef = {\n rule: \"catch-all-not-last\",\n shadowsFrom: i + 1,\n shadowsThrough: fixtures.length - 1,\n };\n results.push({\n severity: \"warning\",\n fixtureIndex: i,\n message: renderValidationRef(ref, String),\n ref,\n });\n }\n }\n\n return results;\n}\n\n// ---------------------------------------------------------------------------\n// FixtureLoadError — the error type for fail-loud fixture-load cases\n// ---------------------------------------------------------------------------\n\n/**\n * The `rule` values owned by MCP fakes (prefix `mcp-fakes/`). The\n * bad-block letters: (a) no scope, (b)\n * malformed scope, (c) shared + deny, (d) bad call entry, (e) duplicate tool,\n * (f) entry-id or block-id collision, (g) bad block/tool shape, (h) unknown\n * key on a block, tool or call entry, (i) mcpFakes, or one of its blocks, has\n * the wrong JSON type, mcpFakes holds no blocks, or an add has an invalid\n * origin or source item, (j) anyArgs not `true`.\n */\nexport const MCP_FAKES_LOAD_RULES = [\n \"mcp-fakes/bad-block:a\",\n \"mcp-fakes/bad-block:b\",\n \"mcp-fakes/bad-block:c\",\n \"mcp-fakes/bad-block:d\",\n \"mcp-fakes/bad-block:e\",\n \"mcp-fakes/bad-block:f\",\n \"mcp-fakes/bad-block:g\",\n \"mcp-fakes/bad-block:h\",\n \"mcp-fakes/bad-block:i\",\n \"mcp-fakes/bad-block:j\",\n \"mcp-fakes/mount-conflict\",\n \"mcp-fakes/loader-cannot-carry-fakes\",\n \"mcp-fakes/watch-reload-changed\",\n] as const;\n\nexport type McpFakesLoadRule = (typeof MCP_FAKES_LOAD_RULES)[number];\n\n/**\n * Every known `FixtureLoadError` rule, by prefix. A feature that throws\n * `FixtureLoadError` adds its own prefix here, with its rule values as a\n * union of string literals; a module can add one by declaration merging.\n */\nexport interface FixtureLoadRuleRegistry {\n \"mcp-fakes\": McpFakesLoadRule;\n}\n\n/**\n * A known `FixtureLoadError` rule, namespaced `<prefix>/<name>`. Each\n * registered value must start with its own prefix and `/` (any other value\n * drops out of the union), so a misspelled or unregistered rule fails to\n * compile.\n */\nexport type FixtureLoadRule = {\n [P in keyof FixtureLoadRuleRegistry]: FixtureLoadRuleRegistry[P] & `${P}/${string}`;\n}[keyof FixtureLoadRuleRegistry];\n\nexport interface FixtureLoadErrorInit {\n /** Namespaced `<prefix>/<name>`, one of {@link FixtureLoadRuleRegistry}. */\n rule: FixtureLoadRule;\n /** Source of the offending input (path, URL, `control-api#<n>`, `code#<n>`), or null. */\n file: string | null;\n /** `<source><load>[<block>]` of the offending block; omit or null when not tied to a block. */\n blockId?: string | null;\n /**\n * Entry id when one entry caused it (bad-block cases d, f, j, and h on a\n * call entry); omit or null otherwise.\n */\n entryId?: string | null;\n /**\n * The offending key or value, in words: text, or a `Message` from the\n * message builder (message-text.ts), whose user parts are quoted and cut\n * once. Cut to `MCP_FAKES_ECHO_LIMIT` chars in the message (see `capPart`).\n */\n detail: string | Message;\n}\n\nexport interface FixtureLoadErrorJSON {\n /** `\"FixtureLoadError\"`, or a subclass's own name (e.g. `\"McpFakesAddError\"`). */\n name: string;\n rule: string;\n file: string | null;\n blockId?: string | null;\n entryId?: string | null;\n message: string;\n}\n\n/**\n * `text` with every run of line breaks, and the spaces around it, folded to\n * one space: CR, LF, VT, FF, NEL, and the Unicode line and paragraph\n * separators.\n */\nfunction oneLine(text: string): string {\n return text.replace(/\\s*[\\r\\n\\v\\f\\u0085\\u2028\\u2029]+\\s*/g, \" \");\n}\n\n/**\n * The `detail` as a `FixtureLoadError` message adds it: built in a budget of\n * its own, cut to at most `MCP_FAKES_ECHO_LIMIT` chars in all, with each of\n * its user parts cut once. A text detail is folded onto one line, gets the\n * escaping of every JSON text part (`jsonText`: each control char left, C0,\n * DEL or C1, and the line and paragraph separators as `\\uXXXX`) and is cut\n * as JSON text (it is\n * made of fixed text, paths and quoted values, where a backslash only starts\n * a JSON escape; a stray one only moves the cut back a few chars).\n */\nfunction capPart(detail: string | Message): Message {\n const message = typeof detail === \"string\" ? msg`${jsonText(oneLine(detail))}` : detail;\n return within(MCP_FAKES_ECHO_LIMIT, message);\n}\n\n/**\n * One `file`, `blockId` or `entryId` as the message names it: JSON-quoted\n * (control chars escaped, so a name can neither break the line nor pose as\n * the message layout), and cut once to `MCP_FAKES_ECHO_LIMIT` chars at most.\n * An empty string is `\"\"`, so the message names every part `toJSON()` keeps.\n */\nfunction namePart(text: string): Message {\n return msg`${quote(text)}`;\n}\n\n/**\n * Thrown for a fixture-load case aimock cannot honor (fail-loud rule). Only\n * the MCP fakes code throws it; other fixture-loader paths log warnings.\n * `blockId` and `entryId` are own properties only when supplied, so\n * `toJSON()` (the control API's HTTP 400 `details`) omits them otherwise.\n * The message names `file` and every non-null `blockId` and `entryId`, an\n * empty string as `\"\"`, so it agrees with `toJSON()`. `options.cause` (the\n * standard `ErrorOptions`) keeps the underlying error, such as a JSON parse\n * failure; `toJSON()` leaves it out.\n */\nexport class FixtureLoadError extends Error {\n /** Typed `string` so a subclass can set its own name. */\n override readonly name: string = \"FixtureLoadError\";\n readonly rule: FixtureLoadRule;\n readonly file: string | null;\n declare readonly blockId?: string | null;\n declare readonly entryId?: string | null;\n\n constructor(init: FixtureLoadErrorInit, options?: ErrorOptions) {\n const file = init.file === null ? msg`<no file>` : namePart(init.file);\n const block = init.blockId == null ? msg`` : msg`, block ${namePart(init.blockId)}`;\n const entry = init.entryId == null ? msg`` : msg`, entry ${namePart(init.entryId)}`;\n super(\n oneLine(build(msg`${file}${block}${entry}: [${fixed(init.rule)}] ${capPart(init.detail)}`)),\n options,\n );\n this.rule = init.rule;\n this.file = init.file;\n if (init.blockId !== undefined) {\n Object.defineProperty(this, \"blockId\", {\n value: init.blockId,\n enumerable: true,\n writable: false,\n });\n }\n if (init.entryId !== undefined) {\n Object.defineProperty(this, \"entryId\", {\n value: init.entryId,\n enumerable: true,\n writable: false,\n });\n }\n }\n\n toJSON(): FixtureLoadErrorJSON {\n const json: FixtureLoadErrorJSON = {\n name: this.name,\n rule: this.rule,\n file: this.file,\n message: this.message,\n };\n if (this.blockId !== undefined) json.blockId = this.blockId;\n if (this.entryId !== undefined) json.entryId = this.entryId;\n return json;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAsCA,SAAgB,kBACd,KACA,aACiB;AACjB,KAAIA,+BAAe,IAAI,CAAE,QAAOC,0CAAqB,KAAK,YAAY;CAEtE,MAAM,WAAW,EAAE,GAAG,KAAK;AAG3B,KAAI,OAAO,SAAS,YAAY,YAAY,SAAS,YAAY,KAC/D,UAAS,UAAU,KAAK,UAAU,SAAS,QAAQ;AAIrD,KAAI,MAAM,QAAQ,SAAS,UAAU,CACnC,UAAS,YAAa,SAAS,UAA6C,KAAK,OAAO;AACtF,MAAI,OAAO,GAAG,cAAc,YAAY,GAAG,cAAc,KACvD,QAAO;GAAE,GAAG;GAAI,WAAW,KAAK,UAAU,GAAG,UAAU;GAAE;AAE3D,SAAO;GACP;AAQJ,KAAI,MAAM,QAAQ,SAAS,OAAO,CAChC,UAAS,SAAU,SAAS,OAA0C,KAAK,UAAU;AACnF,MACE,SAAS,QACT,MAAM,SAAS,cACf,OAAO,MAAM,cAAc,YAC3B,MAAM,cAAc,KAEpB,QAAO;GAAE,GAAG;GAAO,WAAW,KAAK,UAAU,MAAM,UAAU;GAAE;AAEjE,SAAO;GACP;AAGJ,QAAO;;AAGT,IAAM,2BAAN,cAAuC,UAAU;AAEjD,SAAgB,eACd,OACA,QACA,aACS;AACT,KAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,MAAM,CACrE,OAAM,IAAI,UAAU,kCAAkC;AAExD,KAAI,MAAM,SAAS,KACjB,OAAM,IAAI,UAAU,kCAAkC;AAExD,KAAI,OAAO,MAAM,UAAU,YAAY,MAAM,QAAQ,MAAM,MAAM,CAC/D,OAAM,IAAI,yBAAyB,kCAAkC;CAEvE,MAAM,UAAmB;EACvB,OAAO;GACL,aAAa,MAAM,MAAM;GACzB,eAAe,MAAM,MAAM;GAC3B,WAAW,MAAM,MAAM;GACvB,YAAY,M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BAAb,cAAsC,MAAM;;CAE1C,AAAkB,OAAe;CACjC,AAAS;CACT,AAAS;CAIT,YAAY,MAA4B,SAAwB;EAC9D,MAAM,OAAO,KAAK,SAAS,OAAO,wBAAG,cAAc,SAAS,KAAK,KAAK;EACtE,MAAM,QAAQ,KAAK,WAAW,OAAO,wBAAG,KAAK,wBAAG,WAAW,SAAS,KAAK,QAAQ;EACjF,MAAM,QAAQ,KAAK,WAAW,OAAO,wBAAG,KAAK,wBAAG,WAAW,SAAS,KAAK,QAAQ;AACjF,QACE,QAAQC,2BAAM,wBAAG,GAAG,OAAO,QAAQ,MAAM,KAAKC,2BAAM,KAAK,KAAK,CAAC,IAAI,QAAQ,KAAK,OAAO,GAAG,CAAC,EAC3F,QACD;AACD,OAAK,OAAO,KAAK;AACjB,OAAK,OAAO,KAAK;AACjB,MAAI,KAAK,YAAY,OACnB,QAAO,eAAe,MAAM,WAAW;GACrC,OAAO,KAAK;GACZ,YAAY;GACZ,UAAU;GACX,CAAC;AAEJ,MAAI,KAAK,YAAY,OACnB,QAAO,eAAe,MAAM,WAAW;GACrC,OAAO,KAAK;GACZ,YAAY;GACZ,UAAU;GACX,CAAC;;CAIN,SAA+B;EAC7B,MAAM,OAA6B;GACjC,MAAM,KAAK;GACX,MAAM,KAAK;GACX,MAAM,KAAK;GACX,SAAS,KAAK;GACf;AACD,MAAI,KAAK,YAAY,OAAW,MAAK,UAAU,KAAK;AACpD,MAAI,KAAK,YAAY,OAAW,MAAK,UAAU,KAAK;AACpD,SAAO"}
@@ -1,4 +1,6 @@
1
+ import { LiveOptions } from "./live-types.cjs";
1
2
  import { Logger } from "./logger.cjs";
3
+ import { Message } from "./message-text.cjs";
2
4
  import { Fixture, FixtureFileResponse, FixtureResponse } from "./types.cjs";
3
5
 
4
6
  //#region src/fixture-loader.d.ts
@@ -10,14 +12,64 @@ import { Fixture, FixtureFileResponse, FixtureResponse } from "./types.cjs";
10
12
  * `fallthrough` OpenRouter-failover flag) pass through unmodified via the
11
13
  * shallow clone below.
12
14
  */
13
- declare function normalizeResponse(raw: FixtureFileResponse): FixtureResponse;
14
- declare function loadFixtureFile(filePath: string, logger?: Logger): Fixture[];
15
- declare function loadFixturesFromDir(dirPath: string, logger?: Logger): Fixture[];
15
+ declare function normalizeResponse(raw: FixtureFileResponse, liveOptions?: LiveOptions): FixtureResponse;
16
+ /**
17
+ * Load the LLM fixtures of one file. Throws a `FixtureLoadError` (rule
18
+ * `mcp-fakes/loader-cannot-carry-fakes`) when the file has a top-level
19
+ * `mcpFakes` key; use `loadFixtureFileWithServices` (fixture-loader-services.ts) for such files.
20
+ */
21
+ declare function loadFixtureFile(filePath: string, logger?: Logger, liveOptions?: LiveOptions): Fixture[];
22
+ /**
23
+ * The `.json` files (sorted) and the subdirectories (sorted) of `dirPath`,
24
+ * or `null` when it cannot be read (warned).
25
+ *
26
+ * @internal Shared with fixture-loader-services.ts.
27
+ */
28
+
29
+ /**
30
+ * Load the LLM fixtures of every `.json` file under `dirPath`. Throws a
31
+ * `FixtureLoadError` (rule `mcp-fakes/loader-cannot-carry-fakes`) on the
32
+ * first file with a top-level `mcpFakes` key; use
33
+ * `loadFixturesFromDirWithServices` (fixture-loader-services.ts) for such
34
+ * directories.
35
+ */
36
+ declare function loadFixturesFromDir(dirPath: string, logger?: Logger, liveOptions?: LiveOptions): Fixture[];
37
+ /**
38
+ * The fixture indices a finding's message NAMES, carried as data.
39
+ *
40
+ * Two rules (`duplicate userMessage` and the catch-all ordering check) name
41
+ * OTHER fixtures in the array they were given, so their message text embeds an
42
+ * index. A consumer that validates a different array than the one the reader
43
+ * sees — `aimock validate` runs the rules per file and then over the union of
44
+ * every file — has to renumber those indices, and the only safe way to do that
45
+ * is to re-render from the numbers rather than to rewrite the rendered prose:
46
+ * `duplicate userMessage` interpolates the fixture's OWN `userMessage`, so a
47
+ * regex over the message corrupts user-authored text that happens to read
48
+ * "fixture 3".
49
+ */
50
+ type ValidationRef = {
51
+ rule: "duplicate-user-message";
52
+ userMessage: string;
53
+ shadows: number;
54
+ } | {
55
+ rule: "catch-all-not-last";
56
+ shadowsFrom: number;
57
+ shadowsThrough: number;
58
+ };
16
59
  interface ValidationResult {
17
60
  severity: "error" | "warning";
18
61
  fixtureIndex: number;
19
62
  message: string;
63
+ /** Present only on the rules whose message names other fixtures. */
64
+ ref?: ValidationRef;
20
65
  }
66
+ /**
67
+ * Render a ref-carrying finding's message with each named index passed through
68
+ * `renderIndex`. With `String` it reproduces the message `validateFixtures`
69
+ * itself emits; `aimock validate` passes a renderer that resolves a union
70
+ * index to `<file> #<index-in-that-file>`.
71
+ */
72
+ declare function renderValidationRef(ref: ValidationRef, renderIndex: (fixtureIndex: number) => string): string;
21
73
  /**
22
74
  * Human-readable form of the status range an injected error may carry.
23
75
  * Measured on Node v26: `res.writeHead` throws outside 100-999 (the injected
@@ -27,8 +79,82 @@ interface ValidationResult {
27
79
  * client sees it — so a mock server allows it.
28
80
  */
29
81
 
30
- declare function validateFixtures(fixtures: Fixture[]): ValidationResult[];
82
+ declare function validateFixtures(fixtures: Fixture[], liveOptions?: LiveOptions): ValidationResult[];
83
+ /**
84
+ * The `rule` values owned by MCP fakes (prefix `mcp-fakes/`). The
85
+ * bad-block letters: (a) no scope, (b)
86
+ * malformed scope, (c) shared + deny, (d) bad call entry, (e) duplicate tool,
87
+ * (f) entry-id or block-id collision, (g) bad block/tool shape, (h) unknown
88
+ * key on a block, tool or call entry, (i) mcpFakes, or one of its blocks, has
89
+ * the wrong JSON type, mcpFakes holds no blocks, or an add has an invalid
90
+ * origin or source item, (j) anyArgs not `true`.
91
+ */
92
+ declare const MCP_FAKES_LOAD_RULES: readonly ["mcp-fakes/bad-block:a", "mcp-fakes/bad-block:b", "mcp-fakes/bad-block:c", "mcp-fakes/bad-block:d", "mcp-fakes/bad-block:e", "mcp-fakes/bad-block:f", "mcp-fakes/bad-block:g", "mcp-fakes/bad-block:h", "mcp-fakes/bad-block:i", "mcp-fakes/bad-block:j", "mcp-fakes/mount-conflict", "mcp-fakes/loader-cannot-carry-fakes", "mcp-fakes/watch-reload-changed"];
93
+ type McpFakesLoadRule = (typeof MCP_FAKES_LOAD_RULES)[number];
94
+ /**
95
+ * Every known `FixtureLoadError` rule, by prefix. A feature that throws
96
+ * `FixtureLoadError` adds its own prefix here, with its rule values as a
97
+ * union of string literals; a module can add one by declaration merging.
98
+ */
99
+ interface FixtureLoadRuleRegistry {
100
+ "mcp-fakes": McpFakesLoadRule;
101
+ }
102
+ /**
103
+ * A known `FixtureLoadError` rule, namespaced `<prefix>/<name>`. Each
104
+ * registered value must start with its own prefix and `/` (any other value
105
+ * drops out of the union), so a misspelled or unregistered rule fails to
106
+ * compile.
107
+ */
108
+ type FixtureLoadRule = { [P in keyof FixtureLoadRuleRegistry]: FixtureLoadRuleRegistry[P] & `${P}/${string}` }[keyof FixtureLoadRuleRegistry];
109
+ interface FixtureLoadErrorInit {
110
+ /** Namespaced `<prefix>/<name>`, one of {@link FixtureLoadRuleRegistry}. */
111
+ rule: FixtureLoadRule;
112
+ /** Source of the offending input (path, URL, `control-api#<n>`, `code#<n>`), or null. */
113
+ file: string | null;
114
+ /** `<source><load>[<block>]` of the offending block; omit or null when not tied to a block. */
115
+ blockId?: string | null;
116
+ /**
117
+ * Entry id when one entry caused it (bad-block cases d, f, j, and h on a
118
+ * call entry); omit or null otherwise.
119
+ */
120
+ entryId?: string | null;
121
+ /**
122
+ * The offending key or value, in words: text, or a `Message` from the
123
+ * message builder (message-text.ts), whose user parts are quoted and cut
124
+ * once. Cut to `MCP_FAKES_ECHO_LIMIT` chars in the message (see `capPart`).
125
+ */
126
+ detail: string | Message;
127
+ }
128
+ interface FixtureLoadErrorJSON {
129
+ /** `"FixtureLoadError"`, or a subclass's own name (e.g. `"McpFakesAddError"`). */
130
+ name: string;
131
+ rule: string;
132
+ file: string | null;
133
+ blockId?: string | null;
134
+ entryId?: string | null;
135
+ message: string;
136
+ }
137
+ /**
138
+ * Thrown for a fixture-load case aimock cannot honor (fail-loud rule). Only
139
+ * the MCP fakes code throws it; other fixture-loader paths log warnings.
140
+ * `blockId` and `entryId` are own properties only when supplied, so
141
+ * `toJSON()` (the control API's HTTP 400 `details`) omits them otherwise.
142
+ * The message names `file` and every non-null `blockId` and `entryId`, an
143
+ * empty string as `""`, so it agrees with `toJSON()`. `options.cause` (the
144
+ * standard `ErrorOptions`) keeps the underlying error, such as a JSON parse
145
+ * failure; `toJSON()` leaves it out.
146
+ */
147
+ declare class FixtureLoadError extends Error {
148
+ /** Typed `string` so a subclass can set its own name. */
149
+ readonly name: string;
150
+ readonly rule: FixtureLoadRule;
151
+ readonly file: string | null;
152
+ readonly blockId?: string | null;
153
+ readonly entryId?: string | null;
154
+ constructor(init: FixtureLoadErrorInit, options?: ErrorOptions);
155
+ toJSON(): FixtureLoadErrorJSON;
156
+ }
31
157
  //# sourceMappingURL=fixture-loader.d.ts.map
32
158
  //#endregion
33
- export { ValidationResult, loadFixtureFile, loadFixturesFromDir, normalizeResponse, validateFixtures };
159
+ export { FixtureLoadError, FixtureLoadErrorJSON, ValidationRef, ValidationResult, loadFixtureFile, loadFixturesFromDir, normalizeResponse, renderValidationRef, validateFixtures };
34
160
  //# sourceMappingURL=fixture-loader.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fixture-loader.d.cts","names":[],"sources":["../src/fixture-loader.ts"],"sourcesContent":[],"mappings":";;;;;;;AA+BA;;;;;AA0HgB,iBA1HA,iBAAA,CA0He,GAAA,EA1HQ,mBA0HR,CAAA,EA1H8B,eA0H9B;AAA4B,iBAA3C,eAAA,CAA2C,QAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EAAA,MAAA,CAAA,EAAS,OAAT,EAAA;AAAS,iBA6BpD,mBAAA,CA7BoD,OAAA,EAAA,MAAA,EAAA,MAAA,CAAA,EA6BN,MA7BM,CAAA,EA6BG,OA7BH,EAAA;AAAO,UAgF1D,gBAAA,CAhF0D;EA6B3D,QAAA,EAAA,OAAA,GAAA,SAAmB;EAAA,YA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