diff --git a/AGENTS.md b/AGENTS.md index 58296eb..fd65249 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -25,7 +25,7 @@ hub.toml the Hub org this repository publishes to scripts/check.py a dataset directory's rules, its record, and whether its version is published scripts/push upload the cook's output and the card to the Hub's candidate branch; prints the manifest and `commit:` scripts/record < output write a record from the test's and push's output -scripts/promote after the merge, by whoever merged: tag the record's commit on the Hub, never moving a tag; delete the candidate branch +scripts/promote after the merge, by whoever merged: tag the record's commit on the Hub, never moving a tag; give main its files; delete the candidate branch tests/ unit tests of the scripts, with the Hub stubbed .github/workflows/datasets.yml check, on hosted runners ``` diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 84c2a67..20703f4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -96,7 +96,7 @@ A change after cooking changes the tree, so cook, push, and record again. A pros ## Versions -Any change under `datasets//` bumps `metadata.version`, prose included. A published tag is never moved, and `check` refuses a pull request whose tag is already on the Hub. Readers always name a version, never `main`. +Any change under `datasets//` bumps `metadata.version`, prose included. A published tag is never moved, and `check` refuses a pull request whose tag is already on the Hub. Readers always name a version, never `main`, which is a copy of the version last promoted, for the Hub's page. ## The pull request @@ -110,4 +110,4 @@ Any change under `datasets//` bumps `metadata.version`, prose included. A ghcr.io/brineylab/toolshed/datascience:1.0.0 python3 -I scripts/promote ``` - It tags the record's commit `v` on the Hub and deletes the candidate branch; its last line says what it did. It refuses a record that is not on `origin/main`. Run it from a full clone, not a `git worktree`, whose `.git` points outside the mounted directory. CI holds no Hub token, so nothing is published until someone runs it. + It tags the record's commit `v` on the Hub, gives `main` the version's files, and deletes the candidate branch; its last line says what it did. It refuses a record that is not on `origin/main`. Run it from a full clone, not a `git worktree`, whose `.git` points outside the mounted directory. CI holds no Hub token, so nothing is published until someone runs it. diff --git a/docs/DESIGN.md b/docs/DESIGN.md index 06be4c2..4729b55 100644 --- a/docs/DESIGN.md +++ b/docs/DESIGN.md @@ -1,6 +1,6 @@ # The datasets repository: Design -Status: approved 2026-11-04; revised 2026-11-05 by [superpowers/specs/2026-11-05-recipes-tools-and-jaffe-paired-design.md](superpowers/specs/2026-11-05-recipes-tools-and-jaffe-paired-design.md), so that a recipe is instructions any cook runs, names its tools, and runs in the toolshed's `datascience` (§2, §3, §4, §5, §6); revised 2026-11-06 so that whoever merges promotes with their own Hub token, and CI holds none, since a Hub token is a person's, not an org's (§3, §5). This is the repository's own copy of the design that lives in flyloft as [`docs/design/datasets.md`](https://github.com/brineylab/flyloft/blob/main/docs/design/datasets.md), with the lab's decisions on flyloft issue [#174](https://github.com/brineylab/flyloft/issues/174) (D1–D7, all option A) marked by number. §1 to §4 are this repository's; §5 summarizes flyloft's side, which that document settles. Calls made in writing that nobody has discussed are marked **(call)**. The toolshed's design ([brineylab/toolshed, docs/DESIGN.md](https://github.com/brineylab/toolshed/blob/main/docs/DESIGN.md)) is the sibling this one mirrors; where this document says "as the toolshed's", that is the reference. +Status: approved 2026-11-04; revised 2026-11-05 by [superpowers/specs/2026-11-05-recipes-tools-and-jaffe-paired-design.md](superpowers/specs/2026-11-05-recipes-tools-and-jaffe-paired-design.md), so that a recipe is instructions any cook runs, names its tools, and runs in the toolshed's `datascience` (§2, §3, §4, §5, §6); revised 2026-11-06 so that whoever merges promotes with their own Hub token, and CI holds none, since a Hub token is a person's, not an org's (§3, §5); revised 2026-11-10 so that promoting gives the Hub's `main` the version's files, since the Hub's page and viewer show `main`, which was empty (§3). This is the repository's own copy of the design that lives in flyloft as [`docs/design/datasets.md`](https://github.com/brineylab/flyloft/blob/main/docs/design/datasets.md), with the lab's decisions on flyloft issue [#174](https://github.com/brineylab/flyloft/issues/174) (D1–D7, all option A) marked by number. §1 to §4 are this repository's; §5 summarizes flyloft's side, which that document settles. Calls made in writing that nobody has discussed are marked **(call)**. The toolshed's design ([brineylab/toolshed, docs/DESIGN.md](https://github.com/brineylab/toolshed/blob/main/docs/DESIGN.md)) is the sibling this one mirrors; where this document says "as the toolshed's", that is the reference. ## 1. Scenario @@ -63,15 +63,15 @@ results//.txt the record of the candidate's test: the Hub commi scripts/check.py a dataset directory's rules, its record, and whether its version is published scripts/push upload the cook's output and the card to the Hub on the candidate branch; prints the manifest and the commit scripts/record a record from the test's and the push's output, for any cook -scripts/promote run by whoever merges: tag the merged record's commit as the version on the Hub; delete the candidate branch +scripts/promote run by whoever merges: tag the merged record's commit as the version on the Hub; give main its files; delete the candidate branch .github/workflows/datasets.yml check ``` -**Versions.** `metadata.version` is the Hub tag, `v` on `/`, with the org from `hub.toml`, so a fork with its own org is its own catalogue and store with one edit. A published tag is never moved: any change under `datasets//` bumps the version, prose included, and CI refuses a pull request whose tag is already on the Hub. Agents and flyloft always name a version, never `main`. +**Versions.** `metadata.version` is the Hub tag, `v` on `/`, with the org from `hub.toml`, so a fork with its own org is its own catalogue and store with one edit. A published tag is never moved: any change under `datasets//` bumps the version, prose included, and CI refuses a pull request whose tag is already on the Hub. Agents and flyloft always name a version, never `main`. `main` is for people browsing the Hub: a copy of the version last promoted, one commit per promote with the version's files, not the tagged commit itself, since the Hub moves a branch only by a commit. **The Hub** is the store (D1). One dataset repository per dataset, public, created by the first push when it does not exist. The Hub gives what the toolshed's registry gives and more: every commit immutable, a tag per version, every file's sha256, hosting, a dataset viewer, and a download-and-cache library every agent already knows. A dataset built from public data is public from the start, which is also where reviewers look when the lab publishes. A dataset the lab could not make public is the exception, handled when it arrives (a private repository and a read token), not designed for now. A few hundred GB per dataset, the largest foreseen, is within the Hub's guidance (no per-repository cap for public repositories; files under 200 GB, parquet preferred, under 100k files). Free organizations get best-effort public storage beyond the first gigabytes, so before plan A's large dataset the lab confirms its Hub plan holds what it will publish. -**The candidate** is the Hub commit a pull request proposes to publish: the head of the branch `candidate-` on the dataset's Hub repository, `` being git's hash of the committed `datasets//recipe/` directory, so the branch names the inputs it was built from. The scripts compute it from the files, not from `.git`, so `record` and `check` need no checkout **(call)**; `push` needs one, to prove the files are the commit's. The skill is not in the tree: a prose change does not change the bytes. **Building is the cook's.** Whoever cooks a recipe runs it, and its test, where the dataset will be built, into an output directory of their choosing. `scripts/push ` refuses when `datasets//` has uncommitted or ignored changes, or when git cannot say, so the candidate is named by the committed recipe's tree; it uploads the directory to the candidate branch, writes the card as a commit on it, and prints the file manifest with sizes and sha256 and then the head commit on a tagged `commit:` line, so `scripts/record` reads everything it needs from that output and nothing on the flyloft host needs the Hub library **(call)**; the Hub skips every file it already holds, so a second push of the same output moves prose only. Then `scripts/record` writes **the record**, `results//.txt`: the Hub repository, the branch and its head commit, the recipe tree, the parameters, the tools, where it ran, the time, the files with their sizes and sha256, the test's output, and the exit code. The record lives outside `datasets//`, so committing it leaves the candidate alone. A person cooks under `srun` in the recipe's tool image on a cluster, or with `podman` on a laptop for a small one, as `CONTRIBUTING.md` writes out; flyloft cooks as its campaign decides (§5). CI never runs a recipe or pulls a dataset. +**The candidate** is the Hub commit a pull request proposes to publish: the head of the branch `candidate-` on the dataset's Hub repository, `` being git's hash of the committed `datasets//recipe/` directory, so the branch names the inputs it was built from. The scripts compute it from the files, not from `.git`, so `record` and `check` need no checkout **(call)**; `push` needs one, to prove the files are the commit's. The skill is not in the tree: a prose change does not change the bytes. **Building is the cook's.** Whoever cooks a recipe runs it, and its test, where the dataset will be built, into an output directory of their choosing. `scripts/push ` refuses when `datasets//` has uncommitted or ignored changes, or when git cannot say, so the candidate is named by the committed recipe's tree; it uploads the directory to the candidate branch, which starts from `main`, deleting what the output lacks, writes the card as a commit on it, and prints the file manifest with sizes and sha256 and then the head commit on a tagged `commit:` line, so `scripts/record` reads everything it needs from that output and nothing on the flyloft host needs the Hub library **(call)**; the Hub skips every file it already holds, so a second push of the same output moves prose only. Then `scripts/record` writes **the record**, `results//.txt`: the Hub repository, the branch and its head commit, the recipe tree, the parameters, the tools, where it ran, the time, the files with their sizes and sha256, the test's output, and the exit code. The record lives outside `datasets//`, so committing it leaves the candidate alone. A person cooks under `srun` in the recipe's tool image on a cluster, or with `podman` on a laptop for a small one, as `CONTRIBUTING.md` writes out; flyloft cooks as its campaign decides (§5). CI never runs a recipe or pulls a dataset. **The card.** The Hub asks every large dataset for a card and serves its viewer from parquet. `scripts/push` writes `README.md` on the candidate branch from the skill: a header with the license and the name, then the skill's body. One source, two readers. @@ -79,7 +79,7 @@ scripts/promote run by whoever merges: tag the merged record's co - `check`, on every pull request, for the datasets it changes: the skill's frontmatter parses, its name is the directory's, each of its tools is in the toolshed's catalogue at that version (read from the shed's `main` by API); `recipe/build`, `recipe/params.toml`, and `recipe/test` exist; the version's tag is not on the Hub; the record exists for this version, names a commit on the Hub whose tree holds exactly the record's files with the record's sha256 (the Hub's file listing, no download), and shows exit code 0. -**Promoting** is the merger's, as pushing is the cook's: after the merge, whoever merged pulls `main` and runs `scripts/promote ` with their own `HF_TOKEN`, which tags the record's commit `v` on the Hub, never moving a tag that exists, and deletes the candidate branch; it refuses a record that is not on `origin/main`, so only a reviewed, merged record is published, and its last line says what it did. It runs from a full clone, since a worktree's `.git` points outside the directory a container mounts. A Hub token is a person's, so CI holds none; this is the one place the repository differs from the toolshed, whose CI promotes with GitHub's own token. +**Promoting** is the merger's, as pushing is the cook's: after the merge, whoever merged pulls `main` and runs `scripts/promote ` with their own `HF_TOKEN`, which tags the record's commit `v` on the Hub, never moving a tag that exists, gives `main` the version's files in one commit, copied on the Hub (none when `main` holds them already), and deletes the candidate branch; it refuses a record that is not on `origin/main`, so only a reviewed, merged record is published, and its last line says what it did. It runs from a full clone, since a worktree's `.git` points outside the directory a container mounts. A Hub token is a person's, so CI holds none; this is the one place the repository differs from the toolshed, whose CI promotes with GitHub's own token. **Guards.** Nothing a pull request contains runs on the lab's machines: CI runs the check script and its unit tests. Nothing that goes public holds a credential: `check.py` refuses a dataset directory or a record that holds the shape of one, in `scripts/push` before anything goes up, in `scripts/record` before anything is written, and in `check` as the backstop; `scripts/push` reads its token from `HF_TOKEN` and never prints it. The record's file list is the Hub's: what a version holds is what the record says, and `check` proves it. `main` requires `check` and no other approval: flyloft merges as the campaign's owner after its critic's review, and a person's pull request is merged by a member other than its builder. diff --git a/scripts/promote b/scripts/promote index 92bde1d..a78a9e7 100755 --- a/scripts/promote +++ b/scripts/promote @@ -1,11 +1,12 @@ #!/usr/bin/env -S python3 -I """scripts/promote : tag the commit results//.txt names as v on -/, then delete the candidate branch. Whoever merges the dataset's pull request runs it after -pulling main, with their own HF_TOKEN; a record that is not on origin/main as it is here is refused, so only +/, give main the version's files, then delete the candidate branch. Whoever merges the dataset's +pull request runs it after pulling main, with their own HF_TOKEN; a record that is not on origin/main as it is here is refused, so only a reviewed, merged record is published (a guard against mistakes, not misuse: an org token can tag the Hub directly). Run it from a full clone: a worktree's .git points outside a mounted directory. A tag is never moved: one already naming another commit exits 1; -one already naming the record's commit passes, so a promote run again after it succeeded passes. The last -line of stdout says what happened. +one already naming the record's commit passes, so a promote run again after it succeeded passes. main +becomes a copy of the version, one commit on it, so the Hub's page and viewer show the version last promoted; +the tag stays the version anyone names. The last line of stdout says what happened. """ import os import subprocess @@ -14,10 +15,21 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent)) import check # noqa: E402 -from huggingface_hub import HfApi # noqa: E402 +from huggingface_hub import CommitOperationCopy, CommitOperationDelete, HfApi # noqa: E402 from huggingface_hub.errors import HfHubHTTPError # noqa: E402 +def follow(api: HfApi, repo: str, tag: str, commit: str, main_head: str) -> None: + """main gets commit's files in one commit, copied on the Hub, or nothing when it holds them already.""" + def tree(rev): + return {f.path: f.blob_id for f in api.list_repo_tree(repo, revision=rev, recursive=True, repo_type="dataset") if hasattr(f, "blob_id")} + have, want = tree(main_head), tree(commit) + ops = [CommitOperationDelete(p) for p in have if p not in want] + ops += [CommitOperationCopy(src_path_in_repo=p, path_in_repo=p, src_revision=commit) for p, b in want.items() if have.get(p) != b] + if ops: + api.create_commit(repo, ops, commit_message=f"main <- {tag}", revision="main", parent_commit=main_head, repo_type="dataset") + + def main() -> int: if len(sys.argv) != 3: print("usage: scripts/promote ", file=sys.stderr) @@ -33,12 +45,14 @@ def main() -> int: rec = check.parse_record(check.ROOT / rel) repo, tag, commit = f"{check.hub_org()}/{name}", f"v{version}", rec["commit"] api = HfApi(token=os.environ["HF_TOKEN"]) - have = {t.name: t.target_commit for t in api.list_repo_refs(repo, repo_type="dataset").tags} + refs = api.list_repo_refs(repo, repo_type="dataset") + have = {t.name: t.target_commit for t in refs.tags} if tag in have and have[tag] != commit: print(f"{repo} {tag} already exists at {have[tag]}, not the record's {commit}; a published tag is never moved", file=sys.stderr) return 1 if tag not in have: api.create_tag(repo, tag=tag, revision=commit, repo_type="dataset") + follow(api, repo, tag, commit, next(b.target_commit for b in refs.branches if b.name == "main")) try: api.delete_branch(repo, branch=rec["branch"], repo_type="dataset") except HfHubHTTPError as e: diff --git a/scripts/push b/scripts/push index fe4809b..9b69fce 100755 --- a/scripts/push +++ b/scripts/push @@ -77,7 +77,8 @@ def main() -> int: # an earlier candidate of this tree: replaced, so the record's commit holds exactly this output api.delete_branch(repo, branch=branch, repo_type="dataset") api.create_branch(repo, branch=branch, revision="main", repo_type="dataset") - api.upload_folder(folder_path=out, repo_id=repo, repo_type="dataset", revision=branch, ignore_patterns=HIDDEN, + # the branch starts from main, which holds the last version promoted: what this output lacks goes + api.upload_folder(folder_path=out, repo_id=repo, repo_type="dataset", revision=branch, ignore_patterns=HIDDEN, delete_patterns="*", commit_message=f"{name} {meta['version']}: the output of recipe tree {tree}") head = api.upload_file(path_or_fileobj=card(dataset / "SKILL.md").encode(), path_in_repo="README.md", repo_id=repo, repo_type="dataset", revision=branch, commit_message=f"{name} {meta['version']}: the card") diff --git a/tests/stubs/huggingface_hub/__init__.py b/tests/stubs/huggingface_hub/__init__.py index 7e33744..6f78252 100644 --- a/tests/stubs/huggingface_hub/__init__.py +++ b/tests/stubs/huggingface_hub/__init__.py @@ -1,9 +1,9 @@ """A stand-in for huggingface_hub: an HfApi whose Hub is a JSON file, $FAKE_HUB, so a test reads what a script did. The state: repos, branches (name to commit), tags (name to commit), files (path to text, the card's), -uploaded (the paths upload_folder sent), and calls, in order. +uploaded (the paths upload_folder sent), trees (commit to {path: blob id}; a commit it lacks holds nothing), and calls, in order. """ -import fnmatch, json, os, uuid +import fnmatch, hashlib, json, os, uuid from pathlib import Path from huggingface_hub.errors import HfHubHTTPError @@ -21,6 +21,24 @@ def __init__(self, branches, tags): self.branches = [GitRefInfo(n, f"refs/heads/{n}", c) for n, c in branches.items()] self.tags = [GitRefInfo(n, f"refs/tags/{n}", c) for n, c in tags.items()] +class RepoFile: + def __init__(self, path, blob_id): self.path, self.blob_id = path, blob_id + +class CommitOperationDelete: + def __init__(self, path_in_repo): self.path_in_repo = path_in_repo + +class CommitOperationCopy: + def __init__(self, src_path_in_repo, path_in_repo, src_revision=None): + self.src_path_in_repo, self.path_in_repo, self.src_revision = src_path_in_repo, path_in_repo, src_revision + +def _commit(s, branch, tree): + s["branches"][branch] = oid = uuid.uuid4().hex + "0" * 8 + s["trees"][oid] = tree + return CommitInfo(oid) + +def _tree(s, rev): + return dict(s["trees"].get(s["branches"].get(rev) or s["tags"].get(rev) or rev, {})) + class HfApi: def __init__(self, token=None): self.token, self.path = token, Path(os.environ["FAKE_HUB"]) @@ -28,7 +46,7 @@ def __init__(self, token=None): def _change(self, call, f=None): s = json.loads(self.path.read_text()) if self.path.exists() else {} for k in ("repos", "calls", "uploaded"): s.setdefault(k, []) - for k in ("branches", "tags", "files"): s.setdefault(k, {}) + for k in ("branches", "tags", "files", "trees"): s.setdefault(k, {}) s["calls"].append(call) try: return f(s) if f else None @@ -48,20 +66,21 @@ def f(s): def create_branch(self, repo_id, *, branch, revision=None, repo_type=None, **kw): self._change(["create_branch", branch], lambda s: s["branches"].__setitem__(branch, s["branches"].get(revision or "main", "0" * 40))) - def upload_folder(self, *, repo_id, folder_path, revision=None, ignore_patterns=None, **kw): + def upload_folder(self, *, repo_id, folder_path, revision=None, ignore_patterns=None, delete_patterns=None, **kw): def f(s): root = Path(folder_path) paths = sorted(str(p.relative_to(root)) for p in root.rglob("*") if p.is_file()) s["uploaded"] = [p for p in paths if not any(fnmatch.fnmatch(p, pat) for pat in ignore_patterns or [])] - s["branches"][revision] = oid = uuid.uuid4().hex + "0" * 8 - return CommitInfo(oid) + tree = {p: b for p, b in _tree(s, revision).items() # as the Hub's: .gitattributes is never deleted + if p == ".gitattributes" or not any(fnmatch.fnmatch(p, pat) for pat in delete_patterns or [])} + tree.update({p: hashlib.sha1((root / p).read_bytes()).hexdigest() for p in s["uploaded"]}) + return _commit(s, revision, tree) return self._change(["upload_folder", revision], f) def upload_file(self, *, path_or_fileobj, path_in_repo, repo_id, revision=None, **kw): def f(s): - s["files"][path_in_repo] = path_or_fileobj.decode() if isinstance(path_or_fileobj, bytes) else Path(path_or_fileobj).read_text() - s["branches"][revision] = oid = uuid.uuid4().hex + "0" * 8 - return CommitInfo(oid) + s["files"][path_in_repo] = text = path_or_fileobj.decode() if isinstance(path_or_fileobj, bytes) else Path(path_or_fileobj).read_text() + return _commit(s, revision, {**_tree(s, revision), path_in_repo: hashlib.sha1(text.encode()).hexdigest()}) return self._change(["upload_file", path_in_repo], f) def list_repo_refs(self, repo_id, *, repo_type=None, **kw): @@ -73,3 +92,19 @@ def f(s): raise HfHubHTTPError(f"409 Conflict: tag {tag} already exists", response=Response(409)) s["tags"][tag] = revision self._change(["create_tag", tag], f) + + def list_repo_tree(self, repo_id, *, revision=None, recursive=False, repo_type=None, **kw): + return self._change(["list_repo_tree", revision], lambda s: [RepoFile(p, b) for p, b in sorted(_tree(s, revision).items())]) + + def create_commit(self, repo_id, operations, *, commit_message, revision=None, parent_commit=None, repo_type=None, **kw): + def f(s): + if parent_commit and s["branches"].get(revision) != parent_commit: + raise HfHubHTTPError(f"412 Precondition Failed: {revision} is not at {parent_commit}", response=Response(412)) + tree = _tree(s, revision) + for op in operations: + if isinstance(op, CommitOperationDelete): + del tree[op.path_in_repo] + else: + tree[op.path_in_repo] = _tree(s, op.src_revision)[op.src_path_in_repo] + return _commit(s, revision, tree) + return self._change(["create_commit", revision], f) diff --git a/tests/test_push_promote.py b/tests/test_push_promote.py index 7ecbb7a..1d94811 100644 --- a/tests/test_push_promote.py +++ b/tests/test_push_promote.py @@ -46,6 +46,13 @@ def test_push_creates_the_repo_replaces_the_candidate_and_prints_the_manifest(se self.assertEqual(s["uploaded"], ["eval.txt", "train.txt"]) # not .work/ self.assertIn(["upload_file", "README.md"], s["calls"]); self.assertNotIn("hf_test", r.stdout + r.stderr) + def test_push_over_a_published_version_holds_only_the_new_output(self): + # main holds the last version promoted, and a candidate branches from it + self.hub.write_text(json.dumps({"branches": {"main": "m" * 40}, "trees": {"m" * 40: {".gitattributes": "g", "old.parquet": "o", "README.md": "r"}}})) + self.assertEqual(self.run_script("scripts/push", "tiny", self.out).returncode, 0) + s = self.state() + self.assertEqual(sorted(s["trees"][s["branches"][self.branch]]), [".gitattributes", "README.md", "eval.txt", "train.txt"]) + def test_push_of_a_new_candidate_creates_its_branch_without_deleting_one(self): self.assertEqual(self.run_script("scripts/push", "tiny", self.out).returncode, 0) self.assertEqual([c[0] for c in self.state()["calls"][:3]], ["create_repo", "list_repo_refs", "create_branch"]) @@ -137,6 +144,17 @@ def test_promote_tags_the_records_commit_and_deletes_the_branch(self): self.assertEqual(s["tags"]["v1.0.0"], "c" * 40); self.assertNotIn(self.branch, s["branches"]) self.assertEqual(r.stdout.splitlines()[-1], f"promoted: {ORG}/tiny v1.0.0 at {'c' * 40}") + def test_promote_gives_main_the_versions_files(self): + trees = {"m" * 40: {".gitattributes": "g", "old.parquet": "o", "README.md": "r0"}, + "c" * 40: {".gitattributes": "g", "eval.txt": "e", "README.md": "r1"}} + self.hub.write_text(json.dumps({"branches": {"main": "m" * 40, self.branch: "c" * 40}, "trees": trees})) + self.record("c" * 40) + r = self.run_script("scripts/promote", "tiny", "1.0.0") + self.assertEqual(r.returncode, 0, r.stderr) + s = self.state() + self.assertEqual(s["trees"][s["branches"]["main"]], trees["c" * 40]); self.assertEqual(s["tags"]["v1.0.0"], "c" * 40) + self.assertEqual(r.stdout.splitlines()[-1], f"promoted: {ORG}/tiny v1.0.0 at {'c' * 40}") + def test_promote_never_moves_an_existing_tag(self): self.hub.write_text(json.dumps({"branches": {self.branch: "c" * 40}, "tags": {"v1.0.0": "x" * 40}})) self.record("c" * 40) @@ -145,10 +163,20 @@ def test_promote_never_moves_an_existing_tag(self): self.assertEqual(self.state()["tags"]["v1.0.0"], "x" * 40); self.assertIn(self.branch, self.state()["branches"]) def test_promote_run_again_after_it_succeeded_passes(self): - self.hub.write_text(json.dumps({"tags": {"v1.0.0": "c" * 40}})) + trees = {"m" * 40: {"eval.txt": "e"}, "c" * 40: {"eval.txt": "e"}} + self.hub.write_text(json.dumps({"branches": {"main": "m" * 40}, "tags": {"v1.0.0": "c" * 40}, "trees": trees})) self.record("c" * 40) r = self.run_script("scripts/promote", "tiny", "1.0.0") self.assertEqual(r.returncode, 0, r.stderr); self.assertIn("already promoted", r.stdout) + self.assertEqual(self.state()["branches"]["main"], "m" * 40) # main already held the version: no commit + + def test_promote_of_a_version_published_before_main_followed_moves_main(self): + trees = {"m" * 40: {".gitattributes": "g"}, "c" * 40: {".gitattributes": "g", "eval.txt": "e"}} + self.hub.write_text(json.dumps({"branches": {"main": "m" * 40}, "tags": {"v1.0.0": "c" * 40}, "trees": trees})) + self.record("c" * 40) + r = self.run_script("scripts/promote", "tiny", "1.0.0") + self.assertEqual(r.returncode, 0, r.stderr) + s = self.state(); self.assertEqual(s["trees"][s["branches"]["main"]], trees["c" * 40]) if __name__ == "__main__": unittest.main()