Skip to content

Commit 96202c3

Browse files
committed
chore(hack): add the history extraction and verification scripts
paths.txt maps the SDK's core paths (python/openshell, python/navigator, the SDK tests, the root pyproject.toml, and the proto and wheel scripts) to this repository's layout. verify-tree.sh rebuilds the expected tree from core at the freeze tag with the same rules and compares tree hashes. Signed-off-by: Piotr Mlocek <pmlocek@nvidia.com>
1 parent 82b8e14 commit 96202c3

6 files changed

Lines changed: 211 additions & 0 deletions

File tree

‎hack/migration/FREEZE‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
sha=5d25211b25a8fc887e8d5c606d57d6ab22f1d76c
2+
tag=v0.1.7

‎hack/migration/README.md‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# History import
2+
3+
These files record how the Python SDK history was extracted from
4+
NVIDIA/OpenShell. They follow the Go SDK's import (ai-openshell/sdk-go,
5+
`hack/migration`), adapted to a package that is not one subdirectory in core.
6+
7+
| File | Purpose |
8+
|------|---------|
9+
| `FREEZE` | The core commit the import was taken at. |
10+
| `paths.txt` | `git filter-repo --paths-from-file` rules: which core paths to keep and where they land here. |
11+
| `message-rules.txt` | Rewrites bare `#N` in commit messages to `NVIDIA/OpenShell#N`. |
12+
| `extract-history.sh` | Produces the filtered repository from a core clone at the freeze commit. |
13+
| `verify-tree.sh` | Checks the filtered tip against core and prints commit, author, and sign-off counts. |
14+
15+
## Why not `--subdirectory-filter`
16+
17+
The Go SDK lived entirely under `sdk/go`. The Python SDK spans several core
18+
paths:
19+
20+
- `python/openshell/`, and `python/navigator/` before the package was renamed
21+
- SDK tests at `python/*_test.py`
22+
- the repository-root `pyproject.toml`, which is the SDK's package definition
23+
- `tasks/scripts/generate_python_proto.py` and `verify-python-wheel.py`
24+
25+
`paths.txt` selects those paths with filters and maps them with renames.
26+
Filters must come before renames, because filter-repo matches a filter against
27+
the path as renamed so far.
28+
29+
Tests that exercise core packaging, release tooling, or gateway config stay in
30+
core (`release_formula`, `rpm_gateway_config_migration`,
31+
`gateway_config_fixture`, `gateway_schema_v2_*`, `release_tooling`).
32+
33+
The `navigator` package keeps its tests beside it. Moving them to `tests/` too
34+
would put a delete and an add of the same path in the commit that renamed the
35+
package.
36+
37+
## Reproduce
38+
39+
```shell
40+
git clone https://github.com/NVIDIA/OpenShell core
41+
hack/migration/extract-history.sh core "$(sed -n 's/^sha=//p' hack/migration/FREEZE)" /tmp/sdk-python-history
42+
hack/migration/verify-tree.sh core "$(sed -n 's/^sha=//p' hack/migration/FREEZE)" /tmp/sdk-python-history
43+
```
44+
45+
Both scripts need `git-filter-repo` (`uv tool install git-filter-repo`).

‎hack/migration/extract-history.sh‎

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env bash
2+
# extract-history.sh: filter the Python SDK history out of a NVIDIA/OpenShell
3+
# clone at the freeze commit.
4+
#
5+
# Usage: extract-history.sh <core-clone> <freeze-sha> <out-dir>
6+
#
7+
# <out-dir> must not exist. Afterwards it is a standalone repository with one
8+
# branch, main, whose tip tree is the paths in paths.txt at <freeze-sha>,
9+
# mapped to this repository's layout. Every commit that touched those paths
10+
# keeps its author, date, and trailers. Bare #N references in commit messages
11+
# become NVIDIA/OpenShell#N (see message-rules.txt).
12+
# The last output line is the resulting HEAD.
13+
set -euo pipefail
14+
15+
if [ $# -ne 3 ]; then
16+
echo "usage: $0 <core-clone> <freeze-sha> <out-dir>" >&2
17+
exit 2
18+
fi
19+
20+
core=$1
21+
freeze=$2
22+
out=$3
23+
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
24+
rules="$here/message-rules.txt"
25+
paths="$here/paths.txt"
26+
27+
command -v git-filter-repo >/dev/null 2>&1 || {
28+
echo "ERROR: git-filter-repo is not installed" >&2
29+
exit 1
30+
}
31+
for f in "$rules" "$paths"; do
32+
[ -f "$f" ] || {
33+
echo "ERROR: $f is missing" >&2
34+
exit 1
35+
}
36+
done
37+
[ ! -e "$out" ] || {
38+
echo "ERROR: $out exists; pass a path that does not exist yet" >&2
39+
exit 1
40+
}
41+
git -C "$core" cat-file -e "${freeze}^{commit}" 2>/dev/null || {
42+
echo "ERROR: $freeze is not a commit in $core" >&2
43+
exit 1
44+
}
45+
freeze=$(git -C "$core" rev-parse "${freeze}^{commit}")
46+
47+
# A real copy (no hardlinks, no tags, no checkout) that filter-repo may rewrite.
48+
git clone --quiet --no-local --no-checkout --no-tags "$core" "$out"
49+
# A freeze commit that only a remote-tracking ref reaches is not cloned.
50+
git -C "$out" cat-file -e "${freeze}^{commit}" 2>/dev/null ||
51+
git -C "$out" fetch --quiet --no-tags "$core" "$freeze" || {
52+
echo "ERROR: $freeze is not reachable from a branch of $core" >&2
53+
exit 1
54+
}
55+
git -C "$out" remote remove origin
56+
57+
# Keep exactly one branch, main, at the freeze commit.
58+
git -C "$out" branch --force main "$freeze"
59+
git -C "$out" symbolic-ref HEAD refs/heads/main
60+
git -C "$out" for-each-ref --format='%(refname)' refs/heads |
61+
grep -v '^refs/heads/main$' |
62+
while read -r ref; do git -C "$out" update-ref -d "$ref"; done
63+
git -C "$out" checkout --quiet main
64+
65+
# --force: <out-dir> is a throwaway copy without an origin, so filter-repo's
66+
# fresh-clone check does not apply.
67+
# The global and system config are hidden because filter-repo parses
68+
# `git config --list` and chokes on keys without a value.
69+
GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null \
70+
git -C "$out" filter-repo --force --quiet \
71+
--paths-from-file "$paths" \
72+
--replace-message "$rules"
73+
74+
echo "commits: $(git -C "$out" rev-list --count HEAD)"
75+
echo "authors: $(git -C "$out" log --format='%an <%ae>' | sort -u | wc -l | tr -d ' ')"
76+
echo "tree: $(git -C "$out" rev-parse 'HEAD^{tree}')"
77+
git -C "$out" rev-parse HEAD

‎hack/migration/message-rules.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
regex:(^|[^A-Za-z0-9/#])#([0-9]+)==>\1NVIDIA/OpenShell#\2

‎hack/migration/paths.txt‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# git filter-repo --paths-from-file rules for the Python SDK.
2+
#
3+
# Filters (lines without ==>) select what history keeps and match the core
4+
# path. Renames (lines with ==>) run in order and map core paths to this
5+
# repository's layout. Filters must stay above renames: filter-repo checks a
6+
# filter against the path as renamed so far.
7+
8+
# The package, under its current and its pre-rename (navigator) name. Tests
9+
# that exercise core packaging, release tooling, or gateway config stay in
10+
# core and are left out.
11+
regex:^python/(openshell|navigator)/(?!(release_formula|rpm_gateway_config_migration|gateway_config_fixture|gateway_schema_v2_[a-z_]+)_test\.py$)
12+
# SDK tests at the python/ root. release_tooling_test.py covers core's
13+
# release.py and stays in core.
14+
regex:^python/(credential_driver_proto|generate_python_proto|grpc_transport|grpc_typing|wheel_verifier)_test\.py$
15+
# Package metadata and the build scripts the SDK owns.
16+
pyproject.toml
17+
tasks/scripts/generate_python_proto.py
18+
tasks/scripts/verify-python-wheel.py
19+
20+
# Tests move to tests/, the package to src/, scripts to scripts/. The
21+
# navigator package keeps its tests beside it: moving them too would put a
22+
# delete and an add of the same tests/ path in the commit that renamed it.
23+
regex:^python/openshell/([^/]+_test\.py)$==>tests/\1
24+
regex:^python/([^/]+_test\.py)$==>tests/\1
25+
python/openshell/==>src/openshell/
26+
python/navigator/==>src/navigator/
27+
tasks/scripts/==>scripts/

‎hack/migration/verify-tree.sh‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
# verify-tree.sh: check an extracted history against core at the freeze commit.
3+
#
4+
# Usage: verify-tree.sh <core-clone> <freeze-sha> <extracted-repo-or-ref>
5+
#
6+
# The expected tree comes from applying paths.txt to a single commit holding
7+
# core's tree at <freeze-sha>, so the check reuses the extraction rules but
8+
# none of the history. It then prints commit, author, and sign-off counts
9+
# and fails on bare #N references left in commit messages.
10+
set -euo pipefail
11+
12+
if [ $# -ne 3 ]; then
13+
echo "usage: $0 <core-clone> <freeze-sha> <extracted-repo>" >&2
14+
exit 2
15+
fi
16+
17+
core=$1
18+
freeze=$2
19+
repo=$3
20+
here="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21+
paths="$here/paths.txt"
22+
work=$(mktemp -d)
23+
trap 'rm -rf "$work"' EXIT
24+
25+
freeze=$(git -C "$core" rev-parse "${freeze}^{commit}")
26+
27+
# Expected tree: core's freeze tree in a one-commit repository, filtered with
28+
# the same rules.
29+
git init --quiet "$work/expected"
30+
git -C "$core" archive "$freeze" | tar -x -C "$work/expected"
31+
git -C "$work/expected" add -A
32+
GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null \
33+
git -C "$work/expected" -c user.name=verify -c user.email=verify@invalid \
34+
commit --quiet -m freeze
35+
GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=/dev/null \
36+
git -C "$work/expected" filter-repo --force --quiet --paths-from-file "$paths"
37+
expected=$(git -C "$work/expected" rev-parse 'HEAD^{tree}')
38+
actual=$(git -C "$repo" rev-parse 'HEAD^{tree}')
39+
40+
echo "expected tree: $expected"
41+
echo "actual tree: $actual"
42+
echo "commits: $(git -C "$repo" rev-list --count HEAD)"
43+
echo "authors: $(git -C "$repo" log --format='%an <%ae>' | sort -u | wc -l | tr -d ' ')"
44+
echo "sign-offs: $(git -C "$repo" log --format=%B | grep -c '^Signed-off-by:' || true)"
45+
bare=$(git -C "$repo" log --format=%B | grep -cE '(^|[^A-Za-z0-9/#])#[0-9]+' || true)
46+
echo "bare #N refs: $bare"
47+
echo "files:"
48+
git -C "$repo" ls-tree -r --name-only HEAD | sed 's/^/ /'
49+
50+
[ "$expected" = "$actual" ] || {
51+
echo "FAIL: tree mismatch" >&2
52+
diff <(git -C "$work/expected" ls-tree -r HEAD) <(git -C "$repo" ls-tree -r HEAD) >&2 || true
53+
exit 1
54+
}
55+
[ "$bare" = 0 ] || {
56+
echo "FAIL: bare #N references remain" >&2
57+
exit 1
58+
}
59+
echo "OK"

0 commit comments

Comments
 (0)