diff --git a/src/cli.ts b/src/cli.ts index 1f9d8b9..b66a67f 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -90,7 +90,7 @@ COMMANDS: mcp [install] Start stdio MCP server or 1-click install for Claude Desktop, Cursor, Windsurf init [--ide] Initialize workspace or generate AI agent guidelines (.cursorrules, CLAUDE.md) completion Generate native shell tab auto-completion (bash, zsh, fish, powershell) - which Show active CLI binary for an ecosystem (npm, jsr, pypi, conda, cargo, go, nuget, composer, gem, pub) + which Show active CLI binary for an ecosystem (npm, jsr, pypi, conda, cargo, go, nuget, composer, gem, pub, conan, vcpkg, meson, julia) OPTIONS: -D, --dev Install as a development dependency diff --git a/src/doctor/checker.ts b/src/doctor/checker.ts index 6cacaa0..b0e6038 100644 --- a/src/doctor/checker.ts +++ b/src/doctor/checker.ts @@ -270,6 +270,41 @@ export class PolyDoctor { args: ["--version"], hint: "https://dart.dev/get-dart", }, + { + id: "toolchain-conan", + name: "Conan C/C++", + cmd: "conan", + args: ["--version"], + hint: "https://conan.io", + }, + { + id: "toolchain-vcpkg", + name: "vcpkg C/C++", + cmd: "vcpkg", + args: ["version"], + hint: "https://vcpkg.io", + }, + { + id: "toolchain-meson", + name: "Meson Build", + cmd: "meson", + args: ["--version"], + hint: "https://mesonbuild.com", + }, + { + id: "toolchain-cmake", + name: "CMake", + cmd: "cmake", + args: ["--version"], + hint: "https://cmake.org", + }, + { + id: "toolchain-julia", + name: "Julia Pkg.jl", + cmd: "julia", + args: ["--version"], + hint: "https://julialang.org/downloads/", + }, ]; for (const tc of toolchains) { diff --git a/src/engines/cpp-julia.ts b/src/engines/cpp-julia.ts new file mode 100644 index 0000000..2d37303 --- /dev/null +++ b/src/engines/cpp-julia.ts @@ -0,0 +1,133 @@ +import type { PackageSpec } from "../types.js"; +import { type EngineAdapter, defineDeclarativeAdapter } from "./declarative.js"; + +function formatConanTarget(pkg: PackageSpec): string { + const fullName = pkg.namespace ? `${pkg.namespace}/${pkg.name}` : pkg.name; + if (!pkg.version) return fullName; + const cleanVer = pkg.version.replace(/^[~^>=<]+/, ""); + return fullName.includes("/") ? fullName : `${fullName}/${cleanVer}`; +} + +/** C / C++ — Conan (ConanCenter) */ +export const conanAdapter: EngineAdapter = defineDeclarativeAdapter({ + id: "conan", + ecosystem: "conan", + aliases: ["cpp", "c++"], + purlTypes: ["conan"], + manifests: ["conanfile.txt", "conanfile.py"], + lockfiles: ["conan.lock"], + osvEcosystem: "ConanCenter", + sbomPurlType: "conan", + supportedClis: ["conan"], + commands: { + command: "conan", + add: (pkg) => ["install", `--requires=${formatConanTarget(pkg)}`, "--build=missing"], + remove: (pkg) => ["remove", `${pkg.name}/*`, "-c"], + install: () => ["install", ".", "--build=missing"], + update: (pkg) => + pkg + ? ["install", `--requires=${formatConanTarget(pkg)}`, "--update", "--build=missing"] + : ["install", ".", "--update", "--build=missing"], + }, + resolveScriptCommand: (script) => + script === "test" ? ["ctest", ["--test-dir", "build"]] : ["conan", ["build", "."]], + injectRegistryEnv: (endpoint, env) => { + env.CONAN_HOME = endpoint.url; + }, + injectRegistryFlags: (endpoint, args) => { + if (args[0] === "install" && !args.includes("-r")) { + args.push("-r", endpoint.url); + } + }, +}); + +/** C / C++ — vcpkg (Manifest Mode) */ +export const vcpkgAdapter: EngineAdapter = defineDeclarativeAdapter({ + id: "vcpkg", + ecosystem: "vcpkg", + aliases: [], + purlTypes: ["vcpkg"], + manifests: ["vcpkg.json", "vcpkg-configuration.json"], + lockfiles: ["vcpkg-configuration.json"], + osvEcosystem: undefined, + sbomPurlType: "vcpkg", + supportedClis: ["vcpkg"], + commands: { + command: "vcpkg", + add: (pkg) => ["add", "port", pkg.name], + remove: (pkg) => ["remove", pkg.name], + install: () => ["install"], + update: (pkg) => (pkg ? ["upgrade", pkg.name, "--no-dry-run"] : ["upgrade", "--no-dry-run"]), + }, + resolveScriptCommand: (script) => + script === "test" ? ["ctest", ["--test-dir", "build"]] : ["cmake", ["--build", "build"]], + injectRegistryEnv: (endpoint, env) => { + env.VCPKG_BINARY_SOURCES = endpoint.url; + }, +}); + +/** C / C++ — Meson WrapDB */ +export const mesonAdapter: EngineAdapter = defineDeclarativeAdapter({ + id: "meson", + ecosystem: "meson", + aliases: ["wrap", "wrapdb"], + purlTypes: ["meson", "wrap"], + manifests: ["meson.build"], + lockfiles: [], + osvEcosystem: undefined, + sbomPurlType: "meson", + supportedClis: ["meson"], + commands: { + command: "meson", + add: (pkg) => ["wrap", "install", pkg.name], + remove: () => ["subprojects", "purge", "--confirm"], + install: () => ["subprojects", "download"], + update: (pkg) => (pkg ? ["wrap", "update", pkg.name] : ["subprojects", "update"]), + }, + resolveScriptCommand: (script) => + script === "test" ? ["meson", ["test", "-C", "build"]] : ["meson", ["compile", "-C", "build"]], +}); + +/** Julia — Pkg.jl (General Registry) */ +export const juliaAdapter: EngineAdapter = defineDeclarativeAdapter({ + id: "julia", + ecosystem: "julia", + aliases: ["pkg.jl", "pkgjl"], + purlTypes: ["julia"], + manifests: ["Project.toml"], + lockfiles: ["Manifest.toml"], + osvEcosystem: undefined, + sbomPurlType: "julia", + supportedClis: ["julia"], + commands: { + command: "julia", + add: (pkg) => { + const cleanVer = pkg.version?.replace(/^[~^>=<]+/, ""); + const expr = cleanVer + ? `using Pkg; Pkg.add(PackageSpec(name="${pkg.name}", version="${cleanVer}"))` + : `using Pkg; Pkg.add("${pkg.name}")`; + return ["--project=.", "-e", expr]; + }, + remove: (pkg) => ["--project=.", "-e", `using Pkg; Pkg.rm("${pkg.name}")`], + install: () => ["--project=.", "-e", "using Pkg; Pkg.instantiate()"], + update: (pkg) => [ + "--project=.", + "-e", + pkg ? `using Pkg; Pkg.update("${pkg.name}")` : "using Pkg; Pkg.update()", + ], + }, + resolveScriptCommand: (script) => + script === "test" + ? ["julia", ["--project=.", "-e", "using Pkg; Pkg.test()"]] + : ["julia", ["--project=.", "-e", script]], + injectRegistryEnv: (endpoint, env) => { + env.JULIA_PKG_SERVER = endpoint.url; + }, +}); + +export const CPP_JULIA_ADAPTERS: readonly EngineAdapter[] = [ + conanAdapter, + vcpkgAdapter, + mesonAdapter, + juliaAdapter, +]; diff --git a/src/engines/index.ts b/src/engines/index.ts index af348c3..e43004a 100644 --- a/src/engines/index.ts +++ b/src/engines/index.ts @@ -6,6 +6,13 @@ export { nugetAdapter, pubAdapter, } from "./backend-mobile.js"; +export { + CPP_JULIA_ADAPTERS, + conanAdapter, + juliaAdapter, + mesonAdapter, + vcpkgAdapter, +} from "./cpp-julia.js"; export { DeclarativeEngine, defineDeclarativeAdapter, diff --git a/src/engines/registry.ts b/src/engines/registry.ts index 10183f3..d931357 100644 --- a/src/engines/registry.ts +++ b/src/engines/registry.ts @@ -2,6 +2,7 @@ import fs from "node:fs"; import type { Ecosystem, EngineContext } from "../types.js"; import { BACKEND_MOBILE_ADAPTERS } from "./backend-mobile.js"; import type { BaseEngine } from "./base.js"; +import { CPP_JULIA_ADAPTERS } from "./cpp-julia.js"; import { type EngineAdapter, defineDeclarativeAdapter } from "./declarative.js"; import { GoEngine } from "./go.js"; import { NodeEngine } from "./node.js"; @@ -290,6 +291,9 @@ engineRegistry.register(goAdapter); for (const adapter of BACKEND_MOBILE_ADAPTERS) { engineRegistry.register(adapter); } +for (const adapter of CPP_JULIA_ADAPTERS) { + engineRegistry.register(adapter); +} /** Ensures a PackageSpec target cleanly detects its first existing manifest file in cwd if missing. */ export function resolveEcosystemLockContext(ecosystem: Ecosystem, cwd: string): EngineContext { diff --git a/src/types.ts b/src/types.ts index b813683..e5b3522 100644 --- a/src/types.ts +++ b/src/types.ts @@ -13,7 +13,11 @@ export type BuiltinEcosystem = | "nuget" | "composer" | "gem" - | "pub"; + | "pub" + | "conan" + | "vcpkg" + | "meson" + | "julia"; export type Ecosystem = BuiltinEcosystem | (string & {}); export interface EngineContext { diff --git a/src/workspace/crypto.ts b/src/workspace/crypto.ts index 442770d..d3ccbaa 100644 --- a/src/workspace/crypto.ts +++ b/src/workspace/crypto.ts @@ -337,7 +337,121 @@ export function extractDirectDependencies(manifestPath: string, ecosystem: Ecosy } break; } + case "conan": + case "vcpkg": + case "meson": + case "julia": { + for (const item of extractCppJuliaDependencies(manifestPath, content, ecosystem)) { + deps.push(`${item.ecosystem}:${item.name}@${item.version}`); + } + break; + } } return deps.sort(); } + +function extractCppJuliaDependencies( + manifestPath: string, + content: string, + ecosystem: string, +): Array<{ ecosystem: string; name: string; version: string }> { + const results: Array<{ ecosystem: string; name: string; version: string }> = []; + const lowerPath = manifestPath.toLowerCase(); + + if (ecosystem === "conan") { + if (lowerPath.endsWith(".txt")) { + let inRequires = false; + for (const rawLine of content.split(/\r?\n/)) { + const line = rawLine.trim(); + if (!line || line.startsWith("#")) continue; + if (line.startsWith("[")) { + inRequires = line === "[requires]" || line === "[tool_requires]"; + continue; + } + if (inRequires) { + const ref = line.split("@")[0]?.trim() ?? ""; + const slashIdx = ref.indexOf("/"); + if (slashIdx > 0) { + const name = ref.slice(0, slashIdx).trim(); + const version = ref.slice(slashIdx + 1).trim() || "*"; + if (name) results.push({ ecosystem, name, version }); + } + } + } + } else if (lowerPath.endsWith(".py")) { + const matches = content.matchAll(/["']([A-Za-z0-9_.+-]+)\/([^"'@\s]+)(?:@[^"']*)?["']/g); + for (const m of matches) { + if (m[1] && m[2]) { + results.push({ ecosystem, name: m[1], version: m[2] }); + } + } + } + return results; + } + + if (ecosystem === "vcpkg") { + try { + const parsed = JSON.parse(content) as { + dependencies?: Array="?: string }>; + }; + for (const dep of parsed.dependencies ?? []) { + if (typeof dep === "string") { + if (dep.trim()) results.push({ ecosystem, name: dep.trim(), version: "*" }); + } else if ( + dep && + typeof dep === "object" && + typeof dep.name === "string" && + dep.name.trim() + ) { + results.push({ + ecosystem, + name: dep.name.trim(), + version: dep["version>="]?.trim() || "*", + }); + } + } + } catch { + // Ignore malformed vcpkg.json during lockfile hashing + } + return results; + } + + if (ecosystem === "meson") { + const seen = new Set(); + const matches = content.matchAll(/\b(?:dependency|subproject)\(\s*["']([^"']+)["']/g); + for (const m of matches) { + const name = m[1]?.trim(); + if (name && !seen.has(name)) { + seen.add(name); + results.push({ ecosystem, name, version: "*" }); + } + } + return results; + } + + // Julia Project.toml: parse [deps] UUID entries and optional [compat] version constraints + const compatVersions = new Map(); + let section = ""; + const depNames: string[] = []; + for (const rawLine of content.split(/\r?\n/)) { + const line = rawLine.replace(/#.*$/, "").trim(); + if (!line) continue; + const secMatch = line.match(/^\[([^\]]+)\]$/); + if (secMatch) { + section = secMatch[1]?.trim() ?? ""; + continue; + } + if (section === "deps") { + const kv = line.match(/^([A-Za-z0-9_]+)\s*=\s*"([^"]+)"/); + if (kv?.[1]) depNames.push(kv[1]); + } else if (section === "compat") { + const kv = line.match(/^([A-Za-z0-9_]+)\s*=\s*"([^"]+)"/); + if (kv?.[1] && kv[2]) compatVersions.set(kv[1], kv[2].trim()); + } + } + for (const name of depNames) { + results.push({ ecosystem, name, version: compatVersions.get(name) ?? "*" }); + } + return results; +} diff --git a/tests/completion.test.ts b/tests/completion.test.ts index 00444cb..148827f 100644 --- a/tests/completion.test.ts +++ b/tests/completion.test.ts @@ -51,6 +51,10 @@ test("Shell Auto-Completion - Dynamic Resolution", async (t) => { "composer", "gem", "pub", + "conan", + "vcpkg", + "meson", + "julia", ]); }); diff --git a/tests/phase3-cpp-julia.test.ts b/tests/phase3-cpp-julia.test.ts new file mode 100644 index 0000000..85b3bd5 --- /dev/null +++ b/tests/phase3-cpp-julia.test.ts @@ -0,0 +1,313 @@ +import assert from "node:assert/strict"; +import fs from "node:fs"; +import os from "node:os"; +import path from "node:path"; +import test from "node:test"; +import { CrossStackAuditor } from "../src/compliance/auditor.js"; +import { SbomGenerator } from "../src/compliance/sbom.js"; +import { detectContexts } from "../src/detector/tree-walker.js"; +import { PolyDispatcher } from "../src/dispatcher/executor.js"; +import { PolyDoctor } from "../src/doctor/checker.js"; +import { engineRegistry } from "../src/engines/index.js"; +import { parsePackageSpec } from "../src/purl/parser.js"; +import { verifyCompositeLockfile, writeCompositeLockfile } from "../src/workspace/lockfile.js"; + +test("Phase 3 PURL - Parses Conan, vcpkg, Meson, and Julia shorthands & RFC PURLs", () => { + const conanShort = parsePackageSpec("conan:fmt@10.2.1"); + assert.equal(conanShort.ecosystem, "conan"); + assert.equal(conanShort.name, "fmt"); + assert.equal(conanShort.version, "10.2.1"); + + const conanPurl = parsePackageSpec("pkg:conan/zlib@1.3.1"); + assert.equal(conanPurl.ecosystem, "conan"); + assert.equal(conanPurl.name, "zlib"); + assert.equal(conanPurl.version, "1.3.1"); + + const vcpkgShort = parsePackageSpec("vcpkg:zlib"); + assert.equal(vcpkgShort.ecosystem, "vcpkg"); + assert.equal(vcpkgShort.name, "zlib"); + + const vcpkgPurl = parsePackageSpec("pkg:vcpkg/openssl@3.3.0"); + assert.equal(vcpkgPurl.ecosystem, "vcpkg"); + assert.equal(vcpkgPurl.name, "openssl"); + assert.equal(vcpkgPurl.version, "3.3.0"); + + const mesonWrap = parsePackageSpec("wrap:gtest"); + assert.equal(mesonWrap.ecosystem, "meson"); + assert.equal(mesonWrap.name, "gtest"); + + const mesonPurl = parsePackageSpec("pkg:meson/sqlite3@3.46.0"); + assert.equal(mesonPurl.ecosystem, "meson"); + assert.equal(mesonPurl.name, "sqlite3"); + assert.equal(mesonPurl.version, "3.46.0"); + + const juliaShort = parsePackageSpec("julia:DataFrames@1.6.1"); + assert.equal(juliaShort.ecosystem, "julia"); + assert.equal(juliaShort.name, "DataFrames"); + assert.equal(juliaShort.version, "1.6.1"); + + const juliaPurl = parsePackageSpec("pkg:julia/JSON3@1.14.0"); + assert.equal(juliaPurl.ecosystem, "julia"); + assert.equal(juliaPurl.name, "JSON3"); + assert.equal(juliaPurl.version, "1.14.0"); +}); + +test("Phase 3 Engines - Resolves CLI args for conan, vcpkg, meson, and julia Pkg.jl", () => { + const conan = engineRegistry.createEngine("conan"); + const fmtPkg = parsePackageSpec("conan:fmt@10.2.1"); + assert.deepEqual(conan.resolveAddArgs(fmtPkg), { + command: "conan", + args: ["install", "--requires=fmt/10.2.1", "--build=missing"], + }); + assert.deepEqual(conan.resolveRemoveArgs(fmtPkg), { + command: "conan", + args: ["remove", "fmt/*", "-c"], + }); + assert.deepEqual(conan.resolveInstallArgs(), { + command: "conan", + args: ["install", ".", "--build=missing"], + }); + assert.deepEqual(conan.resolveUpdateArgs(fmtPkg), { + command: "conan", + args: ["install", "--requires=fmt/10.2.1", "--update", "--build=missing"], + }); + + const vcpkg = engineRegistry.createEngine("vcpkg"); + const zlibPkg = parsePackageSpec("vcpkg:zlib"); + assert.deepEqual(vcpkg.resolveAddArgs(zlibPkg), { + command: "vcpkg", + args: ["add", "port", "zlib"], + }); + assert.deepEqual(vcpkg.resolveRemoveArgs(zlibPkg), { + command: "vcpkg", + args: ["remove", "zlib"], + }); + assert.deepEqual(vcpkg.resolveInstallArgs(), { + command: "vcpkg", + args: ["install"], + }); + assert.deepEqual(vcpkg.resolveUpdateArgs(zlibPkg), { + command: "vcpkg", + args: ["upgrade", "zlib", "--no-dry-run"], + }); + + const meson = engineRegistry.createEngine("meson"); + const sqlitePkg = parsePackageSpec("meson:sqlite3"); + assert.deepEqual(meson.resolveAddArgs(sqlitePkg), { + command: "meson", + args: ["wrap", "install", "sqlite3"], + }); + assert.deepEqual(meson.resolveInstallArgs(), { + command: "meson", + args: ["subprojects", "download"], + }); + assert.deepEqual(meson.resolveUpdateArgs(sqlitePkg), { + command: "meson", + args: ["wrap", "update", "sqlite3"], + }); + + const julia = engineRegistry.createEngine("julia"); + const dfPkg = parsePackageSpec("julia:DataFrames@^1.6.1"); + assert.deepEqual(julia.resolveAddArgs(dfPkg), { + command: "julia", + args: [ + "--project=.", + "-e", + 'using Pkg; Pkg.add(PackageSpec(name="DataFrames", version="1.6.1"))', + ], + }); + assert.deepEqual(julia.resolveRemoveArgs(dfPkg), { + command: "julia", + args: ["--project=.", "-e", 'using Pkg; Pkg.rm("DataFrames")'], + }); + assert.deepEqual(julia.resolveInstallArgs(), { + command: "julia", + args: ["--project=.", "-e", "using Pkg; Pkg.instantiate()"], + }); + assert.deepEqual(julia.resolveUpdateArgs(), { + command: "julia", + args: ["--project=.", "-e", "using Pkg; Pkg.update()"], + }); +}); + +test("Phase 3 Integration - Monorepo (Node + Python + C/C++ + Julia) lockfile, OSV ConanCenter, SBOM & doctor", async () => { + const wsDir = fs.mkdtempSync(path.join(os.tmpdir(), "poly-phase3-ws-")); + const nodeDir = path.join(wsDir, "app-web"); + const pyDir = path.join(wsDir, "ml-python"); + const vcpkgDir = path.join(wsDir, "native-vcpkg"); + const conanDir = path.join(wsDir, "native-conan"); + const mesonDir = path.join(wsDir, "native-meson"); + const juliaDir = path.join(wsDir, "sci-julia"); + + for (const dir of [nodeDir, pyDir, vcpkgDir, conanDir, mesonDir, juliaDir]) { + fs.mkdirSync(dir, { recursive: true }); + } + + fs.writeFileSync( + path.join(nodeDir, "package.json"), + JSON.stringify({ name: "web-ui", dependencies: { zod: "3.23.8" } }), + ); + fs.writeFileSync( + path.join(pyDir, "pyproject.toml"), + '[project]\nname = "ml-bindings"\ndependencies = [\n "numpy==2.1.0",\n]\n', + ); + fs.writeFileSync( + path.join(vcpkgDir, "vcpkg.json"), + JSON.stringify({ + name: "native-engine", + version: "0.1.0", + dependencies: ["zlib", { name: "fmt", "version>=": "10.2.1" }], + }), + ); + fs.writeFileSync( + path.join(vcpkgDir, "vcpkg-configuration.json"), + JSON.stringify({ "default-registry": { kind: "builtin", baseline: "abc123" } }), + ); + fs.writeFileSync( + path.join(conanDir, "conanfile.txt"), + "[requires]\nopenssl/3.2.1\n\n[generators]\nCMakeToolchain\n", + ); + fs.writeFileSync(path.join(conanDir, "conan.lock"), '{"version":"0.5"}'); + fs.writeFileSync( + path.join(mesonDir, "meson.build"), + "project('video_core', 'cpp')\nsqlite = dependency('sqlite3')\ngtest = subproject('gtest')\n", + ); + fs.writeFileSync( + path.join(juliaDir, "Project.toml"), + [ + 'name = "SimKernel"', + 'uuid = "11111111-2222-3333-4444-555555555555"', + "", + "[deps]", + 'DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"', + "", + "[compat]", + 'DataFrames = "1.6.1"', + "", + ].join("\n"), + ); + fs.writeFileSync( + path.join(juliaDir, "Manifest.toml"), + '# Julia Manifest\njulia_version = "1.10.4"\n', + ); + + const capturedOsvQueries: Array<{ + package?: { name?: string; ecosystem?: string }; + version?: string; + }> = []; + const origFetch = globalThis.fetch; + globalThis.fetch = (async (input: string | URL | Request, init?: RequestInit) => { + const u = typeof input === "string" ? input : input instanceof URL ? input.href : input.url; + if (u.includes("api.osv.dev/v1/querybatch")) { + const body = JSON.parse(String(init?.body ?? "{}")) as { + queries?: Array<{ package?: { name?: string; ecosystem?: string }; version?: string }>; + }; + const queries = body.queries ?? []; + capturedOsvQueries.push(...queries); + const results = queries.map((q) => { + if (q.package?.ecosystem === "ConanCenter" && q.package?.name === "openssl") { + return { + vulns: [{ id: "GHSA-conan-openssl-test", summary: "Mock ConanCenter advisory" }], + }; + } + return {}; + }); + return new Response(JSON.stringify({ results }), { status: 200 }); + } + return new Response("{}", { status: 200 }); + }) as typeof fetch; + + try { + // 1. Detector + Dispatcher across all 4 new toolchains + assert.equal(detectContexts(vcpkgDir)[0]?.manifestFile, "vcpkg.json"); + assert.equal(detectContexts(conanDir)[0]?.manifestFile, "conanfile.txt"); + assert.equal(detectContexts(mesonDir)[0]?.manifestFile, "meson.build"); + assert.equal(detectContexts(juliaDir)[0]?.manifestFile, "Project.toml"); + + const dispatcher = new PolyDispatcher(); + assert.equal(dispatcher.which("conan", conanDir).effectiveCli, "conan"); + assert.equal(dispatcher.which("vcpkg", vcpkgDir).effectiveCli, "vcpkg"); + assert.equal(dispatcher.which("meson", mesonDir).effectiveCli, "meson"); + assert.equal(dispatcher.which("julia", juliaDir).effectiveCli, "julia"); + + // 2. Co-located monorepo detection (Python + Node + vcpkg + Conan) & poly.lock SHA-256 verification + const colocatedDir = path.join(wsDir, "hybrid-cpp-py-node"); + fs.mkdirSync(colocatedDir, { recursive: true }); + fs.writeFileSync(path.join(colocatedDir, "package.json"), JSON.stringify({ name: "hybrid" })); + fs.writeFileSync(path.join(colocatedDir, "pyproject.toml"), '[project]\nname = "hybrid"\n'); + fs.writeFileSync( + path.join(colocatedDir, "vcpkg.json"), + JSON.stringify({ name: "hybrid", dependencies: ["zlib"] }), + ); + fs.writeFileSync(path.join(colocatedDir, "conanfile.txt"), "[requires]\nfmt/10.2.1\n"); + + const colocatedContexts = detectContexts(colocatedDir); + const colocatedEcosystems = colocatedContexts.map((c) => c.ecosystem); + assert.ok(colocatedEcosystems.includes("npm")); + assert.ok(colocatedEcosystems.includes("pypi")); + assert.ok(colocatedEcosystems.includes("vcpkg")); + assert.ok(colocatedEcosystems.includes("conan")); + + for (const ctx of colocatedContexts) { + const eng = engineRegistry.createEngine(ctx.ecosystem, { + cwd: ctx.directory, + manifest: ctx.manifestFile, + lockfile: ctx.lockfile, + }); + const installCmd = eng.resolveInstallArgs(); + assert.ok(installCmd.command.length > 0); + } + + // Write composite poly.lock covering root workspace members (exclude extra test helper folder before locking) + fs.rmSync(colocatedDir, { recursive: true, force: true }); + const lock = writeCompositeLockfile(wsDir); + assert.equal(lock.members.length, 6); + assert.equal(verifyCompositeLockfile(wsDir).isDrifted, false); + + const vcpkgMember = lock.members.find((m) => m.ecosystem === "vcpkg"); + const conanMember = lock.members.find((m) => m.ecosystem === "conan"); + const mesonMember = lock.members.find((m) => m.ecosystem === "meson"); + const juliaMember = lock.members.find((m) => m.ecosystem === "julia"); + assert.ok(vcpkgMember?.directDependencies.includes("vcpkg:fmt@10.2.1")); + assert.ok(vcpkgMember?.directDependencies.includes("vcpkg:zlib@*")); + assert.ok(conanMember?.directDependencies.includes("conan:openssl@3.2.1")); + assert.ok(mesonMember?.directDependencies.includes("meson:sqlite3@*")); + assert.ok(mesonMember?.directDependencies.includes("meson:gtest@*")); + assert.ok(juliaMember?.directDependencies.includes("julia:DataFrames@1.6.1")); + + // 3. CycloneDX SBOM generation with PURLs for C/C++ + Julia + Node + Python + const sbom = JSON.parse(new SbomGenerator().generate(wsDir, { format: "cyclonedx" })) as { + components: Array<{ purl: string }>; + }; + const purls = sbom.components.map((c) => c.purl); + assert.ok(purls.some((p) => p.startsWith("pkg:npm/zod@3.23.8"))); + assert.ok(purls.some((p) => p.startsWith("pkg:pypi/numpy"))); + assert.ok(purls.some((p) => p.startsWith("pkg:conan/openssl@3.2.1"))); + assert.ok(purls.some((p) => p.startsWith("pkg:vcpkg/fmt@10.2.1"))); + assert.ok(purls.some((p) => p.startsWith("pkg:meson/sqlite3"))); + assert.ok(purls.some((p) => p.startsWith("pkg:julia/DataFrames@1.6.1"))); + + // 4. OSV queries ConanCenter while gracefully skipping vcpkg, meson, and julia + const audit = await new CrossStackAuditor().audit(wsDir); + assert.equal(audit.scannedPackages, 8); + assert.ok( + capturedOsvQueries.some( + (q) => q.package?.ecosystem === "ConanCenter" && q.package?.name === "openssl", + ), + ); + assert.ok(!capturedOsvQueries.some((q) => q.package?.ecosystem === "vcpkg")); + assert.ok(!capturedOsvQueries.some((q) => q.package?.ecosystem === "meson")); + assert.ok(!capturedOsvQueries.some((q) => q.package?.ecosystem === "julia")); + assert.ok( + audit.findings.some((f) => f.id === "GHSA-conan-openssl-test" && f.ecosystem === "conan"), + ); + + // 5. PolyDoctor checks lockfile health cleanly across the polyglot workspace + const doctor = await new PolyDoctor().diagnose(wsDir); + assert.equal(doctor.checks.find((c) => c.id === "workspace-lock-drift")?.status, "OK"); + assert.ok(doctor.checks.length > 0); + } finally { + globalThis.fetch = origFetch; + fs.rmSync(wsDir, { recursive: true, force: true }); + } +});