lilith-platform.live/codebase/@features/api/scripts/smoke-opportunity-ranked.ts

55 lines
2.1 KiB
TypeScript

/**
* Smoke-test for listOpportunityRanked + grade-based clearance.
*
* Run:
* QUINN_API_DB_URL=postgres://quinn:devpassword@black.lan:25435/quinn \
* pnpm exec tsx scripts/smoke-opportunity-ranked.ts
*
* Expects (after seed):
* - Cincinnati ranks above LA/Vegas for category=trans (B+ >= C-, big fish)
* - Cincinnati ranks above LA/Vegas for category=general (C+ >= C+, both clear)
* - LA/Vegas show clears_bar=false for category=general (C+ < A-)
*/
import postgres from 'postgres';
import { listOpportunityRanked, type OpportunityRankedRow } from '../src/entities/destination/repo';
const url = process.env['QUINN_API_DB_URL'] ?? 'postgres://quinn:devpassword@black.lan:25435/quinn';
const out = (line: string): void => {
process.stdout.write(`${line}\n`);
};
const fmtRow = (r: OpportunityRankedRow): string =>
` ${r.slug.padEnd(15)} market=${(r.marketGradeForCategory ?? '-').padEnd(3)} ` +
`provider=${(r.providerGradeForCategory ?? '-').padEnd(3)} ` +
`clears=${r.clearsBar === null ? '?' : r.clearsBar ? 'Y' : 'N'} ` +
`delta=${r.gradeStepDelta ?? '-'} score=${r.computedOpportunityScore}${r.bigFishSmallPond ? ' BIG-FISH' : ''}`;
async function main(): Promise<void> {
const sql = postgres(url, { max: 2 });
try {
for (const category of ['general', 'trans'] as const) {
out(`\n=== category=${category} ===`);
const rows = await listOpportunityRanked(sql, { providerSlug: 'quinn', category, limit: 200 });
const focus = rows.filter((r) =>
['cincinnati', 'los-angeles', 'las-vegas', 'san-francisco', 'amsterdam', 'london'].includes(r.slug),
);
for (const r of focus) out(fmtRow(r));
out(' --- top 10 overall ---');
for (const r of rows.slice(0, 10)) {
out(
` ${r.slug.padEnd(15)} score=${r.computedOpportunityScore} clears=${r.clearsBar === null ? '?' : r.clearsBar ? 'Y' : 'N'}`,
);
}
}
} finally {
await sql.end({ timeout: 2 });
}
}
main().catch((err: unknown) => {
process.stderr.write(`${err instanceof Error ? err.stack ?? err.message : String(err)}\n`);
process.exit(1);
});