test(backend): pin schema-linking structured response passthrough

This commit is contained in:
2026-07-06 23:25:00 +02:00
committed by Marco Pancotti
parent bd63e3194f
commit ad5a4d938c
@@ -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();
});