fix(analyst): restore exact region matches and remove search rescue

This commit is contained in:
manjunath committed 2026-10-20 06:31:50 +05:30
commit b0e0945360
86 files changed
+18094 -581

No files matched your search

+6 -71
View File
@@ -120,26 +120,6 @@ test('Georgia resolves from camera geography without a geocoder', async () => {
assert.deepEqual(geocodes, []);
});
test('the Alps under the view resolve before an unrelated remote geocode', async () => {
const { resolve, lookups, geocodes } = harness({
lat: -27.96,
lng: 152.2,
label: 'The Alps, Queensland',
name: 'The Alps',
types: ['locality', 'political'],
});
const resolved = await resolve('the Alps', viewerAt(46.5, 10, 248_000));
assert.equal(resolved?.source, 'bundled');
assert.equal(resolved.naturalRegion, 'Alps');
assert.equal(resolved.synthesized, false);
assert.equal(resolved.footprintKind, 'area');
assert.ok(resolved.ring.length >= 8);
assert.deepEqual(resolved.ring[0], resolved.ring.at(-1));
assert.equal(resolved.resolveOutline, undefined);
assert.deepEqual(geocodes, []);
assert.deepEqual(lookups, []);
});
test('Gold Coast in Australia cannot acquire its West African namesake outline', async () => {
for (const types of [['locality', 'political'], ['natural_feature']]) {
const { resolve, geocodes } = harness({
@@ -160,8 +140,8 @@ test('Gold Coast in Australia cannot acquire its West African namesake outline',
}
});
test('unique natural names without a containing view still need a geocoded anchor', async () => {
for (const viewer of [AUSTIN, {}]) {
test('natural annotation outlines require a geocoded anchor', async () => {
for (const viewer of [AUSTIN, {}, viewerAt(46.5, 10, 248_000)]) {
const miss = harness();
assert.equal(await miss.resolve('the Alps', viewer), null);
assert.ok(miss.geocodes.includes('the Alps'));
@@ -197,15 +177,9 @@ test('overlapping natural candidates continue through geocoding without choosing
assert.deepEqual(geocodes, ['Canadian Shield']);
});
test('natural view recovery preserves point, explicit-coordinate, entity and around intent', async () => {
test('geocoded natural outlines respect district and around intent', async () => {
for (const extra of [
{ footprint: false },
{ latitude: 46.5, longitude: 10 },
{ entityKind: 'building' },
{ entityKind: 'compound' },
{ entityKind: 'district' },
{ entityKind: 'street' },
{ entityKind: 'point_feature' },
{ intent: 'around_the_thing' },
]) {
const { resolve, geocodes } = harness({
@@ -217,16 +191,12 @@ test('natural view recovery preserves point, explicit-coordinate, entity and aro
extra.entityKind === 'district' ? ['locality'] : ['natural_feature'],
});
const resolved = await resolve('the Alps', viewerAt(46.5, 10), extra);
assert.notEqual(resolved?.source, 'bundled');
assert.equal(resolved?.naturalRegion, undefined);
if (extra.entityKind === 'district')
assert.ok(geocodes.includes('the Alps'));
if (extra.intent === 'around_the_thing' || extra.entityKind === 'district')
assert.equal((await resolved.resolveOutline())?.naturalRegion, undefined);
assert.ok(geocodes.includes('the Alps'));
assert.equal((await resolved.resolveOutline())?.naturalRegion, undefined);
}
});
test('cancellation while a natural view lookup is pending cannot publish its outline', async () => {
test('cancellation while a bundled admin lookup is pending cannot publish an annotation', async () => {
const controller = new AbortController();
const { resolve, geocodes } = harness();
const pending = resolve('the Alps', viewerAt(46.5, 10), {
@@ -351,38 +321,3 @@ test('the engine keeps every part on the mark, drawn at once or upgraded', async
);
engine.destroy();
});
test('cancellation after the admin miss rejects the resumed natural view lookup', async () => {
const controller = new AbortController();
const signal = controller.signal;
const throwIfAborted = signal.throwIfAborted.bind(signal);
const checkpoints = [];
let abortCheckpoint = null;
// This exact path has entry, post-admin-miss and post-natural checkpoints.
// Queue at the known post-admin checkpoint: after this callback returns,
// the real natural lookup runs synchronously to its await before the queued
// abort executes. No timeout or guessed number of promise turns is used.
Object.defineProperty(signal, 'throwIfAborted', {
value() {
checkpoints.push(signal.aborted);
throwIfAborted();
if (checkpoints.length === 2) {
queueMicrotask(() => {
abortCheckpoint = checkpoints.length;
controller.abort();
});
}
},
});
const { resolve, lookups, geocodes } = harness();
const pending = resolve('the Alps', viewerAt(46.5, 10), { signal });
await assert.rejects(pending, { name: 'AbortError' });
assert.equal(
abortCheckpoint,
2,
'abort follows admin miss, before natural resume',
);
assert.deepEqual(checkpoints, [false, false, true]);
assert.deepEqual(lookups, []);
assert.deepEqual(geocodes, []);
});
-47
View File
@@ -202,22 +202,6 @@ export function createAnnotationResolver({
);
signal?.throwIfAborted();
if (admin) return bundledAdminTarget(viewer, admin, trace.query);
// A unique pack name can still name an unrelated modern place. Recover
// natural outlines only from a containing view, including unique names.
if (
center &&
entityKind !== 'district' &&
intent !== 'around_the_thing'
) {
const natural = await lookupNaturalRegionOutline(
trace.query,
center.lat,
center.lon,
).catch(() => null);
signal?.throwIfAborted();
if (natural) return bundledNaturalTarget(viewer, natural, trace.query);
}
}
if (!Number.isFinite(lat) || !Number.isFinite(lon)) {
@@ -856,37 +840,6 @@ export function createAnnotationResolver({
};
}
/** A complete annotation target for a natural ring containing the view. */
function bundledNaturalTarget(viewer, natural, query) {
const ring = closeRing([...natural.ring]);
const centroid = ringCentroid(ring);
if (!centroid) return null;
registerDynamicCredit(viewer, NATURAL_EARTH_CREDIT);
const lons = ring.map(([lon]) => lon);
const lats = ring.map(([, lat]) => lat);
console.log(
`[Resolver] "${query}": bundled ${natural.kind} "${natural.name}" ` +
'(natural-earth, view-contained) → FINAL source=bundled',
);
return {
lon: centroid.lon,
lat: centroid.lat,
height: sampleGroundHeight(viewer, centroid.lon, centroid.lat),
ring,
footprintKind: 'area',
buildingHeight: null,
label: natural.name,
source: 'bundled',
synthesized: false,
outlineUnavailable: false,
naturalRegion: natural.name,
viewport: {
low: { latitude: Math.min(...lats), longitude: Math.min(...lons) },
high: { latitude: Math.max(...lats), longitude: Math.max(...lons) },
},
};
}
/**
* Synthesize an approximate circular AREA by buffering a label point. Returns a ring
* marked `synthesized:true` so the renderers draw it "approximate" (dashed/feathered),