Skip to content

Commit 28a26fe

Browse files
committed
chore(gates): derive iOS XCTest selection from Swift guards and ownership
1 parent 08c10f3 commit 28a26fe

15 files changed

Lines changed: 676 additions & 368 deletions

File tree

‎.github/actions/setup-apple-runner-build/action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ runs:
4444
id: source-hash
4545
run: |
4646
set -euo pipefail
47-
echo "value=${{ hashFiles('apple/runner/**', 'apple/snapshot-presentation/**', 'scripts/build-xcuitest-apple.sh', 'scripts/swift-toolchain-tmpdir.ts', 'scripts/patch-xcuitest-runner-icon.ts', 'scripts/write-xcuitest-cache-metadata.mjs', 'packages/platform-apple/src/runner/apple-runner-platform.ts', 'packages/platform-apple/src/runner/runner-cache-metadata.ts', 'packages/platform-apple/src/runner/runner-icon.ts', 'packages/platform-apple/src/runner/runner-xctestrun.ts', 'packages/platform-apple/src/runner/runner-xctestrun-products.ts', '.github/actions/setup-apple-runner-build/action.yml') }}" >> "$GITHUB_OUTPUT"
47+
echo "value=${{ hashFiles('apple/runner/**', 'apple/snapshot-presentation/**', 'scripts/build-xcuitest-apple.sh', 'scripts/swift-toolchain-tmpdir.ts', 'scripts/patch-xcuitest-runner-icon.ts', 'scripts/write-xcuitest-cache-metadata.mjs', 'packages/platform-apple/src/runner/**', '!packages/platform-apple/src/runner/__tests__/**', '.github/actions/setup-apple-runner-build/action.yml') }}" >> "$GITHUB_OUTPUT"
4848
shell: bash
4949

5050
- name: Resolve Apple runner build variant

‎.github/workflows/ios.yml‎

Lines changed: 22 additions & 113 deletions
Large diffs are not rendered by default.

