Skip to content

test(qm-daemon): add 44 pytest unit tests for pure check functions#8

Merged
ctwoodwa merged 1 commit into
mainfrom
chore/qm-daemon-tests
Jun 2, 2026
Merged

test(qm-daemon): add 44 pytest unit tests for pure check functions#8
ctwoodwa merged 1 commit into
mainfrom
chore/qm-daemon-tests

Conversation

@ctwoodwa
Copy link
Copy Markdown
Contributor

@ctwoodwa ctwoodwa commented May 22, 2026

Summary

  • Adds coordination/tests/__init__.py and coordination/tests/test_qm_daemon.py with 44 pytest unit tests for the pure/deterministic functions in qm-daemon.py
  • Zero test coverage today on 1455-line critical fleet infra daemon; this establishes the baseline
  • All 44 tests pass under Python 3.9 + pytest 8.4.2 (0.52s run time)

Coverage

Check Tests Notes
BEACON_RE regex 12 (5 valid + 7 invalid) Parametrized
check_beacon_naming 4 Clean inbox, misnamed file, README skipped, missing dir
check_heartbeats 8 Fresh, warn/alert/critical (FAST agents), idle-tier relaxation, SLOW agent below warn, README skipped, missing dir
check_inbox_drift 2 Clean layout, misfile detected
check_archive_health 4 Under watermark, over watermark, rollup overdue, missing dir
check_buglog_watermark 6 Under, at limit, over, multiple repos, worktree excluded, bugs key format
render_findings_block 8 Smoke test per check name + critical Admiral note + no-findings path

Excluded from unit-test scope (network-dependent): checks 8 (gh CLI), 10 (SSH), 12 (subprocess audiobook).

Test plan

  • python3 -m pytest coordination/tests/test_qm_daemon.py -v — 44 passed, 0 failed, 0.52s

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added comprehensive pytest test suite for daemon quality checks and validation.
    • New tests validate beacon naming conventions, heartbeat monitoring for stale agents, inbox protocol consistency, archive data watermarks, buglog tracking thresholds, and check result rendering.
    • Includes parametrized test cases for valid/invalid beacon formats and smoke tests for output generation.

Review Change Stack

44 tests covering BEACON_RE, check_beacon_naming, check_heartbeats (incl.
idle-tier relaxation), check_inbox_drift, check_archive_health,
check_buglog_watermark, and render_findings_block smoke tests for each
check name. All pass under Python 3.9 + pytest 8.4.2.

Network-dependent checks (SSH windows-worktrees, gh CLI spot-check
backstop, subprocess audio-staleness) are out of scope for unit tests;
pure/deterministic checks only.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

📝 Walkthrough

Walkthrough

This PR adds a complete pytest test module for qm-daemon.py that covers six major check functions: beacon filename validation, inbox file organization, heartbeat staleness detection, inbox protocol drift, archive health watermarks, buglog accumulation limits, and findings output rendering. The tests use temporary directories, file mocking, and parametrization to achieve deterministic unit coverage without network dependencies.

Changes

qm-daemon unit test coverage

Layer / File(s) Summary
Module setup and beacon regex validation
tests/test_qm_daemon.py (lines 1–68)
Module imports via importlib, test constants, and parametrized tests for qm.BEACON_RE against valid and invalid beacon filenames.
Beacon naming detection
tests/test_qm_daemon.py (lines 69–122)
Tests qm.check_beacon_naming() by patching INBOX_DIR, verifying clean inboxes pass, misnamed files are detected, README.md is skipped, and missing inbox returns an appropriate summary.
Heartbeat staleness monitoring
tests/test_qm_daemon.py (lines 123–247)
Adds _write_heartbeat() helper and tests qm.check_heartbeats() across fresh/stale scenarios with WARN/ALERT/CRITICAL severities, FAST vs DEFAULT agent thresholds, idle-state relaxation, slow-agent behavior, and missing-directory handling.
Inbox drift and archive health
tests/test_qm_daemon.py (lines 248–340)
Tests qm.check_inbox_drift() to detect misfiled subdirectories by patching COORD_DIR/ROOT_DIR, and tests qm.check_archive_health() to validate watermark thresholds, rollup-overdue detection, and missing-directory errors by patching ARCHIVE_DIR.
Buglog watermark validation
tests/test_qm_daemon.py (lines 341–425)
Adds _make_buglog() helper and tests qm.check_buglog_watermark() across under/at/over thresholds, multiple repos, .worktrees exclusion, and alternate buglog JSON key format.
Findings output rendering
tests/test_qm_daemon.py (lines 426–534)
Smoke tests for qm.render_findings_block() verifying rendered output includes expected section titles, severity labels, special notes, helper script names, and summary text.

🎯 3 (Moderate) | ⏱️ ~25 minutes

🐰 With beacons and heartbeats all aligned,
Buglog watermarks and archives refined,
Inbox checks drift-free, no findings to fear,
The daemon stands sentinel, steadfast and clear! 🛡️✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.51% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The PR description provides comprehensive coverage details, test results, and excluded scope, but does not follow the repository's required template structure with Type and Checklist sections. Consider using the repository's standard PR template with Type (Repo infrastructure / CI / docs) and Checklist sections to ensure consistency with repository conventions.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding 44 pytest unit tests for the pure check functions in qm-daemon.py.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/qm-daemon-tests

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/test_qm_daemon.py (1)

140-140: 💤 Low value

Consider moving import os to module level.

The import os statement inside the function works correctly but is unconventional. Standard practice is to place all imports at the module level for better visibility and to avoid repeated import overhead.

♻️ Proposed refactor

Move the import to the top of the file with other imports:

 import importlib.util
 import json
+import os
 import time
 from pathlib import Path

Then remove it from the function:

     path.write_text(content)
     # Backdate the mtime by age_seconds
     target_mtime = time.time() - age_seconds
-    import os
     os.utime(str(path), (target_mtime, target_mtime))
🤖 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 `@tests/test_qm_daemon.py` at line 140, The test contains an inline "import os"
inside a function; move that "import os" to the module-level import block at the
top of the file alongside the other imports, then remove the in-function import
so the test function uses the top-level os import instead; no other code changes
are required.
🤖 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.

Nitpick comments:
In `@tests/test_qm_daemon.py`:
- Line 140: The test contains an inline "import os" inside a function; move that
"import os" to the module-level import block at the top of the file alongside
the other imports, then remove the in-function import so the test function uses
the top-level os import instead; no other code changes are required.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f88274b7-7c59-4568-973a-6384a5f90599

📥 Commits

Reviewing files that changed from the base of the PR and between 728ce12 and 754556a.

📒 Files selected for processing (2)
  • tests/__init__.py
  • tests/test_qm_daemon.py

@ctwoodwa ctwoodwa merged commit 87161ad into main Jun 2, 2026
4 checks passed
@ctwoodwa ctwoodwa deleted the chore/qm-daemon-tests branch June 2, 2026 23:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant