|
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'; |
2 | 2 | import { WrapperConfig } from './types'; |
3 | 3 | import * as fs from 'fs'; |
4 | 4 | import * as path from 'path'; |
@@ -2950,6 +2950,42 @@ describe('docker-manager', () => { |
2950 | 2950 | }); |
2951 | 2951 | }); |
2952 | 2952 |
|
| 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 | + |
2953 | 2989 | describe('runAgentCommand', () => { |
2954 | 2990 | let testDir: string; |
2955 | 2991 |
|
|
0 commit comments