interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / tools / test_pinned_checkout.sh

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