Skip to content

Commit 1826b2e

Browse files
authored
refactor(ios): integrate runner with snapshot engine (#2214)
* refactor(ios): integrate runner with snapshot engine * fix(ios): preserve macOS runner snapshots * refactor(ios): keep runner presentation device-aware * fix(ios): validate runner scroll presentation * fix(ios): close presenter package boundaries * fix(ios): preserve snapshot source lineage * test(ios): colocate snapshot engine coverage * fix(ios): settle post-merge audit checks * test(ios): fix manifest parity lint * refactor(ios): simplify runner source walk * test(ios): cover shared package source fixture * fix(ios): close post-merge audit gaps * perf(ios): avoid bundling acquired snapshot path
1 parent 911945a commit 1826b2e

49 files changed

Lines changed: 1306 additions & 174 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.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/**', 'scripts/build-xcuitest-apple.sh', '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', 'package.json', 'pnpm-lock.yaml') }}" >> "$GITHUB_OUTPUT"
47+
echo "value=${{ hashFiles('apple/runner/**', 'apple/snapshot-presentation/**', 'scripts/build-xcuitest-apple.sh', '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', 'package.json', 'pnpm-lock.yaml') }}" >> "$GITHUB_OUTPUT"
4848
shell: bash
4949

5050
- name: Resolve Apple runner build variant

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+Models.swift‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ struct DataPayload: Codable {
239239
var items: [String]?
240240
var nodes: [PresentedNode]?
241241
var truncated: Bool?
242+
var qualityPayload: SnapshotQualityPayload? = nil
242243
var snapshotQuality: SnapshotQuality?
243244
var gestureStartUptimeMs: Double?
244245
var gestureEndUptimeMs: Double?
@@ -274,6 +275,31 @@ struct DataPayload: Codable {
274275
var sequenceResults: [SequenceStepResult]?
275276
}
276277

278+
struct SnapshotQualityPayload: Codable {
279+
let nodes: [PresentedNode]
280+
let truncated: Bool
281+
let scope: String?
282+
283+
init(nodes: [PresentedNode], truncated: Bool) {
284+
self.nodes = nodes
285+
self.truncated = truncated
286+
self.scope = nil
287+
}
288+
289+
private enum CodingKeys: String, CodingKey {
290+
case nodes
291+
case truncated
292+
case scope
293+
}
294+
295+
func encode(to encoder: Encoder) throws {
296+
var container = encoder.container(keyedBy: CodingKeys.self)
297+
try container.encode(nodes, forKey: .nodes)
298+
try container.encode(truncated, forKey: .truncated)
299+
try container.encodeNil(forKey: .scope)
300+
}
301+
}
302+
277303
struct ErrorPayload: Codable {
278304
var code: String?
279305
let message: String

‎apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerTests+SnapshotCapturePlan.swift‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,11 @@ extension RunnerTests {
490490
do {
491491
presented = try timer.measure(.presentation) {
492492
guard let result = try SnapshotPresentation.present(acquisition, options: options) else {
493+
NSLog(
494+
"AGENT_DEVICE_RUNNER_SNAPSHOT_PROJECTION_MISMATCH requested=%@ acquired=%@",
495+
hint.projection.rawValue,
496+
acquisition.hint.projection.rawValue
497+
)
493498
throw Self.snapshotProjectionMismatchFailure(
494499
kind,
495500
requested: hint.projection,
@@ -641,6 +646,10 @@ extension RunnerTests {
641646
message: Self.legacyQualityMessage(quality) ?? payload.message,
642647
nodes: payload.nodes,
643648
truncated: payload.truncated == true || state != "healthy" || capture.effectiveDepth != nil,
649+
qualityPayload: capture.qualityPayload.flatMap { quality in
650+
guard let nodes = quality.nodes else { return nil }
651+
return SnapshotQualityPayload(nodes: nodes, truncated: quality.truncated == true)
652+
},
644653
snapshotQuality: quality,
645654
runnerFatal: payload.runnerFatal,
646655
runnerFatalReason: payload.runnerFatalReason
@@ -877,6 +886,29 @@ extension RunnerTests {
877886
XCTAssertEqual(payload.nodes?.count, 1)
878887
}
879888

889+
func testSnapshotQualityCarriesUnscopedQualityPayload() {
890+
let quality = DataPayload(
891+
nodes: [planTestNode(index: 0, type: "Application", label: "App")],
892+
truncated: false
893+
)
894+
let capture = SnapshotBackendCapture(
895+
payload: quality,
896+
effectiveDepth: nil,
897+
qualityPayload: quality
898+
)
899+
900+
let payload = stampedSnapshotPayload(
901+
capture,
902+
backend: .recursiveTree,
903+
state: "healthy",
904+
reason: nil
905+
)
906+
907+
XCTAssertEqual(payload.qualityPayload?.nodes.count, 1)
908+
XCTAssertEqual(payload.qualityPayload?.truncated, false)
909+
XCTAssertNil(payload.qualityPayload?.scope)
910+
}
911+
880912
func testDirectPresentationDoesNotClaimPlanTiming() {
881913
let options = PresentationOptions(
882914
interactiveOnly: false,

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

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ extension RunnerTests {
307307
}
308308

309309
XCTAssertThrowsError(
310-
try SnapshotPresentationInvariant.validateRegularWithStats(
310+
try SnapshotPresentationInvariant.validateRegular(
311311
folded,
312312
viewport: viewport,
313313
policy: .cursorProjected
@@ -323,30 +323,6 @@ extension RunnerTests {
323323
}
324324
}
325325

326-
func testRegularInvariantUsesOneParentClipLookupPerNode() throws {
327-
let nodeCount = 5_000
328-
let viewport = CGRect(x: 0, y: 0, width: 100, height: 100)
329-
let nodes = (0..<nodeCount).map { index in
330-
let raw = Self.invariantNode(
331-
index,
332-
type: index == 0 ? "Application" : "ScrollView",
333-
rect: SnapshotRect(x: 0, y: 0, width: 100, height: 100),
334-
parentIndex: index == 0 ? nil : index - 1
335-
)
336-
return SnapshotPresentationNode(raw: raw, effectiveRect: raw.rect)
337-
}
338-
339-
let stats = try SnapshotPresentationInvariant.validateRegularWithStats(
340-
nodes,
341-
viewport: viewport,
342-
policy: .cursorProjected
343-
)
344-
345-
// The former per-node ancestor walk performs 12,497,500 lookups for this chain. Counting the
346-
// cached parent resolutions makes the linear guarantee deterministic without timing the test.
347-
XCTAssertEqual(stats.parentClipLookups, nodeCount - 1)
348-
}
349-
350326
func testPresentationFailureKeepsItsNamedSnapshotQualityReason() {
351327
// Non-vacuity: dropping the typed reason preference in the plan mapper changes the assertion
352328
// below to `capture-failed`, losing the distinction this contract is meant to preserve.

apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/RunnerSnapshotScopePolicy.swift renamed to apple/runner/AgentDeviceRunner/AgentDeviceRunnerUITests/UnitTests/RunnerTests+SnapshotScopePolicyTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extension RunnerTests {
2121
func testSnapshotScopePolicyMatchesGoldenParityTable() throws {
2222
// Non-vacuity: label-only semantic values fail the identifier-only and value-only fixtures.
2323
let fixtureURL = URL(fileURLWithPath: #filePath)
24+
.deletingLastPathComponent() // UnitTests
2425
.deletingLastPathComponent() // AgentDeviceRunnerUITests
2526
.deletingLastPathComponent() // AgentDeviceRunner
2627
.deletingLastPathComponent() // runner

‎apple/snapshot-presentation/Package.runner.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ let package = Package(
66
platforms: [
77
.iOS(.v15),
88
.macOS(.v13),
9+
.tvOS(.v15),
10+
.visionOS(.v1),
911
],
1012
products: [
1113
.library(

‎apple/snapshot-presentation/Package.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ let package = Package(
66
platforms: [
77
.iOS(.v15),
88
.macOS(.v13),
9+
.tvOS(.v15),
10+
.visionOS(.v1),
911
],
1012
products: [
1113
.library(

‎apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentation.swift‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import Foundation
22
import CoreGraphics
33

44
public enum SnapshotPresentation {
5-
public typealias PresentedNode = AgentDeviceSnapshotPresentation.PresentedNode
6-
75
public static func present(
86
_ acquisition: SnapshotAcquisition,
97
options: PresentationOptions

‎apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotPresentationInvariant.swift‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import Foundation
22
import CoreGraphics
33

44
public enum SnapshotPresentationInvariant {
5-
public struct ValidationStats: Equatable {
6-
public let parentClipLookups: Int
5+
struct ValidationStats: Equatable {
6+
let parentClipLookups: Int
77

8-
public init(parentClipLookups: Int) {
8+
init(parentClipLookups: Int) {
99
self.parentClipLookups = parentClipLookups
1010
}
1111
}
@@ -18,7 +18,7 @@ public enum SnapshotPresentationInvariant {
1818
_ = try validateRegularWithStats(nodes, viewport: viewport, policy: policy)
1919
}
2020

21-
public static func validateRegularWithStats(
21+
static func validateRegularWithStats(
2222
_ nodes: [SnapshotPresentationNode],
2323
viewport: CGRect,
2424
policy: SnapshotVisibilityFold.Policy

‎apple/snapshot-presentation/Sources/AgentDeviceSnapshotPresentation/SnapshotVisibilityFold.swift‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,7 @@ public enum SnapshotVisibilityFold {
169169
var hints: [Int: (above: Bool, below: Bool)] = [:]
170170

171171
for (offset, node) in nodes.enumerated() {
172-
let parentState = node.parentIndex.flatMap { index in
173-
index >= 0 && index < states.count ? states[index] : nil
174-
}
172+
let parentState = node.parentIndex.flatMap { states[$0] }
175173
let parentTraversal = parentState?.traversal ?? .root
176174
let parentAnchor = policy == .cursorProjected ? parentState?.anchor : nil
177175
let rect = node.rect.cgRect

0 commit comments

Comments
 (0)