An open source design system that's fully customizable and agent ready
TypeScript
ci: lint checks that the probe theme is current (#10305)
Cindy Zhang19171513dbd5
diff --git a/.github/scripts/ci-probe-theme-check.test.mjs b/.github/scripts/ci-probe-theme-check.test.mjsnew file mode 100644index 0000000000..3d0eec0dba--- /dev/null+++ b/.github/scripts/ci-probe-theme-check.test.mjs@@ -0,0 +1,85 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file Contract: required lint checks that the probe theme is current.+ *+ * The visual gate's probe theme is generated from the component docs. A+ * theming target or state documented without regenerating it is one the gate+ * never probes, so lint runs the generator's own --check and names the fix.+ */++import {spawnSync} from 'node:child_process';+import fs from 'node:fs';+import os from 'node:os';+import path from 'node:path';++import {afterAll, describe, expect, it} from 'vitest';+import yaml from 'yaml';++const root = path.resolve(import.meta.dirname, '../..');+const lint = yaml.parse(+ fs.readFileSync(path.join(root, '.github/workflows/lint.yml'), 'utf8'),+);+const steps = lint.jobs.lint.steps;+const check = steps.find(+ step => step.name === 'Check that the probe theme is current',+);+const scratch = [];+afterAll(() => {+ for (const dir of scratch) fs.rmSync(dir, {recursive: true, force: true});+});++// Runs the step's script with a stub `pnpm` that exits with `code`.+function runStep(code) {+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'probe-check-'));+ scratch.push(dir);+ fs.writeFileSync(+ path.join(dir, 'pnpm'),+ `#!/usr/bin/env bash\necho "pnpm $*"\nexit ${code}\n`,+ {+ mode: 0o755,+ },+ );+ return spawnSync('bash', ['-e', '-c', check.run], {+ encoding: 'utf8',+ env: {...process.env, PATH: `${dir}:${process.env.PATH}`},+ });+}++describe('required lint checks the probe theme', () => {+ it('runs the generator check in full lint, after setup, in the same lanes as ESLint', () => {+ expect(check).toBeDefined();+ expect(check.run).toContain('pnpm -s visual:probe-theme:check');+ expect(check.if).toBe(steps.find(step => step.name === 'Run ESLint').if);+ expect(steps.indexOf(check)).toBeGreaterThan(+ steps.findIndex(step => step.uses === './.github/actions/setup'),+ );+ const scripts = JSON.parse(+ fs.readFileSync(path.join(root, 'package.json'), 'utf8'),+ ).scripts;+ expect(scripts['visual:probe-theme:check']).toBe(+ 'node .github/scripts/visual-gate/generate-probe-theme.mjs --check',+ );+ });++ it('fails with the command that regenerates the theme, and passes when it is current', () => {+ const stale = runStep(1);+ expect(stale.status).toBe(1);+ expect(stale.stdout).toContain('::error title=Probe theme out of date::');+ expect(stale.stdout).toContain(+ 'Run pnpm visual:probe-theme and commit the files it changes in packages/themes/probe/src/.',+ );+ const current = runStep(0);+ expect(current.status).toBe(0);+ expect(current.stdout).not.toContain('::error');+ });++ it('passes on this tree: the committed probe theme matches the component docs', () => {+ const result = spawnSync(+ 'node',+ ['.github/scripts/visual-gate/generate-probe-theme.mjs', '--check'],+ {cwd: root, encoding: 'utf8'},+ );+ expect(result.status, result.stdout + result.stderr).toBe(0);+ });+});diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.ymlindex 9bde85fc99..f70f0ff5d9 100644--- a/.github/workflows/lint.yml+++ b/.github/workflows/lint.yml@@ -238,6 +238,17 @@ jobs:if: steps.scope.outputs.docsite_only != 'true' && steps.scope.outputs.spec_only != 'true'run: pnpm check:repo+ # The probe theme is generated from the component docs, so the visual+ # gate probes every documented theming target and state. A target or+ # state added without regenerating is one the gate never sees.+ - name: Check that the probe theme is current+ if: steps.scope.outputs.docsite_only != 'true' && steps.scope.outputs.spec_only != 'true'+ run: |+ if ! pnpm -s visual:probe-theme:check; then+ echo '::error title=Probe theme out of date::The probe theme or its config is out of date. Run pnpm visual:probe-theme and commit the files it changes in packages/themes/probe/src/.'+ exit 1+ fi+# The CLI README's generated tables (commands, error codes, response# types) ship to consumers. A merge from main can silently drop a# generated row, so the merged result is checked against its sources.