/** * CleoOS Startup Migration Verify — fail-fast DB drift check. * * Runs `cleo upgrade --diagnose --json` via subprocess (CLI boundary — no * direct imports from `@cleocode/core` or `@cleocode/cleo`). Classifies each * finding into one of three severity levels and returns an aggregate result * that the harness startup path uses to decide whether to block worker spawn. * * ## Classification Rules * * - **ok**: All DB findings are `status:"ok"`. Silent pass-through. * - **warn**: One or more findings are `status:"warning"`. These correspond to * states the reconciler already auto-fixed (Scenarios 1-4 in the migration * reconciler). Logged but not blocking. * - **fatal**: One or more findings are `status:"error"`, OR the `cleo` * binary could not be invoked, OR the JSON response was unparseable. These * represent states the reconciler could not resolve — typically a missing * migration folder (T1166 ENOENT class) or a schema missing a required * table. Worker spawn is blocked. * * ## Subprocess Boundary * * This module calls `cleo upgrade --diagnose --json` — the same check * exposed by `cleo upgrade --diagnose` — because it is the richest single * command that validates all five DBs and migration journals without starting * an interactive session. If `cleo admin migrations verify` is added in a * future sprint, the runner interface makes it trivial to swap. * * @see ADR-036 — CleoOS Database Topology * @see ADR-049 — CleoOS Sovereignty Invariants * @task T1185 * @epic T1150 * @packageDocumentation */ /** * Severity of a single DB finding returned by the diagnose command. * * @public */ export type DriftSeverity = 'ok' | 'warn' | 'fatal'; /** * A single DB drift report entry derived from a `cleo upgrade --diagnose` * finding. * * @public */ export interface DriftReport { /** The check name (e.g. `"tasks.db.journal"`, `"brain.db.tables"`). */ check: string; /** Severity classification applied by the verifier. */ severity: DriftSeverity; /** Human-readable detail from the diagnose output. */ details: string; /** Remediation hint when severity is `"warn"` or `"fatal"`. */ fix?: string; } /** * Aggregated result returned by {@link verifyMigrations}. * * @public */ export interface MigrationVerifyResult { /** * `true` when the harness may proceed to spawn workers. * `false` when at least one fatal drift was detected. */ ok: boolean; /** Aggregate severity across all findings. */ severity: DriftSeverity; /** Per-finding drift reports. Empty on a clean run. */ drift: DriftReport[]; /** * Whether `cleo admin migrations verify` was available. * * Currently always `false` — this verb does not exist yet. The verifier * falls back to `cleo upgrade --diagnose --json`. Set to `true` in a future * sprint once the dedicated verb lands. */ usedDedicatedVerb: boolean; } /** * Abstraction over the subprocess invocation so tests can inject a stub. * * @public */ export interface CliRunner { /** * Run `cleo upgrade --diagnose --json` and return the raw stdout. * * @throws When the subprocess exits non-zero or cannot be spawned. */ runDiagnose(): Promise; } /** * Default {@link CliRunner} that shells out to the real `cleo` binary. * * @public */ export declare class DefaultCliRunner implements CliRunner { /** @inheritdoc */ runDiagnose(): Promise; } /** * Run the migration verify pre-check and return a structured result. * * Invokes `cleo upgrade --diagnose --json` via subprocess (CLI boundary). * Classifies every non-ok finding into `warn` or `fatal`. A single `fatal` * finding causes `ok: false` — the harness startup path must block spawn and * print remediation instructions before exiting. * * @param runner - Injectable {@link CliRunner}; defaults to * {@link DefaultCliRunner} which shells out to the real `cleo` binary. * @returns Structured {@link MigrationVerifyResult}. * * @example * ```typescript * const result = await verifyMigrations(); * if (!result.ok) { * // print structured error + remediation, then exit * } * ``` * * @public */ export declare function verifyMigrations(runner?: CliRunner): Promise; /** * Format a {@link MigrationVerifyResult} as a human-readable fatal error * block for printing to stderr. * * Only called when `result.ok === false` (fatal drift detected). * * @param result - The failed verify result. * @returns Multi-line string ready for `process.stderr.write`. * * @public */ export declare function renderFatalDriftError(result: MigrationVerifyResult): string; /** * Format a {@link MigrationVerifyResult} as a human-readable warning block * for printing to stdout. * * Only called when `result.severity === "warn"` (reconciler already handled * the drift — non-blocking). * * @param result - The warn-severity verify result. * @returns Multi-line string ready for `process.stdout.write`. * * @public */ export declare function renderWarnDrift(result: MigrationVerifyResult): string; //# sourceMappingURL=verify-migrations.d.ts.map