import type { Dataset, JobSummary, RunSummary, WorkflowInfo } from './types.ts' const base = Date.parse('2026-11-02T10:00:00Z') export function iso(minutes: number) { return new Date(base + minutes * 60000).toISOString() } let nextId = 1000 export function run(input: Partial & { at: number; wall: number }): RunSummary { const id = input.id ?? nextId++ return { id, workflowId: input.workflowId ?? 1, workflowName: input.workflowName ?? 'Validate', event: input.event ?? 'pull_request', headBranch: input.headBranch ?? 'feature', headSha: input.headSha ?? `sha${id}`, status: input.status ?? 'completed', conclusion: input.conclusion === undefined ? 'success' : input.conclusion, runAttempt: input.runAttempt ?? 1, createdAt: iso(input.at), runStartedAt: iso(input.at), updatedAt: iso(input.at + input.wall), prNumbers: input.prNumbers ?? [], } } export function job(input: { runId: number; name: string; at: number; queue?: number; duration: number; conclusion?: string; labels?: string[]; createdAt?: number; steps?: Array<[string, number]> }): JobSummary { const created = input.createdAt ?? input.at const started = created + (input.queue ?? 0) let cursor = started return { id: nextId++, runId: input.runId, name: input.name, conclusion: input.conclusion ?? 'success', status: 'completed', createdAt: iso(created), startedAt: iso(started), completedAt: iso(started + input.duration), labels: input.labels ?? ['ubuntu-latest'], runAttempt: 1, steps: (input.steps ?? []).map(([name, minutes]) => { const step = { name, conclusion: 'success', startedAt: iso(cursor), completedAt: iso(cursor + minutes) } cursor += minutes return step }), } } export function workflow(input: Partial & { runs: RunSummary[] }): WorkflowInfo { return { id: input.id ?? 1, name: input.name ?? 'Validate', path: input.path ?? '.github/workflows/validate.yml', state: 'active', totalInWindow: input.runs.length, runs: input.runs, listingScale: input.listingScale ?? 1, file: input.file ?? { hasPullRequestPaths: false, hasConcurrency: true, cancelInProgress: true }, } } export function dataset(input: Partial & { workflows: WorkflowInfo[] }): Dataset { return { repo: 'acme/widgets', defaultBranch: 'main', since: '2026-10-28T00:00:00.000Z', until: '2026-11-04T00:00:00.000Z', jobsByRun: {}, previousAttemptJobs: {}, timing: {}, caches: [], prFiles: {}, apiCalls: 10, maxApiCalls: 450, notes: [], ...input, } } /** A typical PR run: setup-heavy node shards, a slow windows install, and a short gate. */ export function typicalRun(runId: number, at: number, overrides: { nodeConclusion?: string } = {}) { return [ job({ runId, name: 'Node (1/2)', at, duration: 9, steps: [['🧰 Setup', 0.6], ['🧪 Node unit tests', 8]], conclusion: overrides.nodeConclusion }), job({ runId, name: 'Node (2/2)', at, duration: 10, steps: [['🧰 Setup', 0.6], ['🧪 Node unit tests', 9]] }), job({ runId, name: 'Static', at, duration: 3, steps: [['🧰 Setup', 0.5], ['Lint', 2]] }), job({ runId, name: 'CLI (windows-11-arm)', at, queue: 0.3, duration: 8, labels: ['windows-11-arm'], steps: [['📥 Install deps', 6], ['CLI validate', 1.5]] }), job({ runId, name: 'CLI (windows-latest)', at, queue: 0.3, duration: 2, labels: ['windows-latest'], steps: [['📥 Install deps', 0.7], ['CLI validate', 1]] }), job({ runId, name: '✅ Validate', at, createdAt: at + 10, duration: 0.1, conclusion: overrides.nodeConclusion ? 'failure' : 'success' }), ] }