Skip to content

Commit 6fe98b9

Browse files
mchwangclaude
andcommitted
Restore two failures main's cleanups had; report an inspect answer with no ID and name (#189)
Review round 45: the foreign-name supervisor test fails again when, after its checks pass, the container's removal fails; the unsettled-allocation test checks after its sweep that nothing of the allocation is left, as main's listing did; removeByName reports a parsed answer without an ID and a name, and its doc lists what it stays quiet about; comment blocks rewrapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent bcf1e9f commit 6fe98b9

4 files changed

Lines changed: 29 additions & 13 deletions

File tree

‎test/agent-container.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,6 +2375,10 @@ describe('real Docker agent isolation', () => {
23752375
const data = fixture(), runnerOwner = randomBytes(16).toString('hex');
23762376
const owner = { runnerOwner, attemptId: 'unsettled-allocation', allocationId: randomUUID() };
23772377
// Another runner's objects, so no sweep of this run finds them: removed by allocation when the test finishes (#189).
2378+
// After a pass, nothing of the allocation may be left once that sweep has run, as on main; this check, registered
2379+
// first, runs after the sweep (Vitest runs onTestFinished hooks in reverse order).
2380+
let passed = false;
2381+
onTestFinished(() => { if (passed) expect(byAllocation(owner.allocationId)).toEqual([]); }, 2 * 60_000);
23782382
sweepWhenFinished('io.codeboost.allocation', owner.allocationId);
23792383
// The seeder is refused, and every volume removal fails, so the allocation's cleanup does not settle.
23802384
const failing = [
@@ -2385,6 +2389,7 @@ describe('real Docker agent isolation', () => {
23852389
await withDockerShim([], failing, () => expect(() => prepareTaskFilesystems(data.clone, storageLimits, imageId,
23862390
owner)).toThrow('cleanup did not settle'));
23872391
await expect(recoverLeftovers(runnerOwner)).rejects.toThrow('still holds task storage');
2392+
passed = true;
23882393
}, 60_000);
23892394

23902395
it('recovers only its own runner after a restart, keeping its storage for removal by handle', async () => {

‎test/agent-supervisor.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,7 @@ describe('container invocation supervisor', () => {
389389
const current = await profile(fixture(), 'finite-output', 'foreign-name');
390390
// Removed by name when the test finishes, timeouts included: its label value is shared across runs (#189).
391391
onTestFinished(() => removeByName('container', current.name, 'onTestFinished'), 90_000); // two calls of up to 30 s
392+
let passed = false;
392393
try {
393394
// Inside the try, so its removal runs even if the create's client fails after the daemon made it (#189).
394395
execFileSync('docker', ['create', '--name', current.name, '--label', 'io.codeboost.invocation=foreign',
@@ -402,9 +403,12 @@ describe('container invocation supervisor', () => {
402403
expect(spawnSync('docker', ['network', 'inspect', current.network.name], { stdio: 'ignore' }).status).not.toBe(0);
403404
expect(execFileSync('docker', ['container', 'inspect', '--format',
404405
'{{index .Config.Labels "io.codeboost.invocation"}}', current.name], { encoding: 'utf8' }).trim()).toBe('foreign');
406+
passed = true;
405407
} finally {
406-
// Never throws, whatever exit status this Docker version gives for a missing name.
407-
spawnSync('docker', ['rm', '--force', current.name], { stdio: 'ignore' });
408+
// A failure above stays the one reported, whatever exit status this Docker version gives for a missing name. After
409+
// a pass the container exists, and its removal must succeed, as on main.
410+
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()}`);
408412
}
409413
}, 3 * 60_000);
410414

‎test/docker-sweep.test.ts‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ it('removes by name only an object of exactly that name, and reports failures ot
5858
const calls = join(root, 'calls'), id = 'b'.repeat(64), other = 'c'.repeat(64), raced = 'd'.repeat(64);
5959
// Answers as Docker 27.4 does for `inspect --format '{{json .Id}} {{json .Name}}'` (a volume: '{{json .Name}}') and
6060
// `rm`, in the parts removeByName reads: stdout of an inspect that succeeded, stderr and the exit status. A missing
61-
// object, an object found under another name (by an ID prefix), a refused removal, an inspect killed by a signal, and a
62-
// failure before the daemon (an unknown context; its meta.json path shortened). Also a network gone between its
63-
// inspect and its removal, which 27.4 answers "network <ID> not found", and an inspect answer that is not JSON, which
64-
// 27.4 is not known to give. The stdout of a failed call (a bare newline for a missing object in 27.4, nothing for
65-
// the others) is not read.
61+
// object, an object found under another name (by an ID prefix), a refused removal, an inspect killed by a signal, and
62+
// a failure before the daemon (an unknown context; its meta.json path shortened). Also a network gone between its
63+
// inspect and its removal, which 27.4 answers "network <ID> not found", and inspect answers that are not JSON or not
64+
// an ID and a name, which 27.4 is not known to give. The stdout of a failed call (a bare newline for a missing object
65+
// in 27.4, nothing for the others) is not read.
6666
writeFileSync(join(root, 'docker'), ['#!/bin/sh', `printf '%s\\n' "$*" >> '${calls}'`,
6767
'for arg; do name="$arg"; done',
6868
'if [ "$2" = inspect ]; then case "$1 $name" in',
@@ -76,6 +76,7 @@ it('removes by name only an object of exactly that name, and reports failures ot
7676
` 'volume busy') printf '%s\\n' '"busy"';;`,
7777
` 'network raced') printf '%s\\n' '"${raced}" "raced"';;`,
7878
" 'container junk') echo 'not json';;",
79+
" 'container odd') echo '1 2';;",
7980
" 'container killed') kill -9 $$;;",
8081
" 'container lost') echo 'Failed to initialize: unable to resolve docker endpoint: context \"x\": context not found: open /x/meta.json: no such file or directory' >&2; exit 1;;",
8182
'esac; exit 0; fi',
@@ -88,7 +89,7 @@ it('removes by name only an object of exactly that name, and reports failures ot
8889
const warn = vi.spyOn(console, 'warn').mockImplementation(() => undefined);
8990
const objects = [['container', 'gone'], ['network', 'gone'], ['volume', 'gone'], ['container', 'prefix'], ['network', 'prefix'],
9091
['container', 'busy'], ['network', 'busy'], ['volume', 'busy'], ['container', 'killed'], ['container', 'lost'],
91-
['network', 'raced'], ['container', 'junk']] as const;
92+
['network', 'raced'], ['container', 'junk'], ['container', 'odd']] as const;
9293
expect(() => { for (const [kind, name] of objects) removeByName(kind, name, 'test', join(root, 'docker')); }).not.toThrow();
9394
// Only the exact names are removed, by full ID (a volume's name is its ID).
9495
expect(readFileSync(calls, 'utf8').split('\n').filter(line => / rm |^rm /.test(line)))
@@ -103,6 +104,7 @@ it('removes by name only an object of exactly that name, and reports failures ot
103104
['test: removing container lost: docker container inspect failed:',
104105
'Failed to initialize: unable to resolve docker endpoint: context "x": context not found: open /x/meta.json: no such file or directory'],
105106
['test: removing container junk: docker printed what is not JSON:', 'not json\n'],
107+
['test: removing container odd: docker printed no ID and name:', '1 2\n'],
106108
]);
107109
});
108110

@@ -156,8 +158,9 @@ it.each([
156158
// inspect prints the other and exits 1. Every other call gets no output and exit 0, as for `ls` with no match; the
157159
// removals' stdout (the removed IDs or names in 27.4) is not read. The second case's answer is invented: it stands in
158160
// for an unexpected inspect failure that still printed some holders, which 27.4 is not known to give. The network
159-
// line holds only the fields the sweep reads (27.4 also prints CreatedAt, Driver, IPv6, Internal, Labels and Scope), and the inspect an empty endpoint for
160-
// the network, where 27.4 gives its full settings: the sweep reads only the network names.
161+
// line holds only the fields the sweep reads (27.4 also prints CreatedAt, Driver, IPv6, Internal, Labels and Scope),
162+
// and the inspect an empty endpoint for the network, where 27.4 gives its full settings: the sweep reads only the
163+
// network names.
161164
writeFileSync(join(root, 'docker'), ['#!/bin/sh', `printf '%s\\n' "$*" >> '${calls}'`,
162165
`if [ "$1 $2" = "network ls" ]; then printf '%s\\n' '{"ID":"${net}","Name":"swept"}'; exit 0; fi`,
163166
`if [ "$1" = ps ]; then printf '%s\\n' ${a} ${b}; exit 0; fi`,

‎test/fixtures/docker-sweep.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,9 @@ export const TEST_FILE_LABEL = 'io.codeboost.test-file';
3535
/**
3636
* Removes the container, network or volume named exactly `name`, by its full ID (a volume by its name, which is its
3737
* ID). Docker would read a missing name as an ID prefix, so an object found under another name is left alone. It
38-
* reports a failed call, other than an inspect that finds no such object, prefixed with `when`, and never throws; each
39-
* call has a 30 s limit.
38+
* reports, prefixed with `when`, a failed call and an answer it cannot read, but not an object that is gone: an inspect
39+
* that finds no such object, or a network gone between its inspect and its removal. It never throws; each call has a
40+
* 30 s limit.
4041
*/
4142
export function removeByName(kind: 'container' | 'network' | 'volume', name: string, when: string, docker = REAL_DOCKER): void {
4243
const options = { encoding: 'utf8' as const, timeout: 30_000, killSignal: 'SIGKILL' as const, env: dockerEnv() };
@@ -53,7 +54,10 @@ export function removeByName(kind: 'container' | 'network' | 'volume', name: str
5354
const at = found.stdout.indexOf(' ');
5455
[id, actual] = kind === 'volume' ? [name, JSON.parse(found.stdout)] : [JSON.parse(found.stdout.slice(0, at)), JSON.parse(found.stdout.slice(at + 1))];
5556
} catch { console.warn(`${when}: removing ${kind} ${name}: docker printed what is not JSON:`, found.stdout); return; }
56-
if (typeof id !== 'string' || typeof actual !== 'string' || (kind === 'container' ? actual.replace(/^\//, '') : actual) !== name) return;
57+
if (typeof id !== 'string' || typeof actual !== 'string') {
58+
console.warn(`${when}: removing ${kind} ${name}: docker printed no ID and name:`, found.stdout); return;
59+
}
60+
if ((kind === 'container' ? actual.replace(/^\//, '') : actual) !== name) return;
5761
const removed = spawnSync(docker, kind === 'container' ? ['rm', '--force', id] : [kind, 'rm', ...(kind === 'volume' ? ['--force'] : []), id], options);
5862
// A network gone since the inspect is gone: Docker 27.4 answers "network <ID> not found" (rm --force of a missing
5963
// container or volume exits 0).

0 commit comments

Comments
 (0)