Skip to content

refactor: split src/cli.ts into focused modules#2900

Merged
lpcox merged 3 commits into
mainfrom
copilot/refactor-split-src-cli-into-modules
May 11, 2026
Merged

refactor: split src/cli.ts into focused modules#2900
lpcox merged 3 commits into
mainfrom
copilot/refactor-split-src-cli-into-modules

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

src/cli.ts had grown to 1,394 lines serving four unrelated responsibilities, making the main action handler (~700 lines) untestable in isolation and every subcommand addition inflating the entry point further.

Changes

  • src/cli-options.ts — Commander program creation, custom help formatter, and all program.option() / .argument() declarations (~280 lines)
  • src/commands/main-action.ts — the main awf action handler extracted verbatim, with one design improvement: instead of importing the global program instance to call getOptionValueSource, the handler is now produced by a factory:
    export function createMainAction(getOptionValueSource: OptionSourceResolver) { ... }
    // wired in cli.ts as:
    program.action(createMainAction(program.getOptionValueSource.bind(program)));
    This decouples the handler from the global singleton, enabling unit testing without spinning up Commander.
  • src/commands/subcommands.tsvalidateFormat, handlePredownloadAction, and registerSubcommands() which registers the predownload, logs, logs stats, logs summary, and logs audit Commander subcommands (~165 lines)
  • src/cli.ts — reduced to a ~75-line thin entry point that wires the above together; all backward-compat re-exports are preserved so no existing callers break

Copilot AI linked an issue May 11, 2026 that may be closed by this pull request
Copilot AI added 2 commits May 11, 2026 14:05
Extract cli.ts (1394 lines) into four focused modules:

- src/cli-options.ts: program creation, custom help formatter, and
  all option/argument declarations (~370 lines)
- src/commands/main-action.ts: the main awf action handler with signal
  handling and orchestration (~700 lines)
- src/commands/subcommands.ts: validateFormat, handlePredownloadAction,
  and Commander predownload/logs subcommand registrations (~160 lines)
- src/cli.ts: thin entry point that wires the above together and keeps
  backward-compat re-exports (~90 lines)

All 1817 tests pass and type-check is clean."
- Replace direct program import in main-action.ts with injectable
  OptionSourceResolver type and createMainAction() factory, decoupling
  the handler from the global program instance for easier unit testing
- Consolidate cli.ts imports to avoid duplicate import/re-export for
  program, validateFormat, and handlePredownloadAction
Copilot AI changed the title [WIP] Refactor cli.ts by splitting into focused modules refactor: split src/cli.ts into focused modules May 11, 2026
Copilot AI requested a review from lpcox May 11, 2026 14:12
Copilot finished work on behalf of lpcox May 11, 2026 14:12
@lpcox lpcox marked this pull request as ready for review May 11, 2026 14:59
@lpcox lpcox requested a review from Mossaka as a code owner May 11, 2026 14:59
Copilot AI review requested due to automatic review settings May 11, 2026 14:59
@github-actions
Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 87.84% 87.99% 📈 +0.15%
Statements 87.77% 87.93% 📈 +0.16%
Functions 82.78% 82.97% 📈 +0.19%
Branches 79.72% 79.83% 📈 +0.11%
📁 Per-file Coverage Changes (2 files)
File Lines (Before → After) Statements (Before → After)
src/container-lifecycle.ts 87.1% → 88.2% (+1.14%) 87.5% → 88.6% (+1.11%)
src/cli.ts 28.0% → 98.3% (+70.32%) 28.0% → 98.4% (+70.42%)
✨ New Files (3 files)
  • src/cli-options.ts: 93.0% lines
  • src/commands/main-action.ts: 5.9% lines
  • src/commands/subcommands.ts: 44.7% lines

Coverage comparison generated by scripts/ci/compare-coverage.ts

@github-actions
Copy link
Copy Markdown
Contributor

🧪 Smoke Test Results

Test Result
GitHub MCP connectivity ❌ (401 Bad credentials)
GitHub.com HTTP connectivity ✅ HTTP 200
File write/read smoke-test-copilot-25675471202.txt verified

Overall: FAIL — GitHub MCP auth is not available in this environment.

Note: PR details unavailable due to MCP auth failure; no assignee info retrievable.

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Offline) Mode

Test Result
GitHub MCP connectivity ❌ 401 Bad credentials
GitHub.com HTTP check ⚠️ Template var not expanded (${{ steps.smoke-data.outputs.SMOKE_HTTP_CODE }})
File write/read ⚠️ Template var not expanded (path not resolved)
BYOK inference (this response)

Note: Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com

Overall: FAIL — pre-step template variables were not expanded; GitHub MCP returned 401.

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Tests

  • ❌ GitHub MCP (auth failed)
  • ✅ Playwright: github.com page verified
  • ✅ File writing: test file created
  • ✅ Bash execution: file verification passed

**Status: 3/4 PASS

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

Chroot Smoke Test Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.14.1 v20.20.2
Go go1.22.12 go1.22.12

Result: ❌ Not all versions matched — smoke-chroot label not applied.

Go matches, but Python and Node.js differ between host and chroot environments.

Tested by Smoke Chroot

@github-actions
Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx All passed ✅ PASS
Node.js execa All passed ✅ PASS
Node.js p-limit All passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #2900 · ● 457.2K ·

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

Check Result
Redis PING ❌ Timeout (no response on host.docker.internal:6379)
PostgreSQL pg_isready ❌ No response on host.docker.internal:5432
PostgreSQL SELECT 1 ❌ No response

Overall: FAILhost.docker.internal is not reachable from this agent environment. Service containers appear to be unavailable or not started.

🔌 Service connectivity validated by Smoke Services

@github-actions
Copy link
Copy Markdown
Contributor

Overall status: FAIL
PRs: Add first-class ARC/DinD compatibility mode for AWF; Fix chroot bind mounts for ARC/DinD split runner-daemon filesystems
❌ GitHub MCP: unavailable
❌ safeinputs-gh: unavailable
✅ Playwright title check
❌ Tavily search: no callable search tool
✅ File write + bash read
❌ Discussion query: unavailable
✅ npm ci + npm run build

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the CLI entrypoint by splitting the former monolithic src/cli.ts into focused modules, keeping the existing public re-exports intact while making the main action handler injectable/testable without requiring a global Commander singleton.

Changes:

  • Extracted Commander program construction + option/argument declarations into src/cli-options.ts.
  • Extracted the main awf action handler into src/commands/main-action.ts, now produced via a factory that injects getOptionValueSource.
  • Extracted subcommand registration + helpers into src/commands/subcommands.ts, leaving src/cli.ts as a thin wiring/entry module.
Show a summary per file
File Description
src/cli.ts Reduced to a thin entrypoint that preserves backwards-compat re-exports and wires program/action/subcommands.
src/cli-options.ts Centralizes Commander program creation, help formatting, and all option/argument declarations.
src/commands/main-action.ts Houses the main CLI action handler, now created via a factory for better testability/decoupling.
src/commands/subcommands.ts Registers predownload and logs/* subcommands and exports the related helpers for compatibility/tests.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 4/4 changed files
  • Comments generated: 0

@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 11, 2026

@copilot address review feedback

@lpcox lpcox merged commit 34c816c into main May 11, 2026
67 of 74 checks passed
@lpcox lpcox deleted the copilot/refactor-split-src-cli-into-modules branch May 11, 2026 15:20
Copilot stopped work on behalf of lpcox due to an error May 11, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Refactoring] Split src/cli.ts into focused modules

3 participants