Skip to content

[aw][code health] Test hygiene bundle: unused _NOW constant and CI coverage scope mismatch #32

@microsasa

Description

@microsasa

Overview

Two small independent test/CI hygiene issues that together form a meaningful cleanup.


1. Unused _NOW constant in test_cli.py

tests/copilot_usage/test_cli.py line 18 defines:

_NOW = datetime(2025, 1, 15, 12, 0, 0, tzinfo=UTC)

This constant is never referenced anywhere in the file. It is dead code — likely a leftover from an earlier version that used time-pinned fixtures. Neither ruff (F841 only catches local variables), pyright, nor bandit flag module-level unused constants, so it slips through CI silently.

Fix: Remove the _NOW definition and its UTC import if it becomes unused as a result.


2. CI pytest runs unit + e2e together for coverage

Makefile (test target):

uv run pytest tests/copilot_usage --cov --cov-fail-under=80 ...   # unit only
uv run pytest tests/e2e ...                                        # e2e separate, no coverage gate

.github/workflows/ci.yml:

- run: uv run pytest --cov --cov-fail-under=80 -v   # ALL tests combined

The CI runs both tests/copilot_usage/ and tests/e2e/ together under the same 80% coverage gate. architecture.md explicitly states: "Coverage is measured on unit tests only (e2e coverage would be misleading)."

The practical risk: if unit coverage for a new feature drops below 80% but e2e tests happen to exercise the same lines, CI passes while make check fails. The environments are inconsistent, which erodes trust in CI as a gate.

Fix: Scope the CI coverage step to the unit test directory:

- run: uv run pytest tests/copilot_usage --cov --cov-fail-under=80 -v
- run: uv run pytest tests/e2e -v

Testing Requirement

  • After removing _NOW, run the full unit test suite to confirm no tests regressed
  • After scoping CI, verify make check and CI use equivalent coverage measurement (both unit-only)
  • No new tests needed — this is a cleanup of test infrastructure itself

Generated by Code Health Analysis ·

Metadata

Metadata

Assignees

No one assigned

    Labels

    awCreated by agentic workflowcode-healthCode cleanup and maintenance

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions