spine-framework 0.4.4 → 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 (283) 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/hash-api-key.ts +183 -79
  15. package/.framework/functions/_shared/logging.ts +562 -224
  16. package/.framework/functions/_shared/middleware.ts +47 -44
  17. package/.framework/functions/admin-data.ts +39 -28
  18. package/.framework/functions/ai-agents.ts +10 -6
  19. package/.framework/functions/api-keys.ts +301 -122
  20. package/.framework/functions/apps.ts +43 -26
  21. package/.framework/functions/cil-ingest.ts +48 -15
  22. package/.framework/functions/debug-auth.ts +14 -8
  23. package/.framework/functions/deliveries.ts +39 -12
  24. package/.framework/functions/embeddings.ts +145 -76
  25. package/.framework/functions/integration-outbound.ts +67 -27
  26. package/.framework/functions/integrations.ts +254 -127
  27. package/.framework/functions/logs.ts +273 -133
  28. package/.framework/functions/observability.ts +277 -147
  29. package/.framework/functions/pipeline-executions.ts +1 -1
  30. package/.framework/functions/pipelines.ts +14 -9
  31. package/.framework/functions/prompt-configs.ts +7 -4
  32. package/.framework/functions/roles.ts +8 -5
  33. package/.framework/functions/security.ts +30 -17
  34. package/.framework/functions/system-cron.ts +240 -127
  35. package/.framework/functions/tests.ts +7 -6
  36. package/.framework/functions/timers.ts +310 -107
  37. package/.framework/functions/triggers.ts +28 -13
  38. package/.framework/functions/types.ts +13 -10
  39. package/.framework/migrations/069_log_stats_window.sql +54 -0
  40. package/.framework/migrations/070_app_type_schema_rpcs.sql +166 -0
  41. package/.framework/migrations/071_timer_interval_keys.sql +96 -0
  42. package/.framework/migrations/072_slug_autofill.sql +77 -0
  43. package/.framework/migrations/073_seed_member_roles.sql +26 -0
  44. package/.framework/src/apps/admin/index.tsx +1141 -775
  45. package/.framework/src/components/ErrorBoundary.tsx +136 -0
  46. package/.framework/src/components/admin/AdminListPage.tsx +81 -73
  47. package/.framework/src/components/admin/AdminSidebar.tsx +88 -79
  48. package/.framework/src/components/admin/EntitySelect.tsx +181 -0
  49. package/.framework/src/components/admin/PageInstructions.tsx +86 -127
  50. package/.framework/src/components/app-shell/GenericDetailPage.tsx +37 -13
  51. package/.framework/src/components/app-shell/GenericListPage.tsx +28 -32
  52. package/.framework/src/components/layout/Sidebar.tsx +300 -177
  53. package/.framework/src/components/runtime/DataDetailPage.tsx +67 -35
  54. package/.framework/src/components/runtime/DataHeader.tsx +96 -48
  55. package/.framework/src/components/runtime/DataListPage.tsx +3 -26
  56. package/.framework/src/components/runtime/DataStats.tsx +10 -10
  57. package/.framework/src/components/runtime/DataTable.tsx +12 -10
  58. package/.framework/src/components/ui/sheet.tsx +24 -26
  59. package/.framework/src/components/ui/textarea.tsx +74 -48
  60. package/.framework/src/hooks/useEntityList.ts +12 -9
  61. package/.framework/src/hooks/useListSchema.ts +108 -58
  62. package/.framework/src/instructions/README.md +57 -0
  63. package/.framework/src/instructions/ai-agents.md +69 -0
  64. package/.framework/src/instructions/alerts.md +80 -0
  65. package/.framework/src/instructions/api-keys.md +87 -0
  66. package/.framework/src/instructions/apps.md +77 -0
  67. package/.framework/src/instructions/concepts/ai-and-prompts.md +150 -0
  68. package/.framework/src/instructions/concepts/apps-and-renderers.md +162 -0
  69. package/.framework/src/instructions/concepts/auth-and-api-keys.md +133 -0
  70. package/.framework/src/instructions/concepts/automation.md +186 -0
  71. package/.framework/src/instructions/concepts/concurrency-and-idempotency.md +125 -0
  72. package/.framework/src/instructions/concepts/core-vs-custom.md +124 -0
  73. package/.framework/src/instructions/concepts/design-schema.md +152 -0
  74. package/.framework/src/instructions/concepts/integrations-and-webhooks.md +127 -0
  75. package/.framework/src/instructions/concepts/observability.md +116 -0
  76. package/.framework/src/instructions/concepts/permissions.md +150 -0
  77. package/.framework/src/instructions/concepts/runtime-records.md +111 -0
  78. package/.framework/src/instructions/concepts/scope-and-accounts.md +112 -0
  79. package/.framework/src/instructions/concepts/spine-way.md +172 -0
  80. package/.framework/src/instructions/deliveries.md +59 -0
  81. package/.framework/src/instructions/guide/00-orientation.md +106 -0
  82. package/.framework/src/instructions/guide/01-install-and-first-run.md +253 -0
  83. package/.framework/src/instructions/guide/02-project-map.md +147 -0
  84. package/.framework/src/instructions/guide/03-domain-model.md +223 -0
  85. package/.framework/src/instructions/guide/04-first-app.md +227 -0
  86. package/.framework/src/instructions/guide/05-glossary.md +183 -0
  87. package/.framework/src/instructions/integrations.md +96 -0
  88. package/.framework/src/instructions/internal/cil-markers.md +83 -0
  89. package/.framework/src/instructions/invites.md +60 -0
  90. package/.framework/src/instructions/kb.md +80 -0
  91. package/.framework/src/instructions/logs.md +77 -0
  92. package/.framework/src/instructions/observability.md +61 -0
  93. package/.framework/src/instructions/operations/deployment.md +115 -0
  94. package/.framework/src/instructions/operations/migrations.md +125 -0
  95. package/.framework/src/instructions/operations/security-checklist.md +148 -0
  96. package/.framework/src/instructions/operations/troubleshooting.md +170 -0
  97. package/.framework/src/instructions/operations/upgrade.md +116 -0
  98. package/.framework/src/instructions/pipeline-executions.md +62 -0
  99. package/.framework/src/instructions/pipelines.md +78 -0
  100. package/.framework/src/instructions/prompts.md +95 -0
  101. package/.framework/src/instructions/reference/api/admin-data.md +162 -0
  102. package/.framework/src/instructions/reference/api/auth.md +113 -0
  103. package/.framework/src/instructions/reference/api/errors-and-envelopes.md +113 -0
  104. package/.framework/src/instructions/reference/app-manifest.md +150 -0
  105. package/.framework/src/instructions/reference/cli.md +124 -0
  106. package/.framework/src/instructions/reference/database.md +132 -0
  107. package/.framework/src/instructions/reference/design-schema.md +280 -0
  108. package/.framework/src/instructions/reference/env-vars.md +133 -0
  109. package/.framework/src/instructions/reference/functions/account-nodes.md +75 -0
  110. package/.framework/src/instructions/reference/functions/admin-data.md +195 -0
  111. package/.framework/src/instructions/reference/functions/admin-funnel.md +90 -0
  112. package/.framework/src/instructions/reference/functions/admin-install-funnel.md +107 -0
  113. package/.framework/src/instructions/reference/functions/admin-signals.md +102 -0
  114. package/.framework/src/instructions/reference/functions/ai-agents.md +148 -0
  115. package/.framework/src/instructions/reference/functions/ai-interactions.md +156 -0
  116. package/.framework/src/instructions/reference/functions/api-keys.md +130 -0
  117. package/.framework/src/instructions/reference/functions/apps.md +140 -0
  118. package/.framework/src/instructions/reference/functions/auth.md +99 -0
  119. package/.framework/src/instructions/reference/functions/debug-auth.md +91 -0
  120. package/.framework/src/instructions/reference/functions/deliveries.md +110 -0
  121. package/.framework/src/instructions/reference/functions/embeddings.md +166 -0
  122. package/.framework/src/instructions/reference/functions/eval-harness.md +149 -0
  123. package/.framework/src/instructions/reference/functions/index.md +103 -0
  124. package/.framework/src/instructions/reference/functions/integration-outbound.md +200 -0
  125. package/.framework/src/instructions/reference/functions/integration-routes.md +151 -0
  126. package/.framework/src/instructions/reference/functions/integrations.md +130 -0
  127. package/.framework/src/instructions/reference/functions/invites.md +182 -0
  128. package/.framework/src/instructions/reference/functions/item-progress.md +107 -0
  129. package/.framework/src/instructions/reference/functions/kb.md +166 -0
  130. package/.framework/src/instructions/reference/functions/logs.md +141 -0
  131. package/.framework/src/instructions/reference/functions/observability.md +105 -0
  132. package/.framework/src/instructions/reference/functions/pipeline-executions.md +132 -0
  133. package/.framework/src/instructions/reference/functions/pipeline-runner-background.md +121 -0
  134. package/.framework/src/instructions/reference/functions/pipelines.md +136 -0
  135. package/.framework/src/instructions/reference/functions/prompt-configs.md +121 -0
  136. package/.framework/src/instructions/reference/functions/roles.md +121 -0
  137. package/.framework/src/instructions/reference/functions/security.md +140 -0
  138. package/.framework/src/instructions/reference/functions/system-cron.md +136 -0
  139. package/.framework/src/instructions/reference/functions/system.md +106 -0
  140. package/.framework/src/instructions/reference/functions/tests.md +97 -0
  141. package/.framework/src/instructions/reference/functions/timers.md +117 -0
  142. package/.framework/src/instructions/reference/functions/trigger-scheduler.md +102 -0
  143. package/.framework/src/instructions/reference/functions/triggers.md +140 -0
  144. package/.framework/src/instructions/reference/functions/types.md +146 -0
  145. package/.framework/src/instructions/reference/seeds.md +126 -0
  146. package/.framework/src/instructions/reference/shared-modules.md +127 -0
  147. package/.framework/src/instructions/reference/spine-config.md +114 -0
  148. package/.framework/src/instructions/roles.md +80 -0
  149. package/.framework/src/instructions/runtime-detail.md +70 -0
  150. package/.framework/src/instructions/runtime-list.md +77 -0
  151. package/.framework/src/instructions/security.md +67 -0
  152. package/.framework/src/instructions/tasks/add-a-pipeline.md +110 -0
  153. package/.framework/src/instructions/tasks/add-a-role.md +96 -0
  154. package/.framework/src/instructions/tasks/add-a-timer.md +114 -0
  155. package/.framework/src/instructions/tasks/add-a-trigger.md +106 -0
  156. package/.framework/src/instructions/tasks/add-a-type.md +151 -0
  157. package/.framework/src/instructions/tasks/add-a-webhook.md +108 -0
  158. package/.framework/src/instructions/tasks/add-an-ai-agent.md +108 -0
  159. package/.framework/src/instructions/tasks/add-an-integration.md +124 -0
  160. package/.framework/src/instructions/tasks/build-a-custom-page.md +118 -0
  161. package/.framework/src/instructions/tasks/package-and-install-an-app.md +127 -0
  162. package/.framework/src/instructions/tasks/test-your-code.md +108 -0
  163. package/.framework/src/instructions/tasks/write-a-function.md +132 -0
  164. package/.framework/src/instructions/tasks/write-a-migration.md +110 -0
  165. package/.framework/src/instructions/testing.md +59 -0
  166. package/.framework/src/instructions/timers.md +82 -0
  167. package/.framework/src/instructions/triggers.md +69 -0
  168. package/.framework/src/instructions/types.md +93 -0
  169. package/.framework/src/pages/NotFoundPage.tsx +62 -31
  170. package/.framework/src/pages/admin/AIAgentDetailPage.tsx +117 -106
  171. package/.framework/src/pages/admin/AIAgentsPage.tsx +86 -48
  172. package/.framework/src/pages/admin/APIKeyDetailPage.tsx +153 -152
  173. package/.framework/src/pages/admin/APIKeysPage.tsx +91 -90
  174. package/.framework/src/pages/admin/AlertsConfigPage.tsx +29 -18
  175. package/.framework/src/pages/admin/AppDetailPage.tsx +6 -60
  176. package/.framework/src/pages/admin/AppsPage.tsx +104 -66
  177. package/.framework/src/pages/admin/DeliveriesPage.tsx +5 -5
  178. package/.framework/src/pages/admin/EmbeddingDetailPage.tsx +5 -23
  179. package/.framework/src/pages/admin/EmbeddingsPage.tsx +5 -26
  180. package/.framework/src/pages/admin/IntegrationDetailPage.tsx +7 -7
  181. package/.framework/src/pages/admin/IntegrationsPage.tsx +85 -43
  182. package/.framework/src/pages/admin/LogsPage.tsx +144 -76
  183. package/.framework/src/pages/admin/ObservabilityDashboard.tsx +223 -140
  184. package/.framework/src/pages/admin/PipelineDetailPage.tsx +134 -113
  185. package/.framework/src/pages/admin/PipelineExecutionsPage.tsx +108 -45
  186. package/.framework/src/pages/admin/PipelinesPage.tsx +160 -115
  187. package/.framework/src/pages/admin/PromptConfigDetailPage.tsx +96 -98
  188. package/.framework/src/pages/admin/PromptConfigsPage.tsx +101 -59
  189. package/.framework/src/pages/admin/RoleDetailPage.tsx +90 -79
  190. package/.framework/src/pages/admin/RolesPage.tsx +86 -43
  191. package/.framework/src/pages/admin/SecurityPage.tsx +1 -1
  192. package/.framework/src/pages/admin/TestingDashboard.tsx +16 -28
  193. package/.framework/src/pages/admin/TimerDetailPage.tsx +117 -100
  194. package/.framework/src/pages/admin/TimersPage.tsx +90 -62
  195. package/.framework/src/pages/admin/TriggerDetailPage.tsx +90 -83
  196. package/.framework/src/pages/admin/TriggersPage.tsx +124 -99
  197. package/.framework/src/pages/admin/TypeDetailPage.tsx +152 -138
  198. package/.framework/src/pages/admin/TypesPage.tsx +90 -48
  199. package/.framework/src/pages/admin/cil/CILAgentPage.tsx +17 -25
  200. package/.framework/src/pages/admin/cil/CILChunkDetailPage.tsx +17 -27
  201. package/.framework/src/pages/admin/cil/CILDashboardPage.tsx +72 -40
  202. package/.framework/src/pages/admin/cil/CILFileListPage.tsx +321 -129
  203. package/.framework/src/pages/admin/cil/CILFileSelectPage.tsx +18 -29
  204. package/.framework/src/pages/admin/cil/CILGraphPage.tsx +26 -38
  205. package/.framework/src/pages/admin/cil/CILIngestionPage.tsx +34 -46
  206. package/.framework/src/pages/admin/cil/CILProjectsPage.tsx +189 -103
  207. package/.framework/src/pages/admin/cil/CILSearchPage.tsx +246 -136
  208. package/.framework/src/pages/admin/cil/CILSuggestionsPage.tsx +11 -22
  209. package/.framework/src/pages/admin/cil/CILVersionsPage.tsx +9 -20
  210. package/.framework/src/pages/admin/cil/FlexiblePipelinePage.tsx +26 -38
  211. package/.framework/src/pages/admin/kb/KBAdminPage.tsx +7 -26
  212. package/.framework/templates/agent/AGENTS.md +150 -0
  213. package/.framework/templates/agent/skills/spine-add-ai-agent/SKILL.md +58 -0
  214. package/.framework/templates/agent/skills/spine-add-automation/SKILL.md +62 -0
  215. package/.framework/templates/agent/skills/spine-add-integration/SKILL.md +63 -0
  216. package/.framework/templates/agent/skills/spine-architect/SKILL.md +86 -0
  217. package/.framework/templates/agent/skills/spine-install-app/SKILL.md +72 -0
  218. package/.framework/templates/agent/skills/spine-migration/SKILL.md +75 -0
  219. package/.framework/templates/agent/skills/spine-new-app/SKILL.md +67 -0
  220. package/.framework/templates/agent/skills/spine-new-function/SKILL.md +65 -0
  221. package/.framework/templates/agent/skills/spine-new-type/SKILL.md +65 -0
  222. package/.framework/templates/agent/skills/spine-schema/SKILL.md +77 -0
  223. package/.framework/templates/agent/skills/spine-test/SKILL.md +67 -0
  224. package/.framework/templates/agent/skills/spine-troubleshoot/SKILL.md +74 -0
  225. package/.framework/templates/agent/skills/spine-upgrade/SKILL.md +69 -0
  226. package/.framework/templates/project.json +4 -1
  227. package/.framework/tests/unit/account-scoping-gates.test.ts +392 -0
  228. package/.framework/tests/unit/agent-files.test.ts +355 -0
  229. package/.framework/tests/unit/agent-runner.test.ts +479 -44
  230. package/.framework/tests/unit/api-keys-create-scope-gate.test.ts +160 -0
  231. package/.framework/tests/unit/api-keys-omit-secret-fields.test.ts +38 -0
  232. package/.framework/tests/unit/bootstrap.test.ts +242 -0
  233. package/.framework/tests/unit/cli-context-api-key.test.ts +114 -0
  234. package/.framework/tests/unit/debug-auth.test.ts +38 -0
  235. package/.framework/tests/unit/deliveries-account-scoping.test.ts +185 -0
  236. package/.framework/tests/unit/integration-outbound-credentials.test.ts +167 -0
  237. package/.framework/tests/unit/integrations-audit-redaction.test.ts +130 -0
  238. package/.framework/tests/unit/logging-app-id.test.ts +75 -0
  239. package/.framework/tests/unit/system-context-denial.test.ts +145 -0
  240. package/.framework/tests/unit/system-cron.test.ts +240 -0
  241. package/.framework/tests/unit/timers.test.ts +159 -0
  242. package/README.md +125 -166
  243. package/config/tsconfig.cli.json +2 -2
  244. package/package.json +15 -4
  245. package/templates/project/package-lock.json +2 -2
  246. package/.framework/docs/admin-routes.md +0 -76
  247. package/.framework/docs/api-docs-progress.md +0 -38
  248. package/.framework/docs/api-governance.md +0 -146
  249. package/.framework/docs/api-testing-results.md +0 -212
  250. package/.framework/docs/assembly-launch-guide.md +0 -138
  251. package/.framework/docs/audit-results.md +0 -590
  252. package/.framework/docs/db-api-inventory.md +0 -95
  253. package/.framework/docs/gap-remediation-backlog.md +0 -103
  254. package/.framework/docs/ui-adoption-verification.md +0 -111
  255. package/.framework/docs/ui-api-coverage.md +0 -84
  256. package/.framework/docs/v2-compatibility-audit.md +0 -228
  257. package/.framework/mcp/index.ts +0 -133
  258. package/.framework/mcp/load-env.ts +0 -60
  259. package/.framework/mcp/shared/app-manifest.ts +0 -275
  260. package/.framework/mcp/shared/db.ts +0 -477
  261. package/.framework/mcp/shared/kb.ts +0 -118
  262. package/.framework/mcp/tools/architect.ts +0 -431
  263. package/.framework/mcp/tools/cil/context.ts +0 -345
  264. package/.framework/mcp/tools/cil/graph.ts +0 -242
  265. package/.framework/mcp/tools/cil/ingest.ts +0 -1217
  266. package/.framework/mcp/tools/cil/pipeline-orchestrator.ts +0 -693
  267. package/.framework/mcp/tools/cil/pipeline.ts +0 -767
  268. package/.framework/mcp/tools/cil/project.ts +0 -791
  269. package/.framework/mcp/tools/cil/retrieval.ts +0 -336
  270. package/.framework/mcp/tools/cil/search-core.ts +0 -454
  271. package/.framework/mcp/tools/cil/search.ts +0 -97
  272. package/.framework/mcp/tools/cil/suggest.ts +0 -186
  273. package/.framework/mcp/tools/cil/validate.ts +0 -1369
  274. package/.framework/mcp/tools/kb/delete.ts +0 -139
  275. package/.framework/mcp/tools/kb/index.ts +0 -52
  276. package/.framework/mcp/tools/kb/ingest.ts +0 -84
  277. package/.framework/mcp/tools/kb/list-types.ts +0 -102
  278. package/.framework/mcp/tools/kb/publish.ts +0 -100
  279. package/.framework/mcp/tools/kb/reindex.ts +0 -86
  280. package/.framework/mcp/tools/kb/revoke.ts +0 -85
  281. package/.framework/mcp/tools/kb/search.ts +0 -101
  282. package/.framework/mcp/tools/kb/upsert.ts +0 -125
  283. 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,6 +1558,7 @@ describe('executeToolAction — cil_chunk_lookup code content search', () => {
1370
1558
  describe('executeToolAction — escalate_to_human', () => {
1371
1559
  beforeEach(() => vi.clearAllMocks())
1372
1560
 
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"]
1373
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) => {
@@ -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,14 +1599,18 @@ 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({
@@ -1428,28 +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"]
1439
1639
 
1440
1640
  expect(res.already_escalated).toBe(true)
1441
1641
  expect(updates).toHaveLength(0)
1442
1642
  })
1443
1643
 
1444
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"]
1445
1646
  const updates = mockEscalationFlow({ owner: 'human' })
1647
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:updates:constant"]
1446
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"]
1447
1650
  const res = await executeToolAction(
1448
1651
  { handler: 'escalate_to_human' },
1449
1652
  { reason: 'still stuck' },
1450
1653
  makeCtx(),
1451
1654
  { threadId: THREAD_ID, config: escConfig }
1452
1655
  )
1656
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1453
1657
 
1454
1658
  expect(res.already_escalated).toBe(true)
1455
1659
  expect(updates).toHaveLength(0)
@@ -1461,9 +1665,7 @@ describe('executeToolAction — escalate_to_human', () => {
1461
1665
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1462
1666
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1463
1667
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1464
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_escalateToHuman:block"]
1465
1668
 
1466
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_resolveAgentConfig_escalateToHumanWiring:block" type="block" identity="describe_resolveAgentConfig_escalateToHumanWiring" parent="none"]
1467
1669
  // CIL[DOC-MACRO purpose="Test resolveAgentConfig escalate_to_human wiring"]
1468
1670
  // CIL[DOC-RESPONSIBILITY responsibility="Verify the escalate_to_human tool is offered only when the prompt config sets an escalation_action"]
1469
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"]
@@ -1477,18 +1679,26 @@ describe('resolveAgentConfig — escalate_to_human wiring', () => {
1477
1679
  it('offers escalate_to_human when the prompt config has an escalation_action', async () => {
1478
1680
  setupAgentConfigMocks({}, {}, { escalation_action: 'pipeline', available_tools: [] })
1479
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"]
1480
1683
  const config = await resolveAgentConfig(THREAD_ID, makeCtx())
1684
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
1481
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"]
1482
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"]
1483
1689
  expect(names).toContain('escalate_to_human')
1484
1690
  })
1485
1691
 
1486
1692
  it('does not offer escalate_to_human without an escalation_action', async () => {
1487
1693
  setupAgentConfigMocks({}, {}, { escalation_action: null, available_tools: [] })
1488
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"]
1489
1696
  const config = await resolveAgentConfig(THREAD_ID, makeCtx())
1697
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
1490
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"]
1491
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"]
1492
1702
  expect(names).not.toContain('escalate_to_human')
1493
1703
  })
1494
1704
  })
@@ -1498,9 +1708,7 @@ describe('resolveAgentConfig — escalate_to_human wiring', () => {
1498
1708
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
1499
1709
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
1500
1710
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
1501
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_resolveAgentConfig_escalateToHumanWiring:block"]
1502
1711
 
1503
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_retrieveKnowledge_concurrentRetrieval:block" type="block" identity="describe_retrieveKnowledge_concurrentRetrieval" parent="none"]
1504
1712
  // CIL[DOC-MACRO purpose="Verify retrieveKnowledge concurrent retrieval semantics"]
1505
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"]
1506
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"]
@@ -1511,15 +1719,20 @@ describe('resolveAgentConfig — escalate_to_human wiring', () => {
1511
1719
  describe('retrieveKnowledge — concurrent retrieval', () => {
1512
1720
  beforeEach(() => vi.clearAllMocks())
1513
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"]
1514
1723
  function deferred<T>() {
1515
1724
  let resolve!: (value: T) => void
1516
1725
  let reject!: (error: any) => void
1517
1726
  const promise = new Promise<T>((res, rej) => { resolve = res; reject = rej })
1518
1727
  return { promise, resolve, reject }
1519
1728
  }
1729
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:deferred:function"]
1520
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"]
1521
1732
  const flush = () => new Promise<void>((r) => setImmediate(r))
1733
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:flush:function"]
1522
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"]
1523
1736
  function vectorDoc(id: string, similarity = 0.8, vt = 'semantic', metadata: any = {}) {
1524
1737
  return {
1525
1738
  document_id: id,
@@ -1529,7 +1742,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1529
1742
  account_id: 'acct-1',
1530
1743
  }
1531
1744
  }
1745
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:vectorDoc:function"]
1532
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"]
1533
1748
  function setupRetrievalMocks(opts: { accountError?: any } = {}) {
1534
1749
  const embedding = deferred<any>()
1535
1750
  const lexical = deferred<any>()
@@ -1598,11 +1813,15 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1598
1813
  })
1599
1814
  return { embedding, lexical, rpcCalls, itemsCalls, wasLexicalStarted: () => lexicalStarted }
1600
1815
  }
1816
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:setupRetrievalMocks:function"]
1601
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"]
1602
1819
  function retrieve(policy?: any, sources: string[] = []) {
1603
1820
  return retrieveKnowledge('test query', sources, 'acct-1', policy, makeCtx())
1604
1821
  }
1822
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:retrieve:function"]
1605
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"]
1606
1825
  async function startRetrieval(m: ReturnType<typeof setupRetrievalMocks>, policy?: any, sources: string[] = []) {
1607
1826
  const p = retrieve(policy, sources)
1608
1827
  await flush()
@@ -1610,7 +1829,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1610
1829
  await flush()
1611
1830
  return { p }
1612
1831
  }
1832
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:startRetrieval:function"]
1613
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"]
1614
1835
  async function drainRpcs(
1615
1836
  m: ReturnType<typeof setupRetrievalMocks>,
1616
1837
  resolveWith: (args: any) => any = () => ({ data: [], error: null })
@@ -1620,7 +1841,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1620
1841
  await flush()
1621
1842
  }
1622
1843
  }
1844
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:drainRpcs:function"]
1623
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"]
1624
1847
  async function finishRetrieval(
1625
1848
  m: ReturnType<typeof setupRetrievalMocks>,
1626
1849
  opts: {
@@ -1639,14 +1862,21 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1639
1862
  }
1640
1863
  await flush()
1641
1864
  }
1865
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:finishRetrieval:function"]
1642
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"]
1643
1868
  function emittedSpans() {
1644
1869
  return vi.mocked(emitSpan).mock.calls.map((c) => c[1])
1645
1870
  }
1871
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:emittedSpans:function"]
1646
1872
 
1647
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"]
1648
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"]
1649
1878
  const p = retrieve({ vector_types: ['semantic'] })
1879
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:p:constant"]
1650
1880
  await flush()
1651
1881
 
1652
1882
  expect(m.wasLexicalStarted()).toBe(true)
@@ -1660,8 +1890,12 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1660
1890
  })
1661
1891
 
1662
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"]
1663
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"]
1664
1897
  const channels = ['semantic', 'title', 'content', 'keyword', 'caption']
1898
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
1665
1899
  const { p } = await startRetrieval(m, { vector_types: channels })
1666
1900
 
1667
1901
  expect(m.rpcCalls).toHaveLength(3)
@@ -1680,15 +1914,21 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1680
1914
  await finishRetrieval(m, {
1681
1915
  rpcResult: (args) => ({ data: [vectorDoc(`doc-${args.filter_vector_type}`, 0.9, args.filter_vector_type)], error: null }),
1682
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"]
1683
1918
  const res = await p
1919
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1684
1920
  expect(m.rpcCalls).toHaveLength(5)
1685
1921
  expect(new Set(m.rpcCalls.map((c) => c.args.filter_vector_type))).toEqual(new Set(channels))
1686
1922
  expect(res.docs.map((d: any) => d.document_id).sort()).toEqual(channels.map((c) => `doc-${c}`).sort())
1687
1923
  })
1688
1924
 
1689
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"]
1690
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"]
1691
1930
  const channels = ['semantic', 'title', 'content']
1931
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
1692
1932
  const { p } = await startRetrieval(m, { vector_types: channels, max_vector_concurrency: 1 })
1693
1933
 
1694
1934
  expect(m.rpcCalls).toHaveLength(1)
@@ -1704,9 +1944,13 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1704
1944
  })
1705
1945
 
1706
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"]
1707
1948
  const channels = ['semantic', 'title', 'content', 'keyword', 'caption']
1949
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
1708
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"]
1709
1952
  const m0 = setupRetrievalMocks()
1953
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m0:constant"]
1710
1954
  const { p: p0 } = await startRetrieval(m0, { vector_types: channels, max_vector_concurrency: 0 })
1711
1955
  expect(m0.rpcCalls).toHaveLength(1)
1712
1956
  m0.rpcCalls[0].deferred.resolve({ data: [], error: null })
@@ -1716,7 +1960,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1716
1960
  await p0
1717
1961
 
1718
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"]
1719
1964
  const m9 = setupRetrievalMocks()
1965
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m9:constant"]
1720
1966
  const { p: p9 } = await startRetrieval(m9, { vector_types: channels, max_vector_concurrency: 9 })
1721
1967
  expect(m9.rpcCalls).toHaveLength(5)
1722
1968
  await finishRetrieval(m9)
@@ -1724,10 +1970,14 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1724
1970
  })
1725
1971
 
1726
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"]
1727
1974
  const channels = ['semantic', 'title', 'content', 'keyword', 'caption']
1975
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
1728
1976
  for (const override of [NaN, Infinity, 'fast']) {
1729
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"]
1730
1979
  const m = setupRetrievalMocks()
1980
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
1731
1981
  const { p } = await startRetrieval(m, { vector_types: channels, max_vector_concurrency: override })
1732
1982
  expect(m.rpcCalls).toHaveLength(3)
1733
1983
  await finishRetrieval(m)
@@ -1736,7 +1986,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1736
1986
  })
1737
1987
 
1738
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"]
1739
1990
  const m = setupRetrievalMocks()
1991
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
1740
1992
  const { p } = await startRetrieval(m, { vector_types: ['semantic', 'title'], max_vector_concurrency: 5 })
1741
1993
  expect(m.rpcCalls).toHaveLength(2)
1742
1994
  await finishRetrieval(m)
@@ -1744,8 +1996,12 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1744
1996
  })
