Pre-launch — Gluecron is in final validation. Public signups and git hosting for non-owner users open after launch review.
CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
Blame · Line-by-line history

workflow-matrix.test.ts

Each line is annotated with the commit that last touched it. Click any SHA to jump to that commit and see the surrounding change.

workflow-matrix.test.tsBlame109 lines · 1 contributor
abfa9adClaude1/**
2 * Unit tests for src/lib/workflow-matrix.ts (Agent 4, Sprint 1).
3 *
4 * Pure-function coverage: cartesian expansion, include/exclude semantics,
5 * validator guardrails. No DB, no I/O — just data transformations.
6 */
7
8import { describe, it, expect } from "bun:test";
9import { expandMatrix, validateMatrix } from "../lib/workflow-matrix";
10
11describe("workflow-matrix — expandMatrix", () => {
12 it("empty axes {} with no include returns []", () => {
13 const combos = expandMatrix({ axes: {} });
14 expect(combos).toEqual([]);
15 });
16
17 it("single axis expands to one combo per value in alpha-key order", () => {
18 const combos = expandMatrix({ axes: { os: ["a", "b", "c"] } });
19 expect(combos).toHaveLength(3);
20 expect(combos[0]).toEqual({ os: "a" });
21 expect(combos[1]).toEqual({ os: "b" });
22 expect(combos[2]).toEqual({ os: "c" });
23 });
24
25 it("two axes produce the cartesian product with both keys", () => {
26 const combos = expandMatrix({
27 axes: { os: ["ubuntu", "mac"], node: [16, 18] },
28 });
29 expect(combos).toHaveLength(4);
30 // Every combo must contain both keys.
31 for (const c of combos) {
32 expect(Object.keys(c).sort()).toEqual(["node", "os"]);
33 }
34 // Verify all four combinations are present.
35 const serialized = combos.map((c) => JSON.stringify(c)).sort();
36 expect(serialized).toEqual(
37 [
38 { node: 16, os: "ubuntu" },
39 { node: 16, os: "mac" },
40 { node: 18, os: "ubuntu" },
41 { node: 18, os: "mac" },
42 ]
43 .map((c) => JSON.stringify(c))
44 .sort()
45 );
46 });
47
48 it("exclude removes matching combos", () => {
49 const combos = expandMatrix({
50 axes: { os: ["a", "b"], node: [16, 18] },
51 exclude: [{ os: "a", node: 16 }],
52 });
53 expect(combos).toHaveLength(3);
54 expect(combos.find((c) => c.os === "a" && c.node === 16)).toBeUndefined();
55 });
56
57 it("include adds a standalone combo when it does not match any cartesian entry", () => {
58 const combos = expandMatrix({
59 axes: { os: ["a"] },
60 include: [{ os: "windows", extra: "bonus" }],
61 });
62 // One from the axes + one standalone include.
63 expect(combos).toHaveLength(2);
64 expect(combos.find((c) => c.os === "windows" && c.extra === "bonus")).toBeDefined();
65 });
66
67 it("include extends an existing combo with extra keys when axis keys match", () => {
68 const combos = expandMatrix({
69 axes: { os: ["a", "b"] },
70 include: [{ os: "a", env: "prod" }],
71 });
72 expect(combos).toHaveLength(2);
73 const aCombo = combos.find((c) => c.os === "a");
74 const bCombo = combos.find((c) => c.os === "b");
75 expect(aCombo).toEqual({ os: "a", env: "prod" });
76 expect(bCombo).toEqual({ os: "b" });
77 });
78
79 it("empty axis value [] yields no combos", () => {
80 const combos = expandMatrix({ axes: { os: [] } });
81 expect(combos).toEqual([]);
82 });
83
84 it("validateMatrix rejects non-object input and non-array axis values", () => {
85 expect(validateMatrix(null).ok).toBe(false);
86 expect(validateMatrix(undefined).ok).toBe(false);
87 expect(validateMatrix("not an object").ok).toBe(false);
88 expect(validateMatrix([]).ok).toBe(false);
89 const badAxis = validateMatrix({ axes: { os: "not-an-array" } });
90 expect(badAxis.ok).toBe(false);
91 if (!badAxis.ok) expect(badAxis.error).toMatch(/array/i);
92 });
93
94 it("validateMatrix accepts a well-formed spec", () => {
95 const good = validateMatrix({
96 axes: { os: ["a", "b"] },
97 include: [{ os: "a", env: "x" }],
98 exclude: [{ os: "b" }],
99 failFast: true,
100 maxParallel: 4,
101 });
102 expect(good.ok).toBe(true);
103 if (good.ok) {
104 expect(good.spec.axes.os).toEqual(["a", "b"]);
105 expect(good.spec.failFast).toBe(true);
106 expect(good.spec.maxParallel).toBe(4);
107 }
108 });
109});