Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(minikube): pin origin/dev for the children of a T2 lease

Alfredo Lopezb09d61a8bc37
diff --git a/scripts/tests/lib/minikube-fixture-repo.sh b/scripts/tests/lib/minikube-fixture-repo.sh
index 836f1e7bc..f72f3c303 100755
--- a/scripts/tests/lib/minikube-fixture-repo.sh
+++ b/scripts/tests/lib/minikube-fixture-repo.sh
@@ -28,6 +28,9 @@ minikube_test_fixture_repo_init() {
MINIKUBE_TEST_PROJECT_DIR="$(cd -- "${repo}" && pwd -P)"
MINIKUBE_TEST_BRANCH="$(git -C "${MINIKUBE_TEST_PROJECT_DIR}" branch --show-current)"
MINIKUBE_TEST_HEAD="$(git -C "${MINIKUBE_TEST_PROJECT_DIR}" rev-parse --verify HEAD)"
+ # The origin/dev a T2 lease owner pins: hand-written owner.env fixtures record
+ # it as ORIGIN_DEV and lease children inherit it as T2_PINNED_ORIGIN_DEV.
+ MINIKUBE_TEST_ORIGIN_DEV="$(git -C "${MINIKUBE_TEST_PROJECT_DIR}" rev-parse --verify origin/dev)"
MINIKUBE_TEST_WORKTREE_ID="$(printf '%s' "${MINIKUBE_TEST_PROJECT_DIR}" | shasum | awk '{print $1}')"
MINIKUBE_TEST_LOCK_KEY="$(printf '%s\0%s\0%s\0%s\0%s' \
"${MINIKUBE_TEST_PROJECT_DIR}" "${MINIKUBE_TEST_BRANCH}" \
@@ -38,7 +41,7 @@ minikube_test_fixture_repo_init() {
export MINIKUBE_TEST_HOST_ROOT MINIKUBE_TEST_HOST_HEAD
export MINIKUBE_TEST_HOST_BRANCH MINIKUBE_TEST_HOST_STATUS_HASH
export MINIKUBE_TEST_PROJECT_DIR MINIKUBE_TEST_BRANCH MINIKUBE_TEST_HEAD
- export MINIKUBE_TEST_WORKTREE_ID MINIKUBE_TEST_LOCK_KEY
+ export MINIKUBE_TEST_WORKTREE_ID MINIKUBE_TEST_LOCK_KEY MINIKUBE_TEST_ORIGIN_DEV
}
minikube_test_assert_host_unchanged() {
diff --git a/scripts/tests/test-minikube-build-images-hardening.sh b/scripts/tests/test-minikube-build-images-hardening.sh
index 3254e3b6d..0e6724d4c 100755
--- a/scripts/tests/test-minikube-build-images-hardening.sh
+++ b/scripts/tests/test-minikube-build-images-hardening.sh
@@ -175,6 +175,8 @@ prepare_lease() {
lock_key="$(printf '%s\0%s\0%s\0%s\0%s' \
"$FIXTURE" "$branch" "$head" "$PROFILE" "$PROFILE" | shasum | awk '{print $1}')"
lock_dir="$LOCK_ROOT/$PROFILE.lock"
+ # The fixture has no origin/dev; the owner pins its only commit.
+ LEASE_ORIGIN_DEV="$head"
mkdir -p "$lock_dir"
{
printf 'REPOSITORY=%s\n' "$FIXTURE"
@@ -184,6 +186,7 @@ prepare_lease() {
printf 'CONTEXT=%s\n' "$PROFILE"
printf 'WORKTREE_ID=%s\n' "$worktree_id"
printf 'LOCK_KEY=%s\n' "$lock_key"
+ printf 'ORIGIN_DEV=%s\n' "$LEASE_ORIGIN_DEV"
printf '%s=%s\n' TOKEN "$LEASE_VALUE"
printf 'PID=%s\n' "$$"
printf 'PROCESS_START=unavailable\n'
@@ -216,6 +219,7 @@ run_build() {
"T2_PROJECT_DIR=$FIXTURE"
"T2_PROFILE=$PROFILE"
"T2_CONTEXT=$PROFILE"
+ "T2_PINNED_ORIGIN_DEV=$LEASE_ORIGIN_DEV"
"${LEASE_ENV_KEY}=$LEASE_VALUE"
)
;;
@@ -224,6 +228,7 @@ run_build() {
"T2_PROJECT_DIR=$FIXTURE"
"T2_PROFILE=$PROFILE"
"T2_CONTEXT=$PROFILE"
+ "T2_PINNED_ORIGIN_DEV=$LEASE_ORIGIN_DEV"
"${LEASE_ENV_KEY}=wrong-value"
)
;;
@@ -232,6 +237,7 @@ run_build() {
"T2_PROJECT_DIR=$FIXTURE"
"T2_PROFILE=$PROFILE"
T2_CONTEXT=foreign-context
+ "T2_PINNED_ORIGIN_DEV=$LEASE_ORIGIN_DEV"
"${LEASE_ENV_KEY}=$LEASE_VALUE"
)
;;
diff --git a/scripts/tests/test-minikube-mutation-boundary.sh b/scripts/tests/test-minikube-mutation-boundary.sh
index dd308c1c1..04354d148 100755
--- a/scripts/tests/test-minikube-mutation-boundary.sh
+++ b/scripts/tests/test-minikube-mutation-boundary.sh
@@ -41,12 +41,15 @@ PROFILE=${PROFILE}
CONTEXT=${PROFILE}
WORKTREE_ID=${WORKTREE_ID}
LOCK_KEY=${LOCK_KEY}
+ORIGIN_DEV=${MINIKUBE_TEST_ORIGIN_DEV}
TOKEN=${TOKEN}
PID=${owner_pid}
PROCESS_START=unavailable
EOF
}
write_owner
+# Lease children inherit the owner's pinned origin/dev.
+export T2_PINNED_ORIGIN_DEV="${MINIKUBE_TEST_ORIGIN_DEV}"
# GNU Make may execute recipe lines containing $(MAKE) during a dry run. Force
# the dry-run flag into the child environment so with-t2-mutation-lock.sh
diff --git a/scripts/tests/test-minikube-sync-auth-key-durable.sh b/scripts/tests/test-minikube-sync-auth-key-durable.sh
index a30c97c99..e4f4b08b4 100755
--- a/scripts/tests/test-minikube-sync-auth-key-durable.sh
+++ b/scripts/tests/test-minikube-sync-auth-key-durable.sh
@@ -43,11 +43,13 @@ PROFILE=fake
CONTEXT=fake
WORKTREE_ID=${T2_TEST_WORKTREE_ID}
LOCK_KEY=${T2_TEST_LOCK_KEY}
+ORIGIN_DEV=${MINIKUBE_TEST_ORIGIN_DEV}
TOKEN=${T2_LOCK_TOKEN}
PID=$$
PROCESS_START=${T2_PROCESS_START}
EOF
export T2_PROJECT_DIR="${MINIKUBE_TEST_PROJECT_DIR}" T2_PROFILE=fake T2_CONTEXT=fake T2_LOCK_ROOT T2_LOCK_TOKEN
+export T2_PINNED_ORIGIN_DEV="${MINIKUBE_TEST_ORIGIN_DEV}"
# The discovery helper resolves target-key provenance from a sanitized view of
# the exact ConfigMaps and Secrets referenced by candidate containers. These
diff --git a/scripts/tests/test-minikube-sync-auth-key.sh b/scripts/tests/test-minikube-sync-auth-key.sh
index f7f085094..45dc79026 100755
--- a/scripts/tests/test-minikube-sync-auth-key.sh
+++ b/scripts/tests/test-minikube-sync-auth-key.sh
@@ -43,11 +43,13 @@ PROFILE=fake
CONTEXT=fake
WORKTREE_ID=${T2_TEST_WORKTREE_ID}
LOCK_KEY=${T2_TEST_LOCK_KEY}
+ORIGIN_DEV=${MINIKUBE_TEST_ORIGIN_DEV}
TOKEN=${T2_LOCK_TOKEN}
PID=$$
PROCESS_START=${T2_PROCESS_START}
EOF
export T2_PROJECT_DIR="${MINIKUBE_TEST_PROJECT_DIR}" T2_PROFILE=fake T2_CONTEXT=fake T2_LOCK_ROOT T2_LOCK_TOKEN
+export T2_PINNED_ORIGIN_DEV="${MINIKUBE_TEST_ORIGIN_DEV}"
cat >"${TMP_DIR}/sleep" <<'SH'
#!/usr/bin/env bash
diff --git a/scripts/tests/test-minikube-t2-contract.sh b/scripts/tests/test-minikube-t2-contract.sh
index 3c8455304..4d991df77 100755
--- a/scripts/tests/test-minikube-t2-contract.sh
+++ b/scripts/tests/test-minikube-t2-contract.sh
@@ -431,6 +431,7 @@ bash -c '
source "$1"
parsed="$(t2_get_name control-plane/control-postgres)"
test "$parsed" = "control-plane control-postgres"
+ T2_ORIGIN_DEV=0123456789abcdef0123456789abcdef01234567
t2_lock_acquire
t2_lock_release
' bash "$COMMON"
@@ -449,6 +450,7 @@ T2_WORKTREE_ID=contract-worktree \
bash -c '
common="$1"
source "$common"
+ T2_ORIGIN_DEV=0123456789abcdef0123456789abcdef01234567
t2_lock_acquire
token="$T2_LOCK_TOKEN"
export T2_PROJECT_DIR T2_BRANCH T2_HEAD T2_ORIGIN_DEV T2_MERGE_BASE
@@ -482,7 +484,7 @@ EOF
if T2_LOCK_ROOT="$tmp/locks" MINIKUBE_PROFILE=busy-profile T2_CONTEXT=busy-profile \
T2_PROJECT_DIR="$ROOT" T2_BRANCH=test/minikube-contract T2_HEAD=0123456789abcdef \
T2_ORIGIN_DEV=0123456789abcdef T2_MERGE_BASE=0123456789abcdef \
- bash -c 'source "$1"; t2_lock_acquire' bash "$COMMON" 2>"$tmp/busy.err"; then
+ bash -c 'source "$1"; T2_ORIGIN_DEV=0123456789abcdef0123456789abcdef01234567; t2_lock_acquire' bash "$COMMON" 2>"$tmp/busy.err"; then
echo 'FAIL: live profile owner was replaced' >&2
exit 1
fi
@@ -492,13 +494,27 @@ mkdir -p "$tmp/locks/empty-profile.lock"
if T2_LOCK_ROOT="$tmp/locks" MINIKUBE_PROFILE=empty-profile T2_CONTEXT=empty-profile \
T2_PROJECT_DIR="$ROOT" T2_BRANCH=test/minikube-contract T2_HEAD=0123456789abcdef \
T2_ORIGIN_DEV=0123456789abcdef T2_MERGE_BASE=0123456789abcdef \
- bash -c 'source "$1"; t2_lock_acquire' bash "$COMMON" 2>"$tmp/empty.err"; then
+ bash -c 'source "$1"; T2_ORIGIN_DEV=0123456789abcdef0123456789abcdef01234567; t2_lock_acquire' bash "$COMMON" 2>"$tmp/empty.err"; then
echo 'FAIL: an ownerless profile lock was reclaimed' >&2
exit 1
fi
grep -Fq 'PROFILE_BUSY' "$tmp/empty.err"
grep -Fq 'orphaned' "$tmp/empty.err"
+# The lease owner pins origin/dev for its children, so it cannot take the
+# lease without one.
+if T2_LOCK_ROOT="$tmp/locks" MINIKUBE_PROFILE=clerum-unpinned T2_CONTEXT=clerum-unpinned \
+ T2_PROJECT_DIR="$ROOT" T2_BRANCH=test/minikube-contract T2_HEAD=0123456789abcdef \
+ bash -c 'source "$1"; t2_lock_acquire' bash "$COMMON" 2>"$tmp/unpinned.err"; then
+ echo 'FAIL: a lease owner without origin/dev acquired the lock' >&2
+ exit 1
+fi
+grep -Fq 'DEVELOPMENT_SCOPE_REQUIRED: the lease owner has no origin/dev to pin' "$tmp/unpinned.err"
+if [ -e "$tmp/locks/clerum-unpinned.lock" ]; then
+ echo 'FAIL: an unpinned lease owner left a lock behind' >&2
+ exit 1
+fi
+
cert_root="$tmp/certifications"
mkdir -p "$cert_root/prior" "$cert_root/current"
CERT_FILE="$cert_root/prior/evidence.json" EXPECTED_REPOSITORY="$ROOT" \
diff --git a/scripts/tests/test-minikube-t2-lock-race.sh b/scripts/tests/test-minikube-t2-lock-race.sh
index dcd81dc03..d52b657b6 100755
--- a/scripts/tests/test-minikube-t2-lock-race.sh
+++ b/scripts/tests/test-minikube-t2-lock-race.sh
@@ -50,6 +50,7 @@ source "${TEST_COMMON}"
T2_PROJECT_DIR="${TEST_PROJECT_DIR}"
T2_BRANCH=feat/lock-race
T2_HEAD=1111111111111111111111111111111111111111
+T2_ORIGIN_DEV=2222222222222222222222222222222222222222
T2_PROFILE=race-profile
T2_CONTEXT=race-profile
T2_WORKTREE_ID=lock-race-worktree
diff --git a/scripts/tests/test-minikube-t2-proxy-runtime.sh b/scripts/tests/test-minikube-t2-proxy-runtime.sh
index cf3374059..e564f3d81 100755
--- a/scripts/tests/test-minikube-t2-proxy-runtime.sh
+++ b/scripts/tests/test-minikube-t2-proxy-runtime.sh
@@ -142,11 +142,12 @@ ps() {
case "$*" in *lstart=*) printf 'Tue Sep 15 01:00:00 2026\n' ;; *state=*) printf 'S\n' ;; *) return 1 ;; esac
}
export -f ps
+T2_ORIGIN_DEV="$MINIKUBE_TEST_ORIGIN_DEV"
t2_lock_acquire
run_healthcheck_if_requested
run_playwright_if_requested
cp "$T2_LOCK_DIR/owner.env" "$tmp/owner-original"
-for key in TOKEN REPOSITORY BRANCH HEAD PROFILE CONTEXT WORKTREE_ID LOCK_KEY PROCESS_START PID; do
+for key in TOKEN REPOSITORY BRANCH HEAD PROFILE CONTEXT WORKTREE_ID LOCK_KEY ORIGIN_DEV PROCESS_START PID; do
python3 - "$tmp/owner-original" "$T2_LOCK_DIR/owner.env" "$key" <<'PY'
import sys
from pathlib import Path
diff --git a/scripts/tests/test-minikube-t2-scenarios.sh b/scripts/tests/test-minikube-t2-scenarios.sh
index 82181bda4..b26b862b3 100755
--- a/scripts/tests/test-minikube-t2-scenarios.sh
+++ b/scripts/tests/test-minikube-t2-scenarios.sh
@@ -546,6 +546,94 @@ bash "$ROOT/scripts/tests/test-minikube-t2-process-owner.sh"
grep -Fq 'REUSE_DB=true' "$ROOT/scripts/minikube/t2.sh"
grep -Fq 'CONTROL_DB_RESET_PVC_UID' "$ROOT/scripts/minikube/t2.sh"
+# The lease owner pins origin/dev once. A fetch from any worktree that shares
+# this repository moves refs/remotes/origin/dev while a lane runs; a lease
+# child must keep validating against the pin instead of the moved ref.
+expect_message() {
+ local expected="$1" message="$2" label="$3" output="$4"
+ shift 4
+ expect_code "$expected" "$label" "$output" "$@"
+ grep -Fq "$message" "$tmp/$output" || {
+ printf '%s\n' "$(sed -n '1,20p' "$tmp/$output")" >&2
+ fail "$label did not report: $message"
+ }
+}
+dev_tree="$(git -C "$repo" rev-parse "$base_sha^{tree}")"
+dev_next="$(git -C "$repo" commit-tree "$dev_tree" -p "$base_sha" -m dev-next)"
+dev_forced="$(git -C "$repo" commit-tree "$dev_tree" -p "$base_sha" -m dev-forced)"
+missing_sha="$(printf 'e%.0s' {1..40})"
+pin_env=(env -u T2_PINNED_ORIGIN_DEV -u T2_SKIP_LOCK "${repo_env[@]}")
+print_origin_dev='source "$1"; t2_repo_metadata; printf "ORIGIN_DEV=%s\n" "$T2_ORIGIN_DEV"'
+git -C "$repo" update-ref refs/remotes/origin/dev "$dev_next"
+
+"${pin_env[@]}" T2_SKIP_LOCK=true T2_PINNED_ORIGIN_DEV="$base_sha" \
+ bash -c "$print_origin_dev" bash "$COMMON" >"$tmp/pin-moved.out" 2>&1 || {
+ printf '%s\n' "$(sed -n '1,20p' "$tmp/pin-moved.out")" >&2
+ fail 'a lease child must validate against the pinned origin/dev after the local ref moved'
+}
+grep -Fqx "ORIGIN_DEV=$base_sha" "$tmp/pin-moved.out" || fail 'a lease child must adopt the pinned origin/dev'
+grep -Fq "origin/dev moved during the lane: pinned $base_sha, local ref now $dev_next" "$tmp/pin-moved.out" ||
+ fail 'a lease child must report that the local origin/dev moved'
+
+expect_message DEVELOPMENT_SCOPE_REQUIRED 'origin/dev is not an ancestor of HEAD' unpinned-moved-dev unpinned-moved-dev \
+ "${pin_env[@]}" bash -c "$print_origin_dev" bash "$COMMON"
+expect_message DEVELOPMENT_SCOPE_REQUIRED 'T2_PINNED_ORIGIN_DEV is not a full commit SHA' short-pin short-pin \
+ "${pin_env[@]}" T2_SKIP_LOCK=true T2_PINNED_ORIGIN_DEV=abc123 bash -c "$print_origin_dev" bash "$COMMON"
+expect_message DEVELOPMENT_SCOPE_REQUIRED 'T2_PINNED_ORIGIN_DEV is not a commit in this repository' missing-pin missing-pin \
+ "${pin_env[@]}" T2_SKIP_LOCK=true T2_PINNED_ORIGIN_DEV="$missing_sha" bash -c "$print_origin_dev" bash "$COMMON"
+expect_message DEVELOPMENT_SCOPE_REQUIRED 'the pinned origin/dev is not an ancestor of the current origin/dev' head-as-pin head-as-pin \
+ "${pin_env[@]}" T2_SKIP_LOCK=true T2_PINNED_ORIGIN_DEV="$feature_sha" bash -c "$print_origin_dev" bash "$COMMON"
+expect_message DEVELOPMENT_SCOPE_REQUIRED 'T2_PINNED_ORIGIN_DEV is only honored under an inherited T2 lease' pin-without-lease pin-without-lease \
+ "${pin_env[@]}" T2_PINNED_ORIGIN_DEV="$base_sha" bash -c "$print_origin_dev" bash "$COMMON"
+expect_message DEVELOPMENT_SCOPE_REQUIRED 'an inherited T2 lease carries no pinned origin/dev' lease-without-pin lease-without-pin \
+ "${pin_env[@]}" T2_SKIP_LOCK=true bash -c "$print_origin_dev" bash "$COMMON"
+
+git -C "$repo" update-ref refs/remotes/origin/dev "$dev_forced"
+expect_message DEVELOPMENT_SCOPE_REQUIRED 'the pinned origin/dev is not an ancestor of the current origin/dev' force-pushed-dev force-pushed-dev \
+ "${pin_env[@]}" T2_SKIP_LOCK=true T2_PINNED_ORIGIN_DEV="$dev_next" bash -c "$print_origin_dev" bash "$COMMON"
+
+git -C "$repo" update-ref refs/remotes/origin/dev "$base_sha"
+"${pin_env[@]}" T2_SKIP_LOCK=true T2_PINNED_ORIGIN_DEV="$base_sha" \
+ bash -c "$print_origin_dev" bash "$COMMON" >"$tmp/pin-current.out" 2>&1 || {
+ printf '%s\n' "$(sed -n '1,20p' "$tmp/pin-current.out")" >&2
+ fail 'a lease child whose pin equals the local origin/dev must pass'
+}
+grep -Fqx "ORIGIN_DEV=$base_sha" "$tmp/pin-current.out" || fail 'a lease child must adopt a pin equal to the local ref'
+grep -Fq 'origin/dev moved' "$tmp/pin-current.out" && fail 'a pin equal to the local origin/dev must not report a move'
+
+# The lease owner records the pin in owner.env and exports it; an inherited
+# lease whose pin differs from the owner's, or is empty, is refused.
+# The children are require-t2-mutation-lock.sh, the boundary that validates a
+# lease without resolving repository metadata again.
+"${pin_env[@]}" T2_LOCK_ROOT="$tmp/pin-locks" bash -c '
+ common="$1" base="$2" other="$3" out="$4" child="$5"
+ source "$common"
+ t2_repo_metadata
+ t2_lock_acquire
+ grep -Fqx "ORIGIN_DEV=$base" "$T2_LOCK_DIR/owner.env" || { echo "owner.env does not record the pinned origin/dev" >&2; exit 11; }
+ [ "$(bash -c '\''printf %s "$T2_PINNED_ORIGIN_DEV"'\'')" = "$base" ] || { echo "the lease owner does not export the pinned origin/dev" >&2; exit 12; }
+ T2_LOCK_TOKEN="$T2_LOCK_TOKEN" bash "$child" ||
+ { echo "an inherited lease carrying the owner pin was refused" >&2; exit 13; }
+ if T2_LOCK_TOKEN="$T2_LOCK_TOKEN" T2_PINNED_ORIGIN_DEV="$other" bash "$child" 2>"$out/pin-mismatch.err"; then
+ echo "an inherited lease carrying another pin was accepted" >&2; exit 14
+ fi
+ grep -Fq "PROFILE_OWNERSHIP_MISMATCH: profile lock owner does not match ORIGIN_DEV" "$out/pin-mismatch.err" || { cat "$out/pin-mismatch.err" >&2; exit 15; }
+ if T2_LOCK_TOKEN="$T2_LOCK_TOKEN" T2_PINNED_ORIGIN_DEV= bash "$child" 2>"$out/pin-empty.err"; then
+ echo "an inherited lease without a pin was accepted" >&2; exit 16
+ fi
+ grep -Fq "PROFILE_OWNERSHIP_MISMATCH: profile lock owner does not match ORIGIN_DEV" "$out/pin-empty.err" || { cat "$out/pin-empty.err" >&2; exit 17; }
+ # A lock record without ORIGIN_DEV must not match an empty pin either.
+ grep -v "^ORIGIN_DEV=" "$T2_LOCK_DIR/owner.env" >"$out/owner-unpinned.env"
+ cp "$out/owner-unpinned.env" "$T2_LOCK_DIR/owner.env"
+ if T2_LOCK_TOKEN="$T2_LOCK_TOKEN" T2_PINNED_ORIGIN_DEV= bash "$child" 2>"$out/pin-unrecorded.err"; then
+ echo "a lease without a pin was accepted against a lock record without ORIGIN_DEV" >&2; exit 18
+ fi
+ grep -Fq "PROFILE_OWNERSHIP_MISMATCH: profile lock owner does not match ORIGIN_DEV" "$out/pin-unrecorded.err" || { cat "$out/pin-unrecorded.err" >&2; exit 19; }
+ t2_lock_release 0
+' bash "$COMMON" "$base_sha" "$dev_next" "$tmp" "$ROOT/scripts/minikube/require-t2-mutation-lock.sh" ||
+ fail 'the lease owner must record and export the pinned origin/dev, and its children must match it'
+[ ! -e "$tmp/pin-locks/$profile.lock" ] || fail 'the pinned lease was not released'
+
# branch-profile.sh lifecycle (preflight, start, status, pf, health, pf-health,
# stop-pf, stop, delete, prepare-shims) is exercised end to end against a
# fixture repository with PATH stubs for kubectl, minikube, helm, docker and