fix(map-gateway): unlock warm layers and local station search
This commit is contained in:
@@ -81,6 +81,61 @@ test("bbox fetch uses one cached spatial cell and never exposes upstream payload
|
||||
assert.equal(cached.schemaVersion, "nodedc.map-reference-cell/v1");
|
||||
});
|
||||
|
||||
test("seed and viewed cells resolve locally without waiting for global search", async () => {
|
||||
const cacheDir = await mkdtemp(join(tmpdir(), "nodedc-reference-stations-"));
|
||||
let calls = 0;
|
||||
const source = await createReferenceStationSource({
|
||||
seedFile,
|
||||
cacheDir,
|
||||
cellDegrees: 1,
|
||||
fetchImpl: async () => {
|
||||
calls += 1;
|
||||
return new Response(JSON.stringify({
|
||||
elements: [{
|
||||
type: "node",
|
||||
id: 987654399,
|
||||
lat: 59.93,
|
||||
lon: 30.31,
|
||||
tags: {
|
||||
railway: "station",
|
||||
station: "subway",
|
||||
name: "Petrogradskaya",
|
||||
"name:ru": "Петроградская",
|
||||
"name:en": "Petrogradskaya station",
|
||||
},
|
||||
}],
|
||||
}), { status: 200, headers: { "content-type": "application/json" } });
|
||||
},
|
||||
});
|
||||
|
||||
const seedSnapshot = await source.snapshot();
|
||||
const seedName = seedSnapshot.facts[0].attributes.name;
|
||||
const seedSearch = await source.search({ query: seedName, limit: 8 });
|
||||
assert.equal(seedSearch.complete, true);
|
||||
assert.ok(seedSearch.facts.length > 0);
|
||||
assert.equal(calls, 0);
|
||||
|
||||
await source.snapshot({ bbox: [30, 59, 31, 60] });
|
||||
const viewedSearch = await source.search({ query: "Petrogradskaya station", limit: 8 });
|
||||
assert.equal(viewedSearch.complete, true);
|
||||
assert.equal(viewedSearch.facts[0].sourceId, "osm.node.987654399");
|
||||
assert.equal(calls, 1);
|
||||
|
||||
let restartedCalls = 0;
|
||||
const restarted = await createReferenceStationSource({
|
||||
seedFile,
|
||||
cacheDir,
|
||||
fetchImpl: async () => {
|
||||
restartedCalls += 1;
|
||||
throw new Error("warm viewed cell must not call upstream");
|
||||
},
|
||||
});
|
||||
const restartedSearch = await restarted.search({ query: "Petrogradskaya station", limit: 8 });
|
||||
assert.equal(restartedSearch.complete, true);
|
||||
assert.equal(restartedSearch.facts[0].sourceId, "osm.node.987654399");
|
||||
assert.equal(restartedCalls, 0);
|
||||
});
|
||||
|
||||
test("viewport cells use bounded concurrency and deduplicate inflight fetches", async () => {
|
||||
const cacheDir = await mkdtemp(join(tmpdir(), "nodedc-reference-stations-"));
|
||||
let active = 0;
|
||||
|
||||
Reference in New Issue
Block a user