@@ -9,16 +9,22 @@ import { assertVendorNetwork, createVendorNetwork, removeVendorNetwork, VENDOR_H
99 VendorNetworkCreationCleanupError ,
1010 type VendorNetwork } from '../agents/network/network.ts' ;
1111import { 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.
1515const 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
1723let imageId = '' , network : VendorNetwork , invocation : InvocationInput ;
1824const 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
6673describe ( '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 ) ;
0 commit comments