Skip to content

[Refactoring] Split src/commands/main-action.test.ts into focused test suites #9070

Description

@github-actions

Refactoring Opportunity

Summary

  • File: src/commands/main-action.test.ts
  • Current size: 1,173 lines (22 describe blocks, 54 it cases)
  • Responsibilities identified: at least 4 distinct concerns bundled into one spec file

Evidence

Top-level describe blocks span unrelated concerns:

80:describe('createMainAction', () => {
114:  describe('when args is empty', () => {
151:  describe('when --reflect is used with a command', () => {
162:  describe('when single arg is provided', () => {
173:    describe('work directory selection', () => {
256:  describe('when multiple args are provided', () => {
273:  describe('happy path', () => {
424:  describe('when runMainWorkflow returns non-zero exit code', () => {
432:    describe('sbx runtime wiring', () => {
481:  describe('when runMainWorkflow throws', () => {
590:    describe('when external runtime resolution fails', () => {
609:    describe('when external runtime preflight fails', () => {
678:  describe('performCleanup with keepContainers=true', () => {
727:  describe('external runtime cleanup failures', () => {
759:  describe('external runtime diagnostics', () => {
798:  describe('performCleanup with containers started', () => {
828:  describe('performCleanup signal parameter', () => {
845:  describe('onContainersStarted and onHostIptailesSetup callbacks', () => {
866:  describe('fatal error cleanup after containers started', () => {
900:  describe('redaction of sensitive config fields', () => {

followed by a describe('resolved config artifact', ...) block (audit-dir writing, secret redaction in the on-disk artifact) that runs to the end of the file.

These map onto at least four logically separate concerns: (1) CLI arg parsing/dispatch (empty args, --reflect, single/multi args, work-dir selection), (2) container lifecycle / external runtime wiring (sbx runtime, external runtime resolution/preflight failures), (3) cleanup semantics (performCleanup variants, signal handling, callbacks, fatal-error cleanup), and (4) secret redaction / audit artifact writing (both the "redaction of sensitive config fields" and "resolved config artifact" blocks).

Proposed Split

  • src/commands/main-action.test.ts — CLI dispatch and arg-parsing behavior (~300 lines)
  • src/commands/main-action-lifecycle.test.ts — container/external-runtime start, sbx wiring, resolution/preflight failure paths (~350 lines)
  • src/commands/main-action-cleanup.test.ts — performCleanup variants, signal handling, callbacks, fatal-error cleanup (~250 lines)
  • src/commands/main-action-audit.test.ts — secret redaction and awf-resolved-config.json artifact writing (~270 lines)

Shared fixtures (e.g. MAIN_ACTION_STUB_CONFIG, common mocks for docker-manager, validateOptions) should move to a src/commands/main-action-test-helpers.ts module imported by all four files.

Affected Callers

Test-only file; no production imports. src/cli.ts imports createMainAction from ./commands/main-action (the file under test), which is unaffected by this split.

Effort Estimate

Medium

Benefits

  • Each suite becomes independently reviewable and faster to navigate for its concern (dispatch vs. lifecycle vs. cleanup vs. audit)
  • Reduces risk of merge conflicts when multiple engineers touch different behaviors of createMainAction
  • Shared fixtures/mocks become explicit and reusable rather than re-declared implicitly across unrelated blocks

Detected by Refactoring Scanner workflow.

Generated by Refactoring Opportunity Scanner · copilot · auto · 74.7 AIC · ⊞ 10.8K · ◷

  • expires on Nov 26, 2026, 3:06 PM UTC

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions