Repository navigation
Description
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
NativeTrackerstartup, 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.rsor 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:
NativeTrackerowns the running child; normal shutdown waits for it, and drop cleanup kills and reaps it before releasing the workspace.NativeTrackerFailedStartowns the failed-start child;wait_for_exitreaps it and restores permissions, whileDropremains a non-panicking best-effort fallback.TrackerOutputCapturedrains stdout and stderr concurrently and joins both readers before diagnostics are final.- Workspace/configuration paths remain available until applicable child cleanup completes.
- The root
NativeTrackerreadiness 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 allexits 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-signalscargo test --test cli-configurationcargo test --test lifecycle-signals --test cli-configurationafter every extractionlinter 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, apub(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
Droptogether 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
docs(issues): [torrust#2238] plan native tracker fixture refactor
docs(issues): [torrust#2238] link spec pull request
docs(issues): [torrust#2238] plan native tracker fixture refactor
docs(issues): [torrust#2238] link spec pull request
Merge #2239: docs(issues): [#2238] plan native tracker fixture refactor
docs(issues): [torrust#2238] link implementation pull request
docs(issues): [torrust#2238] start native tracker fixture refactor
refactor(tests): [torrust#2238] establish native tracker module root
refactor(tests): [torrust#2238] extract native tracker output and health
refactor(tests): [torrust#2238] extract native tracker command setup
refactor(tests): [torrust#2238] extract failed native tracker startup
refactor(tests): [torrust#2238] clarify native tracker lifecycle owne…
refactor(tests): [torrust#2238] narrow native tracker fixture API
14 remaining items
refactor(tests): [torrust#2238] consolidate fixture configuration ren…
refactor(tests): [torrust#2238] narrow fixture dead-code allowances
docs(issues): [torrust#2238] record fixture refactor evidence
docs(issues): [torrust#2238] link implementation pull request
fix(docs): [torrust#2238] preserve historical fixture path
fix(docs): [torrust#2238] correct fixture size evidence
fix(docs): [torrust#2238] refresh fixture navigation links
chore(issues): archive closed issue #2238 specification
Merge #2254: chore(issues): archive closed issue #2238 specification
Merge torrust#2249: refactor(tests): [torrust#2238] split native trac…
docs(issues): [torrust#2628] cite the torrust#2238 dead-code rule as …
Merge #2636: refactor(test-helpers): [#2628] move the protocol helper…