|
| 1 | +/** |
| 2 | + * Task-Runner Review Skip Tests — TP-036 |
| 3 | + * |
| 4 | + * Tests for the low-risk step detection logic that skips plan and code |
| 5 | + * reviews for Step 0 (Preflight) and the final step (Delivery/Docs). |
| 6 | + * |
| 7 | + * Test categories: |
| 8 | + * 1.x — isLowRiskStep pure function (boundary detection) |
| 9 | + * 2.x — Review level interactions (level 0, 1, 2 with low-risk steps) |
| 10 | + * 3.x — Edge cases (single-step task, two-step task, large step counts) |
| 11 | + * |
| 12 | + * Run: npx vitest run tests/task-runner-review-skip.test.ts |
| 13 | + */ |
| 14 | + |
| 15 | +import { describe, it, expect } from "vitest"; |
| 16 | +import { isLowRiskStep } from "../task-runner.ts"; |
| 17 | + |
| 18 | +// ══════════════════════════════════════════════════════════════════════ |
| 19 | +// 1.x — isLowRiskStep pure function |
| 20 | +// ══════════════════════════════════════════════════════════════════════ |
| 21 | + |
| 22 | +describe("1.x: isLowRiskStep boundary detection", () => { |
| 23 | + // ── Standard 4-step task (Steps 0, 1, 2, 3) ───────────────────── |
| 24 | + |
| 25 | + it("1.1: Step 0 in a 4-step task → low-risk (Preflight)", () => { |
| 26 | + expect(isLowRiskStep(0, 4)).toBe(true); |
| 27 | + }); |
| 28 | + |
| 29 | + it("1.2: Step 3 (last) in a 4-step task → low-risk (final step)", () => { |
| 30 | + expect(isLowRiskStep(3, 4)).toBe(true); |
| 31 | + }); |
| 32 | + |
| 33 | + it("1.3: Step 1 in a 4-step task → NOT low-risk (middle step)", () => { |
| 34 | + expect(isLowRiskStep(1, 4)).toBe(false); |
| 35 | + }); |
| 36 | + |
| 37 | + it("1.4: Step 2 in a 4-step task → NOT low-risk (middle step)", () => { |
| 38 | + expect(isLowRiskStep(2, 4)).toBe(false); |
| 39 | + }); |
| 40 | + |
| 41 | + // ── Review level 2 interactions ────────────────────────────────── |
| 42 | + // The review decision logic uses isLowRiskStep to gate BOTH plan |
| 43 | + // and code reviews. Verify that: |
| 44 | + // - review level ≥ 1: plan review gated by isLowRiskStep |
| 45 | + // - review level ≥ 2: code review gated by isLowRiskStep |
| 46 | + // Since the gating is: if (reviewLevel >= N) { if (isLowRiskStep) skip; else review; } |
| 47 | + // the pure function test verifies the correct inputs produce the right skip decision. |
| 48 | + |
| 49 | + it("1.5: Step 0 at review level 2 — both plan and code reviews should skip", () => { |
| 50 | + // isLowRiskStep returns true → both plan (level≥1) and code (level≥2) skip |
| 51 | + const reviewLevel = 2; |
| 52 | + const skip = isLowRiskStep(0, 4); |
| 53 | + expect(skip).toBe(true); |
| 54 | + // Plan review: reviewLevel >= 1 && skip → skipped ✓ |
| 55 | + // Code review: reviewLevel >= 2 && skip → skipped ✓ |
| 56 | + expect(reviewLevel >= 1 && skip).toBe(true); |
| 57 | + expect(reviewLevel >= 2 && skip).toBe(true); |
| 58 | + }); |
| 59 | + |
| 60 | + it("1.6: Final step at review level 2 — both plan and code reviews should skip", () => { |
| 61 | + const reviewLevel = 2; |
| 62 | + const skip = isLowRiskStep(3, 4); |
| 63 | + expect(skip).toBe(true); |
| 64 | + expect(reviewLevel >= 1 && skip).toBe(true); |
| 65 | + expect(reviewLevel >= 2 && skip).toBe(true); |
| 66 | + }); |
| 67 | + |
| 68 | + it("1.7: Middle step at review level 2 — reviews should NOT skip", () => { |
| 69 | + const reviewLevel = 2; |
| 70 | + const skip = isLowRiskStep(1, 4); |
| 71 | + expect(skip).toBe(false); |
| 72 | + // Plan review: reviewLevel >= 1 && !skip → review runs ✓ |
| 73 | + // Code review: reviewLevel >= 2 && !skip → review runs ✓ |
| 74 | + expect(reviewLevel >= 1 && !skip).toBe(true); |
| 75 | + expect(reviewLevel >= 2 && !skip).toBe(true); |
| 76 | + }); |
| 77 | + |
| 78 | + // ── Review level 0 (all reviews disabled) ──────────────────────── |
| 79 | + |
| 80 | + it("1.8: Review level 0 — no reviews regardless of step position", () => { |
| 81 | + const reviewLevel = 0; |
| 82 | + // Even if isLowRiskStep returns true, level 0 means no reviews at all |
| 83 | + // The outer gate: if (reviewLevel >= 1) never fires |
| 84 | + expect(reviewLevel >= 1).toBe(false); |
| 85 | + expect(reviewLevel >= 2).toBe(false); |
| 86 | + // isLowRiskStep is never consulted, but let's verify it still works |
| 87 | + expect(isLowRiskStep(0, 4)).toBe(true); |
| 88 | + expect(isLowRiskStep(1, 4)).toBe(false); |
| 89 | + expect(isLowRiskStep(3, 4)).toBe(true); |
| 90 | + }); |
| 91 | + |
| 92 | + // ── Review level 1 (plan only) ────────────────────────────────── |
| 93 | + |
| 94 | + it("1.9: Review level 1, Step 0 — plan review skipped, no code review", () => { |
| 95 | + const reviewLevel = 1; |
| 96 | + const skip = isLowRiskStep(0, 4); |
| 97 | + expect(reviewLevel >= 1 && skip).toBe(true); // plan review gate → skip |
| 98 | + expect(reviewLevel >= 2).toBe(false); // code review gate never fires |
| 99 | + }); |
| 100 | + |
| 101 | + it("1.10: Review level 1, middle step — plan review runs, no code review", () => { |
| 102 | + const reviewLevel = 1; |
| 103 | + const skip = isLowRiskStep(2, 4); |
| 104 | + expect(reviewLevel >= 1 && !skip).toBe(true); // plan review runs |
| 105 | + expect(reviewLevel >= 2).toBe(false); // code review gate never fires |
| 106 | + }); |
| 107 | +}); |
| 108 | + |
| 109 | +// ══════════════════════════════════════════════════════════════════════ |
| 110 | +// 2.x — Edge cases |
| 111 | +// ══════════════════════════════════════════════════════════════════════ |
| 112 | + |
| 113 | +describe("2.x: Edge cases", () => { |
| 114 | + it("2.1: Single-step task — Step 0 is both first AND last → low-risk", () => { |
| 115 | + // totalSteps=1, lastStepIndex=0, stepNumber=0 matches both conditions |
| 116 | + expect(isLowRiskStep(0, 1)).toBe(true); |
| 117 | + }); |
| 118 | + |
| 119 | + it("2.2: Two-step task — Step 0 is low-risk", () => { |
| 120 | + expect(isLowRiskStep(0, 2)).toBe(true); |
| 121 | + }); |
| 122 | + |
| 123 | + it("2.3: Two-step task — Step 1 (last) is low-risk", () => { |
| 124 | + expect(isLowRiskStep(1, 2)).toBe(true); |
| 125 | + }); |
| 126 | + |
| 127 | + it("2.4: Two-step task — both steps are low-risk (no middle steps)", () => { |
| 128 | + // In a 2-step task, Step 0 is first and Step 1 is last |
| 129 | + // No middle steps exist — all reviews would be skipped |
| 130 | + expect(isLowRiskStep(0, 2)).toBe(true); |
| 131 | + expect(isLowRiskStep(1, 2)).toBe(true); |
| 132 | + }); |
| 133 | + |
| 134 | + it("2.5: Three-step task — only Step 1 is NOT low-risk", () => { |
| 135 | + expect(isLowRiskStep(0, 3)).toBe(true); // first |
| 136 | + expect(isLowRiskStep(1, 3)).toBe(false); // middle |
| 137 | + expect(isLowRiskStep(2, 3)).toBe(true); // last |
| 138 | + }); |
| 139 | + |
| 140 | + it("2.6: Large task (10 steps) — only first and last are low-risk", () => { |
| 141 | + expect(isLowRiskStep(0, 10)).toBe(true); // first |
| 142 | + expect(isLowRiskStep(9, 10)).toBe(true); // last |
| 143 | + // All middle steps |
| 144 | + for (let i = 1; i < 9; i++) { |
| 145 | + expect(isLowRiskStep(i, 10)).toBe(false); |
| 146 | + } |
| 147 | + }); |
| 148 | + |
| 149 | + it("2.7: Zero totalSteps → false (defensive)", () => { |
| 150 | + expect(isLowRiskStep(0, 0)).toBe(false); |
| 151 | + }); |
| 152 | + |
| 153 | + it("2.8: Negative totalSteps → false (defensive)", () => { |
| 154 | + expect(isLowRiskStep(0, -1)).toBe(false); |
| 155 | + }); |
| 156 | +}); |
| 157 | + |
| 158 | +// ══════════════════════════════════════════════════════════════════════ |
| 159 | +// 3.x — Integration: review gating decision matrix |
| 160 | +// ══════════════════════════════════════════════════════════════════════ |
| 161 | + |
| 162 | +describe("3.x: Review gating decision matrix", () => { |
| 163 | + // This simulates the full decision logic from task-runner.ts: |
| 164 | + // Plan review: if (reviewLevel >= 1) { if (isLowRisk) skip; else review; } |
| 165 | + // Code review: if (reviewLevel >= 2) { if (isLowRisk) skip; else review; } |
| 166 | + |
| 167 | + type ReviewDecision = "skip" | "review" | "no-gate"; |
| 168 | + |
| 169 | + function planReviewDecision(reviewLevel: number, stepNumber: number, totalSteps: number): ReviewDecision { |
| 170 | + if (reviewLevel < 1) return "no-gate"; |
| 171 | + return isLowRiskStep(stepNumber, totalSteps) ? "skip" : "review"; |
| 172 | + } |
| 173 | + |
| 174 | + function codeReviewDecision(reviewLevel: number, stepNumber: number, totalSteps: number): ReviewDecision { |
| 175 | + if (reviewLevel < 2) return "no-gate"; |
| 176 | + return isLowRiskStep(stepNumber, totalSteps) ? "skip" : "review"; |
| 177 | + } |
| 178 | + |
| 179 | + // ── Level 0: no reviews at all ────────────────────────────────── |
| 180 | + |
| 181 | + it("3.1: Level 0, Step 0 — no plan review, no code review", () => { |
| 182 | + expect(planReviewDecision(0, 0, 4)).toBe("no-gate"); |
| 183 | + expect(codeReviewDecision(0, 0, 4)).toBe("no-gate"); |
| 184 | + }); |
| 185 | + |
| 186 | + it("3.2: Level 0, middle step — no plan review, no code review", () => { |
| 187 | + expect(planReviewDecision(0, 2, 4)).toBe("no-gate"); |
| 188 | + expect(codeReviewDecision(0, 2, 4)).toBe("no-gate"); |
| 189 | + }); |
| 190 | + |
| 191 | + it("3.3: Level 0, final step — no plan review, no code review", () => { |
| 192 | + expect(planReviewDecision(0, 3, 4)).toBe("no-gate"); |
| 193 | + expect(codeReviewDecision(0, 3, 4)).toBe("no-gate"); |
| 194 | + }); |
| 195 | + |
| 196 | + // ── Level 1: plan reviews only ────────────────────────────────── |
| 197 | + |
| 198 | + it("3.4: Level 1, Step 0 — plan review SKIPPED, no code review gate", () => { |
| 199 | + expect(planReviewDecision(1, 0, 4)).toBe("skip"); |
| 200 | + expect(codeReviewDecision(1, 0, 4)).toBe("no-gate"); |
| 201 | + }); |
| 202 | + |
| 203 | + it("3.5: Level 1, middle step — plan review RUNS, no code review gate", () => { |
| 204 | + expect(planReviewDecision(1, 1, 4)).toBe("review"); |
| 205 | + expect(codeReviewDecision(1, 1, 4)).toBe("no-gate"); |
| 206 | + }); |
| 207 | + |
| 208 | + it("3.6: Level 1, final step — plan review SKIPPED, no code review gate", () => { |
| 209 | + expect(planReviewDecision(1, 3, 4)).toBe("skip"); |
| 210 | + expect(codeReviewDecision(1, 3, 4)).toBe("no-gate"); |
| 211 | + }); |
| 212 | + |
| 213 | + // ── Level 2: plan + code reviews ──────────────────────────────── |
| 214 | + |
| 215 | + it("3.7: Level 2, Step 0 — plan review SKIPPED, code review SKIPPED", () => { |
| 216 | + expect(planReviewDecision(2, 0, 4)).toBe("skip"); |
| 217 | + expect(codeReviewDecision(2, 0, 4)).toBe("skip"); |
| 218 | + }); |
| 219 | + |
| 220 | + it("3.8: Level 2, middle step — plan review RUNS, code review RUNS", () => { |
| 221 | + expect(planReviewDecision(2, 1, 4)).toBe("review"); |
| 222 | + expect(codeReviewDecision(2, 1, 4)).toBe("review"); |
| 223 | + }); |
| 224 | + |
| 225 | + it("3.9: Level 2, final step — plan review SKIPPED, code review SKIPPED", () => { |
| 226 | + expect(planReviewDecision(2, 3, 4)).toBe("skip"); |
| 227 | + expect(codeReviewDecision(2, 3, 4)).toBe("skip"); |
| 228 | + }); |
| 229 | + |
| 230 | + // ── Level 2, single-step task ─────────────────────────────────── |
| 231 | + |
| 232 | + it("3.10: Level 2, single step (Step 0 is also final) — all reviews SKIPPED", () => { |
| 233 | + expect(planReviewDecision(2, 0, 1)).toBe("skip"); |
| 234 | + expect(codeReviewDecision(2, 0, 1)).toBe("skip"); |
| 235 | + }); |
| 236 | + |
| 237 | + // ── Level 3+ (future-proofing) ────────────────────────────────── |
| 238 | + |
| 239 | + it("3.11: Level 3, Step 0 — both reviews still skip (higher levels don't change skip logic)", () => { |
| 240 | + expect(planReviewDecision(3, 0, 4)).toBe("skip"); |
| 241 | + expect(codeReviewDecision(3, 0, 4)).toBe("skip"); |
| 242 | + }); |
| 243 | + |
| 244 | + it("3.12: Level 3, middle step — both reviews run", () => { |
| 245 | + expect(planReviewDecision(3, 1, 4)).toBe("review"); |
| 246 | + expect(codeReviewDecision(3, 1, 4)).toBe("review"); |
| 247 | + }); |
| 248 | +}); |
0 commit comments