test: added direct unit tests for app/cli/local_llm/hardware.py#1187
Conversation
Greptile SummaryThis PR adds 24 unit tests for Confidence Score: 5/5Safe to merge — only a minor style nit on a test helper, no logic issues. All findings are P2. The tests are logically correct, mock targets are accurate, fallback values and arithmetic match the implementation, and the iteration pattern used with mock_open is fully supported in Python 3.11+. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[detect_hardware] --> B[_get_total_ram_gb]
A --> C["_get_available_ram_gb(total)"]
A --> D[platform.machine]
A --> E["shutil.which('nvidia-smi')"]
B --> B1{sys.platform?}
B1 -->|darwin| B2["sysctl -n hw.memsize"]
B1 -->|linux| B3["read /proc/meminfo MemTotal"]
B1 -->|other or error| B4["fallback = 8.0 GB"]
C --> C1{sys.platform?}
C1 -->|darwin| C2["sysctl -n hw.usermem"]
C1 -->|linux| C3["read /proc/meminfo MemAvailable"]
C1 -->|other or error| C4["total * 0.5"]
A --> F[HardwareProfile]
F --> F1[total_ram_gb]
F --> F2[available_ram_gb]
F --> F3[arch]
F --> F4[is_apple_silicon]
F --> F5[has_nvidia_gpu]
Reviews (1): Last reviewed commit: "Test: Add direct tests for hardware dete..." | Re-trigger Greptile |
|
|
||
|
|
||
| # --------------------------------------------------------------------------- | ||
| # _get_available_ram_gb — unknown / Windows platform | ||
| # --------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| class TestGetAvailableRamGbUnknownPlatform: | ||
| def test_returns_half_total_on_unrecognised_platform(self) -> None: |
There was a problem hiding this comment.
Missing return type annotation on
_detect helper
The code style guide requires type hints on all function parameters and return types, but _detect has no return annotation. The return type is HardwareProfile.
| # --------------------------------------------------------------------------- | |
| # _get_available_ram_gb — unknown / Windows platform | |
| # --------------------------------------------------------------------------- | |
| class TestGetAvailableRamGbUnknownPlatform: | |
| def test_returns_half_total_on_unrecognised_platform(self) -> None: | |
| def _detect( | |
| self, | |
| *, | |
| platform_str: str, | |
| machine: str, | |
| total_gb: float, | |
| available_gb: float, | |
| nvidia: bool, | |
| ) -> "HardwareProfile": |
Context Used: Code style and conventions (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
|
|
||
| from __future__ import annotations | ||
|
|
||
| import sys |
|
@umeraamir09 CI is failing |
|
Hey @umeraamir09 could you please resolve the test which are failing . Thankss !! |
VaibhavUpreti
left a comment
There was a problem hiding this comment.
awesome @umeraamir09 ! Welcome to the OpenSRE community
|
🔥 Another one. @umeraamir09 said "here's a PR" and maintainers said "ship it". That's how it's done. 👋 Join us on Discord - OpenSRE : hang out, contribute, or hunt for features and issues. Everyone's welcome. |

Fixes #905
Describe the changes you have made in this PR -
Add direct unit tests for
_get_total_ram_gb(),_get_available_ram_gb(), anddetect_hardware()inapp/cli/local_llm/hardware.py./proc/meminfoparsing, macOSsysctlparsing, and unknown platform fallbacksdetect_hardware()tests verify profile assembly: Apple Silicon, macOS Intel, Linux with/without NVIDIA, and fallback RAM propagationshutil.which("nvidia-smi")explicitly verifiedsys.platformpatches — zero host OS dependencyDemo/Screenshot for feature changes and bug fixes -
Code Understanding and AI Usage
Did you use AI assistance (ChatGPT, Claude, Copilot, etc.) to write any part of this code?
If you used AI assistance:
Explain your implementation approach:
This test covers the three hardware detection functions in isolation by patching
sys.platform,subprocess.check_output,builtins.open,platform.machine, andshutil.which. Each test class focuses on one function on one platform (Linux, macOS, or unknown), with helpers like_call()and_detect()reducing boilerplate. Thedetect_hardware()tests mock the lower-level RAM functions to verify profile assembly logic independently. Fallback behavior (8 GB total,total * 0.5available) is tested on every failure mode — file I/O errors, parse failures, missing keys, subprocess failures, and unrecognized platforms.Checklist before requesting a review
Note: Please check Allow edits from maintainers if you would like us to assist in the PR.