(params: {
scriptPath: string;
env: Record<string, string>;
})
| 57 | } |
| 58 | |
| 59 | export function executeRunScriptFile(params: { |
| 60 | scriptPath: string; |
| 61 | env: Record<string, string>; |
| 62 | }): Record<string, string> { |
| 63 | const { scriptPath, env } = params; |
| 64 | const script = fs.readFileSync(scriptPath, 'utf8'); |
| 65 | const output: Record<string, unknown> = Object.create(null) as Record<string, unknown>; |
| 66 | |
| 67 | try { |
| 68 | // Compatibility note: node:vm is not a security sandbox. Maestro runScript |
| 69 | // files are trusted flow-local setup code; the timeout only bounds |
| 70 | // synchronous script execution. Async http.post work is bounded separately |
| 71 | // by the child process timeout in runHttpRequestSync. |
| 72 | vm.runInNewContext(script, buildScriptGlobals(env, output), { |
| 73 | filename: scriptPath, |
| 74 | timeout: RUN_SCRIPT_TIMEOUT_MS, |
| 75 | }); |
| 76 | } catch (error) { |
| 77 | throw new AppError( |
| 78 | 'COMMAND_FAILED', |
| 79 | `Maestro runScript failed for ${scriptPath}: ${error instanceof Error ? error.message : String(error)}`, |
| 80 | { scriptPath }, |
| 81 | error instanceof Error ? error : undefined, |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | validateOutputKeys(output, scriptPath); |
| 86 | return Object.fromEntries( |
| 87 | Object.entries(output).map(([key, rawValue]) => [ |
| 88 | `output.${key}`, |
| 89 | stringifyOutputValue(rawValue), |
| 90 | ]), |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | function readRunScriptConfig( |
| 95 | value: unknown, |
no test coverage detected
searching dependent graphs…