Repository navigation
refactor(ios): keep the modal-scope capture out of the packaged runner - #4127
Conversation
The modal-scope capture from #4124 has one caller, the alert surface corpus capture test, yet its ObjC reader, the Swift acquisition, and the bridge's internal header shipped in the runner source. They move under UnitTests/, which the packager drops, and compile only under AGENT_DEVICE_RUNNER_UNIT_TESTS. The bridging header imports the capture header only when it exists, since OTHER_CFLAGS defines do not reach Swift's clang importer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Size Report
Startup median (7 runs, lower is better):
|
Apex SentinelVerdict: 5 finding(s): 1 minor, 4 nit. Verdict: approve. reached max rounds (1). 🟡 Minor (1)
🔵 Nit (4)
Reply under an inline comment with |
There was a problem hiding this comment.
Apex Sentinel: 5 new findings on e5fb487. The verdict and the full list are in the summary comment.
| @@ -1,4 +1,4 @@ | |||
| #import "RunnerAXSnapshotBridge+Internal.h" | |||
| #import "RunnerAXSnapshotBridge.h" | |||
There was a problem hiding this comment.
🟡 Minor · Bridge's private class-extension declarations are no longer compiled against the implementation
Before this change RunnerAXSnapshotBridge.m began with #import "RunnerAXSnapshotBridge+Internal.h", so the translation unit that defines the helpers also saw the class-extension declarations in that header, and clang checked every definition against its declaration. This PR moves the header to UnitTests/ and changes the production import to the public header, so no production TU includes the extension any more (RunnerAXSnapshotBridge+Internal.h is now imported only by UnitTests/RunnerAXModalScopeCapture.m). The definitions stay in RunnerAXSnapshotBridge.m (e.g. accessibilityApplicationForApplication:axClient: at line 714, snapshotParametersForClient:maxDepth:maxNodes: at 311, rootSnapshotFromClient:... at 327, attributesForKeyPaths:consumedSuffixes: at 380, objectFrom:selectorName: at 660, integerFrom:selectorName: at 670, frameForSnapshot: at 859), so the production file still compiles: Objective-C resolves selectors defined later in the same @implementation without a declaration.
Suggested change
Keep the production implementation compiled against the private declarations: import the internal header (or a production-visible copy of the extension) from RunnerAXSnapshotBridge.m again, or add a guard that the selectors declared in UnitTests/RunnerAXSnapshotBridge+Internal.h still match the definitions in RunnerAXSnapshotBridge.m. Also reconcile the nullable/non-null mismatch on accessibilityApplicationForApplication:axClient:.
Details
What is lost is the cross-check. The unit-test TU now calls these helpers only through the extension declaration, and the TU that defines them never sees that declaration. A signature or nullability drift is silent in both TUs and surfaces only as a runtime failure in the unit/capture tests. There is already such a divergence: the extension declares + (nullable id)accessibilityApplicationForApplication:(XCUIApplication *)application axClient:(id)axClient; (UnitTests/RunnerAXSnapshotBridge+Internal.h line 9) while the implementation at RunnerAXSnapshotBridge.m:714 is + (id)accessibilityApplicationForApplication:... axClient:(id)axClient — the nullable mismatch that clang used to warn about ("conflicting nullability specifier on return types") is now never diagnosed. If a future edit changes a parameter type or selector in the .m, the unit bundle still links against a selector that no longer exists (unrecognized selector / missing symbol at load), with no compile error pointing at it.
Fix: keep a declaration the implementation TU compiles against — either keep importing the internal header from RunnerAXSnapshotBridge.m (a header import adds no code, so the packaging concern is untouched as long as the header itself stays out of the package), or move the extension declaration into the unit-only header's own guard and add a check that the names in it still match the .m.
Also raised here
Also raised at this location by swift-ios: Bridge .m no longer imports its internal header, so nothing checks its definitions against the shared declarations — Previously the .m imported the header, so a signature or nullability drift between the shared declaration and the implementation was a compile error in the same translation unit. Now only the unit-only RunnerAXModalScopeCapture.m sees the declarations and calls them through [self ...]; the production .m compiles against no declaration, so drift between the internal header and the definitions is caught only by a same-file call-site diagnostic at best, and a changed return/parameter type in the implementation would surface as a warning at the capture's call site (or a wrong-value read) rather than a mismatch error in the file that owns both sides. A comment or a static assertion noting that the internal header must stay in sync with the .m would preserve the intent the import used to enforce.
persona: cpp, swift-ios
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
| #import "RunnerSynthesizedTextEntry.h" | ||
| #import "RunnerXCTestEventBridge.h" | ||
| #import "RunnerAXModalScopeCapture.h" | ||
| // The packaged runner omits UnitTests/. OTHER_CFLAGS defines do not reach this header. |
There was a problem hiding this comment.
🔵 Nit · Modal-scope ObjC API stays visible to Swift in normal (non-unit) builds while its implementation is compiled out
This PR guards the implementation with #if defined(AGENT_DEVICE_RUNNER_UNIT_TESTS) (UnitTests/RunnerAXModalScopeCapture.m:1 and the matching #endif at the new line 252) but imports the unguarded header into Swift unconditionally in every checkout build: the new bridging-header guard #if __has_include("UnitTests/RunnerAXModalScopeCapture.h") is true in the repo (the file exists) and false only in dist/, because the packager drops UnitTests/ (scripts/package-apple-runner-source.mjs SKIPPED_DIR_NAMES). So a normal build-for-testing in the checkout still exposes RunnerAXModalScopeCapture, RunnerAXModalScopeTree, RunnerAXModalScopeNode, +[RunnerAXSnapshotBridge modalScopeCaptureForApplication:maxDepth:maxNodes:includeClassNames:deadline:] and modalScopeTreeFromSnapshot:... to Swift while none of those methods are compiled in. Nothing calls them today (the only caller, UnitTests/RunnerModalScopeAcquisition.swift, carries the same #if), so it links — the safety is only that the single caller happens to have a matching guard. Any future non-guarded call site compiles cleanly and traps at runtime with unrecognized selector on +[RunnerAXSnapshotBridge modalScopeCaptureForApplication:...]. Encode the invariant in the header instead: wrap the declarations in UnitTests/RunnerAXModalScopeCapture.h in the same #if defined(AGENT_DEVICE_RUNNER_UNIT_TESTS) so interface and implementation disappear together in the same builds.
Suggested change
Wrap the declarations in UnitTests/RunnerAXModalScopeCapture.h in the same #if defined(AGENT_DEVICE_RUNNER_UNIT_TESTS) guard the .m now uses, so the ObjC API is absent from the Swift-visible interface exactly in the builds where its implementation is absent, instead of relying on the one remaining caller carrying a matching guard.
Details
Also raised here
Also raised at this location by senior-developer: Modal-scope capture header visibility is gated on file presence, not on the macro that gates its implementation — The bridging header now exposes UnitTests/RunnerAXModalScopeCapture.h under #if __has_include(...), which is true in every checkout build (the file is simply present), while the category implementation +modalScopeCaptureForApplication:... / +modalScopeTreeFromSnapshot:... in UnitTests/RunnerAXModalScopeCapture.m is compiled only under #if defined(AGENT_DEVICE_RUNNER_UNIT_TESTS). So in a normal (non-unit) build-for-testing of AgentDeviceRunnerUITests from this checkout, RunnerAXSnapshotBridge.modalScopeCapture(forApplication:...) is visible to Swift but has no implementation: a call from any source outside UnitTests/ compiles and then dies at runtime with unrecognized selector (ObjC class methods dispatch through objc_msgSend, so the linker does not catch it). In the packaged runner the header is absent instead, so the same call is a compile error. …
Also raised at this location by maintainability: __has_include keys on file presence, not on the unit-test configuration — The bridging header now decides whether to expose the capture types with __has_include("UnitTests/RunnerAXModalScopeCapture.h") (lines 6-9). In a source checkout that file is always tracked and present, so the test is always true and the gate never enforces the unit-test-only split it documents; it only goes false in the packaged tree, where the counterpart Swift/Objective-C sources are gone too and nothing needs the import. When it does go false in a tree that still has a Swift caller (e.g. a header search path that does not resolve the UnitTests/ subdirectory, as in this PR's original state), Swift reports cannot find 'RunnerAXModalScopeCapture' in scope with no hint that the import was skipped — a harder failure than the missing-header error an unconditional #import would give. AGENTS.md: "Add compatibility or fallback behavior only on explicit request or approval." …
persona: swift-ios, senior-developer, maintainability
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
| #import "RunnerSynthesizedTextEntry.h" | ||
| #import "RunnerXCTestEventBridge.h" | ||
| #import "RunnerAXModalScopeCapture.h" | ||
| // The packaged runner omits UnitTests/. OTHER_CFLAGS defines do not reach this header. |
There was a problem hiding this comment.
🔵 Nit · The capture header stays reachable to non-unit builds even though the comment says its content belongs to the unit bundle
The added comment states the rule (The packaged runner omits UnitTests/.) but the guard expresses only the packaging half of it, so the line reads as if the unit build is the only one that ever sees RunnerAXModalScopeCaptureStatus and the RunnerAXSnapshotBridge (ModalScope) category — it is not (see the paired finding). Rewording the comment to say "present in the checkout builds, absent from the package; callers live under UnitTests/" makes the line match its effect.
| // The packaged runner omits UnitTests/. OTHER_CFLAGS defines do not reach this header. | |
| // The packaged runner omits UnitTests/, so this header exists only in checkout builds. Callers | |
| // of its declarations live under UnitTests/, where the implementation also compiles. |
Details
persona: senior-developer
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
| #import "RunnerSynthesizedTextEntry.h" | ||
| #import "RunnerXCTestEventBridge.h" | ||
| #import "RunnerAXModalScopeCapture.h" | ||
| // The packaged runner omits UnitTests/. OTHER_CFLAGS defines do not reach this header. |
There was a problem hiding this comment.
🔵 Nit · Comment in the bridging header names the macro the repo guard forbids in packaged runner source
scripts/lib/shipped-test-code.ts testOnlyContentFailures() rejects ANY file under dist/apple/runner whose bytes contain the AGENT_DEVICE_RUNNER_UNIT_TESTS token, and its own documentation states the rule explicitly: "Ship no mention of the macro in runner source for another reason — including in a comment — and the host app's comments say 'the runner's unit-test macro' instead of naming it." The new comment added to AgentDeviceRunnerUITests-Bridging-Header.h (line 6) is copied into the package verbatim (the packager copies non-.swift files unchanged) and reads // The packaged runner omits UnitTests/. OTHER_CFLAGS defines do not reach this header. It does not contain the macro token today, so pnpm check:package passes — but the header is packaged runner source whose only protection is that one word is spelled out in prose instead of as the token, while the file right below it (#import "UnitTests/RunnerAXModalScopeCapture.h") documents the same mechanism the macro name would spell directly. Reword the comment to follow the convention the owning rule states ("the runner's unit-test macro") so a future edit that names the flag here does not break check:package.
| // The packaged runner omits UnitTests/. OTHER_CFLAGS defines do not reach this header. | |
| // The packaged runner omits UnitTests/, and the runner's unit-test macro does not reach this header. | |
| #if __has_include("UnitTests/RunnerAXModalScopeCapture.h") | |
| #import "UnitTests/RunnerAXModalScopeCapture.h" | |
| #endif |
Suggested change
Follow the repo's own convention in scripts/lib/shipped-test-code.ts: refer to "the runner's unit-test macro" in packaged runner source comments instead of anything close to the flag name.
Details
persona: cpp
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
| @@ -1,6 +1,7 @@ | |||
| import XCTest | |||
| import AgentDeviceSnapshotPresentation | |||
|
|
|||
There was a problem hiding this comment.
🔵 Nit · Inconsistent guard placement between ObjC and Swift counterparts
In RunnerAXModalScopeCapture.m, the #if defined(AGENT_DEVICE_RUNNER_UNIT_TESTS) is on line 1, before the #import of the header. In RunnerModalScopeAcquisition.swift, the equivalent #if AGENT_DEVICE_RUNNER_UNIT_TESTS is placed after the two import statements (line 4 in the new file). While Swift allows imports outside a conditional, moving the #if above the imports would be consistent with the ObjC file and makes the guard's scope immediately visible at the top of the file.
| #if AGENT_DEVICE_RUNNER_UNIT_TESTS | |
| import XCTest | |
| import AgentDeviceSnapshotPresentation | |
Details
persona: maintainability
Reply @apex-sentinel-staging note ... to add context, or @apex-sentinel-staging pivot ... if this is wrong — I will re-check the cited code.
Useful? Reply @apex-sentinel-staging like, or @apex-sentinel-staging dislike <why> if it is not.
|
This PR looks good at e5fb487. The modal-scope capture now stays out of the packaged runner, and I found no problems in the code. All 19 checks pass, and there are no conflicts. I did not build the packaged runner or the unit bundle locally, so CI is the only compile evidence. I also could not confirm from reading that CI builds the unit-test bundle with the modal-scope tests, and the device capture test needs a device that I did not use. The five open inline threads from apex-sentinel-staging do not apply, so you can resolve them. The +Internal.h import: #4127 (comment) (the .m defines the methods itself, and the one consumer compiles against the real class). The __has_include guard: #4127 (comment) (UnitTests/ is absent in packaged builds, so no mismatch). The unconditional import: #4127 (comment) (the header exists only where the import is valid). The shipped-test-code check: #4127 (comment) (the comment does not contain the flag name). The #if versus #if defined style: #4127 (comment) (each matches its language idiom and existing files). |
Summary
#4124 shipped the modal-scope capture in the packaged runner source, but its only caller is the dev capture test
testCaptureAlertSurfaceTree(pnpm capture:alert-surface). This PR moves it underUnitTests/, which the packager drops:RunnerAXModalScopeCapture.{h,m},RunnerModalScopeAcquisition.swift, andRunnerAXSnapshotBridge+Internal.hmove toUnitTests/. The.mand Swift compile only underAGENT_DEVICE_RUNNER_UNIT_TESTS, which matchesAgentDeviceRunnerAppFixtures.mand the otherUnitTests/sources.__has_include.OTHER_CFLAGSdefines do not reach Swift's clang importer, so a#if defined(...)gate hid the types from the unit build.RunnerAXSnapshotBridge.mimports its public header again. Production code still uses the split helpers.ModalScopePair.swiftandModalSurface.swiftstay in the host package.6 files, renames plus guards. No behavior change.
Size: −19.9 kB unpacked (CI Size Report)
Validation
At e5fb487:
pnpm check:affected --run --head HEAD: passed.pnpm check:package: passed, with no test code in the 751 packed files.build-for-testingpassed on iOS sim and macOS, for both normal and unit (AGENT_DEVICE_XCUITEST_INCLUDE_UNIT_TESTS=1) builds. The packageddist/apple/runnerproject also built on iOS and macOS. The packaged source has noModalScopeCapturefile.pnpm capture:alert-surfaceagainstcom.apple.Preferenceson an iPhone Duo sim: 1 test passed, 141/141 nodes. I deleted the throwaway fixture, and the corpus is unchanged.testAModalScopeTree*methods passed on the iOS sim and on macOS (2 executed, 0 failures each).CI: Apple Smoke Tests own the swift-runner lanes.
🤖 Generated with Claude Code