Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

docs(acceptance): use an env-less worktree when root .env fails to boot, instead of hard-fixing it or falling back to mocks (#21486)

Arvin Xuaf02e45395c0
diff --git a/.agents/acceptance/PROJECT.md b/.agents/acceptance/PROJECT.md
index 60f79569acd..932ce121230 100644
--- a/.agents/acceptance/PROJECT.md
+++ b/.agents/acceptance/PROJECT.md
@@ -53,6 +53,10 @@ stale standalone install: a recently added workspace package fails to resolve
- With repo-root `.env` present: use the existing local config — `bun run dev`
(full-stack, needed for Web smoke) or `AGENT_RUNTIME_MODE=queue pnpm run dev:next`
(backend only). Do NOT call any `init-dev-env.sh` subcommand when `.env` exists.
+ If that `.env` config does not boot (expired credentials, schema behind
+ the checkout, `setup-auth.sh` refusing to seed), do not repair it in place —
+ open a clean `git worktree` with no root `.env` and use the bootstrap below
+ ([dev-server.md](./references/dev-server.md#root-env-exists-but-does-not-boot)).
- Without `.env`: use the skill-owned bootstrap `.agents/acceptance/scripts/init-dev-env.sh`
(Postgres, Redis, migrations, auth/key-vault/S3 test env, seed user, then the
repo's own dev server — not `e2e/scripts/setup.ts`). It hard-blocks when
diff --git a/.agents/acceptance/common-mistakes.md b/.agents/acceptance/common-mistakes.md
index 128d2e4fc8a..a85839f783f 100644
--- a/.agents/acceptance/common-mistakes.md
+++ b/.agents/acceptance/common-mistakes.md
@@ -67,6 +67,7 @@ the next free number of that prefix.
- **L-S23** A hand-built `node_modules` symlink farm runs unit tests but cannot start the dev server; clone a working checkout's `node_modules` instead of a fresh install, which this lockfile-less repo resolves against a moving registry.
- **L-S24** Read the dev server's URL from its own log, and treat "ready" as any status but `000` — `/` answers `302` to `/signin` when signed out.
- **L-S25** `dev:static` 的 Electron 重启会清空 `dist/renderer`(renderer Vite dev server 启动即删 outDir);`start`/`restart` 后必须重建 renderer 再驱动,否则页面只有 Internal Server Error。
+- **L-S26** 根 `.env` 起不来时不修它:开一个没有 `.env` 的 worktree,先按 L-S23 装依赖、L-S20 取端口、L-S9 建 per-run 库,再 `setup-db` → `migrate` → `seed-user` → `dev`。
## Entries
@@ -618,3 +619,20 @@ dev.mjs 每次启动都会拉起 renderer Vite dev server,而后者启动即
**Rule:** 文本类执行记录用 `.txt` 或 `.json` 保存;必须用 Markdown 排版时,另附一份同内容的
`.txt`。发布后用 `lh acceptance run result list --run <id> --json` 核对每项 verdict。已发布的轮次
用 `lh acceptance run result submit --type text --file <x>.txt --verdict ...` 补交,不要新开一轮。
+
+### L-S26 — 在坏掉的根 `.env` 上原地硬修
+
+`since 2026-10-23` · `holds-while: init-dev-env.sh 在根 .env 存在时直接退出,dev-server.md 只写了「有 .env 用现有配置」这一条分支`
+
+**Trap:** repo 根目录有 `.env`(Neon 口令已失效,或 `DATABASE_URL` 被指到本地库但 schema 落后、缺
+`agent_history_jobs`),于是走「有 `.env` 就用现有配置」这条分支:`bun run dev` 起来但登录 500,
+`setup-auth.sh` 又提示 `root .env exists; do not seed or modify this DB`。接下来会去改根 `.env`、改
+`node_modules` 里的依赖硬救——那都是别人的本地配置,救回来也只是这一轮能跑,下一轮照旧。
+
+**Rule:** 根 `.env` 起不来就离开它:`git worktree add --detach /tmp/<slug> <ref-or-sha>` 开一棵没有
+根 `.env` 的树(`--detach`:正在检出的分支不能重复 checkout),再把这条路径走完整——按 L-S23 复制
+一份可用的 `node_modules`(含各 package 自己的),按 L-S20 从 `docker ps` 取容器真实端口,按 L-S9
+在容器里建 per-run 库并导出 `DATABASE_URL`,然后 `init-dev-env.sh setup-db` → `migrate` →
+`seed-user` → `dev`(脚本一律用绝对路径,L-S21;端口从日志取,L-S24)。worktree 路径写进 report,
+teardown 时 `clean` 停服、删掉这个库、`git worktree remove` 移除这棵树。不要在被改坏的根 `.env` 上
+继续调试。
diff --git a/.agents/acceptance/references/dev-server.md b/.agents/acceptance/references/dev-server.md
index 7c53d4c5181..3aa8357c122 100644
--- a/.agents/acceptance/references/dev-server.md
+++ b/.agents/acceptance/references/dev-server.md
@@ -70,6 +70,73 @@ AGENT_RUNTIME_MODE=queue bun run dev
.agents/acceptance/scripts/init-dev-env.sh dev-next
```
+## Root `.env` exists but does not boot
+
+`init-dev-env.sh` hard-blocks whenever the repo root has a `.env`, and the
+`.env` branch above assumes that config is sound. When it is not — expired
+database credentials, a database whose schema is behind the checkout (missing
+`agent_history_jobs`, so sign-in 500s), or `setup-auth.sh` refusing with
+`root .env exists; do not seed or modify this DB` — do not repair it in place.
+
+That `.env` belongs to whoever set it up. Patching it (or patching
+`node_modules`) to get one run going leaves their environment broken and hides
+the real cause. Open a throwaway worktree instead: it has no root `.env`, so the
+bootstrap branch applies and nothing is shared with that config.
+
+A bare worktree is not enough — it has no `node_modules`, and the bootstrap runs
+through the repo's own tooling. Provision it, keep the shared containers off each
+other's state, and invoke everything by absolute path:
+
+```bash
+WT=/tmp/lh-acceptance-<slug>
+SRC=<working checkout>
+# --detach so a ref already checked out elsewhere (i.e. the branch under test) is legal.
+git worktree add --detach "$WT" <ref-or-sha>
+
+# 1. Install (L-S23): copy $SRC's install rather than resolving a lockfile-less repo.
+# -c is APFS clonefile (macOS); drop it on Linux.
+cp -Rc "$SRC/node_modules" "$WT/node_modules"
+( cd "$SRC" && find . -mindepth 2 -maxdepth 3 -name node_modules -type d ) | while read -r rel; do
+ mkdir -p "$WT/$(dirname "$rel")"
+ cp -Rc "$SRC/$rel" "$WT/$rel"
+done
+# symlink any workspace package this branch adds into "$WT/node_modules/@lobechat/"
+
+# 2. Ports (L-S20): the managed containers are reused, possibly on non-default hosts.
+docker ps --format '{{.Names}} {{.Ports}}' | grep lobehub-agent-testing
+export DB_PORT=<from docker ps> REDIS_PORT=<from docker ps>
+
+# 3. Database of your own (L-S9): a sibling run's migrations and fixture
+# truncation must not land here.
+"$WT/.agents/acceptance/scripts/init-dev-env.sh" setup-db
+docker exec lobehub-agent-testing-postgres psql -U postgres -c "CREATE DATABASE lh_acceptance_<slug>"
+docker exec lobehub-agent-testing-postgres psql -U postgres -d lh_acceptance_<slug> -c "CREATE EXTENSION IF NOT EXISTS vector"
+export DATABASE_URL="postgresql://postgres:postgres@localhost:$DB_PORT/lh_acceptance_<slug>"
+
+# 4. Bootstrap, absolute paths (L-S21).
+"$WT/.agents/acceptance/scripts/init-dev-env.sh" migrate
+"$WT/.agents/acceptance/scripts/init-dev-env.sh" seed-user
+"$WT/.agents/acceptance/scripts/init-dev-env.sh" dev # or dev-next
+```
+
+`setup-db` still migrates the default `postgres` database on the way; step 4's
+`migrate` is what the run actually uses.
+
+Teardown reverses all of it — the worktree is throwaway, and on Linux the copy is
+a real ~6.8 GB, not a clonefile:
+
+```bash
+"$WT/.agents/acceptance/scripts/init-dev-env.sh" clean # stop only this run's server
+docker exec lobehub-agent-testing-postgres psql -U postgres -c "DROP DATABASE IF EXISTS lh_acceptance_<slug>"
+git worktree remove --force "$WT"
+```
+
+Leave the shared `postgres` database holding the other session's rows.
+
+The containers are the part that costs nothing the second time (`setup-db` is a
+no-op when they are up); the price of this path is one checkout plus a
+dependency copy. Record the worktree path in the report.
+
## When a server restart is needed
Next.js hot-reload may not pick up changes in workspace packages — restart when
@@ -94,6 +161,8 @@ in doubt.
| Agent call runs inline | Set `AGENT_RUNTIME_MODE=queue`, make sure `REDIS_URL` is configured, then restart the server |
| Queue mode needs Redis | Run `init-dev-env.sh setup-db`, or provide `REDIS_URL=redis://...` for an existing Redis |
| QStash workflow failures | Start `init-dev-env.sh qstash` and make sure dev server inherited the script's `QSTASH_*` env |
+| Root `.env` present but dev fails (sign-in 500, schema behind the checkout) | Do not repair it in place — see [Root `.env` exists but does not boot](#root-env-exists-but-does-not-boot) |
+| `setup-auth.sh`: `root .env exists; do not seed` | Same: clean worktree without a root `.env`, then `init-dev-env.sh seed-user` |
Marketplace/community endpoints are not part of the local agent-testing auth
gate. Do not block local product-chain verification on marketplace API auth