fix: handle quoted script paths and stabilize lifecycle tests

Parse literal shell arguments for script navigation and pass preloader hook paths as process arguments. Use the actual task entry for ts-node hooks.

Isolate unused history dependencies in the spawn-failure test while preserving its 3-second timeout and real child-process assertions. Add regression coverage for quoting, hooks and navigation safety.

Validated formatting, 240 dev regressions, 45 preload-related regressions, 19 CLI checks, 10 lifecycle repeat runs, and both image variants with 20 execution and navigation scenarios.
This commit is contained in:
whyour committed 2026-11-22 14:00:31 +08:00
1 parent c5458596c8
commit 188f8805cb
6 files changed
+224 -39

No files matched your search

+25 -13
View File
@@ -1,4 +1,4 @@
const { execSync } = require('child_process');
const { execFileSync } = require('child_process');
const Module = require('module');
const path = require('path');
const client = require('./client.js');
@@ -73,15 +73,19 @@ function run() {
process.env.NODE_OPTIONS = PREV_NODE_OPTIONS;
const splitStr = '__sitecustomize__';
const fileName = process.argv[1].replace(`${dir_scripts}/`, '');
// ts-node is argv[1] during preload; the task runner knows the actual script.
const fileName = (process.env.QL_SCRIPT_ENTRY || process.argv[1]).replace(
`${dir_scripts}/`,
'',
);
const tempFile = `/tmp/env_${process.pid}.json`;
const commands = [
`source ${file_task_before} ${fileName}`,
task_before ? `eval '${task_before.replace(/'/g, "'\\''")}'` : null,
`echo -e '${splitStr}'`,
`node -e "require('fs').writeFileSync('${tempFile}', JSON.stringify(process.env))"`,
].filter(Boolean);
// Pass paths as arguments: shell syntax in a filename must stay literal.
const command = `file="$1"; output="$2"; inline="$3"; shift 3
source "$file" "$@" &&
{ if [ -n "$inline" ]; then eval "$inline"; fi; } &&
printf '%s\\n' '__sitecustomize__' &&
node -e 'require("fs").writeFileSync(process.argv[1], JSON.stringify(process.env))' "$output"`;
if (task_before) {
console.log(
@@ -91,11 +95,19 @@ function run() {
);
}
const res = execSync(commands.join(' && '), {
encoding: 'utf-8',
maxBuffer: 50 * 1024 * 1024,
shell: '/bin/bash',
});
const res = execFileSync(
'/bin/bash',
[
'-c',
command,
'ql-before',
file_task_before,
tempFile,
task_before || '',
fileName,
],
{ encoding: 'utf-8', maxBuffer: 50 * 1024 * 1024 },
);
const [output] = res.split(splitStr);
+13 -19
View File
@@ -37,6 +37,7 @@ def expand_range(range_str, max_value):
def run():
task_before = os.getenv("task_before", "")
try:
prev_pythonpath = os.getenv("PREV_PYTHONPATH", "")
os.environ["PYTHONPATH"] = prev_pythonpath
@@ -47,27 +48,20 @@ def run():
# 创建临时文件路径
temp_file = f"/tmp/env_{os.getpid()}.json"
# 构建命令数组
commands = [
f'source {os.getenv("file_task_before")} {file_name}'
]
task_before = os.getenv("task_before")
if task_before:
escaped_task_before = task_before.replace('"', '\\"').replace("$", "\\$")
commands.append(f"eval '{escaped_task_before}'")
print("Executing before command\n" if os.environ.get("QL_LANG") == "en" else "执行前置命令\n")
commands.append(f"echo -e '{split_str}'")
# 修改 Python 命令,使用单行并正确处理引号
python_cmd = f"python3 -c 'import os,json; f=open(\\\"{temp_file}\\\",\\\"w\\\"); json.dump(dict(os.environ),f); f.close()'"
commands.append(python_cmd)
command = " && ".join(cmd for cmd in commands if cmd)
command = f'bash -c "{command}"'
res = subprocess.check_output(command, shell=True, encoding="utf-8")
# Pass paths as arguments, without interpreting filename shell syntax.
command = """file="$1"; output="$2"; inline="$3"; shift 3
source "$file" "$@" &&
{ if [ -n "$inline" ]; then eval "$inline"; fi; } &&
printf '%s\\n' '__sitecustomize__' &&
python3 -c 'import os,json,sys; f=open(sys.argv[1],"w"); json.dump(dict(os.environ),f); f.close()' "$output"
"""
res = subprocess.check_output(
["/bin/bash", "-c", command, "ql-before", os.environ["file_task_before"],
temp_file, task_before, file_name],
encoding="utf-8",
)
output = res.split(split_str)[0]
try: