-
Notifications
You must be signed in to change notification settings - Fork 9
fix(cli): send absolute test_file_path and make binary update version-aware (SDK-7233) #135
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
Bhargavi-BS
wants to merge
2
commits into
main
Choose a base branch
from
fix/sdk-7233-wdio-test-file-path-and-binary-update
base: main
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@wdio/browserstack-service": patch | ||
| --- | ||
|
|
||
| - Fixed test results not appearing in Test Reporting for WebdriverIO + Mocha when the project is not a git repository. | ||
| - Fixed the BrowserStack binary not updating once a copy was already present, which could leave a machine on an old binary indefinitely. |
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
104 changes: 104 additions & 0 deletions
104
packages/browserstack-service/tests/cli/cliUtils.staleBinary.test.ts
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,104 @@ | ||
| import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' | ||
| import fs from 'node:fs' | ||
| import path from 'node:path' | ||
| import os from 'node:os' | ||
| import * as bstackLogger from '../../src/bstackLogger.js' | ||
|
|
||
| import { CLIUtils } from '../../src/cli/cliUtils.js' | ||
|
|
||
| vi.spyOn(bstackLogger.BStackLogger, 'logToFile').mockImplementation(() => {}) | ||
|
|
||
| const DOWNLOAD_URL = 'https://sdk-assets.browserstack.com/binary-macos-arm64-1.48.0.zip' | ||
|
|
||
| describe('SDK-7233 — binary update must not be skipped for a stale binary', () => { | ||
| let cliDir: string | ||
|
|
||
| beforeEach(() => { | ||
| cliDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sdk7233-cli-')) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks() | ||
| fs.rmSync(cliDir, { recursive: true, force: true }) | ||
| }) | ||
|
|
||
| it('parses the target version out of the download URL', () => { | ||
| expect(CLIUtils.getVersionFromBinaryUrl(DOWNLOAD_URL)).toBe('1.48.0') | ||
| expect(CLIUtils.getVersionFromBinaryUrl('https://x/custom-build.zip')).toBeNull() | ||
| }) | ||
|
|
||
| describe('isBinaryAtVersion', () => { | ||
| it('is true only when the binary reports exactly the expected version', async () => { | ||
| vi.spyOn(CLIUtils, 'runShellCommand').mockResolvedValue('1.48.0\n') | ||
| await expect(CLIUtils.isBinaryAtVersion('/bin/bs', '1.48.0')).resolves.toBe(true) | ||
| await expect(CLIUtils.isBinaryAtVersion('/bin/bs', '1.22.1')).resolves.toBe(false) | ||
| }) | ||
|
|
||
| it('fails open (false ⇒ download) on a busy or erroring binary', async () => { | ||
| const shell = vi.spyOn(CLIUtils, 'runShellCommand') | ||
| shell.mockResolvedValue('SHELL_EXECUTE_ERROR') | ||
| await expect(CLIUtils.isBinaryAtVersion('/bin/bs', '1.48.0')).resolves.toBe(false) | ||
| shell.mockResolvedValue('text file busy') | ||
| await expect(CLIUtils.isBinaryAtVersion('/bin/bs', '1.48.0')).resolves.toBe(false) | ||
| shell.mockRejectedValue(new Error('spawn failed')) | ||
| await expect(CLIUtils.isBinaryAtVersion('/bin/bs', '1.48.0')).resolves.toBe(false) | ||
| }) | ||
|
|
||
| it('returns false when no expected version is known', async () => { | ||
| const shell = vi.spyOn(CLIUtils, 'runShellCommand') | ||
| await expect(CLIUtils.isBinaryAtVersion('/bin/bs', null)).resolves.toBe(false) | ||
| expect(shell).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
|
|
||
| it('uses the server-reported version when the URL carries none (custom BROWSERSTACK_BINARY_URL)', async () => { | ||
| // Without this, a custom binary URL would make targetVersion null, which | ||
| // disables the peer-race short-circuit and re-downloads on every run. | ||
| const peerDownloaded = path.join(cliDir, 'binary-macos-arm64') | ||
| fs.writeFileSync(peerDownloaded, 'fresh-binary-v1.48.0') | ||
| const atVersion = vi.spyOn(CLIUtils, 'isBinaryAtVersion').mockResolvedValue(true) | ||
| const fetchSpy = vi.spyOn(globalThis, 'fetch') | ||
|
|
||
| const returned = await CLIUtils.downloadLatestBinary( | ||
| 'https://mirror.internal/custom-build.zip', | ||
| cliDir, | ||
| '1.48.0', | ||
| ) | ||
|
|
||
| expect(atVersion).toHaveBeenCalledWith(peerDownloaded, '1.48.0') | ||
| expect(returned).toBe(peerDownloaded) | ||
| expect(fetchSpy).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('downloads the update when the on-disk binary is a stale version', async () => { | ||
| // downloadLatestBinary is only reached once the server has said an update | ||
| // is required, so a pre-existing binary here is stale by construction. | ||
| fs.writeFileSync(path.join(cliDir, 'binary-macos-arm64'), 'stale-binary-v1.22.1') | ||
| vi.spyOn(CLIUtils, 'isBinaryAtVersion').mockResolvedValue(false) | ||
| const fetchSpy = vi | ||
| .spyOn(globalThis, 'fetch') | ||
| .mockRejectedValue(new Error('network disabled in test')) | ||
|
|
||
| // Now rejects instead of hanging: processDownload() propagates the | ||
| // fetch failure to the caller. | ||
| await expect( | ||
| CLIUtils.downloadLatestBinary(DOWNLOAD_URL, cliDir), | ||
| ).rejects.toThrow('network disabled in test') | ||
| expect(fetchSpy).toHaveBeenCalledWith(DOWNLOAD_URL, expect.anything()) | ||
| // let the aborted write stream finish tearing down before afterEach | ||
| // removes the temp dir out from under its pending open() | ||
| await new Promise((r) => setTimeout(r, 50)) | ||
| }) | ||
|
|
||
| it('skips the download when a peer already fetched the target version', async () => { | ||
| const peerDownloaded = path.join(cliDir, 'binary-macos-arm64') | ||
| fs.writeFileSync(peerDownloaded, 'fresh-binary-v1.48.0') | ||
| vi.spyOn(CLIUtils, 'isBinaryAtVersion').mockResolvedValue(true) | ||
| const fetchSpy = vi.spyOn(globalThis, 'fetch') | ||
|
|
||
| const returned = await CLIUtils.downloadLatestBinary(DOWNLOAD_URL, cliDir) | ||
|
|
||
| expect(returned).toBe(peerDownloaded) | ||
| expect(fetchSpy).not.toHaveBeenCalled() | ||
| }) | ||
| }) |
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
Oops, something went wrong.
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.
verified if
getGitMetaDatais not used anywhere else?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.
yes, verified