[Test Coverage] Add test coverage for subcommands and main-action#3288
Conversation
Add unit tests for two low-coverage modules: - src/commands/subcommands.ts (47% → ~80%+) - src/commands/main-action.ts (19% → ~70%+) subcommands.test.ts: - Verifies all subcommands are registered (predownload, logs, stats, summary, audit) - Tests validateFormat rejects invalid format strings with process.exit(1) - Tests validateFormat accepts all valid format strings - Tests invalid/valid decision filters in logs audit subcommand - Tests --with-pid warning when used without -f - Tests predownload error handling (exitCode propagation) main-action.test.ts: - Tests empty args → process.exit(1) with usage error - Tests single arg passed as-is (shell variable preservation) - Tests multiple args joined via joinShellArgs - Tests full happy path (0 exit code) - Tests non-zero exit code propagation - Tests fatal error → performCleanup → process.exit(1) - Tests API key redaction in debug logs (security) - Tests blocked domains logging Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Pull request overview
Adds new Jest unit tests to raise coverage for the CLI command registration layer (registerSubcommands) and the main CLI action handler (createMainAction), improving confidence in argument handling and security-related validation paths.
Changes:
- Add
subcommands.test.tscovering subcommand registration plus format/decision validation and predownload error exit-code behavior. - Add
main-action.test.tscovering command argument handling, config flow wiring, exit-code propagation, and config logging redaction.
Show a summary per file
| File | Description |
|---|---|
src/commands/subcommands.test.ts |
New tests for subcommand registration, format/decision validation, and predownload error exit-code handling. |
src/commands/main-action.test.ts |
New tests for createMainAction covering args handling, workflow orchestration calls, exit behavior, and redaction checks. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 4
| describe('predownload defaults', () => { | ||
| it('sets default image-registry to ghcr.io/github/gh-aw-firewall', () => { | ||
| const program = makeProgram(); | ||
| const predownload = program.commands.find((c) => c.name() === 'predownload')!; | ||
| expect(predownload.opts().imageRegistry).toBe('ghcr.io/github/gh-aw-firewall'); | ||
| }); |
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| processExitSpy = jest.spyOn(process, 'exit').mockImplementation(() => undefined as never); | ||
| consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(); | ||
| getOptionValueSource = jest.fn().mockReturnValue(undefined); |
| expect(mockedLogger.error).toHaveBeenCalledWith( | ||
| 'Fatal error:', | ||
| expect.any(Error) | ||
| ); |
| if (configDebugCall) { | ||
| const serialized = String(configDebugCall[1]); | ||
| expect(serialized).not.toContain('sk-secret'); | ||
| expect(serialized).not.toContain('ant-secret'); | ||
| expect(serialized).not.toContain('ghp-secret'); | ||
| expect(serialized).not.toContain('cop-secret'); | ||
| expect(serialized).not.toContain('gem-secret'); | ||
| } |
This comment has been minimized.
This comment has been minimized.
|
@copilot address review feedback |
Addressed in commit 36ea17d. Updated the tests to:
Validated with:
|
Smoke Test Results❌ GitHub API — gh CLI authentication failed (HTTP 401) Overall: FAIL (1 of 3 tests failed)
|
🔥 Smoke Test: Copilot BYOK (Offline) Mode
Running in BYOK offline mode ( Overall: FAIL — pre-step smoke data (
|
🔬 Smoke Test Results
Overall: FAIL — GitHub MCP returned 401 and workflow template variables were not substituted before agent execution.
|
|
PRs reviewed: chore: recompile test-coverage-improver lock file; chore: run test coverage improver twice daily Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "registry.npmjs.org"See Network Configuration for more information.
|
Chroot Smoke Test Results
Result: FAILED — Python and Node.js versions differ between host and chroot environment.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Smoke Test Results — Services Connectivity
Overall: FAIL — Service containers appear not to be running in this workflow environment.
|
|
Smoke Test Results: MCP: ❌ (401), Connectivity: ❌ (000), File: ✅, Bash: ✅. Overall: FAIL Warning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
Summary
Adds unit tests for two low-coverage modules:
src/commands/subcommands.tssrc/commands/main-action.tsNew Test Files
src/commands/subcommands.test.ts(~30 tests)Tests the
registerSubcommandsfunction and the inlinevalidateFormathelper:predownload,logs,logs stats,logs summary,logs auditare all registeredimageRegistry,imageTag,agentImage,enableApiProxydefault valuesvalidateFormatrejects invalid strings withprocess.exit(1)across all subcommandsraw,pretty,json,markdownare acceptedlogs audit --decisionrejects values other thanallowed/denied--with-pidwarning: logs warning when used without-fexitCodepropagation from errors thrown bypredownloadCommandsrc/commands/main-action.test.ts(~18 tests)Tests the
createMainActionfactory and the returnedmainActionfunction:$HOMEmust expand in container, not host)joinShellArgsapplyConfigFilePrecedence→validateOptions→setAwfDockerHostregisterSignalHandlersis calledrunMainWorkfloware propagatedlogger.error+performCleanup+process.exit(1)on thrown errorsopenaiApiKey,anthropicApiKey,copilotGithubToken,copilotApiKey,geminiApiKeyare excluded from debug logsSecurity-Critical Paths Covered
validateFormatedge cases)Test Design
jest.mock()for dynamic imports inside action handlersprocess.exitmocked to prevent test runner termination