Skip to content

Commit ff5b89e

Browse files
committed
test(llm): mock AWS credentials through the central @sim/testing mock
1 parent e340e9b commit ff5b89e

1 file changed

Lines changed: 10 additions & 8 deletions

File tree

‎apps/sim/lib/internal/llm/operations.test.ts‎

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import {
22
billingAttributionMock,
33
billingAttributionMockFns,
44
} from '@sim/testing/mocks/billing-attribution.mock'
5+
import {
6+
internalAwsCredentialsMock,
7+
internalAwsCredentialsMockFns,
8+
} from '@sim/testing/mocks/internal-aws-credentials.mock'
59
import {
610
mothershipEnvironmentContextMock,
711
mothershipEnvironmentContextMockFns,
@@ -16,7 +20,6 @@ const mocks = vi.hoisted(() => ({
1620
importProvenance: vi.fn(),
1721
isComplete: vi.fn(),
1822
resolveVertexAccessToken: vi.fn(),
19-
resolveAuthorizedAwsCredential: vi.fn(),
2023
}))
2124

2225
vi.mock('@/providers', () => providersMock)
@@ -28,9 +31,7 @@ vi.mock('@/lib/mothership/environment-context', () => mothershipEnvironmentConte
2831
vi.mock('@/lib/internal/llm/credentials', () => ({
2932
resolveVertexAccessToken: mocks.resolveVertexAccessToken,
3033
}))
31-
vi.mock('@/lib/internal/aws/credentials', () => ({
32-
resolveAuthorizedAwsCredential: mocks.resolveAuthorizedAwsCredential,
33-
}))
34+
vi.mock('@/lib/internal/aws/credentials', () => internalAwsCredentialsMock)
3435
vi.mock('@/lib/oauth/token-resolution', () => ({ recordCredentialAccess: vi.fn() }))
3536
vi.mock('@/lib/workspaces/permissions/utils', () => permissionsMock)
3637
vi.mock('@/executor/utils/resolved-secret-content-projection', () => ({
@@ -39,6 +40,7 @@ vi.mock('@/executor/utils/resolved-secret-content-projection', () => ({
3940
vi.mock('@/ee/access-control/utils/permission-check', () => permissionCheckMock)
4041

4142
const { mockRequireBillingAttributionHeader } = billingAttributionMockFns
43+
const { mockResolveAuthorizedAwsCredential } = internalAwsCredentialsMockFns
4244

4345
import type { LlmOperationError } from '@/lib/internal/llm/errors'
4446
import { executeLlmProviderOperation } from '@/lib/internal/llm/operations'
@@ -132,7 +134,7 @@ describe('executeLlmProviderOperation', () => {
132134

133135
it("signs a Bedrock call with the selected AWS credential's session for the caller", async () => {
134136
mocks.authorizeCredential.mockResolvedValueOnce(AUTHORIZED_AWS_CREDENTIAL)
135-
mocks.resolveAuthorizedAwsCredential.mockResolvedValueOnce({
137+
mockResolveAuthorizedAwsCredential.mockResolvedValueOnce({
136138
accessKeyId: 'ASIASESSIONKEY000001',
137139
secretAccessKey: 'session-secret',
138140
sessionToken: 'session-token',
@@ -148,7 +150,7 @@ describe('executeLlmProviderOperation', () => {
148150
}
149151
)
150152

151-
expect(mocks.resolveAuthorizedAwsCredential).toHaveBeenCalledWith(
153+
expect(mockResolveAuthorizedAwsCredential).toHaveBeenCalledWith(
152154
'aws-cred',
153155
{ workspaceId: 'workspace-1', executionId: 'execution-1' },
154156
undefined
@@ -199,7 +201,7 @@ describe('executeLlmProviderOperation', () => {
199201
it('fails a Bedrock call whose AWS credential cannot be resolved before provider work', async () => {
200202
mockExecuteProviderRequest.mockClear()
201203
mocks.authorizeCredential.mockResolvedValueOnce(AUTHORIZED_AWS_CREDENTIAL)
202-
mocks.resolveAuthorizedAwsCredential.mockRejectedValueOnce(new Error('AccessDenied'))
204+
mockResolveAuthorizedAwsCredential.mockRejectedValueOnce(new Error('AccessDenied'))
203205

204206
await expect(
205207
executeLlmProviderOperation(BEDROCK_CREDENTIAL_INPUT, {
@@ -217,7 +219,7 @@ describe('executeLlmProviderOperation', () => {
217219
it('reports an AWS credential STS could not resolve for a moment as unavailable, not invalid', async () => {
218220
mockExecuteProviderRequest.mockClear()
219221
mocks.authorizeCredential.mockResolvedValueOnce(AUTHORIZED_AWS_CREDENTIAL)
220-
mocks.resolveAuthorizedAwsCredential.mockRejectedValueOnce(
222+
mockResolveAuthorizedAwsCredential.mockRejectedValueOnce(
221223
Object.assign(new Error('Rate exceeded'), {
222224
name: 'ThrottlingException',
223225
$metadata: { httpStatusCode: 400 },

0 commit comments

Comments
 (0)