/** * The bin refuses an ORM or Composer command when the project holds a * second copy of a Prisma package it loads. These run main() with this * checkout's own CLI as the shell, so the CLI's copies are the real * ones installed here, and the project's copies are written in a * temporary folder. */ import { existsSync, readFileSync } from "node:fs"; import { mkdir, mkdtemp, realpath, symlink, writeFile } from "node:fs/promises"; import { createRequire } from "node:module"; import os from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { loadConfig, type StreamEvent } from "@prisma/cli-engine"; import { CliStructuredError, type Diagnostic, } from "@prisma/cli-engine/protocol"; import { beforeEach, describe, expect, it, vi } from "vitest"; import { composerCommandFamily, mountedCommands, ormCommandFamily, } from "../src/cli"; import { installedBinRunner } from "../src/lib/agent/package-manager"; import * as packageCopies from "../src/lib/package-copies"; import { main } from "../src/main"; import type { HostProcess } from "../src/runtime"; import { invokedProductFamilies, mountedPathsOf, PRODUCT_FAMILIES, refusedCommandsFor, refusedPathsOf, } from "../src/second-copy"; import { installPackage, isolateModuleResolution, seedSyncedSkill, } from "./helpers/skills-fixture"; vi.mock("../src/lib/package-copies", async (importOriginal) => { const original = await importOriginal(); return { ...original, findSecondCopies: vi.fn(original.findSecondCopies), }; }); isolateModuleResolution(); const TOOLCHAIN = "@prisma/orm-toolchain"; const FRAMEWORK = "@prisma/orm-framework"; const requireFromCli = createRequire( path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "package.json"), ); /** The CLI's own toolchain release, read from its installed copy. */ const CLI_TOOLCHAIN_VERSION = ( requireFromCli(`${TOOLCHAIN}/package.json`) as { version: string } ).version; /** The real directory of the CLI's own copy of a package. */ async function cliCopyDir(name: string): Promise { return await realpath( path.dirname(requireFromCli.resolve(`${name}/package.json`)), ); } async function makeRoot(): Promise { return await realpath( await mkdtemp(path.join(os.tmpdir(), "prisma-second-copy-")), ); } /** A prisma.config.ts that, when evaluated, writes to `marker` the * directory of the @prisma/orm-framework it would load, resolved by * Node from the config file as an import would be. */ async function writeMarkerConfig(dir: string, marker: string): Promise { await writeFile( path.join(dir, "prisma.config.ts"), [ `import { writeFileSync } from "node:fs";`, `import { createRequire } from "node:module";`, `import { dirname } from "node:path";`, `let loaded = "";`, `try {`, ` loaded = dirname(createRequire(import.meta.url).resolve("${FRAMEWORK}/package.json"));`, `} catch {}`, `writeFileSync(${JSON.stringify(marker)}, loaded);`, `export default {};`, ``, ].join("\n"), "utf8", ); } /** A project in its own repository, whose prisma.config.ts writes a * marker file when it is evaluated. */ async function makeProject(): Promise<{ dir: string; marker: string }> { const dir = path.join(await makeRoot(), "app"); await mkdir(path.join(dir, ".git"), { recursive: true }); const marker = path.join(dir, "config-was-evaluated"); await writeMarkerConfig(dir, marker); return { dir, marker }; } async function writePackage( packageDir: string, name: string, version: string, ): Promise { await mkdir(packageDir, { recursive: true }); await writeFile( path.join(packageDir, "package.json"), `${JSON.stringify({ name, version })}\n`, "utf8", ); } /** The project installed its own toolchain, at another release than * the CLI carries. */ async function makeProjectWithSecondCopy(): Promise<{ dir: string; marker: string; projectCopy: string; }> { const project = await makeProject(); const projectCopy = path.join(project.dir, "node_modules", TOOLCHAIN); await writePackage(projectCopy, TOOLCHAIN, "8.0.0-rc.24"); return { ...project, projectCopy }; } /** The project's node_modules links to the CLI's own copies, as a * hoisted install of the project's own prisma would. */ async function makeProjectSharingCliCopies(): Promise<{ dir: string; marker: string; }> { const project = await makeProject(); await linkCliCopies(path.join(project.dir, "node_modules")); return project; } async function linkCliCopies(nodeModules: string): Promise { await mkdir(path.join(nodeModules, "@prisma"), { recursive: true }); await Promise.all( [TOOLCHAIN, FRAMEWORK].map(async (name) => symlink(await cliCopyDir(name), path.join(nodeModules, name), "dir"), ), ); } function makeProcess(options: { argv: string[]; cwd: string; skillsCheck?: boolean; }): HostProcess & { stdoutText: string; stderrText: string } { const configHome = path.join(options.cwd, ".config-home"); const proc = { argv: ["node", "bin.js", ...options.argv], env: { PRISMA_DISABLE_TELEMETRY: "1", PRISMA_SKILLS_CHECK: options.skillsCheck === true ? "1" : "0", NO_UPDATE_NOTIFIER: "1", XDG_CONFIG_HOME: configHome, APPDATA: configHome, }, cwd: () => options.cwd, version: "v22.12.0", versions: { node: "22.12.0" }, platform: "linux", arch: "x64", stdoutText: "", stderrText: "", stdout: { isTTY: false, write(text: string) { proc.stdoutText += text; }, }, stderr: { isTTY: false, write(text: string) { proc.stderrText += text; }, }, stdin: { isTTY: false, async *[Symbol.asyncIterator]() {}, } as unknown as HostProcess["stdin"], on: () => proc, off: () => proc, exit(code: number): never { throw new Error(`process.exit(${code})`); }, }; return proc; } function resultFailure(stdoutText: string): Diagnostic { const frames = stdoutText .split("\n") .filter((line) => line !== "") .map((line) => JSON.parse(line) as StreamEvent); const last = frames.at(-1); if (last?.kind !== "result" || last.envelope.ok) { throw new Error(`expected a failed result frame, got: ${stdoutText}`); } return last.envelope.error; } /** The error a refused command's stand-in throws. */ async function refusalOf( refused: Awaited>, commandPath: string, ): Promise { const standIn = refused .map((entry) => entry.commands[commandPath]) .find((def) => def !== undefined); if (standIn === undefined) { throw new Error(`'${commandPath}' was not refused`); } try { await (standIn.handler as () => Promise)(); } catch (error) { if (error instanceof CliStructuredError) { return error; } throw error; } throw new Error("the stand-in did not refuse"); } /** A prisma install outside the project, holding its own copies. */ async function writeOutsidePrisma( root: string, copies: Readonly>, ): Promise { const prismaDir = path.join(root, "global", "lib", "node_modules", "prisma"); await writePackage(prismaDir, "prisma", "8.0.0-rc.36"); await Promise.all( Object.entries(copies).map(([name, version]) => writePackage(path.join(prismaDir, "node_modules", name), name, version), ), ); return path.join(prismaDir, "dist", "prisma.js"); } beforeEach(() => { vi.mocked(packageCopies.findSecondCopies).mockClear(); }); const FAMILY_NAMES = new Map([ [ormCommandFamily, "orm"], [composerCommandFamily, "composer"], ]); describe("which invocations run the check", () => { it("gives each product family first words no other mounted command starts with", () => { const owners = new Map>(); for (const mountPath of Object.keys(mountedCommands)) { const word = mountPath.split(" ")[0] as string; const product = PRODUCT_FAMILIES.find((candidate) => mountedPathsOf(candidate.family).includes(mountPath), ); const owner = (product && FAMILY_NAMES.get(product.family)) ?? "other"; owners.set(word, (owners.get(word) ?? new Set()).add(owner)); } const shared = [...owners].filter( ([, families]) => families.size > 1 && (families.has("orm") || families.has("composer")), ); expect(shared).toEqual([]); }); it("finds every family whose command word the invocation contains", () => { const families = (argv: string[]) => invokedProductFamilies(argv).map((product) => product.family); expect(families(["db", "migrate"])).toEqual([ormCommandFamily]); expect(families(["--config", "x.ts", "deploy"])).toEqual([ composerCommandFamily, ]); expect(families(["--config", "dev", "db", "migrate"])).toEqual([ ormCommandFamily, composerCommandFamily, ]); expect(families(["emulator", "list"])).toEqual([]); expect(families(["auth", "login"])).toEqual([]); expect(families(["auth", "login", "--", "db"])).toEqual([]); }); it("never runs the check for a platform command", async () => { const { dir } = await makeProjectWithSecondCopy(); const proc = makeProcess({ argv: ["auth", "login"], cwd: dir }); await main(proc, () => ({ run: async () => 0 })); expect(packageCopies.findSecondCopies).not.toHaveBeenCalled(); }); it("runs the check for a product command", async () => { const { dir } = await makeProjectWithSecondCopy(); const proc = makeProcess({ argv: ["db", "migrate"], cwd: dir }); await main(proc, () => ({ run: async () => 0 })); expect(packageCopies.findSecondCopies).toHaveBeenCalled(); }); }); describe("the commands a second copy refuses", () => { it("leaves only these product commands unrefused", () => { const unrefused = PRODUCT_FAMILIES.flatMap((product) => { const refused = new Set(refusedPathsOf(product.family)); return mountedPathsOf(product.family).filter( (mountPath) => !refused.has(mountPath), ); }); // A command here reads no project config, loads none of the // project's packages and writes nothing the project's runtime reads. expect(unrefused).toEqual(["emulator list"]); }); it("replaces each refused command with one of the same kind, help and arguments", async () => { const { dir } = await makeProjectWithSecondCopy(); await writePackage( path.join(dir, "node_modules", "@prisma", "composer"), "@prisma/composer", "0.39.0", ); const refused = await refusedCommandsFor({ argv: ["db", "dev"], cwd: dir, }); expect(refused.map((entry) => entry.docsBaseUrl)).toEqual( PRODUCT_FAMILIES.map((product) => product.family.docsBaseUrl), ); for (const [index, product] of PRODUCT_FAMILIES.entries()) { const commands = refused[index]?.commands ?? {}; expect(Object.keys(commands).sort()).toEqual( [...refusedPathsOf(product.family)].sort(), ); for (const [mountPath, standIn] of Object.entries(commands)) { const original = mountedCommands[mountPath]; expect(standIn.kind).toBe(original?.kind); expect(standIn.help).toBe(original?.help); expect(standIn.args).toBe(original?.args); expect(standIn.needs.config).toBeUndefined(); expect(standIn.needs.credentials).toBe(false); } } }); it("checks the ORM command when a flag value names a Composer word", async () => { const { dir } = await makeProjectWithSecondCopy(); const refused = await refusedCommandsFor({ argv: ["--config", "dev", "db", "migrate"], cwd: dir, }); expect(refused.some((entry) => "db migrate" in entry.commands)).toBe(true); }); it("looks from the directory of the --config file", async () => { const { dir } = await makeProjectWithSecondCopy(); const elsewhere = path.join(await makeRoot(), "elsewhere"); await mkdir(elsewhere, { recursive: true }); expect( await refusedCommandsFor({ argv: ["db", "migrate"], cwd: elsewhere }), ).toEqual([]); expect( await refusedCommandsFor({ argv: [ "db", "migrate", "--config", path.relative(elsewhere, path.join(dir, "prisma.config.ts")), ], cwd: elsewhere, }), ).not.toEqual([]); }); }); describe("the copy the check compares is the copy the config loads", () => { it("does not refuse a package's own prisma because of a copy beside a repository-wide config", async () => { const repo = path.join(await makeRoot(), "repo"); await mkdir(path.join(repo, ".git"), { recursive: true }); await writeFile( path.join(repo, "prisma.config.ts"), "export default {};\n", "utf8", ); await writePackage( path.join(repo, "node_modules", TOOLCHAIN), TOOLCHAIN, "8.0.0-rc.24", ); const b = path.join(repo, "packages", "b"); await mkdir(b, { recursive: true }); await writeMarkerConfig(b, path.join(b, "evaluated")); const bPrisma = path.join(b, "node_modules", "prisma"); await writePackage(bPrisma, "prisma", "8.0.0-rc.36"); await writePackage( path.join(b, "node_modules", TOOLCHAIN), TOOLCHAIN, "8.0.0-rc.25", ); expect( await refusedCommandsFor({ argv: ["db", "migrate"], cwd: b, shellModuleFile: path.join(bPrisma, "dist", "prisma.js"), }), ).toEqual([]); }); /** A monorepo whose only config is at its root, run from a package * that has its own node_modules. */ async function makeMonorepo(): Promise<{ repo: string; app: string; marker: string; }> { const repo = path.join(await makeRoot(), "repo"); await mkdir(path.join(repo, ".git"), { recursive: true }); const marker = path.join(repo, "config-was-evaluated"); await writeMarkerConfig(repo, marker); const app = path.join(repo, "packages", "app"); await mkdir(app, { recursive: true }); return { repo, app, marker }; } it("refuses when the config would load a copy other than the CLI's", async () => { const { repo, app, marker } = await makeMonorepo(); await writePackage( path.join(repo, "node_modules", FRAMEWORK), FRAMEWORK, "8.0.0-rc.24", ); await linkCliCopies(path.join(app, "node_modules")); const proc = makeProcess({ argv: ["migration", "list", "--json"], cwd: app, }); await main(proc); expect(resultFailure(proc.stdoutText).code).toBe("CLI.SECOND_PACKAGE_COPY"); expect(existsSync(marker)).toBe(false); await loadConfig(app).catch(() => undefined); expect(await realpath(readFileSync(marker, "utf8"))).not.toBe( await cliCopyDir(FRAMEWORK), ); }); it("runs when the config would load the CLI's own copy", async () => { const { repo, app, marker } = await makeMonorepo(); await linkCliCopies(path.join(repo, "node_modules")); await writePackage( path.join(app, "node_modules", FRAMEWORK), FRAMEWORK, "8.0.0-rc.24", ); const proc = makeProcess({ argv: ["migration", "list", "--json"], cwd: app, }); await main(proc); expect(proc.stdoutText).not.toContain("CLI.SECOND_PACKAGE_COPY"); expect(await realpath(readFileSync(marker, "utf8"))).toBe( await cliCopyDir(FRAMEWORK), ); }); }); describe("a product command in a project with a second copy", () => { it("fails before evaluating the project's config, naming both copies", async () => { const { dir, marker, projectCopy } = await makeProjectWithSecondCopy(); const proc = makeProcess({ argv: ["migration", "list"], cwd: dir }); const exitCode = await main(proc); expect(exitCode).toBe(2); expect(existsSync(marker)).toBe(false); expect(proc.stderrText).toContain("CLI.SECOND_PACKAGE_COPY"); expect(proc.stderrText).toContain( `prisma migration list cannot run here: the project uses @prisma/orm-toolchain 8.0.0-rc.24, and this prisma uses ${CLI_TOOLCHAIN_VERSION}.`, ); expect(proc.stderrText).toContain(projectCopy); expect(proc.stderrText).toContain(await cliCopyDir(TOOLCHAIN)); expect(proc.stdoutText).toBe(""); }); it("reports the same failure as a --json envelope", async () => { const { dir, marker, projectCopy } = await makeProjectWithSecondCopy(); const proc = makeProcess({ argv: ["db", "migrate", "--json"], cwd: dir }); const exitCode = await main(proc); expect(exitCode).toBe(2); expect(existsSync(marker)).toBe(false); expect(resultFailure(proc.stdoutText)).toMatchObject({ code: "CLI.SECOND_PACKAGE_COPY", docsUrl: "https://www.prisma.io/docs/cli/error-reference/CLI.SECOND_PACKAGE_COPY", meta: { command: "db migrate", packages: [ { name: TOOLCHAIN, project: { version: "8.0.0-rc.24", path: projectCopy }, cli: { version: CLI_TOOLCHAIN_VERSION, path: await cliCopyDir(TOOLCHAIN), }, }, ], }, nextActions: [ { kind: "user-choice", label: "Install prisma in the project, then run the project's own prisma from the project's directory. If that one is refused too, its error names the versions to change.", }, ], }); }); it("does not evaluate the config for the skills notice after a refusal", async () => { async function makeStaleSkillsProject(): Promise<{ dir: string; marker: string; }> { const project = await makeProjectWithSecondCopy(); await installPackage(project.dir, { name: "@prisma/orm-postgres", version: "8.1.0", skills: ["prisma-8"], }); await seedSyncedSkill(project.dir, ".claude/skills", { skill: "prisma-8", library: "@prisma/orm-postgres", version: "8.0.0", }); return project; } const control = await makeStaleSkillsProject(); await main( makeProcess({ argv: ["auth", "whoami"], cwd: control.dir, skillsCheck: true, }), () => ({ run: async () => 0 }), ); expect(existsSync(control.marker)).toBe(true); const refused = await makeStaleSkillsProject(); const proc = makeProcess({ argv: ["migration", "list"], cwd: refused.dir, skillsCheck: true, }); expect(await main(proc)).toBe(2); expect(proc.stderrText).toContain("CLI.SECOND_PACKAGE_COPY"); expect(existsSync(refused.marker)).toBe(false); }); it("refuses a session command and a server command too", async () => { const { dir, marker } = await makeProjectWithSecondCopy(); await writePackage( path.join(dir, "node_modules", "@prisma", "composer"), "@prisma/composer", "0.39.0", ); const dev = makeProcess({ argv: ["dev", "--json"], cwd: dir }); expect(await main(dev)).toBe(2); expect(resultFailure(dev.stdoutText).code).toBe("CLI.SECOND_PACKAGE_COPY"); const lsp = makeProcess({ argv: ["lsp", "--stdio"], cwd: dir }); expect(await main(lsp)).toBe(2); expect(lsp.stderrText).toContain("CLI.SECOND_PACKAGE_COPY"); expect(lsp.stdoutText).toBe(""); expect(existsSync(marker)).toBe(false); }); it("shows the same help as without a second copy", async () => { const { dir } = await makeProjectWithSecondCopy(); const refused = makeProcess({ argv: ["db", "migrate", "--help"], cwd: dir, }); const plain = makeProcess({ argv: ["db", "migrate", "--help"], cwd: await makeRoot(), }); expect(await main(refused)).toBe(0); expect(await main(plain)).toBe(0); expect(refused.stdoutText).not.toBe(""); expect(refused.stdoutText).toBe(plain.stdoutText); }); }); describe("what the error says", () => { it("offers the project's own prisma, which would pass, as a command that never downloads", async () => { const { dir } = await makeProjectWithSecondCopy(); await writePackage( path.join(dir, "node_modules", "prisma"), "prisma", "8.0.0-rc.35", ); await writeFile(path.join(dir, "pnpm-lock.yaml"), "", "utf8"); const proc = makeProcess({ argv: ["db", "migrate", "--json"], cwd: dir }); await main(proc); expect(resultFailure(proc.stdoutText).nextActions).toEqual([ { kind: "run-command", label: "Run the project's own prisma instead, adding your other arguments after the command", command: "pnpm exec prisma db migrate", }, ]); }); it("keeps the --config the user gave in the suggested command, and nothing else", async () => { const { dir } = await makeProjectWithSecondCopy(); await writePackage( path.join(dir, "node_modules", "prisma"), "prisma", "8.0.0-rc.35", ); await writeFile(path.join(dir, "package-lock.json"), "{}", "utf8"); const configDir = path.join(dir, "config dir"); await mkdir(configDir, { recursive: true }); await writeMarkerConfig(configDir, path.join(configDir, "evaluated")); const proc = makeProcess({ argv: [ "migration", "show", "20261130_init", "--config", "config dir/prisma.config.ts", "--json", ], cwd: dir, }); await main(proc); expect(resultFailure(proc.stdoutText).nextActions).toEqual([ { kind: "run-command", label: "Run the project's own prisma instead, adding your other arguments after the command", command: "npx --no-install prisma migration show --config 'config dir/prisma.config.ts'", }, ]); }); it("names the versions to change when the project's own prisma would be refused too", async () => { const { dir } = await makeProjectWithSecondCopy(); const projectPrisma = path.join(dir, "node_modules", "prisma"); await writePackage(projectPrisma, "prisma", "8.0.0-rc.37"); await writePackage( path.join(projectPrisma, "node_modules", TOOLCHAIN), TOOLCHAIN, "8.0.0-rc.26", ); const error = await refusalOf( await refusedCommandsFor({ argv: ["db", "migrate"], cwd: dir }), "db migrate", ); expect(error.nextActions).toEqual([ { kind: "user-choice", label: "Change the project's @prisma/orm-toolchain to 8.0.0-rc.26, the version the project's own prisma uses, then run the command again.", }, { kind: "user-choice", label: "Or install a release of prisma in the project that uses @prisma/orm-toolchain 8.0.0-rc.24, the version the project has.", }, ]); }); it("names the versions to change when the running prisma is the project's own", async () => { const root = await makeRoot(); const app = path.join(root, "app"); await mkdir(path.join(app, ".git"), { recursive: true }); const projectPrisma = path.join(app, "node_modules", "prisma"); await writePackage(projectPrisma, "prisma", "8.0.0-rc.36"); await writePackage( path.join(app, "node_modules", TOOLCHAIN), TOOLCHAIN, "8.0.0-rc.24", ); await writePackage( path.join(app, "node_modules", FRAMEWORK), FRAMEWORK, "8.0.0-rc.24", ); await writePackage( path.join(projectPrisma, "node_modules", TOOLCHAIN), TOOLCHAIN, "8.0.0-rc.25", ); await writePackage( path.join(projectPrisma, "node_modules", FRAMEWORK), FRAMEWORK, "8.0.0-rc.25", ); const error = await refusalOf( await refusedCommandsFor({ argv: ["db", "migrate"], cwd: app, shellModuleFile: path.join(projectPrisma, "dist", "prisma.js"), }), "db migrate", ); expect(error.why).toContain( `The project's ${TOOLCHAIN} 8.0.0-rc.24 is at ${path.join(app, "node_modules", TOOLCHAIN)}.`, ); expect(error.why).toContain( `This prisma's ${FRAMEWORK} 8.0.0-rc.25 is at ${path.join(projectPrisma, "node_modules", FRAMEWORK)}.`, ); expect( (error.meta?.packages as { name: string }[]).map((copy) => copy.name), ).toEqual([TOOLCHAIN, FRAMEWORK]); expect(error.nextActions[0]?.label).toBe( "Change the project's @prisma/orm-toolchain to 8.0.0-rc.25 and @prisma/orm-framework to 8.0.0-rc.25, the versions this prisma uses, then run the command again.", ); }); it("says when both copies are the same version", async () => { const root = await makeRoot(); const app = path.join(root, "app"); await mkdir(path.join(app, ".git"), { recursive: true }); await writePackage( path.join(app, "node_modules", TOOLCHAIN), TOOLCHAIN, "8.0.0-rc.25", ); const shell = await writeOutsidePrisma(root, { [TOOLCHAIN]: "8.0.0-rc.25", }); const error = await refusalOf( await refusedCommandsFor({ argv: ["db", "migrate"], cwd: app, shellModuleFile: shell, }), "db migrate", ); expect(error.message).toBe( "prisma db migrate cannot run here: the project and this prisma each have their own copy of @prisma/orm-toolchain 8.0.0-rc.25.", ); expect(error.why).toContain( "They are the same version installed twice, and two installed copies do not work together even then.", ); }); it("says to reinstall when the project's prisma holds the same version twice", async () => { const root = await makeRoot(); const app = path.join(root, "app"); await mkdir(path.join(app, ".git"), { recursive: true }); const projectPrisma = path.join(app, "node_modules", "prisma"); await writePackage(projectPrisma, "prisma", "8.0.0-rc.36"); await writePackage( path.join(app, "node_modules", TOOLCHAIN), TOOLCHAIN, "8.0.0-rc.25", ); await writePackage( path.join(projectPrisma, "node_modules", TOOLCHAIN), TOOLCHAIN, "8.0.0-rc.25", ); const error = await refusalOf( await refusedCommandsFor({ argv: ["db", "migrate"], cwd: app, shellModuleFile: path.join(projectPrisma, "dist", "prisma.js"), }), "db migrate", ); expect(error.nextActions).toEqual([ { kind: "user-choice", label: "Reinstall the project's dependencies so that this prisma and the project share one copy of @prisma/orm-toolchain, then run the command again.", }, ]); }); it("says in words to run the project's prisma when only --config reaches it", async () => { const root = await makeRoot(); const app = path.join(root, "app"); await mkdir(path.join(app, ".git"), { recursive: true }); await writeFile(path.join(app, "prisma.config.ts"), "", "utf8"); await writePackage( path.join(app, "node_modules", TOOLCHAIN), TOOLCHAIN, "8.0.0-rc.24", ); const projectPrisma = path.join(app, "node_modules", "prisma"); await writePackage(projectPrisma, "prisma", "8.0.0-rc.35"); const elsewhere = path.join(root, "elsewhere"); await mkdir(elsewhere, { recursive: true }); const shell = await writeOutsidePrisma(root, { [TOOLCHAIN]: "8.0.0-rc.25", }); const error = await refusalOf( await refusedCommandsFor({ argv: ["db", "migrate", "--config", "../app/prisma.config.ts"], cwd: elsewhere, shellModuleFile: shell, }), "db migrate", ); expect(error.nextActions).toEqual([ { kind: "user-choice", label: `From the project's directory, run the project's own prisma (installed at ${projectPrisma}) with the same command and arguments, giving --config ${path.join(app, "prisma.config.ts")}.`, }, ]); }); }); describe("running a bin the project installed", () => { it.each([ ["npm", "npx --no-install"], ["pnpm", "pnpm exec"], ["yarn", "yarn exec"], ["bun", "bunx --no-install"], ] as const)("spells %s as %s", (manager, runner) => { expect(installedBinRunner(manager)).toBe(runner); }); }); describe("a product command where the project's copy is the CLI's own", () => { it("builds the shipped tree unchanged and reads the project's config", async () => { const { dir, marker } = await makeProjectSharingCliCopies(); const options: unknown[] = []; await main(makeProcess({ argv: ["db", "migrate"], cwd: dir }), (built) => { options.push(built); return { run: async () => 0 }; }); await main( makeProcess({ argv: ["migration", "list", "--json"], cwd: dir }), ); expect(options).toEqual([undefined]); expect(existsSync(marker)).toBe(true); }); });