Repository navigation
Extract parsing from Who, LinuxOSProcess, LinuxOperatingSystem - #3203
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 (8)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (5)
📜 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-10T22:44:36.786ZApplied to files:
📚 Learning: 2026-04-12T19:22:09.716ZApplied to files:
🔇 Additional comments (5)
📝 WalkthroughWalkthroughRefactors Linux parsing by extracting parsing logic into package-private static helpers: Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3203 +/- ##
==========================================
+ Coverage 58.56% 58.86% +0.29%
==========================================
Files 421 421
Lines 20355 20358 +3
Branches 3576 3577 +1
==========================================
+ Hits 11921 11983 +62
+ Misses 6688 6624 -64
- Partials 1746 1751 +5
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:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java (1)
38-52: Strengthen the no-host and single-digit-day tests with field-level assertions.Both tests currently prove a match happened, but not that the parsed values are correct. Adding a couple of field assertions will make regressions much easier to catch.
Suggested test assertion additions
`@Test` void testMatchUnixNoHost() { List<OSSession> sessions = new ArrayList<>(); boolean matched = Who.matchUnix(sessions, "root console Jan 15 08:30"); assertThat(matched, is(true)); assertThat(sessions.size(), is(1)); assertThat(sessions.get(0).getUserName(), is("root")); + assertThat(sessions.get(0).getTerminalDevice(), is("console")); } `@Test` void testMatchUnixSingleDigitDay() { List<OSSession> sessions = new ArrayList<>(); boolean matched = Who.matchUnix(sessions, "user1 pts/0 Dec 3 14:22 (10.0.0.1)"); assertThat(matched, is(true)); assertThat(sessions.size(), is(1)); + assertThat(sessions.get(0).getUserName(), is("user1")); + assertThat(sessions.get(0).getTerminalDevice(), is("pts/0")); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java` around lines 38 - 52, Update the two tests that call Who.matchUnix to assert parsed fields on the created OSSession(s): in testMatchUnixNoHost, after the existing assertions also assert sessions.get(0).getTerminal() equals "console" and sessions.get(0).getHost() is null (or empty) and that the parsed month/day/time fields (e.g., getLoginMonth/getLoginDay/getLoginTime or equivalent getters) match Jan/15/"08:30"; in testMatchUnixSingleDigitDay, after the size assertion assert sessions.get(0).getUserName() equals "user1", sessions.get(0).getTerminal() equals "pts/0" and sessions.get(0).getHost() equals "10.0.0.1" (and check the parsed day is 3 and time is "14:22"). Use the existing OSSession getters to locate those fields and add these assertions to make the tests validate field-level parsing from Who.matchUnix.oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java (1)
36-42: Consider asserting the no-host fallback value explicitly.Line 38 exercises a no-host input, but the test doesn’t currently validate the host fallback (
Constants.UNKNOWN). Adding that assertion would pin parser behavior.✅ Suggested test enhancement
import oshi.software.os.OSSession; +import oshi.util.Constants; @@ void testMatchLinuxNoHost() { List<OSSession> sessions = new ArrayList<>(); boolean matched = Who.matchLinux(sessions, "root tty1 2023-01-15 08:30"); assertThat(matched, is(true)); assertThat(sessions.size(), is(1)); assertThat(sessions.get(0).getUserName(), is("root")); + assertThat(sessions.get(0).getHost(), is(Constants.UNKNOWN)); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java` around lines 36 - 42, The test testMatchLinuxNoHost should explicitly assert the parsed host fallback; update the test in WhoTest to check that Who.matchLinux produced a session whose getHost() equals Constants.UNKNOWN (e.g., assertThat(sessions.get(0).getHost(), is(Constants.UNKNOWN))). Locate the assertion block in testMatchLinuxNoHost and add this assertion referencing Who.matchLinux, OSSession.getHost, and Constants.UNKNOWN so the parser's no-host behavior is pinned.
🤖 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/main/java/oshi/software/common/os/linux/LinuxOSProcess.java`:
- Around line 351-354: The code in LinuxOSProcess that splits tasksetOutput
using ParseUtil.whitespaces may produce an empty array for whitespace-only input
and then throw ArrayIndexOutOfBounds when accessing split[split.length - 1];
update the logic in the method (around the use of
ParseUtil.whitespaces.split(tasksetOutput), the BigInteger(..., 16).longValue()
conversion, and the existing NumberFormatException catch) to first check if the
split array is empty or has no non-empty entries and return 0 immediately; only
attempt to parse the last element into a BigInteger if the array contains at
least one element, otherwise return 0 to satisfy the “return 0 if unparseable”
contract.
---
Nitpick comments:
In `@oshi-common/src/test/java/oshi/util/driver/linux/WhoTest.java`:
- Around line 36-42: The test testMatchLinuxNoHost should explicitly assert the
parsed host fallback; update the test in WhoTest to check that Who.matchLinux
produced a session whose getHost() equals Constants.UNKNOWN (e.g.,
assertThat(sessions.get(0).getHost(), is(Constants.UNKNOWN))). Locate the
assertion block in testMatchLinuxNoHost and add this assertion referencing
Who.matchLinux, OSSession.getHost, and Constants.UNKNOWN so the parser's no-host
behavior is pinned.
In `@oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java`:
- Around line 38-52: Update the two tests that call Who.matchUnix to assert
parsed fields on the created OSSession(s): in testMatchUnixNoHost, after the
existing assertions also assert sessions.get(0).getTerminal() equals "console"
and sessions.get(0).getHost() is null (or empty) and that the parsed
month/day/time fields (e.g., getLoginMonth/getLoginDay/getLoginTime or
equivalent getters) match Jan/15/"08:30"; in testMatchUnixSingleDigitDay, after
the size assertion assert sessions.get(0).getUserName() equals "user1",
sessions.get(0).getTerminal() equals "pts/0" and sessions.get(0).getHost()
equals "10.0.0.1" (and check the parsed day is 3 and time is "14:22"). Use the
existing OSSession getters to locate those fields and add these assertions to
make the tests validate field-level parsing from Who.matchUnix.
🪄 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: 83c3082b-1421-4ebe-9a25-425438079cfd
📒 Files selected for processing (8)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.javaoshi-common/src/main/java/oshi/util/driver/linux/Who.javaoshi-common/src/test/java/module-info.testoshi-common/src/test/java/oshi/software/common/os/linux/LinuxOSProcessTest.javaoshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.javaoshi-common/src/test/java/oshi/util/driver/linux/WhoTest.javaoshi-common/src/test/java/oshi/util/driver/unix/WhoTest.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). (5)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (6)
📚 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.testoshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
📚 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.testoshi-common/src/main/java/oshi/util/driver/linux/Who.javaoshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.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/util/driver/linux/Who.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
📚 Learning: 2026-04-10T22:44:36.786Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3136
File: oshi-core-java25/src/main/java/oshi/software/os/linux/LinuxOperatingSystemFFM.java:46-53
Timestamp: 2026-04-10T22:44:36.786Z
Learning: In OSHI's `AuxvFFM.queryAuxv()` (oshi-core-java25/src/main/java/oshi/driver/linux/proc/AuxvFFM.java), the do-while loop is safe even when `/proc/self/auxv` cannot be read: `FileUtil.readAllBytesAsBuffer` returns an empty ByteBuffer on failure, and `FileUtil.readLongFromBuffer`/`readIntFromBuffer` return 0L when reading past the buffer limit. This 0L equals AT_NULL, causing the loop to exit immediately with an empty map, which triggers the `getconf`/hardcoded-default fallback in callers like `LinuxOperatingSystemFFM`. Do not flag this do-while loop or the static initializer that calls `AuxvFFM.queryAuxv()` as unsafe.
Applied to files:
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOSProcess.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/util/driver/linux/WhoTest.javaoshi-common/src/test/java/oshi/util/driver/unix/WhoTest.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/util/driver/unix/WhoTest.java
🔇 Additional comments (8)
oshi-common/src/test/java/oshi/util/driver/unix/WhoTest.java (3)
27-35: Great deterministic coverage for the primary Unixwhoparse path.Nice job validating match result, list mutation, and key parsed fields in one focused fixture test.
55-60: No-match behavior is validated cleanly.Checking both
falseand zero appended sessions is exactly what this negative case should assert.
62-73: Good separation of fixture tests from live/system-dependent checks.Moving runtime-dependent assertions into
LiveTestskeeps parser tests deterministic while still preserving runtime validation.oshi-common/src/test/java/module-info.test (1)
21-22: Good addition for test reflection access.This
--add-opensentry cleanly supports the new Linux package tests without widening production visibility.oshi-common/src/main/java/oshi/util/driver/linux/Who.java (1)
60-60: Visibility change is a solid testability improvement.Line 60 keeps parser behavior intact while enabling deterministic fixture tests.
oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOSProcessTest.java (1)
14-37: Nice focused coverage for the extracted affinity parser.These cases validate both happy paths and invalid/empty fallbacks well.
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java (1)
270-327: Clean extraction of parsing from command/file I/O.The new overloads keep behavior stable while making the parser paths directly unit-testable.
oshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java (1)
35-81: Great fixture coverage for the extracted Linux OS parsers.The test matrix is pragmatic and directly validates the key parsing branches and null-return conditions.
Separate command execution from output parsing for testability: - Who.matchLinux(): made package-private for direct testing - Who.matchUnix(): already public, added fixture tests - LinuxOSProcess.parseAffinityMask(): extracted from getAffinityMask() - LinuxOperatingSystem.readOsRelease(List): extracted from readOsRelease() - LinuxOperatingSystem.execLsbRelease(List): extracted from execLsbRelease() Added fixture-based tests for Linux/Unix who date formats, taskset affinity mask parsing, /etc/os-release and lsb_release -a parsing. No public API changes.
d12c063 to
3a37914
Compare
Resolves part of #3189.
Separates command execution from output parsing in 5 methods:
Refactored methods:
Who.matchLinux()— made package-private (was private) for direct testing with fixture dataWho.matchUnix()— already public, added fixture tests for variouswhodate formatsLinuxOSProcess.getAffinityMask()→ newparseAffinityMask(String)—taskset -poutputLinuxOperatingSystem.readOsRelease()→ newreadOsRelease(List<String>)—/etc/os-releaseLinuxOperatingSystem.execLsbRelease()→ newexecLsbRelease(List<String>)—lsb_release -aTests added:
No public API changes. No new dependencies.
Summary by CodeRabbit
Refactor
Tests