Skip to content

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

TypeScript

fix: harden secret and minikube test boundaries

Alfredo Lopez9530e2b47b8b
diff --git a/.cursor/skills/minikube-t0-t1-t2/SKILL.md b/.cursor/skills/minikube-t0-t1-t2/SKILL.md
index 032d470c5..bc6af46e0 100644
--- a/.cursor/skills/minikube-t0-t1-t2/SKILL.md
+++ b/.cursor/skills/minikube-t0-t1-t2/SKILL.md
@@ -44,6 +44,13 @@ Before running anything, verify ALL of these:
- [ ] Never read `~/.cache/clerum/minikube-profiles/` directly (HARD DENY —
it holds private profile state). The harness reads it for you.
+Shell contract-test rule: fixtures that exercise Git/lease state must use a
+temporary repository via `scripts/tests/lib/minikube-fixture-repo.sh`. Keep the
+real checkout as the script/Makefile source root, pass the temporary path as
+`T2_PROJECT_DIR`, and assert that the host checkout's HEAD, branch, and status
+are unchanged. Never create or restore a branch in the developer checkout to
+make a detached CI checkout testable.
+
## Step 1 — Plan (read-only)
```bash
diff --git a/.cursor/skills/minikube-t0-t1-t2/reference.md b/.cursor/skills/minikube-t0-t1-t2/reference.md
index c25b515ee..f628734ec 100644
--- a/.cursor/skills/minikube-t0-t1-t2/reference.md
+++ b/.cursor/skills/minikube-t0-t1-t2/reference.md
@@ -25,6 +25,11 @@ Companion to `SKILL.md`. Source of truth: `scripts/minikube/t2.sh`,
fixed localhost ports** — only the profile-owned random port mapping.
- **Do not touch another worktree's Minikube profile** (e.g. an NP-08 lane
profile) or kill its port-forwards, even if it looks idle.
+- **Do not mutate the test runner's Git checkout.** Minikube contract fixtures
+ that need a branch/HEAD must use the temporary-repository helper at
+ `scripts/tests/lib/minikube-fixture-repo.sh`, set `T2_PROJECT_DIR` to that
+ fixture, and prove the host checkout is unchanged. This is mandatory for
+ detached-head CI runs; restoring a branch in `trap cleanup` is not isolation.
- **Do not run mutating `build-images.sh` or `pull-images.sh` directly.** Use
the public Make target or T2 orchestrator so the exact
worktree/profile/context lease is inherited. Only `--verify-only` is
diff --git a/AGENTS.md b/AGENTS.md
index 043e92307..38e23d3a3 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -106,6 +106,17 @@ branch-owned Minikube profile and its explicit Kubernetes context. It is not a
production, GKE, Cloudflare, staging, shared-cluster, or customer-data
runbook.
+Shell contract tests for this tooling must be hermetic. They may source the
+real harness scripts from the checkout, but any fixture that needs Git state
+must use a temporary fixture repository (the shared helper is
+`scripts/tests/lib/minikube-fixture-repo.sh`) and point `T2_PROJECT_DIR` at
+that repository. Tests must never `git switch`, create branches, or restore
+HEAD in the developer checkout, including when CI checks out a detached HEAD.
+Each such fixture must assert that the host checkout's HEAD, branch, and
+working-tree status are unchanged on exit. The source checkout remains the
+Makefile/script root; the temporary repository is only the lease identity
+under test.
+
Use these canonical entry points:
```text
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 63275ff3e..41d8754c6 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.492",
+ "version": "0.1.493",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.492",
+ "version": "0.1.493",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/control-api/package.json b/control-api/package.json
index c57856d50..e27bd427d 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.492",
+ "version": "0.1.493",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/routes/admin/secrets.ts b/control-api/src/routes/admin/secrets.ts
index 623302d0f..70aff12ec 100644
--- a/control-api/src/routes/admin/secrets.ts
+++ b/control-api/src/routes/admin/secrets.ts
@@ -552,7 +552,40 @@ export function createAdminSecretsRouter(gateway: K8sGateway): Router {
res.status(400).json({ error: PLATFORM_MANAGED_SECRET_ERROR })
return
}
- const deleted = await gateway.deleteSecret(req.params.name, config.mcpServersNamespace)
+ const name = req.params.name.trim()
+ let existing: {
+ metadata?: { labels?: Record<string, string>; uid?: string; resourceVersion?: string }
+ } | null
+ try {
+ existing = (await gateway.getSecret(name, config.mcpServersNamespace)) as typeof existing
+ } catch (err) {
+ if (extractHttpStatus(err) === 404) {
+ res.status(404).json({ error: `Secret "${name}" not found` })
+ return
+ }
+ throw err
+ }
+ if (!existing) {
+ res.status(404).json({ error: `Secret "${name}" not found` })
+ return
+ }
+ if (existing.metadata?.labels?.[RECIPE_SECRET_LABEL_KEY] === RECIPE_SECRET_LABEL_VALUE) {
+ res.status(409).json({
+ error: `Secret "${name}" is owned by a WorkflowRecipe; delete it through /admin/recipe-secrets`,
+ })
+ return
+ }
+ const metadata = existing.metadata
+ const precondition =
+ metadata?.uid || metadata?.resourceVersion
+ ? {
+ ...(metadata.uid ? { uid: metadata.uid } : {}),
+ ...(metadata.resourceVersion ? { resourceVersion: metadata.resourceVersion } : {}),
+ }
+ : undefined
+ const deleted = precondition
+ ? await gateway.deleteSecret(name, config.mcpServersNamespace, precondition)
+ : await gateway.deleteSecret(name, config.mcpServersNamespace)
res.status(200).json(toPublicDeleteSecretSummary(deleted))
})
)
diff --git a/control-api/src/services/secretService.ts b/control-api/src/services/secretService.ts
index 8ed40554c..5800be328 100644
--- a/control-api/src/services/secretService.ts
+++ b/control-api/src/services/secretService.ts
@@ -71,6 +71,10 @@ export class SecretService {
name: s.metadata?.name,
namespace: s.metadata?.namespace,
labels: s.metadata?.labels || {},
+ // Listing is a metadata projection, not a write response. Preserve the
+ // existing annotation contract for catalog/recipe consumers while still
+ // excluding Secret data and stringData entirely.
+ annotations: s.metadata?.annotations || {},
},
type: s.type,
keys: Object.keys(s.data || {}).sort((a, b) => a.localeCompare(b)),
diff --git a/control-api/test/routes.mcpSecrets.test.ts b/control-api/test/routes.mcpSecrets.test.ts
index 9b19190ea..8304d7308 100644
--- a/control-api/test/routes.mcpSecrets.test.ts
+++ b/control-api/test/routes.mcpSecrets.test.ts
@@ -388,6 +388,44 @@ describe('DELETE /admin/mcp-secrets/:name', () => {
expect(ns).toBe('mcp-server')
})
+ it('refuses to delete a Secret owned by a WorkflowRecipe', async () => {
+ const gateway = createGateway()
+ gateway.getSecret.mockResolvedValueOnce({
+ metadata: {
+ name: 'recipe-creds',
+ namespace: 'mcp-server',
+ labels: { 'clerum.io/recipe-secret': 'true' },
+ },
+ })
+ const app = makeApp(gateway)
+
+ const res = await request(app).delete('/admin/mcp-secrets/recipe-creds').expect(409)
+
+ expect(res.body.error).toContain('WorkflowRecipe')
+ expect(gateway.deleteSecret).not.toHaveBeenCalled()
+ })
+
+ it('binds deletion to the object observed by the ownership check', async () => {
+ const gateway = createGateway()
+ gateway.getSecret.mockResolvedValueOnce({
+ metadata: {
+ name: 'versioned-creds',
+ namespace: 'mcp-server',
+ labels: {},
+ uid: 'secret-uid',
+ resourceVersion: '17',
+ },
+ })
+ const app = makeApp(gateway)
+
+ await request(app).delete('/admin/mcp-secrets/versioned-creds').expect(200)
+
+ expect(gateway.deleteSecret).toHaveBeenCalledWith('versioned-creds', 'mcp-server', {
+ uid: 'secret-uid',
+ resourceVersion: '17',
+ })
+ })
+
it('returns 500 when gateway.deleteSecret throws', async () => {
const gateway = createGateway()
gateway.deleteSecret.mockRejectedValueOnce(new Error('K8s API timeout'))
diff --git a/control-api/test/routes.secrets.platformPullSecretName.test.ts b/control-api/test/routes.secrets.platformPullSecretName.test.ts
index fc2f6536a..61e1241ab 100644
--- a/control-api/test/routes.secrets.platformPullSecretName.test.ts
+++ b/control-api/test/routes.secrets.platformPullSecretName.test.ts
@@ -149,6 +149,13 @@ describe('platform-managed Secret name is reserved', () => {
it('still deletes an ordinary connector Secret whose name merely resembles it', async () => {
const gateway = createGateway()
+ gateway.getSecret = vi.fn(async () => ({
+ metadata: {
+ name: `${EVENFIRE_REGISTRY_PULL_SECRET_NAME}-backup`,
+ namespace: 'mcp-server',
+ labels: {},
+ },
+ })) as never
await request(makeApp(gateway))
.delete(`/admin/mcp-secrets/${EVENFIRE_REGISTRY_PULL_SECRET_NAME}-backup`)
diff --git a/control-api/test/services.secretService.test.ts b/control-api/test/services.secretService.test.ts
index 024bd78e8..8217414c2 100644
--- a/control-api/test/services.secretService.test.ts
+++ b/control-api/test/services.secretService.test.ts
@@ -391,7 +391,7 @@ describe('SecretService — write responses are names-only', () => {
await expect(svc.deleteSecret('credentials', 'channels')).rejects.toThrow('delete rejected')
})
- it('omits annotations from the list projection', async () => {
+ it('preserves metadata annotations while omitting Secret values from the list projection', async () => {
coreApi.listNamespacedSecret.mockResolvedValue({
items: [
{
@@ -414,6 +414,7 @@ describe('SecretService — write responses are names-only', () => {
name: 'credentials',
namespace: 'channels',
labels: { owner: 'platform' },
+ annotations: { 'example.invalid/private': 'do-not-return' },
},
type: 'Opaque',
keys: ['caller-key'],
diff --git a/scripts/minikube/full-setup.sh b/scripts/minikube/full-setup.sh
index 63be04220..8f5afd3de 100755
--- a/scripts/minikube/full-setup.sh
+++ b/scripts/minikube/full-setup.sh
@@ -677,6 +677,84 @@ ensure_control_postgres_ready() {
return 1
}
+# A previous full-setup may have been interrupted after it fenced one or more
+# database writers. Read and validate that durable journal before the first
+# namespace/CRD/Secret mutation. If the journal is in an active recovery phase,
+# close all four writers again before the later recovery code resumes. The
+# journal is deliberately not advanced here: if this guard is interrupted, the
+# old phase remains conservative and the next run repeats the fence.
+guard_interrupted_writer_recovery() {
+ local state_helper="${SCRIPT_DIR}/writer-recovery-state.py"
+ local state_file="${PROJECT_DIR}/.local-notes/infra/runs/writer-recovery/${PROFILE}.json"
+ local state_output state_status=0 phase hcc_replicas workflow_replicas trace_replicas control_api_replicas state_head
+ local pods
+
+ [[ -f "${state_file}" ]] || return 0
+ [[ -f "${state_helper}" ]] || {
+ err "Durable writer-recovery state exists but its validator is missing; refusing profile mutation"
+ return 1
+ }
+ state_output="$(python3 "${state_helper}" read \
+ --path "${state_file}" \
+ --profile "${PROFILE}" \
+ --context "${T2_CONTEXT}" \
+ --worktree "${PROJECT_DIR}" \
+ --branch "${T2_BRANCH}" \
+ --head "${T2_HEAD}" \
+ --include-head)" || state_status=$?
+ if [ "${state_status}" -ne 0 ]; then
+ err "Unable to validate durable writer-recovery state before cluster mutation (status ${state_status})"
+ return 1
+ fi
+ [[ "${state_output}" == NONE ]] && return 0
+
+ IFS='|' read -r phase hcc_replicas workflow_replicas trace_replicas \
+ control_api_replicas state_head <<<"${state_output}"
+ [[ "${phase}" == planned ]] && return 0
+ [[ "${phase}" =~ ^(hcc-fencing|hcc-fenced|workflow-fencing|workflow-fenced|trace-fencing|trace-fenced|api-fencing|api-fenced|policy-ready|roles-ready|api-restoring|api-restored|overlay-applying|overlay-applied)$ ]] || {
+ err "Durable writer-recovery state has an unsupported phase before cluster mutation: ${phase}"
+ return 1
+ }
+ [[ "${hcc_replicas}" =~ ^[0-9]+$ ]] &&
+ [[ "${workflow_replicas}" =~ ^[0-9]+$ ]] &&
+ [[ "${trace_replicas}" =~ ^[0-9]+$ ]] &&
+ [[ "${control_api_replicas}" =~ ^[1-9][0-9]*$ ]] || {
+ err "Durable writer-recovery state has invalid replica counts; refusing profile mutation"
+ return 1
+ }
+
+ log "Resuming interrupted writer recovery from phase ${phase} (recorded HEAD ${state_head}) — fencing all writers before setup mutations"
+ $KC -n control-plane scale deployment/host-context-controller --replicas=0 >/dev/null
+ pods="$($KC -n control-plane get pods -l app=host-context-controller -o name)" || return 1
+ [ -z "${pods}" ] || $KC -n control-plane wait --for=delete pod \
+ -l app=host-context-controller --timeout=180s >/dev/null
+
+ $KC -n control-plane scale deployment/workflow-recipes --replicas=0 >/dev/null
+ pods="$($KC -n control-plane get pods -l app=workflow-recipes -o name)" || return 1
+ [ -z "${pods}" ] || $KC -n control-plane wait --for=delete pod \
+ -l app=workflow-recipes --timeout=180s >/dev/null
+
+ $KC -n control-plane scale deployment/trace-maintenance-worker --replicas=0 >/dev/null
+ [ "$($KC -n control-plane get deployment/trace-maintenance-worker \
+ -o 'jsonpath={.spec.replicas}')" = 0 ] || {
+ err "trace-maintenance-worker did not converge to zero before setup mutation"
+ return 1
+ }
+ pods="$($KC -n control-plane get pods -l app=trace-maintenance-worker -o name)" || return 1
+ [ -z "${pods}" ] || $KC -n control-plane wait --for=delete pod \
+ -l app=trace-maintenance-worker --timeout=180s >/dev/null
+ pods="$($KC -n control-plane get pods -l app=trace-maintenance-worker -o name)" || return 1
+ [ -z "${pods}" ] || {
+ err "trace-maintenance-worker pods remain after the pre-mutation fence"
+ return 1
+ }
+
+ $KC -n control-plane scale deployment/control-api --replicas=0 >/dev/null
+ pods="$($KC -n control-plane get pods -l 'app=control-api,!clerum.io/component' -o name)" || return 1
+ [ -z "${pods}" ] || $KC -n control-plane wait --for=delete pod \
+ -l 'app=control-api,!clerum.io/component' --timeout=180s >/dev/null
+}
+
# ======================================================================
# Step 1: Preconditions
# ======================================================================
@@ -795,6 +873,11 @@ fi
ok "Cluster '${PROFILE}' is reachable"
maybe_exit_after_cluster_step
+# This is intentionally after the profile becomes reachable but before the
+# first setup apply. A stopped profile may be started safely; an active journal
+# must be fenced before any workload/configuration mutation.
+guard_interrupted_writer_recovery || exit 1
+
t2_profile_status
t2_context_check
t2_profile_context_identity_check
diff --git a/scripts/minikube/port-forward-owner.sh b/scripts/minikube/port-forward-owner.sh
index 0a82716c8..12f71c2a9 100755
--- a/scripts/minikube/port-forward-owner.sh
+++ b/scripts/minikube/port-forward-owner.sh
@@ -324,29 +324,73 @@ pf_owner_record_process() {
pf_owner_cleanup_record() {
local pidfile="$1" profile="$2" context="$3" worktree="$4"
local namespace="$5" service="$6" local_port="$7" remote_port="$8"
- local pid state actual_start command_line attempts delay index
+ local pid state actual_start command_line attempts delay index structured_record=false
pf_owner_validate_binding "${profile}" "${context}" "${worktree}" \
"${namespace}" "${service}" "${local_port}" "${remote_port}" || return 1
[[ -e "${pidfile}" || -L "${pidfile}" ]] || return 0
[[ ! -L "${pidfile}" ]] ||
pf_owner_error "refusing to inspect or remove a symlinked pidfile: ${pidfile}" || return 1
- IFS= read -r pid <"${pidfile}" ||
- pf_owner_error "refusing to remove an empty pidfile: ${pidfile}" || return 1
+ # A structured profile record must be validated before its PID state is used.
+ # A dead PID is not proof that the record belongs to this lane: deleting it
+ # first would erase the only durable evidence of an ownership conflict. The
+ # legacy /tmp record is removable only when it is demonstrably dead; it has
+ # no metadata with which a live process could be adopted safely.
+ if grep -Fqx "PORT_FORWARD_OWNER_VERSION=${PF_OWNER_RECORD_VERSION}" "${pidfile}"; then
+ structured_record=true
+ pf_owner_read_record "${pidfile}" || return 1
+ pf_owner_record_matches "${profile}" "${context}" "${worktree}" \
+ "${namespace}" "${service}" "${local_port}" "${remote_port}" ||
+ pf_owner_error "pidfile belongs to a different profile, context, worktree, service, or port binding" || return 1
+ pid="${PF_OWNER_RECORD_PID}"
+ else
+ case "${pidfile}" in
+ /tmp/pf-*.pid) ;;
+ *) pf_owner_error "refusing to remove an unstructured canonical pidfile: ${pidfile}"; return 1 ;;
+ esac
+ IFS= read -r pid <"${pidfile}" ||
+ pf_owner_error "refusing to remove an empty pidfile: ${pidfile}" || return 1
+ fi
pf_owner_validate_pid "${pid}" ||
pf_owner_error "refusing to remove a pidfile without a numeric PID: ${pidfile}" || return 1
state="$(pf_owner_process_state "${pid}")"
case "${state}" in
dead)
+ # Re-read the record and prove the PID is still dead immediately before
+ # removal. This closes the PID-reuse/replacement window for stale records.
+ if [[ "${structured_record}" == true ]]; then
+ pf_owner_read_record "${pidfile}" || return 1
+ pf_owner_record_matches "${profile}" "${context}" "${worktree}" \
+ "${namespace}" "${service}" "${local_port}" "${remote_port}" ||
+ pf_owner_error "dead pidfile changed ownership before cleanup" || return 1
+ [[ "${PF_OWNER_RECORD_PID}" == "${pid}" ]] ||
+ pf_owner_error "dead pidfile PID changed before cleanup" || return 1
+ else
+ local reread_pid
+ IFS= read -r reread_pid <"${pidfile}" ||
+ pf_owner_error "dead legacy pidfile disappeared before cleanup: ${pidfile}" || return 1
+ [[ "${reread_pid}" == "${pid}" ]] ||
+ pf_owner_error "dead legacy pidfile PID changed before cleanup" || return 1
+ fi
+ state="$(pf_owner_process_state "${pid}")"
+ [[ "${state}" == dead ]] ||
+ pf_owner_error "pid ${pid} became live before stale-record cleanup; leaving ${pidfile}" || return 1
pf_owner_reap_process "${pid}"
pf_owner_remove_dead_record "${pidfile}"
return
;;
- live) ;;
+ live)
+ [[ "${structured_record}" == true ]] || {
+ pf_owner_error "refusing to adopt or signal live legacy pidfile: ${pidfile}"
+ return 1
+ }
+ ;;
*) pf_owner_error "cannot establish whether PID ${pid} is live; leaving ${pidfile}"; return 1 ;;
esac
+ # The structured record was validated before the state probe. Re-read it for
+ # the live path so a concurrent replacement cannot be mistaken for the owner.
pf_owner_read_record "${pidfile}" || return 1
pf_owner_record_matches "${profile}" "${context}" "${worktree}" \
"${namespace}" "${service}" "${local_port}" "${remote_port}" ||
diff --git a/scripts/minikube/t2-common.sh b/scripts/minikube/t2-common.sh
index 4b2bf3d71..c674fd144 100755
--- a/scripts/minikube/t2-common.sh
+++ b/scripts/minikube/t2-common.sh
@@ -429,8 +429,20 @@ t2_profile_status() {
}
t2_marker_check() {
- T2_MARKER_JSON="$(t2_kc -n "$T2_CONTROL_NAMESPACE" get configmap "$T2_MARKER_NAME" -o json 2>/dev/null || true)"
- if [ -z "$T2_MARKER_JSON" ]; then
+ local marker_probe marker_status=0
+ # `--ignore-not-found` makes an absent marker an explicit empty-object
+ # result. Preserve every other kubectl failure: a timeout, RBAC denial, or
+ # transport error must never be reclassified as bootstrap permission.
+ marker_probe="$(t2_kc -n "$T2_CONTROL_NAMESPACE" get configmap "$T2_MARKER_NAME" \
+ -o json --ignore-not-found 2>&1)" || marker_status=$?
+ if [ "$marker_status" -ne 0 ]; then
+ T2_NEXT_COMMAND='verify the explicit branch-owned Kubernetes context and retry the read-only preflight'
+ t2_fail PROFILE_UNHEALTHY \
+ "unable to read pre-gate marker (kubectl status ${marker_status}): ${marker_probe}"
+ return 1
+ fi
+ T2_MARKER_JSON="$marker_probe"
+ if [ -z "$T2_MARKER_JSON" ] || [ "$T2_MARKER_JSON" = '{}' ]; then
T2_BOOTSTRAP_REQUIRED=true
[ -n "$T2_PLAN_STATE" ] || T2_PLAN_STATE=full-bootstrap
[ -n "$T2_PLAN_REASON" ] || T2_PLAN_REASON='pre-gate marker is missing'
diff --git a/scripts/tests/lib/minikube-fixture-repo.sh b/scripts/tests/lib/minikube-fixture-repo.sh
new file mode 100644
index 000000000..836f1e7bc
--- /dev/null
+++ b/scripts/tests/lib/minikube-fixture-repo.sh
@@ -0,0 +1,64 @@
+#!/usr/bin/env bash
+
+# Shared fixture repository boundary for Minikube shell tests. Tests may source
+# this file from a checked-out worktree, but all Git operations performed by the
+# fixture live under the caller-provided temporary directory.
+
+minikube_test_fixture_repo_init() {
+ local host_root="$1"
+ local fixture_root="$2"
+ local repo="${fixture_root}/repo"
+
+ MINIKUBE_TEST_HOST_ROOT="$(cd -- "${host_root}" && pwd -P)"
+ MINIKUBE_TEST_HOST_HEAD="$(git -C "${MINIKUBE_TEST_HOST_ROOT}" rev-parse --verify HEAD)"
+ MINIKUBE_TEST_HOST_BRANCH="$(git -C "${MINIKUBE_TEST_HOST_ROOT}" branch --show-current)"
+ MINIKUBE_TEST_HOST_STATUS_HASH="$({ git -C "${MINIKUBE_TEST_HOST_ROOT}" status --porcelain=v1 || true; } | shasum -a 256 | awk '{print $1}')"
+
+ mkdir -p "${repo}"
+ git init -q "${repo}"
+ git -C "${repo}" config user.email [email protected]
+ git -C "${repo}" config user.name minikube-fixture
+ printf 'fixture\n' >"${repo}/README.md"
+ git -C "${repo}" add README.md
+ git -C "${repo}" commit -qm fixture
+ git -C "${repo}" branch -M test/minikube-fixture
+ git -C "${repo}" remote add origin https://github.com/evenfire-ai/evenfire.git
+ git -C "${repo}" update-ref refs/remotes/origin/dev HEAD
+
+ 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)"
+ 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}" \
+ "${MINIKUBE_TEST_HEAD}" "${MINIKUBE_TEST_PROFILE:-fake}" \
+ "${MINIKUBE_TEST_CONTEXT:-${MINIKUBE_TEST_PROFILE:-fake}}" |
+ shasum | awk '{print $1}')"
+
+ 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
+}
+
+minikube_test_assert_host_unchanged() {
+ local current_head current_branch current_status_hash
+ current_head="$(git -C "${MINIKUBE_TEST_HOST_ROOT}" rev-parse --verify HEAD)"
+ current_branch="$(git -C "${MINIKUBE_TEST_HOST_ROOT}" branch --show-current)"
+ current_status_hash="$({ git -C "${MINIKUBE_TEST_HOST_ROOT}" status --porcelain=v1 || true; } | shasum -a 256 | awk '{print $1}')"
+
+ [[ "${current_head}" == "${MINIKUBE_TEST_HOST_HEAD}" ]] || {
+ printf 'fixture mutated the host checkout HEAD: %s != %s\n' \
+ "${current_head}" "${MINIKUBE_TEST_HOST_HEAD}" >&2
+ return 1
+ }
+ [[ "${current_branch}" == "${MINIKUBE_TEST_HOST_BRANCH}" ]] || {
+ printf 'fixture mutated the host checkout branch: %s != %s\n' \
+ "${current_branch}" "${MINIKUBE_TEST_HOST_BRANCH}" >&2
+ return 1
+ }
+ [[ "${current_status_hash}" == "${MINIKUBE_TEST_HOST_STATUS_HASH}" ]] || {
+ printf 'fixture mutated the host checkout working tree\n' >&2
+ return 1
+ }
+}
diff --git a/scripts/tests/test-minikube-mutation-boundary.sh b/scripts/tests/test-minikube-mutation-boundary.sh
index 28bb209b8..64a1c8839 100755
--- a/scripts/tests/test-minikube-mutation-boundary.sh
+++ b/scripts/tests/test-minikube-mutation-boundary.sh
@@ -3,15 +3,18 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd -P)"
TMP_DIR="$(mktemp -d)"
-T2_TEST_RESTORE_DETACHED=false
-T2_TEST_HEAD=""
-T2_TEST_BRANCH=""
+source "${ROOT}/scripts/tests/lib/minikube-fixture-repo.sh"
+
+MINIKUBE_TEST_PROFILE="boundary-profile"
+MINIKUBE_TEST_CONTEXT="boundary-profile"
+minikube_test_fixture_repo_init "${ROOT}" "${TMP_DIR}"
cleanup() {
- if [[ "${T2_TEST_RESTORE_DETACHED}" == true ]]; then
- git -C "${ROOT}" switch --quiet --detach "${T2_TEST_HEAD}" || true
- git -C "${ROOT}" branch -D "${T2_TEST_BRANCH}" >/dev/null 2>&1 || true
+ local status=$?
+ if ! minikube_test_assert_host_unchanged; then
+ status=1
fi
rm -rf "${TMP_DIR}"
+ return "${status}"
}
trap cleanup EXIT
@@ -22,19 +25,12 @@ LOCK_DIR="${LOCK_ROOT}/${PROFILE}.lock"
LOG="${TMP_DIR}/mutations.log"
mkdir -p "${LOCK_DIR}"
-BRANCH="$(git -C "${ROOT}" branch --show-current)"
-HEAD="$(git -C "${ROOT}" rev-parse --verify HEAD)"
-if [[ -z "${BRANCH}" ]]; then
- BRANCH="${GITHUB_HEAD_REF:-detached-ci-test}"
- git -C "${ROOT}" switch --quiet --create "${BRANCH}" "${HEAD}"
- T2_TEST_HEAD="${HEAD}"
- T2_TEST_BRANCH="${BRANCH}"
- T2_TEST_RESTORE_DETACHED=true
-fi
-WORKTREE_ID="$(printf '%s' "${ROOT}" | shasum | awk '{print $1}')"
-LOCK_KEY="$(printf '%s\0%s\0%s\0%s\0%s' "${ROOT}" "${BRANCH}" "${HEAD}" "${PROFILE}" "${PROFILE}" | shasum | awk '{print $1}')"
+BRANCH="${MINIKUBE_TEST_BRANCH}"
+HEAD="${MINIKUBE_TEST_HEAD}"
+WORKTREE_ID="${MINIKUBE_TEST_WORKTREE_ID}"
+LOCK_KEY="${MINIKUBE_TEST_LOCK_KEY}"
cat >"${LOCK_DIR}/owner.env" <<EOF
-REPOSITORY=${ROOT}
+REPOSITORY=${MINIKUBE_TEST_PROJECT_DIR}
BRANCH=${BRANCH}
HEAD=${HEAD}
PROFILE=${PROFILE}
@@ -62,7 +58,7 @@ dry_run_make() {
run_child() {
local status
- if T2_PROJECT_DIR="${ROOT}" T2_PROFILE="${PROFILE}" T2_CONTEXT="${PROFILE}" \
+ if T2_PROJECT_DIR="${MINIKUBE_TEST_PROJECT_DIR}" T2_PROFILE="${PROFILE}" T2_CONTEXT="${PROFILE}" \
T2_LOCK_ROOT="${LOCK_ROOT}" T2_LOCK_TOKEN="${TOKEN}" \
bash "${ROOT}/scripts/minikube/require-t2-mutation-lock.sh"; then
printf 'mutation\n' >>"${LOG}"
@@ -80,7 +76,7 @@ run_child
exit 1
}
-if T2_PROJECT_DIR="${ROOT}" T2_PROFILE="${PROFILE}" T2_CONTEXT="${PROFILE}" \
+if T2_PROJECT_DIR="${MINIKUBE_TEST_PROJECT_DIR}" T2_PROFILE="${PROFILE}" T2_CONTEXT="${PROFILE}" \
T2_LOCK_ROOT="${LOCK_ROOT}" T2_LOCK_TOKEN=wrong-token \
bash "${ROOT}/scripts/minikube/require-t2-mutation-lock.sh" >/dev/null 2>&1; then
echo 'FAIL: random token was accepted by the child mutation boundary' >&2
@@ -91,7 +87,7 @@ fi
exit 1
}
-if T2_PROJECT_DIR="${ROOT}" T2_PROFILE="${PROFILE}" T2_CONTEXT=wrong-context \
+if T2_PROJECT_DIR="${MINIKUBE_TEST_PROJECT_DIR}" T2_PROFILE="${PROFILE}" T2_CONTEXT=wrong-context \
T2_LOCK_ROOT="${LOCK_ROOT}" T2_LOCK_TOKEN="${TOKEN}" \
bash "${ROOT}/scripts/minikube/require-t2-mutation-lock.sh" >/dev/null 2>&1; then
echo 'FAIL: profile/context mismatch was accepted by the child mutation boundary' >&2
diff --git a/scripts/tests/test-minikube-port-forward-owner.sh b/scripts/tests/test-minikube-port-forward-owner.sh
index 72458fac9..7238a0e30 100755
--- a/scripts/tests/test-minikube-port-forward-owner.sh
+++ b/scripts/tests/test-minikube-port-forward-owner.sh
@@ -182,6 +182,25 @@ cleanup_record || fail 'dead legacy pidfile was not cleaned'
[[ ! -s "${KILL_LOG}" ]] || fail 'dead legacy cleanup sent a signal'
pass 'dead stale pidfiles are removed without signalling'
+reset_process_fixture
+write_record 'profile-b'
+printf 'dead\n' >"${STATE_FILE}"
+if cleanup_record >"${TMP_ROOT}/dead-foreign.out" 2>&1; then
+ fail 'dead foreign structured pidfile was removed instead of rejected'
+fi
+[[ -f "${RECORD}" ]] || fail 'dead foreign structured pidfile lost its ownership evidence'
+pass 'dead foreign structured records fail closed and remain durable'
+
+reset_process_fixture
+printf '%s\nPROCESS_START=%s\n' "${PID}" "${RECORDED_START}" >"${RECORD}"
+chmod 600 "${RECORD}"
+printf 'dead\n' >"${STATE_FILE}"
+if cleanup_record >"${TMP_ROOT}/dead-canonical-legacy.out" 2>&1; then
+ fail 'dead unstructured canonical pidfile was removed instead of rejected'
+fi
+[[ -f "${RECORD}" ]] || fail 'dead unstructured canonical pidfile lost its evidence'
+pass 'dead unstructured canonical records fail closed'
+
reset_process_fixture
write_record
pf_owner_record_process_matches "${RECORD}" "${PROFILE}" "${CONTEXT}" \
diff --git a/scripts/tests/test-minikube-sync-auth-key-durable.sh b/scripts/tests/test-minikube-sync-auth-key-durable.sh
index 62e269ee4..a30c97c99 100755
--- a/scripts/tests/test-minikube-sync-auth-key-durable.sh
+++ b/scripts/tests/test-minikube-sync-auth-key-durable.sh
@@ -3,15 +3,16 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
TMP_DIR="$(mktemp -d)"
-T2_TEST_RESTORE_DETACHED=false
-T2_TEST_HEAD=""
-T2_TEST_BRANCH=""
+source "${ROOT}/scripts/tests/lib/minikube-fixture-repo.sh"
+
+minikube_test_fixture_repo_init "${ROOT}" "${TMP_DIR}"
cleanup() {
- if [[ "${T2_TEST_RESTORE_DETACHED}" == true ]]; then
- git -C "${ROOT}" switch --quiet --detach "${T2_TEST_HEAD}" || true
- git -C "${ROOT}" branch -D "${T2_TEST_BRANCH}" >/dev/null 2>&1 || true
+ local status=$?
+ if ! minikube_test_assert_host_unchanged; then
+ status=1
fi
rm -rf "${TMP_DIR}"
+ return "${status}"
}
trap cleanup EXIT
@@ -29,18 +30,13 @@ T2_LOCK_ROOT="${TMP_DIR}/locks"
T2_LOCK_TOKEN='auth-sync-test-token'
T2_LOCK_DIR="${T2_LOCK_ROOT}/fake.lock"
T2_PROCESS_START=unavailable
-T2_TEST_BRANCH="$(git -C "${ROOT}" branch --show-current)"
-T2_TEST_HEAD="$(git -C "${ROOT}" rev-parse --verify HEAD)"
-if [[ -z "${T2_TEST_BRANCH}" ]]; then
- T2_TEST_BRANCH="${GITHUB_HEAD_REF:-detached-ci-test}"
- git -C "${ROOT}" switch --quiet --create "${T2_TEST_BRANCH}" "${T2_TEST_HEAD}"
- T2_TEST_RESTORE_DETACHED=true
-fi
-T2_TEST_WORKTREE_ID="$(printf '%s' "${ROOT}" | shasum | awk '{print $1}')"
-T2_TEST_LOCK_KEY="$(printf '%s\0%s\0%s\0%s\0%s' "${ROOT}" "${T2_TEST_BRANCH}" "${T2_TEST_HEAD}" fake fake | shasum | awk '{print $1}')"
+T2_TEST_BRANCH="${MINIKUBE_TEST_BRANCH}"
+T2_TEST_HEAD="${MINIKUBE_TEST_HEAD}"
+T2_TEST_WORKTREE_ID="${MINIKUBE_TEST_WORKTREE_ID}"
+T2_TEST_LOCK_KEY="${MINIKUBE_TEST_LOCK_KEY}"
mkdir -p "${T2_LOCK_DIR}"
cat >"${T2_LOCK_DIR}/owner.env" <<EOF
-REPOSITORY=${ROOT}
+REPOSITORY=${MINIKUBE_TEST_PROJECT_DIR}
BRANCH=${T2_TEST_BRANCH}
HEAD=${T2_TEST_HEAD}
PROFILE=fake
@@ -51,7 +47,7 @@ TOKEN=${T2_LOCK_TOKEN}
PID=$$
PROCESS_START=${T2_PROCESS_START}
EOF
-export T2_PROJECT_DIR="${ROOT}" T2_PROFILE=fake T2_CONTEXT=fake T2_LOCK_ROOT T2_LOCK_TOKEN
+export T2_PROJECT_DIR="${MINIKUBE_TEST_PROJECT_DIR}" T2_PROFILE=fake T2_CONTEXT=fake T2_LOCK_ROOT T2_LOCK_TOKEN
# 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 d6e369086..f7f085094 100755
--- a/scripts/tests/test-minikube-sync-auth-key.sh
+++ b/scripts/tests/test-minikube-sync-auth-key.sh
@@ -3,13 +3,16 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/../.." && pwd)"
TMP_DIR="$(mktemp -d)"
-T2_TEST_RESTORE_DETACHED=false
+source "${ROOT}/scripts/tests/lib/minikube-fixture-repo.sh"
+
+minikube_test_fixture_repo_init "${ROOT}" "${TMP_DIR}"
cleanup() {
- if [[ "${T2_TEST_RESTORE_DETACHED}" == true ]]; then
- git -C "${ROOT}" switch --quiet --detach "${T2_TEST_HEAD}" || true
- git -C "${ROOT}" branch -D "${T2_TEST_BRANCH}" >/dev/null 2>&1 || true
+ local status=$?
+ if ! minikube_test_assert_host_unchanged; then
+ status=1
fi
rm -rf "${TMP_DIR}"
+ return "${status}"
}
trap cleanup EXIT
@@ -27,22 +30,13 @@ T2_LOCK_ROOT="${TMP_DIR}/locks"
T2_LOCK_TOKEN='auth-sync-test-token'
T2_LOCK_DIR="${T2_LOCK_ROOT}/fake.lock"
T2_PROCESS_START=unavailable
-# GitHub Actions checks out a detached commit. The fixture still needs a
-# non-empty logical lane name because the production lease contract rejects
-# owner records without a branch identity; use the PR source ref when it is
-# available and a test-only identity otherwise.
-T2_TEST_HEAD="$(git -C "${ROOT}" rev-parse --verify HEAD)"
-T2_TEST_BRANCH="$(git -C "${ROOT}" branch --show-current)"
-if [[ -z "${T2_TEST_BRANCH}" ]]; then
- T2_TEST_BRANCH="${GITHUB_HEAD_REF:-detached-ci-test}"
- git -C "${ROOT}" switch --quiet --create "${T2_TEST_BRANCH}" "${T2_TEST_HEAD}"
- T2_TEST_RESTORE_DETACHED=true
-fi
-T2_TEST_WORKTREE_ID="$(printf '%s' "${ROOT}" | shasum | awk '{print $1}')"
-T2_TEST_LOCK_KEY="$(printf '%s\0%s\0%s\0%s\0%s' "${ROOT}" "${T2_TEST_BRANCH}" "${T2_TEST_HEAD}" fake fake | shasum | awk '{print $1}')"
+T2_TEST_HEAD="${MINIKUBE_TEST_HEAD}"
+T2_TEST_BRANCH="${MINIKUBE_TEST_BRANCH}"
+T2_TEST_WORKTREE_ID="${MINIKUBE_TEST_WORKTREE_ID}"
+T2_TEST_LOCK_KEY="${MINIKUBE_TEST_LOCK_KEY}"
mkdir -p "${T2_LOCK_DIR}"
cat >"${T2_LOCK_DIR}/owner.env" <<EOF
-REPOSITORY=${ROOT}
+REPOSITORY=${MINIKUBE_TEST_PROJECT_DIR}
BRANCH=${T2_TEST_BRANCH}
HEAD=${T2_TEST_HEAD}
PROFILE=fake
@@ -53,7 +47,7 @@ TOKEN=${T2_LOCK_TOKEN}
PID=$$
PROCESS_START=${T2_PROCESS_START}
EOF
-export T2_PROJECT_DIR="${ROOT}" T2_PROFILE=fake T2_CONTEXT=fake T2_LOCK_ROOT T2_LOCK_TOKEN
+export T2_PROJECT_DIR="${MINIKUBE_TEST_PROJECT_DIR}" T2_PROFILE=fake T2_CONTEXT=fake T2_LOCK_ROOT T2_LOCK_TOKEN
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 fe7daddbe..2c8ec0a33 100755
--- a/scripts/tests/test-minikube-t2-contract.sh
+++ b/scripts/tests/test-minikube-t2-contract.sh
@@ -23,6 +23,7 @@ for file in "$MINIKUBE_DIR/profile-readiness.sh" "$ROOT/scripts/tests/test-minik
"$ROOT/scripts/minikube/settle-gfs-reader-rollout.sh" \
"$ROOT/scripts/minikube/wait-gfs-reader-ready.sh" \
"$ROOT/scripts/minikube/gfs-rollout-shim/kubectl" \
+ "$ROOT/scripts/tests/lib/minikube-fixture-repo.sh" \
"$ROOT/scripts/tests/test-minikube-t2-public-boundary.sh" \
"$ROOT/scripts/tests/test-minikube-t2-scenarios.sh" \
"$ROOT/scripts/tests/test-minikube-settle-gfs-reader-rollout.sh" \
diff --git a/scripts/tests/test-minikube-t2-scenarios.sh b/scripts/tests/test-minikube-t2-scenarios.sh
index 5a00d5e17..0c730ed39 100755
--- a/scripts/tests/test-minikube-t2-scenarios.sh
+++ b/scripts/tests/test-minikube-t2-scenarios.sh
@@ -227,6 +227,12 @@ expect_code PROFILE_OWNERSHIP_MISMATCH marker-ownership marker-ownership \
env "${marker_env[@]}" FAKE_MARKER='{"data":{"clusterFingerprint":"fp","gitHead":"feature","worktreeId":"worktree-b","imageSource":"local","imageTag":"test"}}' \
bash -c 'source "$1"; T2_WORKTREE_ID=worktree-a; T2_HEAD=feature; t2_kc(){ printf "%s" "$FAKE_MARKER"; }; t2_marker_check' bash "$COMMON"
+missing_marker_state="$(env "${marker_env[@]}" bash -c 'source "$1"; T2_WORKTREE_ID=worktree-a; T2_HEAD=feature; t2_kc(){ printf "%s" "{}"; }; t2_marker_check; printf "%s" "$T2_PLAN_STATE"' bash "$COMMON")"
+[ "$missing_marker_state" = full-bootstrap ] || fail "empty marker selected $missing_marker_state instead of full-bootstrap"
+
+expect_code PROFILE_UNHEALTHY marker-read-timeout marker-read-timeout \
+ env "${marker_env[@]}" bash -c 'source "$1"; T2_WORKTREE_ID=worktree-a; T2_HEAD=feature; t2_kc(){ return 124; }; t2_marker_check' bash "$COMMON"
+
manifest="$tmp/image-manifest.json"
printf '{"imageSource":"local","imageTag":"new"}\n' >"$manifest"
expect_code IMAGE_MANIFEST_MISMATCH stale-image stale-image \