Skip to content

fix(build): look up example skip patterns by directory name - #285

Open
Ref34t wants to merge 1 commit into
PostHog:mainfrom
Ref34t:fix-example-skip-pattern-lookup
Open

fix(build): look up example skip patterns by directory name#285
Ref34t wants to merge 1 commit into
PostHog:mainfrom
Ref34t:fix-example-skip-pattern-lookup

Conversation

@Ref34t

@Ref34t Ref34t commented Jul 28, 2026

Copy link
Copy Markdown

Fixes #284.

Problem

Per-example overrides in context/skip-patterns.yaml were looked up by the wrong key for any skill with a single example, so they never applied.

scripts/lib/skill-generator.js:644

skipPatterns.examples[isSingle ? skill.id : dirName]

Keys in the examples: block are example directory names — laravel, android, swift-xcodegen. With one example path the lookup used skill.id (integration-laravel) instead, missed, and returned undefined. mergeSkipPatterns treats that as "no overrides" and the build carried on with no error.

isSingle is the right switch for the other two things it controls — the output filename and the display title, both generated by the build. Config keys are typed by hand, and they are always directory names, so the same branch shouldn't apply here.

Fix

One lookup, always by directory name, extracted so it can be tested:

function skipPatternsForExample(skipPatterns, dirName) {
    return mergeSkipPatterns(skipPatterns.global, skipPatterns.examples?.[dirName]);
}

No key in skip-patterns.yaml is a skill id today, so nothing that currently resolves stops resolving.

Effect on shipped skills

Two skills had overrides that were being dropped. Rebuilt and compared references/EXAMPLE.md:

Skill Before After Removed
integration-laravel 81,558 60,662 20,896 (26%)
integration-android 67,047 50,906 16,141 (24%)

The Laravel case is almost entirely bootstrap/cache/services.php, Laravel's generated package-discovery cache — a machine-written list of class names that Laravel's own .gitignore excludes. It was 17% of that skill. For scale, references/COMMANDMENTS.md in the same bundle is 1,618 bytes.

integration-swift has two example paths, so it was already taking the dirName branch. Its allow rescue for project.yml still works after the change — verified, still 8 occurrences in EXAMPLE-swift-xcodegen.md.

Tests

Five added to scripts/lib/tests/skip-patterns.test.js, including the one that pins the bug:

it('does not look overrides up by skill id', () => {
    const patterns = skipPatternsForExample(config, 'integration-laravel');
    expect(shouldSkip('bootstrap/cache/services.php', patterns)).toBe(false);
});

The existing suite covered mergeSkipPatterns and shouldSkip, which were both correct — the bug was in the key handed to them, which nothing exercised.

npm test       ✅ 142 passing
npm run build  ✅ 118 skills

Worth a follow-up

The lookup failed silently. A key in examples: that matches no example directory produces no warning, so a rule can look right in the file and do nothing. A build-time check that every examples: key resolves would turn this class of bug into an error. Left out here to keep the change to one thing — happy to add it if you want it.

Separately, bootstrap/cache/*.php is generated output committed to example-apps/laravel. This PR stops it reaching the bundle, but removing it from the repo would be worth doing on its own.

@Ref34t
Ref34t requested a review from a team as a code owner July 28, 2026 09:40
@Ref34t
Ref34t force-pushed the fix-example-skip-pattern-lookup branch from b3fd888 to f9ede84 Compare July 28, 2026 09:41
Keys in the examples: block of skip-patterns.yaml are example directory names,
but a skill with a single example path looked its overrides up by skill.id.
The lookup missed, mergeSkipPatterns read it as no overrides, and the build
carried on with no error, so rules that were written on purpose never ran.

Extract the lookup so it always keys on the directory name and can be tested.
isSingle still selects the output filename and display title, which the build
generates; config keys are typed by hand and are always directories.

Rebuilt: integration-laravel drops 20,896 bytes (bootstrap/cache/services.php,
Laravel's generated package cache) and integration-android drops 16,141.
integration-swift already took the dirName branch and is unchanged.

Fixes PostHog#284
@Ref34t
Ref34t force-pushed the fix-example-skip-pattern-lookup branch from f9ede84 to 2c2b74a Compare July 28, 2026 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Per-example skip patterns are ignored for skills with a single example

1 participant