feat(webdriver-utils): env-var overrides for staging/percy-dev testing#2274
feat(webdriver-utils): env-var overrides for staging/percy-dev testing#2274bhokaremoin wants to merge 2 commits into
Conversation
Replace manual node_modules edits with env vars that default to prod: - PERCY_ENABLE_DEV=true injects projectId:'percy-dev' once at the shared browserstackExecutor chokepoint (covers begin/end + automate/playwright getTiles); omitted entirely when unset, so prod payloads are unchanged. - PERCY_CDP_DOMAIN overrides the Playwright driver CDP host. - PERCY_AUTOMATE_DOMAIN overrides the Automate debug-URL host. Adopts the existing Python percy-appium-app PERCY_ENABLE_DEV convention so one export works across JS + Python. Adds tests for on/off/non-screenshot paths and host overrides. Usage runbook lives in internal docs (not this public repo) to avoid exposing staging cluster hostnames. 🤖 Generated with Claude Opus 4.8 (1M context) via Claude Code + Compound Engineering v2.50.0 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bhokaremoin
left a comment
There was a problem hiding this comment.
Claude Code Review (automated) — 2 inline finding(s). Full report in the PR comment below. Verdict: Passed.
Claude Code PR ReviewPR: #2274 • Head: 364dded • Reviewers: stack:code-reviewer SummaryAdds three developer-only, default-off environment-variable overrides to Review Table
FindingsAll findings below are Low severity for this PR's context (an internal, env-gated, default-off developer override). The original reviewer rated [1] Critical and [2]/[3] High; those severities are downgraded here after verifying the real call sites and threat model — documented so the rationale is transparent.
Verdict: PASS — Small, focused, well-tested change that defaults to byte-identical production behavior when the new env vars are unset. Remaining findings are optional Low-severity hardening/nits, not blockers. |
364dded to
ae01e19
Compare
…cutor Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
bhokaremoin
left a comment
There was a problem hiding this comment.
Claude Code Review (automated) — 4 inline finding(s). Full report in the PR comment below. Verdict: Passed.
|
|
||
| async setDebugUrl() { | ||
| if (!this.driver) throw new Error('Driver is null, please initialize driver with createDriver().'); | ||
| const automateDomain = process.env.PERCY_AUTOMATE_DOMAIN || 'automate.browserstack.com'; |
There was a problem hiding this comment.
[Medium] Cache key omits the domain — stale debug URL on repeated setDebugUrl calls
automateDomain is captured by the Cache.withCache closure, but the cache key is only this.driver.sessionId. A second setDebugUrl call for the same session with a different PERCY_AUTOMATE_DOMAIN returns the stale cached URL. Unreachable in real usage (env vars are fixed at process launch), but it's the kind of hazard this staging workflow could trip in test harnesses — the new test already needs Cache.reset() to dodge it.
Suggestion: Drop the Cache.withCache wrapper entirely — the URL is a pure template-string construction with nothing async to cache — or include the domain in the cache key.
Reviewer: stack:code-reviewer
| async browserstackExecutor(action, args) { | ||
| if (!this.driver) throw new Error('Driver is null, please initialize driver with createDriver().'); | ||
| if (action === 'percyScreenshot' && process.env.PERCY_ENABLE_DEV === 'true') { | ||
| args = { ...args, projectId: 'percy-dev' }; |
There was a problem hiding this comment.
[Low] Spread on possibly-absent args is a latent hazard
If browserstackExecutor('percyScreenshot') were ever called without args, this spread turns a previously argument-less payload into arguments: { projectId: 'percy-dev' }. All current call sites pass an object, so this is latent only.
Suggestion: args = { ...(args || {}), projectId: 'percy-dev' }; to make the intent explicit.
Reviewer: stack:code-reviewer
| } | ||
| const options = this.requestPostOptions(command); | ||
| const baseUrl = `https://cdp.browserstack.com/wd/hub/session/${this.sessionId}/execute`; | ||
| const cdpDomain = process.env.PERCY_CDP_DOMAIN || 'cdp.browserstack.com'; |
There was a problem hiding this comment.
[Low] Domain env vars are interpolated without validation
PERCY_CDP_DOMAIN (and PERCY_AUTOMATE_DOMAIN in the providers) is interpolated into the URL unvalidated. Practical risk is very low: the scheme is hardcoded to https:// and these are internal-developer-only vars.
Suggestion: Optional — validate against a hostname pattern if these ever become user-facing.
Reviewer: stack:code-reviewer
| }); | ||
|
|
||
| it('uses PERCY_AUTOMATE_DOMAIN when set', async () => { | ||
| Cache.reset(); |
There was a problem hiding this comment.
[Low] Unexplained Cache.reset() hides a test-order dependency
This reset is required because the preceding 'sets automate url' test populates bstackSessionDetails for the same session ID — without it this test would read the stale prod URL from cache. That order-dependence isn't stated anywhere.
Suggestion: Add a one-line comment explaining why the reset is needed.
Reviewer: stack:code-reviewer
Claude Code PR ReviewPR: #2274 • Head: ce10d36 • Reviewers: stack:code-reviewer SummaryAdds three opt-in env-var overrides to Review Table
FindingsNo findings rise to Critical/High. The notable non-blocking items:
Verdict: PASS — no Critical/High findings; the Medium cache-key note is non-blocking (unreachable outside test harnesses) and the rest are nits. |
Summary
Makes the screenshot executor's project routing and the CDP / Automate host resolution optionally configurable, all defaulting to current behavior. No change unless explicitly opted in.
Changes
genericProvider.browserstackExecutor: optionally include aprojectIdin thepercyScreenshotpayload, injected once at this shared chokepoint (covers begin/end andgetTilesfor both the Automate and Playwright providers).playwrightDriver: CDP execute host is now resolved with a default ofcdp.browserstack.com.automateProvider/playwrightProvider: Automate debug-URL host resolved with a default ofautomate.browserstack.com.All three are opt-in and fall back to the existing values, so the default path is unchanged.
Testing
Post-Deploy Monitoring & Validation
No additional operational monitoring required: the overrides are opt-in and default to current production behavior; default-path payloads and hosts are byte-identical (covered by unit tests).
🤖 Generated with Claude Opus 4.8 (1M context) via Claude Code