‎.github/workflows/macos.yml‎

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -153,25 +153,18 @@ jobs:
153153
test/artifacts/replays-macos.junit.xml
154154
155155
# Clean-install verification may raise macOS local-network permission UI; keep it after replay.
156-
- name: Verify clean-installed Simulator snapshot bridge preparation and the fold-helper -Werror gate
156+
- name: Select Apple bridge proof
157157
if: github.event_name == 'pull_request'
158+
id: bridge-impact
158159
env:
159160
BASE_SHA: ${{ github.event.pull_request.base.sha }}
160161
run: |
161-
git fetch origin "$BASE_SHA" --depth=1
162-
if git diff --quiet "$BASE_SHA"...HEAD -- \
163-
apple/snapshot-bridge \
164-
apple/fold-helper \
165-
packages/platform-apple/src/snapshot-source \
166-
packages/platform-apple/src/foldable \
167-
scripts/check-package.ts \
168-
scripts/size-report-install.mjs \
169-
scripts/size-report-package.mjs \
170-
.github/workflows/ios.yml \
171-
.github/workflows/macos.yml; then
172-
echo "Snapshot bridge and fold-helper sources are unchanged; skipping preparation proof."
173-
exit 0
174-
fi
162+
git fetch origin "$BASE_SHA" --depth=1 || echo 'Base fetch failed; bridge proof selection will fail open.'
163+
node --experimental-strip-types scripts/apple-ci-impact.ts bridge
164+
165+
- name: Verify clean-installed Simulator snapshot bridge preparation and the fold-helper -Werror gate
166+
if: github.event_name == 'pull_request' && steps.bridge-impact.outputs.run != 'false'
167+
run: |
175168
pnpm build
176169
pnpm exec vitest run \
177170
packages/platform-apple/src/snapshot-source/native-runtime.test.ts \

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+ApplicationStateRawValueTests.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ extension RunnerTests {
77
/// against a second handwritten table: the decoder maps the integer the runner stamps, and #2726
88
/// shipped `runningBackground` and `runningBackgroundSuspended` reversed.
99
///
10-
/// The host lane runs this on every PR, and `.github/workflows/ios.yml` lists it for the simulator
11-
/// lane so the suspended case — compiled out of the macOS build below — is pinned on every PR too.
10+
/// The host lane runs this on every PR; the simulator lane derives it from the platform branch
11+
/// below so the suspended case, compiled out of the macOS build, is pinned on every PR too.
1212
/// `packages/platform-apple/src/runner/__tests__/target-activation.test.ts` reads these calls back
1313
/// and compares them with its decode table, so a table that drifts from them fails on any host
1414
/// instead of waiting for a lane to report a mislabelled repair.

‎docs/agents/testing.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ provider, and coverage tests mock the typed HDC seam. Real validation is local h
4545
Apple runner changes run `pnpm check:xctest-selection` and build the affected target. The source
4646
`#if` guard is the XCTest lane classification — never maintain a second test-name list. Pure runner
4747
decisions use the macOS host lane; iOS/XCTest semantics need a simulator lane.
48-
The iOS PR lane runs its XCTest list for native inputs or uncertain diffs; main and nightly remain broad.
48+
The iOS PR lane derives platform-specific XCTests from Swift guards for runner changes;
49+
nightly runs the full suite.
4950

5051
Local host-lane XCTest may need signing and automation permission:
5152

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import fs from 'node:fs';
2+
import path from 'node:path';
3+
import { expect, test } from 'vitest';
4+
import { parse } from 'yaml';
5+
import { selectAppleBridgeProof, selectIosXctests } from '../apple-ci-impact.ts';
6+
import { selectChecks } from '../check-affected/model.ts';
7+
8+
const repoRoot = path.resolve(import.meta.dirname, '../..');
9+
10+
function cacheInputs(action: string): string[] {
11+
const doc = parse(action) as { runs?: { steps?: Array<{ id?: string; run?: string }> } };
12+
const sourceHash = doc.runs?.steps?.find((step) => step.id === 'source-hash')?.run ?? '';
13+
const expressions = [...sourceHash.matchAll(/hashFiles\(([\s\S]*?)\)/g)];
14+
expect(expressions.length).toBeGreaterThan(0);
15+
return expressions.flatMap((expression) =>
16+
[...expression[1]!.matchAll(/'([^']+)'/g)].map((match) => match[1]!),
17+
);
18+
}
19+
20+
test('every runner build-cache input triggers the PR XCTest lane', () => {
21+
const action = fs.readFileSync(
22+
path.join(repoRoot, '.github/actions/setup-apple-runner-build/action.yml'),
23+
'utf8',
24+
);
25+
expect(cacheInputs(action)).toContain('packages/platform-apple/src/runner/**');
26+
expect(cacheInputs(action)).toContain('!packages/platform-apple/src/runner/__tests__/**');
27+
const uncovered = (text: string) =>
28+
cacheInputs(text)
29+
.filter((input) => !input.startsWith('!'))
30+
.filter((input) => {
31+
const path = input.replace(/\*\*?$/, 'probe.ts');
32+
const plan = selectChecks({ changedFiles: [path] });
33+
return !plan.failOpen && !plan.checks.includes('swift-runner-ios');
34+
});
35+
expect(uncovered(action)).toEqual([]);
36+
expect(
37+
uncovered(action.replace('apple/runner/**', 'packages/platform-apple/src/snapshot-source/**')),
38+
).toEqual(['packages/platform-apple/src/snapshot-source/**']);
39+
expect(
40+
uncovered(
41+
action.replace(
42+
'hashFiles(',
43+
"hashFiles('packages/platform-apple/src/foldable/**',\n ",
44+
),
45+
),
46+
).toEqual(['packages/platform-apple/src/foldable/**']);
47+
});
48+
49+
test('the PR workflow applies the impact decision to the XCTest step', () => {
50+
const workflow = fs.readFileSync(path.join(repoRoot, '.github/workflows/ios.yml'), 'utf8');
51+
expect(workflow).toContain('node --experimental-strip-types scripts/apple-ci-impact.ts xctest');
52+
expect(workflow).toMatch(
53+
/- name: Run targeted iOS runner XCTest regressions\n\s+id: ios-xctest\n\s+if: steps\.xctest-impact\.outputs\.run != 'false'/,
54+
);
55+
expect(workflow).toContain('if [ "$SELECTED" = \'true\' ] && [ "$OUTCOME" = \'skipped\' ]');
56+
});
57+
58+
test('macOS clean-install proof follows live UI replay', () => {
59+
const workflow = fs.readFileSync(path.join(repoRoot, '.github/workflows/macos.yml'), 'utf8');
60+
const replay = workflow.indexOf('- name: Run macOS integration test');
61+
const proof = workflow.indexOf(
62+
'- name: Verify clean-installed Simulator snapshot bridge preparation',
63+
);
64+
expect(replay).toBeGreaterThan(-1);
65+
expect(proof).toBeGreaterThan(replay);
66+
expect(workflow).toContain('node --experimental-strip-types scripts/apple-ci-impact.ts bridge');
67+
expect(workflow).toContain("steps.bridge-impact.outputs.run != 'false'");
68+
});
69+
70+
test('native runner and golden-table changes run XCTest; TypeScript runtime changes use live E2E', () => {
71+
for (const file of [
72+
'apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests.swift',
73+
'apple/snapshot-presentation/Sources/Presenter.swift',
74+
'packages/platform-apple/src/runner/runner-icon.ts',
75+
'contracts/fixtures/scroll-gesture.json',
76+
'.github/workflows/ios.yml',
77+
'scripts/apple-ci-impact.ts',
78+
]) {
79+
expect(selectIosXctests('pull_request', [file]).run, file).toBe(true);
80+
}
81+
for (const file of [
82+
'packages/platform-apple/src/snapshot-source/cache.ts',
83+
'packages/platform-apple/src/runner/__tests__/runner-icon.test.ts',
84+
'apple/fold-helper/fold-helper.c',
85+
'test/integration/ios-simulator-e2e/live-runner.ts',
86+
]) {
87+
expect(selectIosXctests('pull_request', [file]), file).toMatchObject({ run: false });
88+
}
89+
});
90+
91+
test('pushes and uncertain diffs keep the full XCTest selection', () => {
92+
expect(selectIosXctests('push', ['src/index.ts']).run).toBe(true);
93+
expect(selectIosXctests('pull_request', null).run).toBe(true);
94+
expect(selectIosXctests('pull_request', []).run).toBe(true);
95+
expect(selectIosXctests('pull_request', ['src/index.ts', 'package.json']).run).toBe(true);
96+
});
97+
98+
test('bridge proof runs for its owning sources and uncertain tooling changes', () => {
99+
for (const file of [
100+
'apple/snapshot-bridge/Bridge.c',
101+
'apple/fold-helper/Helper.c',
102+
'apple/new-native-module/Source.m',
103+
'packages/platform-apple/src/snapshot-source/native-runtime.ts',
104+
'packages/platform-apple/src/foldable/fold-helper-cache.ts',
105+
'packages/platform-apple/src/new-module/runtime.ts',
106+
'scripts/check-package.ts',
107+
'.github/workflows/macos.yml',
108+
]) {
109+
expect(selectAppleBridgeProof([file]).run, file).toBe(true);
110+
}
111+
expect(selectAppleBridgeProof(['src/index.ts']).run).toBe(false);
112+
expect(selectAppleBridgeProof(null).run).toBe(true);
113+
expect(selectAppleBridgeProof([]).run).toBe(true);
114+
});

‎scripts/__tests__/ios-xctest-impact.test.ts‎

Lines changed: 0 additions & 63 deletions
This file was deleted.

‎scripts/__tests__/xctest-declarations.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,50 @@ describe('the declaration scan', () => {
6767
).toEqual([`${TARGET}/RunnerTests/testGolden`]);
6868
});
6969

