Skip to content

Fix test-to-source ratio calculation to exclude tests from source LOC#12373

Merged
pelikhan merged 2 commits intomainfrom
copilot/investigate-test-coverage-decline
Jan 28, 2026
Merged

Fix test-to-source ratio calculation to exclude tests from source LOC#12373
pelikhan merged 2 commits intomainfrom
copilot/investigate-test-coverage-decline

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 28, 2026

The test-to-source ratio incorrectly included test files in the denominator, causing the Daily Code Metrics Report to show 0.498 (below target) when the actual ratio is 1.443 (healthy).

Changes

Calculation Fix (.github/workflows/shared/metrics-patterns.md):

  • Calculate source LOC as total_loc - test_loc
  • Use test_loc / source_loc instead of test_loc / total_loc
  • Add *.test.cjs to test file patterns
  • Reference specs/metrics-glossary.md definition explicitly

Before:

# Calculate test-to-source ratio
# Scope: test_lines_of_code / lines_of_code_total
test_to_source_ratio=$(echo "scale=3; $test_lines_of_code / $lines_of_code_total" | bc)

After:

# Calculate source LOC (excluding tests)
source_lines_of_code=$((lines_of_code_total - test_lines_of_code))

# Calculate test-to-source ratio
# Scope: test_lines_of_code / source_lines_of_code (excludes test files from source LOC)
# Per specs/metrics-glossary.md: "Excludes test files from source LOC calculation"
test_to_source_ratio=$(echo "scale=3; $test_lines_of_code / $source_lines_of_code" | bc)

Impact

  • Reported "77% decline" was measurement error, not actual coverage decline
  • Corrected ratio: 1.443 (314K test / 218K source) vs incorrect 0.498 (314K test / 532K total)
  • Next metrics run will show accurate baseline
Original prompt

This section details on the original issue you should resolve

<issue_title>[Code Quality] Investigate 77% test coverage decline in past 7 days</issue_title>
<issue_description>### Description

The Daily Code Metrics Report - 2026-01-25 identified a critical test coverage decline:

  • Test-to-Source Ratio: Dropped from ~1.0 to 0.498 (below recommended target)
  • 7-Day Trend: ⬇️ -77.67% decrease
  • Current Test LOC: 264,983 lines
  • Current Source LOC: 531,941 lines

This dramatic decline suggests either:

  • Large amount of new source code added without corresponding tests
  • Test files being removed or refactored
  • Calculation changes in metrics methodology

Impact

  • Critical: Test coverage is below recommended 1.0 target
  • Risk: Reduced confidence in code quality and reliability
  • Trend: Significant negative trend requires immediate investigation

Suggested Investigation Steps

  1. Analyze Recent Commits (last 7 days):

    • Identify large source code additions without tests
    • Check for test file deletions or refactoring
    • Review PRs that added significant LOC
  2. Review Metrics Calculation:

    • Verify test-to-source ratio calculation is correct
    • Check if file counting logic changed
    • Confirm test file pattern matching (*_test.go, *.test.cjs)
  3. Identify Coverage Gaps:

    • Use go test -cover ./... to measure actual coverage
    • Identify packages with <50% coverage
    • Prioritize critical packages (pkg/workflow/, pkg/cli/)
  4. Create Action Plan:

    • Set minimum coverage requirements (>50% per package)
    • Add missing tests for newly added code
    • Implement pre-commit coverage checks

Success Criteria

  • Identify root cause of 77% decline
  • Test-to-source ratio returns to >0.8
  • Coverage gaps documented with remediation plan
  • CI checks prevent future coverage regression

Source

Extracted from Daily Code Metrics Report - 2026-01-25 (Discussion githubnext/gh-aw#11784)

Priority

High - Test coverage decline is a critical quality indicator requiring immediate investigation

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 11, 2026, 9:09 PM UTC

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

The test-to-source ratio was incorrectly calculated as test_loc / total_loc,
but according to specs/metrics-glossary.md it should exclude test files from
the source LOC calculation: test_loc / (total_loc - test_loc).

This fixes the 77% decline in test coverage - it was actually a calculation
bug, not a real decline. The correct ratio should be ~1.44 (healthy) instead
of the incorrectly calculated 0.59.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate 77% test coverage decline in past 7 days Fix test-to-source ratio calculation to exclude tests from source LOC Jan 28, 2026
Copilot AI requested a review from pelikhan January 28, 2026 22:11
@pelikhan pelikhan marked this pull request as ready for review January 28, 2026 23:02
@pelikhan pelikhan merged commit 418a16f into main Jan 28, 2026
@pelikhan pelikhan deleted the copilot/investigate-test-coverage-decline branch January 28, 2026 23:03
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.

[Code Quality] Investigate 77% test coverage decline in past 7 days

2 participants