diff --git a/server/src/__tests__/agent-skills-routes.test.ts b/server/src/__tests__/agent-skills-routes.test.ts index 129075c9..dfa794f9 100644 --- a/server/src/__tests__/agent-skills-routes.test.ts +++ b/server/src/__tests__/agent-skills-routes.test.ts @@ -234,6 +234,7 @@ describe.sequential("agent skill routes", () => { mockAdapter.syncSkills.mockReset(); mockSyncInstructionsBundleConfigFromFilePath.mockImplementation((_agent, config) => config); mockGetTelemetryClient.mockReturnValue({ track: vi.fn() }); + let persistedAgent: Record | null = null; mockAgentService.resolveByReference.mockResolvedValue({ ambiguous: false, agent: makeAgent("claude_local"), @@ -272,18 +273,26 @@ describe.sequential("agent skill routes", () => { entries: [], warnings: [], }); - mockAgentService.update.mockImplementation(async (_id: string, patch: Record) => ({ - ...makeAgent("claude_local"), - adapterConfig: patch.adapterConfig ?? {}, - })); - mockAgentService.create.mockImplementation(async (_companyId: string, input: Record) => ({ - ...makeAgent(String(input.adapterType ?? "claude_local")), - ...input, - adapterConfig: input.adapterConfig ?? {}, - runtimeConfig: input.runtimeConfig ?? {}, - budgetMonthlyCents: Number(input.budgetMonthlyCents ?? 0), - permissions: null, - })); + mockAgentService.update.mockImplementation(async (_id: string, patch: Record) => { + const previousAgent = persistedAgent ?? makeAgent("claude_local"); + persistedAgent = { + ...previousAgent, + ...patch, + adapterConfig: patch.adapterConfig ?? previousAgent.adapterConfig ?? {}, + }; + return persistedAgent; + }); + mockAgentService.create.mockImplementation(async (_companyId: string, input: Record) => { + persistedAgent = { + ...makeAgent(String(input.adapterType ?? "claude_local")), + ...input, + adapterConfig: input.adapterConfig ?? {}, + runtimeConfig: input.runtimeConfig ?? {}, + budgetMonthlyCents: Number(input.budgetMonthlyCents ?? 0), + permissions: null, + }; + return persistedAgent; + }); mockApprovalService.create.mockImplementation(async (_companyId: string, input: Record) => ({ id: "approval-1", companyId: "company-1", @@ -437,13 +446,6 @@ describe.sequential("agent skill routes", () => { }); it("accepts the security role on direct agent creation and preserves it in telemetry", async () => { - mockAgentService.update.mockImplementation(async (_id: string, patch: Record) => ({ - ...makeAgent("claude_local"), - ...patch, - role: "security", - adapterConfig: patch.adapterConfig ?? {}, - })); - const res = await requestApp(await createApp(), (baseUrl) => request(baseUrl) .post("/api/companies/company-1/agents") .send({ @@ -454,6 +456,9 @@ describe.sequential("agent skill routes", () => { })); expect([200, 201], JSON.stringify(res.body)).toContain(res.status); + expect(res.body).toMatchObject({ + role: "security", + }); expect(mockAgentService.create).toHaveBeenCalledWith( "company-1", expect.objectContaining({