1745
1997
 
1746
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"]
1747
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"]
1748
2003
  const channels = ['semantic', 'title', 'content']
2004
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
1749
2005
  const { p } = await startRetrieval(m, { vector_types: channels })
1750
2006
  expect(m.rpcCalls).toHaveLength(3)
1751
2007
 
@@ -1757,16 +2013,30 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1757
2013
  await flush()
1758
2014
  }
1759
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"]
1760
2017
  const res = await p
2018
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1761
2019
  expect(res.docs.map((d: any) => d.document_id)).toEqual(['doc-semantic', 'doc-title', 'doc-content'])
1762
2020
  })
1763
2021
 
1764
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"]
1765
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"]
1766
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"]
1767
2030
  const channels = ['semantic', 'title', 'content', 'keyword', 'caption']
2031
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:channels:constant"]
2032
+
2033
+
1768
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"]
1769
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"]
1770
2040
  await flush()
1771
2041
  m.embedding.resolve({ data: [{ embedding: [0.1, 0.2] }] })
1772
2042
  await flush()
@@ -1789,7 +2059,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1789
2059
  expect(m.rpcCalls).toHaveLength(3)
1790
2060
  for (const c of m.itemsCalls) c.deferred.resolve({ data: [], error: null })
1791
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"]
1792
2063
  const res = await p
2064
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1793
2065
  expect(settled).toBe(true)
1794
2066
  expect(vi.mocked(adminDb.from).mock.calls.filter((c) => c[0] === 'embeddings')).toHaveLength(1)
1795
2067
  expect(res.docs).toHaveLength(1)
@@ -1801,9 +2073,15 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1801
2073
  })
1802
2074
 
1803
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"]
1804
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"]
1805
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"]
1806
2083
  const p = retrieve({ vector_types: ['semantic', 'title'] })
2084
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:p:constant"]
1807
2085
  await flush()
1808
2086
  expect(m.wasLexicalStarted()).toBe(true)
1809
2087
 
@@ -1816,7 +2094,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1816
2094
  expect(m.rpcCalls).toHaveLength(0)
1817
2095
  for (const c of m.itemsCalls) c.deferred.resolve({ data: [], error: null })
1818
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"]
1819
2098
  const res = await p
2099
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1820
2100
  expect(res.docs).toHaveLength(1)
1821
2101
  expect(res.docs[0].document_id).toBe('lex-2')
1822
2102
  expect(res.docs[0].matched_lexically).toBe(true)
@@ -1824,13 +2104,21 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1824
2104
  })
1825
2105
 
1826
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"]
1827
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"]
1828
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"]
1829
2114
  const p = retrieve()
