Skip to content

Extract attemptGatewayStart helper from startGatewayWithOptions for caller-level testability #5113

Closed

Description

@jyaunches

Context

PR #5109 retired test/e2e/test-docker-unreachable-gateway-start.sh (originally protecting #2347 — the gateway-start fallback when Docker/Colima is unreachable). The replacement Vitest integration test at src/lib/onboard/gateway-start-failure-integration.test.ts covers everything reachable through already-exported helpers (printDockerDaemonRecovery, handleFinalGatewayStartFailure, reportLegacyGatewayStartResultFailure, classifyGatewayStartFailure) plus a composition test of the call-site sequence, but it leaves three caller-level contracts as it.todo placeholders because they cannot be proven without driving startGatewayWithOptions past its ~200 lines of preamble (gateway-reuse / ssh-keygen / known_hosts / docker-driver-detect).

What's missing

The three documented it.todo contracts in call-site contracts (caller-level coverage gap):

  1. startGateway aborts via pRetry.AbortError without entering health-poll loop on docker-unreachable streamGatewayStart output
  2. startGateway never invokes openshell statusorgateway info after docker-unreachable streamGatewayStart output
  3. startGateway forwards dockerUnreachable=true to handleFinalGatewayStartFailure (no doctor logs collection, no destroyGateway cleanup) when streamGatewayStart returns docker-unreachable signature

Proposed fix

Extract the inner pRetry async body of startGatewayWithOptions (lines ~2310–2370 of src/lib/onboard.ts) into an exported helper that takes streamGatewayStart as a DI parameter, e.g.:

export async function attemptGatewayStart(
  streamGatewayStartFn: typeof streamGatewayStart,
  args: { command: string; env: NodeJS.ProcessEnv; healthPollCount: number; healthPollInterval: number; ... },
  emitWaitingForHealth: () => void,
  runStatusProbe: () => string,
  runGatewayInfoProbe: (named: boolean) => string,
  // ... other DI seams
): Promise<{ outcome: "healthy" | "unknown_failure"; dockerUnreachable: boolean }> { /* ... */ }

Then startGatewayWithOptions wraps attemptGatewayStart inside its existing try/catch + handleFinalGatewayStartFailure plumbing, and the test drives attemptGatewayStart directly with a mocked streamGatewayStartFn that returns the docker-unreachable signature.

Acceptance

  • The three it.todo entries in gateway-start-failure-integration.test.ts convert to real it() blocks and assert exactly what they claim.
  • startGatewayWithOptions behavior on main is unchanged (regression-test it the same way you'd test any refactor).

Refs

Activity

  1. jyaunches commented on Jun 10, 2026

    @jyaunches
    ContributorAuthor

    Re-scoping after PR #5109 merged: I missed prior art when I filed this issue. test/onboard.test.ts:357 (it("fast-fails gateway start before health polling when Docker is unreachable (#2347)", ...)) already proves two of the three caller-level contracts I listed:

    • ✅ exit 1, recovery guidance, NO "Waiting for gateway health" (covers contract 1)
    • ✅ NO HEALTH POLL REACHED in stdout, i.e. no openshell status / gateway info probes after gateway-start failure (covers contract 2)
    • ❌ Does NOT assert absence of "Cleaning up failed gateway state..." — the only signal that distinguishes dockerUnreachable=true forwarding from other exit-1 paths through startGatewayWithOptions (contract 3 only)

    Re-scoped goal: rather than the full attemptGatewayStart extraction, the smallest change that closes the actual remaining gap is to add one assertion to the existing test/onboard.test.ts:357 test:

    assert.ok(
      !result.stderr.includes("Cleaning up failed gateway state"),
      "dockerUnreachable=true branch must skip cleanup messaging",
    );

    The seam-extraction refactor is still defensible if a future PR has a stronger reason for it (e.g. wanting to test additional startGatewayWithOptions branches without spawning a child process), but it shouldn't be gated on this issue.

    Follow-up PR #5118 corrects the documentation in gateway-start-failure-integration.test.ts and the inventory note that landed in #5109.

  2. added
    area: e2e
    on Jun 10, 2026
  3. cv commented on Jun 10, 2026

    @cv
    Collaborator

    Cross-linking the broader migration guidance from #5098: #5098 (comment)

    For this issue/#5119, the useful policy is narrower than the current inventory machinery: when a legacy E2E script is retired, the PR should show the replacement Vitest coverage or explicit retirement rationale. We should avoid making legacy-inventory.json a long-lived progress ledger; it will drift faster than the issues/PRs.

  4. added a commit that references this issue on Jun 10, 2026
    44376ec
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: e2e

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions