'use strict'; const test = require('node:test'); const assert = require('node:assert/strict'); const path = require('node:path'); const { run } = require('../src/cli'); class Sink { constructor() { this.chunks = []; } write(s) { this.chunks.push(s); } get text() { return this.chunks.join(''); } } const FIX_MAP = path.join(__dirname, 'fixtures', 'maps', 'inspect_sample.map.json'); const FIX_ATLAS = path.join(__dirname, 'fixtures', 'atlases'); test('inspect: prints report to stdout, exit 0', () => { const out = new Sink(); const err = new Sink(); const code = run(['inspect', FIX_MAP], { out, err }); assert.equal(code, 0, err.text); assert.match(out.text, /Map: inspect_sample/); assert.match(out.text, /Roof: 4 cells flagged/); }); test('inspect: --atlas-dir enables name resolution', () => { const out = new Sink(); const err = new Sink(); const code = run(['inspect', FIX_MAP, '--atlas-dir', FIX_ATLAS], { out, err }); assert.equal(code, 0); assert.match(out.text, /atlas_a:grass/); }); test('inspect: missing positional arg prints usage, exit 1', () => { const out = new Sink(); const err = new Sink(); const code = run(['inspect'], { out, err }); assert.equal(code, 1); assert.match(err.text, /usage: sporel-mapper inspect/); }); test('inspect: missing map file prints error, exit 1', () => { const out = new Sink(); const err = new Sink(); const code = run(['inspect', '/no/such/map.json'], { out, err }); assert.equal(code, 1); assert.match(err.text, /error: cannot read/); }); test('inspect: invalid JSON prints error, exit 1', () => { const out = new Sink(); const err = new Sink(); // Use a non-JSON file as bogus input const reallyNotJson = path.join(__dirname, '..', 'src', 'cli.js'); const code = run(['inspect', reallyNotJson], { out, err }); assert.equal(code, 1); assert.match(err.text, /error/i); });