Skip to content

Realize harden-path-escape-helpers-against-symlink-loops § 3: the four containment guards answer a symlink loop (refs #1074) - #1107

Merged
brettheap merged 6 commits into
mainfrom
realize/1074-symlink-loop-guards
Sep 18, 2026
Merged

brettheap merged 6 commits into
mainfrom
realize/1074-symlink-loop-guards

Conversation

@brettheap

@brettheap brettheap commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Lane: openxfactory-5 (openXfactory-5)

REALIZATION of the ratified packet harden-path-escape-helpers-against-symlink-loops (proposal PR #1083 → ebcdbc0c, ratified by Brett Heap 2026-09-18 approximately 09:55Z, verbatim "Ratify; land when green"). This PR lands on his separate word, verbatim "land #1107 when it is un-drafted." Six realization files: three modules and the three test packages that prove them (named below). The packet directory IS touched here, in exactly one file and only in the way this landing authorizes: openspec/changes/harden-path-escape-helpers-against-symlink-loops/tasks.md — commit d8baaeef ticked §§ 3–4 with this PR's own evidence now that the packet is on main, and commit bc9ebf95 added § 4.4's dated evidence note for this PR's own green pytest-suite run. Nothing under openspec/specs/ is touched. The archive (§ 5) and § 6 stay open/carried — a separate act on a separate word and on merged-plus-green evidence.

Refs #1074
Refs #1083

code_surface: openxFactory. Six files: three modules and the three test packages that prove them.

What § 3 owed, and what is here

Path.resolve(strict=True) signals a SYMLINK LOOP by raising RuntimeError, which is a subclass of NEITHER OSError NOR ValueError, so four containment guards that promise an ANSWER were open at exactly that failure and three of the four are driven to it by a COMMITTED tree shape. The packet's four line numbers, re-read on this head 3e32d987, are unchanged from the c6997f12 they were measured at: code_surface.py:777, target_release.py:394 and :630, proposal-support.py:347.

§ file act
3.1 scripts/code_surface.py _unescaped → except (OSError, RuntimeError):, docstring amended
3.3 scripts/target_release.py _unescaped AND _registry_present → except (OSError, RuntimeError):, both docstrings amended
3.5 scripts/proposal-support.py _contained → except (OSError, ValueError, RuntimeError):, the ValueError STAYING; contained_dir and contained_file docstrings amended
3.2 tests/code_surface/ ONE case, _unescaped, all three positions
3.4 tests/target_release/ TWO cases: _unescaped all three positions, and _registry_present DECLARED AS A CLAUSE TEST
3.6 tests/proposal-support/ ONE case, contained_dir + contained_file, all three positions + the clean-candidate sub-case

FOUR CLAUSES, FIVE DOCSTRINGS, FOUR TEST CASES IN THREE PACKAGES — the packet's own counts (proposal.md code_surface: front matter, tasks.md § 4.1).

The three sites are corrected in ONE act because design.md D2 ruled it one: code_surface._unescaped's docstring ends "target_release._unescaped is the exact shape this mirrors" and target_release._unescaped's opens "THIS IS _registry_present'S TEST, GENERALIZED TO ANY PATH THIS MODULE OPENS". Correcting one module alone leaves a documented claim of identity FALSE.

_registry_present is widened too (D3) although no tree state reaches its clause: is_dir() calls os.stat, which reports the loop as OSError(ELOOP), and is_dir() absorbs that and answers False. Re-measured here in all three positions the first requirement names — loop AT the registry leaf, at the ANCESTOR contracts/, and repo_root ITSELF a loop — returned False from every one, which is D0.5's correction to #1074's own text reproduced on this head. Its test is therefore D3's test of the CLAUSE, declared as one in the test's own docstring, driven by a seam that makes the pre-check pass while the resolution is left entirely REAL and meets a REAL loop.

The pair of runs: FAILING against the unfixed clauses, then PASSING

The failing half is taken on a worktree at origin/main (3e32d987) with only this PR's test files checked out over it, so scripts/ is untouched main:

$ git worktree add <baseline> origin/main
$ cd <baseline> && git checkout 4892fa5f -- tests/code_surface tests/target_release tests/proposal-support
$ git status --porcelain -- scripts/ | wc -l
0
$ python3 -m pytest tests/code_surface tests/target_release tests/proposal-support -q -k symlink_loop

scripts/code_surface.py:775: in _unescaped
E   RuntimeError: Symlink loop from '…/leaf/openspec/changes/a-packet/proposal.md'
scripts/target_release.py:392: in _registry_present
E   RuntimeError: Symlink loop from '…/repo/contracts/releases'
scripts/target_release.py:628: in _unescaped
E   RuntimeError: Symlink loop from '…/leaf/openspec/changes/a-packet/proposal.md'
scripts/proposal-support.py:338: in contained_file
scripts/proposal-support.py:343: in _contained
E   RuntimeError: Symlink loop from '…/repo/openspec/changes/a-packet/.openspec.yaml'

FAILED tests/code_surface/test_code_surface_gate.py::test_a_symlink_loop_drops_the_candidate_in_all_three_positions
FAILED tests/target_release/test_target_release_gate.py::test_a_symlink_loop_at_the_registry_is_absent_and_never_raises
FAILED tests/target_release/test_target_release_gate.py::test_a_symlink_loop_drops_the_candidate_in_all_three_positions
FAILED tests/proposal-support/test_proposal_support.py::DeclaredFormerIdTests::test_a_symlink_loop_is_uncontained_in_all_three_positions
4 failed, 448 deselected in 1.97s

Four cases, four clauses, and the raising line of each is the guard's own resolution — including target_release.py:392, which is the seamed clause test really meeting a real loop and not a mocked exception. The same command at this PR's head:

$ python3 -m pytest tests/code_surface tests/target_release tests/proposal-support -k symlink_loop -v

tests/code_surface/test_code_surface_gate.py::test_a_symlink_loop_drops_the_candidate_in_all_three_positions PASSED [ 25%]
tests/target_release/test_target_release_gate.py::test_a_symlink_loop_at_the_registry_is_absent_and_never_raises PASSED [ 50%]
tests/target_release/test_target_release_gate.py::test_a_symlink_loop_drops_the_candidate_in_all_three_positions PASSED [ 75%]
tests/proposal-support/test_proposal_support.py::DeclaredFormerIdTests::test_a_symlink_loop_is_uncontained_in_all_three_positions PASSED [100%]
4 passed, 448 deselected in 0.79s

Each of the three positions was verified to drive its clause on its own, not merely the first one the test reaches — every _unescaped position raises at code_surface.py:775 / target_release.py:628, the CANDIDATE resolution, and never at the root line below it, because candidate = repo_root / relative already traverses the loop (design.md D5). The clean-candidate sub-case is the one that raises at proposal-support.py:346, resolved.relative_to(root.resolve(strict=True)), and it is asserted only in tests/proposal-support/.

§ 4 verification, at this head

§ 4.1 python3 -m pytest tests/code_surface tests/target_release tests/proposal-support -q

452 passed, 296 subtests passed in 87.41s (0:01:27)

§ 4.2 — the widened clauses changed no judgment of the real tree:

$ python3 scripts/validate-code-surface.py .
code_surface: 48 active proposals, 48 declaring — 7 `none`, 33 a repository list, 8 named by the register, 0 outside the grammar.
  archive (read, never judged): 171 proposals, 125 declaring, 3 of them outside the grammar.
code_surface validation passed (every active declaration's head is admitted).          exit 0

$ python3 scripts/validate-target-release.py .
target_release: 48 active proposals, 48 declaring — 23 `implemented`, 3 a named release, 1 `deferred-allocation`, 21 named by the register, 0 outside the vocabulary.
  archive (read, never judged): 171 proposals, 61 of them outside the vocabulary.
target_release validation passed (every active declaration is admitted).               exit 0

$ python3 scripts/proposal-support.py . verify
proposal support verification ok                                                       exit 0

§ 4.3 — design.md D0.3's TWO trees re-run through the FOUR entry points that traceback today, with the FIFTH reader beside them. TREE ONE is a minimal openspec/changes/a-real-change/ whose proposal.md is a two-link a -> b -> a loop; TREE TWO carries the loop on .openspec.yaml instead. Both sides are shown, because D0.3's own record is the traceback:

entry pointon origin/main (3e32d98)at this head
validate-code-surface.py <tree one>RuntimeError: Symlink loop from '…/a-real-change/proposal.md', exit 10 active proposals, 0 declaring … validation passed, exit 0
validate-target-release.py <tree one>RuntimeError: Symlink loop from '…/a-real-change/proposal.md', exit 10 active proposals, 0 declaring … validation passed, exit 0
former_identity_claimants <tree two>RAISED RuntimeError at proposal-support.py:343{'a-real-change': ['the live packet `openspec/changes/a-real-change`']}
declared_former_ids_in_tree <tree two>RAISED RuntimeError at proposal-support.py:343[]
contained_change_dir_names <tree two>{'a-real-change'}{'a-real-change'} — UNCHANGED

All four now REPORT rather than traceback, and the reported judgment is the drop each guard's docstring promises: the looped proposal.md is DROPPED from both scans (0 active proposals), and the unreadable .openspec.yaml contributes no lineage ([]) while the packet the repository really does contain is still swept. The fifth reader's answer is UNCHANGED, which § 4.3 requires as part of the evidence and not as an omission from it: contained_change_dir_names never reached a guard, so the widening must not turn its result into a drop.

§ 4.4 pytest-suite at this head — the check run on this PR.

Beyond § 4: the suite this branch does NOT make green, and does not make red either

$ python3 -m pytest tests/sequenced_after -q
3 failed, 283 passed in 39.28s

test_THE_LIVE_RECORD_DISPOSITIONS_ONLY_REAL_DISAGREEMENTS_and_NAMES_FACTS, test_THE_LIVE_PLAIN_RUN_IS_GREEN_WITH_ZERO_UNDISPOSITIONED and test_corpus_sequenced_after_all_validate, all on one finding:

archive-date-vs-commit: 2026-09-16-add-composed-view-authoring: dated 2026-09-16,
added 2026-09-18 by 3e32d9874b5c68e90b0cef62cd94f9e378831fa3 — undispositioned

INHERITED FROM main, NOT CAUSED HERE — the adding commit named in the finding IS main's own tip. Proved by running the identical command on an untouched worktree at origin/main: 3 failed, 283 passed in 41.53s, the same three tests. This branch adds no disposition row and does not touch tests/sequenced_after/archive-date-dispositions.yaml; that finding belongs to its own lane (PR #1056).

No linter runs on scripts/ in this repository's CI — there is no pyproject.toml, setup.cfg, ruff.toml, .flake8 or tox.ini, and no workflow references ruff, flake8, pylint or black.

§ 3.7 — NO SYMLINK IS ADDED TO THE TRACKED TREE

$ git ls-files -s | awk '$1 == "120000"'
$ git ls-files -s | awk '$1 == "120000"' | wc -l
0

Nothing. Every loop in these four tests is built at test time under the test's own temporary directory and torn down with it. A committed loop is tracked as two ordinary git objects and would be met by every recursive reader this estate runs — the corpus scans, the document-health families, the archive gate, the notebook projection, the packaging tools — not only the guard under test; a fixture that reds tools unrelated to the defect it proves is a second defect introduced to demonstrate the first.

§ 3.8 — NO OTHER FILE MOVES

$ git diff --stat origin/main
 scripts/code_surface.py                          |  16 ++-
 scripts/proposal-support.py                      |  25 ++++-
 scripts/target_release.py                        |  37 ++++++-
 tests/code_surface/test_code_surface_gate.py     |  76 ++++++++++++++
 tests/proposal-support/test_proposal_support.py  |  95 +++++++++++++++++
 tests/target_release/test_target_release_gate.py | 124 +++++++++++++++++++++++
 6 files changed, 369 insertions(+), 4 deletions(-)

Six files. No validator arm, no workflow, no contract member, no schema, no report field, no promoted byte, nothing in openspec/.

And the four deletions are the four clauses and nothing else:

$ git diff -U0 origin/main -- scripts/ | grep '^-' | grep -v '^---'
-    except OSError:
-    except (OSError, ValueError):
-    except OSError:
-    except OSError:

$ git diff -U0 origin/main -- tests/ | grep '^-' | grep -v '^---'
(nothing — no existing test is edited, renamed, flipped or deleted)

The ELEVEN other except OSError-family clauses design.md D4 enumerates by AST scan — code_surface.py :568 and :656, target_release.py :337 and :528, proposal-support.py :162, :416, :2541, :3724, :4290, :4312 and :4511 — are read and deliberately left (§ 6.1): they guard reads, writes and subprocesses, where absorbing a RuntimeError would swallow a defect in this repository's own code. proposal-support.py:3939's already-wider except Exception: is retained rather than narrowed.

One departure from § 3.6's letter, in its own spirit

§ 3.6 says the loop is built "under tmp_path", pytest's spelling. tests/proposal-support/test_proposal_support.py is a pure unittest module ending in unittest.main(), with no pytest import and no fixture use anywhere in its 155 tests; a fixture-taking function added to it would silently not run under that entry point. The loop is therefore built under TemporaryDirectory(), this package's own spelling of the same thing and exactly what the ratified requirement asks for: "SHALL BUILD THAT LOOP AT TEST TIME, under the test's own temporary directory". The other three cases take tmp_path literally, their files being pytest throughout.

🤖 Generated with Claude Code

Summary by Sourcery

Harden path containment helpers against symlink-loop resolution failures and verify that affected scans continue reporting safely.

Bug Fixes:

  • Prevent path-containment and escape checks from raising on symlink loops by treating RuntimeError resolution failures as absent, unescaped, or uncontained paths.

Enhancements:

  • Keep the containment guards’ documented failure behavior consistent across code-surface, target-release, and proposal-support helpers.

Tests:

  • Add temporary symlink-loop coverage across leaf, parent, and scanned-root positions, including a registry race scenario and clean-candidate containment checks.

brettheap and others added 2 commits September 18, 2026 12:39
`harden-path-escape-helpers-against-symlink-loops` § 3.1, § 3.3 and § 3.5,
taken as ONE act because `design.md` D2 ruled it one: `code_surface`'s
docstring ends "`target_release._unescaped` is the exact shape this mirrors"
and `target_release._unescaped`'s opens "THIS IS `_registry_present`'S TEST,
GENERALIZED TO ANY PATH THIS MODULE OPENS", and correcting one module alone
would leave a documented claim of identity FALSE — which misleads the next
reader more than no claim would, the claim being what tells them they need
only understand one of the two.

  § 3.1 `scripts/code_surface.py`: `_unescaped`'s clause widened to
        `except (OSError, RuntimeError):`, and its docstring amended to name
        `RuntimeError` beside `OSError` as a failure this guard closes,
        keeping its written claim that `target_release._unescaped` "is the
        exact shape this mirrors" TRUE.
  § 3.3 `scripts/target_release.py`: `_unescaped`'s clause and
        `_registry_present`'s clause both widened to
        `except (OSError, RuntimeError):`, and both docstrings amended,
        `_unescaped`'s keeping its claim to generalize `_registry_present`'s
        test TRUE.
  § 3.5 `scripts/proposal-support.py`: `_contained`'s clause widened to
        `except (OSError, ValueError, RuntimeError):`, the `ValueError`
        guarding the relative-path computation's own failure and STAYING;
        `contained_dir` and `contained_file` docstrings amended to name the
        set.

`Path.resolve(strict=True)` signals a symlink loop as `RuntimeError`, a
subclass of neither `OSError` nor `ValueError`, so all four clauses were open
at exactly that failure and three of the four are driven to it by a COMMITTED
tree shape. Re-measured on this head (`3e32d987`) at the packet's own line
numbers, unchanged from `c6997f12`: `code_surface.py:777`,
`target_release.py:394` and `:630`, `proposal-support.py:347`.

`_registry_present` is widened too (D3) although NO tree state reaches its
clause — `is_dir()` absorbs the loop as `OSError(ELOOP)` and answers `False`
in all three positions (D0.5, re-measured here) — because a pre-check and a
resolution are two separate reads of a tree that can change between them, and
because a reader of the module sees the clause and not the pre-check.

FOUR CLAUSES AND FIVE DOCSTRINGS, AND NOTHING ELSE. `git diff -U0 -- scripts/`
removes exactly four lines, the four clauses. The ELEVEN other
`except OSError`-family clauses `design.md` D4 enumerates — `code_surface.py`
:568 and :656, `target_release.py` :337 and :528, `proposal-support.py` :162,
:416, :2541, :3724, :4290, :4312 and :4511 — guard reads, writes and
subprocesses where a `RuntimeError` would be a defect in this repository's own
code, and are deliberately left (§ 6.1); so is
`proposal-support.py:3939`'s already-wider `except Exception:`.

Refs #1074
Refs #1083

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…lause

`harden-path-escape-helpers-against-symlink-loops` § 3.2, § 3.4 and § 3.6.
FOUR cases, ONE PER CLAUSE, in THREE packages — which is the packet's own
count and the reason it is not one per module:

  § 3.2 `tests/code_surface/`: one test that builds an `a -> b -> a` loop
        under `tmp_path`, in ALL THREE exposed positions the first requirement
        names (the candidate's own leaf; a parent component above an ordinary
        leaf; and the SCANNED ROOT itself, `spec.md`'s third scenario), and
        asserts `_unescaped` returns `None` in each.
  § 3.4 `tests/target_release/`: TWO cases. One for `_unescaped` in all three
        positions, as 3.2; and one for `_registry_present` DECLARED AS A TEST
        OF THE CLAUSE, with the declaration in the test's own docstring and
        not only in this packet, and driven by a seam that makes the pre-check
        pass while the resolution fails, so it still FAILS against the unfixed
        clause.
  § 3.6 `tests/proposal-support/`: one test that builds the loop and asserts
        `contained_dir` and `contained_file` return `False`, in all three
        positions, plus the CLEAN-CANDIDATE sub-case that only this guard of
        the four reaches — a real candidate under an unresolvable root, so
        `proposal-support.py:343` succeeds and `:346` raises — asserted here
        and claimed nowhere else.

THE PAIR OF RUNS, NOT THE PASSING HALF. Against the unfixed clauses, on
`Python 3.12.3` (the version `.github/workflows/pytest-suite.yml` pins):
4 failed, each with `RuntimeError: Symlink loop from …` out of
`code_surface.py:775`, `target_release.py:392` (the seamed clause test),
`target_release.py:628` and `proposal-support.py:343`. Against the widened
clauses: 4 passed. The three-package suite is 452 passed, 296 subtests passed.

Each of the three positions was verified to drive the clause on its own, and
in the third the loop is reached THROUGH THE CANDIDATE and never through a
separate root read: `candidate = repo_root / relative` traverses it, so
`code_surface.py:775` / `target_release.py:628` raises and the root
resolution on the next line is never executed (`design.md` D5). The
`_registry_present` case re-measures D0.5 first — unseamed, all three
positions return `False` at the `is_dir()` pre-check — which is both the
correction to #1074's own text and the reason that case has to be a clause
test rather than a fourth tree fixture.

§ 3.7 NO SYMLINK IS ADDED TO THE TRACKED TREE: every loop is built at test
time under the test's own temporary directory and torn down with it;
`git ls-files -s | awk '$1 == "120000"'` returns nothing.

§ 3.8 NO OTHER FILE MOVES: `git diff --stat origin/main` is six files, three
scripts and these three test files, and `git diff -U0 -- tests/` removes not
one line — no existing test is edited, renamed, flipped or deleted.

ONE DEPARTURE FROM § 3.6'S LETTER, IN ITS OWN SPIRIT.
`tests/proposal-support/test_proposal_support.py` is a pure `unittest` module
ending in `unittest.main()`, and a pytest-fixture function added to it would
silently not run under that entry point. The loop is therefore built under
`TemporaryDirectory()`, which is this package's spelling of `tmp_path` and is
exactly what the ratified requirement asks for: "SHALL BUILD THAT LOOP AT TEST
TIME, under the test's own temporary directory".

Refs #1074
Refs #1083

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Copilot AI lite review requested due to automatic review settings September 18, 2026 12:43
@sourcery-ai

sourcery-ai Bot commented Sep 18, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR closes symlink-loop escape and containment failure paths by catching RuntimeError alongside the existing resolution exceptions, adds runtime-built coverage for all required loop positions—including the otherwise unreachable registry clause—and verifies the behavior through focused regressions, the relevant test suite, and validators.

Sequence diagram for symlink-loop containment guards

sequenceDiagram
    participant Validator
    participant Guard
    participant Path
    participant Filesystem

    Validator->>Guard: _unescaped(repo_root, relative)
    Guard->>Path: candidate.resolve(strict=True)
    Path->>Filesystem: Resolve candidate path
    Filesystem-->>Path: Symlink loop
    Path-->>Guard: RuntimeError
    Guard-->>Validator: None

    participant Containment
    Validator->>Containment: contained_dir(root, path)
    Containment->>Path: resolved.relative_to(root.resolve(strict=True))
    Path->>Filesystem: Resolve root or candidate
    Filesystem-->>Path: Symlink loop
    Path-->>Containment: RuntimeError
    Containment-->>Validator: False
Loading

Flow diagram for symlink-loop guard handling

flowchart TD
    A[Path resolution begins] --> B{Resolution succeeds}
    B -->|Yes| C[Apply containment or registry judgment]
    B -->|OSError| D[Return safe negative answer]
    B -->|ValueError in containment| D
    B -->|RuntimeError symlink loop| D
    D --> E[Drop candidate or report absent/uncontained]
Loading

File-Level Changes

Change Details Files
Hardened all four path-containment guards to treat symlink-loop resolution failures as negative answers instead of uncaught exceptions.
  • Added RuntimeError handling to both _unescaped implementations and _registry_present.
  • Retained _contained’s existing ValueError handling while adding RuntimeError and preserving False for uncontained paths.
  • Expanded five docstrings to document the failure semantics, candidate/root resolution behavior, and mirrored guard contract.
scripts/code_surface.py
scripts/target_release.py
scripts/proposal-support.py
Added runtime-built symlink-loop coverage across all required guard positions and validation paths.
  • Added loop fixtures and tests for candidate leaf, ancestor, and repository-root loops in both _unescaped implementations and containment helpers.
  • Added a clean-candidate/root-loop subcase for _contained to prove failures during the separate root resolution are absorbed.
  • Added a seam-based _registry_present clause test because its normal is_dir() pre-check absorbs real loop errors before resolution.
tests/code_surface/test_code_surface_gate.py
tests/target_release/test_target_release_gate.py
tests/proposal-support/test_proposal_support.py
Verified the fix with focused regression tests, the package test suite, and all three validators without modifying tracked symlinks or unrelated repository surfaces.
  • Confirmed the four new regression cases fail against the unfixed baseline and pass at the PR head.
  • Ran 452 package tests and 296 subtests successfully; validator commands also passed.
  • Documented the inherited tests/sequenced_after failures and confirmed no committed symlinks or unrelated files were added.
scripts/code_surface.py
scripts/target_release.py
scripts/proposal-support.py
tests/code_surface/test_code_surface_gate.py
tests/target_release/test_target_release_gate.py
tests/proposal-support/test_proposal-support.py

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

🟢 Approval recommended

All reviewed changes are covered by regression tests and no unresolved blocking issues remain.

Pull request overview

Hardens path-containment helpers against symlink-loop resolution failures and adds temporary regression coverage.

Changes:

  • Catch RuntimeError from symlink loops.
  • Update containment documentation.
  • Add coverage across affected validators and loop positions.
File summaries
File Summary
tests/target_release/test_target_release_gate.py Tests candidate and registry loop handling.
tests/proposal-support/test_proposal_support.py Tests containment failures.
tests/code_surface/test_code_surface_gate.py Tests loop handling in three positions.
scripts/target_release.py Hardens registry and candidate checks.
scripts/proposal-support.py Treats looped paths as uncontained.
scripts/code_surface.py Hardens _unescaped.
Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

brettheap added a commit that referenced this pull request Sep 18, 2026
…oop is dropped, never a traceback, in all three path-escape helpers (#1083)

Refs #1074. Proposal packet harden-path-escape-helpers-against-symlink-loops, PACKET ONLY: two ADDED requirements over release-realization (ten scenarios), the README Active changes bullet and the sweep-ledger row. RATIFIED by Brett Heap 2026-09-18 ~09:55Z, verbatim "Ratify; land when green" (terminal multiple-choice answer to lane openXfactory-5), encoded in the packet; LANDED on his word of 2026-09-18 ~14:20Z, verbatim "land #1083". pytest-suite is red only on main's own archive-date-vs-commit finding for 2026-09-16-add-composed-view-authoring (identical on main's run 35336659842; dispositioned on the PR), which this packet does not touch. The realization is PR #1107; the archive is a separate act on a separate word.

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 18, 2026 14:13

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.

🟢 Approval recommended

No blocking issues remain; only a minor documentation nit was identified.

Review details

Suppressed comments (1)

tests/proposal-support/test_proposal_support.py:4221

  • This docstring says the test uses this package's tmp_path, but this unittest module actually creates its temporary directory with TemporaryDirectory() below. That makes the stated fixture/API inaccurate; please name TemporaryDirectory() (or simply say “temporary directory”) so the test documentation matches the implementation.
        directory, which is the second requirement's rule and this package's
        `tmp_path`: a committed loop is tracked as two ordinary git objects
  • Files reviewed: 6/6 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

…oops with this PR's own evidence

`harden-path-escape-helpers-against-symlink-loops` § 3 and § 4, realized by
this pull request (#1107, commits `17390262` the four clause widenings,
`4892fa5f` the four test cases) and now on this branch after merging
`origin/main` (`ebcdbc0c`, #1083's landing of the packet) in the preceding
commit.

§ 3.1/3.3/3.5 (the three modules): DONE, cited by commit and current line
number, docstring claim of identity (code_surface._unescaped mirrors
target_release._unescaped; target_release._unescaped generalizes
_registry_present's test) kept TRUE because all four clauses widen in one
commit, per design.md D2's ruling.

§ 3.2/3.4/3.6 (the four test cases): DONE, cited by test id, with the
fails-then-passes pair the requirement demands (RuntimeError against
c6997f1's clause, PASSED against this branch's).

§ 3.7/3.8: PROVEN, re-run at the merged head 87eb684 — `git ls-files -s |
awk '$1 == "120000"'` empty; `git diff --stat origin/main` names exactly the
six files (three modules, three test files), the four deleted lines being
exactly the four unwidened clauses.

§ 4.1/4.2: GREEN, re-run at 87eb684 — `452 passed, 297 subtests passed`
(the three packages; +1 subtest is the corpus sweep now counting this
packet's own directory, admitted by the merge); the three live-corpus
validators all exit 0.

§ 4.3: PROVEN, the two design.md D0.3 trees rebuilt and the four
tracebacking entry points plus the fifth (unchanged) reader re-run at
87eb684, reproducing PR #1107's own body table exactly.

§ 4.4: LEFT OPEN, `- [ ]`, with a dated note. pytest-suite at 87eb684 (run
35354873708, 14m9s) is red on exactly four tests, all in
tests/sequenced_after/, all one finding — archive-date-disposition STALE:
2026-09-16-add-composed-view-authoring — none touching this packet's six
files. Confirmed inherited and not caused here: the identical 4-failure
signature reproduces on a clean worktree at plain origin/main (ebcdbc0) with
no realization content at all. main is red on this today (lane
openxfactory-4's 2026-09-16-add-composed-view-authoring; repair PR #1109 in
flight).

§ 5 and § 6 untouched; `.openspec.yaml` untouched (its own tasks name no
realization field to record).

Validated at this head: `openspec validate harden-path-escape-helpers-against-symlink-loops --strict`
passes; `--all --strict` 109/110 pass (the one failure, add-chain-attestation,
is untouched by this branch and pre-existing on main); `pytest tests/code_surface
tests/target_release tests/proposal-support tests/sequenced_after -q` → 4
failed (the inherited finding above), 734 passed, 297 subtests passed;
`validate-code-surface.py .` and `proposal-support.py . verify
harden-path-escape-helpers-against-symlink-loops` exit 0;
`validate-sequenced-after.py . --ledger-diff` exit 0, ledger consistent
(220 rows).

Refs #1074

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 18, 2026 14:36

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.

🟡 Changes recommended

Add explicit loop assertions in the parent/root tests and reconcile the task-file scope discrepancy.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (2)

tests/code_surface/test_code_surface_gate.py:619

  • These parent/root cases do not verify that the fixture actually produces RuntimeError: if _symlink_loop failed to create a loop and the remaining path were merely missing, the unfixed except OSError would still return None and these assertions would pass. Since the PR's proof requires a failing run against the old clause, explicitly assert parent_loop.resolve(strict=True) and looped_root.resolve(strict=True) raise before invoking _unescaped.
    _symlink_loop(parent_root, "openspec")
    assert cs._unescaped(
        parent_root, Path("openspec/changes/a-packet/proposal.md")) is None

tests/target_release/test_target_release_gate.py:726

  • The parent and scanned-root assertions do not independently establish a symlink loop. If either helper call produced a missing path rather than a loop, the baseline except OSError would also return None, so the advertised failing-then-passing proof would be incomplete. Add pytest.raises(RuntimeError) checks for the parent-loop path and looped_root before calling _unescaped.
    _symlink_loop(parent_root, "openspec")
    assert tr._unescaped(
        parent_root, Path("openspec/changes/a-packet/proposal.md")) is None
  • Files reviewed: 7/7 changed files
  • Comments generated: 1
  • Review effort level: Lite

Copilot AI review requested due to automatic review settings September 18, 2026 14:55

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.

🔵 Needs a closer look

Resolve the discrepancy between the documented six-file scope and the modified task file.

Review details

Suppressed comments (1)

openspec/changes/harden-path-escape-helpers-against-symlink-loops/tasks.md:126

  • The PR description says this realization changes six files and that nothing in the packet directory is touched, but this diff also modifies this packet's tasks.md (and records the verification state there). Please either update the description/file count to include this bookkeeping change or remove the packet edit if it is not intended to be part of this PR.
- [x] 3.1 `scripts/code_surface.py`: `_unescaped`'s clause widened to
  • Files reviewed: 7/7 changed files
  • Comments generated: 0 new
  • Review effort level: Lite

pytest-suite is GREEN at PR #1107 head 8fb0fc9, run 35359208240
(2026-09-18), confirmed by `gh run view 35359208240 --json conclusion`
returning success. Appended beside the prior LEFT OPEN note (which
recorded the inherited red at the earlier head 87eb684, since
repaired on main) rather than replacing it, because the tick itself
is the ARCHIVE act's: taken from main's own green run at the landed
merge, since a tick commit always moves the head past the run it
cites (the add-declared-former-id precedent). Item stays - [ ]; § 5
stays - [ ]; § 6 stays - [~].

Lane: openxfactory-5 (openXfactory-5)
Refs #1074
Refs #1083
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Copilot AI review requested due to automatic review settings September 18, 2026 15:28

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.

🟡 Changes recommended

Task §4.4 remains unchecked despite green evidence, and the packet description conflicts with the seven-file diff.

Get a fresh assessment by requesting another Copilot review.

Review details

Suppressed comments (1)

openspec/changes/harden-path-escape-helpers-against-symlink-loops/tasks.md:141

  • The realization description says this PR contains six files and that nothing in the packet directory is touched, but this change also modifies this packet's tasks.md (and the added text itself records those task updates). Please reconcile the PR description with the actual seven-file diff so the landing/archive record is not misleading.
      **DONE, commit `17390262` (PR #1107)**: the clause reads
      `except (OSError, RuntimeError):` at `scripts/code_surface.py:791` (the
      docstring's own growth moves the line off the packet's `:777`
      measurement; the two resolutions it guards are unmoved). The docstring
      now reads "`Path.resolve(strict=True)` reports a missing or unreadable
      component as an `OSError` and a SYMLINK LOOP as a `RuntimeError` … A
      clause naming only `OSError` is open at exactly the loop" and still
      closes "`target_release._unescaped` is the exact shape this mirrors" —
      kept TRUE because `target_release._unescaped`'s own clause widens in the
      SAME commit (§ 3.3). `git show 17390262 --numstat --
      scripts/code_surface.py`: `15  1`.
  • Files reviewed: 7/7 changed files
  • Comments generated: 1
  • Review effort level: Lite

@brettheap
brettheap marked this pull request as ready for review September 18, 2026 15:31

@sourcery-ai sourcery-ai Bot 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.

Sorry @brettheap, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 7 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sonarqubecloud

Copy link
Copy Markdown

@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openxfactory-5 (openXfactory-5)

LANDING — lane openXfactory-5, session 651195c7-1854-491e-894a-e6542ef5e9f4@Eagle, 2026-09-18T17:06:12Z, PR #1107 into opensoft/openxFactory main

@brettheap
brettheap merged commit c22c4fc into main Sep 18, 2026
16 checks passed
@brettheap

Copy link
Copy Markdown
Contributor Author

Lane: openxfactory-5 (openXfactory-5)

LANDED — lane openXfactory-5, session 651195c7-1854-491e-894a-e6542ef5e9f4@Eagle, 2026-09-18T17:06:34Z, PR #1107 into opensoft/openxFactory main → merge c22c4fc; Realize harden-path-escape-helpers-against-symlink-loops § 3: the four containment guards answer a symlink loop (refs #1074)

brettheap added a commit that referenced this pull request Sep 18, 2026
…DME entry

The archive makes this packet's per-change sweep-ledger row stale by that
ledger's own design, so it is re-seeded with the sanctioned tool and with no
hand edit:

    python3 scripts/validate-sequenced-after.py . --seed-ledger --moved-by '#1116'
    -> wrote tests/sequenced_after/corpus-ledger.yaml (221 rows, 1 moved by #1116)
       - harden-path-escape-helpers-against-symlink-loops

Before the seed, --ledger-diff read "per-change sweep ledger STALE (4
finding(s))": this change's row plus the three derived totals it feeds (active
ledger-derived 47 != measured 46; archived 174 != 175; active_sole 20 != 19).
After: "per-change sweep ledger consistent with the corpus (221 rows)".

EXACTLY ONE ROW MOVES and no code byte moves: state active -> archived,
moved_by "#1083" -> "#1116", moved_on 2026-09-17 -> 2026-09-18. `class: sole`
is HELD -- this change writes two requirement keys novel to the whole corpus,
so no partner flips from sole to co-modifier and NO MOVEMENT LOG entry is owed.

The same commit writes PR #1116 into the README archived-ledger entry in place
of the ARCHIVE-PR-NUMBER-PENDING marker the archive commit deliberately left:
the real number does not exist until the pull request does, which is why this
is a second commit and not a hand edit to the first.

Refs #1074
Refs #1083
Refs #1107

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
brettheap added a commit that referenced this pull request Sep 18, 2026
…arrier-identity check

`tasks.md` § 3.2, quoted: "`scripts/estate_inventory.py` (NEW): the reader and
the row-level judge, in the shape `scripts/code_surface.py` uses: read through
the shipped strict loader, no second parser, no path reached through a symlink
at leaf or ancestor, deterministic, no network. Public: load the inventory,
resolve an identifier (address, bare name, or former address through
`contracts/policies/repository-identity.yaml`), and report the row-level
findings § 3.4 gates. IT RE-CHECKS THE FOUR IN-TREE KINDS ONLY … It also
carries the CARRIER-IDENTITY CHECK that mode uses — given a path, read the
tree's own origin URL and normalize it, and resolve a FORMER carrier address
through `contracts/policies/repository-identity.yaml` — returning verified /
unverified rather than raising, so § 3.3 can report an unverified tree as NOT
RE-CHECKED instead of failing the run (ruling "Bind the carrier identity",
§ 1.5 (a))."

WHAT IS HERE. `load_inventory` reads the file through `frontmatter_strict.
strict_load` — the shipped strict loader, no second parser — and REFUSES rather
than picks: a duplicate address, a shared bare name (naming BOTH rows, because
"picking is how an authorization lands in the wrong repository"), a kind
outside the closed five, a governance class outside the closed three, an
admission with no site, a `gitlink` with no carrier, a `change` whose id is not
a change-directory name, a `pin`/`workflow` path that is absolute, carries `..`
or sits outside the directory its kind names, and — both ways — a
`provisional:` that disagrees with the presence of a `change` admission.

`resolve` resolves three spellings and no fourth: an address against a row's
address, a bare name against a row's unique bare name, a FORMER address through
the transfer map to a current row, carrying WHICH of the three happened so the
caller can report the former case rather than refuse it (`design.md` D5).
Nothing is resolved by asking the provider. The comparison is CASE-SENSITIVE
because the transfer map's own `field_rules.current` says this estate compares
the owner segment case-sensitively "even where the provider compares
case-insensitively" — a case-insensitive resolver would admit exactly the
spellings each row's `owner_case` names as NOT this estate's.

`load_transfers` drops the PENDING rows, which is the map's own
`pending_row_rule` and not a strictness invented here: a pending row declares a
change that has not happened, and every use this module makes of the map is a
live reference.

`evidence_verdicts` re-checks the four IN-TREE kinds on every run and reports
`gitlink` as NOT RE-CHECKED without exception — not passed, not failed. A `pin`
or `workflow` whose file is present but no longer NAMES the row's repository is
GONE too: presence of the file is not presence of the evidence. A `change` is
judged in three states, and the archived one's detail names both remedies the
requirement reaches.

`carrier_identity` NEVER RAISES. It reads the tree's own origin URL (`git -C
<path> remote get-url origin`, a local config read that reaches no network),
normalizes past the `git@`/`https://` spellings and the `.git` suffix, and
verifies against the carrier or against the carrier's FORMER address through
the transfer map — the two places this estate already states an identity. Every
failure (no git, no repository, no origin, an unrecognized URL spelling, a
timeout) returns unverified, because the one verdict for a tree that could not
be confirmed is NOT RE-CHECKED and a raise would turn a caller's typo into a
failed run.

THE CONTAINMENT GUARDS ARE MIRRORED AND NOT APPROXIMATED.
`_has_symlinked_ancestor` and `_unescaped` are `code_surface.py`'s exact shapes,
including `except (OSError, RuntimeError)` — `Path.resolve(strict=True)` reports
a SYMLINK LOOP as a `RuntimeError`, a subclass of neither `OSError` nor
`ValueError`, so a clause naming only `OSError` is open at exactly the loop
(openxFactory #1074, realized at PR #1107).

Exercised over the live tree: 33 rows load; the six identifiers the corpus
declares all resolve (three by bare name, three by address); `opensoft/
codexFactory` resolves as a FORMER address to `codeXfactory/codexFactory`;
`openxFactorie` does not resolve; 30 admissions report NOT RE-CHECKED, 9 NAMED,
0 GONE.

Refs #1087
Refs #1101

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
brettheap added a commit that referenced this pull request Sep 21, 2026
…87eb684

Copilot found the § 3 bullet naming 87eb684 as the realization head that
tasks.md's §§ 4.1-4.3 measurements were re-run at. 87eb684 is PR #1107's
intermediate merge of origin/main on that branch, not its actual head: the
realization head was bc9ebf9, merged to main as c22c4fc (already correct
at line 45's Green-at-the-realization-head row). The measurements were
genuinely taken at 87eb684 per tasks.md's own text, so that citation
stands; only the mislabel is corrected.

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Refs #1074
brettheap added a commit that referenced this pull request Sep 23, 2026
…d-plus-green realization evidence (#1083 → ebcdbc0, #1107 → c22c4fc, main green at 049d54a) (#1116)

Closes #1074 (the packet's § 5.3: the archive pull request closes the governing issue by a closing keyword written here and in no commit message). ARCHIVE of harden-path-escape-helpers-against-symlink-loops on merged-plus-green realization evidence: proposal PR #1083 → ebcdbc0, realization PR #1107 → c22c4fc, main pytest-suite green at 049d54a (run 35372664200). Promotes the two ADDED requirements (ten scenarios) onto release-realization; tasks.md §§ 4.4 and 5 ticked on that evidence. LANDED by MERGE COMMIT on Brett Heap's word of 2026-09-21 ~20:40Z, verbatim "archive it #1112 and #1116". Refs #1083, #1107.

Lane: openxfactory-5 (openXfactory-5)
Co-Authored-By: Claude Fable 5.1 <[email protected]>
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.

2 participants