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.
Same pattern as fetch_version_manifest_from from the earlier batch:
each fetcher gets a sibling that takes the URL as a parameter; the
existing function delegates to it with the upstream constant.
Production callers are unchanged.
- src/net/forge.rs: fetch_forge_versions_from(client, promotions_url,
game_version) and fetch_forge_game_versions_from(client,
promotions_url).
- src/net/fabric.rs: fetch_fabric_game_versions_from(client, base) and
fetch_fabric_versions_from(client, base, game_version). The fabric
API is hierarchical so the helpers take the meta base URL and append
the rest internally, matching the existing layout.
- src/net/quilt.rs: same pair as fabric.
- src/net/neoforge.rs: fetch_neoforge_versions_from(client, api_url,
game_version).
- src/net/mojang.rs: download_assets_from(client, meta, meta_dir,
assets_base) so tests can route per-asset CDN downloads through a
wiremock server. download_assets delegates to it with
ASSETS_BASE_URL.
tests/net_loaders.rs adds eight wiremock tests covering each new
fetcher and a happy + error case for neoforge's invalid-game-version
branch. tests/net_mojang.rs gains download_assets_from_writes_index_and_assets
which now exercises the full per-asset download path against synthetic
hashes.
Production touches are minimal (one new pub fn delegating to the
existing one for each fetcher). Behaviour of existing callers is
unchanged.
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.
Picks up the remaining test-only suggestions from the style audit. No
production code change.
- launch_profile/templates.rs: introduces a Fixture struct that owns
the four PathBuf inputs (lib/nat/game/assets) and exposes a ctx()
method. Eight tests that each rebuilt the same context inline now
collapse into one rstest with eight cases plus two standalone
tests for the recursive-substitution and Windows-backslash edge
cases. Net code: ~120 lines saved.
- launch_profile/render.rs: same pattern. Fixture::new() owns the
paths plus a FeatureSet; ctx() and rule_ctx() expose what every
test needs. Six tests stop redeclaring four PathBufs + a five-line
RuleContext literal apiece.
- instance/launch/mod.rs: three installer_version_dir_name tests
(Forge / NeoForge / non-installer loaders) become one rstest with
five cases (one per ModLoader variant). A regression that
misorders the match arms would now fail a specific case, not just
the catch-all "non-installer" test.
- instance/content/resource_packs.rs: ten extract_description_*
tests become one rstest with ten cases. Each case still hits a
distinct match arm (string, object{text}, object{no text}, array
variants, null, number, bool); the rstest is cosmetic, not a
consolidation that loses coverage.
Net effect: same coverage, ~250 lines less repetitive test setup,
clearer intent. Test count rises by 2 because rstest expands cases
into separate test functions.
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.