Skip to content

fix(repo): budget names a linked directory and a link loop as the reason (#1331) - #1424

Merged
vchamarthi merged 7 commits into
intel:mainfrom
vchamarthi:issue-1331-repo-budget-gives-misleading-reasons
Dec 1, 2026
Merged

vchamarthi merged 7 commits into
intel:mainfrom
vchamarthi:issue-1331-repo-budget-gives-misleading-reasons

Conversation

@vchamarthi

Copy link
Copy Markdown
Contributor

Summary

repo budget printed not found, broken link, or outside tree for a guidance link to a directory and for a symlink loop, though repo scan names both. It now says links to a directory or symbolic link loop. Fixes #1331. Related: #1272, #1329.

Changes

  • dokimi/repos/source_errors.py: new LinkLoopError and LinkToDirectoryError, both SourceArgumentError.
  • dokimi/repos/source.py: WorkTree.resolve, GitTree._follow and GitTree.resolve raise them; WorkTree._readable raises LinkToDirectoryError for a symlink to a directory, which read_text used to report as a bare IsADirectoryError.
  • dokimi/repos/links.py: _LinkLoop derives from LinkLoopError.
  • dokimi/repos/budget.py: _unreadable_reason maps the two types.
  • A changelog fragment.
  • tests/test_repo_budget_link_reasons.py: the new tests, in their own file because tests/test_repo_budget.py is near the 1000 line cap.
  • WorkTree._readable also turns a RuntimeError from a link loop (Python before 3.13) into LinkLoopError.

Risk

WorkTree.read_text and read_bytes on a symlink to a directory now raise LinkToDirectoryError (a ValueError) instead of IsADirectoryError, which matches what GitTree already raised. I think a caller that catches only OSError around such a read would now see it escape; I did not find one in dokimi/repos. The new raise sites carry a comment naming #1331.

Testing

Four tests in tests/test_repo_budget_link_reasons.py: a directory link for AGENTS.md and CLAUDE.md, a self-link loop in a work tree and in a commit, a loop reported as RuntimeError as Python before 3.13 does, and a dangling link that keeps the old text. That file, tests/test_repo_budget.py, tests/test_repo_source_links.py and tests/test_growth_ratchet.py pass together (179 passed, 2 skipped).

Open questions

None beyond the choices listed by the program.

  • I chose Typed errors mapped in _unreadable_reason over Reading the exception message in repo budget: repo scan mishandles guidance links with invalid or non-UTF-8 targets #1272 chose to decide by type, and test_unreadable_reason_goes_by_the_error_type_not_its_words pins that. Is that the behaviour you want?
  • I chose WorkTree._readable raises LinkToDirectoryError for a symlink to a directory over Mapping IsADirectoryError in _unreadable_reason: A plain directory would then also read 'links to a directory', and GitTree already raises this type. Is that the behaviour you want?

Revert

A plain revert restores the old text. Nothing is stored.

Checklist

None.

  • Tests added/updated and pytest passes
  • ruff, mypy, and schema checks pass
  • Docs updated (or N/A) — see the docs-drift checklist in CONTRIBUTING.md
  • Self-reviewed per "Before opening a PR" in AGENTS.md
  • Each new raise/exit and test names the doc, contract or issue it traces to
  • No ad-hoc run artifacts committed
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml)
Checklist evidence
  • Tests added/updated and pytest passes: 1 test file(s) changed; suite: 31624 passed; 1 failing test(s) fail on the base branch too: tests/test_repo_compare_interval.py::test_the_row_p_places_zero_where_large_deltas_round_p_at_zero_apart; 3 of 4 proof(s) fail before the change; 1 pin behaviour the base code already had
  • ruff, mypy, and schema checks pass: passed: ci.yml:static / ruff check, ci.yml:typecheck / mypy, ci.yml:static / schema-check, ci.yml:static / schema_compat vs the PR base
  • Docs updated (or N/A): N/A: No doc quotes the old warning text; the repo budget warning wording is described only by the changelog fragment added here.
  • Self-reviewed per "Before opening a PR" in AGENTS.md: nothing left open; mutation of changed lines ran
  • Each new raise/exit and test names the doc, contract or issue it traces to: every new error path and test names a doc, contract or issue
  • No ad-hoc run artifacts committed: 2 added file(s), none a run's output
  • New files carry the SPDX license header (or are exempt in .github/.licenserc.yaml): every new source file carries the header

