From 6aadf1423c1822e90ecc80d90275cd8b220e7e70 Mon Sep 17 00:00:00 2001 From: claude Date: Fri, 14 Aug 2026 20:22:21 -0700 Subject: [PATCH] Count what the seed wrote, instead of claiming it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The demo seed's summary was hardcoded when the book was split into modules, and it drifted the moment the book grew: it reported 12 demand deals and 5 capacity commitments against a database holding 13 and 6. Caught by reading the seed's own output beside the table it had just written. Nobody would have noticed for a while, because the numbers were close enough to look right — which is the whole problem. That output is the only feedback `pnpm db:demo` gives an operator, and a command that misreports what it did teaches you to stop reading it. Counted in SQL now, including the number of distinct stages, so the line about the pipeline covering every stage is a measurement rather than a promise the seed makes about itself. Co-Authored-By: Claude Opus 5 (1M context) --- packages/db/src/seed/demo/index.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/packages/db/src/seed/demo/index.ts b/packages/db/src/seed/demo/index.ts index 20f041b..8e96e95 100644 --- a/packages/db/src/seed/demo/index.ts +++ b/packages/db/src/seed/demo/index.ts @@ -46,8 +46,9 @@ * always run in; sections depend on ids the earlier ones return. */ import { quarterBoundsFor } from '@pig/core'; +import { sql } from 'drizzle-orm'; import { createDatabase, type Database } from '../../client'; -import { users } from '../../schema/index'; +import { capacityCommitments, demandDeals, supplyDeals, users } from '../../schema/index'; import { seedSupplyActivities } from './activities'; import { seedFacts } from './agent'; import { seedCalendar } from './calendar'; @@ -175,14 +176,32 @@ export async function seedDemo(context: DemoContext): Promise { const facts = await seedFacts(context); - console.log(' 5 capacity commitments (4 live, 1 lapsed), with sites, MSAs and negotiated SLAs'); + /* + * Counted, not asserted. These lines were hardcoded when the book was split + * into modules, and they drifted the moment the seed grew: the summary + * claimed 12 demand deals and 5 commitments against a database holding 13 + * and 6. A seed that misreports what it wrote teaches an operator to + * distrust the only feedback the command gives them. + */ + const [written] = await context.db + .select({ + commitments: sql`(select count(*)::int from ${capacityCommitments})`, + demandDeals: sql`(select count(*)::int from ${demandDeals})`, + supplyDeals: sql`(select count(*)::int from ${supplyDeals})`, + demandStages: sql`(select count(distinct stage)::int from ${demandDeals})`, + }) + .from(sql`(select 1) as one`); + const book = written ?? { commitments: 0, demandDeals: 0, supplyDeals: 0, demandStages: 0 }; + + console.log(` ${book.commitments} capacity commitments, with sites, MSAs and negotiated SLAs`); console.log(` ${facts.total} agent-derived facts (${facts.added} new) — 2 applied, 4 awaiting review`); console.log( ` ${facts.tasks} agent tasks and ${facts.runs} Piggy runs, ${facts.actions} idempotency-keyed actions, ` + `${(facts.costMicroCents / 1_000_000).toFixed(4)} cents of model spend`, ); console.log( - ' 12 demand deals across all ten stages — 2 won, 1 lost, 1 expansion off a closed parent — and 8 supply deals', + ` ${book.demandDeals} demand deals across ${book.demandStages} stages — including a won parent with its ` + + `expansion child, and a loss with a reason — and ${book.supplyDeals} supply deals`, ); console.log(' Allocations including one unconverted hold and internal research burn'); console.log(