2115
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:p:constant"]
1830
2116
  await flush()
1831
2117
  m.embedding.reject(new Error('no_api_key'))
1832
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"]
1833
2120
  const res = await p
2121
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1834
2122
 
1835
2123
  expect(res).toEqual({ docs: [], meanSimilarity: 0 })
1836
2124
  expect(warn.mock.calls.every((c) => !String(c[0]).includes('vector search failed'))).toBe(true)
@@ -1838,8 +2126,12 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1838
2126
  })
1839
2127
 
1840
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"]
1841
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"]
1842
2133
  const lexId = '123e4567-e89b-42d3-a456-426614174000'
2134
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:lexId:constant"]
1843
2135
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
1844
2136
  m.rpcCalls[0].deferred.resolve({ data: [], error: null })
1845
2137
  m.lexical.resolve({
@@ -1852,9 +2144,13 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1852
2144
  error: null,
1853
2145
  })
1854
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"]
1855
2148
  const res = await p
2149
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1856
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"]
1857
2152
  const d = res.docs[0]
2153
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:d:constant"]
1858
2154
  expect(d.similarity).toBe(0)
1859
2155
  expect(d.matched_lexically).toBe(true)
1860
2156
  expect(d.title).toBe('Lex Title')
@@ -1865,10 +2161,18 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1865
2161
  })
