1+ import { cleanupDaemonTestState } from './support/daemon-test-cleanup.ts' ;
12import test from 'node:test' ;
23import assert from 'node:assert/strict' ;
34import fs from 'node:fs' ;
@@ -24,6 +25,7 @@ test('daemon HTTP transport starts from CLI and accepts a command RPC', async (t
2425 }
2526
2627 const stateDir = fs . mkdtempSync ( path . join ( os . tmpdir ( ) , 'agent-device-http-smoke-' ) ) ;
28+ let info : DaemonInfo | null = null ;
2729 try {
2830 const args = [
2931 'session' ,
@@ -46,7 +48,7 @@ test('daemon HTTP transport starts from CLI and accepts a command RPC', async (t
4648 assert . equal ( cli . status , 0 , formatResultDebug ( 'start HTTP daemon' , [ 'session' , 'list' ] , cli ) ) ;
4749 assert . equal ( cli . json ?. success , true , JSON . stringify ( cli . json ) ) ;
4850
49- const info = readDaemonInfo ( stateDir ) ;
51+ info = readDaemonInfo ( stateDir ) ;
5052 assert . equal ( info . transport , 'http' ) ;
5153 assert . equal ( typeof info . httpPort , 'number' ) ;
5254 assert . ok ( ( info . httpPort ?? 0 ) > 0 ) ;
@@ -73,14 +75,7 @@ test('daemon HTTP transport starts from CLI and accepts a command RPC', async (t
7375 await stopDaemon ( info ) ;
7476 await assertNoDaemonLeaks ( { stateDir, daemonPids : [ info . pid ] , phase : 'after-shutdown' } ) ;
7577 } finally {
76- try {
77- if ( fs . existsSync ( path . join ( stateDir , 'daemon.json' ) ) ) {
78- await stopDaemon ( readDaemonInfo ( stateDir ) ) ;
79- }
80- fs . rmSync ( stateDir , { recursive : true , force : true } ) ;
81- } catch ( error ) {
82- console . warn ( 'Daemon test cleanup retained state:' , stateDir , error ) ;
83- }
78+ await cleanupDaemonTestState ( stateDir , info ) ;
8479 }
8580} ) ;
8681
0 commit comments