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.

fix(audit): mirror pytest discovery rules

wellkiloc9dd92037d25
diff --git a/scripts/lib/harness-audit-consumer.js b/scripts/lib/harness-audit-consumer.js
index cafe5cff9..0bb51516d 100644
--- a/scripts/lib/harness-audit-consumer.js
+++ b/scripts/lib/harness-audit-consumer.js
@@ -154,12 +154,10 @@ function getActivePytestConfig(rootDir) {
const configPath = path.join(rootDir, fileName);
if (!fs.existsSync(configPath)) continue;
const text = safeRead(configPath);
- if (!text.trim() || /^\s*\[pytest]\s*$/m.test(text)) {
- return {
- paths: parseIniOption(text, 'pytest', 'testpaths'),
- pythonFiles: parseIniOption(text, 'pytest', 'python_files'),
- };
- }
+ return {
+ paths: parseIniOption(text, 'pytest', 'testpaths'),
+ pythonFiles: parseIniOption(text, 'pytest', 'python_files'),
+ };
}
const pyproject = safeRead(path.join(rootDir, 'pyproject.toml'));
@@ -391,24 +389,30 @@ function gitignoreIgnoresEnvFiles(text) {
'config/.env',
'secrets.env',
];
- const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-gitignore-'));
- const repoRoot = path.join(tempRoot, 'repo');
- const templateRoot = path.join(tempRoot, 'template');
+ let tempRoot;
try {
+ tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-gitignore-'));
+ const repoRoot = path.join(tempRoot, 'repo');
+ const templateRoot = path.join(tempRoot, 'template');
+ const globalExcludesPath = path.join(tempRoot, 'global-excludes');
fs.mkdirSync(repoRoot);
fs.mkdirSync(templateRoot);
+ fs.writeFileSync(globalExcludesPath, '');
fs.writeFileSync(path.join(repoRoot, '.gitignore'), text);
const init = spawnSync('git', ['init', '--quiet', `--template=${templateRoot}`, repoRoot], {
encoding: 'utf8',
stdio: ['ignore', 'pipe', 'pipe'],
timeout: 5000,
});
- if (init.error || init.status !== 0) return false;
+ if (init.error || init.status !== 0) {
+ process.stderr.write('[harness-audit] Unable to initialize isolated gitignore check\n');
+ return false;
+ }
const result = spawnSync(
'git',
- ['-C', repoRoot, '-c', `core.excludesFile=${os.devNull}`, 'check-ignore', '--no-index', '--stdin'],
+ ['-C', repoRoot, '-c', `core.excludesFile=${globalExcludesPath}`, 'check-ignore', '--no-index', '--stdin'],
{
input: `${candidates.join('\n')}\n`,
encoding: 'utf8',
@@ -416,9 +420,16 @@ function gitignoreIgnoresEnvFiles(text) {
timeout: 5000,
}
);
- return !result.error && result.status === 0 && Boolean(result.stdout.trim());
+ if (result.error || ![0, 1].includes(result.status)) {
+ process.stderr.write('[harness-audit] Unable to evaluate gitignore rules with git\n');
+ return false;
+ }
+ return result.status === 0 && Boolean(result.stdout.trim());
+ } catch (_error) {
+ process.stderr.write('[harness-audit] Unable to prepare isolated gitignore check\n');
+ return false;
} finally {
- fs.rmSync(tempRoot, { recursive: true, force: true });
+ if (tempRoot) fs.rmSync(tempRoot, { recursive: true, force: true });
}
}
diff --git a/tests/scripts/harness-audit.test.js b/tests/scripts/harness-audit.test.js
index f92500cad..f0fb56c1b 100644
--- a/tests/scripts/harness-audit.test.js
+++ b/tests/scripts/harness-audit.test.js
@@ -583,10 +583,16 @@ function runTests() {
fs.writeFileSync(path.join(projectRoot, 'active', 'test_active.py'), '');
fs.writeFileSync(path.join(projectRoot, 'inactive', 'test_inactive.py'), '');
assert.strictEqual(countPythonTestFiles(projectRoot), 1);
-
const parsed = JSON.parse(run(['repo', '--format', 'json'], { cwd: projectRoot, homeDir }));
assert.ok(parsed.checks.some(check => check.id === 'consumer-test-suite' && check.pass));
assert.ok(parsed.checks.some(check => check.id === 'consumer-eval-coverage' && !check.pass));
+
+ fs.writeFileSync(path.join(projectRoot, 'pytest.ini'), '[invalid]\nvalue = true\n');
+ assert.strictEqual(
+ countPythonTestFiles(projectRoot),
+ 5,
+ 'Existing pytest.ini must win by presence and use default root discovery'
+ );
} finally {
cleanup(homeDir);
cleanup(projectRoot);
@@ -685,7 +691,6 @@ function runTests() {
['# Do not commit .env files\nnode_modules/\n', false],
['environment.json\n.envexample\n', false],
['[z-a]env\n', false],
- ['[z-a]env\n', false],
['.env.example\n', false],
['.env\n', true],
['.env.local\n', true],