Skip to content

feat: worktree-isolated network identity (own ip/port/domain) + hosts crash fix - #15

Merged
graphicfox merged 3 commits into
masterfrom
fix/worktree-network-identity
Jul 17, 2026
Merged

feat: worktree-isolated network identity (own ip/port/domain) + hosts crash fix#15
graphicfox merged 3 commits into
masterfrom
fix/worktree-network-identity

Conversation

@graphicfox

Copy link
Copy Markdown
Contributor

4.3.0 — worktree apps run side by side with main

Fixes the bug report: a worktree app couldn't start because only the compose project name was namespaced — the loopback IP / host port / hosts domain still came from .env, so the worktree reused main's APP_IP and the container failed to bind (:443 already allocated). It also depended on rewriting .env, which dirties a committed .env and fails when .env is read-only.

What changed

  • New AppIdentity overlay. The effective compose project / domain / IP is now resolved at runtime and injected into docker compose (shell env overrides .env), the loopback alias, and the hosts entry — never written to .env.
    • Inside a worktree: suffixed compose project + derived domain + its own stable loopback IP (allocated once, cached in the per-worktree registry). → runs alongside main on its own ip/port/domain.
    • .env and .env.template stay untouched → works even when .env is committed or read-only, and git status stays clean.
    • main checkout unaffected; Doppler project stays shared.
  • lab up --domain <domain> / --ip <ip> to set the identity explicitly (CI/agents).
  • Fix: DockerHosts.removeDomain/removeCurrent crashed with "Could not iterate given object!" (passed a Map to the vendored forEach). Now use native Map.forEach — also fixes lab down's hosts cleanup.

Not needed anymore

The reporter's manual workaround (hand-editing APP_DOMAIN in the worktree .env) is obsolete. (lab test -y for headless runs already shipped in 4.1.0.)

Verification

npm run build ✅ · npm test ✅ (29 suites / 59 tests). New AppIdentity tests (main passthrough, worktree isolation, fresh-IP allocation + idempotent reuse, suffix idempotency, overrides) and a DockerHosts regression test (no Map-iteration crash). The docker-level side-by-side run is validated by the reporter's environment.

🤖 Generated with Claude Code

Kim Martini and others added 3 commits July 17, 2026 15:16
…run side by side

Worktree support previously namespaced only the compose project name; the
loopback IP, host port and hosts domain were still taken from .env, so a
worktree reused the main checkout's APP_IP and its container failed to bind
(":443 already allocated"). It also relied on rewriting .env, which dirties a
committed .env and fails when .env is read-only.

Introduce AppIdentity: the effective compose project / domain / ip is now
resolved at runtime as an OVERLAY and injected into docker compose (shell env
overrides .env), the loopback alias and the hosts entry - never written to .env.
Inside a worktree it derives a suffixed compose project + domain and allocates
its own stable loopback ip (cached in the per-worktree registry), so the app
runs alongside the main checkout on its own ip/port/domain. .env and
.env.template stay untouched (works even when committed or read-only), and the
main checkout is unaffected. Adds `lab up --domain <domain>` / `--ip <ip>` to set
the identity explicitly (CI/agents). Doppler stays on the base project.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
removeDomain and removeCurrent passed a Map to the vendored forEach helper,
which cannot iterate Maps and threw "Could not iterate given object!" - breaking
the hosts-conflict path and `lab down`'s hosts cleanup. Use the native
Map.forEach (as set() already does).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@graphicfox
graphicfox merged commit c453c5e into master Jul 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant