Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions .github/workflows/compat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Compatibility

# Released clients and this branch against an Archive before and after a renames table
# (tests/compat/README.md). Nightly, it catches changes in the Archive's skeleton
# builder and in the clients' dependencies. Replay a proposed table before merging it
# into a template with "Run workflow".

on:
push:
branches: [master, 'maint/*']
pull_request:
schedule:
- cron: '23 3 * * *'
workflow_dispatch:
inputs:
renames-url:
description: >-
HTTPS URL of a renames table to replay: rows of the root renames.tsv, or a
template's .renames.tsv (set the template). Empty runs the sample table.
required: false
default: ''
template:
description: Template of a .renames.tsv fragment (tpl-X); empty for root rows
required: false
default: ''
archive-ref:
description: Ref of templateflow/templateflow whose build-skeletons.py builds the Archive
required: false
default: master

permissions:
contents: read

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
compat:
name: Python ${{ matrix.python-version }}
runs-on: ubuntu-26.04
timeout-minutes: 45
strategy:
fail-fast: false
matrix:
# SPEC 0
python-version: ['3.13', '3.14', '3.15']
env:
TEMPLATEFLOW_COMPAT_PYTHON: ${{ matrix.python-version }}
TEMPLATEFLOW_ARCHIVE_SCRIPTS: ${{ github.workspace }}/archive/.github/scripts
steps:
- uses: actions/checkout@v7
with:
fetch-depth: 0 # hatch-vcs versions the client under test
persist-credentials: false
- uses: actions/checkout@v7
with:
repository: templateflow/templateflow
ref: ${{ inputs.archive-ref || 'master' }}
path: archive
sparse-checkout: .github/scripts
persist-credentials: false
- uses: astral-sh/setup-uv@v10.4.1
- name: Fetch the table to replay
if: inputs.renames-url != ''
env:
URL: ${{ inputs.renames-url }}
TEMPLATE: ${{ inputs.template }}
run: |
curl -fsSL --proto '=https' --max-filesize 1048576 -o "$RUNNER_TEMP/renames.tsv" "$URL"
echo "TEMPLATEFLOW_COMPAT_RENAMES=$RUNNER_TEMP/renames.tsv" >> "$GITHUB_ENV"
if [ -n "$TEMPLATE" ]; then
echo "TEMPLATEFLOW_COMPAT_TEMPLATE=$TEMPLATE" >> "$GITHUB_ENV"
fi
cat "$RUNNER_TEMP/renames.tsv"
- name: Set up the test environment
run: |
uv venv --python "$TEMPLATEFLOW_COMPAT_PYTHON" "$RUNNER_TEMP/compat"
uv pip install --python "$RUNNER_TEMP/compat/bin/python" . pytest
- name: Run the compatibility matrix
run: >-
"$RUNNER_TEMP/compat/bin/python" -m pytest -o addopts="" -rxXs
--junitxml="$RUNNER_TEMP/compat.xml" tests/compat
- uses: actions/upload-artifact@v7
if: always()
with:
name: compat-python-${{ matrix.python-version }}
path: ${{ runner.temp }}/compat.xml
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ TemplateFlow 2.0 file names: the client reads the v2 skeleton and resolves old n
* FIX: ``get()`` skipped files when DataLad fetched several at once, and failed for
files without a stub in the home.
* FIX: Network errors other than connection errors no longer break skeleton updates.
* MAINT: A compatibility matrix (``tests/compat``, workflow *Compatibility*) runs the
released clients and this one against an Archive before and after a renames table,
in S3 and DataLad homes. It replays a proposed table before it is merged.

25.1.2 (March 11, 2026)
=======================
Expand Down
84 changes: 84 additions & 0 deletions tests/compat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Compatibility matrix

Released clients and this branch, run against a fixture Archive before and after a
renames table. It checks the promise of TemplateFlow 2.0: renaming files in the Archive
breaks no released client that reads it through S3.

## How it works

