mirror of
https://github.com/wassname/pi-plan.git
synced 2026-09-26 14:10:23 +08:00
Use explicit hello requests and replies, keep workers unready until model restoration succeeds, distinguish paused peers, and align all goal readers at the Log boundary. Add two-real-adapter handshake and failed-Ready/clear-during-wait regressions; warn once for unavailable supervisor context usage.
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
// Wire two real GoalIntercom adapters. This router never invents hello replies.
|
|
export function pairedIntercomFixture() {
|
|
const receivers = new Map<string, (event: any) => void>();
|
|
const endpoint = (id: string, peer: string) => {
|
|
const sent: any[] = [];
|
|
let connected = true;
|
|
const transport = {
|
|
sent,
|
|
drop: (_message: any) => false,
|
|
connect: (value: boolean) => { connected = value; receivers.get(id)?.({ type: "connection", connected: value, supported: true }); },
|
|
events: {
|
|
on: () => () => {},
|
|
emit: (name: string, registration: any) => {
|
|
if (name !== "intercom:extension-register") return false;
|
|
receivers.set(id, registration.onEvent);
|
|
registration.onReady({
|
|
snapshot: () => ({ connected, supported: true }),
|
|
publish: (message: any) => {
|
|
sent.push(message);
|
|
if (sent.length > 200) throw new Error("Handshake did not settle; possible hello loop.");
|
|
if (connected && !transport.drop(message)) queueMicrotask(() => receivers.get(peer)?.({ type: "message", fromSessionId: id, payload: message }));
|
|
},
|
|
});
|
|
return true;
|
|
},
|
|
},
|
|
};
|
|
return transport;
|
|
};
|
|
return { worker: endpoint("worker", "supervisor"), supervisor: endpoint("supervisor", "worker") };
|
|
}
|