Skip to content

task: add download artifacts method#70

Merged
na66im merged 3 commits intomainfrom
task/tssdk-53-download-artifacts-method
Apr 15, 2026
Merged

task: add download artifacts method#70
na66im merged 3 commits intomainfrom
task/tssdk-53-download-artifacts-method

Conversation

@na66im
Copy link
Copy Markdown
Contributor

@na66im na66im commented Apr 8, 2026

Summary

Adds a new downloadArtifact method to PlatformSDKHttp that allows downloading binary artifact files (reports, images, etc.) from completed application runs, with built-in retry logic for transient failures.

Changes

New feature: downloadArtifact(runId, artifactId)

  • Requests artifact binary content using responseType: 'arraybuffer' to prevent corruption of binary data (images, etc.)
  • Wraps the API call with downloadWithRetry (powered by p-retry) — retries up to 3 times with exponential backoff, aborting immediately on non-retryable status codes (403, 404, 410, 422)
  • Returns ArrayBuffer for straightforward binary handling by consumers
  • Full JSDoc with @throws annotations for AuthenticationError, APIError, and UnexpectedError

New utility: downloadWithRetry (dwonloadWithRetry.ts)

  • Generic retry wrapper around an Axios call using p-retry
  • Accepts configurable abort status codes to short-circuit retries on permanent errors

Error handling improvements

  • Added 403 Forbidden and 410 Gone cases to handleRequestError for more precise error classification

Interface update

  • Added downloadArtifact to the PlatformSDK interface

Comment thread packages/sdk/src/platform-sdk.ts Outdated
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #70      +/-   ##
==========================================
+ Coverage   96.38%   97.19%   +0.81%     
==========================================
  Files          13       14       +1     
  Lines        1301     1357      +56     
  Branches      191      199       +8     
