import { describe, expect, it } from 'vitest'; import { readFileSync } from 'node:fs'; import { resolve } from 'node:path'; import { fileURLToPath, pathToFileURL } from 'node:url'; import { isDirectModule } from '../src/index.js'; const REPO_ROOT = fileURLToPath(new URL('../../../', import.meta.url)); describe('team server entrypoint detection', () => { it('is left out of the community-edition package build with the rest of team mode (ADR-0003)', () => { const rootPackage = JSON.parse(readFileSync(resolve(REPO_ROOT, 'package.json'), 'utf8')) as { scripts: Record; }; const build = rootPackage.scripts['build:packages']; expect(build).toContain('cd ../server && npx tsc --build'); for (const postponed of ['../team-server', '../worker', '../waggle-dance']) { expect(build).not.toContain(postponed); } }); it('recognizes the compiled dist entrypoint by URL identity', () => { const distPath = resolve(REPO_ROOT, 'packages/team-server/dist/index.js'); expect(isDirectModule(distPath, pathToFileURL(distPath).href)).toBe(true); }); it('does not start when imported by another process entrypoint', () => { const distPath = resolve(REPO_ROOT, 'packages/team-server/dist/index.js'); const importerUrl = pathToFileURL(resolve(REPO_ROOT, 'packages/team-server/dist/consumer.js')).href; expect(isDirectModule(distPath, importerUrl)).toBe(false); expect(isDirectModule(undefined, importerUrl)).toBe(false); }); });