fix(system): replace uptime with psutil#548
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
cb45b98 to
ebd809f
Compare
|
There was a problem hiding this comment.
Pull request overview
This PR removes the uptime dependency (a source-only C extension causing CI failures on Windows/Python 3.14 build isolation) and replaces its usage in the system module with psutil-based boot time and uptime computation, keeping the Service.info() output shape consistent.
Changes:
- Drop
uptimefrom project dependencies and lockfile. - Update
src/aignostics/system/_service.pyto compute boot time viapsutil.boot_time()and uptime seconds viatime.time() - boot_ts. - Add unit tests validating that
Service.info()includes the expected uptime keys and formats.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
pyproject.toml |
Removes uptime from declared dependencies. |
uv.lock |
Removes the uptime package entry and dependency edges from the lockfile. |
src/aignostics/system/_service.py |
Replaces uptime calls with psutil + time implementation for boot time/uptime seconds. |
tests/aignostics/system/service_test.py |
Adds tests and shared mocking helper to validate the new uptime fields in Service.info(). |
PR Review: fix(system): replace uptime with psutil✅ SUMMARYStatus: APPROVED - All critical checks pass, excellent implementation! This PR successfully fixes a Windows CI build issue by replacing the problematic ✅ CRITICAL CHECKS - ALL PASS1. Test Markers ✅All 3 new test functions have the required
Verification: 2. Test Coverage ✅
3. Code Quality ✅$ uv run ruff check src/aignostics/system/_service.py tests/aignostics/system/service_test.py
All checks passed!
4. Conventional Commits ✅Format:
✅ REPOSITORY-SPECIFIC CHECKS - ALL PASS5. Architecture Compliance ✅
6. Testing Strategy ✅
7. Medical Device & Security ✅
8. Breaking Changes ✅None - External API unchanged: "uptime": {
"seconds": <float>, # Still float seconds
"boottime": <ISO string> # Still ISO 8601 + UTC
}Minor change (safe):
9. CI/CD Impact ✅
10. Documentation Updates ✅
💡 SUGGESTIONS (Non-blocking)1. Test Quality EnhancementFile: The # Current test (line 494-496):
seconds = result["runtime"]["host"]["uptime"]["seconds"]
assert isinstance(seconds, float)
assert seconds > 0 # Only checks positive, not the actual value
# Suggested enhancement:
seconds = result["runtime"]["host"]["uptime"]["seconds"]
assert isinstance(seconds, float)
assert seconds == pytest.approx(3600.0, rel=0.1) # Verify calculation is correct
# Fixture mocks: boot_time=1_000_000.0, time.time()=1_003_600.0
# Expected: time.time() - boot_ts = 3600.0 seconds (1 hour)Rationale: Would catch bugs like reversed subtraction ( Benefit: Higher confidence in calculation correctness. 2. Test Fixture DocumentationFile: Consider adding brief comments: FIXED_BOOT_TIME = 1_000_000.0 # Arbitrary fixed epoch seconds for deterministic tests
now = boot_time + 3600.0 # Pretend system has been up 1 hour (3600 seconds)3. Edge Case Test (Optional)Consider adding a test for very recent boot time: @pytest.mark.unit
@pytest.mark.asyncio
async def test_info_uptime_very_short() -> None:
"""Test uptime with very recent boot (< 1 second)."""
recent_boot = time.time() - 0.5 # 500ms ago
with _patch_info_dependencies(boot_time=recent_boot):
result = await Service.info()
seconds = result["runtime"]["host"]["uptime"]["seconds"]
assert 0 < seconds < 1.0 # Between 0 and 1 second🌟 EXCELLENT PRACTICES
📋 REVIEW CHECKLIST
🎯 FINAL VERDICTAPPROVED ✅ This is a well-executed bug fix with:
The suggestions above are non-blocking quality improvements. The PR is ready to merge as-is. Great work! 🎉 Commands to verify: # Run the new tests
uv run pytest tests/aignostics/system/service_test.py::test_info_uptime_keys_present -v
uv run pytest tests/aignostics/system/service_test.py::test_info_uptime_seconds_positive -v
uv run pytest tests/aignostics/system/service_test.py::test_info_uptime_boottime_is_iso_string -v
# Check linting
uv run ruff check src/aignostics/system/_service.py tests/aignostics/system/service_test.py
# Verify no unmarked tests
uv run pytest -m "not unit and not integration and not e2e" --collect-only |
Codecov Report✅ All modified and coverable lines are covered by tests.
|
|
Tests passed on |



Why?
uptime==3.0.1is a source-only C extension with no pre-built wheels. On Windows, uv's build isolation uses Python 3.14'styping.pywhen compiling it for older Python versions (3.11–3.13), causing aSyntaxErrorthat breaks CI.How?
Remove
uptimefrom dependencies and replace its two call sites insystem/_service.pywithpsutilequivalents: boot time viapsutil.boot_time()(already a direct dependency with binary wheels for all platforms) and uptime seconds viatime.time() - boot_ts. The returned dict shape is unchanged.