CI / test (push) Canceled after 0s
Extract the duplicated `_pr/<n>` deleted-branch PR-head branch name into a single pure helper `refs.pr_head_branch(n)`, now the only definition. The git-mirror layer (mirror.py) and the REST/entity layer (issues.py) both call it instead of spelling the pattern, so the two can no longer diverge — editing one side previously broke the other silently and late (404/500 on PR create for deleted-branch PRs only). Behavior-preserving string round-trip. refs.py widens from "cross-reference rewriting" to "reference-namespace knowledge" (branch-name patterns + cross-ref rewriting), still pure stdlib. No new test — a shared symbol prevents divergence by construction (issue #3 testing decision); the deleted-branch round-trip stays covered by the existing phase test seam. Closes #3
4.4 KiB
4.4 KiB
Own the _pr/ deleted-branch PR-head contract (shared pr_head_branch helper in refs.py)
Date: 2026-08-11 Type: issue Reference: #3
Goal
Eliminate the duplicated _pr/<n> branch-name literal that the deleted-branch
PR survival feature rested on. The git-transport layer (mirror.py) created
refs/heads/_pr/<n>; the REST/entity layer (issues.py) referenced the same
branch as a PR's head when the source branch was gone. Both spelled
f"_pr/{n}" with no shared symbol binding them — editing one side silently
broke the other, and the failure was narrow and late (404/500 on PR create for
deleted-branch PRs only). Own the contract as one shared, importable helper so
the two cannot diverge.
What Was Done
- Added
pr_head_branch(n: int) -> strtorefs.py(returnsf"_pr/{n}"); pure, no I/O. The single source of truth for the_pr/<n>namespace. mirror.py(producer): addedfrom .refs import pr_head_branch; refspec nowf"{sha}:refs/heads/{pr_head_branch(n)}"(refspec syntax stays local).issues.py(consumer): addedfrom .refs import pr_head_branch; PR head nowpr_head_branch(item["number"])instead of the inline literal.- Widened
refs.py's module docstring from "cross-reference rewriting" to "reference-namespace knowledge" (branch-name patterns + cross-ref rewriting); still pure stdlib (reonly). - Docs closeout:
src/.../AGENTS.mdmodule-map (refs.py+issues.pyentries) andREADME.md"Pull-request heads" bullet now namerefs.pr_head_branchas the single source of truth.
Decisions & Rationale
| Decision | Rationale |
|---|---|
Free function, not a Migration method |
The producer (mirror.py, git layer) holds no Migration handle, so both layers reach a neutral pure module instead of one depending on the other's internals. |
House it in refs.py |
A branch-name pattern is reference-namespace knowledge; broadens refs.py coherently. Pure stdlib, so the git layer importing it drags in no REST coupling. |
| Shared kernel = bare branch name only | The producer prefixes refspec syntax (refs/heads/, the sha: source) locally — those are refspec concerns, not part of the shared contract. |
n stays int on both sides |
The mirror parses int(ref.split("/")[2]); the consumer reads the source PR number — no int/str bridge needed. |
| No change-specific test | A shared symbol prevents divergence by construction; a test asserting "the two literals agree" tests the absence of duplication (issue #3 testing decision). The deleted-branch round-trip stays covered by the existing phase test seam. |
Gotchas & Fixes
| Problem | Root Cause | Fix |
|---|---|---|
PRD claimed refs.py was "already imported" in issues.py |
It wasn't — issues.py imported .clients + .migration only (m.rewrite reaches refs via the Migration handle) |
Added from .refs import pr_head_branch to issues.py. Minimal deviation from the PRD; intent unchanged. |
First cut added a __main__ self-check assert pr_head_branch(42) == "_pr/42" |
That asserts "the literal agrees" — exactly the redundant test the spec's testing decision warns against, and a trivial one-liner under ponytail | Removed it after the fresh-context review fanout confirmed it was redundant. |
Files Changed
| File | Change Summary |
|---|---|
src/codeberg_to_gitea_migrator/refs.py |
Add pr_head_branch(n); widen module docstring to reference-namespace knowledge. |
src/codeberg_to_gitea_migrator/mirror.py |
Import + route the PR-head refspec through pr_head_branch. |
src/codeberg_to_gitea_migrator/issues.py |
Import + route the deleted-branch PR head through pr_head_branch. |
src/codeberg_to_gitea_migrator/AGENTS.md |
Module map: refs.py and issues.py entries note the shared symbol. |
README.md |
"Pull-request heads" bullet notes refs.pr_head_branch as the single source of truth. |
AGENTS.md (root) |
GitNexus symbol count auto-bump (434→444) from re-index. |
Open Items & Next Steps
- Untracked
CONTEXT.md— predates this session, not gitignored, but referenced byAGENTS.mdas the DOX "single-context" core doc. Track-vs-ignore intent undecided; left out of this commit intentionally. Not in #3's scope. - None for #3 itself — all 13 user stories met; behaviour unchanged.
Log written by write-log skill