From a8a3b0f509a24bf883d9f5749e8d95e8187d2d8e Mon Sep 17 00:00:00 2001 From: Danny Avila Date: Sun, 22 Mar 2026 13:08:34 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20chore:=20Optimize=20provisioning?= =?UTF-8?q?=20=E2=80=94=20single=20credential=20load,=20deferred=20DB=20wr?= =?UTF-8?q?ites?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Fix initialize.ts: guard provisionWarnings access with null check (tests don't mock primeResources warnings field) - Fix resources.test.ts: update 4 assertions from toBeUndefined() to toEqual([]) — primeResources now always returns an array for attachments which is more consistent and avoids null checks downstream --- packages/api/src/agents/initialize.ts | 3 ++- packages/api/src/agents/resources.test.ts | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/api/src/agents/initialize.ts b/packages/api/src/agents/initialize.ts index e5f78ec5e6..be81f4fef9 100644 --- a/packages/api/src/agents/initialize.ts +++ b/packages/api/src/agents/initialize.ts @@ -1338,7 +1338,8 @@ export async function initializeAgent( useLegacyContent: !!options.useLegacyContent, tools: (tools ?? []) as GenericTool[] & string[], maxToolResultChars: maxToolResultCharsResolved, - provisionWarnings: provisionWarnings.length > 0 ? provisionWarnings : undefined, + provisionWarnings: + provisionWarnings != null && provisionWarnings.length > 0 ? provisionWarnings : undefined, maxContextTokens: maxContextTokens != null && maxContextTokens > 0 ? maxContextTokens diff --git a/packages/api/src/agents/resources.test.ts b/packages/api/src/agents/resources.test.ts index 04849a5177..75b9bab471 100644 --- a/packages/api/src/agents/resources.test.ts +++ b/packages/api/src/agents/resources.test.ts @@ -110,7 +110,7 @@ describe('primeResources', () => { }); expect(mockGetFiles).not.toHaveBeenCalled(); - expect(result.attachments).toBeUndefined(); + expect(result.attachments).toEqual([]); expect(result.tool_resources).toEqual(tool_resources); }); }); @@ -1342,7 +1342,7 @@ describe('primeResources', () => { role: 'USER', agentId: 'agent_shared', }); - expect(result.attachments).toBeUndefined(); + expect(result.attachments).toEqual([]); }); it('should skip filtering when filterFiles is not provided', async () => { @@ -1510,8 +1510,8 @@ describe('primeResources', () => { expect(mockGetFiles).not.toHaveBeenCalled(); // When appConfig agents endpoint is missing, context is disabled - // and no attachments are provided, the function returns undefined - expect(result.attachments).toBeUndefined(); + // and no attachments are provided, the function returns an empty array + expect(result.attachments).toEqual([]); }); it('should handle undefined tool_resources', async () => { @@ -1525,7 +1525,7 @@ describe('primeResources', () => { }); expect(result.tool_resources).toEqual({}); - expect(result.attachments).toBeUndefined(); + expect(result.attachments).toEqual([]); }); it('should handle empty requestFileSet', async () => {