|
| 1 | +import { |
| 2 | + RunloopSDK, |
| 3 | + RunloopAPI, |
| 4 | + Devbox, |
| 5 | + Blueprint, |
| 6 | + Snapshot, |
| 7 | + StorageObject, |
| 8 | + DevboxOps, |
| 9 | + BlueprintOps, |
| 10 | + SnapshotOps, |
| 11 | + StorageObjectOps, |
| 12 | + DevboxCmdOps, |
| 13 | + DevboxFileOps, |
| 14 | + DevboxNetOps, |
| 15 | + Execution, |
| 16 | + ExecutionResult, |
| 17 | + type ExecuteStreamingCallbacks, |
| 18 | + type ClientOptions, |
| 19 | +} from '../../dist/sdk'; |
| 20 | + |
| 21 | +describe('smoketest: built package import', () => { |
| 22 | + let sdk: RunloopSDK; |
| 23 | + |
| 24 | + beforeAll(() => { |
| 25 | + // Initialize SDK from built package - using dummy token since we're only testing imports/types |
| 26 | + sdk = new RunloopSDK({ |
| 27 | + bearerToken: 'dummy-token-for-import-test', |
| 28 | + baseURL: 'https://api.runloop.ai', |
| 29 | + timeout: 120_000, |
| 30 | + maxRetries: 1, |
| 31 | + }); |
| 32 | + }); |
| 33 | + |
| 34 | + describe('RunloopSDK from built package', () => { |
| 35 | + test('should create SDK instance from built package', () => { |
| 36 | + expect(sdk).toBeDefined(); |
| 37 | + expect(sdk.devbox).toBeDefined(); |
| 38 | + expect(sdk.blueprint).toBeDefined(); |
| 39 | + expect(sdk.snapshot).toBeDefined(); |
| 40 | + expect(sdk.storageObject).toBeDefined(); |
| 41 | + expect(sdk.api).toBeDefined(); |
| 42 | + }); |
| 43 | + |
| 44 | + test('should provide access to legacy API', () => { |
| 45 | + expect(sdk.api).toBeDefined(); |
| 46 | + expect(sdk.api.devboxes).toBeDefined(); |
| 47 | + expect(sdk.api.blueprints).toBeDefined(); |
| 48 | + expect(sdk.api.objects).toBeDefined(); |
| 49 | + }); |
| 50 | + |
| 51 | + test('should verify RunloopSDK namespace exports are available', () => { |
| 52 | + // Test that namespace exports are accessible |
| 53 | + // These are exported from the RunloopSDK namespace |
| 54 | + expect(DevboxOps).toBeDefined(); |
| 55 | + expect(BlueprintOps).toBeDefined(); |
| 56 | + expect(SnapshotOps).toBeDefined(); |
| 57 | + expect(StorageObjectOps).toBeDefined(); |
| 58 | + expect(Devbox).toBeDefined(); |
| 59 | + expect(Blueprint).toBeDefined(); |
| 60 | + expect(Snapshot).toBeDefined(); |
| 61 | + expect(StorageObject).toBeDefined(); |
| 62 | + }); |
| 63 | + |
| 64 | + test('should verify additional SDK classes are available', () => { |
| 65 | + expect(DevboxCmdOps).toBeDefined(); |
| 66 | + expect(DevboxFileOps).toBeDefined(); |
| 67 | + expect(DevboxNetOps).toBeDefined(); |
| 68 | + expect(Execution).toBeDefined(); |
| 69 | + expect(ExecutionResult).toBeDefined(); |
| 70 | + }); |
| 71 | + |
| 72 | + test('should verify types are available', () => { |
| 73 | + // Type check - if this compiles, the type is available |
| 74 | + const callback: ExecuteStreamingCallbacks = { |
| 75 | + stdout: () => {}, |
| 76 | + stderr: () => {}, |
| 77 | + output: () => {}, |
| 78 | + }; |
| 79 | + expect(callback).toBeDefined(); |
| 80 | + expect(typeof callback.stdout).toBe('function'); |
| 81 | + expect(typeof callback.stderr).toBe('function'); |
| 82 | + expect(typeof callback.output).toBe('function'); |
| 83 | + }); |
| 84 | + |
| 85 | + test('should allow wrapping runloop types', () => { |
| 86 | + // Test that types can be imported and used for type annotations |
| 87 | + const options: ClientOptions = { |
| 88 | + bearerToken: 'test-token', |
| 89 | + baseURL: 'https://api.runloop.ai', |
| 90 | + timeout: 120_000, |
| 91 | + maxRetries: 1, |
| 92 | + }; |
| 93 | + expect(options).toBeDefined(); |
| 94 | + expect(options.bearerToken).toBeDefined(); |
| 95 | + expect(options.baseURL).toBeDefined(); |
| 96 | + |
| 97 | + // Verify type wrapping works by creating a wrapper function |
| 98 | + function createSDKWithOptions(opts: ClientOptions): RunloopSDK { |
| 99 | + return new RunloopSDK(opts); |
| 100 | + } |
| 101 | + const wrappedSDK = createSDKWithOptions(options); |
| 102 | + expect(wrappedSDK).toBeInstanceOf(RunloopSDK); |
| 103 | + }); |
| 104 | + |
| 105 | + test('should verify RunloopAPI namespace and nested resources', () => { |
| 106 | + expect(RunloopAPI).toBeDefined(); |
| 107 | + expect(RunloopAPI.Devboxes).toBeDefined(); |
| 108 | + expect(RunloopAPI.Blueprints).toBeDefined(); |
| 109 | + expect(RunloopAPI.Objects).toBeDefined(); |
| 110 | + expect(RunloopAPI.Secrets).toBeDefined(); |
| 111 | + expect(RunloopAPI.Agents).toBeDefined(); |
| 112 | + expect(RunloopAPI.Benchmarks).toBeDefined(); |
| 113 | + expect(RunloopAPI.Scenarios).toBeDefined(); |
| 114 | + expect(RunloopAPI.Repositories).toBeDefined(); |
| 115 | + }); |
| 116 | + |
| 117 | + test('should allow creating new types based on execution.result() return type', () => { |
| 118 | + // Extract the return type from execution.result() |
| 119 | + // execution.result() returns Promise<ExecutionResult> |
| 120 | + type ExecutionResultType = Awaited<ReturnType<Execution['result']>>; |
| 121 | + |
| 122 | + // Create a new type based on the extracted type |
| 123 | + type WrappedExecutionResult = { |
| 124 | + result: ExecutionResultType; |
| 125 | + timestamp: number; |
| 126 | + metadata?: Record<string, unknown>; |
| 127 | + }; |
| 128 | + |
| 129 | + // Verify the type works by creating an instance |
| 130 | + // Note: We can't actually call execution.result() without a real execution, |
| 131 | + // but we can verify the type extraction works by using ExecutionResult directly |
| 132 | + const mockResult = new ExecutionResult(sdk.api, 'devbox-123', 'execution-456', { |
| 133 | + execution_id: 'execution-456', |
| 134 | + devbox_id: 'devbox-123', |
| 135 | + status: 'completed', |
| 136 | + exit_code: 0, |
| 137 | + } as any); |
| 138 | + |
| 139 | + const wrapped: WrappedExecutionResult = { |
| 140 | + result: mockResult, |
| 141 | + timestamp: Date.now(), |
| 142 | + metadata: { test: true }, |
| 143 | + }; |
| 144 | + |
| 145 | + expect(wrapped).toBeDefined(); |
| 146 | + expect(wrapped.result).toBeInstanceOf(ExecutionResult); |
| 147 | + expect(wrapped.timestamp).toBeGreaterThan(0); |
| 148 | + expect(wrapped.metadata?.['test']).toBe(true); |
| 149 | + |
| 150 | + // Verify the type is correctly inferred |
| 151 | + const resultType: ExecutionResultType = mockResult; |
| 152 | + expect(resultType).toBeInstanceOf(ExecutionResult); |
| 153 | + }); |
| 154 | + }); |
| 155 | +}); |
0 commit comments