Files
pi-goals/test/intercom-fixture.ts
T
wassname 489298d58b Replace supervision mailbox polling with pi-intercom
Scope messages to each pairing, wait for supervisor readiness, retain instructions in session history until acknowledgment, and rejoin after disconnect. Reuse installed Intercom or load the package dependency. Validate over an isolated real broker; existing user panes are untouched.
2026-09-08 16:31:58 +08:00

27 lines
955 B
TypeScript

export function intercomFixture() {
let registration: any;
const sent: any[] = [];
let connected = true;
const receive = (payload: any, fromSessionId = "peer") => registration.onEvent({ type: "message", fromSessionId, payload });
return {
sent, receive,
event: (event: any) => registration.onEvent(event),
connect: (value: boolean) => { connected = value; registration.onEvent({ type: "connection", connected: value, supported: true }); },
events: {
on: () => () => {},
emit: (name: string, value: any) => {
if (name !== "intercom:extension-register") return false;
registration = value;
value.onReady({
snapshot: () => ({ connected, supported: true }),
publish: (message: any) => {
sent.push(message);
if (message.kind === "hello") queueMicrotask(() => receive({ ...message, role: message.role === "worker" ? "supervisor" : "worker", ready: true }));
},
});
return true;
},
},
};
}