Wire bake orchestrator and CLI

Connects scan + lock + pack + write into the full pipeline. CLI entry
parses args, dispatches to bake(), prints summary or error. Five
integration tests cover fresh bake, lock-aware ID preservation,
deleted-tile tracking, oversize hard-fail, and bit-identical
determinism across re-bakes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Axel Meyer
2026-05-21 22:48:08 +02:00
parent 589bdaef10
commit dea2d8fb88
7 changed files with 309 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
const { test } = require('node:test');
const assert = require('node:assert');
const path = require('node:path');
const fs = require('node:fs');
const os = require('node:os');
const { bake } = require('../src/bake');
test('bake-deleted: missing source moves ID to deleted[]', async () => {
const srcDir = fs.mkdtempSync(path.join(os.tmpdir(), 'atlas-src-'));
const outDir = fs.mkdtempSync(path.join(os.tmpdir(), 'atlas-out-'));
try {
// Copy only grass + stone from fixture (omit water)
const FIX = path.resolve(__dirname, 'fixtures/small-fresh');
fs.copyFileSync(path.join(FIX, 'grass_diffuse.png'), path.join(srcDir, 'grass_diffuse.png'));
fs.copyFileSync(path.join(FIX, 'stone_diffuse.png'), path.join(srcDir, 'stone_diffuse.png'));
// Pre-existing lock has all 3 names
fs.writeFileSync(
path.join(outDir, 'tiles.atlas.lock.json'),
JSON.stringify({
atlas_id: 'small_demo',
bindings: { grass: 1, stone: 2, water: 3 },
deleted: [],
next_id: 4,
}, null, 2),
);
await bake({ inDir: srcDir, outDir, atlasId: 'small_demo', tileSize: 32 });
const lock = JSON.parse(fs.readFileSync(path.join(outDir, 'tiles.atlas.lock.json'), 'utf8'));
assert.strictEqual(lock.bindings.water, undefined);
assert.deepStrictEqual(lock.deleted, [3]);
assert.strictEqual(lock.next_id, 4); // not advanced
} finally {
fs.rmSync(srcDir, { recursive: true, force: true });
fs.rmSync(outDir, { recursive: true, force: true });
}
});