mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-22 03:02:20 +00:00
fix(street-level): KartaView PR review — context loss mid-load, chunked reads, source switches, a11y
From the IC8 review of #1121 (2 P2, 7 P3; each with a test that fails on the old code): P2 - A WebGL context lost while a newer panorama loaded left a black viewer and a 'successful' open: the panorama now builds on the new canvas (or falls back to its front view). - The streaming body read every real answer takes was tested with one chunk only: answers split mid-character are reassembled; the shared test fake now streams, so every source test runs the production path. P3 - Lighting another source by its chip (params) now stops a running lookup and clears its spinner and error, as setProviderEnabled did; a restore that changes nothing leaves them alone. - Panoramas decode off the main thread (ImageBitmap, RGBA upload: ~90 ms → ~15 ms at 4,096 px on a phone-class CPU) and are 2,048 px docked, 4,096 once the viewer grows; a closed viewer keeps a 1×1 texture. - The lit KARTAVIEW chip label is #8f8aff (~6:1; #635bff was 3.7:1). - The viewer's keyboard focus ring is drawn above the photo. - Tests: a second context loss and a drag on the new canvas; the look direction kept across a loss; a page's 30 s first try. - The browser gate loses a real WebGL context in the 360° step and checks the 429 lookup was asked again (the fixture counter is reset first). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
97a1a667de
commit
c99eb93174
12 files changed
+512
-26
No files matched your search
@@ -12,14 +12,37 @@ import {
|
||||
PHOTO_API_RETRIES,
|
||||
PHOTO_API_FIRST_TIMEOUT_MS,
|
||||
PHOTO_API_TIMEOUT_MS,
|
||||
PAGE_TIMEOUT_MS,
|
||||
TILE_CONCURRENCY,
|
||||
} from './policy.js';
|
||||
|
||||
/** A body streamed as browsers do, in `size`-byte chunks. */
|
||||
function streamed(text, size = 16_384) {
|
||||
const bytes = new TextEncoder().encode(text);
|
||||
let at = 0;
|
||||
return {
|
||||
getReader: () => ({
|
||||
read: async () => {
|
||||
if (at >= bytes.length) return { done: true };
|
||||
const value = bytes.slice(at, at + size);
|
||||
at += size;
|
||||
return { done: false, value };
|
||||
},
|
||||
cancel: async () => {},
|
||||
}),
|
||||
};
|
||||
}
|
||||
|
||||
// A 200 as browsers deliver it: streamed, so the code under test reads it
|
||||
// the way it does in production (`json` is there only to fail loudly).
|
||||
const ok = (body) => ({
|
||||
ok: true,
|
||||
status: 200,
|
||||
headers: new Map(),
|
||||
json: async () => body,
|
||||
body: streamed(JSON.stringify(body)),
|
||||
json: async () => {
|
||||
throw new Error('a browser answer is read from its stream');
|
||||
},
|
||||
});
|
||||
const status = (code, headers = new Map()) => ({
|
||||
ok: false,
|
||||
@@ -358,7 +381,7 @@ const flush = () => new Promise((resolve) => setImmediate(resolve));
|
||||
* Run `call` on the mocked clock in 100 ms steps until it settles (60 s at
|
||||
* most). `stamp()` reads the clock, for a fetch to record when it was asked.
|
||||
*/
|
||||
async function onMockClock(t, call) {
|
||||
async function onMockClock(t, call, { until = 60_000 } = {}) {
|
||||
let now = 0;
|
||||
const stamp = () => now;
|
||||
let outcome = null;
|
||||
@@ -367,7 +390,7 @@ async function onMockClock(t, call) {
|
||||
(value) => (outcome = { value, at: now }),
|
||||
(error) => (outcome = { error, at: now }),
|
||||
);
|
||||
while (!outcome && now < 60_000) {
|
||||
while (!outcome && now < until) {
|
||||
await flush();
|
||||
if (outcome) break;
|
||||
t.mock.timers.tick(100);
|
||||
@@ -486,3 +509,46 @@ test('a chunked answer with no length is cut off once it grows past the cap', as
|
||||
});
|
||||
assert.deepEqual(await small.getTile({ x: 1, y: 2, z: 13 }), { lines: [] });
|
||||
});
|
||||
|
||||
test('a chunked answer split mid-character is reassembled in order', async () => {
|
||||
const payload = {
|
||||
lines: [
|
||||
{
|
||||
track: [{ lat: '1', lng: '2' }],
|
||||
name: 'Strada Memorandumului — Cluj-Napoca 😀',
|
||||
},
|
||||
],
|
||||
note: 'ăîşţ'.repeat(200),
|
||||
};
|
||||
const source = createKartaViewSource({
|
||||
fetchImpl: async () => ({
|
||||
ok: true,
|
||||
status: 200,
|
||||
headers: new Map(),
|
||||
// 3-byte chunks cut multi-byte characters in two.
|
||||
body: streamed(JSON.stringify(payload), 3),
|
||||
}),
|
||||
});
|
||||
assert.deepEqual(await source.getTile({ x: 1, y: 2, z: 13 }), payload);
|
||||
});
|
||||
|
||||
test('a sequence page gets the full 30 s on its first try, then 30 s once more', async (t) => {
|
||||
t.mock.timers.enable({ apis: ['setTimeout'] });
|
||||
const asked = [];
|
||||
const outcome = await onMockClock(
|
||||
t,
|
||||
(stamp) =>
|
||||
createKartaViewSource({
|
||||
fetchImpl: (url, { signal }) => {
|
||||
asked.push(stamp());
|
||||
return new Promise((resolve, reject) =>
|
||||
signal.addEventListener('abort', () => reject(signal.reason)),
|
||||
);
|
||||
},
|
||||
}).getSequencePhotos('9', { page: 1, itemsPerPage: 250 }),
|
||||
{ until: 120_000 },
|
||||
);
|
||||
assert.deepEqual(asked, [0, PAGE_TIMEOUT_MS]);
|
||||
assert.match(String(outcome?.error?.message), /did not answer in time/);
|
||||
assert.equal(outcome.at, 2 * PAGE_TIMEOUT_MS);
|
||||
});
|
||||
Reference in new issue
Block a user