The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import * as Schema from "effect/Schema"; |
| 2 | import { compileTagsFilter } from "./Tags.ts"; |
| 3 | |
| 4 | const Branch = Schema.Struct({ |
| 5 | /** Tag expressions are ANDed, just like repeated --tags flags. Empty selects all. */ |
| 6 | tags: Schema.Array(Schema.String), |
| 7 | concurrency: Schema.optional( |
| 8 | Schema.Union([Schema.Int.check(Schema.isGreaterThan(0)), Schema.Literal("unbounded")]), |
| 9 | ), |
| 10 | }); |
| 11 | const Plan = Schema.Array( |
| 12 | Schema.Union([Branch, Schema.Array(Branch).check(Schema.isMinLength(1))]), |
| 13 | ).check(Schema.isMinLength(1)); |
| 14 | |
| 15 | export type TestPlan = typeof Plan.Type; |
| 16 | |
| 17 | /** Parse before collection so an invalid plan cannot trigger test imports. */ |
| 18 | export const parsePlan = (json: string): TestPlan => { |
| 19 | try { |
| 20 | const plan = Schema.decodeUnknownSync(Plan, { onExcessProperty: "error" })(JSON.parse(json)); |
| 21 | for (const phase of plan) { |
| 22 | for (const branch of Array.isArray(phase) ? phase : [phase]) { |
| 23 | compileTagsFilter(branch.tags); |
| 24 | } |
| 25 | } |
| 26 | return plan; |
| 27 | } catch (cause) { |
| 28 | throw new Error(`Invalid --plan: ${cause instanceof Error ? cause.message : String(cause)}`); |
| 29 | } |
| 30 | }; |
| 31 | |
| 32 | /** Shared plain/TUI/log representation of a dry-run plan. */ |
| 33 | export const formatPlanPreview = ( |
| 34 | phases: Extract<import("./Reporter.ts").TestEvent, { _tag: "PlanPreview" }>["phases"], |
| 35 | ): string => |
| 36 | [ |
| 37 | "Dry run — no tests or hooks executed", |
| 38 | ...phases.flatMap((branches, index) => [ |
| 39 | `Phase ${index + 1}${branches.length > 1 ? " (parallel)" : ""}:`, |
| 40 | ...branches.map( |
| 41 | (branch, i) => |
| 42 | ` Branch ${i + 1}: tags=${JSON.stringify(branch.tags)}, concurrency=${branch.concurrency} — ${branch.tests} tests in ${branch.files} files${branch.skipped ? ` (${branch.skipped} skipped/todo)` : ""}`, |
| 43 | ), |
| 44 | ]), |
| 45 | ].join("\n"); |