Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/route-a-sha-of-unreadable.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The Route A driver no longer hashes a file openssl cannot read as an empty digest: such an input is reported as unreadable, and the crosswalk and base digests fail the run.
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,65 @@ def test_overridden_feed_pin_still_verifies_digest_and_size(
)


@pytest.mark.parametrize(
"openssl",
[
# Nothing on stdout: openssl could not open the file.
"openssl() { return 1; }",
# An error on stdout instead of a digest.
"openssl() { echo 'Operation not permitted'; }",
# A digest-shaped line that is not 64 hex digits.
"openssl() { echo '0123 *x'; }",
],
)
def test_an_input_openssl_cannot_read_is_unreadable_not_an_empty_digest(
tmp_path: Path, openssl: str
) -> None:
# On 2026-11-17 a launchd job's /usr/bin/openssl could not read the
# archive drive, and sha_of turned that into an empty digest. Now it
# prints nothing and fails, and the input is reported as unreadable.
feed = tmp_path / "new-feed.jsonl"
payload = b'{"fixture": "feed"}\n'
feed.write_bytes(payload)
result = _input_settings_result(
tmp_path,
{
"FEED": str(feed),
"FEED_SHA": hashlib.sha256(payload).hexdigest(),
"FEED_BYTES": str(len(payload)),
},
f"""
registered_rows=$(input_rows)
input_rows() {{ printf '%s\\n' "$registered_rows" | awk -F '|' '$1 == "release_ledger_facts"'; }}
stat() {{ "$PYTHON" -c 'import os,sys; print(os.stat(sys.argv[1]).st_size)' "$3"; }}
{openssl}
if out=$(sha_of "{feed}"); then echo "sha_of ok [$out]"; else echo "sha_of failed [$out]"; fi
verify_inputs
printf '%s\\n' "${{INPUT_PROBLEMS[@]}}"
""",
)
assert result.returncode == 0, result.stderr.decode()
lines = result.stdout.decode().splitlines()
assert lines[0] == "sha_of failed []"
assert lines[1:] == [f"release_ledger_facts could not be read to hash it: {feed}"]
report = json.loads((tmp_path / "run_root" / "inputs.resolved.json").read_text())
assert report["inputs"][0]["status"] == "unreadable"
assert report["inputs"][0]["observed_sha256"] == ""


def test_the_crosswalk_and_base_digests_refuse_an_unreadable_file() -> None:
# These run after the fetch, where the settings harness stops, so the
# source is checked: neither compares nor records an empty digest.
source = (ROUTE_A_TOOLS / "route_a.sh").read_text(encoding="utf-8")
assert (
'CROSSWALK_ACTUAL=$(sha_of "$W/$CROSSWALK_REL") || fail "could not read'
in source
)
assert 'BASE_SHA=$(sha_of "$BASE_H5") || fail "could not read $BASE_H5' in source
assert "[[ $BASE_SHA =~ ^[0-9a-f]{64}$ ]] || fail" in source
assert '"$(sha_of ' not in source


def _tiny_main(tmp_path: Path, files: dict[str, str]) -> tuple[Path, str]:
"""A throwaway local repository standing in for ``$MAIN`` at one commit."""

Expand Down
8 changes: 7 additions & 1 deletion tools/route_a/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,13 @@ and 18,991,218 bytes. Use a fresh `RUN_ROOT` for that attempt: an existing
does not rebuild a previously accepted base.

