Skip to content
Draft
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
8 changes: 8 additions & 0 deletions .github/scripts/change-scope.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ const OFFICIAL_PACKAGES = 'packages/cli/assets/discover/official-packages.json';
const LAB_STORY =
/^apps\/storybook\/stories\/([A-Z][A-Za-z0-9]*)\.stories\.tsx$/;
const LAB_COMPONENT_DIR = /^packages\/lab\/src\/([A-Z][A-Za-z0-9]*)\//;
// The swizzle proof's Lab samples, which `pnpm lab:sync` writes.
const LAB_SAMPLES = 'packages/lab/swizzle-samples.mjs';
// A Lab component's own spec records.
const LAB_SPEC_DIR = /^docs\/specs\/components\/([A-Z][A-Za-z0-9]*)\//;

// The registry's route slug for a component name. It mirrors
// slugifyRegistryName in apps/docsite/src/lib/shadcnRegistry.mjs (a test pins
Expand Down Expand Up @@ -165,6 +169,9 @@ function isLabEntryChange(change, {names, patches, officialPackagesBase}) {
)
return false;
const slugs = new Set([...names].map(labRouteSlug));
if (change.filename === LAB_SAMPLES) return true;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI never reaches this line for the samples file or a record folder. The guard above refuses a file with no patch, and .github/actions/test-scope/action.yml passes patches only for the route lock, official-packages.json and stories (LAB_ENTRY), so in CI the new Rating fixture still classifies as mixed with the full suite. Decide these two entries by path before the patch guard (keeping the rename refusal), and add an end-to-end case to test-scope-action.test.mjs.

const spec = LAB_SPEC_DIR.exec(change.filename);
if (spec) return names.has(spec[1]);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This matches by folder name only. Lab's InfoTip (a deprecated re-export of Core InfoTip) and Chat folders share names with Core record folders, so packages/lab/src/InfoTip/index.ts plus Core's current docs/specs/components/InfoTip/InfoTip.spec.md classifies as Lab-only with no full suite. Match the record to the Lab component by content (for example, accept only an added record whose patch names packages/lab/src/<Name>/ and no packages/core/ path), and add a refused InfoTip case.

if (change.filename === ROUTES_LOCK)
return routesLockNamesLabOnly(patch, slugs);
if (change.filename === OFFICIAL_PACKAGES)
Expand Down Expand Up @@ -576,6 +583,7 @@ if (require.main === module) {

module.exports = {
LAB_ROOT,
LAB_SAMPLES,
OFFICIAL_PACKAGES,
ROUTES_LOCK,
NODE_TOOLING_PATHS,
Expand Down
84 changes: 84 additions & 0 deletions .github/scripts/change-scope.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -960,6 +960,90 @@ describe('Lab entry files (spec:AST-030 FR26)', () => {
});
});

describe('a new Lab component with its samples and spec folder (spec:AST-030 FR26)', () => {
const {ROUTES_LOCK, LAB_SAMPLES} = require('./change-scope.cjs');
const item = (name, path) => [
'+ {',
`+ "name": "${name}",`,
`+ "path": "${path}",`,
'+ "aliases": []',
'+ },',
];
const lockPatch = items =>
['@@ -98,6 +98,16 @@', ...items.flatMap(([n, p]) => item(n, p))].join('\n');
const added = text => `@@ -0,0 +1,1 @@\n+${text}`;
// One component named for its own folder, as a new Lab component lands
// once lab:sync has written its route entries and sample.
const rating = [
{filename: 'packages/lab/src/Rating/Rating.tsx', status: 'A'},
{filename: 'packages/lab/src/Rating/Rating.doc.mjs', status: 'A'},
{filename: 'packages/lab/src/index.ts', status: 'M'},
{filename: 'packages/lab/blocks/RatingBasic.doc.mjs', status: 'A'},
{filename: LAB_SAMPLES, status: 'M'},
{filename: 'docs/specs/components/Rating/Rating.spec.md', status: 'A'},
{filename: 'apps/storybook/stories/Rating.stories.tsx', status: 'A'},
{filename: ROUTES_LOCK, status: 'M'},
{filename: '.changeset/lab-rating.md', status: 'A'},
];
const ratingPatches = {
[ROUTES_LOCK]: lockPatch([
['component-lab-rating', 'components/lab/rating'],
['example-rating-basic', 'examples/rating/basic'],
]),
'apps/storybook/stories/Rating.stories.tsx': added(
"import {Rating} from '@astryxdesign/lab';",
),
[LAB_SAMPLES]: added(' lab__Rating: () => null,'),
'docs/specs/components/Rating/Rating.spec.md': added('# Rating'),
};

it('stays in the Lab lane with its samples, its own spec folder and its routes', () => {
const result = classifyChanges(rating, {patches: ratingPatches});
expect(result.labOnly).toBe(true);
expect(result.fullSuite).toBe(false);
});

it("refuses another component's spec folder", () => {
const other = rating.map(f =>
f.filename.startsWith('docs/specs/')
? {...f, filename: 'docs/specs/components/Drawer/Drawer.spec.md'}
: f,
);
expect(
classifyChanges(other, {
patches: {
...ratingPatches,
'docs/specs/components/Drawer/Drawer.spec.md': added('x'),
},
}).labOnly,
).toBe(false);
});

it('keeps the full suite for a family folder, as #9832 added MediaPlayer with AudioPlayer and VideoPlayer', () => {
const family = [
{filename: 'packages/lab/src/MediaPlayer/MediaPlayer.tsx', status: 'A'},
{filename: 'packages/lab/src/MediaPlayer/AudioPlayer.tsx', status: 'A'},
{
filename: 'packages/lab/src/MediaPlayer/MediaPlayer.doc.mjs',
status: 'A',
},
{filename: LAB_SAMPLES, status: 'M'},
{filename: ROUTES_LOCK, status: 'M'},
];
const result = classifyChanges(family, {
patches: {
[LAB_SAMPLES]: added(' lab__MediaPlayer: () => null,'),
[ROUTES_LOCK]: lockPatch([
['component-lab-audio-player', 'components/lab/audio-player'],
['component-lab-media-player', 'components/lab/media-player'],
]),
},
});
expect(result.labOnly).toBe(false);
expect(result.fullSuite).toBe(true);
});
});

