豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit afceae0

Browse files
committed
fix(bazel): integration rule using incorrect casing for working dir of commands
The integration rule currently directly takes the Bazel `TEST_TMP_DIR` as directory for the integration test. Bazel will use a lower-case variant of the path on case-insensitive platforms (like Windows). This is acceptable for standard IO operations (as within Bazel), but can unexpectedly break module resolution/or cause subtle differences. We should always normalize the path to an actual case-exact system realpath when setting it as `CWD` for command invocations. This enables the use of e.g. playwright within Bazel integration tests. microsoft/playwright#9193.
1 parent 0ef299c commit afceae0

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

bazel/integration/test_runner/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ ts_library(
1414
"@npm//@types/node",
1515
"@npm//@types/tmp",
1616
"@npm//tmp",
17+
"@npm//true-case-path",
1718
],
1819
)
1920

bazel/integration/test_runner/file_system_utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88

99
import * as fs from 'fs';
10+
import {trueCasePath} from 'true-case-path';
1011

1112
/** Gets whether the file is executable or not. */
1213
export async function isExecutable(filePath: string): Promise<boolean> {
@@ -18,6 +19,16 @@ export async function isExecutable(filePath: string): Promise<boolean> {
1819
}
1920
}
2021

22+
/**
23+
* Gets a case-exact system realpath for the specified path.
24+
*
25+
* This is useful for example because Bazel passes `C:\users\<..>` as action input, but
26+
* the actual case-exact path for the current platform would be: `C:\Users\<..>`.
27+
*/
28+
export async function getCaseExactRealpath(filePath: string): Promise<string> {
29+
return trueCasePath(filePath);
30+
}
31+
2132
/** Adds the `write` permission to the given file using `chmod`. */
2233
export async function addWritePermissionFlag(filePath: string) {
2334
if (await isExecutable(filePath)) {

bazel/integration/test_runner/process_utils.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import * as childProcess from 'child_process';
1010
import * as path from 'path';
1111
import {debug} from './debug';
12+
import {getCaseExactRealpath} from './file_system_utils';
1213

1314
/**
1415
* Regular expression matching environment variable substitutions
@@ -41,21 +42,26 @@ export function expandEnvironmentVariableSubstitutions(
4142
* @returns a Promise that resolves with a boolean indicating whether the
4243
* command completed successfully or not.
4344
*/
44-
export function runCommandInChildProcess(
45+
export async function runCommandInChildProcess(
4546
binary: string,
4647
args: string[],
4748
workingDir: string,
4849
env: NodeJS.ProcessEnv,
4950
): Promise<boolean> {
5051
const humanReadableCommand = `${binary}${args.length ? ` ${args.join(' ')}` : ''}`;
52+
// Note: We resolve the working directory to a case-exact system `realpath`. This is
53+
// necessary as otherwise Node module resolution could behave unexpectedly when invoked
54+
// tools down-the-line resolve files with an actual system realpath. Here is an example
55+
// within Microsoft's `playwright`: https://github.com/microsoft/playwright/issues/9193.
56+
const normalizedWorkingDir = await getCaseExactRealpath(path.posix.normalize(workingDir));
5157

52-
debug(`Executing command: ${humanReadableCommand} in ${workingDir}`);
58+
debug(`Executing command: ${humanReadableCommand} in ${normalizedWorkingDir}`);
5359

5460
return new Promise<boolean>((resolve) => {
5561
const commandProcess = childProcess.spawn(binary, args, {
5662
shell: true,
5763
stdio: 'inherit',
58-
cwd: workingDir,
64+
cwd: normalizedWorkingDir,
5965
env,
6066
});
6167

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
"selenium-webdriver": "3.5.0",
5757
"semver": "^7.3.5",
5858
"tmp": "^0.2.1",
59+
"true-case-path": "^2.2.1",
5960
"ts-node": "^10.2.1",
6061
"tslib": "^2.3.0",
6162
"tslint": "^6.1.3",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3091,6 +3091,11 @@ trim-newlines@^3.0.0:
30913091
resolved "https://registry.yarnpkg.com/trim-newlines/-/trim-newlines-3.0.1.tgz#260a5d962d8b752425b32f3a7db0dcacd176c144"
30923092
integrity sha512-c1PTsA3tYrIsLGkJkzHF+w9F2EyxfXGo4UyJc4pFL++FMjnq0HJS69T3M7d//gKrFKwy429bouPescbjecU+Zw==
30933093

3094+
"true-case-path@^2.2.1":
3095+
version "2.2.1"
3096+
resolved "https://registry.yarnpkg.com/true-case-path/-/true-case-path-2.2.1.tgz#c5bf04a5bbec3fd118be4084461b3a27c4d796bf"
3097+
integrity sha512-0z3j8R7MCjy10kc/g+qg7Ln3alJTodw9aDuVWZa3uiWqfuBMKeAeP2ocWcxoyM3D73yz3Jt/Pu4qPr4wHSdB/Q==
3098+
30943099
ts-node@^10.2.1:
30953100
version "10.4.0"
30963101
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.4.0.tgz#680f88945885f4e6cf450e7f0d6223dd404895f7"

0 commit comments

Comments
 (0)