Skip to content

Commit 8e7e197

Browse files
committed
fix(tools): keep dropping falsy impersonation subjects and surface refresh-failure causes
1 parent 4beef48 commit 8e7e197

3 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎apps/sim/lib/oauth/credential-service.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,7 @@ async function performCoalescedRefresh({
856856
logger.error('Failed to refresh token', {
857857
...logContext,
858858
errorCode: result.errorCode,
859+
message: result.message,
859860
})
860861
if (result.errorCode && isTerminalRefreshError(result.errorCode)) {
861862
// A refresh that lost a race with a concurrent connect fails with

‎apps/sim/tools/index.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4519,6 +4519,33 @@ describe('Managed OAuth Credential Delegation', () => {
45194519
expect(mockGenerateInternalDelegationToken).not.toHaveBeenCalled()
45204520
expect(fetchMock).not.toHaveBeenCalled()
45214521
})
4522+
4523+
it('drops an empty impersonation subject instead of asserting it', async () => {
4524+
mockResolveExecutorCredentialToken.mockResolvedValueOnce({ accessToken: 'token-1' })
4525+
const fetchMock = vi.fn().mockResolvedValueOnce(
4526+
new Response(JSON.stringify({ messages: [] }), {
4527+
status: 200,
4528+
headers: { 'Content-Type': 'application/json' },
4529+
})
4530+
)
4531+
global.fetch = Object.assign(fetchMock, { preconnect: vi.fn() }) as typeof fetch
4532+
4533+
const context = createToolExecutionContext({
4534+
userId: 'current-user',
4535+
workflowId: 'current-workflow',
4536+
executionId: 'current-execution',
4537+
})
4538+
4539+
await executeTool(
4540+
'gmail_read',
4541+
{ credential: 'cred-1', impersonateUserEmail: '' },
4542+
{ executionContext: context }
4543+
)
4544+
4545+
expect(mockResolveExecutorCredentialToken).toHaveBeenCalledWith(
4546+
expect.objectContaining({ credentialId: 'cred-1', impersonateEmail: undefined })
4547+
)
4548+
})
45224549
})
45234550

45244551
describe('Copilot Env Variable Reference Resolution', () => {

‎apps/sim/tools/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,9 @@ async function executeToolImplementation(
18321832
const userId = scope.userId
18331833
const credentialId = contextParams.credential as string
18341834
const toolLabel = tool?.name || toolId
1835-
const impersonateEmail = contextParams.impersonateUserEmail as string | undefined
1835+
const impersonateEmail = contextParams.impersonateUserEmail
1836+
? (contextParams.impersonateUserEmail as string)
1837+
: undefined
18361838

18371839
let providerScopes: string[] | undefined
18381840
if (tool?.oauth?.provider) {

0 commit comments

Comments
 (0)