import { describe, expect, it } from "vitest"; import { importRecipe, records, runPipeline, type Stage, } from "../../src/core/pipeline"; describe("pipeline", () => { const input = records([ { name: "Ada", team: "a", score: 2 }, { name: "Grace", team: "a", score: 4 }, { name: "Linus", team: "b", score: 9 }, ]); it("filters sorts groups and exposes snapshots", () => { const stages: Stage[] = [ { id: "1", type: "filter", enabled: true, config: { field: "score", operator: ">=", value: "4" }, }, { id: "2", type: "group", enabled: true, config: { key: "team", fn: "avg", field: "score", output: "mean" }, }, ]; const result = runPipeline(input, stages); expect(result.rows).toEqual([ { team: "a", mean: 4 }, { team: "b", mean: 9 }, ]); expect(result.snapshots).toHaveLength(3); }); it("joins with prefixed right values", () => { const result = runPipeline( input, [ { id: "j", type: "join", enabled: true, config: { left: "team", right: "id", mode: "left", prefix: "r_" }, }, ], records([{ id: "a", lead: "Mina" }]), ); expect(result.rows[0]?.r_lead).toBe("Mina"); expect(result.rows[2]?.r_lead).toBeUndefined(); }); it("validates recipes and rejects code stages", () => { expect(() => importRecipe( '{"schema":"de.add-ideas.flow-tools.recipe.v1","stages":[{"type":"javascript","config":{}}]}', ), ).toThrow(/Invalid recipe/iu); }); });