==========================================
+ Hits         1254     1319      +65     
+ Misses         47       38       -9     
Flag Coverage Δ
unittests 97.19% <100.00%> (+0.81%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/sdk/src/platform-sdk.ts 98.76% <100.00%> (+4.67%) ⬆️
packages/sdk/src/utils/downloadWithRetry.ts 100.00% <100.00%> (ø)

Impacted file tree graph

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds initial support in the SDK for retrieving a downloadable artifact reference (via a new downloadArtifact method) and updates the test/mocking utilities to support the new endpoint and updated response shapes.

Changes:

  • Added downloadArtifact(runId, artifactId) to PlatformSDK / PlatformSDKHttp.
  • Extended MSW HTTP mocks to handle GET /v1/runs/:runId/artifacts/:artifactId/file across scenarios.
  • Updated tests and item factories/specs to include the newly-required input_artifacts field.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
packages/sdk/src/test-utils/http-mocks.ts Adds mock handlers for the artifact file URL endpoint; updates item result factory shape (input_artifacts).
packages/sdk/src/platform-sdk.ts Introduces the new SDK method and interface entry for artifact download/URL retrieval.
packages/sdk/src/platform-sdk.test.ts Adds tests for the new artifact method (success, not found, no token).
packages/sdk/src/entities/run-item/process-run-item.spec.ts Updates test fixture to include input_artifacts to match the updated API type shape.

Comment thread packages/sdk/src/platform-sdk.ts
Comment thread packages/sdk/src/platform-sdk.ts Outdated
Comment thread packages/sdk/src/platform-sdk.ts Outdated
Comment thread packages/sdk/src/platform-sdk.test.ts
@na66im na66im force-pushed the task/tssdk-53-download-artifacts-method branch from ee41883 to 817fc31 Compare April 9, 2026 13:59
Comment thread packages/sdk/src/utils/dwonloadWithRetry.ts Outdated
Copilot AI review requested due to automatic review settings April 9, 2026 14:39
@na66im na66im force-pushed the task/tssdk-53-download-artifacts-method branch from 817fc31 to b33b780 Compare April 9, 2026 14:39
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

packages/sdk/package.json:53

  • The newly added p-retry dependency resolves to v8.0.0, which (per package-lock.json) requires Node >=22. This repo pins Node 20.18.0 in .node-version and declares engines >=18, so npm install will fail on the supported Node versions. Pin p-retry to a major that supports Node 18/20, or bump the repo's Node/engines consistently if Node 22 is intended.
  "dependencies": {
    "axios": "^1.12.2",
    "p-retry": "^8.0.0",
    "zod": "^4.0.17"
  },
  "engines": {
    "node": ">=18.0.0"
  }

Comment thread packages/sdk/src/utils/dwonloadWithRetry.ts Outdated
Comment thread packages/sdk/src/platform-sdk.ts Outdated
Comment thread packages/sdk/src/platform-sdk.ts Outdated
Comment thread packages/sdk/src/platform-sdk.test.ts
@na66im na66im force-pushed the task/tssdk-53-download-artifacts-method branch from b33b780 to efe6a43 Compare April 9, 2026 14:46
Comment thread packages/sdk/src/platform-sdk.ts
@na66im na66im force-pushed the task/tssdk-53-download-artifacts-method branch from efe6a43 to be7ae01 Compare April 9, 2026 14:55
Copilot AI review requested due to automatic review settings April 9, 2026 14:55
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (1)

packages/sdk/package.json:53

  • Adding p-retry as ^8.0.0 pulls in a dependency that (per the updated lockfile) requires Node >=22, while this package declares engines.node >=18 and the workspace uses Node 20. Please align the p-retry version with the Node versions you support (or update the package/workspace engines and build targets).
  "license": "MIT",
  "dependencies": {
    "axios": "^1.12.2",
    "p-retry": "^8.0.0",
    "zod": "^4.0.17"
  },
  "engines": {
    "node": ">=18.0.0"
  }

Comment thread packages/sdk/src/utils/downloadWithRetry.ts
Comment thread packages/sdk/src/platform-sdk.test.ts Outdated
Comment on lines +539 to +555
it('should download artifact successfully', async () => {
mockTokenProvider.mockResolvedValue('mocked-token');
setMockScenario('success');

const result = await sdk.downloadArtifact('test-run-id', 'test-artifact-id');
expect(result).toBeDefined();
expect(result.byteLength).toBe(8);
});

it('should handle download artifact failure', async () => {
mockTokenProvider.mockResolvedValue('mocked-token');
setMockScenario('notFoundError');

await expect(sdk.downloadArtifact('test-run-id', 'test-artifact-id')).rejects.toThrow(
'Resource not found: '
);
}, 30000);
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new tests validate success and a 404 failure, but they don’t verify the newly introduced retry behavior (e.g., retrying on transient 500/network failures, and not retrying on abort statuses like 404/422). Please add at least one deterministic test that asserts retry attempts (e.g., fail once with 500 then succeed) and one that asserts immediate abort (e.g., ensure only one request is made for 404).

Copilot uses AI. Check for mistakes.
Comment thread packages/sdk/src/platform-sdk.test.ts Outdated
Comment thread packages/sdk/src/platform-sdk.ts
Copilot AI review requested due to automatic review settings April 15, 2026 09:41
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

packages/sdk/package.json:53

  • p-retry@8.0.0 appears to require Node >=22 (see package-lock), but this package declares engines.node >=18 and the SDK is built/CI-tested on Node 18/20. This dependency choice is likely to break installs/runs on supported Node versions; please pin to a p-retry major that supports Node 18 (or raise the SDK/CI Node engine/target accordingly).
  "dependencies": {
    "axios": "^1.12.2",
    "p-retry": "^8.0.0",
    "zod": "^4.0.17"
  },
  "engines": {
    "node": ">=18.0.0"
  }

Comment on lines +671 to +672
async downloadArtifact(runId: string, artifactId: string): Promise<ArrayBuffer> {
const client = await this.#getClient();
Copy link

Copilot AI Apr 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parameter naming is inconsistent with the rest of the SDK: other run-related methods use applicationRunId, but this method uses runId. Consider renaming the public parameter (and interface signature) to applicationRunId for consistency and to avoid ambiguity with other IDs.

Copilot uses AI. Check for mistakes.
Comment thread packages/sdk/src/platform-sdk.ts
@na66im na66im force-pushed the task/tssdk-53-download-artifacts-method branch from 7e69544 to 0cd82ff Compare April 15, 2026 10:04
@sonarqubecloud
Copy link
Copy Markdown

@na66im na66im merged commit 8a1fed4 into main Apr 15, 2026
13 checks passed
@na66im na66im deleted the task/tssdk-53-download-artifacts-method branch April 15, 2026 10:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants