omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / tools / test_pinned_checkout.sh
| 1 | #!/usr/bin/env bash |
| 2 | # SPDX-License-Identifier: Apache-2.0 |
| 3 | # Copyright 2026 Drake Stapleton (AIEN / aien-dev) |
| 4 | # Host-only regression controls for tools/pinned_checkout.sh. No network or GPU. |
| 5 | set -euo pipefail |
| 6 | ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)" |
| 7 | TOOL="$ROOT/tools/pinned_checkout.sh" |
| 8 | SCR="$(mktemp -d "${TMPDIR:-/tmp}/omega-pin-test.XXXXXX")" |
| 9 | trap 'chmod -R u+w "$SCR" 2>/dev/null || true; rm -rf "$SCR"' EXIT |
| 10 | SRC="$SCR/source" |
| 11 | PASS=0 |
| 12 | |
| 13 | check() { |
| 14 | local title=$1 |
| 15 | shift |
| 16 | if "$@"; then PASS=$((PASS + 1)); else echo "FAIL $title" >&2; exit 1; fi |
| 17 | } |
| 18 | refuse() { ! "$@" >/dev/null 2>&1; } |
| 19 | |
| 20 | git init -q "$SRC" |
| 21 | git -C "$SRC" config user.name pin-test |
| 22 | git -C "$SRC" config user.email pin-test@example.invalid |
| 23 | printf 'locked bytes\n' > "$SRC/regular" |
| 24 | printf '#!/bin/sh\nexit 0\n' > "$SRC/executable" |
| 25 | chmod 755 "$SRC/executable" |
| 26 | ln -s regular "$SRC/link" |
| 27 | git -C "$SRC" add regular executable link |
| 28 | git -C "$SRC" commit -qm locked |
| 29 | LOCK=$(git -C "$SRC" rev-parse HEAD) |
| 30 | TREE=$(git -C "$SRC" rev-parse "$LOCK^{tree}") |
| 31 | |
| 32 | printf 'replacement bytes\n' > "$SRC/regular" |
| 33 | git -C "$SRC" add regular |
| 34 | git -C "$SRC" commit -qm replacement |
| 35 | REPLACEMENT=$(git -C "$SRC" rev-parse HEAD) |
| 36 | git -C "$SRC" replace "$LOCK" "$REPLACEMENT" |
| 37 | git -C "$SRC" -c advice.detachedHead=false checkout -q "$LOCK" |
| 38 | printf 'dirty bytes\n' > "$SRC/regular" |
| 39 | printf 'untracked\n' > "$SRC/untracked" |
| 40 | |
| 41 | PIN1="$SCR/pin1" |
| 42 | GOT_TREE=$("$TOOL" materialize "$SRC" "$LOCK" "$PIN1") |
| 43 | check "tree identity retained" test "$GOT_TREE" = "$TREE" |
| 44 | check "dirty source ignored" grep -qx 'locked bytes' "$PIN1/regular" |
| 45 | check "replacement ref ignored" test "$(git -C "$PIN1" rev-parse HEAD)" = "$LOCK" |
| 46 | check "independent objects copied" test ! -s "$PIN1/.git/objects/info/alternates" |
| 47 | check "executable mode retained" test -x "$PIN1/executable" |
| 48 | check "symlink retained" test "$(readlink "$PIN1/link")" = regular |
| 49 | check "materialized tree verifies" test "$("$TOOL" verify "$PIN1" "$LOCK")" = "$TREE" |
| 50 | check "source files are read-only" test "$((8#$(stat -c %a "$PIN1/regular") & 8#222))" -eq 0 |
| 51 | |
| 52 | HOOK="$SCR/hook-ran" |
| 53 | rm -f "$HOOK" |
| 54 | git -C "$SRC" config uploadpack.packObjectsHook "touch $HOOK" |
| 55 | git -C "$SRC" config core.fsmonitor "touch $HOOK" |
| 56 | PINH="$SCR/pinh" |
| 57 | GOT_HOOK=$("$TOOL" materialize "$SRC" "$LOCK" "$PINH") |
| 58 | check "source pack and fsmonitor hooks did not run" test ! -e "$HOOK" |
| 59 | check "hooked source still pins the locked tree" test "$GOT_HOOK" = "$TREE" |
| 60 | |
| 61 | chmod u+w "$PIN1/regular" |
| 62 | printf 'changed after setup\n' > "$PIN1/regular" |
| 63 | check "changed bytes refused" refuse "$TOOL" verify "$PIN1" "$LOCK" |
| 64 | |
| 65 | PIN2="$SCR/pin2" |
| 66 | "$TOOL" materialize "$SRC" "$LOCK" "$PIN2" >/dev/null |
| 67 | chmod u+w "$PIN2/executable" |
| 68 | chmod a-x "$PIN2/executable" |
| 69 | check "changed mode refused" refuse "$TOOL" verify "$PIN2" "$LOCK" |
| 70 | |
| 71 | PIN3="$SCR/pin3" |
| 72 | "$TOOL" materialize "$SRC" "$LOCK" "$PIN3" >/dev/null |
| 73 | chmod u+w "$PIN3" |
| 74 | printf 'extra\n' > "$PIN3/extra" |
| 75 | check "extra path refused" refuse "$TOOL" verify "$PIN3" "$LOCK" |
| 76 | check "short commit refused" refuse "$TOOL" materialize "$SRC" "${LOCK:0:12}" "$SCR/short" |
| 77 | mkdir "$SCR/existing" |
| 78 | check "existing destination refused" refuse "$TOOL" materialize "$SRC" "$LOCK" "$SCR/existing" |
| 79 | |
| 80 | echo "OMEGA_PINNED_CHECKOUT_PASS checks=$PASS" |