Skip to content

Commit ee41883

Browse files
committed
task: add download artifacts method
1 parent 6687e05 commit ee41883

4 files changed

Lines changed: 65 additions & 0 deletions

File tree

packages/sdk/src/entities/run-item/process-run-item.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ function buildItem(
1414
termination_reason: overrides.termination_reason ?? undefined,
1515
error_code: null,
1616
error_message: null,
17+
input_artifacts: [],
1718
output_artifacts: [],
1819
} as ItemResultReadResponse;
1920
}

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,4 +535,29 @@ describe('PlatformSDK', () => {
535535
await expect(sdk.listRunResults('test-run-id')).rejects.toThrow(AuthenticationError);
536536
await expect(sdk.listRunResults('test-run-id')).rejects.toThrow(errorMessage);
537537
});
538+
539+
it('should download artifact successfully', async () => {
540+
mockTokenProvider.mockResolvedValue('mocked-token');
541+
setMockScenario('success');
542+
543+
const result = await sdk.downloadArtifact('test-run-id', 'test-artifact-id');
544+
expect(result).toBeDefined();
545+
});
546+
547+
it('should handle download artifact failure', async () => {
548+
mockTokenProvider.mockResolvedValue('mocked-token');
549+
setMockScenario('notFoundError');
550+
551+
await expect(sdk.downloadArtifact('test-run-id', 'test-artifact-id')).rejects.toThrow(
552+
'Resource not found: '
553+
);
554+
});
555+
556+
it('should handle no token for download artifact', async () => {
557+
mockTokenProvider.mockResolvedValue(null);
558+
559+
await expect(sdk.downloadArtifact('test-run-id', 'test-artifact-id')).rejects.toThrow(
560+
AuthenticationError
561+
);
562+
});
538563
});

packages/sdk/src/platform-sdk.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export interface PlatformSDK {
121121
applicationId: string,
122122
version: string
123123
): Promise<VersionReadResponse>;
124+
downloadArtifact(runId: string, artifactId: string): Promise<unknown>;
124125
}
125126
/**
126127
* Main SDK class for interacting with the Aignostics Platform
@@ -615,4 +616,17 @@ export class PlatformSDKHttp implements PlatformSDK {
615616
getConfig(): PlatformSDKConfig {
616617
return { ...this.#config };
617618
}
619+
620+
async downloadArtifact(runId: string, artifactId: string): Promise<unknown> {
621+
const client = await this.#getClient();
622+
try {
623+
const response = await client.getArtifactUrlV1RunsRunIdArtifactsArtifactIdFileGet({
624+
runId,
625+
artifactId,
626+
});
627+
return response;
628+
} catch (error) {
629+
handleRequestError(error);
630+
}
631+
}
618632
}

packages/sdk/src/test-utils/http-mocks.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ const itemResultFactory = Factory.define<ItemResultReadResponse>(() => ({
118118
terminated_at: faker.date.recent().toISOString(),
119119
output_artifacts: outputArtifactFactory.buildList(faker.number.int({ min: 0, max: 3 })),
120120
error_code: null,
121+
input_artifacts: [],
121122
}));
122123

123124
const runFactory = Factory.define<RunReadResponse>(() => ({
@@ -246,6 +247,12 @@ export const handlers = {
246247
http.get('*/v1/runs/:runId/items', () => {
247248
return HttpResponse.json(mockResponses.runResultsSuccess, { status: 200 });
248249
}),
250+
http.get('*/v1/runs/:runId/artifacts/:artifactId/file', () => {
251+
return HttpResponse.json(
252+
{ url: 'https://storage.example.com/presigned-url' },
253+
{ status: 200 }
254+
);
255+
}),
249256
],
250257

251258
// Empty responses
@@ -265,6 +272,12 @@ export const handlers = {
265272
http.get('*/v1/runs/:runId/items', () => {
266273
return HttpResponse.json([], { status: 200 });
267274
}),
275+
http.get('*/v1/runs/:runId/artifacts/:artifactId/file', () => {
276+
return HttpResponse.json(
277+
{ url: 'https://storage.example.com/presigned-url' },
278+
{ status: 200 }
279+
);
280+
}),
268281
],
269282

270283
// Not found responses
@@ -293,6 +306,9 @@ export const handlers = {
293306
http.get('*/v1/runs/:runId/items', () => {
294307
return HttpResponse.json(mockResponses.error, { status: 404 });
295308
}),
309+
http.get('*/v1/runs/:runId/artifacts/:artifactId/file', () => {
310+
return HttpResponse.json(mockResponses.error, { status: 404 });
311+
}),
296312
],
297313

298314
validationError: [
@@ -320,6 +336,9 @@ export const handlers = {
320336
http.get('*/v1/runs/:runId/items', () => {
321337
return HttpResponse.json(mockResponses.validationError, { status: 422 });
322338
}),
339+
http.get('*/v1/runs/:runId/artifacts/:artifactId/file', () => {
340+
return HttpResponse.json(mockResponses.validationError, { status: 422 });
341+
}),
323342
],
324343

325344
internalServerError: [
@@ -347,6 +366,9 @@ export const handlers = {
347366
http.get('*/v1/runs/:runId/items', () => {
348367
return HttpResponse.json(mockResponses.error, { status: 500 });
349368
}),
369+
http.get('*/v1/runs/:runId/artifacts/:artifactId/file', () => {
370+
return HttpResponse.json(mockResponses.error, { status: 500 });
371+
}),
350372
],
351373

352374
// Network error (connection failure)
@@ -375,6 +397,9 @@ export const handlers = {
375397
http.get('*/v1/runs/:runId/items', () => {
376398
return HttpResponse.error();
377399
}),
400+
http.get('*/v1/runs/:runId/artifacts/:artifactId/file', () => {
401+
return HttpResponse.error();
402+
}),
378403
],
379404
};
380405

0 commit comments

Comments
 (0)