mirror of
https://github.com/affaan-m/ECC.git
synced 2026-09-02 14:08:44 +02:00
Merge pull request #2870 from actus7/consolidate/hooks-observer-v3
fix(hooks): consolidate hooks and observer fixes (5 PRs)
This commit is contained in:
@@ -243,6 +243,95 @@ test('preview names match the files --generate writes', () => {
|
||||
}
|
||||
});
|
||||
|
||||
function parseFrontmatter(filePath) {
|
||||
const raw = fs.readFileSync(filePath, 'utf8');
|
||||
const match = /^---\r?\n([\s\S]*?)\r?\n---\r?\n/.exec(raw);
|
||||
if (!match) return null;
|
||||
const fm = {};
|
||||
for (const line of match[1].split(/\r?\n/)) {
|
||||
const idx = line.indexOf(':');
|
||||
if (idx > 0 && !line.startsWith(' ')) {
|
||||
fm[line.slice(0, idx).trim()] = line.slice(idx + 1).trim();
|
||||
}
|
||||
}
|
||||
return fm;
|
||||
}
|
||||
|
||||
test('generated skills carry loadable name + description frontmatter', () => {
|
||||
const root = createTempDir();
|
||||
try {
|
||||
writeInstinct(root, 'first', 'when investigating complex systems');
|
||||
writeInstinct(root, 'second', 'when investigating complex systems');
|
||||
writeInstinct(root, 'third', 'when running tests');
|
||||
|
||||
assert.strictEqual(runCli(root, ['evolve', '--generate']).status, 0);
|
||||
|
||||
const skillsDir = path.join(root, 'evolved', 'skills');
|
||||
const skillDirs = fs.existsSync(skillsDir) ? fs.readdirSync(skillsDir) : [];
|
||||
assert.ok(skillDirs.length > 0, 'expected at least one generated skill');
|
||||
|
||||
for (const name of skillDirs) {
|
||||
const skillFile = path.join(skillsDir, name, 'SKILL.md');
|
||||
const fm = parseFrontmatter(skillFile);
|
||||
assert.ok(fm, `${name}/SKILL.md has no frontmatter block`);
|
||||
assert.strictEqual(fm.name, name, `${name}: frontmatter name must match its folder`);
|
||||
assert.ok(fm.description && fm.description.length > 0, `${name}: description must not be empty`);
|
||||
assert.ok(!/[<>]/.test(fm.description), `${name}: description must not contain < or >`);
|
||||
}
|
||||
} finally {
|
||||
cleanupDir(root);
|
||||
}
|
||||
});
|
||||
|
||||
test('generated agents carry name + description alongside model/tools', () => {
|
||||
const root = createTempDir();
|
||||
try {
|
||||
writeInstinct(root, 'a', 'when reviewing pull requests');
|
||||
writeInstinct(root, 'b', 'when reviewing pull requests');
|
||||
writeInstinct(root, 'c', 'when reviewing pull requests');
|
||||
|
||||
assert.strictEqual(runCli(root, ['evolve', '--generate']).status, 0);
|
||||
|
||||
const agentsDir = path.join(root, 'evolved', 'agents');
|
||||
const agents = fs.existsSync(agentsDir) ? fs.readdirSync(agentsDir) : [];
|
||||
assert.ok(agents.length > 0, 'expected at least one generated agent');
|
||||
|
||||
for (const file of agents) {
|
||||
const fm = parseFrontmatter(path.join(agentsDir, file));
|
||||
assert.ok(fm, `${file} has no frontmatter block`);
|
||||
assert.strictEqual(fm.name, path.basename(file, '.md'));
|
||||
assert.ok(fm.description && fm.description.length > 0, `${file}: description must not be empty`);
|
||||
assert.strictEqual(fm.model, 'sonnet');
|
||||
}
|
||||
} finally {
|
||||
cleanupDir(root);
|
||||
}
|
||||
});
|
||||
|
||||
test('generated descriptions quote YAML comment markers', () => {
|
||||
const root = createTempDir();
|
||||
try {
|
||||
writeInstinct(root, 'hash-marker', 'when reviewing output # preserve this text');
|
||||
writeInstinct(root, 'run-tests', 'when running tests');
|
||||
writeInstinct(root, 'build-images', 'when building images');
|
||||
|
||||
const result = runCli(root, ['evolve', '--generate']);
|
||||
assert.strictEqual(result.status, 0, result.stderr);
|
||||
|
||||
const commandsDir = path.join(root, 'evolved', 'commands');
|
||||
const descriptions = generatedCommands(root).map(file =>
|
||||
fs.readFileSync(path.join(commandsDir, file), 'utf8')
|
||||
.split(/\r?\n/)
|
||||
.find(line => line.startsWith('description: '))
|
||||
);
|
||||
const description = descriptions.find(line => line.includes('# preserve this text'));
|
||||
assert.ok(description, `missing hash-bearing description in ${descriptions.join(', ')}`);
|
||||
assert.match(description, /^description: ".* # preserve this text.*"$/);
|
||||
} finally {
|
||||
cleanupDir(root);
|
||||
}
|
||||
});
|
||||
|
||||
console.log(`\nPassed: ${passed}`);
|
||||
console.log(`Failed: ${failed}`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user