feat(reference): add indexed readers and station source

This commit is contained in:
jb
2026-09-19 09:53:46 -04:00
parent 9ddd12fbc5
commit f7b604f40f
10 changed files with 429 additions and 25 deletions
+10
View File
@@ -21,6 +21,7 @@ function zipFixture(options: { duplicateSystems?: boolean; duplicateSystemField?
'mapConstellations.jsonl': '{"_key":2,"name":{"en":"Constellation"},"regionID":1}\n',
'mapSolarSystems.jsonl': options.duplicateSystemField ? '{"_key":3,"_key":3,"name":{"en":"System"},"constellationID":2,"position":{"x":1,"y":2,"z":3},"securityStatus":0.5}\n' : '{"_key":3,"name":{"en":"System"},"constellationID":2,"position":{"x":1,"y":2,"z":3},"securityStatus":0.5}\n',
'mapStargates.jsonl': '{"_key":4,"solarSystemID":3,"destination":{"solarSystemID":3,"stargateID":4}}\n',
'npcStations.jsonl': '{"_key":60000001,"solarSystemID":3,"typeID":1,"ownerID":2,"position":{"x":1,"y":2,"z":3}}\n',
};
const records = Object.entries(rows).map(([name, value]) => ({ name, data: encoder.encode(options.duplicateSystems && name === 'mapSolarSystems.jsonl' ? value + value : value) }));
const locals: Uint8Array[] = []; const centrals: Uint8Array[] = []; let offset = 0;
@@ -58,6 +59,15 @@ describe('production archive boundaries', () => {
await expect(collectTarMembers(chunks(oneZero), 'test', new Set(['meta.json']), new Set(['meta.json']))).rejects.toThrow(/two-block/);
});
test('imports verified NPC station records when the CCP SDE member is present', async () => {
const directory = await mkdtemp(join(tmpdir(), 'eden-reference-stations-'));
try {
const path = join(directory, 'stations.zip'); await writeFile(path, zipFixture());
const universe = await ccpUniverse(path);
expect(universe.stations).toEqual({ '60000001': { station_id: 60000001, system_id: 3, type_id: 1, owner_id: 2, position: { x: 1, y: 2, z: 3 } } });
} finally { await rm(directory, { recursive: true, force: true }); }
});
test('rejects duplicate CCP keys and ZIP CRC/size mismatches', async () => {
const directory = await mkdtemp(join(tmpdir(), 'eden-reference-zip-'));
try {
+66
View File
@@ -0,0 +1,66 @@
import { expect, test } from 'bun:test';
import { cp, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises';
import { join } from 'node:path';
import { tmpdir } from 'node:os';
import { ReferenceCompiler, SqliteReferenceRepository } from '../src/lib/server/reference';
import { fixtureSources } from '../src/lib/server/reference/sources';
test('reference readers search normalized types and expose group/category/system/region/station joins', async () => {
const root = await mkdtemp(join(tmpdir(), 'eden-reference-readers-'));
const sources = join(root, 'fixtures');
const directory = join(root, 'reference');
try {
await cp('fixtures/reference', sources, { recursive: true });
const universePath = join(sources, 'systems.json');
const universe = JSON.parse(await readFile(universePath, 'utf8')) as Record<string, unknown>;
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 } } };
await writeFile(universePath, JSON.stringify(universe));
const result = await new ReferenceCompiler({ directory, profile: 'fixture', sources: fixtureSources(sources) }).compile();
expect(result.status).toBe('success');
const reader = new SqliteReferenceRepository(directory, 'fixture');
try {
expect(await reader.searchTypesByName(' trit ')).toEqual([{ id: 34, name: 'Tritanium', categoryId: 4, groupId: 18, published: true, volume: 0.01 }]);
expect(await reader.searchTypes({ query: 'RIF', categoryId: 6 })).toEqual([{ id: 587, name: 'Rifter', categoryId: 6, groupId: 25, published: true, volume: 2500 }]);
expect(await reader.categories([4])).toEqual([{ id: 4, name: 'Material', published: true }]);
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 pinned = reader.pin();
try { expect((await pinned.searchTypesByName('pyerite'))[0]?.id).toBe(35); }
finally { pinned.close(); }
} finally { reader.close(); }
} finally { await rm(root, { recursive: true, force: true }); }
});
test('readers reject empty type searches and preserve unknown station metadata', async () => {
const root = await mkdtemp(join(tmpdir(), 'eden-reference-readers-'));
try {
const result = await new ReferenceCompiler({ directory: join(root, 'reference'), profile: 'fixture' }).compile();
expect(result.status).toBe('success');
const reader = new SqliteReferenceRepository(join(root, 'reference'), 'fixture');
try {
await expect(reader.searchTypes({ query: ' ' })).rejects.toThrow('must contain letters or numbers');
expect(await reader.stations([999])).toEqual([]);
await expect(reader.categories(Array.from({ length: 501 }, (_, index) => index))).rejects.toThrow('selection exceeds 500 IDs');
} finally { reader.close(); }
} finally { await rm(root, { recursive: true, force: true }); }
});
test('unknown system station IDs cannot satisfy verified production station coverage', async () => {
const root = await mkdtemp(join(tmpdir(), 'eden-reference-station-gate-'));
const sources = join(root, 'fixtures');
try {
await cp('fixtures/reference', sources, { recursive: true });
const universePath = join(sources, 'systems.json');
const universe = JSON.parse(await readFile(universePath, 'utf8')) as { systems: Record<string, { stations?: number[] }> };
universe.systems['30000142'].stations = [60003760];
await writeFile(universePath, JSON.stringify(universe));
const result = await new ReferenceCompiler({ directory: join(root, 'reference'), profile: 'fixture', thresholds: { stationsMinimum: 1 }, sources: fixtureSources(sources) }).compile();
expect(result.status).toBe('failed');
expect(result.error).toContain('verified stations');
} finally { await rm(root, { recursive: true, force: true }); }
});