1866
2162
 
1867
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"]
1868
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"]
1869
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"]
1870
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"]
1871
2174
  const idC = '33333333-3333-4333-8333-333333333333'
2175
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idC:constant"]
1872
2176
  const { p } = await startRetrieval(m, { vector_types: ['semantic', 'title'] })
1873
2177
 
1874
2178
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc(idA, 0.9, 'semantic')], error: null })
@@ -1895,7 +2199,9 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1895
2199
  }
1896
2200
  }
1897
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"]
1898
2203
  const res = await p
2204
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1899
2205
  expect(res.docs).toHaveLength(3)
1900
2206
  expect(res.docs.map((d: any) => d.document_id)).toEqual([idA, idC, idB])
1901
2207
  expect(res.docs[0].matched_lexically).toBe(false)
@@ -1914,17 +2220,27 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1914
2220
  })
1915
2221
 
1916
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"]
1917
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"]
1918
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"]
1919
2230
  const idB = 'stable-doc-1'
2231
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idB:constant"]
1920
2232
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
1921
2233
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc(idA, 0.9), vectorDoc(idB, 0.8)], error: null })
1922
2234
  m.lexical.resolve({ data: [], error: null })
1923
2235
  await flush()
1924
2236
 
1925
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"]
1926
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"]
1927
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"]
1928
2244
  expect(uuidCall.ids).toEqual([idA])