Fixes #1331.

…son (intel#1331)

`repo budget` gave "not found, broken link, or outside tree" for every
unreadable guidance link except a decode error or a FIFO. A guidance link
to a directory and a symbolic link loop now have their own error types,
raised where the trees already detect them, and `_unreadable_reason` maps
them to "links to a directory" and "symbolic link loop".

Fixes intel#1331

Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
@vchamarthi
vchamarthi requested a review from a team as a code owner November 30, 2026 07:48
Copilot AI balanced review requested due to automatic review settings November 30, 2026 07:48
@exai-bot

exai-bot commented Nov 30, 2026 •

Copy link
Copy Markdown

✅ OpenCodeReview: Review complete: 0 finding(s) across 6 selected item(s).

CI at 8c1356e: 26 passing, 4 skipped.

Test notes (1)
  • dokimi/dokimi/repos/source.py:389: With if hops > 40: # ELOOP as in a checkout; typed so `repo budget` names it (#1331) changed to if hops >= 40: # ELOOP as in a checkout; typed so `repo budget` names it (#1331), the tests still pass: dokimi/tests/test_repo_budget_link_reasons.py. A value exactly at the boundary gives the same result either way here, so no test says which one is meant.
Review details
  • Commit reviewed: 8c1356e against merge base e1f7740
  • Coverage: 6 files in 1 groups
  • Engine: OpenCodeReview v1.13.5-exai.4.8f73eada, us.openai.gpt-6.1-sol
  • Usage: 150k tokens (86k from cache), 26s
  • Tool calls: 16 (11 file_read, 3 code_search, 1 ci_status, 1 local_check_results)
  • Repository budget link reasons, source error handling, and regression tests: 6 files

@codecov-commenter

codecov-commenter commented Nov 30, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.30%. Comparing base (e1f7740) to head (8c1356e).
⚠️ Report is 9 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1424   +/-   ##
=======================================
  Coverage   96.30%   96.30%           
=======================================
  Files         515      515           
  Lines       68905    68966   +61     
  Branches    11932    11940    +8     
=======================================
+ Hits        66360    66420   +60     
+ Misses       1568     1567    -1     
- Partials      977      979    +2     
Files with missing lines Coverage Δ
dokimi/dokimi/repos/budget.py 98.85% <100.00%> (+0.01%) ⬆️
dokimi/dokimi/repos/links.py 97.82% <100.00%> (ø)
dokimi/dokimi/repos/source.py 97.30% <100.00%> (+0.43%) ⬆️
dokimi/dokimi/repos/source_errors.py 100.00% <100.00%> (ø)

... and 14 files with indirect coverage changes

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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Copilot review overview

4 open issues
What changed in this PR

This PR makes repo budget warnings more specific by introducing typed errors for symlink loops and symlinks to directories, and mapping them to clearer human-readable reasons (fixing #1331).

Changes:

  • Add LinkLoopError and LinkToDirectoryError as SourceArgumentError subclasses and raise them from WorkTree/GitTree resolution paths.
  • Update repo budget’s unreadable-reason mapping to emit “symbolic link loop” / “links to a directory”.
  • Add targeted tests and a changelog fragment for the new warning wording.
File Description
dokimi/​tests/​test_repo_budget_link_reasons.py Adds regression tests ensuring repo budget names “links to a directory” and “symbolic link loop”.
dokimi/​dokimi/​repos/​source_errors.py Introduces typed exceptions so callers can distinguish loop vs directory-link errors.
dokimi/​dokimi/​repos/​source.py Raises the new typed exceptions from WorkTree/GitTree resolution and readability checks.
dokimi/​dokimi/​repos/​links.py Makes internal _LinkLoop derive from LinkLoopError to preserve typing.
dokimi/​dokimi/​repos/​budget.py Maps LinkLoopError / LinkToDirectoryError to the new warning strings.
dokimi/​changelog.d/​20261129_120000_budget-link-reasons.md Documents the improved warning wording in the changelog.

Review effort: Lite

Comment thread dokimi/dokimi/repos/source.py Resolved
Comment thread dokimi/dokimi/repos/source.py Outdated
Comment on lines +232 to +233
except (RuntimeError, OSError) as exc: # a link loop (RuntimeError before Python 3.13); typed so `repo budget` names it (#1331)
raise LinkLoopError(f"too many levels of symbolic links: {path}") from exc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in 25f14f3: WorkTree.resolve now raises LinkLoopError only for RuntimeError or an OSError with ELOOP; any other OSError is a SourceArgumentError with its own message, and a test covers both.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was already fixed in 25f14f3: WorkTree.resolve raises LinkLoopError only for RuntimeError or ELOOP, and tests/test_repo_budget_link_reasons.py::test_only_an_eloop_while_resolving_is_a_link_loop covers ELOOP and EACCES.

@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Mutation of changed lines

⚠️ Not a clean result: some breaks or tests were left out

At 8c1356e: 22 caught · 0 missed · 6 inconclusive

This is not a clean result:

  • 4 candidate test files were not run
  • 1 changed line was not mutated

Warning only: a missed break does not fail the job. Updated on every push; the full report is in the ci run summary.

…y resolve

Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>
Signed-off-by: Vladislav Perevezentsev <vladislav.perevezentsev@intel.com>

@vlad-perevezentsev vlad-perevezentsev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 LGTM · re-checked 25f14f3 · nothing required from @vchamarthi

🔀 Merge: safe now · merges cleanly into current main, 0 commits behind · after it, #1402 needs a rebase (repos/links.py, repos/source.py), and #1328, #1321, #1190 and #1416 (repos/source.py)

✅ make ci-local --offline: 31,402 passed, 117 skipped · ✅ 4 of the 5 original tests fail on the base · ✅ the junction and ELOOP tests fail with their fix reverted · ✅ Windows (Server 2025, Python 3.13): tests/test_repo_budget_link_reasons.py 10 passed, a real junction included

repo budget now names a linked directory and a link loop correctly, in a work tree and in a commit.

Disagreed with @Copilot on the ELOOP path and on target_is_directory: replied in their threads.

Fixed in this branch, up to 25f14f3:

  • The GitTree link-to-directory branch had no test: 0cd6153 runs the test on a commit too and checks resolve().
  • A Windows junction to a directory got the generic reason: 22ec887 checks _is_link().
  • The fallback comment still named a loop: b046fdc.
  • WorkTree.resolve called every OSError a loop (the @Copilot thread): 25f14f3 keeps it for ELOOP only.

Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
- _readable translated only RuntimeError, so an ELOOP OSError escaped
  untyped; resolve and _readable now share _loop_checked.
- The link tests follow main's renames (link_text, files listed by hand
  for the mocked junction); _link marks directory targets and the git
  helper is a def.

Signed-off-by: vchamarthi <123653452+vchamarthi@users.noreply.github.com>
@vchamarthi

Copy link
Copy Markdown
Contributor Author

This is ready for another look: I've pushed 2 commits on issue-1331-repo-budget-gives-misleading-reasons (25f14f3..8c1356e).

Changes:

  • WorkTree._readable raises LinkLoopError for an OSError with ELOOP, and a SourceArgumentError with its own cause for any other OSError.

Threads:

  • I answered each one in its thread: 3 fixed, 1 already settled.

What I checked on the new commit: the 1 test of the fix pass; the full test suite passes with main merged in (32,270 tests), apart from 1 failure main has too.

What each test shows
  • read_text types ELOOP as a loop and other OSErrors as their own cause: passes.

@vchamarthi
vchamarthi merged commit 049bc53 into intel:main Dec 1, 2026
30 checks passed
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.

Repo budget gives misleading reasons for unusable guidance links

5 participants