[loop-generated] [test] Add unit tests for infrastructure/hermes/monitor.py — 660 lines untested #1371

Closed
opened 2026-03-24 10:08:59 +00:00 by Timmy · 1 comment
Owner

Priority: High
Impact: System reliability, test coverage
Size: 660 lines, 0% test coverage

Problem

src/infrastructure/hermes/monitor.py has NO unit test coverage despite being 660 lines of critical system monitoring code. This is a major reliability risk.

Required Test Coverage

  1. Memory monitoring: Test memory pressure detection, threshold checks
  2. Disk monitoring: Test disk usage calculation, cleanup triggers
  3. Ollama monitoring: Test service status checks, model management
  4. Process monitoring: Test zombie detection, health checks
  5. Network monitoring: Test connectivity validation
  6. Alert system: Test alert triggering, rate limiting
  7. Error handling: Test failure scenarios, graceful degradation

Test File

tests/infrastructure/test_hermes_monitor.py

Acceptance Criteria

  • Create comprehensive test suite
  • Mock external dependencies (disk, network, processes)
  • Test both success and failure scenarios
  • Achieve >85% code coverage
  • Include integration tests for critical paths
  • Verify alert behavior under various conditions

Testing Strategy

  • Use pytest fixtures for mocking system calls
  • Test threshold-based alerting
  • Verify cleanup operations work correctly
  • Test configuration edge cases

Estimated effort: 4-5 hours

**Priority**: High **Impact**: System reliability, test coverage **Size**: 660 lines, 0% test coverage ## Problem `src/infrastructure/hermes/monitor.py` has NO unit test coverage despite being 660 lines of critical system monitoring code. This is a major reliability risk. ## Required Test Coverage 1. **Memory monitoring**: Test memory pressure detection, threshold checks 2. **Disk monitoring**: Test disk usage calculation, cleanup triggers 3. **Ollama monitoring**: Test service status checks, model management 4. **Process monitoring**: Test zombie detection, health checks 5. **Network monitoring**: Test connectivity validation 6. **Alert system**: Test alert triggering, rate limiting 7. **Error handling**: Test failure scenarios, graceful degradation ## Test File `tests/infrastructure/test_hermes_monitor.py` ## Acceptance Criteria - [ ] Create comprehensive test suite - [ ] Mock external dependencies (disk, network, processes) - [ ] Test both success and failure scenarios - [ ] Achieve >85% code coverage - [ ] Include integration tests for critical paths - [ ] Verify alert behavior under various conditions ## Testing Strategy - Use pytest fixtures for mocking system calls - Test threshold-based alerting - Verify cleanup operations work correctly - Test configuration edge cases Estimated effort: 4-5 hours
Author
Owner

Kimi Task Instructions

Files to work with:

  • src/infrastructure/hermes/monitor.py (read-only, analyze code structure)
  • tests/infrastructure/test_hermes_monitor.py (create this new test file)

What to implement:

  1. Create comprehensive unit tests for the SystemMonitor class and all its methods
  2. Focus on these critical methods:
    • check_memory_pressure() - mock system stats, test thresholds
    • check_disk_usage() - mock disk stats, test percentage calculations
    • check_ollama_status() - mock HTTP responses, test connectivity
    • get_process_health() - mock process info, test health scoring
    • generate_status_report() - test report formatting and completeness

Test structure to follow:

import pytest
from unittest.mock import Mock, patch, MagicMock
from src.infrastructure.hermes.monitor import SystemMonitor, MemoryPressure, DiskUsage

class TestSystemMonitor:
    def test_check_memory_pressure_normal(self):
        # Mock psutil.virtual_memory() with normal values
        pass
    
    def test_check_memory_pressure_high(self):
        # Mock psutil.virtual_memory() with high usage
        pass
    
    # ... more tests

How to verify:
Run tox -e unit and ensure all new tests pass. Target 90%+ coverage of monitor.py.

Key testing principles:

  • Mock all external dependencies (psutil, requests, subprocess)
  • Test both normal and edge cases (high memory, disk full, ollama down)
  • Test error handling and graceful degradation
  • Ensure thread safety if applicable

This is critical system reliability code - thorough tests are essential.

## Kimi Task Instructions **Files to work with:** - `src/infrastructure/hermes/monitor.py` (read-only, analyze code structure) - `tests/infrastructure/test_hermes_monitor.py` (create this new test file) **What to implement:** 1. Create comprehensive unit tests for the `SystemMonitor` class and all its methods 2. Focus on these critical methods: - `check_memory_pressure()` - mock system stats, test thresholds - `check_disk_usage()` - mock disk stats, test percentage calculations - `check_ollama_status()` - mock HTTP responses, test connectivity - `get_process_health()` - mock process info, test health scoring - `generate_status_report()` - test report formatting and completeness **Test structure to follow:** ```python import pytest from unittest.mock import Mock, patch, MagicMock from src.infrastructure.hermes.monitor import SystemMonitor, MemoryPressure, DiskUsage class TestSystemMonitor: def test_check_memory_pressure_normal(self): # Mock psutil.virtual_memory() with normal values pass def test_check_memory_pressure_high(self): # Mock psutil.virtual_memory() with high usage pass # ... more tests ``` **How to verify:** Run `tox -e unit` and ensure all new tests pass. Target 90%+ coverage of monitor.py. **Key testing principles:** - Mock all external dependencies (psutil, requests, subprocess) - Test both normal and edge cases (high memory, disk full, ollama down) - Test error handling and graceful degradation - Ensure thread safety if applicable This is critical system reliability code - thorough tests are essential.
kimi was assigned by Timmy 2026-03-24 10:21:12 +00:00
kimi was unassigned by Timmy 2026-03-24 19:33:37 +00:00
Timmy closed this issue 2026-03-24 21:54:35 +00:00
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Rockachopa/Timmy-time-dashboard#1371