Repository navigation
fix(cli): honour BROWSERSTACK_PROJECT_NAME / BROWSERSTACK_BUILD_NAME in session caps (SDK-7075) - #282
shivam5643 wants to merge 3 commits into
Conversation
The service read projectName/buildName only from the config file, so an
exported BROWSERSTACK_PROJECT_NAME / BROWSERSTACK_BUILD_NAME never reached
the session and the build was created under the config-file name.
Every other SDK already maps these (node-agent capsMapping.js, python
constants.py, javaagent SeleniumPatchUtils.java, csharp utils.cs) and so
does the binary's own env->config map (core/config/env.js). The binary
resolves them correctly here too, but the service consumes only hubUrl,
apis, credentials, accessibilityOptions and testContextOptions from that
resolved config, so the values were dropped before reaching the caps.
Write them into the capability at both shapes, mirroring the existing
localIdentifier handling, so the session carries the env value.
Verified against a wdio_cucumber sample in binary flow (SDK_CLI_BIN_PATH
pinned, cold cache). Session capabilities, config file vs env differing:
before platforms[0].projectName = 'repro_project'
platforms[0].buildName = 'repro_build'
after platforms[0].projectName = 'repro_project_env_vars'
platforms[0].buildName = 'repro_build_env_vars'
Refs SDK-7075. v9 counterpart of the same fix on v8.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…7075) Adds three constructor tests: the env vars win over the caps for both the array and the multiremote capability shapes, and the caps values survive when the env vars are unset. The two "prefer env" tests fail without the launcher change. Folding BROWSERSTACK_BUILD_NAME into the caps also means a buildName is now present whenever that var is exported, so _handleBuildIdentifier no longer treats it as missing and keeps the identifier instead of dropping it. Updates that test to the corrected contract and refreshes the SDK-4748 comments that asserted this service never reads the var as a buildName source. "buildName absent" now means absent from both the caps and the environment, which the BUILD_RUN_IDENTIFIER test already covers. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
|
v8 backport: #283 — same change, same tests, verified the same way. Please review the two together. |
|
🔴 SDK PR Review gate is red. Pending:
It turns green once the SDK PR Review Agent has run on the current head commit (any verdict — the gate only requires that the review ran). A native reviewer approval is separately required by branch protection before merge. |
What is this about?
BROWSERSTACK_PROJECT_NAMEandBROWSERSTACK_BUILD_NAMEwere ignored by this service. The launcher readprojectName/buildNameonly out of the capabilities, so a value exported in the environment never reached the session — the build landed on the dashboard under whatever the config file said.Every other SDK, and the binary's own env→config map, already give the environment precedence over the config file. The service was the one place that did not, so a user who overrides the build name per CI run (the standard pattern) silently got the config name instead.
The fix
In the constructor, before the
bstack:optionsvalues are folded intothis._buildName/this._projectName, take the env value when one is exported. Both capability shapes are covered — the array form and the multiremote object form.Writing it back into the caps (rather than only into the private field) is what makes the session itself carry the name; the private fields are assigned from the caps on the next lines, so Test Reporting picks the env value up too.
Knock-on:
_handleBuildIdentifier— please readBecause the env var is now folded into the caps, a
buildNameis present wheneverBROWSERSTACK_BUILD_NAMEis exported._handleBuildIdentifierdrops the identifier when!this._buildName, so that branch no longer fires in this case and the identifier is appended to the env-sourced name instead of being discarded.This is the direction already taken and approved in this repo, not a new one:
f1ebafc,079f4b8, merged) removed|| process.env.BROWSERSTACK_BUILD_NAMEfrom that guard, so the env var stopped suppressing the identifier.Together they give the coherent result: the env names the build, and the identifier is appended to it. The previously open #192 (SDK-4165) asked for the same end state and was superseded by SDK-4748.
The one test that encoded the old edge case — env var set, caps carrying no
buildName— asserted the identifier was dropped. Its premise is now self-contradictory, since the env var is abuildNamesource, so it is rewritten to assert the corrected contract. AbuildNamecounts as absent only when neither the caps nor the environment supply one, whichshould not set buildIdentifier from env when buildName is absentalready covers and which still passes unchanged. The SDK-4748 comments that asserted "this service never reads that var as a buildName source" are updated, since that is no longer true.Scope boundary
Only the
bstack:options(W3C) capability shape is covered. The legacy branch — caps with nobstack:options, where the build name comes from the top-levelbuildkey — is left as is. That is the shape the CLI flow never produces, and it is not the path SDK-7075 reproduces on.Verification
End to end, against a real session. The config file and the environment deliberately disagreed:
sdk7075repro_projectsdk7075v9_project_env_varssdk7075repro_buildsdk7075v9_build_env_vars v9_identifier_reproRun via the
automate/wdio_cucumberBStackAutomation sample (binary/CLI flow) —Spec Files: 1 passed, 1 total, session statuspassed. Both env values won; before the fix both came through as the config values. The identifier is appended, as described above.Unit tests. Three new constructor tests. Reverting only
launcher.tswhile keeping the tests makes the two "prefer env" tests fail, so they are not vacuous; the third ("keep the caps values when the env vars are not set") passes either way and is there as a no-regression guard.Full suite green on this branch: 61 files, 1386 tests passed, build clean.
Related Jira task/s
SDK-7075
Release (mandatory for every PR — required for the
ready-for-reviewlabel)Version bump: (required — tick exactly one)
Release notes type:
Release notes (customer-facing):
BROWSERSTACK_PROJECT_NAMEandBROWSERSTACK_BUILD_NAMEbeing ignored — the environment now takes precedence over the project and build names in your config file, matching the other BrowserStack SDKs.Release notes (internal):
BROWSERSTACK_PROJECT_NAME/BROWSERSTACK_BUILD_NAMEintobstack:optionsfor both the array and multiremote capability shapes, ahead of thethis._buildName/this._projectNameassignment, so the session and Test Reporting both carry the env value.buildNameis now present wheneverBROWSERSTACK_BUILD_NAMEis set, so_handleBuildIdentifierkeeps the identifier rather than dropping it. Completes the direction SDK-4748 started; the test encoding the old edge case is rewritten and the stale comments corrected.bstack:options) capability shape deliberately out of scope.Checklist
PR Validations
Run Tests: Comment RUN_TESTS to trigger sanity tests.
🤖 Generated with Claude Code