Skip to content

Commit 9f4670b

Browse files
committed
test(scroll): drive the TS and Swift scroll-plan parity vectors from one table (#1820 review)
The two suites hand-mirrored the same vectors and #1820 had to edit both by hand — the drift class the repo already closes for the tap-point rule via contracts/fixtures/tap-point-policy.json. The scroll vectors (plus both planner constants, pinned behaviourally on a 1000px axis) now live in contracts/fixtures/scroll-gesture.json; scroll-gesture.test.ts and RunnerTests+ScrollGesture.swift iterate it. Verified: vitest 10/10; the four XCTests run on an iOS 26.2 simulator with the unit flag on (Executed 4 tests, 0 failures). Also: test/ci/android-workflow-evidence.json says what it guards. Follow-up for content-safe viewport bounds + discovery order: #1821.
1 parent 8ece823 commit 9f4670b

4 files changed

Lines changed: 203 additions & 255 deletions

File tree

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

Lines changed: 74 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import XCTest
33
// Swift port of buildScrollGesturePlan from packages/contracts/src/scroll-gesture.ts.
44
//
55
// This is a deliberate two-place invariant: the daemon keeps the TS implementation (for Android,
6-
// recording, and reported-pixels), and the runner places the gesture with this Swift copy. The
7-
// parity test vectors at the bottom of this file mirror
8-
// packages/contracts/src/scroll-gesture.test.ts —
9-
// if you change the math in either language, update the other and both vector sets.
6+
// recording, and reported-pixels), and the runner places the gesture with this Swift copy. Both
7+
// ports are asserted against the same table, contracts/fixtures/scroll-gesture.json (gated
8+
// XCTest at the bottom of this file, vitest twin packages/contracts/src/scroll-gesture.test.ts) —
9+
// if you change the math in either language, update the other and the table.
1010
//
1111
// All inputs here are positive (reference dims, travel, center), so Swift's `.rounded()`
1212
// (half away from zero) matches JS `Math.round` (half up) on every value computed below.
@@ -20,8 +20,9 @@ struct RunnerScrollGesturePlan {
2020
}
2121

2222
private let runnerDefaultScrollAmount = 0.6
23-
// Mirrors DEFAULT_EDGE_PADDING_FRACTION: scroll gestures stay out of the outer 10% of each axis so a
24-
// saturated scroll never touches down inside the status bar / Dynamic Island band (#1781 A1).
23+
// Both constants are pinned by contracts/fixtures/scroll-gesture.json (`constants`). Scroll gestures
24+
// stay out of the outer 10% of each axis so a saturated scroll never touches down inside the status
25+
// bar / Dynamic Island band (#1781 A1).
2526
private let runnerDefaultEdgePaddingFraction = 0.1
2627

2728
func runnerScrollGesturePlan(
@@ -66,133 +67,88 @@ func runnerScrollGesturePlan(
6667
}
6768

6869
#if AGENT_DEVICE_RUNNER_UNIT_TESTS
69-
extension RunnerTests {
70-
// Cross-language parity vectors mirroring packages/contracts/src/scroll-gesture.test.ts. Keep these
71-
// in sync with the vitest vectors so the two buildScrollGesturePlan implementations cannot drift.
72-
73-
func testRunnerScrollGesturePlanMapsRelativeAmount() throws {
74-
let plan = try XCTUnwrap(
75-
runnerScrollGesturePlan(
76-
direction: "down",
77-
amount: 0.5,
78-
pixels: nil,
79-
referenceWidth: 400,
80-
referenceHeight: 800
81-
)
82-
)
83-
XCTAssertEqual(plan.x1, 200)
84-
XCTAssertEqual(plan.y1, 600)
85-
XCTAssertEqual(plan.x2, 200)
86-
XCTAssertEqual(plan.y2, 200)
87-
XCTAssertEqual(plan.travelPixels, 400)
70+
private struct ScrollGestureFixture: Decodable {
71+
struct Constants: Decodable {
72+
let defaultScrollAmount: Double
73+
let defaultEdgePaddingFraction: Double
8874
}
89-
90-
func testRunnerScrollGesturePlanPixelsDown() throws {
91-
// 300x600, down, pixels 120 -> (150,360)->(150,240), travel 120.
92-
let plan = try XCTUnwrap(
93-
runnerScrollGesturePlan(
94-
direction: "down",
95-
amount: nil,
96-
pixels: 120,
97-
referenceWidth: 300,
98-
referenceHeight: 600
99-
)
100-
)
101-
XCTAssertEqual(plan.x1, 150)
102-
XCTAssertEqual(plan.y1, 360)
103-
XCTAssertEqual(plan.x2, 150)
104-
XCTAssertEqual(plan.y2, 240)
105-
XCTAssertEqual(plan.travelPixels, 120)
75+
struct Expected: Decodable {
76+
let x1: Double
77+
let y1: Double
78+
let x2: Double
79+
let y2: Double
80+
let pixels: Double
10681
}
107-
108-
func testRunnerScrollGesturePlanClampsAmountAboveOne() throws {
109-
// 400x800, down, amount 2 -> requested 1600 clamps to the safe band (640): (200,720)->(200,80).
110-
let plan = try XCTUnwrap(
111-
runnerScrollGesturePlan(
112-
direction: "down",
113-
amount: 2,
114-
pixels: nil,
115-
referenceWidth: 400,
116-
referenceHeight: 800
117-
)
118-
)
119-
XCTAssertEqual(plan.x1, 200)
120-
XCTAssertEqual(plan.y1, 720)
121-
XCTAssertEqual(plan.x2, 200)
122-
XCTAssertEqual(plan.y2, 80)
123-
XCTAssertEqual(plan.travelPixels, 640)
82+
struct Case: Decodable {
83+
let name: String
84+
let direction: String
85+
let amount: Double?
86+
let pixels: Double?
87+
let referenceWidth: Double
88+
let referenceHeight: Double
89+
let expected: Expected
12490
}
12591

126-
func testRunnerScrollGesturePlanClampsExplicitPixelsVertically() throws {
127-
// 400x800, down, pixels 1000 clamps travel to the safe band (640): (200,720)->(200,80).
128-
let plan = try XCTUnwrap(
129-
runnerScrollGesturePlan(
130-
direction: "down",
131-
amount: nil,
132-
pixels: 1000,
133-
referenceWidth: 400,
134-
referenceHeight: 800
135-
)
136-
)
137-
XCTAssertEqual(plan.x1, 200)
138-
XCTAssertEqual(plan.y1, 720)
139-
XCTAssertEqual(plan.x2, 200)
140-
XCTAssertEqual(plan.y2, 80)
141-
XCTAssertEqual(plan.travelPixels, 640)
92+
let constants: Constants
93+
let cases: [Case]
94+
}
95+
96+
extension RunnerTests {
97+
// Cross-language parity table: every case in contracts/fixtures/scroll-gesture.json must agree
98+
// with the vitest twin (packages/contracts/src/scroll-gesture.test.ts). Add vectors there,
99+
// never fork the math.
100+
private func loadScrollGestureFixture() throws -> ScrollGestureFixture {
101+
let fixtureURL = URL(fileURLWithPath: #filePath)
102+
.deletingLastPathComponent() // AgentDeviceRunnerUITests
103+
.deletingLastPathComponent() // AgentDeviceRunner
104+
.deletingLastPathComponent() // runner
105+
.deletingLastPathComponent() // apple
106+
.deletingLastPathComponent() // repo root
107+
.appendingPathComponent("contracts")
108+
.appendingPathComponent("fixtures")
109+
.appendingPathComponent("scroll-gesture.json")
110+
return try JSONDecoder().decode(ScrollGestureFixture.self, from: Data(contentsOf: fixtureURL))
142111
}
143112

144-
func testRunnerScrollGesturePlanFloorsTinyFrames() throws {
145-
// 2x2, down, pixels 10 engages every max(1, ...) floor and the .5 rounding cases the two
146-
// ports must agree on (halfTravel 0.5 -> 1, center 1 from 2/2): (1,2)->(1,0), travel 1.
147-
let plan = try XCTUnwrap(
148-
runnerScrollGesturePlan(
149-
direction: "down",
150-
amount: nil,
151-
pixels: 10,
152-
referenceWidth: 2,
153-
referenceHeight: 2
113+
func testRunnerScrollGesturePlanMatchesParityTable() throws {
114+
let fixture = try loadScrollGestureFixture()
115+
XCTAssertFalse(fixture.cases.isEmpty, "parity table must not be empty")
116+
for testCase in fixture.cases {
117+
let plan = try XCTUnwrap(
118+
runnerScrollGesturePlan(
119+
direction: testCase.direction,
120+
amount: testCase.amount,
121+
pixels: testCase.pixels,
122+
referenceWidth: testCase.referenceWidth,
123+
referenceHeight: testCase.referenceHeight
124+
),
125+
testCase.name
154126
)
155-
)
156-
XCTAssertEqual(plan.x1, 1)
157-
XCTAssertEqual(plan.y1, 2)
158-
XCTAssertEqual(plan.x2, 1)
159-
XCTAssertEqual(plan.y2, 0)
160-
XCTAssertEqual(plan.travelPixels, 1)
127+
XCTAssertEqual(plan.x1, testCase.expected.x1, testCase.name)
128+
XCTAssertEqual(plan.y1, testCase.expected.y1, testCase.name)
129+
XCTAssertEqual(plan.x2, testCase.expected.x2, testCase.name)
130+
XCTAssertEqual(plan.y2, testCase.expected.y2, testCase.name)
131+
XCTAssertEqual(plan.travelPixels, testCase.expected.pixels, testCase.name)
132+
}
161133
}
162134

163-
func testRunnerScrollGesturePlanClampsToSafeBand() throws {
164-
// 300x600, right, pixels 500 clamps travel to the safe band (240).
165-
let plan = try XCTUnwrap(
135+
// The planner constants are private on both sides; the table pins them behaviourally on a
136+
// 1000px axis where every rounding step is exact.
137+
func testRunnerScrollGesturePlanUsesParityTableConstants() throws {
138+
let constants = try loadScrollGestureFixture().constants
139+
let defaulted = try XCTUnwrap(
166140
runnerScrollGesturePlan(
167-
direction: "right",
168-
amount: nil,
169-
pixels: 500,
170-
referenceWidth: 300,
171-
referenceHeight: 600
141+
direction: "down", amount: nil, pixels: nil, referenceWidth: 1000, referenceHeight: 1000
172142
)
173143
)
174-
XCTAssertEqual(plan.x1, 270)
175-
XCTAssertEqual(plan.x2, 30)
176-
XCTAssertEqual(plan.y1, 300)
177-
XCTAssertEqual(plan.y2, 300)
178-
XCTAssertEqual(plan.travelPixels, 240)
179-
}
180-
181-
func testRunnerScrollGesturePlanKeepsSaturatedScrollUpOutOfStatusBar() throws {
182-
// 1080x2400, up, amount 3 (#1781 A1): the touch-down at y=240 clears a Pixel 7's 136px cutout
183-
// status bar; the 5% band used to start at y=120 and pulled the notification shade down.
184-
let plan = try XCTUnwrap(
144+
XCTAssertEqual(defaulted.travelPixels, 1000 * constants.defaultScrollAmount)
145+
let saturated = try XCTUnwrap(
185146
runnerScrollGesturePlan(
186-
direction: "up",
187-
amount: 3,
188-
pixels: nil,
189-
referenceWidth: 1080,
190-
referenceHeight: 2400
147+
direction: "down", amount: 10, pixels: nil, referenceWidth: 1000, referenceHeight: 1000
191148
)
192149
)
193-
XCTAssertEqual(plan.y1, 240)
194-
XCTAssertEqual(plan.y2, 2160)
195-
XCTAssertGreaterThan(plan.y1, 136)
150+
XCTAssertEqual(
151+
saturated.travelPixels, 1000 - 2 * 1000 * constants.defaultEdgePaddingFraction)
196152
}
197153

198154
func testRunnerScrollGesturePlanRejectsUnknownDirection() {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
{
2+
"constants": {
3+
"defaultScrollAmount": 0.6,
4+
"defaultEdgePaddingFraction": 0.1
5+
},
6+
"cases": [
7+
{
8+
"name": "relative amount maps to viewport travel: 400x800 down 0.5 -> (200,600)->(200,200), travel 400",
9+
"direction": "down",
10+
"amount": 0.5,
11+
"referenceWidth": 400,
12+
"referenceHeight": 800,
13+
"expected": { "x1": 200, "y1": 600, "x2": 200, "y2": 200, "pixels": 400 }
14+
},
15+
{
16+
"name": "explicit pixels below the safe band cap: 300x600 down 120px -> (150,360)->(150,240)",
17+
"direction": "down",
18+
"pixels": 120,
19+
"referenceWidth": 300,
20+
"referenceHeight": 600,
21+
"expected": { "x1": 150, "y1": 360, "x2": 150, "y2": 240, "pixels": 120 }
22+
},
23+
{
24+
"name": "amount above 1 clamps to the safe band: 400x800 down 2 -> requested 1600 clamps to 640, (200,720)->(200,80)",
25+
"direction": "down",
26+
"amount": 2,
27+
"referenceWidth": 400,
28+
"referenceHeight": 800,
29+
"expected": { "x1": 200, "y1": 720, "x2": 200, "y2": 80, "pixels": 640 }
30+
},
31+
{
32+
"name": "explicit pixels clamp to the vertical safe band: 400x800 down 1000px -> 640, (200,720)->(200,80)",
33+
"direction": "down",
34+
"pixels": 1000,
35+
"referenceWidth": 400,
36+
"referenceHeight": 800,
37+
"expected": { "x1": 200, "y1": 720, "x2": 200, "y2": 80, "pixels": 640 }
38+
},
39+
{
40+
"name": "tiny frame engages every max(1, ...) floor and the .5 rounding both ports must agree on: 2x2 down 10px -> (1,2)->(1,0), travel 1",
41+
"direction": "down",
42+
"pixels": 10,
43+
"referenceWidth": 2,
44+
"referenceHeight": 2,
45+
"expected": { "x1": 1, "y1": 2, "x2": 1, "y2": 0, "pixels": 1 }
46+
},
47+
{
48+
"name": "explicit pixels clamp to the horizontal safe band: 300x600 right 500px -> 240, (270,300)->(30,300)",
49+
"direction": "right",
50+
"pixels": 500,
51+
"referenceWidth": 300,
52+
"referenceHeight": 600,
53+
"expected": { "x1": 270, "y1": 300, "x2": 30, "y2": 300, "pixels": 240 }
54+
},
55+
{
56+
"name": "#1781 A1: a saturated scroll up on a Pixel 7 (1080x2400) touches down at y=240, clear of its 136px cutout status bar; the 5% band started at y=120 and pulled the notification shade",
57+
"direction": "up",
58+
"amount": 3,
59+
"referenceWidth": 1080,
60+
"referenceHeight": 2400,
61+
"expected": { "x1": 540, "y1": 240, "x2": 540, "y2": 2160, "pixels": 1920 }
62+
}
63+
]
64+
}

0 commit comments

Comments
 (0)