Compare commits

...

4 Commits

Author SHA1 Message Date
Affaan Mustafa
45a9bcf295 test: lift harness manifest branch coverage 2026-04-29 18:38:48 -04:00
Affaan Mustafa
ebf0d4322b test: support windows pre-bash linter shims 2026-04-29 18:36:33 -04:00
Affaan Mustafa
015b00b8fc test: stabilize mcp health crash probes 2026-04-29 18:29:02 -04:00
Affaan Mustafa
51511461f6 test: cover pre-bash commit quality edges 2026-04-29 18:28:56 -04:00
5 changed files with 628 additions and 10 deletions

View File

@@ -422,7 +422,7 @@ async function runTests() {
CLAUDE_HOOK_EVENT_NAME: 'PreToolUse',
ECC_MCP_CONFIG_PATH: configPath,
ECC_MCP_HEALTH_STATE_PATH: statePath,
ECC_MCP_HEALTH_TIMEOUT_MS: '100'
ECC_MCP_HEALTH_TIMEOUT_MS: '1000'
}
);
@@ -458,7 +458,7 @@ async function runTests() {
ECC_MCP_CONFIG_PATH: configPath,
ECC_MCP_HEALTH_STATE_PATH: statePath,
ECC_MCP_HEALTH_FAIL_OPEN: '1',
ECC_MCP_HEALTH_TIMEOUT_MS: '100'
ECC_MCP_HEALTH_TIMEOUT_MS: '1000'
}
);
@@ -490,7 +490,7 @@ async function runTests() {
CLAUDE_HOOK_EVENT_NAME: 'PreToolUse',
ECC_MCP_CONFIG_PATH: configPath,
ECC_MCP_HEALTH_STATE_PATH: statePath,
ECC_MCP_HEALTH_TIMEOUT_MS: '100'
ECC_MCP_HEALTH_TIMEOUT_MS: '1000'
}
);
const missingCommand = runHook(
@@ -499,7 +499,7 @@ async function runTests() {
CLAUDE_HOOK_EVENT_NAME: 'PreToolUse',
ECC_MCP_CONFIG_PATH: configPath,
ECC_MCP_HEALTH_STATE_PATH: statePath,
ECC_MCP_HEALTH_TIMEOUT_MS: '100'
ECC_MCP_HEALTH_TIMEOUT_MS: '1000'
}
);
@@ -597,7 +597,7 @@ async function runTests() {
ECC_MCP_CONFIG_PATH: configPath,
ECC_MCP_HEALTH_STATE_PATH: statePath,
ECC_MCP_RECONNECT_COMMAND: `${JSON.stringify(process.execPath)} ${JSON.stringify(reconnectScript)}`,
ECC_MCP_HEALTH_TIMEOUT_MS: '100',
ECC_MCP_HEALTH_TIMEOUT_MS: '1000',
ECC_MCP_HEALTH_BACKOFF_MS: '10'
}
);
@@ -660,7 +660,7 @@ async function runTests() {
ECC_MCP_CONFIG_PATH: configPath,
ECC_MCP_HEALTH_STATE_PATH: statePath,
ECC_MCP_RECONNECT_COMMAND: `node ${JSON.stringify(reconnectScript)}`,
ECC_MCP_HEALTH_TIMEOUT_MS: '100'
ECC_MCP_HEALTH_TIMEOUT_MS: '1000'
}
);

View File

