Skip to content

Commit 5a962a4

Browse files
Mossakaclaude
andcommitted
test(cli): add handlePredownloadAction test for coverage
Extract predownload action handler to named exported function and add unit test to maintain function coverage levels. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cefeca7 commit 5a962a4

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

src/cli.test.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Command } from 'commander';
2-
import { parseEnvironmentVariables, parseDomains, parseDomainsFile, escapeShellArg, joinShellArgs, parseVolumeMounts, isValidIPv4, isValidIPv6, parseDnsServers, validateAgentImage, isAgentImagePreset, AGENT_IMAGE_PRESETS, processAgentImageOption, processLocalhostKeyword, validateSkipPullWithBuildLocal, validateAllowHostPorts, parseMemoryLimit, validateFormat, validateApiProxyConfig, buildRateLimitConfig, validateRateLimitFlags, validateApiTargetInAllowedDomains, DEFAULT_OPENAI_API_TARGET, DEFAULT_ANTHROPIC_API_TARGET, emitApiProxyTargetWarnings } from './cli';
2+
import { parseEnvironmentVariables, parseDomains, parseDomainsFile, escapeShellArg, joinShellArgs, parseVolumeMounts, isValidIPv4, isValidIPv6, parseDnsServers, validateAgentImage, isAgentImagePreset, AGENT_IMAGE_PRESETS, processAgentImageOption, processLocalhostKeyword, validateSkipPullWithBuildLocal, validateAllowHostPorts, parseMemoryLimit, validateFormat, validateApiProxyConfig, buildRateLimitConfig, validateRateLimitFlags, validateApiTargetInAllowedDomains, DEFAULT_OPENAI_API_TARGET, DEFAULT_ANTHROPIC_API_TARGET, emitApiProxyTargetWarnings, handlePredownloadAction } from './cli';
33
import { redactSecrets } from './redact-secrets';
44
import * as fs from 'fs';
55
import * as path from 'path';
@@ -1732,4 +1732,27 @@ describe('cli', () => {
17321732
});
17331733
});
17341734

1735+
describe('handlePredownloadAction', () => {
1736+
it('should delegate to predownloadCommand with correct options', async () => {
1737+
// Mock the predownload module that handlePredownloadAction dynamically imports
1738+
const mockPredownloadCommand = jest.fn().mockResolvedValue(undefined);
1739+
jest.mock('./commands/predownload', () => ({
1740+
predownloadCommand: mockPredownloadCommand,
1741+
}));
1742+
1743+
await handlePredownloadAction({
1744+
imageRegistry: 'ghcr.io/test',
1745+
imageTag: 'v1.0',
1746+
agentImage: 'default',
1747+
enableApiProxy: false,
1748+
});
1749+
1750+
expect(mockPredownloadCommand).toHaveBeenCalledWith({
1751+
imageRegistry: 'ghcr.io/test',
1752+
imageTag: 'v1.0',
1753+
agentImage: 'default',
1754+
enableApiProxy: false,
1755+
});
1756+
});
1757+
});
17351758
});

src/cli.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,22 @@ export function validateFormat(format: string, validFormats: string[]): void {
14011401
}
14021402
}
14031403

1404+
// Predownload action handler - exported for testing
1405+
export async function handlePredownloadAction(options: {
1406+
imageRegistry: string;
1407+
imageTag: string;
1408+
agentImage: string;
1409+
enableApiProxy: boolean;
1410+
}): Promise<void> {
1411+
const { predownloadCommand } = await import('./commands/predownload');
1412+
await predownloadCommand({
1413+
imageRegistry: options.imageRegistry,
1414+
imageTag: options.imageTag,
1415+
agentImage: options.agentImage,
1416+
enableApiProxy: options.enableApiProxy,
1417+
});
1418+
}
1419+
14041420
// Predownload subcommand - pre-pull container images
14051421
program
14061422
.command('predownload')
@@ -1417,15 +1433,7 @@ program
14171433
'default'
14181434
)
14191435
.option('--enable-api-proxy', 'Also download the API proxy image', false)
1420-
.action(async (options) => {
1421-
const { predownloadCommand } = await import('./commands/predownload');
1422-
await predownloadCommand({
1423-
imageRegistry: options.imageRegistry,
1424-
imageTag: options.imageTag,
1425-
agentImage: options.agentImage,
1426-
enableApiProxy: options.enableApiProxy,
1427-
});
1428-
});
1436+
.action(handlePredownloadAction);
14291437

14301438
// Logs subcommand - view Squid proxy logs
14311439
const logsCmd = program

0 commit comments

Comments
 (0)