Skip to content

Fix machine-dependent format_cpu_cores tests - #155

Merged
l1a merged 1 commit into
mainfrom
fix/format-cpu-cores-flaky-test
Jul 13, 2026
Merged

Fix machine-dependent format_cpu_cores tests#155
l1a merged 1 commit into
mainfrom
fix/format-cpu-cores-flaky-test

Conversation

@l1a

@l1a l1a commented Jul 13, 2026

Copy link
Copy Markdown
Owner

What

format_cpu_cores reads the host's real CPU topology (Linux /sys/.../cpufreq,
macOS hw.perflevel*) and returns a "NP + ME / KT" hybrid string on Intel P/E and Apple
Silicon machines, ignoring its passed-in (logical, physical) counts. The four fallback unit
tests called it with fixed arguments, so they passed on non-hybrid CPUs and CI runners but
failed on a hybrid host — an i7-1360P produced "8P + 8E / 16T" for (16, Some(8)) where
test_format_cpu_cores_hyperthreaded expected "8C / 16T", hard-failing just pr on that
machine. It had gone unnoticed because it was only ever exercised on non-hybrid hosts/runners.

Fix

Extract the pure fallback (match physical { … }) into a private
format_cpu_cores_plain(logical, physical) and retarget the four fallback tests at it, so they
test deterministic formatting without touching host hardware. format_cpu_cores's public
behavior is unchanged — it still detects hybrid topology first, then delegates to the helper.

Internal refactor + test-only fix; no user-visible behavior change.
retch-sysinfo0.1.42, retch-cli0.4.2.

Test plan

  • cargo test -p retch-sysinfo --lib format_cpu_cores — all 4 pass on this i7-1360P hybrid (previously 1 failed)
  • just pr gate passes end-to-end (fmt, clippy --workspace, full test suite 85 green, man page current, Cargo.lock current)

`format_cpu_cores` reads the host's real CPU topology (Linux /sys cpufreq,
macOS hw.perflevel*) and returns a "NP + ME / KT" hybrid string on Intel P/E
and Apple Silicon machines, ignoring its passed-in (logical, physical) counts.
The four fallback unit tests called it with fixed args, so they passed on
non-hybrid CPUs/CI runners but failed on a hybrid host — an i7-1360P produced
"8P + 8E / 16T" for (16, Some(8)) where the test expected "8C / 16T", hard-
failing `just pr` there.

Extract the pure fallback into `format_cpu_cores_plain` and retarget the four
tests at it, so they no longer depend on the runner's hardware. Public
behavior of `format_cpu_cores` is unchanged.

Assisted-By: Claude Opus 4.8
@l1a
l1a merged commit 84a7d7c into main Jul 13, 2026
18 checks passed
@l1a
l1a deleted the fix/format-cpu-cores-flaky-test branch July 13, 2026 01:42
l1a added a commit that referenced this pull request Jul 24, 2026
Two coupled docs/test-hygiene fixes (no runtime behavior change), bundled
because the first is what lets `just pr` pass on the reinstalled Fedora box.

1. Machine-independent xrandr display tests. parse_xrandr_displays called
   get_monitor_name_for_port (live /sys/class/drm EDID) inline, so the
   fixture tests substituted the physically-attached monitor for the
   fixture's connector name (DP-1 -> the panel's EDID model ATNA33AA08-0).
   These tests are cfg(not(macos/windows)) and never ran on the old Windows
   arrakis, so the defect was latent until the first cargo test after the
   Fedora reinstall. Same class as #155. Extract a pure
   parse_xrandr_displays_with(stdout, resolve); the public wrapper passes
   get_monitor_name_for_port (production unchanged) and the tests pass
   |_| None. Add a regression test asserting the resolver is honored.

2. Regenerate docs/retch.1. The committed page carried double-bold groff
   runs from the Windows #160 `just man` run, where the recipe's
   sed 's/\fB\fB/\fB/g' strip did not take effect. Linux regeneration
   produces the intended single-bold output, matching the recipe's intent.

Patch bump: retch-cli 0.6.2, retch-sysinfo 0.1.46 (new pub
parse_xrandr_displays_with).

Assisted-By: Claude Opus 4.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant