Skip to content

Fix wily rank to reconstruct full project state at latest revision (#262)#268

Open
tonybaloney wants to merge 1 commit into
masterfrom
fix/rank-latest-revision-reconstruction
Open

Fix wily rank to reconstruct full project state at latest revision (#262)#268
tonybaloney wants to merge 1 commit into
masterfrom
fix/rank-latest-revision-reconstruction

Conversation

@tonybaloney

Copy link
Copy Markdown
Owner

Fixes #262.

Problem

wily rank (without --revision) ranks against the most recent revision. But wily v2 stores metrics as deltas — a full "seed" revision plus only the files that changed in each subsequent revision. The previous implementation built its lookup from rows whose revision exactly matched the target revision:

for row in index:
    if row["revision"] == target_revision_key:
        revision_data[row["path"]] = row.get(resolved_metric.name)

So on any real repository, the latest revision contains only the file(s) changed in the last commit, and wily rank listed ~1 file by default. The no-path variant also surfaced directory/root aggregate rows that all shared an identical value.

Before (microsoft/graphrag, default latest revision)

$ wily rank packages/graphrag/graphrag raw.loc
┌────────────────────────────────────────────────────────────┬───────────────┐
│ File                                                       │ Lines of Code │
│ packages/graphrag/graphrag/index/utils/derive_from_rows.py │ 182           │
└────────────────────────────────────────────────────────────┴───────────────┘

After

$ wily rank packages/graphrag/graphrag raw.loc -l 10
┌─────────────────────────────────────────────────────────────┬───────────────┐
│ File                                                        │ Lines of Code │
│ packages/graphrag/graphrag/cache/__init__.py                │ 5             │
│ packages/graphrag/graphrag/callbacks/__init__.py            │ 5             │
│ ... (all files in the project)                              │ ...           │
└─────────────────────────────────────────────────────────────┴───────────────┘

Fix

In src/wily/commands/rank.py, reconstruct the project state at the target revision by taking, for each file path, the most recent row at or before the target revision's date — instead of exact-matching revision. Ranking is also restricted to path_type == "file" rows, so directory/root aggregates and function/class detail rows no longer pollute the table with duplicate values.

Tests

Added test_rank_latest_includes_unchanged_files, which builds a repo where src/stable.py exists only in the seed commit and src/churn.py is modified in a later commit, then asserts both appear when ranking the latest revision. (The existing gitdir fixture has a single file that changes in every commit, so it never exercised this bug.)

All test/integration/test_rank.py tests pass (16 passed); ruff check is clean.

)

rank built its per-revision lookup from rows whose `revision` exactly
matched the target revision. Because v2 storage is delta-based (a full seed
revision plus only the files changed in each later revision), the latest
revision only contains the file(s) touched in that commit, so `wily rank`
on a real repository listed roughly one file by default.

Reconstruct each file's value from the most recent row at or before the
target revision's date, and rank file-level rows only (skipping directory/
root aggregates and function/class detail rows that previously appeared with
identical values).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@codecov-commenter

codecov-commenter commented May 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 61.53846% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.00%. Comparing base (cd768bb) to head (f2f7307).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
src/wily/commands/rank.py 61.53% 2 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #268      +/-   ##
==========================================
- Coverage   90.36%   90.00%   -0.36%     
==========================================
  Files          20       20              
  Lines        1193     1201       +8     
  Branches      161      163       +2     
==========================================
+ Hits         1078     1081       +3     
- Misses         87       89       +2     
- Partials       28       31       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

Bug (v2): wily rank against latest revision only shows files changed in the last commit

2 participants