Revision: 1 Last modified: 2026-12-04T18:15:21Z
This is a library. It is sourced by the tests/sync/* suites, never executed. Mode rw-rw-r--.
scripts/sync/fixture_lib.sh builds real git repositories for the sync tests: bare "upstream" repositories
under $SB/remotes/<org>/<name>.git, producer clones, working clones with real submodules (via file://
URLs), plus a small assertion vocabulary and a runner that invokes the engine through a recording shim.
Nothing here touches the network, a forge, $HOME, or the repository the tests run from. That is the point: the
tests exercise the real engine and the real git binary against real repositories, which is LIVE-class for
git behaviour and fixture-class only for the network aspects (§11.4.289).
Two design details worth knowing:
- The engine under test runs with
PATHstarting at a recording shim that logs every argument vector and thenexecs the same real git. So a test can assert which git calls the engine made, without replacing git. - The file lives outside
tests/on purpose (see the header's own note): the full-suite census counts every script undertests/, and a sourced helper there would need an excluded row inscripts/run_full_suite.sh.
bash,git,cksum,cut,mktemp,python3(only forsx_q).scripts/lib/safe_rm.shmust exist — this file sources it and routes every recursive delete throughsafe_rm_rf, restricted bySAFE_RM_ALLOWED_ROOTSto the sandbox.- Sourced after any
T_NAMEyou want in the summary line (defaultsync-tests).
In a test file:
. "$REPO/scripts/sync/fixture_lib.sh"
sx_sandbox # create $SB, set git config, install the shim, trap cleanup
U_A="$(sx_bare HelixDevelopment liba)" # a bare upstream with one commit on main
W="$(sx_seed "$U_A")" # a scratch producer clone
sx_commit "$U_A" "second commit" # a new commit on the bare upstream's main
sx_clone "$U_A" "$SB/work/consumer" # a working clone
sx_run --check --root "$SB/work/consumer" # runs the engine through the shim
eq "check reports updates" 3 "$SX_RC"
has "report names the repo" "consumer" "$(cat "$SX_JSON")"
sx_std_tree # the standard own-org + nested + third-party tree
finish # prints "NAME: PASS n FAIL m"; returns non-zero on any failureHelper inventory:
| Helper | Effect |
|---|---|
ok MSG / nok MSG |
count a pass / a failure and print a line |
eq NAME EXPECTED ACTUAL |
equality assertion |
has NAME NEEDLE HAYSTACK / hasnt NAME NEEDLE HAYSTACK |
substring present / absent |
finish |
print NAME: PASS n FAIL m; returns 1 if any failure |
sx_sandbox |
create $SB, write a private gitconfig, install the recording shim, trap cleanup |
sx_cleanup |
chmod -R u+w then safe_rm_rf the sandbox |
sx_bare ORG NAME |
new bare repository with one commit on main; prints its file:// URL |
sx_seed URL |
scratch producer clone for that URL (cached per URL, cksum-keyed) |
sx_commit URL MESSAGE |
a new commit on the bare repository's main |
sx_add_sub PARENT_URL CHILD_URL PATH |
parent records the child as a submodule at PATH |
sx_bump_pin PARENT_URL PATH |
the parent's gitlink at PATH moves to the child's current upstream main |
sx_clone URL DEST |
working clone with all submodules initialised recursively |
sx_run ARGS... |
run the engine through the shim; sets SX_RC, SX_OUT, SX_ERR, SX_JSON, SX_TSV |
sx_q EXPR |
evaluate a Python expression over the last report, with r bound to it and P = path→repo |
sx_head DIR / sx_remote_head DIR |
rev-parse HEAD of a work tree / rev-parse main of a bare repo |
sx_std_tree |
the standard tree: own-org libs/a with nested own-org inner, plus third-party vendor/t; sets U_ROOT U_A U_IN U_T W |
The library does not exit on its own (except via sx_sandbox's exit 2 when mktemp fails).
| Call | Returns / sets |
|---|---|
sx_sandbox |
exit 2 if mktemp fails; otherwise sets SB and cds into it |
sx_run |
sets SX_RC to the engine's exit code; never fails the test by itself |
finish |
0 when T_FAIL == 0, 1 otherwise |
ok / nok / eq / has / hasnt |
increment T_PASS / T_FAIL; return 0 |
sx_q |
prints the expression's value, or nothing when the report cannot be read |
| others | 0 on success; a git failure propagates from the underlying git call |
sx_sandboxmust be called first. It creates$SBandcds into it; every other helper assumes$SB.TMPDIRunset —mktemp -d "${TMPDIR:-/tmp}/helix-sync-test.XXXXXX"falls back to/tmp.- No global
core.hooksPathis deliberately written into the sandbox gitconfig (a review finding: a globalhooksPathhid hook regressions). GIT_CEILING_DIRECTORIESis set to the sandbox's parent, so git discovery cannot escape upward into a real repository.XDG_CACHE_HOMEis redirected into the sandbox so a cache cannot leak between runs.- Repository-locating
GIT_*variables are cleared at source time, so an inheritedGIT_DIRcannot redirect the fixtures. - The recording shim writes one line per call with
O_APPENDand underPIPE_BUF, so concurrent engine calls never interleave inside a line (the log stays parseable under--jobs). sx_qusesevalon a literal written by the test author — the header says so explicitly. It is not an input path; do not pass external data through it.sx_cleanupis registered withtrap … EXIT, so an aborted test still removes the sandbox.
- Resolves
SX_REPOfrom its own location, setsSX_ENGINE(overridable), sourcesscripts/lib/safe_rm.sh, records the realgitpath inSX_GIT, and pins deterministic git identity/dates (GIT_AUTHOR_DATE/GIT_COMMITTER_DATE=2026-01-01T00:00:00Z) so fixtures are reproducible. sx_sandboxcreates the sandbox withmktemp -d, setsSAFE_RM_ALLOWED_ROOTS="$SB", writes a private gitconfig, createsremotes/ work/ seed/ out/ shim/, setsGIT_CEILING_DIRECTORIESandXDG_CACHE_HOME, writes the recording shim to$SB/shim/git, traps cleanup, andcds into$SB.sx_barecreates a bare repository, seeds one commit in a scratch clone, and pushesmain— a real upstream.sx_seedcaches one producer clone per URL; a second callpull --ff-onlys it.sx_runincrementsSX_N, invokes the engine with--outand--run-idunique to that call, withPATH="$SB/shim:$PATH", capturing stdout/stderr separately and recording the exit code.sx_std_treecomposes the canonical tree: a nested own-org child inside an own-org parent, plus a third-party submodule, then clones it — the shape the own-org/nesting rules need.
scripts/sync/sync_all_upstreams.sh/.py— the engine under test.scripts/lib/safe_rm.sh—safe_rm_rf, the only sanctioned recursive delete used here.scripts/sync/robustness_checks.py— the behavioural suite that drives the engine directly.scripts/sync/race_git_shim.py— the shim that acts as a user mid-run.scripts/sync/inproc_driver.py— in-process fault injection for the engine.tests/sync/*— the consumers of this library.
2026-12-04 — bash -n scripts/sync/fixture_lib.sh → exit 0 (a library: sourced, not executed).
A reader can confirm the library loads and the shim machinery builds without running a test suite:
bash -c 'cd "$(mktemp -d)" && . /path/to/constitution/scripts/sync/fixture_lib.sh \
&& sx_sandbox && echo "SB=$SB" && ls && finish'Expected: SB=<a temp dir>, the directories remotes work seed out shim listed, then sync-tests: PASS 0 FAIL 0
(the suite name defaults to sync-tests).