Skip to content

test(electron): make dev-resolution tests self-sufficient on fresh clones#689

Open
ozymandiashh wants to merge 1 commit into
mainfrom
fix/issue-681-electron-test-fixture
Open

test(electron): make dev-resolution tests self-sufficient on fresh clones#689
ozymandiashh wants to merge 1 commit into
mainfrom
fix/issue-681-electron-test-fixture

Conversation

@ozymandiashh

Copy link
Copy Markdown
Collaborator

Closes #681.

Problem

On a fresh clone (no npm run build), the two Vite-development resolveCodeburnPath tests failed with .toMatch() expects to receive a string, but got object: the dev branch only returns the repo CLI path when dist/cli.js exists and is executable.

Fix

Per the issue's preferred direction, the tests now create the fixture they depend on:

  • fakeRepoDevCli() writes a stub executable dist/cli.js at the exact path the production sourceDevBin fallback resolves, and snapshot-restores any pre-existing real build artifact (content and mode restored byte-identically in afterEach; the fixture deletes only what it created, and dist/ is kept when it was non-empty before).
  • A fail-fast precondition asserts the parent-level dist/cli.js candidate (which resolution prefers under vitest's module layout) does not exist, naming the offending absolute path instead of failing later with a confusing toBe mismatch.
  • No skip-when-absent: the tests run and pass with no build present, and still pin the preference order (repo dev CLI over a persisted stale global).

Production code untouched.

Verification

  • npx vitest run app/electron/cli.test.ts on a checkout with NO dist/cli.js: 19/19.
  • Same suite with a pre-existing sentinel dist/cli.js (distinct bytes, mode 0711): 19/19, then the sentinel is restored byte-identically with its exact mode (cmp clean).
  • npx tsc --noEmit clean.

@iamtoruk iamtoruk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The core fixture is sound and the assertions got stronger (exact-path toBe instead of toMatch, real statSync and X_OK checks still exercised), but three things before this can merge.

  1. It is stale against main: there is a content conflict in app/electron/cli.test.ts, and main gained a third fresh-clone failure after this branched (the resolveTarget test where the dev repo CLI beats the bundled CLI). As-is, Closes #681 would close the issue with one of its three symptoms still failing. Rebase and cover that test too.

  2. The stub writes the real repo dist/cli.js, which is the published bin and exactly what npm run dev spawns. The snapshot-restore in afterEach is careful, but a SIGKILL or worker crash between the write and the restore leaves a developer's real build replaced by a 20-byte no-op, silently. Since there is no CI test job, this suite runs precisely on developer machines where that hurts. The cleaner shape already has precedent in this file: CODEBURN_PATH_DIRS exists for tests and advanced setups. A matching dev-root override env var lets the whole fixture live in the per-test tmpdir and deletes the snapshot machinery, the precondition check, and the crash window.

  3. Please drop the beforeAll repo-scanning guard that globs test files and regex-scans imports. It misses import-star and indirect uses, will spuriously fail the suite when someone adds a legitimate isolated resolver test, and likely self-detects on Windows path separators. It is the needless-defensiveness pattern we strip in review.

Happy to re-review quickly, the direction is right.

…_ROOT

Rework of the #681 fix per review: instead of stubbing the real repo
dist/cli.js with snapshot-restore, the Vite-dev resolution branch gains a
CODEBURN_DEV_REPO_ROOT override (matching the CODEBURN_PATH_DIRS precedent)
so the whole fixture lives in a per-test tmpdir. With the env unset the
resolution order is byte-identical to before.

- covers all three fresh-clone failures on current main, including the
  resolveTarget dev-repo-beats-bundled case
- deletes the snapshot-restore machinery, the parent-path precondition and
  the beforeAll repo-scanning guard
- tests assert both override-set (tmpdir wins) and override-unset behavior

Closes #681
@ozymandiashh

Copy link
Copy Markdown
Collaborator Author

Reworked per review, force-pushed as a fresh implementation on current main:

  • Env-var shape adopted: CODEBURN_DEV_REPO_ROOT on the Vite-dev resolution branch (mirroring the CODEBURN_PATH_DIRS precedent). The whole fixture now lives in a per-test tmpdir; the real repo dist/cli.js is never written, so the crash-window concern is gone along with the snapshot-restore machinery and the precondition check. With the env unset, resolution is byte-identical to before (both candidates, same order), covered both ways.
  • All three fresh-clone failures covered on current main, including the newer resolveTarget dev-repo-beats-bundled case; verified on a checkout with no dist/cli.js at any point (27/27).
  • beforeAll scanning guard dropped.

@ozymandiashh
ozymandiashh force-pushed the fix/issue-681-electron-test-fixture branch from c832e85 to 044a062 Compare July 16, 2026 22:54
@ozymandiashh
ozymandiashh requested a review from iamtoruk July 16, 2026 22:54
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.

app/electron/cli.test.ts fails on a fresh clone: dev-resolution tests require a built dist/cli.js

2 participants