Skip to content

Fix early-year growth estimation and make integration tests year-independent#116

Merged
nicklegan merged 2 commits intomainfrom
fix/growth-estimate-early-year-logic
Feb 23, 2026
Merged

Fix early-year growth estimation and make integration tests year-independent#116
nicklegan merged 2 commits intomainfrom
fix/growth-estimate-early-year-logic

Conversation

@nicklegan
Copy link
Collaborator

Summary

Fixes growth estimation logic when running early in the year (< 60 days) and resolves CI failures caused by year-dependent fixture comparisons.

Changes

Growth estimation fix

  • When early in the year, CalculateNewEstimate now projects current year totals using last year's growth delta instead of copying previous year's values unchanged
  • This ensures displayed totals are consistent with displayed deltas

Test improvements

  • Added unit tests for CalculateNewEstimate covering early-year, mid-year, and fallback scenarios
  • Made integration tests deterministic by using dynamic year for test commits and filtering year-based output rows

Before

Early-year estimate showed previous year's totals with a delta suggesting growth (inconsistent).

After

Early-year estimate shows projected totals that match the applied delta (consistent).

@nicklegan nicklegan self-assigned this Feb 18, 2026
@nicklegan nicklegan force-pushed the fix/growth-estimate-early-year-logic branch from 88ce52a to 53d7ef8 Compare February 18, 2026 13:34
@nicklegan nicklegan marked this pull request as ready for review February 18, 2026 13:36
@nicklegan nicklegan requested review from Copilot and steffen February 18, 2026 13:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes growth estimation behavior early in the year so projected totals and deltas stay consistent, and updates integration testing to be year-independent/deterministic across calendar years.

Changes:

  • Update CalculateNewEstimate early-year logic to project using the prior year’s growth delta (when available).
  • Add unit tests covering early-year, later-year, and fallback estimation scenarios.
  • Make integration outputs deterministic by normalizing/removing year-dependent rows and updating fixtures accordingly.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
script/remove-non-deterministic-rows Filters additional non-deterministic rows and normalizes leading year values to YYYY for stable fixture comparisons.
script/build-test-repository Uses the current year when creating test-repo commits so integration tests don’t go stale year-to-year.
pkg/display/sections/growth_tables_test.go Adds unit tests for CalculateNewEstimate across early/mid-year and fallback cases.
pkg/display/sections/growth_estimates.go Adjusts early-year estimation to apply last year’s delta (using two-years-ago data when present).
fixtures/git-metrics.txt Updates fixture output to match normalized year placeholders and removed commit-date rows.
Comments suppressed due to low confidence (1)

script/remove-non-deterministic-rows:50

  • The success check at the end now keys off the exit status of the last rm -f (or sed/rm), not the grep/filtering step (and even previously it didn’t validate grep). This means the script will report success and overwrite the input even if grep/sed fails. Capture and validate grep/sed exit codes explicitly (treating grep exit 1 as acceptable when it matches all lines), or enable set -e and restructure with a trap for temp-file cleanup.
grep -Ev -f "$pattern_file" "$input_file" > "$temp_file"
rm -f "$pattern_file"

# Normalize year references to YYYY for deterministic comparison
sed -i.bak -E 's/^([0-9]{4})([\^~\* ]+)/YYYY\2/g' "$temp_file"
rm -f "$temp_file.bak"

# Check if the temporary file was created successfully
if [ $? -eq 0 ]; then
  mv "$temp_file" "$input_file"
  echo "Non-deterministic rows removed successfully. Output written to '$input_file'."

@nicklegan nicklegan force-pushed the fix/growth-estimate-early-year-logic branch from 53d7ef8 to 3b635ff Compare February 18, 2026 13:44
Apply previous years growth rate when < 60 days into current year

Projected totals now include expected growth instead of copying previous year

Add unit tests for CalculateNewEstimate edge cases

Make integration tests year-independent to prevent CI failures
@nicklegan nicklegan force-pushed the fix/growth-estimate-early-year-logic branch from 3b635ff to 29b74b8 Compare February 18, 2026 13:46
@nicklegan nicklegan added the bug Something isn't working label Feb 18, 2026
The else branch handling missing yearlyStats[currentYear-2] was unreachable.
CalculateNewEstimate is only called from DisplayUnifiedGrowth when
estimationYears > 0, which guarantees at least 2 full years of commit
history exist. Removed the dead code and corresponding test case.
@nicklegan nicklegan linked an issue Feb 20, 2026 that may be closed by this pull request
@nicklegan nicklegan merged commit 2db12a5 into main Feb 23, 2026
7 checks passed
@nicklegan nicklegan deleted the fix/growth-estimate-early-year-logic branch February 23, 2026 10:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Growth estimation not working

3 participants