From ee7d39f4338d4805f373867a8089fb55a46d45b8 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 22 Nov 2025 14:45:56 +0000 Subject: [PATCH] Fix NODE_OPTIONS not being available in task_before commands Export NODE_OPTIONS and PYTHONPATH in bash subprocess so that any node/python commands in task_before (pre-execution field) can access the QLAPI preload. This fixes the issue where running "node /ql/data/scripts/ql_sample.js" in pre-execution fails with "ReferenceError: QLAPI is not defined". Co-authored-by: whyour <22700758+whyour@users.noreply.github.com> --- shell/preload/sitecustomize.js | 7 +++++++ shell/preload/sitecustomize.py | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/shell/preload/sitecustomize.js b/shell/preload/sitecustomize.js index dbb9198f..ec8704f2 100644 --- a/shell/preload/sitecustomize.js +++ b/shell/preload/sitecustomize.js @@ -28,6 +28,7 @@ function run() { numParam, file_task_before, file_task_before_js, + file_preload_js, dir_scripts, task_before, PREV_NODE_OPTIONS, @@ -40,7 +41,13 @@ function run() { const fileName = process.argv[1].replace(`${dir_scripts}/`, ''); const tempFile = `/tmp/env_${process.pid}.json`; + // Export NODE_OPTIONS so task_before can use it for any node commands + const nodeOptionsForBash = file_preload_js + ? `-r ${file_preload_js} ${PREV_NODE_OPTIONS || ''}` + : PREV_NODE_OPTIONS || ''; + const commands = [ + `export NODE_OPTIONS="${nodeOptionsForBash}"`, `source ${file_task_before} ${fileName}`, task_before ? `eval '${task_before.replace(/'/g, "'\\''")}'` : null, `echo -e '${splitStr}'`, diff --git a/shell/preload/sitecustomize.py b/shell/preload/sitecustomize.py index f4c51dd6..864a9026 100644 --- a/shell/preload/sitecustomize.py +++ b/shell/preload/sitecustomize.py @@ -44,11 +44,19 @@ def run(): split_str = "__sitecustomize__" file_name = sys.argv[0].replace(f"{os.getenv('dir_scripts')}/", "") + # Get environment variables needed for PYTHONPATH + dir_preload = os.getenv("dir_preload", "") + dir_config = os.getenv("dir_config", "") + # 创建临时文件路径 temp_file = f"/tmp/env_{os.getpid()}.json" + # Export PYTHONPATH so task_before can use it for any python commands + pythonpath_for_bash = f"{dir_preload}:{dir_config}:{prev_pythonpath}" if dir_preload else prev_pythonpath + # 构建命令数组 commands = [ + f'export PYTHONPATH="{pythonpath_for_bash}"', f'source {os.getenv("file_task_before")} {file_name}' ]