Skip to content

Commit d2c3f2a

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 b6375a9 commit d2c3f2a

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, formatItem, program } 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, formatItem, program, handlePredownloadAction } from './cli';
33
import { redactSecrets } from './redact-secrets';
44
import * as fs from 'fs';
55
import * as path from 'path';
@@ -1783,4 +1783,27 @@ describe('cli', () => {
17831783
});
17841784
});
17851785

1786+
describe('handlePredownloadAction', () => {
1787+
it('should delegate to predownloadCommand with correct options', async () => {
1788+
// Mock the predownload module that handlePredownloadAction dynamically imports
1789+
const mockPredownloadCommand = jest.fn().mockResolvedValue(undefined);
1790+
jest.mock('./commands/predownload', () => ({
1791+
predownloadCommand: mockPredownloadCommand,
1792+
}));
1793+
1794+
await handlePredownloadAction({
1795+
imageRegistry: 'ghcr.io/test',
1796+
imageTag: 'v1.0',
1797+
agentImage: 'default',
1798+
enableApiProxy: false,
1799+
});
1800+
1801+
expect(mockPredownloadCommand).toHaveBeenCalledWith({
1802+
imageRegistry: 'ghcr.io/test',
1803+
imageTag: 'v1.0',
1804+
agentImage: 'default',
1805+
enableApiProxy: false,
1806+
});
1807+
});
1808+
});
17861809
});

src/cli.ts

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

1485+
// Predownload action handler - exported for testing
1486+
export async function handlePredownloadAction(options: {
1487+
imageRegistry: string;
1488+
imageTag: string;
1489+
agentImage: string;
1490+
enableApiProxy: boolean;
1491+
}): Promise<void> {
1492+
const { predownloadCommand } = await import('./commands/predownload');
1493+
await predownloadCommand({
1494+
imageRegistry: options.imageRegistry,
1495+
imageTag: options.imageTag,
1496+
agentImage: options.agentImage,
1497+
enableApiProxy: options.enableApiProxy,
1498+
});
1499+
}
1500+
14851501
// Predownload subcommand - pre-pull container images
14861502
program
14871503
.command('predownload')
@@ -1498,15 +1514,7 @@ program
14981514
'default'
14991515
)
15001516
.option('--enable-api-proxy', 'Also download the API proxy image', false)
1501-
.action(async (options) => {
1502-
const { predownloadCommand } = await import('./commands/predownload');
1503-
await predownloadCommand({
1504-
imageRegistry: options.imageRegistry,
1505-
imageTag: options.imageTag,
1506-
agentImage: options.agentImage,
1507-
enableApiProxy: options.enableApiProxy,
1508-
});
1509-
});
1517+
.action(handlePredownloadAction);
15101518

15111519
// Logs subcommand - view Squid proxy logs
15121520
const logsCmd = program

0 commit comments

Comments
 (0)