caelum0x a126131ed9 feat(consumers): portfolio Rago seeds, the consumer contract fixtures, switch table, key plan and nightly reconciliation (PY1.5)
Railyard side of PY1.5 (dispatch 5.3). Acceptance:
1. tests/contract/consumers/contract.json is the contract PM1.5, PR1.5 and
   the Scribase carve-out test against: env names (RELAY_URL, RELAY_KEY,
   RAGO_URL, RAGO_API_KEY, MINT_URL, MINT_API_KEY, RAILYARD_LIVE), the
   RAILYARD_LIVE switch (default 0), every product's meters and one sample
   event per meter with the <product>:<meter>:<source id> idempotency key.
2. apps/rago/seeds/portfolio/{scribase,menivor,rally}-portfolio.json define
   exactly those meters (valid Rago aggregations, field names where summed)
   under $0 mirror plans; consumers.test.ts checks seeds against the contract.
4. tools/reconcile-portfolio/reconcile.mjs compares each product's own counts
   with Rago's totals per customer, meter and month; on the fixtures the
   difference is 0, and dropped, extra or malformed rows are named (exit 1/2).
5. Nothing switches live in code: docs/CONSUMERS.md gains the Wave P switch
   table. scripts/relay/provision-product-keys.mjs prints names and the box
   steps only (no value is generated, read or printed).
3 (Mint stack, 128 MiB, /metrics scraped): infra-box stacks/mint; Mint's
/metrics handler exists since RY-MT1.
Not in this commit: Mint outbound event webhooks and the paid-event mirror
(see the lane report).

Tests: consumers 3/3, reconcile 2/2, provision 1/1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 21:57:43 +03:00

28 lines
1.6 KiB
JavaScript

import { test } from "node:test";
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import { readFileSync } from "node:fs";
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { reconcile } from "../reconcile.mjs";
const HERE = dirname(fileURLToPath(import.meta.url));
const SCRIPT = join(HERE, "../reconcile.mjs");
const product = JSON.parse(readFileSync(join(HERE, "fixtures/product-counts.json"), "utf8"));
const rago = JSON.parse(readFileSync(join(HERE, "fixtures/rago-totals.json"), "utf8"));
test("on the fixtures Rago's totals equal each product's own counts: difference 0", () => {
assert.deepEqual(reconcile(product, rago), []);
const r = spawnSync(process.execPath, [SCRIPT, "--product", join(HERE, "fixtures/product-counts.json"), "--rago", join(HERE, "fixtures/rago-totals.json")], { encoding: "utf8" });
assert.equal(r.status, 0, r.stderr);
assert.equal(JSON.parse(r.stdout).difference_rows, 0);
});
test("a dropped event, an extra event and a missing row are each named", () => {
const dropped = rago.filter((row) => row.code !== "rally.email.sent");
const extra = [...rago, { external_customer_id: "menivor_org_0001", code: "menivor.reel.rendered", month: "2026-09", value: 1 }];
assert.deepEqual(reconcile(product, dropped), [{ external_customer_id: "rally_org_0001", code: "rally.email.sent", month: "2026-09", product: 480, rago: 0, difference: -480 }]);
assert.equal(reconcile(product, extra)[0].difference, 1);
assert.throws(() => reconcile([{ code: "x" }], []), /malformed/);
});