Skip to content

feat(local-dev): deploy from a sibling git worktree via up --worktree/--branch#6031

Open
Yicong-Huang wants to merge 2 commits into
apache:mainfrom
Yicong-Huang:feat/local-dev-worktree-deploy
Open

feat(local-dev): deploy from a sibling git worktree via up --worktree/--branch#6031
Yicong-Huang wants to merge 2 commits into
apache:mainfrom
Yicong-Huang:feat/local-dev-worktree-deploy

Conversation

@Yicong-Huang

Copy link
Copy Markdown
Contributor

What changes were proposed in this PR?

bin/local-dev.sh can now build and run the stack from a sibling git worktree while the orchestration tooling itself always runs from the canonical checkout.

The key split is SELF_ROOT (where local-dev.sh, tui.py, and the docker overlay live — the tooling) vs SOURCE_ROOT (the application tree that gets built/run, which REPO_ROOT now points at).

  • up / auto accept --worktree=PATH or --branch=NAME (resolved to the worktree that has the branch checked out). A plain up returns to this checkout.
  • The selection persists to $STATE_DIR/deploy-source, so status / down / logs / single-service rebuild / auto all act on the active deployment. up re-marks the deploy target (branch / sha / worktree) at startup, and status --json gains "worktree" and "source" fields.
  • Build stamps are namespaced per source tree (sha1 of the absolute path), so switching worktrees can't let a stamp from tree A suppress the required first build of tree B.
  • Infra docker compose / .env / overlay stay pinned to the canonical checkout (orchestration), while the app schema/DDL still comes from the deployed source.
  • The interactive TUI mirrors the CLI: u / a accept the same selectors, and the banner + SRC-dirty column re-point to the active tree live (the shell exports TEXERA_DEPLOY_SOURCE; the TUI re-reads the persisted pointer after a switch).
  • Invalid --branch / --worktree fail fast with a clear, actionable message before anything is built or started.

Any related issues, documentation, discussions?

Closes #6030. The --help text and the in-TUI help (h) document the new selectors.

How was this PR tested?

Extended both existing local-dev test suites (all green):

  • bin/local-dev/tests/test_local_dev_sh.sh — 25 checks (6 new): --help documents the selectors; status --json carries worktree/source; a stale pointer is dropped and falls back to self; a valid pointer to a throwaway worktree (created and cleaned up in-test) is honored and reports its branch; invalid --branch and --worktree fail fast with rc=1.
  • bin/local-dev/tests/test_local_dev_tui.py — 43 checks (5 new): _stamp_dir_for matches the shell's sha1(path)[:12] namespacing; _resolve_deploy_source returns self when the pointer is missing/stale/points at a non-checkout, and the worktree when valid.

Run:

bash bin/local-dev/tests/test_local_dev_sh.sh
python3 -m pytest bin/local-dev/tests/test_local_dev_tui.py -q

Also verified manually that status --json against a persisted worktree pointer reports that worktree's branch/sha/source, and that bash -n / py_compile pass.

Was this PR authored or co-authored using generative AI tooling?

Generated-by: Claude Opus 4.8 (Claude Code)

…/--branch

Split the orchestration tree (SELF_ROOT — where local-dev.sh lives, always
main's copy of the tooling: the script, tui.py, docker overlay) from the
application source tree (SOURCE_ROOT). `up`/`auto` now take --worktree=PATH or
--branch=NAME to build/run a sibling worktree without disturbing the main
checkout; a plain `up` returns to this checkout. The choice persists to
$STATE_DIR/deploy-source so status/down/logs/<svc>/auto all follow it, and
status --json gains "worktree"/"source" fields. Build stamps are namespaced
per source so switching worktrees can't skip a needed build. The TUI mirrors
all of this: u/a accept the selectors and re-point the banner live.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

Automated Reviewer Suggestions

Based on the git blame history of the changed files, we recommend the following reviewers:

  • No candidates found from git blame history.

@Yicong-Huang Yicong-Huang requested a review from Copilot June 30, 2026 05:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Yicong-Huang Yicong-Huang requested a review from bobbai00 June 30, 2026 05:05
The deploy source's branch + short-sha was computed inline in four spots
(status JSON, status banner, the up Deploy-target line, the TUI dashboard
banner). Fold the three pre-existing copies plus the one this feature added
into a single `_git_head` helper.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@Yicong-Huang Yicong-Huang requested a review from Copilot June 30, 2026 06:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@Yicong-Huang Yicong-Huang requested a review from mengw15 July 1, 2026 18:12
@Yicong-Huang

Copy link
Copy Markdown
Contributor Author

@mengw15 could you please help on review? thanks

@mengw15 mengw15 requested a review from Copilot July 1, 2026 18:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review any files in this pull request.

@mengw15 mengw15 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, left one forward-looking note

Comment thread bin/local-dev/main.sh
Comment on lines +766 to +772
# Infra orchestration is part of the tooling, not the deployed app — pin it to
# the self tree so a deployed worktree always comes up against main's known-good
# docker compose (the app schema/DDL it applies still comes from the source tree
# via $REPO_ROOT).
DOCKER_COMPOSE_FILE="$SELF_ROOT/bin/single-node/docker-compose.yml"
DOCKER_OVERLAY_FILE="$SELF_ROOT/bin/local-dev/docker-compose.override.yml"
DOCKER_ENV_FILE="$SELF_ROOT/bin/single-node/.env"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The intentional split (SOURCE_ROOT for app, SELF_ROOT for infra) is the right call for the common case — 95% of PRs only touch app code and this is a huge quality-of-life win. But it silently deposits a real footgun for the other 5%:

  • PR adds a new docker service (Redis, ClickHouse, etc.) in its compose file → deployed stack silently misses it (self's compose wins)
  • PR adds a required env var → app starts, hits NPE at runtime (self's .env has no such var)
  • PR adds a new backend service to the SERVICES=(...) array in main.sh → self's main.sh never launches it
  • PR is itself a tooling change (like this PR) → self's tooling doesn't have the change under test

Worth surfacing this boundary to the user. Two lightweight options:

  1. Add a note in --help (and the TUI ? help): "--worktree / --branch assumes the target only differs in app code — if it modifies bin/local-dev/**, bin/single-node/**, docker-compose*, or .env, checkout that branch and run its own local-dev.sh instead."
  2. At startup of up --worktree=..., diff -q $SELF_ROOT/bin/local-dev/ $SOURCE_ROOT/bin/local-dev/ (same for bin/single-node/) and print a one-line warn if there's drift. Non-fatal, just informational.

Not blocking — the design is sound and the failure modes are recoverable. Just want future users to have a chance to notice the boundary before they burn 30 minutes debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Let local-dev.sh deploy from a sibling git worktree

3 participants