spine-framework 0.4.3 → 0.5.0-rc.4

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 (320) hide show
  1. package/.env.example +13 -3
  2. package/.framework/cli/commands/bootstrap.ts +392 -0
  3. package/.framework/cli/commands/dev.ts +91 -218
  4. package/.framework/cli/commands/doctor.ts +132 -26
  5. package/.framework/cli/commands/generate.ts +38 -298
  6. package/.framework/cli/commands/init.ts +20 -1
  7. package/.framework/cli/commands/migrate.ts +36 -30
  8. package/.framework/cli/commands/migrations.ts +16 -56
  9. package/.framework/cli/commands/upgrade.ts +35 -0
  10. package/.framework/cli/commands/validate-schema.ts +147 -0
  11. package/.framework/cli/context.ts +223 -110
  12. package/.framework/cli/index.ts +6 -0
  13. package/.framework/cli/lib/project-files.ts +241 -1
  14. package/.framework/functions/_shared/agent-runner.ts +1000 -81
  15. package/.framework/functions/_shared/cil.ts +2 -1
  16. package/.framework/functions/_shared/db.ts +3 -6
  17. package/.framework/functions/_shared/hash-api-key.ts +183 -79
  18. package/.framework/functions/_shared/kb.ts +61 -7
  19. package/.framework/functions/_shared/logging.ts +562 -224
  20. package/.framework/functions/_shared/message-sequence.ts +53 -0
  21. package/.framework/functions/_shared/middleware.ts +47 -44
  22. package/.framework/functions/_shared/pipeline-runner.ts +150 -37
  23. package/.framework/functions/_shared/principal.ts +9 -6
  24. package/.framework/functions/_shared/trigger-engine.ts +149 -40
  25. package/.framework/functions/admin-data.ts +48 -31
  26. package/.framework/functions/ai-agents.ts +103 -33
  27. package/.framework/functions/api-keys.ts +301 -122
  28. package/.framework/functions/apps.ts +43 -26
  29. package/.framework/functions/cil-ingest.ts +48 -15
  30. package/.framework/functions/debug-auth.ts +14 -8
  31. package/.framework/functions/deliveries.ts +39 -12
  32. package/.framework/functions/embeddings.ts +145 -76
  33. package/.framework/functions/integration-outbound.ts +67 -27
  34. package/.framework/functions/integrations.ts +254 -127
  35. package/.framework/functions/logs.ts +273 -133
  36. package/.framework/functions/observability.ts +277 -147
  37. package/.framework/functions/pipeline-executions.ts +1 -1
  38. package/.framework/functions/pipeline-runner-background.ts +120 -0
  39. package/.framework/functions/pipelines.ts +14 -9
  40. package/.framework/functions/prompt-configs.ts +7 -4
  41. package/.framework/functions/roles.ts +8 -5
  42. package/.framework/functions/security.ts +30 -17
  43. package/.framework/functions/system-cron.ts +250 -128
  44. package/.framework/functions/tests.ts +7 -6
  45. package/.framework/functions/timers.ts +310 -107
  46. package/.framework/functions/trigger-scheduler.ts +65 -5
  47. package/.framework/functions/triggers.ts +28 -13
  48. package/.framework/functions/types.ts +13 -10
  49. package/.framework/migrations/064_episode_leases.sql +196 -0
  50. package/.framework/migrations/065_execution_tables_updated_at.sql +20 -0
  51. package/.framework/migrations/066_episode_steal_thread_merge.sql +148 -0
  52. package/.framework/migrations/067_episode_lease_stale_steal.sql +93 -0
  53. package/.framework/migrations/068_cron_schedule_timer_rpcs.sql +251 -0
  54. package/.framework/migrations/069_log_stats_window.sql +54 -0
  55. package/.framework/migrations/070_app_type_schema_rpcs.sql +166 -0
  56. package/.framework/migrations/071_timer_interval_keys.sql +96 -0
  57. package/.framework/migrations/072_slug_autofill.sql +77 -0
  58. package/.framework/migrations/073_seed_member_roles.sql +26 -0
  59. package/.framework/schemas/spine.config.schema.json +62 -0
  60. package/.framework/src/App.tsx +3 -1
  61. package/.framework/src/apps/admin/index.tsx +1141 -775
  62. package/.framework/src/components/ErrorBoundary.tsx +136 -0
  63. package/.framework/src/components/admin/AdminListPage.tsx +81 -73
  64. package/.framework/src/components/admin/AdminSidebar.tsx +92 -81
  65. package/.framework/src/components/admin/EntitySelect.tsx +181 -0
  66. package/.framework/src/components/admin/PageInstructions.tsx +86 -127
  67. package/.framework/src/components/app-shell/GenericAppShell.tsx +3 -1
  68. package/.framework/src/components/app-shell/GenericDetailPage.tsx +37 -13
  69. package/.framework/src/components/app-shell/GenericListPage.tsx +28 -32
  70. package/.framework/src/components/auth/TurnstileWidget.tsx +9 -6
  71. package/.framework/src/components/kb/KBArticleEditor.tsx +49 -6
  72. package/.framework/src/components/layout/Layout.tsx +4 -2
  73. package/.framework/src/components/layout/Sidebar.tsx +304 -179
  74. package/.framework/src/components/runtime/DataDetailPage.tsx +67 -35
  75. package/.framework/src/components/runtime/DataHeader.tsx +96 -48
  76. package/.framework/src/components/runtime/DataListPage.tsx +3 -26
  77. package/.framework/src/components/runtime/DataStats.tsx +10 -10
  78. package/.framework/src/components/runtime/DataTable.tsx +12 -10
  79. package/.framework/src/components/ui/sheet.tsx +24 -26
  80. package/.framework/src/components/ui/textarea.tsx +74 -48
  81. package/.framework/src/hooks/useBranding.ts +47 -0
  82. package/.framework/src/hooks/useEntityList.ts +12 -9
  83. package/.framework/src/hooks/useListSchema.ts +108 -58
  84. package/.framework/src/instructions/README.md +57 -0
  85. package/.framework/src/instructions/ai-agents.md +69 -0
  86. package/.framework/src/instructions/alerts.md +80 -0
  87. package/.framework/src/instructions/api-keys.md +87 -0
  88. package/.framework/src/instructions/apps.md +77 -0
  89. package/.framework/src/instructions/concepts/ai-and-prompts.md +150 -0
  90. package/.framework/src/instructions/concepts/apps-and-renderers.md +162 -0
  91. package/.framework/src/instructions/concepts/auth-and-api-keys.md +133 -0
  92. package/.framework/src/instructions/concepts/automation.md +186 -0
  93. package/.framework/src/instructions/concepts/concurrency-and-idempotency.md +125 -0
  94. package/.framework/src/instructions/concepts/core-vs-custom.md +124 -0
  95. package/.framework/src/instructions/concepts/design-schema.md +152 -0
  96. package/.framework/src/instructions/concepts/integrations-and-webhooks.md +127 -0
  97. package/.framework/src/instructions/concepts/observability.md +116 -0
  98. package/.framework/src/instructions/concepts/permissions.md +150 -0
  99. package/.framework/src/instructions/concepts/runtime-records.md +111 -0
  100. package/.framework/src/instructions/concepts/scope-and-accounts.md +112 -0
  101. package/.framework/src/instructions/concepts/spine-way.md +172 -0
  102. package/.framework/src/instructions/deliveries.md +59 -0
  103. package/.framework/src/instructions/guide/00-orientation.md +106 -0
  104. package/.framework/src/instructions/guide/01-install-and-first-run.md +253 -0
  105. package/.framework/src/instructions/guide/02-project-map.md +147 -0
  106. package/.framework/src/instructions/guide/03-domain-model.md +223 -0
  107. package/.framework/src/instructions/guide/04-first-app.md +227 -0
  108. package/.framework/src/instructions/guide/05-glossary.md +183 -0
  109. package/.framework/src/instructions/integrations.md +96 -0
  110. package/.framework/src/instructions/internal/cil-markers.md +83 -0
  111. package/.framework/src/instructions/invites.md +60 -0
  112. package/.framework/src/instructions/kb.md +80 -0
  113. package/.framework/src/instructions/logs.md +77 -0
  114. package/.framework/src/instructions/observability.md +61 -0
  115. package/.framework/src/instructions/operations/deployment.md +115 -0
  116. package/.framework/src/instructions/operations/migrations.md +125 -0
  117. package/.framework/src/instructions/operations/security-checklist.md +148 -0
  118. package/.framework/src/instructions/operations/troubleshooting.md +170 -0
  119. package/.framework/src/instructions/operations/upgrade.md +116 -0
  120. package/.framework/src/instructions/pipeline-executions.md +62 -0
  121. package/.framework/src/instructions/pipelines.md +78 -0
  122. package/.framework/src/instructions/prompts.md +95 -0
  123. package/.framework/src/instructions/reference/api/admin-data.md +162 -0
  124. package/.framework/src/instructions/reference/api/auth.md +113 -0
  125. package/.framework/src/instructions/reference/api/errors-and-envelopes.md +113 -0
  126. package/.framework/src/instructions/reference/app-manifest.md +150 -0
  127. package/.framework/src/instructions/reference/cli.md +124 -0
  128. package/.framework/src/instructions/reference/database.md +132 -0
  129. package/.framework/src/instructions/reference/design-schema.md +280 -0
  130. package/.framework/src/instructions/reference/env-vars.md +133 -0
  131. package/.framework/src/instructions/reference/functions/account-nodes.md +75 -0
  132. package/.framework/src/instructions/reference/functions/admin-data.md +195 -0
  133. package/.framework/src/instructions/reference/functions/admin-funnel.md +90 -0
  134. package/.framework/src/instructions/reference/functions/admin-install-funnel.md +107 -0
  135. package/.framework/src/instructions/reference/functions/admin-signals.md +102 -0
  136. package/.framework/src/instructions/reference/functions/ai-agents.md +148 -0
  137. package/.framework/src/instructions/reference/functions/ai-interactions.md +156 -0
  138. package/.framework/src/instructions/reference/functions/api-keys.md +130 -0
  139. package/.framework/src/instructions/reference/functions/apps.md +140 -0
  140. package/.framework/src/instructions/reference/functions/auth.md +99 -0
  141. package/.framework/src/instructions/reference/functions/debug-auth.md +91 -0
  142. package/.framework/src/instructions/reference/functions/deliveries.md +110 -0
  143. package/.framework/src/instructions/reference/functions/embeddings.md +166 -0
  144. package/.framework/src/instructions/reference/functions/eval-harness.md +149 -0
  145. package/.framework/src/instructions/reference/functions/index.md +103 -0
  146. package/.framework/src/instructions/reference/functions/integration-outbound.md +200 -0
  147. package/.framework/src/instructions/reference/functions/integration-routes.md +151 -0
  148. package/.framework/src/instructions/reference/functions/integrations.md +130 -0
  149. package/.framework/src/instructions/reference/functions/invites.md +182 -0
  150. package/.framework/src/instructions/reference/functions/item-progress.md +107 -0
  151. package/.framework/src/instructions/reference/functions/kb.md +166 -0
  152. package/.framework/src/instructions/reference/functions/logs.md +141 -0
  153. package/.framework/src/instructions/reference/functions/observability.md +105 -0
  154. package/.framework/src/instructions/reference/functions/pipeline-executions.md +132 -0
  155. package/.framework/src/instructions/reference/functions/pipeline-runner-background.md +121 -0
  156. package/.framework/src/instructions/reference/functions/pipelines.md +136 -0
  157. package/.framework/src/instructions/reference/functions/prompt-configs.md +121 -0
  158. package/.framework/src/instructions/reference/functions/roles.md +121 -0
  159. package/.framework/src/instructions/reference/functions/security.md +140 -0
  160. package/.framework/src/instructions/reference/functions/system-cron.md +136 -0
  161. package/.framework/src/instructions/reference/functions/system.md +106 -0
  162. package/.framework/src/instructions/reference/functions/tests.md +97 -0
  163. package/.framework/src/instructions/reference/functions/timers.md +117 -0
  164. package/.framework/src/instructions/reference/functions/trigger-scheduler.md +102 -0
  165. package/.framework/src/instructions/reference/functions/triggers.md +140 -0
  166. package/.framework/src/instructions/reference/functions/types.md +146 -0
  167. package/.framework/src/instructions/reference/seeds.md +126 -0
  168. package/.framework/src/instructions/reference/shared-modules.md +127 -0
  169. package/.framework/src/instructions/reference/spine-config.md +114 -0
  170. package/.framework/src/instructions/roles.md +80 -0
  171. package/.framework/src/instructions/runtime-detail.md +70 -0
  172. package/.framework/src/instructions/runtime-list.md +77 -0
  173. package/.framework/src/instructions/security.md +67 -0
  174. package/.framework/src/instructions/tasks/add-a-pipeline.md +110 -0
  175. package/.framework/src/instructions/tasks/add-a-role.md +96 -0
  176. package/.framework/src/instructions/tasks/add-a-timer.md +114 -0
  177. package/.framework/src/instructions/tasks/add-a-trigger.md +106 -0
  178. package/.framework/src/instructions/tasks/add-a-type.md +151 -0
  179. package/.framework/src/instructions/tasks/add-a-webhook.md +108 -0
  180. package/.framework/src/instructions/tasks/add-an-ai-agent.md +108 -0
  181. package/.framework/src/instructions/tasks/add-an-integration.md +124 -0
  182. package/.framework/src/instructions/tasks/build-a-custom-page.md +118 -0
  183. package/.framework/src/instructions/tasks/package-and-install-an-app.md +127 -0
  184. package/.framework/src/instructions/tasks/test-your-code.md +108 -0
  185. package/.framework/src/instructions/tasks/write-a-function.md +132 -0
  186. package/.framework/src/instructions/tasks/write-a-migration.md +110 -0
  187. package/.framework/src/instructions/testing.md +59 -0
  188. package/.framework/src/instructions/timers.md +82 -0
  189. package/.framework/src/instructions/triggers.md +69 -0
  190. package/.framework/src/instructions/types.md +93 -0
  191. package/.framework/src/lib/branding.ts +128 -0
  192. package/.framework/src/pages/NoAppPage.tsx +3 -1
  193. package/.framework/src/pages/NotFoundPage.tsx +62 -31
  194. package/.framework/src/pages/SetupPage.tsx +5 -2
  195. package/.framework/src/pages/admin/AIAgentDetailPage.tsx +117 -106
  196. package/.framework/src/pages/admin/AIAgentsPage.tsx +86 -48
  197. package/.framework/src/pages/admin/APIKeyDetailPage.tsx +153 -152
  198. package/.framework/src/pages/admin/APIKeysPage.tsx +91 -90
  199. package/.framework/src/pages/admin/AlertsConfigPage.tsx +29 -18
  200. package/.framework/src/pages/admin/AppDetailPage.tsx +6 -60
  201. package/.framework/src/pages/admin/AppsPage.tsx +104 -66
  202. package/.framework/src/pages/admin/DeliveriesPage.tsx +5 -5
  203. package/.framework/src/pages/admin/EmbeddingDetailPage.tsx +5 -23
  204. package/.framework/src/pages/admin/EmbeddingsPage.tsx +5 -26
  205. package/.framework/src/pages/admin/IntegrationDetailPage.tsx +7 -7
  206. package/.framework/src/pages/admin/IntegrationsPage.tsx +85 -43
  207. package/.framework/src/pages/admin/LogsPage.tsx +144 -76
  208. package/.framework/src/pages/admin/ObservabilityDashboard.tsx +223 -140
  209. package/.framework/src/pages/admin/PipelineDetailPage.tsx +134 -113
  210. package/.framework/src/pages/admin/PipelineExecutionsPage.tsx +108 -45
  211. package/.framework/src/pages/admin/PipelinesPage.tsx +160 -115
  212. package/.framework/src/pages/admin/PromptConfigDetailPage.tsx +96 -98
  213. package/.framework/src/pages/admin/PromptConfigsPage.tsx +101 -59
  214. package/.framework/src/pages/admin/RoleDetailPage.tsx +90 -79
  215. package/.framework/src/pages/admin/RolesPage.tsx +86 -43
  216. package/.framework/src/pages/admin/SecurityPage.tsx +1 -1
  217. package/.framework/src/pages/admin/TestingDashboard.tsx +16 -28
  218. package/.framework/src/pages/admin/TimerDetailPage.tsx +117 -100
  219. package/.framework/src/pages/admin/TimersPage.tsx +90 -62
  220. package/.framework/src/pages/admin/TriggerDetailPage.tsx +90 -83
  221. package/.framework/src/pages/admin/TriggersPage.tsx +124 -99
  222. package/.framework/src/pages/admin/TypeDetailPage.tsx +152 -138
  223. package/.framework/src/pages/admin/TypesPage.tsx +90 -48
  224. package/.framework/src/pages/admin/cil/CILAgentPage.tsx +17 -25
  225. package/.framework/src/pages/admin/cil/CILChunkDetailPage.tsx +17 -27
  226. package/.framework/src/pages/admin/cil/CILDashboardPage.tsx +72 -40
  227. package/.framework/src/pages/admin/cil/CILFileListPage.tsx +321 -129
  228. package/.framework/src/pages/admin/cil/CILFileSelectPage.tsx +18 -29
  229. package/.framework/src/pages/admin/cil/CILGraphPage.tsx +26 -38
  230. package/.framework/src/pages/admin/cil/CILIngestionPage.tsx +34 -46
  231. package/.framework/src/pages/admin/cil/CILProjectsPage.tsx +189 -103
  232. package/.framework/src/pages/admin/cil/CILSearchPage.tsx +246 -136
  233. package/.framework/src/pages/admin/cil/CILSuggestionsPage.tsx +11 -22
  234. package/.framework/src/pages/admin/cil/CILVersionsPage.tsx +9 -20
  235. package/.framework/src/pages/admin/cil/FlexiblePipelinePage.tsx +26 -38
  236. package/.framework/src/pages/admin/kb/KBAdminPage.tsx +7 -26
  237. package/.framework/src/pages/auth/AuthConfirmPage.tsx +3 -1
  238. package/.framework/src/pages/auth/ForgotPasswordPage.tsx +3 -1
  239. package/.framework/src/pages/auth/LoginPage.tsx +4 -2
  240. package/.framework/src/pages/auth/RegisterPage.tsx +3 -1
  241. package/.framework/templates/agent/AGENTS.md +150 -0
  242. package/.framework/templates/agent/skills/spine-add-ai-agent/SKILL.md +58 -0
  243. package/.framework/templates/agent/skills/spine-add-automation/SKILL.md +62 -0
  244. package/.framework/templates/agent/skills/spine-add-integration/SKILL.md +63 -0
  245. package/.framework/templates/agent/skills/spine-architect/SKILL.md +86 -0
  246. package/.framework/templates/agent/skills/spine-install-app/SKILL.md +72 -0
  247. package/.framework/templates/agent/skills/spine-migration/SKILL.md +75 -0
  248. package/.framework/templates/agent/skills/spine-new-app/SKILL.md +67 -0
  249. package/.framework/templates/agent/skills/spine-new-function/SKILL.md +65 -0
  250. package/.framework/templates/agent/skills/spine-new-type/SKILL.md +65 -0
  251. package/.framework/templates/agent/skills/spine-schema/SKILL.md +77 -0
  252. package/.framework/templates/agent/skills/spine-test/SKILL.md +67 -0
  253. package/.framework/templates/agent/skills/spine-troubleshoot/SKILL.md +74 -0
  254. package/.framework/templates/agent/skills/spine-upgrade/SKILL.md +69 -0
  255. package/.framework/templates/project.json +5 -1
  256. package/.framework/tests/unit/account-scoping-gates.test.ts +392 -0
  257. package/.framework/tests/unit/agent-files.test.ts +355 -0
  258. package/.framework/tests/unit/agent-runner.test.ts +496 -47
  259. package/.framework/tests/unit/api-keys-create-scope-gate.test.ts +160 -0
  260. package/.framework/tests/unit/api-keys-omit-secret-fields.test.ts +38 -0
  261. package/.framework/tests/unit/bootstrap.test.ts +242 -0
  262. package/.framework/tests/unit/cli-context-api-key.test.ts +114 -0
  263. package/.framework/tests/unit/debug-auth.test.ts +38 -0
  264. package/.framework/tests/unit/deliveries-account-scoping.test.ts +185 -0
  265. package/.framework/tests/unit/episode-lease.test.ts +695 -0
  266. package/.framework/tests/unit/integration-outbound-credentials.test.ts +167 -0
  267. package/.framework/tests/unit/integrations-audit-redaction.test.ts +130 -0
  268. package/.framework/tests/unit/kb-ingest-lease.test.ts +19 -0
  269. package/.framework/tests/unit/logging-app-id.test.ts +75 -0
  270. package/.framework/tests/unit/pipeline-runner-background.test.ts +120 -0
  271. package/.framework/tests/unit/pipeline-runner.test.ts +153 -1
  272. package/.framework/tests/unit/principal-cache.test.ts +15 -0
  273. package/.framework/tests/unit/system-context-denial.test.ts +145 -0
  274. package/.framework/tests/unit/system-cron.test.ts +240 -0
  275. package/.framework/tests/unit/timers.test.ts +159 -0
  276. package/.framework/tests/unit/trigger-engine.test.ts +278 -91
  277. package/.framework/tests/unit/trigger-scheduler.test.ts +78 -0
  278. package/README.md +125 -166
  279. package/config/tsconfig.cli.json +2 -2
  280. package/netlify.toml +5 -0
  281. package/package.json +15 -4
  282. package/templates/project/package-lock.json +2 -2
  283. package/.framework/docs/admin-routes.md +0 -76
  284. package/.framework/docs/api-docs-progress.md +0 -38
  285. package/.framework/docs/api-governance.md +0 -146
  286. package/.framework/docs/api-testing-results.md +0 -212
  287. package/.framework/docs/assembly-launch-guide.md +0 -138
  288. package/.framework/docs/audit-results.md +0 -590
  289. package/.framework/docs/db-api-inventory.md +0 -95
  290. package/.framework/docs/gap-remediation-backlog.md +0 -103
  291. package/.framework/docs/ui-adoption-verification.md +0 -111
  292. package/.framework/docs/ui-api-coverage.md +0 -84
  293. package/.framework/docs/v2-compatibility-audit.md +0 -228
  294. package/.framework/mcp/index.ts +0 -133
  295. package/.framework/mcp/load-env.ts +0 -60
  296. package/.framework/mcp/shared/app-manifest.ts +0 -275
  297. package/.framework/mcp/shared/db.ts +0 -477
  298. package/.framework/mcp/shared/kb.ts +0 -118
  299. package/.framework/mcp/tools/architect.ts +0 -431
  300. package/.framework/mcp/tools/cil/context.ts +0 -345
  301. package/.framework/mcp/tools/cil/graph.ts +0 -242
  302. package/.framework/mcp/tools/cil/ingest.ts +0 -1217
  303. package/.framework/mcp/tools/cil/pipeline-orchestrator.ts +0 -693
  304. package/.framework/mcp/tools/cil/pipeline.ts +0 -767
  305. package/.framework/mcp/tools/cil/project.ts +0 -791
  306. package/.framework/mcp/tools/cil/retrieval.ts +0 -336
  307. package/.framework/mcp/tools/cil/search-core.ts +0 -454
  308. package/.framework/mcp/tools/cil/search.ts +0 -97
  309. package/.framework/mcp/tools/cil/suggest.ts +0 -186
  310. package/.framework/mcp/tools/cil/validate.ts +0 -1369
  311. package/.framework/mcp/tools/kb/delete.ts +0 -139
  312. package/.framework/mcp/tools/kb/index.ts +0 -52
  313. package/.framework/mcp/tools/kb/ingest.ts +0 -84
  314. package/.framework/mcp/tools/kb/list-types.ts +0 -102
  315. package/.framework/mcp/tools/kb/publish.ts +0 -100
  316. package/.framework/mcp/tools/kb/reindex.ts +0 -86
  317. package/.framework/mcp/tools/kb/revoke.ts +0 -85
  318. package/.framework/mcp/tools/kb/search.ts +0 -101
  319. package/.framework/mcp/tools/kb/upsert.ts +0 -125
  320. package/.framework/mcp/tools/observability.ts +0 -510
