From 974d68356e15df03584924c18f280991943c7fb9 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Sun, 26 Jul 2026 01:05:48 -0700 Subject: [PATCH] Document the seeder's exported surface MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CodeRabbit flagged docstring coverage. Added docs where a caller would actually need them — that `seedDevDatabase` is destructive and not incremental, that it validates before opening anything so a rejected run leaves the target intact, that the caller still owns the attachment files, and that `DevSeedError.hint` is the actionable half the CLI prints separately. Left the self-describing internals (`placeholders`, `hasTable`, `columnsOf`, `stateDbPath`) alone: the surrounding scripts/ code documents about 2% of its declarations, so padding to an 80% tool default would read as noise rather than convention. Co-Authored-By: Claude Opus 5 (1M context) --- scripts/lib/dev-seed.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/scripts/lib/dev-seed.ts b/scripts/lib/dev-seed.ts index 1f981442fb..f164580d32 100644 --- a/scripts/lib/dev-seed.ts +++ b/scripts/lib/dev-seed.ts @@ -34,8 +34,10 @@ import { PROJECTION_TABLES_IN_DEPENDENCY_ORDER, PROJECTOR_NAMES } from "./projec */ export const MAX_SEED_THREAD_LIMIT = 32_766; +/** Inputs to {@link seedDevDatabase}. Both limits must be positive. */ export interface DevSeedOptions { readonly sourceDbPath: string; + /** Emptied and rewritten. Must not be a database a server has open. */ readonly targetDbPath: string; /** How many recent threads to copy. Capped at {@link MAX_SEED_THREAD_LIMIT}. */ readonly threadLimit: number; @@ -49,6 +51,7 @@ export interface DevSeedOptions { readonly seededAt: string; } +/** What {@link seedDevDatabase} copied, for the CLI's summary output. */ export interface DevSeedSummary { readonly projects: number; readonly threads: number; @@ -65,6 +68,11 @@ export interface DevSeedSummary { readonly attachmentIds: ReadonlyArray; } +/** + * A seed that could not proceed. `hint` carries the actionable half — the + * underlying cause, or what to do about it — which the CLI prints on its own + * line beneath the message. + */ export class DevSeedError extends Error { override readonly name = "DevSeedError"; readonly hint: string | undefined; @@ -311,6 +319,21 @@ function dropPendingTurnStarts( .run(...threadIds); } +/** + * Replaces the target's projections with a recent slice of the source's. + * + * Destructive and not incremental: every projection table, the event log, and + * the command receipts are emptied first, inside one transaction that rolls + * back on any failure. Validation that can reject the whole run happens before + * that transaction opens, so a rejected seed leaves the target as it was. + * + * The caller must ensure no server is using the target — see the guard in + * scripts/dev-seed.ts. Returns counts plus the attachment ids whose files the + * caller still has to copy. + * + * @throws {DevSeedError} on bad limits, an unopenable database, or a source + * with no active threads. + */ export function seedDevDatabase(options: DevSeedOptions): DevSeedSummary { // Checked before anything is opened, and certainly before the target is // emptied: overrunning the ceiling mid-copy destroys the target's data and