From 85ea43d25facba086bb6e5aa8bc2023e85979bb2 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Tue, 14 Apr 2026 03:15:06 +0200 Subject: [PATCH] Add test for non-actor scheduler effects and default restoration --- .../domain/runtime-project-scheduler.test.ts | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/tests/domain/runtime-project-scheduler.test.ts b/tests/domain/runtime-project-scheduler.test.ts index 26ffeee2..0f67a672 100644 --- a/tests/domain/runtime-project-scheduler.test.ts +++ b/tests/domain/runtime-project-scheduler.test.ts @@ -1,10 +1,14 @@ import { describe, expect, it } from "vitest"; import { + applyControlEffectToResolvedState, createActorControlTargetRef, + createDefaultResolvedControlSource, createEmptyRuntimeResolvedControlState, + createLightControlTargetRef, createSetActorPresenceControlEffect } from "../../src/controls/control-surface"; +import { createSetLightIntensityControlEffect } from "../../src/controls/control-surface"; import { createEmptyProjectScheduler, createProjectScheduleRoutine, @@ -153,4 +157,85 @@ describe("runtime project scheduler", () => { }) ]); }); + + it("applies non-actor scheduler effects over baseline control state and restores defaults when inactive", () => { + const lightTarget = createLightControlTargetRef( + "pointLight", + "entity-point-light-main" + ); + const scheduler = createEmptyProjectScheduler(); + scheduler.routines["routine-night-light"] = createProjectScheduleRoutine({ + id: "routine-night-light", + title: "Night Light", + target: lightTarget, + startHour: 18, + endHour: 6, + effect: createSetLightIntensityControlEffect({ + target: lightTarget, + intensity: 3.5 + }) + }); + + const baselineResolved = applyControlEffectToResolvedState( + createEmptyRuntimeResolvedControlState(), + createSetLightIntensityControlEffect({ + target: lightTarget, + intensity: 1.25 + }), + createDefaultResolvedControlSource() + ); + const activeSchedule = resolveRuntimeProjectScheduleState({ + scheduler, + actorIds: [], + dayNumber: 1, + timeOfDayHours: 21 + }); + const activeResolved = applyRuntimeProjectScheduleToControlState( + baselineResolved, + activeSchedule, + baselineResolved + ); + const inactiveSchedule = resolveRuntimeProjectScheduleState({ + scheduler, + actorIds: [], + dayNumber: 2, + timeOfDayHours: 9 + }); + const inactiveResolved = applyRuntimeProjectScheduleToControlState( + activeResolved, + inactiveSchedule, + baselineResolved + ); + + expect(activeSchedule.controls).toEqual([ + expect.objectContaining({ + routineId: "routine-night-light", + title: "Night Light", + resolutionKey: "channel:light.intensity:entity:pointLight:entity-point-light-main" + }) + ]); + expect(activeResolved.channels).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + type: "lightIntensity", + value: 3.5, + source: { + kind: "scheduler", + scheduleId: "routine-night-light" + } + }) + ]) + ); + expect(inactiveResolved.channels).toEqual( + expect.arrayContaining([ + expect.objectContaining({ + type: "lightIntensity", + value: 1.25, + source: { + kind: "default" + } + }) + ]) + ); + }); });