Skip to content

Commit 3a93341

Browse files
committed
increase test coverage
1 parent be7ae01 commit 3a93341

3 files changed

Lines changed: 43 additions & 3 deletions

File tree

packages/sdk/src/platform-sdk.test.ts

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { describe, it, expect, beforeEach, vi } from 'vitest';
2+
import { http, HttpResponse } from 'msw';
23
import { PlatformSDKHttp } from './platform-sdk.js';
34
import { AuthenticationError } from './errors.js';
4-
import { setMockScenario } from './test-utils/http-mocks.js';
5+
import { setMockScenario, server } from './test-utils/http-mocks.js';
56
import { ItemState, ItemTerminationReason } from './generated/api.js';
67

78
describe('PlatformSDK', () => {
@@ -552,7 +553,7 @@ describe('PlatformSDK', () => {
552553
await expect(sdk.downloadArtifact('test-run-id', 'test-artifact-id')).rejects.toThrow(
553554
'Resource not found: '
554555
);
555-
}, 30000);
556+
});
556557

557558
it('should handle no token for download artifact', async () => {
558559
mockTokenProvider.mockResolvedValue(null);
@@ -561,4 +562,43 @@ describe('PlatformSDK', () => {
561562
AuthenticationError
562563
);
563564
});
565+
566+
it('should retry on transient 500 error and succeed on second attempt', async () => {
567+
mockTokenProvider.mockResolvedValue('mocked-token');
568+
569+
let callCount = 0;
570+
server.use(
571+
http.get('*/v1/runs/:runId/artifacts/:artifactId/file', () => {
572+
callCount++;
573+
if (callCount === 1) {
574+
return HttpResponse.json({}, { status: 500 });
575+
}
576+
return new HttpResponse(new ArrayBuffer(8), {
577+
status: 200,
578+
headers: { 'Content-Type': 'application/octet-stream' },
579+
});
580+
})
581+
);
582+
583+
const result = await sdk.downloadArtifact('test-run-id', 'test-artifact-id');
584+
expect(result.byteLength).toBe(8);
585+
expect(callCount).toBe(2);
586+
}, 10_000);
587+
588+
it('should not retry on 404 and make exactly one request', async () => {
589+
mockTokenProvider.mockResolvedValue('mocked-token');
590+
591+
let callCount = 0;
592+
server.use(
593+
http.get('*/v1/runs/:runId/artifacts/:artifactId/file', () => {
594+
callCount++;
595+
return HttpResponse.json({}, { status: 404 });
596+
})
597+
);
598+
599+
await expect(sdk.downloadArtifact('test-run-id', 'test-artifact-id')).rejects.toThrow(
600+
'Resource not found:'
601+
);
602+
expect(callCount).toBe(1);
603+
});
564604
});

packages/sdk/src/platform-sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { processApplicationRun } from './entities/application-run/process-applic
1616
import { ApplicationRun } from './entities/application-run/types.js';
1717
import { processRunItem } from './entities/run-item/process-run-item.js';
1818
import { ApplicationRunItem } from './entities/run-item/types.js';
19-
import { downloadWithRetry } from './utils/dwonloadWithRetry.js';
19+
import { downloadWithRetry } from './utils/downloadWithRetry.js';
2020

2121
const validationErrorSchema = z.object({
2222
detail: z.array(
File renamed without changes.

0 commit comments

Comments
 (0)