|
1 | 1 | import fs from 'node:fs'; |
| 2 | +import { execFileSync } from 'node:child_process'; |
| 3 | +import os from 'node:os'; |
2 | 4 | import path from 'node:path'; |
3 | 5 | import { expect, test } from 'vitest'; |
4 | 6 | import { parse } from 'yaml'; |
@@ -112,3 +114,43 @@ test('bridge proof runs for its owning sources and uncertain tooling changes', ( |
112 | 114 | expect(selectAppleBridgeProof(null).run).toBe(true); |
113 | 115 | expect(selectAppleBridgeProof([]).run).toBe(true); |
114 | 116 | }); |
| 117 | + |
| 118 | +test('a shallow PR merge still yields a known change set for both selectors', () => { |
| 119 | + const root = fs.mkdtempSync(path.join(os.tmpdir(), 'apple-ci-impact-')); |
| 120 | + const source = path.join(root, 'source'); |
| 121 | + const shallow = path.join(root, 'shallow'); |
| 122 | + fs.mkdirSync(source); |
| 123 | + const git = (cwd: string, ...args: string[]) => |
| 124 | + execFileSync('git', args, { cwd, encoding: 'utf8' }).trim(); |
| 125 | + try { |
| 126 | + git(source, 'init', '-q', '-b', 'main'); |
| 127 | + git(source, 'config', 'user.email', '[email protected]'); |
| 128 | + git(source, 'config', 'user.name', 'Test'); |
| 129 | + git(source, 'commit', '--allow-empty', '-qm', 'base'); |
| 130 | + const base = git(source, 'rev-parse', 'HEAD'); |
| 131 | + git(source, 'checkout', '-qb', 'feature'); |
| 132 | + fs.mkdirSync(path.join(source, 'src')); |
| 133 | + fs.writeFileSync(path.join(source, 'src', 'feature.ts'), 'export const feature = true;\n'); |
| 134 | + git(source, 'add', '.'); |
| 135 | + git(source, 'commit', '-qm', 'feature'); |
| 136 | + git(source, 'checkout', '-q', 'main'); |
| 137 | + git(source, 'merge', '-q', '--no-ff', '-m', 'merge', 'feature'); |
| 138 | + git(root, 'clone', '-q', '--depth=1', '--branch', 'main', `file://${source}`, shallow); |
| 139 | + git(shallow, 'fetch', '-q', 'origin', base, '--depth=1'); |
| 140 | + expect(git(shallow, 'rev-parse', '--is-shallow-repository')).toBe('true'); |
| 141 | + const select = (target: string) => |
| 142 | + execFileSync( |
| 143 | + process.execPath, |
| 144 | + ['--experimental-strip-types', path.join(repoRoot, 'scripts/apple-ci-impact.ts'), target], |
| 145 | + { |
| 146 | + cwd: shallow, |
| 147 | + encoding: 'utf8', |
| 148 | + env: { ...process.env, BASE_SHA: base, GITHUB_EVENT_NAME: 'pull_request' }, |
| 149 | + }, |
| 150 | + ); |
| 151 | + expect(select('xctest')).toContain('skip;'); |
| 152 | + expect(select('bridge')).toContain('skip;'); |
| 153 | + } finally { |
| 154 | + fs.rmSync(root, { recursive: true, force: true }); |
| 155 | + } |
| 156 | +}); |
0 commit comments