import fs from 'node:fs'; import path from 'node:path'; import { describe, expect, it } from 'vitest'; import { main, type Io } from '../src/cli.js'; import { DEMO_ROOT, fixture } from './helpers.js'; // /setup.md (site/lib/llms.ts) has an agent run these commands, and says what each one does. They // run here, on the demo app as a stranger's app is before anything of onsystem is in it, and as it // is when the user ran `init` by hand and declined the baseline, with no terminal to answer // questions in, as an agent runs them. site/test/setup.test.ts checks that /setup.md names them. /** A copy of the demo app, without its dependencies and with only the onsystem files in `keep`. */ function demo(keep: string[] = []): string { const root = fixture({}); const leftOut = ['onsystem.config.json', 'onsystem.baseline.json'].filter( (f) => !keep.includes(f), ); fs.cpSync(DEMO_ROOT, root, { recursive: true, filter: (src) => { const rel = path.relative(DEMO_ROOT, src); return rel !== 'node_modules' && !leftOut.includes(rel); }, }); return root; } async function run(args: string[], cwd: string) { const out: string[] = []; const io: Io = { cwd, color: false, stdout: (t) => out.push(t), stderr: (t) => out.push(t), }; const code = await main([...args, '--no-cache'], io); return { code, text: out.join('\n') }; } describe('the steps /setup.md gives an agent', () => { it('write the config and the baseline, then pass the check, and keep a config that is there', async () => { const root = demo(); // Step 2: the config, a check of the project by rule, and the baseline. const init = await run(['init', '--yes'], root); expect(init.code).toBe(0); expect(init.text).toMatch( /Dry run of `onsystem check \.`: \d+ errors? and \d+ warnings? .* By rule: /, ); expect(fs.existsSync(path.join(root, 'onsystem.config.json'))).toBe(true); expect(fs.existsSync(path.join(root, 'onsystem.baseline.json'))).toBe(true); // Step 5: the check passes, since what is already there is in the baseline... expect((await run(['check', '.', '--require-design-system'], root)).code).toBe(0); // ...and --ignore-baseline lists each finding with its fix. const all = await run(['check', '.', '--ignore-baseline'], root); expect(all.code).toBe(1); expect(all.text).toContain('Use