|
| 1 | +#!/usr/bin/env node |
| 2 | +// Runs one named vitest batch with an explicit file list so the batches do |
| 3 | +// not depend on shell glob expansion (npm runs scripts through cmd.exe on |
| 4 | +// Windows, which leaves *.test.ts untouched and vitest then finds nothing). |
| 5 | +import { spawnSync } from "node:child_process"; |
| 6 | +import { globSync } from "glob"; |
| 7 | + |
| 8 | +const BATCHES = { |
| 9 | + core: ["tests/rules/*.test.ts", "tests/scanner/*.test.ts", "tests/reporter/*.test.ts"], |
| 10 | + analysis: [ |
| 11 | + "tests/integration.test.ts", |
| 12 | + "tests/injection.test.ts", |
| 13 | + "tests/action.test.ts", |
| 14 | + "tests/action-policy.test.ts", |
| 15 | + "tests/action-supply-chain.test.ts", |
| 16 | + "tests/action-hardening.test.ts", |
| 17 | + "tests/action-promotion.test.ts", |
| 18 | + ], |
| 19 | + "miniclaw-a": ["tests/miniclaw/index.test.ts", "tests/miniclaw/server.test.ts"], |
| 20 | + "miniclaw-b": ["tests/miniclaw/cli.test.ts", "tests/miniclaw/sandbox.test.ts"], |
| 21 | + misc: [ |
| 22 | + "tests/corpus.test.ts", |
| 23 | + "tests/logger.test.ts", |
| 24 | + "tests/init/init.test.ts", |
| 25 | + "tests/taint/taint.test.ts", |
| 26 | + "tests/opus/*.test.ts", |
| 27 | + "tests/fixer/*.test.ts", |
| 28 | + "tests/types.test.ts", |
| 29 | + "tests/skills/*.test.ts", |
| 30 | + "tests/llm/*.test.ts", |
| 31 | + "tests/compliance/*.test.ts", |
| 32 | + "tests/miniclaw/router.test.ts", |
| 33 | + "tests/miniclaw/tools.test.ts", |
| 34 | + "tests/miniclaw/types.test.ts", |
| 35 | + "tests/sandbox/sandbox.test.ts", |
| 36 | + "tests/threat-intel/*.test.ts", |
| 37 | + "tests/watch/*.test.ts", |
| 38 | + "tests/runtime/*.test.ts", |
| 39 | + "tests/baseline/*.test.ts", |
| 40 | + "tests/evidence-pack/*.test.ts", |
| 41 | + "tests/supply-chain/*.test.ts", |
| 42 | + "tests/policy/*.test.ts", |
| 43 | + "tests/sponsor-surface.test.ts", |
| 44 | + ], |
| 45 | +}; |
| 46 | + |
| 47 | +const name = process.argv[2]; |
| 48 | +const patterns = BATCHES[name]; |
| 49 | +if (!patterns) { |
| 50 | + console.error(`Unknown test batch "${name}". Known: ${Object.keys(BATCHES).join(", ")}`); |
| 51 | + process.exit(2); |
| 52 | +} |
| 53 | + |
| 54 | +const files = [...new Set(patterns.flatMap((pattern) => globSync(pattern, { posix: true })))].sort(); |
| 55 | +if (files.length === 0) { |
| 56 | + console.error(`Batch "${name}" matched no test files.`); |
| 57 | + process.exit(1); |
| 58 | +} |
| 59 | + |
| 60 | +const vitest = process.platform === "win32" ? "npx.cmd" : "npx"; |
| 61 | +const result = spawnSync(vitest, ["vitest", "run", ...files], { stdio: "inherit", shell: process.platform === "win32" }); |
| 62 | +process.exit(result.status ?? 1); |
0 commit comments