Commit 0905319
refactor(core,cli-app): decompose merged self-hosted Maestro relay + app:exec injection (#2315)
* refactor(core): extract /percy/comparison/upload handler into comparison-upload.js
Move handleComparisonUpload out of api.js into its own module (handleSyncJob
extraction pattern); promote the shared encodeURLSearchParams helper to utils.js
so both api.js and the new module use it without a circular import. No behavior
change.
* refactor(core): decompose /percy/maestro-screenshot relay (incl. self-hosted) into modules
Extract the ~517-line maestro-screenshot handler out of api.js into cohesive
modules, folding in #2261's self-hosted branches:
- maestro-screenshot.js — handleMaestroScreenshot orchestrator + parsePngDimensions;
runtime detection (selfHosted = !sessionId), conditional sessionId validation,
PERCY_MAESTRO_SCREENSHOT_DIR scope-root resolution + filePath rejection.
- maestro-screenshot-file.js — locateScreenshot({...,scopeRoot,selfHosted}):
BS session glob + self-hosted recursive dot:true glob (Windows-normalized) +
manualScreenshotWalk (BS only) + realpath/scopeRoot prefix check.
- maestro-regions.js — validateRegionInputs + resolveRegions (explicit-key merge).
api.js is now a route table (1072 → 382 lines) delegating via named imports;
dead ServerError/maestro-hierarchy imports dropped. semgrep path-traversal
suppression retargeted to maestro-screenshot-file.js (+ api.js createStaticServer).
Behavior-preserving: api.test.js (BS + self-hosted) passes unchanged.
* refactor(cli-app): extract Maestro argv/env injection into maestro-inject.js
Move maybeInjectMaestroServer + maybeInjectScreenshotDir (and the private argv
helpers findTestSubcommandIdx / hasExistingPercyServerFlag / findTestOutputDirValue
+ constants) out of exec.js into a dedicated maestro-inject.js. exec.js returns
to a thin command (211 → 47 lines) whose app:exec callback calls the injectors;
index.js re-exports them from the new module. No behavior change — exec.test.js
43/43 unchanged (imports via the @percy/cli-app barrel).
* feat(core): add device system-bar inset derivation to maestro-hierarchy
Port deriveDeviceInsets (+ findStatusBarFrameHeight, deriveIosInsets,
parseStableInsets, deriveAndroidInsets) from PR #2286 onto the decomposed
modules: iOS status bar from /viewHierarchy statusBars frame × empirical PNG
scale; Android status+nav via adb dumpsys mStableInsets; iOS navBar always 0;
null on any failure. Additive; dump()/resolver cascade untouched. ~25 specs.
* feat(core): per-session maestroInsetCache on the Percy instance
Add this.maestroInsetCache (Map keyed by sessionId), constructed alongside
grpcClientCache and cleared in stop() — insets are device-constant within a
session, so the relay derives once and reuses (incl. a null outcome). Ported
from PR #2286.
* feat(core): wire device-inset derivation into the Maestro relay
handleMaestroScreenshot derives insets once per session (cached) and uses them
for the tile's statusBarHeight/navBarHeight, authoritative over the SDK static
defaults; iOS navBar=0; any failure falls back to the SDK value. Relay
override/fallback/iOS-0/derive-and-cache specs + the beforeEach cache-seed seam,
ported from PR #2286 onto the self-hosted-inclusive orchestrator.
* feat(cli-app): auto-inject --driver-host-port on Maestro 2.6+ (iOS)
Maestro 2.6.0 changed the iOS driver to bind an OS-assigned ephemeral port
(ServerSocket(0)); <= 2.4.0 bound the deterministic 7001. The @percy/core relay
resolves the iOS /viewHierarchy port via PERCY_IOS_DRIVER_HOST_PORT, then a
127.0.0.1:7001 probe — which finds nothing on 2.6+, so self-hosted iOS element
regions (and device insets, whose relay path is env-only with no probe) degrade.
maybeInjectDriverHostPort picks a free port, pins Maestro's iOS driver to it via
--driver-host-port <port>, and mirrors it to process.env.PERCY_IOS_DRIVER_HOST_PORT
so the relay (same Node process) targets it deterministically. Version-gated:
the flag is a fatal Unknown option on <= 2.4.0 (the reason 13616a8 was reverted),
so it fires only on Maestro >= 2.6.0; older versions no-op and the relay's 7001
probe serves them. Conservatively gated to iOS (--platform=ios/-p ios), skips
sharded runs (a single pinned port collides), respects customer overrides, and
no-ops on any version-detection failure. BrowserStack is unaffected (host-injected
port; never routes through app:exec).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* fix(cli-app): degrade gracefully if free-port reservation fails
Address code-review findings on the --driver-host-port injector:
- Wrap the pickFreePort() call in try/catch — an OS listen(0) failure now
warns and no-ops (falling back to the relay's 127.0.0.1:7001 probe) instead
of crashing app:exec with an unattributed rejection and leaving Maestro 2.6+
iOS with no port at all. Matches the graceful-degradation pattern used by
every other failure path in the helper.
- Start findDriverHostPortValue's scan at i=1 for consistency with the sibling
finders (skip args[0], the executable).
- Refresh the stale "two helpers" comment in exec.js (now three; iOS argv shape).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
* test(core): cover canonicalHost malformed-IPv6 catch branch (utils.js:103)
The CORS/SSRF hardening in #2282 added canonicalHost's `catch { return bare }`
fallback for colon-bearing hosts that are not valid IPv6 literals, but no test
exercised it — leaving utils.js line 103 uncovered and dropping @percy/core
below the 100% NYC gate (a failure pre-existing on master's HEAD).
Add an isMetadataIP('gg::1') case: the invalid IPv6 makes `new URL` throw, so
canonicalHost returns the raw value and the non-metadata address is allowed
through (null). Restores 100% coverage.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 3f32984 commit 0905319
17 files changed
Lines changed: 1992 additions & 876 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
33 | 41 | | |
34 | 42 | | |
35 | 43 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | 1 | | |
5 | 2 | | |
| 3 | + | |
6 | 4 | | |
7 | 5 | | |
8 | 6 | | |
| |||
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
113 | | - | |
114 | | - | |
115 | | - | |
116 | | - | |
117 | | - | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
142 | | - | |
143 | | - | |
144 | | - | |
145 | | - | |
146 | | - | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
180 | | - | |
181 | | - | |
182 | | - | |
183 | 19 | | |
184 | 20 | | |
185 | 21 | | |
| |||
199 | 35 | | |
200 | 36 | | |
201 | 37 | | |
202 | | - | |
203 | | - | |
204 | | - | |
205 | | - | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
210 | 50 | | |
211 | 51 | | |
| 52 | + | |
212 | 53 | | |
213 | 54 | | |
214 | 55 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
| 3 | + | |
0 commit comments