Skip to content

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

TypeScript

fix(prereqs): resolve the .env that setup actually loads

Jose Ramirez764614243798
diff --git a/scripts/check-prereqs.sh b/scripts/check-prereqs.sh
index bfddc8c2b..e0ab9ec04 100755
--- a/scripts/check-prereqs.sh
+++ b/scripts/check-prereqs.sh
@@ -217,10 +217,21 @@ env_value() {
}
echo
-ENV_FILE="$PROJECT_DIR/.env"
+# Check the .env setup will actually load. scripts/e2e/load-dotenv.sh resolves a
+# Git worktree to the PRIMARY checkout's .env and deliberately ignores a
+# worktree-local one, so testing "$PROJECT_DIR/.env" here fails this gate in
+# every worktree on a file that is never read.
+# shellcheck source=scripts/e2e/load-dotenv.sh
+. "$PROJECT_DIR/scripts/e2e/load-dotenv.sh"
+ENV_DIR="$(dotenv_canonical_dir "$PROJECT_DIR")"
+ENV_FILE="$ENV_DIR/.env"
if [ ! -f "$ENV_FILE" ]; then
- err ".env not found — setup aborts in Step 1"
- echo -e " Create it: ${BOLD}cp .env.example .env${NC}"
+ err ".env not found at ${ENV_FILE} — setup aborts in Step 1"
+ if [ "$ENV_DIR" != "$PROJECT_DIR" ]; then
+ echo " This is a Git worktree; setup reads the primary checkout's .env,"
+ echo " so a worktree-local copy would be ignored."
+ fi
+ echo -e " Create it: ${BOLD}cp $PROJECT_DIR/.env.example $ENV_FILE${NC}"
echo " then set ADMIN_PASSWORD (required, no default) and ONE LLM key"
MISSING=$((MISSING + 1))
else
diff --git a/scripts/e2e/load-dotenv.sh b/scripts/e2e/load-dotenv.sh
index 3f7f6a399..b07cfb1f5 100755
--- a/scripts/e2e/load-dotenv.sh
+++ b/scripts/e2e/load-dotenv.sh
@@ -49,27 +49,33 @@ dotenv_load_file() {
done < "${env_file}"
}
-dotenv_canonical_root() {
+# Directory whose .env is authoritative for this checkout. For a Git worktree
+# that is the primary checkout, never the worktree itself: the primary checkout
+# is the canonical local source of truth, and accepting a worktree-local file
+# would reintroduce per-lane credential drift. Exposed separately from
+# dotenv_canonical_root so callers that must report the path (prereq checks)
+# resolve it the same way the loader does, instead of assuming $PWD/.env.
+dotenv_canonical_dir() {
local repo_root="${1:?repository root is required}"
- local common_dir main_repo_dir
+ local common_dir
common_dir="$(git -C "${repo_root}" rev-parse --git-common-dir 2>/dev/null || true)"
- if [[ -n "${common_dir}" ]]; then
- case "${common_dir}" in
- /*) main_repo_dir="$(cd "${common_dir}/.." && pwd)" ;;
- *) main_repo_dir="$(cd "${repo_root}/${common_dir}/.." && pwd)" ;;
- esac
- if [[ -f "${main_repo_dir}/.env" ]]; then
- printf '%s\n' "${main_repo_dir}/.env"
- return 0
- fi
- # A Git worktree intentionally does not fall back to its own .env. The
- # primary checkout is the canonical local source of truth, and accepting a
- # worktree-local file would reintroduce per-lane credential drift.
+ if [[ -z "${common_dir}" ]]; then
+ printf '%s\n' "${repo_root}"
return 0
fi
- if [[ -f "${repo_root}/.env" ]]; then
- printf '%s\n' "${repo_root}/.env"
+ case "${common_dir}" in
+ /*) (cd "${common_dir}/.." && pwd) ;;
+ *) (cd "${repo_root}/${common_dir}/.." && pwd) ;;
+ esac
+}
+
+dotenv_canonical_root() {
+ local repo_root="${1:?repository root is required}" canonical_dir
+ canonical_dir="$(dotenv_canonical_dir "${repo_root}")"
+ if [[ -f "${canonical_dir}/.env" ]]; then
+ printf '%s\n' "${canonical_dir}/.env"
fi
+ # A missing canonical .env is not an error here; callers decide.
return 0
}