refactor: split main-action.ts into validate-options and build-config modules#3229
Conversation
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
Refactors the CLI entrypoint by extracting option validation and config assembly out of src/commands/main-action.ts, reducing the orchestration function’s size and centralizing the pre-/post-config guardrails that gate process.exit(1).
Changes:
- Added
validateOptions()to own CLI option validation, guardrails, and post-assembly checks before returning a ready-to-useWrapperConfig. - Added
buildConfig()to assembleWrapperConfigfrom pre-parsed inputs and centralize API key/env resolution. - Simplified
main-action.tsto orchestrate argument handling, config precedence, validation/config creation, and workflow execution.
Show a summary per file
| File | Description |
|---|---|
| src/commands/validate-options.ts | New module encapsulating CLI validation + guardrails and returning a validated WrapperConfig. |
| src/commands/build-config.ts | New module assembling WrapperConfig (including env-based credential resolution) from pre-validated inputs. |
| src/commands/main-action.ts | Reduced to orchestration: parse args, apply config-file precedence, call validateOptions, then run workflow + cleanup. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 3/3 changed files
- Comments generated: 1
| // Parse --allow-urls for SSL Bump mode | ||
| let allowedUrls: string[] | undefined; | ||
| if (options.allowUrls) { | ||
| allowedUrls = parseDomains(options.allowUrls as string); | ||
| if (allowedUrls.length > 0 && !options.sslBump) { | ||
| logger.error('--allow-urls requires --ssl-bump to be enabled'); | ||
| process.exit(1); | ||
| } |
This comment has been minimized.
This comment has been minimized.
|
@copilot address the review feedback |
Added Coverage includes:
Also added |
Smoke Test Results
Result: 2/3 PASS
|
🔬 Smoke Test Results
Overall: FAIL — GitHub MCP returned 401; workflow template variables (
|
Smoke Test: Copilot BYOK (Offline) Mode
Running in BYOK offline mode ( Overall: PARTIAL — BYOK inference path confirmed working; pre-step outputs were not interpolated into the prompt.
|
Smoke TestMerged PRs: fix: clean up remaining export audit issues; fix(api-proxy): apply responses wire API unconditionally for GPT-5/O3 models on COPILOT_GITHUB_TOKEN path 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.
|
Smoke Test Results\n\n1. GitHub MCP Testing: ❌\n2. GitHub.com Connectivity: ❌\n3. File Writing Testing: ✅\n4. Bash Tool Testing: ✅\n\nOverall status: FAILWarning Firewall blocked 1 domainThe following domain was blocked by the firewall during workflow execution:
network:
allowed:
- defaults
- "localhost"See Network Configuration for more information.
|
Chroot Smoke Test Results
Result: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot.
|
🏗️ Build Test Suite Results
Overall: 8/8 ecosystems passed — ✅ PASS
|
Smoke Test Results — FAIL
Overall: FAIL —
|
src/commands/main-action.tscontained a single 540-linemainActionfunction embedding five distinct concerns, making it the hardest function to review in the codebase and a bottleneck for security audits of domain/URL validation logic.Changes
src/commands/build-config.ts(new) — purebuildConfig(inputs: BuildConfigInputs): WrapperConfigassembly; no validation, no side effects. API key resolution fromprocess.envis centralised here.src/commands/validate-options.ts(new) —validateOptions(options, agentCommand): WrapperConfig; owns all 19process.exit(1)guards: log level, URL pattern safety, memory limits, env vars, volume mounts, feature-flag compatibility, API proxy config, rate limits. CallsbuildConfigafter pre-config validation, then runs post-config checks.src/commands/main-action.ts(reduced 607 → 173 lines) — now purely orchestrates: parse args →applyConfigFilePrecedence→validateOptions→setAwfDockerHost→ log config → wire cleanup/signals →runMainWorkflow. No public API change;createMainActionremains the single export.