From 283f2e78c0d7ac8c65fe7cc6dca6a072e369ecb3 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 10 Oct 2026 03:33:13 +0000 Subject: [PATCH] test(core): build a private bundle for the worker-event forwarding test The test imported packages/core/dist/index.js, which `pnpm build` (tsup, clean: true) deletes and rewrites. A build running alongside the test could remove the bundle mid-import: ERR_MODULE_NOT_FOUND, 2 failures in 50 runs with build and lint looping in parallel. The test now builds its own copy into a fresh directory under node_modules (so bare imports resolve) and removes it afterwards. 0 failures in 50 runs under the same load. Closes #58 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EmiChUUtLdjbg6mNzKqVep Signed-off-by: Claude --- packages/core/src/check/progress.test.ts | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/core/src/check/progress.test.ts b/packages/core/src/check/progress.test.ts index 769a77e..bd21e55 100644 --- a/packages/core/src/check/progress.test.ts +++ b/packages/core/src/check/progress.test.ts @@ -1,7 +1,9 @@ import { execFileSync } from 'node:child_process'; -import { resolve } from 'node:path'; +import { mkdirSync, mkdtempSync, rmSync } from 'node:fs'; +import { createRequire } from 'node:module'; +import { dirname, join, resolve } from 'node:path'; import { pathToFileURL } from 'node:url'; -import { expect, it } from 'vitest'; +import { afterAll, expect, it } from 'vitest'; import { type ProgressEvent, progress } from '../domain/progress.js'; it('pairs progress events even when a phase fails', async () => { @@ -18,8 +20,23 @@ it('pairs progress events even when a phase fails', async () => { expect(events.map((e) => e.state)).toEqual(['start', 'done']); expect(events[1]?.ms).toBeGreaterThanOrEqual(0); }); +// The built worker (dist/worker.js), not the source one the rest of the suite runs. Built into +// a private directory: `pnpm build` cleans and rewrites dist/, so a build running alongside +// (turbo, an editor, a second terminal) could delete the bundle mid-import (#58). Inside +// node_modules so the bundle's bare imports still resolve from the package. +const pkg = resolve(import.meta.dirname, '../..'); +mkdirSync(join(pkg, 'node_modules'), { recursive: true }); +const privateDist = mkdtempSync(join(pkg, 'node_modules/.uptide-progress-test-')); +afterAll(() => rmSync(privateDist, { recursive: true, force: true })); it('forwards real workspace worker events without serializing the callback', () => { - const entry = pathToFileURL(resolve(import.meta.dirname, '../../dist/index.js')).href; + const tsup = join( + dirname(createRequire(import.meta.url).resolve('tsup/package.json')), + 'dist/cli-default.js', + ); + execFileSync(process.execPath, [tsup, '--no-dts', '--no-sourcemap', '--out-dir', privateDist], { + cwd: pkg, + }); + const entry = pathToFileURL(join(privateDist, 'index.js')).href; const cwd = resolve(import.meta.dirname, '../../../../fixtures/repos/workspace-consumer'); const output = execFileSync( process.execPath,