feat/sites-v2
needs attentionviewing older commit8b42c1e · incrementalpre-PRreviewed 2026-08-11 23:01 UTC0H · 2M · 3L · 3I- Purpose
- Seed a complete demo org for the Batu sites & devices demo — five hero sites with real CFE bills, synthetic hourly metrics, monitoring subscriptions, savings configs, counterfactual baseline contracts, and savings reports.
- Goal
- All five demo sites show real monitoring data, production-level savings numbers, and a connected fleet status in the app.
- Sub-goals
- SG-1: Prod fixture extractor pulls real RPU/site/bill data
- SG-2: Demo org seeder — org, sites, contracts, monitoring subs, metric sources
- SG-3: Demo metrics seeder — synthetic hourly time-series through now
- SG-4: Savings baseline — SIMULATED_CFE_TOTAL counterfactual contracts + persisted savings_reports
- SG-5: Previews read DEV Tinybird workspace (not staging/prod)
- What
- Incremental fixes since 3a888ad1: (1) Tinybird preview token prefers DEV workspace; (2) .vercel to .gitignore; (3) coverageTo always generates to now; (4) period tail extension for unbilled hours; (5) solar generation unconditional for demo; (6) DEMO_GRANULARITY=1h constant + priority-1 source granularity fix; (7) DEMO_COVERAGE_TO dynamic; (8) monitoring subscriptions seeded per contract; (9) solar_tag guard removed from savings configs; (10) SIMULATED_CFE_TOTAL contracts, counterfactual bills, and savings_reports seeded.
- Why
- First cut had charts empty and fleet showing disconnected — coverage pinned to stale July date, granularity mismatch caused 12x energy under-count, no monitoring subs made bills invisible, no savings_reports meant endpoint returned configured:false.
- Areas
- .github/workflows+12−5packages/database/src/demo+1369−0
- Blast
- 7 files total (+1644/-5); entirely dev tooling — no production domain code, no schema migrations, no API surface changes.
Findings · 8
correctness3
Wrong PublicIdPrefix for monitoring subscription public_ids
packages/database/src/demo/seed-demo-org.ts
Both utility_service_monitoring_subscriptions and payment_monitoring_subscriptions insert rows using generatePublicId(PublicIdPrefix.UtilityContract) (prefix uct). The registry has MonitoringSubscription: 'sub' and PaymentMonitoringSubscription: 'pms'. Using the wrong prefix gives these rows uct_ IDs indistinguishable from contract IDs.
Division by zero when billedKwh === 0 in savings baseline
packages/database/src/demo/seed-demo-org.ts
rate = billedTotal / billedKwh produces Infinity/NaN on demand-only bills or missing CONSUMO_R line items. The guard 'if (billedKwh <= 0 || billedTotal <= 0) continue' exists in the diff — confirm it fires BEFORE the rate computation, not after. If the guard is upstream of the division, this is a non-issue.
GHA secrets.X || secrets.Y syntax IS valid — disputed HIGH finding
.github/workflows/preview-provision.yml
One lens flagged this as HIGH. Verified: GitHub Actions expression || treats unset secrets (empty string) as falsy and returns the right operand. Documented GHA behavior. The fallback is correct as written.
conventions1
Solar generation deviation is intentionally commented in source
packages/database/src/demo/seed-demo-metrics.ts
The unconditional solar generation block includes a // DEMO DEVIATION comment in the committed source. Convention satisfied.
tests1
Tail extension and solarShare are untested — acceptable for demo scripts
packages/database/src/demo/seed-demo-metrics.ts
No unit tests expected for seeder scripts. Manual dry-run against staging DB before each demo is the verification gate. The explicit billedKwh <= 0 guard reduces the division-by-zero risk.
improvement3
DEMO_COVERAGE_TO and seed-demo-metrics capture `new Date()` independently
packages/database/src/demo/seed-demo-org.ts
Both files call new Date() at module init. Run as separate processes, coverage boundaries diverge by seconds to minutes. A single DEMO_SEED_NOW env var consumed by both files would pin the boundary identically.
solarShare constants (0.35/0.28) are magic numbers
packages/database/src/demo/seed-demo-org.ts
Extract NETMET_SOLAR_SHARE = 0.35 and DEFAULT_SOLAR_SHARE = 0.28 as named constants with a comment ('estimated displacement ratio; replace when Tinybird generation data is available in seed context').
GHA Tinybird fallback silently uses prod workspace with no warning
.github/workflows/preview-provision.yml
When TINYBIRD_TOKEN_DEV is unset, previews silently fall back to TINYBIRD_TOKEN (the staging/prod workspace). Add `echo '::warning::TINYBIRD_TOKEN_DEV not set, falling back to prod Tinybird workspace'` so the condition surfaces in Actions logs.
History · 7 commits
- bf960baneeds attentionincremental5H · 12M · 4L2026-08-12 05:48
- eb284feneeds attentionincremental0H · 5M · 4L2026-08-12 05:10
- 6bfc5bcneeds attentionincremental4H · 7M · 6L2026-08-12 02:49
- 3d49126safeincremental0H · 0M · 2L2026-08-11 23:15
- df18b6bneeds attentionincremental2H · 5M · 5L2026-08-11 23:08
- 8b42c1eneeds attentionincremental0H · 2M · 3L2026-08-11 23:01current
- 5c64ea3needs attentionfull3H · 4M · 5L2026-08-11 19:15