teqo-backup/scripts/test-affected.mjs
Francisco Ignácio Fontoura Solla 2e0cc2c03e chore(ci): parallel PR jobs, affected tests, push gate, owner-of-red-CI policy
- ci-pr.yml: split the serial checks job into parallel lint/format/
  typecheck/knip/cycles + unit/int (vitest --changed vs PR base via
  scripts/test-affected.mjs, full fallback on high-risk paths) + e2e
  (manifest path->spec via scripts/e2e-affected.mjs, blocking) + build;
  migration-lock gains checkout + pull-requests:read (fixes the failures
  that blocked PR #50)
- ci.yml (main): full safety net — seed:minimal + int full + build + e2e
- package.json: gate:fast / gate:push; .husky/pre-push runs gate:push
- docs: "Dono do PR, dono do CI" policy in AGENT-OPS + work-issue +
  engineering-standards; changelog entry; plans for OPS3-OPS7
2026-07-30 17:37:20 -03:00

39 lines
1.3 KiB
JavaScript

#!/usr/bin/env node
/**
* test-affected (OPS5) — decides the vitest scope for a PR diff and prints it
* as JSON on stdout: { mode, reason, base }.
*
* mode=full → run the whole suite (high-risk path / new src file)
* mode=changed → run `vitest --changed <base>`
* mode=none → nothing to run (docs-only diff); CI skips the step
*
* Base ref: $GITHUB_BASE_REF (PR target) or origin/stage locally. No DB, no
* Payload — pure git + the pure core in scripts/lib/test-affected-core.mjs.
*/
import { execFileSync } from 'node:child_process'
import { classifyTestScope } from './lib/test-affected-core.mjs'
const base = `origin/${process.env.GITHUB_BASE_REF ?? 'stage'}`
let mergeBase
try {
mergeBase = execFileSync('git', ['merge-base', 'HEAD', base], { encoding: 'utf8' }).trim()
} catch {
const result = { mode: 'full', reason: `no merge-base with ${base} (shallow clone?)`, base }
console.log(JSON.stringify(result))
process.exit(0)
}
const raw = execFileSync('git', ['diff', '--name-status', `${mergeBase}...HEAD`], {
encoding: 'utf8',
})
const files = raw
.split('\n')
.filter(Boolean)
.map((line) => {
const [status, path] = line.split('\t')
return { status, path }
})
console.log(JSON.stringify({ ...classifyTestScope(files), base }))