Skip to content

Commit bb56268

Browse files
Mossakaclaude
andcommitted
test: add unit tests for fastKillAgentContainer
Cover default timeout, custom timeout, and error-swallowing behavior to satisfy CI coverage gate. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 57c2a64 commit bb56268

1 file changed

Lines changed: 37 additions & 1 deletion

File tree

src/docker-manager.test.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { generateDockerCompose, subnetsOverlap, writeConfigs, startContainers, stopContainers, cleanup, runAgentCommand, validateIdNotInSystemRange, getSafeHostUid, getSafeHostGid, getRealUserHome, extractGhHostFromServerUrl, readGitHubPathEntries, mergeGitHubPathEntries, readEnvFile, MIN_REGULAR_UID, ACT_PRESET_BASE_IMAGE } from './docker-manager';
1+
import { generateDockerCompose, subnetsOverlap, writeConfigs, startContainers, stopContainers, fastKillAgentContainer, cleanup, runAgentCommand, validateIdNotInSystemRange, getSafeHostUid, getSafeHostGid, getRealUserHome, extractGhHostFromServerUrl, readGitHubPathEntries, mergeGitHubPathEntries, readEnvFile, MIN_REGULAR_UID, ACT_PRESET_BASE_IMAGE } from './docker-manager';
22
import { WrapperConfig } from './types';
33
import * as fs from 'fs';
44
import * as path from 'path';
@@ -2950,6 +2950,42 @@ describe('docker-manager', () => {
29502950
});
29512951
});
29522952

2953+
describe('fastKillAgentContainer', () => {
2954+
beforeEach(() => {
2955+
jest.clearAllMocks();
2956+
});
2957+
2958+
it('should call docker stop with default 3-second timeout', async () => {
2959+
mockExecaFn.mockResolvedValueOnce({ stdout: '', stderr: '', exitCode: 0 } as any);
2960+
2961+
await fastKillAgentContainer();
2962+
2963+
expect(mockExecaFn).toHaveBeenCalledWith(
2964+
'docker',
2965+
['stop', '-t', '3', 'awf-agent'],
2966+
{ reject: false, timeout: 8000 }
2967+
);
2968+
});
2969+
2970+
it('should accept a custom stop timeout', async () => {
2971+
mockExecaFn.mockResolvedValueOnce({ stdout: '', stderr: '', exitCode: 0 } as any);
2972+
2973+
await fastKillAgentContainer(5);
2974+
2975+
expect(mockExecaFn).toHaveBeenCalledWith(
2976+
'docker',
2977+
['stop', '-t', '5', 'awf-agent'],
2978+
{ reject: false, timeout: 10000 }
2979+
);
2980+
});
2981+
2982+
it('should not throw when docker stop fails', async () => {
2983+
mockExecaFn.mockRejectedValueOnce(new Error('docker not found'));
2984+
2985+
await expect(fastKillAgentContainer()).resolves.toBeUndefined();
2986+
});
2987+
});
2988+
29532989
describe('runAgentCommand', () => {
29542990
let testDir: string;
29552991

0 commit comments

Comments
 (0)