From 6be6b46c91e950f5dfd5e376096f6ebbe6eb6872 Mon Sep 17 00:00:00 2001 From: Felix Delval Date: Thu, 24 Sep 2026 11:55:20 +0200 Subject: [PATCH 1/4] test(guest,host): characterize the extension-loading-timeout bug Adds unit tests documenting the root cause found while investigating a regression where a single unreachable/404 extension caused RPC calls from unrelated, healthy extensions to fail with false "timed out" errors (docs/extension-loading-timeout-investigation.md). - guest.test.ts (new): a host method call is subject to a hardcoded 10000ms timeout (guest.ts's `host` proxy) that is completely decoupled from GuestConfig.timeout, which only governs the initial connectParentWindow handshake. Includes one intentionally-red test: a call resolving at 12000ms should succeed once the guest-side call timeout is raised/made configurable to be >= Port's 20000ms connect default, instead of spuriously timing out. Wires up @adobe/uix-guest for unit testing for the first time (it had no test files and wasn't registered as a jest project). - host.test.ts (new): confirms Host's Promise.all-based batching in addLoadsNewGuests is correct by design -- the per-guest "guestload" event and getLoadedGuests() reflect a healthy guest immediately, without waiting on a broken sibling's full connection timeout, while "loadallguests" correctly waits for the whole cohort to settle. - port.test.ts: adds a tripwire asserting Port's default connection timeout stays 20000ms, since the guest-side fix's target value is anchored to it. Co-Authored-By: Claude Sonnet 5 --- jest.config.ts | 11 ++- package-lock.json | 32 +++++- packages/uix-guest/package.json | 8 ++ packages/uix-guest/src/guest.test.ts | 135 +++++++++++++++++++++++++ packages/uix-host/src/host.test.ts | 142 +++++++++++++++++++++++++++ packages/uix-host/src/port.test.ts | 45 +++++++++ 6 files changed, 371 insertions(+), 2 deletions(-) create mode 100644 packages/uix-guest/src/guest.test.ts create mode 100644 packages/uix-host/src/host.test.ts diff --git a/jest.config.ts b/jest.config.ts index fa5445ab..73af46bd 100644 --- a/jest.config.ts +++ b/jest.config.ts @@ -31,7 +31,16 @@ const jestConfig = { "/packages/uix-core/src/__helpers__/jest.messagechannel.cjs", ], }), - sdkProject("host", {}), + sdkProject("host", { + moduleNameMapper: { + "^(\\.{1,2}/.*)\\.js$": "$1", + }, + }), + sdkProject("guest", { + moduleNameMapper: { + "^(\\.{1,2}/.*)\\.js$": "$1", + }, + }), sdkProject("host-react", { testMatch: [ "/packages/uix-host-react/src/**/*.test.ts", diff --git a/package-lock.json b/package-lock.json index 7370e391..5cf6e583 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21656,6 +21656,12 @@ "@adobe/uix-core": "^1.1.11", "ajv": "^8.12.0", "js-yaml": "^4.1.0" + }, + "devDependencies": { + "@types/jest": "^29.5.12", + "jest": "^29.7.0", + "ts-jest": "^29.1.2", + "typescript": "^5.3.3" } }, "packages/uix-guest/node_modules/ajv": { @@ -21694,6 +21700,20 @@ "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" }, + "packages/uix-guest/node_modules/typescript": { + "version": "5.9.3", + "resolved": "https://artifactory.corp.adobe.com/artifactory/api/npm/npm-adobe-release/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "packages/uix-host": { "name": "@adobe/uix-host", "version": "1.1.11", @@ -21862,8 +21882,12 @@ "version": "file:packages/uix-guest", "requires": { "@adobe/uix-core": "^1.1.11", + "@types/jest": "^29.5.12", "ajv": "^8.12.0", - "js-yaml": "^4.1.0" + "jest": "^29.7.0", + "js-yaml": "^4.1.0", + "ts-jest": "^29.1.2", + "typescript": "^5.3.3" }, "dependencies": { "ajv": { @@ -21894,6 +21918,12 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==" + }, + "typescript": { + "version": "5.9.3", + "resolved": "https://artifactory.corp.adobe.com/artifactory/api/npm/npm-adobe-release/typescript/-/typescript-5.9.3.tgz", + "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", + "dev": true } } }, diff --git a/packages/uix-guest/package.json b/packages/uix-guest/package.json index 40cd3bce..b9949bee 100644 --- a/packages/uix-guest/package.json +++ b/packages/uix-guest/package.json @@ -11,6 +11,8 @@ "scripts": { "build": "tsup", "build:esm": "tsup --format esm,cjs,iife", + "test": "NODE_ENV=test jest", + "test:watch": "NODE_ENV=test jest --watch", "watch": "tsup --watch --silent" }, "browserslist": [ @@ -22,6 +24,12 @@ "ajv": "^8.12.0", "js-yaml": "^4.1.0" }, + "devDependencies": { + "@types/jest": "^29.5.12", + "jest": "^29.7.0", + "ts-jest": "^29.1.2", + "typescript": "^5.3.3" + }, "files": [ "README.md", "dist", diff --git a/packages/uix-guest/src/guest.test.ts b/packages/uix-guest/src/guest.test.ts new file mode 100644 index 00000000..3b4d1fee --- /dev/null +++ b/packages/uix-guest/src/guest.test.ts @@ -0,0 +1,135 @@ +import { Guest } from "./guest"; +import type { + CrossRealmObject, + GuestApis, + HostConnection, +} from "@adobe/uix-core"; + +interface TestHostApis extends GuestApis { + someNamespace: { someMethod: () => Promise }; +} + +type TestGuest = Guest<{ + incoming: TestHostApis; + outgoing: GuestApis; + sharedContext: Record; +}>; + +// Mock connectParentWindow from uix-core so we can control the guest's +// "host connection" without a real postMessage handshake. +jest.mock("@adobe/uix-core", () => { + const actual = jest.requireActual("@adobe/uix-core"); + return { + ...actual, + connectParentWindow: jest.fn(), + }; +}); + +import { connectParentWindow } from "@adobe/uix-core"; +const mockConnectParentWindow = connectParentWindow as jest.MockedFunction< + typeof connectParentWindow +>; + +function connectGuest( + invokeHostMethod: jest.Mock, + config?: { timeout?: number } +) { + const fakeRemoteApi = { + invokeHostMethod, + getSharedContext: jest.fn().mockResolvedValue({}), + getConfiguration: jest.fn().mockResolvedValue({}), + }; + const fakeHostConnection = { + getRemoteApi: () => fakeRemoteApi, + } as unknown as CrossRealmObject; + + mockConnectParentWindow.mockResolvedValue(fakeHostConnection); + + const guest: TestGuest = new Guest({ id: "test-guest", ...config }); + return guest.connect().then(() => guest); +} + +describe("Guest host-method call timeout", () => { + beforeEach(() => { + jest.useFakeTimers(); + mockConnectParentWindow.mockReset(); + }); + + afterEach(() => { + jest.useRealTimers(); + }); + + // Characterizes the bug from the extension-loading-timeout investigation + // (docs/extension-loading-timeout-investigation.md): a call to a host + // method is subject to a hardcoded 10000ms timeout in guest.ts's `host` + // proxy, which is completely independent of GuestConfig.timeout. That + // config option (see guest.ts's `this.timeout`) only governs the initial + // connectParentWindow handshake, not per-call RPC timeouts -- there is + // currently no way to configure the latter at all. + it("times out a host method call at 10000ms even when GuestConfig.timeout is set much higher", async () => { + // Never resolves/rejects: simulates a host method call that is still + // legitimately in flight (e.g. the host is mid-batch loading a sibling + // extension) rather than one that has actually failed. + const invokeHostMethod = jest.fn(() => new Promise(() => undefined)); + const guest = await connectGuest(invokeHostMethod, { timeout: 20000 }); + + const callPromise = guest.host.someNamespace.someMethod(); + const assertion = expect(callPromise).rejects.toThrow( + "timed out after 10000ms" + ); + + await jest.advanceTimersByTimeAsync(10001); + await assertion; + }); + + it("times out a host method call at the same 10000ms with no GuestConfig.timeout set (default config)", async () => { + const invokeHostMethod = jest.fn(() => new Promise(() => undefined)); + const guest = await connectGuest(invokeHostMethod); + + const callPromise = guest.host.someNamespace.someMethod(); + const assertion = expect(callPromise).rejects.toThrow( + "timed out after 10000ms" + ); + + await jest.advanceTimersByTimeAsync(10001); + await assertion; + }); + + it("succeeds when the host responds comfortably inside 10000ms (control case)", async () => { + const invokeHostMethod = jest.fn( + () => new Promise((resolve) => setTimeout(() => resolve("ok"), 500)) + ); + const guest = await connectGuest(invokeHostMethod); + + const callPromise = guest.host.someNamespace.someMethod(); + const assertion = expect(callPromise).resolves.toBe("ok"); + + await jest.advanceTimersByTimeAsync(501); + await assertion; + }); + + // RED TEST -- expected to FAIL until the fix for the extension-loading- + // timeout bug lands (docs/extension-loading-timeout-investigation.md). + // `uix-host`'s Port connection timeout defaults to 20000ms (port.ts's + // defaultOptions.timeout), longer than uix-guest's current hardcoded + // 10000ms call timeout -- so any host method call that legitimately takes + // between 10s and 20s (e.g. because the host is still resolving a load + // batch containing an unrelated slow/broken guest) fails with a false + // "timed out" error today. Once the guest-side call timeout is raised or + // made configurable to be >= 20000ms (or otherwise decoupled from this + // hardcoded value), a call resolving at 12000ms should succeed instead of + // spuriously timing out, and this test will go green with no changes to + // the test itself. + it("does not time out a call that resolves at 12000ms, past the old 10000ms ceiling", async () => { + const invokeHostMethod = jest.fn( + () => new Promise((resolve) => setTimeout(() => resolve("ok"), 12000)) + ); + const guest = await connectGuest(invokeHostMethod); + + const callPromise = guest.host.someNamespace.someMethod(); + const assertion = expect(callPromise).resolves.toBe("ok"); + + await jest.advanceTimersByTimeAsync(12001); + await assertion; + }); +}); diff --git a/packages/uix-host/src/host.test.ts b/packages/uix-host/src/host.test.ts new file mode 100644 index 00000000..f33aac25 --- /dev/null +++ b/packages/uix-host/src/host.test.ts @@ -0,0 +1,142 @@ +// Mock Port so Host's batching/event behavior can be tested without a real +// iframe handshake. Each fake Port's load() resolves/rejects after a +// controllable delay, standing in for a fast-connecting guest or one that +// never responds (e.g. a 404'd extension) until Port's own connect timeout. +jest.mock("./port.js", () => ({ Port: jest.fn() })); + +import { Port } from "./port.js"; +import { Host } from "./host"; + +const MockPort = Port as unknown as jest.Mock; + +interface FakePortBehavior { + /** load() resolves successfully after this many ms. */ + readyAfterMs?: number; + /** load() rejects (guest never connected) after this many ms. */ + failAfterMs?: number; +} + +function installFakePorts(behaviors: Record) { + MockPort.mockImplementation((config: { id: string; url: URL }) => { + const behavior = behaviors[config.id] ?? { readyAfterMs: 0 }; + const instance: Record & { + _ready: boolean; + error?: Error; + } = { + id: config.id, + url: config.url, + _ready: false, + error: undefined, + isReady: () => instance._ready, + unload: jest.fn().mockResolvedValue(undefined), + hasCapabilities: jest.fn().mockReturnValue(true), + }; + instance.load = jest.fn(async () => { + if (behavior.failAfterMs !== undefined) { + await new Promise((resolve) => + setTimeout(resolve, behavior.failAfterMs) + ); + instance.error = new Error( + `Guest ${config.id} did not send ready message within ${behavior.failAfterMs}ms` + ); + throw instance.error; + } + await new Promise((resolve) => + setTimeout(resolve, behavior.readyAfterMs ?? 0) + ); + instance._ready = true; + }); + return instance; + }); +} + +function createHost() { + return new Host({ hostName: "test-host", disableMetrics: true }); +} + +describe("Host guest-loading events", () => { + beforeEach(() => { + jest.useFakeTimers(); + MockPort.mockReset(); + }); + + afterEach(() => { + jest.useRealTimers(); + document + .querySelectorAll("[data-uix-guest-container]") + .forEach((el) => el.remove()); + }); + + // Documents the mechanism that, once consumed correctly, already avoids + // the bug from the extension-loading-timeout investigation + // (docs/extension-loading-timeout-investigation.md): the per-guest + // "guestload" event (and getLoadedGuests()/isReady()) reflect a healthy + // guest immediately, without waiting for a broken sibling guest's full + // connection timeout. (universal-editor's Api.ts bug was subscribing to + // the batch-level "loadallguests" event instead of this one.) + it("fires 'guestload' for a healthy guest well before a broken sibling's connection timeout elapses", async () => { + installFakePorts({ + healthy: { readyAfterMs: 50 }, + broken: { failAfterMs: 20000 }, + }); + + const host = createHost(); + const guestloadTimes: string[] = []; + host.addEventListener("guestload", (event) => { + const { guest } = (event as CustomEvent<{ guest: { id: string } }>) + .detail; + guestloadTimes.push(guest.id); + }); + + const loadPromise = host.load({ + healthy: "https://example.com/healthy", + broken: "https://example.com/broken", + }); + + await jest.advanceTimersByTimeAsync(51); + expect(guestloadTimes).toEqual(["healthy"]); + expect(host.getLoadedGuests().map((g) => g.id)).toEqual(["healthy"]); + + await jest.advanceTimersByTimeAsync(20000); + await loadPromise; + expect(guestloadTimes).toEqual(["healthy"]); + }); + + // Documents that Promise.all-based batching in addLoadsNewGuests is + // intentional: "loadallguests" is a whole-cohort signal and correctly + // waits for the slowest/broken guest to settle. This is by design, not + // the bug -- consumers that need a guest's methods as soon as that guest + // is ready should use "guestload"/getLoadedGuests() instead, as the test + // above demonstrates. + it("only fires 'loadallguests' once every guest in the batch has settled, including a broken one", async () => { + installFakePorts({ + healthy: { readyAfterMs: 50 }, + broken: { failAfterMs: 20000 }, + }); + + type LoadAllGuestsDetail = { + failed: { id: string }[]; + loaded: { id: string }[]; + }; + const host = createHost(); + let loadAllGuestsDetail: LoadAllGuestsDetail | undefined; + host.addEventListener("loadallguests", (event) => { + loadAllGuestsDetail = (event as CustomEvent).detail; + }); + + const loadPromise = host.load({ + healthy: "https://example.com/healthy", + broken: "https://example.com/broken", + }); + + await jest.advanceTimersByTimeAsync(19999); + expect(loadAllGuestsDetail).toBeUndefined(); + + await jest.advanceTimersByTimeAsync(2); + await loadPromise; + + expect(loadAllGuestsDetail).toBeDefined(); + expect(loadAllGuestsDetail?.loaded.map((g) => g.id)).toEqual(["healthy"]); + expect(loadAllGuestsDetail?.failed.map((g) => g.id)).toEqual(["broken"]); + }); +}); diff --git a/packages/uix-host/src/port.test.ts b/packages/uix-host/src/port.test.ts index 966761df..7f298cf5 100644 --- a/packages/uix-host/src/port.test.ts +++ b/packages/uix-host/src/port.test.ts @@ -63,6 +63,27 @@ function createPort(options?: { timeout?: number }) { return { port, container }; } +/** Constructs a Port without an explicit `options.timeout`, so it falls back to Port's own internal default. */ +function createPortWithDefaultTimeout() { + const container = document.createElement("div"); + document.body.appendChild(container); + containers.push(container); + const events = new Emitter("test-events") as unknown as Emits; + + const port = new Port({ + owner: "test-owner", + id: "test-extension", + url: new URL("https://example.com/extension"), + runtimeContainer: container, + options: {}, + sharedContext: {}, + extensionPoints: ["test-ep"], + events, + }); + + return { port, container }; +} + describe("Port", () => { beforeEach(() => { jest.useFakeTimers(); @@ -138,4 +159,28 @@ describe("Port", () => { ); }); }); + + // Tripwire for the value the extension-loading-timeout investigation + // (docs/extension-loading-timeout-investigation.md) is anchored to: + // uix-guest's per-call RPC timeout needs to be raised to be >= this + // default, so a legitimately-slow-but-healthy connection window doesn't + // spuriously time out unrelated in-flight host method calls. If this + // default ever changes, that guest-side value needs to move with it. + it("defaults the connection timeout to 20000ms when none is configured", async () => { + createMockConnectIframe("1.1.4"); + const { port } = createPortWithDefaultTimeout(); + + const loadPromise = port.load(); + await Promise.resolve(); + await Promise.resolve(); + + jest.advanceTimersByTime(19999); + await Promise.resolve(); + + jest.advanceTimersByTime(2); + + await expect(loadPromise).rejects.toThrow( + "did not send ready message within 20000ms" + ); + }); }); From 8d9da5c3068e0ee75c3b4fdab3b79857001336f1 Mon Sep 17 00:00:00 2001 From: Felix Delval Date: Thu, 24 Sep 2026 11:58:51 +0200 Subject: [PATCH 2/4] fix(guest): decouple host-method call timeout from hardcoded 10000ms Root cause (docs/extension-loading-timeout-investigation.md): a guest's call to a host method was subject to a hardcoded 10000ms timeout, completely independent of GuestConfig.timeout (which only ever governed the initial connectParentWindow handshake). uix-host's Port defaults its own connection timeout to 20000ms, so any host method call that legitimately took between 10s and 20s -- e.g. because the host was still resolving a load batch containing an unrelated slow/broken (404) extension -- failed with a false "timed out" error, even though the calling guest itself was healthy and already connected. Adds GuestConfig.callTimeout (default 20000ms, matching Port's default) and uses it in place of the hardcoded value, so the two packages' default timeouts can't drift out of sync again, while remaining independently tunable from GuestConfig.timeout and configurable per guest. Also removes invokeAwaiter's dead "final" setTimeout: it never actually enforced anything (its rejection was never attached to the returned promise chain) and only produced a stray unhandled rejection whenever a call was still pending at the 20000ms mark -- harmless while the real call timeout was a shorter 10000ms, but a direct collision once the default here also became 20000ms. The real timeout enforcement was always the outer timeoutPromise() wrapping this method's result. Turns green the previously-red test added in the prior commit (guest.test.ts's "does not time out a call that resolves at 12000ms"). Updates the two tests that characterized the old 10000ms-regardless-of- config bug to assert the new, decoupled, configurable behavior instead, and adds a test for the new callTimeout override. Co-Authored-By: Claude Sonnet 5 --- packages/uix-guest/src/guest.test.ts | 66 ++++++++++++++++------------ packages/uix-guest/src/guest.ts | 30 +++++++------ 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/packages/uix-guest/src/guest.test.ts b/packages/uix-guest/src/guest.test.ts index 3b4d1fee..47b0938c 100644 --- a/packages/uix-guest/src/guest.test.ts +++ b/packages/uix-guest/src/guest.test.ts @@ -32,7 +32,7 @@ const mockConnectParentWindow = connectParentWindow as jest.MockedFunction< function connectGuest( invokeHostMethod: jest.Mock, - config?: { timeout?: number } + config?: { timeout?: number; callTimeout?: number } ) { const fakeRemoteApi = { invokeHostMethod, @@ -59,43 +59,62 @@ describe("Guest host-method call timeout", () => { jest.useRealTimers(); }); - // Characterizes the bug from the extension-loading-timeout investigation - // (docs/extension-loading-timeout-investigation.md): a call to a host - // method is subject to a hardcoded 10000ms timeout in guest.ts's `host` - // proxy, which is completely independent of GuestConfig.timeout. That - // config option (see guest.ts's `this.timeout`) only governs the initial - // connectParentWindow handshake, not per-call RPC timeouts -- there is - // currently no way to configure the latter at all. - it("times out a host method call at 10000ms even when GuestConfig.timeout is set much higher", async () => { + // See docs/extension-loading-timeout-investigation.md. A host method call + // used to be subject to a hardcoded 10000ms timeout in guest.ts's `host` + // proxy, decoupled from GuestConfig.timeout (which only ever governed the + // initial connectParentWindow handshake, not per-call RPC timeouts). This + // meant any call that legitimately took between 10s and 20s (e.g. because + // the host was still resolving a load batch containing an unrelated + // slow/broken guest) failed with a false "timed out" error, since Port's + // own connection timeout defaults to 20000ms (port.ts's + // defaultOptions.timeout) -- longer than the old 10000ms call ceiling. + // + // The fix: GuestConfig.callTimeout, independent of GuestConfig.timeout, + // defaulting to 20000ms to match Port's default. + it("uses the default 20000ms call timeout, independent of a smaller GuestConfig.timeout (connect timeout)", async () => { // Never resolves/rejects: simulates a host method call that is still // legitimately in flight (e.g. the host is mid-batch loading a sibling // extension) rather than one that has actually failed. const invokeHostMethod = jest.fn(() => new Promise(() => undefined)); - const guest = await connectGuest(invokeHostMethod, { timeout: 20000 }); + // A small connect timeout should have no bearing on the call timeout. + const guest = await connectGuest(invokeHostMethod, { timeout: 5000 }); const callPromise = guest.host.someNamespace.someMethod(); const assertion = expect(callPromise).rejects.toThrow( - "timed out after 10000ms" + "timed out after 20000ms" ); - await jest.advanceTimersByTimeAsync(10001); + await jest.advanceTimersByTimeAsync(20001); await assertion; }); - it("times out a host method call at the same 10000ms with no GuestConfig.timeout set (default config)", async () => { + it("times out a host method call at 20000ms with no config set (default)", async () => { const invokeHostMethod = jest.fn(() => new Promise(() => undefined)); const guest = await connectGuest(invokeHostMethod); const callPromise = guest.host.someNamespace.someMethod(); const assertion = expect(callPromise).rejects.toThrow( - "timed out after 10000ms" + "timed out after 20000ms" ); - await jest.advanceTimersByTimeAsync(10001); + await jest.advanceTimersByTimeAsync(20001); await assertion; }); - it("succeeds when the host responds comfortably inside 10000ms (control case)", async () => { + it("respects an explicit GuestConfig.callTimeout override", async () => { + const invokeHostMethod = jest.fn(() => new Promise(() => undefined)); + const guest = await connectGuest(invokeHostMethod, { callTimeout: 5000 }); + + const callPromise = guest.host.someNamespace.someMethod(); + const assertion = expect(callPromise).rejects.toThrow( + "timed out after 5000ms" + ); + + await jest.advanceTimersByTimeAsync(5001); + await assertion; + }); + + it("succeeds when the host responds comfortably inside the call timeout (control case)", async () => { const invokeHostMethod = jest.fn( () => new Promise((resolve) => setTimeout(() => resolve("ok"), 500)) ); @@ -108,18 +127,9 @@ describe("Guest host-method call timeout", () => { await assertion; }); - // RED TEST -- expected to FAIL until the fix for the extension-loading- - // timeout bug lands (docs/extension-loading-timeout-investigation.md). - // `uix-host`'s Port connection timeout defaults to 20000ms (port.ts's - // defaultOptions.timeout), longer than uix-guest's current hardcoded - // 10000ms call timeout -- so any host method call that legitimately takes - // between 10s and 20s (e.g. because the host is still resolving a load - // batch containing an unrelated slow/broken guest) fails with a false - // "timed out" error today. Once the guest-side call timeout is raised or - // made configurable to be >= 20000ms (or otherwise decoupled from this - // hardcoded value), a call resolving at 12000ms should succeed instead of - // spuriously timing out, and this test will go green with no changes to - // the test itself. + // The scenario from the investigation: a call that resolves at 12000ms -- + // past the old, buggy 10000ms ceiling, but comfortably inside the new + // 20000ms default -- now succeeds instead of spuriously timing out. it("does not time out a call that resolves at 12000ms, past the old 10000ms ceiling", async () => { const invokeHostMethod = jest.fn( () => new Promise((resolve) => setTimeout(() => resolve("ok"), 12000)) diff --git a/packages/uix-guest/src/guest.ts b/packages/uix-guest/src/guest.ts index 9302c580..781ced60 100644 --- a/packages/uix-guest/src/guest.ts +++ b/packages/uix-guest/src/guest.ts @@ -95,6 +95,16 @@ export interface GuestConfig { * Time out and stop trying to reach the host after this many milliseconds */ timeout?: number; + /** + * Time to wait for a single call to a host method to resolve before + * rejecting it as timed out, in milliseconds. Defaults to 20000, matching + * {@link @adobe/uix-host#Port}'s default connection timeout -- keep this + * at or above that value (or the host's configured `guestOptions.timeout`, + * if overridden) so a host that is still legitimately establishing or + * settling a batch of connections doesn't cause an in-flight call from an + * already-connected guest to fail with a false timeout. + */ + callTimeout?: number; } /** @@ -180,6 +190,9 @@ export class Guest< if (typeof config.timeout === "number") { this.timeout = config.timeout; } + if (typeof config.callTimeout === "number") { + this.callTimeout = config.callTimeout; + } if (config.debug) { this.logger = debugGuest(this); } @@ -206,7 +219,7 @@ export class Guest< this.hostConnection.getRemoteApi().invokeHostMethod, address ), - 10000 + this.callTimeout ); return result; } catch (e) { @@ -241,21 +254,10 @@ export class Guest< invoker: RemoteMethodInvoker, address: HostMethodAddress ): Promise { - const final = setTimeout(() => { - return new Promise((resolve, reject) => - reject(`${address} doesn't exist`) - ); - }, 20000); - const res = await this.invokeChecker(invoker, address); - return new Promise((resolve) => { - clearTimeout(final); - return resolve(res); - }).catch((e) => { - clearTimeout(final); - return e; - }); + return this.invokeChecker(invoker, address); } private timeout = 20000; + private callTimeout = 20000; protected hostConnectionPromise: Promise>; protected hostConnection!: CrossRealmObject; /** @internal */ From bfa2d95ed74fd5e9dd5dc167ed202c58f2bd18b8 Mon Sep 17 00:00:00 2001 From: Felix Delval Date: Thu, 24 Sep 2026 12:07:52 +0200 Subject: [PATCH 3/4] fix: resolve uix-guest's new devDependencies against registry.npmjs.org The package-lock.json committed alongside the new uix-guest test infrastructure resolved its freshly-added typescript devDependency through an Adobe-internal Artifactory proxy (a local machine default, not this repo's configured registry -- see .npmrc) at a version Artifactory had never cached. CI's npm ci then failed trying to fetch it through Artifactory with UNABLE_TO_GET_ISSUER_CERT_LOCALLY, since that path isn't what .npmrc/CI actually use. Regenerated by wiping node_modules and running npm ci explicitly against registry.npmjs.org (matching .npmrc), so every entry resolves the way CI expects. Verified: npm ci, build, declarations, and the full unit suite all pass cleanly on the regenerated lockfile. Co-Authored-By: Claude Sonnet 5 --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 5cf6e583..beffd030 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21702,7 +21702,7 @@ }, "packages/uix-guest/node_modules/typescript": { "version": "5.9.3", - "resolved": "https://artifactory.corp.adobe.com/artifactory/api/npm/npm-adobe-release/typescript/-/typescript-5.9.3.tgz", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", @@ -21921,7 +21921,7 @@ }, "typescript": { "version": "5.9.3", - "resolved": "https://artifactory.corp.adobe.com/artifactory/api/npm/npm-adobe-release/typescript/-/typescript-5.9.3.tgz", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz", "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true } From 09759ba6555dbd23a5e09997ff3b8e4698036ae3 Mon Sep 17 00:00:00 2001 From: Felix Delval Date: Fri, 25 Sep 2026 10:07:47 +0200 Subject: [PATCH 4/4] docs: remove references to internal-only investigation doc Comments in guest.test.ts, host.test.ts, and port.test.ts pointed to docs/extension-loading-timeout-investigation.md, which lives in an internal mono repo outside of this open-source repo rather than in this tree. Removed the dangling path references while keeping the surrounding explanatory context intact. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- packages/uix-guest/src/guest.test.ts | 18 +++++++++--------- packages/uix-host/src/host.test.ts | 3 +-- packages/uix-host/src/port.test.ts | 5 ++--- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/packages/uix-guest/src/guest.test.ts b/packages/uix-guest/src/guest.test.ts index 47b0938c..56e8f508 100644 --- a/packages/uix-guest/src/guest.test.ts +++ b/packages/uix-guest/src/guest.test.ts @@ -59,15 +59,15 @@ describe("Guest host-method call timeout", () => { jest.useRealTimers(); }); - // See docs/extension-loading-timeout-investigation.md. A host method call - // used to be subject to a hardcoded 10000ms timeout in guest.ts's `host` - // proxy, decoupled from GuestConfig.timeout (which only ever governed the - // initial connectParentWindow handshake, not per-call RPC timeouts). This - // meant any call that legitimately took between 10s and 20s (e.g. because - // the host was still resolving a load batch containing an unrelated - // slow/broken guest) failed with a false "timed out" error, since Port's - // own connection timeout defaults to 20000ms (port.ts's - // defaultOptions.timeout) -- longer than the old 10000ms call ceiling. + // A host method call used to be subject to a hardcoded 10000ms timeout in + // guest.ts's `host` proxy, decoupled from GuestConfig.timeout (which only + // ever governed the initial connectParentWindow handshake, not per-call + // RPC timeouts). This meant any call that legitimately took between 10s + // and 20s (e.g. because the host was still resolving a load batch + // containing an unrelated slow/broken guest) failed with a false "timed + // out" error, since Port's own connection timeout defaults to 20000ms + // (port.ts's defaultOptions.timeout) -- longer than the old 10000ms call + // ceiling. // // The fix: GuestConfig.callTimeout, independent of GuestConfig.timeout, // defaulting to 20000ms to match Port's default. diff --git a/packages/uix-host/src/host.test.ts b/packages/uix-host/src/host.test.ts index f33aac25..31b2405f 100644 --- a/packages/uix-host/src/host.test.ts +++ b/packages/uix-host/src/host.test.ts @@ -68,8 +68,7 @@ describe("Host guest-loading events", () => { }); // Documents the mechanism that, once consumed correctly, already avoids - // the bug from the extension-loading-timeout investigation - // (docs/extension-loading-timeout-investigation.md): the per-guest + // the bug from the extension-loading-timeout investigation: the per-guest // "guestload" event (and getLoadedGuests()/isReady()) reflect a healthy // guest immediately, without waiting for a broken sibling guest's full // connection timeout. (universal-editor's Api.ts bug was subscribing to diff --git a/packages/uix-host/src/port.test.ts b/packages/uix-host/src/port.test.ts index 7f298cf5..38f91362 100644 --- a/packages/uix-host/src/port.test.ts +++ b/packages/uix-host/src/port.test.ts @@ -160,9 +160,8 @@ describe("Port", () => { }); }); - // Tripwire for the value the extension-loading-timeout investigation - // (docs/extension-loading-timeout-investigation.md) is anchored to: - // uix-guest's per-call RPC timeout needs to be raised to be >= this + // Tripwire for the value the extension-loading-timeout investigation is + // anchored to: uix-guest's per-call RPC timeout needs to be raised to be >= this // default, so a legitimately-slow-but-healthy connection window doesn't // spuriously time out unrelated in-flight host method calls. If this // default ever changes, that guest-side value needs to move with it.