Skip to content

Refactor native tracker test fixture #2238

Closed

Description

@josecelano

Goal

Make the native tracker executable fixture easier and safer to understand, review, test, and change. Separate its private responsibilities so a maintainer, human or AI agent, can modify one concern with a bounded context consisting of the owning module, its colocated tests, and at most one or two named collaborators, without loading or disturbing unrelated child-process behavior. Improve the internal fixture API and module paths where that makes the test code clearer while retaining the executable behaviors and lifecycle guarantees protected by the tests.

Background

tests/common/native_tracker.rs is 1,272 lines and combines normal tracker lifecycle management, temporary-workspace and command creation, concurrent output capture and readiness probing, failed-start fixtures, Unix permission recovery, and unit tests. It is compiled independently by the lifecycle-signals and cli-configuration integration-test binaries, which use different subsets of its API.

The objective is not merely to reduce file size. The refactor should establish clear ownership of running and failed-start child resources, local reasoning about configuration/output/readiness/cleanup, tests colocated with the contracts they protect, smaller review surfaces, and module documentation that keeps ownership invariants in Git-tracked context rather than contributor or agent working memory.

This is especially important for AI-agent work: the current file forces an agent to retrieve lifecycle, failure, rendering, and probing code to change any one concern, obscuring which type owns a child process or deadline. Cohesive responsibility-based modules allow one module and its focused tests to provide a bounded context and a reviewable diff. Splitting beyond one responsibility per module would instead scatter control flow.

Two implementation constraints require deliberate treatment: nested module resolution under the fixture's #[path] inclusion in both test binaries, and consolidation of the current 21 #[allow(dead_code)] attributes under -D unused when each binary uses a different API subset.

Scope

In scope

  • Choose a clear module path and fixture API, updating both integration-test consumers.
  • Decide whether both binaries retain one facade or import narrower fixture modules under #[path] inclusion.
  • Extract cohesive modules for failed-start behavior, workspace/configuration and child-command construction, output capture, and health probing.
  • Keep normal NativeTracker startup, readiness, shutdown, and drop cleanup together with explicit ownership of its child process.
  • Preserve one absolute startup deadline across health probing and readiness retries.
  • Add short //! documentation to every fixture module stating what it owns and must not do.
  • Consolidate #[allow(dead_code)] at module level only when one binary leaves the entire module unused; retain item-level allowances otherwise.
  • Relocate unit tests with the implementation behavior they protect, preserving coverage.
  • Verify both executable-boundary integration-test binaries and fixture unit tests.

Out of scope

  • Changing tracker CLI configuration precedence, diagnostics, startup, health, signal behavior, timeout values, process signal policy, or test behavior merely while moving code.
  • Routing the fixture through tests/common/mod.rs or sharing it with the in-process fixture.
  • General refactoring of unrelated integration-test helpers.
  • Creating an ADR unless implementation reveals a durable cross-fixture architectural decision.

Technical task ledger

The linked native tracker fixture refactor plan is the sole ledger for code-refactor tasks, ordering, implementation commit points, responsibility maps, maintenance-task maps, and item statuses. Do not duplicate or independently track technical implementation tasks in this issue.

The plan must preserve these ownership invariants:

  • NativeTracker owns the running child; normal shutdown waits for it, and drop cleanup kills and reaps it before releasing the workspace.
  • NativeTrackerFailedStart owns the failed-start child; wait_for_exit reaps it and restores permissions, while Drop remains a non-panicking best-effort fallback.
  • TrackerOutputCapture drains stdout and stderr concurrently and joins both readers before diagnostics are final.
  • Workspace/configuration paths remain available until applicable child cleanup completes.
  • The root NativeTracker readiness loop owns one absolute startup deadline; resource-specific deadline constants stay with their owners.
  • Cross-module access uses internal visibility only, and no fixture item becomes more visible than before.

