Skip to content

Commit ab215c6

Browse files
mchwangclaude
andcommitted
Label agent-network's unnamed helper containers for afterAll; track the rogue endpoint (#189)
Review round 39: a helper run killed between create and start is never removed by --rm, and is no holder once its vendor network is gone, so the curl, DNS and concurrent-network helpers carry this file's run ID and afterAll sweeps it (13-minute hook for two sweeps); agent-container's rogue endpoint is tracked by name; the holder fake says the removals' stdout is not read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent e4e048d commit ab215c6

3 files changed

Lines changed: 20 additions & 10 deletions

File tree

‎test/agent-container.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2787,6 +2787,8 @@ describe('real Docker agent isolation', () => {
27872787
it('rejects a new endpoint attached to the invocation network before launch', async () => {
27882788
const data = fixture(), valid = await profile(data, 'planning', 'must-not-run');
27892789
const rogue = `codeboost-rogue-${randomUUID()}`;
2790+
// Tracked for afterAll: its create may land after the finally, and once the network is gone it is no holder (#189).
2791+
containers.add(rogue);
27902792
try {
27912793
docker('run', '--detach', '--name', rogue, `--network=${valid.network.name}`, '--entrypoint', 'node', imageId,
27922794
'-e', 'setInterval(()=>{},1000)');

‎test/agent-network.test.ts‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,22 @@ import { assertVendorNetwork, createVendorNetwork, removeVendorNetwork, VENDOR_H
99
VendorNetworkCreationCleanupError,
1010
type VendorNetwork } from '../agents/network/network.ts';
1111
import { captureInvocation, type InvocationInput } from '../agents/contract.ts';
12-
import { removeByName, removeRunnerObjects, requireRealDocker } from './fixtures/docker-sweep.ts';
12+
import { removeByName, removeLabelledObjects, removeRunnerObjects, requireRealDocker, TEST_FILE_LABEL } from './fixtures/docker-sweep.ts';
1313
// Each run has its own runner owner, so the sweep after this file removes only what this run left behind. Network and
1414
// proxy names are random, so the fixed attempt IDs below reach only labels, where this owner tells runs apart.
1515
const TEST_RUNNER_OWNER = randomBytes(16).toString('hex');
16+
/**
17+
* On the unnamed `run --rm` containers that join a vendor network (#189): a client killed after the create but before
18+
* the start leaves a container `--rm` never removes, which is no holder once its network is gone (Docker 27.4 removes
19+
* a network a created, never started container still names). afterAll sweeps this label.
20+
*/
21+
const TEST_FILE_RUN = randomUUID(), fileLabel = ['--label', `${TEST_FILE_LABEL}=${TEST_FILE_RUN}`];
1622

1723
let imageId = '', network: VendorNetwork, invocation: InvocationInput;
1824
const docker = (...args: string[]) => execFileSync('docker', args, {
1925
encoding: 'utf8', timeout: 60_000, stdio: ['ignore', 'pipe', 'pipe'],
2026
}).trim();
21-
const curl = (url: string, direct = false) => spawnSync('docker', ['run', '--rm', `--network=${network.name}`,
27+
const curl = (url: string, direct = false) => spawnSync('docker', ['run', '--rm', ...fileLabel, `--network=${network.name}`,
2228
'--env', `HTTPS_PROXY=${network.proxyUrl}`, ...(direct ? ['--env', 'NO_PROXY=*'] : []),
2329
'--entrypoint', 'curl', imageId, '--silent', '--show-error', '--output', '/dev/null', '--write-out', '%{http_code}',
2430
'--max-time', '15', url], { encoding: 'utf8', timeout: 30_000, stdio: ['ignore', 'pipe', 'pipe'] });
@@ -54,14 +60,15 @@ afterAll(async () => {
5460
}
5561
finally {
5662
// Then remove whatever this run still owns, even when a test failed or the removal above threw. Objects a test
57-
// makes without the runner label are found here only while they hold one of this run's networks or volumes; the
58-
// tests remove their own, and the try above removes those registered in `unlabelled`. It may not run before a hook
59-
// timeout. The hook's 7 minutes leave a minute and a half over this sweep's worst case (eleven calls of 30 s), for
60-
// the cleanup before it.
63+
// makes without the runner label are found here only while they hold one of this run's networks or volumes, or
64+
// carry this file's run ID; the tests remove their own, and the try above removes those registered in
65+
// `unlabelled`. It may not run before a hook timeout. The hook's 13 minutes leave two over the worst case of these
66+
// two sweeps (eleven calls of 30 s each), for the cleanup before them.
67+
removeLabelledObjects(TEST_FILE_LABEL, TEST_FILE_RUN, 'afterAll');
6168
removeRunnerObjects(TEST_RUNNER_OWNER);
6269
if (records) rmSync(records, { recursive: true, force: true });
6370
}
64-
}, 7 * 60_000);
71+
}, 13 * 60_000);
6572

6673
describe('vendor-only egress', () => {
6774
it('keeps failed allocation and its cleanup inside the caller deadline', async () => {
@@ -303,7 +310,7 @@ describe('vendor-only egress', () => {
303310
}, 60_000);
304311

305312
it('does not forward arbitrary DNS even when the embedded resolver is addressed directly', async () => {
306-
const result = spawnSync('docker', ['run', '--rm', `--network=${network.name}`, '--dns=127.0.0.1',
313+
const result = spawnSync('docker', ['run', '--rm', ...fileLabel, `--network=${network.name}`, '--dns=127.0.0.1',
307314
'--entrypoint', 'node', imageId, '-e', [
308315
"const dns=require('node:dns');dns.setServers(['127.0.0.11']);",
309316
"dns.resolve4('example.com',(error)=>process.exit(error?0:1));",
@@ -328,7 +335,7 @@ describe('vendor-only egress', () => {
328335
try {
329336
docker('run', '--detach', '--name', peer, `--network=${network.name}`, '--network-alias', 'codeboost-peer',
330337
'--entrypoint', 'node', imageId, '-e', "require('node:net').createServer(()=>{}).listen(4567,'0.0.0.0');setInterval(()=>{},1000)");
331-
const result = spawnSync('docker', ['run', '--rm', `--network=${other.name}`, '--entrypoint', 'node', imageId,
338+
const result = spawnSync('docker', ['run', '--rm', ...fileLabel, `--network=${other.name}`, '--entrypoint', 'node', imageId,
332339
'-e', "const s=require('node:net').connect(4567,'codeboost-peer');s.on('connect',()=>process.exit(0));s.on('error',()=>process.exit(1));setTimeout(()=>process.exit(2),3000)"],
333340
{ encoding: 'utf8', timeout: 10_000, stdio: ['ignore', 'pipe', 'pipe'] });
334341
expect(result.status).not.toBe(0);

‎test/docker-sweep.test.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ it.each([
145145
const root = mkdtempSync(join(tmpdir(), 'codeboost-sweep-')); roots.push(root);
146146
const calls = join(root, 'calls'), net = 'n'.repeat(64), a = 'a'.repeat(64), b = 'b'.repeat(64);
147147
// Answers as Docker 27.4 does for one swept network with two candidate holders, one gone before the inspect: the
148-
// inspect prints the other and exits 1. Every other call gets no output and exit 0, as for `ls` with no match.
148+
// inspect prints the other and exits 1. Every other call gets no output and exit 0, as for `ls` with no match; the
149+
// removals' stdout (the removed IDs or names in 27.4) is not read.
149150
writeFileSync(join(root, 'docker'), ['#!/bin/sh', `printf '%s\\n' "$*" >> '${calls}'`,
150151
`if [ "$1 $2" = "network ls" ]; then printf '%s\\n' '{"ID":"${net}","Name":"swept"}'; exit 0; fi`,
151152
`if [ "$1" = ps ]; then printf '%s\\n' ${a} ${b}; exit 0; fi`,

0 commit comments

Comments
 (0)