Skip to content

repo inspect counts looping guidance links in subdirectories #1329

Todo

Description

@vchamarthi

Summary

Nested guidance discovery counts unusable links as instruction files. The resulting inventory overstates the guidance available from both a working tree and a committed revision.

Scenarios (1)

1. repo inspect counts a nested sub/AGENTS.md symlink loop as an instruction file and raises no finding

Input: a git repo with a regular root AGENTS.md and sub/AGENTS.md as a symlink to itself (ln -s AGENTS.md sub/AGENTS.md inside sub/), or as a two-link loop (sub/AGENTS.md -> sub/B.md -> sub/AGENTS.md). Same result for the plain directory and for <dir>@HEAD.

repo inspect prints 2 instruction files (1 root), 0 check surfaces, risk low and exits 0. The findings are only checks.test.missing and checks.lint.missing; nothing names sub/AGENTS.md. repo scan on the same fixture says guidance file not scanned: sub/AGENTS.md: too many levels of symbolic links and marks the scan incomplete.

Expected: the looping file is not counted, or a finding or note names sub/AGENTS.md and the loop, as repo scan does.

cd sub && ln -s AGENTS.md AGENTS.md   # in a repo with a root AGENTS.md
python cli.py repo inspect <repo>

Tests are attached as tests/test_inspect_nested_guidance_loop.py (self-link, tree and @HEAD) and tests/test_inspect_nested_two_link_loop.py (two-link loop). Both fail on 9bf1ce70.

tests/test_inspect_nested_guidance_loop.py
import subprocess
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def _build(tmp_path: Path) -> Path:
    repo = tmp_path / "fixture"
    (repo / "sub").mkdir(parents=True)
    ident = ["-c", "user.email=a@b", "-c", "user.name=n"]
    subprocess.run(["git", "init", "-q", "."], cwd=repo, check=True)
    (repo / "AGENTS.md").write_text("# rules\n", encoding="utf-8")
    (repo / "sub" / "AGENTS.md").symlink_to("AGENTS.md")
    subprocess.run(["git", "add", "-A"], cwd=repo, check=True)
    subprocess.run(["git", *ident, "commit", "-qm", "x"], cwd=repo, check=True)
    return repo


def _check(source: str) -> None:
    run = subprocess.run(
        [sys.executable, "cli.py", "repo", "inspect", source],
        capture_output=True, text=True, cwd=ROOT,
    )
    out = run.stdout + run.stderr
    assert "Traceback" not in out, out
    counted_loop_file = "2 instruction files" in out
    mentions = any(w in out for w in ("sub/AGENTS.md", "symbolic", "too many levels"))
    assert not counted_loop_file or mentions, out


def test_inspect_working_tree(tmp_path: Path) -> None:
    _check(str(_build(tmp_path)))


def test_inspect_at_head(tmp_path: Path) -> None:
    _check(str(_build(tmp_path)) + "@HEAD")
tests/test_inspect_nested_two_link_loop.py
import subprocess
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def _build(repo: Path) -> None:
    (repo / "sub").mkdir(parents=True)
    (repo / "AGENTS.md").write_text("# rules\n", encoding="utf-8")
    (repo / "sub" / "AGENTS.md").symlink_to("B.md")
    (repo / "sub" / "B.md").symlink_to("AGENTS.md")
    git = ["git", "-c", "user.email=a@b", "-c", "user.name=n"]
    subprocess.run(["git", "init", "-q", "."], cwd=repo, check=True)
    subprocess.run(["git", "add", "-A"], cwd=repo, check=True)
    subprocess.run([*git, "commit", "-qm", "x"], cwd=repo, check=True)


def test_inspect_nested_two_link_loop(tmp_path: Path) -> None:
    repo = tmp_path / "twoloop"
    repo.mkdir()
    _build(repo)
    for source in (str(repo), str(repo) + "@HEAD"):
        run = subprocess.run([sys.executable, str(ROOT / "cli.py"), "repo", "inspect", source],
                             capture_output=True, text=True, cwd=ROOT)
        out = run.stdout + run.stderr
        assert "Traceback" not in out, out
        assert run.returncode == 0, out
        assert "2 instruction files" not in out or "sub/" in out, out

Related

Activity

  1. self-assigned this
    on Nov 27, 2026
  2. added
    bug
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions