@@ -124,6 +124,80 @@ describe("orchestration section validation", () => { |
124 | 124 | expect(() => todayFromSection(minimal)).not.toThrow(); |
125 | 125 | }); |
126 | 126 |
|
| 127 | + // #2417: the gate checked array presence only, so poisoned elements |
| 128 | + // (null / primitives / shapeless objects) passed into consumers and |
| 129 | + // threw TypeErrors. Every array's elements are now validated at this |
| 130 | + // boundary; a poisoned section must reject, normalize to null, and |
| 131 | + // diagnose as invalid with a stable failed-check name. |
| 132 | + test("rejects poisoned tier elements in both tier arrays", () => { |
| 133 | + for (const bad of [null, 42, {}]) { |
| 134 | + const drew = { ...SECTION, tiers: { ...SECTION.tiers, needsDrew: [bad] } }; |
| 135 | + expect(isOrchestrationSection(drew)).toBe(false); |
| 136 | + expect(orchestrationSectionProblem(drew)).toBe("tiers.needsDrew (per-item shape)"); |
| 137 | + expect(normalizeOrchestrationSection(drew)).toBeNull(); |
| 138 | + const orch = { ...SECTION, tiers: { ...SECTION.tiers, needsOrchestrator: [bad] } }; |
| 139 | + expect(isOrchestrationSection(orch)).toBe(false); |
| 140 | + expect(orchestrationSectionProblem(orch)).toBe("tiers.needsOrchestrator (per-item shape)"); |
| 141 | + } |
| 142 | + }); |
| 143 | + |
| 144 | + test("rejects non-record elements in goal linedUp and stalled arrays", () => { |
| 145 | + const goal = SECTION.goals[0]!; |
| 146 | + for (const field of ["linedUp", "stalled"] as const) { |
| 147 | + const malformed = { ...SECTION, goals: [{ ...goal, [field]: [null] }] }; |
| 148 | + expect(isOrchestrationSection(malformed)).toBe(false); |
| 149 | + expect(orchestrationSectionProblem(malformed)).toBe("goals (per-goal shape)"); |
| 150 | + expect(normalizeOrchestrationSection(malformed)).toBeNull(); |
| 151 | + } |
| 152 | + const nullGoal = { ...SECTION, goals: [null] }; |
| 153 | + expect(isOrchestrationSection(nullGoal)).toBe(false); |
| 154 | + }); |
| 155 | + |
| 156 | + test("rejects poisoned dependency elements and bad dependency shapes", () => { |
| 157 | + const nullDep = { ...SECTION, dependencies: [null] }; |
| 158 | + expect(isOrchestrationSection(nullDep)).toBe(false); |
| 159 | + expect(orchestrationSectionProblem(nullDep)).toBe("dependencies (per-dependency shape)"); |
| 160 | + const noStatus = { ...SECTION, dependencies: [{ task: "Write the thing" }] }; |
| 161 | + expect(isOrchestrationSection(noStatus)).toBe(false); |
| 162 | + const badStatus = { ...SECTION, dependencies: [{ task: "Write the thing", status: "bogus" }] }; |
| 163 | + expect(isOrchestrationSection(badStatus)).toBe(false); |
| 164 | + const badRef = { |
| 165 | + ...SECTION, |
| 166 | + dependencies: [{ task: "Write the thing", status: "queued", ref: 42 }], |
| 167 | + }; |
| 168 | + expect(isOrchestrationSection(badRef)).toBe(false); |
| 169 | + const good = { |
| 170 | + ...SECTION, |
| 171 | + dependencies: [{ task: "Write the thing", status: "queued", ref: "developing-today/code#1" }], |
| 172 | + }; |
| 173 | + expect(isOrchestrationSection(good)).toBe(true); |
| 174 | + }); |
| 175 | + |
| 176 | + test("rejects poisoned action elements and actions missing rendered fields", () => { |
| 177 | + const nullAction = { ...SECTION, actions: [null] }; |
| 178 | + expect(isOrchestrationSection(nullAction)).toBe(false); |
| 179 | + expect(orchestrationSectionProblem(nullAction)).toBe("actions (per-action shape)"); |
| 180 | + const noSummary = { |
| 181 | + ...SECTION, |
| 182 | + actions: [{ at: "2026-10-25T17:20:00.000Z", kind: "nudge", target: "task 1" }], |
| 183 | + }; |
| 184 | + expect(isOrchestrationSection(noSummary)).toBe(false); |
| 185 | + const good = { |
| 186 | + ...SECTION, |
| 187 | + actions: [ |
| 188 | + { at: "2026-10-25T17:20:00.000Z", kind: "nudge", target: "task 1", summary: "Nudged it." }, |
| 189 | + ], |
| 190 | + }; |
| 191 | + expect(isOrchestrationSection(good)).toBe(true); |
| 192 | + }); |
| 193 | + |
| 194 | + test("a poisoned section diagnoses as invalid, never absent or live", () => { |
| 195 | + const poisoned = { ...SECTION, tiers: { ...SECTION.tiers, needsDrew: [null] } }; |
| 196 | + const diagnosis = diagnoseOrchestrationSection(poisoned); |
| 197 | + expect(diagnosis.state).toBe("invalid"); |
| 198 | + expect(diagnosis.failedChecks).toEqual(["tiers.needsDrew (per-item shape)"]); |
| 199 | + }); |
| 200 | + |
127 | 201 | test("a fleet feed carrying the section still validates as a feed", () => { |
128 | 202 | const feed = { |
129 | 203 | version: 1, |
|