Skip to content

Commit 515fe0c

Browse files
mchwangclaude
andcommitted
Test the load-time docker as the default and a relative PATH entry; client limit; messages (#189)
Review round 48: the finds-docker test loads the fixture through a relative PATH entry, then puts another docker first and calls both removals with no docker given, checking only the docker found at load ran; the network listing in the killed-create test gets its 60 s client limit back; the supervisor's removal message handles a docker that could not start; the fake says what it answers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent a0bcb1d commit 515fe0c

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

‎test/agent-container.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -974,7 +974,7 @@ describe('real Docker agent isolation', () => {
974974
const created = await withDockerShim(['network', 'create'], foreign, () =>
975975
createVendorNetwork(invocation(data.clone, 'planning'), imageId, allocationId).then(() => undefined, error => error));
976976
const left = spawnSync('docker', ['network', 'ls', '--quiet', '--filter', `label=io.codeboost.allocation=${allocationId}`],
977-
{ encoding: 'utf8' }).stdout?.trim() ?? '';
977+
{ encoding: 'utf8', timeout: 60_000, killSignal: 'SIGKILL' }).stdout?.trim() ?? '';
978978
expect(created).toBeInstanceOf(VendorNetworkCreationCleanupError);
979979
const cleanup = (created as VendorNetworkCreationCleanupError).errors[1] as AggregateError;
980980
expect(cleanup.errors.map(error => (error as Error).message)).toEqual(['Refused to remove unowned vendor network.']);

‎test/agent-supervisor.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ describe('container invocation supervisor', () => {
408408
// A failure above stays the one reported, whatever exit status this Docker version gives for a missing name. After
409409
// a pass the container exists, and its removal must succeed, as on main.
410410
const removed = spawnSync('docker', ['rm', '--force', current.name], { encoding: 'utf8' });
411-
if (passed && removed.status !== 0) throw new Error(`Removing ${current.name} failed: ${removed.stderr.trim()}`);
411+
if (passed && removed.status !== 0) throw new Error(`Removing ${current.name} failed: ${removed.error?.message ?? removed.stderr?.trim()}`);
412412
}
413413
}, 3 * 60_000);
414414

‎test/docker-sweep.test.ts‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
1+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
22
import { tmpdir } from 'node:os';
3-
import { join } from 'node:path';
3+
import { join, relative } from 'node:path';
44
import { spawnSync } from 'node:child_process';
55
import { afterEach, expect, it, vi } from 'vitest';
66
import { removeByName, removeLabelledObjects, TEST_RUN_LABEL } from './fixtures/docker-sweep.ts';
@@ -174,23 +174,31 @@ it.each([
174174
expect(readFileSync(calls, 'utf8').split('\n')).toContain(`rm --force ${a}`);
175175
});
176176

177-
it('finds the real docker once, at load, and refuses a shim when none was found', async () => {
177+
it('finds the real docker once, at load, uses it by default, and refuses a shim when none was found', async () => {
178178
const root = mkdtempSync(join(tmpdir(), 'codeboost-sweep-')); roots.push(root);
179-
// Two directories, each with a docker and the sh the lookup runs, and one with only sh.
179+
// Two directories, each with a docker and the sh the lookup runs, and one with only sh. Each docker records its calls
180+
// and answers as Docker 27.4 does for a missing container and for an `ls` with no match; nothing else is asked of it.
180181
const bin = (name: string, docker: boolean) => {
181182
const dir = join(root, name); mkdirSync(dir);
182183
symlinkSync(spawnSync('sh', ['-c', 'command -v sh'], { encoding: 'utf8' }).stdout.trim(), join(dir, 'sh'));
183-
if (docker) writeFileSync(join(dir, 'docker'), '#!/bin/sh\nexit 0\n', { mode: 0o755 });
184+
if (docker) writeFileSync(join(dir, 'docker'), ['#!/bin/sh', `printf '%s\\n' "$*" >> '${join(dir, 'calls')}'`,
185+
'if [ "$2" = inspect ]; then echo; echo "Error response from daemon: No such container: x" >&2; exit 1; fi', 'exit 0'].join('\n'),
186+
{ mode: 0o755 });
184187
return dir;
185188
};
186189
const first = bin('first', true), second = bin('second', true), none = bin('none', false);
187-
vi.stubEnv('PATH', first);
190+
// A relative PATH entry, resolved at load.
191+
vi.stubEnv('PATH', relative(process.cwd(), first));
188192
vi.resetModules();
189193
const loaded = await import('./fixtures/docker-sweep.ts') as typeof Sweep;
190-
// A shim put on PATH later does not change it.
194+
// A shim put on PATH later does not change it, and the removals use it when given no docker.
191195
vi.stubEnv('PATH', second);
192196
expect(loaded.REAL_DOCKER).toBe(join(first, 'docker'));
193197
expect(loaded.requireRealDocker()).toBe(join(first, 'docker'));
198+
loaded.removeByName('container', 'x', 'test');
199+
loaded.removeLabelledObjects(TEST_RUN_LABEL, 'x', 'test');
200+
expect(readFileSync(join(first, 'calls'), 'utf8').split('\n').filter(Boolean).length).toBeGreaterThan(1);
201+
expect(existsSync(join(second, 'calls'))).toBe(false);
194202
vi.stubEnv('PATH', none);
195203
vi.resetModules();
196204
const missing = await import('./fixtures/docker-sweep.ts') as typeof Sweep;

0 commit comments

Comments
 (0)