describe('Lab component folders (spec:AST-030 FR26)', () => {
it('reads a carried component only from a component folder, not a shared one', () => {
const {ROUTES_LOCK} = require('./change-scope.cjs');
Expand Down
82 changes: 81 additions & 1 deletion .github/scripts/ci-lab-only-routing.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
* @position Workflow contract beside ci-tooling-routing.test.mjs.
*/

import {execFileSync, spawnSync} from 'node:child_process';
import fs from 'node:fs';
import {createRequire} from 'node:module';
import os from 'node:os';
import path from 'node:path';

import {describe, expect, it} from 'vitest';
Expand Down Expand Up @@ -123,14 +125,92 @@ describe('Lab-only lane (spec:AST-030 FR26)', () => {
expect(official.run).toBe(
'pnpm exec vitest run scripts/check-cli-official-packages.test.mjs --maxWorkers=1',
);
for (const s of steps('test-node').filter(s => s !== official)) {
// Every Lab route-lock entry and swizzle sample is present.
const sync = step('test-node', 'Lab-only: Lab sync check');
expect(sync.if).toBe(`matrix.shard == 1 && ${LAB_TRUE}`);
expect(sync.run).toBe('node scripts/lab-sync.mjs --check');
for (const s of steps('test-node').filter(
s => s !== official && s !== sync,
)) {
expect(String(s.if ?? ''), s.name ?? s.uses ?? s.run).not.toContain(
'lab_only',
);
expect(s.run ?? '', s.name).not.toContain('LAB_ONLY');
}
});

it('always runs the swizzle samples test, a source-reading guard the scoped Node run lists', async () => {
const {fsGuardTests} = await import('./fs-guard-tests.mjs');
const file = 'packages/cli/test/swizzle-proof/samples.test.mjs';
expect(fsGuardTests([file], f => read(f))).toEqual([file]);
});

it('a Lab-only doc change with an unchanged lock still runs the route-lock check', () => {
const routeLock = step(
'build-storybook',
'Lab-only: check the ShadCN route lock',
);
const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'lab-route-lock-'));
const dir = path.join(tmp, 'repo');
fs.mkdirSync(dir);
const ran = path.join(tmp, 'ran');
const git = (...args) =>
execFileSync('git', args, {cwd: dir, encoding: 'utf8'}).trim();
const put = (file, text) => {
fs.mkdirSync(path.dirname(path.join(dir, file)), {recursive: true});
fs.writeFileSync(path.join(dir, file), text);
};
git('init', '-q');
put('internal/shadcn-registry/routes.lock.json', '{"items": []}\n');
put('packages/lab/src/Foo/Foo.doc.mjs', "export default {name: 'Foo'};\n");
put('packages/lab/src/Foo/Foo.tsx', 'export {};\n');
git('add', '-A');
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-qm', 'base');
const base = git('rev-parse', 'HEAD');
// A stand-in for node that records the generator run.
const bin = path.join(tmp, 'bin');
fs.mkdirSync(bin);
fs.writeFileSync(
path.join(bin, 'node'),
`#!/bin/sh\necho "$@" >> "${ran}"\n`,
{mode: 0o755},
);
const run = () => {
fs.rmSync(ran, {force: true});
spawnSync('bash', ['-c', routeLock.run], {
cwd: dir,
env: {
...process.env,
MERGE_BASE: base,
PATH: `${bin}:${process.env.PATH}`,
},
});
return fs.existsSync(ran) ? fs.readFileSync(ran, 'utf8') : '';
};
const commit = (file, text) => {
put(file, text);
git('add', '-A');
git('-c', 'user.name=t', '-c', 'user.email=t@t', 'commit', '-qm', file);
};
// A source-only change leaves the lock alone: no check.
commit('packages/lab/src/Foo/Foo.tsx', 'export const x = 1;\n');
expect(run()).toBe('');
// A Lab doc change, a Lab entry module change or a lock change checks.
for (const [file, text] of [
['packages/lab/src/Foo/Foo.doc.mjs', "export default {name: 'Foo2'};\n"],
['packages/lab/src/index.ts', "export * from './Foo/Foo';\n"],
[
'packages/lab/blocks/FooBasic.doc.mjs',
"export default {name: 'Basic'};\n",
],
['internal/shadcn-registry/routes.lock.json', '{"items": [1]}\n'],
]) {
git('reset', '-q', '--hard', base);
commit(file, text);
expect(run(), file).toContain('apps/docsite/scripts/generate-data.mjs');
}
});

it('runs every Lab test and the source-reading guards on the UI legs, with the repository guards', () => {
const suite = step('test-ui', 'Run this shard of the UI tests');
expect(suite.env.LAB_ONLY).toBe('${{ steps.scope.outputs.lab_only }}');
Expand Down
1 change: 1 addition & 0 deletions .github/scripts/ci-node-leg-bounds.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ describe('the Node legs inside their job limit', () => {
expect(legOneOnly.sort()).toEqual([
'Check out the change for the tests that read its records',
'Lab-only: CLI official-packages check',
'Lab-only: Lab sync check',
'List the tests that read a changed record',
]);
expect(
Expand Down
19 changes: 14 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,14 @@ jobs:
# One Node-project test file: Vitest finds its project from the path.
run: pnpm exec vitest run scripts/check-cli-official-packages.test.mjs --maxWorkers=1

# Every Lab component's route-lock entry and swizzle sample is present
# (spec:AST-030 FR26): it names any that `pnpm lab:sync` would write.
# The swizzle samples' own test reads sources, so the scoped run above
# already ran it as a source-reading guard.
- name: 'Lab-only: Lab sync check'
if: matrix.shard == 1 && steps.scope.outputs.lab_only == 'true'
run: node scripts/lab-sync.mjs --check

# The Node project's browser contracts run in a job of their own, beside the
# Node legs: theme-family compilation (owned by `theme-build`, not Build,
# until that surface has an admitted lane of its own), offline-media's
Expand Down Expand Up @@ -2897,17 +2905,18 @@ jobs:
if: steps.scope.outputs.spec_only != 'true' && steps.scope.outputs.lab_only == 'true'
run: pnpm -F @astryxdesign/lab -F @astryxdesign/storybook typecheck

# A Lab-only change whose route lock differs from the merge base checks
# the lock against the registry the docsite builds from these packages
# (spec:AST-030 FR26). Without a merge base, it checks anyway.
# A Lab-only change that changes the route lock, a Lab doc or a Lab
# index.ts checks the lock against the registry the docsite builds from
# these packages (spec:AST-030 FR26): a new Lab doc with no route entry
# fails here. Without a merge base, it checks anyway.
- name: 'Lab-only: check the ShadCN route lock'
if: steps.scope.outputs.docsite_only != 'true' && steps.scope.outputs.spec_only != 'true' && steps.scope.outputs.tooling_only != 'true' && steps.scope.outputs.lab_only == 'true'
env:
DOCSITE_TARGET: canary
MERGE_BASE: ${{ steps.merge-base.outputs.sha }}
run: |
if [ -n "$MERGE_BASE" ] && git diff --quiet "$MERGE_BASE" HEAD -- internal/shadcn-registry/routes.lock.json 2>/dev/null; then
echo "The route lock matches the merge base."
if [ -n "$MERGE_BASE" ] && git diff --quiet "$MERGE_BASE" HEAD -- internal/shadcn-registry/routes.lock.json ':(glob)packages/lab/src/**/*.doc.mjs' ':(glob)packages/lab/blocks/*.doc.mjs' ':(glob)packages/lab/src/**/index.ts' 2>/dev/null; then
echo "The route lock, the Lab docs and the Lab entry modules match the merge base."
exit 0
fi
node apps/docsite/scripts/generate-data.mjs
Expand Down