Skip to content

feat(migrate): tfmgr migrate plan, apply and verify, and the legacy gate (M301) - #27

Merged
oesteban merged 4 commits into
masterfrom
feat/migrate-apply
Dec 6, 2026
Merged

oesteban merged 4 commits into
masterfrom
feat/migrate-apply

Conversation

@oesteban

@oesteban oesteban commented Dec 5, 2026 •

Copy link
Copy Markdown
Member

Summary

Stacked on #26 (base feat/migrate-atlases). WP4 PR 6: the commands that turn a plan into a template's pull request.

tfmgr migrate plan (-t tpl-X | --all) --source ZIP|CHECKOUT|ARCHIVE -o OUT
  plan_template              + M301: simulate the legacy skeleton build (blocking)
  OUT/tpl-X/plan.json        everything apply reads (tfmanager.migration-plan/1)
           /plan.md          the complete plan, with diffs, for review
           /pr.md            the template PR's body (at most 65,536 characters)
           /renames.tsv
  exit 0 ready, 1 blocked, 2 error

tfmgr migrate apply PLAN CHECKOUT [--branch] [--dry-run]
  refuse   blocked plan, checkout not the plan's base (lists what differs), dirty
           worktree, adjusted/ branch, unlocked annexed file, existing branch
  build    temporary index, HEAD and worktree untouched
           commit 1 names:    same mode and blob (annex keys kept), rename rows
           commit 2 metadata: hash-object --no-filters, .gitattributes, n/a rows
           a commit that would change nothing is left out (a re-plan once the README
           is written gets one commit); a plan that changes nothing is refused
  check    both fingerprints, annex keys, only planned paths, predicted validation
  branch   update-ref (only if absent), switch, clean worktree; else roll back
  never pushes; --dry-run uses a temporary object store

tfmgr migrate verify PLAN CHECKOUT [--ref REF]     e.g. after a rebase
tfmanager/migrate/
├── legacy.py   # M301: the rule of build-skeletons.py (templateflow/templateflow#219, merged)
├── report.py   # plan.json, plan.md, pr.md, summary.md
└── apply.py    # apply and verify

