mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
fix(client,sdk): the smaller silent failures, and a dead SDK test file
The SDK's parity suite had an unescaped apostrophe in an it() title, so the file did not parse and vitest reported it as "no tests". Both guards in it were dead - including the byte-identical egress-policy check the package's own notes call the worst possible bug in that module to lose. No CI job runs the SDK suite, so it landed quietly; the next npm publish would have failed on it, since prepublishOnly runs the tests. Also in the SDK: the dev preview answered trek:geolocation without checking the geolocation:read grant, so a plugin whose manifest is missing the permission works perfectly in dev and is dead once installed. That is the lenient direction, which is the one that ships broken plugins. Client side: the background-task poll never dismissed a 404'd import job and spun forever, "Update All" collapsed its busy flag after the first plugin settled, the lightbox had no cancellation so a slow signed URL rendered the wrong image, the plugin geolocation watch was torn down by any unrelated settings write, manual date entry accepted 31 February, cover previews were never revoked, and check-all issued one request per packing item.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// FE-PLUGINS-FRAME-001 to 046
|
||||
// FE-PLUGINS-FRAME-001 to 061
|
||||
import { render, cleanup, waitFor, fireEvent, screen, act } from '@testing-library/react';
|
||||
import PluginFrame from './PluginFrame';
|
||||
import { usePluginStore } from '../../store/pluginStore';
|
||||
@@ -340,12 +340,12 @@ describe('PluginFrame', () => {
|
||||
|
||||
function mount(granted: boolean) {
|
||||
grant(granted);
|
||||
const { container, unmount } = render(<PluginFrame pluginId="demo" />);
|
||||
const iframe = container.querySelector('iframe')!;
|
||||
const view = render(<PluginFrame pluginId="demo" />);
|
||||
const iframe = view.container.querySelector('iframe')!;
|
||||
const posted: Array<Record<string, unknown>> = [];
|
||||
(iframe.contentWindow as unknown as { postMessage: (m: unknown) => void }).postMessage = (m: unknown) =>
|
||||
posted.push(m as Record<string, unknown>);
|
||||
return { iframe, posted, unmount };
|
||||
return { ...view, iframe, posted };
|
||||
}
|
||||
|
||||
it('FE-PLUGINS-FRAME-015: refuses an ungranted plugin without touching the browser API', () => {
|
||||
@@ -381,6 +381,33 @@ describe('PluginFrame', () => {
|
||||
expect(geo.clearWatch).toHaveBeenCalledWith(7);
|
||||
});
|
||||
|
||||
it('FE-PLUGINS-FRAME-060: a host settings change re-bridges without dropping the watch', () => {
|
||||
let tick: ((p: unknown) => void) | null = null;
|
||||
geo.watchPosition.mockImplementation((ok: (p: unknown) => void) => { tick = ok; return 7; });
|
||||
const { iframe, posted, rerender } = mount(true);
|
||||
act(() => { fromFrame(iframe, { type: 'trek:geolocation', requestId: 'g20', action: 'watch' }); });
|
||||
|
||||
// Any settings write re-runs the bridge effect; the watch must survive it.
|
||||
host.settings = { ...DEFAULT_SETTINGS, distance_unit: 'imperial' };
|
||||
act(() => { rerender(<PluginFrame pluginId="demo" />); });
|
||||
|
||||
expect(geo.clearWatch).not.toHaveBeenCalled();
|
||||
const before = posted.length;
|
||||
act(() => tick!({ coords: { latitude: 5, longitude: 6, accuracy: 5, heading: null, speed: null }, timestamp: 3 }));
|
||||
expect(posted.length).toBe(before + 1);
|
||||
});
|
||||
|
||||
it('FE-PLUGINS-FRAME-061: a frame that navigates itself has its watch released', () => {
|
||||
const { iframe } = mount(true);
|
||||
act(() => { fireEvent.load(iframe); });
|
||||
act(() => { fromFrame(iframe, { type: 'trek:geolocation', requestId: 'g21', action: 'watch' }); });
|
||||
|
||||
// Second load = the frame navigated away, so nothing receives the stream any more.
|
||||
act(() => { fireEvent.load(iframe); });
|
||||
|
||||
expect(geo.clearWatch).toHaveBeenCalledWith(7);
|
||||
});
|
||||
|
||||
it('FE-PLUGINS-FRAME-018: clear stops the watch on request', () => {
|
||||
const { iframe, posted } = mount(true);
|
||||
fromFrame(iframe, { type: 'trek:geolocation', requestId: 'g4', action: 'watch' });
|
||||
|
||||
@@ -650,8 +650,6 @@ export default function PluginFrame({ pluginId, tripId = null, placeId = null, d
|
||||
window.removeEventListener('message', onMessage)
|
||||
themeObserver.disconnect()
|
||||
if (wsForward) removeListener(wsForward)
|
||||
// The frame is going away (or re-bridging) — never leave a live GPS watch behind.
|
||||
if (geoWatchRef.current != null) { navigator.geolocation.clearWatch(geoWatchRef.current); geoWatchRef.current = null }
|
||||
}
|
||||
}, [pluginId, tripId, fill, navigate, postFrame, buildContext, userId])
|
||||
|
||||
@@ -664,6 +662,11 @@ export default function PluginFrame({ pluginId, tripId = null, placeId = null, d
|
||||
setHeight(null)
|
||||
confirmReqRef.current = null
|
||||
setConfirmReq(null)
|
||||
// Only a real teardown may kill the watch: the bridge above re-runs on any
|
||||
// settings, locale or breakpoint change, and nothing would re-arm it.
|
||||
return () => {
|
||||
if (geoWatchRef.current != null) { navigator.geolocation.clearWatch(geoWatchRef.current); geoWatchRef.current = null }
|
||||
}
|
||||
}, [pluginId])
|
||||
|
||||
const answerConfirm = (confirmed: boolean) => {
|
||||
@@ -689,7 +692,14 @@ export default function PluginFrame({ pluginId, tripId = null, placeId = null, d
|
||||
// Deliver the context as soon as the document is parsed (the plugin sets up its
|
||||
// message listener during parse), closing the trek:ready race so the theme is
|
||||
// right on first paint. A 2nd load is a self-navigation — don't bridge to it.
|
||||
onLoad={() => { setLoadFailed(false); loadsRef.current += 1; if (loadsRef.current === 1) postFrame(buildContext()) }}
|
||||
onLoad={() => {
|
||||
setLoadFailed(false)
|
||||
loadsRef.current += 1
|
||||
if (loadsRef.current === 1) postFrame(buildContext())
|
||||
// A self-navigated frame is no longer bridged, so its watch is only
|
||||
// burning battery for positions nobody receives.
|
||||
else if (geoWatchRef.current != null) { navigator.geolocation.clearWatch(geoWatchRef.current); geoWatchRef.current = null }
|
||||
}}
|
||||
onError={() => setLoadFailed(true)}
|
||||
sandbox="allow-scripts allow-forms"
|
||||
referrerPolicy="no-referrer"
|
||||
|
||||
Reference in New Issue
Block a user