Skip to content

test(docs): fail a citation pin the page stopped citing, reject :0 and ../ (#1265) - #1277

Merged
Birfy merged 4 commits into
mainfrom
agent/1265-citation-pin-staleness
Nov 25, 2026
Merged

Birfy merged 4 commits into
mainfrom
agent/1265-citation-pin-staleness

Conversation

@HugoXK

@HugoXK HugoXK commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1265.

What changed

Before: tests/test_docs_citations.py only checked that a cited file exists and that the last cited line is inside it. A _EXTERNAL pin stayed valid after the page stopped citing that path or moved the citation to another line; :0 was accepted; and a ../ citation could read a line count outside the repository.

After: the same single walk gains three checks:

  • collect the external coordinates the pages actually cite and report _EXTERNAL - seen, naming the page and pin: docs/algo-genesis.md -> agents/nowhere.ex:7 (pinned in _EXTERNAL, no longer cited);
  • reject first < 1 or end < first: docs/page.md:1 -> pkg/mod.py:0 (line numbers start at 1 and run forward);
  • reject a .. segment before touching the filesystem: docs/page.md:1 -> ../../outside.txt:1 (citation path escapes this repository).

_EXTERNAL stays exact coordinates and the shipped docs are untouched; every current citation still passes. Tests-only plus the guard in the test module — no docs/ or runtime change, so no changelog fragment (changelog_fragments check passes without one).

Verification at the tip

Tip SHA: 5c0a73a

Red at 0a6e782f8f with only the test delta (guard as merged in #1264, tests/test_docs_citations.py from this branch):

3 failed, 1 passed in 0.47s
tests/test_docs_citations.py:103: AssertionError  assert any(...) -> AssertionError: []
tests/test_docs_citations.py:121: AssertionError  assert len(problems) == 1 -> assert 0 == 1
tests/test_docs_citations.py:132: AssertionError  assert len(problems) == 1 -> assert 0 == 1

Ran:

  • python -m pytest tests/test_docs_citations.py -q → 4 passed in 0.47s
  • python -m pytest tests/test_docs_links.py tests/test_site_navigation.py tests/test_docs_examples.py -q → 31 passed in 58.64s
  • python -m tools.changelog_fragments check → 45 changelog fragment(s) OK
  • python -m tools.gen_api_docs --check → docs/api.md is up to date

Not run:

  • full pytest -q — the delta is one test file, the docs family above is the affected surface.
  • mkdocs build --strict — no page, nav or mkdocs.yml change.

Update at 95c87086

Tip SHA: 95c8708

The tip named above stays as the record of the first read; the current tip is this one. Security found that an absolute citation path also escaped the checkout: _CITATION allowed a leading /, and root / path discards root when path is absolute, so /etc/ld.so.conf:1 was line-counted from outside the repository (read-only, benign in outcome, but the guard did not do what its docstring said). _problems() now rejects Path(path).is_absolute() before any filesystem touch, with the same (citation path escapes this repository) message and the same place as the .. check.

Red was taken red-first at 5c0a73a2db with only the test delta: 1 failed, 4 passed in 0.95s, tests/test_docs_citations.py:168 asserting the escape message against docs/page.md:1 -> /nonexistent/outside.txt:1 (file does not exist). The test cites a nonexistent absolute path so it fails on the message, not on the runner.

Ran at this tip:

  • python -m pytest tests/test_docs_citations.py -q → 5 passed in 0.40s
  • docs family → 31 passed in 60.44s
  • python -m tools.changelog_fragments check → 45 changelog fragment(s) OK
  • python -m tools.gen_api_docs --check → docs/api.md is up to date

@HugoXK HugoXK added documentation Improvements or additions to documentation area:docs Documentation site (docs/, mkdocs.yml) and README risk:T1 Risk tier T1 (tests, examples, changelog.d), set by the controller from the diff labels Nov 25, 2026
@HugoXK

HugoXK commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

PR #1277 — field draft: true -> false — reason: all four gates are green at tip 5c0a73a2db9032177b0b264e05bbc083d9b14bdf, so this is ready for review under the Lead's seat-2 instruction.

Red was re-taken on the new default branch: 0a6e782f8f with only the test delta gives 3 failed, 1 passed in 0.47s; at this tip 4 passed in 0.47s, docs family 31 passed in 58.64s, 45 changelog fragment(s) OK, docs/api.md is up to date.

No agent-pr label (owner banned it); labels are the issue's own documentation, area:docs, risk:T1.

@HugoXK
HugoXK marked this pull request as ready for review November 25, 2026 04:32
@github-actions github-actions Bot added the agent-pr Pull request opened by an agent label Nov 25, 2026
@HugoXK

HugoXK commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

New tip 95c870865c62129128fcd6c456522d37222499c8, reviewed red first at 5c0a73a2db.

The hole. The guard claimed to require the path to stay inside the checkout, but _CITATION allowed a leading / and root / path discards root for an absolute path, so target.is_file() line-counted a real file outside the checkout. /etc/ld.so.conf:1 passed: read-only and benign in outcome, but a false claim in the guard's own docstring. _problems() now rejects Path(path).is_absolute() before any filesystem touch, with the same (citation path escapes this repository) message and the same position as the .. check.

Red at 5c0a73a2db, test delta only (no guard change):

1 failed, 4 passed in 0.95s
tests/test_docs_citations.py:168: AssertionError
assert 'escapes this repository' in 'docs/page.md:1 -> /nonexistent/outside.txt:1 (file does not exist)'

The new test cites /nonexistent/outside.txt:1 — an absolute path that does not exist — so it fails on the wrong message, not on a missing file, and does not depend on the runner.

Green at 95c87086: 5 passed in 0.40s; docs family (test_docs_links, test_site_navigation, test_docs_examples) 31 passed in 60.44s; python -m tools.changelog_fragments check → 45 changelog fragment(s) OK; python -m tools.gen_api_docs --check → docs/api.md is up to date. Diff is still the one test file (+100/-13).

Pushed as two new commits on top, no force, no rebase, base still 0a6e782f8f, no draft/ready change. Docstring re-read: no other sentence overstates what the guard does, so it is untouched.

@HugoXK

HugoXK commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Read at 95c870865c62129128fcd6c456522d37222499c8 (base 0a6e782f8f; mergeable_state: blocked = the review gate, no conflict). Python 3.10.12, pytest 8.3.5, -o addopts="" -p no:cacheprovider, PYTHONPATH at the tree, AGENTDESCENT_HOME/TMPDIR in a scratch dir, real HOME.

The two reds are the real test-first commits, not a whole-file swap.

  • e1238961 (base + tests only, guard scaffolding but no new checks): 3 failed, 1 passed in 0.44s — the body's 3 failed, 1 passed, at :103 (assert any(...) → []), :121 (zero-line → len([]) == 0), :132 (escape target is a real file, so no problem). Three distinct assertions and three distinct causes.
  • 926a3052 (old tip 5c0a73a2 + the absolute test): 1 failed, 4 passed in 0.48s, :168, with (file does not exist) where escapes this repository was expected.
  • At the tip: 5 passed in 0.40s, including the shipped-corpus test.

Each check is independently load-bearing (full-tree complement probes at the tip): remove the stale-pin reporting loop → only test_a_stale_external_pin_is_named fails (1 failed, 4 passed); neutralize first < 1 or end < first → only the zero-line test (1 failed, 4 passed); drop the ../absolute branch → only the two escape tests (2 failed, 3 passed).

The absolute fix rejects before any touch. The condition is ".." in Path(path).parts or Path(path).is_absolute(), ahead of target = root / path. With a real absolute file, the old tip calls _line_count on it (touched: [<that path>], problems: []); the tip returns … (citation path escapes this repository) with touched: []. The new test cites /nonexistent/outside.txt, which does not exist on this host, so it fails on the message and not on runner state.

_EXTERNAL stays exact coordinates. Probe against pins: exact pkg/x.ex:7 → []; page cites :8 while pinned at :7 → two problems (file does not exist + pinned in _EXTERNAL, no longer cited); exact range :7-9 → []; single :7 against the :7-9 pin → both problems; same path pinned to another page → the pin is reported stale. Shipped docs pass.

Docstring: no other sentence overstates what the guard does, and every real file citation matches _CITATION (the only loose :digits string in the shipped docs is the flag example `--resolved review:1,comment:2`). One residual the docstring does not claim: a committed symlink to an outside target is still followed (probe docs/link.txt:1 → []); the guard is lexical, out of this card's scope.

Family: test_site_navigation.py test_docs_examples.py → 9 passed in 1.83s, so the body's 31 = 22 (docs_links) + 9. python -m tools.gen_api_docs --check current; python -m tools.changelog_fragments check → 45 changelog fragment(s) OK. Old tip → tip is +19/−1: the condition and the one test, nothing else.

Not run: tests/test_docs_links.py (ModuleNotFoundError: No module named 'markdown' here), mkdocs build --strict (not installed), full pytest -q (one test module, no docs/ or runtime change).

No UI surface: a test module only; nothing renders.

No merge action from QA: this report is advisory, the merge gate is the repo's review decision on the head sha, and the merge itself is executed by the repo's merge process.

The guard as merged in #1264 accepts a stale `_EXTERNAL` pin, a `:0`
citation, and a `../` citation that resolves outside the repository. Each
new test fails at that head: the stale pin is never compared with what the
pages quote, line zero never exceeds a file's length, and the escape target
is a real file so the existence check passes.

The guard takes an optional root and pin set so the new cases can run against
a temp tree; the shipped docs are not touched.
Three gaps in the guard as merged: `_EXTERNAL` pins were allowed whether or
not a page still quotes them, `:0` never exceeded a line count, and a `../`
path resolved outside the checkout and was checked against a file that really
exists there. The walk now records the external coordinates it sees and reports
`_EXTERNAL - seen`, rejects line numbers below 1 or running backwards, and
rejects a path with a `..` segment before touching the filesystem.
@Birfy

Birfy commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Review (Birfy)

Tip SHA: 95c8708
Ran:

  • .github/scripts/risk_gate.py --repo ThinkFlowLab/agentdescent --pr 1277 → T1
  • pytest -q -o addopts='' tests/test_docs_citations.py at this tip → 5 passed
  • python -m tools.changelog_fragments check → 45 changelog fragment(s) OK
  • python -m tools.gen_api_docs --check → docs/api.md is up to date
    Not run:
  • Full offline suite locally — required CI is green on this tip (test 3.9–3.13, build, otel-wire)
    Findings:
  • No actionable defects. A stale _EXTERNAL pin is now reported, :0 / backward ranges are rejected, and a .. or absolute citation path is refused before the guard touches the filesystem. The follow-up tip correctly closes the absolute-path hole the first guard left (root / path dropping the repo root).
    Verdict: PASS

@Birfy
Birfy merged commit 74e811e into main Nov 25, 2026
10 checks passed
@Birfy
Birfy deleted the agent/1265-citation-pin-staleness branch November 25, 2026 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-pr Pull request opened by an agent area:docs Documentation site (docs/, mkdocs.yml) and README documentation Improvements or additions to documentation risk:T1 Risk tier T1 (tests, examples, changelog.d), set by the controller from the diff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

docs: the citation guard cannot see a stale pin, accepts :0, and lets a ../ citation escape the repo

2 participants