Skip to content

Commit

Permalink
fix: ensure that find-process does not error out due to a bad regex (#…
Browse files Browse the repository at this point in the history
…30380)

* fix: ensure that find-process does not error out due to a bad regex

* add changelog

* fix patch

* add a test

* add comment

* update comment

* blank

* blank
  • Loading branch information
ryanthemanuel authored Oct 10, 2024
1 parent 8a8015b commit 04c1e8c
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 5 deletions.
10 changes: 5 additions & 5 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ mainBuildFilters: &mainBuildFilters
- /^release\/\d+\.\d+\.\d+$/
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- 'update-v8-snapshot-cache-on-develop'
- 'misc/remove_marionette_for_geckodriver'
- 'ryanm/fix/find-process'
- 'publish-binary'

# usually we don't build Mac app - it takes a long time
Expand All @@ -42,7 +42,7 @@ macWorkflowFilters: &darwin-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'misc/remove_marionette_for_geckodriver', << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/find-process', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand All @@ -53,7 +53,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'misc/remove_marionette_for_geckodriver', << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/find-process', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand All @@ -76,7 +76,7 @@ windowsWorkflowFilters: &windows-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'chore/patch_windows_build', << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/find-process', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand Down Expand Up @@ -152,7 +152,7 @@ commands:
name: Set environment variable to determine whether or not to persist artifacts
command: |
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "misc/remove_marionette_for_geckodriver" ]]; then
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "ryanm/fix/find-process" ]]; then
export SHOULD_PERSIST_ARTIFACTS=true
fi' >> "$BASH_ENV"
# You must run `setup_should_persist_artifacts` command and be using bash before running this command
Expand Down
4 changes: 4 additions & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

_Released 10/1/2024 (PENDING)_

**Bugfixes:**

- Patched [find-process](https://github.com/yibn2008/find-process) to fix an issue where trying to clean up browser profiles can throw an error on Windows. Addresses [#30378](https://github.com/cypress-io/cypress/issues/30378).

**Misc:**

- Cypress now consumes [geckodriver](https://firefox-source-docs.mozilla.org/testing/geckodriver/index.html) to help automate the Firefox browser instead of [marionette-client](https://github.com/cypress-io/marionette-client). Addresses [#30217](https://github.com/cypress-io/cypress/issues/30217).
Expand Down
83 changes: 83 additions & 0 deletions packages/server/test/unit/util/find_process_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import utils from 'find-process/lib/utils'
import { sinon } from '../../spec_helper'
import { byPid } from '../../../lib/util/find_process'

describe('lib/util/find_process', function () {
// This is testing the patch for find-process to handle windows processes that have a mixture of carriage returns
it('does not crash in windows with processes that deal with a mixture of carriage returns', async () => {
sinon.stub(process, 'platform').value('win32')
// Create a table that matches what 'Get-CimInstance -className win32_process | select Name,ProcessId,ParentProcessId,CommandLine,ExecutablePath' does in powershell
const process1 = 'Name : abc\r\nProcessId : 123\r\nParentProcessId : 456\r\nCommandLine : "c:\\path\\to\\abc.exe"\r\nExecutablePath : c:\\path\\to\\abc.exe'
const process2 = 'Name : xyz\r\nProcessId : 789\r\nParentProcessId : 1011\r\nCommandLine : "c:\\path\\to\\xyz.exe"\r\nExecutablePath : c:\\path\\to\\xyz.exe'
const process3 = 'Name : def\r\nProcessId : 1213\r\nParentProcessId : 1415\r\nCommandLine : "c:\\path\\to\\def.exe"\r\nExecutablePath : c:\\path\\to\\def.exe'
const process4 = 'Name : ghi\r\nProcessId : 1617\r\nParentProcessId : 1819\r\nCommandLine : "c:\\path\\to\\ghi.exe"\r\nExecutablePath : c:\\path\\to\\ghi.exe'
const process5 = 'Name : jkl\r\nProcessId : 2021\r\nParentProcessId : 2223\r\nCommandLine : "c:\\path\\to\\jkl.exe"\r\nExecutablePath : c:\\path\\to\\jkl.exe'
// Include all of this regex: (\r\n\r\n|\r\n\n|\n\r\n|\n\n)
const returnString = `${process1}\r\n\r\n${process2}\r\n\n${process3}\n\r\n${process4}\n\n${process5}`

sinon.stub(utils, 'spawn').returns({
stdout: {
on: (event: string, callback: (data: string) => void) => {
if (event === 'data') {
callback(returnString)
}
},
},
on: (event: string, callback: (code: number) => void) => {
if (event === 'close') {
callback(0)
}
},
})

const result1 = await byPid(123)

expect(result1).to.eql([{
pid: 123,
ppid: 456,
name: 'abc',
cmd: '"c:\\path\\to\\abc.exe"',
bin: 'c:\\path\\to\\abc.exe',
}])

const result2 = await byPid(789)

expect(result2).to.eql([{
pid: 789,
ppid: 1011,
name: 'xyz',
cmd: '"c:\\path\\to\\xyz.exe"',
bin: 'c:\\path\\to\\xyz.exe',
}])

const result3 = await byPid(1213)

expect(result3).to.eql([{
pid: 1213,
ppid: 1415,
name: 'def',
cmd: '"c:\\path\\to\\def.exe"',
bin: 'c:\\path\\to\\def.exe',
}])

const result4 = await byPid(1617)

expect(result4).to.eql([{
pid: 1617,
ppid: 1819,
name: 'ghi',
cmd: '"c:\\path\\to\\ghi.exe"',
bin: 'c:\\path\\to\\ghi.exe',
}])

const result5 = await byPid(2021)

expect(result5).to.eql([{
pid: 2021,
ppid: 2223,
name: 'jkl',
cmd: '"c:\\path\\to\\jkl.exe"',
bin: 'c:\\path\\to\\jkl.exe',
}])
})
})
13 changes: 13 additions & 0 deletions patches/find-process+1.4.7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/node_modules/find-process/lib/utils.js b/node_modules/find-process/lib/utils.js
index fb7592b..a192426 100644
--- a/node_modules/find-process/lib/utils.js
+++ b/node_modules/find-process/lib/utils.js
@@ -134,7 +134,7 @@ const utils = {
* @return {Array}
*/
parseTable (data) {
- const lines = data.split(/(\r\n\r\n|\r\n\n|\n\r\n)|\n\n/).filter(line => {
+ const lines = data.split(/(\r\n\r\n|\r\n\n|\n\r\n|\n\n)/).filter(line => {
return line.trim().length > 0
}).map((e) => e.split(/(\r\n|\n|\r)/).filter(line => line.trim().length > 0))

5 comments on commit 04c1e8c

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 04c1e8c Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.15.1/linux-x64/develop-04c1e8c90bc74ce4f736191ee73ac09c5a014867/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 04c1e8c Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.15.1/linux-arm64/develop-04c1e8c90bc74ce4f736191ee73ac09c5a014867/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 04c1e8c Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.15.1/darwin-arm64/develop-04c1e8c90bc74ce4f736191ee73ac09c5a014867/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 04c1e8c Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.15.1/darwin-x64/develop-04c1e8c90bc74ce4f736191ee73ac09c5a014867/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 04c1e8c Oct 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/13.15.1/win32-x64/develop-04c1e8c90bc74ce4f736191ee73ac09c5a014867/cypress.tgz

Please sign in to comment.