From ad00544ed77258e28231085b6482e1dfe1cbad54 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 Aug 2022 10:35:52 -0500 Subject: [PATCH 01/14] Include bin scripts for all platforms These will get symlinked as part of the postinstall. These scripts provide everything ours does inside the integrated terminal plus more. --- ci/build/build-vscode.sh | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/ci/build/build-vscode.sh b/ci/build/build-vscode.sh index 71d33960fb63..38b3801f5f94 100755 --- a/ci/build/build-vscode.sh +++ b/ci/build/build-vscode.sh @@ -6,12 +6,25 @@ set -euo pipefail # MINIFY controls whether a minified version of vscode is built. MINIFY=${MINIFY-true} +delete-bin-script() { + rm "lib/vscode-reh-web-linux-x64/bin/$1" +} + +copy-bin-script() { + local script="$1" + local dest="lib/vscode-reh-web-linux-x64/bin/$script" + cp "lib/vscode/resources/server/bin/$script" "$dest" + sed -i "s/@@VERSION@@/$(vscode_version)/g" "$dest" + sed -i "s/@@COMMIT@@/$VSCODE_DISTRO_COMMIT/g" "$dest" + sed -i "s/@@APPNAME@@/code-server/g" "$dest" +} + main() { cd "$(dirname "${0}")/../.." source ./ci/lib.sh - cd lib/vscode + pushd lib/vscode # Set the commit Code will embed into the product.json. We need to do this # since Code tries to get the commit from the `.git` directory which will fail @@ -58,13 +71,31 @@ main() { EOF ) > product.json - # Any platform works since we have our own packaging step (for now). + # Any platform here works since we will do our own packaging. We have to do + # this because we have an NPM package that could be installed on any platform. + # The correct platform dependencies and scripts will be installed as part of + # the post-install during `npm install` or when building a standalone release. yarn gulp "vscode-reh-web-linux-x64${MINIFY:+-min}" # Reset so if you develop after building you will not be stuck with the wrong # commit (the dev client will use `oss-dev` but the dev server will still use # product.json which will have `stable-$commit`). git checkout product.json + + popd + + # These provide a `code-server` command in the integrated terminal to open + # files in the current instance. + delete-bin-script remote-cli/code-server + copy-bin-script remote-cli/code-darwin.sh + copy-bin-script remote-cli/code-linux.sh + copy-bin-script remote-cli/code.cmd + + # These provide a way for terminal applications to open browser windows. + delete-bin-script helpers/browser.sh + copy-bin-script helpers/browser-darwin.sh + copy-bin-script helpers/browser-linux.sh + copy-bin-script helpers/browser.cmd } main "$@" From 974170b64791d30f029c41f2f24ab9a6c34c9bf5 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 Aug 2022 14:02:13 -0500 Subject: [PATCH 02/14] Improve OS detection Specifically for Windows although we do not yet support Windows. Also standardize the duplicate arch functions since they had drifted from each other bit. --- ci/build/npm-postinstall.sh | 36 +++++++++++++++++--------------- ci/lib.sh | 41 ++++++++++++++++--------------------- 2 files changed, 38 insertions(+), 39 deletions(-) diff --git a/ci/build/npm-postinstall.sh b/ci/build/npm-postinstall.sh index cc40fd291b7e..b251a279d30a 100755 --- a/ci/build/npm-postinstall.sh +++ b/ci/build/npm-postinstall.sh @@ -1,23 +1,29 @@ #!/usr/bin/env sh set -eu -# Copied from arch() in ci/lib.sh. -detect_arch() { - case "$(uname -m)" in - aarch64) - echo arm64 - ;; - x86_64 | amd64) - echo amd64 - ;; - *) - # This will cause the download to fail, but is intentional - uname -m - ;; +# Copied from ../lib.sh. +arch() { + cpu="$(uname -m)" + case "$cpu" in + aarch64) cpu=arm64 ;; + x86_64) cpu=amd64 ;; esac + echo "$cpu" } -ARCH="${NPM_CONFIG_ARCH:-$(detect_arch)}" +# Copied from ../lib.sh except we do not rename Darwin since the cloud agent +# uses "darwin" in the release names and we do not need to detect Alpine. +os() { + osname=$(uname | tr '[:upper:]' '[:lower:]') + case $osname in + cygwin* | mingw*) osname="windows" ;; + esac + echo "$osname" +} + +ARCH="${NPM_CONFIG_ARCH:-$(arch)}" +OS="$(os)" + # This is due to an upstream issue with RHEL7/CentOS 7 comptability with node-argon2 # See: https://github.com/cdr/code-server/pull/3422#pullrequestreview-677765057 export npm_config_build_from_source=true @@ -56,8 +62,6 @@ main() { ;; esac - OS="$(uname | tr '[:upper:]' '[:lower:]')" - mkdir -p ./lib if curl -fsSL "https://github.com/coder/cloud-agent/releases/latest/download/cloud-agent-$OS-$ARCH" -o ./lib/coder-cloud-agent; then diff --git a/ci/lib.sh b/ci/lib.sh index 414fe1569e7c..ae65c273492b 100755 --- a/ci/lib.sh +++ b/ci/lib.sh @@ -18,35 +18,30 @@ vscode_version() { } os() { - local os - os=$(uname | tr '[:upper:]' '[:lower:]') - if [[ $os == "linux" ]]; then - # Alpine's ldd doesn't have a version flag but if you use an invalid flag - # (like --version) it outputs the version to stderr and exits with 1. - local ldd_output - ldd_output=$(ldd --version 2>&1 || true) - if echo "$ldd_output" | grep -iq musl; then - os="alpine" - fi - elif [[ $os == "darwin" ]]; then - os="macos" - fi - echo "$os" + osname=$(uname | tr '[:upper:]' '[:lower:]') + case $osname in + linux) + # Alpine's ldd doesn't have a version flag but if you use an invalid flag + # (like --version) it outputs the version to stderr and exits with 1. + # TODO: Better to check /etc/os-release; see ../install.sh. + ldd_output=$(ldd --version 2>&1 || true) + if echo "$ldd_output" | grep -iq musl; then + osname="alpine" + fi + ;; + darwin) osname="macos" ;; + cygwin* | mingw*) osname="windows" ;; + esac + echo "$osname" } arch() { cpu="$(uname -m)" case "$cpu" in - aarch64) - echo arm64 - ;; - x86_64 | amd64) - echo amd64 - ;; - *) - echo "$cpu" - ;; + aarch64) cpu=arm64 ;; + x86_64) cpu=amd64 ;; esac + echo "$cpu" } # Grabs the most recent ci.yaml github workflow run that was triggered from the From 0b9d8d0f5c6e03b23f0ac4432c061eb98f1314e1 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 Aug 2022 14:05:48 -0500 Subject: [PATCH 03/14] Remove duplicate asar symlink Since standalone releases run the postinstall they will get the asar symlink there. That means the symlink will not exist for the npm package and we will not need to ignore it. The symlink portion is split out so it can be re-used for other symlinks (for example linking bin scripts). --- ci/build/build-release.sh | 4 ---- ci/build/build-standalone-release.sh | 3 ++- ci/build/npm-postinstall.sh | 32 +++++++++++++++++++--------- ci/lib.sh | 18 ---------------- ci/steps/publish-npm.sh | 4 ---- 5 files changed, 24 insertions(+), 37 deletions(-) diff --git a/ci/build/build-release.sh b/ci/build/build-release.sh index 8bcf823070dc..53d17d8efaaf 100755 --- a/ci/build/build-release.sh +++ b/ci/build/build-release.sh @@ -110,10 +110,6 @@ bundle_vscode() { rsync "$VSCODE_SRC_PATH/extensions/package.json" "$VSCODE_OUT_PATH/extensions/package.json" rsync "$VSCODE_SRC_PATH/extensions/yarn.lock" "$VSCODE_OUT_PATH/extensions/yarn.lock" rsync "$VSCODE_SRC_PATH/extensions/postinstall.mjs" "$VSCODE_OUT_PATH/extensions/postinstall.mjs" - - pushd "$VSCODE_OUT_PATH" - symlink_asar - popd } main "$@" diff --git a/ci/build/build-standalone-release.sh b/ci/build/build-standalone-release.sh index 2bc553a619ce..1a6b6f95f747 100755 --- a/ci/build/build-standalone-release.sh +++ b/ci/build/build-standalone-release.sh @@ -27,8 +27,9 @@ main() { ln -s "./bin/code-server" "$RELEASE_PATH/code-server" ln -s "./lib/node" "$RELEASE_PATH/node" - cd "$RELEASE_PATH" + pushd "$RELEASE_PATH" yarn --production --frozen-lockfile + popd } main "$@" diff --git a/ci/build/npm-postinstall.sh b/ci/build/npm-postinstall.sh index b251a279d30a..edf66013f977 100755 --- a/ci/build/npm-postinstall.sh +++ b/ci/build/npm-postinstall.sh @@ -20,6 +20,28 @@ os() { esac echo "$osname" } +# Create a symlink at $2 pointing to $1 on any platform. Anything that +# currently exists at $2 will be deleted. +symlink() { + source="$1" + dest="$2" + rm -rf "$dest" + case $OS in + windows) mklink /J "$dest" "$source" ;; + *) ln -s "$source" "$dest" ;; + esac +} + +# VS Code bundles some modules into an asar which is an archive format that +# works like tar. It then seems to get unpacked into node_modules.asar. +# +# I don't know why they do this but all the dependencies they bundle already +# exist in node_modules so just symlink it. We have to do this since not only +# Code itself but also extensions will look specifically in this directory for +# files (like the ripgrep binary or the oniguruma wasm). +symlink_asar() { + symlink node_modules node_modules.asar +} ARCH="${NPM_CONFIG_ARCH:-$(arch)}" OS="$(os)" @@ -83,16 +105,6 @@ main() { fi } -# This is a copy of symlink_asar in ../lib.sh. Look there for details. -symlink_asar() { - rm -rf node_modules.asar - if [ "${WINDIR-}" ]; then - mklink /J node_modules.asar node_modules - else - ln -s node_modules node_modules.asar - fi -} - vscode_yarn() { echo 'Installing Code dependencies...' cd lib/vscode diff --git a/ci/lib.sh b/ci/lib.sh index ae65c273492b..cef865234ad5 100755 --- a/ci/lib.sh +++ b/ci/lib.sh @@ -99,21 +99,3 @@ export OS # RELEASE_PATH is the destination directory for the release from the root. # Defaults to release RELEASE_PATH="${RELEASE_PATH-release}" - -# VS Code bundles some modules into an asar which is an archive format that -# works like tar. It then seems to get unpacked into node_modules.asar. -# -# I don't know why they do this but all the dependencies they bundle already -# exist in node_modules so just symlink it. We have to do this since not only VS -# Code itself but also extensions will look specifically in this directory for -# files (like the ripgrep binary or the oniguruma wasm). -symlink_asar() { - rm -rf node_modules.asar - if [ "${WINDIR-}" ]; then - # mklink takes the link name first. - mklink /J node_modules.asar node_modules - else - # ln takes the link name second. - ln -s node_modules node_modules.asar - fi -} diff --git a/ci/steps/publish-npm.sh b/ci/steps/publish-npm.sh index 847c46ab5a20..c2cca90dee34 100755 --- a/ci/steps/publish-npm.sh +++ b/ci/steps/publish-npm.sh @@ -81,10 +81,6 @@ main() { # https://github.com/actions/upload-artifact/issues/38 tar -xzf release-npm-package/package.tar.gz - # Ignore symlink when publishing npm package - # See: https://github.com/coder/code-server/pull/3935 - echo "node_modules.asar" > release/.npmignore - # We use this to set the name of the package in the # package.json PACKAGE_NAME="code-server" From 527680905c817c22ba7a9d2e56abe8ade37cf3d2 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 Aug 2022 14:07:31 -0500 Subject: [PATCH 04/14] Add symlinks to bin scripts --- ci/build/npm-postinstall.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/ci/build/npm-postinstall.sh b/ci/build/npm-postinstall.sh index edf66013f977..93807b30039c 100755 --- a/ci/build/npm-postinstall.sh +++ b/ci/build/npm-postinstall.sh @@ -20,6 +20,7 @@ os() { esac echo "$osname" } + # Create a symlink at $2 pointing to $1 on any platform. Anything that # currently exists at $2 will be deleted. symlink() { @@ -43,6 +44,23 @@ symlink_asar() { symlink node_modules node_modules.asar } +# Make a symlink at bin/$1/$3 pointing to the platform-specific version of the +# script in $2. The extension of the link will be .cmd for Windows otherwise it +# will be whatever is in $4 (or no extension if $4 is not set). +symlink_bin_script() { + oldpwd="$(pwd)" + cd "bin/$1" + source="$2" + dest="$3" + ext="${4-}" + case $OS in + windows) symlink "$source.cmd" "$dest.cmd" ;; + darwin | macos) symlink "$source-darwin.sh" "$dest$ext" ;; + *) symlink "$source-linux.sh" "$dest$ext" ;; + esac + cd "$oldpwd" +} + ARCH="${NPM_CONFIG_ARCH:-$(arch)}" OS="$(os)" @@ -111,6 +129,8 @@ vscode_yarn() { yarn --production --frozen-lockfile --no-default-rc symlink_asar + symlink_bin_script remote-cli code code-server + symlink_bin_script helpers browser browser .sh cd extensions yarn --production --frozen-lockfile From 7c2c7d74856c8cbd5da6c84ab29598ce0ce87569 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 Aug 2022 14:07:46 -0500 Subject: [PATCH 05/14] Add test for opening a file from the terminal --- test/e2e/models/CodeServer.ts | 14 +++++++------- test/e2e/terminal.test.ts | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index 8b3c4a4afd62..d84d912d204c 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -283,16 +283,16 @@ export class CodeServerPage { } /** - * Focuses Integrated Terminal - * by using "Terminal: Focus Terminal" - * from the Command Palette + * Focuses the integrated terminal by navigating through the command palette. * - * This should focus the terminal no matter - * if it already has focus and/or is or isn't - * visible already. + * This should focus the terminal no matter if it already has focus and/or is + * or isn't visible already. It will always create a new terminal to avoid + * clobbering parallel tests. */ async focusTerminal() { - await this.executeCommandViaMenus("Terminal: Focus Terminal") + // We need to create a new terminal since multiple tests could be running at + // once and they will step over each other if they use the same terminal. + await this.executeCommandViaMenus("Terminal: Create New Terminal") // Wait for terminal textarea to show up await this.page.waitForSelector("textarea.xterm-helper-textarea") diff --git a/test/e2e/terminal.test.ts b/test/e2e/terminal.test.ts index ae55b0670365..b95331b94bcf 100644 --- a/test/e2e/terminal.test.ts +++ b/test/e2e/terminal.test.ts @@ -1,4 +1,5 @@ import * as cp from "child_process" +import { promises as fs } from "fs" import * as path from "path" import util from "util" import { clean, tmpdir } from "../utils/helpers" @@ -24,10 +25,21 @@ describe("Integrated Terminal", true, [], {}, () => { await codeServerPage.page.waitForLoadState("load") await codeServerPage.page.keyboard.type(`printenv VSCODE_PROXY_URI > ${tmpFile}`) await codeServerPage.page.keyboard.press("Enter") - // It may take a second to process - await codeServerPage.page.waitForTimeout(1000) const { stdout } = await output expect(stdout).toMatch(await codeServerPage.address()) }) + + test("should be able to invoke `code-server` to open a file", async ({ codeServerPage }) => { + const tmpFolderPath = await tmpdir(testName) + const tmpFile = path.join(tmpFolderPath, "test-file") + await fs.writeFile(tmpFile, "test") + + await codeServerPage.focusTerminal() + + await codeServerPage.page.keyboard.type(`code-server ${tmpFile}`) + await codeServerPage.page.keyboard.press("Enter") + + await codeServerPage.waitForTab(path.basename(tmpFile)) + }) }) From 73982c95ecb2eaade662c508518d4d1cdcef1149 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 Aug 2022 16:38:21 -0500 Subject: [PATCH 06/14] Add global Playwright timeout Otherwise it will exceed the Actions timeout and get rudely killed without any output. --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5049226043d8..6430d2c2a5ed 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -499,7 +499,7 @@ jobs: ./test/node_modules/.bin/playwright install - name: Run end-to-end tests - run: yarn test:e2e + run: yarn test:e2e --global-timeout 840000 - name: Upload test artifacts if: always() From a5d2200510878e1ea92251d83c8a2598538da565 Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 Aug 2022 16:46:46 -0500 Subject: [PATCH 07/14] Make sed work on macOS --- ci/build/build-vscode.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ci/build/build-vscode.sh b/ci/build/build-vscode.sh index 38b3801f5f94..51a60feb53ce 100755 --- a/ci/build/build-vscode.sh +++ b/ci/build/build-vscode.sh @@ -14,9 +14,9 @@ copy-bin-script() { local script="$1" local dest="lib/vscode-reh-web-linux-x64/bin/$script" cp "lib/vscode/resources/server/bin/$script" "$dest" - sed -i "s/@@VERSION@@/$(vscode_version)/g" "$dest" - sed -i "s/@@COMMIT@@/$VSCODE_DISTRO_COMMIT/g" "$dest" - sed -i "s/@@APPNAME@@/code-server/g" "$dest" + sed -i.bak "s/@@VERSION@@/$(vscode_version)/g" "$dest" + sed -i.bak "s/@@COMMIT@@/$VSCODE_DISTRO_COMMIT/g" "$dest" + sed -i.bak "s/@@APPNAME@@/code-server/g" "$dest" } main() { From b732bf9dbfb16ae431d4ae0cb354bf5ba376096e Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 Aug 2022 17:51:22 -0500 Subject: [PATCH 08/14] Add back wait for load state Removing it did not help. Still not sure if this is necessary though. --- test/e2e/terminal.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/terminal.test.ts b/test/e2e/terminal.test.ts index b95331b94bcf..4bd3aa2762f3 100644 --- a/test/e2e/terminal.test.ts +++ b/test/e2e/terminal.test.ts @@ -37,6 +37,7 @@ describe("Integrated Terminal", true, [], {}, () => { await codeServerPage.focusTerminal() + await codeServerPage.page.waitForLoadState("load") await codeServerPage.page.keyboard.type(`code-server ${tmpFile}`) await codeServerPage.page.keyboard.press("Enter") From 43225a37bad04a37ebf2af735fbf0e0ec59e80fe Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 Aug 2022 17:51:48 -0500 Subject: [PATCH 09/14] Fix Node path in bin scripts --- ci/build/build-vscode.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/ci/build/build-vscode.sh b/ci/build/build-vscode.sh index 51a60feb53ce..38185b192f5a 100755 --- a/ci/build/build-vscode.sh +++ b/ci/build/build-vscode.sh @@ -17,6 +17,14 @@ copy-bin-script() { sed -i.bak "s/@@VERSION@@/$(vscode_version)/g" "$dest" sed -i.bak "s/@@COMMIT@@/$VSCODE_DISTRO_COMMIT/g" "$dest" sed -i.bak "s/@@APPNAME@@/code-server/g" "$dest" + + # Fix Node path on Darwin and Linux. + sed -i.bak 's/^ROOT=\(.*\)$/VSROOT=\1\nROOT="$(dirname "$(dirname "$VSROOT")")"/g' "$dest" + sed -i.bak 's/ROOT\/out/VSROOT\/out/g' "$dest" + + # Fix Node path on Windows. + sed -i.bak 's/^set ROOT_DIR=\(.*\)$/set ROOT_DIR=%~dp0..\\..\\..\\..\r\nset VSROOT_DIR=\1/g' "$dest" + sed -i.bak 's/%ROOT_DIR%\\out/%VSROOT_DIR%\\out/g' "$dest" } main() { From 8c2096f13a2008b2d19b63345f21e90985ab994b Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 Aug 2022 17:57:20 -0500 Subject: [PATCH 10/14] Disable shellcheck expansion error --- ci/build/build-vscode.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/build/build-vscode.sh b/ci/build/build-vscode.sh index 38185b192f5a..9df12ee434c7 100755 --- a/ci/build/build-vscode.sh +++ b/ci/build/build-vscode.sh @@ -19,6 +19,8 @@ copy-bin-script() { sed -i.bak "s/@@APPNAME@@/code-server/g" "$dest" # Fix Node path on Darwin and Linux. + # We do not want expansion here; this text should make it to the file as-is. + # shellcheck disable=SC2016 sed -i.bak 's/^ROOT=\(.*\)$/VSROOT=\1\nROOT="$(dirname "$(dirname "$VSROOT")")"/g' "$dest" sed -i.bak 's/ROOT\/out/VSROOT\/out/g' "$dest" From 44bd6ff87a96408240a6a91f06251d6a02e0b7aa Mon Sep 17 00:00:00 2001 From: Asher Date: Mon, 1 Aug 2022 17:08:41 -0500 Subject: [PATCH 11/14] Make scripts executable --- ci/build/build-vscode.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/build/build-vscode.sh b/ci/build/build-vscode.sh index 9df12ee434c7..bf7a1c65425b 100755 --- a/ci/build/build-vscode.sh +++ b/ci/build/build-vscode.sh @@ -27,6 +27,8 @@ copy-bin-script() { # Fix Node path on Windows. sed -i.bak 's/^set ROOT_DIR=\(.*\)$/set ROOT_DIR=%~dp0..\\..\\..\\..\r\nset VSROOT_DIR=\1/g' "$dest" sed -i.bak 's/%ROOT_DIR%\\out/%VSROOT_DIR%\\out/g' "$dest" + + chmod +x "$dest" } main() { From 4a00441eecafe82db6fd9af2f302b461eb5073f7 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 2 Aug 2022 10:43:14 -0500 Subject: [PATCH 12/14] Remove .bak files created by sed --- ci/build/build-vscode.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/build/build-vscode.sh b/ci/build/build-vscode.sh index bf7a1c65425b..248368522a4f 100755 --- a/ci/build/build-vscode.sh +++ b/ci/build/build-vscode.sh @@ -7,7 +7,7 @@ set -euo pipefail MINIFY=${MINIFY-true} delete-bin-script() { - rm "lib/vscode-reh-web-linux-x64/bin/$1" + rm -f "lib/vscode-reh-web-linux-x64/bin/$1" } copy-bin-script() { @@ -29,6 +29,7 @@ copy-bin-script() { sed -i.bak 's/%ROOT_DIR%\\out/%VSROOT_DIR%\\out/g' "$dest" chmod +x "$dest" + rm "$dest.bak" } main() { From 602f8d4dd791ae3a7effc1c3638429d6bdb61001 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 2 Aug 2022 10:46:07 -0500 Subject: [PATCH 13/14] Include Code build script in cache hash Otherwise if we change the script it will not rebuild Code. --- .github/workflows/ci.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6430d2c2a5ed..eec90db30b57 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -156,7 +156,7 @@ jobs: uses: actions/cache@v3 with: path: lib/vscode-reh-web-* - key: vscode-reh-package-${{ secrets.VSCODE_CACHE_VERSION }}-${{ steps.vscode-rev.outputs.rev }}-${{ steps.version.outputs.version }}-${{ hashFiles('patches/*.diff') }} + key: vscode-reh-package-${{ secrets.VSCODE_CACHE_VERSION }}-${{ steps.vscode-rev.outputs.rev }}-${{ steps.version.outputs.version }}-${{ hashFiles('patches/*.diff', 'ci/build/build-vscode.sh') }} - name: Build vscode if: steps.cache-vscode.outputs.cache-hit != 'true' From b62191a6f3d0e77347814f603832b41dd8736852 Mon Sep 17 00:00:00 2001 From: Asher Date: Tue, 2 Aug 2022 10:39:47 -0500 Subject: [PATCH 14/14] Make sure the terminal opens The selector was timing out even though it matched more than one element but matching on the focused one appears to work. In addition add a loop so even it can keep trying to open the terminal if something goes wrong with the focus. --- test/e2e/models/CodeServer.ts | 24 ++++++++++++++++++------ test/e2e/terminal.test.ts | 5 ++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/test/e2e/models/CodeServer.ts b/test/e2e/models/CodeServer.ts index d84d912d204c..4100a1660ad6 100644 --- a/test/e2e/models/CodeServer.ts +++ b/test/e2e/models/CodeServer.ts @@ -290,12 +290,24 @@ export class CodeServerPage { * clobbering parallel tests. */ async focusTerminal() { - // We need to create a new terminal since multiple tests could be running at - // once and they will step over each other if they use the same terminal. - await this.executeCommandViaMenus("Terminal: Create New Terminal") + const doFocus = async (): Promise => { + await this.executeCommandViaMenus("Terminal: Create New Terminal") + try { + await this.page.waitForLoadState("load") + await this.page.waitForSelector("textarea.xterm-helper-textarea:focus-within", { timeout: 5000 }) + return true + } catch (error) { + return false + } + } + + let attempts = 1 + while (!(await doFocus())) { + ++attempts + this.codeServer.logger.debug(`no focused terminal textarea, retrying (${attempts}/∞)`) + } - // Wait for terminal textarea to show up - await this.page.waitForSelector("textarea.xterm-helper-textarea") + this.codeServer.logger.debug(`opening terminal took ${attempts} ${plural(attempts, "attempt")}`) } /** @@ -423,7 +435,7 @@ export class CodeServerPage { let context = new Context() while (!(await Promise.race([openThenWaitClose(context), navigate(context)]))) { ++attempts - logger.debug("closed, retrying (${attempt}/∞)") + logger.debug(`closed, retrying (${attempts}/∞)`) context.cancel() context = new Context() } diff --git a/test/e2e/terminal.test.ts b/test/e2e/terminal.test.ts index 4bd3aa2762f3..175d51c29321 100644 --- a/test/e2e/terminal.test.ts +++ b/test/e2e/terminal.test.ts @@ -22,7 +22,6 @@ describe("Integrated Terminal", true, [], {}, () => { // Open terminal and type in value await codeServerPage.focusTerminal() - await codeServerPage.page.waitForLoadState("load") await codeServerPage.page.keyboard.type(`printenv VSCODE_PROXY_URI > ${tmpFile}`) await codeServerPage.page.keyboard.press("Enter") @@ -34,13 +33,13 @@ describe("Integrated Terminal", true, [], {}, () => { const tmpFolderPath = await tmpdir(testName) const tmpFile = path.join(tmpFolderPath, "test-file") await fs.writeFile(tmpFile, "test") + const fileName = path.basename(tmpFile) await codeServerPage.focusTerminal() - await codeServerPage.page.waitForLoadState("load") await codeServerPage.page.keyboard.type(`code-server ${tmpFile}`) await codeServerPage.page.keyboard.press("Enter") - await codeServerPage.waitForTab(path.basename(tmpFile)) + await codeServerPage.waitForTab(fileName) }) })