Skip to content

Commit fc63b1e

Browse files
committed
refactor(gates): one macro owner and a rename guard on the fixture-host lookup
scripts/package-apple-runner-source.mjs exports AGENT_DEVICE_RUNNER_UNIT_TESTS and scripts/lib/shipped-test-code.ts imports it, so the stripper and the leak guard cannot drift apart. A second guard reads the class name the host app resolves with NSClassFromString and requires the fixtures file to declare and implement it, so a rename fails CI instead of every fixture test quietly falling back to the plain host on devices.
1 parent 8fa7f6a commit fc63b1e

4 files changed

Lines changed: 40 additions & 2 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* The shipped host app reaches the unit-test fixture screens through a string, not a symbol:
3+
* `+agentDeviceRootViewControllerClass` looks up `AgentDeviceRunnerFixtureViewController` with
4+
* NSClassFromString and falls back to the plain host when the class is absent. A rename on the
5+
* fixtures side would then fail silently — production keeps working, every fixture-dependent test
6+
* starts falling back to the plain host. This guard makes that rename fail CI instead.
7+
*/
8+
import assert from 'node:assert/strict';
9+
import fs from 'node:fs';
10+
import path from 'node:path';
11+
import { test } from 'vitest';
12+
13+
const repoRoot = path.resolve(import.meta.dirname, '../..');
14+
const hostSource = path.join(
15+
repoRoot,
16+
'apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerApp.m',
17+
);
18+
const fixturesSource = path.join(
19+
repoRoot,
20+
'apple/runner/AgentDeviceRunner/AgentDeviceRunner/AgentDeviceRunnerAppFixtures.m',
21+
);
22+
23+
test('the host app looks up a fixture class the fixtures file declares', () => {
24+
const host = fs.readFileSync(hostSource, 'utf8');
25+
const lookup = host.match(/NSClassFromString\(@"(\w+)"\)/);
26+
assert.ok(lookup, 'the host app must resolve the fixture host with NSClassFromString');
27+
const className = lookup[1]!;
28+
const fixtures = fs.readFileSync(fixturesSource, 'utf8');
29+
// The class the host names must be declared and implemented by the fixtures file.
30+
assert.match(fixtures, new RegExp(`@interface ${className} :`));
31+
assert.match(fixtures, new RegExp(`@implementation ${className}\\b`));
32+
});

‎scripts/lib/shipped-test-code.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
* human-readable violations come out.
1313
*/
1414

15+
import { UNIT_TEST_CONDITION } from '../package-apple-runner-source.mjs';
16+
1517
/** Test-only directory names. Any packed path carrying one of these segments is test code. */
1618
const TEST_ONLY_DIRECTORY_NAMES = new Set(['UnitTests', 'Tests', '__tests__', 'fixtures', 'mocks']);
1719

@@ -42,7 +44,6 @@ const RUNNER_HOST_APP_TARGET = [
4244
'AgentDeviceRunner',
4345
];
4446

45-
const UNIT_TEST_CONDITION = 'AGENT_DEVICE_RUNNER_UNIT_TESTS';
4647
/**
4748
* The host app's fixture screens switch on these launch arguments; the shipped host must not carry
4849
* one. This is also what catches the fixture file itself if its drop entry is ever removed: the

‎scripts/package-apple-runner-source.mjs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import path from 'node:path';
44
import { fileURLToPath } from 'node:url';
55
import { stripSwiftComments } from './strip-swift-comments.mjs';
66

7-
const UNIT_TEST_CONDITION = 'AGENT_DEVICE_RUNNER_UNIT_TESTS';
7+
// The macro the packager strips unit-test source under. One owner for the stripper and the leak
8+
// guard: scripts/lib/shipped-test-code.ts imports this value, so they cannot drift apart.
9+
export const UNIT_TEST_CONDITION = 'AGENT_DEVICE_RUNNER_UNIT_TESTS';
810
const SOURCE_DIR = path.join('apple', 'runner');
911
const OUTPUT_DIR = path.join('dist', 'apple', 'runner');
1012
const SNAPSHOT_PRESENTATION_SOURCE_DIR = path.join('apple', 'snapshot-presentation');

‎vitest.config.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ export default defineConfig({
187187
// The publishing package guard's no-test-code predicates, over fixture paths and
188188
// bytes: the gate itself can only watch a healthy package pass.
189189
'scripts/__tests__/shipped-test-code.test.ts',
190+
// The fixture-host class-name hook between the shipped host app and the unit-test
191+
// fixtures file: a rename there must fail here, not fall back silently on devices.
192+
'scripts/__tests__/runner-fixture-host-lookup.test.ts',
190193
// The line-parity comparison behind `pnpm check:packaged-runner-swift`. Pure text
191194
// over two strings; the gate itself is what runs the packager and the Swift parse.
192195
'scripts/__tests__/packaged-runner-swift.test.ts',

0 commit comments

Comments
 (0)