@@ -140,6 +140,68 @@ function runValidator(validatorName) {
140140 }
141141}
142142
143+ function runCatalogValidator ( overrides = { } ) {
144+ const validatorPath = path . join ( validatorsDir , 'catalog.js' ) ;
145+ let source = fs . readFileSync ( validatorPath , 'utf8' ) ;
146+ source = source . replace ( / ^ # ! .* \n / , '' ) ;
147+ source = `process.argv.push('--text');\n${ source } ` ;
148+
149+ const resolvedOverrides = {
150+ ROOT : repoRoot ,
151+ README_PATH : path . join ( repoRoot , 'README.md' ) ,
152+ AGENTS_PATH : path . join ( repoRoot , 'AGENTS.md' ) ,
153+ ...overrides ,
154+ } ;
155+
156+ for ( const [ constant , overridePath ] of Object . entries ( resolvedOverrides ) ) {
157+ const dirRegex = new RegExp ( `const ${ constant } = .*?;` ) ;
158+ source = source . replace ( dirRegex , `const ${ constant } = ${ JSON . stringify ( overridePath ) } ;` ) ;
159+ }
160+
161+ try {
162+ const stdout = execFileSync ( 'node' , [ '-e' , source ] , {
163+ encoding : 'utf8' ,
164+ stdio : [ 'pipe' , 'pipe' , 'pipe' ] ,
165+ timeout : 10000 ,
166+ } ) ;
167+ return { code : 0 , stdout, stderr : '' } ;
168+ } catch ( err ) {
169+ return {
170+ code : err . status || 1 ,
171+ stdout : err . stdout || '' ,
172+ stderr : err . stderr || '' ,
173+ } ;
174+ }
175+ }
176+
177+ function writeCatalogFixture ( testDir , options = { } ) {
178+ const {
179+ readmeCounts = { agents : 1 , skills : 1 , commands : 1 } ,
180+ summaryCounts = { agents : 1 , skills : 1 , commands : 1 } ,
181+ structureLines = [
182+ 'agents/ — 1 specialized subagents' ,
183+ 'skills/ — 1 workflow skills and domain knowledge' ,
184+ 'commands/ — 1 slash commands' ,
185+ ] ,
186+ } = options ;
187+
188+ const readmePath = path . join ( testDir , 'README.md' ) ;
189+ const agentsPath = path . join ( testDir , 'AGENTS.md' ) ;
190+
191+ fs . mkdirSync ( path . join ( testDir , 'agents' ) , { recursive : true } ) ;
192+ fs . mkdirSync ( path . join ( testDir , 'commands' ) , { recursive : true } ) ;
193+ fs . mkdirSync ( path . join ( testDir , 'skills' , 'demo-skill' ) , { recursive : true } ) ;
194+
195+ fs . writeFileSync ( path . join ( testDir , 'agents' , 'planner.md' ) , '---\nmodel: sonnet\ntools: Read\n---\n# Planner' ) ;
196+ fs . writeFileSync ( path . join ( testDir , 'commands' , 'plan.md' ) , '---\ndescription: Plan\n---\n# Plan' ) ;
197+ fs . writeFileSync ( path . join ( testDir , 'skills' , 'demo-skill' , 'SKILL.md' ) , '---\nname: demo-skill\ndescription: Demo skill\norigin: ECC\n---\n# Demo Skill' ) ;
198+
199+ fs . writeFileSync ( readmePath , `Access to ${ readmeCounts . agents } agents, ${ readmeCounts . skills } skills, and ${ readmeCounts . commands } commands.\n| Feature | Claude Code | Cursor IDE | Codex CLI | OpenCode |\n|---------|------------|------------|-----------|----------|\n| Agents | ✅ ${ readmeCounts . agents } agents | Shared | Shared | 1 |\n| Commands | ✅ ${ readmeCounts . commands } commands | Shared | Shared | 1 |\n| Skills | ✅ ${ readmeCounts . skills } skills | Shared | Shared | 1 |\n` ) ;
200+ fs . writeFileSync ( agentsPath , `This is a **production-ready AI coding plugin** providing ${ summaryCounts . agents } specialized agents, ${ summaryCounts . skills } skills, ${ summaryCounts . commands } commands, and automated hook workflows for software development.\n\n\`\`\`\n${ structureLines . join ( '\n' ) } \n\`\`\`\n` ) ;
201+
202+ return { readmePath, agentsPath } ;
203+ }
204+
143205function runTests ( ) {
144206 console . log ( '\n=== Testing CI Validators ===\n' ) ;
145207
@@ -262,6 +324,60 @@ function runTests() {
262324 assert . ok ( result . stdout . includes ( 'Validated' ) , 'Should output validation count' ) ;
263325 } ) ) passed ++ ; else failed ++ ;
264326
327+ // ==========================================
328+ // catalog.js
329+ // ==========================================
330+ console . log ( '\ncatalog.js:' ) ;
331+
332+ if ( test ( 'passes on real project catalog counts' , ( ) => {
333+ const result = runCatalogValidator ( ) ;
334+ assert . strictEqual ( result . code , 0 , `Should pass, got stderr: ${ result . stderr } ` ) ;
335+ assert . ok ( result . stdout . includes ( 'Documentation counts match the repository catalog.' ) , 'Should report matching counts' ) ;
336+ } ) ) passed ++ ; else failed ++ ;
337+
338+ if ( test ( 'fails when README and AGENTS catalog counts drift' , ( ) => {
339+ const testDir = createTestDir ( ) ;
340+ const { readmePath, agentsPath } = writeCatalogFixture ( testDir , {
341+ readmeCounts : { agents : 99 , skills : 99 , commands : 99 } ,
342+ summaryCounts : { agents : 99 , skills : 99 , commands : 99 } ,
343+ structureLines : [
344+ 'agents/ — 99 specialized subagents' ,
345+ 'skills/ — 99 workflow skills and domain knowledge' ,
346+ 'commands/ — 99 slash commands' ,
347+ ] ,
348+ } ) ;
349+
350+ const result = runCatalogValidator ( {
351+ ROOT : testDir ,
352+ README_PATH : readmePath ,
353+ AGENTS_PATH : agentsPath ,
354+ } ) ;
355+
356+ assert . strictEqual ( result . code , 1 , 'Should fail when catalog counts drift' ) ;
357+ assert . ok ( ( result . stdout + result . stderr ) . includes ( 'Documentation count mismatches found:' ) , 'Should report mismatches' ) ;
358+ cleanupTestDir ( testDir ) ;
359+ } ) ) passed ++ ; else failed ++ ;
360+
361+ if ( test ( 'accepts AGENTS project structure entries with varied spacing and dash styles' , ( ) => {
362+ const testDir = createTestDir ( ) ;
363+ const { readmePath, agentsPath } = writeCatalogFixture ( testDir , {
364+ structureLines : [
365+ ' agents/ - 1 specialized subagents ' ,
366+ '\tskills/\t–\t1+ workflow skills and domain knowledge\t' ,
367+ ' commands/ — 1 slash commands ' ,
368+ ] ,
369+ } ) ;
370+
371+ const result = runCatalogValidator ( {
372+ ROOT : testDir ,
373+ README_PATH : readmePath ,
374+ AGENTS_PATH : agentsPath ,
375+ } ) ;
376+
377+ assert . strictEqual ( result . code , 0 , `Should accept formatting variations, got stderr: ${ result . stderr } ` ) ;
378+ cleanupTestDir ( testDir ) ;
379+ } ) ) passed ++ ; else failed ++ ;
380+
265381 if ( test ( 'exits 0 when hooks.json does not exist' , ( ) => {
266382 const result = runValidatorWithDir ( 'validate-hooks' , 'HOOKS_FILE' , '/nonexistent/hooks.json' ) ;
267383 assert . strictEqual ( result . code , 0 , 'Should skip when no hooks.json' ) ;
0 commit comments