@@ -40,6 +40,65 @@ function inTempRepo(fn) {
}
}
function captureConsoleError(fn) {
const previousError = console.error;
const lines = [];
console.error = (...args) => {
lines.push(args.join(' '));
};
try {
const result = fn();
return { result, stderr: lines.join('\n') };
} finally {
console.error = previousError;
}
}
function writeAndStage(repoDir, relativePath, content) {
const filePath = path.join(repoDir, relativePath);
fs.mkdirSync(path.dirname(filePath), { recursive: true });
fs.writeFileSync(filePath, content, '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) {
const previous = {};
for (const key of Object.keys(overrides)) {
previous[key] = process.env[key];
process.env[key] = overrides[key];
}
try {
return fn();
} finally {
for (const key of Object.keys(overrides)) {
if (typeof previous[key] === 'string') {
process.env[key] = previous[key];
} else {
delete process.env[key];
}
}
}
}
let passed = 0;
let failed = 0;
@@ -77,5 +136,157 @@ if (test('evaluate inspects staged snapshot instead of newer working tree conten
});
})) passed++; else failed++;
if (test('passes through non-commit amend malformed JSON and run wrapper paths', () => {
const readInput = JSON.stringify({ tool_input: { command: 'git status --short' } });
assert.deepStrictEqual(hook.evaluate(readInput), { output: readInput, exitCode: 0 });
const amendInput = JSON.stringify({ tool_input: { command: 'git commit --amend -m "fix: update"' } });
assert.deepStrictEqual(hook.evaluate(amendInput), { output: amendInput, exitCode: 0 });
const malformed = 'not json {{{';
const malformedResult = captureConsoleError(() => hook.run(malformed));
assert.deepStrictEqual(malformedResult.result, { stdout: malformed, exitCode: 0 });
assert.ok(malformedResult.stderr.includes('[Hook] Error:'), 'should log JSON parse errors without blocking');
})) passed++; else failed++;
if (test('allows git commit when no files are staged', () => {
inTempRepo(() => {
const input = JSON.stringify({ tool_input: { command: 'git commit -m "fix: no staged files"' } });
const { result, stderr } = captureConsoleError(() => hook.evaluate(input));
assert.strictEqual(result.output, input);
assert.strictEqual(result.exitCode, 0);
assert.ok(stderr.includes('No staged files found'), `expected no-staged warning, got: ${stderr}`);
});
})) passed++; else failed++;
if (test('allows warning-only issues while reporting console TODO and message warnings', () => {
inTempRepo(repoDir => {
writeAndStage(repoDir, 'index.js', [
'console.log("debug only");',
'// TODO: clean this up',
'// TODO: tracked in issue #123',
'// console.log("commented out");',
'* console.log("doc comment");',
'const ok = true;',
''
].join('\n'));
const input = JSON.stringify({
tool_input: {
command: 'git commit -m "fix: Uppercase subject."'
}
});
const { result, stderr } = captureConsoleError(() => hook.evaluate(input));
assert.strictEqual(result.output, input);
assert.strictEqual(result.exitCode, 0, 'warning-only issues should not block');
assert.ok(stderr.includes('WARNING Line 1'), `expected console warning, got: ${stderr}`);
assert.ok(stderr.includes('INFO Line 2'), `expected TODO info warning, got: ${stderr}`);
assert.ok(stderr.includes('Subject should start with lowercase'), `expected capitalization warning, got: ${stderr}`);
assert.ok(stderr.includes('should not end with a period'), `expected punctuation warning, got: ${stderr}`);
assert.ok(stderr.includes('Warnings found'), `expected warning summary, got: ${stderr}`);
});
})) passed++; else failed++;
if (test('reports invalid and long commit messages without blocking when files are clean', () => {
inTempRepo(repoDir => {
writeAndStage(repoDir, 'index.js', 'const clean = true;\n');
const longMessage = `Bad message ${'x'.repeat(80)}`;
const input = JSON.stringify({
tool_input: {
command: `git commit --message="${longMessage}"`
}
});
const { result, stderr } = captureConsoleError(() => hook.evaluate(input));
assert.strictEqual(result.output, input);
assert.strictEqual(result.exitCode, 0);
assert.ok(stderr.includes('does not follow conventional commit format'), `expected format warning, got: ${stderr}`);
assert.ok(stderr.includes('Commit message too long'), `expected length warning, got: ${stderr}`);
});
})) passed++; else failed++;
if (test('blocks commits with staged secret patterns across checkable files', () => {
inTempRepo(repoDir => {
writeAndStage(repoDir, 'index.js', [
"const openai = 'sk-abcdefghijklmnopqrstuvwxyz';",
"const token = 'ghp_abcdefghijklmnopqrstuvwxyzABCDEFGHIJ';",
''
].join('\n'));
writeAndStage(repoDir, 'app.py', [
'aws = "AKIAABCDEFGHIJKLMNOP"',
'api_key = "secret-value"',
''
].join('\n'));
const input = JSON.stringify({ tool_input: { command: 'git commit -m "fix: block secrets"' } });
const { result, stderr } = captureConsoleError(() => hook.evaluate(input));
assert.strictEqual(result.output, input);
assert.strictEqual(result.exitCode, 2);
assert.ok(stderr.includes('Potential OpenAI API key'), `expected OpenAI secret warning, got: ${stderr}`);
assert.ok(stderr.includes('Potential GitHub PAT'), `expected GitHub PAT warning, got: ${stderr}`);
assert.ok(stderr.includes('Potential AWS Access Key'), `expected AWS key warning, got: ${stderr}`);
assert.ok(stderr.includes('Potential API key'), `expected generic API key warning, got: ${stderr}`);
});
})) passed++; else failed++;
if (test('reports eslint pylint and golint failures from staged files', () => {
inTempRepo(repoDir => {
writeAndStage(repoDir, 'index.js', 'const lint = true;\n');
writeAndStage(repoDir, 'app.py', 'print("lint")\n');
writeAndStage(repoDir, 'main.go', 'package main\n');
const eslintPath = path.join(repoDir, 'node_modules', '.bin', executableName('eslint'));
fs.mkdirSync(path.dirname(eslintPath), { recursive: true });
writeFakeExecutable(eslintPath, 'eslint failed', 1);
const binDir = path.join(repoDir, 'fake-bin');
fs.mkdirSync(binDir, { recursive: true });
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));
assert.strictEqual(result.output, input);
assert.strictEqual(result.exitCode, 2);
assert.ok(stderr.includes('ESLint Issues'), `expected ESLint output, got: ${stderr}`);
assert.ok(stderr.includes('eslint failed'), `expected ESLint failure text, got: ${stderr}`);
assert.ok(stderr.includes('Pylint Issues'), `expected Pylint output, got: ${stderr}`);
assert.ok(stderr.includes('pylint failed'), `expected Pylint failure text, got: ${stderr}`);
assert.ok(stderr.includes('golint Issues'), `expected golint output, got: ${stderr}`);
assert.ok(stderr.includes('main.go:1: lint failed'), `expected golint failure text, got: ${stderr}`);
});
});
})) passed++; else failed++;
if (test('stdin entry point truncates oversized input and preserves pass-through output', () => {
const oversized = JSON.stringify({
tool_input: {
command: 'git status',
filler: 'x'.repeat(1024 * 1024 + 1024)
}
});
const result = spawnSync('node', [path.join(__dirname, '..', '..', 'scripts', 'hooks', 'pre-bash-commit-quality.js')], {
input: oversized,
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 10000
});
assert.strictEqual(result.status, 0);
assert.ok(result.stdout.length > 0, 'expected truncated payload to pass through');
assert.ok(result.stdout.length <= 1024 * 1024, 'expected stdout to stay within hook input limit');
assert.strictEqual(result.stdout, oversized.slice(0, result.stdout.length));
assert.ok(result.stderr.includes('[Hook] Error:'), 'truncated JSON should be logged and allowed');
})) passed++; else failed++;
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);

