From ad5a4d938c3142fd2251677948a1dac639770479 Mon Sep 17 00:00:00 2001 From: mptyl Date: Mon, 6 Jul 2026 19:26:07 +0200 Subject: [PATCH] test(backend): pin schema-linking structured response passthrough --- .../test/schema-linking-passthrough.test.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 backend/test/schema-linking-passthrough.test.ts diff --git a/backend/test/schema-linking-passthrough.test.ts b/backend/test/schema-linking-passthrough.test.ts new file mode 100644 index 00000000..74aac7b4 --- /dev/null +++ b/backend/test/schema-linking-passthrough.test.ts @@ -0,0 +1,35 @@ +import { test, expect, vi } from "vitest"; +import { SessionBridge } from "../src/bridge/session-bridge.js"; + +function fakeRpc() { + const sent: any[] = []; + let evcb: any; + return { + rpc: { + send: (c: any) => sent.push(c), + on: (_: any, cb: any) => { evcb = cb; }, + request: vi.fn(), + } as any, + sent, + fire: (m: any) => evcb(m), + }; +} + +test("respond forwards the structured schema-linking tables payload to Pi verbatim", () => { + const { rpc, sent, fire } = fakeRpc(); + const b = new SessionBridge(rpc); + // Pi emits the ui request with its own RPC id ("pi-123"); the descriptor in the title + // carries the gate's own id ("u7"), matching the structured response below. + fire({ type: "extension_ui_request", id: "pi-123", method: "input", title: JSON.stringify({ id: "u7", widget: "schema-linking" }) }); + + const resp = { id: "u7", kind: "schema-linking", tables: [{ id: "t1", enacted: true, columns: ["cod_paz"] }] }; + b.respond(resp); + + // Correlates on Pi's own id, and JSON.stringifies the whole structured object untouched. + expect(sent.at(-1)).toEqual({ + type: "extension_ui_response", + id: "pi-123", + value: JSON.stringify(resp), + }); + expect(b.pendingWidget()).toBeNull(); +});