import assert from 'node:assert/strict' import path from 'node:path' import test from 'node:test' import { resolvePythonExecutable, runPythonCommand } from '../scripts/python-runtime.mjs' test('显式 PYTHON 配置优先于所有自动发现路径', () => { const selected = resolvePythonExecutable({ pipelineDirectory: 'C:\\repo\\design-pipeline', environment: { PYTHON: 'D:\\tools\\python.exe', LOCALAPPDATA: 'C:\\Users\\tester\\AppData\\Local', }, platform: 'win32', pathExists: () => true, canRun: candidate => candidate === 'D:\\tools\\python.exe', }) assert.equal(selected, 'D:\\tools\\python.exe') }) test('Windows 环境在虚拟环境缺失时选择 Python Manager 的真实入口', () => { const managerPython = path.win32.join( 'C:\\Users\\tester\\AppData\\Local', 'Python', 'bin', 'python.exe', ) const selected = resolvePythonExecutable({ pipelineDirectory: 'C:\\repo\\design-pipeline', environment: { LOCALAPPDATA: 'C:\\Users\\tester\\AppData\\Local' }, platform: 'win32', pathExists: candidate => candidate === managerPython, canRun: candidate => candidate === managerPython, }) assert.equal(selected, managerPython) }) test('所有候选解释器均不可用时给出可执行的中文修复指引', () => { assert.throws( () => resolvePythonExecutable({ pipelineDirectory: 'C:\\repo\\design-pipeline', environment: {}, platform: 'win32', pathExists: () => false, canRun: () => false, }), /未找到可用的 Python.*PYTHON.*\.venv/s, ) }) test('统一执行器始终把禁止字节码缓存参数放在首位', () => { let invocation runPythonCommand({ executable: 'python-test', args: ['script.py', '--flag'], cwd: 'C:\\repo', spawn: (command, args, options) => { invocation = { command, args, options } return { status: 0 } }, }) assert.equal(invocation.command, 'python-test') assert.deepEqual(invocation.args, ['-B', 'script.py', '--flag']) assert.equal(invocation.options.cwd, 'C:\\repo') })