fix(reference): preserve station evidence and rollback schema
This commit is contained in:
@@ -16,6 +16,7 @@ test('reference readers search normalized types and expose group/category/system
|
||||
universe.regions = { '10000001': { region_id: 10000001, name: 'The Forge' } };
|
||||
universe.constellations = { '20000020': { constellation_id: 20000020, name: 'Kimotoro', region_id: 10000001 } };
|
||||
universe.stations = { '60003760': { station_id: 60003760, system_id: 30000142, name: 'Jita IV - Moon 4 - Caldari Navy Assembly Plant', type_id: 587, owner_id: 1000035, position: { x: 1, y: 2, z: 3 } } };
|
||||
(universe.systems as Record<string, Record<string, unknown>>)['30000142'].stations = [60003761];
|
||||
await writeFile(universePath, JSON.stringify(universe));
|
||||
|
||||
const result = await new ReferenceCompiler({ directory, profile: 'fixture', sources: fixtureSources(sources) }).compile();
|
||||
@@ -28,7 +29,13 @@ test('reference readers search normalized types and expose group/category/system
|
||||
expect(await reader.groups({ categoryId: 4 })).toEqual([{ id: 18, categoryId: 4, name: 'Mineral', published: true }]);
|
||||
expect(await reader.regions({ query: 'forge' })).toEqual([{ id: 10000001, name: 'The Forge' }]);
|
||||
expect(await reader.systems({ regionId: 10000001 })).toEqual([{ id: 30000142, name: 'Jita', constellationId: 20000020, regionId: 10000001, x: -129064861735000000, y: 60755306910000000, z: 117469227060000000, securityStatus: 0.9459131360054016, securityClass: null }]);
|
||||
expect(await reader.stations({ systemId: 30000142 })).toEqual([{ id: 60003760, systemId: 30000142, systemName: 'Jita', regionId: 10000001, name: 'Jita IV - Moon 4 - Caldari Navy Assembly Plant', typeId: 587, ownerId: 1000035, x: 1, y: 2, z: 3 }]);
|
||||
const stations = await reader.stations({ systemId: 30000142 });
|
||||
expect(stations).toHaveLength(2);
|
||||
expect(stations).toEqual([
|
||||
{ id: 60003760, systemId: 30000142, systemName: 'Jita', regionId: 10000001, sourceVerified: true, name: 'Jita IV - Moon 4 - Caldari Navy Assembly Plant', typeId: 587, ownerId: 1000035, x: 1, y: 2, z: 3 },
|
||||
{ id: 60003761, systemId: 30000142, systemName: 'Jita', regionId: 10000001, sourceVerified: false, name: null, typeId: null, ownerId: null, x: null, y: null, z: null },
|
||||
]);
|
||||
expect(await reader.stations({ query: 'assembly' })).toEqual([stations[0]]);
|
||||
const pinned = reader.pin();
|
||||
try { expect((await pinned.searchTypesByName('pyerite'))[0]?.id).toBe(35); }
|
||||
finally { pinned.close(); }
|
||||
|
||||
+25
-3
@@ -24,9 +24,9 @@ describe('fixture reference compiler', () => {
|
||||
const resultVersion = result.version;
|
||||
const repository = new SqliteReferenceRepository(join(root, 'reference'));
|
||||
expect(await repository.types([34, 35, 587, 999999])).toEqual([
|
||||
{ id: 34, name: 'Tritanium', categoryId: 4, volume: 0.01 },
|
||||
{ id: 35, name: 'Pyerite', categoryId: 4, volume: 0.01 },
|
||||
{ id: 587, name: 'Rifter', categoryId: 6, volume: 2500 },
|
||||
expect.objectContaining({ id: 34, name: 'Tritanium', categoryId: 4, groupId: 18, volume: 0.01 }),
|
||||
expect.objectContaining({ id: 35, name: 'Pyerite', categoryId: 4, groupId: 18, volume: 0.01 }),
|
||||
expect.objectContaining({ id: 587, name: 'Rifter', categoryId: 6, groupId: 25, volume: 2500 }),
|
||||
]);
|
||||
expect(await repository.version()).toBe(resultVersion);
|
||||
repository.close();
|
||||
@@ -299,6 +299,28 @@ describe('fixture reference compiler', () => {
|
||||
} finally { await rm(root, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
test('rejects a malformed PREVIOUS artifact before rollback', async () => {
|
||||
const { root, sources } = await fixtureDirectory();
|
||||
const directory = join(root, 'reference');
|
||||
try {
|
||||
const first = await new ReferenceCompiler({ directory, profile: 'fixture', sources: fixtureSources(sources) }).compile();
|
||||
expect(first.status).toBe('success');
|
||||
if (first.status !== 'success' || !first.version) throw new Error('initial fixture build did not publish a version');
|
||||
await writeFile(join(sources, 'reference-data.json'), `${await readFile(join(sources, 'reference-data.json'), 'utf8')}\n`);
|
||||
const second = await new ReferenceCompiler({ directory, profile: 'fixture', sources: fixtureSources(sources) }).compile();
|
||||
expect(second.status).toBe('success');
|
||||
if (second.status !== 'success' || !second.version) throw new Error('second fixture build did not publish a version');
|
||||
const manifest = await readReferenceManifest(directory);
|
||||
if (!manifest.previous) throw new Error('fixture build did not retain PREVIOUS');
|
||||
const previousPath = join(directory, 'databases', `${manifest.previous.version}.sqlite`);
|
||||
const malformed = new Database(previousPath);
|
||||
malformed.run('DROP INDEX type_search_normalized_name_idx');
|
||||
malformed.close();
|
||||
await expect(new ReferenceCompiler({ directory, profile: 'fixture', sources: fixtureSources(sources) }).rollback()).rejects.toThrow(/incompatible schema version/);
|
||||
expect((await readReferenceManifest(directory)).active?.version).toBe(second.version);
|
||||
} finally { await rm(root, { recursive: true, force: true }); }
|
||||
});
|
||||
|
||||
test('recovers a validated orphan database after manifest publication crash', async () => {
|
||||
const { root, sources } = await fixtureDirectory();
|
||||
const directory = join(root, 'reference');
|
||||
|
||||
Reference in New Issue
Block a user