-
Notifications
You must be signed in to change notification settings - Fork 3
fix(sdk): Fix exports of the SDK not getting clobbered #662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| name: Build Package Test | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| build-package-test: | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - name: Checkout | ||
| uses: runloopai/checkout@main | ||
|
|
||
| - name: Setup Node | ||
| uses: runloopai/setup-node@main | ||
| with: | ||
| node-version: '20' | ||
| cache: 'yarn' | ||
|
|
||
| - name: Install dependencies | ||
| run: yarn --frozen-lockfile | ||
|
|
||
| - name: Run build package test | ||
| run: yarn test:built-package | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,155 @@ | ||
| import { | ||
| RunloopSDK, | ||
| RunloopAPI, | ||
| Devbox, | ||
| Blueprint, | ||
| Snapshot, | ||
| StorageObject, | ||
| DevboxOps, | ||
| BlueprintOps, | ||
| SnapshotOps, | ||
| StorageObjectOps, | ||
| DevboxCmdOps, | ||
| DevboxFileOps, | ||
| DevboxNetOps, | ||
| Execution, | ||
| ExecutionResult, | ||
| type ExecuteStreamingCallbacks, | ||
| type ClientOptions, | ||
| } from '../../dist/sdk'; | ||
|
|
||
| describe('smoketest: built package import', () => { | ||
| let sdk: RunloopSDK; | ||
|
|
||
| beforeAll(() => { | ||
| // Initialize SDK from built package - using dummy token since we're only testing imports/types | ||
| sdk = new RunloopSDK({ | ||
| bearerToken: 'dummy-token-for-import-test', | ||
| baseURL: 'https://api.runloop.ai', | ||
| timeout: 120_000, | ||
| maxRetries: 1, | ||
| }); | ||
| }); | ||
|
|
||
| describe('RunloopSDK from built package', () => { | ||
| test('should create SDK instance from built package', () => { | ||
| expect(sdk).toBeDefined(); | ||
| expect(sdk.devbox).toBeDefined(); | ||
| expect(sdk.blueprint).toBeDefined(); | ||
| expect(sdk.snapshot).toBeDefined(); | ||
| expect(sdk.storageObject).toBeDefined(); | ||
| expect(sdk.api).toBeDefined(); | ||
| }); | ||
|
|
||
| test('should provide access to legacy API', () => { | ||
| expect(sdk.api).toBeDefined(); | ||
| expect(sdk.api.devboxes).toBeDefined(); | ||
| expect(sdk.api.blueprints).toBeDefined(); | ||
| expect(sdk.api.objects).toBeDefined(); | ||
| }); | ||
|
|
||
| test('should verify RunloopSDK namespace exports are available', () => { | ||
| // Test that namespace exports are accessible | ||
| // These are exported from the RunloopSDK namespace | ||
| expect(DevboxOps).toBeDefined(); | ||
| expect(BlueprintOps).toBeDefined(); | ||
| expect(SnapshotOps).toBeDefined(); | ||
| expect(StorageObjectOps).toBeDefined(); | ||
| expect(Devbox).toBeDefined(); | ||
| expect(Blueprint).toBeDefined(); | ||
| expect(Snapshot).toBeDefined(); | ||
| expect(StorageObject).toBeDefined(); | ||
| }); | ||
|
|
||
| test('should verify additional SDK classes are available', () => { | ||
| expect(DevboxCmdOps).toBeDefined(); | ||
| expect(DevboxFileOps).toBeDefined(); | ||
| expect(DevboxNetOps).toBeDefined(); | ||
| expect(Execution).toBeDefined(); | ||
| expect(ExecutionResult).toBeDefined(); | ||
| }); | ||
|
|
||
| test('should verify types are available', () => { | ||
| // Type check - if this compiles, the type is available | ||
| const callback: ExecuteStreamingCallbacks = { | ||
| stdout: () => {}, | ||
| stderr: () => {}, | ||
| output: () => {}, | ||
| }; | ||
| expect(callback).toBeDefined(); | ||
| expect(typeof callback.stdout).toBe('function'); | ||
| expect(typeof callback.stderr).toBe('function'); | ||
| expect(typeof callback.output).toBe('function'); | ||
| }); | ||
|
|
||
| test('should allow wrapping runloop types', () => { | ||
| // Test that types can be imported and used for type annotations | ||
| const options: ClientOptions = { | ||
| bearerToken: 'test-token', | ||
| baseURL: 'https://api.runloop.ai', | ||
| timeout: 120_000, | ||
| maxRetries: 1, | ||
| }; | ||
| expect(options).toBeDefined(); | ||
| expect(options.bearerToken).toBeDefined(); | ||
| expect(options.baseURL).toBeDefined(); | ||
|
|
||
| // Verify type wrapping works by creating a wrapper function | ||
| function createSDKWithOptions(opts: ClientOptions): RunloopSDK { | ||
| return new RunloopSDK(opts); | ||
| } | ||
| const wrappedSDK = createSDKWithOptions(options); | ||
| expect(wrappedSDK).toBeInstanceOf(RunloopSDK); | ||
| }); | ||
|
|
||
| test('should verify RunloopAPI namespace and nested resources', () => { | ||
| expect(RunloopAPI).toBeDefined(); | ||
| expect(RunloopAPI.Devboxes).toBeDefined(); | ||
| expect(RunloopAPI.Blueprints).toBeDefined(); | ||
| expect(RunloopAPI.Objects).toBeDefined(); | ||
| expect(RunloopAPI.Secrets).toBeDefined(); | ||
| expect(RunloopAPI.Agents).toBeDefined(); | ||
| expect(RunloopAPI.Benchmarks).toBeDefined(); | ||
| expect(RunloopAPI.Scenarios).toBeDefined(); | ||
| expect(RunloopAPI.Repositories).toBeDefined(); | ||
| }); | ||
|
|
||
| test('should allow creating new types based on execution.result() return type', () => { | ||
| // Extract the return type from execution.result() | ||
| // execution.result() returns Promise<ExecutionResult> | ||
| type ExecutionResultType = Awaited<ReturnType<Execution['result']>>; | ||
|
|
||
| // Create a new type based on the extracted type | ||
| type WrappedExecutionResult = { | ||
| result: ExecutionResultType; | ||
| timestamp: number; | ||
| metadata?: Record<string, unknown>; | ||
| }; | ||
|
|
||
| // Verify the type works by creating an instance | ||
| // Note: We can't actually call execution.result() without a real execution, | ||
| // but we can verify the type extraction works by using ExecutionResult directly | ||
| const mockResult = new ExecutionResult(sdk.api, 'devbox-123', 'execution-456', { | ||
| execution_id: 'execution-456', | ||
| devbox_id: 'devbox-123', | ||
| status: 'completed', | ||
| exit_code: 0, | ||
| } as any); | ||
|
|
||
| const wrapped: WrappedExecutionResult = { | ||
| result: mockResult, | ||
| timestamp: Date.now(), | ||
| metadata: { test: true }, | ||
| }; | ||
|
|
||
| expect(wrapped).toBeDefined(); | ||
| expect(wrapped.result).toBeInstanceOf(ExecutionResult); | ||
| expect(wrapped.timestamp).toBeGreaterThan(0); | ||
| expect(wrapped.metadata?.['test']).toBe(true); | ||
|
|
||
| // Verify the type is correctly inferred | ||
| const resultType: ExecutionResultType = mockResult; | ||
| expect(resultType).toBeInstanceOf(ExecutionResult); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: The regex
([^;]+)stops at the first semicolon, so if the default export expression contains additional semicolons (e.g. a function body) the replacement truncates the expression and corruptssdk.js; replace just theexports.default =prefix and insertmodule.exports = exportsbefore it so the rest of the original expression (and its semicolons) remain untouched. [logic error]Severity Level: Minor⚠️
Why it matters? ⭐
The current regex captures only until the next semicolon, so if
exports.defaultis set to a function or object literal that contains other semicolons (common in the bundledsdk.js), the replacement slices the expression mid-stream and corrupts the file. The suggested change simply prefixes the existing assignment withmodule.exports = exports;while leaving the rest untouched, which avoids breaking any validexports.defaultexpression.Prompt for AI Agent 🤖