"""Isolated local Git ref examples. No network, user Git config, or existing repo. Run: python3 verify_refs.py ; requires Python 3 and Git on PATH. This is not a GitHub quorum implementation or a throughput benchmark. """ import json import platform import shutil import subprocess import tempfile from pathlib import Path git = shutil.which('git') if not git: raise SystemExit('Git is required') env = { 'PATH': '/usr/bin:/bin:/usr/local/bin:/opt/homebrew/bin', 'GIT_CONFIG_NOSYSTEM': '1', 'GIT_CONFIG_GLOBAL': '/dev/null', 'GIT_AUTHOR_NAME': 'Example', 'GIT_AUTHOR_EMAIL': 'example@example.invalid', 'GIT_COMMITTER_NAME': 'Example', 'GIT_COMMITTER_EMAIL': 'example@example.invalid', 'GIT_AUTHOR_DATE': '2026-10-28T00:00:00+09:00', 'GIT_COMMITTER_DATE': '2026-10-28T00:00:00+09:00', 'LC_ALL': 'C', 'GIT_TERMINAL_PROMPT': '0', } with tempfile.TemporaryDirectory(prefix='techdokhae-git-refs-') as tmp: root = Path(tmp) empty = root / 'empty-template' empty.mkdir() repo = root / 'example.git' def run(*args, data=None, ok=True): result = subprocess.run([git, *args], cwd=root, env=env, input=data, capture_output=True, text=True, timeout=20) if ok and result.returncode != 0: raise AssertionError(result.stderr) return result def g(*args, **kwargs): return run('--git-dir=' + str(repo), *args, **kwargs) run('init', '--bare', '--template=' + str(empty), str(repo)) tree = g('mktree', data='').stdout.strip() base = g('commit-tree', tree, '-m', 'base').stdout.strip() alice = g('commit-tree', tree, '-p', base, '-m', 'alice').stdout.strip() bob = g('commit-tree', tree, '-p', base, '-m', 'bob').stdout.strip() ref = lambda name: 'refs/heads/' + name value = lambda name: g('rev-parse', ref(name)).stdout.strip() reset = lambda name: g('update-ref', ref(name), base) cases = [] reset('shared') g('update-ref', ref('shared'), alice, base) stale = g('update-ref', ref('shared'), bob, base, ok=False) assert stale.returncode != 0 and value('shared') == alice cases.append({'case': 'same-ref-stale-expectation', 'first': 'accepted', 'second': 'rejected', 'final': 'alice', 'errorClass': 'current OID does not match expected old OID'}) reset('alice'); reset('bob') g('update-ref', ref('alice'), alice, base) g('update-ref', ref('bob'), bob, base) assert value('alice') == alice and value('bob') == bob cases.append({'case': 'different-refs', 'alice': 'accepted', 'bob': 'accepted', 'limit': 'sequential commands; no concurrency or timing measurement'}) reset('release'); reset('catalog') g('update-ref', ref('catalog'), bob, base) def transaction(expected_catalog): return ('start\n' + f'update {ref("release")} {alice} {base}\n' + f'update {ref("catalog")} {alice} {expected_catalog}\n' + 'prepare\ncommit\n') rejected = g('update-ref', '--stdin', data=transaction(base), ok=False) assert rejected.returncode != 0 assert value('release') == base and value('catalog') == bob cases.append({'case': 'two-ref-transaction-stale', 'transaction': 'rejected', 'release': 'base', 'catalog': 'bob'}) g('update-ref', '--stdin', data=transaction(bob)) assert value('release') == alice and value('catalog') == alice cases.append({'case': 'two-ref-transaction-revalidated', 'transaction': 'accepted', 'release': 'alice', 'catalog': 'alice', 'limit': 'empty-tree teaching case; real content must be re-evaluated'}) service_ms = 60 waves = {'one-repository-queue': 4 * service_ms, 'four-independent-refs': service_ms, 'three-on-main-one-other': 3 * service_ms} assert list(waves.values()) == [240, 60, 180] print(json.dumps({'gitVersion': run('--version').stdout.strip(), 'pythonVersion': platform.python_version(), 'platform': platform.system() + ' ' + platform.machine(), 'cases': cases, 'hypotheticalBatchCompletionMs': waves, 'assumptions': 'four arrivals at time zero, 60ms each, independent unlimited workers; no extra overhead', 'limits': 'No GitHub network, distributed quorum, parallel race, UI, CI or throughput test'}, ensure_ascii=False, indent=2))