Skip to content

Commit f4b177f

Browse files
committed
fix(cli): os migrate list-preferences gates --apply before the boot and exits 1 without --yes off a terminal
The migrate family's confirmation pin: a run that did not give its confirmation applies nothing and exits 1, naming --yes. Claude-Session: https://claude.ai/code/session_01FEkQ5oY5WCqqqBMtn9qt7m Co-Authored-By: Claude <noreply@anthropic.com>
1 parent edcf4e1 commit f4b177f

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

‎content/docs/deployment/cli.mdx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2420,7 +2420,8 @@ its key starts with `ui.list.`, compared exactly, dot and case included:
24202420
- `--apply` — delete the listed rows (default off: a read-only dry run)
24212421
- `--export <path>` — **mandatory with `--apply`**: every row the run deletes, as stored, written
24222422
owner-only (`0600`) and read back before the first delete; refuses to overwrite an existing file
2423-
- `-y, --yes` — skip the confirmation prompt (required with `--json`)
2423+
- `-y, --yes` — skip the confirmation prompt; without it, a run whose stdin is not a terminal (or `--json`) reads
2424+
nothing, deletes nothing and exits `1`
24242425
- `--force` — apply even when another process is using the SQLite file
24252426
- `--database-url <url>`, `--json`
24262427

‎packages/cli/src/commands/migrate/list-preferences.ts‎

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,25 @@ export default class MigrateListPreferences extends Command {
152152
printWarning(`Could not check whether the database is in use — ${occupancy.detail}`);
153153
}
154154

155+
// The `os migrate` family's gate, before the boot: a run that did not give
156+
// its confirmation reads nothing, deletes nothing and exits 1, naming `--yes`;
157+
// an operator who declines at the prompt made a choice, and exits 0.
158+
if (apply && !flags.yes) {
159+
if (json) { await emitJson({ error: 'confirmation_required', hint: 'pass --yes' }, 1, { compact: true }); return; }
160+
if (!process.stdin.isTTY) {
161+
printWarning('Apply mode deletes rows. Re-run with --yes to confirm, or run without --apply to preview.');
162+
this.exit(1);
163+
return;
164+
}
165+
const ok = await confirm(chalk.bold(
166+
`\nDelete every sys_user_preference row keyed ui.list.* after writing the export to ${exportPath}? [y/N] `,
167+
));
168+
if (!ok) {
169+
printInfo('Aborted — nothing was read, written or deleted.');
170+
return;
171+
}
172+
}
173+
155174
if (!json) printStep(apply ? 'Booting (APPLY mode)…' : 'Booting (dry run)…');
156175

157176
// Loaded at the point of use, never at module load: oclif `import()`s every
@@ -223,14 +242,9 @@ export default class MigrateListPreferences extends Command {
223242
if (!json) {
224243
renderPlan(plan);
225244
printWarning(
226-
`About to permanently delete ${rows.length} ${LIST_PREFERENCE_OBJECT} row(s). The export below is the only copy that survives.`,
245+
`Deleting ${rows.length} ${LIST_PREFERENCE_OBJECT} row(s). The export below is the only copy that survives.`,
227246
);
228247
}
229-
if (!flags.yes) {
230-
if (json) { await emitJson({ error: 'confirmation_required', hint: 'pass --yes' }, 1, { compact: true }); return; }
231-
const ok = await confirm(chalk.yellow(` Delete ${rows.length} row(s) after writing the export? [y/N] `));
232-
if (!ok) { printInfo(`Aborted — no export was written and no row was deleted.${journalNote}`); return; }
233-
}
234248

235249
// ── The export, written and READ BACK before anything is deleted ──────
236250
const ids = rows.map((row) => String(row.id));

‎packages/cli/test/migrate-confirmation-exit.pin.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ const ROSTER: Record<string, Member> = {
262262
'comment-parent-pair': { argv: ['--apply'], confirm: '--yes', writes: BOOT },
263263
'comment-reactions': { argv: ['--apply'], confirm: '--yes', writes: BOOT },
264264
'files-to-references': { argv: ['--apply'], confirm: '--yes', writes: BOOT },
265+
// `--apply` deletes only with its pre-delete export named; the gate sits before the boot.
266+
'list-preferences': { argv: ['--apply', '--export', join(SCRATCH, 'list-preferences-export.json')], confirm: '--yes', writes: BOOT },
265267
// `--yes` belongs to the stored-row pass; without `--stored` the command converts source files.
266268
meta: { argv: ['--stored', '--apply'], confirm: '--yes', writes: BOOT },
267269
'multi-value-columns': { argv: ['--apply'], confirm: '--yes', writes: BOOT },

0 commit comments

Comments
 (0)