fix(tui): synchronize shared session clients
This commit is contained in:
@@ -71,6 +71,35 @@ afterEach(() => {
|
||||
});
|
||||
|
||||
describe("NanobotClient", () => {
|
||||
it("reconciles simultaneous client submissions to the gateway-owned turn", () => {
|
||||
const client = new NanobotClient({
|
||||
url: "ws://test",
|
||||
reconnect: false,
|
||||
socketFactory: (url) => new FakeSocket(url) as unknown as WebSocket,
|
||||
});
|
||||
client.connect();
|
||||
const socket = lastSocket();
|
||||
socket.fakeOpen();
|
||||
|
||||
client.sendMessage("shared-chat", "from terminal B", undefined, {
|
||||
turnId: "turn-b",
|
||||
});
|
||||
expect(client.getRunTurnId("shared-chat")).toBe("turn-b");
|
||||
|
||||
socket.fakeMessage({
|
||||
event: "message_accepted",
|
||||
chat_id: "shared-chat",
|
||||
turn_id: "turn-b",
|
||||
active_turn_id: "turn-a",
|
||||
starts_turn: false,
|
||||
started_at: 1_700_000_000,
|
||||
});
|
||||
|
||||
expect(client.getRunTurnId("shared-chat")).toBe("turn-a");
|
||||
expect(client.getRunStartedAt("shared-chat")).toBe(1_700_000_000);
|
||||
expect(client.hasUnsettledRun("shared-chat")).toBe(true);
|
||||
});
|
||||
|
||||
it("correlates successful WebUI mutation replies by request id", async () => {
|
||||
const client = new NanobotClient({
|
||||
url: "ws://test",
|
||||
|
||||
@@ -1869,6 +1869,56 @@ describe("useNanobotStream", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("projects a user turn submitted from another attached client exactly once", () => {
|
||||
const fake = fakeClient();
|
||||
const { result } = renderHook(
|
||||
() => useNanobotStream("chat-shared", EMPTY_MESSAGES),
|
||||
{ wrapper: wrap(fake.client) },
|
||||
);
|
||||
const event: InboundEvent = {
|
||||
event: "user_message",
|
||||
chat_id: "chat-shared",
|
||||
text: "hello from terminal A",
|
||||
turn_id: "remote-turn",
|
||||
active_turn_id: "remote-turn",
|
||||
starts_turn: true,
|
||||
started_at: 1_700_000_000,
|
||||
media_urls: [{ kind: "file", url: "/api/media/sig/report", name: "report.pdf" }],
|
||||
cli_apps: [{ name: "drawio", display_name: "Draw.io" }],
|
||||
mcp_presets: [{ name: "github", display_name: "GitHub" }],
|
||||
session_mentions: [{
|
||||
name: "pricing",
|
||||
session_key: "websocket:pricing",
|
||||
title: "Pricing",
|
||||
}],
|
||||
};
|
||||
|
||||
act(() => {
|
||||
fake.emit("chat-shared", event);
|
||||
fake.emit("chat-shared", event);
|
||||
});
|
||||
|
||||
expect(result.current.messages).toEqual([
|
||||
expect.objectContaining({
|
||||
role: "user",
|
||||
content: "hello from terminal A",
|
||||
turnId: "remote-turn",
|
||||
deliveryStatus: "accepted",
|
||||
createdAt: expect.any(Number),
|
||||
media: [{ kind: "file", url: "/api/media/sig/report", name: "report.pdf" }],
|
||||
cliApps: [{ name: "drawio", display_name: "Draw.io" }],
|
||||
mcpPresets: [{ name: "github", display_name: "GitHub" }],
|
||||
sessionMentions: [{
|
||||
name: "pricing",
|
||||
session_key: "websocket:pricing",
|
||||
title: "Pricing",
|
||||
}],
|
||||
}),
|
||||
]);
|
||||
expect(result.current.isStreaming).toBe(true);
|
||||
expect(result.current.runStartedAt).toBe(1_700_000_000);
|
||||
});
|
||||
|
||||
it("marks only the optimistic turn named by a correlated rejection as failed", () => {
|
||||
const fake = fakeClient();
|
||||
const { result } = renderHook(
|
||||
|
||||
Reference in New Issue
Block a user