@akal/supaforge 0.0.0-stage → 0.0.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/README.md +350 -2
  2. package/bin/dev.js +10 -0
  3. package/bin/run.js +18 -0
  4. package/dist/base-command.d.ts +134 -0
  5. package/dist/base-command.js +9 -0
  6. package/dist/base-command.js.map +1 -0
  7. package/dist/branch-C4ndfoj5.d.ts +58 -0
  8. package/dist/chunk-4OU7KO5Y.js +13 -0
  9. package/dist/chunk-4OU7KO5Y.js.map +1 -0
  10. package/dist/chunk-5QQBTLWO.js +642 -0
  11. package/dist/chunk-5QQBTLWO.js.map +1 -0
  12. package/dist/chunk-5Z3SAIQS.js +2807 -0
  13. package/dist/chunk-5Z3SAIQS.js.map +1 -0
  14. package/dist/chunk-6WAMNZLO.js +336 -0
  15. package/dist/chunk-6WAMNZLO.js.map +1 -0
  16. package/dist/chunk-BHYLBKYD.js +156 -0
  17. package/dist/chunk-BHYLBKYD.js.map +1 -0
  18. package/dist/chunk-BLKJWDTL.js +153 -0
  19. package/dist/chunk-BLKJWDTL.js.map +1 -0
  20. package/dist/chunk-DQQ5E563.js +64 -0
  21. package/dist/chunk-DQQ5E563.js.map +1 -0
  22. package/dist/chunk-G2DIPIYU.js +94 -0
  23. package/dist/chunk-G2DIPIYU.js.map +1 -0
  24. package/dist/chunk-H5MJ5DFX.js +16 -0
  25. package/dist/chunk-H5MJ5DFX.js.map +1 -0
  26. package/dist/chunk-KIFJGON5.js +248 -0
  27. package/dist/chunk-KIFJGON5.js.map +1 -0
  28. package/dist/chunk-LQXF65MC.js +240 -0
  29. package/dist/chunk-LQXF65MC.js.map +1 -0
  30. package/dist/chunk-NXRSAVRU.js +478 -0
  31. package/dist/chunk-NXRSAVRU.js.map +1 -0
  32. package/dist/chunk-PARSNTBD.js +837 -0
  33. package/dist/chunk-PARSNTBD.js.map +1 -0
  34. package/dist/chunk-RRMI5CZD.js +376 -0
  35. package/dist/chunk-RRMI5CZD.js.map +1 -0
  36. package/dist/chunk-SF3YA42C.js +506 -0
  37. package/dist/chunk-SF3YA42C.js.map +1 -0
  38. package/dist/chunk-TQJSQLWA.js +574 -0
  39. package/dist/chunk-TQJSQLWA.js.map +1 -0
  40. package/dist/chunk-VMTBLHN2.js +122 -0
  41. package/dist/chunk-VMTBLHN2.js.map +1 -0
  42. package/dist/chunk-VOXZWQ3N.js +948 -0
  43. package/dist/chunk-VOXZWQ3N.js.map +1 -0
  44. package/dist/chunk-X6V2GGDZ.js +333 -0
  45. package/dist/chunk-X6V2GGDZ.js.map +1 -0
  46. package/dist/chunk-XMYMIURR.js +552 -0
  47. package/dist/chunk-XMYMIURR.js.map +1 -0
  48. package/dist/chunk-YVDSR4GM.js +1264 -0
  49. package/dist/chunk-YVDSR4GM.js.map +1 -0
  50. package/dist/commands/clone.d.ts +66 -0
  51. package/dist/commands/clone.js +416 -0
  52. package/dist/commands/clone.js.map +1 -0
  53. package/dist/commands/diff.d.ts +65 -0
  54. package/dist/commands/diff.js +24 -0
  55. package/dist/commands/diff.js.map +1 -0
  56. package/dist/commands/help.d.ts +32 -0
  57. package/dist/commands/help.js +36 -0
  58. package/dist/commands/help.js.map +1 -0
  59. package/dist/commands/hukam.d.ts +13 -0
  60. package/dist/commands/hukam.js +29 -0
  61. package/dist/commands/hukam.js.map +1 -0
  62. package/dist/commands/init.d.ts +47 -0
  63. package/dist/commands/init.js +388 -0
  64. package/dist/commands/init.js.map +1 -0
  65. package/dist/commands/mcp.d.ts +13 -0
  66. package/dist/commands/mcp.js +44 -0
  67. package/dist/commands/mcp.js.map +1 -0
  68. package/dist/commands/migrate/baseline.d.ts +24 -0
  69. package/dist/commands/migrate/baseline.js +69 -0
  70. package/dist/commands/migrate/baseline.js.map +1 -0
  71. package/dist/commands/migrate/create.d.ts +36 -0
  72. package/dist/commands/migrate/create.js +128 -0
  73. package/dist/commands/migrate/create.js.map +1 -0
  74. package/dist/commands/migrate/list.d.ts +23 -0
  75. package/dist/commands/migrate/list.js +110 -0
  76. package/dist/commands/migrate/list.js.map +1 -0
  77. package/dist/commands/migrate/run.d.ts +61 -0
  78. package/dist/commands/migrate/run.js +19 -0
  79. package/dist/commands/migrate/run.js.map +1 -0
  80. package/dist/commands/report.d.ts +27 -0
  81. package/dist/commands/report.js +210 -0
  82. package/dist/commands/report.js.map +1 -0
  83. package/dist/commands/restore.d.ts +26 -0
  84. package/dist/commands/restore.js +268 -0
  85. package/dist/commands/restore.js.map +1 -0
  86. package/dist/commands/snapshot.d.ts +33 -0
  87. package/dist/commands/snapshot.js +251 -0
  88. package/dist/commands/snapshot.js.map +1 -0
  89. package/dist/commands/sync.d.ts +16 -0
  90. package/dist/commands/sync.js +39 -0
  91. package/dist/commands/sync.js.map +1 -0
  92. package/dist/config-CTbeRlJk.d.ts +134 -0
  93. package/dist/help.d.ts +28 -0
  94. package/dist/help.js +64 -0
  95. package/dist/help.js.map +1 -0
  96. package/dist/index.d.ts +493 -0
  97. package/dist/index.js +147 -0
  98. package/dist/index.js.map +1 -0
  99. package/package.json +74 -4
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/commands/diff.ts","../src/ci.ts"],"sourcesContent":["import { Flags } from '@oclif/core'\nimport { BaseCommand } from '../base-command.js'\nimport { createDefaultRegistry } from '../checks/index.js'\nimport { scan } from '../scanner.js'\nimport type { ScanProgressEvent } from '../scanner.js'\nimport { renderSummary, renderDetailed, formatSkips } from '../render.js'\nimport { promote, planWork, type PromoteResult } from '../promote.js'\nimport type { CheckName, ScanResult } from '../types/drift.js'\nimport { CHECK_NAMES, CHECK_META } from '../types/drift.js'\nimport { ok, warn, dim, cmd, bold } from '../ui.js'\nimport { sanitizeForReport } from '../utils/sanitize.js'\nimport { renderTip } from '../tips.js'\nimport { formatGitHubAnnotations, computeCiExitCode, formatCiSummary, type FailOn } from '../ci.js'\nimport { resolveTableFilter, isFiltered, describeTableFilter } from '../utils/table-filter.js'\nimport { parseFlagList } from '../utils/strings.js'\nimport { isCloneDatabase, sourceLooksLikeCloneOf } from '../branch.js'\nimport { proveConvergence, residualHeldBack, proofScope, comparedSchemas } from '../prove.js'\nimport { summarizeByKind } from '../scoring.js'\nimport { CLONE_SKIP_FLAGS, DEFAULT_IGNORE_SCHEMAS, schemaDiffIgnores } from '../defaults.js'\n\n/**\n * Glyph and text for a finished check, so the three outcomes are visually\n * distinct in the live progress list.\n */\nfunction describeCheckOutcome(\n status: 'clean' | 'drifted' | 'error' | 'skipped',\n issueCount: number,\n skipReason?: string,\n): { glyph: string; text: string } {\n if (status === 'error') return { glyph: warn('✗'), text: warn('error') }\n if (status === 'skipped') {\n return { glyph: dim('○'), text: dim(`skipped — ${skipReason ?? 'no reason given'}`) }\n }\n return { glyph: ok('✓'), text: `${issueCount} issues` }\n}\n\n/**\n * Flags that only mean something when fixes are being planned or executed.\n *\n * Passed on their own they used to be inert *and silent* — the run printed\n * byte-identical output to one with no flag at all. Worst for the two that read\n * as safety measures: someone reaching for `--prove` or `--dry-run` alone, the\n * natural instinct for \"don't actually do it\", got an ordinary diff and no sign\n * they had neither previewed nor proved anything (issue #71).\n *\n * `--dry-run` is deliberately absent: it now selects the planning path by\n * itself, so previewing never requires typing the flag that writes. Flags that\n * shape the *plan* rather than the execution are honoured under `--dry-run`, so\n * they are only inert when neither flag is present.\n */\nconst APPLY_ONLY_FLAGS: ReadonlyArray<{ flag: string; shapesThePlan: boolean }> = [\n { flag: 'prove', shapesThePlan: false },\n { flag: 'no-transaction', shapesThePlan: false },\n { flag: 'only', shapesThePlan: true },\n { flag: 'apply-posture', shapesThePlan: true },\n { flag: 'allow-destructive', shapesThePlan: true },\n]\n\n/** Which apply-only flags this invocation will silently ignore. */\nexport function inertApplyFlags(\n flags: Record<string, unknown>,\n): ReadonlyArray<{ flag: string; shapesThePlan: boolean }> {\n if (flags['apply']) return []\n const dryRun = Boolean(flags['dry-run'])\n\n return APPLY_ONLY_FLAGS.filter(({ flag, shapesThePlan }) => {\n const given = flags[flag]\n const passed = Array.isArray(given) ? given.length > 0 : Boolean(given)\n if (!passed) return false\n return !(dryRun && shapesThePlan)\n })\n}\n\n/**\n * Unified drift detection & resolution command.\n *\n * Default: summary of what's drifted (was: scan)\n * --detail: full SQL diffs (was: diff)\n * --apply: fix the drift (was: promote)\n * --ci: emit GitHub Actions annotations + structured exit codes\n */\nexport default class Diff extends BaseCommand {\n static override description = 'Detect drift between Supabase environments and optionally fix it'\n\n static override examples = [\n '<%= config.bin %> diff',\n '<%= config.bin %> diff --detail',\n '<%= config.bin %> diff --apply',\n '<%= config.bin %> diff --check=rls',\n '<%= config.bin %> diff --check=rls --apply',\n '<%= config.bin %> diff --source=staging --target=production',\n '<%= config.bin %> diff --skip=storage --skip=vault',\n '<%= config.bin %> diff --tables=orders,order_items',\n \"<%= config.bin %> diff --tables='billing_*' --exclude-tables='*_audit'\",\n '<%= config.bin %> diff --tables=orders --detail',\n // Built from the same constant the tips and the post-clone output use, so\n // the advice cannot fall behind the check list again: this example predated\n // Layer 14 and omitted `roles`, which on a real clone → remote diff is 227\n // of the findings someone following it was left to puzzle over (issue #70).\n `<%= config.bin %> diff ${CLONE_SKIP_FLAGS}`,\n '<%= config.bin %> diff --ci',\n '<%= config.bin %> diff --ci --fail-on=warning',\n ]\n\n /**\n * Read from the environment rather than passed as flags, because they tune\n * limits rather than select behaviour. Rendered as their own `--help`\n * section (issue #40); the README carries the same table plus the timeout\n * precedence chain.\n */\n static envVars = [\n { name: 'SUPAFORGE_CONNECT_TIMEOUT', description: 'Seconds before a database connection attempt is abandoned (default 15).' },\n { name: 'SUPAFORGE_DBDIFF_TIMEOUT', description: 'Seconds before the schema/data diff is abandoned. Overrides checks.schema.timeout (default 600).' },\n { name: 'SUPAFORGE_DBDIFF_MEMORY', description: \"PHP memory limit for @dbdiff/cli — 512M, 2G, or -1 for unlimited (default dbdiff's own 1G).\" },\n ]\n\n static override flags = {\n check: Flags.string({\n char: 'l',\n description: 'Limit to a specific check',\n options: [...CHECK_NAMES],\n }),\n skip: Flags.string({\n char: 'x',\n description: 'Skip a specific check (repeatable). Also configurable via checks.exclude in supaforge.config.json.',\n options: [...CHECK_NAMES],\n multiple: true,\n }),\n detail: Flags.boolean({\n description: 'Show detailed SQL diffs (default: summary)',\n default: false,\n }),\n apply: Flags.boolean({\n description: 'Apply SQL fixes to resolve drift in the target environment',\n default: false,\n }),\n 'allow-destructive': Flags.boolean({\n description: 'With --apply, also run fixes that drop tables or columns (destroys data)',\n default: false,\n }),\n 'dry-run': Flags.boolean({\n description: 'With --apply, print the fixes in the order they would run without executing any of them',\n default: false,\n }),\n 'no-transaction': Flags.boolean({\n description: 'With --apply, run each fix on its own instead of rolling the whole set back on the first failure',\n aliases: ['continue-on-error'],\n default: false,\n }),\n only: Flags.string({\n description: 'With --apply, only apply these issue ids (repeatable, comma-separated, globs allowed). Ids come from --json.',\n multiple: true,\n }),\n 'include-files': Flags.boolean({\n description: 'Include file-level drift detection in storage check',\n default: false,\n }),\n tables: Flags.string({\n description: 'Only compare these tables in the schema and data checks (repeatable, comma-separated, globs allowed). Overrides checks.tables.',\n multiple: true,\n }),\n 'exclude-tables': Flags.string({\n description: 'Never compare these tables (repeatable, comma-separated, globs allowed). Merged with checks.excludeTables.',\n multiple: true,\n }),\n json: Flags.boolean({ description: 'Output results as JSON' }),\n source: Flags.string({ char: 's', description: 'Source environment name' }),\n target: Flags.string({ char: 't', description: 'Target environment name' }),\n ci: Flags.boolean({\n description: 'CI mode: emit GitHub Actions annotations and use semantic exit codes (0=clean, 1=drift, 2=error)',\n default: false,\n }),\n prove: Flags.boolean({\n description:\n 'Before applying, replay the migration on a throwaway clone of the target '\n + 'and verify it reproduces the source exactly. Refuses to apply if it does not.',\n default: false,\n }),\n 'apply-posture': Flags.boolean({\n description:\n 'With --apply, also apply fixes from checks that judge the target on its own '\n + '(RLS coverage, migration history). Off by default: those fixes move the target '\n + 'away from the source and so create drift.',\n default: false,\n }),\n 'fail-on': Flags.string({\n description: 'Threshold for a non-zero exit in CI mode',\n options: ['critical', 'warning', 'any'],\n default: 'critical',\n }),\n 'fail-on-posture': Flags.boolean({\n description:\n 'Let findings from the target-only checks (RLS coverage, migration history) '\n + 'affect the exit code too. Off by default: they fire identically whichever '\n + 'pair you diff, so they cannot indicate that the environments have diverged.',\n default: false,\n }),\n }\n\n /**\n * Report what `--apply` did, or — under `--dry-run` — what it would do.\n *\n * The applied list is printed in execution order, which is now dependency\n * order rather than the order the checks reported the issues. That ordering\n * is the whole point of the dry run: it is what makes the outcome of a real\n * apply predictable before running it (issue #48).\n */\n private renderApplyResult(result: PromoteResult, dryRun: boolean): void {\n const verb = dryRun ? 'Would apply' : 'Applied'\n if (result.applied.length > 0) {\n const heading = `${verb} ${result.applied.length} fix(es)${dryRun ? ', in this order' : ''}:`\n this.log(dryRun ? bold(heading) : ok(heading))\n result.applied.forEach((stmt, i) => {\n const glyph = dryRun ? dim(`${i + 1}.`) : ok('✓')\n this.log(` ${glyph} ${dim(`[${stmt.check}]`)} ${stmt.issueId}`)\n // The SQL itself only in a dry run: it is the thing being reviewed,\n // and printing it after the fact would just repeat --detail.\n if (dryRun && stmt.sql) this.log(` ${dim(stmt.sql.replace(/\\s*\\n\\s*/g, ' '))}`)\n if (dryRun && stmt.action) this.log(` ${dim(stmt.action)}`)\n })\n }\n\n if (result.skipped.length > 0) {\n this.log(`\\n${dim(`Skipped ${result.skipped.length} issue(s):`)}`)\n // Collapsed where several share a reason: a posture check on a project\n // with 47 tables lacking RLS printed the same sentence 47 times, and\n // pushed the result of the apply off the top of the screen (issue #84).\n for (const line of formatSkips(result.skipped)) this.log(` ${dim(line)}`)\n }\n\n // Printed before the errors: the first thing to know about a failed apply\n // is whether anything landed, and the answer here is that nothing did.\n if (result.rolledBack?.length) {\n this.log(`\\n${warn(`Rolled back ${result.rolledBack.length} fix(es)`)} — the target is unchanged:`)\n for (const item of result.rolledBack) {\n this.log(` ${dim('↩')} ${dim(`[${item.check}]`)} ${item.issueId}`)\n }\n }\n\n if (result.errors.length > 0) {\n this.log(`\\n${warn(`${result.errors.length} error(s):`)}`)\n for (const item of result.errors) {\n this.log(` ${warn('✗')} ${dim(`[${item.check}]`)} ${item.issueId}: ${item.error}`)\n }\n if (result.rolledBack) {\n this.log(`\\n ${dim(`Nothing was written. Re-run with ${cmd('--no-transaction')} to apply the fixes that do work.`)}`)\n }\n }\n\n if (dryRun) {\n this.log(`\\n ${dim(`Nothing was executed. Drop ${cmd('--dry-run')} to apply.`)}`)\n }\n }\n\n async run(): Promise<void> {\n const { flags } = await this.parse(Diff)\n\n // On stderr, so a --json or --ci consumer still gets clean stdout while a\n // human is told the flag did nothing.\n for (const { flag, shapesThePlan } of inertApplyFlags(flags as unknown as Record<string, unknown>)) {\n const suggestion = shapesThePlan\n ? `Add ${cmd('--apply')} (or ${cmd('--dry-run')} to preview) for it to take effect.`\n : `Add ${cmd('--apply')} for it to take effect.`\n process.stderr.write(` ${warn(`--${flag} has no effect without --apply.`)} ${suggestion}\\n`)\n }\n\n const config = await this.loadConfigOrFail()\n this.validateDualEnvConfig(config, flags.source, flags.target)\n\n const registry = createDefaultRegistry({ includeFiles: flags['include-files'] })\n const checks = flags.check ? [flags.check as CheckName] : undefined\n const skip = flags.skip?.length ? (flags.skip as CheckName[]) : undefined\n\n const tableFilter = resolveTableFilter(config, {\n tables: flags.tables,\n excludeTables: flags['exclude-tables'],\n })\n\n // Stated up front: a narrowed run must not look like a full one, and with\n // --apply the difference is which statements actually execute (issue #43).\n if (isFiltered(tableFilter) && !flags.json && !flags.ci) {\n this.log(`\\n ${dim(describeTableFilter(tableFilter)!)}`)\n }\n\n // ── Preflight: verify both databases are reachable ────────────────────────\n if (!flags.json && !flags.ci) {\n const sourceEnv = config.environments[config.source!]\n const targetEnv = config.environments[config.target!]\n const pre = this.createPreflight('Diff preflight checks')\n .addDatabase('Source', config.source!, sourceEnv.dbUrl)\n .addDatabase('Target', config.target!, targetEnv.dbUrl)\n await this.runPreflight(pre, 'Diff')\n }\n\n /** Build a progress callback for scan calls. Only active when not --json or --ci. */\n const makeProgress = (): ((event: ScanProgressEvent) => void) | undefined => {\n if (flags.json || flags.ci) return undefined\n process.stdout.write('\\n Scanning...\\n')\n return (event: ScanProgressEvent) => {\n const meta = CHECK_META[event.check]\n const label = meta?.label ?? event.check\n const idx = `[${event.index + 1}/${event.total}]`\n if (event.phase === 'check:start') {\n process.stdout.write(` ▶ ${idx} ${label}...\\n`)\n } else {\n // Clear any in-place detail line before the final result line.\n if (process.stdout.isTTY) process.stdout.write('\\r\\u001b[2K')\n const dur = `${(event.durationMs / 1000).toFixed(1)}s`\n // A skipped layer gets its own glyph and its reason. A green tick\n // beside \"0 issues\" was indistinguishable from a comparison that\n // passed (issue #42).\n const { glyph, text } = describeCheckOutcome(event.status, event.issueCount, event.skipReason)\n process.stdout.write(` ${glyph} ${idx} ${label.padEnd(24)} ${text} (${dur})\\n`)\n }\n }\n }\n\n /**\n * Render fine-grained progress from within a check, in place.\n *\n * A ~100s schema diff on one static spinner line reads as a hang\n * (issue #29). Only used on a TTY — piped or CI output would otherwise\n * accumulate thousands of partial lines.\n */\n const makeDetail = (): ((check: CheckName, detail: string) => void) | undefined => {\n if (flags.json || flags.ci || !process.stdout.isTTY) return undefined\n return (_check, detail) => {\n process.stdout.write(`\\r\\u001b[2K ${dim(detail)}`)\n }\n }\n\n // ── Apply mode (was: promote) ───────────────────────────────────────────────\n // `--dry-run` enters here without `--apply`: it plans, prints the execution\n // order, and writes nothing. Previewing an apply should not require typing\n // the flag that performs one (issue #71).\n if (flags.apply || flags['dry-run']) {\n const onProgress = makeProgress()\n const scanResult = await scan(registry, { config, checks, skip, tableFilter, onProgress, onDetail: makeDetail() })\n this.setCheckSummaries(scanResult.checks.map(c => ({\n check: c.check,\n status: c.status,\n issueCount: c.issues.length,\n durationMs: c.durationMs,\n ...(c.error ? { error: sanitizeForReport(c.error) } : {}),\n })))\n\n if (scanResult.summary.total === 0) {\n // --json promises JSON on stdout whatever the outcome. This branch used\n // to print the sentence below instead, so a script reading the result\n // of an apply failed on the one run where there was nothing to do.\n if (flags.json) {\n const empty: PromoteResult = { applied: [], skipped: [], errors: [] }\n this.json(empty)\n return\n }\n this.log(`${ok('No drift detected.')} Nothing to apply. ✓`)\n this.log(renderTip({ command: 'diff', apply: true, driftTotal: 0 }))\n return\n }\n\n const targetEnv = config.environments[config.target!]\n const dryRun = flags['dry-run']\n\n // Prove before touching the target. A migration that executes without\n // error can still leave the database in a state that is not the source —\n // a flattened partition or an index that never reached its partitions\n // both apply cleanly. Only replaying it and looking at the result catches\n // that, so when --prove is set a failure blocks the apply rather than\n // warning after the fact.\n if (flags.prove && !dryRun) {\n const sourceEnv = config.environments[config.source!]\n const planned = planWork(scanResult, {\n checks, only: parseFlagList(flags.only),\n allowDestructive: flags['allow-destructive'], tableFilter,\n applyPosture: flags['apply-posture'],\n })\n const { replay, unproved } = proofScope(planned.sqlStatements)\n const migrationSql = replay.map(s => s.sql).join('\\n')\n\n this.log(`\\n ${dim('Proving convergence on a throwaway clone…')}`)\n if (unproved.length > 0) {\n // Applied all the same; the proof just cannot speak for them.\n const byCheck = [...new Set(unproved.map(s => s.check))]\n .map(c => `${c} ×${unproved.filter(s => s.check === c).length}`).join(', ')\n this.log(` ${dim(`Not proved — act outside the proved schemas or on the whole server: ${byCheck}`)}`)\n }\n // Nothing left to replay means nothing to prove. Running it anyway\n // compared the whole schema, and refused a cron-only apply over\n // tables it was never going to touch.\n const proof = replay.length === 0\n ? { converged: false, residual: [], cloneName: '', skipped: 'none of the planned fixes is one the proof can replay' }\n : await proveConvergence({\n sourceUrl: sourceEnv.dbUrl,\n targetUrl: targetEnv.dbUrl,\n migrationSql,\n // Every schema the schema diff compares, not `public` alone: a\n // migration dropping a schema the source lacks runs against it.\n schemas: await comparedSchemas(sourceEnv.dbUrl, targetEnv.dbUrl,\n schemaDiffIgnores(config.ignoreSchemas ?? DEFAULT_IGNORE_SCHEMAS)),\n // The checks this run compares: without the schema check, what the\n // target already lacks elsewhere is not this migration's to fix.\n checks: scanResult.checks.map(c => c.check),\n })\n\n if (proof.skipped) {\n // Could not prove is not the same as failed to converge; say which.\n this.log(` ${warn('Convergence not proven')}: ${proof.skipped}`)\n this.log(` ${dim('Continuing — re-run without --prove to silence this.')}\\n`)\n } else if (!proof.converged && residualHeldBack(proof.residual, heldBackSql(scanResult, planned)).unexplained.length === 0) {\n // Everything left over is what this run deliberately holds back.\n this.log(` ${ok('Converged')}, apart from what is held back and stays on the target:`)\n for (const line of proof.residual.slice(0, 15)) this.log(` ${dim(line)}`)\n this.log('')\n } else if (!proof.converged) {\n this.log(` ${warn('Migration does not reproduce the source.')} Nothing was applied.\\n`)\n const { unexplained } = residualHeldBack(proof.residual, heldBackSql(scanResult, planned))\n for (const line of unexplained.slice(0, 15)) this.log(` ${line}`)\n if (unexplained.length > 15) {\n this.log(` ${dim(`…and ${unexplained.length - 15} more`)}`)\n }\n this.log(`\\n ${dim('These objects would still differ after applying.')}`)\n this.exit(1)\n } else {\n if (proof.outOfScope?.length) {\n this.log(` ${ok('Converged')} on what this run compares. Outside it, and already different before:`)\n for (const line of proof.outOfScope.slice(0, 15)) this.log(` ${dim(line)}`)\n if (proof.outOfScope.length > 15) this.log(` ${dim(`…and ${proof.outOfScope.length - 15} more`)}`)\n this.log('')\n } else {\n this.log(` ${ok('Converged')} — the migration reproduces the source exactly.\\n`)\n }\n }\n }\n\n const result = await promote({\n dbUrl: targetEnv.dbUrl,\n scanResult,\n checks,\n dryRun,\n allowDestructive: flags['allow-destructive'],\n tableFilter,\n only: parseFlagList(flags.only),\n applyPosture: flags['apply-posture'],\n transactional: !flags['no-transaction'],\n })\n\n if (flags.json) {\n this.json(result)\n return\n }\n\n this.renderApplyResult(result, dryRun)\n\n if (result.errors.length > 0) {\n this.exit(1)\n }\n\n this.log(renderTip({\n command: 'diff',\n apply: true,\n driftTotal: scanResult.summary.total,\n driftedChecks: scanResult.checks.filter(c => c.status === 'drifted').map(c => c.check),\n }))\n return\n }\n\n // ── Scan mode (summary, detail, CI, or JSON) ────────────────────────────\n const onProgress = makeProgress()\n const result = await scan(registry, { config, checks, skip, tableFilter, onProgress, onDetail: makeDetail() })\n this.setCheckSummaries(result.checks.map(c => ({\n check: c.check,\n status: c.status,\n issueCount: c.issues.length,\n durationMs: c.durationMs,\n ...(c.error ? { error: sanitizeForReport(c.error) } : {}),\n })))\n\n // Whether the source is a local clone changes what `--apply` means, and so\n // changes what the closing tip should say about it (issue #48).\n //\n // Two signals, because the bookkeeping one is local and exact: a clone\n // diffed from another directory, or renamed, answered \"not a clone\" and got\n // the unqualified \"add --apply\" advice in the most destructive direction\n // (issue #71). The second signal asks the databases whether the source is\n // missing the Supabase substrate the target has, which is the property that\n // makes the advice wrong.\n const sourceUrl = config.environments[config.source!]?.dbUrl\n const sourceIsClone = await isCloneDatabase(sourceUrl)\n || await sourceLooksLikeCloneOf(sourceUrl, config.environments[config.target!]?.dbUrl)\n\n const driftedChecks = result.checks.filter(c => c.status === 'drifted').map(c => c.check)\n const skippedChecks = result.checks.filter(c => c.status === 'skipped').map(c => c.check)\n // A check that errored measured nothing — surfaced so the summary and tips\n // never present an unmeasured scan as a clean one (issue #29).\n const erroredChecks = result.checks.filter(c => c.status === 'error').map(c => c.check)\n\n // ── CI mode ──────────────────────────────────────────────────────────────\n if (flags.ci) {\n const failOn = (flags['fail-on'] ?? 'critical') as FailOn\n // Annotations go to stderr; the machine-readable summary is the *only*\n // thing on stdout. This lets a workflow capture a clean JSON artifact\n // (`supaforge diff --ci > report.json`) while GitHub Actions still renders\n // the `::error`/`::warning` workflow commands from stderr.\n const annotations = formatGitHubAnnotations(result)\n for (const line of annotations) {\n process.stderr.write(line + '\\n')\n }\n const summary = formatCiSummary(result)\n process.stdout.write(JSON.stringify(summary, null, 2) + '\\n')\n const exitCode = computeCiExitCode(result, failOn, {\n failOnPosture: flags['fail-on-posture'],\n })\n if (exitCode !== 0) {\n this.exit(exitCode)\n }\n return\n }\n\n if (flags.json) {\n this.json(result)\n } else if (flags.detail) {\n this.log(renderDetailed(result))\n this.log(renderTip({\n command: 'diff',\n detail: true,\n driftTotal: result.summary.total,\n driftedChecks,\n skippedChecks,\n erroredChecks,\n singleCheck: checks?.[0],\n sourceIsClone,\n }))\n } else {\n this.log(renderSummary(result))\n\n if (result.summary.total > 0) {\n this.log(` → Run with ${cmd('--detail')} to see SQL diffs`)\n // Direction matters here, not just in the tip below. From a clone this\n // line was recommending the command that reshapes a shared remote to\n // match a vanilla-PostgreSQL copy — dropping the roles, grants and\n // policies the clone never had (issue #71).\n this.log(\n sourceIsClone\n ? ` → ${cmd('--apply')} would push this clone's shape onto the target, `\n + `absences included — preview it first with ${cmd('--apply --dry-run')}\\n`\n : ` → Run with ${cmd('--apply')} to fix drift\\n`,\n )\n }\n\n this.log(renderTip({\n command: 'diff',\n detail: false,\n driftTotal: result.summary.total,\n driftedChecks,\n skippedChecks,\n erroredChecks,\n singleCheck: checks?.[0],\n sourceIsClone,\n }))\n }\n\n // Exit code deliberately unchanged for an errored check: `--ci` is the\n // documented contract for scripting and already exits 2 in that case\n // (0=clean, 1=drift, 2=error). Making plain `diff` exit non-zero here\n // would break every non-CI caller for a signal that already has a\n // supported home. The misleading *output* is fixed above instead.\n //\n // Only drift decides the code. A critical posture finding — RLS disabled on\n // a table, a migration file with no tracking row — is true of the target\n // whichever pair you diff, so letting it exit 1 meant a perfectly\n // synchronised pair failed a sync check forever (issue #66).\n const { drift, posture } = summarizeByKind(result.checks)\n\n // Said once, where it changes what the reader should conclude: the report\n // above shows critical findings and the command is about to succeed.\n if (drift.critical === 0 && posture.critical > 0 && !flags.json) {\n this.log(\n ` ${dim('Posture findings do not affect the exit code — they describe the target, '\n + 'not drift from the source. Add')} ${cmd('--fail-on-posture')} ${dim('to gate on them.')}\\n`,\n )\n }\n\n if (drift.critical > 0 || (flags['fail-on-posture'] && posture.critical > 0)) {\n this.exit(1)\n }\n }\n}\n\n/** The SQL of the fixes this run plans to skip, which the proof did not replay. */\nfunction heldBackSql(scanResult: ScanResult, planned: { skipped: Array<{ issueId: string }> }): string[] {\n const skipped = new Set(planned.skipped.map(s => s.issueId))\n return scanResult.checks.flatMap(c => c.issues)\n .filter(i => skipped.has(i.id) && i.sql?.up)\n .map(i => i.sql!.up)\n}\n\n","import type { ScanResult, DriftIssue } from './types/drift.js'\nimport { coverage } from './render.js'\nimport { summarizeByKind } from './scoring.js'\n\nexport type FailOn = 'critical' | 'warning' | 'any'\n\n/**\n * Escape a workflow-command *message* (the text after `::`).\n *\n * GitHub Actions uses percent-encoding, not backslash escaping. `%` must be\n * encoded first so the percent signs introduced by the other replacements are\n * not double-encoded. Mirrors `@actions/core`'s `escapeData`.\n */\nfunction escapeData(value: string): string {\n return value\n .replace(/%/g, '%25')\n .replace(/\\r/g, '%0D')\n .replace(/\\n/g, '%0A')\n}\n\n/**\n * Escape a workflow-command *property* value (e.g. `title=`). In addition to\n * the message escapes, `:` and `,` must be encoded because they delimit\n * properties. Mirrors `@actions/core`'s `escapeProperty`.\n */\nfunction escapeProperty(value: string): string {\n return escapeData(value)\n .replace(/:/g, '%3A')\n .replace(/,/g, '%2C')\n}\n\n/**\n * Format a DriftIssue as a GitHub Actions annotation line.\n * Spec: https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#setting-a-notice-message\n */\nexport function formatAnnotation(issue: DriftIssue): string {\n const level = issue.severity === 'critical' ? 'error' : 'warning'\n const title = escapeProperty(issue.title)\n const message = escapeData(issue.description)\n return `::${level} title=${title}::${message}`\n}\n\n/** Emit all drift issues as GitHub Actions annotation lines. */\nexport function formatGitHubAnnotations(result: ScanResult): string[] {\n const lines: string[] = []\n for (const check of result.checks) {\n for (const issue of check.issues) {\n lines.push(formatAnnotation(issue))\n }\n }\n return lines\n}\n\n/** Does this set of counts cross the threshold? */\nfunction exceeds(counts: { critical: number; warning: number; total: number }, failOn: FailOn): boolean {\n if (failOn === 'critical') return counts.critical > 0\n if (failOn === 'warning') return counts.critical > 0 || counts.warning > 0\n return counts.total > 0\n}\n\n/**\n * Determine the exit code for CI.\n *\n * 0 = no drift above threshold\n * 1 = drift exceeds threshold\n * 2 = scan error (connection failure, etc.)\n *\n * Only the comparison checks count. RLS Coverage and Migration History judge\n * the target on its own and fire identically whichever pair you diff, so\n * including them made the exit code unable to distinguish \"the environments\n * have diverged\" from \"the target has a pre-existing gap\" — a sync check failed\n * permanently against an identical target (issue #66). `--fail-on` is a\n * *severity* threshold and could not express the difference, because the\n * difference is one of scope.\n *\n * Pass `failOnPosture` to gate on those findings too. They are never silenced:\n * they keep their severity, appear in the report and the annotations, and are\n * scored as `postureScore`.\n */\nexport function computeCiExitCode(\n result: ScanResult, failOn: FailOn = 'critical', opts: { failOnPosture?: boolean } = {},\n): number {\n const hasError = result.checks.some(c => c.status === 'error')\n if (hasError) return 2\n\n const { drift, posture } = summarizeByKind(result.checks)\n if (exceeds(drift, failOn)) return 1\n if (opts.failOnPosture && exceeds(posture, failOn)) return 1\n\n return 0\n}\n\n/**\n * Produce a structured CI summary object for GitHub Actions step summaries\n * or artifact upload.\n */\nexport function formatCiSummary(result: ScanResult): {\n timestamp: string\n /** Drift between the two environments, over the comparison checks only. */\n score: number\n /**\n * The target's own security and tracking posture, over the non-comparative\n * checks. Reported separately so a pre-existing RLS gap cannot mask, or be\n * mistaken for, environments having diverged (issue #40).\n */\n postureScore: number | null\n summary: ScanResult['summary']\n /**\n * Checks that failed to run. Empty on a healthy scan.\n *\n * Without this a reader of the uploaded artifact saw only a clean summary\n * and had no way to tell that a check never ran — the exit code carried\n * that signal, but the artifact did not (issue #29).\n */\n errors: Array<{ check: string; message: string }>\n /**\n * Checks that declined to run, with the reason.\n *\n * A skipped check is not a failure, so it does not belong in `errors` — but\n * omitting it entirely left a CI artifact that read as full coverage when\n * three layers had never opened a connection (issue #42).\n */\n skipped: Array<{ check: string; reason: string }>\n /** How many checks compared the two environments, over how many were attempted. */\n coverage: { compared: number; total: number }\n criticalIssues: Array<{ check: string; id: string; title: string }>\n warningIssues: Array<{ check: string; id: string; title: string }>\n} {\n const criticalIssues: Array<{ check: string; id: string; title: string }> = []\n const warningIssues: Array<{ check: string; id: string; title: string }> = []\n const errors: Array<{ check: string; message: string }> = []\n const skipped: Array<{ check: string; reason: string }> = []\n\n for (const check of result.checks ?? []) {\n if (check?.status === 'error') {\n errors.push({ check: check.check, message: check.error ?? 'Check failed with no error message' })\n }\n if (check?.status === 'skipped') {\n skipped.push({ check: check.check, reason: check.skipReason ?? 'no reason given' })\n }\n for (const issue of check?.issues ?? []) {\n const entry = { check: check.check, id: issue.id, title: issue.title }\n if (issue.severity === 'critical') {\n criticalIssues.push(entry)\n } else if (issue.severity === 'warning') {\n warningIssues.push(entry)\n }\n }\n }\n\n return {\n timestamp: result.timestamp,\n score: result.score,\n postureScore: result.postureScore ?? null,\n summary: result.summary,\n errors,\n skipped,\n coverage: coverage(result),\n criticalIssues,\n warningIssues,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;;;ACatB,SAAS,WAAW,OAAuB;AACzC,SAAO,MACJ,QAAQ,MAAM,KAAK,EACnB,QAAQ,OAAO,KAAK,EACpB,QAAQ,OAAO,KAAK;AACzB;AAOA,SAAS,eAAe,OAAuB;AAC7C,SAAO,WAAW,KAAK,EACpB,QAAQ,MAAM,KAAK,EACnB,QAAQ,MAAM,KAAK;AACxB;AAMO,SAAS,iBAAiB,OAA2B;AAC1D,QAAM,QAAU,MAAM,aAAa,aAAa,UAAU;AAC1D,QAAM,QAAU,eAAe,MAAM,KAAK;AAC1C,QAAM,UAAU,WAAW,MAAM,WAAW;AAC5C,SAAO,KAAK,KAAK,UAAU,KAAK,KAAK,OAAO;AAC9C;AAGO,SAAS,wBAAwB,QAA8B;AACpE,QAAM,QAAkB,CAAC;AACzB,aAAW,SAAS,OAAO,QAAQ;AACjC,eAAW,SAAS,MAAM,QAAQ;AACh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