Count what the seed wrote, instead of claiming it
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) <noreply@anthropic.com>
This commit is contained in:
@@ -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<void> {
|
||||
|
||||
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<number>`(select count(*)::int from ${capacityCommitments})`,
|
||||
demandDeals: sql<number>`(select count(*)::int from ${demandDeals})`,
|
||||
supplyDeals: sql<number>`(select count(*)::int from ${supplyDeals})`,
|
||||
demandStages: sql<number>`(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(
|
||||
|
||||
Reference in New Issue
Block a user