Skip to content

Commit 44af7f5

Browse files
test(webui): keep a Mini App's view URL stable across a proxy restart
Closes #255's stability criterion with evidence. The page's `localStorage` and `IndexedDB` are keyed by its origin, so a port that moved between runs would silently discard the page's own state. The derived port is a pure function of the plugin id, and this asserts the property end to end: start on the derived port, close, start again from a fresh derivation, and the view URL is identical. Verified: pnpm typecheck:webui; the focused suite (9 cases).
1 parent 5ca1c6e commit 44af7f5

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

‎packages/webui/test/unit/miniapp-proxy.test.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,28 @@ describe('Mini App proxy', () => {
148148
expect(seen.at(-1)?.headers[CREDENTIAL_HEADER]).toBe(CREDENTIAL);
149149
});
150150

151+
it('keeps one plugin on the same port across a restart, so the page storage survives', async () => {
152+
const derived = deriveMiniAppProxyPort('fixture.miniapp');
153+
const target = {
154+
pluginId: 'fixture.miniapp',
155+
upstreamOrigin: `http://127.0.0.1:${upstreamPort}`,
156+
credential: CREDENTIAL,
157+
credentialHeader: CREDENTIAL_HEADER,
158+
};
159+
160+
const first = await startMiniAppProxy({ target, port: derived });
161+
const firstUrl = first.viewUrl;
162+
await first.close();
163+
164+
const second = await startMiniAppProxy({ target, port: deriveMiniAppProxyPort('fixture.miniapp') });
165+
try {
166+
expect(second.viewUrl).toBe(firstUrl);
167+
expect(second.port).toBe(derived);
168+
} finally {
169+
await second.close();
170+
}
171+
});
172+
151173
it('derives a stable loopback port per plugin', () => {
152174
const first = deriveMiniAppProxyPort('fixture.miniapp');
153175

0 commit comments

Comments
 (0)