diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eb7d1ee..2a4038d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,14 +6,20 @@ on: branches: [main] jobs: + # Runs on the three desktop platforms of the community edition (P1.3b, P2.1). test: - runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 + # The Node version the installer and the desktop app ship (ADR-0008). - uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 22.23.2 - name: Cache npm dependencies uses: actions/cache@v4 @@ -23,24 +29,23 @@ jobs: restore-keys: | ${{ runner.os }}-npm- - # NOTE: the switch to `npm ci` (deterministic, lockfile-faithful) is deferred - # to the deps/lockfile hardening pass, after the root package-lock.json is - # regenerated in sync with every workspace manifest. `npm install` is the - # safe, lockfile-tolerant install until then. - run: npm install + env: + ONNXRUNTIME_NODE_INSTALL_CUDA: skip - # Real typecheck gate. The old step ran `npx tsc --noEmit` against the root - # tsconfig.json, whose `"files": ["apps/web/src/vite-env.d.ts"]` (and no - # `include`) typechecks essentially nothing. build:packages is the actual - # `tsc --build` chain for every @waggle/* package (shared → hive-mind-core → - # core → agent → server) and also emits the dist/ that apps/web unit tests - # import; typecheck:web is the real apps/web check (tsc -p tsconfig.app.json). - - name: Type check — workspace packages (tsc --build chain) + # One `tsc -b` over the project references in tsconfig.build.json: every + # in-scope @waggle/* package, in dependency order. + - name: Type check — workspace packages (tsc -b) run: npm run build:packages - name: Type check — web (apps/web, tsc -p tsconfig.app.json) run: npm run typecheck:web + # Advisory until the existing test type errors are fixed. + - name: Type check — tests (tsconfig.tests.json) + run: npm run typecheck:tests + continue-on-error: true + - name: Lint (root flat config) run: npm run lint @@ -54,39 +59,31 @@ jobs: # dist/ payload explicitly so CI proves a fresh checkout. - name: Build package-install test runtimes run: | - npm run build:hook-runtime npm run build --workspace @waggle/cli npm run build --workspace @waggle-ai/waggle - npm run build --workspace waggle-memory-mcp - name: Unit tests — packages + cross-cutting (root vitest) - run: | - npm test -- \ - --exclude=packages/cli/tests/cli-runtime.test.ts \ - --exclude=packages/marketplace/tests/cli-runtime.test.ts \ - --exclude=packages/hive-mind-cli/tests/cli-help.test.ts \ - --exclude=packages/hive-mind-mcp-server/tests/runtime.test.ts \ - --exclude=packages/launcher/tests/cli.test.ts \ - --exclude=packages/memory-mcp/tests/runtime.test.ts \ - --maxWorkers=2 + run: >- + npm test -- + --exclude=packages/cli/tests/cli-runtime.test.ts + --exclude=packages/marketplace/tests/cli-runtime.test.ts + --exclude=packages/launcher/tests/cli.test.ts + --maxWorkers=2 # These tests each create a temporary project and run npm install. Running # several cold installs in parallel makes individual test timeouts measure # runner contention rather than package correctness. - name: Package-install runtime tests (serial) - run: | - npx vitest run \ - packages/cli/tests/cli-runtime.test.ts \ - packages/marketplace/tests/cli-runtime.test.ts \ - packages/hive-mind-cli/tests/cli-help.test.ts \ - packages/hive-mind-mcp-server/tests/runtime.test.ts \ - packages/launcher/tests/cli.test.ts \ - packages/memory-mcp/tests/runtime.test.ts \ - --maxWorkers=1 \ - --no-file-parallelism + run: >- + npx vitest run + packages/cli/tests/cli-runtime.test.ts + packages/marketplace/tests/cli-runtime.test.ts + packages/launcher/tests/cli.test.ts + --maxWorkers=1 + --no-file-parallelism - # The root vitest.config.ts excludes `apps/**`, so apps/web's own 131-file - # suite never ran in CI. Run it via its own vitest config (jsdom). Blocking. + # The root vitest.config.ts excludes `apps/**`; apps/web runs its own + # suite (jsdom). - name: Unit tests — apps/web run: npm run test -w apps/web @@ -110,7 +107,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 22.23.2 - name: Cache npm dependencies uses: actions/cache@v4 @@ -143,7 +140,7 @@ jobs: - uses: actions/setup-node@v4 with: - node-version: 20 + node-version: 22.23.2 - name: Cache npm dependencies uses: actions/cache@v4 diff --git a/app/src-tauri/src/service.rs b/app/src-tauri/src/service.rs index 977f183..ad96c32 100644 --- a/app/src-tauri/src/service.rs +++ b/app/src-tauri/src/service.rs @@ -621,7 +621,12 @@ fn build_service_command( let mut cmd = if service_script.kind == ServiceScriptKind::DevSource { let mut c = Command::new(&node_path); - c.arg("--import").arg("tsx").arg(&service_script.path); + // Workspace packages resolve to their sources through the `source` + // export condition, so a dev launch needs no build:packages first. + c.arg("--conditions=source") + .arg("--import") + .arg("tsx") + .arg(&service_script.path); c } else { let mut c = Command::new(&node_path); diff --git a/apps/web/tsconfig.app.json b/apps/web/tsconfig.app.json index 51f581d..9b5f746 100644 --- a/apps/web/tsconfig.app.json +++ b/apps/web/tsconfig.app.json @@ -11,6 +11,7 @@ "module": "ESNext", "moduleDetection": "force", "moduleResolution": "bundler", + "customConditions": ["source"], "noEmit": true, "noFallthroughCasesInSwitch": false, "noImplicitAny": false, diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index f38ae38..7dbf78e 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -1,4 +1,4 @@ -import { defineConfig } from "vite"; +import { defineConfig, defaultClientConditions } from "vite"; import react from "@vitejs/plugin-react-swc"; import path from "path"; import { componentTagger } from "lovable-tagger"; @@ -47,6 +47,9 @@ export default defineConfig(({ mode }) => ({ }, }, resolve: { + // Workspace packages (@waggle/shared) resolve to src/ through their + // `source` export, so the UI builds without build:packages (P2.1). + conditions: ["source", ...defaultClientConditions], alias: { "@": path.resolve(__dirname, "./src"), }, diff --git a/apps/web/vitest.config.ts b/apps/web/vitest.config.ts index 0e62eab..8b38e19 100644 --- a/apps/web/vitest.config.ts +++ b/apps/web/vitest.config.ts @@ -1,4 +1,5 @@ import { defineConfig } from "vitest/config"; +import { defaultClientConditions } from "vite"; import react from "@vitejs/plugin-react-swc"; import path from "path"; @@ -27,6 +28,7 @@ export default defineConfig({ retry: 1, }, resolve: { + conditions: ["source", ...defaultClientConditions], alias: { "@": path.resolve(__dirname, "./src") }, }, }); diff --git a/package.json b/package.json index 8c3b39f..843e6c3 100644 --- a/package.json +++ b/package.json @@ -14,12 +14,13 @@ "scripts": { "dev": "cd apps/web && npx vite", "dev:web": "npm run dev", - "dev:server": "cd packages/server && npx tsx src/local/start.ts", + "dev:server": "cd packages/server && npx tsx --conditions=source src/local/start.ts", "build": "cd apps/web && npx tsc --noEmit -p tsconfig.app.json && npx vite build --outDir ../../dist --emptyOutDir", "build:dev": "cd apps/web && npx vite build --mode development --outDir ../../dist --emptyOutDir", "typecheck:web": "cd apps/web && npx tsc --noEmit -p tsconfig.app.json", + "typecheck:tests": "tsc -p tsconfig.tests.json", "preview": "cd apps/web && npx vite preview", - "build:packages": "cd packages/shared && npx tsc --build && cd ../memory-contract && npx tsc --build && cd ../memory-mem0 && npx tsc --build && cd ../core && npx tsc --build && cd ../marketplace && npx tsc --build && cd ../agent && npx tsc --build && cd ../server && npx tsc --build", + "build:packages": "tsc -b tsconfig.build.json", "build:hook-runtime": "node scripts/build-hook-runtime.mjs", "build:all": "npm run build:packages && npm run build", "dev:www": "npm run dev -w apps/www", diff --git a/packages/agent/package.json b/packages/agent/package.json index a146e37..68966f7 100644 --- a/packages/agent/package.json +++ b/packages/agent/package.json @@ -7,16 +7,19 @@ "types": "dist/index.d.ts", "exports": { ".": { + "source": "./src/index.ts", "types": "./dist/index.d.ts", "import": "./dist/index.js" }, "./external-process-env": { + "source": "./src/external-process-env.ts", "types": "./dist/external-process-env.d.ts", "import": "./dist/external-process-env.js" } }, "files": [ - "dist" + "dist", + "src" ], "scripts": { "build": "tsc --build --force && node ../../scripts/stage-agent-pptx-runtime.mjs", diff --git a/packages/agent/tsconfig.json b/packages/agent/tsconfig.json index 3d7b52b..8906086 100644 --- a/packages/agent/tsconfig.json +++ b/packages/agent/tsconfig.json @@ -20,6 +20,8 @@ "exclude": ["node_modules", "dist", "tests"], "references": [ { "path": "../core" }, - { "path": "../memory-contract" } + { "path": "../marketplace" }, + { "path": "../memory-contract" }, + { "path": "../shared" } ] } diff --git a/packages/cli/package.json b/packages/cli/package.json index fde4c96..1bba2bb 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -7,6 +7,7 @@ "types": "dist/index.d.ts", "exports": { ".": { + "source": "./src/index.ts", "types": "./dist/index.d.ts", "import": "./dist/index.js" } @@ -16,6 +17,7 @@ }, "files": [ "dist", + "src", "bin" ], "license": "MIT", @@ -46,7 +48,7 @@ "scripts": { "build": "tsc", "test": "node ../../node_modules/vitest/vitest.mjs run --root ../.. --config vitest.config.ts packages/cli/tests/commands.test.ts packages/cli/tests/admin.test.ts packages/cli/tests/renderer.test.ts packages/cli/tests/memory-persistence-hard.test.ts packages/cli/tests/auth.test.ts packages/cli/tests/mode-detector.test.ts packages/cli/tests/comprehensive-e2e.test.ts packages/cli/tests/cli-runtime.test.ts", - "dev": "tsx src/index.ts" + "dev": "tsx --conditions=source src/index.ts" }, "dependencies": { "@waggle/core": "*", diff --git a/packages/cli/tsconfig.json b/packages/cli/tsconfig.json index 2dfcb87..2a42506 100644 --- a/packages/cli/tsconfig.json +++ b/packages/cli/tsconfig.json @@ -19,8 +19,8 @@ "include": ["src/**/*.ts"], "exclude": ["node_modules", "dist", "tests"], "references": [ - { "path": "../core" }, { "path": "../agent" }, + { "path": "../core" }, { "path": "../memory-contract" }, { "path": "../memory-mem0" } ] diff --git a/packages/core/package.json b/packages/core/package.json index b76a442..81619c5 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -7,6 +7,7 @@ "types": "dist/index.d.ts", "exports": { ".": { + "source": "./src/index.ts", "types": "./dist/index.d.ts", "import": "./dist/index.js" } diff --git a/packages/core/tsconfig.json b/packages/core/tsconfig.json index 3620688..26f47ee 100644 --- a/packages/core/tsconfig.json +++ b/packages/core/tsconfig.json @@ -19,6 +19,7 @@ "include": ["src/**/*.ts"], "exclude": ["node_modules", "dist", "tests"], "references": [ - { "path": "../memory-contract" } + { "path": "../memory-contract" }, + { "path": "../shared" } ] } diff --git a/packages/launcher/package.json b/packages/launcher/package.json index 6e492e5..df26d03 100644 --- a/packages/launcher/package.json +++ b/packages/launcher/package.json @@ -18,7 +18,7 @@ }, "scripts": { "build": "tsup", - "start": "tsx src/cli.ts", + "start": "tsx --conditions=source src/cli.ts", "test": "node ../../node_modules/vitest/vitest.mjs run --root ../.. --config vitest.config.ts packages/launcher/tests/cli.test.ts", "prepublishOnly": "npm run build" }, diff --git a/packages/launcher/tsup.config.ts b/packages/launcher/tsup.config.ts index 93e5468..ed7d7a0 100644 --- a/packages/launcher/tsup.config.ts +++ b/packages/launcher/tsup.config.ts @@ -12,6 +12,10 @@ export default defineConfig({ // Inline all @waggle/* workspace packages into the bundle. // Third-party npm packages stay external (installed as dependencies). noExternal: [/^@waggle\//], + // Build the workspace packages from their source export, not a stale dist/. + esbuildOptions(options) { + options.conditions = ['source']; + }, // Runtime packages that cannot be bundled safely. external: [ '@huggingface/transformers', diff --git a/packages/marketplace/package.json b/packages/marketplace/package.json index 534e508..10c13ef 100644 --- a/packages/marketplace/package.json +++ b/packages/marketplace/package.json @@ -7,6 +7,7 @@ "types": "dist/index.d.ts", "exports": { ".": { + "source": "./src/index.ts", "types": "./dist/index.d.ts", "import": "./dist/index.js" } @@ -41,6 +42,7 @@ }, "files": [ "dist/", + "src/", "README.md" ], "keywords": [ diff --git a/packages/marketplace/tests/cli-runtime.test.ts b/packages/marketplace/tests/cli-runtime.test.ts index 316beb0..2fd5cdf 100644 --- a/packages/marketplace/tests/cli-runtime.test.ts +++ b/packages/marketplace/tests/cli-runtime.test.ts @@ -113,9 +113,11 @@ describe('marketplace CLI runtime UX', () => { expect(pkg.main).toBe('dist/index.js'); expect(pkg.types).toBe('dist/index.d.ts'); expect(pkg.exports['.']).toEqual({ + source: './src/index.ts', import: './dist/index.js', types: './dist/index.d.ts', }); + expect(packedFiles.has('src/index.ts')).toBe(true); expect(packedFiles.has('dist/index.js')).toBe(true); expect(packedFiles.has('dist/index.d.ts')).toBe(true); expect(packedFiles.has('dist/cli.js')).toBe(true); diff --git a/packages/marketplace/tsconfig.json b/packages/marketplace/tsconfig.json index af0993f..4458553 100644 --- a/packages/marketplace/tsconfig.json +++ b/packages/marketplace/tsconfig.json @@ -14,7 +14,8 @@ "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "resolveJsonModule": true, - "isolatedModules": true + "isolatedModules": true, + "composite": true }, "include": ["src/**/*.ts"], "exclude": ["node_modules", "dist"] diff --git a/packages/memory-contract/package.json b/packages/memory-contract/package.json index f9db2f3..59e9f28 100644 --- a/packages/memory-contract/package.json +++ b/packages/memory-contract/package.json @@ -6,6 +6,7 @@ "type": "module", "exports": { ".": { + "source": "./src/index.ts", "types": "./dist/index.d.ts", "import": "./dist/index.js" } diff --git a/packages/memory-mem0/package.json b/packages/memory-mem0/package.json index 1ce19cf..179daec 100644 --- a/packages/memory-mem0/package.json +++ b/packages/memory-mem0/package.json @@ -6,6 +6,7 @@ "type": "module", "exports": { ".": { + "source": "./src/index.ts", "types": "./dist/index.d.ts", "import": "./dist/index.js" } diff --git a/packages/memory-mem0/tsconfig.json b/packages/memory-mem0/tsconfig.json index b0c54fe..3620688 100644 --- a/packages/memory-mem0/tsconfig.json +++ b/packages/memory-mem0/tsconfig.json @@ -17,5 +17,8 @@ "composite": true }, "include": ["src/**/*.ts"], - "exclude": ["node_modules", "dist", "tests"] + "exclude": ["node_modules", "dist", "tests"], + "references": [ + { "path": "../memory-contract" } + ] } diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 7ec0e19..0db66ba 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -6,7 +6,11 @@ "main": "dist/index.js", "types": "dist/index.d.ts", "exports": { - ".": "./src/index.ts" + ".": { + "source": "./src/index.ts", + "types": "./dist/index.d.ts", + "import": "./dist/index.js" + } }, "license": "MIT", "scripts": { diff --git a/packages/sdk/tsconfig.json b/packages/sdk/tsconfig.json index b0c54fe..634efe5 100644 --- a/packages/sdk/tsconfig.json +++ b/packages/sdk/tsconfig.json @@ -17,5 +17,8 @@ "composite": true }, "include": ["src/**/*.ts"], - "exclude": ["node_modules", "dist", "tests"] + "exclude": ["node_modules", "dist", "tests"], + "references": [ + { "path": "../shared" } + ] } diff --git a/packages/server/package.json b/packages/server/package.json index 1c71344..fcd88a6 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -3,15 +3,27 @@ "version": "0.1.0", "type": "module", "exports": { - "./local": "./src/local/index.ts", - "./local/service": "./src/local/service.ts", - "./local/routes/*": "./src/local/routes/*.ts" + "./local": { + "source": "./src/local/index.ts", + "types": "./dist/local/index.d.ts", + "import": "./dist/local/index.js" + }, + "./local/service": { + "source": "./src/local/service.ts", + "types": "./dist/local/service.d.ts", + "import": "./dist/local/service.js" + }, + "./local/routes/*": { + "source": "./src/local/routes/*.ts", + "types": "./dist/local/routes/*.d.ts", + "import": "./dist/local/routes/*.js" + } }, "scripts": { - "dev": "tsx watch src/local/start.ts", + "dev": "tsx watch --conditions=source src/local/start.ts", "build": "tsc", "test": "node ../../node_modules/vitest/vitest.mjs run --root ../.. --config vitest.config.ts packages/server/tests --maxWorkers=1 --silent", - "start:local": "tsx src/local/start.ts" + "start:local": "tsx --conditions=source src/local/start.ts" }, "dependencies": { "@anthropic-ai/sdk": "^0.78.0", diff --git a/packages/server/tsconfig.json b/packages/server/tsconfig.json index 54753e6..7fe2af6 100644 --- a/packages/server/tsconfig.json +++ b/packages/server/tsconfig.json @@ -16,9 +16,15 @@ "sourceMap": true, "composite": true }, - "references": [ - { "path": "../shared" } - ], "include": ["src/**/*.ts"], - "exclude": ["node_modules", "dist", "tests"] + "exclude": ["node_modules", "dist", "tests"], + "references": [ + { "path": "../agent" }, + { "path": "../core" }, + { "path": "../marketplace" }, + { "path": "../memory-contract" }, + { "path": "../memory-mem0" }, + { "path": "../sdk" }, + { "path": "../shared" } + ] } diff --git a/packages/shared/package.json b/packages/shared/package.json index 9be8f07..7627f9b 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -4,6 +4,7 @@ "type": "module", "exports": { ".": { + "source": "./src/index.ts", "types": "./dist/index.d.ts", "import": "./dist/index.js" } diff --git a/playwright.config.ts b/playwright.config.ts index c1fdfce..922e09e 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -93,7 +93,7 @@ export default defineConfig({ * The server auto-detects /dist per packages/server/src/local/ * index.ts — no WAGGLE_FRONTEND_DIR override needed. */ webServer: { - command: `npm run build:all && ${e2eNodeCommand} node_modules/tsx/dist/cli.mjs packages/server/src/local/start.ts${e2eSkipLiteLLM ? ' --skip-litellm' : ''}`, + command: `npm run build:all && ${e2eNodeCommand} node_modules/tsx/dist/cli.mjs --conditions=source packages/server/src/local/start.ts${e2eSkipLiteLLM ? ' --skip-litellm' : ''}`, url: new URL('/health', e2eBaseURL).toString(), reuseExistingServer: e2eReuseExistingServer, timeout: 600_000, // Cold Windows build + scanning + tsx sidecar import can exceed 5 min diff --git a/scripts/build-sidecar.mjs b/scripts/build-sidecar.mjs index 6fb5127..d555ad6 100644 --- a/scripts/build-sidecar.mjs +++ b/scripts/build-sidecar.mjs @@ -173,23 +173,11 @@ try { format: 'esm', outfile: outFile, external: EXTERNAL, - // P4/D12: workspace package metadata can resolve to gitignored dist/. - // Alias all bundled first-party packages to their tracked source entry. - // Without these aliases the bundle silently embeds whatever dist/ was - // last compiled — the same stale-server-in-the-binary class D12 exists - // to kill — and a clean checkout can't build at all without - // build:packages. Alias to source so the bundle ALWAYS compiles from - // src, like the vitest aliases do. Exact subpath aliases must precede - // their package root so esbuild never appends a subpath to index.ts. - alias: { - '@waggle/agent/external-process-env': path.join(root, 'packages', 'agent', 'src', 'external-process-env.ts'), - '@waggle/agent': path.join(root, 'packages', 'agent', 'src', 'index.ts'), - '@waggle/core': path.join(root, 'packages', 'core', 'src', 'index.ts'), - '@waggle/marketplace': path.join(root, 'packages', 'marketplace', 'src', 'index.ts'), - '@waggle/memory-contract': path.join(root, 'packages', 'memory-contract', 'src', 'index.ts'), - '@waggle/memory-mem0': path.join(root, 'packages', 'memory-mem0', 'src', 'index.ts'), - '@waggle/shared': path.join(root, 'packages', 'shared', 'src', 'index.ts'), - }, + // P4/D12: workspace packages publish dist/ entries, which are gitignored + // and can be stale. Every first-party package also exports its source + // under the `source` condition, so the bundle always compiles from src/ + // and a clean checkout builds without build:packages. + conditions: ['source'], sourcemap: false, minify: true, // metafile lets stage-sidecar-deps.mjs enumerate exactly which of the diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 0000000..f1c3561 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,14 @@ +{ + "files": [], + "references": [ + { "path": "packages/shared" }, + { "path": "packages/memory-contract" }, + { "path": "packages/memory-mem0" }, + { "path": "packages/core" }, + { "path": "packages/marketplace" }, + { "path": "packages/sdk" }, + { "path": "packages/agent" }, + { "path": "packages/server" }, + { "path": "packages/cli" } + ] +} diff --git a/tsconfig.tests.json b/tsconfig.tests.json new file mode 100644 index 0000000..af18e55 --- /dev/null +++ b/tsconfig.tests.json @@ -0,0 +1,27 @@ +{ + "compilerOptions": { + "target": "ES2022", + "module": "ESNext", + "moduleResolution": "bundler", + "customConditions": ["source"], + "lib": ["ES2022", "DOM"], + "strict": true, + "esModuleInterop": true, + "skipLibCheck": true, + "resolveJsonModule": true, + "allowImportingTsExtensions": true, + "noEmit": true, + "types": ["node", "vitest/globals"] + }, + "include": [ + "packages/shared/tests/**/*.ts", + "packages/memory-contract/tests/**/*.ts", + "packages/memory-mem0/tests/**/*.ts", + "packages/core/tests/**/*.ts", + "packages/marketplace/tests/**/*.ts", + "packages/sdk/tests/**/*.ts", + "packages/agent/tests/**/*.ts", + "packages/server/tests/**/*.ts", + "packages/cli/tests/**/*.ts" + ] +} diff --git a/vitest.aliases.ts b/vitest.aliases.ts index d490249..17eb073 100644 --- a/vitest.aliases.ts +++ b/vitest.aliases.ts @@ -1,35 +1,36 @@ -import { readdirSync, existsSync } from 'node:fs'; +import { readdirSync, existsSync, readFileSync } from 'node:fs'; import { resolve, join } from 'node:path'; /** - * Map every `@waggle/` workspace package to its TypeScript source entry - * (`packages//src/index.ts`) so vitest resolves them from source without - * a build step. - * - * Why: several packages (shared, all hive-mind-*, cli, mcp-server) declare a - * `dist/` entry in package.json `exports` — correct for publishing, but on a - * fresh checkout (including CI) `dist/` isn't built, so importing them in tests - * fails with "Failed to resolve entry for package". Aliasing to `src/` — the - * same trick the former inline `@waggle/marketplace` alias used — makes the test - * environment build-independent. Packages that already export `src/` (agent, - * core, …) resolve to the same place, so the alias is a no-op for them. - * - * Only packages with a real `src/index.ts` are aliased (guarded), so dirs - * without that entry (e.g. admin-web) are left to normal resolution. + * Resolve conditions for the test runs: workspace packages export their + * TypeScript source under the `source` condition (P2.1), so tests run against + * src/ without a build step, the same way tsx and the sidecar bundle do. + */ +export const WAGGLE_SOURCE_CONDITIONS = ['source', 'module', 'node', 'development|production']; + +/** + * Map the `@waggle/` packages that do not export a `source` condition to + * their `src/` directory. Only the packages excluded from the community + * edition (hive-mind-*, memory-mcp, wiki-compiler and the postponed team + * packages) still need this; it goes away with them. * * The alias target is the `src/` DIRECTORY (not `src/index.ts`): vite resolves * a bare `@waggle/x` import to the directory's index, AND a subpath import like - * `@waggle/server/local/service` to `…/src/local/service`. Pointing at the file - * instead would rewrite the subpath to `…/src/index.ts/local/service` and break. + * `@waggle/x/scope` to `…/src/scope`. */ export function waggleSrcAliases(repoRoot: string): Record { const pkgsDir = resolve(repoRoot, 'packages'); const aliases: Record = {}; for (const dir of readdirSync(pkgsDir)) { const srcDir = join(pkgsDir, dir, 'src'); - if (existsSync(join(srcDir, 'index.ts'))) { - aliases[`@waggle/${dir}`] = srcDir; - } + if (!existsSync(join(srcDir, 'index.ts')) || exportsSource(join(pkgsDir, dir, 'package.json'))) continue; + aliases[`@waggle/${dir}`] = srcDir; } return aliases; } + +function exportsSource(manifestPath: string): boolean { + if (!existsSync(manifestPath)) return false; + const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8')) as { exports?: unknown }; + return JSON.stringify(manifest.exports ?? null).includes('"source"'); +} diff --git a/vitest.config.ts b/vitest.config.ts index 5dd2f7b..1a38518 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -1,19 +1,24 @@ import { defineConfig } from 'vitest/config'; import path from 'node:path'; import { INFRA_TEST_SUITES } from './vitest.infra-suites'; -import { waggleSrcAliases } from './vitest.aliases'; +import { WAGGLE_SOURCE_CONDITIONS, waggleSrcAliases } from './vitest.aliases'; export default defineConfig({ resolve: { + // Workspace packages resolve to src/ through their `source` export, so + // tests need no build step (P2.1). + conditions: WAGGLE_SOURCE_CONDITIONS, alias: { - // Resolve every @waggle/* workspace package from src/ so tests don't need - // a build step (several packages export dist/, unbuilt on fresh checkout/CI). + // Packages without a `source` export (the excluded ones) map to src/. ...waggleSrcAliases(__dirname), // App uses @/ alias for src directory '@/': path.resolve(__dirname, 'app/src') + '/', '@': path.resolve(__dirname, 'app/src'), }, }, + ssr: { + resolve: { conditions: WAGGLE_SOURCE_CONDITIONS }, + }, test: { globals: true, // Passing tests should not bury failures under expected provider/startup @@ -37,6 +42,11 @@ export default defineConfig({ // via `npm run test:infra`. exclude: [ 'apps/**', 'node_modules/**', '**/__faza1-closed/**', + // Packages outside the community edition: excluded ones (ADR-0002) and + // the postponed team runtime (ADR-0003). They are not built either. + 'packages/hive-mind-*/**', 'packages/memory-mcp/**', 'packages/wiki-compiler/**', + 'packages/team-server/**', 'packages/waggle-dance/**', 'packages/worker/**', + 'packages/weaver/**', ...INFRA_TEST_SUITES, // Copies the ~13MB pre-built packages/marketplace/marketplace.db fixture // (createTempDb). Proper fix: regenerate it from sources-seed.ts in test diff --git a/vitest.infra.config.ts b/vitest.infra.config.ts index 76c9c80..c0bbecf 100644 --- a/vitest.infra.config.ts +++ b/vitest.infra.config.ts @@ -1,7 +1,7 @@ import { defineConfig } from 'vitest/config'; import path from 'node:path'; import { INFRA_TEST_SUITES } from './vitest.infra-suites'; -import { waggleSrcAliases } from './vitest.aliases'; +import { WAGGLE_SOURCE_CONDITIONS, waggleSrcAliases } from './vitest.aliases'; /** * Infra-lane vitest config — runs ONLY the suites that require live PostgreSQL @@ -13,12 +13,16 @@ import { waggleSrcAliases } from './vitest.aliases'; */ export default defineConfig({ resolve: { + conditions: WAGGLE_SOURCE_CONDITIONS, alias: { ...waggleSrcAliases(__dirname), '@/': path.resolve(__dirname, 'app/src') + '/', '@': path.resolve(__dirname, 'app/src'), }, }, + ssr: { + resolve: { conditions: WAGGLE_SOURCE_CONDITIONS }, + }, test: { globals: true, testTimeout: 30_000,