Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/sdk-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ on:
- dev
- prod

concurrency:
group: ${{ github.event_name == 'pull_request' && 'dev' || inputs.environment }}

jobs:
smoke-and-coverage:
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/smoke-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ on:
- dev
- prod

concurrency:
group: ${{ inputs.environment }}

jobs:
smoke-tests:
runs-on: ubuntu-latest
Expand All @@ -37,7 +40,6 @@ jobs:
uses: runloopai/setup-node@main
with:
node-version: '20'
cache: yarn

- name: Install dependencies
run: yarn --frozen-lockfile
Expand Down
2 changes: 1 addition & 1 deletion examples/blueprint-with-build-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export async function recipe(ctx: RecipeContext): Promise<RecipeOutput> {
dockerfile: 'FROM ubuntu:22.04\nWORKDIR /app\nCOPY . .',
build_context: storageObject,
},
{ polling: { timeoutMs: BLUEPRINT_POLL_TIMEOUT_MS } },
{ longPoll: { timeoutMs: BLUEPRINT_POLL_TIMEOUT_MS } },
);
cleanup.add(`blueprint:${blueprint.id}`, () => sdk.blueprint.fromId(blueprint.id).delete());

Expand Down
2 changes: 1 addition & 1 deletion examples/devbox-from-blueprint-lifecycle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export async function recipe(ctx: RecipeContext): Promise<RecipeOutput> {
name: uniqueName('example-blueprint'),
dockerfile: 'FROM ubuntu:22.04\nRUN echo "Hello from your blueprint"',
},
{ polling: { timeoutMs: BLUEPRINT_POLL_TIMEOUT_MS } },
{ longPoll: { timeoutMs: BLUEPRINT_POLL_TIMEOUT_MS } },
);
cleanup.add(`blueprint:${blueprint.id}`, () => sdk.blueprint.fromId(blueprint.id).delete());

Expand Down
4 changes: 2 additions & 2 deletions src/resources/scenarios/scenarios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
ScenariosCursorIDPage,
type ScenariosCursorIDPageParams,
} from '../../pagination';
import { PollingOptions } from '@runloop/api-client/lib/polling';
import { LongPollRequestOptions } from '@runloop/api-client/lib/polling';
import { DevboxView } from '../devboxes';