@@ -1,4 +1,19 @@
1
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:module_header:module_header" type="module_header" identity="module_header" parent="none"]
1
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:module_header:module_header" type="module_header" identity="module_header" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2
+ /**
3
+ * @module agent-runner.test
4
+ * @audience both
5
+ * @layer shared-core
6
+ * @stability stable
7
+ *
8
+ * This module sets up the testing environment for the agent-runner functionality by configuring mocks for various dependencies such as database access, audit logging, and external integrations. It ensures that all necessary components are mocked before the actual agent-runner functions are imported for testing. INVARIANT: All mocks must be properly configured to avoid test failures due to missing dependencies.
9
+ *
10
+ * @seeAlso db.ts (provides database access functionality).
11
+ * @seeAlso audit.ts (handles audit logging).
12
+ * @seeAlso outcomes.ts (manages outcome emissions).
13
+ * @seeAlso llm.ts (interfaces with language model APIs).
14
+ *
15
+ * @cil-generated
16
+ */
2
17
  // CIL[DOC-MACRO purpose="Test setup and imports for agent-runner tests"]
3
18
  // CIL[DOC-RESPONSIBILITY responsibility="Configure module mocks for db, audit, outcomes, llm, admin-data, integration-outbound, and pipeline-runner, then import the agent-runner surface under test"]
4
19
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -9,6 +24,7 @@
9
24
  // CIL[DOC-AUDIENCE audience="test maintainers"]
10
25
  import { describe, it, expect, vi, beforeEach } from 'vitest'
11
26
  import type { CoreContext } from '../../functions/_shared/middleware.ts'
27
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:module_header:module_header"]
12
28
 