70+
test('discovers tests in indented extensions and new files without a name list', () => {
71+
expect(
72+
parseDeclaredTests(TARGET, [
73+
{
74+
file: 'UnitTests/NewScreenCaptureTests.swift',
75+
text:
76+
'#if os(iOS)\n' +
77+
' extension RunnerTests {\n' +
78+
' func testObservedScreenCapture() {}\n' +
79+
' }\n' +
80+
'#endif\n',
81+
},
82+
{
83+
file: 'NewTests.swift',
84+
text: ' extension RunnerTests {\n func testAnotherIndent() {}\n }\n',
85+
},
86+
]),
87+
).toEqual([
88+
`${TARGET}/RunnerTests/testAnotherIndent`,
89+
`${TARGET}/RunnerTests/testObservedScreenCapture`,
90+
]);
91+
});
92+
93+
test('fails closed when a test-shaped declaration cannot be classified', () => {
94+
expect(() => parseDeclaredTests(TARGET, source('func testOutsideAType() {}\n'))).toThrow(
95+
'RunnerTests+Fixture.swift:1: unrecognized XCTest declaration',
96+
);
97+
expect(() =>
98+
parseDeclaredTests(
99+
TARGET,
100+
source('extension RunnerTests {\n func testGeneric<T>() {}\n}\n'),
101+
),
102+
).toThrow('RunnerTests+Fixture.swift:2: unrecognized XCTest declaration');
103+
expect(() =>
104+
parseDeclaredTests(TARGET, source('extension RunnerTests { func testInline() {} }\n')),
105+
).toThrow('RunnerTests+Fixture.swift:1: unrecognized XCTest declaration');
106+
expect(() =>
107+
parseDeclaredTests(
108+
TARGET,
109+
source('extension RunnerTests {\n @available(iOS 17, *) func testAttributed() {}\n}\n'),
110+
),
111+
).toThrow('RunnerTests+Fixture.swift:2: unrecognized XCTest declaration');
112+
});
113+
70114
test('attributes each declared method to the platforms that compile it', () => {
71115
expect(
72116
parseDeclaredTestsByPlatform(

0 commit comments

Comments
 (0)