From 4f2419f7b25d1da1c4ce1824a6c88d753b549bda Mon Sep 17 00:00:00 2001 From: Dotta Date: Thu, 9 Jul 2026 18:05:23 +0000 Subject: [PATCH] Materialize built-in bundles after approval Co-Authored-By: Paperclip --- server/src/__tests__/built-in-agents.test.ts | 8 +++++++- server/src/services/approvals.ts | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/server/src/__tests__/built-in-agents.test.ts b/server/src/__tests__/built-in-agents.test.ts index 3f74b37a4dc..336bb207ac2 100644 --- a/server/src/__tests__/built-in-agents.test.ts +++ b/server/src/__tests__/built-in-agents.test.ts @@ -591,13 +591,19 @@ describeEmbeddedPostgres("built-in agents", () => { }); await approvalService(db).approve(approval.id, "board-user", "Approved Reflection Coach"); - await expect(builtInAgentService(db).get(companyId, "reflection-coach")).resolves.toMatchObject({ + const approvedState = await builtInAgentService(db).get(companyId, "reflection-coach"); + expect(approvedState).toMatchObject({ agent: { permissions: { builtInMutationPolicy: mutationPolicy, }, }, }); + expect(approvedState.resources.map((resource) => resource.stockStatus)).toEqual([ + "stock_current", + "stock_current", + "stock_current", + ]); await reconcileBuiltInAgentsOnStartup(db); const agentRows = await db.select().from(agents).where(eq(agents.companyId, companyId)); diff --git a/server/src/services/approvals.ts b/server/src/services/approvals.ts index 832f0dce7e0..a8a2ebac0fd 100644 --- a/server/src/services/approvals.ts +++ b/server/src/services/approvals.ts @@ -24,6 +24,13 @@ export function approvalService(db: Db) { }; } + async function reconcileApprovedBuiltInAgent(companyId: string, payload: Record) { + const sourceBuiltInAgentKey = typeof payload.sourceBuiltInAgentKey === "string" ? payload.sourceBuiltInAgentKey : null; + if (!sourceBuiltInAgentKey) return; + const { builtInAgentService } = await import("./built-in-agents.js"); + await builtInAgentService(db).ensure(companyId, sourceBuiltInAgentKey); + } + async function getExistingApproval(id: string) { const existing = await db .select() @@ -129,6 +136,7 @@ export function approvalService(db: Db) { const payloadAgentId = typeof payload.agentId === "string" ? payload.agentId : null; if (payloadAgentId) { await agentsSvc.activatePendingApproval(payloadAgentId, payload); + await reconcileApprovedBuiltInAgent(updated.companyId, payload); hireApprovedAgentId = payloadAgentId; } else { const created = await agentsSvc.create(updated.companyId, {