Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

ci: add CLI smoke test (#883)

Joey352718399b45
diff --git a/.github/scripts/cli-smoke-test.mjs b/.github/scripts/cli-smoke-test.mjs
new file mode 100644
index 0000000000..4f2c2b78d8
--- /dev/null
+++ b/.github/scripts/cli-smoke-test.mjs
@@ -0,0 +1,166 @@
+#!/usr/bin/env node
+/**
+ * CLI smoke test — auto-discovers every command and checks for output + clean exit.
+ *
+ * Nothing is hardcoded. Components are discovered from `xds component --list`,
+ * doc topics from `xds docs`, and detail levels from `xds --help`.
+ *
+ * Catches regressions like:
+ * - xds component <name> crashing on bad imports
+ * - xds docs returning empty content
+ * - any command exiting non-zero
+ *
+ * Usage:
+ * node .github/scripts/cli-smoke-test.mjs
+ *
+ * Exit code 0 = all commands passed
+ * Exit code 1 = one or more commands failed
+ */
+
+import {spawnSync} from 'node:child_process';
+import {fileURLToPath} from 'node:url';
+import * as path from 'node:path';
+
+const __dirname = path.dirname(fileURLToPath(import.meta.url));
+const ROOT = path.resolve(__dirname, '../..');
+const CLI = path.join(ROOT, 'packages/cli/bin/xds.mjs');
+
+let passed = 0;
+let failed = 0;
+const failures = [];
+
+function run(args) {
+ const result = spawnSync(process.execPath, [CLI, ...args], {
+ cwd: ROOT,
+ encoding: 'utf8',
+ timeout: 30_000,
+ });
+ return {
+ stdout: result.stdout ?? '',
+ stderr: result.stderr ?? '',
+ status: result.status ?? 1,
+ timedOut: result.signal === 'SIGTERM',
+ };
+}
+
+function check(label, args, {minLength = 10} = {}) {
+ const {stdout, stderr, status, timedOut} = run(args);
+ const output = (stdout + stderr).trim();
+
+ let reason = null;
+ if (timedOut) reason = 'timed out';
+ else if (status !== 0) reason = `exit ${status}`;
+ else if (output.length < minLength) reason = `output too short (${output.length} chars, need ${minLength})`;
+
+ if (reason) {
+ console.log(` FAIL ${label} (${reason})`);
+ if (stderr.trim()) {
+ console.log(` ${stderr.trim().split('\n')[0]}`);
+ }
+ failures.push({label, reason});
+ failed++;
+ } else {
+ console.log(` ok ${label}`);
+ passed++;
+ }
+}
+
+// ---------------------------------------------------------------------------
+// 1. Discover detail levels from --help
+// ---------------------------------------------------------------------------
+const helpOutput = run(['--help']).stdout;
+const detailMatch = helpOutput.match(/full, compact, brief|full\|compact\|brief/);
+const DETAIL_LEVELS = detailMatch
+ ? detailMatch[0].split(/[,|]\s*/).map(s => s.trim())
+ : ['brief', 'compact', 'full'];
+
+console.log(`detail levels: ${DETAIL_LEVELS.join(', ')}`);
+
+// ---------------------------------------------------------------------------
+// 2. Discover components from xds component --list
+// ---------------------------------------------------------------------------
+console.log('\ncomponent listing');
+check('xds component --list', ['component', '--list']);
+
+const listResult = run(['component', '--list']);
+const componentNames = listResult.stdout
+ .split('\n')
+ .filter(line => /^\s+[A-Z]/.test(line))
+ .map(line => line.trim());
+
+console.log(`discovered ${componentNames.length} components`);
+
+if (componentNames.length === 0) {
+ console.log('\nFATAL: no components discovered from --list output. Aborting.');
+ process.exit(1);
+}
+
+// ---------------------------------------------------------------------------
+// 3. Discover categories from the --list output
+// ---------------------------------------------------------------------------
+const categories = listResult.stdout
+ .split('\n')
+ .filter(line => /^[A-Z].*:$/.test(line))
+ .map(line => line.replace(/:$/, ''));
+
+console.log(`discovered ${categories.length} categories: ${categories.join(', ')}`);
+
+// ---------------------------------------------------------------------------
+// 4. Discover doc topics from xds docs
+// ---------------------------------------------------------------------------
+const docsResult = run(['docs']);
+const docTopics = docsResult.stdout
+ .split('\n')
+ .filter(line => /^\s{2}\w+\s{2,}/.test(line))
+ .map(line => line.trim().split(/\s{2,}/)[0]);
+
+console.log(`discovered ${docTopics.length} doc topics: ${docTopics.join(', ')}`);
+
+// ---------------------------------------------------------------------------
+// 5. Run all checks
+// ---------------------------------------------------------------------------
+
+// component --list with each detail level
+for (const detail of DETAIL_LEVELS) {
+ check(`xds component --list --detail ${detail}`, ['component', '--list', '--detail', detail]);
+}
+
+// component --category for each category
+console.log(`\ncomponent --category (${categories.length} categories)`);
+for (const cat of categories) {
+ check(`xds component --category ${cat}`, ['component', '--category', cat]);
+}
+
+// component docs: every component x every detail level
+console.log(`\ncomponent docs (${componentNames.length} components x ${DETAIL_LEVELS.length} detail levels)`);
+for (const name of componentNames) {
+ for (const detail of DETAIL_LEVELS) {
+ check(`xds component ${name} --detail ${detail}`, ['component', name, '--detail', detail]);
+ }
+}
+
+// component --props for every component
+console.log(`\ncomponent --props (${componentNames.length} components)`);
+for (const name of componentNames) {
+ check(`xds component ${name} --props`, ['component', name, '--props']);
+}
+
+// docs for each topic
+console.log('\ndocs');
+check('xds docs (no args)', ['docs']);
+for (const topic of docTopics) {
+ check(`xds docs ${topic}`, ['docs', topic]);
+}
+
+// ---------------------------------------------------------------------------
+// 6. Summary
+// ---------------------------------------------------------------------------
+console.log(`\n${passed + failed} checks total: ${passed} passed, ${failed} failed`);
+
+if (failed > 0) {
+ console.log('\nFailed commands:');
+ for (const f of failures) {
+ console.log(` - ${f.label}: ${f.reason}`);
+ }
+ process.exit(1);
+}
diff --git a/.github/workflows/cli-smoke-test.yml b/.github/workflows/cli-smoke-test.yml
new file mode 100644
index 0000000000..8e44365f26
--- /dev/null
+++ b/.github/workflows/cli-smoke-test.yml
@@ -0,0 +1,31 @@
+# CLI smoke test — runs every xds command to catch regressions
+# Auto-discovers components and doc topics, nothing hardcoded.
+name: CLI Smoke Test
+
+on:
+ pull_request:
+ branches: ["main"]
+ merge_group:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: "cli-smoke-${{ github.event.merge_group.head_sha || github.head_ref }}"
+ cancel-in-progress: true
+
+jobs:
+ smoke-test:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v4
+
+ - uses: actions/setup-node@v4
+ with:
+ node-version: 20
+ cache: "yarn"
+
+ - run: yarn install --frozen-lockfile
+
+ - name: CLI smoke test
+ run: node .github/scripts/cli-smoke-test.mjs