fix: wait briefly for installation names before answering

Installation tile results can arrive before the name pack, and the tool
answered with generic names such as "Military area" where a moment later
it would say "Camp Mabry". It now waits up to five seconds for the named
result and says when names are still loading.
This commit is contained in:
Sameh Khamis committed 2026-10-02 15:21:36 -07:00
1 parent 9e4cc9095b
commit 13f8fa7c8e
2 files changed
+84 -2

No files matched your search

+38
View File
@@ -742,3 +742,41 @@ test('stale weather and partial fire data reach answers and the HUD caption', as
],
);
});
test('installation names wait for the name pack, briefly', async (t) => {
const site = (name) => ({
id: 'osm:9',
kind: 'installation',
name,
latitude: 30.31,
longitude: -97.76,
});
const source = (enrichment) => ({
getMappedSites: async () => ({
source: 'OpenStreetMap tiles',
records: [site('Military area')],
enrichment,
}),
});
const area = { lat: 30.31, lon: -97.76, radius_km: 5 };
const named = await catalogWith({
installations: source(
Promise.resolve({
source: 'OpenStreetMap tiles',
records: [site('Camp Mabry')],
}),
),
}).call('find_military_installations', { area });
assert.equal(named.data.rows[0].name, 'Camp Mabry');
assert.equal(named.data.names_pending, false);
t.mock.timers.enable({ apis: ['setTimeout'] });
const pending = catalogWith({
installations: source(new Promise(() => {})),
}).call('find_military_installations', { area });
await new Promise((resolve) => setImmediate(resolve));
t.mock.timers.tick(5000);
const slow = await pending;
assert.equal(slow.data.rows[0].name, 'Military area');
assert.equal(slow.data.names_pending, true);
assert.match(slow.summary, /site names are still loading\)\.$/);
});