Skip to content

[aw][code health] dead code branch in _format_log_files_lineunreadable < 0 is structurally unreachable #1001

@microsasa

Description

@microsasa

Root Cause

_format_log_files_line in vscode_report.py has three branches:

unreadable = found - parsed
if unreadable > 0:   # ← reachable: some files failed to parse
    ...
if unreadable < 0:   # ← dead: structurally unreachable
    return (f"... ([yellow]{found} found; inconsistent counts[/yellow])")
return f"[bold]Log Files:[/bold]  {parsed}"

The unreadable < 0 case implies log_files_parsed > log_files_found. This can never be true because get_vscode_summary constructs the accumulator as:

acc = _SummaryAccumulator(log_files_found=len(logs))  # parsed starts at 0
for log_path, file_id in log_ids:
    try:
        ...
    except OSError:
        continue  # parsed NOT incremented on failure
    acc.log_files_parsed += 1  # incremented only on success

log_files_parsed starts at zero and is only incremented on successful reads; it can never exceed log_files_found = len(logs). The unreadable < 0 guard was likely added as a defensive measure when the counts were computed separately, but the invariant parsed ≤ found is now guaranteed by construction.

Impact

The dead branch is harmless but:

  1. Misleads future readers into thinking parsed > found is a realistic runtime state.
  2. The companion test test_inconsistent_counts_shown_when_parsed_exceeds_found in test_vscode_report.py exercises this impossible state, adding noise to the test suite and coverage numbers without guarding against a real regression.
  3. The docstring on _format_log_files_line says "surfacing unreadable or inconsistent counts" — the second clause documents behaviour that can't occur.

Fix

  1. vscode_report.py — remove the if unreadable < 0: branch and update the docstring to drop the "inconsistent counts" reference:

    def _format_log_files_line(summary: VSCodeLogSummary) -> str:
        """Build the 'Log Files' line, surfacing unreadable file counts."""
        found = summary.log_files_found
        parsed = summary.log_files_parsed
        unreadable = found - parsed
        if unreadable > 0:
            return (
                f"[bold]Log Files:[/bold]  {parsed}"
                f" ({found} found, "
                f"[red]{unreadable} unreadable[/red])"
            )
        return f"[bold]Log Files:[/bold]  {parsed}"
  2. tests/copilot_usage/test_vscode_report.py — remove test_inconsistent_counts_shown_when_parsed_exceeds_found entirely (it tests an impossible state and has no value as a regression guard).

Testing Requirement

After the removal:

  • Verify the remaining two test cases (test_unreadable_files_shown_when_found_exceeds_parsed and test_happy_path_no_unreadable_annotation) still pass — they cover the only two real branches.
  • make check must pass (lint + typecheck + all tests).
  • No new test is needed: the removed branch is unreachable by design.

Warning

⚠️ Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • pypi.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "pypi.org"

See Network Configuration for more information.

Generated by Code Health Analysis · ● 7.2M ·

Metadata

Metadata

Assignees

No one assigned

    Labels

    awCreated by agentic workflowaw-dispatchedIssue has been dispatched to implementercode-healthCode cleanup and maintenance

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions