Skip to content

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

TypeScript

fix(branch-profile): create a never-created profile named by MINIKUBE_PROFILE (#1001)

Alfredo Lopezb2fb6389d22d
diff --git a/.cursor/rules/minikube-t0-t1-t2.mdc b/.cursor/rules/minikube-t0-t1-t2.mdc
index 8aa4a34e3..54a62dd9c 100644
--- a/.cursor/rules/minikube-t0-t1-t2.mdc
+++ b/.cursor/rules/minikube-t0-t1-t2.mdc
@@ -121,7 +121,9 @@ packages legitimately have none), then re-enter `make minikube-t2` on the
same HEAD/profile. `PROFILE_METADATA_MISSING` surfaces as
`PROFILE_OWNERSHIP_MISMATCH`: restore `profile.env` or stop and ask
(`scripts/minikube-profiles/branch.mk` never regenerates metadata for an
-existing profile directory), never invent ports. Do not edit tracked files while `make minikube-t2`
+existing profile directory), never invent ports. A never-created profile
+has no directory: run `branch-profile-start` (an explicit `MINIKUBE_PROFILE`
+must equal this branch's derived name), then retry. Do not edit tracked files while `make minikube-t2`
is running: T0 fixtures fail with `fixture mutated the host checkout
working tree`, and T2 refuses a dirty tree (`DEVELOPMENT_SCOPE_REQUIRED`).
diff --git a/.cursor/skills/minikube-t0-t1-t2/reference.md b/.cursor/skills/minikube-t0-t1-t2/reference.md
index fe60d8e6a..56acedad8 100644
--- a/.cursor/skills/minikube-t0-t1-t2/reference.md
+++ b/.cursor/skills/minikube-t0-t1-t2/reference.md
@@ -134,7 +134,11 @@ probes, treating Error 127 as GFS/`PROFILE_UNHEALTHY`.
when the profile directory does not exist; it never regenerates metadata for
an existing directory, derived or adopted, and the helper refuses with
`PROFILE_METADATA_MISSING`. Restore `profile.env` from a backup or stop and
-ask. Never invent ports or `ls`/`cat` `~/.cache/clerum/minikube-profiles/`.
+ask. When the directory does not exist the profile was never created: the T2
+hint names `branch-profile-start`, which creates it, also with an explicit
+`MINIKUBE_PROFILE` equal to this branch's derived name; any other explicit
+name is refused with `PROFILE_NOT_FOUND`. Never invent ports or `ls`/`cat`
+`~/.cache/clerum/minikube-profiles/`.
## Stable failure codes
@@ -143,7 +147,7 @@ ask. Never invent ports or `ls`/`cat` `~/.cache/clerum/minikube-profiles/`.
| `LOCAL_DEPENDENCY_MISSING` | Node/package-local dependencies, Python, Docker, kubectl, Minikube, or another required local tool is unavailable. T1 preflight (`packages=2`) only checks `control-api` and `gfs-controller` for host `vitest`+`pg`. | Repair the named local prerequisite (`npm ci` in that package). Then `npm ci` every remaining pre-gate package in the Host npm section before re-entering T2. The preflight never auto-installs and never covers `external-rest-api` / `rpc-proxy` / `mcp-host` / … |
| `minikube-pre-gate-sync` Error 127 / `sh: vitest: command not found` | Host `npm test` in a `run_if_changed` package after planner PASS and Ready deployments. **Not** a T2 stable code. | `npm ci` the named dir **and every remaining** pre-gate package, then `make minikube-t2` on the same HEAD/profile. Not GFS, not a new profile. |
| `UNSUPPORTED_T1_CONCURRENCY` | A caller attempted more than one T1 worker. | Remove the override or set `VITEST_MAX_WORKERS=1`; T1 role/fixture mutation is serial by contract. |
-| `PROFILE_OWNERSHIP_MISMATCH` | Profile metadata, context, worktree, or branch does not match this lane. Includes wrapped `PROFILE_METADATA_MISSING` (unreadable `profile.env` / ports). | Resolve through this worktree's `scripts/minikube-profiles/branch.mk` helper. When metadata is missing for an existing profile directory, restore `profile.env` or stop and ask: `branch-profile-start` creates metadata only for a directory that does not exist. Never invent ports, adopt a foreign profile, or `ls`/`cat` `~/.cache/clerum/minikube-profiles/`. |
+| `PROFILE_OWNERSHIP_MISMATCH` | Profile metadata, context, worktree, or branch does not match this lane. Includes wrapped `PROFILE_METADATA_MISSING` (unreadable `profile.env` / ports). | Resolve through this worktree's `scripts/minikube-profiles/branch.mk` helper. When metadata is missing for an existing profile directory, restore `profile.env` or stop and ask: `branch-profile-start` creates metadata only for a directory that does not exist. A never-created profile (no directory) is created by `branch-profile-start`. Never invent ports, adopt a foreign profile, or `ls`/`cat` `~/.cache/clerum/minikube-profiles/`. |
| `PROFILE_LOCK_REQUIRED` | A mutating child did not inherit the exact parent lease. | Invoke the public Make target/orchestrator; do not fabricate or bypass its lock token. |
| `DOCKER_ENDPOINT_REQUIRED` / `DOCKER_ENDPOINT_UNSAFE` / `DOCKER_ENDPOINT_MISMATCH` | Docker did not resolve exactly one approved local endpoint, or isolation selected a different endpoint. | Select a local Docker Desktop/rootless context or set an explicit local `DOCKER_HOST`; do not weaken the endpoint check. |
| `DOCKER_CONFIG_REQUIRED` / `REGISTRY_AUTH_REQUIRED` | A Docker operation lacks its empty task-local config, or a private pull lacks an explicit readable auth config. | Use the canonical Make/orchestrator path; for a genuinely private source, pass only the intended config directory through `MINIKUBE_DOCKER_AUTH_CONFIG`. |
diff --git a/docs/deploy/minikube.md b/docs/deploy/minikube.md
index d68f1db62..0aba64c01 100644
--- a/docs/deploy/minikube.md
+++ b/docs/deploy/minikube.md
@@ -280,6 +280,7 @@ An unreadable list is a refusal, never an empty list.
| `HOST must be 127.0.0.1` | branch-profile forwards bind only `127.0.0.1` |
| `CACHE_ROOT ...` | the profile cache root is unscoped, a symlink, not a directory, or contains a control character |
| `PROFILE_METADATA_MISSING` | `profile.env` of an existing profile is missing or unreadable; it is never regenerated |
+| `PROFILE_NOT_FOUND: explicit profile ... was never created` | `MINIKUBE_PROFILE` names a profile that does not exist and is not this branch's derived profile; `branch-profile-start` creates only the derived one |
| `PROFILE_PORTS_MISSING`, `PROFILE_PORTS_INVALID` | `ports.env` is missing or disagrees with its port base and `HOST` |
| `BRANCH_PROFILE_KUBECONFIG_UNREADABLE` | the kubeconfig contexts cannot be read |
| `BRANCH_PROFILE_CONTEXT_DANGLING` | the profile's context has no resolvable cluster or no server |
diff --git a/scripts/minikube-profiles/branch-profile.sh b/scripts/minikube-profiles/branch-profile.sh
index 7bc272745..25925ff4f 100755
--- a/scripts/minikube-profiles/branch-profile.sh
+++ b/scripts/minikube-profiles/branch-profile.sh
@@ -261,7 +261,7 @@ apply_resolution() {
}
resolve_profile() {
- local output status=0 identity_output
+ local output status=0 identity_output explicit_never_created=false
local -a resolve_args=(
resolve
--repo-dir "${REPO_DIR}"
@@ -277,15 +277,26 @@ resolve_profile() {
apply_resolution "${output}"
return 0
fi
+ # profile-owner.sh reports an explicit profile without profile.env as
+ # PROFILE_METADATA_MISSING whether or not its directory exists. A profile
+ # that was never created has no directory: it takes the derived creation
+ # path below, provided the explicit name is this branch's derived profile
+ # (#1001).
+ if [[ "${output}" == *PROFILE_METADATA_MISSING:* && -n "${EXPLICIT_PROFILE}" &&
+ "${EXPLICIT_PROFILE}" =~ ^clerum-[a-z0-9][a-z0-9._-]*$ &&
+ ! -e "${CACHE_ROOT}/${EXPLICIT_PROFILE}" && ! -L "${CACHE_ROOT}/${EXPLICIT_PROFILE}" ]]; then
+ explicit_never_created=true
+ fi
# Missing metadata for an existing profile directory has one safe next step.
# branch-profile-start only creates metadata when the directory does not
# exist, so pointing at it here would send the operator into this refusal
# again, or, without the explicit selection, into a brand-new profile.
- if [[ "${output}" == *PROFILE_METADATA_MISSING:* ]]; then
+ if [[ "${output}" == *PROFILE_METADATA_MISSING:* && "${explicit_never_created}" != true ]]; then
printf '%s\n' "${output}" >&2
die "PROFILE_METADATA_MISSING: profile metadata for ${EXPLICIT_PROFILE:-this branch} is missing or unreadable; restore profile.env from a backup or stop and ask. branch-profile-start only creates metadata when the profile directory does not exist and never regenerates it for an existing one"
fi
- if [[ -n "${EXPLICIT_PROFILE}" || ${status} -ne 3 || "${output}" != *PROFILE_NOT_FOUND:* ]]; then
+ if [[ "${explicit_never_created}" != true ]] &&
+ [[ -n "${EXPLICIT_PROFILE}" || ${status} -ne 3 || "${output}" != *PROFILE_NOT_FOUND:* ]]; then
printf '%s\n' "${output}" >&2
die 'profile ownership resolution failed closed'
fi
@@ -300,6 +311,9 @@ resolve_profile() {
PROFILE="$(record_value "${identity_output}" PROFILE)"
[[ "${PROFILE_SCHEMA_VERSION}" == 2 && "${CREATED_HEAD}" == "${HEAD}" ]] ||
die 'stable identity output is incomplete'
+ if [[ "${explicit_never_created}" == true && "${PROFILE}" != "${EXPLICIT_PROFILE}" ]]; then
+ die "PROFILE_NOT_FOUND: explicit profile ${EXPLICIT_PROFILE} was never created and is not this branch's profile (${PROFILE}); run branch-profile-start without MINIKUBE_PROFILE to create ${PROFILE}"
+ fi
[[ "${WORKTREE_ID}" =~ ^[0-9a-f]{40}$ && "${OWNER_ID}" =~ ^[0-9a-f]{40}$ ]] ||
die 'stable identity output is malformed'
validate_profile_name
diff --git a/scripts/minikube/t2-common.sh b/scripts/minikube/t2-common.sh
index 45b6c096a..8a68c5902 100755
--- a/scripts/minikube/t2-common.sh
+++ b/scripts/minikube/t2-common.sh
@@ -351,7 +351,12 @@ t2_profile_scope() {
"$T2_PROJECT_DIR" "$T2_BRANCH" "$T2_PROFILE"; then
case "$PROFILE_OWNER_ERROR_CODE" in
PROFILE_METADATA_MISSING)
- T2_NEXT_COMMAND='restore profile.env from a backup or stop and ask; the branch profile helper never regenerates metadata for an existing profile directory' ;;
+ # A profile that was never created has no directory to restore (#1001).
+ if [ ! -e "$(dirname -- "$T2_PROFILE_ENV")" ]; then
+ T2_NEXT_COMMAND='the profile was never created; run make -f scripts/minikube-profiles/branch.mk branch-profile-start, then retry'
+ else
+ T2_NEXT_COMMAND='restore profile.env from a backup or stop and ask; the branch profile helper never regenerates metadata for an existing profile directory'
+ fi ;;
PROFILE_PORTS_MISSING)
T2_NEXT_COMMAND='restore the persisted profile-owned ports.env; never regenerate adopted ports' ;;
PROFILE_PORTS_INVALID)
diff --git a/scripts/tests/test-branch-profile-lifecycle.sh b/scripts/tests/test-branch-profile-lifecycle.sh
index aa8af1335..53567138d 100755
--- a/scripts/tests/test-branch-profile-lifecycle.sh
+++ b/scripts/tests/test-branch-profile-lifecycle.sh
@@ -1177,6 +1177,42 @@ assert_log_has 'kubectl config get-contexts -o name' 'start of a brand-new profi
assert_log_lacks 'minikube profile list' 'start of a brand-new profile must not need minikube profile list'
assert_log_has "minikube start -p ${profile} --keep-context" 'start of a brand-new profile ran minikube start'
+# An explicit MINIKUBE_PROFILE that names this branch's derived profile before
+# that profile was ever created takes the same creation path as the derived
+# selection (#1001). The profile directory is set aside so it does not exist.
+mv "${profile_dir}" "${tmp}/branch-profile-aside"
+reset_state
+write_kube_contexts '' ''
+write_minikube_profiles
+bp explicit-new-profile-start start "MINIKUBE_PROFILE=${profile}"
+assert_rc 0 'explicit start of the never-created branch profile'
+assert_output_lacks 'PROFILE_METADATA_MISSING' 'explicit start of the never-created branch profile is not refused'
+# Witnesses: the metadata was created and minikube started the named profile.
+assert_file "${profile_dir}/profile.env" 'explicit start of the never-created branch profile writes profile.env'
+assert_file "${profile_dir}/ports.env" 'explicit start of the never-created branch profile writes ports.env'
+assert_log_has "minikube start -p ${profile} --keep-context" \
+ 'explicit start of the never-created branch profile ran minikube start'
+rm -rf "${profile_dir:?}"
+
+# An explicit name that was never created and is not this branch's derived
+# profile has no owner to prove, so it is refused before minikube or kubectl.
+other_profile=clerum-not-this-branch-0123abcd
+reset_state
+write_kube_contexts '' ''
+write_minikube_profiles
+bp explicit-foreign-new-profile-start start "MINIKUBE_PROFILE=${other_profile}"
+assert_rc 1 'explicit start of a never-created profile that is not this branch'
+# Witness: the refusal names both profiles.
+assert_output_has "PROFILE_NOT_FOUND: explicit profile ${other_profile} was never created and is not this branch's profile (${profile})" \
+ 'explicit start of a never-created foreign profile names the derived profile'
+assert_output_lacks 'restore profile.env from a backup' \
+ 'a never-created foreign profile is not told to restore a backup'
+assert_no_file "${cache_root}/${other_profile}" 'a never-created foreign profile is not created'
+assert_no_file "${profile_dir}" 'a never-created foreign profile does not create the branch profile'
+assert_log_lacks 'minikube' 'a never-created foreign profile must not reach minikube'
+assert_log_lacks 'kubectl --context=' 'a never-created foreign profile must not address a cluster'
+mv "${tmp}/branch-profile-aside" "${profile_dir}"
+
# A stopped profile minikube knows is started, after the profile list read.
reset_state
printf '{"invalid":[],"valid":[{"Name":"%s","Status":"Stopped"}]}\n' "${profile}" \
diff --git a/scripts/tests/test-minikube-t2-scenarios.sh b/scripts/tests/test-minikube-t2-scenarios.sh
index 5b7861ef2..0f85eb5f6 100755
--- a/scripts/tests/test-minikube-t2-scenarios.sh
+++ b/scripts/tests/test-minikube-t2-scenarios.sh
@@ -105,9 +105,33 @@ expect_code DEVELOPMENT_SCOPE_REQUIRED protected-branch protected-branch \
env "${repo_env[@]}" bash -c 'git -C "$T2_PROJECT_DIR" switch -q main; source "$1"; t2_repo_metadata' bash "$COMMON"
git -C "$repo" switch -q feat/scenario
+# Every t2_profile_scope refusal below runs t2_repo_metadata first. Without it
+# the branch is unset and every case is refused earlier, with the same code,
+# as "branch is empty or malformed"; each case therefore also asserts its own
+# message.
+# The profile directory exists without profile.env: restore it or stop and ask.
missing_profile_env=("${repo_env[@]}" T2_PROFILE_ENV="$tmp/missing-profile.env")
expect_code PROFILE_OWNERSHIP_MISMATCH missing-profile missing-profile \
- env "${missing_profile_env[@]}" bash -c 'source "$1"; t2_profile_scope' bash "$COMMON"
+ env "${missing_profile_env[@]}" bash -c 'source "$1"; t2_repo_metadata; t2_profile_scope' bash "$COMMON"
+grep -Fq 'next: restore profile.env from a backup or stop and ask' "$tmp/missing-profile" ||
+ { cat "$tmp/missing-profile" >&2; fail 'missing profile.env in an existing directory did not name the restore step'; }
+
+# A profile that was never created has no directory, so there is nothing to
+# restore: the next step is to create it (#1001).
+never_created_env=("${repo_env[@]}" T2_PROFILE_ENV="$tmp/profiles/never-created/profile.env"
+ T2_PORTS_ENV="$tmp/profiles/never-created/ports.env")
+expect_code PROFILE_OWNERSHIP_MISMATCH never-created-profile never-created-profile \
+ env "${never_created_env[@]}" bash -c 'source "$1"; t2_repo_metadata; t2_profile_scope' bash "$COMMON"
+grep -Fq 'next: the profile was never created; run make -f scripts/minikube-profiles/branch.mk branch-profile-start, then retry' \
+ "$tmp/never-created-profile" ||
+ { cat "$tmp/never-created-profile" >&2; fail 'a never-created profile did not name branch-profile-start as the next step'; }
+# Witness for the negative assertion below: the refusal came from the
+# profile.env check, not from an earlier one.
+grep -Fq 'PROFILE_OWNERSHIP_MISMATCH: profile.env' "$tmp/never-created-profile" ||
+ { cat "$tmp/never-created-profile" >&2; fail 'the never-created refusal did not come from the profile.env check'; }
+if grep -Fq 'restore profile.env' "$tmp/never-created-profile"; then
+ fail 'a never-created profile was told to restore profile.env'
+fi
expect_code DEVELOPMENT_SCOPE_REQUIRED shared-profile shared-profile \
env "${repo_env[@]}" MINIKUBE_PROFILE=default CONTROL_API_REAL_PG_CONTEXT=default \
@@ -180,10 +204,13 @@ expect_code PROFILE_UNHEALTHY incomplete-profile-status incomplete-profile-statu
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_LOCK_ROOT="$tmp/locks" T2_EVIDENCE_ROOT="$tmp/evidence" bash -c 'source "$1"; t2_mk(){ printf "%s" "host: Running\nkubelet: Unknown\napiserver: Running"; return 1; }; t2_profile_status' bash "$COMMON"
ownership_env=("${repo_env[@]}" T2_PROFILE_ENV="$tmp/ownership.env")
+mkdir -p "$tmp/other"
printf 'PROFILE=%s\nBRANCH=feat/scenario\nSHA_SHORT=%s\nDIRTY=false\nREPO_DIR=%s\n' \
"$profile" "$(git -C "$repo" rev-parse --short=8 HEAD)" "$tmp/other" >"$tmp/ownership.env"
expect_code PROFILE_OWNERSHIP_MISMATCH profile-ownership profile-ownership \
- env "${ownership_env[@]}" bash -c 'source "$1"; t2_profile_scope' bash "$COMMON"
+ env "${ownership_env[@]}" bash -c 'source "$1"; t2_repo_metadata; t2_profile_scope' bash "$COMMON"
+grep -Fq 'PROFILE_OWNERSHIP_MISMATCH: profile metadata belongs to another worktree' "$tmp/profile-ownership" ||
+ { cat "$tmp/profile-ownership" >&2; fail 'profile metadata from another worktree was not refused as such'; }
stale_profile_env="$tmp/stale-profile.env"
printf 'PROFILE=%s\nBRANCH=feat/scenario\nSHA_SHORT=deadbeef\nDIRTY=false\nREPO_DIR=%s\n' \