Skip to content

Self-improving AI Employees for everyone

chore(cli): drop dead scripts and the npm fallback, harden the start smoke

trohitgfc3bbc2fca4e
diff --git a/.github/workflows/predeploy.yml b/.github/workflows/predeploy.yml
index 258afc87..ad38eeea 100644
--- a/.github/workflows/predeploy.yml
+++ b/.github/workflows/predeploy.yml
@@ -90,11 +90,23 @@ jobs:
APP_PORT=$(grep -E '^PYTHON_BACKEND_PORT=' .env.template | cut -d= -f2)
bun run start &
PID=$!
- for i in {1..15}; do
- curl -sf "http://localhost:${APP_PORT}/health" > /dev/null 2>&1 && break
+ # Pass only if /health answers. A cold macOS runner can need well
+ # over 30 s, so wait up to 90 s, and stop early if start exited.
+ healthy=0
+ deadline=$((SECONDS + 90))
+ while [ "$SECONDS" -lt "$deadline" ]; do
+ if curl -sf -m 5 "http://localhost:${APP_PORT}/health" > /dev/null 2>&1; then
+ healthy=1
+ break
+ fi
+ kill -0 "$PID" 2>/dev/null || break
sleep 2
done
- kill -0 $PID 2>/dev/null && bun run stop || (echo FAILED; exit 1)
+ bun run stop || true
+ if [ "$healthy" -ne 1 ]; then
+ echo "FAILED: /health never answered on port ${APP_PORT}"
+ exit 1
+ fi
- name: Test start (Windows)
if: runner.os == 'Windows'
diff --git a/bin/cli.js b/bin/cli.js
index f1e5f547..751762bf 100755
--- a/bin/cli.js
+++ b/bin/cli.js
@@ -1,7 +1,8 @@
#!/usr/bin/env bun
// The `company` launcher. Installed by `bun add -g @zeenie-ai/opencompany`
-// and run by bun (the shebang); the code itself is plain JavaScript so a
-// legacy npm-installed copy still runs under node.
+// and run by bun (the shebang). The code itself is plain JavaScript, so it
+// also parses under node, but the paths that need bun say so instead of
+// falling back to npm.
import { spawn, spawnSync, execSync } from 'child_process';
import { basename, dirname, resolve } from 'path';
@@ -58,8 +59,8 @@ Documentation: https://docs.opencompany.sh/
}
// bun is the package manager, script runner and JS runtime everywhere.
-// A legacy npm-installed copy may run this file under node without bun
-// on PATH, so every bun use below keeps an npm fallback for that case.
+// There is no npm fallback: without bun on PATH, the paths below that need
+// it stop with a pointer to https://bun.sh.
function hasBun() {
return getVersion('bun --version') !== null;
}
@@ -126,12 +127,13 @@ function checkDeps() {
function doctor() {
console.log('\nOpenCompany Doctor\n');
- try {
- const runner = hasBun() ? 'bun x' : 'npx';
- execSync(`${runner} envinfo --system --binaries --npmPackages edgymeow,agent-browser,cross-env`, {
- cwd: ROOT, stdio: 'inherit', shell: true,
- });
- } catch { /* envinfo not available, continue with manual checks */ }
+ if (hasBun()) {
+ try {
+ execSync('bun x envinfo --system --binaries', { cwd: ROOT, stdio: 'inherit', shell: true });
+ } catch { /* envinfo not available, continue with manual checks */ }
+ } else {
+ console.log(' bun: Not Found (required: https://bun.sh)\n');
+ }
console.log(' Additional checks:');
const checks = [
@@ -148,9 +150,10 @@ function doctor() {
console.log('');
}
-// Resolve <ROOT>/.cli-venv Python if provisioning has run. Returns null on
-// source checkouts (no venv -> fall back to ``bun run``) and on a fresh
-// global install before its first run.
+// Resolve <ROOT>/.cli-venv Python if provisioning has run. Returns null on a
+// fresh global install before its first run, and on a source checkout whose
+// `bun install` skipped the postinstall hook (which runs scripts/install.js,
+// the step that creates the venv); `run()` then falls back to `bun run`.
function venvPython() {
const py = process.platform === 'win32'
? resolve(ROOT, '.cli-venv', 'Scripts', 'python.exe')
@@ -222,9 +225,9 @@ function run(script, extraArgs = []) {
// ``-m cli <cmd>``. Skips the script-runner hop that previously re-
// resolved the system ``python`` (which on PEP 668 systems lacks
// the CLI runtime deps -- typer/rich/anyio/psutil). The script-runner
- // path stays as the source-checkout fallback: ``bun run <script>``
- // when bun is on PATH (source checkouts are bun-only), else ``npm run``
- // for a legacy npm-installed copy.
+ // path stays as the fallback when no venv exists (see venvPython):
+ // ``bun run <script>``. It needs bun on PATH; without it the command
+ // stops with a pointer to bun rather than trying npm.
ensureProvisioned();
const venvPy = venvPython();
if (venvPy) {
@@ -237,11 +240,13 @@ function run(script, extraArgs = []) {
return;
}
+ if (!hasBun()) {
+ console.error('OpenCompany requires bun to run this command. Install it: https://bun.sh');
+ process.exit(1);
+ }
const runnerArgs = ['run', script];
if (extraArgs.length) runnerArgs.push('--', ...extraArgs);
- const runner = hasBun()
- ? (process.platform === 'win32' ? 'bun.exe' : 'bun')
- : (process.platform === 'win32' ? 'npm.cmd' : 'npm');
+ const runner = process.platform === 'win32' ? 'bun.exe' : 'bun';
const child = spawn(runner, runnerArgs, {
cwd: ROOT,
stdio: 'inherit',
diff --git a/cli/tests/test_env_ports.py b/cli/tests/test_env_ports.py
new file mode 100644
index 00000000..c98a103f
--- /dev/null
+++ b/cli/tests/test_env_ports.py
@@ -0,0 +1,53 @@
+"""Port relationships the committed env files must keep.
+
+Port numbers live only in ``.env.template`` and the dev-only ``.env.dev``,
+and nothing else ties those literals together, so a change to one file can
+silently break a mode the author did not run. Three relationships are
+load-bearing:
+
+- The backend binds ``PYTHON_BACKEND_PORT`` (``build_backend_spec`` passes it
+ as uvicorn's ``--port``), while code that dials the backend from inside it
+ reads ``PORT`` (``Settings.port``): the Temporal workers' ``/ws/internal``
+ socket and broadcast URL, and the Stripe daemon's ``--forward-to``.
+ ``company start`` and ``company dev`` do not set ``PORT`` for the child,
+ so each file must set both, to the same value.
+- ``company dev`` runs Vite on ``VITE_CLIENT_PORT`` and moves the backend
+ behind it with ``.env.dev``, so the dev backend port must differ from it.
+- The app URL is the same in dev and production (``client/vite.config.js``):
+ OAuth apps are registered with that one callback URL. So the template's
+ ``VITE_CLIENT_PORT`` equals its ``PYTHON_BACKEND_PORT``.
+"""
+
+from __future__ import annotations
+
+import pytest
+
+from cli.config import _load_env_file
+from cli.platform_ import project_root
+
+ROOT = project_root()
+TEMPLATE = _load_env_file(ROOT / ".env.template")
+DEV = _load_env_file(ROOT / ".env.dev")
+
+
[email protected]("name,env", [(".env.template", TEMPLATE), (".env.dev", DEV)])
+def test_bind_port_matches_self_dial_port(name: str, env: dict[str, str]) -> None:
+ assert "PORT" in env and "PYTHON_BACKEND_PORT" in env, f"{name} must set both PORT and PYTHON_BACKEND_PORT"
+ assert env["PORT"] == env["PYTHON_BACKEND_PORT"], (
+ f"{name}: PORT={env['PORT']} but PYTHON_BACKEND_PORT={env['PYTHON_BACKEND_PORT']}. "
+ "uvicorn binds PYTHON_BACKEND_PORT, while the workers and the Stripe daemon dial PORT."
+ )
+
+
+def test_dev_backend_port_leaves_the_app_port_to_vite() -> None:
+ app_port = TEMPLATE["VITE_CLIENT_PORT"]
+ assert DEV["PYTHON_BACKEND_PORT"] != app_port, (
+ f".env.dev puts the backend on the app port {app_port}, where company dev runs Vite."
+ )
+
+
+def test_app_port_is_the_same_in_dev_and_production() -> None:
+ assert TEMPLATE["VITE_CLIENT_PORT"] == TEMPLATE["PYTHON_BACKEND_PORT"], (
+ ".env.template: the dev app port (VITE_CLIENT_PORT) must equal the production app port "
+ "(PYTHON_BACKEND_PORT), or OAuth callback URLs differ between the two modes."
+ )
diff --git a/cli/tests/test_release_pipeline_config.py b/cli/tests/test_release_pipeline_config.py
index ff8f9f08..2a1693e1 100644
--- a/cli/tests/test_release_pipeline_config.py
+++ b/cli/tests/test_release_pipeline_config.py
@@ -646,6 +646,17 @@ def test_launcher_and_install_scripts_run_under_bun(root: Path):
assert first == "#!/usr/bin/env bun", f"{rel}: {first!r}"
+def test_launcher_never_falls_back_to_npm(root: Path):
+ """bun is required everywhere, so the launcher stops with a pointer to
+ bun when it is missing instead of spawning npm or npx. ``doctor`` no
+ longer lists packages that are not root dependencies (edgymeow lives in
+ the shared packages tree; agent-browser is retired)."""
+ launcher = (root / "bin" / "cli.js").read_text(encoding="utf-8")
+ for needle in ("npm.cmd", "'npm'", "npx", "--npmPackages"):
+ assert needle not in launcher, f"bin/cli.js still contains {needle!r}"
+ assert "https://bun.sh" in launcher
+
+
def test_bunfig_pins_the_isolated_linker(root: Path):
"""``linker = "isolated"`` preserves pnpm's phantom-dependency guard
(symlinked layout); the tsgo typeRoots / vite-env.d.ts workarounds
diff --git a/docs-internal/ci_cd.md b/docs-internal/ci_cd.md
index 6a694f74..a41f7eff 100644
--- a/docs-internal/ci_cd.md
+++ b/docs-internal/ci_cd.md
@@ -91,7 +91,7 @@ Reusable `workflow_call` workflow with four independent jobs (no plan/change-det
- `build-and-lint` — `bun install --frozen-lockfile` + `bun run build`, then client lint (`bun run --filter react-flow-client lint`), TypeScript check (`... typecheck`), and frontend tests (`... test`, vitest). Runs on `ubuntu-latest`.
- `backend-tests` — `uv lock --check` (the committed `server/uv.lock` must match `pyproject.toml`; the desktop app installs from it with `--frozen`), then `uv sync` + `uv run pytest tests/ -v` in `server/`. Whole suite, unsharded. Runs on `ubuntu-latest`.
- `cli-tests` — `uv pip install --system pytest pytest-asyncio pyyaml` + `python -m pytest cli/tests/ -v`. Runs on `ubuntu-latest`.
-- `test-build-start` — cross-OS matrix (`ubuntu-latest`, `macos-latest`, `windows-latest`, `fail-fast: false`). Runs `bun run build`, then `bun run tsc --version` (proves the per-platform TypeScript 7 Go binary delivered via `optionalDependencies` resolves on every OS — the type-check gate itself runs on ubuntu only; `bun run`, never `bunx`, so it resolves strictly from the root `node_modules/.bin`), then a start smoke test. On Unix it backgrounds `bun run start`, reads `PYTHON_BACKEND_PORT` out of `.env.template` and polls `http://localhost:${APP_PORT}/health` for up to ~30 s, but only as a wait: the loop exits after its last attempt whether or not `/health` ever answered. The pass condition is that the backgrounded `bun run start` process is still alive (`kill -0`) and `bun run stop` then succeeds; a backend that stays up without ever serving `/health` passes. On Windows it starts the supervisor as a background job, waits 15 s, and fails if the job already exited.
+- `test-build-start` — cross-OS matrix (`ubuntu-latest`, `macos-latest`, `windows-latest`, `fail-fast: false`). Runs `bun run build`, then `bun run tsc --version` (proves the per-platform TypeScript 7 Go binary delivered via `optionalDependencies` resolves on every OS — the type-check gate itself runs on ubuntu only; `bun run`, never `bunx`, so it resolves strictly from the root `node_modules/.bin`), then a start smoke test. On Unix it backgrounds `bun run start`, reads `PYTHON_BACKEND_PORT` out of `.env.template` and polls `http://localhost:${APP_PORT}/health` (`curl -sf -m 5`, every 2 s) for up to 90 s, giving up early if the start process exits. It always runs `bun run stop` afterwards, then fails unless `/health` answered. On Windows it starts the supervisor as a background job, waits 15 s, and fails if the job already exited.
---
diff --git a/package.json b/package.json
index 00839a87..9850a3a6 100644
--- a/package.json
+++ b/package.json
@@ -83,9 +83,6 @@
"client:start": "bun --cwd=client run start",
"python:start": "cd server && uv run python main.py",
"python:daemon": "cd server && cross-env HOST=0.0.0.0 uv run python main.py",
- "temporal:start": "temporal api",
- "temporal:stop": "temporal stop",
- "temporal:status": "temporal status",
"temporal:worker": "cd server && uv run python -m services.temporal.worker",
"build": "python -m cli build",
"clean": "python -m cli clean",