From edb09fe6ba4727bf2ac2ae1b83edca30da5c791b Mon Sep 17 00:00:00 2001 From: oratis Date: Sat, 30 May 2026 01:34:01 +0800 Subject: [PATCH] test(cli,lsp): alias @deepcode/core to source so tests need no prior build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `pnpm -r test` (and `pnpm --filter` on cli/lsp alone) failed from a clean checkout with: Error: Failed to resolve entry for package "@deepcode/core". The package may have incorrect main/module/exports specified... Both apps import @deepcode/core, whose package "main" points at ./dist. Vitest extends Vite, which resolves that bare specifier to the (unbuilt) dist at transform time. It only worked in CI because `pnpm typecheck` (`tsc -b`, which emits) runs before `pnpm test`, so dist happened to exist — a build-order footgun for anyone running tests directly. Add a vitest.config.ts to each app aliasing `@deepcode/core` to its source entry, mirroring apps/desktop/vite.config.ts. Tests now run against source, are self-contained, and need no prior build. Verified `pnpm -r test` passes from a fully clean (no dist) state; typecheck/lint/format unaffected. Co-Authored-By: Claude Opus 4.8 (1M context) --- apps/cli/vitest.config.ts | 22 ++++++++++++++++++++++ apps/lsp/vitest.config.ts | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 apps/cli/vitest.config.ts create mode 100644 apps/lsp/vitest.config.ts diff --git a/apps/cli/vitest.config.ts b/apps/cli/vitest.config.ts new file mode 100644 index 0000000..6822f21 --- /dev/null +++ b/apps/cli/vitest.config.ts @@ -0,0 +1,22 @@ +// CLI unit tests run in node. They import from @deepcode/core, whose +// package "main" points at ./dist — so without this alias the tests would +// require `@deepcode/core` to be built first (a build-order footgun that +// only works in CI because `pnpm typecheck` runs `tsc -b` and emits dist +// before `pnpm test`). Aliasing the bare specifier to core's source makes +// the tests self-contained and fast, mirroring apps/desktop/vite.config.ts. + +import { defineConfig } from 'vitest/config'; +import { resolve } from 'node:path'; + +export default defineConfig({ + test: { + include: ['src/**/*.test.ts'], + environment: 'node', + globals: true, + }, + resolve: { + alias: { + '@deepcode/core': resolve(__dirname, '..', '..', 'packages', 'core', 'src', 'index.ts'), + }, + }, +}); diff --git a/apps/lsp/vitest.config.ts b/apps/lsp/vitest.config.ts new file mode 100644 index 0000000..c7fec2d --- /dev/null +++ b/apps/lsp/vitest.config.ts @@ -0,0 +1,22 @@ +// LSP unit tests run in node and reach @deepcode/core through handler.ts. +// core's package "main" points at ./dist, so without this alias the tests +// would require core to be built first (a build-order footgun that only +// works in CI because `pnpm typecheck` runs `tsc -b` and emits dist before +// `pnpm test`). Aliasing the bare specifier to core's source keeps the +// tests self-contained, mirroring apps/cli + apps/desktop. + +import { defineConfig } from 'vitest/config'; +import { resolve } from 'node:path'; + +export default defineConfig({ + test: { + include: ['src/**/*.test.ts'], + environment: 'node', + globals: true, + }, + resolve: { + alias: { + '@deepcode/core': resolve(__dirname, '..', '..', 'packages', 'core', 'src', 'index.ts'), + }, + }, +});