Addresses the six items the last review flagged. Four are polish for
existing tests; two add coverage for previously-untested public APIs.
Polish:
- instance/content/mods.rs: icon_path_from_value_map now asserts a
single deterministic value. serde_json::Map is a BTreeMap so the
"128" key sorts before "64" and the test no longer needs an
order-tolerant disjunction.
- cli/log.rs: replace the hand-rolled unique_temp_dir with
tempfile::tempdir() across both tests. Drop the trailing
remove_dir_all cleanup since TempDir handles that on Drop. Last
inline test file using the hand-rolled pattern.
- running.rs: remove drain_empty_returns_empty. Two consecutive calls
to drain_last_played in the same test can race with the parallel
push_and_drain_last_played test which pushes to the same global
LAST_PLAYED state. drain semantics are covered by the existing
push_and_drain test.
- tui/error_buffer.rs: peek_does_not_remove now actually verifies the
invariant the name promises. Pushes a tagged event, captures the
count before and after peek_error, asserts the count is unchanged
and the tagged event is still in the queue. Previous version only
asserted that something was returned.
New coverage:
- net/neoforge.rs: added fetch_neoforge_game_versions_from(client,
api_url) mirroring the existing _from pattern. tests/net_loaders.rs
gains neoforge_fetch_game_versions_reverse_engineers_mc_versions
covering the maven-version-to-MC-version reverse mapping, which was
only touched by the #[ignore] live API test before.
- instance/import/mod.rs: six new tests for detect_format covering
mrpack detection, mmc-pack at root and nested, the priority case
where both markers are present, unknown archives, and missing
files. Helper make_pack_zip builds in-memory zips so the tests
don't need fixture files on disk.
Closes the seven remaining tractable coverage gaps the final review
flagged. All tests-only or tiny *_from variants matching the existing
pattern. 18 new tests.
- src/instance/launch/patches.rs: seven inline tests for the lwjgl3ify
patch helpers that were entirely untested before. strip_replaced_libs
has happy + no-op cases. parse_add_opens covers the basic Add-Opens
extraction, the MANIFEST.MF continuation-line case (the tricky one:
jar manifests wrap lines with a trailing space + leading-space marker
that gets stripped on join), missing manifest, and missing file.
add_lwjgl3 verifies that only jars that actually exist in lib_dir
end up on the classpath.
- src/net/forge.rs: three inline tests for has_legacy_install_profile.
Builds synthetic forge installer zips in a tempdir with and without
the versionInfo key in install_profile.json; covers the missing-jar
branch with a path that doesn't exist.
- src/net/modrinth.rs: five-case rstest for url_encode covering the
unreserved set, space, RFC 3986 reserved characters, multi-byte UTF-8
(the encoder operates per-byte so emoji exercises the multi-byte
path), and empty input.
- src/net/fabric.rs / src/net/quilt.rs: added fetch_*_profile_from and
fetch_*_profile_with_raw_from variants mirroring the existing pattern.
Existing fetch_*_profile and *_with_raw delegate to them with the
upstream constants.
- tests/net_loaders.rs: two new wiremock tests (fabric_fetch_profile
parses libraries, quilt_fetch_profile parses libraries) using the
new _from variants.
- src/tui/widgets/popups/import_modpack/render.rs: extra snapshot for
the Confirm step when loader_version is None (vanilla pack or old
mmc pack). The previous Confirm snapshot covered Some(_) only.
Production touches stay minimal: the four new pub fn delegators in
fabric.rs and quilt.rs, all behaviour-preserving.
Closes the "zero production touches" subset of the deferred coverage
items the audit had flagged.
- src/tui/widgets/popups/new_instance/render.rs: three new snapshots
for the Version, LoaderVersion, and Confirm steps. Each pre-populates
WIZARD_STATE so ensure_versions_loaded and ensure_loader_versions_loaded
short-circuit on LoadState::Loaded and never spawn a network task. The
TEST_SERIAL mutex established in the earlier batch serialises against
the existing Name/Loader snapshots.
- src/tui/widgets/popups/import_modpack/render.rs: two new snapshots
for the Version step (synthetic VersionInfo entries) and the Confirm
step (synthetic ImportSummary). Same serialisation pattern.
- tests/net_mojang.rs: three new wiremock tests.
download_libraries_writes_artifact_to_meta_dir constructs a synthetic
VersionMeta whose single library points at the wiremock server, then
asserts the bytes land at meta_dir/libraries/<artifact.path>.
download_libraries_skips_when_destination_exists verifies the cache
hit path via wiremock's expect(0).
download_assets_writes_index_when_objects_is_empty exercises the
index fetch+write code path with an empty objects map so the per-asset
download loop never fires.
Zero production touches. download_libraries already takes a
VersionMeta whose libraries carry their own URLs; download_assets'
index fetch reads from meta.asset_index.url (also configurable
per-call), so the empty-objects path doesn't need ASSETS_BASE_URL
overridable. Full per-asset coverage lands in a separate commit.
Final-review pass flagged three items. All addressed:
- src/instance/loader/mod.rs: rename and rewrite the two profile-shape
tests so the test name matches what the body does.
legacy_forge_version_info_round_trips_through_save_profile_json was
misleading; the body never called save_installer_profile, it only
wrote bytes to disk and read them back. Renamed to
legacy_forge_version_info_deserialises_as_launch_profile and dropped
the filesystem dance - the test was only ever verifying serde shape
on the literal byte string.
raw_fabric_profile_bytes_parse_as_launch_profile got the same
treatment for consistency: dropped the TempDir + write + read round
trip since the test only checks deserialisation.
- src/tui/error_buffer.rs: removed has_errors_after_push. The test
read global state populated by other tests in the same module, so
it would still pass if push_error were a no-op. The push semantics
are properly covered by peek_all_returns_newest_first and
overflow_drops_oldest, both of which use unique tagged messages to
isolate from cross-test interference.
Phase E added snapshots for the ErrorPopup; this extends the same
pattern to the three other high-value widgets the audit flagged.
- src/tui/widgets/instances.rs: two snapshots covering the instance
list with three synthetic instances (verifies layout, "Never played"
rendering, scrollbar gutter) and the empty list. State is passed in
via the existing State::with_instances constructor; no global state
involved.
- src/tui/widgets/popups/new_instance/render.rs: two snapshots covering
the Name step (default) and Loader step (hardcoded loader list, no
network). WIZARD_STATE is global, so the tests reset it under its
mutex and serialise via a per-module TEST_SERIAL mutex to prevent
cross-test races. The Version and LoaderVersion steps are skipped
here because their render path calls ensure_versions_loaded which
tokio::spawns a network task; covering them would need a fully
pre-populated state and is deferred.
- src/tui/widgets/popups/import_modpack/render.rs: two snapshots
covering the Input step (default) and the Fetching step (just a
spinner + label, no network triggered by render). Same global-state
serialisation pattern as new_instance.
Snapshots live next to each widget under snapshots/ as plain text and
are committed to git.
Audit identified six high-priority coverage gaps. This commit closes
them with 30 net new passing tests.
- tests/net_retry.rs (new): 5 wiremock-based tests for the retry
envelope in net/mod.rs. Covers get_json + download_file across:
5xx retry-then-succeed, 4xx fail-fast (asserted via wiremock
expect(1) so any retry attempt fails the test), and exhaust at
MAX_RETRIES = 3 (asserted via expect(4)). The exhaust test takes
~3.5s of wall time because the production code sleeps 500 + 1000 +
2000 ms between attempts; this is unavoidable without making the
delays configurable.
- tests/launch_pipeline.rs: 3 new error-path tests against
build_launch_invocation. merged_profile_missing_main_class_fails
surfaces the LaunchError::Parse branch when meta.json deserialises
cleanly but lacks mainClass. legacy_loader_profile_missing_loader_version_errors
and legacy_loader_profile_missing_installer_json_errors exercise the
two Parse branches inside migrate_legacy_loader_profile_if_needed.
- instance/manager.rs: 6 tests for rename (happy path, noop on same
name, empty target rejected, missing source, target collision) and
touch_last_played (sets the field to a stamp within 5 seconds of
now). The InstanceManager rename surface had no coverage before;
mutating the validation order or the std::fs::rename target would
not have failed any existing test.
- instance/content/mods.rs: 4 new precedence-chain tests. The reader
chain is fabric > quilt > forge-toml (which itself tries
neoforge.mods.toml before mods.toml) > mcmod.info. Only the
fabric-over-forge precedence had a test before. Adds quilt > forge,
forge_toml > mcmod_info, neoforge.mods.toml > mods.toml, and a test
that a mods.toml carrying only logoFile (no [[mods]] array) still
resolves the icon.
- tui/widgets/instances.rs: 12 new tests for format_last_played. One
case for the None input (returns "Never played"), then an rstest
covering each bucket boundary in the match (0/59 just-now,
60/3599 minutes, 3600/86399 hours, 86400/2591999 days,
2592000/31535999 months, >=31536000 over-a-year). A mutation that
bumps any boundary by one second, or swaps a unit suffix, fails at
least one case.