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:
43
tests/bake-with-lock.test.js
Normal file
43
tests/bake-with-lock.test.js
Normal file
@@ -0,0 +1,43 @@
|
||||
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');
|
||||
|
||||
const FIX = path.resolve(__dirname, 'fixtures/small-fresh');
|
||||
|
||||
test('bake-with-lock: existing IDs preserved, new tile appended', async () => {
|
||||
const outDir = fs.mkdtempSync(path.join(os.tmpdir(), 'atlas-bake-lock-'));
|
||||
try {
|
||||
// Pre-seed lock with grass=5, stone=6 (non-default IDs)
|
||||
fs.writeFileSync(
|
||||
path.join(outDir, 'tiles.atlas.lock.json'),
|
||||
JSON.stringify({
|
||||
atlas_id: 'small_demo',
|
||||
bindings: { grass: 5, stone: 6 },
|
||||
deleted: [],
|
||||
next_id: 7,
|
||||
}, null, 2),
|
||||
);
|
||||
const result = await bake({
|
||||
inDir: FIX,
|
||||
outDir,
|
||||
atlasId: 'small_demo',
|
||||
tileSize: 32,
|
||||
});
|
||||
assert.strictEqual(result.tileCount, 3);
|
||||
|
||||
const lock = JSON.parse(fs.readFileSync(path.join(outDir, 'tiles.atlas.lock.json'), 'utf8'));
|
||||
assert.strictEqual(lock.bindings.grass, 5); // preserved
|
||||
assert.strictEqual(lock.bindings.stone, 6); // preserved
|
||||
assert.strictEqual(lock.bindings.water, 7); // new
|
||||
assert.strictEqual(lock.next_id, 8);
|
||||
|
||||
const atlas = JSON.parse(fs.readFileSync(path.join(outDir, 'tiles.atlas.json'), 'utf8'));
|
||||
const ids = atlas.tiles.map(t => t.id).sort();
|
||||
assert.deepStrictEqual(ids, [5, 6, 7]);
|
||||
} finally {
|
||||
fs.rmSync(outDir, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user