mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-16 16:22:20 +00:00
Reconcile origin #835 with merged voice core #837. Classify pointer crop separately from full screenshots, retain existing session/camera freshness guards, and log bounded static reason codes. Add dispatch regressions and changelog fragment. Credit: asturksever identified the incompatibility; preserve #837 authorship.
182 lines
5.0 KiB
JavaScript
182 lines
5.0 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import { RealtimeViewport, viewportContextDecision } from './realtimeViewport.js';
|
|
|
|
const localContext = (overrides = {}) => ({
|
|
action: 'get_entity_context',
|
|
scene: { basemap: { viewScale: 'local' } },
|
|
...overrides,
|
|
});
|
|
|
|
test('viewport context reasons preserve the existing escalation gate', () => {
|
|
assert.deepEqual(
|
|
viewportContextDecision({ action: 'get_current_view_state' }),
|
|
{
|
|
send: false,
|
|
reason: 'not-entity-context',
|
|
},
|
|
);
|
|
assert.deepEqual(
|
|
viewportContextDecision(localContext(), { channelOpen: false }),
|
|
{ send: false, reason: 'channel-closed' },
|
|
);
|
|
assert.deepEqual(
|
|
viewportContextDecision({
|
|
action: 'get_entity_context',
|
|
scene: { basemap: { viewScale: 'regional' } },
|
|
}),
|
|
{
|
|
send: false,
|
|
reason: 'view-scale-not-local',
|
|
viewScale: 'regional',
|
|
},
|
|
);
|
|
assert.deepEqual(
|
|
viewportContextDecision(
|
|
localContext({
|
|
selected: {
|
|
id: 'earthquake:1',
|
|
layerId: 'earthquakes',
|
|
},
|
|
}),
|
|
),
|
|
{
|
|
send: false,
|
|
reason: 'structured-identity-sufficient',
|
|
viewScale: 'local',
|
|
},
|
|
);
|
|
assert.deepEqual(viewportContextDecision(localContext()), {
|
|
send: true,
|
|
kind: 'viewport',
|
|
reason: 'structured-identity-missing',
|
|
viewScale: 'local',
|
|
});
|
|
});
|
|
|
|
test('nearby structured place identity avoids visual escalation too', () => {
|
|
assert.deepEqual(
|
|
viewportContextDecision(
|
|
localContext({
|
|
scene: {
|
|
basemap: {
|
|
viewScale: 'local',
|
|
nearbyPlaces: [{ name: 'Austin' }],
|
|
},
|
|
},
|
|
}),
|
|
),
|
|
{
|
|
send: false,
|
|
reason: 'structured-identity-sufficient',
|
|
viewScale: 'local',
|
|
},
|
|
);
|
|
});
|
|
|
|
test('pointer ground selects the #837 crop path, not a full viewport', () => {
|
|
const pointerContext = localContext({
|
|
scope: 'pointer',
|
|
pointer: { target: 'ground' },
|
|
scene: { basemap: { viewScale: 'city' } },
|
|
});
|
|
assert.deepEqual(viewportContextDecision(pointerContext), {
|
|
send: true,
|
|
kind: 'crop',
|
|
reason: 'pointer-ground-crop',
|
|
viewScale: 'city',
|
|
});
|
|
assert.deepEqual(
|
|
viewportContextDecision({
|
|
...pointerContext,
|
|
scene: { basemap: { viewScale: 'global' } },
|
|
}),
|
|
{
|
|
send: false,
|
|
reason: 'pointer-scale-not-useful',
|
|
viewScale: 'global',
|
|
},
|
|
);
|
|
assert.deepEqual(
|
|
viewportContextDecision({ ...pointerContext, selected: { id: 'building' } }),
|
|
{
|
|
send: false,
|
|
reason: 'pointer-identity-present',
|
|
viewScale: 'city',
|
|
},
|
|
);
|
|
assert.deepEqual(
|
|
viewportContextDecision({ ...pointerContext, pointer: null }),
|
|
{ send: false, reason: 'pointer-missing', viewScale: 'city' },
|
|
);
|
|
});
|
|
|
|
test('runtime dispatch preserves pointer crop and full image separation', async () => {
|
|
const channel = { readyState: 'open' };
|
|
const pointer = { fresh: true, target: 'ground' };
|
|
const calls = [];
|
|
const viewport = new RealtimeViewport({
|
|
readChannel: () => channel,
|
|
readPointer: () => pointer,
|
|
operations: {
|
|
debugLog: (event, detail) => calls.push({ event, detail }),
|
|
},
|
|
capture: async () => 'unused',
|
|
});
|
|
viewport.sendPointerCrop = async (snapshot, options) => {
|
|
calls.push({ kind: 'crop', snapshot, options });
|
|
return true;
|
|
};
|
|
viewport.sendRetainedImage = async () => {
|
|
calls.push({ kind: 'viewport' });
|
|
return true;
|
|
};
|
|
|
|
assert.equal(
|
|
await viewport.sendVisualContextIfUseful(
|
|
localContext({
|
|
scope: 'pointer',
|
|
pointer: { target: 'ground' },
|
|
scene: { basemap: { viewScale: 'city' } },
|
|
}),
|
|
),
|
|
true,
|
|
);
|
|
assert.equal(calls.filter((call) => call.kind === 'crop').length, 1);
|
|
assert.deepEqual(calls.find((call) => call.kind === 'crop').snapshot, pointer);
|
|
assert.equal(calls.find((call) => call.kind === 'crop').options.viewScale, 'city');
|
|
assert.equal(calls.filter((call) => call.kind === 'viewport').length, 0);
|
|
|
|
assert.equal(await viewport.sendVisualContextIfUseful(localContext()), true);
|
|
assert.equal(calls.filter((call) => call.kind === 'viewport').length, 1);
|
|
assert.equal(
|
|
await viewport.sendVisualContextIfUseful(
|
|
localContext({ selected: { id: 'existing' } }),
|
|
),
|
|
false,
|
|
);
|
|
assert.equal(calls.filter((call) => call.kind === 'viewport').length, 1);
|
|
assert.ok(calls.some((call) =>
|
|
call.event === 'viewport_context.decision' &&
|
|
call.detail.reason === 'pointer-ground-crop'
|
|
));
|
|
});
|
|
|
|
test('closed channel never captures pointer or full viewport', async () => {
|
|
const viewport = new RealtimeViewport({
|
|
readChannel: () => ({ readyState: 'closed' }),
|
|
readPointer: () => {
|
|
throw new Error('should not inspect pointer when channel is closed');
|
|
},
|
|
operations: {},
|
|
});
|
|
assert.equal(
|
|
await viewport.sendVisualContextIfUseful(
|
|
localContext({ scope: 'pointer', pointer: { target: 'ground' } }),
|
|
),
|
|
false,
|
|
);
|
|
assert.equal(await viewport.sendVisualContextIfUseful(localContext()), false);
|
|
});
|