Street Level: Panoramax review follow-ups (gekh, #1134)

Image loading (photoViewer.js)
- One AbortController per open: a new open, close or unmount stops the
  previous photo's first and sharper downloads (an <img> by src = '').
  A collapsed viewer never falls back to the original; Panoramax's flat
  fallback is the thumbnail. A superseded open resolves quietly.
- Flat HD tracked as "loading" and "shown" apart: a discarded response no
  longer blocks later upgrades, and resizes while it loads ask once.
- No upgrade of the photo still shown while another opens.
- Size limits before decoding: imageSize.js reads JPEG/PNG/WebP/GIF
  headers; more than 64 MP or 16,384 px a side is refused undecoded, an
  <img> that decodes larger is refused and let go, flat HD needs a known
  width of at most 8,192 px, and panoramas always decode with a resize.

Panoramax provider
- Retry-After parsed as seconds or an HTTP date; the browser cannot read
  it here, so busy answers back off 5 s doubling to 300 s, reset once
  answered.
- Headers timed, then the body by an idle timeout (15 s of silence), so a
  slow link still gets its megabyte tiles.
- Cones centre only on the picture shown (onShowing), never on a late
  lookup; lookups nobody waits for are aborted (shared, refcounted).
- onReopen: a GPU reset redraws in the viewer, not through the core.
- Cones draw the home z15 tile at once and add neighbours as they arrive;
  a neighbour that failed is not counted as drawn.
- Coverage tiles decode in ~8 ms slices (a 2 MB z10 tile over Paris was
  one ~85-200 ms task); sorted by measured length without a Map.
- Box search asks for 20, not 100 (the API returns them nearest first).
- looksLikeEmail checks every '@'; creatorOf de-duplicates with a Set.

lineCoverage.js
- A redraw while a swap still builds keeps what is on screen (the swap's
  old lines and its ready new ones) and drops only the unready ones.

Tests for each (mutation-checked), two vacuous tests made real, the
cones' pictures lane and readable()'s busy/timeout paths covered; the
fixture's box search is nearest first. Docs: README filters and share
links, CHANGELOG HD wording, CURRENT-STATE.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Said TurkseverandClaude Opus 5.5 committed 2026-10-15 16:55:59 +01:00
1 parent e3bc431f9a
commit b645a767c8
25 files changed
+1362 -135

No files matched your search

+206 -1
View File
@@ -7,6 +7,7 @@ const PHOTOS = {
a: { id: 'a', sequenceId: 's', lon: 1, lat: 2, heading: 0, isPano: true },
b: { id: 'b', sequenceId: 's', lon: 1, lat: 2, heading: 0, isPano: true },
f: { id: 'f', sequenceId: 's', lon: 1, lat: 2, heading: 0, isPano: false },
g: { id: 'g', sequenceId: 's', lon: 1, lat: 2, heading: 0, isPano: false },
};
/** Sources whose panoramas and sharper flat versions are named after the photo. */
@@ -294,7 +295,11 @@ test('a picture file or bitmap past any real photo’s size is refused', async (
(globalThis.fetch = async () => ({
ok: true,
headers: new Map([['content-length', String(length ?? '')]]),
blob: async () => ({ size: size ?? 10, bitmap: bitmap(width, height) }),
blob: async () => ({
size: size ?? 10,
bitmap: bitmap(width, height),
slice: () => ({ arrayBuffer: async () => new ArrayBuffer(0) }),
}),
}));
const refusedForSize = (error) => {
assert.match(error.message, /could not be loaded/);
@@ -331,3 +336,203 @@ test('a picture file or bitmap past any real photo’s size is refused', async (
respond({});
assert.equal((await loadImage('https://x/a.jpg')).width, 100);
});
/** A viewer whose loads are held, recording each load's signal by url. */
function heldViewer() {
const pending = new Map();
const signals = new Map();
const loads = [];
const viewer = createPhotoViewer({
providerId: 'test',
name: 'Test',
sources: SOURCES,
getPhoto: async (id) => PHOTOS[id],
step: async () => null,
onStep() {},
load: (url, options = {}) =>
new Promise((resolve, reject) => {
loads.push(url);
signals.set(url, options.signal);
options.signal?.addEventListener('abort', () =>
reject(new Error('aborted')),
);
pending.set(url, { resolve, reject });
}),
});
const release = (url) => {
pending.get(url).resolve({ src: url });
pending.delete(url);
};
return { viewer, pending, signals, loads, release, host: fakeHost() };
}
test('a new open, a close or an unmount stops the downloads of the open before it', async () => {
const env = heldViewer();
await env.viewer.mount(env.host);
const first = env.viewer.open('f');
assert.ok(await until(() => env.signals.has('f-first')));
const second = env.viewer.open('g');
assert.equal(env.signals.get('f-first').aborted, true, 'f is not wanted now');
await first.catch(() => {});
assert.ok(await until(() => env.signals.has('g-first')));
env.viewer.close();
assert.equal(env.signals.get('g-first').aborted, true, 'closed');
await second.catch(() => {});
const third = env.viewer.open('f');
assert.ok(await until(() => env.pending.has('f-first')));
env.viewer.unmount();
assert.equal(env.signals.get('f-first').aborted, true, 'unmounted');
await third.catch(() => {});
});
test('a sharper flat version on its way stops when another photo opens, and is asked again later', async (t) => {
t.after(() => delete globalThis.devicePixelRatio);
globalThis.devicePixelRatio = 1;
const env = heldViewer();
await env.viewer.mount(env.host);
parts(env.host).picture.clientWidth = 1200;
const opening = env.viewer.open('f');
assert.ok(await until(() => env.pending.has('f-first')));
env.release('f-first');
await opening;
assert.ok(
await until(() => env.pending.has('f-sharp')),
'the 1,200 px viewer asks for more',
);
// Resizes while it loads (the panel animating) do not ask again.
env.viewer.resize();
env.viewer.resize();
await new Promise((resolve) => setTimeout(resolve, 0));
assert.equal(env.loads.filter((url) => url === 'f-sharp').length, 1);
// g opens (and fails): f's sharp download stops, f stays on screen.
const failing = env.viewer.open('g');
assert.equal(env.signals.get('f-sharp').aborted, true);
assert.ok(await until(() => env.pending.has('g-first')));
env.pending.get('g-first').reject(new Error('gone'));
env.pending.delete('g-first');
await failing.catch(() => {});
// The discarded response does not block f's sharp version for good.
env.signals.delete('f-sharp');
env.viewer.resize();
assert.ok(await until(() => env.signals.has('f-sharp')), 'asked again');
});
test('a resize while another photo opens does not upgrade the photo still shown', async (t) => {
t.after(() => delete globalThis.devicePixelRatio);
globalThis.devicePixelRatio = 1;
const env = heldViewer();
await env.viewer.mount(env.host);
const opening = env.viewer.open('f');
assert.ok(await until(() => env.pending.has('f-first')));
env.release('f-first');
await opening;
// g is opening; EXPAND resizes the viewer meanwhile.
const next = env.viewer.open('g');
assert.ok(await until(() => env.pending.has('g-first')));
parts(env.host).picture.clientWidth = 1200;
env.viewer.resize();
await new Promise((resolve) => setTimeout(resolve, 0));
assert.equal(env.pending.has('f-sharp'), false, 'f is on its way out');
env.release('g-first');
await next;
assert.ok(await until(() => env.pending.has('g-sharp')), 'g gets it');
});
test('a panorama is always decoded at a bounded size', async () => {
const env = heldViewer();
const options = [];
const viewer = createPhotoViewer({
providerId: 'test',
name: 'Test',
sources: SOURCES,
getPhoto: async (id) => PHOTOS[id],
step: async () => null,
onStep() {},
load: async (url, opts) => {
options.push(opts);
return { src: url };
},
createRenderer: () => ({
setImage() {},
setView() {},
getView: () => ({ yaw: 0, pitch: 0, fov: 80 }),
resize() {},
clear() {},
destroy() {},
}),
});
await viewer.mount(env.host);
await viewer.open('a');
// SOURCES' panoFirst names no size: the viewer still bounds it.
assert.deepEqual(options[0].resize, [2048, 1024]);
});
test('a header that declares a huge image is refused before anything decodes it', async (t) => {
const { loadImage } = await import('./photoViewer.js');
const saved = {
fetch: globalThis.fetch,
createImageBitmap: globalThis.createImageBitmap,
};
t.after(() => Object.assign(globalThis, saved));
let decoded = 0;
globalThis.createImageBitmap = async () => {
decoded++;
return { width: 10, height: 10 };
};
// A 1 kB PNG that says it is 16,384 × 16,384.
const png = new Uint8Array(1024);
png.set([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a, 0, 0, 0, 13]);
png.set(
[...'IHDR'].map((c) => c.charCodeAt(0)),
12,
);
png.set([0, 0, 0x40, 0, 0, 0, 0x40, 0], 16);
globalThis.fetch = async () => new Response(png);
await assert.rejects(
loadImage('https://x/bomb.png'),
(error) => error.tooLarge === true,
);
assert.equal(decoded, 0, 'never decoded');
});
test('an <img> that turns out too large is refused and let go', async (t) => {
const { loadImage, MAX_IMAGE_SIDE } = await import('./photoViewer.js');
const saved = globalThis.Image;
t.after(() => (globalThis.Image = saved));
let size = [MAX_IMAGE_SIDE + 1, 100];
const images = [];
globalThis.Image = class {
constructor() {
images.push(this);
}
set src(value) {
this._src = value;
if (value)
queueMicrotask(() => {
[this.naturalWidth, this.naturalHeight] = size;
this.onload?.();
});
}
get src() {
return this._src;
}
};
await assert.rejects(
loadImage('https://x/a.jpg', { crossOrigin: false }),
(error) => error.tooLarge === true,
);
assert.equal(images.at(-1).src, '', 'its pixels let go');
size = [4000, 3000];
const ok = await loadImage('https://x/b.jpg', { crossOrigin: false });
assert.equal(ok.naturalWidth, 4000);
// An aborted <img> load stops and rejects.
size = [10, 10];
const controller = new AbortController();
const aborted = loadImage('https://x/c.jpg', {
crossOrigin: false,
signal: controller.signal,
});
controller.abort();
await assert.rejects(aborted);
assert.equal(images.at(-1).src, '', 'its download stops');
});