1929
2245
  expect(stableCall.ids).toEqual([idB])
1930
2246
 
@@ -1932,16 +2248,26 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1932
2248
  await flush()
1933
2249
  uuidCall.deferred.resolve({ data: [{ id: idA, title: 'A', data: {} }], error: null })
1934
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"]
1935
2252
  const res = await p
2253
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1936
2254
  expect(res.docs.find((d: any) => d.document_id === idA)!.title).toBe('A')
1937
2255
  expect(res.docs.find((d: any) => d.document_id === idB)!.title).toBe('B')
1938
2256
  })
1939
2257
 
1940
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"]
1941
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"]
1942
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"]
1943
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"]
1944
2269
  const idB = 'stable-doc-1'
2270
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idB:constant"]
1945
2271
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
1946
2272
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc(idA, 0.9), vectorDoc(idB, 0.8)], error: null })
1947
2273
  m.lexical.resolve({ data: [], error: null })
@@ -1953,18 +2279,26 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1953
2279
  error: null,
1954
2280
  })
1955
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"]
1956
2283
  const res = await p
2284
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
1957
2285
  expect(res.docs).toHaveLength(2)
1958
2286
  expect(res.docs.find((d: any) => d.document_id === idA)!.title).toBe('')
1959
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"]
1960
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"]
1961
2291
  expect(hydSpan?.status).toBe('error')
1962
2292
  warn.mockRestore()
1963
2293
  })
1964
2294
 
1965
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"]
1966
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"]
1967
2300
  const idA = '11111111-1111-4111-8111-111111111111'
2301
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:idA:constant"]
1968
2302
  const { p } = await startRetrieval(m, { vector_types: ['semantic', 'title'] })
1969
2303
  await drainRpcs(m, () => ({ data: [vectorDoc(idA, 0.9)], error: null }))
1970
2304
  m.lexical.resolve({ data: [], error: null })
@@ -1972,20 +2306,28 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1972
2306
  for (const c of m.itemsCalls) c.deferred.resolve({ data: [], error: null })
1973
2307
  await p
1974
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"]
1975
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"]
1976
2313
  const names = spans.map((s: any) => s.spanName)
2314
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:names:constant"]
1977
2315
  expect(names).toContain('agent.retrieve_knowledge')
1978
2316
  expect(names).toContain('agent.retrieve.account_scope')
1979
2317
  expect(names).toContain('agent.retrieve.embedding')
1980
2318
  expect(names).toContain('agent.retrieve.lexical')
1981
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"]
1982
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"]
1983
2323
  expect(vectorSpans.map((s: any) => s.attributes.vector_type).sort()).toEqual(['semantic', 'title'])
1984
2324
  for (const s of vectorSpans) {
1985
2325
  expect(s.attributes.match_count).toBe(24)
1986
2326
  expect(s.attributes.project_filter).toBe(false)
1987
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"]
1988
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"]
1989
2331
  expect(lexSpan?.attributes).toMatchObject({ limit: 8, item_type_count: 0, project_filter: false })
1990
2332
  expect(names).toContain('agent.retrieve.hydrate_uuid')
1991
2333
  expect(names).not.toContain('agent.retrieve.hydrate_stable')
@@ -1993,16 +2335,24 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
1993
2335
  })
1994
2336
 
1995
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"]
1996
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"]
1997
2342
  const m = setupRetrievalMocks()
2343
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
1998
2344
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
1999
2345
  m.rpcCalls[0].deferred.resolve({ data: null, error: { message: 'rpc exploded' } })
2000
2346
  m.lexical.resolve({ data: [{ document_id: 'lex-9', content: 'x', metadata: {}, account_id: 'acct-1' }], error: null })
2001
2347
  await flush()
2002
2348
  for (const c of m.itemsCalls) c.deferred.resolve({ data: [], error: null })
2003
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"]
2004
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"]
2005
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"]
2006
2356
  expect(vSpan?.status).toBe('error')
2007
2357
  expect(String(vSpan?.attributes?.error)).toContain('rpc exploded')
2008
2358
  expect(res.docs).toHaveLength(1)
@@ -2011,34 +2361,48 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
2011
2361
  })
2012
2362
 
2013
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"]
2014
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"]
2015
2368
  const m = setupRetrievalMocks()
2369
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2016
2370
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
2017
2371
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc('v1', 0.9)], error: null })
2018
2372
  m.lexical.resolve({ data: null, error: { message: 'fts down' } })
2019
2373
  await flush()
2020
2374
  for (const c of m.itemsCalls) c.deferred.resolve({ data: [], error: null })
2021
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"]
2022
2377
  const res = await p
2378
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2023
2379
  expect(res.docs).toHaveLength(1)
2024
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"]
2025
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"]
2026
2384
  expect(lexSpan?.status).toBe('error')
2027
2385
  warn.mockRestore()
2028
2386
  })
2029
2387
 
