Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(minikube): certify the pre-gate marker against the current source
Alfredo Lopez4c0cfa9cae3e
diff --git a/docs/testing/minikube-t2-runbook.md b/docs/testing/minikube-t2-runbook.mdindex 76276e045..5cff480ad 100644--- a/docs/testing/minikube-t2-runbook.md+++ b/docs/testing/minikube-t2-runbook.md@@ -42,8 +42,8 @@ make minikube-t2-runtime MINIKUBE_PROFILE=<generated-profile>````make minikube-t2-runtime` is valid only when the pre-gate marker already-matches HEAD. `make minikube-pre-gate-sync` reconciles the profile; it does-not emit a T2 verdict.+matches HEAD and the current source fingerprint. `make minikube-pre-gate-sync`+reconciles the profile; it does not emit a T2 verdict.The profile helper that generated the profile remains the source of truth forthe profile metadata and random localhost port mapping. Resolve it from the@@ -103,8 +103,18 @@ delete a PVC by default.### Targeted syncWhen the pre-gate marker already matches the current worktree path and `HEAD`,-the planner selects `already-synced` and `make minikube-t2` skips setup and-`pre-gate-sync`. That is the T2-runtime precondition.+and its `clusterFingerprint` still matches the fingerprint recomputed from the+current source tree, the planner selects `already-synced` and+`make minikube-t2` skips setup and `pre-gate-sync`. That is the T2-runtime+precondition. A marker whose `HEAD` matches but whose source fingerprint does+not (for example after an uncommitted edit or a rewritten generated file) is+planned as `targeted-sync` with reason `source fingerprint changed since the+pre-gate marker`; outside plan mode it fails with `HEAD_MARKER_MISMATCH`. A+fingerprint that cannot be computed fails with `HEAD_MARKER_MISMATCH` in both+modes. Agent state under `*/.claude/*` is not part of the fingerprint. After+an in-run `pre-gate-sync`, T2 re-reads the marker it stamped, so the T0/T1+attestation carries the fingerprint that `make minikube-t2-runtime` needs to+reuse it.An already healthy profile whose marker is stale may use a targetedimage/deployment update only when the diff since `origin/dev` is limited to adiff --git a/scripts/minikube/pre-gate-marker.sh b/scripts/minikube/pre-gate-marker.shindex a8134311f..0d517c60a 100755--- a/scripts/minikube/pre-gate-marker.sh+++ b/scripts/minikube/pre-gate-marker.sh@@ -12,11 +12,14 @@ pre_gate_marker_fingerprint_dir() {return 0fi+ # `.claude/` holds agent tool state (plan-state.json and the like) that is+ # rewritten outside any source change; hashing it invalidates a fresh marker.local digestif ! digest="$(set -o pipefailfind "${project_dir}/${dir}" \-type f \+ ! -path '*/.claude/*' \! -path '*/node_modules/*' \! -path '*/dist/*' \! -path '*/.next/*' \diff --git a/scripts/minikube/t2-common.sh b/scripts/minikube/t2-common.shindex 8e58e11fe..5b3bb32db 100755--- a/scripts/minikube/t2-common.sh+++ b/scripts/minikube/t2-common.sh@@ -15,6 +15,8 @@ if [ -z "$T2_SCRIPT_DIR" ]; then T2_SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SO. "$T2_SCRIPT_DIR/port-forward-owner.sh"# shellcheck source=profile-readiness.sh. "$T2_SCRIPT_DIR/profile-readiness.sh"+# shellcheck source=pre-gate-marker.sh+. "$T2_SCRIPT_DIR/pre-gate-marker.sh"T2_PROJECT_DIR="$T2_PROJECT_DIR"if [ -z "$T2_PROJECT_DIR" ]; then T2_PROJECT_DIR="$(cd -- "$T2_SCRIPT_DIR/../.." && pwd -P)"; fiT2_PROFILE="$T2_PROFILE"@@ -489,6 +491,28 @@ PY;;*) T2_NEXT_COMMAND="MINIKUBE_PROFILE=$T2_PROFILE make minikube-setup-local"; t2_fail BOOTSTRAP_REQUIRED 'pre-gate marker is incomplete' ;;esac+ # Explicit so a caller in an `||` context (errexit suspended) cannot fall+ # through to the fingerprint check with the error text as marker values.+ return 1+ fi+ local marker_fingerprint source_fingerprint+ IFS=$'\t' read -r marker_fingerprint _ <<< "$marker_values"+ # A marker for this HEAD is current only while the working tree still hashes+ # to the digest it was stamped with; NP-08 recomputes the same digest.+ if ! source_fingerprint="$(pre_gate_marker_cluster_fingerprint "$T2_PROJECT_DIR")"; then+ T2_NEXT_COMMAND="MINIKUBE_PROFILE=$T2_PROFILE make minikube-t2"+ t2_fail HEAD_MARKER_MISMATCH 'source fingerprint could not be computed'+ return 1+ fi+ if [ "$source_fingerprint" != "$marker_fingerprint" ]; then+ if [ "$T2_PLAN_MODE" = true ]; then+ T2_MARKER_MATCHES_HEAD=false+ T2_PLAN_REASON='source fingerprint changed since the pre-gate marker'+ return 0+ fi+ T2_NEXT_COMMAND="MINIKUBE_PROFILE=$T2_PROFILE make minikube-t2"+ t2_fail HEAD_MARKER_MISMATCH 'source fingerprint changed since the pre-gate marker'+ return 1fiT2_MARKER_MATCHES_HEAD=trueIFS=$'\t' read -r T2_CLUSTER_FINGERPRINT T2_IMAGE_SOURCE T2_IMAGE_TAG \diff --git a/scripts/minikube/t2.sh b/scripts/minikube/t2.shindex e930effe4..4468ccc81 100755--- a/scripts/minikube/t2.sh+++ b/scripts/minikube/t2.sh@@ -257,6 +257,12 @@ run_pre_gate() {# minikube-restart-all). A host `kubectl port-forward svc/...` stays bound to# the pod it resolved at start, so the host hold is stale from here on.T2_PRE_GATE_SYNC_RAN=true+ # pre-gate-sync has just run against a live profile, so bootstrap is no+ # longer pending. Re-read the marker it stamped: the lanes attestation and+ # the final preflight carry its fingerprint, and a marker that does not+ # describe the current source fails here instead of at NP-08.+ T2_BOOTSTRAP_REQUIRED=false+ t2_marker_check || return 1t2_evidence_write pre-gate-sync PASS \"duration=$((SECONDS - phase_started_seconds))s setupHandoffExpected=$setup_handoff_expected"}diff --git a/scripts/tests/test-minikube-build-images-hardening.sh b/scripts/tests/test-minikube-build-images-hardening.shindex 5adff2e65..62409bf60 100755--- a/scripts/tests/test-minikube-build-images-hardening.sh+++ b/scripts/tests/test-minikube-build-images-hardening.sh@@ -144,6 +144,7 @@ prepare_fixture() {"$ROOT/scripts/minikube/docker-cli-env.sh" \"$ROOT/scripts/minikube/image-mode.sh" \"$ROOT/scripts/minikube/port-forward-owner.sh" \+ "$ROOT/scripts/minikube/pre-gate-marker.sh" \"$ROOT/scripts/minikube/profile-owner.sh" \"$ROOT/scripts/minikube/profile-readiness.sh" \"$ROOT/scripts/minikube/require-t2-mutation-lock.sh" \diff --git a/scripts/tests/test-minikube-pre-gate-sync-state.sh b/scripts/tests/test-minikube-pre-gate-sync-state.shindex a73e43e9c..8ffe48dd4 100755--- a/scripts/tests/test-minikube-pre-gate-sync-state.sh+++ b/scripts/tests/test-minikube-pre-gate-sync-state.sh@@ -223,6 +223,41 @@ elsefirm -rf "${marker_failure_dir}"+# Agent tooling rewrites `.claude/` state files on its own schedule. Hashing+# them lets a marker stamped by pre-gate-sync stop matching the source seconds+# later, with no source change at all (evenfire PR #773, run 8d).+agent_state_dir="$(mktemp -d)"+mkdir -p "${agent_state_dir}/workflow-recipes/src/.claude" \+ "${agent_state_dir}/workflow-recipes/.claude" \+ "${agent_state_dir}/deploy/minikube"+printf 'export const a = 1\n' >"${agent_state_dir}/workflow-recipes/src/index.ts"+printf '{"step":1}\n' >"${agent_state_dir}/workflow-recipes/.claude/plan-state.json"+printf '{"step":1}\n' >"${agent_state_dir}/workflow-recipes/src/.claude/plan-state.json"+printf '{"images":1}\n' >"${agent_state_dir}/deploy/minikube/.image-manifest.json"+# shellcheck source=/dev/null+agent_state_fp() { (source "$MARKER_SCRIPT" && pre_gate_marker_fingerprint_dir "${agent_state_dir}" "$1"); }+wr_before="$(agent_state_fp workflow-recipes)"+printf '{"step":2}\n' >"${agent_state_dir}/workflow-recipes/.claude/plan-state.json"+printf '{"step":2}\n' >"${agent_state_dir}/workflow-recipes/src/.claude/plan-state.json"+wr_after_state="$(agent_state_fp workflow-recipes)"+printf 'export const a = 2\n' >"${agent_state_dir}/workflow-recipes/src/index.ts"+wr_after_source="$(agent_state_fp workflow-recipes)"+deploy_before="$(agent_state_fp deploy)"+printf '{"images":2}\n' >"${agent_state_dir}/deploy/minikube/.image-manifest.json"+deploy_after="$(agent_state_fp deploy)"+if [[ "${wr_before}" =~ ^[0-9a-f]{40}$ && "${wr_before}" == "${wr_after_state}" ]]; then+ pass "pre-gate fingerprint ignores agent state under .claude/ directories"+else+ fail "pre-gate fingerprint changes when agent tooling rewrites .claude/ state (${wr_before} -> ${wr_after_state})"+fi+if [[ "${wr_after_source}" =~ ^[0-9a-f]{40}$ && "${wr_after_source}" != "${wr_after_state}" &&+ "${deploy_before}" =~ ^[0-9a-f]{40}$ && "${deploy_after}" != "${deploy_before}" ]]; then+ pass "pre-gate fingerprint still changes for source files and ignored deploy inputs"+else+ fail "pre-gate fingerprint no longer sees source or ignored deploy inputs"+fi+rm -rf "${agent_state_dir}"+control_api_migration_line="$(grep -nF 'run-control-api-db-migration.sh' "$SCRIPT" | head -n 1 | cut -d: -f1)"runtime_roles_line="$(grep -nF 'provision-control-api-runtime-roles.sh' "$SCRIPT" | head -n 1 | cut -d: -f1)"control_api_probe_restore_line="$(grep -nF ' restore_control_api' "$SCRIPT" | tail -n 1 | cut -d: -f1)"diff --git a/scripts/tests/test-minikube-t2-port-forward-refresh.sh b/scripts/tests/test-minikube-t2-port-forward-refresh.shindex 6643df24a..a34f6d8a9 100755--- a/scripts/tests/test-minikube-t2-port-forward-refresh.sh+++ b/scripts/tests/test-minikube-t2-port-forward-refresh.sh@@ -34,20 +34,97 @@ reset_case() {: >"$CALLS"}-# run_pre_gate records the sync only when it actually ran.+# run_pre_gate records the sync only when it actually ran, and after a sync it+# re-reads the marker pre-gate-sync stamped so the lanes attestation carries+# its cluster fingerprint.+SAVED_PROJECT_DIR="$T2_PROJECT_DIR"+T2_PROJECT_DIR="$WORK/project"+mkdir -p "$T2_PROJECT_DIR/workflow-recipes/src" "$T2_PROJECT_DIR/scripts/minikube"+printf 'export {}\n' >"$T2_PROJECT_DIR/workflow-recipes/src/index.ts"+printf '#!/usr/bin/env bash\n' >"$T2_PROJECT_DIR/scripts/minikube/t2.sh"+SOURCE_FP="$(pre_gate_marker_cluster_fingerprint "$T2_PROJECT_DIR")"+[[ "$SOURCE_FP" =~ ^[0-9a-f]{40}$ ]] || fail "fixture source fingerprint is not a digest: $SOURCE_FP"+T2_HEAD=pre-gate-fixture-head+T2_WORKTREE_ID=pre-gate-fixture-worktree+T2_PLAN_MODE=false+KC_CALLS="$WORK/kc-calls"+marker_json() {+ printf '{"data":{"clusterFingerprint":"%s","gitHead":"%s","worktreeId":"%s","imageSource":"local","imageTag":"fixture","imagesGeneratedAt":"2026-09-24T00:00:00Z"}}' \+ "$1" "$T2_HEAD" "$2"+}+FAKE_MARKER=''+t2_kc() {+ printf 'kc %s\n' "$*" >>"$KC_CALLS"+ case "$*" in+ *"get configmap"*) printf '%s' "$FAKE_MARKER" ;;+ *) printf 'unexpected kubectl call: %s\n' "$*" >&2; return 1 ;;+ esac+}+reset_pre_gate_case() {+ reset_case+ : >"$KC_CALLS"+ T2_PRE_GATE_SYNC_RAN=false+ T2_CLUSTER_FINGERPRINT=''+ T2_MARKER_MATCHES_HEAD=false+ T2_BOOTSTRAP_REQUIRED=false+}make() { printf 'make %s\n' "$*" >>"$CALLS"; }-reset_case-T2_PRE_GATE_SYNC_RAN=false+SYNC_CALL='make minikube-pre-gate-sync GATE=minikube-t2 ARGS=--skip-port-forwards'++# already-synced: no sync and no marker re-read.+reset_pre_gate_caseT2_PLAN_STATE=already-synced-run_pre_gate >/dev/null+run_pre_gate >"$WORK/skip.log"[[ "$T2_PRE_GATE_SYNC_RAN" == false && ! -s "$CALLS" && "$EVIDENCE_LOG" == 'pre-gate-sync=SKIPPED;' ]] ||fail "an already-synced plan recorded a sync: flag=${T2_PRE_GATE_SYNC_RAN} evidence=${EVIDENCE_LOG}"-reset_case-T2_PLAN_STATE=full-reconcile-run_pre_gate >/dev/null-[[ "$T2_PRE_GATE_SYNC_RAN" == true && "$(cat "$CALLS")" == 'make minikube-pre-gate-sync GATE=minikube-t2 ARGS=--skip-port-forwards' ]] ||- fail "a full-reconcile plan did not record its sync: flag=${T2_PRE_GATE_SYNC_RAN} calls=$(cat "$CALLS")"-unset -f make+[[ "$(cat "$WORK/skip.log")" == *'skipping pre-gate-sync'* && ! -s "$KC_CALLS" ]] ||+ fail "an already-synced plan re-read the marker: log=$(cat "$WORK/skip.log") kc=$(cat "$KC_CALLS")"++# targeted-sync, full-reconcile and full-bootstrap: the sync runs once and the+# marker it stamped is re-read, so the fingerprint is set for the attestation.+for plan_state in targeted-sync full-reconcile full-bootstrap; do+ reset_pre_gate_case+ T2_PLAN_STATE="$plan_state"+ # full-bootstrap starts with bootstrap pending; pre-gate-sync clears it.+ [[ "$plan_state" != full-bootstrap ]] || T2_BOOTSTRAP_REQUIRED=true+ FAKE_MARKER="$(marker_json "$SOURCE_FP" "$T2_WORKTREE_ID")"+ run_pre_gate >/dev/null+ [[ "$T2_PRE_GATE_SYNC_RAN" == true && "$(cat "$CALLS")" == "$SYNC_CALL" ]] ||+ fail "a ${plan_state} plan did not record its sync: flag=${T2_PRE_GATE_SYNC_RAN} calls=$(cat "$CALLS")"+ [[ "$(grep -c 'get configmap' "$KC_CALLS")" == 1 ]] ||+ fail "a ${plan_state} plan did not re-read the marker once: kc=$(cat "$KC_CALLS")"+ [[ "$T2_CLUSTER_FINGERPRINT" == "$SOURCE_FP" && "$T2_MARKER_MATCHES_HEAD" == true &&+ "$T2_BOOTSTRAP_REQUIRED" == false && "$EVIDENCE_LOG" == pre-gate-sync=PASS* ]] ||+ fail "a ${plan_state} plan left fingerprint='${T2_CLUSTER_FINGERPRINT}' matches=${T2_MARKER_MATCHES_HEAD} bootstrap=${T2_BOOTSTRAP_REQUIRED} evidence=${EVIDENCE_LOG}"+done++# A stamped marker that does not describe the current source fails the sync+# before its PASS evidence is written.+reset_pre_gate_case+T2_PLAN_STATE=targeted-sync+FAKE_MARKER="$(marker_json 0000000000000000000000000000000000000000 "$T2_WORKTREE_ID")"+if run_pre_gate >/dev/null 2>&1; then+ fail 'a sync whose marker carries a foreign fingerprint was accepted'+fi+[[ "$(cat "$CALLS")" == "$SYNC_CALL" && "$(grep -c 'get configmap' "$KC_CALLS")" == 1 ]] ||+ fail "the foreign-fingerprint case did not sync and re-read: calls=$(cat "$CALLS") kc=$(cat "$KC_CALLS")"+[[ "$T2_ERROR_CODE" == HEAD_MARKER_MISMATCH && -z "$T2_CLUSTER_FINGERPRINT" && "$EVIDENCE_LOG" == '' ]] ||+ fail "a foreign fingerprint returned ${T2_ERROR_CODE:-<empty>} fingerprint='${T2_CLUSTER_FINGERPRINT}' evidence=${EVIDENCE_LOG}"++# A marker stamped by another worktree keeps its ownership code: the re-read+# runs with errexit suspended and must not fall through to the digest check.+reset_pre_gate_case+T2_PLAN_STATE=targeted-sync+FAKE_MARKER="$(marker_json "$SOURCE_FP" another-worktree)"+if run_pre_gate >/dev/null 2>&1; then+ fail 'a sync whose marker belongs to another worktree was accepted'+fi+[[ "$(grep -c 'get configmap' "$KC_CALLS")" == 1 ]] ||+ fail "the ownership case did not re-read the marker: kc=$(cat "$KC_CALLS")"+[[ "$T2_ERROR_CODE" == PROFILE_OWNERSHIP_MISMATCH && -z "$T2_CLUSTER_FINGERPRINT" && "$EVIDENCE_LOG" == '' ]] ||+ fail "a foreign-owned marker returned ${T2_ERROR_CODE:-<empty>} fingerprint='${T2_CLUSTER_FINGERPRINT}' evidence=${EVIDENCE_LOG}"+unset -f make t2_kc+T2_PROJECT_DIR="$SAVED_PROJECT_DIR"# pre-gate-sync did not run (already-synced): the hold is not touched.reset_casediff --git a/scripts/tests/test-minikube-t2-scenarios.sh b/scripts/tests/test-minikube-t2-scenarios.shindex 37acafdf2..fe9494676 100755--- a/scripts/tests/test-minikube-t2-scenarios.sh+++ b/scripts/tests/test-minikube-t2-scenarios.sh@@ -335,26 +335,43 @@ already_state="$(env "${repo_env[@]}" T2_PROJECT_DIR="$repo" T2_BOOTSTRAP_REQUIRbash -c 'source "$1"; T2_ORIGIN_DEV="$2"; T2_HEAD="$3"; T2_BOOTSTRAP_REQUIRED=false; T2_MARKER_MATCHES_HEAD=true; t2_classify_transition; printf "%s" "$T2_PLAN_STATE"' bash "$COMMON" "$base_sha" "$infra_sha")"[ "$already_state" = already-synced ] || fail "matching marker selected $already_state instead of already-synced"+# The marker's clusterFingerprint is recomputed from the working tree, so a+# fixture marker must carry the real digest of the fixture repository.+source_fingerprint() {+ bash -c 'source "$1"; pre_gate_marker_cluster_fingerprint "$2"' bash \+ "$ROOT/scripts/minikube/pre-gate-marker.sh" "$repo"+}+# A new image acquisition can replace the digest while Git HEAD stays the# same. The marker must carry the manifest's generated stamp; otherwise the# planner would incorrectly choose already-synced/T2-runtime against the new# image set.stamp_manifest="$tmp/stamp-image-manifest.json"printf '{"generated":"new-generated","imageSource":"local","imageTag":"test","images":{"clerum/control-api:test":"sha256:0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"}}\n' >"$stamp_manifest"-stamp_state="$(env T2_PROJECT_DIR="$repo" MINIKUBE_PROFILE="$profile" \- T2_CONTEXT="$profile" CONTROL_API_REAL_PG_CONTEXT="$profile" \- T2_PROFILE_ROOT="$tmp/profiles" T2_PROFILE_ENV="$profile_root/profile.env" \- T2_PORTS_ENV="$profile_root/ports.env" T2_REQUIRED_DEPLOYMENTS=gfs/gfsc-reader \- T2_BRANCH=feat/scenario T2_HEAD="$feature_sha" T2_ORIGIN_DEV="$base_sha" \- T2_LOCK_ROOT="$tmp/locks" T2_EVIDENCE_ROOT="$tmp/evidence" \- T2_IMAGE_MANIFEST="$stamp_manifest" \- FAKE_MARKER='{"data":{"clusterFingerprint":"fp","gitHead":"'"$feature_sha"'","worktreeId":"worktree-a","imageSource":"local","imageTag":"test","imagesGeneratedAt":"old-generated"}}' \- bash -c 'source "$1"; T2_WORKTREE_ID=worktree-a; T2_HEAD="$3"; T2_ORIGIN_DEV="$2"; T2_PLAN_MODE=true; T2_BOOTSTRAP_REQUIRED=false; t2_kc(){ printf "%s" "$FAKE_MARKER"; }; t2_marker_check; t2_image_check; t2_classify_transition; printf "%s|%s" "$T2_PLAN_STATE" "$T2_PLAN_REASON"' bash "$COMMON" "$base_sha" "$feature_sha")"+stamp_fp="$(source_fingerprint)"+[[ "$stamp_fp" =~ ^[0-9a-f]{40}$ ]] || fail "fixture source fingerprint is not a digest: $stamp_fp"+stamp_plan() {+ env T2_PROJECT_DIR="$repo" MINIKUBE_PROFILE="$profile" \+ T2_CONTEXT="$profile" CONTROL_API_REAL_PG_CONTEXT="$profile" \+ T2_PROFILE_ROOT="$tmp/profiles" T2_PROFILE_ENV="$profile_root/profile.env" \+ T2_PORTS_ENV="$profile_root/ports.env" T2_REQUIRED_DEPLOYMENTS=gfs/gfsc-reader \+ T2_BRANCH=feat/scenario T2_HEAD="$feature_sha" T2_ORIGIN_DEV="$base_sha" \+ T2_LOCK_ROOT="$tmp/locks" T2_EVIDENCE_ROOT="$tmp/evidence" \+ T2_IMAGE_MANIFEST="$stamp_manifest" \+ FAKE_MARKER='{"data":{"clusterFingerprint":"'"$stamp_fp"'","gitHead":"'"$feature_sha"'","worktreeId":"worktree-a","imageSource":"local","imageTag":"test","imagesGeneratedAt":"'"$1"'"}}' \+ bash -c 'source "$1"; T2_WORKTREE_ID=worktree-a; T2_HEAD="$3"; T2_ORIGIN_DEV="$2"; T2_PLAN_MODE=true; T2_BOOTSTRAP_REQUIRED=false; t2_kc(){ printf "%s" "$FAKE_MARKER"; }; t2_marker_check; t2_image_check; t2_classify_transition; printf "%s|%s" "$T2_PLAN_STATE" "$T2_PLAN_REASON"' bash "$COMMON" "$base_sha" "$feature_sha"+}+stamp_state="$(stamp_plan old-generated)"case "$stamp_state" inalready-synced*) fail "a changed image acquisition was treated as already-synced: $stamp_state" ;;targeted-sync*|full-reconcile*) ;;*) fail "changed image acquisition selected an unexpected plan: $stamp_state" ;;esac+# Twin: the same marker with the current stamp is already-synced, so the case+# above flips on the image stamp and not on any other marker field.+stamp_current_state="$(stamp_plan new-generated)"+[ "${stamp_current_state%%|*}" = already-synced ] ||+ fail "a marker matching HEAD, source and image stamp selected $stamp_current_state"# A bootstrapped profile with an unready required deployment must not stop# the orchestrator planner before a transition exists (PROFILE_UNHEALTHY was@@ -443,6 +460,33 @@ plan_mode_head="$(env "${marker_env[@]}" T2_PLAN_MODE=true FAKE_MARKER='{"data":bash -c 'source "$1"; T2_WORKTREE_ID=worktree-a; T2_HEAD=feature; T2_PLAN_MODE=true; t2_kc(){ printf "%s" "$FAKE_MARKER"; }; t2_marker_check; printf "%s" "$T2_MARKER_MATCHES_HEAD"' bash "$COMMON")"[ "$plan_mode_head" = false ] || fail "planner mode still treated a stale marker as matching HEAD"+# A marker for the current HEAD is only current while the working tree still+# hashes to its clusterFingerprint. An agent or tool rewriting a hashed file+# after the stamp must not reach already-synced or a T2 verdict.+drift_fp="$(source_fingerprint)"+[[ "$drift_fp" =~ ^[0-9a-f]{40}$ ]] || fail "fixture source fingerprint is not a digest: $drift_fp"+drift_marker='{"data":{"clusterFingerprint":"'"$drift_fp"'","gitHead":"feature","worktreeId":"worktree-a","imageSource":"local","imageTag":"test","imagesGeneratedAt":"generated"}}'+marker_after_check() {+ env "${marker_env[@]}" T2_PLAN_MODE="$1" FAKE_MARKER="$drift_marker" \+ bash -c 'source "$1"; T2_WORKTREE_ID=worktree-a; T2_HEAD=feature; T2_PLAN_MODE="$2"; t2_kc(){ printf "%s" "$FAKE_MARKER"; }; t2_marker_check; printf "%s|%s|%s" "$T2_MARKER_MATCHES_HEAD" "$T2_CLUSTER_FINGERPRINT" "${T2_PLAN_REASON:-}"' bash "$COMMON" "$1"+}+# Guard: an untouched tree keeps the fast path and adopts the marker digest.+drift_guard="$(marker_after_check true)"+[ "$drift_guard" = "true|$drift_fp|" ] ||+ fail "a marker matching HEAD and the source fingerprint was not accepted: $drift_guard"++drift_file="$repo/control-api/agent-state.json"+printf '{"rewritten":true}\n' >"$drift_file"+drift_plan="$(marker_after_check true)"+[ "$drift_plan" = "false||source fingerprint changed since the pre-gate marker" ] ||+ fail "planner treated a marker whose source fingerprint drifted as current: $drift_plan"+expect_code HEAD_MARKER_MISMATCH source-fingerprint-drift source-fingerprint-drift \+ marker_after_check false+grep -Fq 'source fingerprint changed since the pre-gate marker' "$tmp/source-fingerprint-drift" ||+ fail 'source fingerprint drift did not name its cause'+rm "$drift_file"+[ "$(source_fingerprint)" = "$drift_fp" ] || fail 'fixture fingerprint did not return after removing the drift file'+# The bounded kubectl runner writes HARNESS_DEADLINE diagnostics to stderr.# They must remain outside the captured JSON so a valid exact-head marker keeps# the already-synced fast path.@@ -450,7 +494,7 @@ marker_stderr="$tmp/marker-deadline.stderr"marker_fast_path_status=0marker_fast_path="$(env "${marker_env[@]}" T2_PLAN_MODE=false \PATH="$fake_bin:$PATH" \- FAKE_MARKER='{"data":{"clusterFingerprint":"fp","gitHead":"feature","worktreeId":"worktree-a","imageSource":"local","imageTag":"test","imagesGeneratedAt":"generated"}}' \+ FAKE_MARKER="$drift_marker" \bash -c 'source "$1"; T2_WORKTREE_ID=worktree-a; T2_HEAD=feature; T2_PLAN_MODE=false; t2_marker_check; printf "%s" "$T2_MARKER_MATCHES_HEAD"' bash "$COMMON" 2>"$marker_stderr")" || marker_fast_path_status=$?if [ "$marker_fast_path_status" -ne 0 ] || [ "$marker_fast_path" != true ]; thenfail "stderr from the bounded marker read broke the valid-marker fast path (status=$marker_fast_path_status result=$marker_fast_path)"