View File

@@ -577,7 +577,7 @@ async function runTests() {
CLAUDE_HOOK_EVENT_NAME: 'PreToolUse',
ECC_MCP_CONFIG_PATH: configPath,
ECC_MCP_HEALTH_STATE_PATH: statePath,
ECC_MCP_HEALTH_TIMEOUT_MS: '100'
ECC_MCP_HEALTH_TIMEOUT_MS: '1000'
}
);

View File

@@ -8,6 +8,7 @@ const os = require('os');
const path = require('path');
const {
getInstallComponent,
loadInstallManifests,
listInstallComponents,
listLegacyCompatibilityLanguages,
@@ -45,6 +46,24 @@ function writeJson(filePath, value) {
fs.writeFileSync(filePath, JSON.stringify(value, null, 2));
}
function writeManifestSet(repoRoot, options = {}) {
writeJson(path.join(repoRoot, 'manifests', 'install-modules.json'), {
version: options.modulesVersion || 1,
modules: options.modules || [],
});
writeJson(path.join(repoRoot, 'manifests', 'install-profiles.json'), {
version: options.profilesVersion || 1,
profiles: options.profiles || {},
});
if (Object.prototype.hasOwnProperty.call(options, 'components')) {
writeJson(path.join(repoRoot, 'manifests', 'install-components.json'), {
version: options.componentsVersion || 1,
components: options.components,
});
}
}
function runTests() {
console.log('\n=== Testing install-manifests.js ===\n');
@@ -80,6 +99,43 @@ function runTests() {
'Should include capability:security');
})) passed++; else failed++;
if (test('gets install component details and validates component IDs', () => {
const component = getInstallComponent(' lang:typescript ');
assert.strictEqual(component.id, 'lang:typescript');
assert.strictEqual(component.family, 'language');
assert.ok(component.moduleIds.length > 0, 'Should expose component module IDs');
assert.strictEqual(component.moduleCount, component.moduleIds.length);
assert.strictEqual(component.modules.length, component.moduleIds.length);
assert.ok(component.modules.every(module => component.moduleIds.includes(module.id)));
assert.ok(Array.isArray(component.targets));
assert.throws(
() => getInstallComponent(''),
/An install component ID is required/
);
assert.throws(
() => getInstallComponent('lang:missing'),
/Unknown install component: lang:missing/
);
})) passed++; else failed++;
if (test('validates install component filters', () => {
const claudeComponents = listInstallComponents({ family: 'capability', target: 'claude' });
assert.ok(claudeComponents.length > 0, 'Should list Claude capability components');
assert.ok(claudeComponents.every(component => component.family === 'capability'));
assert.ok(claudeComponents.every(component => component.targets.includes('claude')));
assert.throws(
() => listInstallComponents({ family: 'unknown' }),
/Unknown component family: unknown/
);
assert.throws(
() => listInstallComponents({ target: 'unknown-target' }),
/Unknown install target: unknown-target/
);
})) passed++; else failed++;
if (test('labels continuous-learning as a legacy v1 install surface', () => {
const components = listInstallComponents({ family: 'skill' });
const component = components.find(entry => entry.id === 'skill:continuous-learning');
@@ -172,6 +228,10 @@ function runTests() {
() => validateInstallModuleIds(['ghost-module']),
/Unknown install module: ghost-module/
);
assert.throws(
() => validateInstallModuleIds(['ghost-one', 'ghost-two']),
/Unknown install modules: ghost-one, ghost-two/
);
})) passed++; else failed++;
if (test('resolves legacy compatibility selections into manifest module IDs', () => {
@@ -251,6 +311,25 @@ function runTests() {
}),
/Unknown legacy language: brainfuck/
);
assert.throws(
() => resolveLegacyCompatibilitySelection({
legacyLanguages: [],
}),
/No legacy languages were provided/
);
assert.throws(
() => resolveLegacyCompatibilitySelection({
target: 'not-a-target',
legacyLanguages: ['typescript'],
}),
/Unknown install target: not-a-target/
);
assert.throws(
() => resolveLegacyCompatibilitySelection({
legacyLanguages: ['brainfuck', 'whitespace'],
}),
/Unknown legacy languages: brainfuck, whitespace/
);
})) passed++; else failed++;
if (test('resolves included and excluded user-facing components', () => {
@@ -293,6 +372,61 @@ function runTests() {
);
})) passed++; else failed++;
if (test('rejects empty, unknown, and fully excluded install selections', () => {
const repoRoot = createTestRepo();
try {
writeManifestSet(repoRoot, {
modules: [
{
id: 'core',
kind: 'rules',
description: 'Core',
paths: ['rules/core.md'],
targets: ['claude'],
dependencies: [],
defaultInstall: true,
cost: 'light',
stability: 'stable'
}
],
profiles: {
core: { description: 'Core', modules: ['core'] }
},
components: [
{
id: 'capability:core',
family: 'capability',
description: 'Core',
modules: ['core']
}
],
});
assert.throws(
() => resolveInstallPlan({ repoRoot }),
/No install profile, module IDs, or included component IDs were provided/
);
assert.throws(
() => resolveInstallPlan({ repoRoot, moduleIds: ['missing'] }),
/Unknown install module: missing/
);
assert.throws(
() => resolveInstallPlan({ repoRoot, includeComponentIds: ['capability:missing'] }),
/Unknown install component: capability:missing/
);
assert.throws(
() => resolveInstallPlan({
repoRoot,
profileId: 'core',
excludeComponentIds: ['capability:core'],
}),
/Selection excludes every requested install module/
);
} finally {
cleanupTestRepo(repoRoot);
}
})) passed++; else failed++;
if (test('validates projectRoot and homeDir option types before adapter planning', () => {
assert.throws(
() => resolveInstallPlan({ profileId: 'core', target: 'cursor', projectRoot: 42 }),
@@ -349,6 +483,92 @@ function runTests() {
}
})) passed++; else failed++;
if (test('rejects missing, malformed, and unsupported manifest fixtures', () => {
const repoRoot = createTestRepo();
try {
assert.throws(
() => loadInstallManifests({ repoRoot }),
/Install manifests not found/
);
fs.writeFileSync(path.join(repoRoot, 'manifests', 'install-modules.json'), '{ bad json');
writeJson(path.join(repoRoot, 'manifests', 'install-profiles.json'), {
version: 1,
profiles: {},
});
assert.throws(
() => loadInstallManifests({ repoRoot }),
/Failed to read install-modules\.json/
);
writeManifestSet(repoRoot, {
modules: [
{
id: 'empty-target',
kind: 'rules',
description: 'Empty target',
paths: ['rules/core.md'],
targets: ['claude', ''],
dependencies: [],
defaultInstall: false,
cost: 'light',
stability: 'stable'
}
],
profiles: {},
});
assert.throws(
() => loadInstallManifests({ repoRoot }),
/Install module empty-target has invalid targets/
);
writeManifestSet(repoRoot, {
modules: [
{
id: 'unsupported-target',
kind: 'rules',
description: 'Unsupported target',
paths: ['rules/core.md'],
targets: ['claude', 'moonbase'],
dependencies: [],
defaultInstall: false,
cost: 'light',
stability: 'stable'
}
],
profiles: {},
});
assert.throws(
() => loadInstallManifests({ repoRoot }),
/Install module unsupported-target has unsupported targets: moonbase/
);
writeManifestSet(repoRoot, {
modules: [
{
id: 'core',
kind: 'rules',
description: 'Core',
paths: ['rules/core.md'],
targets: ['claude'],
dependencies: [],
defaultInstall: false,
cost: 'light',
stability: 'stable'
}
],
profiles: {
core: { description: 'Core', modules: ['core'] }
},
});
const manifests = loadInstallManifests({ repoRoot });
assert.deepStrictEqual(manifests.components, []);
assert.strictEqual(manifests.componentsVersion, null);
} finally {
cleanupTestRepo(repoRoot);
}
})) passed++; else failed++;
if (test('fails fast when install manifest module targets is not an array', () => {
const repoRoot = createTestRepo();
try {
@@ -431,6 +651,48 @@ function runTests() {
}
})) passed++; else failed++;
if (test('detects circular install dependencies', () => {
const repoRoot = createTestRepo();
try {
writeManifestSet(repoRoot, {
modules: [
{
id: 'alpha',
kind: 'skills',
description: 'Alpha',
paths: ['skills/alpha'],
targets: ['claude'],
dependencies: ['beta'],
defaultInstall: false,
cost: 'light',
stability: 'stable'
},
{
id: 'beta',
kind: 'skills',
description: 'Beta',
paths: ['skills/beta'],
targets: ['claude'],
dependencies: ['alpha'],
defaultInstall: false,
cost: 'light',
stability: 'stable'
}
],
profiles: {
core: { description: 'Core', modules: ['alpha'] }
},
});
assert.throws(
() => resolveInstallPlan({ repoRoot, profileId: 'core' }),
/Circular install dependency detected at alpha/
);
} finally {
cleanupTestRepo(repoRoot);
}
})) passed++; else failed++;
console.log(`\nResults: Passed: ${passed}, Failed: ${failed}`);
process.exit(failed > 0 ? 1 : 0);
}

View File

@@ -6,9 +6,10 @@ const assert = require('assert');
const fs = require('fs');
const os = require('os');
const path = require('path');
const { execFileSync } = require('child_process');
const { execFileSync, spawnSync } = require('child_process');
const SCRIPT = path.join(__dirname, '..', '..', 'scripts', 'harness-audit.js');
const { parseArgs } = require(SCRIPT);
function createTempDir(prefix) {
return fs.mkdtempSync(path.join(os.tmpdir(), prefix));
@@ -18,7 +19,7 @@ function cleanup(dirPath) {
fs.rmSync(dirPath, { recursive: true, force: true });
}
function run(args = [], options = {}) {
function buildEnv(options = {}) {
const userProfile = options.userProfile || options.homeDir || process.env.USERPROFILE;
const env = {
...process.env,
@@ -31,9 +32,13 @@ function run(args = [], options = {}) {
env.HOME = process.env.HOME;
}
return env;
}
function run(args = [], options = {}) {
const stdout = execFileSync('node', [SCRIPT, ...args], {
cwd: options.cwd || path.join(__dirname, '..', '..'),
env,
env: buildEnv(options),
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 10000,
@@ -42,6 +47,16 @@ function run(args = [], options = {}) {
return stdout;
}
function runProcess(args = [], options = {}) {
return spawnSync('node', [SCRIPT, ...args], {
cwd: options.cwd || path.join(__dirname, '..', '..'),
env: buildEnv(options),
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe'],
timeout: 10000,
});
}
function test(name, fn) {
try {
fn();
@@ -60,6 +75,46 @@ function runTests() {
let passed = 0;
let failed = 0;
if (test('parseArgs accepts supported forms and rejects invalid arguments', () => {
const rootDir = createTempDir('harness-audit-args-root-');
try {
assert.strictEqual(parseArgs(['node', 'script', '--help']).help, true);
assert.strictEqual(parseArgs(['node', 'script', '-h']).help, true);
const spaced = parseArgs(['node', 'script', '--format', 'json', '--scope', 'skills', '--root', rootDir]);
assert.strictEqual(spaced.format, 'json');
assert.strictEqual(spaced.scope, 'skills');
assert.strictEqual(spaced.root, path.resolve(rootDir));
const equals = parseArgs(['node', 'script', '--format=json', '--scope=hooks', `--root=${rootDir}`]);
assert.strictEqual(equals.format, 'json');
assert.strictEqual(equals.scope, 'hooks');
assert.strictEqual(equals.root, path.resolve(rootDir));
assert.strictEqual(parseArgs(['node', 'script', 'commands']).scope, 'commands');
assert.strictEqual(parseArgs(['node', 'script', '--scope']).scope, 'repo');
assert.throws(() => parseArgs(['node', 'script', '--format', 'xml']), /Invalid format: xml/);
assert.throws(() => parseArgs(['node', 'script', '--scope', 'bad-scope']), /Invalid scope: bad-scope/);
assert.throws(() => parseArgs(['node', 'script', '--unknown']), /Unknown argument: --unknown/);
} finally {
cleanup(rootDir);
}
})) passed++; else failed++;
if (test('cli help exits cleanly and invalid cli args exit with stderr', () => {
const help = runProcess(['--help']);
assert.strictEqual(help.status, 0);
assert.strictEqual(help.stderr, '');
assert.ok(help.stdout.includes('Usage: node scripts/harness-audit.js'));
assert.ok(help.stdout.includes('Deterministic harness audit'));
const invalid = runProcess(['--format', 'xml']);
assert.strictEqual(invalid.status, 1);
assert.strictEqual(invalid.stdout, '');
assert.ok(invalid.stderr.includes('Error: Invalid format: xml. Use text or json.'));
})) passed++; else failed++;
if (test('json output is deterministic between runs', () => {
const first = run(['repo', '--format', 'json']);
const second = run(['repo', '--format', 'json']);
@@ -103,6 +158,29 @@ function runTests() {
assert.ok(output.includes('Top 3 Actions:') || output.includes('Checks:'));
})) passed++; else failed++;
if (test('detects repo mode from structural markers when package name differs', () => {
const projectRoot = createTempDir('harness-audit-structural-repo-');
try {
fs.mkdirSync(path.join(projectRoot, 'scripts'), { recursive: true });
fs.mkdirSync(path.join(projectRoot, '.claude-plugin'), { recursive: true });
fs.mkdirSync(path.join(projectRoot, 'agents'), { recursive: true });
fs.mkdirSync(path.join(projectRoot, 'skills'), { recursive: true });
fs.writeFileSync(path.join(projectRoot, 'scripts', 'harness-audit.js'), '#!/usr/bin/env node\n');
fs.writeFileSync(path.join(projectRoot, '.claude-plugin', 'plugin.json'), JSON.stringify({ name: 'ecc' }, null, 2));
fs.writeFileSync(
path.join(projectRoot, 'package.json'),
JSON.stringify({ name: 'forked-harness', scripts: { test: 'node scripts/validate-commands.js && node tests/run-all.js' } }, null, 2)
);
const parsed = JSON.parse(run(['--format=json', `--root=${projectRoot}`]));
assert.strictEqual(parsed.target_mode, 'repo');
assert.strictEqual(parsed.root_dir, path.resolve(projectRoot));
} finally {
cleanup(projectRoot);
}
})) passed++; else failed++;
if (test('audits consumer projects from cwd instead of the ECC repo root', () => {
const homeDir = createTempDir('harness-audit-home-');
const projectRoot = createTempDir('harness-audit-project-');
@@ -141,6 +219,73 @@ function runTests() {
}
})) passed++; else failed++;
if (test('scores empty consumer projects without plugin or harness signals as failing checks', () => {
const homeDir = createTempDir('harness-audit-empty-home-');
const projectRoot = createTempDir('harness-audit-empty-project-');
try {
const parsed = JSON.parse(run(['repo', '--format', 'json'], { cwd: projectRoot, homeDir }));
assert.strictEqual(parsed.target_mode, 'consumer');
assert.strictEqual(parsed.overall_score, 0);
assert.ok(parsed.max_score > 0);
assert.strictEqual(parsed.top_actions.length, 3);
assert.ok(parsed.checks.some(check => check.id === 'consumer-plugin-install' && !check.pass));
assert.ok(parsed.checks.some(check => check.id === 'consumer-project-overrides' && !check.pass));
assert.ok(parsed.checks.some(check => check.id === 'consumer-secret-hygiene' && !check.pass));
} finally {
cleanup(homeDir);
cleanup(projectRoot);
}
})) passed++; else failed++;
if (test('prints no top actions when consumer checks all pass', () => {
const homeDir = createTempDir('harness-audit-passing-home-');
const projectRoot = createTempDir('harness-audit-passing-project-');
try {
fs.mkdirSync(path.join(projectRoot, '.claude', 'plugins', 'ecc@ecc'), { recursive: true });
fs.writeFileSync(
path.join(projectRoot, '.claude', 'plugins', 'ecc@ecc', 'plugin.json'),
JSON.stringify({ name: 'ecc' }, null, 2)
);
fs.mkdirSync(path.join(projectRoot, '.claude'), { recursive: true });
fs.mkdirSync(path.join(projectRoot, '.github', 'workflows', 'nested'), { recursive: true });
fs.mkdirSync(path.join(projectRoot, 'docs', 'adr'), { recursive: true });
fs.mkdirSync(path.join(projectRoot, 'evals'), { recursive: true });
fs.mkdirSync(path.join(projectRoot, 'src'), { recursive: true });
fs.writeFileSync(path.join(projectRoot, '.claude', 'hooks.json'), JSON.stringify({ hooks: [] }, null, 2));
fs.writeFileSync(path.join(projectRoot, '.claude', 'settings.local.json'), JSON.stringify({ local: true }, null, 2));
fs.writeFileSync(path.join(projectRoot, 'CLAUDE.md'), '# Consumer instructions\n');
fs.writeFileSync(path.join(projectRoot, 'src', 'app.spec.ts'), 'test placeholder\n');
fs.writeFileSync(path.join(projectRoot, '.github', 'workflows', 'nested', 'ci.yaml'), 'name: ci\n');
fs.writeFileSync(path.join(projectRoot, 'docs', 'adr', '001.md'), '# Record\n');
fs.writeFileSync(path.join(projectRoot, 'evals', 'smoke.json'), '{}\n');
fs.writeFileSync(path.join(projectRoot, '.github', 'dependabot.yml'), 'version: 2\n');
fs.writeFileSync(path.join(projectRoot, '.gitignore'), 'node_modules\n.env.local\n');
fs.writeFileSync(
path.join(projectRoot, 'package.json'),
JSON.stringify({ name: 'passing-consumer', scripts: {} }, null, 2)
);
const parsed = JSON.parse(run(['repo', '--format', 'json'], { cwd: projectRoot, homeDir }));
assert.strictEqual(parsed.target_mode, 'consumer');
assert.strictEqual(parsed.overall_score, parsed.max_score);
const text = run(['repo'], { cwd: projectRoot, homeDir });
assert.ok(text.includes(`Harness Audit (repo, consumer): ${parsed.max_score}/${parsed.max_score}`));
assert.ok(text.includes('Checks: 11 total, 0 failing'));
assert.ok(!text.includes('Top 3 Actions:'));
const scopedText = run(['agents'], { cwd: projectRoot, homeDir });
assert.ok(scopedText.includes('Harness Audit (agents, consumer):'));
assert.ok(scopedText.includes('Checks: 1 total, 0 failing'));
} finally {
cleanup(homeDir);
cleanup(projectRoot);
}
})) passed++; else failed++;
if (test('detects marketplace-installed Claude plugins under home marketplaces/', () => {
const homeDir = createTempDir('harness-audit-marketplace-home-');
const projectRoot = createTempDir('harness-audit-marketplace-project-');