|
| 1 | +const fs = require("node:fs"); |
| 2 | +const path = require("node:path"); |
| 3 | + |
| 4 | +const WORKFLOW = ".github/workflows/closura-arc-ci.yml"; |
| 5 | +const REQUIRED_CHECK = "Voice + founder inbox (Linux ARC)"; |
| 6 | +const WORKERS = ["voice-and-inbox-core", "voice-and-inbox-web", "voice-and-inbox-mobile"]; |
| 7 | + |
| 8 | +// Every test the single serial job ran before the split. A parallel job that |
| 9 | +// drops one of these makes the required check pass without running it. |
| 10 | +const REQUIRED_TESTS = [ |
| 11 | + "apps/server/src/speech/CloudSpeech.test.ts", |
| 12 | + "apps/server/src/speech/GroqSpeechStream.test.ts", |
| 13 | + "apps/server/src/speech/stream.test.ts", |
| 14 | + "packages/contracts/src/threadInbox.test.ts", |
| 15 | + "packages/contracts/src/threadInbox.invariants.test.ts", |
| 16 | + "packages/contracts/src/threadInbox.upgrade.test.ts", |
| 17 | + "packages/contracts/src/threadMetadataMcp.test.ts", |
| 18 | + "apps/web/src/components/threadActionMenu.logic.test.ts", |
| 19 | + "apps/web/src/components/sidebar/threadListFilter.logic.test.ts", |
| 20 | + "packages/client-runtime/src/state/threadAttribution.test.ts", |
| 21 | + "apps/server/src/orchestration-v2/ThreadLaunchService.test.ts", |
| 22 | + "apps/server/src/orchestration-v2/SubagentProjection.test.ts", |
| 23 | + "apps/server/src/orchestration-v2/ModelAlertReactor.test.ts", |
| 24 | + "apps/server/src/orchestration-v2/ThreadEventAlerts.test.ts", |
| 25 | + "apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts", |
| 26 | + "packages/shared/src/threadPlacement.test.ts", |
| 27 | + "apps/server/src/peer/RemoteDelegation.test.ts", |
| 28 | + "apps/server/src/mcp/OrchestratorMcpService.test.ts", |
| 29 | + "apps/server/src/cli/thread.test.ts", |
| 30 | + "apps/web/src/composerDraftStore.test.ts", |
| 31 | + "packages/client-runtime/src/voice-input/controller.test.ts", |
| 32 | + "apps/web/src/components/chat/composerSend.logic.test.ts", |
| 33 | + "apps/web/src/components/chat/chatViewSend.test.ts", |
| 34 | + "apps/web/src/components/chat/composerImagePersistence.test.ts", |
| 35 | + "apps/web/src/components/chat/draftPlacement.test.ts", |
| 36 | + "apps/web/src/components/chat/draftAttachmentUploads.test.ts", |
| 37 | + "apps/web/src/components/chat/draftUploadReconcile.test.ts", |
| 38 | + "apps/web/src/lib/attachmentUploadQueue.test.ts", |
| 39 | + "apps/server/src/ws.test.ts", |
| 40 | + "packages/contracts/src/environment.test.ts", |
| 41 | + "scripts/feature-map.test.ts", |
| 42 | + "apps/mobile/src/state/thread-placement.model.test.ts", |
| 43 | + "apps/mobile/src/state/threadOutboxDelivery.placement.test.ts", |
| 44 | + "apps/mobile/src/state/composer-attachment-uploads.test.ts", |
| 45 | + "apps/mobile/src/lib/composerAttachmentUploadQueue.test.ts", |
| 46 | + "apps/mobile/src/lib/attachmentUpload.test.ts", |
| 47 | + "apps/mobile/src/state/use-composer-drafts.test.ts", |
| 48 | + "apps/mobile/src/state/thread-outbox.test.ts", |
| 49 | + "apps/mobile/src/state/threadOutboxDelivery.permissions.test.ts", |
| 50 | + "apps/mobile/src/state/threadOutboxDelivery.test.ts", |
| 51 | + "apps/mobile/src/state/pending-thread-creation.test.ts", |
| 52 | + "apps/mobile/src/lib/projectThreadStartTurn.test.ts", |
| 53 | + "apps/mobile/src/features/threads/thread-route-state.test.ts", |
| 54 | + "apps/mobile/src/features/threads/new-task-flow-provider.test.tsx", |
| 55 | + "apps/mobile/src/features/home/pendingTaskRoute.test.tsx", |
| 56 | + "apps/mobile/src/features/threads/NewTaskDraftRouteScreen.test.tsx", |
| 57 | + "apps/web/src/speech/voiceInputLatency.browser.test.ts", |
| 58 | + "apps/web/src/speech/useEnvironmentSpeechInput.browser.test.tsx", |
| 59 | +]; |
| 60 | + |
| 61 | +function unquote(value) { |
| 62 | + const trimmed = value.trim(); |
| 63 | + if ( |
| 64 | + (trimmed.startsWith('"') && trimmed.endsWith('"')) || |
| 65 | + (trimmed.startsWith("'") && trimmed.endsWith("'")) |
| 66 | + ) { |
| 67 | + return trimmed.slice(1, -1); |
| 68 | + } |
| 69 | + return trimmed; |
| 70 | +} |
| 71 | + |
| 72 | +// Workflow files are small and this only needs the step structure, so a flat |
| 73 | +// scan beats pulling in a YAML parser. It tracks job ids, job names, `needs`, |
| 74 | +// and the `run` / `working-directory` pairs inside each job's steps. |
| 75 | +function parseWorkflow(source) { |
| 76 | + const jobs = {}; |
| 77 | + let current = null; |
| 78 | + let inRun = false; |
| 79 | + let runIndent = 0; |
| 80 | + let inTriggers = true; |
| 81 | + const lines = source.split("\n"); |
| 82 | + for (const line of lines) { |
| 83 | + if (inRun) { |
| 84 | + const indent = line.match(/^\s*/)[0].length; |
| 85 | + if (line.trim() !== "" && indent <= runIndent) inRun = false; |
| 86 | + else { |
| 87 | + current.run.push(line.trim().replace(/\\$/, "").trim()); |
| 88 | + continue; |
| 89 | + } |
| 90 | + } |
| 91 | + if (inTriggers) { |
| 92 | + if (line === "jobs:") inTriggers = false; |
| 93 | + continue; |
| 94 | + } |
| 95 | + const job = line.match(/^ {2}([\w-]+):\s*$/); |
| 96 | + if (job) { |
| 97 | + current = { id: job[1], name: null, needs: [], condition: null, steps: [] }; |
| 98 | + jobs[current.id] = current; |
| 99 | + continue; |
| 100 | + } |
| 101 | + if (!current) continue; |
| 102 | + const condition = line.match(/^ {4}if:\s*(.+)$/); |
| 103 | + if (condition && current.condition === null && current.steps.length === 0) { |
| 104 | + current.condition = unquote(condition[1]); |
| 105 | + continue; |
| 106 | + } |
| 107 | + if (!current) continue; |
| 108 | + const name = line.match(/^ {4}name:\s*(.+)$/); |
| 109 | + if (name) { |
| 110 | + current.name = unquote(name[1]); |
| 111 | + continue; |
| 112 | + } |
| 113 | + const needs = line.match(/^ {4}needs:\s*\[([^\]]*)\]/); |
| 114 | + if (needs) { |
| 115 | + current.needs = needs[1] |
| 116 | + .split(",") |
| 117 | + .map((item) => unquote(item)) |
| 118 | + .filter(Boolean); |
| 119 | + continue; |
| 120 | + } |
| 121 | + const directory = line.match(/^ {8}working-directory:\s*(.+)$/); |
| 122 | + if (directory) { |
| 123 | + current.directory = unquote(directory[1]); |
| 124 | + continue; |
| 125 | + } |
| 126 | + const run = line.match(/^ {8}run:\s*(\||>)?\s*$/); |
| 127 | + if (run) { |
| 128 | + const step = { directory: current.directory ?? "", run: [] }; |
| 129 | + current.steps.push(step); |
| 130 | + current.run = step.run; |
| 131 | + current.directory = ""; |
| 132 | + inRun = true; |
| 133 | + runIndent = 8; |
| 134 | + } |
| 135 | + } |
| 136 | + return jobs; |
| 137 | +} |
| 138 | + |
| 139 | +// A test path only counts when a worker actually invokes it. A path that only |
| 140 | +// appears inside a comment or a branch that never runs would otherwise let the |
| 141 | +// guard pass while the required check runs nothing. |
| 142 | +function testsIn(job) { |
| 143 | + const found = []; |
| 144 | + for (const step of job.steps) { |
| 145 | + const prefix = step.directory ? `${step.directory}/` : ""; |
| 146 | + let skipping = false; |
| 147 | + for (const line of step.run) { |
| 148 | + if (/^(?:if\s+false\b|exit\b)/.test(line)) skipping = true; |
| 149 | + else if (skipping && /^(?:fi|else|elif)\b/.test(line)) skipping = false; |
| 150 | + if (skipping || line.startsWith("#")) continue; |
| 151 | + if (/^[\w./-]+\.(ts|tsx)$/.test(line)) found.push(prefix + line); |
| 152 | + } |
| 153 | + } |
| 154 | + return found; |
| 155 | +} |
| 156 | + |
| 157 | +function jobBody(source, id) { |
| 158 | + const marker = `\n ${id}:`; |
| 159 | + const start = source.indexOf(marker); |
| 160 | + if (start < 0) return ""; |
| 161 | + const rest = source.slice(start + marker.length); |
| 162 | + const next = rest.search(/\n {2}[\w-]+:\s*\n/); |
| 163 | + return next < 0 ? rest : rest.slice(0, next); |
| 164 | +} |
| 165 | + |
| 166 | +function checkCoverage(source) { |
| 167 | + const jobs = parseWorkflow(source); |
| 168 | + const problems = []; |
| 169 | + const aggregator = jobs["voice-and-inbox"]; |
| 170 | + if (!aggregator) problems.push("missing voice-and-inbox job"); |
| 171 | + else { |
| 172 | + if (aggregator.name !== REQUIRED_CHECK) { |
| 173 | + problems.push(`required check is named ${JSON.stringify(aggregator.name)}`); |
| 174 | + } |
| 175 | + const needs = [...aggregator.needs].sort(); |
| 176 | + if (needs.join() !== [...WORKERS].sort().join()) { |
| 177 | + problems.push(`aggregator needs ${needs.join(", ") || "nothing"}`); |
| 178 | + } |
| 179 | + // `always()` is true for a cancelled run, and a worker that never started |
| 180 | + // reports success, so the required check would pass with nothing tested. |
| 181 | + if (!aggregator.condition || !aggregator.condition.includes("!cancelled()")) { |
| 182 | + problems.push("aggregator runs when the workflow is cancelled"); |
| 183 | + } |
| 184 | + // The ARC image has no node on PATH. setup-node downloads an official |
| 185 | + // Node 26 binary that needs libatomic, so both have to run first. |
| 186 | + const body = jobBody(source, "voice-and-inbox"); |
| 187 | + const libatomic = body.indexOf("uses: ./.github/actions/provide-libatomic"); |
| 188 | + const setupNode = body.indexOf("uses: actions/setup-node@"); |
| 189 | + const guard = body.indexOf("run: node .github/scripts/arc-ci-coverage.cjs"); |
| 190 | + if ( |
| 191 | + libatomic < 0 || |
| 192 | + setupNode < 0 || |
| 193 | + guard < 0 || |
| 194 | + !(libatomic < setupNode && setupNode < guard) |
| 195 | + ) { |
| 196 | + problems.push("coverage guard runs before Node is on PATH"); |
| 197 | + } |
| 198 | + } |
| 199 | + const ran = []; |
| 200 | + for (const id of WORKERS) { |
| 201 | + if (!jobs[id]) { |
| 202 | + problems.push(`missing worker ${id}`); |
| 203 | + continue; |
| 204 | + } |
| 205 | + ran.push(...testsIn(jobs[id])); |
| 206 | + } |
| 207 | + const ranSet = new Set(ran); |
| 208 | + for (const test of REQUIRED_TESTS) { |
| 209 | + if (!ranSet.has(test)) problems.push(`no worker runs ${test}`); |
| 210 | + } |
| 211 | + const duplicates = ran.filter((test, index) => ran.indexOf(test) !== index); |
| 212 | + for (const test of new Set(duplicates)) problems.push(`run twice: ${test}`); |
| 213 | + return problems; |
| 214 | +} |
| 215 | + |
| 216 | +module.exports = { REQUIRED_CHECK, REQUIRED_TESTS, WORKERS, checkCoverage, parseWorkflow }; |
| 217 | + |
| 218 | +if (require.main === module) { |
| 219 | + const root = process.argv[2] ?? process.cwd(); |
| 220 | + const source = fs.readFileSync(path.join(root, WORKFLOW), "utf8"); |
| 221 | + const problems = checkCoverage(source); |
| 222 | + if (problems.length > 0) { |
| 223 | + for (const problem of problems) process.stderr.write(`${problem}\n`); |
| 224 | + process.exit(1); |
| 225 | + } |
| 226 | + process.stdout.write( |
| 227 | + `${REQUIRED_CHECK} covers ${REQUIRED_TESTS.length} tests across ${WORKERS.length} workers\n`, |
| 228 | + ); |
| 229 | +} |
0 commit comments