/** * lib/cli-args — an unknown flag / missing mandatory value never leaves stdout * EMPTY (audit 2026-09-24, C-WARN-11 / B-WARN-09): a parseArgs CLI and a * commander CLI both answer a `success:false` envelope naming what they accept, * exit 1; `--help` still exits 0. Real entry-point runs. */ import { describe, it, expect } from 'vitest' import { dirname, resolve } from 'node:path' import { fileURLToPath } from 'node:url' import { runCli } from './helpers/run-cli.js' const HERE = dirname(fileURLToPath(import.meta.url)) const PARSEARGS_CLI = resolve(HERE, '../../development/backend/data-layer/cli/scaffold-migration/index.ts') const COMMANDER_CLI = resolve(HERE, '../../development/audit-dev-data/cli/audit-dev-data/index.ts') describe('parseArgsOrFail — node:util.parseArgs CLIs', () => { it('an unknown option answers an envelope on stdout (exit 1), naming the accepted options', () => { const r = runCli(PARSEARGS_CLI, ['--bogus']) expect(r.envelope, `stdout was: ${r.stdout.slice(0, 200)} / stderr: ${r.stderr.slice(0, 200)}`).not.toBeNull() expect(r.status).toBe(1) expect(r.envelope.success).toBe(false) expect(r.envelope.command).toBe('scaffold-migration') expect(r.envelope.errors.join('\n')).toMatch(/--bogus/) expect(r.envelope.errors.join('\n')).toMatch(/Accepted options: .*--spec/) }) }) describe('withEnvelopeExit — commander CLIs', () => { it('an unknown option answers an envelope on stdout (exit 1)', () => { // Every mandatory option supplied, so commander's complaint is the unknown one. const r = runCli(COMMANDER_CLI, ['--project-path', HERE, '--module-path', HERE, '--module-code', 'm', '--app-code', 'a', '--bogus']) expect(r.envelope, `stdout was: ${r.stdout.slice(0, 200)}`).not.toBeNull() expect(r.status).toBe(1) expect(r.envelope).toMatchObject({ success: false, command: 'audit-dev-data' }) expect(r.envelope.errors.join('\n')).toMatch(/unknown option '--bogus'/) }) it('a missing mandatory option answers an envelope on stdout (exit 1)', () => { const r = runCli(COMMANDER_CLI, []) expect(r.envelope, `stdout was: ${r.stdout.slice(0, 200)}`).not.toBeNull() expect(r.status).toBe(1) expect(r.envelope.success).toBe(false) expect(r.envelope.errors.join('\n')).toMatch(/required option/) }) it('--help still exits 0', () => { const r = runCli(COMMANDER_CLI, ['--help']) expect(r.status).toBe(0) expect(r.stdout).toMatch(/--project-path/) }) })