🧹 chore: Optimize provisioning — single credential load, deferred DB writes

- 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
This commit is contained in:
Danny Avila 2026-03-22 13:08:34 -04:00
parent 4433b5d0da
commit a8a3b0f509
2 changed files with 7 additions and 6 deletions

View file

@ -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

View file

@ -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 () => {