gram/packages/kitchen/tests/processor.test.ts
abiwab 06039f200b feat(kitchen): implement ALAP (As Late As Possible) scheduling
This commit replaces the naive forward-pass timeline generation in the Kitchen processor with a comprehensive 3-phase ALAP algorithm.

Passive timers and their dependencies are now natively pushed backwards from the end of the recipe. This guarantees that ingredients are prepared just-in-time and finish resting exactly when the downstream step requires them, preventing prolonged idle states on the kitchen counter. Named Tracks (sequential background tasks) also benefit from this mechanism, automatically interleaving with active tasks optimally.

Additionally, the documentation has been updated across both English and French versions to reflect these changes. A brand new Deep Dive guide has been added to visually explain ALAP scheduling and Gantt chart best practices.
2026-07-19 23:46:35 +02:00

35 lines
1 KiB
TypeScript

import { describe, it, expect } from "bun:test";
import { getAST } from "@gram-lang/parser";
import { compile } from "../src/index";
describe("Processor ALAP Scheduling", () => {
it("complex backward chaining with an independent step between timer and consumer", () => {
const source = `
## ALAP Section
[Preheat] The oven for ~_{15m}. ->&oven
[Prepare] The dough.
[Bake] In the &oven.
`;
const ast = getAST(source);
const result = compile(ast);
const steps = result.sections[0].steps.filter((s) => s.type === "step");
// Step 0: Preheat. Active: 0, Timer: 15m.
expect(steps[0].timings.start).toBe(0);
expect(steps[0].timings.end).toBe(0);
// Step 1: Prepare Dough. Active: 2 (fallback).
// ALAP pulls this to start at 13, right before Bake.
expect(steps[1].timings.start).toBe(13);
expect(steps[1].timings.end).toBe(15);
// Step 2: Bake. Active: 2 (fallback). Needs &oven.
// Wait for &oven (15m timer finishes at 15).
expect(steps[2].timings.start).toBe(15);
expect(steps[2].timings.end).toBe(17);
});
});