Skip to content

Give start_vite's unit tests a toolchain, rather than weakening the refusal - #9656

Merged
danielhanchen merged 1 commit into
mainfrom
fix/start-vite-toolchain-precondition-tests
Aug 24, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
fix/start-vite-toolchain-precondition-tests

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Repo tests (CPU) is red on main at f2fa54f8c:

FAILED tests/studio/test_playwright_server_lifecycle.py::test_start_vite_picks_the_platform_process_group[posix]
FAILED tests/studio/test_playwright_server_lifecycle.py::test_start_vite_picks_the_platform_process_group[nt]
  RuntimeError: the frontend dev dependencies are not installed at .../studio/frontend/node_modules

Attribution is #9654, f2fa54f8c, which is the commit that introduced _require_frontend_toolchain and the string in that message. Reproduced locally on a clean checkout of f2fa54f8c: 2 failed, 17 passed.

Which side is wrong

Both readings were live, so stating the one I took and why.

The refusal is right and stays exactly as it is. start_vite's entire job is to start vite. There is no caller that reaches it without meaning to launch a dev server; the only thing in the repo that calls it with subprocess.Popen stubbed is a unit test. Moving the check to the point of use means moving it after the spawn, and after the spawn is precisely the state #9654 removed: npm run dev exits 127, the readiness poll reports vite exited with code 127, and a missing setup step reads as a vite crash. That cost a day of it looking like flake. Weakening or relocating it would undo the PR.

The two tests are stale. Three things say so:

  • They exercise which process-group flag the platform gets, nothing else. _require_frontend_toolchain is not what they are about.
  • They already stub the sibling precondition. monkeypatch.setattr(robust, "_port_is_taken", lambda port, host: False) is in both of them, because the occupied-port refusal is not what they are about either. The toolchain check is a precondition of exactly the same shape, added later, and the tests were not updated for it.
  • The file's own docstring is explicit: "Everything here is monkeypatched: no npm, no browser, no sockets bound." A check that stats the real studio/frontend is a real-world dependency this file never intended to have.

So the change is entirely in the test file. tests/studio/_playwright_robust.py is untouched.

A tree, not a stub

The obvious fix is monkeypatch.setattr(robust, "_require_frontend_toolchain", lambda: None), and it is the wrong one: it would keep both tests green if the refusal were deleted from start_vite outright, which is the vacuity shape we keep finding. They get a synthetic tree instead:

@pytest.fixture
def installed_frontend(monkeypatch, tmp_path):
    binaries = tmp_path / "node_modules" / ".bin"
    binaries.mkdir(parents = True)
    (binaries / "vite").write_text("#!/bin/sh\n", encoding = "utf-8")
    monkeypatch.setattr(robust, "FRONTEND", tmp_path)

The check runs and passes on its merits, and nothing depends on a real install. The demonstration that this is not a stub is case V6 below.

test_an_occupied_port_is_refused_rather_than_measured gets the same fixture. It passes on main today only because the port check happens to be written above the toolchain check; with a satisfied toolchain it asserts the port refusal itself rather than the order the two preconditions are written in.

The refusal had no test at all

That is the other half of this. #9654's up-front refusal is the thing the PR exists for, and nothing pinned it, so it could be deleted or narrowed silently. Three tests added:

  • it must reject a tree with no toolchain before anything is spawned. The assertion is not just that it raises, it is assert spawned == [], because a refusal landing after Popen has already lost the cause.
  • it must accept vite.cmd, vite.exe and vite.bunx, not only the POSIX name. bun writes .bunx shims and npm writes .cmd on Windows, and a POSIX-only check would reject a good tree.
  • a missing checkout must be reported as its own failure, not folded into "not installed". Run from outside the repo is a different mistake from run without an install.

Anti-vacuity

25 passed on a clean tree, on a checkout with no studio/frontend/node_modules at all, which is the condition that made main red. Every case mutated the real file, was confirmed on disk by md5, and was restored from a byte snapshot.

mutation expect result
V1 the _require_frontend_toolchain() call deleted from start_vite fail FAILED ...refuses_a_tree_with_no_frontend_toolchain
V2 the call moved to after the Popen fail AssertionError: the refusal must land before npm is spawned, or the cause is lost
V3 the check returns early and accepts anything fail 2 failed, both toolchain tests
V4 vite.cmd / vite.exe / vite.bunx dropped from the accepted names fail 3 failed, one per shim
V5 the missing-frontend branch removed fail FAILED ...names_a_missing_frontend_separately
V6 control: the check made to reject everything fail FAILED ...picks_the_platform_process_group[posix] and [nt]

V6 is the one that matters for the fixture. Both process-group tests go red when the check is broken, which is only possible because they run it. Had they stubbed it out they would have stayed green, and the fix would have been a way of not noticing.

Checked

  • tests/studio/test_playwright_server_lifecycle.py: 25 passed, was 17 passed / 2 failed on main
  • tests/studio/test_playwright_suites_run_in_ci.py and test_indicator_browsers_run_in_parallel.py: 21 passed
  • ruff clean, git diff --check clean
  • tests/studio/_playwright_robust.py not modified: git diff origin/main touches one file

…efusal

#9654 added an up-front toolchain refusal to start_vite so a job with no
node_modules fails with the cause instead of 'vite exited with code 127'. That
is right, and the two process-group tests were simply not updated for the new
precondition: they exercise which process-group flag the platform gets, they
already stub the sibling _port_is_taken precondition for the same reason, and
this file's own docstring promises nothing here touches npm or a real install.

So the tests get a synthetic frontend tree in tmp_path with a vite shim, not a
stubbed-out check. A stub would keep them green if the refusal were deleted;
a tree makes the check run and pass on its merits.

Adds the tests the refusal never had: it must reject a tree with no toolchain
BEFORE anything is spawned, accept the bun and Windows shims as well as the
POSIX name, and report a missing checkout as its own failure.
@danielhanchen
danielhanchen merged commit 2d5d4d8 into main Aug 24, 2026
26 checks passed
@danielhanchen
danielhanchen deleted the fix/start-vite-toolchain-precondition-tests branch August 24, 2026 23:38
rhsCZ pushed a commit to rhsCZ/unsloth that referenced this pull request Aug 25, 2026
Picks up unslothai#9654 and unslothai#9656, which clear the overlay rail shard, and the Apertus
mapping fix. No conflicts.
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