mirror of
https://github.com/whyour/qinglong.git
synced 2026-12-01 01:39:52 +08:00
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:
1 parent
c5458596c8
commit
188f8805cb
6 files changed
+224
-39
No files matched your search
@@ -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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user