export class Scenarios extends APIResource {
Expand Down Expand Up @@ -132,7 +132,7 @@ export class Scenarios extends APIResource {
*/
async startRunAndAwaitEnvReady(
body: ScenarioStartRunParams,
options?: Core.RequestOptions & { polling?: Partial<PollingOptions<DevboxView>> },
options?: LongPollRequestOptions<DevboxView>,
): Promise<ScenarioRunView> {
const run = await this.startRun(body, options);
await this._client.devboxes.awaitRunning(run.devbox_id, options);
Expand Down
6 changes: 2 additions & 4 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,14 +726,12 @@ export class BlueprintOps {
/**
* Create a new blueprint.
* @param {BlueprintCreateParams} params - Parameters for creating the blueprint.
* @param {Core.RequestOptions & { polling?: Partial<PollingOptions<RunloopAPI.Blueprints.BlueprintView>> }} [options] - Request options including polling configuration.
* @param {LongPollRequestOptions<RunloopAPI.Blueprints.BlueprintView>} [options] - Request options with optional long-poll configuration.
* @returns {Promise<Blueprint>} A {@link Blueprint} instance.
*/
async create(
params: BlueprintCreateParams,
options?: Core.RequestOptions & {
polling?: Partial<PollingOptions<RunloopAPI.Blueprints.BlueprintView>>;
},
options?: LongPollRequestOptions<RunloopAPI.Blueprints.BlueprintView>,
): Promise<Blueprint> {
return Blueprint.create(this.client, params, options);
}
Expand Down
14 changes: 5 additions & 9 deletions src/sdk/blueprint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
BlueprintBuildLogsListView,
} from '../resources/blueprints';
import type { DevboxCreateParams, DevboxView } from '../resources/devboxes/devboxes';
import type { PollingOptions } from '../lib/polling';
import type { LongPollRequestOptions } from '../lib/polling';
import type { IgnoreMatcher } from '../lib/ignore-matcher';
import { Devbox } from './devbox';
import { StorageObject } from './storage-object';
Expand Down Expand Up @@ -80,15 +80,13 @@ export class Blueprint {
*
* @param {Runloop} client - The Runloop client instance
* @param {CreateParams} params - Parameters for creating the blueprint
* @param {Core.RequestOptions & { polling?: Partial<PollingOptions<BlueprintView>> }} [options] - Request options with optional polling configuration
* @param {LongPollRequestOptions<BlueprintView>} [options] - Request options with optional long-poll configuration
* @returns {Promise<Blueprint>} A {@link Blueprint} instance with completed build
*/
static async create(
client: Runloop,
params: CreateParams,
options?: Core.RequestOptions & {
polling?: Partial<PollingOptions<BlueprintView>>;
},
options?: LongPollRequestOptions<BlueprintView>,
): Promise<Blueprint> {
const { build_context, build_context_dir, ...other } = params as any;
let rawParams: BlueprintCreateParams;
Expand Down Expand Up @@ -214,14 +212,12 @@ export class Blueprint {
* @private
*
* @param {Omit<DevboxCreateParams, 'blueprint_id' | 'snapshot_id' | 'blueprint_name'>} [params] - Additional devbox creation parameters (optional)
* @param {Core.RequestOptions & { polling?: Partial<PollingOptions<DevboxView>> }} [options] - Request options with optional polling configuration
* @param {LongPollRequestOptions<DevboxView>} [options] - Request options with optional long-poll configuration
* @returns {Promise<Devbox>} A new {@link Devbox} instance created from this blueprint
*/
async createDevbox(
params?: Omit<DevboxCreateParams, 'blueprint_id' | 'snapshot_id' | 'blueprint_name'>,
options?: Core.RequestOptions & {
polling?: Partial<PollingOptions<DevboxView>>;
},
options?: LongPollRequestOptions<DevboxView>,
): Promise<Devbox> {
const createParams: DevboxCreateParams = {
...params,
Expand Down
9 changes: 3 additions & 6 deletions src/sdk/scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
ScenarioStartRunParams,
} from '../resources/scenarios/scenarios';
import type { DevboxView } from '../resources/devboxes/devboxes';
import { PollingOptions } from '../lib/polling';
import { LongPollRequestOptions } from '../lib/polling';
import { ScenarioRun } from './scenario-run';

/**
Expand Down Expand Up @@ -177,13 +177,10 @@ export class Scenario {
* ```
*
* @param {ScenarioRunParams} [params] - Run parameters
* @param {Core.RequestOptions & { polling?: Partial<PollingOptions<DevboxView>> }} [options] - Request options with optional polling config
* @param {LongPollRequestOptions<DevboxView>} [options] - Request options with optional long-poll config
* @returns {Promise<ScenarioRun>} ScenarioRun instance with ready devbox
*/
async run(
params?: ScenarioRunParams,
options?: Core.RequestOptions & { polling?: Partial<PollingOptions<DevboxView>> },
): Promise<ScenarioRun> {
async run(params?: ScenarioRunParams, options?: LongPollRequestOptions<DevboxView>): Promise<ScenarioRun> {
const runView = await this.client.scenarios.startRunAndAwaitEnvReady(
{ scenario_id: this._id, ...params },
options,
Expand Down
4 changes: 2 additions & 2 deletions tests/smoketests/blueprints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('smoketest: blueprints', () => {
name: blueprintName,
},
{
polling: { maxAttempts: 180, pollingIntervalMs: 5_000, timeoutMs: 30 * 60 * 1000 },
longPoll: { timeoutMs: 30 * 60 * 1000 },
},
);
expect(created.status).toBe('build_complete');
Expand Down Expand Up @@ -101,7 +101,7 @@ describe('smoketest: blueprints', () => {
},
},
{
polling: { maxAttempts: 180, pollingIntervalMs: 5_000, timeoutMs: 30 * 60 * 1000 },
longPoll: { timeoutMs: 30 * 60 * 1000 },
},
);

Expand Down
65 changes: 43 additions & 22 deletions tests/smoketests/devboxes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ describe('smoketest: devboxes', () => {
test.concurrent(
'create devbox with authenticated tunnel in create params (deprecated polling path)',
async () => {
const warnSpy = jest.spyOn(console, 'warn').mockImplementation((...args: unknown[]) => {
if (typeof args[0] === 'string' && args[0].includes('[runloop-api-client]')) return;
process.stderr.write(`console.warn: ${args.join(' ')}\n`);
});
let devbox: DevboxView | undefined;
try {
devbox = await client.devboxes.createAndAwaitRunning(
Expand All @@ -63,6 +67,7 @@ describe('smoketest: devboxes', () => {
expect(devbox.tunnel?.auth_mode).toBe('authenticated');
expect(devbox.tunnel?.auth_token).toBeTruthy();
} finally {
warnSpy.mockRestore();
if (devbox) {
await client.devboxes.shutdown(devbox.id);
}
Expand Down Expand Up @@ -178,17 +183,25 @@ describe('smoketest: devboxes', () => {
);

test('await running (createAndAwaitRunning, deprecated polling path)', async () => {
const created = await client.devboxes.createAndAwaitRunning(
{
name: uniqueName('smoketest-devbox2'),
launch_parameters: { resource_size_request: 'X_SMALL', keep_alive_time_seconds: 60 * 5 }, // 5 minutes
},
{
polling: { timeoutMs: 20 * 60 * 1000 },
},
);
expect(created.status).toBe('running');
devboxId = created.id;
const warnSpy = jest.spyOn(console, 'warn').mockImplementation((...args: unknown[]) => {
if (typeof args[0] === 'string' && args[0].includes('[runloop-api-client]')) return;
process.stderr.write(`console.warn: ${args.join(' ')}\n`);
});
try {
const created = await client.devboxes.createAndAwaitRunning(
{
name: uniqueName('smoketest-devbox2'),
launch_parameters: { resource_size_request: 'X_SMALL', keep_alive_time_seconds: 60 * 5 }, // 5 minutes
},
{
polling: { timeoutMs: 20 * 60 * 1000 },
},
);
expect(created.status).toBe('running');
devboxId = created.id;
} finally {
warnSpy.mockRestore();
}
});

test('list devboxes', async () => {
Expand Down Expand Up @@ -232,17 +245,25 @@ describe('smoketest: devboxes', () => {
test.concurrent(
'createAndAwaitRunning timeout (deprecated polling path)',
async () => {
await expect(
client.devboxes.createAndAwaitRunning(
{
name: uniqueName('smoketest-devbox-await-running-timeout'),
launch_parameters: { launch_commands: ['sleep 70'], keep_alive_time_seconds: 30 },
},
{
polling: { timeoutMs: 100 },
},
),
).rejects.toThrow();
const warnSpy = jest.spyOn(console, 'warn').mockImplementation((...args: unknown[]) => {
if (typeof args[0] === 'string' && args[0].includes('[runloop-api-client]')) return;
process.stderr.write(`console.warn: ${args.join(' ')}\n`);
});
try {
await expect(
client.devboxes.createAndAwaitRunning(
{
name: uniqueName('smoketest-devbox-await-running-timeout'),
launch_parameters: { launch_commands: ['sleep 70'], keep_alive_time_seconds: 30 },
},
{
polling: { timeoutMs: 100 },
},
),
).rejects.toThrow();
} finally {
warnSpy.mockRestore();
}
},
SHORT_TIMEOUT * 4,
);
Expand Down
22 changes: 15 additions & 7 deletions tests/smoketests/executions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,22 @@ describe('smoketest: executions', () => {
);

test('execute async and await completion (deprecated polling path)', async () => {
const started = await client.devboxes.executions.executeAsync(devboxId!, {
command: 'echo hello && sleep 1',
});
execId = started.execution_id;
const completed = await client.devboxes.executions.awaitCompleted(devboxId!, execId!, {
polling: { timeoutMs: 10 * 60 * 1000 },
const warnSpy = jest.spyOn(console, 'warn').mockImplementation((...args: unknown[]) => {
if (typeof args[0] === 'string' && args[0].includes('[runloop-api-client]')) return;
process.stderr.write(`console.warn: ${args.join(' ')}\n`);
});
expect(completed.status).toBe('completed');
try {
const started = await client.devboxes.executions.executeAsync(devboxId!, {
command: 'echo hello && sleep 1',
});
execId = started.execution_id;
const completed = await client.devboxes.executions.awaitCompleted(devboxId!, execId!, {
polling: { timeoutMs: 10 * 60 * 1000 },
});
expect(completed.status).toBe('completed');
} finally {
warnSpy.mockRestore();
}
});

test('tail stdout logs', async () => {
Expand Down
12 changes: 6 additions & 6 deletions tests/smoketests/object-oriented/blueprint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('smoketest: object-oriented blueprint', () => {
dockerfile: 'FROM ubuntu:22.04\nRUN apt-get update && apt-get install -y curl',
system_setup_commands: ['echo "Blueprint setup complete"'],
},
{ polling: { timeoutMs: 10 * 60 * 1000 } },
{ longPoll: { timeoutMs: 10 * 60 * 1000 } },
);
blueprintId = blueprint.id;
}, LONG_TIMEOUT);
Expand Down Expand Up @@ -144,7 +144,7 @@ WORKDIR /app
COPY . .`,
build_context: storageObject,
},
{ polling: { timeoutMs: 10 * 60 * 1000 } },
{ longPoll: { timeoutMs: 10 * 60 * 1000 } },
);

expect(blueprint).toBeDefined();
Expand Down Expand Up @@ -226,7 +226,7 @@ WORKDIR /app
COPY . .`,
build_context_dir: contextDir,
},
{ polling: { timeoutMs: 10 * 60 * 1000 } },
{ longPoll: { timeoutMs: 10 * 60 * 1000 } },
);

expect(blueprint).toBeDefined();
Expand Down Expand Up @@ -288,7 +288,7 @@ COPY . .`,
name: uniqueName('sdk-blueprint-retrieve'),
dockerfile: 'FROM ubuntu:22.04',
},
{ polling: { timeoutMs: 10 * 60 * 1000 } },
{ longPoll: { timeoutMs: 10 * 60 * 1000 } },
);
expect(blueprint?.id).toBeTruthy();

Expand Down Expand Up @@ -326,7 +326,7 @@ COPY . .`,
dockerfile: 'FROM ubuntu:22.04\nRUN apt-get update',
network_policy_id: policy.id,
},
{ polling: { timeoutMs: 10 * 60 * 1000 } },
{ longPoll: { timeoutMs: 10 * 60 * 1000 } },
);

expect(blueprint).toBeDefined();
Expand Down Expand Up @@ -371,7 +371,7 @@ COPY . .`,
network_policy_id: policy.id,
},
},
{ polling: { timeoutMs: 10 * 60 * 1000 } },
{ longPoll: { timeoutMs: 10 * 60 * 1000 } },
);

expect(blueprint).toBeDefined();
Expand Down
8 changes: 4 additions & 4 deletions tests/smoketests/object-oriented/devbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,13 @@ describe('smoketest: object-oriented devbox', () => {
test.concurrent(
'create devbox from blueprint ID',
async () => {
// First create a blueprint with extended polling timeout
// First create a blueprint with extended long-poll timeout
const blueprint = await sdk.blueprint.create(
{
name: uniqueName('sdk-blueprint-for-devbox'),
dockerfile: 'FROM ubuntu:22.04\nRUN apt-get update && apt-get install -y curl',
},
{ polling: { timeoutMs: 10 * 60 * 1000 } },
{ longPoll: { timeoutMs: 10 * 60 * 1000 } },
);
expect(blueprint).toBeDefined();

Expand All @@ -473,14 +473,14 @@ describe('smoketest: object-oriented devbox', () => {
test.concurrent(
'create devbox from blueprint name',
async () => {
// First create a blueprint with a specific name and extended polling timeout
// First create a blueprint with a specific name and extended long-poll timeout
const blueprintName = uniqueName('sdk-blueprint-name-test');
const blueprint = await sdk.blueprint.create(
{
name: blueprintName,
dockerfile: 'FROM ubuntu:22.04\nRUN apt-get update && apt-get install -y wget',
},
{ polling: { timeoutMs: 10 * 60 * 1000 } },
{ longPoll: { timeoutMs: 10 * 60 * 1000 } },
);
expect(blueprint).toBeDefined();

Expand Down
Loading
Loading