Repository navigation
fix(util): recognize *.bsstag.com hosts as BrowserStack (v8, SDK-6948) #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7ef36e1
25529d2
c4d9545
ccb370d
d91e729
61570d3
d0a8fba
0f1d173
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@wdio/browserstack-service": patch | ||
| --- | ||
|
|
||
| - SDK-6948: `*.bsstag.com` hubs are now recognised as BrowserStack on named internal staging envs (`BROWSERSTACK_STAGING_ENV` / `BROWSERSTACK_ENV`), so with the CLI flow (default) session marking and TRA linking work there. The classic (non-CLI) flow on a named staging env is not supported; its session update is skipped at debug. | ||
| - SDK-6948: `update_cli` failures fall back to `BROWSERSTACK_BINARY_URL`. A failed fallback download uses the cached binary. | ||
| - SDK-6948: `_printSessionURL` and `_update` log a failed session lookup or update (HTTP error) at debug instead of throwing. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@wdio/browserstack-service": patch | ||
| --- | ||
|
|
||
| fix(cli): fall back to `BROWSERSTACK_BINARY_URL` when `update_cli` fails (SDK-6948) | ||
|
|
||
| `update_cli` runs during bootstrap — before the binary is spawned and before GRR localizes the API hosts — so it always targets production `api.browserstack.com`. On an internal staging run (`BROWSERSTACK_STAGING_ENV`) the staging credentials are rejected there (`401`), which left the CLI binary path empty and crashed the launcher with `spawn('') … ERR_INVALID_ARG_VALUE: 'file' cannot be empty`. When `update_cli` fails and `BROWSERSTACK_BINARY_URL` is set, download the binary from that URL instead so the run can proceed; the same applies when a 2xx reply carries no download URL and no binary is cached. If that download fails, the cached binary is used when there is one, and both errors are logged. Opt-in only — with the variable unset the original error propagates exactly as before. Ports main/v9 #224 to the v8 line. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "@wdio/browserstack-service": patch | ||
| --- | ||
|
|
||
| fix(util): recognize `*.bsstag.com` hosts as BrowserStack on internal staging envs (SDK-6948) | ||
|
|
||
| `getCloudProvider` and `isBrowserstackInfra` only matched `browserstack.com`, so a session pointed at an internal staging env (`*.bsstag.com`) was classified as non-BrowserStack: session marking and Automate <-> TRA session linking did not work there. `*.bsstag.com` hosts are now treated as BrowserStack when `BROWSERSTACK_STAGING_ENV` is a bare env name (e.g. `k8s`, trimmed; blank means unset) or `BROWSERSTACK_ENV` is `staging`/`stag`/`preprod`/`pre-prod`. Hosts are matched case-insensitively. Production behaviour is unchanged. With the CLI flow (the default), session marking and Automate <-> TRA session linking now work on those envs, because the binary supplies the staging session REST host. The classic (non-CLI) flow on a named staging env is not supported: it has no staging session REST host, so the session name/status update is skipped at debug instead of failing the hook. `_printSessionURL` and `_update` log a failed session lookup or update (HTTP error reply) at debug instead of throwing. Ports main/v9 #275 to the v8 line. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -794,18 +794,27 @@ export default class BrowserstackService implements Services.ServiceInstance { | |
| } | ||
| const sessionUrl = `${this._sessionBaseUrl}/${sessionId}.json` | ||
| BStackLogger.debug(`Updating Browserstack session at ${sessionUrl} with request body: `, requestBody) | ||
| // SDK-6948: an HTTP error reply (e.g. 401/404 from a named staging env's session REST host) | ||
| // must not fail the calling hook. got rejects on non-2xx; main/v9 uses fetch, which resolves, | ||
| // so only HTTP-status errors are swallowed here and network errors still propagate. | ||
| const onHttpError = (err: { response?: { statusCode?: number } }) => { | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Critical (reviewer note: should be
|
||
| if (!err?.response) { | ||
| throw err | ||
| } | ||
| BStackLogger.debug(`Could not update Browserstack session (${err.response.statusCode}) at ${sessionUrl}`) | ||
| } | ||
| if (this._turboScale) { | ||
| return got.patch(sessionUrl, { | ||
| json: requestBody, | ||
| username: this._config.user, | ||
| password: this._config.key | ||
| }) | ||
| }).catch(onHttpError) | ||
| } | ||
| return got.put(sessionUrl, { | ||
| json: requestBody, | ||
| username: this._config.user, | ||
| password: this._config.key | ||
| }) | ||
| }).catch(onHttpError) | ||
| } | ||
|
|
||
| @PerformanceTester.Measure(PERFORMANCE_SDK_EVENTS.AUTOMATE_EVENTS.PRINT_BUILDLINK) | ||
|
|
@@ -824,12 +833,25 @@ export default class BrowserstackService implements Services.ServiceInstance { | |
| responseType: 'json' | ||
| } | ||
|
|
||
| if (this._turboScale) { | ||
| const response = await got<TurboScaleSessionResponse>(sessionUrl, reqOpts) | ||
| browserUrl = response.body.url | ||
| } else { | ||
| const response = await got<SessionResponse>(sessionUrl, reqOpts) | ||
| browserUrl = response.body.automation_session.browser_url | ||
| try { | ||
| if (this._turboScale) { | ||
| const response = await got<TurboScaleSessionResponse>(sessionUrl, reqOpts) | ||
| browserUrl = response.body.url | ||
| } else { | ||
| const response = await got<SessionResponse>(sessionUrl, reqOpts) | ||
| const session = response.body?.automation_session | ||
| if (!session) { | ||
| BStackLogger.debug(`Could not fetch Browserstack session URL (${response.statusCode}) at ${sessionUrl}`) | ||
| return | ||
| } | ||
| browserUrl = session.browser_url | ||
| } | ||
| } catch (err) { | ||
| // SDK-6948: on a named staging env the session REST host may not serve this session | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔴 Critical (reviewer note: should be
|
||
| // (e.g. classic non-CLI flow). Printing the link is informational, so don't fail the hook. | ||
| const status = (err as { response?: { statusCode?: number } })?.response?.statusCode ?? (err as Error)?.message | ||
| BStackLogger.debug(`Could not fetch Browserstack session URL (${status}) at ${sessionUrl}`) | ||
| return | ||
| } | ||
|
|
||
| if (!this._browser) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Suggestion (engine: 🔴 Critical, overridden: changelog nit) — [MAINTAINABILITY] The changelog will list each SDK-6948 fix twice
Problem
pr-183.mdis auto-generated by.github/workflows/changeset-from-pr.ymlfrom the PR body's## Releasesection. It restates the two hand-written changesets,sdk-6948-v8-binary-url-fallback.mdandsdk-6948-v8-bsstag-host-recognition.md. All three arepatchfor@wdio/browserstack-service, so the "Version Packages" changelog will carry each fix twice.Suggested Fix (non-blocking)
Pick one source:
pr-183.md, which already covers all three points. Don't deletepr-183.mditself: the bot regenerates it on every PR body edit.skip-changesetlabel and keep the hand-written ones.Verified at
0f1d1732: all three files are in.changeset/, andpr-183.md's commits are bygithub-actions[bot]("auto-generate from PR template").