2030
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"]
2031
2390
  const m = setupRetrievalMocks()
2391
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2032
2392
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
2033
2393
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc('d1', 0.9)], error: null })
2034
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"]
2035
2396
  const res = await p
2397
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2036
2398
  expect(m.rpcCalls).toHaveLength(1)
2037
2399
  expect(res.docs.map((d: any) => d.document_id)).toEqual(['d1'])
2038
2400
  })
2039
2401
 
2040
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"]
2041
2404
  const m = setupRetrievalMocks()
2405
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2042
2406
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
2043
2407
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc('weak-1', 0.4)], error: null })
2044
2408
  await flush()
@@ -2048,24 +2412,34 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
2048
2412
 
2049
2413
  m.rpcCalls[1].deferred.resolve({ data: [vectorDoc('sum-1', 0.6)], error: null })
2050
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"]
2051
2416
  const res = await p
2417
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2052
2418
  expect(res.docs.map((d: any) => d.document_id).sort()).toEqual(['sum-1', 'weak-1'])
2053
2419
  })
2054
2420
 
2055
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"]
2056
2423
  const m = setupRetrievalMocks()
2424
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2057
2425
  const { p } = await startRetrieval(m, { vector_types: ['semantic', 'summary'] })
2058
2426
  await drainRpcs(m, (args) => ({ data: [vectorDoc(`d-${args.filter_vector_type}`, 0.4, args.filter_vector_type)], error: null }))
2059
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"]
2060
2429
  const res = await p
2430
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2061
2431
  expect(m.rpcCalls).toHaveLength(2)
2062
2432
  expect(m.rpcCalls.map((c) => c.args.filter_vector_type)).toEqual(['semantic', 'summary'])
2063
2433
  expect(res.docs).toHaveLength(2)
2064
2434
  })
2065
2435
 
2066
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"]
2067
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"]
2068
2441
  const m = setupRetrievalMocks()
2442
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2069
2443
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
2070
2444
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc('weak-1', 0.4)], error: null })
2071
2445
  await flush()
@@ -2073,16 +2447,24 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
2073
2447
  m.rpcCalls[1].deferred.resolve({ data: null, error: { message: 'summary boom' } })
2074
2448
  await finishRetrieval(m)
2075
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"]
2076
2451
  const res = await p
2452
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2077
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"]
2078
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"]
2079
2457
  expect(sumSpan?.status).toBe('error')
2080
2458
  warn.mockRestore()
2081
2459
  })
2082
2460
 
2083
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"]
2084
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"]
2085
2466
  const allowed = '44444444-4444-4444-8444-444444444444'
2467
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:allowed:constant"]
2086
2468
  const { p } = await startRetrieval(
2087
2469
  m,
2088
2470
  { vector_types: ['semantic'], project_ids: ['p1'], max_security_level: 'internal' },
@@ -2101,21 +2483,31 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
2101
2483
  error: null,
2102
2484
  })
2103
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"]
2104
2487
  const res = await p
2488
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2105
2489
  expect(res.docs.map((d: any) => d.document_id)).toEqual([allowed])
2106
2490
  })
2107
2491
 
2108
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"]
2109
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"]
2110
2497
  const m = setupRetrievalMocks({ accountError: { message: 'accounts down' } })
2498
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:m:constant"]
2111
2499
  const { p } = await startRetrieval(m, { vector_types: ['semantic'] })
2112
2500
  m.rpcCalls[0].deferred.resolve({ data: [vectorDoc('d1', 0.9)], error: null })
2113
2501
  await finishRetrieval(m)
2114
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"]
2115
2504
  const res = await p
2505
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:res:constant"]
2116
2506
  expect(m.rpcCalls[0].args.filter_account_ids).toEqual(['acct-1'])
2117
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"]
2118
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"]
2119
2511
  expect(acctSpan?.status).toBe('error')
2120
2512
  warn.mockRestore()
2121
2513
  })
@@ -2126,9 +2518,7 @@ describe('retrieveKnowledge — concurrent retrieval', () => {
2126
2518
  // CIL[DOC-VECTOR type="constraint" content="Standard runtime; no special invariants documented"]
2127
2519
  // CIL[DOC-VECTOR type="implementation_pattern" content="" status="pending_human_input"]
2128
2520
  // CIL[DOC-VECTOR type="user_journey" content="" status="pending_human_input"]
2129
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_retrieveKnowledge_concurrentRetrieval:block"]
2130
2521
 
2131
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_sendNotificationRoleRecipients:block" type="block" identity="describe_executeToolAction_sendNotificationRoleRecipients" parent="none"]
2132
2522
  // CIL[DOC-MACRO purpose="Test executeToolAction send_notification role:<slug> recipient resolution"]
2133
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"]
2134
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"]
@@ -2141,6 +2531,7 @@ describe('executeToolAction — send_notification role:<slug> recipients', () =>
2141
2531
  vi.spyOn(console, 'warn').mockImplementation(() => {})
2142
2532
  })
2143
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"]
2144
2535
  function mockNotifyTables(peopleRows: any[] | null, insertCapture: { rows?: any[] }) {
2145
2536
  const peopleQ: any = {
2146
2537
  select: vi.fn(() => peopleQ),
@@ -2169,16 +2560,21 @@ describe('executeToolAction — send_notification role:<slug> recipients', () =>
2169
2560
  } as any
2170
2561
  })
2171
2562
  }
2563
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:mockNotifyTables:function"]
2172
2564
 
2173
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"]
2174
2567
  const cap: { rows?: any[] } = {}
2568
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:cap:constant"]
2175
2569
  mockNotifyTables([{ id: 'admin-1' }, { id: 'admin-2' }], cap)
2176
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"]
2177
2572
  const result = await executeToolAction(
2178
2573
  { handler: 'send_notification', handler_module: 'functions' },
2179
2574
  { message: 'Escalated', recipients: ['role:member_admin'], entity_type: 'threads' },
2180
2575
  makeCtx()
2181
2576
  )
2577
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
2182
2578
 
2183
2579
  expect(result.notified_count).toBe(2)
2184
2580
  expect(cap.rows!.map((r: any) => r.person_id)).toEqual(['admin-1', 'admin-2'])
@@ -2187,29 +2583,39 @@ describe('executeToolAction — send_notification role:<slug> recipients', () =>
2187
2583
  })
2188
2584
 
2189
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"]
2190
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"]
2191
2590
  const uuid = '22222222-2222-4222-8222-222222222222'
2591
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:uuid:constant"]
2192
2592
  mockNotifyTables([{ id: 'admin-1' }], cap)
2193
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"]
2194
2595
  const result = await executeToolAction(
2195
2596
  { handler: 'send_notification', handler_module: 'functions' },
2196
2597
  { message: 'Escalated', recipients: [uuid, 'role:member_admin'] },
2197
2598
  makeCtx()
2198
2599
  )
2600
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
2199
2601
 
2200
2602
  expect(result.notified_count).toBe(2)