The driver uses macOS `stat -f` and requires bash, git, openssl, uv and the
configured paths. It creates clean detached worktrees at the chosen commits,
configured paths. A file openssl cannot read is an input problem or a failed
run, never an empty digest. Under launchd, macOS can refuse the system's own
tools access to an external drive: on 2026-11-17, in a launchd job,
`/usr/bin/openssl`, `/usr/bin/shasum` and `/usr/bin/python3` got "Operation
not permitted" there, while a Homebrew openssl and the worktree's Python
read the same files. Put Homebrew's `bin` before `/usr/bin` on such a job's
`PATH`, or copy the inputs to the internal disk. It creates clean detached worktrees at the chosen commits,
runs `uv sync --all-packages --locked --extra us`, and checks that their Python
can import psutil and policyengine-us. The supervised stages use that worktree's
interpreter.
Expand Down
22 changes: 17 additions & 5 deletions tools/route_a/route_a.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,15 @@ fail() {
echo "$(date '+%F %T') $*" > "$RUN_ROOT/ROUTE_A_FAILED"
exit 1
}
sha_of() { openssl dgst -sha256 -r "$1" 2>/dev/null | cut -c1-64; }
# The file's sha256, or nothing and status 1 when openssl prints no digest:
# an unreadable file (in a launchd job on 2026-11-17, /usr/bin/openssl got
# "Operation not permitted" on an external drive) must not hash as empty.
sha_of() {
local out
out=$(openssl dgst -sha256 -r "$1" 2>/dev/null | cut -c1-64)
[[ $out =~ ^[0-9a-f]{64}$ ]] || return 1
printf '%s\n' "$out"
}
free_bytes() { df -k "$DISK_PATH" | awk 'NR==2 {print $4*1024}'; }

INPUT_PROBLEMS=()
Expand All @@ -139,8 +147,9 @@ verify_inputs() { # fills INPUT_PROBLEMS; writes $RUN_ROOT/inputs.resolved.json
if [ "$size" != "-" ] && [ "$asize" != "$size" ]; then
status=size_mismatch; INPUT_PROBLEMS+=("$role size $asize != $size: $path")
fi
actual=$(sha_of "$path")
if [ "$actual" != "$sha" ]; then
if ! actual=$(sha_of "$path"); then
status=unreadable; INPUT_PROBLEMS+=("$role could not be read to hash it: $path")
elif [ "$actual" != "$sha" ]; then
status=sha_mismatch; INPUT_PROBLEMS+=("$role sha256 $actual != $sha: $path")
fi
fi
Expand Down Expand Up @@ -402,7 +411,8 @@ ensure_worktree() { # $1 = full sha; sets WT
ensure_worktree "$C"; W=$WT
ensure_worktree "$PC"; PW=$WT
PY=$W/.venv/bin/python
[ "$(sha_of "$W/$CROSSWALK_REL")" = "$CROSSWALK_SHA" ] || fail "packaged crosswalk digest in $W"
CROSSWALK_ACTUAL=$(sha_of "$W/$CROSSWALK_REL") || fail "could not read $W/$CROSSWALK_REL to hash it"
[ "$CROSSWALK_ACTUAL" = "$CROSSWALK_SHA" ] || fail "packaged crosswalk digest in $W"
PEUS=$("$PY" -c 'import importlib.metadata as m; print(m.version("policyengine-us"))')
[ -x "$W/.venv/bin/microcosm-publish-release-build" ] || fail "no microcosm-publish-release-build in $W/.venv"
log "build worktree $W (policyengine-us $PEUS); preflight worktree $PW"
Expand Down Expand Up @@ -585,9 +595,11 @@ if ! stage_done base; then
fi
[ -f "$BASE_H5" ] || fail "base stage accepted but $BASE_H5 is missing"
if [ ! -f "$RUN/base.sha256" ] || [ "$BASE_H5" -nt "$RUN/base.sha256" ]; then
echo "$(sha_of "$BASE_H5") $BASE_H5" > "$RUN/base.sha256"
BASE_SHA=$(sha_of "$BASE_H5") || fail "could not read $BASE_H5 to hash it"
echo "$BASE_SHA $BASE_H5" > "$RUN/base.sha256"
fi
BASE_SHA=$(cut -c1-64 "$RUN/base.sha256")
[[ $BASE_SHA =~ ^[0-9a-f]{64}$ ]] || fail "$RUN/base.sha256 holds no sha256; delete it and rerun"
log "base H5 $BASE_H5 sha256 $BASE_SHA ($(stat -f %z "$BASE_H5") bytes)"
if [ "$PRUNE_BASE_CHECKPOINTS" = 1 ] && ls "$BASE_CKPT"/*.frame.h5 >/dev/null 2>&1; then
log "PRUNE_BASE_CHECKPOINTS=1: removing base frame checkpoints ($(du -sh "$BASE_CKPT" | cut -f1)) after the base H5 was hashed"
Expand Down
Loading