Files
agentic-labs-challenge-subm…/adaptive-loop/tests/helpers.ts
T
2026-08-13 07:33:43 +02:00

47 lines
2.4 KiB
TypeScript

// Test helpers: build minimal isolated states against the fixture-free TEST_SCENARIO
// so a single pipeline phase can be exercised without cross-phase interference.
import { buildBaselineState } from "../src/domain/scenario";
import { defaultSharedOwner } from "../src/domain/constants";
import type { Chamber, GameState, LineageId, LoopId, PressureId } from "../src/domain/types";
// (Patch still carries slot for placement; it is stripped before building chambers.)
import { emptyLineage } from "../src/domain/serialize";
export type Patch = Partial<Chamber> & { slot: number };
export function makeState(patches: Patch[] = [], opts: {
scenarioId?: string;
loops?: Partial<Record<LoopId, "cw" | "ccw">>;
sharedOwner?: Record<string, LoopId>;
unlocked?: Partial<Record<LineageId, PressureId[]>>;
pressure?: Partial<Record<LineageId, Partial<Record<PressureId, number>>>>;
env?: Partial<Record<PressureId, boolean>>;
turn?: number;
outcome?: GameState["outcome"];
consecutive?: number;
} = {}): GameState {
const base = buildBaselineState(opts.scenarioId ?? "test", "standalone");
const chambers: Chamber[] = Array.from({ length: 12 }, () => ({ nutrient: 0, heat: 0, toxin: 0, producer: 0, grazer: 0, phage: 0 }));
for (const p of patches) {
const { slot: _omit, ...rest } = p;
void _omit;
chambers[p.slot] = { nutrient: 0, heat: 0, toxin: 0, producer: 0, grazer: 0, phage: 0, ...rest };
}
base.chambers = chambers;
if (opts.loops) for (const L of ["A", "B", "C"] as LoopId[]) if (opts.loops[L]) base.loops[L].direction = opts.loops[L]!;
if (opts.sharedOwner) base.sharedOwner = { ...defaultSharedOwner(), ...opts.sharedOwner };
if (opts.unlocked) for (const id of ["producer", "grazer"] as LineageId[]) for (const p of opts.unlocked[id] ?? []) base.lineage[id].unlocked[p] = true;
if (opts.pressure) for (const id of ["producer", "grazer"] as LineageId[]) for (const p of Object.keys(opts.pressure[id] ?? {}) as PressureId[]) base.lineage[id].pressure[p] = opts.pressure[id]![p]!;
if (opts.env) base.environmentActive = { heat: false, hunger: false, toxin: false, immunity: false, ...opts.env };
if (opts.turn !== undefined) base.turn = opts.turn;
if (opts.outcome) base.outcome = opts.outcome;
if (opts.consecutive !== undefined) base.consecutiveObjectiveTurns = opts.consecutive;
return base;
}
export function chamber(state: GameState, slot: number): Chamber {
return state.chambers[slot];
}
export { emptyLineage };