From 4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7 Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 13:50:36 -0800 Subject: [PATCH 1/2] test(ci): record attestation fixture and metadata subprocess budgets RED: original 45 tests pass but launch 2,154 Git subprocesses in 186.506 s locally. Fixture isolation/no-spawn and single metadata read regressions fail before optimization. Refs #4896. --- ci/test_pr_attestation.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/ci/test_pr_attestation.py b/ci/test_pr_attestation.py index 4c01623159..0eb902cc65 100644 --- a/ci/test_pr_attestation.py +++ b/ci/test_pr_attestation.py @@ -957,6 +957,31 @@ def test_repository_policy_names_all_six_targets_with_explicit_freshness(self): self.assertIsNotNone(match) self.assertIn(f" {match[1]}: {{max-age-hours: 24}}", text) + def test_fixture_setup_reuses_objects_without_sharing_mutable_state(self): + other = type(self)("runTest") + try: + with patch.object(subprocess, "run", wraps=subprocess.run) as run: + other.setUp() + self.assertEqual(run.call_count, 0) + other.write("src/value.txt", "isolated\n") + other.facts.clear() + other.proof_reports.clear() + (other.root / ".git/shallow").write_text(other.head + "\n") + self.assertEqual((self.root / "src/value.txt").read_text(), "head\n") + self.assertTrue(self.facts) + self.assertTrue(self.proof_reports) + self.assertFalse((self.root / ".git/shallow").exists()) + self.assertTrue(self.evaluate()["trusted"]) + finally: + other.doCleanups() + + def test_commit_metadata_uses_one_git_read(self): + with patch.object(subprocess, "run", wraps=subprocess.run) as run: + commit = subject.Git(self.root).commit(self.head) + self.assertEqual(run.call_count, 1) + self.assertEqual((commit.sha, commit.tree, commit.parents), + (self.head, self.tree, (self.base,))) + if __name__ == "__main__": unittest.main() From 4c16a448af06815e5836aa0d6841d623d06b3bbf Mon Sep 17 00:00:00 2001 From: Zach Vorhies Date: Thu, 19 Nov 2026 13:55:10 -0800 Subject: [PATCH 2/2] ci: build attestation-verifier test fixtures once instead of per test Construct isolated copies of one real-object template; write fixture objects in process and reuse successful immutable Git reads. Batch production commit metadata into one Git query. Preserve all 45 original test bodies and their assertions. Refs #4896. Ci-Attestation: {"at":1795126715,"gate":"data/all/compatibility","host":"linux-x86_64","key":"","lane":"client-checks","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":339,"stamp":"94670f9b5e08d2fb7ddc2c28eebe58fc","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126715,"gate":"data/all/flatpak-manifest","host":"linux-x86_64","key":"","lane":"client-checks","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":339,"stamp":"65da1b88d8bc87f04bbe32752e2a3560","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126715,"gate":"data/all/qt-xml","host":"linux-x86_64","key":"","lane":"client-checks","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":339,"stamp":"64a58b4c32b3f3e62dd90a847e90f9b5","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126715,"gate":"data/all/services-schema","host":"linux-x86_64","key":"","lane":"client-checks","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":339,"stamp":"4b979e159f45825e2972b99782dc6237","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126352,"gate":"general/all/client-lint","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"671957504840b0c53ee88c0f6260dc6e","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126715,"gate":"python/all/self-test","host":"linux-x86_64","key":"","lane":"client-checks","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":339,"stamp":"633fae30b2ff88de5625fd6b95a8819e","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126358,"gate":"rust/aarch64-apple-darwin/client-clippy","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"1b4b804e509b70482241f755891d5605","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126360,"gate":"rust/aarch64-apple-darwin/client-dylint","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"22e0790913ba40688ce90372e144ce25","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126355,"gate":"rust/aarch64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"e01cd62afe179c6d1b04ef59f4f85b52","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126355,"gate":"rust/aarch64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"cdf09131a9ab802c0d8ba2dcaffc2674","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126353,"gate":"rust/aarch64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"186f949148b5b21bb4eb3ef8967ef63f","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126353,"gate":"rust/aarch64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"59b43d883b141f34955a79d849113157","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126357,"gate":"rust/x86_64-apple-darwin/client-clippy","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"f8fe050c0f7b0ccbd9d3eaab971f501b","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126357,"gate":"rust/x86_64-apple-darwin/client-dylint","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"9fdfbb20a5ffb10b91eeea577d1e21fc","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126354,"gate":"rust/x86_64-pc-windows-msvc/client-clippy","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"a436d1515f05a1be77ce4278d98c0293","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126355,"gate":"rust/x86_64-pc-windows-msvc/client-dylint","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"ddb109d1e399d3a102c4607f44c575b0","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126352,"gate":"rust/x86_64-unknown-linux-gnu/client-clippy","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"8ebd0bdacfc2d7f916032b08247970a1","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795126352,"gate":"rust/x86_64-unknown-linux-gnu/client-dylint","host":"linux-x86_64","key":"c59997cca264ff0efd43cd9cbeb49a5be661f27f44b47921a7f42b64312a92bc","lane":"client-lint","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":133,"stamp":"ed9857e87c2e1df5b09edc995b5dae47","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Ci-Attestation: {"at":1795128338,"gate":"rust/x86_64-unknown-linux-gnu/client-test","host":"linux-x86_64","key":"a08bf3f165984e0525be4c0ff929849a7b945a6200fd7f328a99d146eb362f25","lane":"client-test-x86_64-unknown-linux-gnu","parents":["4ff698d238e05c6e19fe439e8bd7c5947a7fe7f7"],"secs":1617,"stamp":"931917ed6ba1789d4c1da2979fc6487c","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958","v":1,"via":"run"} Client-Checks: {"checks":{"base":"fb7d018d535fabef94fc62230556ce620132f294","coverage":"all-tracked-applicable-files","diff":["ci/pr_attestation.py","ci/test_pr_attestation.py"],"head":"e968ff17d7ac3b0d89df4d0672a36fde0caee457","tools":{"orchestrator-python":"3.14.7 (main, Aug 14 2026, 15:35:28) [Clang 22.1.3 ]","schema-dependencies":"3.14.7 (main, Aug 14 2026, 15:35:28) [Clang 22.1.3 ]\n{'jsonschema': '4.26.0', 'json_source_map': '1.0.5'}","uv":"uv 0.13.5 (x86_64-unknown-linux-gnu)","xmllint":"xmllint: using libxml version 21504\n compiled with: Threads Tree Output Push Reader Patterns Writer SAXv1 DTDValid HTML C14N Catalog XPath XPointer XInclude Iconv ISO8859X Regexps Automata RelaxNG Schemas Modules Debug"},"tracked-digest":"7a3e43b61f87b99d235bacd040858566f2d5218e6b72c05115dadbf8a39cfa33","tree":"3a8bb83e0ca02c902c1b542cfa75548e05b0d958"}} --- ci/pr_attestation.py | 15 +-- ci/test_pr_attestation.py | 232 ++++++++++++++++++++++++++++++++++---- 2 files changed, 216 insertions(+), 31 deletions(-) diff --git a/ci/pr_attestation.py b/ci/pr_attestation.py index ebf977d5fe..6cdb591262 100644 --- a/ci/pr_attestation.py +++ b/ci/pr_attestation.py @@ -181,13 +181,14 @@ def show(self, rev, path): return self.run("show", f"{rev}:{path}") def commit(self, rev): - sha = self.run("rev-parse", "--verify", f"{rev}^{{commit}}").strip() - return Commit( - sha, - self.run("rev-parse", f"{sha}^{{tree}}").strip(), - tuple(self.run("log", "-1", "--format=%P", sha).split()), - self.run("log", "-1", "--format=%B", sha), - ) + fields = self.run( + "show", "--no-patch", "--format=%H%x00%T%x00%P%x00%B", f"{rev}^{{commit}}", "--" + ).split("\0", 3) + if len(fields) != 4: + raise GitError("commit lookup returned malformed metadata") + sha, tree, parents, message = fields + return Commit(sha, tree, tuple(parents.split()), message) + def prooft_api(request): diff --git a/ci/test_pr_attestation.py b/ci/test_pr_attestation.py index 0eb902cc65..f041e22546 100644 --- a/ci/test_pr_attestation.py +++ b/ci/test_pr_attestation.py @@ -14,6 +14,7 @@ from dataclasses import dataclass, replace import hashlib import re +import shutil import io import json from pathlib import Path @@ -22,6 +23,7 @@ import sys import tempfile import unittest +import zlib from unittest.mock import patch import pr_attestation as subject @@ -103,26 +105,153 @@ def to_trailer(self): )) +class ObjectFixture: + """Write real loose Git objects; fixture construction needs no Git processes. + + Only the test builder uses this. The verifier still reads the resulting + repository with real Git, including its real merge-base and shallow logic. + """ + + def __init__(self, root): + self.root = root + self.index = {} + self.trees = {} + self.commits = {} + + def object(self, kind, body): + raw = f"{kind} {len(body)}\0".encode() + body + sha = hashlib.sha1(raw).hexdigest() + path = self.root / ".git/objects" / sha[:2] / sha[2:] + path.parent.mkdir(parents=True, exist_ok=True) + path.write_bytes(zlib.compress(raw)) + return sha + + def tree(self, entries): + children = {} + for path, sha in entries.items(): + name, sep, rest = path.partition("/") + if sep: + children.setdefault(name, {})[rest] = sha + else: + children[name] = sha + body = bytearray() + for name, value in sorted(children.items(), key=lambda item: item[0] + ("/" if isinstance(item[1], dict) else "")): + mode, sha = ("40000", self.tree(value)) if isinstance(value, dict) else ("100644", value) + body.extend(f"{mode} {name}\0".encode() + bytes.fromhex(sha)) + sha = self.object("tree", body) + self.trees[sha] = dict(entries) + return sha + + def run(self, *args, input_text=None): + command, *values = args + if command == "add": + paths = sorted(p.relative_to(self.root).as_posix() for p in self.root.rglob("*") + if p.is_file() and ".git" not in p.relative_to(self.root).parts) if values == ["."] else values + for path in paths: + self.index[path] = self.object("blob", (self.root / path).read_bytes()) + elif command == "write-tree": + return self.tree(self.index) + elif command == "commit-tree": + tree, *parents = values + headers = [f"tree {tree}"] + [f"parent {parent}" for parent in parents[1::2]] + identity = "Local fixture 1794519000 +0000" + headers += [f"author {identity}", f"committer {identity}"] + message = input_text + ("" if input_text.endswith("\n") else "\n") + sha = self.object("commit", ("\n".join(headers) + "\n\n" + message).encode()) + self.commits[sha] = tree + return sha + elif command == "read-tree": + tree = self.commits.get(values[0], values[0]) + self.index = dict(self.trees[tree]) + elif command == "hash-object": + return self.object("blob", input_text.encode()) + elif command == "update-index": + if values[0] == "--force-remove": + self.index.pop(values[1], None) + else: + assert values[:3] == ["--add", "--cacheinfo", "100644"], values + self.index[values[4]] = values[3] + else: + raise AssertionError(f"unsupported fixture operation: {args}") + return "" + + +REAL_GIT = subject.Git + + +class FixtureGit(REAL_GIT): + """Reuse successful immutable reads across identical fixture copies. + + Keys contain the exact command and full object IDs. Shallow repositories + always go through Git: shallow boundaries change ancestry without changing + object IDs. Failures are never cached. All distinct queries execute real Git. + """ + + reads = {} + + def run(self, *args): + git_dir = self.root / ".git" + if (args[0] not in {"show", "diff"} + or any((git_dir / path).exists() for path in + ("shallow", "info/grafts", "refs/replace", "packed-refs", "objects/info/alternates"))): + return super().run(*args) + ids = re.findall(r"(?