Skip to content

Commit abffc75

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 40393d3 commit abffc75

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, validateFormat, validateApiProxyConfig, buildRateLimitConfig, validateRateLimitFlags } from './cli';
2+
import { parseEnvironmentVariables, parseDomains, parseDomainsFile, escapeShellArg, joinShellArgs, parseVolumeMounts, isValidIPv4, isValidIPv6, parseDnsServers, validateAgentImage, isAgentImagePreset, AGENT_IMAGE_PRESETS, processAgentImageOption, processLocalhostKeyword, validateSkipPullWithBuildLocal, validateAllowHostPorts, validateFormat, validateApiProxyConfig, buildRateLimitConfig, validateRateLimitFlags, handlePredownloadAction } from './cli';
33
import { redactSecrets } from './redact-secrets';
44
import * as fs from 'fs';
55
import * as path from 'path';
@@ -1539,4 +1539,28 @@ describe('cli', () => {
15391539
expect(result.error).toBeUndefined();
15401540
});
15411541
});
1542+
1543+
describe('handlePredownloadAction', () => {
1544+
it('should delegate to predownloadCommand with correct options', async () => {
1545+
// Mock the predownload module that handlePredownloadAction dynamically imports
1546+
const mockPredownloadCommand = jest.fn().mockResolvedValue(undefined);
1547+
jest.mock('./commands/predownload', () => ({
1548+
predownloadCommand: mockPredownloadCommand,
1549+
}));
1550+
1551+
await handlePredownloadAction({
1552+
imageRegistry: 'ghcr.io/test',
1553+
imageTag: 'v1.0',
1554+
agentImage: 'default',
1555+
enableApiProxy: false,
1556+
});
1557+
1558+
expect(mockPredownloadCommand).toHaveBeenCalledWith({
1559+
imageRegistry: 'ghcr.io/test',
1560+
imageTag: 'v1.0',
1561+
agentImage: 'default',
1562+
enableApiProxy: false,
1563+
});
1564+
});
1565+
});
15421566
});

src/cli.ts

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

1285+
// Predownload action handler - exported for testing
1286+
export async function handlePredownloadAction(options: {
1287+
imageRegistry: string;
1288+
imageTag: string;
1289+
agentImage: string;
1290+
enableApiProxy: boolean;
1291+
}): Promise<void> {
1292+
const { predownloadCommand } = await import('./commands/predownload');
1293+
await predownloadCommand({
1294+
imageRegistry: options.imageRegistry,
1295+
imageTag: options.imageTag,
1296+
agentImage: options.agentImage,
1297+
enableApiProxy: options.enableApiProxy,
1298+
});
1299+
}
1300+
12851301
// Predownload subcommand - pre-pull container images
12861302
program
12871303
.command('predownload')
@@ -1298,15 +1314,7 @@ program
12981314
'default'
12991315
)
13001316
.option('--enable-api-proxy', 'Also download the API proxy image', false)
1301-
.action(async (options) => {
1302-
const { predownloadCommand } = await import('./commands/predownload');
1303-
await predownloadCommand({
1304-
imageRegistry: options.imageRegistry,
1305-
imageTag: options.imageTag,
1306-
agentImage: options.agentImage,
1307-
enableApiProxy: options.enableApiProxy,
1308-
});
1309-
});
1317+
.action(handlePredownloadAction);
13101318

13111319
// Logs subcommand - view Squid proxy logs
13121320
const logsCmd = program

0 commit comments

Comments
 (0)