Skip to content

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

TypeScript

fix(np08): make local evidence gates fail closed

Alfredo Lopezb073d5ed349c
diff --git a/.github/workflows/ci-public.yml b/.github/workflows/ci-public.yml
index 4b3b8f1a7..62f62a3e6 100644
--- a/.github/workflows/ci-public.yml
+++ b/.github/workflows/ci-public.yml
@@ -471,6 +471,9 @@ jobs:
- name: Test NP-08 Host clients have no v1 fallback
run: bash scripts/tests/test-np08-v1-reference-inventory.sh
+ - name: Test NP-08 deployed E2E cleanup and provenance guards
+ run: bash scripts/tests/test-np08-e2e-guards.sh
+
# ADMIN_PASSWORD is a required precondition of full-setup.sh Step 1 on the
# default (minimal) seed profile. Two cases in this harness execute the
# script against stubbed docker/minikube/kubectl, so without it they abort
diff --git a/scripts/e2e/_lib/np08-cleanup.sh b/scripts/e2e/_lib/np08-cleanup.sh
new file mode 100644
index 000000000..d2c907215
--- /dev/null
+++ b/scripts/e2e/_lib/np08-cleanup.sh
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+
+# Fail-closed residual check for the NP-08 service-to-service E2E. The caller
+# provides the existing `kctl` function and MCP_NS namespace; this helper never
+# prints object names or Secret values.
+
+np08_cleanup_check_residual() {
+ local resource="$1"
+ local label_selector="$2"
+ local residual
+
+ if ! residual="$(kctl -n "${MCP_NS}" get "${resource}" \
+ -l "${label_selector}" -o name 2>/dev/null)"; then
+ return 1
+ fi
+ [[ -z "${residual}" ]]
+}
+
+# Keep the original journey failure when cleanup succeeds. A cleanup failure
+# upgrades an otherwise successful journey to a generic failure, but never
+# turns an existing failure into success.
+np08_cleanup_final_status() {
+ local prior_status="$1"
+ local cleanup_status="$2"
+
+ if [[ "${cleanup_status}" -ne 0 ]]; then
+ printf '1'
+ else
+ printf '%s' "${prior_status}"
+ fi
+}
diff --git a/scripts/e2e/_lib/np08-provenance.sh b/scripts/e2e/_lib/np08-provenance.sh
new file mode 100644
index 000000000..d1a62012f
--- /dev/null
+++ b/scripts/e2e/_lib/np08-provenance.sh
@@ -0,0 +1,81 @@
+#!/usr/bin/env bash
+
+# Validate the complete pre-gate marker tuple. The marker JSON is passed as an
+# argument so callers can keep kubectl's response in memory without persisting
+# it or printing it.
+
+# Read the marker without ever converting an API/read error into an empty
+# payload. The caller supplies the existing `kctl` function; only the JSON
+# document is returned, never kubectl diagnostics or object contents on error.
+np08_read_sync_marker() {
+ local namespace="$1"
+ local name="$2"
+ local marker
+
+ if ! marker="$(kctl -n "${namespace}" get configmap "${name}" -o json 2>/dev/null)"; then
+ return 1
+ fi
+ [[ -n "${marker}" ]] || return 1
+ printf '%s' "${marker}"
+}
+
+np08_verify_sync_marker() {
+ local expected_worktree="$1"
+ local expected_head="$2"
+ local expected_cluster="$3"
+ local expected_infra="$4"
+ local expected_image_source="$5"
+ local expected_image_tag="$6"
+ local expected_images_generated_at="$7"
+ local marker_json="$8"
+
+ python3 - "${expected_worktree}" "${expected_head}" \
+ "${expected_cluster}" "${expected_infra}" \
+ "${expected_image_source}" "${expected_image_tag}" \
+ "${expected_images_generated_at}" "${marker_json}" <<'PY'
+import json
+import sys
+
+(
+ expected_worktree,
+ expected_head,
+ expected_cluster,
+ expected_infra,
+ expected_image_source,
+ expected_image_tag,
+ expected_images_generated_at,
+ marker_json,
+) = sys.argv[1:]
+
+if not expected_cluster or not expected_infra:
+ raise SystemExit("FAIL: current pre-gate fingerprints are unavailable")
+if not expected_worktree or not expected_head or not expected_image_source:
+ raise SystemExit("FAIL: current pre-gate identity is incomplete")
+if not expected_images_generated_at:
+ raise SystemExit("FAIL: current image acquisition timestamp is unavailable")
+if expected_image_source != "local" or expected_image_tag:
+ raise SystemExit("FAIL: NP-08 E2E requires the branch-owned local image coordinate")
+
+try:
+ payload = json.loads(marker_json)
+except (TypeError, json.JSONDecodeError) as exc:
+ raise SystemExit(f"FAIL: pre-gate marker is not valid JSON: {exc}") from exc
+if not isinstance(payload, dict) or not isinstance(payload.get("data"), dict):
+ raise SystemExit("FAIL: pre-gate marker has no data object")
+data = payload["data"]
+
+expected = {
+ "worktreeId": expected_worktree,
+ "gitHead": expected_head,
+ "clusterFingerprint": expected_cluster,
+ "infraFingerprint": expected_infra,
+ "imageSource": expected_image_source,
+ "imageTag": expected_image_tag,
+ "imagesGeneratedAt": expected_images_generated_at,
+}
+
+for key, value in expected.items():
+ if data.get(key) != value:
+ raise SystemExit(f"FAIL: pre-gate marker field mismatch: {key}")
+PY
+}
diff --git a/scripts/e2e/e2e-np08-hcc-authorization.sh b/scripts/e2e/e2e-np08-hcc-authorization.sh
index bfb0b3dca..9abe0d147 100755
--- a/scripts/e2e/e2e-np08-hcc-authorization.sh
+++ b/scripts/e2e/e2e-np08-hcc-authorization.sh
@@ -58,7 +58,7 @@ case "${context}" in
;;
esac
-for command_name in kubectl jq git shasum awk python3; do
+for command_name in kubectl jq git shasum awk python3 node; do
command -v "${command_name}" >/dev/null || {
echo "FAIL: required command missing: ${command_name}" >&2
exit 1
@@ -69,6 +69,15 @@ kctl() {
kubectl --context="${context}" "$@"
}
+# shellcheck source=scripts/minikube/pre-gate-marker.sh
+source "${PROJECT_DIR}/scripts/minikube/pre-gate-marker.sh"
+# shellcheck source=scripts/minikube/image-mode.sh
+source "${PROJECT_DIR}/scripts/minikube/image-mode.sh"
+# shellcheck source=scripts/e2e/_lib/np08-cleanup.sh
+source "${SCRIPT_DIR}/_lib/np08-cleanup.sh"
+# shellcheck source=scripts/e2e/_lib/np08-provenance.sh
+source "${SCRIPT_DIR}/_lib/np08-provenance.sh"
+
SYNC_CONFIGMAP="${CLERUM_PRE_GATE_SYNC_CONFIGMAP:-clerum-pre-gate-sync-state}"
PORTS_ENV="${CLERUM_PROFILE_PORTS_ENV:-${HOME}/.cache/clerum/minikube-profiles/${profile}/ports.env}"
@@ -98,31 +107,43 @@ verify_profile_ownership() {
verify_clean_and_sync_marker() {
local head worktree_id marker_json
+ local expected_cluster expected_infra expected_image_source expected_image_tag
+ local expected_images_generated_at
[[ -z "$(git -C "${PROJECT_DIR}" status --porcelain)" ]] || {
echo "FAIL: worktree is dirty; commit or restore before deployed NP-08 E2E" >&2
exit 1
}
head="$(git -C "${PROJECT_DIR}" rev-parse --verify HEAD)"
worktree_id="$(printf '%s' "${PROJECT_DIR}" | shasum | awk '{print $1}')"
- marker_json="$(kctl -n control-plane get configmap "${SYNC_CONFIGMAP}" -o json 2>/dev/null)" || {
+ marker_json="$(np08_read_sync_marker control-plane "${SYNC_CONFIGMAP}")" || {
echo "FAIL: pre-gate marker is missing: control-plane/${SYNC_CONFIGMAP}" >&2
exit 1
}
- python3 - "${worktree_id}" "${head}" "${marker_json}" <<'PY'
-import json
-import sys
-
-expected_worktree, expected_head, marker_json = sys.argv[1:]
-data = (json.loads(marker_json).get("data") or {})
-if not data.get("clusterFingerprint"):
- raise SystemExit("FAIL: pre-gate marker has no cluster fingerprint")
-if data.get("worktreeId") != expected_worktree:
- raise SystemExit("FAIL: pre-gate marker belongs to another worktree")
-if data.get("gitHead") != expected_head:
- raise SystemExit("FAIL: pre-gate marker does not match current HEAD")
-if data.get("imageSource") != "local":
- raise SystemExit("FAIL: pre-gate marker is not for local images")
-PY
+ if ! expected_cluster="$(pre_gate_marker_cluster_fingerprint "${PROJECT_DIR}")"; then
+ echo "FAIL: unable to compute current cluster fingerprint" >&2
+ exit 1
+ fi
+ if ! expected_infra="$(pre_gate_marker_infra_fingerprint "${PROJECT_DIR}")"; then
+ echo "FAIL: unable to compute current infrastructure fingerprint" >&2
+ exit 1
+ fi
+ if ! expected_image_source="$(image_mode_source "${PROJECT_DIR}")"; then
+ echo "FAIL: unable to resolve current image source" >&2
+ exit 1
+ fi
+ if ! expected_image_tag="$(image_mode_tag "${PROJECT_DIR}")"; then
+ echo "FAIL: unable to resolve current image tag" >&2
+ exit 1
+ fi
+ if ! expected_images_generated_at="$(image_mode_images_generated_at "${PROJECT_DIR}")"; then
+ echo "FAIL: unable to resolve current image acquisition timestamp" >&2
+ exit 1
+ fi
+ np08_verify_sync_marker \
+ "${worktree_id}" "${head}" \
+ "${expected_cluster}" "${expected_infra}" \
+ "${expected_image_source}" "${expected_image_tag}" \
+ "${expected_images_generated_at}" "${marker_json}"
}
MCP_NS='mcp-server'
@@ -145,7 +166,7 @@ verify_clean_and_sync_marker
cleanup() {
local status=$?
local cleanup_status=0
- local remove_patch residual context_contains_fixture context_a_json
+ local remove_patch context_contains_fixture context_a_json
set +e
if [[ "${fixture_context_patched:-0}" == 1 ]]; then
remove_patch="$(kctl -n "${MCP_NS}" get context "${CONTEXT_A}" -o json 2>/dev/null | jq -c --arg server "${SERVER_A}" '
@@ -174,15 +195,15 @@ cleanup() {
cleanup_status=1
fi
for resource in mcpserver secret context; do
- residual="$(kctl -n "${MCP_NS}" get "${resource}" -l "${OWNER_LABEL_KEY}=${OWNER_LABEL_VALUE},np08.evenfire/run=${RUN_ID}" -o name 2>/dev/null)"
- if [[ -n "${residual}" ]]; then
+ if ! np08_cleanup_check_residual "${resource}" \
+ "${OWNER_LABEL_KEY}=${OWNER_LABEL_VALUE},np08.evenfire/run=${RUN_ID}"; then
cleanup_status=1
fi
done
if [[ "${cleanup_status}" -ne 0 ]]; then
- status=1
echo 'FAIL: NP-08 E2E cleanup did not remove all owned fixtures' >&2
fi
+ status="$(np08_cleanup_final_status "${status}" "${cleanup_status}")"
if [[ "${status}" -eq 0 ]]; then
echo 'PASS: NP-08 deployed HCC authorization E2E'
else
diff --git a/scripts/minikube/pre-gate-marker.sh b/scripts/minikube/pre-gate-marker.sh
new file mode 100644
index 000000000..a8134311f
--- /dev/null
+++ b/scripts/minikube/pre-gate-marker.sh
@@ -0,0 +1,81 @@
+#!/usr/bin/env bash
+
+# Shared, side-effect-free provenance helpers for the Minikube pre-gate marker.
+# This file performs no Kubernetes, Docker, or network operation.
+
+pre_gate_marker_fingerprint_dir() {
+ local project_dir="$1"
+ local dir="$2"
+
+ if [[ ! -d "${project_dir}/${dir}" ]]; then
+ echo "missing"
+ return 0
+ fi
+
+ local digest
+ if ! digest="$(
+ set -o pipefail
+ find "${project_dir}/${dir}" \
+ -type f \
+ ! -path '*/node_modules/*' \
+ ! -path '*/dist/*' \
+ ! -path '*/.next/*' \
+ ! -path '*/playwright-report/*' \
+ ! -path '*/test-results/*' \
+ ! -path '*/coverage/*' \
+ -exec shasum {} + 2>/dev/null | sort | shasum | awk '{print $1}'
+ )"; then
+ return 1
+ fi
+ [[ "${digest}" =~ ^[0-9a-f]{40}$ ]] || return 1
+
+ printf '%s\n' "${digest}"
+}
+
+pre_gate_marker_fingerprint_dirs() {
+ local project_dir="$1"
+ shift
+ (( $# > 0 )) || return 1
+
+ local dir digest
+ if ! digest="$(
+ set -o pipefail
+ for dir in "$@"; do
+ pre_gate_marker_fingerprint_dir "${project_dir}" "${dir}" || exit 1
+ done | shasum | awk '{print $1}'
+ )"; then
+ return 1
+ fi
+ [[ "${digest}" =~ ^[0-9a-f]{40}$ ]] || return 1
+
+ printf '%s\n' "${digest}"
+}
+
+pre_gate_marker_cluster_fingerprint() {
+ local project_dir="$1"
+ pre_gate_marker_fingerprint_dirs "${project_dir}" \
+ control-api \
+ external-rest-api \
+ rpc-proxy \
+ mcp-host \
+ host-context-controller \
+ packages/workflow-runtime-core \
+ packages/network-policy-core \
+ workflow-recipes \
+ packages/workflow-sdk \
+ tests/e2e/fixtures/custom-workflow-coordinator \
+ channel-reader \
+ workflow-approval-request-reader \
+ control-ui \
+ deploy \
+ charts \
+ scripts/minikube
+}
+
+pre_gate_marker_infra_fingerprint() {
+ local project_dir="$1"
+ pre_gate_marker_fingerprint_dirs "${project_dir}" \
+ deploy \
+ charts \
+ scripts/minikube
+}
diff --git a/scripts/minikube/pre-gate-sync.sh b/scripts/minikube/pre-gate-sync.sh
index b8e38cbf5..04ef78cfc 100755
--- a/scripts/minikube/pre-gate-sync.sh
+++ b/scripts/minikube/pre-gate-sync.sh
@@ -57,6 +57,8 @@ log() {
# environment only for a cluster nothing has built or pulled into yet.
# shellcheck source=scripts/minikube/image-mode.sh
source "${SCRIPT_DIR}/image-mode.sh"
+# shellcheck source=scripts/minikube/pre-gate-marker.sh
+source "${SCRIPT_DIR}/pre-gate-marker.sh"
if ! IMAGE_SOURCE="$(image_mode_source "${PROJECT_DIR}")"; then
exit 1
@@ -164,25 +166,7 @@ restore_pre_gate_writers() {
trap restore_pre_gate_writers EXIT
fingerprint_dir() {
- local dir="$1"
-
- if [[ ! -d "${PROJECT_DIR}/${dir}" ]]; then
- echo "missing"
- return
- fi
-
- local digest
- digest="$(find "${PROJECT_DIR}/${dir}" \
- -type f \
- ! -path '*/node_modules/*' \
- ! -path '*/dist/*' \
- ! -path '*/.next/*' \
- ! -path '*/playwright-report/*' \
- ! -path '*/test-results/*' \
- ! -path '*/coverage/*' \
- -exec shasum {} + 2>/dev/null | sort | shasum | awk '{print $1}')"
-
- echo "${digest:-empty}"
+ pre_gate_marker_fingerprint_dir "${PROJECT_DIR}" "$1"
}
state_file_for() {
@@ -387,34 +371,14 @@ log "Evaluating sync requirements for ${GATE_NAME}"
log "Cluster images: ${IMAGE_SOURCE}${IMAGE_TAG:+ (${IMAGE_TAG})}; overlay $(basename "${PRE_GATE_RENDER_DIR}")"
preflight_host_lifecycle_probe
-cluster_fingerprint="$(
- {
- fingerprint_dir control-api
- fingerprint_dir external-rest-api
- fingerprint_dir rpc-proxy
- fingerprint_dir mcp-host
- fingerprint_dir host-context-controller
- fingerprint_dir packages/workflow-runtime-core
- fingerprint_dir packages/network-policy-core
- fingerprint_dir workflow-recipes
- fingerprint_dir packages/workflow-sdk
- fingerprint_dir tests/e2e/fixtures/custom-workflow-coordinator
- fingerprint_dir channel-reader
- fingerprint_dir workflow-approval-request-reader
- fingerprint_dir control-ui
- fingerprint_dir deploy
- fingerprint_dir charts
- fingerprint_dir scripts/minikube
- } | shasum | awk '{print $1}'
-)"
-
-infra_fingerprint="$(
- {
- fingerprint_dir deploy
- fingerprint_dir charts
- fingerprint_dir scripts/minikube
- } | shasum | awk '{print $1}'
-)"
+if ! cluster_fingerprint="$(pre_gate_marker_cluster_fingerprint "${PROJECT_DIR}")"; then
+ log "ERROR: unable to compute the cluster fingerprint; refusing to sync or stamp the marker"
+ exit 1
+fi
+if ! infra_fingerprint="$(pre_gate_marker_infra_fingerprint "${PROJECT_DIR}")"; then
+ log "ERROR: unable to compute the infrastructure fingerprint; refusing to sync or stamp the marker"
+ exit 1
+fi
cluster_changed=false
infra_changed=false
diff --git a/scripts/tests/test-minikube-pre-gate-probe-contract.sh b/scripts/tests/test-minikube-pre-gate-probe-contract.sh
index f56d8a407..c7d83ff9d 100755
--- a/scripts/tests/test-minikube-pre-gate-probe-contract.sh
+++ b/scripts/tests/test-minikube-pre-gate-probe-contract.sh
@@ -52,7 +52,7 @@ else
fi
probe_line="$(grep -n '^preflight_host_lifecycle_probe$' "$PARENT" | cut -d: -f1)"
-fingerprint_line="$(grep -n '^cluster_fingerprint=' "$PARENT" | cut -d: -f1)"
+fingerprint_line="$(grep -n 'cluster_fingerprint=.*pre_gate_marker_cluster_fingerprint' "$PARENT" | cut -d: -f1)"
if [ -n "$probe_line" ] && [ -n "$fingerprint_line" ] && [ "$probe_line" -lt "$fingerprint_line" ]; then
pass "probe preflight runs before package checks and cluster rebuild"
else
diff --git a/scripts/tests/test-minikube-pre-gate-shadow.sh b/scripts/tests/test-minikube-pre-gate-shadow.sh
index 3858c5faa..060a0ee97 100755
--- a/scripts/tests/test-minikube-pre-gate-shadow.sh
+++ b/scripts/tests/test-minikube-pre-gate-shadow.sh
@@ -937,7 +937,8 @@ assert_a_targeted_build_carries_the_recorded_coordinate_forward() {
assert_the_touched_scripts_parse() {
local f bad=""
- for f in scripts/minikube/image-mode.sh scripts/minikube/pre-gate-sync.sh \
+ for f in scripts/minikube/image-mode.sh scripts/minikube/pre-gate-marker.sh \
+ scripts/minikube/pre-gate-sync.sh \
scripts/minikube/pre-gate-incremental.sh scripts/minikube/build-images.sh \
scripts/tests/test-minikube-pre-gate-shadow.sh; do
bash -n "$REPO_ROOT/$f" || bad+="$f "
diff --git a/scripts/tests/test-minikube-pre-gate-sync-state.sh b/scripts/tests/test-minikube-pre-gate-sync-state.sh
index 6c0b133ae..ffd66b0f1 100755
--- a/scripts/tests/test-minikube-pre-gate-sync-state.sh
+++ b/scripts/tests/test-minikube-pre-gate-sync-state.sh
@@ -3,6 +3,7 @@ set -u
FAIL=0
SCRIPT="scripts/minikube/pre-gate-sync.sh"
+MARKER_SCRIPT="scripts/minikube/pre-gate-marker.sh"
RUNTIME_SCRIPT="scripts/minikube/pre-gate-runtime.sh"
INCREMENTAL_SCRIPT="scripts/minikube/pre-gate-incremental.sh"
REGISTRY_SCRIPT="scripts/minikube/deploy-evenfire-registry.sh"
@@ -25,6 +26,10 @@ incremental_contains() {
grep -Fq -- "$1" "$INCREMENTAL_SCRIPT"
}
+marker_contains() {
+ grep -Fq -- "$1" "$MARKER_SCRIPT"
+}
+
not_contains() {
! grep -Fq -- "$1" "$SCRIPT"
}
@@ -35,6 +40,12 @@ else
fail "pre-gate sync script has invalid bash syntax"
fi
+if bash -n "$MARKER_SCRIPT"; then
+ pass "shared pre-gate marker helper has valid bash syntax"
+else
+ fail "shared pre-gate marker helper has invalid bash syntax"
+fi
+
if bash -n "$INCREMENTAL_SCRIPT"; then
pass "incremental pre-gate helper has valid bash syntax"
else
@@ -165,7 +176,7 @@ else
fail "pre-gate runtime guard can confuse SIGPIPE or exec failure with a missing route"
fi
-if contains 'fingerprint_dir packages/workflow-runtime-core' &&
+if marker_contains 'packages/workflow-runtime-core' &&
contains 'run_if_changed packages/workflow-runtime-core "npm test && npm run build"' &&
contains 'ensure_artifact packages/workflow-runtime-core dist/index.js "npm run build"'; then
pass "pre-gate sync builds workflow-runtime-core before dependent package tests"
@@ -173,6 +184,29 @@ else
fail "pre-gate sync does not build workflow-runtime-core before dependent package tests"
fi
+marker_failure_dir="$(mktemp -d)"
+mkdir -p "${marker_failure_dir}/bin" "${marker_failure_dir}/repo/control-api"
+printf '#!/usr/bin/env bash\nexit 42\n' >"${marker_failure_dir}/bin/find"
+chmod +x "${marker_failure_dir}/bin/find"
+if (
+ # shellcheck source=/dev/null
+ source "$MARKER_SCRIPT"
+ PATH="${marker_failure_dir}/bin:${PATH}"
+ export PATH
+ pre_gate_marker_fingerprint_dir "${marker_failure_dir}/repo" control-api >/dev/null
+) || (
+ # shellcheck source=/dev/null
+ source "$MARKER_SCRIPT"
+ PATH="${marker_failure_dir}/bin:${PATH}"
+ export PATH
+ pre_gate_marker_cluster_fingerprint "${marker_failure_dir}/repo" >/dev/null
+); then
+ fail "shared pre-gate marker helper can turn a hashing failure into a valid fingerprint"
+else
+ pass "shared pre-gate marker helper propagates hashing failures instead of stamping empty input"
+fi
+rm -rf "${marker_failure_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-np08-e2e-guards.sh b/scripts/tests/test-np08-e2e-guards.sh
new file mode 100755
index 000000000..af67334b9
--- /dev/null
+++ b/scripts/tests/test-np08-e2e-guards.sh
@@ -0,0 +1,156 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
+E2E_SCRIPT="${ROOT}/scripts/e2e/e2e-np08-hcc-authorization.sh"
+
+# shellcheck source=scripts/e2e/_lib/np08-cleanup.sh
+source "${ROOT}/scripts/e2e/_lib/np08-cleanup.sh"
+# shellcheck source=scripts/e2e/_lib/np08-provenance.sh
+source "${ROOT}/scripts/e2e/_lib/np08-provenance.sh"
+
+MCP_NS='mcp-server'
+KCTL_RESULT='empty'
+
+kctl() {
+ case "${KCTL_RESULT}" in
+ empty)
+ return 0
+ ;;
+ residual)
+ printf '%s\n' 'mcpserver/owned-fixture'
+ return 0
+ ;;
+ error)
+ printf '%s\n' 'secret/owned-fixture'
+ printf '%s\n' 'simulated kubectl read error' >&2
+ return 42
+ ;;
+ *)
+ return 99
+ ;;
+ esac
+}
+
+pass() {
+ printf 'PASS: %s\n' "$1"
+}
+
+fail() {
+ printf 'FAIL: %s\n' "$1" >&2
+ exit 1
+}
+
+KCTL_RESULT='empty'
+np08_cleanup_check_residual mcpserver 'np08.evenfire/run=test' || \
+ fail 'an empty successful residual read failed cleanup'
+pass 'cleanup accepts an empty successful residual read'
+
+KCTL_RESULT='empty'
+set +e
+marker_output="$(np08_read_sync_marker control-plane marker 2>&1)"
+marker_rc=$?
+set -e
+if [[ "${marker_rc}" -eq 0 || -n "${marker_output}" ]]; then
+ fail 'an empty marker read was treated as a valid marker'
+fi
+pass 'provenance rejects an empty marker read without disclosure'
+
+KCTL_RESULT='error'
+set +e
+marker_output="$(np08_read_sync_marker control-plane marker 2>&1)"
+marker_rc=$?
+set -e
+if [[ "${marker_rc}" -eq 0 || -n "${marker_output}" ]]; then
+ fail 'a failed marker read was treated as a valid marker'
+fi
+pass 'provenance fails closed on a marker read error without disclosure'
+
+KCTL_RESULT='residual'
+set +e
+cleanup_output="$(np08_cleanup_check_residual mcpserver 'np08.evenfire/run=test' 2>&1)"
+cleanup_rc=$?
+set -e
+if [[ "${cleanup_rc}" -eq 0 ]]; then
+ fail 'a residual object was treated as clean'
+fi
+if [[ -n "${cleanup_output}" ]]; then
+ fail 'the residual check disclosed a resource name'
+fi
+pass 'cleanup rejects a residual object without disclosing it'
+
+KCTL_RESULT='error'
+set +e
+cleanup_output="$(np08_cleanup_check_residual secret 'np08.evenfire/run=test' 2>&1)"
+cleanup_rc=$?
+set -e
+if [[ "${cleanup_rc}" -eq 0 ]]; then
+ fail 'a failed residual read was treated as an empty result'
+fi
+if [[ -n "${cleanup_output}" ]]; then
+ fail 'the failed residual read emitted command or Secret output'
+fi
+pass 'cleanup fails closed on a read error without disclosure'
+
+if [[ "$(np08_cleanup_final_status 17 0)" != '17' ]]; then
+ fail 'successful cleanup erased the prior journey failure'
+fi
+if [[ "$(np08_cleanup_final_status 0 1)" != '1' ]]; then
+ fail 'cleanup failure did not fail an otherwise successful journey'
+fi
+if [[ "$(np08_cleanup_final_status 17 1)" != '1' ]]; then
+ fail 'cleanup failure did not preserve a failed overall result'
+fi
+pass 'cleanup preserves prior failures and promotes cleanup failures'
+
+marker_json() {
+ local cluster="$1"
+ local generated="$2"
+ printf '%s' "{\"data\":{\"worktreeId\":\"worktree-a\",\"gitHead\":\"head-a\",\"clusterFingerprint\":\"${cluster}\",\"infraFingerprint\":\"infra-a\",\"imageSource\":\"local\",\"imageTag\":\"\",\"imagesGeneratedAt\":\"${generated}\"}}"
+}
+
+exact_marker="$(marker_json 'cluster-a' '2026-08-17T12:54:11Z')"
+np08_verify_sync_marker \
+ 'worktree-a' 'head-a' 'cluster-a' 'infra-a' \
+ 'local' '' '2026-08-17T12:54:11Z' "${exact_marker}" || \
+ fail 'the exact provenance tuple was rejected'
+pass 'provenance accepts the exact marker tuple'
+
+if np08_verify_sync_marker \
+ 'worktree-a' 'head-a' 'cluster-current' 'infra-a' \
+ 'local' '' '2026-08-17T12:54:11Z' "${exact_marker}" >/dev/null 2>&1; then
+ fail 'a wrong but non-empty cluster fingerprint was accepted'
+fi
+pass 'provenance rejects a wrong cluster fingerprint'
+
+if np08_verify_sync_marker \
+ 'worktree-a' 'head-a' 'cluster-a' 'infra-a' \
+ 'local' '' '2026-08-17T13:00:00Z' "${exact_marker}" >/dev/null 2>&1; then
+ fail 'a stale image acquisition timestamp was accepted'
+fi
+pass 'provenance rejects a stale image acquisition timestamp'
+
+if np08_verify_sync_marker \
+ 'worktree-a' 'head-a' 'cluster-a' 'infra-a' \
+ 'local' '' '2026-08-17T12:54:11Z' 'not-json' >/dev/null 2>&1; then
+ fail 'a malformed marker read was accepted'
+fi
+pass 'provenance fails closed on a malformed marker read'
+
+if np08_verify_sync_marker \
+ 'worktree-a' 'head-a' 'cluster-a' 'infra-a' \
+ 'ghcr' 'v0.0.0' '2026-08-17T12:54:11Z' "${exact_marker}" >/dev/null 2>&1; then
+ fail 'the local-only NP-08 E2E accepted a non-local image coordinate'
+fi
+pass 'provenance rejects a non-local image coordinate'
+
+if ! grep -Fq 'np08_cleanup_check_residual' "${E2E_SCRIPT}" ||
+ ! grep -Fq 'np08_cleanup_final_status' "${E2E_SCRIPT}" ||
+ ! grep -Fq 'np08_read_sync_marker' "${E2E_SCRIPT}" ||
+ ! grep -Fq 'pre_gate_marker_cluster_fingerprint' "${E2E_SCRIPT}" ||
+ ! grep -Fq 'image_mode_images_generated_at' "${E2E_SCRIPT}" ||
+ ! grep -Fq 'np08_verify_sync_marker' "${E2E_SCRIPT}" ||
+ ! grep -Eq '^for command_name in .* node;' "${E2E_SCRIPT}"; then
+ fail 'the deployed E2E is not wired to every tested guard'
+fi
+pass 'the deployed E2E is wired to cleanup and provenance guards'