Skip to content
Open
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
9 changes: 9 additions & 0 deletions scripts/lib/example-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ function mergeSkipPatterns(globalPatterns, examplePatterns = {}) {
};
}

/**
* Global patterns plus any override for this example. The `examples:` block in
* skip-patterns.yaml is keyed by directory name, not skill id.
*/
function skipPatternsForExample(skipPatterns, dirName) {
return mergeSkipPatterns(skipPatterns.global, skipPatterns.examples?.[dirName]);
}

/**
* Recursively collect all files in a directory
*/
Expand Down Expand Up @@ -199,6 +207,7 @@ const defaultPlugins = [ignoreFilePlugin, ignoreBlockPlugin, ignoreLinePlugin];
export {
loadSkipPatterns,
mergeSkipPatterns,
skipPatternsForExample,
shouldSkip,
processExample,
defaultPlugins,
Expand Down
4 changes: 2 additions & 2 deletions scripts/lib/skill-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import path from 'path';
import crypto from 'crypto';
import yaml from 'js-yaml';
import matter from 'gray-matter';
import { processExample, loadSkipPatterns, mergeSkipPatterns, defaultPlugins } from './example-processor.js';
import { processExample, loadSkipPatterns, skipPatternsForExample, defaultPlugins } from './example-processor.js';
import { CLI_ROLES, validateCommandName } from './cli-block-validation.js';

/**
Expand Down Expand Up @@ -641,7 +641,7 @@ async function generateSkill({
displayName: isSingle ? skill.display_name : dirName,
id: skill.id,
repoRoot,
skipPatterns: mergeSkipPatterns(skipPatterns.global, skipPatterns.examples[isSingle ? skill.id : dirName]),
skipPatterns: skipPatternsForExample(skipPatterns, dirName),
plugins: defaultPlugins,
});

Expand Down
41 changes: 40 additions & 1 deletion scripts/lib/tests/skip-patterns.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest';
import { mergeSkipPatterns, shouldSkip } from '../example-processor.js';
import { mergeSkipPatterns, shouldSkip, skipPatternsForExample } from '../example-processor.js';

const globalPatterns = {
includes: ['.yml', '.gitignore', 'node_modules'],
Expand Down Expand Up @@ -42,6 +42,45 @@ describe('shouldSkip', () => {
});
});

describe('skipPatternsForExample', () => {
const config = {
global: globalPatterns,
examples: {
laravel: { includes: ['bootstrap/cache'] },
'swift-xcodegen': { allow: ['project.yml'] },
},
};

it('finds an example override by directory name', () => {
const patterns = skipPatternsForExample(config, 'laravel');
expect(shouldSkip('bootstrap/cache/services.php', patterns)).toBe(true);
});

// The lookup key is the example directory, never the skill id — a skill
// with a single example used to be looked up as `integration-laravel`,
// silently missing every override written for `laravel`.
it('does not look overrides up by skill id', () => {
const patterns = skipPatternsForExample(config, 'integration-laravel');
expect(shouldSkip('bootstrap/cache/services.php', patterns)).toBe(false);
});

it('applies allow overrides by directory name', () => {
const patterns = skipPatternsForExample(config, 'swift-xcodegen');
expect(shouldSkip('project.yml', patterns)).toBe(false);
});

it('falls back to global patterns for an example with no overrides', () => {
const patterns = skipPatternsForExample(config, 'php');
expect(shouldSkip('node_modules/foo.js', patterns)).toBe(true);
expect(shouldSkip('bootstrap/cache/services.php', patterns)).toBe(false);
});

it('tolerates a config with no examples block', () => {
const patterns = skipPatternsForExample({ global: globalPatterns }, 'laravel');
expect(shouldSkip('node_modules/foo.js', patterns)).toBe(true);
});
});

describe('mergeSkipPatterns', () => {
it('concatenates example includes and allow onto global patterns', () => {
const merged = mergeSkipPatterns(globalPatterns, {
Expand Down