|
| 1 | +import { execFileSync } from 'node:child_process'; |
| 2 | +import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'node:fs'; |
| 3 | +import { tmpdir } from 'node:os'; |
1 | 4 | import { join } from 'node:path'; |
2 | 5 | import { describe, expect, it } from 'vitest'; |
3 | 6 | import { classifyAgainstBaseline, loadRedBaseline } from '../scripts/lib/red-baseline.mjs'; |
@@ -37,6 +40,32 @@ describe('integration gate red baseline', () => { |
37 | 40 | expect(loadRedBaseline(undefined)).toBeNull(); |
38 | 41 | }); |
39 | 42 |
|
| 43 | + it('reads the list as committed at the base, so a change cannot exempt itself', () => { |
| 44 | + const repo = mkdtempSync(join(tmpdir(), 'o8-red-baseline-')); |
| 45 | + try { |
| 46 | + const git = (...args: string[]) => execFileSync('git', args, { cwd: repo, stdio: 'pipe' }); |
| 47 | + const list = (paths: string[]) => JSON.stringify({ files: paths.map((path) => ({ path })) }); |
| 48 | + git('init', '-q'); |
| 49 | + mkdirSync(join(repo, 'tests')); |
| 50 | + writeFileSync(join(repo, 'tests/quarantine.json'), list(['tests/known-red-real-path.test.ts'])); |
| 51 | + git('add', '.'); |
| 52 | + git('-c', 'user.name=fixture', '-c', 'user.email=fixture@example.invalid', 'commit', '-q', '-m', 'base'); |
| 53 | + // The change under test adds its own broken file to the list. |
| 54 | + writeFileSync(join(repo, 'tests/quarantine.json'), list(['tests/known-red-real-path.test.ts', 'tests/new-break-real-path.test.ts'])); |
| 55 | + const committed = loadRedBaseline('tests/quarantine.json', 'HEAD', repo); |
| 56 | + expect([...(committed ?? [])]).toEqual(['tests/known-red-real-path.test.ts']); |
| 57 | + const outcome = classifyAgainstBaseline([ |
| 58 | + { file: 'tests/known-red-real-path.test.ts', failed: true }, |
| 59 | + { file: 'tests/new-break-real-path.test.ts', failed: true }, |
| 60 | + ], committed); |
| 61 | + expect(outcome.baselineRed).toEqual(['tests/known-red-real-path.test.ts']); |
| 62 | + expect(outcome.newRed).toEqual(['tests/new-break-real-path.test.ts']); |
| 63 | + expect(loadRedBaseline('tests/quarantine.json', 'no-such-ref', repo)).toBeNull(); |
| 64 | + } finally { |
| 65 | + rmSync(repo, { recursive: true, force: true }); |
| 66 | + } |
| 67 | + }); |
| 68 | + |
40 | 69 | it('loads the recorded Linux baseline, which lists only resource-owning files', async () => { |
41 | 70 | const recorded = loadRedBaseline(join(__dirname, 'integration-linux-baseline.json')); |
42 | 71 | expect(recorded?.size).toBe(0); |
|
0 commit comments