Repository navigation
Extract macOS parsing logic for testability - #3199
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (4)
📜 Recent review details⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
🧰 Additional context used🧠 Learnings (2)📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
📚 Learning: 2026-04-18T03:18:06.205ZApplied to files:
🔇 Additional comments (6)
📝 WalkthroughWalkthroughExtracts parsing/version-resolution logic from three macOS-specific classes into package-private helper methods and adds unit tests exercising those helpers. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches✨ Simplify code
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacGraphicsCardTest.java (1)
53-78: Consider one more test for the Applehw.memsizeVRAM fallback path.Non-blocking, but adding this would close the remaining branch in
resolveVramwhen no VRAM line is present.Proposed test addition
+ `@Test` + void testAppleFallbackToHwMemsizeWhenVramMissing() { + List<String> sp = Arrays.asList("Graphics/Displays:", " Chipset Model: Apple M3 Pro"); + MacGraphicsCard.SysctlLong sysctl = (name, def) -> "hw.memsize".equals(name) ? 36L * 1024 * 1024 * 1024 : def; + List<GraphicsCard> cards = MacGraphicsCard.parseGraphicsCards(sp, FACTORY, sysctl); + assertThat(cards, hasSize(1)); + assertThat(cards.get(0).getVRam(), is(36L * 1024 * 1024 * 1024)); + }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacGraphicsCardTest.java` around lines 53 - 78, Add a test in MacGraphicsCardTest that verifies MacGraphicsCard.parseGraphicsCards uses the sysctl hw.memsize fallback in resolveVram when no VRAM/VRAM (Total)/(Dynamic) line exists: create input lines representing a GPU block without any "VRAM" entries (e.g., "Chipset Model: Test GPU" but no VRAM line), mock/override SYSCTL to return a known hw.memsize value, call MacGraphicsCard.parseGraphicsCards(…) and assert the resulting GraphicsCard.getVRam() equals that hw.memsize value (in bytes); name the test clearly (e.g., testVramFallbackHwMemsize) so it targets the resolveVram fallback behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.java`:
- Around line 46-84: The subclass StubMacCentralProcessor leaves sysctlStrings
uninitialized so when AbstractCentralProcessor calls initProcessorCounts() →
parseX86FeatureFlags() → sysctlStringNoWarn() during superclass construction it
NPEs; fix by initializing sysctlStrings at declaration (e.g., private final
Map<String,String> sysctlStrings = new HashMap<>();) or, alternatively, ensure
sysctlString/sysctlStringNoWarn handle a null sysctlStrings (null-safe
getOrDefault) and then populate the map in the StubMacCentralProcessor
constructor; reference StubMacCentralProcessor, sysctlStrings,
sysctlStringNoWarn, initProcessorCounts, parseX86FeatureFlags,
AbstractCentralProcessor.
---
Nitpick comments:
In
`@oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacGraphicsCardTest.java`:
- Around line 53-78: Add a test in MacGraphicsCardTest that verifies
MacGraphicsCard.parseGraphicsCards uses the sysctl hw.memsize fallback in
resolveVram when no VRAM/VRAM (Total)/(Dynamic) line exists: create input lines
representing a GPU block without any "VRAM" entries (e.g., "Chipset Model: Test
GPU" but no VRAM line), mock/override SYSCTL to return a known hw.memsize value,
call MacGraphicsCard.parseGraphicsCards(…) and assert the resulting
GraphicsCard.getVRam() equals that hw.memsize value (in bytes); name the test
clearly (e.g., testVramFallbackHwMemsize) so it targets the resolveVram fallback
behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 06660d5d-ffff-4df4-856e-52f51914d5af
📒 Files selected for processing (7)
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacGraphicsCard.javaoshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.javaoshi-common/src/test/java/module-info.testoshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/mac/MacGraphicsCardTest.javaoshi-common/src/test/java/oshi/software/common/os/mac/MacOperatingSystemTest.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (7)
📚 Learning: 2026-03-29T20:01:06.452Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3014
File: oshi-core-java11/src/main/java/module-info.java:10-17
Timestamp: 2026-03-29T20:01:06.452Z
Learning: In the oshi project, `oshi-core-java25/src/main/java/module-info.java` intentionally does NOT export `oshi.util.platform.unix.freebsd`, `oshi.util.platform.unix.openbsd`, or `oshi.util.platform.unix.solaris`, because the FFM (Foreign Function & Memory) implementation only supports Windows, macOS, and Linux. This differs from `oshi-core-java11/src/main/java/module-info.java` which exports all Unix platform packages. The asymmetry is by design.
Applied to files:
oshi-common/src/test/java/module-info.test
📚 Learning: 2026-04-06T04:45:51.516Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:51.516Z
Learning: In the oshi/oshi project, the public API is strictly limited to interfaces and classes in the `oshi`, `oshi.hardware`, and `oshi.software.os` packages. All platform-specific code under subpackages like `oshi.software.os.linux`, `oshi.hardware.platform.linux`, etc., is considered implementation detail — not public API. Do not flag changes to platform-specific classes (e.g., making `LinuxOperatingSystem` abstract, narrowing constructor visibility, adding abstract methods) as public API breaks.
Applied to files:
oshi-common/src/test/java/module-info.test
📚 Learning: 2026-04-15T04:56:18.352Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3163
File: oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java:97-103
Timestamp: 2026-04-15T04:56:18.352Z
Learning: In CoreFoundationTest.java (oshi-core-java25/src/test/java/oshi/ffm/mac/CoreFoundationTest.java), asserting exact CFGetRetainCount deltas (+1 after retain, -1 after release) is intentional and considered reliable for freshly created CF objects (e.g., CFStringRef via CFStringRef.createCFString) where the test holds sole ownership. Do not flag these assertions as flaky — the Apple "avoid CFGetRetainCount" advisory applies to shared/framework-managed objects, not exclusively owned objects in unit tests.
Applied to files:
oshi-common/src/test/java/oshi/software/common/os/mac/MacOperatingSystemTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.javaoshi-common/src/main/java/oshi/hardware/common/platform/mac/MacGraphicsCard.java
📚 Learning: 2026-04-18T03:18:06.205Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3170
File: oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java:177-183
Timestamp: 2026-04-18T03:18:06.205Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/PerfmonComparisonTest.java`, GPU engine PDH instance counts (from `GpuInformationJNA.queryGpuEngineCounters()` / `GpuInformationFFM.queryGpuEngineCounters()`) are highly volatile — counts can differ dramatically (e.g., 53 vs 40) even between queries taken milliseconds apart. Do not assert instance count equality or exact instance list matching between JNA and FFM results. The only reliable assertion is that both are empty or both are non-empty (`assertThat(ffm.getA().isEmpty()).isEqualTo(jna.getA().isEmpty())`).
Applied to files:
oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.javaoshi-common/src/test/java/oshi/hardware/common/platform/mac/MacGraphicsCardTest.java
📚 Learning: 2026-04-19T01:28:47.155Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3174
File: oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java:237-257
Timestamp: 2026-04-19T01:28:47.155Z
Learning: In `oshi-benchmark/src/test/java/oshi/comparison/WmiComparisonTest.java`, the WMI comparison tests (e.g., `testProcessor`) intentionally validate only index 0 and a few representative fields per WMI data type (String, uint16, uint32, uint64). Exhaustive row-by-row comparison is deliberately avoided for numerically heavy multi-row tables. The design rationale is: matching row counts + a few selected fields covering each data type is sufficient to verify JNA vs FFM driver parity. Do not suggest looping over all rows for these tests.
Applied to files:
oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacCentralProcessorTest.java
📚 Learning: 2026-04-12T19:34:56.879Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:34:56.879Z
Learning: In OSHI’s Java platform implementations, `PhysicalProcessor.getEfficiency()` / `EfficiencyClass` follow the same convention as Windows `PROCESSOR_RELATIONSHIP.EfficiencyClass`: a *higher* numeric efficiency class value represents *greater performance* and *less efficiency* (typically P-cores higher than E-cores). When reviewing, do not treat cases where P-cores are assigned higher efficiency/class values as a bug—this is intentional cross-platform consistency.
Applied to files:
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java
🔇 Additional comments (6)
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacGraphicsCard.java (1)
30-36: Nice extraction for testability with behavior preserved.Great split of command execution from parsing; the new overload keeps parsing logic local and makes fixtures straightforward to test.
oshi-common/src/test/java/oshi/hardware/common/platform/mac/MacGraphicsCardTest.java (1)
27-78: Great fixture coverage for the extracted parser.This is a solid, contributor-friendly test suite: it validates empty input, multi-GPU parsing, VRAM conversion, and version-info aggregation with realistic samples.
oshi-common/src/test/java/module-info.test (1)
19-20: Good test-module opening for the new macOS package tests.This
--add-opensaddition is consistent with the new package-private test coverage and keeps the change scoped to test runtime config.oshi-common/src/main/java/oshi/software/common/os/mac/MacOperatingSystem.java (1)
68-83: Nice extraction of version-resolution logic.Moving this into
resolveVersionimproves testability without changing the constructor’s behavior.oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java (1)
199-209: Solid parsing extraction with preserved fallback behavior.This separation is clean and makes the sysctl parsing path directly testable while keeping existing runtime behavior.
oshi-common/src/test/java/oshi/software/common/os/mac/MacOperatingSystemTest.java (1)
14-22: Good focused branch coverage forresolveVersion.Both expected paths are exercised with clear, deterministic assertions.
Separate command execution from output parsing in three macOS classes, following the established pattern (e.g., LinuxCentralProcessor): - MacGraphicsCard: extract system_profiler SPDisplaysDataType parsing into parseGraphicsCards(List<String>, ...) overload - MacOperatingSystem: extract sw_vers version resolution into static resolveVersion(String, String) - MacCentralProcessor: extract x86 feature flag sysctl parsing into parseX86FeatureFlags() Add tests with real fixture data (captured from M3 Pro) and representative multi-GPU fixture data from Intel Mac.
95d4dcf to
2684dbe
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3199 +/- ##
==========================================
+ Coverage 57.88% 58.15% +0.26%
==========================================
Files 421 421
Lines 20332 20336 +4
Branches 3576 3575 -1
==========================================
+ Hits 11770 11827 +57
+ Misses 6801 6752 -49
+ Partials 1761 1757 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Addresses the macOS items in #3189.
Separates command execution from output parsing in three macOS classes, following the established pattern (e.g.,
LinuxCentralProcessor.readTopologyFromCpuinfo(List<String>)):system_profiler SPDisplaysDataTypeparsing into a package-privateparseGraphicsCards(List<String>, ...)overloadsw_versversion resolution into a staticresolveVersion(String, String)parseX86FeatureFlags()Tests use real fixture data captured from an M3 Pro, plus representative multi-GPU fixture data from an Intel Mac.
No public API changes.
Summary by CodeRabbit
Tests
Refactor