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:
Maurice
2026-08-23 10:08:38 +02:00
committed by Maurice
parent b3d8bf08f1
commit c75e958fc0
27 changed files with 476 additions and 53 deletions
+52
View File
@@ -70,3 +70,55 @@ describe('design kit', () => {
expect(out.match(/<style data-trek-ui>/g)?.length).toBe(2);
});
});
/**
* Boot the kit bootstrap against a stub window, so the bridge's promise handling can be
* exercised without a DOM. `document.readyState` stays 'loading', which parks boot() on
* DOMContentLoaded and leaves only the message plumbing live. The stub's postMessage runs
* structuredClone first, exactly like the browser's — a value it cannot carry throws.
*/
function bootBridge() {
const sent: Record<string, unknown>[] = [];
const parent = { postMessage: (msg: Record<string, unknown>) => { structuredClone(msg); sent.push(msg); } };
let onMessage: ((ev: { source: unknown; data: unknown }) => void) | null = null;
const win: Record<string, unknown> = {
parent,
addEventListener: (type: string, cb: (ev: { source: unknown; data: unknown }) => void) => { if (type === 'message') onMessage = cb; },
};
const docEl = { setAttribute: () => {}, removeAttribute: () => {}, style: { setProperty: () => {} } };
const doc = { documentElement: docEl, readyState: 'loading', addEventListener: () => {}, body: null };
new Function('window', 'document', TREK_THEME_JS)(win, doc);
return {
trek: win.trek as {
session: { set: (k: string, v: unknown) => Promise<unknown>; get: (k: string) => Promise<unknown> };
invoke: (sub: string, opts?: { body?: unknown }) => Promise<unknown>;
confirm: (opts: unknown) => Promise<boolean>;
},
sent,
deliver: (data: unknown) => onMessage?.({ source: parent, data }),
};
}
describe('bridge requests never hang', () => {
it('rejects session.set with a value the frame cannot post, instead of pending forever', async () => {
const { trek, sent } = bootBridge();
// A function can't be structured-cloned: postMessage throws synchronously and the
// request never reaches the host, so the promise has to settle here.
await expect(trek.session.set('k', () => 1)).rejects.toMatchObject({ code: 'SESSION_INVALID_VALUE' });
expect(sent).toEqual([]);
});
it('rejects invoke with an unpostable body and resolves confirm as declined', async () => {
const { trek } = bootBridge();
await expect(trek.invoke('/x', { body: { cb: () => 1 } })).rejects.toMatchObject({ code: 'error' });
await expect(trek.confirm({ message: 'ok?', title: () => 'x' })).resolves.toBe(false);
});
it('still settles a normal request from the host response', async () => {
const { trek, sent, deliver } = bootBridge();
const p = trek.session.get('k');
expect(sent).toHaveLength(1);
deliver({ type: 'trek:response', requestId: sent[0].requestId, data: 'v' });
await expect(p).resolves.toBe('v');
});
});