lawsynth/apps/studio/tests/scenario-board.test.ts
caelum0x 3c257cc9ef feat(product): scenarios & decisions across CLI, SDK, notebook, Studio
Wave 4 — compare what-ifs to decide:
CLI — lawsynth scenarios: define N named what-if scenarios (scheduled
interventions), compare final-state divergence from baseline in a table + a
self-contained multi-series HTML report (overlaid trajectories + legend).
lawsynth doctor: environment/health check with a real world round-trip self-test.

SDK — Study.add_scenario/compare_scenarios -> ScenarioComparison (table +
overlaid-SVG _repr_html_); a cohesive StudyDashboard in lawsynth-notebook that
composes equations/trajectory/frontier/regimes/uncertainty/scenarios into one
themed Jupyter view; Study._repr_html_ now renders the full dashboard when the
notebook package is present, degrading gracefully otherwise.

Studio — Scenario Board (9th screen): define scenarios, overlay trajectories
(multi-series chart + legend), baseline-divergence table, store-driven selection.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-08-17 21:45:50 +03:00

41 lines
1.6 KiB
TypeScript

import { BASELINE_SCENARIO_ID, defaultScenarios, scenarioBoardModel } from "../src/screens/index.js";
import { equal, world } from "./support.js";
export async function scenarioBoardTests(): Promise<void> {
const scenarios = defaultScenarios(world);
// The support world exposes one adjustable parameter (`growth`), so the board
// seeds a high/low pair of illustrative scenarios.
equal(scenarios.length, 2);
const model = scenarioBoardModel({
world,
initialState: { prey: 1 },
scenarios,
draft: { name: "", overrides: {}, activeInterventionIds: [] },
horizon: 5,
step: 1,
selectedScenarioId: scenarios[0]!.id,
});
equal(model.id, "scenario-board");
// Multi-series overlay: one labeled series (with legend) per scenario plus baseline.
const chart = model.sections.find((section) => section.kind === "chart");
equal(chart?.kind, "chart");
if (chart?.kind === "chart") {
equal(chart.legend?.length, scenarios.length + 1);
equal(chart.chart.series.length, scenarios.length + 1);
}
// Comparison table: a baseline row plus one row per scenario, baseline first.
const table = model.sections.find((section) => section.kind === "table" && section.id === "scenarios");
equal(table?.kind, "table");
if (table?.kind === "table") {
equal(table.rows.length, scenarios.length + 1);
equal(table.rows[0]?.id, BASELINE_SCENARIO_ID);
// The selected scenario is highlighted, and it has diverged from baseline.
const selected = table.rows.find((row) => row.selected === true);
equal(selected?.id, scenarios[0]!.id);
equal(Number(selected?.cells[selected.cells.length - 1]) > 0, true);
}
}