-
Notifications
You must be signed in to change notification settings - Fork 45
fix(a11y): stop TestHub build for accessibility-only runs [SDK-7793] #1202
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
Open
kamal-kaur04
wants to merge
1
commit into
master
Choose a base branch
from
fix/SDK-7793-a11y-testhub-build-stop
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| 'use strict'; | ||
| const chai = require('chai'); | ||
| const expect = chai.expect; | ||
| const sinon = require('sinon'); | ||
|
|
||
| const helper = require('../../../../bin/testObservability/helper/helper'); | ||
|
|
||
| const ENV_KEYS = [ | ||
| 'BROWSERSTACK_TEST_OBSERVABILITY', | ||
| 'BS_TESTOPS_BUILD_COMPLETED', | ||
| 'BS_TESTOPS_JWT', | ||
| 'BS_TESTOPS_BUILD_HASHED_ID', | ||
| 'BROWSERSTACK_TESTHUB_UUID', | ||
| 'BROWSERSTACK_TESTHUB_JWT', | ||
| ]; | ||
|
|
||
| describe('TestHub build stop', () => { | ||
| let savedEnv, nodeRequest; | ||
|
|
||
| beforeEach(() => { | ||
| savedEnv = {}; | ||
| ENV_KEYS.forEach((k) => { savedEnv[k] = process.env[k]; delete process.env[k]; }); | ||
| helper.buildStopped = false; | ||
| nodeRequest = sinon.stub(helper, 'nodeRequest').resolves({ data: {} }); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sinon.restore(); | ||
| ENV_KEYS.forEach((k) => { | ||
| if (savedEnv[k] === undefined) delete process.env[k]; else process.env[k] = savedEnv[k]; | ||
| }); | ||
| helper.buildStopped = false; | ||
| }); | ||
|
|
||
| const stopCall = () => nodeRequest.getCalls().find((c) => c.args[0] === 'PUT'); | ||
|
|
||
| it('stops an accessibility-only TestHub build when observability is off', async () => { | ||
| process.env.BROWSERSTACK_TEST_OBSERVABILITY = 'false'; | ||
| process.env.BS_TESTOPS_BUILD_COMPLETED = 'false'; | ||
| process.env.BS_TESTOPS_JWT = 'null'; | ||
| process.env.BS_TESTOPS_BUILD_HASHED_ID = 'null'; | ||
| process.env.BROWSERSTACK_TESTHUB_UUID = 'th-build-uuid'; | ||
| process.env.BROWSERSTACK_TESTHUB_JWT = 'th-jwt'; | ||
|
|
||
| await helper.printBuildLink(true); | ||
|
|
||
| const call = stopCall(); | ||
| expect(call, 'PUT stop request').to.exist; | ||
| expect(call.args[1]).to.equal('api/v1/builds/th-build-uuid/stop'); | ||
| expect(call.args[3].headers.Authorization).to.equal('Bearer th-jwt'); | ||
| }); | ||
|
|
||
| it('keeps using the observability token and build id when observability launched the build', async () => { | ||
| process.env.BROWSERSTACK_TEST_OBSERVABILITY = 'true'; | ||
| process.env.BS_TESTOPS_BUILD_COMPLETED = 'true'; | ||
| process.env.BS_TESTOPS_JWT = 'o11y-jwt'; | ||
| process.env.BS_TESTOPS_BUILD_HASHED_ID = 'o11y-build'; | ||
| process.env.BROWSERSTACK_TESTHUB_UUID = 'o11y-build'; | ||
| process.env.BROWSERSTACK_TESTHUB_JWT = 'o11y-jwt'; | ||
|
|
||
| await helper.printBuildLink(true); | ||
|
|
||
| const call = stopCall(); | ||
| expect(call.args[1]).to.equal('api/v1/builds/o11y-build/stop'); | ||
| expect(call.args[3].headers.Authorization).to.equal('Bearer o11y-jwt'); | ||
| }); | ||
|
|
||
| it('sends no stop when no TestHub build was launched', async () => { | ||
| process.env.BROWSERSTACK_TEST_OBSERVABILITY = 'false'; | ||
| process.env.BROWSERSTACK_TESTHUB_UUID = 'null'; | ||
| process.env.BROWSERSTACK_TESTHUB_JWT = 'null'; | ||
|
|
||
| await helper.printBuildLink(true); | ||
|
|
||
| expect(stopCall()).to.be.undefined; | ||
| }); | ||
|
|
||
| it('sends the stop only once across repeated calls', async () => { | ||
| process.env.BROWSERSTACK_TEST_OBSERVABILITY = 'false'; | ||
| process.env.BROWSERSTACK_TESTHUB_UUID = 'th-build-uuid'; | ||
| process.env.BROWSERSTACK_TESTHUB_JWT = 'th-jwt'; | ||
|
|
||
| await helper.printBuildLink(true); | ||
| await helper.printBuildLink(true); | ||
|
|
||
| expect(nodeRequest.getCalls().filter((c) => c.args[0] === 'PUT')).to.have.length(1); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
cat test/unit/bin/testObservability/buildStop.js rg -n 'stopBuildUpstream|data.error|BROWSERSTACK_TESTHUB|BS_TESTOPS_BUILD_COMPLETED' test/unit/bin/testObservability git diff a4eaeb63ee468da94517bb338feecc4d218bd2a1 d986604b01517fcbe7b316a1fc054be21b71e51e -- bin/testObservability/helper/helper.js test/unit/bin/testObservability/buildStop.jsRepository: browserstack/browserstack-cypress-cli
Length of output: 10930
🏁 Script executed:
Repository: browserstack/browserstack-cypress-cli
Length of output: 33881
Cover independent credential-validation paths.
Add cases where each TestHub UUID or JWT is independently absent, empty,
"null", or"undefined". Assert that no stop request is sent.Use distinct TestHub and observability IDs and tokens. The current observability case cannot detect incorrect credential-source selection because both sources use identical values.
When
BS_TESTOPS_BUILD_COMPLETEDis"true", callstopBuildUpstream()with invalid observability credentials and assertstatus: 'error'.The
nodeRequestrejection andresponse.data.errorbranches are unchanged generic handling instopBuildUpstream()and are outside this change-specific coverage.🤖 Prompt for AI Agents