Skip to content

Self-improving AI Employees for everyone

test(cli): rewrite pnpm assertions for bun, keep invariant coverage

trohitg473ec670c9c9
diff --git a/cli/tests/conftest.py b/cli/tests/conftest.py
index 1a738b85..c010b39a 100644
--- a/cli/tests/conftest.py
+++ b/cli/tests/conftest.py
@@ -1,19 +1,21 @@
"""Shared fixtures for ``company`` tests.
The release-pipeline config tests need to read files that live in
-pnpm workspace members (``client/``, ``server/nodejs/``) without
+bun workspace members (``client/``, ``server/nodejs/``) without
hardcoding those filesystem paths in every test. The canonical
-oracle for "where does workspace X live" is pnpm itself:
-
- pnpm list --json --only-projects --recursive --depth 0
-
-That returns every workspace member's name + absolute path. We invoke
-it once per test session and expose the result as a name → path map.
+source for "where does workspace X live" is the root ``package.json``
+``workspaces`` array (bun's SSOT — ``pnpm-workspace.yaml`` is gone and
+bun has no machine-readable workspace-listing command), so the fixture
+parses it directly: expand each entry (globs included), read every
+member's ``package.json``, and map package name → absolute path.
Tests then reference workspaces by their npm package name (a stable
identifier defined in each ``package.json``) rather than by path. If
``server/nodejs/`` is later renamed or moved, the test suite keeps
-working — pnpm resolves the new location.
+working — the ``workspaces`` array resolves the new location. Parsing
+in-process (no subprocess) also removes the old skip-when-PM-missing
+hazard: a broken ``workspaces`` array now fails loudly instead of
+silently skipping the config tests.
For files that don't live inside a workspace (``.github/workflows``,
``scripts/install.js``), tests resolve via the ``root`` fixture which
@@ -24,13 +26,11 @@ canonical worktree-aware helper.
from __future__ import annotations
import json
-import subprocess
from pathlib import Path
import pytest
from cli.platform_ import project_root
-from cli.run import which_argv
@pytest.fixture(scope="session")
@@ -41,29 +41,22 @@ def root() -> Path:
@pytest.fixture(scope="session")
def workspace_members(root: Path) -> dict[str, Path]:
- """Map of pnpm workspace member name → absolute filesystem path.
-
- Resolved once per session by shelling out to ``pnpm``. The ``--depth 0``
- + ``--only-projects`` flags trim the output to just workspace members
- (no transitive npm deps). Skips with a clear message if pnpm isn't
- installed so the rest of the suite remains runnable.
-
- Reference: https://pnpm.io/cli/list
+ """Map of bun workspace member name → absolute filesystem path.
+
+ Parsed once per session from the root ``package.json`` ``workspaces``
+ array. Entries may be globs, so non-literal patterns expand via
+ ``Path.glob``. Doubles as a regression lock that ``workspaces`` holds
+ real member *paths* (bun's pnpm-lock migrator has been observed to
+ write package names instead): a bogus entry yields no ``package.json``
+ and the dependent tests fail on the missing member name.
"""
- # which_argv resolves Windows .cmd / .bat shims via PATHEXT — the
- # same helper cli.run uses everywhere else for the same reason.
- argv = which_argv(
- ["pnpm", "list", "--json", "--only-projects", "--recursive", "--depth", "0"]
- )
- try:
- out = subprocess.run(
- argv,
- cwd=root,
- check=True,
- capture_output=True,
- text=True,
- )
- except (FileNotFoundError, subprocess.CalledProcessError) as e:
- pytest.skip(f"pnpm workspace listing unavailable ({e}); skipping config tests")
- members = json.loads(out.stdout)
- return {m["name"]: Path(m["path"]) for m in members}
+ pkg = json.loads((root / "package.json").read_text(encoding="utf-8"))
+ members: dict[str, Path] = {}
+ for pattern in pkg.get("workspaces", []):
+ dirs = sorted(root.glob(pattern)) if "*" in pattern else [root / pattern]
+ for d in dirs:
+ manifest = d / "package.json"
+ if manifest.is_file():
+ m = json.loads(manifest.read_text(encoding="utf-8"))
+ members[m["name"]] = d.resolve()
+ return members
diff --git a/cli/tests/test_build_compile_pipeline.py b/cli/tests/test_build_compile_pipeline.py
index f51ef2f1..791ac211 100644
--- a/cli/tests/test_build_compile_pipeline.py
+++ b/cli/tests/test_build_compile_pipeline.py
@@ -2,7 +2,7 @@
Covers the two new steps wired into ``cli.commands.build.build_command``:
-- ``[3/6] Building Node.js sidecar`` -> ``pnpm --filter opencompany-nodejs-executor run build``
+- ``[3/6] Building Node.js sidecar`` -> ``bun run --filter opencompany-nodejs-executor build``
- ``[5/6] Compiling Python bytecode`` -> ``uv run python -m compileall -q -j 0 ...``
The orchestrator is exercised once per test with every external surface
@@ -118,23 +118,26 @@ def test_source_dirs_constant_covers_runtime_modules():
# ---------------------------------------------------------------------------
-def test_build_invokes_sidecar_pnpm_filter(tmp_path: Path):
+def test_build_invokes_sidecar_bun_filter(tmp_path: Path):
"""[3/6] Build Node.js sidecar via the package's ``build`` script."""
captured = _run_build_capture_invocations(tmp_path)
match = _find_call(
captured,
- lambda c: c[:1] == ["pnpm"]
+ lambda c: c[:2] == ["bun", "run"]
and "--filter" in c
and "opencompany-nodejs-executor" in c,
)
assert match is not None, (
- "expected `pnpm --filter opencompany-nodejs-executor run build` in "
+ "expected `bun run --filter opencompany-nodejs-executor build` in "
f"{[c['argv'] for c in captured]}"
)
argv = match[1]["argv"]
- assert (
- "run" in argv and "build" in argv
- ), f"sidecar step must invoke the `build` script, got {argv}"
+ assert "build" in argv, f"sidecar step must invoke the `build` script, got {argv}"
+ # bun rejects --filter BEFORE the run subcommand (it would parse the
+ # next word as a script name) — lock the flag position.
+ assert argv.index("--filter") > argv.index("run"), (
+ f"--filter must come after the `run` subcommand for bun, got {argv}"
+ )
def test_sidecar_build_runs_after_client_build(tmp_path: Path):
@@ -352,8 +355,8 @@ def test_only_one_temporal_install_invocation(tmp_path: Path):
def test_pipeline_order_client_then_sidecar_then_uv_then_compileall(tmp_path: Path):
"""Full ordering invariant for the new pipeline:
- 1. client build (``pnpm --filter react-flow-client run build``)
- 2. sidecar bundle (``pnpm --filter opencompany-nodejs-executor run build``)
+ 1. client build (``bun run --filter react-flow-client build``)
+ 2. sidecar bundle (``bun run --filter opencompany-nodejs-executor build``)
3. uv sync (``uv sync``)
4. compileall (``uv run python -m compileall ...``)
diff --git a/cli/tests/test_clean.py b/cli/tests/test_clean.py
index c3dd7496..b05cd6ec 100644
--- a/cli/tests/test_clean.py
+++ b/cli/tests/test_clean.py
@@ -13,6 +13,7 @@ def test_targets_list_is_stable():
assert clean._TARGETS == [
"node_modules",
"client/node_modules",
+ "server/nodejs/node_modules",
"client/dist",
"client/.vite",
"server/.venv",
diff --git a/cli/tests/test_dev.py b/cli/tests/test_dev.py
index a6791e21..4ffa2e7d 100644
--- a/cli/tests/test_dev.py
+++ b/cli/tests/test_dev.py
@@ -60,7 +60,7 @@ def test_build_specs_dev_uses_vite_when_available(tmp_path: Path):
cfg = _cfg()
specs = dev._build_specs(tmp_path, cfg, daemon=False, use_vite=True)
by_name = {s.name: s for s in specs}
- assert by_name["client"].argv[:3] == ["pnpm", "run", "client:start"]
+ assert by_name["client"].argv[:3] == ["bun", "run", "client:start"]
def test_build_specs_dev_without_vite_is_backend_only(tmp_path: Path):
diff --git a/cli/tests/test_release_pipeline_config.py b/cli/tests/test_release_pipeline_config.py
index 291f6db4..a5e0563d 100644
--- a/cli/tests/test_release_pipeline_config.py
+++ b/cli/tests/test_release_pipeline_config.py
@@ -6,7 +6,7 @@ TypeScript, esbuild, GitHub Actions, ``scripts/install.js``).
Reused infrastructure (no path strings duplicated across tests):
- ``conftest.workspace_members`` → name → Path map from ``pnpm list``
+ ``conftest.workspace_members`` → name → Path map from root ``workspaces``
``conftest.root`` → project_root() for top-level files
``cli.commands.build.COMPILEALL_SOURCE_DIRS``
→ SSOT for the bytecode-compile path
@@ -209,14 +209,18 @@ def test_client_typecheck_delegates_to_the_root_gate(
Placement is forced, not stylistic: ``client`` already depends on
``typescript@^5.9.3`` (typescript-eslint needs the JS API), and one
manifest cannot declare the same package twice. Worse, ``typescript``
- 7 and 5 both ship a ``tsc`` bin, so co-locating them would let pnpm's
- bin-link conflict resolution decide which compiler gates CI.
+ 7 and 5 both ship a ``tsc`` bin, so co-locating them would leave the
+ package manager's bin-link conflict resolution deciding which
+ compiler gates CI. (Under bun's isolated linker each package resolves
+ its own ``.bin/tsc`` — root gets 7, client gets 5 — verified during
+ the pnpm→bun migration.)
The client script therefore delegates upward, which keeps the CI
- command (``pnpm --filter react-flow-client run typecheck``) and its
- guard below unchanged.
+ command (``bun run --filter react-flow-client typecheck``) and its
+ guard below unchanged. Note bun 1.4 requires the ``--cwd=..`` form —
+ the space-separated ``--cwd ..`` is rejected by ``bun run``.
"""
- assert client_pkg["scripts"].get("typecheck") == "pnpm -w run typecheck", (
+ assert client_pkg["scripts"].get("typecheck") == "bun --cwd=.. run typecheck", (
"client typecheck must delegate to the root gate, got "
f"{client_pkg['scripts'].get('typecheck')!r}"
)
@@ -263,10 +267,12 @@ def test_client_keeps_typescript_5_for_typescript_eslint(client_pkg: dict):
"""Do NOT 'clean this up' by unifying on one TypeScript.
``typescript-eslint`` loads the TypeScript API at module scope and
- declares a peer range that excludes 6.x and 7.x. With
- ``strict-peer-dependencies=true`` in .npmrc, bumping this is not a
- warning — it is a hard ``pnpm install`` failure, and CI installs with
- ``--frozen-lockfile``.
+ declares a peer range that excludes 6.x and 7.x. Under pnpm,
+ ``strict-peer-dependencies=true`` made a bad bump a hard install
+ failure; bun has no strict-peer mode and never errors on peer
+ conflicts (oven-sh/bun#9135), so THIS TEST is now the only guard
+ keeping the client on a TypeScript major that typescript-eslint's
+ peer range accepts.
"""
version = client_pkg.get("dependencies", {}).get("typescript")
assert version is not None and version.startswith("^5."), (
@@ -331,8 +337,9 @@ def test_vite_config_chunk_warning_below_one_megabyte(client_dir: Path):
def test_tsconfig_drops_baseurl_and_sets_typeroots(client_dir: Path):
"""TS 7 / tsgo removed the deprecated ``baseUrl`` option.
``typeRoots`` is the explicit replacement for telling the compiler
- where to find ``@types/*`` packages — needed because pnpm's
- symlinked ``node_modules`` layout can confuse auto-discovery.
+ where to find ``@types/*`` packages — needed because the symlinked
+ ``node_modules`` layout (pnpm before, bun's isolated linker now)
+ can confuse auto-discovery.
"""
src = (client_dir / "tsconfig.json").read_text(encoding="utf-8")
assert not re.search(r'^\s*"baseUrl"', src, re.MULTILINE), (
@@ -342,7 +349,7 @@ def test_tsconfig_drops_baseurl_and_sets_typeroots(client_dir: Path):
assert re.search(
r'"typeRoots":\s*\[\s*"\./node_modules/@types"\s*\]',
src,
- ), "typeRoots must point at ./node_modules/@types for tsgo + pnpm"
+ ), "typeRoots must point at ./node_modules/@types for tsgo + symlinked node_modules"
# The path alias must survive the baseUrl removal.
assert re.search(
r'"@/\*":\s*\["\./src/\*"\]', src
@@ -352,7 +359,8 @@ def test_tsconfig_drops_baseurl_and_sets_typeroots(client_dir: Path):
def test_vite_env_dts_references_google_maps(client_dir: Path):
"""``@types/google.maps`` exposes a global ``google.maps`` namespace
(no module export). tsgo's auto-discovery doesn't pick it up
- reliably through pnpm's symlinks, so the canonical Google-recommended
+ reliably through symlinked node_modules (pnpm before, bun's isolated
+ linker now), so the canonical Google-recommended
pattern (a triple-slash reference) is applied once in the
Vite-injected ambient declarations file.
@@ -388,22 +396,29 @@ def _step_by_name(job: dict, step_name: str) -> dict | None:
return None
-def test_predeploy_typecheck_step_routes_through_pnpm_script(predeploy_yml: dict):
+def test_predeploy_typecheck_step_routes_through_workspace_filter(predeploy_yml: dict):
"""The CI typecheck step must invoke the npm script (which delegates
up to the root TypeScript 7 gate) rather than calling ``tsc``
directly. Keeps the compiler choice in one place — the ROOT
``package.json`` — so it can change without editing the workflow.
+
+ Bun's flag placement matters: ``--filter`` must come AFTER the
+ ``run`` subcommand, and the script name goes last (no ``run`` between
+ the filter pattern and the script, unlike pnpm).
"""
job = predeploy_yml["jobs"]["build-and-lint"]
step = _step_by_name(job, "TypeScript check")
assert step is not None, "predeploy.yml must define a `TypeScript check` step"
cmd = step.get("run", "")
- assert (
- "run typecheck" in cmd
- ), f"predeploy.yml typecheck step must call `pnpm ... run typecheck`, got {cmd!r}"
+ assert cmd.startswith("bun run --filter"), (
+ f"predeploy.yml typecheck step must call `bun run --filter ... typecheck`, got {cmd!r}"
+ )
assert (
CLIENT_PKG_NAME in cmd
), f"predeploy.yml typecheck step must filter to {CLIENT_PKG_NAME}, got {cmd!r}"
+ assert cmd.rstrip().endswith("typecheck"), (
+ f"predeploy.yml typecheck step must end with the script name, got {cmd!r}"
+ )
assert "tsc --noEmit" not in cmd, (
"predeploy.yml still calls `tsc --noEmit` directly — switch to "
"the typecheck script so the root TypeScript 7 gate is used"
@@ -511,6 +526,55 @@ def test_preinstall_never_removes_current_package_directory(preinstall_js_src: s
assert "if (fullPath === currentPackageDir) continue" in preinstall_js_src
+def test_preinstall_gates_source_checkouts_to_bun(preinstall_js_src: str):
+ """The dev-PM gate keys on ``bunfig.toml`` (committed, excluded from
+ the npm tarball by the ``files`` allowlist) and on the user agent
+ starting with ``bun``. Bun's UA contains the literal ``npm/?``
+ substring, so a substring match on ``npm`` would misfire — the gate
+ must use a prefix check. End-user tarball installs (no bunfig.toml)
+ must stay on npm without triggering the gate.
+ """
+ assert "bunfig.toml" in preinstall_js_src
+ assert "agent.startsWith('bun')" in preinstall_js_src
+ assert "pnpm-workspace" not in preinstall_js_src
+
+
+def test_root_manifest_declares_bun_as_the_dev_package_manager(root_pkg: dict):
+ """The ``packageManager`` pin is read by ``oven-sh/setup-bun`` in CI
+ and doubles as the read-floor for ``bun.lock`` (the ranged overrides
+ force lockfileVersion 3, which older bun cannot parse). The security
+ pins that lived in ``pnpm.overrides`` must survive at the top level.
+ """
+ assert root_pkg.get("packageManager", "").startswith("bun@")
+ assert "pnpm" not in root_pkg, (
+ "the pnpm config block must not resurface — its overrides moved to "
+ "the top-level 'overrides' key and peerDependencyRules has no bun "
+ "equivalent"
+ )
+ overrides = root_pkg.get("overrides", {})
+ assert overrides, "top-level overrides (security pins) must exist"
+ assert any("@<" in key or "@>=" in key for key in overrides), (
+ "the version-ranged override keys (e.g. 'esbuild@<0.28.1') must be "
+ "preserved verbatim"
+ )
+ assert root_pkg.get("workspaces") == ["client", "server/nodejs"], (
+ "workspaces must list both member PATHS — pnpm-workspace.yaml is gone "
+ "and bun reads only this array"
+ )
+
+
+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
+ asserted above depend on it. bun.lock's configVersion=1 implies the
+ same default, but the explicit bunfig makes the choice reviewable.
+ """
+ src = (root / "bunfig.toml").read_text(encoding="utf-8")
+ assert re.search(r'^linker\s*=\s*"isolated"', src, re.MULTILINE), (
+ 'bunfig.toml must pin linker = "isolated"'
+ )
+
+
# ---------------------------------------------------------------------------
# postinstall — scripts/install.js
# ---------------------------------------------------------------------------