Skip to content

Add production-style worktree start command - #2045

Merged
ymichael merged 2 commits into
mainfrom
bb/support-pnpm-dev-start-behavior-thr_7r3gr979n4
Aug 20, 2026
Merged

Add production-style worktree start command#2045
ymichael merged 2 commits into
mainfrom
bb/support-pnpm-dev-start-behavior-thr_7r3gr979n4

Conversation

@ymichael

@ymichael ymichael commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

What was wrong

Production-bundle QA required choosing between the convenient worktree isolation of pnpm dev and the production build/serving behavior of pnpm start. The dev launcher already derived stable checkout-specific data and ports, but only launched the Vite development server; the production launcher used the desired optimized, same-origin bundle path without applying those worktree selectors.

What changed

  • Added pnpm start:worktree, which reuses the development dotenv cascade and checkout-specific data/server/host-daemon selectors before invoking the existing production-style source launcher.
  • Added a typed worktree runtime policy that is reapplied after persisted config.json/env.json settings are loaded, locking the worktree data directory, ports, inherited skills, listener host, absent Vite port, and disabled telemetry.
  • Made start-bb.mjs build children lead process groups and forward SIGINT/SIGTERM with leader-first shutdown and escalation, waiting until descendant processes are gone.
  • Added focused launcher-policy and real process-tree SIGTERM tests.
  • Documented the command in the README, configuration/debugging guides, and platform support list.
  • No server/host-daemon wire contract changed, so HOST_DAEMON_PROTOCOL_VERSION is unchanged.

How you verified

  • pnpm exec turbo run typecheck --filter=@bb/scripts --filter=bb-app
  • pnpm exec turbo run test --filter=@bb/scripts --filter=bb-app --force (@bb/scripts: 18 files/97 tests; bb-app: 1 file/65 tests)
  • pnpm exec prettier scripts/start-bb.mjs packages/bb-app/src/launcher.ts packages/bb-app/src/index.ts packages/bb-app/test/index.test.ts packages/scripts/src/commands/run-dev.ts packages/scripts/test/run-dev.test.ts packages/scripts/test/start-bb.test.mjs docs/configuration.md docs/platform-support.md --check
  • The process regression sends SIGTERM to a live launcher fixture and asserts both its build leader and grandchild are gone before exit.
  • Started BB_TELEMETRY=false pnpm start:worktree, fetched the worktree server URL, and confirmed it returned hashed /assets/*.js production bundles with no Vite client or source-module entry. Ctrl-C stopped both listeners.

Fixes #2044

AGENT GENERATED: by GPT-5

@bb-slop-cop

bb-slop-cop Bot commented Aug 20, 2026

Copy link
Copy Markdown

🚨 SLOP COP 🚨 · review

Plain-English summary: This PR adds a command that starts a worktree with production-style settings.

I am SlopCop. I am reviewing this PR for security, code quality, performance, reuse, and end-to-end behavior.

Comment thread packages/scripts/src/commands/run-dev.ts
Comment thread packages/scripts/src/commands/run-dev.ts

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🚨 SLOP COP 🚨 · review

Plain-English summary: This PR adds a worktree start command. It builds production files and starts BB with worktree data and ports.

I found two important defects and one small documentation gap.

  1. High — Saved settings can defeat the worktree rules.

    The wrapper sets worktree data, worktree ports, and disabled telemetry. The production launcher then loads saved settings over those values.

    A saved setting can select other data or ports. It can also enable telemetry or restore BB_DEV_APP_PORT.

    Apply a typed worktree policy after all saved settings load. Test the final launcher state with conflicting saved values.

  2. Medium — A direct stop during the build leaves child processes alive.

    The wrapper sends SIGTERM to start-bb.mjs only. That script does not send the signal to its active Turbo child.

    We reproduced this result during a forced build. Turbo and Vite continued under PID 1 after the wrapper stopped.

    Forward stop signals through the full process tree. Add a process test that checks every child after SIGTERM.

  3. Low — The support list omits the new command.

    docs/platform-support.md lists only pnpm start for source checkout startup. Add pnpm start:worktree to that support entry.

The design reuses toDevProcessEnv, scripts/start-bb.mjs, and runScriptProcess. I found no duplicate implementation that needs a separate refactor.

The focused Turbo tests passed all 95 tests. The scripts typecheck and format checks passed.

The end-to-end run returned HTTP 200. Doobie loaded the bb page and showed the new-thread interface.

All continuous-integration checks passed. All test processes stopped, and the worktree stayed clean.

I posted this review as a comment. I did not use an approval or change-request action.

@ymichael

Copy link
Copy Markdown
Collaborator Author

Addressed all SlopCop findings in 111d24f35:

  • persisted settings are now followed by an immutable typed worktree runtime policy, covered with conflicting saved-value regression coverage;
  • build SIGINT/SIGTERM now shuts down and waits for the full process group, covered by a real leader/grandchild process test; and
  • docs/platform-support.md now lists pnpm start:worktree.

Focused typechecks pass. @bb/scripts passes 97 tests and bb-app passes 65 tests.

@ymichael
ymichael merged commit 23a4eae into main Aug 20, 2026
14 checks passed
@ymichael
ymichael deleted the bb/support-pnpm-dev-start-behavior-thr_7r3gr979n4 branch August 20, 2026 17:56
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.

Add a production-style start command for the current worktree

1 participant