Skip to content

[aw][test audit] logging_config.py has zero test coverage #43

@microsasa

Description

@microsasa

Root Cause

src/copilot_usage/logging_config.py contains two callables — setup_logging() and _emoji_patcher() — plus the LEVEL_EMOJI registry. Neither is exercised by any test in the suite. The module is invoked on every CLI run (main() calls setup_logging() before dispatching subcommands), so any regression would silently affect all warning/error output visible to users.

What Is Untested

Symbol Behaviour to assert
setup_logging() Removes existing loguru handlers and adds exactly one stderr handler at WARNING level
setup_logging() Is idempotent — calling it twice does not duplicate handlers
_emoji_patcher Injects the correct emoji key into the extra dict for every level in LEVEL_EMOJI
_emoji_patcher Falls back to " " for an unknown level name
LEVEL_EMOJI Contains entries for all standard loguru levels (TRACE, DEBUG, INFO, SUCCESS, WARNING, ERROR, CRITICAL)

Expected Behaviour

  • After setup_logging(), logger has exactly one sink, it targets sys.stderr, and its minimum level is WARNING.
  • _emoji_patcher mutates record["extra"]["emoji"] to match the entry in LEVEL_EMOJI, or " " when the level is not registered.
  • The LEVEL_EMOJI dict is a complete mapping covering at least the seven standard loguru levels.

Spec

Add a tests/copilot_usage/test_logging_config.py file with:

# test: setup_logging removes all sinks and adds exactly 1
# test: calling setup_logging() twice still results in exactly 1 sink (idempotency)
# test: after setup_logging(), the single sink targets sys.stderr
# test: after setup_logging(), the minimum log level is "WARNING"
# test: _emoji_patcher sets record["extra"]["emoji"] for each known level
# test: _emoji_patcher falls back to "  " for an unknown level name
# test: LEVEL_EMOJI covers TRACE, DEBUG, INFO, SUCCESS, WARNING, ERROR, CRITICAL

Loguru exposes sink/handler inspection via logger._core.handlers (internal but stable for testing) or by patching sys.stderr and asserting that warnings/errors appear while debug messages do not.

Generated by Test Suite Analysis ·

Metadata

Metadata

Assignees

No one assigned

    Labels

    awCreated by agentic workflowtest-auditTest coverage gaps

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions