Skip to content

armgit / ECC

Public Imported from GitHub
0

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

test: support windows pre-bash linter shims

Affaan Mustafaebf0d4322b97
diff --git a/tests/hooks/pre-bash-commit-quality.test.js b/tests/hooks/pre-bash-commit-quality.test.js
index ba5c7ec2a..4a2b8d845 100644
--- a/tests/hooks/pre-bash-commit-quality.test.js
+++ b/tests/hooks/pre-bash-commit-quality.test.js
@@ -62,6 +62,23 @@ function writeAndStage(repoDir, relativePath, content) {
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) {
const previous = {};
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, '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.writeFileSync(eslintPath, '#!/bin/sh\necho "eslint failed"\nexit 1\n', 'utf8');
- fs.chmodSync(eslintPath, 0o755);
+ writeFakeExecutable(eslintPath, 'eslint failed', 1);
const binDir = path.join(repoDir, 'fake-bin');
fs.mkdirSync(binDir, { recursive: true });
- const pylintPath = path.join(binDir, 'pylint');
- const golintPath = path.join(binDir, 'golint');
- fs.writeFileSync(pylintPath, '#!/bin/sh\necho "pylint failed"\nexit 1\n', 'utf8');
- fs.writeFileSync(golintPath, '#!/bin/sh\necho "main.go:1: lint failed"\nexit 0\n', 'utf8');
- fs.chmodSync(pylintPath, 0o755);
- fs.chmodSync(golintPath, 0o755);
-
- withEnv({ PATH: `${binDir}${path.delimiter}${process.env.PATH || ''}` }, () => {
+ const pylintPath = path.join(binDir, executableName('pylint'));
+ const golintPath = path.join(binDir, executableName('golint'));
+ writeFakeExecutable(pylintPath, 'pylint failed', 1);
+ writeFakeExecutable(golintPath, 'main.go:1: lint failed', 0);
+
+ 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 { result, stderr } = captureConsoleError(() => hook.evaluate(input));