import { matchesGlob } from "node:path"; const groupedProjects = (group, projects) => projects.map(({ name, ...settings }) => ({ name, group, ...settings })); /** Canonical file ownership shared by Vitest and development-test planning. */ export const SOURCE_TEST_PROJECTS = groupedProjects("source", [ { name: "domain", isolate: false, include: ["src/{contracts,domain,kernel,ports}/**/*.test.ts"], }, { name: "services", isolate: false, include: ["src/application/**/*.test.ts"], }, { name: "adapters", include: [ "src/*.test.ts", "src/{android,apkSignature,apktool,jeb,adb,artifacts,browser,compression,config,cutter,deb,desktop,dotnet,electron,erlang,evm,firmware,flutter,frida,pcap,ghidra,go,gpu,hopper,hopperPaths,ida,inspector,java,javascript,kuna,labview,main,native,nuget,oci,process,providers,python,reference,resources,rust,server,sqlite,uefi,v8,vsix,wasm,windows,yara}/**/*.test.ts", ], }, { name: "composition", isolate: false, include: ["tests/composition/**/*.test.ts"], }, { name: "conformance", isolate: false, include: ["tests/conformance/**/*.test.ts"], exclude: ["tests/conformance/providers/hopper/realHopperSearch.test.ts"], }, { name: "evaluation", isolate: false, include: ["tests/evaluation/**/*.test.ts"], }, ]); export const BUILT_TEST_PROJECTS = groupedProjects("built", [ { name: "boundary", include: [ "tests/boundary/**/*.test.ts", "tests/conformance/providers/hopper/realHopperSearch.test.ts", ], exclude: [ "tests/boundary/cli/**/*.test.ts", "tests/boundary/mcp/**/*.test.ts", "tests/boundary/process/**/*.test.ts", ], }, { name: "cli-boundary", isolate: false, include: ["tests/boundary/cli/**/*.test.ts"], }, { name: "process-boundary", include: ["tests/boundary/process/**/*.test.ts"], }, { name: "mcp-boundary", isolate: false, include: ["tests/boundary/mcp/**/*.test.ts"], }, { name: "acceptance", include: ["tests/acceptance/**/*.test.ts"], }, { name: "process-global", include: ["tests/process-global/**/*.test.ts"], }, ]); const ALL_TEST_PROJECTS = [...SOURCE_TEST_PROJECTS, ...BUILT_TEST_PROJECTS]; /** Return the unique Vitest owner for an exact repository-relative test path. */ export const projectForTest = (testPath) => { if ( typeof testPath !== "string" || testPath.startsWith("/") || testPath.includes("\\") || testPath.split("/").some((part) => part === ".." || part === ".") || !testPath.endsWith(".test.ts") ) throw new Error(`Expected a normalized repository test path: ${testPath}`); const owners = ALL_TEST_PROJECTS.filter( ({ include, exclude = [] }) => include.some((pattern) => matchesGlob(testPath, pattern)) && !exclude.some((pattern) => matchesGlob(testPath, pattern)), ); if (owners.length !== 1) throw new Error( owners.length === 0 ? `No test project owns ${testPath}` : `Multiple test projects own ${testPath}: ${owners.map(({ name }) => name).join(", ")}`, ); return owners[0]; };