Issue workflow tasks

  • I1: Review and approve the issue specification and linked refactor plan.
  • I2: Create and link this GitHub issue, promote both planning artifacts to their open locations, and replace placeholders.
  • I3: Publish the planning artifacts, optionally through a documentation-only spec PR; no fixture implementation belongs in that PR.
  • I4: After every refactor-plan item and the issue acceptance review are complete, close this issue and archive both planning artifacts.

Implementation commit points remain exclusively in the linked refactor plan.

Acceptance criteria

  • Both integration-test consumers use a narrow, expressive fixture API and module layout; paths and signatures may change when the result is clearer and more maintainable.
  • Normal startup, readiness, graceful shutdown, and drop-path cleanup retain their ownership and deadline guarantees.
  • Failed-start invalid-source behavior, output diagnostics, permission restoration, and fallback cleanup retain their observable behavior.
  • Configuration/command construction and output/health support have clear internal ownership boundaries without unnecessary generic abstractions, and no item is more visible than before.
  • Fixture unit tests are colocated with their protected behavior and pass.
  • Every fixture module has a //! doc stating what it owns and must not do, consistent with the plan's responsibility map.
  • Every row of the plan's maintenance-task map can be completed using only its named primary module and collaborators.
  • #[allow(dead_code)] is module-level only where an entire module is unused by one binary, and no allowance hides code made dead by the refactor.
  • linter all exits with code 0 and all relevant tests pass.
  • Manual verification scenarios are completed and recorded in issue-local manual-verification-evidence.md.
  • Acceptance criteria are re-reviewed against the implemented behavior before closure.

Verification

Automatic

  • cargo test --test lifecycle-signals
  • cargo test --test cli-configuration
  • cargo test --test lifecycle-signals --test cli-configuration after every extraction
  • linter all
  • Repository pre-push checks when preparing the implementation PR

As a review aid rather than a gate, inspect git diff --color-moved=dimmed-zebra develop...HEAD -- tests/ so moved blocks remain distinguishable from visibility, import, and documentation changes.

Manual

  • Trace a signal test through the final fixture API into startup, readiness, shutdown, and drop cleanup. Confirm the normal lifecycle is understandable without entering failed-start implementation and every child, output reader, and workspace has one owner.
  • Trace an invalid-source test through source preparation, spawn, diagnostics, permission restoration, wait, and drop fallback. Confirm the failure lifecycle is understandable without entering normal readiness orchestration and ownership/deadlines remain explicit.
  • Walk every row in the plan's maintenance-task map using only the named primary module and collaborators. Record and resolve or justify any additional context required.

Record commands, observations, and evidence in manual-verification-evidence.md, then perform an evidence-based implementation completion review. Create an issue-local retrospective for reusable lessons, material design changes, or approved-plan deviations; otherwise record why one is unnecessary.

Risks

  • Moving ownership-sensitive cleanup may regress child or workspace lifetimes. Preserve the ownership map and run both integration-test binaries after each extraction.
  • A bare nested mod child; under a #[path]-loaded fixture resolves beside that file, not beneath a same-named directory. Settle the layout in the plan before extracting modules and compile both binaries immediately afterward.
  • Under -D unused, a pub(super) item unused by one binary is an error. Apply the allowance policy deliberately rather than broadly suppressing warnings.
  • Over-splitting can obscure the normal lifecycle. Keep startup, readiness, shutdown, and Drop together and extract only leaf collaborators plus failed-start behavior.
  • Cross-module movement can accidentally expand visibility. Use pub(super) only and verify no item becomes more public.
  • Tests using private struct literals must move with their structs to avoid transient or lasting compile failures.

Activity

  1. added theissue type on Sep 16, 2026
  2. added 13 commits that reference this issue on Sep 16, 2026
  3. 14 remaining items

  4. added 7 commits that reference this issue on Sep 17, 2026
  5. self-assigned this
    on Sep 17, 2026
  6. added 2 commits that reference this issue on Sep 17, 2026
  7. added a commit that references this issue on Sep 18, 2026
  8. added 2 commits that reference this issue on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Code Cleanup / Refactoringtask

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions