Repository navigation
Cover Linux command and file parsing via seam extraction - #3514
Conversation
Coverage-driven from Codecov cross-OS missed-line data: add unit coverage for previously-untested Linux command and file parsing, extracting seams where acquire+parse was inline and grounding fixtures in documented formats. - LinuxGraphicsCard: extract getGraphicsCardsFromLshw(List, factory, drmLookup) from the inline `lshw -C display` parse; add fixtures for the two-card lshw path and two lspci gaps (vendor line without a "[hex]" id -> raw fallback; output with no trailing blank line -> last-card flush). - LinuxOperatingSystem: extract parseServices(systemctl, running, initDir) (systemctl list-unit-files + /etc/init .conf fallback) and getReleaseFilename(etcPath) (/etc *-release/*-version scan). Fixtures cover the systemctl enabled/dedup path, the upstart .conf fallback, the missing init-dir branch, distrib-file match, excluded os/lsb/system-release files, and the release/issue fallbacks. The /etc/init fallback now guards on listFiles() == null (behavior-preserving; also closes a latent NPE from iterating listFiles() without a null check). - LinuxCgroupInfo: extract static resolveV1ControllerPath(selfCgroup, controller) parsing /proc/self/cgroup; fixtures cover a comma-controller exact match, a single controller, a not-found default, and a v2-only unified line. No CHANGELOG entry: test/coverage plus behavior-preserving extractions.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
🚧 Files skipped from review as they are similar to previous changes (3)
📜 Recent review details⏰ Context from checks skipped due to timeout. (7)
📝 WalkthroughWalkthroughLinux platform parsing was refactored into testable helpers for graphics DRM data, cgroup controller paths, release files, and service enumeration. New tests cover parser fallbacks, incomplete input, hybrid cgroup layouts, temporary directories, and empty results. ChangesGraphics parsing
Cgroup controller resolution
Linux operating-system parsing
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 #3514 +/- ##
============================================
+ Coverage 77.72% 77.92% +0.19%
Complexity 83 83
============================================
Files 694 694
Lines 24246 24249 +3
Branches 4028 4029 +1
============================================
+ Hits 18846 18895 +49
+ Misses 3184 3131 -53
- Partials 2216 2223 +7
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java (1)
323-327: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAssert the missing-version expectation.
The comment says the second card should have
UNKNOWNversion information, but the test never checks it. Add an assertion so regressions that leak the first card’s version into the second card are detected.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java` around lines 323 - 327, Add an assertion in LinuxGraphicsCardTest for the second card variable intel, verifying its version is UNKNOWN as documented by the existing comment. Keep the existing name, vendor, and VRAM assertions unchanged.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In
`@oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java`:
- Around line 565-574: Update the systemctl parsing loop in LinuxOperatingSystem
so systemctlFound is set whenever an enabled .service row is successfully
parsed, before checking running services or deduplicating names. Preserve
stopped-service creation behavior, and add coverage for a case where the only
enabled unit is already running to ensure /etc/init fallback is not used.
---
Nitpick comments:
In
`@oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java`:
- Around line 323-327: Add an assertion in LinuxGraphicsCardTest for the second
card variable intel, verifying its version is UNKNOWN as documented by the
existing comment. Keep the existing name, vendor, and VRAM assertions unchanged.
🪄 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: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 515b6fdd-faf2-4d61-8b37-12cf92728e71
📒 Files selected for processing (6)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxCgroupInfo.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.javaoshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.javaoshi-common/src/test/java/oshi/software/common/os/linux/LinuxCgroupInfoV1DispatchTest.javaoshi-common/src/test/java/oshi/software/common/os/linux/LinuxOperatingSystemTest.java
📜 Review details
⏰ Context from checks skipped due to timeout. (8)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 26, ubuntu-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 25, ubuntu-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, ubuntu-latest
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
🧰 Additional context used
🧠 Learnings (2)
📚 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/hardware/common/platform/linux/LinuxGraphicsCard.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxCgroupInfo.java
📚 Learning: 2026-07-06T19:25:59.225Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3432
File: oshi-common/src/main/java/oshi/util/ExceptionUtil.java:26-56
Timestamp: 2026-07-06T19:25:59.225Z
Learning: In this repo’s SLF4J 1.x-compatible logging code, do not flag cases where a logger call uses SLF4J 1.6+ implicit-cause handling—e.g., `log.error("...{}", value, t)` (or similar with a single `{}` placeholder) where `t` is passed as the final/trailing argument. SLF4J will attach `t` as the log event’s cause with the full stack trace; this is equivalent to SLF4J 2.x’s fluent `atLevel(...).setCause(t).log(...)` and is intentionally used to preserve SLF4J 1.x runtime compatibility.
Applied to files:
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.javaoshi-common/src/main/java/oshi/software/common/os/linux/LinuxCgroupInfo.java
🪛 ast-grep (0.44.1)
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxOperatingSystem.java
[warning] 517-517: Prevent path traversal
Context: new File(etc, "issue")
Note: [CWE-22] Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'). Security best practice.
(path-traversal-java)
🔇 Additional comments (4)
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxGraphicsCard.java (1)
299-300: LGTM!Also applies to: 311-312, 326-326, 357-357
oshi-common/src/test/java/oshi/hardware/common/platform/linux/LinuxGraphicsCardTest.java (1)
271-292: LGTM!Also applies to: 298-310, 311-322, 328-334
oshi-common/src/main/java/oshi/software/common/os/linux/LinuxCgroupInfo.java (1)
204-214: LGTM!oshi-common/src/test/java/oshi/software/common/os/linux/LinuxCgroupInfoV1DispatchTest.java (1)
16-26: LGTM!Also applies to: 143-184
- parseServices: mark systemctlFound as soon as an enabled .service row is parsed (before the running-check/dedup) so the /etc/init fallback runs only when systemctl produced no enabled units. Fixes a latent case where every enabled unit is already running would spuriously trigger the fallback. Add a test covering that case. - LinuxGraphicsCardTest: assert the second lshw card's version is UNKNOWN, as the existing comment documents.
Summary
Coverage-driven (from Codecov cross-OS missed-line data): add unit coverage for previously-untested Linux command/file parsing, extracting seams where acquire+parse was inline and grounding fixtures in documented Linux formats.
LinuxGraphicsCard— thelshw -C displayparse was inline and unseamed. ExtractgetGraphicsCardsFromLshw(List, factory, drmLookup)(mirroring the existing lspci seam) and add a two-card fixture grounded in reallshw -C displayoutput (memory-range VRAM math). Also cover two lspci gaps: aVendorline without a[hex]id (raw-text fallback) and output that ends mid-card with no trailing blank line (last-card flush).LinuxOperatingSystem— extractparseServices(systemctl, running, initDir)(thesystemctl list-unit-filesscan plus the/etc/init.confupstart fallback) andgetReleaseFilename(etcPath)(the/etc*-release/*-versionscan). Fixtures are grounded in realsystemctl list-unit-filescolumns, upstart.conffiles, and the/etcscan: the enabled/dedup-by-name-and-short-name path, the init-dir fallback, the missing-init-dir branch, a distrib-file match, excludedos/lsb/system-releasefiles, and therelease/issuefallbacks. The/etc/initfallback now guards onlistFiles() == nullinstead ofexists() && isDirectory()— behavior-preserving, and it closes a latent NPE from iteratinglistFiles()without a null check.LinuxCgroupInfo— extract staticresolveV1ControllerPath(selfCgroup, controller)parsing/proc/self/cgroup. Fixtures grounded in a real hybrid (v1 + unified) cgroup file cover a comma-separated-controller exact match, a single controller, a not-found default, and a v2-only unified line whose controllers field is empty.Deliberately left alone (not cleanly seamable):
queryFamilyVersionCodenameFromReleaseFiles(interleaves several real file reads), theLinuxFileSystemmount-table loop / NFS / TCP probing (file-I/O + network), andqueryBitness.Testing
oshi-commonfull gate green: spotless, checkstyle, install + forbiddenapis, javadoc.SysPath-dependent cgroup assertions and theLinuxOperatingSystemfile/command tests run on Linux CI (where cross-OS coverage is collected) and skip elsewhere.No CHANGELOG entry — test/coverage plus behavior-preserving extractions.
Summary by CodeRabbit
lshw, including incomplete vendor metadata andlspcioutput without a trailing blank line.