mirror of
https://github.com/affaan-m/ECC.git
synced 2026-08-20 22:42:22 +02:00
Load bounded project-local Hookify rules, evaluate untrusted regexes in a resource-limited worker, and emit event-correct structured warn/block outputs for PreToolUse, PostToolUse, UserPromptSubmit, and Stop. Register bounded entrypoints, prevent recursive Stop loops, document the runtime contract, and package the implementation.\n\nCloses #2561
90 lines
2.5 KiB
JavaScript
90 lines
2.5 KiB
JavaScript
/**
|
|
* Documentation contract tests for the built-in Hookify runtime.
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
const REPO_ROOT = path.join(__dirname, '..', '..');
|
|
|
|
function read(relativePath) {
|
|
return fs.readFileSync(path.join(REPO_ROOT, relativePath), 'utf8');
|
|
}
|
|
|
|
function test(name, fn) {
|
|
try {
|
|
fn();
|
|
console.log(` ✓ ${name}`);
|
|
return true;
|
|
} catch (error) {
|
|
console.log(` ✗ ${name}`);
|
|
console.log(` Error: ${error.message}`);
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function runTests() {
|
|
console.log('\n=== Hookify runtime documentation tests ===\n');
|
|
|
|
let passed = 0;
|
|
let failed = 0;
|
|
|
|
if (test('help documents the built-in runtime, limits, and event-correct warning/block behavior', () => {
|
|
const help = read('commands/hookify-help.md');
|
|
|
|
for (const requiredText of [
|
|
'built-in Node.js runtime',
|
|
'PreToolUse',
|
|
'PostToolUse',
|
|
'UserPromptSubmit',
|
|
'Stop',
|
|
'PostToolUse cannot undo',
|
|
'Stop warning does not make Claude continue',
|
|
'fail open',
|
|
'worker',
|
|
'does not read `transcript_path`',
|
|
]) {
|
|
assert.ok(help.includes(requiredText), `Hookify help should mention: ${requiredText}`);
|
|
}
|
|
})) passed++; else failed++;
|
|
|
|
if (test('authoring command and skill document the complete supported schema', () => {
|
|
const authoring = read('commands/hookify.md');
|
|
const skill = read('skills/hookify-rules/SKILL.md');
|
|
const combined = `${authoring}\n${skill}`;
|
|
|
|
for (const requiredText of [
|
|
'conditions:',
|
|
'tool_matcher',
|
|
'regex_match',
|
|
'not_contains',
|
|
'starts_with',
|
|
'ends_with',
|
|
'pattern',
|
|
'action: block|warn',
|
|
]) {
|
|
assert.ok(combined.includes(requiredText), `Hookify authoring docs should mention: ${requiredText}`);
|
|
}
|
|
assert.ok(skill.includes('last assistant message'));
|
|
assert.ok(skill.includes('project `.claude/` directory'));
|
|
})) passed++; else failed++;
|
|
|
|
if (test('list and configure commands state that malformed rules are skipped rather than enforced', () => {
|
|
const list = read('commands/hookify-list.md');
|
|
const configure = read('commands/hookify-configure.md');
|
|
|
|
assert.ok(list.includes('malformed'));
|
|
assert.ok(list.includes('skipped'));
|
|
assert.ok(configure.includes('strict schema'));
|
|
})) passed++; else failed++;
|
|
|
|
console.log(`\nPassed: ${passed}`);
|
|
console.log(`Failed: ${failed}`);
|
|
process.exit(failed > 0 ? 1 : 0);
|
|
}
|
|
|
|
runTests();
|