Plan options: --date, --authored DIR (DIR/tpl-<label>/<path>), --headers TSV and --labels DIR (added to the shipped facts), --legacy-skeleton ZIP (exact names for M301; otherwise the gate checks every name the skeleton may list: the template's files and the old paths of its rows), and --config FILE. plan.json records the sha256 of every input, and each commit carries a Migration-Plan: sha256:... trailer.

Evidence

Archive: tfmgr migrate plan --all from the pinned v2 zip (45755e5), with --legacy-skeleton the pinned legacy zip (597b047):

  • 30 plans ready, 0 blocked, 6 strict-clean; no M301 (the tpl-MNI152NLin2009cAsym R22 merge passes with the rule of fix: keep every old name of a merged file in the legacy skeleton templateflow#219);
  • no M301 without --legacy-skeleton either. The names checked then include every name of the zip (test_archive_previous_names). Before fe29a21 (after Codex's review) they did not: the rows of tpl-MNI152NLin6Asym (11), tpl-MNIInfant (11) and tpl-fsaverage (1) were written after their renames, so the zip lists their targets, not their old paths. fe29a21's message leaves out tpl-MNIInfant;
  • the largest pr.md is fsaverage's (11,715 characters); the largest plan.json is NMT31Sym's (1.3 MB).

Pilot, ~/tmp/templateflow/tpl-MNI152NLin2009cSym at fc02ec3, planned from the checkout:

$ tfmgr migrate apply --dry-run .../tpl-MNI152NLin2009cSym/plan.json tpl-MNI152NLin2009cSym
ok: fingerprints of both commits are the plan's
ok: 2 renamed annexed files keep their keys
ok: 14 paths change, all planned
ok: the result validates as predicted
file names: 02c1beea9891b4751b5e5df81aa594240d999a21
metadata: 2a9562dd2ecfb2010c4023bfe7560b976cc2922c
Dry run: nothing was kept, and the repository is unchanged.

Its refs, HEAD, index, object counts and status are the same before and after, and the checkout's plan equals the zip's. The pilot's rows replay through templateflow/python-client tests/compat (clients 25.0.4, 25.1.2 and 26.0): 16 passed, 2 expected failures, once the harness handles text files (its first table with one; draft templateflow/python-client#167).

Tests:

  • test_migrate_apply.py (20), on a repository with annex links. It covers:
    • the happy path, with a merge, a frozen sidecar and .gitattributes;
    • a byte-identical dry run (dropping the temporary object store fails this test);
    • five refusals, plus blocked and tampered plans and an unlocked pointer;
    • rollback at three fault points, and verify;
    • a template planned again once its README is written: one metadata commit, then nothing to apply;
    • an Archive template planned from the zip and from a checkout, then applied;
    • one annex test: keys follow the renames, git annex fsck --fast passes, and the written files stay in git.
  • test_migrate_legacy.py (6, with a row written after its rename: a target that leaves without its own row is caught), test_archive_legacy_gate with the pinned legacy zip, and test_archive_previous_names.

Local CI (stacked PR, so no GitHub CI), a mirror of pythonapp.yml on a clean worktree of a scratch merge of the stack (this PR at fe29a21, #25 at 2f17daf, #28 at 69aa5c5; it merges without conflicts):

== test (3.13)   All checks passed!   417 passed
== test (3.15)   All checks passed!   417 passed
== annex (3.13)  git-annex 10.20220504   1 passed, 382 deselected
== build (3.13)  twine check PASSED (sdist, wheel)
tar.gz: 26.0.0rc5.dev42+g64c56fd6e
whl: 26.0.0rc5.dev42+g64c56fd6e

On this branch alone (fe29a21), 413 passed. The first commit (92cb4fb) passes on its own: 389 passed.

Merge Danger

Door: two-way

New commands and modules. Existing code changes in two places:

  • every plan gains the gate's findings (none fire on the Archive);
  • GitTree and load_checkout take an optional git environment.

The legacy skeleton fixture moves from test_archive.py to conftest.py.

Blast Radius: migration tooling

Nothing runs against a template until WP5, and apply never pushes. The new CI job annex installs git-annex from apt on ubuntu-26.04.

oesteban and others added 3 commits December 5, 2026 17:25
The superdataset builds the legacy skeleton from the templates and their
.renames.tsv, and stops when a name of the previous skeleton would vanish.
Every plan now simulates that build (the rule of
templateflow/templateflow#219, where several old names may share a target)
and blocks with M301 when its result would stop it. The previous names
come from the legacy zip when given, and are otherwise inferred from the
template and its rows.

Plan.names_rows and Plan.names_result describe the template after the
first of the two commits (the names), for apply.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
plan writes, for each template, plan.json (self-contained: what apply
reads), plan.md (the complete plan, for review), pr.md (the pull request
body, within GitHub's limit) and renames.tsv; summary.md with --all.

apply builds two commits with git plumbing in a temporary index (the
names, then the metadata), checks fingerprints, annex keys, the paths
changed and the predicted validation, and only then creates and checks
out the branch. It refuses stale, dirty, adjusted or unlocked checkouts
and existing branches, rolls back on failure, and never pushes. A dry run
keeps its objects in a temporary store. verify checks a commit against
the plan.

A CI job runs the apply tests with git-annex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A template that does not move to 2.0 in its first migration (most lack a
README) is planned again once its README is written. That plan renames
nothing, and apply made an empty first commit. Now each commit is built
only when its tree differs from its parent's, the commits are numbered
(1/2, 2/2) only when both are made, and a plan that changes nothing in the
checkout is refused. plan.json keeps each commit's part, title and body;
the headings of plan.md and pr.md no longer number the commits. The checks
say "1 path changes" and "1 renamed annexed file keeps its key".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 6, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-06T08:35:08.031303Z 8ec9bef Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8ec9bef49a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread tfmanager/migrate/legacy.py Resolved
…eton may list

previous_names dropped the targets of rename rows, taking them for new
names. The Archive has targets that the legacy skeleton lists: the rows
of tpl-MNI152NLin6Asym (11) and tpl-fsaverage (1) were written after
their renames, so the legacy zip lists their targets and not their old
paths. The inference missed those 11 + 1 names and added the 11 + 1 old
paths the zip does not list.

The names are now the template's files and the old paths of its rows: a
superset of the zip's (a test checks it on every Archive template), so
the gate never passes a result that the build would stop. On the
Archive, no plan gets M301 either way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from feat/migrate-atlases to master December 6, 2026 09:08
@oesteban
oesteban merged commit 0f0d6df into master Dec 6, 2026
@oesteban
oesteban deleted the feat/migrate-apply branch December 6, 2026 09:09
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.

1 participant