Skip to content

refactor(ios): keep the modal-scope capture out of the packaged runner - #4127

Merged
thymikee merged 1 commit into
mainfrom
refactor/ios-modal-capture-test-only
Nov 1, 2026
Merged

thymikee merged 1 commit into
mainfrom
refactor/ios-modal-capture-test-only

Conversation

@thymikee

@thymikee thymikee commented Nov 1, 2026 •

Copy link
Copy Markdown
Member

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 under UnitTests/, which the packager drops:

  • RunnerAXModalScopeCapture.{h,m}, RunnerModalScopeAcquisition.swift, and RunnerAXSnapshotBridge+Internal.h move to UnitTests/. The .m and Swift compile only under AGENT_DEVICE_RUNNER_UNIT_TESTS, which matches AgentDeviceRunnerAppFixtures.m and the other UnitTests/ sources.
  • The bridging header imports the capture header behind __has_include. OTHER_CFLAGS defines do not reach Swift's clang importer, so a #if defined(...) gate hid the types from the unit build.
  • RunnerAXSnapshotBridge.m imports its public header again. Production code still uses the split helpers. ModalScopePair.swift and ModalSurface.swift stay 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.
  • Runner build-for-testing passed on iOS sim and macOS, for both normal and unit (AGENT_DEVICE_XCUITEST_INCLUDE_UNIT_TESTS=1) builds. The packaged dist/apple/runner project also built on iOS and macOS. The packaged source has no ModalScopeCapture file.
  • pnpm capture:alert-surface against com.apple.Preferences on an iPhone Duo sim: 1 test passed, 141/141 nodes. I deleted the throwaway fixture, and the corpus is unchanged.
  • Both 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

View guided diff Turn on auto-fix

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>
@vercel

vercel Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
agent-device-website Ready Ready Preview Nov 1, 2026 6:42am UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 6 files

View guided diff | Turn on auto-fix | Re-trigger cubic

@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.67 MB 5.65 MB -19.9 kB
Package (unpacked) 5.67 MB 5.65 MB -19.9 kB
Package (download) 1.72 MB 1.72 MB -3.9 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 39.7 ms 38.8 ms -0.9 ms
CLI --help 87.8 ms 83.6 ms -4.2 ms

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel

Verdict: approve

5 finding(s): 1 minor, 4 nit. Verdict: approve. reached max rounds (1).

🟡 Minor (1)

Where Finding
apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerAXSnapshotBridge.m:1 Bridge's private class-extension declarations are no longer compiled against the implementation
🔵 Nit (4)
Where Finding
apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests-Bridging-Header.h:6 Modal-scope ObjC API stays visible to Swift in normal (non-unit) builds while its implementation is compiled out
apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests-Bridging-Header.h:6 The capture header stays reachable to non-unit builds even though the comment says its content belongs to the unit bundle
apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/AgentDeviceRunnerUITests-Bridging-Header.h:6 Comment in the bridging header names the macro the repo guard forbids in packaged runner source
apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerModalScopeAcquisition.swift:3 Inconsistent guard placement between ObjC and Swift counterparts

Reply under an inline comment with @apex-sentinel-staging note ... or @apex-sentinel-staging pivot ... to re-check that finding.
Comment @apex-sentinel-staging review on this conversation to run a full review.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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.

Suggested change
// 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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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.

Suggested change
// 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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.

Suggested change
#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.

@thymikee

thymikee commented Nov 1, 2026

Copy link
Copy Markdown
Member Author

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).

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 1, 2026
@thymikee
thymikee merged commit 32bf98d into main Nov 1, 2026
19 of 20 checks passed
@thymikee
thymikee deleted the refactor/ios-modal-capture-test-only branch November 1, 2026 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant