mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-05-14 18:44:44 +08:00
test: harden InsAIts wrapper fake Python shim
This commit is contained in:
parent
901e41997b
commit
22aabf7d4f
@ -20,11 +20,13 @@ function cleanup(dirPath) {
|
|||||||
fs.rmSync(dirPath, { recursive: true, force: true });
|
fs.rmSync(dirPath, { recursive: true, force: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function shellQuote(value) {
|
||||||
|
return `'${String(value).replace(/'/g, "'\\''")}'`;
|
||||||
|
}
|
||||||
|
|
||||||
function writeFakePython(binDir) {
|
function writeFakePython(binDir) {
|
||||||
fs.mkdirSync(binDir, { recursive: true });
|
fs.mkdirSync(binDir, { recursive: true });
|
||||||
if (process.platform === 'win32') {
|
|
||||||
const fakePythonJs = path.join(binDir, 'fake-python.js');
|
const fakePythonJs = path.join(binDir, 'fake-python.js');
|
||||||
const fakePythonCmd = path.join(binDir, 'python3.cmd');
|
|
||||||
fs.writeFileSync(fakePythonJs, [
|
fs.writeFileSync(fakePythonJs, [
|
||||||
"'use strict';",
|
"'use strict';",
|
||||||
"const fs = require('fs');",
|
"const fs = require('fs');",
|
||||||
@ -47,6 +49,9 @@ function writeFakePython(binDir) {
|
|||||||
" process.exit(1);",
|
" process.exit(1);",
|
||||||
"}",
|
"}",
|
||||||
].join('\n'), 'utf8');
|
].join('\n'), 'utf8');
|
||||||
|
|
||||||
|
if (process.platform === 'win32') {
|
||||||
|
const fakePythonCmd = path.join(binDir, 'python3.cmd');
|
||||||
fs.writeFileSync(fakePythonCmd, [
|
fs.writeFileSync(fakePythonCmd, [
|
||||||
'@echo off',
|
'@echo off',
|
||||||
`"${process.execPath}" "%~dp0fake-python.js" %*`,
|
`"${process.execPath}" "%~dp0fake-python.js" %*`,
|
||||||
@ -57,26 +62,7 @@ function writeFakePython(binDir) {
|
|||||||
const fakePython = path.join(binDir, 'python3');
|
const fakePython = path.join(binDir, 'python3');
|
||||||
fs.writeFileSync(fakePython, [
|
fs.writeFileSync(fakePython, [
|
||||||
'#!/bin/sh',
|
'#!/bin/sh',
|
||||||
'mode="${FAKE_INSAITS_MODE:-clean}"',
|
`exec ${shellQuote(process.execPath)} ${shellQuote(fakePythonJs)} "$@"`,
|
||||||
'case "$mode" in',
|
|
||||||
' clean)',
|
|
||||||
' cat >/dev/null',
|
|
||||||
' exit 0',
|
|
||||||
' ;;',
|
|
||||||
' echo)',
|
|
||||||
' cat',
|
|
||||||
' exit 0',
|
|
||||||
' ;;',
|
|
||||||
' block)',
|
|
||||||
' printf "blocked by monitor\\n"',
|
|
||||||
' printf "monitor warning\\n" >&2',
|
|
||||||
' exit 2',
|
|
||||||
' ;;',
|
|
||||||
' error)',
|
|
||||||
' printf "spawned but failed\\n" >&2',
|
|
||||||
' exit 1',
|
|
||||||
' ;;',
|
|
||||||
'esac',
|
|
||||||
].join('\n'), 'utf8');
|
].join('\n'), 'utf8');
|
||||||
fs.chmodSync(fakePython, 0o755);
|
fs.chmodSync(fakePython, 0o755);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user