mirror of
https://github.com/affaan-m/everything-claude-code.git
synced 2026-04-30 22:13:28 +08:00
test: support windows pre-bash linter shims
This commit is contained in:
@@ -62,6 +62,23 @@ function writeAndStage(repoDir, relativePath, content) {
|
|||||||
spawnSync('git', ['add', relativePath], { cwd: repoDir, stdio: 'pipe', encoding: 'utf8' });
|
spawnSync('git', ['add', relativePath], { cwd: repoDir, stdio: 'pipe', encoding: 'utf8' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function executableName(name) {
|
||||||
|
return process.platform === 'win32' ? `${name}.cmd` : name;
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeFakeExecutable(filePath, output, exitCode) {
|
||||||
|
const source = process.platform === 'win32'
|
||||||
|
? `@echo off\r\necho ${output}\r\nexit /b ${exitCode}\r\n`
|
||||||
|
: `#!/bin/sh\necho "${output}"\nexit ${exitCode}\n`;
|
||||||
|
|
||||||
|
fs.writeFileSync(filePath, source, 'utf8');
|
||||||
|
fs.chmodSync(filePath, 0o755);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pathEnvKey() {
|
||||||
|
return Object.keys(process.env).find(key => key.toLowerCase() === 'path') || 'PATH';
|
||||||
|
}
|
||||||
|
|
||||||
function withEnv(overrides, fn) {
|
function withEnv(overrides, fn) {
|
||||||
const previous = {};
|
const previous = {};
|
||||||
for (const key of Object.keys(overrides)) {
|
for (const key of Object.keys(overrides)) {
|
||||||
@@ -222,21 +239,19 @@ if (test('reports eslint pylint and golint failures from staged files', () => {
|
|||||||
writeAndStage(repoDir, 'app.py', 'print("lint")\n');
|
writeAndStage(repoDir, 'app.py', 'print("lint")\n');
|
||||||
writeAndStage(repoDir, 'main.go', 'package main\n');
|
writeAndStage(repoDir, 'main.go', 'package main\n');
|
||||||
|
|
||||||
const eslintPath = path.join(repoDir, 'node_modules', '.bin', process.platform === 'win32' ? 'eslint.cmd' : 'eslint');
|
const eslintPath = path.join(repoDir, 'node_modules', '.bin', executableName('eslint'));
|
||||||
fs.mkdirSync(path.dirname(eslintPath), { recursive: true });
|
fs.mkdirSync(path.dirname(eslintPath), { recursive: true });
|
||||||
fs.writeFileSync(eslintPath, '#!/bin/sh\necho "eslint failed"\nexit 1\n', 'utf8');
|
writeFakeExecutable(eslintPath, 'eslint failed', 1);
|
||||||
fs.chmodSync(eslintPath, 0o755);
|
|
||||||
|
|
||||||
const binDir = path.join(repoDir, 'fake-bin');
|
const binDir = path.join(repoDir, 'fake-bin');
|
||||||
fs.mkdirSync(binDir, { recursive: true });
|
fs.mkdirSync(binDir, { recursive: true });
|
||||||
const pylintPath = path.join(binDir, 'pylint');
|
const pylintPath = path.join(binDir, executableName('pylint'));
|
||||||
const golintPath = path.join(binDir, 'golint');
|
const golintPath = path.join(binDir, executableName('golint'));
|
||||||
fs.writeFileSync(pylintPath, '#!/bin/sh\necho "pylint failed"\nexit 1\n', 'utf8');
|
writeFakeExecutable(pylintPath, 'pylint failed', 1);
|
||||||
fs.writeFileSync(golintPath, '#!/bin/sh\necho "main.go:1: lint failed"\nexit 0\n', 'utf8');
|
writeFakeExecutable(golintPath, 'main.go:1: lint failed', 0);
|
||||||
fs.chmodSync(pylintPath, 0o755);
|
|
||||||
fs.chmodSync(golintPath, 0o755);
|
|
||||||
|
|
||||||
withEnv({ PATH: `${binDir}${path.delimiter}${process.env.PATH || ''}` }, () => {
|
const pathKey = pathEnvKey();
|
||||||
|
withEnv({ [pathKey]: `${binDir}${path.delimiter}${process.env[pathKey] || process.env.PATH || ''}` }, () => {
|
||||||
const input = JSON.stringify({ tool_input: { command: 'git commit -m "fix: lint failures"' } });
|
const input = JSON.stringify({ tool_input: { command: 'git commit -m "fix: lint failures"' } });
|
||||||
const { result, stderr } = captureConsoleError(() => hook.evaluate(input));
|
const { result, stderr } = captureConsoleError(() => hook.evaluate(input));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user