Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions tools/readiness-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,19 @@ export async function scanSkillDirectories(root: string): Promise<string[]> {
const foundSet = new Set<string>();
for (const dir of dirs) {
if (!(await fileExists(dir))) continue;
const entries = await readdir(dir, { withFileTypes: true });
for (const e of entries) {
if (e.isDirectory()) foundSet.add(e.name);
if (e.isFile() && e.name === 'SKILL.md') foundSet.add('root-skill');
try {
const entries = await readdir(dir, { withFileTypes: true });
for (const e of entries) {
if (e.isDirectory()) foundSet.add(e.name);
if (e.isFile() && e.name === 'SKILL.md') foundSet.add('root-skill');
}
} catch {
// fileExists only proves the path existed at stat time -- it can still
// turn out to not be a directory (ENOTDIR), be unreadable (EPERM), or
// be removed between the two calls (ENOENT/TOCTOU). Any of those used
// to propagate out of this function uncaught, aborting the whole
// audit run in loop-audit/goal-audit instead of just skipping this one
// path. Matches tools/mcp-server/src/resolver.ts's listSkills().
}
}
return [...foundSet];
Expand Down
18 changes: 18 additions & 0 deletions tools/readiness-core/test/index.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,21 @@ test('scanSkillDirectories finds skills in target directory', async () => {

await fs.rm(fixtureDir, { recursive: true, force: true });
});

test('scanSkillDirectories skips a skills path that is not a directory instead of throwing', async () => {
// fileExists() only proves the path existed at stat() time -- it doesn't
// prove readdir() will succeed on it. A `skills` path that's actually a
// file (renamed, a broken checkout, a stray artifact) used to crash the
// whole scan with an uncaught ENOTDIR, aborting the entire audit run in
// loop-audit/goal-audit instead of just skipping this one path.
const fixtureDir = path.join(process.cwd(), '.test-fixture-not-a-dir');
await fs.rm(fixtureDir, { recursive: true, force: true });
await fs.mkdir(path.join(fixtureDir, '.claude'), { recursive: true });
await fs.writeFile(path.join(fixtureDir, '.claude', 'skills'), 'not actually a directory');
await fs.mkdir(path.join(fixtureDir, 'skills', 'bar'), { recursive: true });

const skills = await scanSkillDirectories(fixtureDir);
assert.ok(skills.includes('bar'), 'A valid skills dir is still scanned despite a broken sibling path');

await fs.rm(fixtureDir, { recursive: true, force: true });
});