Formalize simulator system with manifest, input-policy, runner, and admin UI (#409)
Introduces three new schema tables (simulator_profiles,
sports_season_simulator_configs, season_participant_simulator_inputs),
a central model layer (app/models/simulator.ts), and a single runner
entry point so every simulator run follows the same prepare → simulate
→ persist → snapshot → recalculate flow.
Key additions:
- manifest.ts: per-simulator display names, default configs, required/
optional inputs, derivable-input declarations, and setup sections
- input-policy.ts: resolves sourceElo from projectedWins,
projectedTablePoints, or sourceOdds; resolves ratings from sourceOdds;
supports block / fallbackElo / averageKnown / worstKnownMinus strategies
- runner.ts: single entry point for admin simulation runs; materialises
derived inputs, normalises result columns, zeroes omitted participants,
snapshots EVs, and recalculates linked fantasy standings
- /admin/simulators: inventory page with per-season readiness and bulk run
- /admin/sports-seasons/:id/simulator: per-season setup page with readiness
summary, input-policy editor, raw JSON config override, and CSV bulk input
- NCAAM/NCAAW simulators now read ratings from season_participant_simulator_inputs,
falling back to the hardcoded name-keyed maps while DB data is being populated
- Clone flow copies simulator config by default; volatile inputs (odds, Elo)
only copied when explicitly requested
Code-review fixes included in this commit:
- source field in compatibility bridge checked with !== null instead of !== undefined
- sourceEloRequirementLabel no longer appends "configured fallback" when the
participant is already excluded from all resolved sources
- Duplicate inline label maps in input-policy.ts replaced with simulatorInputLabel
- save-config preserves existing inputPolicy when the submitted JSON omits it
- Input table truncation label added (Showing 20 of N)
- CSV description notes values must not contain commas
- N+1 comment added to listSportsSeasonSimulatorSummaries
- assertRegistrySchemaDriftFree called in manifest tests
- Runner test suite added covering happy path, already-running guard,
readiness failure, empty results, and error recovery with status reset
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 21:09:53 -07:00
|
|
|
import { describe, expect, it } from "vitest";
|
|
|
|
|
import * as schema from "~/database/schema";
|
|
|
|
|
import { SIMULATOR_MANIFEST } from "../manifest";
|
|
|
|
|
import { SIMULATOR_TYPES } from "../registry";
|
|
|
|
|
import { assertRegistrySchemaDriftFree } from "~/models/simulator";
|
|
|
|
|
|
|
|
|
|
describe("simulator manifest", () => {
|
|
|
|
|
it("has a manifest profile for every registered simulator type", () => {
|
|
|
|
|
expect(Object.keys(SIMULATOR_MANIFEST).toSorted()).toEqual([...SIMULATOR_TYPES].toSorted());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("keeps the registry and database enum in sync", () => {
|
|
|
|
|
expect([...schema.simulatorTypeEnum.enumValues].toSorted()).toEqual([...SIMULATOR_TYPES].toSorted());
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("assertRegistrySchemaDriftFree does not throw when registry and schema are aligned", async () => {
|
|
|
|
|
await expect(assertRegistrySchemaDriftFree()).resolves.toBeUndefined();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("documents admin setup requirements for all profiles", () => {
|
|
|
|
|
for (const simulatorType of SIMULATOR_TYPES) {
|
|
|
|
|
const profile = SIMULATOR_MANIFEST[simulatorType];
|
|
|
|
|
expect(profile.displayName).toBeTruthy();
|
|
|
|
|
expect(profile.description).toBeTruthy();
|
|
|
|
|
expect(Array.isArray(profile.requiredInputs)).toBe(true);
|
|
|
|
|
expect(Array.isArray(profile.optionalInputs)).toBe(true);
|
|
|
|
|
expect(profile.setupSections.length).toBeGreaterThan(0);
|
|
|
|
|
expect(profile.defaultConfig).toBeTypeOf("object");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("only derives inputs from declared optional inputs", () => {
|
|
|
|
|
for (const simulatorType of SIMULATOR_TYPES) {
|
|
|
|
|
const profile = SIMULATOR_MANIFEST[simulatorType];
|
|
|
|
|
for (const alternatives of Object.values(profile.derivableInputs ?? {})) {
|
|
|
|
|
for (const alternative of alternatives ?? []) {
|
|
|
|
|
expect(profile.optionalInputs).toContain(alternative);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-05-13 15:02:23 -07:00
|
|
|
|
|
|
|
|
it("keeps EPL projection and match parity as separate config knobs", () => {
|
|
|
|
|
expect(SIMULATOR_MANIFEST.epl_standings.defaultConfig).toMatchObject({
|
|
|
|
|
parityFactor: 400,
|
|
|
|
|
matchParityFactor: 400,
|
|
|
|
|
averageOpponentElo: 1500,
|
|
|
|
|
baseDrawRate: 0.26,
|
|
|
|
|
drawDecay: 0.002,
|
|
|
|
|
});
|
|
|
|
|
});
|
Formalize simulator system with manifest, input-policy, runner, and admin UI (#409)
Introduces three new schema tables (simulator_profiles,
sports_season_simulator_configs, season_participant_simulator_inputs),
a central model layer (app/models/simulator.ts), and a single runner
entry point so every simulator run follows the same prepare → simulate
→ persist → snapshot → recalculate flow.
Key additions:
- manifest.ts: per-simulator display names, default configs, required/
optional inputs, derivable-input declarations, and setup sections
- input-policy.ts: resolves sourceElo from projectedWins,
projectedTablePoints, or sourceOdds; resolves ratings from sourceOdds;
supports block / fallbackElo / averageKnown / worstKnownMinus strategies
- runner.ts: single entry point for admin simulation runs; materialises
derived inputs, normalises result columns, zeroes omitted participants,
snapshots EVs, and recalculates linked fantasy standings
- /admin/simulators: inventory page with per-season readiness and bulk run
- /admin/sports-seasons/:id/simulator: per-season setup page with readiness
summary, input-policy editor, raw JSON config override, and CSV bulk input
- NCAAM/NCAAW simulators now read ratings from season_participant_simulator_inputs,
falling back to the hardcoded name-keyed maps while DB data is being populated
- Clone flow copies simulator config by default; volatile inputs (odds, Elo)
only copied when explicitly requested
Code-review fixes included in this commit:
- source field in compatibility bridge checked with !== null instead of !== undefined
- sourceEloRequirementLabel no longer appends "configured fallback" when the
participant is already excluded from all resolved sources
- Duplicate inline label maps in input-policy.ts replaced with simulatorInputLabel
- save-config preserves existing inputPolicy when the submitted JSON omits it
- Input table truncation label added (Showing 20 of N)
- CSV description notes values must not contain commas
- N+1 comment added to listSportsSeasonSimulatorSummaries
- assertRegistrySchemaDriftFree called in manifest tests
- Runner test suite added covering happy path, already-running guard,
readiness failure, empty results, and error recovery with status reset
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-11 21:09:53 -07:00
|
|
|
});
|