13
29
  vi.mock('../../functions/_shared/db.ts', () => ({
14
30
  adminDb: { from: vi.fn(), rpc: vi.fn() }
@@ -61,9 +77,7 @@ import { emitSignal } from '../../functions/_shared/funnel.ts'
61
77
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
62
78
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
63
79
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
64
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:module_header:module_header"]
65
80
 
66
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:makeCtx:function" type="function" identity="makeCtx" parent="none"]
67
81
  // CIL[DOC-MACRO purpose="Create a test CoreContext with a system principal"]
68
82
  // CIL[DOC-RESPONSIBILITY responsibility="Generate CoreContext objects for direct agent-runner calls"]
69
83
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -71,6 +85,19 @@ import { emitSignal } from '../../functions/_shared/funnel.ts'
71
85
  // CIL[DOC-MICRO logic_summary="Returns a machine-principal context with accountId acct-test and applies overrides" notable_decisions="[]"]
72
86
  // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
73
87
  // CIL[DOC-STABILITY stability="stable"]
88
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:makeCtx:function" type="function" identity="makeCtx" parent="~/.framework/tests/unit/agent-runner.test.ts"]
89
+ /**
90
+ * Creates a test CoreContext with a system principal for unit testing purposes. This function allows for the customization of the context through optional overrides.
91
+ *
92
+ * @macro Context generator for unit tests providing a default CoreContext structure.
93
+ * @micro Merges default context values with any provided overrides to create a complete CoreContext object.
94
+ * @inputSpec
95
+ * overrides: Partial<CoreContext> (optional) — custom values to override the default context properties.
96
+ * @outputSpec CoreContext — an object representing the context with merged default and overridden properties.
97
+ * @sideEffects none
98
+ * @stability internal
99
+ * @cil-generated
100
+ */
74
101
  function makeCtx(overrides: Partial<CoreContext> = {}): CoreContext {
75
102
  return {
76
103
  principal: {
@@ -87,15 +114,14 @@ function makeCtx(overrides: Partial<CoreContext> = {}): CoreContext {
87
114
  ...overrides
88
115
  } as CoreContext
89
116
  }
117
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:makeCtx:function"]
90
118
  // CIL[DOC-VECTOR type="context" content="purpose='Create a test CoreContext with a system principal'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts"]
91
119
  // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
92
120
  // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
93
121
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
94
122
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
95
123
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
96
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:makeCtx:function"]
97
124
 
98
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:test_ids:block" type="block" identity="test_ids" parent="none"]
99
125
  // CIL[DOC-MACRO purpose="Shared test identifiers"]
100
126
  // CIL[DOC-RESPONSIBILITY responsibility="Provide consistent thread, agent, and prompt-config IDs across tests"]
101
127
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -103,18 +129,29 @@ function makeCtx(overrides: Partial<CoreContext> = {}): CoreContext {
103
129
  // CIL[DOC-MICRO logic_summary="Defines THREAD_ID, AGENT_ID, and PROMPT_CONFIG_ID constants" notable_decisions="[]"]
104
130
  // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
105
131
  // CIL[DOC-STABILITY stability="stable"]
132
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:THREAD_ID:constant" type="constant" identity="THREAD_ID" parent="~/.framework/tests/unit/agent-runner.test.ts"]
106
133
  const THREAD_ID = 'thread-1'
134
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:THREAD_ID:constant"]
135
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:AGENT_ID:constant" type="constant" identity="AGENT_ID" parent="~/.framework/tests/unit/agent-runner.test.ts"]
136
+ /**
137
+ * AGENT_ID is a constant that holds the identifier for the agent used in tests. It exists to provide a consistent reference to the agent's ID throughout the test suite.
138
+ *
139
+ * @sideEffects none
140
+ * @stability internal
141
+ * @cil-generated
142
+ */
107
143
  const AGENT_ID = 'agent-1'
144
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:AGENT_ID:constant"]
145
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:PROMPT_CONFIG_ID:constant" type="constant" identity="PROMPT_CONFIG_ID" parent="~/.framework/tests/unit/agent-runner.test.ts"]
108
146
  const PROMPT_CONFIG_ID = 'prompt-1'
147
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:PROMPT_CONFIG_ID:constant"]
109
148
  // CIL[DOC-VECTOR type="context" content="purpose='Shared test identifiers'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts"]
110
149
  // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
111
150
  // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
112
151
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
113
152
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
114
153
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
115
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:test_ids:block"]
116
154
 
117
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockThread:function" type="function" identity="mockThread" parent="none"]
118
155
  // CIL[DOC-MACRO purpose="Build a thread fixture"]
119
156
  // CIL[DOC-RESPONSIBILITY responsibility="Return a thread record with data overrides for agent config resolution"]
120
157
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -122,6 +159,7 @@ const PROMPT_CONFIG_ID = 'prompt-1'
122
159
  // CIL[DOC-MICRO logic_summary="Builds a thread row with id THREAD_ID and merges data overrides" notable_decisions="[]"]
123
160
  // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
124
161
  // CIL[DOC-STABILITY stability="stable"]
162
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockThread:function" type="function" identity="mockThread" parent="~/.framework/tests/unit/agent-runner.test.ts"]
125
163
  function mockThread(overrides: Record<string, any> = {}) {
126
164
  return {
127
165
  id: THREAD_ID,
@@ -135,15 +173,14 @@ function mockThread(overrides: Record<string, any> = {}) {
135
173
  ...overrides
136
174
  }
137
175
  }
176
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockThread:function"]
138
177
  // CIL[DOC-VECTOR type="context" content="purpose='Build a thread fixture'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts"]
139
178
  // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
140
179
  // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
141
180
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
142
181
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
143
182
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
144
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockThread:function"]
145
183
 
146
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockAgent:function" type="function" identity="mockAgent" parent="none"]
147
184
  // CIL[DOC-MACRO purpose="Build an agent fixture"]
148
185
  // CIL[DOC-RESPONSIBILITY responsibility="Return an agent record with model_config overrides"]
149
186
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -151,6 +188,7 @@ function mockThread(overrides: Record<string, any> = {}) {
151
188
  // CIL[DOC-MICRO logic_summary="Builds an agent row with id AGENT_ID and merges model_config overrides" notable_decisions="[]"]
152
189
  // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
153
190
  // CIL[DOC-STABILITY stability="stable"]
191
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockAgent:function" type="function" identity="mockAgent" parent="~/.framework/tests/unit/agent-runner.test.ts"]
154
192
  function mockAgent(overrides: Record<string, any> = {}) {
155
193
  return {
156
194
  id: AGENT_ID,
@@ -162,15 +200,14 @@ function mockAgent(overrides: Record<string, any> = {}) {
162
200
  ...overrides
163
201
  }
164
202
  }
203
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockAgent:function"]
165
204
  // CIL[DOC-VECTOR type="context" content="purpose='Build an agent fixture'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts"]
166
205
  // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
167
206
  // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
168
207
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
169
208
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
170
209
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
171
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockAgent:function"]
172
210
 
173
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockPromptConfig:function" type="function" identity="mockPromptConfig" parent="none"]
174
211
  // CIL[DOC-MACRO purpose="Build a prompt config fixture"]
175
212
  // CIL[DOC-RESPONSIBILITY responsibility="Return a prompt config record with metadata overrides"]
176
213
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -178,6 +215,7 @@ function mockAgent(overrides: Record<string, any> = {}) {
178
215
  // CIL[DOC-MICRO logic_summary="Builds a prompt_configs row with id PROMPT_CONFIG_ID and merges metadata overrides" notable_decisions="[]"]
179
216
  // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
180
217
  // CIL[DOC-STABILITY stability="stable"]
218
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockPromptConfig:function" type="function" identity="mockPromptConfig" parent="~/.framework/tests/unit/agent-runner.test.ts"]
181
219
  function mockPromptConfig(overrides: Record<string, any> = {}) {
182
220
  return {
183
221
  id: PROMPT_CONFIG_ID,
@@ -189,15 +227,14 @@ function mockPromptConfig(overrides: Record<string, any> = {}) {
189
227
  ...overrides
190
228
  }
191
229
  }
230
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockPromptConfig:function"]
192
231
  // CIL[DOC-VECTOR type="context" content="purpose='Build a prompt config fixture'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts"]
193
232
  // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
194
233
  // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
195
234
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
196
235
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
197
236
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
198
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockPromptConfig:function"]
199
237
 
200
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:setupAgentConfigMocks:function" type="function" identity="setupAgentConfigMocks" parent="none"]
201
238
  // CIL[DOC-MACRO purpose="Mock adminDb.from queries used by agent config resolution and retrieval"]
202
239
  // CIL[DOC-RESPONSIBILITY responsibility="Return thenable Supabase-style query builders per table: threads, agents, prompt_configs, embeddings, items, and messages"]
203
240
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -205,6 +242,22 @@ function mockPromptConfig(overrides: Record<string, any> = {}) {
205
242
  // CIL[DOC-MICRO logic_summary="Resolves thread, agent, and prompt config lookups from fixtures; the embeddings branch is a thenable builder resolving an empty successful lexical result so the always-on lexical leg degrades quietly" notable_decisions="The embeddings thenable prevents expected lexical-failure warning noise in non-retrieval tests"]
206
243
  // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
207
244
  // CIL[DOC-STABILITY stability="stable"]
245
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:setupAgentConfigMocks:function" type="function" identity="setupAgentConfigMocks" parent="~/.framework/tests/unit/agent-runner.test.ts"]
246
+ /**
247
+ * Sets up mock implementations for database interactions related to agent configuration, threads, prompts, and other entities. This function is essential for testing components that depend on these database interactions without hitting the actual database.
248
+ *
249
+ * @macro Mock setup function for database interactions in unit tests.
250
+ * @micro Utilizes conditional logic to return different mock implementations based on the specified table name.
251
+ * @inputSpec
252
+ * threadOverrides: Record<string, any> (optional) — overrides for thread configurations.
253
+ * agentOverrides: Record<string, any> (optional) — overrides for agent configurations.
254
+ * promptOverrides: Record<string, any> (optional) — overrides for prompt configurations.
255
+ * @outputSpec void — sets up mocks without returning a value.
256
+ * @sideEffects Mocks database calls for various tables, affecting how tests interact with the database layer.
257
+ * @stability internal
258
+ * @calls adminDb.from, mockThread, mockAgent, mockPromptConfig
259
+ * @cil-generated
260
+ */
208
261
  function setupAgentConfigMocks(
209
262
  threadOverrides: Record<string, any> = {},
210
263
  agentOverrides: Record<string, any> = {},
@@ -304,15 +357,14 @@ function setupAgentConfigMocks(
304
357
 
305
358
  vi.mocked(adminDb.rpc).mockResolvedValue({ data: [], error: null } as any)
306
359
  }
360
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:setupAgentConfigMocks:function"]
307
361
  // CIL[DOC-VECTOR type="context" content="purpose='Mock adminDb.from queries used by agent config resolution and retrieval'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts"]
308
362
  // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
309
363
  // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
310
364
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
311
365
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
312
366
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
313
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:setupAgentConfigMocks:function"]
314
367
 
315
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockCreateRecord:function" type="function" identity="mockCreateRecord" parent="none"]
316
368
  // CIL[DOC-MACRO purpose="Mock admin-data createRecord"]
317
369
  // CIL[DOC-RESPONSIBILITY responsibility="Control the return value of record creation in tests"]
318
370
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -320,18 +372,18 @@ function setupAgentConfigMocks(
320
372
  // CIL[DOC-MICRO logic_summary="Wraps vi.mocked(createRecord).mockResolvedValue" notable_decisions="[]"]
321
373
  // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
322
374
  // CIL[DOC-STABILITY stability="stable"]
375
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockCreateRecord:function" type="function" identity="mockCreateRecord" parent="~/.framework/tests/unit/agent-runner.test.ts"]
323
376
  function mockCreateRecord(returnValue: any) {
324
377
  vi.mocked(createRecord).mockResolvedValue(returnValue)
325
378
  }
379
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockCreateRecord:function"]
326
380
  // CIL[DOC-VECTOR type="context" content="purpose='Mock admin-data createRecord'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts"]
327
381
  // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
328
382
  // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
329
383
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
330
384
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
331
385
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
332
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockCreateRecord:function"]
333
386
 
334
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockLlmResponse:function" type="function" identity="mockLlmResponse" parent="none"]
335
387
  // CIL[DOC-MACRO purpose="Mock callOpenAIChat JSON responses"]
336
388
  // CIL[DOC-RESPONSIBILITY responsibility="Control the LLM chat payload returned to the agent runner"]
337
389
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -339,18 +391,18 @@ function mockCreateRecord(returnValue: any) {
339
391
  // CIL[DOC-MICRO logic_summary="Wraps vi.mocked(callOpenAIChat).mockResolvedValue" notable_decisions="[]"]
340
392
  // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
341
393
  // CIL[DOC-STABILITY stability="stable"]
394
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockLlmResponse:function" type="function" identity="mockLlmResponse" parent="~/.framework/tests/unit/agent-runner.test.ts"]
342
395
  function mockLlmResponse(response: any) {
343
396
  vi.mocked(callOpenAIChat).mockResolvedValue(response)
344
397
  }
398
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockLlmResponse:function"]
345
399
  // CIL[DOC-VECTOR type="context" content="purpose='Mock callOpenAIChat JSON responses'; No verified external callers; imports: .framework/functions/_shared/middleware.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts"]
346
400
  // CIL[DOC-VECTOR type="blast_radius" content="No direct caller data from CIL graph; local impact only"]
347
401
  // CIL[DOC-VECTOR type="configuration" content="No environment or build configuration dependencies identified"]
348
402
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
349
403
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
350
404
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
351
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockLlmResponse:function"]
352
405
 
353
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_runAgent_singleTurn:block" type="block" identity="describe_runAgent_singleTurn" parent="none"]
354
406
  // CIL[DOC-MACRO purpose="Test runAgent single-turn execution"]
355
407
  // CIL[DOC-RESPONSIBILITY responsibility="Verify single-turn agent runs return replies and persist messages"]
356
408
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -376,8 +428,12 @@ describe('runAgent — single-turn', () => {
376
428
  })
377
429
  mockCreateRecord({ id: 'msg-1', content: 'Here is the answer.' })
378
430
 
431
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:ctx:constant" type="constant" identity="ctx" parent="~/.framework/tests/unit/agent-runner.test.ts"]
379
432
  const ctx = makeCtx()
433
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:ctx:constant"]
434
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
380
435
  const result = await runAgent(THREAD_ID, 'What is X?', ctx, 'complete')
436
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
381
437
 
382
438
  expect(result).toBeDefined()
383
439
  expect(createRecord).toHaveBeenCalledWith(
@@ -396,9 +452,7 @@ describe('runAgent — single-turn', () => {
396
452
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
397
453
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
398
454
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
399
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_runAgent_singleTurn:block"]
400
455
 
401
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_runAgent_stepMode:block" type="block" identity="describe_runAgent_stepMode" parent="none"]
402
456
  // CIL[DOC-MACRO purpose="Test runAgent step mode"]
403
457
  // CIL[DOC-RESPONSIBILITY responsibility="Verify step-mode agent execution and tool dispatch flow"]
404
458
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -420,8 +474,12 @@ describe('runAgent — step mode', () => {
420
474
  })
421
475
  mockCreateRecord({ id: 'msg-final', content: 'Final answer.' })
422
476
 
477
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:ctx:constant" type="constant" identity="ctx" parent="~/.framework/tests/unit/agent-runner.test.ts"]
423
478
  const ctx = makeCtx()
479
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:ctx:constant"]
480
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
424
481
  const result = await runAgent(THREAD_ID, 'Question?', ctx, 'step')
482
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
425
483
 
426
484
  expect(result).toBeDefined()
427
485
  expect(createRecord).toHaveBeenCalledWith(
@@ -460,8 +518,12 @@ describe('runAgent — step mode', () => {
460
518
  })
461
519
  mockCreateRecord({ id: 'msg-ask', content: 'Which project?' })
462
520
 
521
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:ctx:constant" type="constant" identity="ctx" parent="~/.framework/tests/unit/agent-runner.test.ts"]
463
522
  const ctx = makeCtx()
523
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:ctx:constant"]
524
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
464
525
  const result = await runAgent(THREAD_ID, 'Tell me about it.', ctx, 'step')
526
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
465
527
 
466
528
  expect(result).toBeDefined()
467
529
  expect(createRecord).toHaveBeenCalledWith(
@@ -499,8 +561,12 @@ describe('runAgent — step mode', () => {
499
561
  }
500
562
  })
501
563
 
564
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:ctx:constant" type="constant" identity="ctx" parent="~/.framework/tests/unit/agent-runner.test.ts"]
502
565
  const ctx = makeCtx()
566
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:ctx:constant"]
567
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
503
568
  const result = await runAgent(THREAD_ID, 'Question?', ctx, 'step')
569
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
504
570
 
505
571
  expect(result).toBeDefined()
506
572
  expect(emitSignal).not.toHaveBeenCalled()
@@ -524,10 +590,23 @@ describe('runAgent — complete mode state retention', () => {
524
590
 
525
591
  // Capture threads.update payloads — setResearchState checkpoints
526
592
  // data.research_state on each step.
593
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:threadUpdates:constant" type="constant" identity="threadUpdates" parent="~/.framework/tests/unit/agent-runner.test.ts"]
594
+ /**
595
+ * The constant 'threadUpdates' is an array that stores updates related to threads in the agent runner tests. It exists to facilitate the tracking and management of thread-related information during testing.
596
+ *
597
+ * @sideEffects none
598
+ * @stability internal
599
+ * @cil-generated
600
+ */
527
601
  const threadUpdates: any[] = []
602
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:threadUpdates:constant"]
603
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:origFrom:constant" type="constant" identity="origFrom" parent="~/.framework/tests/unit/agent-runner.test.ts"]
528
604
  const origFrom = vi.mocked(adminDb.from).getMockImplementation()!
605
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:origFrom:constant"]
529
606
  vi.mocked(adminDb.from).mockImplementation(((table: string) => {
607
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:builder:constant" type="constant" identity="builder" parent="~/.framework/tests/unit/agent-runner.test.ts"]
530
608
  const builder: any = origFrom(table)
609
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:builder:constant"]
531
610
  if (table === 'threads' && builder?.update?.mock) {
532
611
  // update() is mockReturnThis() — must return the builder, not `this`
533
612
  // captured from an unbound call.
@@ -561,23 +640,31 @@ describe('runAgent — complete mode state retention', () => {
561
640
  })
562
641
  mockCreateRecord({ id: 'msg-final', content: 'Here is the answer [1].', data: {} })
563
642
 
643
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:ctx:constant" type="constant" identity="ctx" parent="~/.framework/tests/unit/agent-runner.test.ts"]
564
644
  const ctx = makeCtx()
645
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:ctx:constant"]
565
646
  await runAgent(THREAD_ID, 'How do I configure sshd?', ctx, 'complete', 'lease-1')
566
647
 
567
648
  expect(callOpenAIChat).toHaveBeenCalledTimes(2)
568
649
 
569
650
  // Turn 2's inference context must carry turn 1's tool output.
651
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:secondTurnMessages:constant" type="constant" identity="secondTurnMessages" parent="~/.framework/tests/unit/agent-runner.test.ts"]
570
652
  const secondTurnMessages = vi.mocked(callOpenAIChat).mock.calls[1][1] as any[]
653
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:secondTurnMessages:constant"]
654
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:contextText:constant" type="constant" identity="contextText" parent="~/.framework/tests/unit/agent-runner.test.ts"]
571
655
  const contextText = secondTurnMessages.map((m: any) => m.content).join('\n')
656
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:contextText:constant"]
572
657
  expect(contextText).toContain('## Tool Results')
573
658
  expect(contextText).toContain('search_knowledge')
574
659
 
575
660
  // The final checkpoint shows one accumulated result over two turns, and
576
661
  // the driver token is stamped as the lease owner.
662
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:lastState:constant" type="constant" identity="lastState" parent="~/.framework/tests/unit/agent-runner.test.ts"]
577
663
  const lastState = threadUpdates
578
664
  .map(u => u?.data?.research_state)
579
665
  .filter(Boolean)
580
666
  .pop()
667
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:lastState:constant"]
581
668
  expect(lastState.turn_count).toBe(2)
582
669
  expect(lastState.gathered_results).toHaveLength(1)
583
670
  expect(lastState.status).toBe('complete')
@@ -589,6 +676,7 @@ describe('runAgent — complete mode state retention', () => {
589
676
  describe('runAgent — evidence-based escalation gating', () => {
590
677
  beforeEach(() => vi.clearAllMocks())
591
678
 
679
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:evidenceRpc:function" type="function" identity="evidenceRpc" parent="~/.framework/tests/unit/agent-runner.test.ts"]
592
680
  const evidenceRpc = () => {
593
681
  vi.mocked(adminDb.rpc).mockResolvedValue({
594
682
  data: [{
@@ -601,6 +689,7 @@ describe('runAgent — evidence-based escalation gating', () => {
601
689
  error: null
602
690
  } as any)
603
691
  }
692
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:evidenceRpc:function"]
604
693
 
605
694
  it('does not escalate an evidence_found answer below the confidence threshold', async () => {
606
695
  // Regression: sanitizeRecordData strips data.* keys the message type does
@@ -626,8 +715,10 @@ describe('runAgent — evidence-based escalation gating', () => {
626
715
 
627
716
  await runAgent(THREAD_ID, 'Question?', makeCtx(), 'complete', 'lease-1')
628
717
 
718
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:escalated:constant" type="constant" identity="escalated" parent="~/.framework/tests/unit/agent-runner.test.ts"]
629
719
  const escalated = vi.mocked(emitAudit).mock.calls
630
720
  .some((call: any[]) => call[1] === 'agent.inference.low_confidence')
721
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:escalated:constant"]
631
722
  expect(escalated).toBe(false)
632
723
  })
633
724
 
@@ -644,8 +735,10 @@ describe('runAgent — evidence-based escalation gating', () => {
644
735
 
645
736
  await runAgent(THREAD_ID, 'Question?', makeCtx(), 'complete', 'lease-1')
646
737
 
738
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:escalated:constant" type="constant" identity="escalated" parent="~/.framework/tests/unit/agent-runner.test.ts"]
647
739
  const escalated = vi.mocked(emitAudit).mock.calls
648
740
  .some((call: any[]) => call[1] === 'agent.inference.low_confidence')
741
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:escalated:constant"]
649
742
  expect(escalated).toBe(true)
650
743
  })
651
744
  })
@@ -655,9 +748,7 @@ describe('runAgent — evidence-based escalation gating', () => {
655
748
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
656
749
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
657
750
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
658
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_runAgent_stepMode:block"]
659
751
 
660
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_handlerModuleDispatch:block" type="block" identity="describe_executeToolAction_handlerModuleDispatch" parent="none"]
661
752
  // CIL[DOC-MACRO purpose="Test executeToolAction handler_module dispatch"]
662
753
  // CIL[DOC-RESPONSIBILITY responsibility="Verify handler_module tools dispatch to the correct module function"]
663
754
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -671,11 +762,13 @@ describe('executeToolAction — handler_module dispatch', () => {
671
762
  it('dispatches to executeOutbound for webhook actions', async () => {
672
763
  vi.mocked(executeOutbound).mockResolvedValue({ success: true, response_body: { ok: 1 } })
673
764
 
765
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
674
766
  const result = await executeToolAction(
675
767
  { handler_module: 'webhook', config: { url: 'https://example.com', method: 'POST' } },
676
768
  { foo: 'bar' },
677
769
  makeCtx()
678
770
  )
771
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
679
772
 
680
773
  expect(executeOutbound).toHaveBeenCalled()
681
774
  expect(result).toEqual({ ok: 1 })
@@ -684,11 +777,13 @@ describe('executeToolAction — handler_module dispatch', () => {
684
777
  it('dispatches to executeOutbound for integrations actions', async () => {
685
778
  vi.mocked(executeOutbound).mockResolvedValue({ success: true, response_body: { ok: 1 } })
686
779
 
780
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
687
781
  const result = await executeToolAction(
688
782
  { handler_module: 'integrations', config: { integration_slug: 'github', action_config: {} } },
689
783
  { repo: 'x' },
690
784
  makeCtx()
691
785
  )
786
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
692
787
 
693
788
  expect(executeOutbound).toHaveBeenCalledWith(
694
789
  expect.any(Object),
@@ -700,11 +795,13 @@ describe('executeToolAction — handler_module dispatch', () => {
700
795
  it('dispatches to runPipeline for pipeline actions', async () => {
701
796
  vi.mocked(runPipeline).mockResolvedValue({ status: 'completed', result: { ok: 1 } })
702
797
 
798
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
703
799
  const result = await executeToolAction(
704
800
  { handler_module: 'pipeline', config: { pipeline_id: 'pipe-1' } },
705
801
  { x: 1 },
706
802
  makeCtx()
707
803
  )
804
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
708
805
 
709
806
  expect(runPipeline).toHaveBeenCalledWith('pipe-1', { x: 1 }, expect.any(Object))
710
807
  expect(result).toEqual({ success: true, result: { status: 'completed', result: { ok: 1 } } })
@@ -713,11 +810,13 @@ describe('executeToolAction — handler_module dispatch', () => {
713
810
  it('dispatches built-in functions by handler name', async () => {
714
811
  vi.mocked(adminDb.rpc).mockResolvedValue({ data: [], error: null } as any)
715
812
 
813
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
716
814
  const result = await executeToolAction(
717
815
  { handler: 'query_items', handler_module: 'functions' },
718
816
  { entity: 'items', limit: 5 },
719
817
  makeCtx()
720
818
  )
819
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
721
820
 
722
821
  expect(result).toEqual({ items: [] })
723
822
  })
@@ -728,9 +827,7 @@ describe('executeToolAction — handler_module dispatch', () => {
728
827
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
729
828
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
730
829
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
731
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_handlerModuleDispatch:block"]
732
830
 
733
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_runAgentStep_directQuestionFallback:block" type="block" identity="describe_runAgentStep_directQuestionFallback" parent="none"]
734
831
  // CIL[DOC-MACRO purpose="Test runAgentStep direct-question fallback and research gating"]
735
832
  // CIL[DOC-RESPONSIBILITY responsibility="Verify the ask_user gate, research tool detection, and direct-answer fallback paths"]
736
833
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -752,6 +849,7 @@ describe('runAgentStep — direct question fallback', () => {
752
849
  })
753
850
  mockCreateRecord({ id: 'msg-q', content: 'Could you clarify which repository?' })
754
851
 
852
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
755
853
  const config = {
756
854
  agent: mockAgent(),
757
855
  promptConfig: mockPromptConfig(),
@@ -769,8 +867,11 @@ describe('runAgentStep — direct question fallback', () => {
769
867
  }),
770
868
  threadType: { slug: 'support_thread' }
771
869
  }
870
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
772
871
 
872
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
773
873
  const result = await runAgentStep(THREAD_ID, 'Tell me about the code.', makeCtx(), config)
874
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
774
875
 
775
876
  expect(result.state.status).toBe('awaiting_input')
776
877
  expect(result.state.pending_question).toContain('clarify')
@@ -778,6 +879,7 @@ describe('runAgentStep — direct question fallback', () => {
778
879
 
779
880
  it('keeps a complete markdown answer with a polite sign-off as final', async () => {
780
881
  setupAgentConfigMocks()
882
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:answer:constant" type="constant" identity="answer" parent="~/.framework/tests/unit/agent-runner.test.ts"]
781
883
  const answer = [
782
884
  '### Overview',
783
885
  '',
@@ -797,6 +899,7 @@ describe('runAgentStep — direct question fallback', () => {
797
899
  '',
798
900
  'If you encounter any issues or need further assistance, please let me know!'
799
901
  ].join('\n')
902
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:answer:constant"]
800
903
  mockLlmResponse({
801
904
  choices: [{
802
905
  message: { content: answer, tool_calls: undefined },
@@ -806,14 +909,18 @@ describe('runAgentStep — direct question fallback', () => {
806
909
  })
807
910
  mockCreateRecord({ id: 'msg-final', content: answer })
808
911
 
912
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
809
913
  const config = {
810
914
  agent: mockAgent(),
811
915
  promptConfig: mockPromptConfig(),
812
916
  thread: mockThread(),
813
917
  threadType: { slug: 'support_thread' }
814
918
  }
919
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
815
920
 
921
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
816
922
  const result = await runAgentStep(THREAD_ID, 'Explain the engine.', makeCtx(), config)
923
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
817
924
 
818
925
  expect(result.state.status).toBe('complete')
819
926
  expect(createRecord).toHaveBeenCalledWith(
@@ -827,7 +934,9 @@ describe('runAgentStep — direct question fallback', () => {
827
934
 
828
935
  it('keeps a short answer with a sign-off as final', async () => {
829
936
  setupAgentConfigMocks()
937
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:answer:constant" type="constant" identity="answer" parent="~/.framework/tests/unit/agent-runner.test.ts"]
830
938
  const answer = 'Run `npm run dev` to start the server. Let me know if that works!'
939
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:answer:constant"]
831
940
  mockLlmResponse({
832
941
  choices: [{
833
942
  message: { content: answer, tool_calls: undefined },
@@ -837,14 +946,18 @@ describe('runAgentStep — direct question fallback', () => {
837
946
  })
838
947
  mockCreateRecord({ id: 'msg-final-2', content: answer })
839
948
 
949
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
840
950
  const config = {
841
951
  agent: mockAgent(),
842
952
  promptConfig: mockPromptConfig(),
843
953
  thread: mockThread(),
844
954
  threadType: { slug: 'support_thread' }
845
955
  }
956
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
846
957
 
958
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
847
959
  const result = await runAgentStep(THREAD_ID, 'How do I start it?', makeCtx(), config)
960
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
848
961
 
849
962
  expect(result.state.status).toBe('complete')
850
963
  expect(createRecord).toHaveBeenCalledWith(
@@ -858,7 +971,9 @@ describe('runAgentStep — direct question fallback', () => {
858
971
 
859
972
  it('still treats a short question with a please-let-me-know phrase as awaiting_input', async () => {
860
973
  setupAgentConfigMocks()
974
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:question:constant" type="constant" identity="question" parent="~/.framework/tests/unit/agent-runner.test.ts"]
861
975
  const question = 'Please let me know which project you are working in.'
976
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:question:constant"]
862
977
  mockLlmResponse({
863
978
  choices: [{
864
979
  message: { content: question, tool_calls: undefined },
@@ -868,6 +983,7 @@ describe('runAgentStep — direct question fallback', () => {
868
983
  })
869
984
  mockCreateRecord({ id: 'msg-q2', content: question })
870
985
 
986
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
871
987
  const config = {
872
988
  agent: mockAgent(),
873
989
  promptConfig: mockPromptConfig(),
@@ -885,8 +1001,11 @@ describe('runAgentStep — direct question fallback', () => {
885
1001
  }),
886
1002
  threadType: { slug: 'support_thread' }
887
1003
  }
1004
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
888
1005
 
1006
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
889
1007
  const result = await runAgentStep(THREAD_ID, 'Help me.', makeCtx(), config)
1008
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
890
1009
 
891
1010
  expect(result.state.status).toBe('awaiting_input')
892
1011
  })
@@ -902,6 +1021,7 @@ describe('runAgentStep — direct question fallback', () => {
902
1021
  })
903
1022
  mockCreateRecord({ id: 'msg-final', content: 'Final answer.' })
904
1023
 
1024
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
905
1025
  const config = {
906
1026
  agent: mockAgent({
907
1027
  model_config: {
@@ -915,11 +1035,23 @@ describe('runAgentStep — direct question fallback', () => {
915
1035
  thread: mockThread(),
916
1036
  threadType: { slug: 'support_thread' }
917
1037
  }
1038
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
918
1039
 
919
1040
  await runAgentStep(THREAD_ID, 'Tell me about it.', makeCtx(), config)
920
1041
 
1042
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:options:constant" type="constant" identity="options" parent="~/.framework/tests/unit/agent-runner.test.ts"]
921
1043
  const options = vi.mocked(callOpenAIChat).mock.calls[0][3] as any
1044
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:options:constant"]
1045
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:names:constant" type="constant" identity="names" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1046
+ /**
1047
+ * The 'names' constant extracts the names of functions from the tools defined in the agent's model configuration. It is used to verify the presence of the 'escalate_to_human' function in the available tools.
1048
+ *
1049
+ * @sideEffects none
1050
+ * @stability internal
1051
+ * @cil-generated
1052
+ */
922
1053
  const names = (options?.tools || []).map((t: any) => t.function?.name)
1054
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:names:constant"]
923
1055
  expect(names).toContain('search_knowledge')
924
1056
  expect(names).not.toContain('ask_user')
925
1057
  })
@@ -940,14 +1072,18 @@ describe('runAgentStep — direct question fallback', () => {
940
1072
  })
941
1073
  mockCreateRecord({ id: 'msg-tool' })
942
1074
 
1075
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
943
1076
  const config = {
944
1077
  agent: mockAgent(),
945
1078
  promptConfig: mockPromptConfig(),
946
1079
  thread: mockThread(),
947
1080
  threadType: { slug: 'support_thread' }
948
1081
  }
1082
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
949
1083
 
1084
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
950
1085
  const result = await runAgentStep(THREAD_ID, 'Tell me about it.', makeCtx(), config)
1086
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
951
1087
 
952
1088
  expect(result.state.status).toBe('gathering')
953
1089
  expect(createRecord).toHaveBeenCalledWith(
@@ -979,14 +1115,18 @@ describe('runAgentStep — direct question fallback', () => {
979
1115
  })
980
1116
  mockCreateRecord({ id: 'msg-thinking' })
981
1117
 
1118
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
982
1119
  const config = {
983
1120
  agent: mockAgent(),
984
1121
  promptConfig: mockPromptConfig(),
985
1122
  thread: mockThread(),
986
1123
  threadType: { slug: 'support_thread' }
987
1124
  }
1125
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
988
1126
 
1127
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
989
1128
  const result = await runAgentStep(THREAD_ID, 'Tell me about it.', makeCtx(), config)
1129
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
990
1130
 
991
1131
  expect(result.state.status).toBe('gathering')
992
1132
  expect(createRecord).not.toHaveBeenCalledWith(
@@ -1008,24 +1148,32 @@ describe('runAgentStep — direct question fallback', () => {
1008
1148
  })
1009
1149
  mockCreateRecord({ id: 'msg-final', content: 'Final answer.' })
1010
1150
 
1151
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1011
1152
  const config = {
1012
1153
  agent: mockAgent(),
1013
1154
  promptConfig: mockPromptConfig({ context_template: 'Question: {{user_message}}' }),
1014
1155
  thread: mockThread(),
1015
1156
  threadType: { slug: 'support_thread' }
1016
1157
  }
1158
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
1017
1159
 
1018
1160
  await runAgentStep(THREAD_ID, 'Tell me about it.', makeCtx(), config)
1019
1161
 
1162
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:messages:constant" type="constant" identity="messages" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1020
1163
  const messages = vi.mocked(callOpenAIChat).mock.calls[0][1] as any[]
1164
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:messages:constant"]
1165
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:combined:constant" type="constant" identity="combined" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1021
1166
  const combined = messages.map((m: any) => m.content).join('\n')
1167
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:combined:constant"]
1022
1168
  expect(combined).toContain('Question: Tell me about it.')
1023
1169
  expect(combined).not.toContain('{{user_message}}')
1024
1170
  })
1025
1171
 
1026
1172
  it('fences retrieved evidence as untrusted data, never instructions', async () => {
1027
1173
  setupAgentConfigMocks()
1174
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:docId:constant" type="constant" identity="docId" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1028
1175
  const docId = '123e4567-e89b-42d3-a456-426614174000'
1176
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:docId:constant"]
1029
1177
  vi.mocked(adminDb.rpc).mockResolvedValue({
1030
1178
  data: [{
1031
1179
  document_id: docId,
@@ -1036,17 +1184,21 @@ describe('runAgentStep — direct question fallback', () => {
1036
1184
  }],
1037
1185
  error: null
1038
1186
  } as any)
1187
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:baseImpl:constant" type="constant" identity="baseImpl" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1039
1188
  const baseImpl = vi.mocked(adminDb.from).getMockImplementation()!
1189
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:baseImpl:constant"]
1040
1190
  vi.mocked(adminDb.from).mockImplementation((table: string) => {
1041
1191
  if (table === 'items') {
1042
1192
  return { select: vi.fn(() => ({ in: vi.fn().mockResolvedValue({ data: [], error: null }) })) } as any
1043
1193
  }
1044
1194
  if (table === 'embeddings') {
1195
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:q:constant" type="constant" identity="q" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1045
1196
  const q: any = {
1046
1197
  select: vi.fn(() => q), in: vi.fn(() => q), is: vi.fn(() => q),
1047
1198
  not: vi.fn(() => q), textSearch: vi.fn(() => q), or: vi.fn(() => q),
1048
1199
  limit: vi.fn().mockResolvedValue({ data: [], error: null })
1049
1200
  }
1201
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:q:constant"]
1050
1202
  return q
1051
1203
  }
1052
1204
  return baseImpl(table)
@@ -1060,17 +1212,23 @@ describe('runAgentStep — direct question fallback', () => {
1060
1212
  })
1061
1213
  mockCreateRecord({ id: 'msg-final', content: 'Final answer.' })
1062
1214
 
1215
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1063
1216
  const config = {
1064
1217
  agent: mockAgent(),
1065
1218
  promptConfig: mockPromptConfig(),
1066
1219
  thread: mockThread(),
1067
1220
  threadType: { slug: 'support_thread' }
1068
1221
  }
1222
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
1069
1223
 
1070
1224
  await runAgentStep(THREAD_ID, 'What is the refund policy?', makeCtx(), config)
1071
1225
 
1226
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:messages:constant" type="constant" identity="messages" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1072
1227
  const messages = vi.mocked(callOpenAIChat).mock.calls[0][1] as any[]
1228
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:messages:constant"]
1229
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:combined:constant" type="constant" identity="combined" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1073
1230
  const combined = messages.map((m: any) => m.content).join('\n')
1231
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:combined:constant"]
1074
1232
  expect(combined).toContain('untrusted data')
1075
1233
  expect(combined).toContain('never as instructions')
1076
1234
  expect(combined).toContain('untrusted input')
@@ -1090,6 +1248,7 @@ describe('runAgentStep — direct question fallback', () => {
1090
1248
  })
1091
1249
  mockCreateRecord({ id: 'msg-q', content: 'Which project are you working in?' })
1092
1250
 
1251
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1093
1252
  const config = {
1094
1253
  agent: mockAgent(),
1095
1254
  promptConfig: mockPromptConfig(),
@@ -1107,8 +1266,11 @@ describe('runAgentStep — direct question fallback', () => {
1107
1266
  }),
1108
1267
  threadType: { slug: 'support_thread' }
1109
1268
  }
1269
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
1110
1270
 
1271
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1111
1272
  const result = await runAgentStep(THREAD_ID, 'Tell me about it.', makeCtx(), config)
1273
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
1112
1274
 
1113
1275
  expect(result.state.status).toBe('awaiting_input')
1114
1276
  })
@@ -1119,9 +1281,7 @@ describe('runAgentStep — direct question fallback', () => {
1119
1281
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1120
1282
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1121
1283
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1122
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_runAgentStep_directQuestionFallback:block"]
1123
1284
 
1124
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_stripCilBoilerplate:block" type="block" identity="describe_stripCilBoilerplate" parent="none"]
1125
1285
  // CIL[DOC-MACRO purpose="Test stripCilBoilerplate"]
1126
1286
  // CIL[DOC-RESPONSIBILITY responsibility="Verify CIL boilerplate is stripped from model output"]
1127
1287
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -1131,8 +1291,12 @@ describe('runAgentStep — direct question fallback', () => {
1131
1291
  // CIL[DOC-STABILITY stability="stable"]
1132
1292
  describe('stripCilBoilerplate', () => {
1133
1293
  it('removes boilerplate phrases and leftover empty labels', () => {
1294
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:input:constant" type="constant" identity="input" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1134
1295
  const input = "DesignSchema [interface] in .framework/src/types/types.ts. Context: purpose='Complete design schema for an item type'; No verified external callers; imports: none. Blast radius: No direct caller data from CIL graph; local impact only. Complete design schema for an item type"
1296
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:input:constant"]
1297
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:out:constant" type="constant" identity="out" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1135
1298
  const out = stripCilBoilerplate(input)
1299
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:out:constant"]
1136
1300
  expect(out).toContain('Complete design schema for an item type')
1137
1301
  expect(out).toContain('purpose=')
1138
1302
  expect(out).not.toContain('No verified external callers')
@@ -1146,9 +1310,7 @@ describe('stripCilBoilerplate', () => {
1146
1310
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1147
1311
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1148
1312
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1149
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_stripCilBoilerplate:block"]
1150
1313
 
1151
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_extractCitedSources:block" type="block" identity="describe_extractCitedSources" parent="none"]
1152
1314
  // CIL[DOC-MACRO purpose="Test extractCitedSources"]
1153
1315
  // CIL[DOC-RESPONSIBILITY responsibility="Verify citation extraction from model output"]
1154
1316
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -1157,10 +1319,14 @@ describe('stripCilBoilerplate', () => {
1157
1319
  // CIL[DOC-CONFIDENCE pass="second" score="0.90" flags="none"]
1158
1320
  // CIL[DOC-STABILITY stability="stable"]
1159
1321
  describe('extractCitedSources', () => {
1322
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:sources:constant" type="constant" identity="sources" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1160
1323
  const sources = [{ document_id: 'a' }, { document_id: 'b' }, { document_id: 'c' }]
1324
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:sources:constant"]
1161
1325
 
1162
1326
  it('returns cited sources in order of first appearance', () => {
1327
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:out:constant" type="constant" identity="out" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1163
1328
  const out = extractCitedSources('A [2] and B [1] and again [2]. Bogus [9].', sources)
1329
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:out:constant"]
1164
1330
  expect(out).toEqual([sources[1], sources[0]])
1165
1331
  })
1166
1332
 
@@ -1174,9 +1340,7 @@ describe('extractCitedSources', () => {
1174
1340
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1175
1341
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1176
1342
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1177
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_extractCitedSources:block"]
1178
1343
 
1179
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_cilFetchDocument:block" type="block" identity="describe_executeToolAction_cilFetchDocument" parent="none"]
1180
1344
  // CIL[DOC-MACRO purpose="Test executeToolAction cil_fetch_document handler"]
1181
1345
  // CIL[DOC-RESPONSIBILITY responsibility="Verify CIL document fetch tool behavior and errors"]
1182
1346
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -1187,6 +1351,7 @@ describe('extractCitedSources', () => {
1187
1351
  describe('executeToolAction — cil_fetch_document', () => {
1188
1352
  beforeEach(() => vi.clearAllMocks())
1189
1353
 
1354
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:itemsFetchQuery:function" type="function" identity="itemsFetchQuery" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1190
1355
  function itemsFetchQuery(item: any, captured: { filterArgs?: any[] } = {}) {
1191
1356
  const q: any = {
1192
1357
  select: vi.fn(() => q),
@@ -1197,7 +1362,9 @@ describe('executeToolAction — cil_fetch_document', () => {
1197
1362
  }
1198
1363
  return q
1199
1364
  }
1365
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:itemsFetchQuery:function"]
1200
1366
 
1367
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockFetchTables:function" type="function" identity="mockFetchTables" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1201
1368
  function mockFetchTables(item: any, captured: { filterArgs?: any[] } = {}) {
1202
1369
  vi.mocked(adminDb.from).mockImplementation((table: string) => {
1203
1370
  if (table === 'apps') {
@@ -1226,12 +1393,17 @@ describe('executeToolAction — cil_fetch_document', () => {
1226
1393
  return {} as any
1227
1394
  })
1228
1395
  }
1396
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockFetchTables:function"]
1229
1397
 
1230
1398
  it('returns content from data.content for a KB item by UUID', async () => {
1399
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:docId:constant" type="constant" identity="docId" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1231
1400
  const docId = '123e4567-e89b-42d3-a456-426614174000'
1401
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:docId:constant"]
1232
1402
  mockFetchTables({ id: 'item-1', title: 'Doc', data: { content: 'full body', kb_type: 'kb_article' } })
1233
1403
 
1404
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1234
1405
  const res = await executeToolAction({ handler: 'cil_fetch_document' }, { document_id: docId }, makeCtx())
1406
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1235
1407
 
1236
1408
  expect(res.content).toBe('full body')
1237
1409
  expect(res.item_id).toBe('item-1')
@@ -1239,14 +1411,20 @@ describe('executeToolAction — cil_fetch_document', () => {
1239
1411
  })
1240
1412
 
1241
1413
  it('resolves a stable_id via data->>stable_id and returns code_content', async () => {
1414
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:sid:constant" type="constant" identity="sid" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1242
1415
  const sid = '~/.framework/src/types/types.ts:DesignSchema:interface'
1416
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:sid:constant"]
1417
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:captured:constant" type="constant" identity="captured" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1243
1418
  const captured: { filterArgs: any[] } = { filterArgs: [] }
1419
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:captured:constant"]
1244
1420
  mockFetchTables(
1245
1421
  { id: 'item-2', title: 'DesignSchema', data: { code_content: 'export interface DesignSchema {}', kb_type: 'cil_chunk', project_id: 'proj-a', stable_id: sid } },
1246
1422
  captured
1247
1423
  )
1248
1424
 
1425
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1249
1426
  const res = await executeToolAction({ handler: 'cil_fetch_document' }, { document_id: sid }, makeCtx())
1427
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1250
1428
 
1251
1429
  expect(captured.filterArgs).toContainEqual(['data->>stable_id', 'eq', sid])
1252
1430
  expect(res.content).toBe('export interface DesignSchema {}')
@@ -1259,14 +1437,18 @@ describe('executeToolAction — cil_fetch_document', () => {
1259
1437
  })
1260
1438
 
1261
1439
  it('rejects a cil_chunk outside the configured project scope', async () => {
1440
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:docId:constant" type="constant" identity="docId" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1262
1441
  const docId = '123e4567-e89b-42d3-a456-426614174000'
1442
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:docId:constant"]
1263
1443
  mockFetchTables({
1264
1444
  id: 'item-9', title: 'Other chunk',
1265
1445
  data: { code_content: 'secret code', kb_type: 'cil_chunk', project_id: 'proj-other', stable_id: 's-9' }
1266
1446
  })
1447
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:runCtx:constant" type="constant" identity="runCtx" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1267
1448
  const runCtx = {
1268
1449
  config: { thread: { data: { cil_config: { project_ids: ['proj-a'] } } } }
1269
1450
  } as any
1451
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:runCtx:constant"]
1270
1452
 
1271
1453
  await expect(
1272
1454
  executeToolAction({ handler: 'cil_fetch_document' }, { document_id: docId }, makeCtx(), runCtx)
@@ -1274,18 +1456,24 @@ describe('executeToolAction — cil_fetch_document', () => {
1274
1456
  })
1275
1457
 
1276
1458
  it('allows a cil_chunk inside the configured project scope', async () => {
1459
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:docId:constant" type="constant" identity="docId" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1277
1460
  const docId = '123e4567-e89b-42d3-a456-426614174000'
1461
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:docId:constant"]
1278
1462
  mockFetchTables({
1279
1463
  id: 'item-10', title: 'In-scope chunk',
1280
1464
  data: { code_content: 'scoped code', kb_type: 'cil_chunk', project_id: 'proj-a', stable_id: 's-10' }
1281
1465
  })
1466
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:runCtx:constant" type="constant" identity="runCtx" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1282
1467
  const runCtx = {
1283
1468
  config: { thread: { data: { cil_config: { project_ids: ['proj-a'] } } } }
1284
1469
  } as any
1470
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:runCtx:constant"]
1285
1471
 
1472
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1286
1473
  const res = await executeToolAction(
1287
1474
  { handler: 'cil_fetch_document' }, { document_id: docId }, makeCtx(), runCtx
1288
1475
  )
1476
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1289
1477
  expect(res.content).toBe('scoped code')
1290
1478
  })
1291
1479
  })
@@ -1295,9 +1483,7 @@ describe('executeToolAction — cil_fetch_document', () => {
1295
1483
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1296
1484
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1297
1485
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1298
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_cilFetchDocument:block"]
1299
1486
 
1300
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_cilChunkLookup:block" type="block" identity="describe_executeToolAction_cilChunkLookup" parent="none"]
1301
1487
  // CIL[DOC-MACRO purpose="Test executeToolAction cil_chunk_lookup code content search"]
1302
1488
  // CIL[DOC-RESPONSIBILITY responsibility="Verify CIL chunk lookup searches code content correctly"]
1303
1489
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -1309,7 +1495,10 @@ describe('executeToolAction — cil_chunk_lookup code content search', () => {
1309
1495
  beforeEach(() => vi.clearAllMocks())
1310
1496
 
1311
1497
  it('includes data->>code_content in the or() filter', async () => {
1498
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:orArgs:constant" type="constant" identity="orArgs" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1312
1499
  const orArgs: string[] = []
1500
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:orArgs:constant"]
1501
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:itemsQ:constant" type="constant" identity="itemsQ" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1313
1502
  const itemsQ: any = {
1314
1503
  select: vi.fn(() => itemsQ),
1315
1504
  filter: vi.fn(() => itemsQ),
@@ -1319,6 +1508,7 @@ describe('executeToolAction — cil_chunk_lookup code content search', () => {
1319
1508
  limit: vi.fn(() => itemsQ),
1320
1509
  then: (resolve: any) => resolve({ data: [], error: null }),
1321
1510
  }
1511
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:itemsQ:constant"]
1322
1512
  vi.mocked(adminDb.from).mockImplementation((table: string) => {
1323
1513
  if (table === 'apps') {
1324
1514
  return {
@@ -1357,9 +1547,7 @@ describe('executeToolAction — cil_chunk_lookup code content search', () => {
1357
1547
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1358
1548
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1359
1549
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1360
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_cilChunkLookup:block"]
1361
1550
 
1362
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_escalateToHuman:block" type="block" identity="describe_executeToolAction_escalateToHuman" parent="none"]
1363
1551
  // CIL[DOC-MACRO purpose="Test executeToolAction escalate_to_human handler"]
1364
1552
  // CIL[DOC-RESPONSIBILITY responsibility="Verify escalation tool creates the expected records"]
1365
1553
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -1370,7 +1558,8 @@ describe('executeToolAction — cil_chunk_lookup code content search', () => {
1370
1558
  describe('executeToolAction — escalate_to_human', () => {
1371
1559
  beforeEach(() => vi.clearAllMocks())
1372
1560
 
1373
- function mockEscalationFlow(opts: { escalationStatus?: string } = {}) {
1561
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockEscalationFlow:function" type="function" identity="mockEscalationFlow" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1562
+ function mockEscalationFlow(opts: { escalationStatus?: string; owner?: string } = {}) {
1374
1563
  const updates: { table: string; payload: any }[] = []
1375
1564
  vi.mocked(adminDb.from).mockImplementation((table: string) => {
1376
1565
  const q: any = {
@@ -1381,7 +1570,7 @@ describe('executeToolAction — escalate_to_human', () => {
1381
1570
  update: vi.fn((payload: any) => { updates.push({ table, payload }); return q }),
1382
1571
  single: vi.fn(() => {
1383
1572
  if (table === 'threads' && q._cols === 'data') {
1384
- return Promise.resolve({ data: { data: { escalation_status: opts.escalationStatus } }, error: null })
1573
+ return Promise.resolve({ data: { data: { owner: opts.owner, escalation_status: opts.escalationStatus } }, error: null })
1385
1574
  }
1386
1575
  if (table === 'threads' && q._cols === 'target_type, target_id') {
1387
1576
  return Promise.resolve({ data: { target_type: 'items', target_id: 'item-1' }, error: null })
@@ -1397,8 +1586,11 @@ describe('executeToolAction — escalate_to_human', () => {
1397
1586
  })
1398
1587
  return updates
1399
1588
  }
1589
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockEscalationFlow:function"]
1400
1590
 
1591
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:escConfig:constant" type="constant" identity="escConfig" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1401
1592
  const escConfig = { promptConfig: mockPromptConfig({ escalation_action: 'pipeline', confidence_threshold: 0.75 }) }
1593
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:escConfig:constant"]
1402
1594
 
1403
1595
  it('throws without a thread context', async () => {
1404
1596
  await expect(
@@ -1407,19 +1599,23 @@ describe('executeToolAction — escalate_to_human', () => {
1407
1599
  })
1408
1600
 
1409
1601
  it('marks the thread escalation pending and the ticket human_assigned', async () => {
1602
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:updates:constant" type="constant" identity="updates" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1410
1603
  const updates = mockEscalationFlow()
1604
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:updates:constant"]
1411
1605
 
1606
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1412
1607
  const res = await executeToolAction(
1413
1608
  { handler: 'escalate_to_human' },
1414
1609
  { reason: 'no relevant docs' },
1415
1610
  makeCtx(),
1416
1611
  { threadId: THREAD_ID, config: escConfig }
1417
1612
  )
1613
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1418
1614
 
1419
1615
  expect(res).toEqual({ escalated: true, already_escalated: false, reason: 'no relevant docs' })
1420
1616
  expect(updates).toContainEqual({
1421
1617
  table: 'threads',
1422
- payload: { data: { escalation_status: 'pending' } }
1618
+ payload: { data: { owner: 'human' } }
1423
1619
  })
1424
1620
  expect(updates).toContainEqual({
1425
1621
  table: 'items',
@@ -1428,14 +1624,36 @@ describe('executeToolAction — escalate_to_human', () => {
1428
1624
  })
1429
1625
 
1430
1626
  it('dedupes when the thread is already pending escalation', async () => {
1627
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:updates:constant" type="constant" identity="updates" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1431
1628
  const updates = mockEscalationFlow({ escalationStatus: 'pending' })
1629
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:updates:constant"]
1432
1630
 
1631
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1433
1632
  const res = await executeToolAction(
1434
1633
  { handler: 'escalate_to_human' },
1435
1634
  { reason: 'still stuck' },
1436
1635
  makeCtx(),
1437
1636
  { threadId: THREAD_ID, config: escConfig }
1438
1637
  )
1638
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1639
+
1640
+ expect(res.already_escalated).toBe(true)
1641
+ expect(updates).toHaveLength(0)
1642
+ })
1643
+
1644
+ it('dedupes when the thread is already human-owned', async () => {
1645
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:updates:constant" type="constant" identity="updates" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1646
+ const updates = mockEscalationFlow({ owner: 'human' })
1647
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:updates:constant"]
1648
+
1649
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1650
+ const res = await executeToolAction(
1651
+ { handler: 'escalate_to_human' },
1652
+ { reason: 'still stuck' },
1653
+ makeCtx(),
1654
+ { threadId: THREAD_ID, config: escConfig }
1655
+ )
1656
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1439
1657
 
1440
1658
  expect(res.already_escalated).toBe(true)
1441
1659
  expect(updates).toHaveLength(0)
@@ -1447,9 +1665,7 @@ describe('executeToolAction — escalate_to_human', () => {
1447
1665
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1448
1666
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1449
1667
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1450
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_escalateToHuman:block"]
1451
1668
 
1452
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_resolveAgentConfig_escalateToHumanWiring:block" type="block" identity="describe_resolveAgentConfig_escalateToHumanWiring" parent="none"]
1453
1669
  // CIL[DOC-MACRO purpose="Test resolveAgentConfig escalate_to_human wiring"]
1454
1670
  // CIL[DOC-RESPONSIBILITY responsibility="Verify the escalate_to_human tool is offered only when the prompt config sets an escalation_action"]
1455
1671
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -1463,18 +1679,26 @@ describe('resolveAgentConfig — escalate_to_human wiring', () => {
1463
1679
  it('offers escalate_to_human when the prompt config has an escalation_action', async () => {
1464
1680
  setupAgentConfigMocks({}, {}, { escalation_action: 'pipeline', available_tools: [] })
1465
1681
 
1682
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1466
1683
  const config = await resolveAgentConfig(THREAD_ID, makeCtx())
1684
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
1467
1685
 
1686
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:names:constant" type="constant" identity="names" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1468
1687
  const names = (config?.agent.model_config.tools || []).map((t: any) => t.function?.name)
1688
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:names:constant"]
1469
1689
  expect(names).toContain('escalate_to_human')
1470
1690
  })
1471
1691
 
1472
1692
  it('does not offer escalate_to_human without an escalation_action', async () => {
1473
1693
  setupAgentConfigMocks({}, {}, { escalation_action: null, available_tools: [] })
1474
1694
 
1695
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1475
1696
  const config = await resolveAgentConfig(THREAD_ID, makeCtx())
1697
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
1476
1698
 
1699
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:names:constant" type="constant" identity="names" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1477
1700
  const names = (config?.agent.model_config.tools || []).map((t: any) => t.function?.name)
1701
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:names:constant"]
1478
1702
  expect(names).not.toContain('escalate_to_human')
1479
1703
  })
1480
1704
  })
@@ -1484,9 +1708,7 @@ describe('resolveAgentConfig — escalate_to_human wiring', () => {
1484
1708
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1485
1709
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1486
1710
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1487
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_resolveAgentConfig_escalateToHumanWiring:block"]
1488
1711
 
1489
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_retrieveKnowledge_concurrentRetrieval:block" type="block" identity="describe_retrieveKnowledge_concurrentRetrieval" parent="none"]
1490
1712
  // CIL[DOC-MACRO purpose="Verify retrieveKnowledge concurrent retrieval semantics"]
1491
1713
  // CIL[DOC-RESPONSIBILITY responsibility="Verify deterministic channel ordering, bounded vector concurrency (default 3, clamped to 1..5 and channel count), lexical fallback on embedding/vector failure, child span emission and error status, summary gating, security/project/knowledge-source filters, and independent hydration degradation"]
1492
1714
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,.framework/functions/_shared/db.ts,.framework/functions/_shared/audit.ts,.framework/functions/_shared/llm.ts,.framework/functions/_shared/outcomes.ts,.framework/functions/_shared/middleware.ts,.framework/functions/_shared/cil.ts,.framework/functions/_shared/pipeline-runner.ts,.framework/functions/admin-data.ts,.framework/functions/integration-outbound.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -1497,15 +1719,20 @@ describe('resolveAgentConfig — escalate_to_human wiring', () => {
1497
1719
  describe('retrieveKnowledge — concurrent retrieval', () => {
1498
1720
  beforeEach(() => vi.clearAllMocks())
1499
1721
 
1722
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:deferred:function" type="function" identity="deferred" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1500
1723
  function deferred<T>() {
1501
1724
  let resolve!: (value: T) => void
1502
1725
  let reject!: (error: any) => void
1503
1726
  const promise = new Promise<T>((res, rej) => { resolve = res; reject = rej })
1504
1727
  return { promise, resolve, reject }
1505
1728
  }
1729
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:deferred:function"]
1506
1730
 
1731
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:flush:function" type="function" identity="flush" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1507
1732
  const flush = () => new Promise<void>((r) => setImmediate(r))
1733
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:flush:function"]
1508
1734
 
1735
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:vectorDoc:function" type="function" identity="vectorDoc" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1509
1736
  function vectorDoc(id: string, similarity = 0.8, vt = 'semantic', metadata: any = {}) {
1510
1737
  return {
1511
1738
  document_id: id,
@@ -1515,7 +1742,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1515
1742
  account_id: 'acct-1',
1516
1743
  }
1517
1744
  }
1745
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:vectorDoc:function"]
1518
1746
 
1747
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:setupRetrievalMocks:function" type="function" identity="setupRetrievalMocks" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1519
1748
  function setupRetrievalMocks(opts: { accountError?: any } = {}) {
1520
1749
  const embedding = deferred<any>()
1521
1750
  const lexical = deferred<any>()
@@ -1584,11 +1813,15 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1584
1813
  })
1585
1814
  return { embedding, lexical, rpcCalls, itemsCalls, wasLexicalStarted: () => lexicalStarted }
1586
1815
  }
1816
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:setupRetrievalMocks:function"]
1587
1817
 
1818
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:retrieve:function" type="function" identity="retrieve" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1588
1819
  function retrieve(policy?: any, sources: string[] = []) {
1589
1820
  return retrieveKnowledge('test query', sources, 'acct-1', policy, makeCtx())
1590
1821
  }
1822
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:retrieve:function"]
1591
1823
 
1824
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:startRetrieval:function" type="function" identity="startRetrieval" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1592
1825
  async function startRetrieval(m: ReturnType<typeof setupRetrievalMocks>, policy?: any, sources: string[] = []) {
1593
1826
  const p = retrieve(policy, sources)
1594
1827
  await flush()
@@ -1596,7 +1829,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1596
1829
  await flush()
1597
1830
  return { p }
1598
1831
  }
1832
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:startRetrieval:function"]
1599
1833
 
1834
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:drainRpcs:function" type="function" identity="drainRpcs" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1600
1835
  async function drainRpcs(
1601
1836
  m: ReturnType<typeof setupRetrievalMocks>,
1602
1837
  resolveWith: (args: any) => any = () => ({ data: [], error: null })
@@ -1606,7 +1841,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1606
1841
  await flush()
1607
1842
  }
1608
1843
  }
1844
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:drainRpcs:function"]
1609
1845
 
1846
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:finishRetrieval:function" type="function" identity="finishRetrieval" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1610
1847
  async function finishRetrieval(
1611
1848
  m: ReturnType<typeof setupRetrievalMocks>,
1612
1849
  opts: {
@@ -1625,14 +1862,21 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1625
1862
  }
1626
1863
  await flush()
1627
1864
  }
1865
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:finishRetrieval:function"]
1628
1866
 
1867
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:emittedSpans:function" type="function" identity="emittedSpans" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1629
1868
  function emittedSpans() {
1630
1869
  return vi.mocked(emitSpan).mock.calls.map((c) => c[1])
1631
1870
  }
1871
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:emittedSpans:function"]
1632
1872
 
1633
1873
  it('starts the lexical query before the embedding resolves', async () => {
1874
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1634
1875
  const m = setupRetrievalMocks()
1876
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
1877
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:p:constant" type="constant" identity="p" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1635
1878
  const p = retrieve({ vector_types: ['semantic'] })
1879
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:p:constant"]
1636
1880
  await flush()
1637
1881
 
1638
1882
  expect(m.wasLexicalStarted()).toBe(true)
@@ -1646,8 +1890,12 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1646
1890
  })
1647
1891
 
1648
1892
  it('peaks at 3 active RPCs across five channels and executes each once', async () => {
1893
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1649
1894
  const m = setupRetrievalMocks()
1895
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
1896
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant" type="constant" identity="channels" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1650
1897
  const channels = ['semantic', 'title', 'content', 'keyword', 'caption']
1898
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
1651
1899
  const { p } = await startRetrieval(m, { vector_types: channels })
1652
1900
 
1653
1901
  expect(m.rpcCalls).toHaveLength(3)
@@ -1666,15 +1914,21 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1666
1914
  await finishRetrieval(m, {
1667
1915
  rpcResult: (args) => ({ data: [vectorDoc(`doc-${args.filter_vector_type}`, 0.9, args.filter_vector_type)], error: null }),
1668
1916
  })
1917
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1669
1918
  const res = await p
1919
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1670
1920
  expect(m.rpcCalls).toHaveLength(5)
1671
1921
  expect(new Set(m.rpcCalls.map((c) => c.args.filter_vector_type))).toEqual(new Set(channels))
1672
1922
  expect(res.docs.map((d: any) => d.document_id).sort()).toEqual(channels.map((c) => `doc-${c}`).sort())
1673
1923
  })
1674
1924
 
1675
1925
  it('runs strictly sequentially when max_vector_concurrency is 1', async () => {
1926
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1676
1927
  const m = setupRetrievalMocks()
1928
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
1929
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant" type="constant" identity="channels" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1677
1930
  const channels = ['semantic', 'title', 'content']
1931
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
1678
1932
  const { p } = await startRetrieval(m, { vector_types: channels, max_vector_concurrency: 1 })
1679
1933
 
1680
1934
  expect(m.rpcCalls).toHaveLength(1)
@@ -1690,9 +1944,13 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1690
1944
  })
1691
1945
 
1692
1946
  it('clamps max_vector_concurrency of 0 to sequential and values above 5 to five', async () => {
1947
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant" type="constant" identity="channels" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1693
1948
  const channels = ['semantic', 'title', 'content', 'keyword', 'caption']
1949
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
1694
1950
 
1951
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m0:constant" type="constant" identity="m0" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1695
1952
  const m0 = setupRetrievalMocks()
1953
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m0:constant"]
1696
1954
  const { p: p0 } = await startRetrieval(m0, { vector_types: channels, max_vector_concurrency: 0 })
1697
1955
  expect(m0.rpcCalls).toHaveLength(1)
1698
1956
  m0.rpcCalls[0].deferred.resolve({ data: [], error: null })
@@ -1702,7 +1960,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1702
1960
  await p0
1703
1961
 
1704
1962
  vi.clearAllMocks()
1963
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m9:constant" type="constant" identity="m9" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1705
1964
  const m9 = setupRetrievalMocks()
1965
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m9:constant"]
1706
1966
  const { p: p9 } = await startRetrieval(m9, { vector_types: channels, max_vector_concurrency: 9 })
1707
1967
  expect(m9.rpcCalls).toHaveLength(5)
1708
1968
  await finishRetrieval(m9)
@@ -1710,10 +1970,14 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1710
1970
  })
1711
1971
 
1712
1972
  it('defaults invalid or non-finite max_vector_concurrency to 3', async () => {
1973
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant" type="constant" identity="channels" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1713
1974
  const channels = ['semantic', 'title', 'content', 'keyword', 'caption']
1975
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
1714
1976
  for (const override of [NaN, Infinity, 'fast']) {
1715
1977
  vi.clearAllMocks()
1978
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1716
1979
  const m = setupRetrievalMocks()
1980
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
1717
1981
  const { p } = await startRetrieval(m, { vector_types: channels, max_vector_concurrency: override })
1718
1982
  expect(m.rpcCalls).toHaveLength(3)
1719
1983
  await finishRetrieval(m)
@@ -1722,7 +1986,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1722
1986
  })
1723
1987
 
1724
1988
  it('never starts more workers than channels', async () => {
1989
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1725
1990
  const m = setupRetrievalMocks()
1991
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
1726
1992
  const { p } = await startRetrieval(m, { vector_types: ['semantic', 'title'], max_vector_concurrency: 5 })
1727
1993
  expect(m.rpcCalls).toHaveLength(2)
1728
1994
  await finishRetrieval(m)
@@ -1730,8 +1996,12 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1730
1996
  })
1731
1997
 
1732
1998
  it('preserves configured channel order in output regardless of completion order', async () => {
1999
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1733
2000
  const m = setupRetrievalMocks()
2001
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2002
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant" type="constant" identity="channels" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1734
2003
  const channels = ['semantic', 'title', 'content']
2004
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
1735
2005
  const { p } = await startRetrieval(m, { vector_types: channels })
1736
2006
  expect(m.rpcCalls).toHaveLength(3)
1737
2007
 
@@ -1743,16 +2013,30 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1743
2013
  await flush()
1744
2014
  }
1745
2015
  await finishRetrieval(m)
2016
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1746
2017
  const res = await p
2018
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1747
2019
  expect(res.docs.map((d: any) => d.document_id)).toEqual(['doc-semantic', 'doc-title', 'doc-content'])
1748
2020
  })
1749
2021
 
1750
2022
  it('stops scheduling on a vector error, waits for in-flight work, and returns the shaped lexical fallback', async () => {
2023
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant" type="constant" identity="warn" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1751
2024
  const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
2025
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant"]
2026
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1752
2027
  const m = setupRetrievalMocks()
2028
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2029
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant" type="constant" identity="channels" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1753
2030
  const channels = ['semantic', 'title', 'content', 'keyword', 'caption']
2031
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
2032
+
2033
+
1754
2034
  let settled = false
2035
+
2036
+
2037
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:p:constant" type="constant" identity="p" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1755
2038
  const p = retrieve({ vector_types: channels }).then((r) => { settled = true; return r })
2039
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:p:constant"]
1756
2040
  await flush()
1757
2041
  m.embedding.resolve({ data: [{ embedding: [0.1, 0.2] }] })
1758
2042
  await flush()
@@ -1775,7 +2059,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1775
2059
  expect(m.rpcCalls).toHaveLength(3)
1776
2060
  for (const c of m.itemsCalls) c.deferred.resolve({ data: [], error: null })
1777
2061
 
2062
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1778
2063
  const res = await p
2064
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1779
2065
  expect(settled).toBe(true)
1780
2066
  expect(vi.mocked(adminDb.from).mock.calls.filter((c) => c[0] === 'embeddings')).toHaveLength(1)
1781
2067
  expect(res.docs).toHaveLength(1)
@@ -1787,9 +2073,15 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1787
2073
  })
1788
2074
 
1789
2075
  it('returns the already-running shaped lexical fallback when the embedding fails', async () => {
2076
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant" type="constant" identity="warn" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1790
2077
  const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
2078
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant"]
2079
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1791
2080
  const m = setupRetrievalMocks()
2081
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2082
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:p:constant" type="constant" identity="p" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1792
2083
  const p = retrieve({ vector_types: ['semantic', 'title'] })
2084
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:p:constant"]
1793
2085
  await flush()
1794
2086
  expect(m.wasLexicalStarted()).toBe(true)
1795
2087
 
@@ -1802,7 +2094,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1802
2094
  expect(m.rpcCalls).toHaveLength(0)
1803
2095
  for (const c of m.itemsCalls) c.deferred.resolve({ data: [], error: null })
1804
2096
 
2097
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1805
2098
  const res = await p
2099
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1806
2100
  expect(res.docs).toHaveLength(1)
1807
2101
  expect(res.docs[0].document_id).toBe('lex-2')
1808
2102
  expect(res.docs[0].matched_lexically).toBe(true)
@@ -1810,13 +2104,21 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1810
2104
  })
1811
2105
 
1812
2106
  it('suppresses the fallback warning when the embedding fails with no_api_key', async () => {
2107
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant" type="constant" identity="warn" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1813
2108
  const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
2109
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant"]
2110
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1814
2111
  const m = setupRetrievalMocks()
2112
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2113
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:p:constant" type="constant" identity="p" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1815
2114
  const p = retrieve()
2115
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:p:constant"]
1816
2116
  await flush()
1817
2117
  m.embedding.reject(new Error('no_api_key'))
1818
2118
  m.lexical.resolve({ data: [], error: null })
2119
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1819
2120
  const res = await p
2121
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1820
2122
 
1821
2123
  expect(res).toEqual({ docs: [], meanSimilarity: 0 })
1822
2124
  expect(warn.mock.calls.every((c) => !String(c[0]).includes('vector search failed'))).toBe(true)
@@ -1824,8 +2126,12 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1824
2126
  })
1825
2127
 
1826
2128
  it('returns a shaped, hydrated lexical-only doc when vectors are empty', async () => {
2129
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1827
2130
  const m = setupRetrievalMocks()
2131
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2132
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:lexId:constant" type="constant" identity="lexId" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1828
2133
  const lexId = '123e4567-e89b-42d3-a456-426614174000'
2134
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:lexId:constant"]
1829
2135
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
1830
2136
  m.rpcCalls[0].deferred.resolve({ data: [], error: null })
1831
2137
  m.lexical.resolve({
@@ -1838,9 +2144,13 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1838
2144
  error: null,
1839
2145
  })
1840
2146
 
2147
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1841
2148
  const res = await p
2149
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1842
2150
  expect(res.docs).toHaveLength(1)
2151
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:d:constant" type="constant" identity="d" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1843
2152
  const d = res.docs[0]
2153
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:d:constant"]
1844
2154
  expect(d.similarity).toBe(0)
1845
2155
  expect(d.matched_lexically).toBe(true)
1846
2156
  expect(d.title).toBe('Lex Title')
@@ -1851,10 +2161,18 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1851
2161
  })
1852
2162
 
1853
2163
  it('preserves ordered IDs, flags, content selection, count, and mean for fixed vector+lexical fixtures', async () => {
2164
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1854
2165
  const m = setupRetrievalMocks()
2166
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2167
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:idA:constant" type="constant" identity="idA" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1855
2168
  const idA = '11111111-1111-4111-8111-111111111111'
2169
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idA:constant"]
2170
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:idB:constant" type="constant" identity="idB" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1856
2171
  const idB = '~/.framework/src/foo.ts:Bar:function'
2172
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idB:constant"]
2173
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:idC:constant" type="constant" identity="idC" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1857
2174
  const idC = '33333333-3333-4333-8333-333333333333'
2175
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idC:constant"]
1858
2176
  const { p } = await startRetrieval(m, { vector_types: ['semantic', 'title'] })
1859
2177
 
1860
2178
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc(idA, 0.9, 'semantic')], error: null })
@@ -1881,7 +2199,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1881
2199
  }
1882
2200
  }
1883
2201
 
2202
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1884
2203
  const res = await p
2204
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1885
2205
  expect(res.docs).toHaveLength(3)
1886
2206
  expect(res.docs.map((d: any) => d.document_id)).toEqual([idA, idC, idB])
1887
2207
  expect(res.docs[0].matched_lexically).toBe(false)
@@ -1900,17 +2220,27 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1900
2220
  })
1901
2221
 
1902
2222
  it('starts UUID and stable-ID hydration concurrently and hydrates both regardless of completion order', async () => {
2223
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1903
2224
  const m = setupRetrievalMocks()
2225
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2226
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:idA:constant" type="constant" identity="idA" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1904
2227
  const idA = '11111111-1111-4111-8111-111111111111'
2228
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idA:constant"]
2229
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:idB:constant" type="constant" identity="idB" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1905
2230
  const idB = 'stable-doc-1'
2231
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idB:constant"]
1906
2232
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
1907
2233
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc(idA, 0.9), vectorDoc(idB, 0.8)], error: null })
1908
2234
  m.lexical.resolve({ data: [], error: null })
1909
2235
  await flush()
1910
2236
 
1911
2237
  expect(m.itemsCalls).toHaveLength(2)
2238
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:uuidCall:constant" type="constant" identity="uuidCall" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1912
2239
  const uuidCall = m.itemsCalls.find((c) => c.field === 'id')!
2240
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:uuidCall:constant"]
2241
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:stableCall:constant" type="constant" identity="stableCall" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1913
2242
  const stableCall = m.itemsCalls.find((c) => c.field === 'data->>stable_id')!
2243
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:stableCall:constant"]
1914
2244
  expect(uuidCall.ids).toEqual([idA])
1915
2245
  expect(stableCall.ids).toEqual([idB])
1916
2246
 
@@ -1918,16 +2248,26 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1918
2248
  await flush()
1919
2249
  uuidCall.deferred.resolve({ data: [{ id: idA, title: 'A', data: {} }], error: null })
1920
2250
 
2251
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1921
2252
  const res = await p
2253
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1922
2254
  expect(res.docs.find((d: any) => d.document_id === idA)!.title).toBe('A')
1923
2255
  expect(res.docs.find((d: any) => d.document_id === idB)!.title).toBe('B')
1924
2256
  })
1925
2257
 
1926
2258
  it('degrades a failed hydration branch without discarding documents or the other branch', async () => {
2259
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant" type="constant" identity="warn" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1927
2260
  const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
2261
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant"]
2262
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1928
2263
  const m = setupRetrievalMocks()
2264
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2265
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:idA:constant" type="constant" identity="idA" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1929
2266
  const idA = '11111111-1111-4111-8111-111111111111'
2267
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idA:constant"]
2268
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:idB:constant" type="constant" identity="idB" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1930
2269
  const idB = 'stable-doc-1'
2270
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idB:constant"]
1931
2271
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
1932
2272
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc(idA, 0.9), vectorDoc(idB, 0.8)], error: null })
1933
2273
  m.lexical.resolve({ data: [], error: null })
@@ -1939,18 +2279,26 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1939
2279
  error: null,
1940
2280
  })
1941
2281
 
2282
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1942
2283
  const res = await p
2284
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1943
2285
  expect(res.docs).toHaveLength(2)
1944
2286
  expect(res.docs.find((d: any) => d.document_id === idA)!.title).toBe('')
1945
2287
  expect(res.docs.find((d: any) => d.document_id === idB)!.title).toBe('B')
2288
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:hydSpan:constant" type="constant" identity="hydSpan" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1946
2289
  const hydSpan = emittedSpans().find((s: any) => s.spanName === 'agent.retrieve.hydrate_uuid')
2290
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:hydSpan:constant"]
1947
2291
  expect(hydSpan?.status).toBe('error')
1948
2292
  warn.mockRestore()
1949
2293
  })
1950
2294
 
1951
2295
  it('emits a child span per leg with low-cardinality names and static attributes', async () => {
2296
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1952
2297
  const m = setupRetrievalMocks()
2298
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2299
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:idA:constant" type="constant" identity="idA" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1953
2300
  const idA = '11111111-1111-4111-8111-111111111111'
2301
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idA:constant"]
1954
2302
  const { p } = await startRetrieval(m, { vector_types: ['semantic', 'title'] })
1955
2303
  await drainRpcs(m, () => ({ data: [vectorDoc(idA, 0.9)], error: null }))
1956
2304
  m.lexical.resolve({ data: [], error: null })
@@ -1958,20 +2306,28 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1958
2306
  for (const c of m.itemsCalls) c.deferred.resolve({ data: [], error: null })
1959
2307
  await p
1960
2308
 
2309
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:spans:constant" type="constant" identity="spans" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1961
2310
  const spans = emittedSpans()
2311
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:spans:constant"]
2312
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:names:constant" type="constant" identity="names" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1962
2313
  const names = spans.map((s: any) => s.spanName)
2314
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:names:constant"]
1963
2315
  expect(names).toContain('agent.retrieve_knowledge')
1964
2316
  expect(names).toContain('agent.retrieve.account_scope')
1965
2317
  expect(names).toContain('agent.retrieve.embedding')
1966
2318
  expect(names).toContain('agent.retrieve.lexical')
1967
2319
  expect(names.filter((n: string) => n === 'agent.retrieve.vector')).toHaveLength(2)
2320
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:vectorSpans:constant" type="constant" identity="vectorSpans" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1968
2321
  const vectorSpans = spans.filter((s: any) => s.spanName === 'agent.retrieve.vector')
2322
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:vectorSpans:constant"]
1969
2323
  expect(vectorSpans.map((s: any) => s.attributes.vector_type).sort()).toEqual(['semantic', 'title'])
1970
2324
  for (const s of vectorSpans) {
1971
2325
  expect(s.attributes.match_count).toBe(24)
1972
2326
  expect(s.attributes.project_filter).toBe(false)
1973
2327
  }
2328
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:lexSpan:constant" type="constant" identity="lexSpan" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1974
2329
  const lexSpan = spans.find((s: any) => s.spanName === 'agent.retrieve.lexical')
2330
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:lexSpan:constant"]
1975
2331
  expect(lexSpan?.attributes).toMatchObject({ limit: 8, item_type_count: 0, project_filter: false })
1976
2332
  expect(names).toContain('agent.retrieve.hydrate_uuid')
1977
2333
  expect(names).not.toContain('agent.retrieve.hydrate_stable')
@@ -1979,16 +2335,24 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1979
2335
  })
1980
2336
 
1981
2337
  it('records an error span for a failed vector RPC while degradation continues', async () => {
2338
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant" type="constant" identity="warn" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1982
2339
  const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
2340
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant"]
2341
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1983
2342
  const m = setupRetrievalMocks()
2343
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
1984
2344
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
1985
2345
  m.rpcCalls[0].deferred.resolve({ data: null, error: { message: 'rpc exploded' } })
1986
2346
  m.lexical.resolve({ data: [{ document_id: 'lex-9', content: 'x', metadata: {}, account_id: 'acct-1' }], error: null })
1987
2347
  await flush()
1988
2348
  for (const c of m.itemsCalls) c.deferred.resolve({ data: [], error: null })
1989
2349
 
2350
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1990
2351
  const res = await p
2352
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2353
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:vSpan:constant" type="constant" identity="vSpan" parent="~/.framework/tests/unit/agent-runner.test.ts"]
1991
2354
  const vSpan = emittedSpans().find((s: any) => s.spanName === 'agent.retrieve.vector')
2355
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:vSpan:constant"]
1992
2356
  expect(vSpan?.status).toBe('error')
1993
2357
  expect(String(vSpan?.attributes?.error)).toContain('rpc exploded')
1994
2358
  expect(res.docs).toHaveLength(1)
@@ -1997,34 +2361,48 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1997
2361
  })
1998
2362
 
1999
2363
  it('marks the lexical span as error and keeps vector results when lexical fails', async () => {
2364
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant" type="constant" identity="warn" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2000
2365
  const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
2366
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant"]
2367
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2001
2368
  const m = setupRetrievalMocks()
2369
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2002
2370
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
2003
2371
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc('v1', 0.9)], error: null })
2004
2372
  m.lexical.resolve({ data: null, error: { message: 'fts down' } })
2005
2373
  await flush()
2006
2374
  for (const c of m.itemsCalls) c.deferred.resolve({ data: [], error: null })
2007
2375
 
2376
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2008
2377
  const res = await p
2378
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2009
2379
  expect(res.docs).toHaveLength(1)
2010
2380
  expect(res.docs[0].document_id).toBe('v1')
2381
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:lexSpan:constant" type="constant" identity="lexSpan" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2011
2382
  const lexSpan = emittedSpans().find((s: any) => s.spanName === 'agent.retrieve.lexical')
2383
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:lexSpan:constant"]
2012
2384
  expect(lexSpan?.status).toBe('error')
2013
2385
  warn.mockRestore()
2014
2386
  })
2015
2387
 
2016
2388
  it('skips the summary RPC when the primary vector hit is strong', async () => {
2389
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2017
2390
  const m = setupRetrievalMocks()
2391
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2018
2392
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
2019
2393
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc('d1', 0.9)], error: null })
2020
2394
  await finishRetrieval(m)
2395
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2021
2396
  const res = await p
2397
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2022
2398
  expect(m.rpcCalls).toHaveLength(1)
2023
2399
  expect(res.docs.map((d: any) => d.document_id)).toEqual(['d1'])
2024
2400
  })
2025
2401
 
2026
2402
  it('runs exactly one summary RPC when the primary hit is weak', async () => {
2403
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2027
2404
  const m = setupRetrievalMocks()
2405
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2028
2406
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
2029
2407
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc('weak-1', 0.4)], error: null })
2030
2408
  await flush()
@@ -2034,24 +2412,34 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
2034
2412
 
2035
2413
  m.rpcCalls[1].deferred.resolve({ data: [vectorDoc('sum-1', 0.6)], error: null })
2036
2414
  await finishRetrieval(m)
2415
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2037
2416
  const res = await p
2417
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2038
2418
  expect(res.docs.map((d: any) => d.document_id).sort()).toEqual(['sum-1', 'weak-1'])
2039
2419
  })
2040
2420
 
2041
2421
  it('does not run a duplicate summary RPC when summary is a configured channel', async () => {
2422
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2042
2423
  const m = setupRetrievalMocks()
2424
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2043
2425
  const { p } = await startRetrieval(m, { vector_types: ['semantic', 'summary'] })
2044
2426
  await drainRpcs(m, (args) => ({ data: [vectorDoc(`d-${args.filter_vector_type}`, 0.4, args.filter_vector_type)], error: null }))
2045
2427
  await finishRetrieval(m)
2428
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2046
2429
  const res = await p
2430
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2047
2431
  expect(m.rpcCalls).toHaveLength(2)
2048
2432
  expect(m.rpcCalls.map((c) => c.args.filter_vector_type)).toEqual(['semantic', 'summary'])
2049
2433
  expect(res.docs).toHaveLength(2)
2050
2434
  })
2051
2435
 
2052
2436
  it('keeps primary vectors when the summary RPC fails', async () => {
2437
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant" type="constant" identity="warn" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2053
2438
  const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
2439
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant"]
2440
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2054
2441
  const m = setupRetrievalMocks()
2442
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2055
2443
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
2056
2444
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc('weak-1', 0.4)], error: null })
2057
2445
  await flush()
@@ -2059,16 +2447,24 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
2059
2447
  m.rpcCalls[1].deferred.resolve({ data: null, error: { message: 'summary boom' } })
2060
2448
  await finishRetrieval(m)
2061
2449
 
2450
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2062
2451
  const res = await p
2452
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2063
2453
  expect(res.docs.map((d: any) => d.document_id)).toEqual(['weak-1'])
2454
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:sumSpan:constant" type="constant" identity="sumSpan" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2064
2455
  const sumSpan = emittedSpans().find((s: any) => s.spanName === 'agent.retrieve.summary')
2456
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:sumSpan:constant"]
2065
2457
  expect(sumSpan?.status).toBe('error')
2066
2458
  warn.mockRestore()
2067
2459
  })
2068
2460
 
2069
2461
  it('keeps similarity, security, project, and knowledge-source filtering intact', async () => {
2462
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2070
2463
  const m = setupRetrievalMocks()
2464
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2465
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:allowed:constant" type="constant" identity="allowed" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2071
2466
  const allowed = '44444444-4444-4444-8444-444444444444'
2467
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:allowed:constant"]
2072
2468
  const { p } = await startRetrieval(
2073
2469
  m,
2074
2470
  { vector_types: ['semantic'], project_ids: ['p1'], max_security_level: 'internal' },
@@ -2087,21 +2483,31 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
2087
2483
  error: null,
2088
2484
  })
2089
2485
  await finishRetrieval(m)
2486
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2090
2487
  const res = await p
2488
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2091
2489
  expect(res.docs.map((d: any) => d.document_id)).toEqual([allowed])
2092
2490
  })
2093
2491
 
2094
2492
  it('degrades to account-only scope when the platform account lookup fails', async () => {
2493
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant" type="constant" identity="warn" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2095
2494
  const warn = vi.spyOn(console, 'warn').mockImplementation(() => {})
2495
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:warn:constant"]
2496
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant" type="constant" identity="m" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2096
2497
  const m = setupRetrievalMocks({ accountError: { message: 'accounts down' } })
2498
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2097
2499
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
2098
2500
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc('d1', 0.9)], error: null })
2099
2501
  await finishRetrieval(m)
2100
2502
 
2503
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant" type="constant" identity="res" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2101
2504
  const res = await p
2505
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2102
2506
  expect(m.rpcCalls[0].args.filter_account_ids).toEqual(['acct-1'])
2103
2507
  expect(res.docs).toHaveLength(1)
2508
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:acctSpan:constant" type="constant" identity="acctSpan" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2104
2509
  const acctSpan = emittedSpans().find((s: any) => s.spanName === 'agent.retrieve.account_scope')
2510
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:acctSpan:constant"]
2105
2511
  expect(acctSpan?.status).toBe('error')
2106
2512
  warn.mockRestore()
2107
2513
  })
@@ -2112,9 +2518,7 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
2112
2518
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
2113
2519
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
2114
2520
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
2115
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_retrieveKnowledge_concurrentRetrieval:block"]
2116
2521
 
2117
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_sendNotificationRoleRecipients:block" type="block" identity="describe_executeToolAction_sendNotificationRoleRecipients" parent="none"]
2118
2522
  // CIL[DOC-MACRO purpose="Test executeToolAction send_notification role:<slug> recipient resolution"]
2119
2523
  // CIL[DOC-RESPONSIBILITY responsibility="Verify the agent-runner notification writer resolves role: handles to account-scoped people ids and passes UUIDs through before the notifications insert"]
2120
2524
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/notify.ts,.framework/functions/_shared/agent-runner.ts,.framework/tests/unit/agent-runner.test.ts"]
@@ -2127,6 +2531,7 @@ describe('executeToolAction — send_notification role:<slug> recipients', () =>
2127
2531
  vi.spyOn(console, 'warn').mockImplementation(() => {})
2128
2532
  })
2129
2533
 
2534
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockNotifyTables:function" type="function" identity="mockNotifyTables" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2130
2535
  function mockNotifyTables(peopleRows: any[] | null, insertCapture: { rows?: any[] }) {
2131
2536
  const peopleQ: any = {
2132
2537
  select: vi.fn(() => peopleQ),
@@ -2155,16 +2560,21 @@ describe('executeToolAction — send_notification role:<slug> recipients', () =>
2155
2560
  } as any
2156
2561
  })
2157
2562
  }
2563
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockNotifyTables:function"]
2158
2564
 
2159
2565
  it('resolves role:member_admin to the account’s people ids', async () => {
2566
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:cap:constant" type="constant" identity="cap" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2160
2567
  const cap: { rows?: any[] } = {}
2568
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:cap:constant"]
2161
2569
  mockNotifyTables([{ id: 'admin-1' }, { id: 'admin-2' }], cap)
2162
2570
 
2571
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2163
2572
  const result = await executeToolAction(
2164
2573
  { handler: 'send_notification', handler_module: 'functions' },
2165
2574
  { message: 'Escalated', recipients: ['role:member_admin'], entity_type: 'threads' },
2166
2575
  makeCtx()
2167
2576
  )
2577
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
2168
2578
 
2169
2579
  expect(result.notified_count).toBe(2)
2170
2580
  expect(cap.rows!.map((r: any) => r.person_id)).toEqual(['admin-1', 'admin-2'])
@@ -2173,29 +2583,39 @@ describe('executeToolAction — send_notification role:<slug> recipients', () =>
2173
2583
  })
2174
2584
 
2175
2585
  it('passes UUID recipients through alongside resolved roles', async () => {
2586
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:cap:constant" type="constant" identity="cap" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2176
2587
  const cap: { rows?: any[] } = {}
2588
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:cap:constant"]
2589
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:uuid:constant" type="constant" identity="uuid" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2177
2590
  const uuid = '22222222-2222-4222-8222-222222222222'
2591
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:uuid:constant"]
2178
2592
  mockNotifyTables([{ id: 'admin-1' }], cap)
2179
2593
 
2594
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2180
2595
  const result = await executeToolAction(
2181
2596
  { handler: 'send_notification', handler_module: 'functions' },
2182
2597
  { message: 'Escalated', recipients: [uuid, 'role:member_admin'] },
2183
2598
  makeCtx()
2184
2599
  )
2600
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
2185
2601
 
2186
2602
  expect(result.notified_count).toBe(2)
2187
2603
  expect(cap.rows!.map((r: any) => r.person_id)).toEqual([uuid, 'admin-1'])
2188
2604
  })
2189
2605
 
2190
2606
  it('an unknown role is a valid zero-notification result, not an error', async () => {
2607
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:cap:constant" type="constant" identity="cap" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2191
2608
  const cap: { rows?: any[] } = {}
2609
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:cap:constant"]
2192
2610
  mockNotifyTables([], cap)
2193
2611
 
2612
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2194
2613
  const result = await executeToolAction(
2195
2614
  { handler: 'send_notification', handler_module: 'functions' },
2196
2615
  { message: 'Escalated', recipients: ['role:no_such_role'] },
2197
2616
  makeCtx()
2198
2617
  )
2618
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
2199
2619
 
2200
2620
  expect(result.notified_count).toBe(0)
2201
2621
  expect(cap.rows).toBeUndefined()
@@ -2203,7 +2623,9 @@ describe('executeToolAction — send_notification role:<slug> recipients', () =>
2203
2623
  })
2204
2624
 
2205
2625
  it('never writes a literal role: string into person_id', async () => {
2626
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:cap:constant" type="constant" identity="cap" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2206
2627
  const cap: { rows?: any[] } = {}
2628
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:cap:constant"]
2207
2629
  mockNotifyTables([{ id: 'admin-1' }], cap)
2208
2630
 
2209
2631
  await executeToolAction(
@@ -2217,9 +2639,7 @@ describe('executeToolAction — send_notification role:<slug> recipients', () =>
2217
2639
  }
2218
2640
  })
2219
2641
  })
2220
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_sendNotificationRoleRecipients:block"]
2221
2642
 
2222
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_denyCilRetrievalPolicy:block" type="block" identity="describe_denyCilRetrievalPolicy" parent="none"]
2223
2643
  // CIL[DOC-MACRO purpose="Test the retrieval_policy.deny_cil kill switch"]
2224
2644
  // CIL[DOC-RESPONSIBILITY responsibility="Verify a denied prompt config resolves zero CIL tools, skips thread cil_config augmentation, and dispatchTools rejects built-in CIL calls — while the non-deny path stays unchanged"]
2225
2645
  // CIL[DOC-CONTEXT module="tests/unit/agent-runner" layer="test-unit" related_files=".framework/functions/_shared/agent-runner.ts,custom/apps/demo/seed/prompt-configs.json"]
@@ -2234,16 +2654,22 @@ describe('deny_cil retrieval policy', () => {
2234
2654
  // built-ins search_knowledge, ask_user, and escalate_to_human — denying
2235
2655
  // those would break ordinary agents (e.g. demo triage), so they must
2236
2656
  // survive a denied agent's resolved tool set.
2657
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:CIL_NAMES:constant" type="constant" identity="CIL_NAMES" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2237
2658
  const CIL_NAMES = [
2238
2659
  'cil_chunk_lookup', 'cil_get_contract', 'cil_blast_radius', 'cil_hash_validate',
2239
2660
  'cil_project_status', 'cil_fetch_document',
2240
2661
  ]
2662
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:CIL_NAMES:constant"]
2663
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:GENERIC_BUILTIN_NAMES:constant" type="constant" identity="GENERIC_BUILTIN_NAMES" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2241
2664
  const GENERIC_BUILTIN_NAMES = ['search_knowledge', 'ask_user', 'escalate_to_human']
2665
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:GENERIC_BUILTIN_NAMES:constant"]
2666
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:cilThreadData:constant" type="constant" identity="cilThreadData" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2242
2667
  const cilThreadData = {
2243
2668
  agent_id: AGENT_ID,
2244
2669
  prompt_config_id: PROMPT_CONFIG_ID,
2245
2670
  cil_config: { enabled: true, use_cil_tools: true, project_ids: ['proj-a'] },
2246
2671
  }
2672
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:cilThreadData:constant"]
2247
2673
 
2248
2674
  it('resolves zero CIL tools and no cil_config merge when denied', async () => {
2249
2675
  setupAgentConfigMocks(
@@ -2260,9 +2686,13 @@ describe('deny_cil retrieval policy', () => {
2260
2686
  }
2261
2687
  )
2262
2688
 
2689
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2263
2690
  const config = await resolveAgentConfig(THREAD_ID, makeCtx())
2691
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
2264
2692
 
2693
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:toolNames:constant" type="constant" identity="toolNames" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2265
2694
  const toolNames = (config?.agent.model_config.tools || []).map((t: any) => t.function?.name)
2695
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:toolNames:constant"]
2266
2696
  for (const name of CIL_NAMES) {
2267
2697
  expect(toolNames).not.toContain(name)
2268
2698
  expect(config?.promptConfig.available_tools).not.toContain(name)
@@ -2287,9 +2717,13 @@ describe('deny_cil retrieval policy', () => {
2287
2717
  { available_tools: [], metadata: {} }
2288
2718
  )
2289
2719
 
2720
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2290
2721
  const config = await resolveAgentConfig(THREAD_ID, makeCtx())
2722
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
2291
2723
 
2724
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:toolNames:constant" type="constant" identity="toolNames" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2292
2725
  const toolNames = (config?.agent.model_config.tools || []).map((t: any) => t.function?.name)
2726
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:toolNames:constant"]
2293
2727
  expect(toolNames).toContain('cil_chunk_lookup')
2294
2728
  expect(toolNames).toContain('ask_user') // multi-turn default still applies
2295
2729
  expect(config?.promptConfig.metadata.cil_config).toEqual(cilThreadData.cil_config)
@@ -2312,17 +2746,23 @@ describe('deny_cil retrieval policy', () => {
2312
2746
  })
2313
2747
  mockCreateRecord({ id: 'msg-tool' })
2314
2748
 
2749
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2315
2750
  const config = {
2316
2751
  agent: mockAgent(),
2317
2752
  promptConfig: mockPromptConfig({ metadata: { retrieval_policy: { deny_cil: true } } }),
2318
2753
  thread: mockThread(),
2319
2754
  threadType: { slug: 'support_thread' }
2320
2755
  }
2756
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
2321
2757
 
2758
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2322
2759
  const result = await runAgentStep(THREAD_ID, 'Where is design_schema?', makeCtx(), config)
2760
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
2323
2761
 
2324
2762
  expect(result.state.status).toBe('gathering')
2763
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:toolResult:constant" type="constant" identity="toolResult" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2325
2764
  const toolResult = result.state.gathered_results.find((r: any) => r.tool === 'cil_chunk_lookup')
2765
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:toolResult:constant"]
2326
2766
  expect(toolResult?.error).toBe('Tool "cil_chunk_lookup" is not permitted by the retrieval policy')
2327
2767
  expect(createRecord).toHaveBeenCalledWith(
2328
2768
  expect.any(Object),
@@ -2341,6 +2781,7 @@ describe('deny_cil retrieval policy', () => {
2341
2781
  // executeCilChunkLookup chains .filter().in().eq().or().limit() on the
2342
2782
  // items builder — the generic mock lacks .or, so give items a thenable
2343
2783
  // builder that resolves an empty result set.
2784
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:itemsQ:constant" type="constant" identity="itemsQ" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2344
2785
  const itemsQ: any = {
2345
2786
  select: vi.fn(() => itemsQ),
2346
2787
  filter: vi.fn(() => itemsQ),
@@ -2350,7 +2791,10 @@ describe('deny_cil retrieval policy', () => {
2350
2791
  limit: vi.fn(() => itemsQ),
2351
2792
  then: (onF: any, onR: any) => Promise.resolve({ data: [], error: null }).then(onF, onR),
2352
2793
  }
2794
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:itemsQ:constant"]
2795
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:baseImpl:constant" type="constant" identity="baseImpl" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2353
2796
  const baseImpl = vi.mocked(adminDb.from).getMockImplementation()!
2797
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:baseImpl:constant"]
2354
2798
  vi.mocked(adminDb.from).mockImplementation((table: string) => {
2355
2799
  if (table === 'items') return itemsQ
2356
2800
  return baseImpl(table)
@@ -2369,6 +2813,7 @@ describe('deny_cil retrieval policy', () => {
2369
2813
  })
2370
2814
  mockCreateRecord({ id: 'msg-tool' })
2371
2815
 
2816
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant" type="constant" identity="config" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2372
2817
  const config = {
2373
2818
  agent: mockAgent(),
2374
2819
  promptConfig: mockPromptConfig({
@@ -2377,13 +2822,17 @@ describe('deny_cil retrieval policy', () => {
2377
2822
  thread: mockThread(),
2378
2823
  threadType: { slug: 'support_thread' }
2379
2824
  }
2825
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
2380
2826
 
2827
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant" type="constant" identity="result" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2381
2828
  const result = await runAgentStep(THREAD_ID, 'Where is design_schema?', makeCtx(), config)
2829
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
2382
2830
 
2831
+ // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:toolResult:constant" type="constant" identity="toolResult" parent="~/.framework/tests/unit/agent-runner.test.ts"]
2383
2832
  const toolResult = result.state.gathered_results.find((r: any) => r.tool === 'cil_chunk_lookup')
2833
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:toolResult:constant"]
2384
2834
  expect(toolResult).toBeDefined()
2385
2835
  expect(toolResult?.error).toBeUndefined()
2386
2836
  expect(toolResult?.result).toEqual({ results: [], count: 0 })
2387
2837
  })
2388
2838
  })
2389
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_denyCilRetrievalPolicy:block"]