Skip to content

[Refactoring] Split test file into focused suites by feature area #8013

Description

@github-actions

Refactoring Opportunity

Summary

  • File: src/cloud-hypervisor-runtime-backend.test.ts
  • Current size: 1,180 lines
  • Responsibilities identified: single monolithic describe('Cloud Hypervisor runtime backend', ...) block containing 38 it() cases spanning at least 5 distinct concerns

Evidence

All 38 test cases live under one top-level describe (line 220) with no nested describe blocks. Test names cluster into clear feature areas:

  • Startup/preflight/boot (lines 232–438): "constructs default backend dependencies...", "plans filesystem.allowWrite before any boot attempt...", "reuses and cleans the snapshot created by the explicit preflight phase", "fails closed on an unmatched allowlist path...", "starts infrastructure, revalidates it, boots and probes...", "reuses the CLI preflight snapshot..."
  • Readiness probing/retry (lines 563–819): "stops the partial VM when readiness probing fails", "waits with bounded backoff for the complete guest data plane...", "retries the boot and fails with structured diagnostics...", "includes captured guest stdout/stderr in the readiness probe failure message", "includes captured guest network state...", "probes guest connectivity with the ARC build-tools baseline nc/wget commands", "uses bounded API proxy retries...", "recovers in the same invocation by recreating a VM after a classified readiness failure", "fails fast without boot recovery for a permanent connectivity configuration error"
  • Execution/cancellation (lines 954–1050): "does not retry a failed wrapped command after execution starts", "rejects execution before readiness and unsupported TTY execution", "cancels an active guest command before stopping", "cancels after stdin forwarding failure without changing command output", "serializes stdin chunks before sending EOF"
  • Diagnostics/cleanup hooks (lines 632–891): "marks itself stopped after a successful internal cleanup...", "collects diagnostics at most once even if called again after teardown...", "passes a beforeCleanup diagnostics hook to stop()...", "preserves boot-attempt diagnostics even when --diagnostic-logs is unset", "surfaces the original startup error even if pre-cleanup diagnostics collection itself fails", "fails closed when manager readiness or startup cleanup is unavailable"
  • Env/path sanitization (pure functions, no manager mocking) (lines 1050–1166): "preserves sanitized env values without leaking real provider secrets", "sets lowercase http_proxy so BusyBox wget honors the proxy...", "maps only exported runner paths...", "does not forward runner path variables without matching exports", "rejects unsupported strict-security and topology combinations"

The file exceeds the 1,000-line review threshold, and the last group (env/path sanitization) tests plain utility functions independent of the async manager-mocking setup used by the rest of the file — a strong signal it can be extracted as an isolated, faster-running unit-test file.

Proposed Split

  • src/cloud-hypervisor-runtime-backend.test.ts — keep shared mocks/dependencies setup + nested describe groups for boot/readiness/execution/diagnostics (~950 lines)
  • src/cloud-hypervisor-runtime-backend.env-mapping.test.ts — extract the pure env/path sanitization tests (lines ~1050–1166, ~120 lines), which don't require the manager mock scaffolding used elsewhere in the file

At minimum, wrap the existing flat test list in nested describe('startup and preflight'), describe('readiness probing'), describe('execution and cancellation'), describe('diagnostics and cleanup'), describe('env and path mapping') blocks for navigability even without a full file split.

Affected Callers

Test-only file; no production callers. Jest test discovery (**/*.test.ts) picks up any new split file automatically.

Effort Estimate

Low (nested describe grouping) to Medium (extracting the env-mapping tests into their own file)

Benefits

  • Faster, more isolated test runs for pure env/path-mapping logic without manager mock overhead
  • Easier to locate and modify tests for a specific runtime-backend concern
  • Smaller, more reviewable diffs when adding coverage for one area (e.g., readiness retries) without touching unrelated sections

Detected by Refactoring Scanner workflow. Run date: 2026-09-02

Generated by Refactoring Opportunity Scanner · copilot · auto · 43.4 AIC · ⊞ 10.9K ·

  • expires on Nov 1, 2026, 3:04 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