diff --git a/CHANGELOG.md b/CHANGELOG.md index e351e03..ed68e0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,22 @@ All notable changes to this project are documented here, following ## [Unreleased] +## [0.5.1] - 2026-11-06 + +### Fixed + +- **The constitution gate no longer depends on a warm cache.** `validate` + clones crunchtools/constitution from inside the container, which on a gateway + seat goes through a CONNECT proxy that refuses github.com -- the route to + GitHub there is a git `insteadOf` in the host's git config, which the + container never reads. A seat whose cache volume already held the pinned tag + passed; an empty volume, or a repo moving to a tag nobody had fetched, was a + gate that could not run. `bin/sdlc` now makes that clone with the host's git, + once per tag under `~/.cache/python-sdlc/constitution/`, and mounts it + read-only where `validate` already looks. The container still gets no git + config or credentials. If the host clone fails, nothing changes: `validate` + tries its own and reports a 2 as before. + ## [0.5.0] - 2026-11-05 ### Changed diff --git a/Containerfile b/Containerfile index 22c1f68..270b3cc 100644 --- a/Containerfile +++ b/Containerfile @@ -44,7 +44,7 @@ LABEL description="Every CrunchTools Python SDLC check in one image: ruff, mypy, LABEL org.opencontainers.image.source="https://github.com/crunchtools/python-sdlc" LABEL org.opencontainers.image.description="Every CrunchTools Python SDLC check in one image." LABEL org.opencontainers.image.licenses="AGPL-3.0-or-later" -LABEL version="0.5.0" +LABEL version="0.5.1" # What the image carries, readable without starting anything. `sdlc versions` # prints these and a consuming repo's CI pins them. diff --git a/IMAGE_TAG b/IMAGE_TAG index 8f0916f..4b9fcbe 100644 --- a/IMAGE_TAG +++ b/IMAGE_TAG @@ -1 +1 @@ -0.5.0 +0.5.1 diff --git a/bin/sdlc b/bin/sdlc index 9879d60..40c7a30 100755 --- a/bin/sdlc +++ b/bin/sdlc @@ -172,6 +172,48 @@ need_volume() { podman volume exists "$1" 2>/dev/null || die "cannot create the podman volume $1" } +# ------------------------------------------------- the constitution, by the host +# +# `validate` clones crunchtools/constitution at the tag the repo pins, into the +# cache volume. From inside the container that clone takes whatever route the +# network gives a container, and on a gateway seat that is a CONNECT proxy that +# refuses github.com: the route to GitHub there is a git `insteadOf` in the +# HOST's git config, which the container never reads. A warm cache volume hid +# it; an empty one, or a repo moving to a tag nobody has fetched, was a gate +# that could not run (claude-agent#9, developer3, 2026-11-06). +# +# So the host's git makes the clone, once per tag, and the checkout is mounted +# read-only at the path `validate` already looks in. The container still gets +# no git config and no credentials -- what crosses is a public repo's files. +# Done once here, before any lane forks. Two sdlc runs -- two repos on one tag +# -- can still meet, so each clones into its own directory and publishes it +# with `ln -sn`, which only one of them can win; the loser removes only its own +# copy and uses the winner's. Every failure is silent on purpose: without the +# mount `validate` tries its own clone and reports a 2 exactly as it did before. +CONSTITUTION_MOUNT= +host_constitution() { + _manifest=$REPO/.specify/memory/constitution.md + [ -f "$_manifest" ] || return 0 + _tag=$(awk '/^>[ \t]*\*\*Inherits:\*\*/ { + if (match($0, /v[0-9]+\.[0-9]+\.[0-9]+/)) print substr($0, RSTART, RLENGTH) + exit + }' "$_manifest") + [ -n "$_tag" ] || return 0 + _root=${XDG_CACHE_HOME:-$HOME/.cache}/python-sdlc/constitution + _dir=$_root/$_tag + if [ ! -f "$_dir/constitution.md" ]; then + mkdir -p "$_root" 2>/dev/null || return 0 + _own=$(mktemp -d "$_root/.$_tag.XXXXXX" 2>/dev/null) || return 0 + git clone --quiet --depth 1 --branch "$_tag" \ + https://github.com/crunchtools/constitution "$_own" >/dev/null 2>&1 \ + || { rm -rf "$_own"; return 0; } + ln -sn "${_own##*/}" "$_dir" 2>/dev/null || rm -rf "$_own" + [ -f "$_dir/constitution.md" ] || return 0 + fi + CONSTITUTION_MOUNT="$_dir:/cache/constitution/$_tag:ro,z" +} +host_constitution + # ------------------------------------------------------------------ podman run # # `z`, not `Z`: more than one of these can mount the same tree at once, and `Z` @@ -221,6 +263,7 @@ run_in_image() { --cpus "$GATE_CPUS" --memory "$GATE_MEMORY" --cpu-shares 256 \ -v "$REPO:/repo:$_mode,z" -w /repo \ -v "$CACHE_VOLUME:/cache" \ + ${CONSTITUTION_MOUNT:+-v "$CONSTITUTION_MOUNT"} \ --tmpfs /tmp:rw,exec,size=4g,mode=1777 \ -e HOME=/tmp \ -e PYTHONPYCACHEPREFIX=/tmp/pycache \ diff --git a/pyproject.toml b/pyproject.toml index 7b034c8..b73a6b8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ [project] name = "python-sdlc" -version = "0.5.0" +version = "0.5.1" description = "One container image and one script for every CrunchTools Python SDLC check" requires-python = ">=3.14" license = "AGPL-3.0-or-later" diff --git a/tests/test_host_contract.sh b/tests/test_host_contract.sh index 52e87bd..1b17cca 100755 --- a/tests/test_host_contract.sh +++ b/tests/test_host_contract.sh @@ -607,6 +607,57 @@ else bad "$locked of ${runs:-0} gate containers dropped capabilities" fi +# The constitution is cloned by the HOST's git and published with `ln -sn`, so +# runs that meet on a cold cache never delete each other's clone. Three run at +# once against a git whose clone is slow and offline; what must be left is one +# checkout, one link to it, and no loser's copy. +CLONESHIM=$(mktemp -d) +CLONECACHE=$(mktemp -d) +for prog in $POSIX_UTILS podman pre-commit gh; do + [ -e "$SHIM/$prog" ] && ln -s "$(readlink -f "$SHIM/$prog")" "$CLONESHIM/$prog" +done +REALGIT=$(command -v git) +cat > "$CLONESHIM/git" < "\$dest/constitution.md" ;; + *) exec "$REALGIT" "\$@" ;; +esac +EOF +chmod +x "$CLONESHIM/git" +# The check's own verdict depends on the checkout (CI has no pre-push hook), so +# each concurrent run must match one that had a cache to itself. +_solo=$(mktemp -d) +PATH="$CLONESHIM" XDG_CACHE_HOME="$_solo" sh bin/sdlc hooks-installed >/dev/null 2>&1 \ + && _want=0 || _want=$? +rm -rf "$_solo" +_pids= +for _ in 1 2 3; do + PATH="$CLONESHIM" XDG_CACHE_HOME="$CLONECACHE" sh bin/sdlc hooks-installed >/dev/null 2>&1 & + _pids="$_pids $!" +done +_odd=0 +for _pid in $_pids; do + wait "$_pid" && _got=0 || _got=$? + [ "$_got" = "$_want" ] || _odd=$((_odd + 1)) +done +if [ "$_odd" = 0 ]; then + ok "three runs racing one cold cache each exit $_want, as a run alone does" +else + bad "$_odd of 3 runs racing one cold cache did not exit $_want" +fi +_root="$CLONECACHE/python-sdlc/constitution" +_links=$(find "$_root" -mindepth 1 -maxdepth 1 -type l | wc -l | tr -d ' ') +_dirs=$(find "$_root" -mindepth 1 -maxdepth 1 -type d | wc -l | tr -d ' ') +_nested=$(find "$_root" -mindepth 2 -name '.v*' | wc -l | tr -d ' ') +if [ "$_links" = 1 ] && [ "$_dirs" = 1 ] && [ "$_nested" = 0 ] \ + && [ -f "$(find "$_root" -mindepth 1 -maxdepth 1 -type l)/constitution.md" ]; then + ok "three runs on a cold cache leave one constitution checkout and one link" +else + bad "concurrent constitution clones left $_links link(s), $_dirs dir(s), $_nested nested" +fi +rm -rf "$CLONESHIM" "$CLONECACHE" + printf '\n' if [ "$FAILED" -eq 0 ]; then printf 'host contract PASSED\n'; exit 0