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
11 changes: 11 additions & 0 deletions packages/core/src/evaluation/workspace/docker-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,17 @@ export class DockerWorkspaceProvider {

/** Pull the configured Docker image. No-op if already cached locally. */
async pullImage(): Promise<void> {
// Skip pull if image already exists locally (e.g. locally-built images)
const inspectResult = await this.executor.exec(
['docker', 'image', 'inspect', this.config.image],
{
timeoutMs: 10_000,
},
);
if (inspectResult.exitCode === 0) {
return; // Image exists locally, no pull needed
}

const result = await this.executor.exec(['docker', 'pull', this.config.image], {
timeoutMs: this.timeoutMs,
});
Expand Down
39 changes: 32 additions & 7 deletions packages/core/test/evaluation/workspace/docker-workspace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,43 @@ describe('DockerWorkspaceProvider', () => {
});

describe('pullImage', () => {
it('calls docker pull with the configured image', async () => {
it('skips pull when image exists locally', async () => {
// docker image inspect succeeds → image exists locally
executor.pushResponse({ exitCode: 0 });
const provider = new DockerWorkspaceProvider({ image: 'myimage:v1' }, executor);
await provider.pullImage();
expect(executor.callArgv(0)).toEqual(['docker', 'image', 'inspect', 'myimage:v1']);
expect(executor.calls.length).toBe(1); // no pull call
});

it('calls docker pull when image not found locally', async () => {
// docker image inspect fails → pull needed
executor.pushResponse({ exitCode: 1, stderr: 'No such image' });
executor.pushResponse({ stdout: 'Pull complete\n', exitCode: 0 });
const provider = new DockerWorkspaceProvider({ image: 'myimage:v1' }, executor);
await provider.pullImage();
expect(executor.callArgv(0)).toEqual(['docker', 'pull', 'myimage:v1']);
expect(executor.callArgv(0)).toEqual(['docker', 'image', 'inspect', 'myimage:v1']);
expect(executor.callArgv(1)).toEqual(['docker', 'pull', 'myimage:v1']);
});

it('throws on pull failure', async () => {
// inspect fails, pull also fails
executor.pushResponse({ exitCode: 1, stderr: 'No such image' });
executor.pushResponse({ exitCode: 1, stderr: 'manifest not found' });
const provider = new DockerWorkspaceProvider({ image: 'bad:image' }, executor);
await expect(provider.pullImage()).rejects.toThrow('docker pull failed');
});

it('uses configured timeout', async () => {
it('uses configured timeout for pull', async () => {
// inspect fails, then pull happens with configured timeout
executor.pushResponse({ exitCode: 1, stderr: 'No such image' });
executor.pushResponse({ exitCode: 0 });
const provider = new DockerWorkspaceProvider({ image: 'img:1', timeout: 60 }, executor);
await provider.pullImage();
expect(executor.callOptions(0)?.timeoutMs).toBe(60_000);
// First call (inspect) uses 10s timeout
expect(executor.callOptions(0)?.timeoutMs).toBe(10_000);
// Second call (pull) uses configured timeout
expect(executor.callOptions(1)?.timeoutMs).toBe(60_000);
});
});

Expand Down Expand Up @@ -351,18 +370,24 @@ describe('DockerWorkspaceProvider', () => {
});

describe('timeout configuration', () => {
it('defaults to 1800s (30 min) timeout', async () => {
it('defaults to 1800s (30 min) timeout for pull', async () => {
// inspect fails → pull with default timeout
executor.pushResponse({ exitCode: 1, stderr: 'No such image' });
executor.pushResponse({ exitCode: 0 });
const provider = new DockerWorkspaceProvider({ image: 'img:1' }, executor);
await provider.pullImage();
expect(executor.callOptions(0)?.timeoutMs).toBe(1_800_000);
// Pull call (second) uses default timeout
expect(executor.callOptions(1)?.timeoutMs).toBe(1_800_000);
});

it('uses custom timeout from config', async () => {
// inspect fails → pull with custom timeout
executor.pushResponse({ exitCode: 1, stderr: 'No such image' });
executor.pushResponse({ exitCode: 0 });
const provider = new DockerWorkspaceProvider({ image: 'img:1', timeout: 300 }, executor);
await provider.pullImage();
expect(executor.callOptions(0)?.timeoutMs).toBe(300_000);
// Pull call (second) uses custom timeout
expect(executor.callOptions(1)?.timeoutMs).toBe(300_000);
});
});
});
Loading
Loading