@percy/core 1.32.8-beta.2 → 1.32.8-beta.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/config.js CHANGED
@@ -425,6 +425,10 @@ export const configSchema = {
425
425
  minLength: 1
426
426
  }
427
427
  },
428
+ enablePseudoClassSerialization: {
429
+ type: 'boolean',
430
+ default: false
431
+ },
428
432
  pseudoClassEnabledElements: {
429
433
  type: 'object',
430
434
  additionalProperties: false,
@@ -753,6 +757,9 @@ export const snapshotSchema = {
753
757
  ignoreIframeSelectors: {
754
758
  $ref: '/config/snapshot#/properties/ignoreIframeSelectors'
755
759
  },
760
+ enablePseudoClassSerialization: {
761
+ $ref: '/config/snapshot#/properties/enablePseudoClassSerialization'
762
+ },
756
763
  pseudoClassEnabledElements: {
757
764
  $ref: '/config/snapshot#/properties/pseudoClassEnabledElements'
758
765
  },
package/dist/discovery.js CHANGED
@@ -60,6 +60,7 @@ function debugSnapshotOptions(snapshot) {
60
60
  debugProp(snapshot, 'ignoreCanvasSerializationErrors');
61
61
  debugProp(snapshot, 'ignoreStyleSheetSerializationErrors');
62
62
  debugProp(snapshot, 'pseudoClassEnabledElements', JSON.stringify);
63
+ debugProp(snapshot, 'enablePseudoClassSerialization');
63
64
  debugProp(snapshot, 'discovery.autoConfigureAllowedHostnames');
64
65
  if (Array.isArray(snapshot.domSnapshot)) {
65
66
  debugProp(snapshot, 'domSnapshot.0.userAgent');
@@ -1,6 +1,7 @@
1
1
  import fs from 'fs';
2
2
  import path from 'path';
3
3
  import { ServerError } from './server.js';
4
+ const MAX_SEARCH_DEPTH = 15;
4
5
 
5
6
  // Root under which BrowserStack App Automate hosts write Maestro session
6
7
  // artifacts (screenshots + debug output). Historically /tmp; hosts that
@@ -14,6 +15,12 @@ export function appAutomateTmpDir() {
14
15
  let dir = (process.env.PERCY_APP_AUTOMATE_TMP_DIR || '/tmp').replace(/[/\\]+$/, '');
15
16
  return path.isAbsolute(dir) ? dir : '/tmp';
16
17
  }
18
+ export function bsScopeRootOverride() {
19
+ let raw = process.env.PERCY_MAESTRO_BS_SCOPE_ROOT;
20
+ if (!raw) return null;
21
+ let dir = raw.replace(/[/\\]+$/, '');
22
+ return path.isAbsolute(dir) ? dir : null;
23
+ }
17
24
 
18
25
  /* istanbul ignore next — defensive manual directory walker invoked only when
19
26
  fast-glob import fails (broken install / FS corruption). Unit tests
@@ -21,31 +28,35 @@ export function appAutomateTmpDir() {
21
28
  the walker against real session layouts. Path-traversal sinks inside this
22
29
  function are suppressed at file level in .semgrepignore with the same
23
30
  rationale (upstream SAFE_ID validation, depth cap, exact filename match). */
24
- async function manualScreenshotWalk(platform, sessionId, name) {
31
+ async function manualScreenshotWalk(platform, sessionId, name, scopeRoot) {
25
32
  const files = [];
26
- try {
27
- if (platform === 'ios') {
28
- const sessionDir = `${appAutomateTmpDir()}/${sessionId}`;
29
- const walk = async (dir, depth) => {
30
- if (depth > 15) return; // sanity cap
31
- let entries;
32
- try {
33
- entries = await fs.promises.readdir(dir, {
34
- withFileTypes: true
35
- });
36
- } catch {
37
- return;
38
- }
39
- for (const entry of entries) {
40
- const full = path.join(dir, entry.name);
41
- if (entry.isDirectory()) {
42
- await walk(full, depth + 1);
43
- } else if (entry.isFile() && entry.name === `${name}.png` && full.includes('_maestro_debug_')) {
44
- files.push(full);
45
- }
33
+ const walkFrom = async (root, accept) => {
34
+ const walk = async (dir, depth) => {
35
+ if (depth > MAX_SEARCH_DEPTH) return;
36
+ let entries;
37
+ try {
38
+ entries = await fs.promises.readdir(dir, {
39
+ withFileTypes: true
40
+ });
41
+ } catch {
42
+ return;
43
+ }
44
+ for (const entry of entries) {
45
+ const full = path.join(dir, entry.name);
46
+ if (entry.isDirectory()) {
47
+ await walk(full, depth + 1);
48
+ } else if (entry.isFile() && entry.name === `${name}.png` && accept(full)) {
49
+ files.push(full);
46
50
  }
47
- };
48
- await walk(sessionDir, 0);
51
+ }
52
+ };
53
+ await walk(root, 0);
54
+ };
55
+ try {
56
+ if (scopeRoot) {
57
+ await walkFrom(scopeRoot, () => true);
58
+ } else if (platform === 'ios') {
59
+ await walkFrom(`${appAutomateTmpDir()}/${sessionId}`, full => full.includes('_maestro_debug_'));
49
60
  } else {
50
61
  const baseDir = `${appAutomateTmpDir()}/${sessionId}_test_suite/logs`;
51
62
  const logDirs = await fs.promises.readdir(baseDir);
@@ -78,8 +89,10 @@ export async function locateScreenshot({
78
89
  name,
79
90
  filePath,
80
91
  scopeRoot,
81
- selfHosted
92
+ selfHosted,
93
+ recursiveScope
82
94
  }) {
95
+ let scopedGlob = selfHosted || !!recursiveScope;
83
96
  let chosenFile;
84
97
  if (filePath) {
85
98
  chosenFile = filePath;
@@ -94,7 +107,7 @@ export async function locateScreenshot({
94
107
  // (scopeRoot = PERCY_MAESTRO_SCREENSHOT_DIR). `name` is SAFE_ID-validated
95
108
  // by the caller, so it cannot contain separators or traversal chars.
96
109
  let searchPattern;
97
- if (selfHosted) {
110
+ if (scopedGlob) {
98
111
  // fast-glob requires forward-slashes in patterns on every platform; on
99
112
  // Windows scopeRoot contains backslashes, so normalize before embedding.
100
113
  // Production-code Windows portability — verified by the CI Windows runner.
@@ -111,12 +124,9 @@ export async function locateScreenshot({
111
124
  let {
112
125
  default: glob
113
126
  } = await import('fast-glob');
114
- // Self-hosted needs `dot: true` because Maestro's default output dir is
115
- // `.maestro/` — a dot-prefixed entry fast-glob hides by default. BS
116
- // layouts have no dot-prefixed segments, so omitting it there keeps the
117
- // byte-identical behavior.
118
- files = await glob(searchPattern, selfHosted ? {
119
- dot: true
127
+ files = await glob(searchPattern, scopedGlob ? {
128
+ dot: true,
129
+ deep: MAX_SEARCH_DEPTH
120
130
  } : undefined);
121
131
  } catch {
122
132
  // Fast-glob import / glob call failed — fall back to manual walker (BS
@@ -125,7 +135,7 @@ export async function locateScreenshot({
125
135
  // See manualScreenshotWalk() at file top + the file-level .semgrepignore.
126
136
  /* istanbul ignore next — only fires when fast-glob import throws
127
137
  (broken install / FS corruption); integration-test territory. */
128
- files = selfHosted ? [] : await manualScreenshotWalk(platform, sessionId, name);
138
+ files = selfHosted ? [] : await manualScreenshotWalk(platform, sessionId, name, recursiveScope ? scopeRoot : null);
129
139
  }
130
140
  if (!files || files.length === 0) {
131
141
  throw new ServerError(404, `Screenshot not found: ${name}.png (searched ${searchPattern})`);
@@ -177,7 +187,8 @@ export async function locateScreenshot({
177
187
  const realPathFwd = realPath.replace(/\\/g, '/');
178
188
  const realPrefixFwd = realPrefix.replace(/\\/g, '/');
179
189
  if (!realPathFwd.startsWith(`${realPrefixFwd}/`)) {
180
- throw new ServerError(404, `Screenshot not found: ${name}.png (resolved outside ${selfHosted ? 'PERCY_MAESTRO_SCREENSHOT_DIR' : 'session dir'})`);
190
+ const scopeLabel = selfHosted ? 'PERCY_MAESTRO_SCREENSHOT_DIR' : recursiveScope ? 'PERCY_MAESTRO_BS_SCOPE_ROOT' : 'session dir';
191
+ throw new ServerError(404, `Screenshot not found: ${name}.png (resolved outside ${scopeLabel})`);
181
192
  }
182
193
  return realPath;
183
194
  }
@@ -4,7 +4,7 @@ import { normalize } from '@percy/config/utils';
4
4
  import { ServerError } from './server.js';
5
5
  import { encodeURLSearchParams } from './utils.js';
6
6
  import { handleSyncJob } from './snapshot.js';
7
- import { locateScreenshot, appAutomateTmpDir } from './maestro-screenshot-file.js';
7
+ import { locateScreenshot, appAutomateTmpDir, bsScopeRootOverride } from './maestro-screenshot-file.js';
8
8
  import { validateRegionInputs, resolveRegions } from './maestro-regions.js';
9
9
  import { deriveDeviceInsets } from './maestro-hierarchy.js';
10
10
 
@@ -103,6 +103,7 @@ export async function handleMaestroScreenshot(req, res, percy) {
103
103
  // realpath + prefix check inside locateScreenshot enforces the security
104
104
  // invariant at whichever root applies; the boundary is relocated, not removed.
105
105
  let scopeRoot;
106
+ let recursiveScope = false;
106
107
  if (selfHosted) {
107
108
  // Reject filePath outright in self-hosted mode. The SDK never emits it (it
108
109
  // sends a relative SCREENSHOT_NAME); honoring an absolute filePath against
@@ -133,8 +134,24 @@ export async function handleMaestroScreenshot(req, res, percy) {
133
134
  throw new ServerError(400, `PERCY_MAESTRO_SCREENSHOT_DIR is not an existing directory: ${dir}`);
134
135
  }
135
136
  scopeRoot = dir;
137
+ recursiveScope = true;
136
138
  } else {
137
- scopeRoot = platform === 'ios' ? `${appAutomateTmpDir()}/${sessionId}` : `${appAutomateTmpDir()}/${sessionId}_test_suite`;
139
+ let overrideRoot = bsScopeRootOverride();
140
+ if (overrideRoot) {
141
+ var _sessionStat;
142
+ recursiveScope = true;
143
+ let sessionScoped = `${overrideRoot}/${sessionId}`;
144
+ let sessionStat;
145
+ try {
146
+ sessionStat = await fs.promises.stat(sessionScoped);
147
+ } catch {
148
+ sessionStat = null;
149
+ }
150
+ scopeRoot = (_sessionStat = sessionStat) !== null && _sessionStat !== void 0 && _sessionStat.isDirectory() ? sessionScoped : overrideRoot;
151
+ percy.log.debug(`maestro screenshot scope root: ${scopeRoot}`);
152
+ } else {
153
+ scopeRoot = platform === 'ios' ? `${appAutomateTmpDir()}/${sessionId}` : `${appAutomateTmpDir()}/${sessionId}_test_suite`;
154
+ }
138
155
  }
139
156
 
140
157
  // Validate regions input shape early (before file I/O and ADB work) so
@@ -150,7 +167,8 @@ export async function handleMaestroScreenshot(req, res, percy) {
150
167
  name,
151
168
  filePath: suppliedFilePath,
152
169
  scopeRoot,
153
- selfHosted
170
+ selfHosted,
171
+ recursiveScope
154
172
  });
155
173
 
156
174
  // Read and base64-encode the screenshot
package/dist/page.js CHANGED
@@ -262,7 +262,8 @@ export class Page {
262
262
  ignoreCanvasSerializationErrors,
263
263
  ignoreStyleSheetSerializationErrors,
264
264
  ignoreIframeSelectors,
265
- pseudoClassEnabledElements
265
+ pseudoClassEnabledElements,
266
+ enablePseudoClassSerialization
266
267
  } = snapshot;
267
268
  this.log.debug(`Taking snapshot: ${name}${width ? ` @${width}px` : ''}`, this.meta);
268
269
 
@@ -337,7 +338,8 @@ export class Page {
337
338
  ignoreCanvasSerializationErrors,
338
339
  ignoreStyleSheetSerializationErrors,
339
340
  ignoreIframeSelectors,
340
- pseudoClassEnabledElements
341
+ pseudoClassEnabledElements,
342
+ enablePseudoClassSerialization
341
343
  });
342
344
 
343
345
  // Attach readiness diagnostics onto the captured DOM snapshot so the backend/UI can surface
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@percy/core",
3
- "version": "1.32.8-beta.2",
3
+ "version": "1.32.8-beta.4",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -46,12 +46,12 @@
46
46
  "dependencies": {
47
47
  "@grpc/grpc-js": "^1.14.3",
48
48
  "@grpc/proto-loader": "^0.8.0",
49
- "@percy/client": "1.32.8-beta.2",
50
- "@percy/config": "1.32.8-beta.2",
51
- "@percy/dom": "1.32.8-beta.2",
52
- "@percy/logger": "1.32.8-beta.2",
53
- "@percy/monitoring": "1.32.8-beta.2",
54
- "@percy/webdriver-utils": "1.32.8-beta.2",
49
+ "@percy/client": "1.32.8-beta.4",
50
+ "@percy/config": "1.32.8-beta.4",
51
+ "@percy/dom": "1.32.8-beta.4",
52
+ "@percy/logger": "1.32.8-beta.4",
53
+ "@percy/monitoring": "1.32.8-beta.4",
54
+ "@percy/webdriver-utils": "1.32.8-beta.4",
55
55
  "adm-zip": "^0.6.0",
56
56
  "busboy": "^1.6.0",
57
57
  "content-disposition": "^0.5.4",
@@ -67,7 +67,7 @@
67
67
  "yaml": "^2.4.1"
68
68
  },
69
69
  "optionalDependencies": {
70
- "@percy/cli-doctor": "1.32.8-beta.2"
70
+ "@percy/cli-doctor": "1.32.8-beta.4"
71
71
  },
72
- "gitHead": "3886c115aa583e2c5af3b16643dd34c379415f5b"
72
+ "gitHead": "8cb91228f629119207fa169f8db8388d66e0c2e0"
73
73
  }