/** * scaffold-tests-from-ac — real entry-point run: JSON on stdout ALWAYS and * `errors[]` (audit 2026-09-24, D-WARN-07 / R5). Before: the Phase 4 gate read * `success` from a stdout that carried a human summary unless --json, and a * missing --spec answered on stderr only. */ import { describe, it, expect, beforeAll, afterAll } from 'vitest' import { mkdirSync, mkdtempSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' import { dirname, join, resolve } from 'node:path' import { fileURLToPath } from 'node:url' import { runCli } from '../../../../../lib/__tests__/helpers/run-cli.js' const INDEX = resolve(dirname(fileURLToPath(import.meta.url)), '../index.ts') let root: string beforeAll(() => { root = mkdtempSync(join(tmpdir(), 'ss-fromac-entry-')) mkdirSync(join(root, 'ba', 'CRM', 'PIPELINE'), { recursive: true }) mkdirSync(join(root, 'app'), { recursive: true }) }) afterAll(() => rmSync(root, { recursive: true, force: true })) describe('scaffold-tests-from-ac entry', () => { it('no --spec: JSON envelope with errors[], exit 2 — without --json', () => { const r = runCli(INDEX, []) expect(r.envelope, r.stderr).not.toBeNull() expect(r.status).toBe(2) expect(r.envelope).toMatchObject({ success: false, errors: ['--spec is required'], ucsScanned: 0, filesCreated: [] }) expect(r.envelope).not.toHaveProperty('error') }) it('a valid spec on a module with no use-case.md: success:true JSON by default, exit 0', () => { const spec = { moduleDir: join(root, 'ba/CRM/PIPELINE'), projectPath: join(root, 'app'), appCode: 'crm', module: 'pipeline', dryRun: true } const r = runCli(INDEX, ['--spec', JSON.stringify(spec)]) expect(r.envelope, r.stderr).not.toBeNull() expect(r.status).toBe(0) expect(r.envelope).toMatchObject({ success: true, errors: [], ucsScanned: 0, acsParsed: 0, factsEmitted: 0 }) }) })