diff --git a/docs/architecture/adrs/0006-consent-as-a-statement.md b/docs/architecture/adrs/0006-consent-as-a-statement.md index c2cea4fe..605c68e8 100644 --- a/docs/architecture/adrs/0006-consent-as-a-statement.md +++ b/docs/architecture/adrs/0006-consent-as-a-statement.md @@ -47,10 +47,6 @@ These came from the ORM's first use and the reviews of this change, all in engin - **A signal while a prompt waits cancels the prompt** with `CLI.PROMPT_CANCELLED`: exit 3 for SIGINT, as Ctrl-C at the prompt is the user declining, and 143 for SIGTERM, which ends the run as a delivered signal. Later prompts in the run are cancelled at once, and a further signal force-exits. - **`last: true`** marks a batch as the run's final ask: values still unconsumed fail with `CLI.CONSENT_UNUSED` as soon as it is answered, before the command acts on the answers. -Added in engine 0.10.1: - -- **The question is the first line of the refusal** when it is the only question nobody can answer; with several, the first line counts them and `why` lists them. So a question is one line that names what it is about and what is at stake. - ## Consequences - A product adds a consent vocabulary by declaring it on the command that uses it, and its help text with it. The engine stays free of product words. diff --git a/docs/reference/error-reference.md b/docs/reference/error-reference.md index 2cfdbc88..44403258 100644 --- a/docs/reference/error-reference.md +++ b/docs/reference/error-reference.md @@ -186,7 +186,7 @@ The config file's `$prismaConfig` marker declares a version other than the one t A consent prompt was reached under `--yes` or in a non-interactive session. Consent has no default answer and `--yes` does not grant it, so there is nothing for the run to assume. When the consent declares a token, the message and next action say to pass `--confirm `, and the token travels in meta; without a token, the only path is running the command interactively. Meta: `consentToken` (only when the consent declares a token). -A statement prompt (`ctx.prompt.statement` or `ctx.prompt.statements`) raises the same code when no statement flag on the command line answers it. One error lists every question still unanswered, and the next actions give one flag to pass per verb, such as `--delete Legacy` or `--rename 'Legacy:'`. With one question unanswered, the summary is the command's question and `why` says that the user has to choose and that the run cannot ask (or, under `--yes`, that `--yes` does not choose). With several, the summary gives their number and `why` carries the questions. `why` also lists every given statement flag that names none of the questions' subjects, and any `--confirm` token, which answers no statement, so a misspelled flag is reported before anyone answers a prompt. Meta: `unanswered` (a list of `{ subject, verbs }`), plus `subject` and `verbs` when exactly one question is unanswered; `unmatched` (a list of `{ verb, values }`) and `confirm` (the tokens) when any. +A statement prompt (`ctx.prompt.statement` or `ctx.prompt.statements`) raises the same code when no statement flag on the command line answers it. One error lists every question still unanswered: the summary says the command requires explicit consent and did not get it (under `--yes`, that `--yes` does not give it), `why` carries the questions, and the next actions give one flag to pass per verb, such as `--delete Legacy` or `--rename 'Legacy:'`. `why` also lists every given statement flag that names none of the questions' subjects, and any `--confirm` token, which answers no statement, so a misspelled flag is reported before anyone answers a prompt. Meta: `unanswered` (a list of `{ subject, verbs }`), plus `subject` and `verbs` when exactly one question is unanswered; `unmatched` (a list of `{ verb, values }`) and `confirm` (the tokens) when any. ### CLI.CONSENT_UNUSED diff --git a/packages/cli-engine/README.md b/packages/cli-engine/README.md index 8d58d56d..419a0d4a 100644 --- a/packages/cli-engine/README.md +++ b/packages/cli-engine/README.md @@ -66,7 +66,7 @@ Each occurrence of `--` takes exactly `arity` values, in argv order across The engine answers the question in this order: 1. A verb flag whose first value names the subject: the value is the subject, or starts with `:`. `--delete Legacy` and `--rename Legacy:Archive` both name `Legacy`. Within one batch, a value equal to a subject answers that subject first, and any other value goes to the longest subject it names, so `--delete A:B` answers the question about `A:B`, not the one about `A`. Ask questions whose subjects are prefixes of one another in one batch. A value `validate` rejects fails the run with `CLI.PROMPT_INVALID`. -2. With no such value, a non-interactive run, or one under `--yes`, fails with `CLI.CONSENT_REQUIRED`. When one question is unanswered, the error's first line is that question word for word, so write the question to name what it is about. Its next actions give one flag to pass per verb, safe to paste into a shell: a value with anything but plain characters is single-quoted, and a value starting with `-` is written `--=`, and its `meta` carries `subject`, `verbs` and `unanswered`. +2. With no such value, a non-interactive run, or one under `--yes`, fails with `CLI.CONSENT_REQUIRED`. Its next actions give one flag to pass per verb, safe to paste into a shell: a value with anything but plain characters is single-quoted, and a value starting with `-` is written `--=`, and its `meta` carries `subject`, `verbs` and `unanswered`. 3. Otherwise the user is asked, and answers ` `, or `` alone to mean the subject. A verb with an arity above 1 takes its values from the text, separated by whitespace, and `text` is them joined by one space, as for a flag. A rejected answer is asked again on a terminal; with scripted or piped input it fails with `CLI.PROMPT_INVALID`. `ctx.prompt.statements([...])` asks several questions at once and returns the answers in order. Flags answer what they can, a refusal lists every question still unanswered, and an interactive run asks the rest one after another. diff --git a/packages/cli-engine/package.json b/packages/cli-engine/package.json index 7e1631a0..accc1dbe 100644 --- a/packages/cli-engine/package.json +++ b/packages/cli-engine/package.json @@ -1,6 +1,6 @@ { "name": "@prisma/cli-engine", - "version": "0.10.1", + "version": "0.10.2", "description": "The execution engine of the unified Prisma CLI.", "type": "module", "exports": { diff --git a/packages/cli-engine/src/context.ts b/packages/cli-engine/src/context.ts index 0ed1cf49..357ef066 100644 --- a/packages/cli-engine/src/context.ts +++ b/packages/cli-engine/src/context.ts @@ -216,8 +216,6 @@ export interface StatementOptions { export interface StatementQuestion extends StatementOptions { - /** Shown as the prompt, and as the first line of the error when it is - * the only question nobody can answer. Name what it is about. */ readonly question: string; } diff --git a/packages/cli-engine/src/execution/prompts.ts b/packages/cli-engine/src/execution/prompts.ts index 6875ae3a..79444451 100644 --- a/packages/cli-engine/src/execution/prompts.ts +++ b/packages/cli-engine/src/execution/prompts.ts @@ -158,7 +158,6 @@ function answerFromFlags( function strayFlagLines( state: RunState, subjects: readonly string[], - verbs: readonly string[], ): readonly string[] { const unmatched = state.statementValues.filter( (value) => @@ -168,11 +167,11 @@ function strayFlagLines( return [ ...unmatched.map( (value) => - `${flagForm(value.verb, value.values)} does not name ${subjects.join(" or ")}.`, + `${flagForm(value.verb, value.values)} answers no question; the questions are about ${subjects.join(", ")}.`, ), ...state.confirmValues.map( (token) => - `${flagForm("confirm", [token])} does not choose what happens; ${verbs.map((verb) => `--${verb}`).join(" or ")} does.`, + `${flagForm("confirm", [token])} answers no consent in this run; a statement flag is what answers these questions.`, ), ]; } @@ -182,14 +181,9 @@ function statementUnavailable( subjects: readonly string[], state: RunState, ): CliStructuredError { - const situation = state.yes - ? "--yes does not choose for you" - : "this run cannot ask you"; - const [only, ...others] = unanswered; - const alone = others.length === 0; - const summary = alone - ? only.question - : `${unanswered.length} choices are needed, and ${situation}.`; + const summary = state.yes + ? "This command requires explicit consent, and --yes does not give it." + : "This command requires explicit consent, but it was not provided."; const listed = unanswered.map(({ subject, verbs }) => ({ subject, verbs })); const unmatched = state.statementValues .filter( @@ -200,12 +194,8 @@ function statementUnavailable( .map(({ verb, values }) => ({ verb, values })); return new CliStructuredError("CLI.CONSENT_REQUIRED", summary, { why: [ - ...(alone - ? [`You have to choose what happens, and ${situation}.`] - : unanswered.map((question) => question.question)), - ...strayFlagLines(state, subjects, [ - ...new Set(unanswered.flatMap((question) => question.verbs)), - ]), + ...unanswered.map((question) => question.question), + ...strayFlagLines(state, subjects), ].join("\n"), nextActions: unanswered.flatMap((question) => question.verbs.map((verb) => ({ diff --git a/packages/cli-engine/tests/consent-leftovers.test.ts b/packages/cli-engine/tests/consent-leftovers.test.ts index 22e71874..931fd90f 100644 --- a/packages/cli-engine/tests/consent-leftovers.test.ts +++ b/packages/cli-engine/tests/consent-leftovers.test.ts @@ -99,7 +99,7 @@ describe("an unconsumed --confirm token", () => { }); }); - test("is reported with a statement refusal, which names the flags that choose", async () => { + test("is reported with a statement refusal, which says a statement flag answers it", async () => { const result = await cliWith(askBoth).run([ "probe", "--confirm", @@ -109,32 +109,10 @@ describe("an unconsumed --confirm token", () => { expect(errorOf(result)).toMatchObject({ code: "CLI.CONSENT_REQUIRED", - why: "What happens to Legacy?\nWhat happens to User.nickname?\n--confirm mydb does not choose what happens; --rename or --delete does.", + why: "What happens to Legacy?\nWhat happens to User.nickname?\n--confirm mydb answers no consent in this run; a statement flag is what answers these questions.", meta: { confirm: ["mydb"] }, }); }); - - test("names only the flags of the questions still unanswered", async () => { - const result = await cliWith((prompt) => - prompt.statements([ - question("Legacy"), - { ...question("User.nickname"), verbs: ["delete"] }, - ]), - ).run([ - "probe", - "--rename", - "Legacy:Archive", - "--confirm", - "mydb", - "--json", - ]); - - expect(errorOf(result)).toMatchObject({ - code: "CLI.CONSENT_REQUIRED", - summary: "What happens to User.nickname?", - why: "You have to choose what happens, and this run cannot ask you.\n--confirm mydb does not choose what happens; --delete does.", - }); - }); }); describe("a statement value that matches no question", () => { @@ -148,7 +126,7 @@ describe("a statement value that matches no question", () => { expect(errorOf(result)).toMatchObject({ code: "CLI.CONSENT_REQUIRED", - why: "What happens to Legacy?\nWhat happens to User.nickname?\n--delete Legcy does not name Legacy or User.nickname.", + why: "What happens to Legacy?\nWhat happens to User.nickname?\n--delete Legcy answers no question; the questions are about Legacy, User.nickname.", meta: { unmatched: [{ verb: "delete", values: ["Legcy"] }] }, }); }); diff --git a/packages/cli-engine/tests/statement-prompts.test.ts b/packages/cli-engine/tests/statement-prompts.test.ts index b675d0bf..3a4e0c9c 100644 --- a/packages/cli-engine/tests/statement-prompts.test.ts +++ b/packages/cli-engine/tests/statement-prompts.test.ts @@ -179,15 +179,16 @@ describe("a verb flag answers the statement", () => { }); describe("without a flag, a non-interactive run refuses", () => { - test("the refusal leads with the question and gives one flag form per verb", async () => { + test("the refusal names the subject and one flag form per verb", async () => { const result = await cliWith(askLegacy).run(["probe", "--json"]); expect(result.exitCode).toBe(2); expect(errorOf(result)).toEqual({ code: "CLI.CONSENT_REQUIRED", severity: "error", - summary: LEGACY_QUESTION, - why: "You have to choose what happens, and this run cannot ask you.", + summary: + "This command requires explicit consent, but it was not provided.", + why: LEGACY_QUESTION, nextActions: [ { kind: "user-choice", @@ -213,19 +214,16 @@ describe("without a flag, a non-interactive run refuses", () => { ); expect(result.exitCode).toBe(2); - expect(errorOf(result)).toMatchObject({ - summary: LEGACY_QUESTION, - why: "You have to choose what happens, and --yes does not choose for you.", - }); + expect(errorOf(result)?.summary).toBe( + "This command requires explicit consent, and --yes does not give it.", + ); }); test("the human refusal prints each flag form as a next action", async () => { const result = await cliWith(askLegacy).run(["probe", "--format", "human"]); expect(result.exitCode).toBe(2); - expect(result.stderr).toContain( - `[CLI.CONSENT_REQUIRED] ${LEGACY_QUESTION}`, - ); + expect(result.stderr).toContain("[CLI.CONSENT_REQUIRED]"); expect(result.stderr).toContain( "Run the command again with --rename 'Legacy:'", ); @@ -235,38 +233,6 @@ describe("without a flag, a non-interactive run refuses", () => { }); }); -describe("a refusal of one question with a flag that answers nothing", () => { - test("says which subject a statement flag does not name", async () => { - const result = await cliWith(askLegacy).run([ - "probe", - "--delete", - "Legcy", - "--json", - ]); - - expect(errorOf(result)).toMatchObject({ - code: "CLI.CONSENT_REQUIRED", - summary: LEGACY_QUESTION, - why: "You have to choose what happens, and this run cannot ask you.\n--delete Legcy does not name Legacy.", - }); - }); - - test("says which flags choose when --confirm was given", async () => { - const result = await cliWith(askLegacy).run([ - "probe", - "--confirm", - "mydb", - "--json", - ]); - - expect(errorOf(result)).toMatchObject({ - code: "CLI.CONSENT_REQUIRED", - summary: LEGACY_QUESTION, - why: "You have to choose what happens, and this run cannot ask you.\n--confirm mydb does not choose what happens; --rename or --delete does.", - }); - }); -}); - describe("an interactive run asks", () => { test("a bare verb answers with the subject", async () => { const result = await cliWith(askLegacy).run(["probe"], { @@ -346,8 +312,8 @@ describe("prompt.statements asks several questions together", () => { expect(result.exitCode).toBe(2); expect(errorOf(result)).toMatchObject({ code: "CLI.CONSENT_REQUIRED", - summary: USER_NAME_QUESTION, - why: "You have to choose what happens, and this run cannot ask you.", + summary: + "This command requires explicit consent, but it was not provided.", nextActions: [ { kind: "user-choice", @@ -364,19 +330,6 @@ describe("prompt.statements asks several questions together", () => { }); }); - test("--yes answers none of several questions", async () => { - const result = await cliWith(askBoth).run( - ["probe", "--yes", "--json"], - INTERACTIVE, - ); - - expect(errorOf(result)).toMatchObject({ - code: "CLI.CONSENT_REQUIRED", - summary: "2 choices are needed, and --yes does not choose for you.", - why: `${LEGACY_QUESTION}\n${USER_NAME_QUESTION}`, - }); - }); - test("one refusal lists every unanswered question", async () => { const result = await cliWith(askBoth).run(["probe", "--json"]); @@ -384,7 +337,8 @@ describe("prompt.statements asks several questions together", () => { expect(errorOf(result)).toEqual({ code: "CLI.CONSENT_REQUIRED", severity: "error", - summary: "2 choices are needed, and this run cannot ask you.", + summary: + "This command requires explicit consent, but it was not provided.", why: `${LEGACY_QUESTION}\n${USER_NAME_QUESTION}`, nextActions: [ { diff --git a/packages/cli/package.json b/packages/cli/package.json index 60ea193e..fc2cff5c 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -49,7 +49,7 @@ }, "dependencies": { "@manypkg/tools": "^2.1.2", - "@prisma/cli-engine": "workspace:0.10.1", + "@prisma/cli-engine": "workspace:0.10.2", "@prisma/composer-cli": "0.39.0", "@prisma/compute-sdk": "0.43.0", "@prisma/management-api-sdk": "1.80.0", diff --git a/packages/cli/scripts/conformance.ts b/packages/cli/scripts/conformance.ts index e440b15d..d6a5309a 100644 --- a/packages/cli/scripts/conformance.ts +++ b/packages/cli/scripts/conformance.ts @@ -113,20 +113,22 @@ async function tarball(): Promise { { familyPackage: "@prisma/composer-cli", familyPin: "0.10.0", - shellPin: "0.10.1", + shellPin: "0.10.2", channel: "dev", - reason: "engine 0.10.1 must publish before composer-cli can peer it", + reason: + "engine 0.10.2 changes the first line of the statement refusal; composer-cli still peers 0.10.0", removeWhen: - "composer-cli releases peering 0.10.1 and the follow-up bump PR pins that release", + "composer-cli releases peering 0.10.2 and the follow-up bump PR pins that release", }, { familyPackage: "@prisma/orm-toolchain", familyPin: "0.10.0", - shellPin: "0.10.1", + shellPin: "0.10.2", channel: "dev", - reason: "engine 0.10.1 must publish before orm-toolchain can peer it", + reason: + "engine 0.10.2 changes the first line of the statement refusal; orm-toolchain still peers 0.10.0", removeWhen: - "orm-toolchain releases peering 0.10.1 and the follow-up bump PR pins that release", + "orm-toolchain releases peering 0.10.2 and the follow-up bump PR pins that release", }, ], channel: CHANNEL, diff --git a/packages/prisma/package.json b/packages/prisma/package.json index 310c3f7e..0aef011b 100644 --- a/packages/prisma/package.json +++ b/packages/prisma/package.json @@ -50,7 +50,7 @@ }, "dependencies": { "@manypkg/tools": "^2.1.2", - "@prisma/cli-engine": "workspace:0.10.1", + "@prisma/cli-engine": "workspace:0.10.2", "@prisma/composer-cli": "0.39.0", "@prisma/compute-sdk": "0.43.0", "@prisma/management-api-sdk": "1.80.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 09631fdc..8785466c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,7 +27,7 @@ importers: specifier: ^2.1.2 version: 2.1.2 '@prisma/cli-engine': - specifier: workspace:0.10.1 + specifier: workspace:0.10.2 version: link:../cli-engine '@prisma/composer-cli': specifier: 0.39.0 @@ -210,7 +210,7 @@ importers: specifier: ^2.1.2 version: 2.1.2 '@prisma/cli-engine': - specifier: workspace:0.10.1 + specifier: workspace:0.10.2 version: link:../cli-engine '@prisma/composer-cli': specifier: 0.39.0