- 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
87 lines
3 KiB
TypeScript
87 lines
3 KiB
TypeScript
// @vitest-environment node
|
|
|
|
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
classifyTestScope,
|
|
HIGH_RISK_EXACT,
|
|
HIGH_RISK_PREFIXES,
|
|
selectE2eSpecs,
|
|
} from '../../scripts/lib/test-affected-core.mjs'
|
|
|
|
const changed = (path: string) => ({ path, status: 'M' })
|
|
|
|
describe('classifyTestScope (OPS5)', () => {
|
|
it('runs the full suite when a high-risk path changes', () => {
|
|
for (const path of [
|
|
'src/migrations/20260730_000000_x.ts',
|
|
'src/payload-types.ts',
|
|
'pnpm-lock.yaml',
|
|
'src/collections/Post.ts',
|
|
'scripts/lib/seed-minimal-manifest.mjs',
|
|
'tests/helpers/campaignFixtures.ts',
|
|
]) {
|
|
expect(classifyTestScope([changed(path)]).mode, path).toBe('full')
|
|
}
|
|
})
|
|
|
|
it('runs the full suite when a new src file appears', () => {
|
|
expect(classifyTestScope([{ path: 'src/utilities/newThing.ts', status: 'A' }]).mode).toBe(
|
|
'full',
|
|
)
|
|
})
|
|
|
|
it('selects vitest --changed for a plain src/tests diff', () => {
|
|
expect(classifyTestScope([changed('src/utilities/posts.ts')]).mode).toBe('changed')
|
|
expect(classifyTestScope([changed('tests/int/api.int.spec.ts')]).mode).toBe('changed')
|
|
})
|
|
|
|
it('skips tests for a docs-only diff', () => {
|
|
expect(classifyTestScope([changed('docs/AGENT-OPS.md'), changed('README.md')]).mode).toBe(
|
|
'none',
|
|
)
|
|
})
|
|
|
|
it('high-risk lists cover the harness files the CI relies on', () => {
|
|
expect(HIGH_RISK_EXACT.has('vitest.config.mts')).toBe(true)
|
|
expect(HIGH_RISK_EXACT.has('playwright.config.ts')).toBe(true)
|
|
expect(HIGH_RISK_PREFIXES).toContain('tests/e2e/fixtures/')
|
|
})
|
|
})
|
|
|
|
describe('selectE2eSpecs (OPS5)', () => {
|
|
const manifest = [
|
|
{ prefixes: ['src/components/campaign/municipality'], specs: ['campaignMunicipalities'] },
|
|
{ prefixes: ['src/app/(payload)'], specs: ['admin'] },
|
|
]
|
|
|
|
it('maps src prefixes to specs via the manifest', () => {
|
|
const result = selectE2eSpecs(
|
|
[changed('src/components/campaign/municipality/MunicipalityTable.tsx')],
|
|
manifest,
|
|
)
|
|
expect(result).toMatchObject({ mode: 'selected', specs: ['campaignMunicipalities'] })
|
|
})
|
|
|
|
it('runs a changed e2e spec directly', () => {
|
|
const result = selectE2eSpecs([changed('tests/e2e/campaignAuth.e2e.spec.ts')], manifest)
|
|
expect(result.mode).toBe('selected')
|
|
expect(result.specs).toContain('campaignAuth')
|
|
})
|
|
|
|
it('runs the full suite on high-risk paths', () => {
|
|
expect(selectE2eSpecs([changed('tests/e2e/fixtures/auth.ts')], manifest).mode).toBe('full')
|
|
expect(selectE2eSpecs([changed('src/migrations/x.ts')], manifest).mode).toBe('full')
|
|
})
|
|
|
|
it('reports unmapped src paths without failing and skips the run', () => {
|
|
const result = selectE2eSpecs([changed('src/utilities/brandNewModule.ts')], manifest)
|
|
expect(result.mode).toBe('none')
|
|
expect(result.unmapped).toEqual(['src/utilities/brandNewModule.ts'])
|
|
})
|
|
|
|
it('skips e2e for diffs with no src/e2e changes', () => {
|
|
const result = selectE2eSpecs([changed('docs/AGENT-OPS.md')], manifest)
|
|
expect(result).toMatchObject({ mode: 'none', specs: [], unmapped: [] })
|
|
})
|
|
})
|