2201
2603
  expect(cap.rows!.map((r: any) => r.person_id)).toEqual([uuid, 'admin-1'])
2202
2604
  })
2203
2605
 
2204
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"]
2205
2608
  const cap: { rows?: any[] } = {}
2609
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:cap:constant"]
2206
2610
  mockNotifyTables([], cap)
2207
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"]
2208
2613
  const result = await executeToolAction(
2209
2614
  { handler: 'send_notification', handler_module: 'functions' },
2210
2615
  { message: 'Escalated', recipients: ['role:no_such_role'] },
2211
2616
  makeCtx()
2212
2617
  )
2618
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:result:constant"]
2213
2619
 
2214
2620
  expect(result.notified_count).toBe(0)
2215
2621
  expect(cap.rows).toBeUndefined()
@@ -2217,7 +2623,9 @@ describe('executeToolAction — send_notification role:<slug> recipients', () =>
2217
2623
  })
2218
2624
 
2219
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"]
2220
2627
  const cap: { rows?: any[] } = {}
2628
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:cap:constant"]
2221
2629
  mockNotifyTables([{ id: 'admin-1' }], cap)
2222
2630
 
2223
2631
  await executeToolAction(
@@ -2231,9 +2639,7 @@ describe('executeToolAction — send_notification role:<slug> recipients', () =>
2231
2639
  }
2232
2640
  })
2233
2641
  })
2234
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_executeToolAction_sendNotificationRoleRecipients:block"]
2235
2642
 
2236
- // CIL[BEGIN stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_denyCilRetrievalPolicy:block" type="block" identity="describe_denyCilRetrievalPolicy" parent="none"]
2237
2643
  // CIL[DOC-MACRO purpose="Test the retrieval_policy.deny_cil kill switch"]
2238
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"]
2239
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"]
@@ -2248,16 +2654,22 @@ describe('deny_cil retrieval policy', () => {
2248
2654
  // built-ins search_knowledge, ask_user, and escalate_to_human — denying
2249
2655
  // those would break ordinary agents (e.g. demo triage), so they must
2250
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"]
2251
2658
  const CIL_NAMES = [
2252
2659
  'cil_chunk_lookup', 'cil_get_contract', 'cil_blast_radius', 'cil_hash_validate',
2253
2660
  'cil_project_status', 'cil_fetch_document',
2254
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"]
2255
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"]
2256
2667
  const cilThreadData = {
2257
2668
  agent_id: AGENT_ID,
2258
2669
  prompt_config_id: PROMPT_CONFIG_ID,
2259
2670
  cil_config: { enabled: true, use_cil_tools: true, project_ids: ['proj-a'] },
2260
2671
  }
2672
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:cilThreadData:constant"]
2261
2673
 
2262
2674
  it('resolves zero CIL tools and no cil_config merge when denied', async () => {
2263
2675
  setupAgentConfigMocks(
@@ -2274,9 +2686,13 @@ describe('deny_cil retrieval policy', () => {
2274
2686
  }
2275
2687
  )
2276
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"]
2277
2690
  const config = await resolveAgentConfig(THREAD_ID, makeCtx())
2691
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
2278
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"]
2279
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"]
2280
2696
  for (const name of CIL_NAMES) {
2281
2697
  expect(toolNames).not.toContain(name)
2282
2698
  expect(config?.promptConfig.available_tools).not.toContain(name)
@@ -2301,9 +2717,13 @@ describe('deny_cil retrieval policy', () => {
2301
2717
  { available_tools: [], metadata: {} }
2302
2718
  )
2303
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"]
2304
2721
  const config = await resolveAgentConfig(THREAD_ID, makeCtx())
2722
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
2305
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"]
2306
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"]
2307
2727
  expect(toolNames).toContain('cil_chunk_lookup')
2308
2728
  expect(toolNames).toContain('ask_user') // multi-turn default still applies
2309
2729
  expect(config?.promptConfig.metadata.cil_config).toEqual(cilThreadData.cil_config)
@@ -2326,17 +2746,23 @@ describe('deny_cil retrieval policy', () => {
2326
2746
  })
2327
2747
  mockCreateRecord({ id: 'msg-tool' })
2328
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"]
2329
2750
  const config = {
2330
2751
  agent: mockAgent(),
2331
2752
  promptConfig: mockPromptConfig({ metadata: { retrieval_policy: { deny_cil: true } } }),
2332
2753
  thread: mockThread(),
2333
2754
  threadType: { slug: 'support_thread' }
2334
2755
  }
2756
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
2335
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"]
2336
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"]
2337
2761
 
2338
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"]
2339
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"]
2340
2766
  expect(toolResult?.error).toBe('Tool "cil_chunk_lookup" is not permitted by the retrieval policy')
2341
2767
  expect(createRecord).toHaveBeenCalledWith(
2342
2768
  expect.any(Object),
@@ -2355,6 +2781,7 @@ describe('deny_cil retrieval policy', () => {
2355
2781
  // executeCilChunkLookup chains .filter().in().eq().or().limit() on the
2356
2782
  // items builder — the generic mock lacks .or, so give items a thenable
2357
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"]
2358
2785
  const itemsQ: any = {
2359
2786
  select: vi.fn(() => itemsQ),
2360
2787
  filter: vi.fn(() => itemsQ),
@@ -2364,7 +2791,10 @@ describe('deny_cil retrieval policy', () => {
2364
2791
  limit: vi.fn(() => itemsQ),
2365
2792
  then: (onF: any, onR: any) => Promise.resolve({ data: [], error: null }).then(onF, onR),
2366
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"]
2367
2796
  const baseImpl = vi.mocked(adminDb.from).getMockImplementation()!
2797
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:baseImpl:constant"]
2368
2798
  vi.mocked(adminDb.from).mockImplementation((table: string) => {
2369
2799
  if (table === 'items') return itemsQ
2370
2800
  return baseImpl(table)
@@ -2383,6 +2813,7 @@ describe('deny_cil retrieval policy', () => {
2383
2813
  })
2384
2814
  mockCreateRecord({ id: 'msg-tool' })
2385
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"]
2386
2817
  const config = {
2387
2818
  agent: mockAgent(),
2388
2819
  promptConfig: mockPromptConfig({
@@ -2391,13 +2822,17 @@ describe('deny_cil retrieval policy', () => {
2391
2822
  thread: mockThread(),
2392
2823
  threadType: { slug: 'support_thread' }
2393
2824
  }
2825
+ // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:config:constant"]
2394
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"]
2395
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"]
2396
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"]
2397
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"]
2398
2834
  expect(toolResult).toBeDefined()
2399
2835
  expect(toolResult?.error).toBeUndefined()
2400
2836
  expect(toolResult?.result).toEqual({ results: [], count: 0 })
2401
2837
  })
2402
2838
  })
2403
- // CIL[END stable_id="~/.framework/tests/unit/agent-runner.test.ts:describe_denyCilRetrievalPolicy:block"]