diff --git a/.aoci/baseline.json b/.aoci/baseline.json index 942c403e8..aa1370f37 100644 --- a/.aoci/baseline.json +++ b/.aoci/baseline.json @@ -1,7 +1,7 @@ { "version": 1, "created_at": "2026-11-19T05:53:26Z", - "updated_at": "2026-11-20T10:44:13Z", + "updated_at": "2026-11-20T13:38:12Z", "files": { ".agents/skills/changelog-card-publish/SKILL.md": { "role": "index", @@ -773,9 +773,9 @@ }, "aoci.code.txt": { "role": "index", - "sha256": "a8c909897c9fd56baac348d81d13888fe6a67cface1601909d50041cacd43ff7", - "size": 638265, - "normalized_sha256": "a8c909897c9fd56baac348d81d13888fe6a67cface1601909d50041cacd43ff7" + "sha256": "d3b40b8fc163405aa92f3e6f7d1abccca3e8efd7f93c282c5129282d9ac21283", + "size": 638875, + "normalized_sha256": "d3b40b8fc163405aa92f3e6f7d1abccca3e8efd7f93c282c5129282d9ac21283" }, "aoci.meta.txt": { "role": "index", @@ -24676,9 +24676,9 @@ }, "packages/webui/src/client/features/miniapp/application/miniapp-workflows.ts": { "role": "index", - "sha256": "1b8a1ab8af8178d756664a40fc135b5c5981464cd335e2fa406a62d53dd72974", - "size": 54343, - "normalized_sha256": "1b8a1ab8af8178d756664a40fc135b5c5981464cd335e2fa406a62d53dd72974" + "sha256": "b8919e0a18fb5117afd0e4e6c57d26990219c3ce0d5d45484723ed30812cdeba", + "size": 54643, + "normalized_sha256": "b8919e0a18fb5117afd0e4e6c57d26990219c3ce0d5d45484723ed30812cdeba" }, "packages/webui/src/client/features/miniapp/bindings/use-miniapp-catalogue.public.ts": { "role": "index", @@ -26217,9 +26217,9 @@ }, "packages/webui/src/client/platform/event-channel.ts": { "role": "index", - "sha256": "fae86f2709bfc7b79babb225d00591b93a8a963883b81165e41c012f690595a7", - "size": 24078, - "normalized_sha256": "fae86f2709bfc7b79babb225d00591b93a8a963883b81165e41c012f690595a7" + "sha256": "aaa819d1d116843220db7f4a9bdbb8896f565731ccff39b6cbcfada33c123b08", + "size": 24114, + "normalized_sha256": "aaa819d1d116843220db7f4a9bdbb8896f565731ccff39b6cbcfada33c123b08" }, "packages/webui/src/client/platform/miniapp-frame-url.ts": { "role": "index", @@ -26295,9 +26295,9 @@ }, "packages/webui/src/client/platform/wire.ts": { "role": "index", - "sha256": "8a53501fb7ce146941d81fdea485859d981e1439271be3eaecd36e509ada6cf7", - "size": 38361, - "normalized_sha256": "8a53501fb7ce146941d81fdea485859d981e1439271be3eaecd36e509ada6cf7" + "sha256": "8ee603cab0f2fdf669ffba8f74187fd57676476b18ceadfb4c888adf527567a0", + "size": 38379, + "normalized_sha256": "8ee603cab0f2fdf669ffba8f74187fd57676476b18ceadfb4c888adf527567a0" }, "packages/webui/src/client/projection/common/context-menu.ts": { "role": "index", @@ -27908,9 +27908,9 @@ }, "packages/webui/src/server/operation/operation-dispatch.ts": { "role": "index", - "sha256": "03c1a80198e1a7a64d1951bd0f5effabe8827a2b20e602cbd069436485c55722", - "size": 6817, - "normalized_sha256": "03c1a80198e1a7a64d1951bd0f5effabe8827a2b20e602cbd069436485c55722" + "sha256": "f069d78ac61b888848e2c6824b6ddb5c1eb3dc922c0628beb2a77e3f28c0d5cf", + "size": 7610, + "normalized_sha256": "f069d78ac61b888848e2c6824b6ddb5c1eb3dc922c0628beb2a77e3f28c0d5cf" }, "packages/webui/src/server/operation/operations.ts": { "role": "index", @@ -28346,9 +28346,9 @@ }, "packages/webui/src/shared/envelope.ts": { "role": "index", - "sha256": "98044229fce3336f71eedc0d377a1bc80381969a26772dd274602e89d887fe3e", - "size": 10158, - "normalized_sha256": "98044229fce3336f71eedc0d377a1bc80381969a26772dd274602e89d887fe3e" + "sha256": "2fa53f2fe61ddd8813593efd076d6187279350001f9de5a4bcd2f78c011cfe30", + "size": 10391, + "normalized_sha256": "2fa53f2fe61ddd8813593efd076d6187279350001f9de5a4bcd2f78c011cfe30" }, "packages/webui/src/shared/operation-codecs.ts": { "role": "index", @@ -29462,9 +29462,9 @@ }, "packages/webui/test/integration/miniapp-real-flow.test.ts": { "role": "observe", - "sha256": "b25bdbed07987d6c1538d449164a355c83145dcec1fe392965b0dee0bd0538df", - "size": 10215, - "normalized_sha256": "b25bdbed07987d6c1538d449164a355c83145dcec1fe392965b0dee0bd0538df" + "sha256": "dce9b2952cc6327ad0cd3644207fcb64d458dbcfd45fe8607bcaf3fda5c12e30", + "size": 11867, + "normalized_sha256": "dce9b2952cc6327ad0cd3644207fcb64d458dbcfd45fe8607bcaf3fda5c12e30" }, "packages/webui/test/integration/miniapp-ui-flow.test.ts": { "role": "observe", @@ -30104,9 +30104,9 @@ }, "packages/webui/test/unit/miniapp-client-state.test.ts": { "role": "observe", - "sha256": "5258988f815dd7da3526f29649385cd9d39a6f1ed81743f7500d3db1c90c87fc", - "size": 21759, - "normalized_sha256": "5258988f815dd7da3526f29649385cd9d39a6f1ed81743f7500d3db1c90c87fc" + "sha256": "8424fe8d741cef4115011c1cbb88a6b607621b4058f99696d7336d61a0590f5a", + "size": 22008, + "normalized_sha256": "8424fe8d741cef4115011c1cbb88a6b607621b4058f99696d7336d61a0590f5a" }, "packages/webui/test/unit/miniapp-operations.test.ts": { "role": "observe", @@ -31100,9 +31100,9 @@ }, "packages/webui/test/unit/webui-transport-wire.test.ts": { "role": "observe", - "sha256": "4d9e5b0ad87ad203d683b024d2c6c4c56fca16f5565e9df396ba0aee393a5362", - "size": 33999, - "normalized_sha256": "4d9e5b0ad87ad203d683b024d2c6c4c56fca16f5565e9df396ba0aee393a5362" + "sha256": "793d0ab954ed7e9c0dc897dbde379d4deb20d2c2259fb7df0227e6e8bb89b827", + "size": 34703, + "normalized_sha256": "793d0ab954ed7e9c0dc897dbde379d4deb20d2c2259fb7df0227e6e8bb89b827" }, "packages/webui/test/unit/webui-unary-operation-typing.test.ts": { "role": "observe", @@ -31148,9 +31148,9 @@ }, "packages/webui/test/unit/webui-wire-envelope.test.ts": { "role": "observe", - "sha256": "5b570c3d47c613becb621bc7447ca6f075aff96fa17da8a6cd7185c534f49e38", - "size": 10190, - "normalized_sha256": "5b570c3d47c613becb621bc7447ca6f075aff96fa17da8a6cd7185c534f49e38" + "sha256": "aa62fbfeba2cc0ba43bbfa9ba62d7a8a6c352dc3d0ac5d50e17d37b8e11c4228", + "size": 11014, + "normalized_sha256": "aa62fbfeba2cc0ba43bbfa9ba62d7a8a6c352dc3d0ac5d50e17d37b8e11c4228" }, "packages/webui/test/unit/webui-workspace-archive.test.ts": { "role": "observe", diff --git a/aoci.code.txt b/aoci.code.txt index bd7ab8755..5ffb0f3b2 100644 --- a/aoci.code.txt +++ b/aoci.code.txt @@ -4873,7 +4873,7 @@ miniapp-agent-bridge.ts[SE4L]: F:Bridges Mini App requests to agent operations. miniapp-bridge.ts[SE4S]: F:Constructs Mini App bridge requests. | R:- | A:- | S:- miniapp-tool-bridge.ts[SE4T]: F:Bridges Mini App tool calls through the client tool port. | R:- | A:- | S:- miniapp-window-bridge.ts[SE4T]: F:Defines Mini App window request messages and bridges window operations. | R:- | A:- | S:- -miniapp-workflows.ts[SE4L]: F:Coordinates Mini App workflows through a client port slice. | R:- | A:- | S:- +miniapp-workflows.ts[SE4L]: F:Coordinates Mini App workflows and maps preparation refusal details to client state. | R:code:packages/webui/src/shared/envelope.ts | A:- | S:Only a preparation failure with OWNED_ELSEWHERE is promoted to the takeover refusal code. ===//packages/webui/src/client/features/miniapp/bindings/=== use-miniapp-catalogue.public.ts[SE4T]: F:Exposes Mini App catalogue summaries to React consumers. | R:- | A:- | S:- @@ -5250,7 +5250,7 @@ app-mode.ts[SE4T]: F:Defines coding and work application modes. | R:- | A:- | S: browser-auto-open.ts[SE4T]: F:Persists the browser auto-open preference. | R:- | A:- | S:- browser-dom.ts[SE4L]: F:Provides browser drawing helpers and exports canvas and image types. | R:- | A:- | S:- connection-health.ts[SE4S]: F:Provides connection health helpers including unref for timers. | R:- | A:- | S:- -event-channel.ts[SE4L]: F:Adapts and exposes client event watching for the browser. | R:- | A:- | S:- +event-channel.ts[SE4L]: F:Defines WebUI socket and wire frame contracts, including optional refusal reason codes, and adapts event watching. | R:code:packages/webui/src/shared/envelope.ts | A:- | S:- miniapp-frame-url.ts[SE4T]: F:Builds the URL for a Mini App frame. | R:- | A:- | S:- no-project.ts[SE4T]: F:Recognizes the flag for a session without a project. | R:- | A:- | S:- page-host.ts[SE4T]: F:Reads the hostname of the hosting page. | R:- | A:- | S:- @@ -5263,7 +5263,7 @@ team-mode.ts[SE4T]: F:Models and resolves team mode for sessions. | R:- | A:- | transport-origin.ts[SE4T]: F:Converts WebSocket URLs to HTTP transport origins. | R:- | A:- | S:- transport.ts[SE4L]: F:Implements the browser transport over the WebUI wire. | R:- | A:- | S:- webui-shutdown.ts[SE4T]: F:Requests WebUI service shutdown and reports refusals. | R:- | A:- | S:- -wire.ts[SE4L]: F:Defines and implements the WebSocket wire and its options. | R:- | A:- | S:- +wire.ts[SE4L]: F:Manages the browser WebSocket wire and preserves refusal codes when rejecting a pending request. | R:code:packages/webui/src/shared/envelope.ts | A:- | S:- ===//packages/webui/src/client/projection/common/=== context-menu.ts[SE4T]: F:Places browser context menus relative to the viewport. | R:- | A:- | S:- @@ -5560,7 +5560,7 @@ messages.ts[SE4S]: F:Defines message history retrieval. | R:- | A:- | S:- miniapp-agent.ts[SE4S]: F:Defines Mini App agent turn operations. | R:- | A:- | S:- miniapp.ts[SE4M]: F:Defines Mini App catalogue and runtime operations. | R:- | A:- | S:- operation-contract.ts[SE4S]: F:Defines server operation and context contracts. | R:- | A:- | S:- -operation-dispatch.ts[SE4M]: F:Dispatches WebUI transport frames to operations. | R:- | A:- | S:- +operation-dispatch.ts[SE4M]: F:Dispatches WebUI frames and carries validated Mini App preparation refusal reasons back to the caller. | R:code:packages/webui/src/shared/envelope.ts | A:- | S:Surfaces reasonCode only for open Mini App preparation failures, using a bounded uppercase identifier. operations.ts[SE4L]: F:Exports the server operation catalogue. | R:- | A:- | S:- permission-mode.ts[SE4T]: F:Defines permission mode operations. | R:- | A:- | S:- personalization.ts[SE4T]: F:Defines personalization and global instructions operations. | R:- | A:- | S:- @@ -5598,7 +5598,7 @@ usage.ts[SE4T]: F:Projects turn usage and identifies compaction messages. | R:- account-legal-links.ts[SE4T]: F:Resolves account legal links by scope. | R:- | A:- | S:- capability-manifest.ts[SE4M]: F:Enumerates capabilities exposed by the WebUI. | R:- | A:- | S:- design-input.ts[SE4T]: F:Validates Design input and caps media bytes. | R:- | A:- | S:- -envelope.ts[SE4M]: F:Defines the versioned WebUI transport envelope. | R:- | A:- | S:- +envelope.ts[SE4M]: F:Defines and decodes versioned WebUI frames and request errors with an optional refusal reason. | R:- | A:WebuiWireError,decodeWebuiServerFrame | S:- operation-codecs.ts[SE4M]: F:Defines result codecs for WebUI operations. | R:- | A:- | S:- operation-names.ts[SE4L]: F:Enumerates operation names used by the WebUI protocol. | R:- | A:- | S:- plugin-management.ts[SE4T]: F:Defines plugin management action payloads. | R:- | A:- | S:- diff --git a/packages/webui/src/client/features/miniapp/application/miniapp-workflows.ts b/packages/webui/src/client/features/miniapp/application/miniapp-workflows.ts index 07831a6da..683ffb2e3 100644 --- a/packages/webui/src/client/features/miniapp/application/miniapp-workflows.ts +++ b/packages/webui/src/client/features/miniapp/application/miniapp-workflows.ts @@ -221,9 +221,13 @@ function refusalOf(error: unknown): WebuiMiniAppRefusal { error && typeof error === "object" && typeof (error as { code?: unknown }).code === "string" ? ((error as { code: string }).code) : "harness_error"; + const message = error instanceof Error ? error.message : String(error); + const reasonCode = code === "MINIAPP_PREPARATION_FAILED" && error instanceof Error + ? (error as { reasonCode?: unknown }).reasonCode + : undefined; return { - code, - message: error instanceof Error ? error.message : String(error), + code: reasonCode === "OWNED_ELSEWHERE" ? reasonCode : code, + message: typeof reasonCode === "string" ? `${message} (${reasonCode})` : message, }; } diff --git a/packages/webui/src/client/platform/event-channel.ts b/packages/webui/src/client/platform/event-channel.ts index 7c857c459..c22c24bc4 100644 --- a/packages/webui/src/client/platform/event-channel.ts +++ b/packages/webui/src/client/platform/event-channel.ts @@ -78,6 +78,7 @@ export type WireFrame = readonly requestId: string; readonly code: WebuiWireErrorCode; readonly message: string; + readonly reasonCode?: string; }; export interface WebuiSocket { diff --git a/packages/webui/src/client/platform/wire.ts b/packages/webui/src/client/platform/wire.ts index 23775b5b9..f2db1af49 100644 --- a/packages/webui/src/client/platform/wire.ts +++ b/packages/webui/src/client/platform/wire.ts @@ -467,7 +467,7 @@ export function createWebuiWire({ // stable code intact instead of turning every refusal into one shape. fail( session, - new WebuiWireError(frame.code, frame.message, frame.requestId), + new WebuiWireError(frame.code, frame.message, frame.requestId, frame.reasonCode), ); return; } diff --git a/packages/webui/src/server/operation/operation-dispatch.ts b/packages/webui/src/server/operation/operation-dispatch.ts index 8ca728e00..bfe0c0663 100644 --- a/packages/webui/src/server/operation/operation-dispatch.ts +++ b/packages/webui/src/server/operation/operation-dispatch.ts @@ -9,6 +9,7 @@ import { type WebuiWireErrorCode, } from "../../shared/envelope.js"; import type { WebuiOperationRegistryEntry } from "./operations.js"; +import { OPEN_MINI_APP_OPERATION_NAME } from "../../shared/operation-names.js"; /** * The stable code a thrown failure carries, if it names one. @@ -150,11 +151,23 @@ export async function dispatchWebuiFrame( sendFrame(ws, responseFrame(parsed.requestId, result.body)); } catch (error) { const message = error instanceof Error ? error.message : String(error); + const code = stableCodeOf(error); + const miniAppPreparationFailed = parsed.operation === OPEN_MINI_APP_OPERATION_NAME && + code === "MINIAPP_PREPARATION_FAILED"; + let reasonCode: string | undefined; + if (miniAppPreparationFailed) { + const reason = (error as { reasonCode?: unknown }).reasonCode ?? + (error instanceof Error ? stableCodeOf(error.cause) : undefined); + if (typeof reason === "string" && /^[A-Z][A-Z0-9_]{0,63}$/u.test(reason)) { + reasonCode = reason; + } + console.warn("[webui] Mini App publication preparation failed", { code, reasonCode }); + } // The capability's own stable code is preserved; only a failure that names // no code at all becomes `harness_error`. sendFrame( ws, - errorFrame(parsed.requestId, stableCodeOf(error), message), + errorFrame(parsed.requestId, code, message, reasonCode), ); } } @@ -201,6 +214,7 @@ export function errorFrame( requestId: string, code: string, message: string, + reasonCode?: string, ): WebuiErrorFrame { return { protocolVersion: WEBUI_PROTOCOL_VERSION, @@ -208,5 +222,6 @@ export function errorFrame( requestId, code, message, + ...(reasonCode !== undefined ? { reasonCode } : {}), }; } diff --git a/packages/webui/src/shared/envelope.ts b/packages/webui/src/shared/envelope.ts index 7fe6c977e..ece8507bb 100644 --- a/packages/webui/src/shared/envelope.ts +++ b/packages/webui/src/shared/envelope.ts @@ -49,6 +49,7 @@ export interface WebuiErrorFrame { readonly requestId: string; readonly code: string; readonly message: string; + readonly reasonCode?: string; } export interface WebuiEventFrame { @@ -218,6 +219,7 @@ export function decodeWebuiServerFrame(text: string): WebuiFrameDecode { requestId: candidate.requestId, code: candidate.code, message: candidate.message, + ...(typeof candidate.reasonCode === "string" ? { reasonCode: candidate.reasonCode } : {}), }, }; } @@ -245,16 +247,19 @@ export class WebuiWireError extends Error { readonly code: WebuiWireErrorCode; /** The request this refusal answers, or {@link WEBUI_ANONYMOUS_REQUEST_ID} for one that could not be attributed. */ readonly requestId: string; + readonly reasonCode: string | undefined; constructor( code: WebuiWireErrorCode, message: string, requestId: string = WEBUI_ANONYMOUS_REQUEST_ID, + reasonCode?: string, ) { super(message); this.name = "WebuiWireError"; this.code = code; this.requestId = requestId; + this.reasonCode = reasonCode; } } diff --git a/packages/webui/test/integration/miniapp-real-flow.test.ts b/packages/webui/test/integration/miniapp-real-flow.test.ts index 17d28ff11..35d666a09 100644 --- a/packages/webui/test/integration/miniapp-real-flow.test.ts +++ b/packages/webui/test/integration/miniapp-real-flow.test.ts @@ -32,7 +32,10 @@ // is `miniapp-ui-flow.test.ts`. The data directory is a temporary one, so a // run can never reach the operator's own `~/.minimax`. +import { mkdir } from "node:fs/promises"; +import { join } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; +import { acquireMiniAppOwner } from "../../../local-runtime-v2/src/service/miniapp/process/node-runtime/owner-lease.js"; import { LOCAL_SOURCE, @@ -135,6 +138,40 @@ describe("the Mini App business flow against the real host", () => { expect(rowsOf(await client.call("listMiniApps"))).toEqual([]); }, 60_000); + it("reports another client's ownership and opens after that client releases the lease", async () => { + const host = await bootRealHost(); + const client = await connect(host.url); + const name = "ownership-flow.miniapp"; + await publishLocalPackage(host.dataDir, name); + expectAnswered(await client.call("pluginManagement", { + action: "enablePlugin", + input: { pluginName: name, source: LOCAL_SOURCE }, + })); + const pluginDataDir = join(host.dataDir, "v2", "plugin-data", "liveboards", name); + await mkdir(pluginDataDir, { recursive: true }); + const owner = await acquireMiniAppOwner({ + pluginDataDir, + pluginId: name, + identity: { client: "desktop" }, + }); + if (owner.kind !== "acquired") throw new Error("The fixture could not acquire the ownership lease"); + try { + const refused = await client.call("openMiniApp", { pluginId: name }); + expect(refused).toMatchObject({ + kind: "error", + code: "MINIAPP_PREPARATION_FAILED", + reasonCode: "OWNED_ELSEWHERE", + }); + } finally { + await owner.release(); + } + const opened = await client.call("openMiniApp", { pluginId: name }); + expectAnswered(opened); + const page = await fetch(String(bodyOf(opened).viewUrl)); + expect(page.status).toBe(200); + expect(await page.text()).toContain(PAGE_MARKER); + }, 120_000); + it("keeps a Mini App that failed to start out of the running set", async () => { const host = await bootRealHost(); const client = await connect(host.url); @@ -161,6 +198,7 @@ describe("the Mini App business flow against the real host", () => { // person has to act on: the entry refused to start. const cause = await openCause(host, name); expect(cause.join(" <- ")).toContain("RUNNER_START_FAILED"); + expect(opened.reasonCode, cause.join(" <- ")).toBe("RUNNER_START_FAILED"); // And the Mini App is not left claiming to be running: the row says the // start failed, and names the reason, instead of reading as a Mini App diff --git a/packages/webui/test/unit/miniapp-client-state.test.ts b/packages/webui/test/unit/miniapp-client-state.test.ts index 7c2aedd7a..97f42ac24 100644 --- a/packages/webui/test/unit/miniapp-client-state.test.ts +++ b/packages/webui/test/unit/miniapp-client-state.test.ts @@ -360,33 +360,38 @@ describe("the Mini App business", () => { expect(workflows.getSnapshot().presentations.fourth?.kind).toBe("open"); }); - it("reports an app another client owns, naming that client, in both surfaces' state", async () => { - const port = scriptedPort({ - miniApps: [miniApp("shared-app", "stopped")], - open: async () => { - throw Object.assign( - new Error("Mini App shared-app is already running in electron (pid 4242)"), - { code: "OWNED_ELSEWHERE" }, - ); - }, - }); - const workflows = createWebuiMiniAppWorkflows({ port }); - await workflows.loadListing(); - expect(await workflows.open("shared-app")).toBe(false); - - const snapshot = workflows.getSnapshot(); - const refusal = snapshot.refusals["shared-app"]; - expect(refusal?.code).toBe("OWNED_ELSEWHERE"); - const text = webuiMiniAppRefusalText({ - code: refusal!.code, - message: refusal!.message, - rows: snapshot.listing.rows, - }); - // Keep diagnostics while presenting a neutral client name. - expect(text).not.toContain("electron"); - expect(text).toContain("4242"); - expect(snapshot.presentations["shared-app"]).toBeUndefined(); - }); + it.each(["OWNED_ELSEWHERE", "MINIAPP_PREPARATION_FAILED"])( + "reports an app another client owns when the runtime returns %s", + async (code) => { + const wrapped = code === "MINIAPP_PREPARATION_FAILED"; + const port = scriptedPort({ + miniApps: [miniApp("shared-app", "stopped")], + open: async () => { + throw Object.assign( + new Error(wrapped + ? "Mini App publication preparation failed" + : "Mini App shared-app is already running in electron (pid 4242)"), + { code, ...(wrapped ? { reasonCode: "OWNED_ELSEWHERE" } : {}) }, + ); + }, + }); + const workflows = createWebuiMiniAppWorkflows({ port }); + await workflows.loadListing(); + expect(await workflows.open("shared-app")).toBe(false); + + const snapshot = workflows.getSnapshot(); + const refusal = snapshot.refusals["shared-app"]; + expect(refusal?.code).toBe("OWNED_ELSEWHERE"); + const text = webuiMiniAppRefusalText({ + code: refusal!.code, + message: refusal!.message, + rows: snapshot.listing.rows, + }); + expect(text).not.toContain("electron"); + expect(text).toContain(wrapped ? "OWNED_ELSEWHERE" : "4242"); + expect(snapshot.presentations["shared-app"]).toBeUndefined(); + }, + ); it("offers to stop a Mini App another client is running", () => { const rows = webuiMiniAppRows([ diff --git a/packages/webui/test/unit/webui-transport-wire.test.ts b/packages/webui/test/unit/webui-transport-wire.test.ts index 4935a9159..53731d5eb 100644 --- a/packages/webui/test/unit/webui-transport-wire.test.ts +++ b/packages/webui/test/unit/webui-transport-wire.test.ts @@ -664,6 +664,26 @@ describe("an inbound frame is judged before it is believed", () => { ); }); + it("carries the Mini App preparation reason to the request caller", async () => { + const transport = transportWith(ControllableSocket); + const pending = transport.openMiniApp!({ pluginId: "fixture" }); + const refused = expect(pending).rejects.toMatchObject({ + code: "MINIAPP_PREPARATION_FAILED", + reasonCode: "OWNED_ELSEWHERE", + }); + await tick(); + const socket = ControllableSocket.latest!; + socket.deliver({ + protocolVersion: 1, + kind: "error", + requestId: socket.request.requestId, + code: "MINIAPP_PREPARATION_FAILED", + message: "Mini App publication preparation failed", + reasonCode: "OWNED_ELSEWHERE", + }); + await refused; + }); + it("refuses a frame from a different protocol version instead of reading it as an answer", async () => { // The client used to `JSON.parse(...) as WireFrame` and check nothing else, // so a frame from a service speaking another version was accepted as though diff --git a/packages/webui/test/unit/webui-wire-envelope.test.ts b/packages/webui/test/unit/webui-wire-envelope.test.ts index f658637f3..ea22ba1e6 100644 --- a/packages/webui/test/unit/webui-wire-envelope.test.ts +++ b/packages/webui/test/unit/webui-wire-envelope.test.ts @@ -34,6 +34,26 @@ function socket(): { readyState: number; OPEN: number; sent: string[]; send(payl } describe("the service judges an inbound frame", () => { + it("preserves the reason of a Mini App publication refusal", async () => { + const ws = socket(); + const entry = { + operation: { validate: () => ({ ok: true, body: {} }) }, + handle: async () => { + throw Object.assign(new Error("Mini App publication preparation failed"), { + code: "MINIAPP_PREPARATION_FAILED", + reasonCode: "OWNED_ELSEWHERE", + }); + }, + } as unknown as WebuiOperationRegistryEntry; + await dispatchWebuiFrame(ws as unknown as WebSocket, + { protocolVersion: 1, kind: "request", requestId: "open", operation: "openMiniApp", body: {} }, + new Map([["openMiniApp", entry]]), true, () => undefined); + expect(JSON.parse(ws.sent[0]!)).toMatchObject({ + code: "MINIAPP_PREPARATION_FAILED", + reasonCode: "OWNED_ELSEWHERE", + }); + }); + it("observes a rejecting finalizer once when abort interrupts a parked pull", async () => { const ws = socket(); const controller = new AbortController();