```text
test_compat.py (pytest, the branch installed)
├── archive.py the fixture Archive: names from the bundled v2 skeleton, made-up
│ content, annexed files as MD5E symlinks; skeletons built by the
│ real build-skeletons.py (templateflow/templateflow), before and
│ after the table
├── datalad_archive.py a one-template git-annex Archive for DataLad homes
├── server.py local S3 (404 answers as S3 sends them) and skeleton URLs
└── client processes one uv environment per client (25.0.4, 25.1.2, branch)
├── runtime/sitecustomize.py sends requests to server.py; no other network
└── runtime/scenario.py get / update / files, with the API all clients share
```

The server serves one state at a time:

| State | S3 | Skeleton URLs |
|---|---|---|
| `before` | every file, and the old names of the Archive's `renames.tsv` | built before the table |
| `after` | the table applied: new names, old names kept, purged names gone | rebuilt |
| `no-copies` (control) | `after` without the old names of the table | rebuilt |
| `v2-as-legacy` (control) | `after` | the v2 skeleton at the legacy URL |

## Scenarios

| Test | Expects |
|---|---|
| `test_pinned` | a client that never updates downloads every old name; purged names fail |
| `test_released_update` | after `update()`, released clients get one file per old name |
| `test_branch_update` | the branch finds old queries (with a `FutureWarning` when entities changed) and removed files |
| `test_shared_home` | a released client's home, used without and with `--migrate`; migration moves downloads, nothing is downloaded again |
| `test_branch_datalad` | in DataLad homes, the branch resolves old names after `datalad update` |
| `test_released_datalad` | released clients in DataLad homes keep renames that preserve entities |
| `test_released_datalad_break` | expected failure (strict): released clients in DataLad homes lose old names that changed entities, and removed files. Accepted for 2.0 and announced with 26.0 |
| `*_control_*` | the matrix notices a missing S3 copy, and the v2 skeleton served at the legacy URL |

Released clients 25.0 and older save S3's error body as the file when a key is missing,
and never download it again; the tests count that as a miss.

## Running it

```bash
git clone --depth 1 --filter=blob:none --sparse https://github.com/templateflow/templateflow
git -C templateflow sparse-checkout set .github/scripts
pip install . pytest
TEMPLATEFLOW_ARCHIVE_SCRIPTS=$PWD/templateflow/.github/scripts \
python -m pytest -o addopts="" -rxXs tests/compat
```

It needs `uv` and `git`; the DataLad environments install `datalad` and the
`git-annex` wheel. Client processes never see the `TEMPLATEFLOW_HOME` of your
environment, and `scenario.py` refuses any home the matrix did not make.

| Variable | Default | Meaning |
|---|---|---|
| `TEMPLATEFLOW_ARCHIVE_SCRIPTS` | (required) | `.github/scripts` of templateflow/templateflow |
| `TEMPLATEFLOW_COMPAT_RENAMES` | `sample-renames.tsv` | the table to replay |
| `TEMPLATEFLOW_COMPAT_TEMPLATE` | | with a template's `.renames.tsv`, its name (`tpl-X`) |
| `TEMPLATEFLOW_COMPAT_CLIENTS` | `25.0.4 25.1.2 branch` | clients to run |
| `TEMPLATEFLOW_COMPAT_PYTHON` | `3.13` | Python of the client environments |

## Replaying a table

Before merging a template PR with a `.renames.tsv`, run the *Compatibility* workflow
with its raw URL and the template's name, or locally:

```bash
TEMPLATEFLOW_COMPAT_RENAMES=path/to/.renames.tsv TEMPLATEFLOW_COMPAT_TEMPLATE=tpl-X \
TEMPLATEFLOW_ARCHIVE_SCRIPTS=... python -m pytest -o addopts="" -rxXs tests/compat
```

The table's old names must be in the skeleton bundled with this branch. Tests a table
does not exercise (no removed files, say) are skipped.

The sample table renames `tpl-MNI152Lin` files as the 2.0 rules do: `res-01` to
`res-1` (entities kept), entity order with `res` (kept), `PET` to `pet` and
`desc-head` to `label-head` (entities changed), one removed file (`n/a`) and one purged.
Loading