Skip to content

Commit ef4cfca

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 8fb4180 commit ef4cfca

File tree

2 files changed

+42
-10
lines changed

2 files changed

+42
-10
lines changed

src/cli.test.ts

Lines changed: 25 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, parseAgentTimeout, applyAgentTimeout } 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, parseAgentTimeout, applyAgentTimeout, handlePredownloadAction } from './cli';
33
import { redactSecrets } from './redact-secrets';
44
import * as fs from 'fs';
55
import * as path from 'path';
@@ -1881,4 +1881,28 @@ describe('cli', () => {
18811881
expect(result).toBe(' --flag');
18821882
});
18831883
});
1884+
1885+
describe('handlePredownloadAction', () => {
1886+
it('should delegate to predownloadCommand with correct options', async () => {
1887+
// Mock the predownload module that handlePredownloadAction dynamically imports
1888+
const mockPredownloadCommand = jest.fn().mockResolvedValue(undefined);
1889+
jest.mock('./commands/predownload', () => ({
1890+
predownloadCommand: mockPredownloadCommand,
1891+
}));
1892+
1893+
await handlePredownloadAction({
1894+
imageRegistry: 'ghcr.io/test',
1895+
imageTag: 'v1.0',
1896+
agentImage: 'default',
1897+
enableApiProxy: false,
1898+
});
1899+
1900+
expect(mockPredownloadCommand).toHaveBeenCalledWith({
1901+
imageRegistry: 'ghcr.io/test',
1902+
imageTag: 'v1.0',
1903+
agentImage: 'default',
1904+
enableApiProxy: false,
1905+
});
1906+
});
1907+
});
18841908
});

src/cli.ts

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

1524+
// Predownload action handler - exported for testing
1525+
export async function handlePredownloadAction(options: {
1526+
imageRegistry: string;
1527+
imageTag: string;
1528+
agentImage: string;
1529+
enableApiProxy: boolean;
1530+
}): Promise<void> {
1531+
const { predownloadCommand } = await import('./commands/predownload');
1532+
await predownloadCommand({
1533+
imageRegistry: options.imageRegistry,
1534+
imageTag: options.imageTag,
1535+
agentImage: options.agentImage,
1536+
enableApiProxy: options.enableApiProxy,
1537+
});
1538+
}
1539+
15241540
// Predownload subcommand - pre-pull container images
15251541
program
15261542
.command('predownload')
@@ -1537,15 +1553,7 @@ program
15371553
'default'
15381554
)
15391555
.option('--enable-api-proxy', 'Also download the API proxy image', false)
1540-
.action(async (options) => {
1541-
const { predownloadCommand } = await import('./commands/predownload');
1542-
await predownloadCommand({
1543-
imageRegistry: options.imageRegistry,
1544-
imageTag: options.imageTag,
1545-
agentImage: options.agentImage,
1546-
enableApiProxy: options.enableApiProxy,
1547-
});
1548-
});
1556+
.action(handlePredownloadAction);
15491557

15501558
// Logs subcommand - view Squid proxy logs
15511559
const logsCmd = program

0 commit comments

Comments
 (0)