From ec52e62fbd3eec2bc339932f17aa9b7798a0ed9d Mon Sep 17 00:00:00 2001 From: divyanshujethi Date: Thu, 26 Nov 2026 21:37:52 +0530 Subject: [PATCH] feat(engines): Phase 2 Tier 1 backend & mobile ecosystems (NuGet, Composer, RubyGems, Pub) --- src/cli.ts | 2 +- src/compliance/osv.ts | 2 +- src/compliance/sbom.ts | 7 +- src/doctor/checker.ts | 55 ++++++ src/engines/backend-mobile.ts | 219 ++++++++++++++++++++++ src/engines/index.ts | 7 + src/engines/registry.ts | 6 +- src/outdated/checker.ts | 137 ++++++++++++++ src/outdated/upgrader.ts | 52 +++++- src/security/registry.ts | 144 +++++++++++++++ src/types.ts | 12 +- src/workspace/crypto.ts | 109 +++++++++++ tests/completion.test.ts | 13 +- tests/phase1-registry.test.ts | 42 ++--- tests/phase2-backend-mobile.test.ts | 277 ++++++++++++++++++++++++++++ 15 files changed, 1047 insertions(+), 37 deletions(-) create mode 100644 src/engines/backend-mobile.ts create mode 100644 tests/phase2-backend-mobile.test.ts diff --git a/src/cli.ts b/src/cli.ts index a7d6bb0..1f9d8b9 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) + which Show active CLI binary for an ecosystem (npm, jsr, pypi, conda, cargo, go, nuget, composer, gem, pub) OPTIONS: -D, --dev Install as a development dependency diff --git a/src/compliance/osv.ts b/src/compliance/osv.ts index e950307..829689d 100644 --- a/src/compliance/osv.ts +++ b/src/compliance/osv.ts @@ -73,7 +73,7 @@ export class OsvClient { name: pkg.name, ecosystem: osvEcosystem, }, - version: pkg.version.replace(/^[~^>=<]/, "").trim(), + version: pkg.version.replace(/^[~^>=<\s]+/, "").trim(), })); try { diff --git a/src/compliance/sbom.ts b/src/compliance/sbom.ts index c172ae4..3606098 100644 --- a/src/compliance/sbom.ts +++ b/src/compliance/sbom.ts @@ -41,11 +41,12 @@ export class SbomGenerator { const components = packages.map((pkg) => { const purlEcosystem = engineRegistry.getSbomPurlType(pkg.ecosystem); + const cleanVer = pkg.version.replace(/^[~^>=<\s]+/, ""); return { type: "library", name: pkg.packageName, - version: pkg.version.replace(/^[~^>=<]/, ""), - purl: `pkg:${purlEcosystem}/${pkg.packageName}@${pkg.version.replace(/^[~^>=<]/, "")}`, + version: cleanVer, + purl: `pkg:${purlEcosystem}/${pkg.packageName}@${cleanVer}`, licenses: [ { license: { @@ -93,7 +94,7 @@ export class SbomGenerator { return { name: pkg.packageName, SPDXID: `SPDXRef-Package-${safeId}-${idx}`, - versionInfo: pkg.version.replace(/^[~^>=<]/, ""), + versionInfo: pkg.version.replace(/^[~^>=<\s]+/, ""), downloadLocation: "NOASSERTION", filesAnalyzed: false, licenseConcluded: pkg.license, diff --git a/src/doctor/checker.ts b/src/doctor/checker.ts index 4002c17..6cacaa0 100644 --- a/src/doctor/checker.ts +++ b/src/doctor/checker.ts @@ -19,6 +19,7 @@ export class PolyDoctor { this.checkPythonToolchain(checks); this.checkRustToolchain(checks); this.checkGoToolchain(checks); + this.checkBackendAndMobileToolchains(checks); // 2. Build Environment this.checkBuildEnvironment(checks); @@ -233,6 +234,60 @@ export class PolyDoctor { } } + private checkBackendAndMobileToolchains(checks: DiagnosticCheckItem[]): void { + const toolchains: Array<{ + id: string; + name: string; + cmd: string; + args: string[]; + hint: string; + }> = [ + { + id: "toolchain-dotnet", + name: ".NET / NuGet CLI", + cmd: "dotnet", + args: ["--version"], + hint: "https://dotnet.microsoft.com", + }, + { + id: "toolchain-composer", + name: "PHP Composer", + cmd: "composer", + args: ["--version"], + hint: "https://getcomposer.org", + }, + { + id: "toolchain-bundler", + name: "Ruby Bundler", + cmd: "bundle", + args: ["--version"], + hint: "https://bundler.io", + }, + { + id: "toolchain-dart", + name: "Dart / Flutter Pub", + cmd: "dart", + args: ["--version"], + hint: "https://dart.dev/get-dart", + }, + ]; + + for (const tc of toolchains) { + const res = this.runCommandSafe(tc.cmd, tc.args); + if (res.available) { + const ver = res.output.trim().split(/\r?\n/)[0].trim(); + checks.push({ + id: tc.id, + name: tc.name, + category: "Toolchain", + status: "OK", + version: ver, + message: `${ver} active`, + }); + } + } + } + private checkBuildEnvironment(checks: DiagnosticCheckItem[]): void { const hasGcc = this.runCommandSafe("gcc", ["--version"]).available; const hasClang = this.runCommandSafe("clang", ["--version"]).available; diff --git a/src/engines/backend-mobile.ts b/src/engines/backend-mobile.ts new file mode 100644 index 0000000..4844136 --- /dev/null +++ b/src/engines/backend-mobile.ts @@ -0,0 +1,219 @@ +import fs from "node:fs"; +import path from "node:path"; +import type { EngineContext, PackageSpec } from "../types.js"; +import { type EngineAdapter, defineDeclarativeAdapter } from "./declarative.js"; + +function isFlutterProject(ctx?: EngineContext): boolean { + if (ctx?.preferredCli === "flutter") return true; + if (ctx?.cwd) { + const pubspec = path.join(ctx.cwd, ctx.manifest || "pubspec.yaml"); + if (fs.existsSync(pubspec)) { + try { + const content = fs.readFileSync(pubspec, "utf-8"); + if (/(?:sdk:\s*flutter|^\s*flutter:\s*$)/m.test(content)) { + return true; + } + } catch { + // Ignore read failure and fall back to dart + } + } + } + return false; +} + +function isPaketProject(ctx?: EngineContext): boolean { + return ( + ctx?.preferredCli === "paket" || + ctx?.manifest === "paket.dependencies" || + ctx?.lockfile === "paket.lock" + ); +} + +function isGemCliProject(ctx?: EngineContext): boolean { + if (ctx?.preferredCli === "gem") return true; + if (ctx?.manifest?.endsWith(".gemspec") && ctx?.cwd) { + return !fs.existsSync(path.join(ctx.cwd, "Gemfile")); + } + return false; +} + +function isPearProject(ctx?: EngineContext): boolean { + return ctx?.preferredCli === "pear" || ctx?.manifest === "package.xml"; +} + +function isProjectXmlManifest(manifest?: string): manifest is string { + return Boolean(manifest && /\.(cs|fs|vb)proj$/i.test(manifest)); +} + +function formatScopedName(pkg: PackageSpec): string { + return pkg.namespace ? `${pkg.namespace}/${pkg.name}` : pkg.name; +} + +/** C# / .NET — NuGet (dotnet CLI) & Paket */ +export const nugetAdapter: EngineAdapter = defineDeclarativeAdapter({ + id: "dotnet", + ecosystem: "nuget", + aliases: ["dotnet", "csharp", "paket"], + purlTypes: ["nuget"], + manifests: ["*.csproj", "*.fsproj", "*.vbproj", "paket.dependencies"], + lockfiles: ["packages.lock.json", "paket.lock"], + osvEcosystem: "NuGet", + sbomPurlType: "nuget", + supportedClis: ["dotnet", "paket"], + commands: { + command: (ctx) => (isPaketProject(ctx) ? "paket" : "dotnet"), + add: (pkg, ctx) => { + const cleanVer = pkg.version?.replace(/^[~^>=<]+/, ""); + if (isPaketProject(ctx)) { + return ["add", pkg.name, ...(cleanVer ? ["--version", cleanVer] : [])]; + } + const targetProj = isProjectXmlManifest(ctx?.manifest) ? [ctx.manifest] : []; + return [ + "add", + ...targetProj, + "package", + pkg.name, + ...(cleanVer ? ["--version", cleanVer] : []), + ]; + }, + remove: (pkg, ctx) => { + if (isPaketProject(ctx)) { + return ["remove", pkg.name]; + } + const targetProj = isProjectXmlManifest(ctx?.manifest) ? [ctx.manifest] : []; + return ["remove", ...targetProj, "package", pkg.name]; + }, + install: (ctx) => (isPaketProject(ctx) ? ["install"] : ["restore"]), + update: (pkg, ctx) => { + if (isPaketProject(ctx)) { + return pkg ? ["update", pkg.name] : ["update"]; + } + const targetProj = isProjectXmlManifest(ctx?.manifest) ? [ctx.manifest] : []; + return pkg ? ["add", ...targetProj, "package", pkg.name] : ["restore", "--force"]; + }, + }, + resolveScriptCommand: (script) => { + if (script === "test") return ["dotnet", ["test"]]; + if (script === "build") return ["dotnet", ["build"]]; + return ["dotnet", ["run"]]; + }, + injectRegistryEnv: (endpoint, env) => { + env.NUGET_SOURCE = endpoint.url; + }, + injectRegistryFlags: (endpoint, args) => { + if ((args[0] === "add" || args[0] === "restore") && !args.includes("--source")) { + args.push("--source", endpoint.url); + } + }, +}); + +/** PHP — Composer (Packagist) & legacy PEAR fallback */ +export const composerAdapter: EngineAdapter = defineDeclarativeAdapter({ + id: "composer", + ecosystem: "composer", + aliases: ["php", "packagist", "pear"], + purlTypes: ["composer"], + manifests: ["composer.json", "package.xml"], + lockfiles: ["composer.lock"], + osvEcosystem: "Packagist", + sbomPurlType: "composer", + supportedClis: ["composer", "pear"], + commands: { + command: (ctx) => (isPearProject(ctx) ? "pear" : "composer"), + add: (pkg, ctx) => { + const fullName = formatScopedName(pkg); + if (isPearProject(ctx)) { + return ["install", pkg.version ? `${fullName}-${pkg.version}` : fullName]; + } + const target = pkg.version ? `${fullName}:${pkg.version}` : fullName; + return ["require", target, ...(pkg.isDev ? ["--dev"] : [])]; + }, + remove: (pkg, ctx) => { + const fullName = formatScopedName(pkg); + if (isPearProject(ctx)) { + return ["uninstall", fullName]; + } + return ["remove", fullName, ...(pkg.isDev ? ["--dev"] : [])]; + }, + install: (ctx) => (isPearProject(ctx) ? ["install", "package.xml"] : ["install"]), + update: (pkg, ctx) => { + const fullName = pkg ? formatScopedName(pkg) : undefined; + if (isPearProject(ctx)) { + return fullName ? ["upgrade", fullName] : ["upgrade"]; + } + return fullName ? ["update", fullName] : ["update"]; + }, + }, + resolveScriptCommand: (script) => ["composer", [script]], + injectRegistryEnv: (endpoint, env) => { + env.COMPOSER_MIRROR_URL = endpoint.url; + }, +}); + +/** Ruby — Bundler / RubyGems */ +export const gemAdapter: EngineAdapter = defineDeclarativeAdapter({ + id: "bundler", + ecosystem: "gem", + aliases: ["ruby", "bundler", "rubygems"], + purlTypes: ["gem"], + manifests: ["Gemfile", "*.gemspec"], + lockfiles: ["Gemfile.lock"], + osvEcosystem: "RubyGems", + sbomPurlType: "gem", + supportedClis: ["bundle", "gem"], + commands: { + command: (ctx) => (isGemCliProject(ctx) ? "gem" : "bundle"), + add: (pkg, ctx) => { + if (isGemCliProject(ctx)) { + return ["install", pkg.name, ...(pkg.version ? ["-v", pkg.version] : [])]; + } + const args = ["add", pkg.name]; + if (pkg.version) args.push("--version", pkg.version); + if (pkg.isDev) args.push("--group", "development"); + return args; + }, + remove: (pkg, ctx) => + isGemCliProject(ctx) ? ["uninstall", "-x", pkg.name] : ["remove", pkg.name], + install: () => ["install"], + update: (pkg) => (pkg ? ["update", pkg.name] : ["update"]), + }, + resolveScriptCommand: (script) => ["bundle", ["exec", script]], + injectRegistryEnv: (endpoint, env) => { + env.BUNDLE_MIRROR__ALL = endpoint.url; + }, +}); + +/** Dart / Flutter — Pub */ +export const pubAdapter: EngineAdapter = defineDeclarativeAdapter({ + id: "pub", + ecosystem: "pub", + aliases: ["dart", "flutter"], + purlTypes: ["pub"], + manifests: ["pubspec.yaml"], + lockfiles: ["pubspec.lock"], + osvEcosystem: "Pub", + sbomPurlType: "pub", + supportedClis: ["dart", "flutter"], + commands: { + command: (ctx) => (isFlutterProject(ctx) ? "flutter" : "dart"), + add: (pkg) => { + const target = pkg.version ? `${pkg.name}:${pkg.version}` : pkg.name; + return ["pub", "add", pkg.isDev ? `dev:${target}` : target]; + }, + remove: (pkg) => ["pub", "remove", pkg.name], + install: () => ["pub", "get"], + update: (pkg) => (pkg ? ["pub", "upgrade", pkg.name] : ["pub", "upgrade"]), + }, + resolveScriptCommand: (script, ctx) => + isFlutterProject(ctx) ? ["flutter", [script]] : ["dart", [script]], + injectRegistryEnv: (endpoint, env) => { + env.PUB_HOSTED_URL = endpoint.url; + }, +}); + +export const BACKEND_MOBILE_ADAPTERS: readonly EngineAdapter[] = [ + nugetAdapter, + composerAdapter, + gemAdapter, + pubAdapter, +]; diff --git a/src/engines/index.ts b/src/engines/index.ts index cf0909b..af348c3 100644 --- a/src/engines/index.ts +++ b/src/engines/index.ts @@ -1,4 +1,11 @@ export { BaseEngine } from "./base.js"; +export { + BACKEND_MOBILE_ADAPTERS, + composerAdapter, + gemAdapter, + nugetAdapter, + pubAdapter, +} from "./backend-mobile.js"; export { DeclarativeEngine, defineDeclarativeAdapter, diff --git a/src/engines/registry.ts b/src/engines/registry.ts index fda1869..10183f3 100644 --- a/src/engines/registry.ts +++ b/src/engines/registry.ts @@ -1,5 +1,6 @@ import fs from "node:fs"; -import type { Ecosystem, EngineContext, PackageSpec } from "../types.js"; +import type { Ecosystem, EngineContext } from "../types.js"; +import { BACKEND_MOBILE_ADAPTERS } from "./backend-mobile.js"; import type { BaseEngine } from "./base.js"; import { type EngineAdapter, defineDeclarativeAdapter } from "./declarative.js"; import { GoEngine } from "./go.js"; @@ -286,6 +287,9 @@ engineRegistry.register(pypiAdapter); engineRegistry.register(condaAdapter); engineRegistry.register(cargoAdapter); engineRegistry.register(goAdapter); +for (const adapter of BACKEND_MOBILE_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/outdated/checker.ts b/src/outdated/checker.ts index c69d256..213e409 100644 --- a/src/outdated/checker.ts +++ b/src/outdated/checker.ts @@ -2,6 +2,7 @@ import fs from "node:fs"; import path from "node:path"; import type { Ecosystem } from "../types.js"; import { resolveWorkspaceMembers } from "../workspace/config.js"; +import { extractBackendMobileDependencies } from "../workspace/crypto.js"; import { compareSemver } from "./semver.js"; import type { OutdatedDependency, OutdatedScanReport } from "./types.js"; @@ -137,6 +138,118 @@ async function fetchGoLatest(name: string): Promise { } } +async function fetchNugetLatest(name: string): Promise { + const cacheKey = `nuget:${name.toLowerCase()}`; + if (REGISTRY_CACHE.has(cacheKey)) return REGISTRY_CACHE.get(cacheKey) || null; + + try { + const controller = new AbortController(); + const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS); + const res = await fetch( + `https://api.nuget.org/v3-flatcontainer/${encodeURIComponent(name.toLowerCase())}/index.json`, + { signal: controller.signal }, + ); + clearTimeout(timer); + if (!res.ok) { + REGISTRY_CACHE.set(cacheKey, null); + return null; + } + const data = (await res.json()) as { versions?: string[] }; + const stable = (data.versions ?? []).filter((v) => !v.includes("-")); + const latest = stable[stable.length - 1] ?? data.versions?.[data.versions.length - 1] ?? null; + REGISTRY_CACHE.set(cacheKey, latest); + return latest; + } catch { + REGISTRY_CACHE.set(cacheKey, null); + return null; + } +} + +async function fetchComposerLatest(name: string): Promise { + const pkgKey = name.toLowerCase(); + const cacheKey = `composer:${pkgKey}`; + if (REGISTRY_CACHE.has(cacheKey)) return REGISTRY_CACHE.get(cacheKey) || null; + + try { + const controller = new AbortController(); + const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS); + const res = await fetch(`https://repo.packagist.org/p2/${pkgKey}.json`, { + signal: controller.signal, + }); + clearTimeout(timer); + if (!res.ok) { + REGISTRY_CACHE.set(cacheKey, null); + return null; + } + const data = (await res.json()) as { + packages?: Record>; + }; + const list = data.packages?.[pkgKey] ?? Object.values(data.packages ?? {})[0] ?? []; + const stable = list.find( + (v) => v.version && !v.version.includes("dev") && !v.version.includes("-"), + ); + const latest = (stable?.version ?? list[0]?.version)?.replace(/^v/, "") || null; + REGISTRY_CACHE.set(cacheKey, latest); + return latest; + } catch { + REGISTRY_CACHE.set(cacheKey, null); + return null; + } +} + +async function fetchGemLatest(name: string): Promise { + const cacheKey = `gem:${name}`; + if (REGISTRY_CACHE.has(cacheKey)) return REGISTRY_CACHE.get(cacheKey) || null; + + try { + const controller = new AbortController(); + const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS); + const res = await fetch( + `https://rubygems.org/api/v1/versions/${encodeURIComponent(name)}.json`, + { + signal: controller.signal, + }, + ); + clearTimeout(timer); + if (!res.ok) { + REGISTRY_CACHE.set(cacheKey, null); + return null; + } + const items = (await res.json()) as Array<{ number?: string; prerelease?: boolean }>; + const latest = items.find((i) => i.number && !i.prerelease)?.number ?? items[0]?.number ?? null; + REGISTRY_CACHE.set(cacheKey, latest); + return latest; + } catch { + REGISTRY_CACHE.set(cacheKey, null); + return null; + } +} + +async function fetchPubLatest(name: string): Promise { + const cacheKey = `pub:${name}`; + if (REGISTRY_CACHE.has(cacheKey)) return REGISTRY_CACHE.get(cacheKey) || null; + + try { + const controller = new AbortController(); + const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS); + const res = await fetch(`https://pub.dev/api/packages/${encodeURIComponent(name)}`, { + signal: controller.signal, + }); + clearTimeout(timer); + if (!res.ok) { + REGISTRY_CACHE.set(cacheKey, null); + return null; + } + const data = (await res.json()) as { latest?: { version?: string } }; + const latest = data.latest?.version || null; + REGISTRY_CACHE.set(cacheKey, latest); + return latest; + } catch { + REGISTRY_CACHE.set(cacheKey, null); + return null; + } +} + /** * Dispatches to registry fetcher based on ecosystem. */ @@ -153,6 +266,14 @@ export async function fetchLatestVersion( return fetchCratesLatest(name); case "go": return fetchGoLatest(name); + case "nuget": + return fetchNugetLatest(name); + case "composer": + return fetchComposerLatest(name); + case "gem": + return fetchGemLatest(name); + case "pub": + return fetchPubLatest(name); default: return null; } @@ -290,6 +411,22 @@ function extractDeclaredDependencies( } break; } + + case "nuget": + case "composer": + case "gem": + case "pub": { + for (const item of extractBackendMobileDependencies(manifestPath, content, ecosystem)) { + if (item.version === "any" || item.version === "latest") continue; + deps.push({ + name: item.name, + version: item.version, + ecosystem: item.ecosystem, + memberPath, + }); + } + break; + } } return deps; diff --git a/src/outdated/upgrader.ts b/src/outdated/upgrader.ts index 7d5981a..4c7a250 100644 --- a/src/outdated/upgrader.ts +++ b/src/outdated/upgrader.ts @@ -16,20 +16,18 @@ export function patchManifestVersion( if (!fs.existsSync(manifestPath)) return false; const content = fs.readFileSync(manifestPath, "utf-8"); - // 1. JSON (package.json) + // 1. JSON (package.json, composer.json) if (manifestPath.endsWith(".json")) { try { const json = JSON.parse(content); let modified = false; const cleanVer = `^${newVersion.replace(/^[\^~><=v]+/, "")}`; - if (json.dependencies?.[pkgName]) { - json.dependencies[pkgName] = cleanVer; - modified = true; - } - if (json.devDependencies?.[pkgName]) { - json.devDependencies[pkgName] = cleanVer; - modified = true; + for (const field of ["dependencies", "devDependencies", "require", "require-dev"] as const) { + if (json[field]?.[pkgName]) { + json[field][pkgName] = cleanVer; + modified = true; + } } if (modified) { @@ -41,6 +39,44 @@ export function patchManifestVersion( } } + // 1b. .NET Project XML (*.csproj, *.fsproj, *.vbproj) + if (/\.(cs|fs|vb)proj$/i.test(manifestPath)) { + const cleanVer = newVersion.replace(/^[\^~><=v]+/, ""); + const escapedPkg = pkgName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + const regex = new RegExp( + `(]*Include=["']${escapedPkg}["'][^>]*Version=["'])([^"']+)(["'][^>]*>)`, + "i", + ); + if (regex.test(content)) { + const updated = content.replace(regex, `$1${cleanVer}$3`); + fs.writeFileSync(manifestPath, updated, "utf-8"); + return true; + } + } + + // 1c. Dart / Flutter pubspec.yaml or Ruby Gemfile + if (manifestPath.endsWith("pubspec.yaml")) { + const cleanVer = `^${newVersion.replace(/^[\^~><=v]+/, "")}`; + const escapedPkg = pkgName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + const regex = new RegExp(`^(\\s+${escapedPkg}\\s*:\\s*)([^\\s#]+)`, "m"); + if (regex.test(content)) { + const updated = content.replace(regex, `$1${cleanVer}`); + fs.writeFileSync(manifestPath, updated, "utf-8"); + return true; + } + } + + if (manifestPath.endsWith("Gemfile")) { + const cleanVer = `~> ${newVersion.replace(/^[\^~><=v\s]+/, "")}`; + const escapedPkg = pkgName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); + const regex = new RegExp(`^(\\s*gem\\s+["']${escapedPkg}["']\\s*,\\s*["'])([^"']+)(["'])`, "m"); + if (regex.test(content)) { + const updated = content.replace(regex, `$1${cleanVer}$3`); + fs.writeFileSync(manifestPath, updated, "utf-8"); + return true; + } + } + // 2. TOML (pyproject.toml, Cargo.toml) if (manifestPath.endsWith(".toml")) { const cleanVer = newVersion.replace(/^[\^~><=v]+/, ""); diff --git a/src/security/registry.ts b/src/security/registry.ts index f4ac14b..24795a4 100644 --- a/src/security/registry.ts +++ b/src/security/registry.ts @@ -170,6 +170,150 @@ export async function fetchRegistryMetadata( return meta; } + if (ecosystem === "nuget") { + const res = await fetch( + `https://api.nuget.org/v3/registration5-semver1/${encodeURIComponent(packageName.toLowerCase())}/index.json`, + { signal: controller.signal, headers: { Accept: "application/json" } }, + ); + clearTimeout(timer); + if (!res.ok) return null; + + const data = (await res.json()) as { + items?: Array<{ + items?: Array<{ + catalogEntry?: { + version?: string; + published?: string; + licenseExpression?: string; + }; + }>; + }>; + }; + const versions: Record = {}; + let latestVersion: string | undefined; + for (const page of data.items ?? []) { + for (const entry of page.items ?? []) { + const cat = entry.catalogEntry; + if (!cat?.version) continue; + latestVersion = cat.version; + versions[cat.version] = { + version: cat.version, + publishedAt: cat.published, + license: normalizeLicenseString(cat.licenseExpression), + }; + } + } + const meta: RegistryMetadata = { + name: packageName, + ecosystem: "nuget", + latestVersion, + versions, + }; + REGISTRY_CACHE.set(cacheKey, meta); + return meta; + } + + if (ecosystem === "composer") { + const pkgKey = packageName.toLowerCase(); + const res = await fetch(`https://repo.packagist.org/p2/${pkgKey}.json`, { + signal: controller.signal, + headers: { Accept: "application/json" }, + }); + clearTimeout(timer); + if (!res.ok) return null; + + const data = (await res.json()) as { + packages?: Record>; + }; + const entries = data.packages?.[pkgKey] ?? Object.values(data.packages ?? {})[0] ?? []; + const versions: Record = {}; + let latestVersion: string | undefined; + for (const item of entries) { + if (!item.version || item.version.includes("dev")) continue; + const clean = item.version.replace(/^v/, ""); + if (!latestVersion) latestVersion = clean; + versions[clean] = { + version: clean, + publishedAt: item.time, + license: normalizeLicenseString(item.license?.[0]), + }; + } + const meta: RegistryMetadata = { + name: packageName, + ecosystem: "composer", + latestVersion, + versions, + }; + REGISTRY_CACHE.set(cacheKey, meta); + return meta; + } + + if (ecosystem === "gem") { + const res = await fetch( + `https://rubygems.org/api/v1/versions/${encodeURIComponent(packageName)}.json`, + { signal: controller.signal, headers: { Accept: "application/json" } }, + ); + clearTimeout(timer); + if (!res.ok) return null; + + const items = (await res.json()) as Array<{ + number?: string; + created_at?: string; + licenses?: string[]; + prerelease?: boolean; + }>; + const versions: Record = {}; + let latestVersion: string | undefined; + for (const item of items) { + if (!item.number) continue; + if (!latestVersion && !item.prerelease) latestVersion = item.number; + versions[item.number] = { + version: item.number, + publishedAt: item.created_at, + license: normalizeLicenseString(item.licenses?.[0]), + }; + } + const meta: RegistryMetadata = { + name: packageName, + ecosystem: "gem", + latestVersion, + versions, + }; + REGISTRY_CACHE.set(cacheKey, meta); + return meta; + } + + if (ecosystem === "pub") { + const res = await fetch(`https://pub.dev/api/packages/${encodeURIComponent(packageName)}`, { + signal: controller.signal, + headers: { Accept: "application/json" }, + }); + clearTimeout(timer); + if (!res.ok) return null; + + const data = (await res.json()) as { + latest?: { version?: string; published?: string }; + versions?: Array<{ version?: string; published?: string }>; + }; + const versions: Record = {}; + for (const v of data.versions ?? []) { + if (!v.version) continue; + versions[v.version] = { + version: v.version, + publishedAt: v.published, + license: "BSD-3-CLAUSE", + }; + } + const meta: RegistryMetadata = { + name: packageName, + ecosystem: "pub", + latestVersion: data.latest?.version, + versions, + }; + REGISTRY_CACHE.set(cacheKey, meta); + return meta; + } + clearTimeout(timer); return null; } catch { diff --git a/src/types.ts b/src/types.ts index 9ed67c7..b813683 100644 --- a/src/types.ts +++ b/src/types.ts @@ -3,7 +3,17 @@ * Universal Package & Dependency Orchestration Specification */ -export type BuiltinEcosystem = "npm" | "jsr" | "pypi" | "conda" | "cargo" | "go"; +export type BuiltinEcosystem = + | "npm" + | "jsr" + | "pypi" + | "conda" + | "cargo" + | "go" + | "nuget" + | "composer" + | "gem" + | "pub"; export type Ecosystem = BuiltinEcosystem | (string & {}); export interface EngineContext { diff --git a/src/workspace/crypto.ts b/src/workspace/crypto.ts index 65ed1fa..442770d 100644 --- a/src/workspace/crypto.ts +++ b/src/workspace/crypto.ts @@ -3,6 +3,105 @@ import fs from "node:fs"; import path from "node:path"; import type { Ecosystem } from "../types.js"; +export interface ParsedManifestDep { + name: string; + version: string; + ecosystem: Ecosystem; +} + +/** + * Extracts dependency name/version pairs for Phase 2 backend & mobile ecosystems + * (NuGet/Paket, Composer, RubyGems/Bundler, Dart/Flutter Pub). + */ +export function extractBackendMobileDependencies( + manifestPath: string, + content: string, + ecosystem: Ecosystem, +): ParsedManifestDep[] { + const deps: ParsedManifestDep[] = []; + const fileName = path.basename(manifestPath); + + if (ecosystem === "nuget") { + if (/\.(cs|fs|vb)proj$/i.test(fileName)) { + const refTags = content.match(/]*>/gi) ?? []; + for (const tag of refTags) { + const inc = tag.match(/\bInclude=["']([^"']+)["']/i)?.[1]; + const ver = tag.match(/\bVersion=["']([^"']+)["']/i)?.[1]; + if (inc) { + deps.push({ name: inc.trim(), version: (ver || "latest").trim(), ecosystem: "nuget" }); + } + } + } else if (fileName === "paket.dependencies") { + for (const line of content.split("\n")) { + const match = line.trim().match(/^nuget\s+([^\s]+)(?:\s+(.+))?$/i); + if (match) { + deps.push({ + name: match[1].trim(), + version: (match[2] || "latest").trim(), + ecosystem: "nuget", + }); + } + } + } + } else if (ecosystem === "composer" && fileName === "composer.json") { + try { + const json = JSON.parse(content) as { + require?: Record; + "require-dev"?: Record; + }; + for (const section of [json.require, json["require-dev"]]) { + if (!section) continue; + for (const [name, ver] of Object.entries(section)) { + if (name === "php" || name === "composer-plugin-api" || /^(ext|lib)-/i.test(name)) { + continue; + } + deps.push({ name, version: String(ver), ecosystem: "composer" }); + } + } + } catch { + // Ignore malformed JSON + } + } else if (ecosystem === "gem") { + for (const line of content.split("\n")) { + const trimmed = line.trim(); + if (!trimmed || trimmed.startsWith("#")) continue; + const gemMatch = + fileName === "Gemfile" + ? trimmed.match(/^gem\s+["']([^"']+)["'](?:\s*,\s*["']([^"']+)["'])?/) + : trimmed.match( + /\.add_(?:runtime_|development_)?dependency\s*\(?\s*["']([^"']+)["'](?:\s*,\s*["']([^"']+)["'])?/, + ); + if (gemMatch) { + deps.push({ + name: gemMatch[1], + version: (gemMatch[2] || "latest").trim(), + ecosystem: "gem", + }); + } + } + } else if (ecosystem === "pub" && fileName === "pubspec.yaml") { + let inDeps = false; + for (const rawLine of content.split("\n")) { + const trimmed = rawLine.trim(); + if (!trimmed || trimmed.startsWith("#")) continue; + const indent = rawLine.search(/\S|$/); + if (indent === 0) { + inDeps = trimmed === "dependencies:" || trimmed === "dev_dependencies:"; + continue; + } + if (!inDeps || indent !== 2) continue; + if (trimmed.startsWith("flutter:") || trimmed.startsWith("sdk:")) continue; + const depMatch = trimmed.match(/^([a-zA-Z0-9_]+)\s*:\s*([^\s#]+)?/); + if (depMatch && depMatch[1] !== "flutter" && depMatch[1] !== "flutter_test") { + const ver = depMatch[2]?.replace(/["']/g, "") || "any"; + deps.push({ name: depMatch[1], version: ver, ecosystem: "pub" }); + } + } + } + + return deps; +} + /** * Computes a standardized SHA-256 digest of a file. */ @@ -228,6 +327,16 @@ export function extractDirectDependencies(manifestPath: string, ecosystem: Ecosy } break; } + + case "nuget": + case "composer": + case "gem": + case "pub": { + for (const item of extractBackendMobileDependencies(manifestPath, content, ecosystem)) { + deps.push(`${item.ecosystem}:${item.name}@${item.version}`); + } + break; + } } return deps.sort(); diff --git a/tests/completion.test.ts b/tests/completion.test.ts index 2211c4e..00444cb 100644 --- a/tests/completion.test.ts +++ b/tests/completion.test.ts @@ -40,7 +40,18 @@ test("Shell Auto-Completion - Dynamic Resolution", async (t) => { await t.test("resolves ecosystems for which command", () => { const ecosystems = resolveDynamicCompletions("which"); - assert.deepEqual(ecosystems, ["npm", "jsr", "pypi", "conda", "cargo", "go"]); + assert.deepEqual(ecosystems, [ + "npm", + "jsr", + "pypi", + "conda", + "cargo", + "go", + "nuget", + "composer", + "gem", + "pub", + ]); }); await t.test("resolves all CLI command names", () => { diff --git a/tests/phase1-registry.test.ts b/tests/phase1-registry.test.ts index dd52bb5..96719f8 100644 --- a/tests/phase1-registry.test.ts +++ b/tests/phase1-registry.test.ts @@ -56,39 +56,39 @@ test("Detector - Glob matching handles *.csproj, *.rockspec, and *.cabal", () => assert.equal(matchesManifestGlob("package.json", "*.csproj"), false); const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), "poly-phase1-glob-")); - const nugetAdapter = defineDeclarativeAdapter({ - id: "dotnet-test", - ecosystem: "nuget", - purlTypes: ["nuget"], - manifests: ["*.csproj"], - lockfiles: ["packages.lock.json"], + const luarocksAdapter = defineDeclarativeAdapter({ + id: "luarocks-test", + ecosystem: "luarocks", + purlTypes: ["luarocks"], + manifests: ["*.rockspec"], + lockfiles: ["luarocks.lock"], commands: { - command: "dotnet", - add: (pkg) => ["add", "package", pkg.name], - remove: (pkg) => ["remove", "package", pkg.name], - install: () => ["restore"], - update: (pkg) => ["add", "package", pkg?.name ?? ""], + command: "luarocks", + add: (pkg) => ["install", pkg.name], + remove: (pkg) => ["remove", pkg.name], + install: () => ["make"], + update: (pkg) => ["install", pkg?.name ?? ""], }, }); try { - engineRegistry.register(nugetAdapter); - fs.writeFileSync(path.join(tmpDir, "BillingService.csproj"), ""); + engineRegistry.register(luarocksAdapter); + fs.writeFileSync(path.join(tmpDir, "awesome-1.0-1.rockspec"), "package = 'awesome'"); const contexts = detectContexts(tmpDir); assert.equal(contexts.length, 1); - assert.equal(contexts[0].ecosystem, "nuget"); - assert.equal(contexts[0].manifestFile, "BillingService.csproj"); + assert.equal(contexts[0].ecosystem, "luarocks"); + assert.equal(contexts[0].manifestFile, "awesome-1.0-1.rockspec"); - const spec = parsePackageSpec("nuget:Newtonsoft.Json@13.0.3"); - assert.equal(spec.ecosystem, "nuget"); - const engine = engineRegistry.createEngine("nuget"); + const spec = parsePackageSpec("luarocks:luasocket@3.1.0"); + assert.equal(spec.ecosystem, "luarocks"); + const engine = engineRegistry.createEngine("luarocks"); assert.deepEqual(engine.resolveAddArgs(spec), { - command: "dotnet", - args: ["add", "package", "Newtonsoft.Json"], + command: "luarocks", + args: ["install", "luasocket"], }); } finally { - engineRegistry.unregister("nuget"); + engineRegistry.unregister("luarocks"); fs.rmSync(tmpDir, { recursive: true, force: true }); } }); diff --git a/tests/phase2-backend-mobile.test.ts b/tests/phase2-backend-mobile.test.ts new file mode 100644 index 0000000..3bdf762 --- /dev/null +++ b/tests/phase2-backend-mobile.test.ts @@ -0,0 +1,277 @@ +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 { fetchLatestVersion, scanOutdatedDependencies } from "../src/outdated/checker.js"; +import { patchManifestVersion } from "../src/outdated/upgrader.js"; +import { parsePackageSpec } from "../src/purl/parser.js"; +import { fetchRegistryMetadata } from "../src/security/registry.js"; +import { verifyCompositeLockfile, writeCompositeLockfile } from "../src/workspace/lockfile.js"; + +test("Phase 2 PURL - Parses NuGet, Composer, RubyGems, and Pub shorthands & RFC PURLs", () => { + const nuget = parsePackageSpec("nuget:Newtonsoft.Json@13.0.3"); + assert.equal(nuget.ecosystem, "nuget"); + assert.equal(nuget.name, "Newtonsoft.Json"); + assert.equal(nuget.version, "13.0.3"); + + const composer = parsePackageSpec("composer:laravel/framework@^11.0.0", { isDev: true }); + assert.equal(composer.ecosystem, "composer"); + assert.equal(composer.name, "laravel/framework"); + assert.equal(composer.version, "^11.0.0"); + assert.equal(composer.isDev, true); + + const gem = parsePackageSpec("pkg:gem/sidekiq@7.3.0"); + assert.equal(gem.ecosystem, "gem"); + assert.equal(gem.name, "sidekiq"); + assert.equal(gem.version, "7.3.0"); + + const pub = parsePackageSpec("pkg:pub/http@1.2.0"); + assert.equal(pub.ecosystem, "pub"); + assert.equal(pub.name, "http"); + assert.equal(pub.version, "1.2.0"); +}); + +test("Phase 2 Engines - Resolves CLI args for dotnet/paket, composer/pear, bundle/gem, and dart/flutter", () => { + const dotnet = engineRegistry.createEngine("nuget", { manifest: "Api.csproj" }); + const jsonPkg = parsePackageSpec("nuget:Serilog@4.0.0"); + assert.deepEqual(dotnet.resolveAddArgs(jsonPkg), { + command: "dotnet", + args: ["add", "Api.csproj", "package", "Serilog", "--version", "4.0.0"], + }); + assert.deepEqual(dotnet.resolveRemoveArgs(jsonPkg), { + command: "dotnet", + args: ["remove", "Api.csproj", "package", "Serilog"], + }); + assert.deepEqual(dotnet.resolveInstallArgs(), { command: "dotnet", args: ["restore"] }); + + const paket = engineRegistry.createEngine("nuget", { manifest: "paket.dependencies" }); + assert.deepEqual(paket.resolveInstallArgs(), { command: "paket", args: ["install"] }); + + const composer = engineRegistry.createEngine("composer"); + const phpPkg = parsePackageSpec("composer:monolog/monolog@^3.7", { isDev: true }); + assert.deepEqual(composer.resolveAddArgs(phpPkg), { + command: "composer", + args: ["require", "monolog/monolog:^3.7", "--dev"], + }); + assert.deepEqual(composer.resolveUpdateArgs(phpPkg), { + command: "composer", + args: ["update", "monolog/monolog"], + }); + + const pear = engineRegistry.createEngine("composer", { manifest: "package.xml" }); + assert.equal(pear.resolveInstallArgs().command, "pear"); + + const bundler = engineRegistry.createEngine("gem"); + const gemPkg = parsePackageSpec("gem:rspec@3.13.0", { isDev: true }); + assert.deepEqual(bundler.resolveAddArgs(gemPkg), { + command: "bundle", + args: ["add", "rspec", "--version", "3.13.0", "--group", "development"], + }); + assert.deepEqual(bundler.resolveRemoveArgs(gemPkg), { + command: "bundle", + args: ["remove", "rspec"], + }); + + const tmpFlutter = fs.mkdtempSync(path.join(os.tmpdir(), "poly-phase2-flutter-")); + try { + fs.writeFileSync( + path.join(tmpFlutter, "pubspec.yaml"), + "name: mobile_app\ndependencies:\n flutter:\n sdk: flutter\n http: ^1.1.0\n", + ); + const flutterEngine = engineRegistry.createEngine("pub", { + cwd: tmpFlutter, + manifest: "pubspec.yaml", + }); + const pubPkg = parsePackageSpec("pub:dio@^5.7.0", { isDev: true }); + assert.deepEqual(flutterEngine.resolveAddArgs(pubPkg), { + command: "flutter", + args: ["pub", "add", "dev:dio:^5.7.0"], + }); + assert.deepEqual(flutterEngine.resolveInstallArgs(), { + command: "flutter", + args: ["pub", "get"], + }); + } finally { + fs.rmSync(tmpFlutter, { recursive: true, force: true }); + } +}); + +test("Phase 2 Exit Gate - OSV mapping, SBOM, poly.lock SHA-256, Doctor & Registry Metadata across 4 stacks", async () => { + assert.equal(engineRegistry.getOsvEcosystem("nuget"), "NuGet"); + assert.equal(engineRegistry.getOsvEcosystem("composer"), "Packagist"); + assert.equal(engineRegistry.getOsvEcosystem("gem"), "RubyGems"); + assert.equal(engineRegistry.getOsvEcosystem("pub"), "Pub"); + + const wsDir = fs.mkdtempSync(path.join(os.tmpdir(), "poly-phase2-ws-")); + const csDir = path.join(wsDir, "services", "billing"); + const phpDir = path.join(wsDir, "services", "storefront"); + const rbDir = path.join(wsDir, "services", "worker"); + const dartDir = path.join(wsDir, "apps", "cli"); + + for (const d of [csDir, phpDir, rbDir, dartDir]) fs.mkdirSync(d, { recursive: true }); + + fs.writeFileSync( + path.join(wsDir, "poly.toml"), + '[workspace]\nname = "phase2-multi"\nmembers = ["services/*", "apps/*"]\n', + ); + + fs.writeFileSync( + path.join(csDir, "Billing.fsproj"), + '\n \n \n \n\n', + ); + fs.writeFileSync(path.join(csDir, "packages.lock.json"), "{}"); + + fs.writeFileSync( + path.join(phpDir, "composer.json"), + JSON.stringify({ require: { php: "^8.3", "monolog/monolog": "^3.5.0" } }, null, 2), + ); + fs.writeFileSync(path.join(phpDir, "composer.lock"), "{}"); + + fs.writeFileSync( + path.join(rbDir, "Gemfile"), + 'source "https://rubygems.org"\ngem "sidekiq", "~> 7.2.0"\n', + ); + fs.writeFileSync(path.join(rbDir, "Gemfile.lock"), ""); + + fs.writeFileSync( + path.join(dartDir, "pubspec.yaml"), + "name: cli_tool\ndependencies:\n http: ^1.1.0\n", + ); + fs.writeFileSync(path.join(dartDir, "pubspec.lock"), "{}"); + + const origFetch = globalThis.fetch; + globalThis.fetch = (async (url: string | URL | Request) => { + const u = String(url); + if (u.includes("api.nuget.org/v3-flatcontainer/newtonsoft.json")) { + return new Response(JSON.stringify({ versions: ["13.0.1", "13.0.3"] }), { status: 200 }); + } + if (u.includes("api.nuget.org/v3/registration5-semver1/newtonsoft.json")) { + return new Response( + JSON.stringify({ + items: [ + { + items: [ + { + catalogEntry: { + version: "13.0.3", + published: "2024-01-01T00:00:00Z", + licenseExpression: "MIT", + }, + }, + ], + }, + ], + }), + { status: 200 }, + ); + } + if (u.includes("repo.packagist.org/p2/monolog/monolog.json")) { + return new Response( + JSON.stringify({ + packages: { + "monolog/monolog": [ + { version: "3.8.0", time: "2025-01-01T00:00:00Z", license: ["MIT"] }, + ], + }, + }), + { status: 200 }, + ); + } + if (u.includes("rubygems.org/api/v1/versions/sidekiq.json")) { + return new Response( + JSON.stringify([ + { + number: "7.3.6", + created_at: "2025-02-01T00:00:00Z", + licenses: ["LGPL-3.0"], + prerelease: false, + }, + ]), + { status: 200 }, + ); + } + if (u.includes("pub.dev/api/packages/http")) { + return new Response( + JSON.stringify({ + latest: { version: "1.3.0", published: "2025-03-01T00:00:00Z" }, + versions: [{ version: "1.3.0", published: "2025-03-01T00:00:00Z" }], + }), + { status: 200 }, + ); + } + return new Response("{}", { status: 200 }); + }) as typeof fetch; + + try { + // 1. Detector + Dispatcher + assert.equal(detectContexts(csDir)[0]?.manifestFile, "Billing.fsproj"); + const dispatcher = new PolyDispatcher(); + assert.equal(dispatcher.which("nuget", csDir).effectiveCli, "dotnet"); + assert.equal(dispatcher.which("composer", phpDir).effectiveCli, "composer"); + assert.equal(dispatcher.which("gem", rbDir).effectiveCli, "bundle"); + assert.equal(dispatcher.which("pub", dartDir).effectiveCli, "dart"); + + // 2. poly.lock generation & zero-drift verification + const lock = writeCompositeLockfile(wsDir); + assert.equal(lock.members.length, 4); + assert.equal(verifyCompositeLockfile(wsDir).isDrifted, false); + + // 3. CycloneDX SBOM generation with canonical PURLs + 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:nuget/Newtonsoft.Json@13.0.1"))); + assert.ok(purls.some((p) => p.startsWith("pkg:composer/monolog/monolog@3.5.0"))); + assert.ok(purls.some((p) => p.startsWith("pkg:gem/sidekiq@7.2.0"))); + assert.ok(purls.some((p) => p.startsWith("pkg:pub/http@1.1.0"))); + + // 4. Outdated & Firewall Registry Metadata lookups + assert.equal(await fetchLatestVersion("Newtonsoft.Json", "nuget"), "13.0.3"); + assert.equal(await fetchLatestVersion("monolog/monolog", "composer"), "3.8.0"); + assert.equal(await fetchLatestVersion("sidekiq", "gem"), "7.3.6"); + assert.equal(await fetchLatestVersion("http", "pub"), "1.3.0"); + + const nugetMeta = await fetchRegistryMetadata("nuget", "Newtonsoft.Json"); + assert.equal(nugetMeta?.versions["13.0.3"]?.license, "MIT"); + const composerMeta = await fetchRegistryMetadata("composer", "monolog/monolog"); + assert.equal(composerMeta?.latestVersion, "3.8.0"); + const gemMeta = await fetchRegistryMetadata("gem", "sidekiq"); + assert.equal(gemMeta?.versions["7.3.6"]?.license, "LGPL-3.0"); + const pubMeta = await fetchRegistryMetadata("pub", "http"); + assert.equal(pubMeta?.latestVersion, "1.3.0"); + + const outdated = await scanOutdatedDependencies(wsDir); + assert.equal(outdated.outdatedCount, 4); + + // 5. Upgrader manifest patching across all 4 formats + assert.equal( + patchManifestVersion(path.join(csDir, "Billing.fsproj"), "Newtonsoft.Json", "13.0.3"), + true, + ); + assert.equal( + patchManifestVersion(path.join(phpDir, "composer.json"), "monolog/monolog", "3.8.0"), + true, + ); + assert.equal(patchManifestVersion(path.join(rbDir, "Gemfile"), "sidekiq", "7.3.6"), true); + assert.equal(patchManifestVersion(path.join(dartDir, "pubspec.yaml"), "http", "1.3.0"), true); + + // Refresh poly.lock after manifest upgrades -> audit + doctor pass cleanly + writeCompositeLockfile(wsDir); + const audit = await new CrossStackAuditor().audit(wsDir); + assert.equal(audit.scannedPackages, 4); + + const doctor = await new PolyDoctor().diagnose(wsDir); + assert.equal(doctor.checks.find((c) => c.id === "workspace-lock-drift")?.status, "OK"); + } finally { + globalThis.fetch = origFetch; + fs.rmSync(wsDir, { recursive: true, force: true }); + } +});