Skip to content

fix(cli): honour BROWSERSTACK_PROJECT_NAME / BROWSERSTACK_BUILD_NAME in session caps (SDK-7075) - #282

Merged
Dalwin-Barnard merged 7 commits into
mainfrom
fix/SDK-7075-honour-project-name-env-v9
Oct 16, 2026
Merged

Dalwin-Barnard merged 7 commits into
mainfrom
fix/SDK-7075-honour-project-name-env-v9

Conversation

@shivam5643

@shivam5643 shivam5643 commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

What is this about?

BROWSERSTACK_PROJECT_NAME and BROWSERSTACK_BUILD_NAME were ignored by this service. The launcher read projectName / buildName only 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

A private helper, _applyEnvBuildNames(capability), reads BROWSERSTACK_PROJECT_NAME / BROWSERSTACK_BUILD_NAME (trimmed; blank values ignored) and writes them back into the capabilities, so the session itself carries them and this._buildName / this._projectName (Test Reporting) read the same values. It is called from all four capability arms in the constructor - array and multiremote, with and without bstack:options.

Knock-on: _handleBuildIdentifier — please read

Because the env var is now folded into the caps, a buildName is present whenever BROWSERSTACK_BUILD_NAME is exported (on a BrowserStack session, or whenever the caps carry bstack:options). _handleBuildIdentifier drops 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:

  • SDK-4748 (f1ebafc, 079f4b8, merged) removed || process.env.BROWSERSTACK_BUILD_NAME from that guard, so the env var stopped suppressing the identifier.
  • SDK-7075 (this PR) makes the env var supply the build name.

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 a buildName source, so it is rewritten to assert the corrected contract. A buildName counts as absent only when neither the caps nor the environment supply one, which should not set buildIdentifier from env when buildName is absent already 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

Capability shape What the env value does
has bstack:options overwrites bstack:options.projectName / buildName; any top-level project / build the caps already carry are aligned to the same value (never added there)
no bstack:options, extension caps (e.g. goog:chromeOptions), BrowserStack session written into the bstack:options the service creates
legacy caps (no bstack:options, no : keys), BrowserStack session written to the top-level project / build keys
non-BrowserStack session without bstack:options nothing - caps untouched, and _buildName / _projectName keep the caps values

Top-level project / build are only ever added where the caps have no : extension keys - webdriver rejects a capability mixing : extension keys with non-W3C unprefixed keys, and any capability with a : key gets bstack:options instead.

testObservabilityOptions.projectName / buildName, when set, still take precedence for Test Reporting naming (util.ts, cli/cliUtils.ts) - unchanged by this PR. The environment always wins for the session itself.

Verification

End to end, against a real session. The config file and the environment deliberately disagreed:

config file said dashboard shows
project sdk7075repro_project sdk7075v9_project_env_vars
build sdk7075repro_build sdk7075v9_build_env_vars v9_identifier_repro

Run via the automate/wdio_cucumber BStackAutomation sample (binary/CLI flow) — Spec Files: 1 passed, 1 total, session status passed. Both env values won; before the fix both came through as the config values. The identifier is appended, as described above.

Capability shapes checked directly against the hub - raw W3C POST /session to hub-cloud.browserstack.com, then GET api.browserstack.com/automate/sessions/<id>.json:

Request Recorded on the session
alwaysMatch {browserName, build, project} only - no bstack:options the top-level build / project values: the hub honours legacy keys in a W3C request
bstack:options {buildName, projectName} and top-level build / project with different values the bstack:options values: bstack:options wins, so the top-level alignment above is defensive

Unit tests. 11 constructor tests in a dedicated describe with afterEach env cleanup: prefer env, keep caps when unset, blank values ignored, padded values trimmed, build-only override, service-created bstack:options, legacy caps, aligned top-level keys, multiremote with and without bstack:options, and an untouched non-BrowserStack session; plus the rewritten _handleBuildIdentifier test. Against the base launcher.ts 8 of the 11 fail, so they are not vacuous; the other 3 (env unset, blank env, non-BrowserStack session) are no-regression guards that pass either way. launcher.test.ts: 143 passed.

Full suite on this branch: 61 files, 1394 tests passed (the 3 unhandled errors from uploadLogsArchive.test.ts are pre-existing - identical on the base commit), tsc and eslint clean.

Related Jira task/s

SDK-7075

Release (mandatory for every PR — required for the ready-for-review label)

Version bump: (required — tick exactly one)

  • minor (backwards-compatible feature)
  • patch (bug fix or other small change)

Release notes type:

  • New Feature
  • Bug Fix
  • Other Improvement

Release notes (customer-facing):

  • Fixed BROWSERSTACK_PROJECT_NAME and BROWSERSTACK_BUILD_NAME being ignored — the environment now takes precedence over the project and build names in your config file, matching the other BrowserStack SDKs.

Release notes (internal):

  • New _applyEnvBuildNames helper, called from all four capability arms of the launcher constructor, folds BROWSERSTACK_PROJECT_NAME / BROWSERSTACK_BUILD_NAME into the caps ahead of the this._buildName / this._projectName assignment, so the session and Test Reporting both carry the env value.
  • Knock-on: a buildName is now present whenever BROWSERSTACK_BUILD_NAME is set, so _handleBuildIdentifier keeps 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.
  • Every capability shape is covered: bstack:options (incl. the one the service creates for extension caps), and top-level project / build for legacy caps on BrowserStack sessions. Non-BrowserStack sessions are left untouched.

Checklist

  • Ready to review
  • Has it been tested locally?

PR Validations

Run Tests: Comment RUN_TESTS to trigger sanity tests.

🤖 Generated with Claude Code

shivamku-BS and others added 2 commits October 13, 2026 15:34
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>
@shivam5643
shivam5643 requested a review from a team as a code owner October 13, 2026 12:06
@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Central YAML (base), Organization UI (inherited), Workspace UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Enterprise
  • Run ID: 5c8c499f-4107-4ca4-9f4f-f3ee6ca490d9

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@shivam5643

Copy link
Copy Markdown
Collaborator Author

v8 backport: #283 — same change, same tests, verified the same way. Please review the two together.

@github-actions

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not been run on the current head commit yet — run the SDK PR Review Agent (its verdict is advisory; this gate only requires that it ran on the latest commit).

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.

rounak610
rounak610 previously approved these changes Oct 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not been run on the current head commit yet — run the SDK PR Review Agent (its verdict is advisory; this gate only requires that it ran on the latest commit).

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.

@rounak610

Copy link
Copy Markdown
Collaborator

@shivam5643 Please test a scenario where you set different project names and build names using environment variables and in the config file. Then check whether the O11y build and the Automate/App Automate build contain the names set using the environment variables.

shivamku-BS and others added 3 commits October 15, 2026 16:36
…(SDK-7075)

The env override only ran when the caps already carried bstack:options.
Caps the service builds bstack:options for (extension caps such as
goog:chromeOptions) and legacy caps (top-level build/project keys) still
ignored BROWSERSTACK_PROJECT_NAME / BROWSERSTACK_BUILD_NAME, so the build
start payload and _handleBuildIdentifier kept seeing the config name.

Fold the override into one _applyEnvBuildNames helper called from all four
capability arms: it writes into bstack:options when present, into the
top-level project/build keys of legacy caps on a BrowserStack session, and
never touches the caps of a non-BrowserStack session. Blank env values are
ignored. The tests now clean the env vars in afterEach and cover the
service-created, legacy, multiremote and non-BrowserStack shapes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…orting (SDK-7075)

- Align top-level project/build keys that sit next to bstack:options, so a
  capability never carries two different names. (Live probe: the hub prefers
  bstack:options, so this is defensive, not a behaviour change.)
- Return no names for a non-BrowserStack session: its caps are left untouched,
  so the Test Reporting fields keep the caps values instead of disagreeing with
  the session.
- Tests: restore the isBStackSession spy in finally; cover padded env values,
  a build-only env override and the mixed bstack:options + top-level shape.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…plies (SDK-7075)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@shivam5643

Copy link
Copy Markdown
Collaborator Author

@shivam5643 Please test a scenario where you set different project names and build names using environment variables and in the config file. Then check whether the O11y build and the Automate/App Automate build contain the names set using the environment variables.

Yes working, have verified.
attached here: https://browserstack.atlassian.net/browse/SDK-7075?focusedCommentId=2459470

@github-actions

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not been run on the current head commit yet — run the SDK PR Review Agent (its verdict is advisory; this gate only requires that it ran on the latest commit).

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.

@shivam5643

Copy link
Copy Markdown
Collaborator Author

✅ Good to go

Per-File Confidence

File Status
.changeset/pr-282.md ✅ All Clear
packages/browserstack-service/src/launcher.ts ✅ All Clear
packages/browserstack-service/tests/launcher.test.ts ✅ All Clear

Change map (generated deterministically from the diff)

graph LR
  subgraph nwdio_service["wdio-service"]
    npackages_browserstack_service_src_launcher_ts["⚠ launcher.ts<br/>~113 lines"]
    npackages_browserstack_service_tests_launcher_test_ts["⚠ launcher.test.ts<br/>~113 lines"]
    n_changeset_pr_282_md["pr-282.md<br/>~5 lines"]
  end
Loading

↻ This verdict comment is the review anchor — it's updated in place on each run (the gate posts its status separately).

— SDK PR Review Agent

@github-actions

Copy link
Copy Markdown
Contributor

🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: success).

This gate confirms a review ran on the latest commit. The verdict itself is advisory — read the findings and use your judgement; it does not block merge. A native GitHub reviewer approval is still separately required by branch protection before this PR can merge.

1 similar comment
@github-actions

Copy link
Copy Markdown
Contributor

🟢 SDK PR Review gate is green — the SDK PR Review Agent has run on the current head commit (verdict: success).

This gate confirms a review ran on the latest commit. The verdict itself is advisory — read the findings and use your judgement; it does not block merge. A native GitHub reviewer approval is still separately required by branch protection before this PR can merge.

@shivam5643

Copy link
Copy Markdown
Collaborator Author

RUN_TESTS

@minionhelperappqa

Copy link
Copy Markdown

[SDK Wdio Test] TRA build state: failed | Stability 98% — verdict: success. Passed: 51, Failed: 1, Aggregate: 52. TRA: https://observability.browserstack.com/builds/sktqkkdampcskw3nnggpiuetif2qqf1m87wdwfvs

@github-actions

Copy link
Copy Markdown
Contributor

🔴 SDK PR Review gate is red. Pending:

  • The SDK PR Review Agent has not been run on the current head commit yet — run the SDK PR Review Agent (its verdict is advisory; this gate only requires that it ran on the latest commit).

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.

@Dalwin-Barnard
Dalwin-Barnard merged commit a3a3f4c into main Oct 16, 2026
19 of 23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants