test: cover _check_memory_health threshold branches#1262
Conversation
Greptile SummaryAdds four deterministic unit tests for Confidence Score: 5/5Safe to merge — test-only changes with no production code modifications. All four new tests are arithmetically correct against the production implementation, fake Path classes properly handle the No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[_check_memory_health] --> B{/proc/meminfo\nexists?}
B -- No --> C[status: missing\n'unavailable on this platform']
B -- Yes --> D[read_text encoding=utf-8]
D -- OSError --> E[status: missing\n'Unable to read meminfo']
D -- success --> F[parse key:value lines\nskip lines without ':']
F --> G{MemTotal and\nMemAvailable\npresent?}
G -- No --> H[status: missing\n'Incomplete /proc/meminfo data.']
G -- Yes --> I[used_pct = int\ntotal - avail / total * 100]
I --> J{used_pct < 90?}
J -- Yes --> K[status: passed\n✅ NEW TEST: 50% usage]
J -- No --> L[status: warn\n✅ NEW TEST: 90% usage boundary]
H -.->|NEW TEST| M[MemTotal absent]
H -.->|Existing test| N[MemAvailable absent]
Reviews (1): Last reviewed commit: "test: cover memory health thresholds" | Re-trigger Greptile |
|
💜 One more reason the project grows. Thanks @kespineira — your contribution just landed! 👋 Join us on Discord - OpenSRE : hang out, contribute, or hunt for features and issues. Everyone's welcome. |

Fixes #1156
Describe the changes you have made in this PR -
Added deterministic unit coverage for the remaining
_check_memory_health()cases not handled by #1212:passedwarnMemTotalreturnsmissing/proc/meminfoNo production code changes were needed.
Demo/Screenshot for feature changes and bug fixes -
Terminal validation:
The adjusted
PATHmakes the local authenticatedcodexbinary unavailable so the Codex CLI smoke test follows its intended skip path.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:
#1212 covered the missing-file, incomplete-
MemAvailable, andOSErrorbranches. This PR covers the remaining threshold behavior by replacingapp.remote.server.Pathwith small per-test fake path classes. That keeps the tests deterministic and prevents reads from the host/proc/meminfo.The fixtures use fixed
MemTotalandMemAvailablevalues so the expected percentages are clear: 50% for thepassedbranch and exactly 90% for thewarnbranch. I also added aMemTotal-missing case because the issue explicitly calls out both required meminfo fields.Checklist before requesting a review
Note: Please check Allow edits from maintainers if you would like us to assist in the PR.