@wherever-dev/client 0.2.2 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts CHANGED
@@ -9,6 +9,26 @@ export interface ChatMessage {
9
9
  toolArgs?: string;
10
10
  toolOutput?: string;
11
11
  isError?: boolean;
12
+ // Wall-clock start of a tool call (ms epoch), set when the tool_start frame
13
+ // arrives. `timestamp` also carries this, but startedAt is kept explicit so
14
+ // the elapsed/took duration is unambiguous and survives content rewrites.
15
+ startedAt?: number;
16
+ // Wall-clock end of a tool call (ms epoch), set when tool_end arrives. While a
17
+ // tool is running this is undefined and the UI ticks a live "Elapsed N.Ns";
18
+ // once set the UI freezes it as "Took N.Ns" (mirrors the pi CLI).
19
+ endedAt?: number;
20
+ // Delivery state for an OUTBOUND user message. A frame handed to a socket that
21
+ // reports OPEN can still never reach the server (a half-open TCP connection:
22
+ // send() buffers locally, no throw, but the bytes never land). So an optimistic
23
+ // echo is NOT proof of delivery. `delivery` tracks that:
24
+ // 'sending' -> handed to the socket, awaiting the server's echo.
25
+ // 'failed' -> no echo within the confirmation window; delivery is
26
+ // uncertain, so the UI surfaces a retry affordance rather than
27
+ // a normal-looking sent message.
28
+ // Undefined = confirmed/delivered (or a message that never needed tracking,
29
+ // e.g. one loaded from server history). Confirmed on the server's user echo
30
+ // (message_end role:user) or when it reappears in loaded history.
31
+ delivery?: 'sending' | 'failed';
12
32
  }
13
33
 
14
34
  export interface ConflictInfo {
@@ -31,6 +51,13 @@ export interface WhereverState {
31
51
  // messages remain visible; the UI shows a "reconnecting/syncing" affordance
32
52
  // and blocks input until the resync completes.
33
53
  resyncing: boolean;
54
+ // True after a `pending` session_created (history painted from a cheap read)
55
+ // until session_ready arrives (the live agent finished building). The
56
+ // conversation is READABLE during this window, but SENDING must be blocked:
57
+ // reading only needs the transcript, sending needs the live agent. Distinct
58
+ // from loadingSession/resyncing, which gate the whole view; agentPending gates
59
+ // only the composer so opening a cold session to read is instant.
60
+ agentPending: boolean;
34
61
  error: string | null;
35
62
  session: string | null;
36
63
  sessionId: string | null;
@@ -0,0 +1,107 @@
1
+ import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
2
+ import {get} from 'sveltore';
3
+ import {WhereverClient} from '../src/client.js';
4
+ import {makeWSFactory} from './harness.js';
5
+
6
+ // Fast-first load reducer contract: a `pending` session_created paints history
7
+ // but keeps the composer blocked (agentPending) until session_ready; a
8
+ // non-pending create is immediately sendable; a session_error while pending
9
+ // degrades to readable-but-not-sendable.
10
+
11
+ describe('agentPending (fast-first load)', () => {
12
+ let ws: ReturnType<typeof makeWSFactory>;
13
+ let client: WhereverClient;
14
+
15
+ beforeEach(() => {
16
+ vi.useFakeTimers();
17
+ ws = makeWSFactory();
18
+ client = new WhereverClient({
19
+ host: 'localhost',
20
+ port: 1234,
21
+ secure: false,
22
+ WebSocketCtor: ws.ctor,
23
+ });
24
+ client.connect();
25
+ ws.last().open();
26
+ });
27
+
28
+ afterEach(() => {
29
+ client.disconnect(true);
30
+ vi.useRealTimers();
31
+ });
32
+
33
+ function loadPending() {
34
+ client.joinSession('/tmp/p/session.jsonl');
35
+ ws.last().receive({
36
+ type: 'session_created',
37
+ sessionId: 'sid-1',
38
+ sessionFile: '/tmp/p/session.jsonl',
39
+ cwd: '/tmp/p',
40
+ model: '',
41
+ isStreaming: false,
42
+ pending: true,
43
+ });
44
+ ws.last().receive({
45
+ type: 'message_history',
46
+ sessionId: 'sid-1',
47
+ messages: [
48
+ {role: 'user', content: 'hi', timestamp: 1},
49
+ {role: 'assistant', content: 'hello', timestamp: 2},
50
+ ],
51
+ totalCount: 2,
52
+ offset: 0,
53
+ });
54
+ }
55
+
56
+ it('paints history but stays agentPending until session_ready', () => {
57
+ loadPending();
58
+ let s = get(client.stateStore);
59
+ // History is readable now.
60
+ expect(s.messages.length).toBe(2);
61
+ expect(s.loadingSession).toBe(false);
62
+ // But sending is blocked until the agent is ready.
63
+ expect(s.agentPending).toBe(true);
64
+ expect(client.sendMessage('nope')).toBe(false);
65
+
66
+ ws.last().receive({
67
+ type: 'session_ready',
68
+ sessionId: 'sid-1',
69
+ sessionFile: '/tmp/p/session.jsonl',
70
+ model: 'fake:model',
71
+ isStreaming: false,
72
+ });
73
+ s = get(client.stateStore);
74
+ expect(s.agentPending).toBe(false);
75
+ expect(s.activeModel).toBe('fake:model');
76
+ // Now a send goes out over the open socket.
77
+ expect(client.sendMessage('now it works')).toBe(true);
78
+ expect(ws.last().lastSentOfType('message')?.message).toBe('now it works');
79
+ });
80
+
81
+ it('a non-pending create is immediately sendable', () => {
82
+ client.createSession('/tmp/new');
83
+ ws.last().receive({
84
+ type: 'session_created',
85
+ sessionId: 'sid-2',
86
+ sessionFile: '/tmp/new/session.jsonl',
87
+ cwd: '/tmp/new',
88
+ model: 'fake:model',
89
+ isStreaming: false,
90
+ // no pending flag
91
+ });
92
+ const s = get(client.stateStore);
93
+ expect(s.agentPending).toBe(false);
94
+ expect(client.sendMessage('hi')).toBe(true);
95
+ });
96
+
97
+ it('session_error while pending degrades to readable-but-not-sendable', () => {
98
+ loadPending();
99
+ expect(get(client.stateStore).agentPending).toBe(true);
100
+ ws.last().receive({type: 'session_error', sessionId: 'sid-1', error: 'agent build failed'});
101
+ const s = get(client.stateStore);
102
+ expect(s.agentPending).toBe(false);
103
+ expect(s.sessionError).toBe('agent build failed');
104
+ // History is still there to read.
105
+ expect(s.messages.length).toBe(2);
106
+ });
107
+ });
@@ -0,0 +1,82 @@
1
+ import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
2
+ import {get} from 'sveltore';
3
+ import {WhereverClient} from '../src/client.js';
4
+ import {makeWSFactory} from './harness.js';
5
+
6
+ // Bug 1: creating a new session shows the full-screen "Creating session..."
7
+ // spinner (state.creatingSession) forever when the server never replies with
8
+ // session_created / session_error (a slow git init or remote-repo creation, an
9
+ // error thrown before the reply is sent, or a half-open socket the liveness
10
+ // watchdog has not reaped yet). Every OTHER load flag (loadingSession,
11
+ // resyncing) is guarded by a watchdog; creatingSession was not. These tests pin
12
+ // the contract: creatingSession must always resolve.
13
+
14
+ describe('creating-session watchdog', () => {
15
+ let ws: ReturnType<typeof makeWSFactory>;
16
+ let client: WhereverClient;
17
+
18
+ beforeEach(() => {
19
+ vi.useFakeTimers();
20
+ ws = makeWSFactory();
21
+ client = new WhereverClient({
22
+ host: 'localhost',
23
+ port: 1234,
24
+ secure: false,
25
+ WebSocketCtor: ws.ctor,
26
+ });
27
+ client.connect();
28
+ ws.last().open();
29
+ });
30
+
31
+ afterEach(() => {
32
+ client.disconnect(true);
33
+ vi.useRealTimers();
34
+ });
35
+
36
+ it('sets creatingSession true when a create is requested', () => {
37
+ client.createSession('/tmp/project');
38
+ expect(get(client.stateStore).creatingSession).toBe(true);
39
+ });
40
+
41
+ it('clears creatingSession and surfaces a recoverable error if no reply ever arrives', () => {
42
+ client.createSession('/tmp/project');
43
+ expect(get(client.stateStore).creatingSession).toBe(true);
44
+
45
+ // No session_created / session_error comes back. Advance past the watchdog.
46
+ vi.advanceTimersByTime(30_000);
47
+
48
+ const s = get(client.stateStore);
49
+ expect(s.creatingSession).toBe(false);
50
+ expect(s.sessionError).toBeTruthy();
51
+ });
52
+
53
+ it('clears creatingSession normally on session_created (watchdog does not fire)', () => {
54
+ client.createSession('/tmp/project');
55
+ ws.last().receive({
56
+ type: 'session_created',
57
+ sessionId: 'sid-1',
58
+ sessionFile: '/tmp/project/session.jsonl',
59
+ cwd: '/tmp/project',
60
+ model: 'fake:model',
61
+ isStreaming: false,
62
+ });
63
+
64
+ expect(get(client.stateStore).creatingSession).toBe(false);
65
+
66
+ // The watchdog must have been disarmed: advancing time must NOT resurrect
67
+ // an error on the now-successfully-created session.
68
+ vi.advanceTimersByTime(30_000);
69
+ const s = get(client.stateStore);
70
+ expect(s.creatingSession).toBe(false);
71
+ expect(s.sessionError).toBeFalsy();
72
+ expect(s.activeSessionFile).toBe('/tmp/project/session.jsonl');
73
+ });
74
+
75
+ it('clears creatingSession on session_error', () => {
76
+ client.createSession('/tmp/project');
77
+ ws.last().receive({type: 'session_error', error: 'boom'});
78
+ const s = get(client.stateStore);
79
+ expect(s.creatingSession).toBe(false);
80
+ expect(s.sessionError).toBe('boom');
81
+ });
82
+ });
@@ -0,0 +1,97 @@
1
+ // Minimal fake WebSocket for driving WhereverClient.handleMessage deterministically
2
+ // in unit tests. It records outbound frames and lets a test push inbound frames
3
+ // (server -> client) synchronously. No real network. Mirrors the tiny slice of
4
+ // the WHATWG WebSocket API that the client uses (readyState, addEventListener for
5
+ // open/message/close/error, send, close).
6
+
7
+ export type WSListener = (event: any) => void;
8
+
9
+ export class FakeWebSocket {
10
+ // WHATWG readyState constants.
11
+ static CONNECTING = 0;
12
+ static OPEN = 1;
13
+ static CLOSING = 2;
14
+ static CLOSED = 3;
15
+
16
+ url: string;
17
+ readyState = FakeWebSocket.CONNECTING;
18
+ sent: any[] = [];
19
+ private listeners: Record<string, Set<WSListener>> = {
20
+ open: new Set(),
21
+ message: new Set(),
22
+ close: new Set(),
23
+ error: new Set(),
24
+ };
25
+
26
+ constructor(url: string) {
27
+ this.url = url;
28
+ }
29
+
30
+ addEventListener(type: string, cb: WSListener) {
31
+ this.listeners[type]?.add(cb);
32
+ }
33
+
34
+ removeEventListener(type: string, cb: WSListener) {
35
+ this.listeners[type]?.delete(cb);
36
+ }
37
+
38
+ removeAllListeners() {
39
+ for (const key of Object.keys(this.listeners)) {
40
+ this.listeners[key].clear();
41
+ }
42
+ }
43
+
44
+ send(data: string) {
45
+ this.sent.push(JSON.parse(data));
46
+ }
47
+
48
+ close() {
49
+ if (this.readyState === FakeWebSocket.CLOSED) return;
50
+ this.readyState = FakeWebSocket.CLOSED;
51
+ this.emit('close', {});
52
+ }
53
+
54
+ // terminate() is used by the liveness watchdog's forcible teardown path.
55
+ terminate() {
56
+ this.close();
57
+ }
58
+
59
+ // --- test-only helpers -------------------------------------------------
60
+
61
+ /** Simulate the socket opening (server accepted the connection). */
62
+ open() {
63
+ this.readyState = FakeWebSocket.OPEN;
64
+ this.emit('open', {});
65
+ }
66
+
67
+ /** Push a server -> client frame. */
68
+ receive(msg: any) {
69
+ this.emit('message', {data: JSON.stringify(msg)});
70
+ }
71
+
72
+ /** Last outbound frame of a given type, or undefined. */
73
+ lastSentOfType(type: string) {
74
+ return [...this.sent].reverse().find((m) => m.type === type);
75
+ }
76
+
77
+ private emit(type: string, event: any) {
78
+ for (const cb of this.listeners[type] ?? []) cb(event);
79
+ }
80
+ }
81
+
82
+ // A WebSocket constructor that records every instance it creates, so a test can
83
+ // grab the live socket the client just opened and drive it. Assigned to
84
+ // config.WebSocketCtor.
85
+ export function makeWSFactory() {
86
+ const instances: FakeWebSocket[] = [];
87
+ const ctor = function (url: string) {
88
+ const ws = new FakeWebSocket(url);
89
+ instances.push(ws);
90
+ return ws;
91
+ } as unknown as {new (url: string): FakeWebSocket};
92
+ return {
93
+ ctor,
94
+ instances,
95
+ last: () => instances[instances.length - 1],
96
+ };
97
+ }
@@ -0,0 +1,194 @@
1
+ import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
2
+ import {get} from 'sveltore';
3
+ import {WhereverClient} from '../src/client.js';
4
+ import type {WhereverState} from '../src/types.js';
5
+ import {makeWSFactory} from './harness.js';
6
+
7
+ // The half-open loss: the socket reports OPEN, ws.send() succeeds (buffers, no
8
+ // throw), but the frame never reaches the server. The optimistic user echo must
9
+ // NOT be treated as delivered: it stays unconfirmed, is recoverable on reload,
10
+ // and flips to a "failed / needs retry" state instead of vanishing.
11
+
12
+ // A localStorage shim so persistence works under the node test env.
13
+ function installLocalStorage() {
14
+ const store = new Map<string, string>();
15
+ (globalThis as any).localStorage = {
16
+ getItem: (k: string) => (store.has(k) ? store.get(k)! : null),
17
+ setItem: (k: string, v: string) => void store.set(k, v),
18
+ removeItem: (k: string) => void store.delete(k),
19
+ clear: () => store.clear(),
20
+ };
21
+ return store;
22
+ }
23
+
24
+ function createAndLoad(
25
+ ws: ReturnType<typeof makeWSFactory>,
26
+ client: WhereverClient,
27
+ messages: any[] = [],
28
+ ) {
29
+ client.joinSession('/tmp/project/session.jsonl');
30
+ ws.last().receive({
31
+ type: 'session_created',
32
+ sessionId: 'sid-1',
33
+ sessionFile: '/tmp/project/session.jsonl',
34
+ cwd: '/tmp/project',
35
+ model: 'fake:model',
36
+ isStreaming: false,
37
+ });
38
+ ws.last().receive({
39
+ type: 'message_history',
40
+ sessionId: 'sid-1',
41
+ messages,
42
+ totalCount: messages.length,
43
+ offset: 0,
44
+ });
45
+ }
46
+
47
+ describe('outbound message delivery confirmation', () => {
48
+ let ws: ReturnType<typeof makeWSFactory>;
49
+ let client: WhereverClient;
50
+ const state = () => get<WhereverState>(client.stateStore);
51
+
52
+ beforeEach(() => {
53
+ vi.useFakeTimers();
54
+ installLocalStorage();
55
+ (globalThis as any).localStorage.clear();
56
+ ws = makeWSFactory();
57
+ client = new WhereverClient({
58
+ host: 'localhost',
59
+ port: 1234,
60
+ secure: false,
61
+ WebSocketCtor: ws.ctor,
62
+ });
63
+ client.connect();
64
+ ws.last().open();
65
+ createAndLoad(ws, client);
66
+ });
67
+
68
+ afterEach(() => {
69
+ client.disconnect(true);
70
+ vi.useRealTimers();
71
+ });
72
+
73
+ it('marks a sent message as unconfirmed (sending), not delivered', () => {
74
+ const ok = client.sendMessage('hello there');
75
+ expect(ok).toBe(true);
76
+ const m = state().messages.find((x) => x.content === 'hello there')!;
77
+ expect(m.delivery).toBe('sending');
78
+ });
79
+
80
+ it('confirms the message when the server echoes it back', () => {
81
+ client.sendMessage('confirm me');
82
+ ws.last().receive({
83
+ type: 'message_end',
84
+ sessionId: 'sid-1',
85
+ role: 'user',
86
+ content: 'confirm me',
87
+ });
88
+ const m = state().messages.find((x) => x.content === 'confirm me')!;
89
+ expect(m.delivery).toBeUndefined();
90
+ // No duplicate echo added.
91
+ expect(
92
+ state().messages.filter((x) => x.content === 'confirm me').length,
93
+ ).toBe(1);
94
+ });
95
+
96
+ it('flips to failed when no echo arrives within the window (half-open loss)', () => {
97
+ // Half-open: send() reports success but the server never processes it, so
98
+ // no echo is ever received.
99
+ client.sendMessage('lost message');
100
+ expect(
101
+ state().messages.find((x) => x.content === 'lost message')!.delivery,
102
+ ).toBe('sending');
103
+
104
+ vi.advanceTimersByTime(12_000);
105
+ const m = state().messages.find((x) => x.content === 'lost message')!;
106
+ expect(m.delivery).toBe('failed');
107
+ });
108
+
109
+ it('persists an unconfirmed message so a reload can recover it', () => {
110
+ client.sendMessage('recover me on reload');
111
+ // Simulate a reload: a fresh client instance against the same localStorage.
112
+ const ws2 = makeWSFactory();
113
+ const client2 = new WhereverClient({
114
+ host: 'localhost',
115
+ port: 1234,
116
+ secure: false,
117
+ WebSocketCtor: ws2.ctor,
118
+ });
119
+ client2.connect();
120
+ ws2.last().open();
121
+ // History comes back WITHOUT the message (the server never got it).
122
+ createAndLoad(ws2, client2, []);
123
+
124
+ const recovered = get<WhereverState>(client2.stateStore).messages.find(
125
+ (x) => x.content === 'recover me on reload',
126
+ );
127
+ expect(recovered).toBeTruthy();
128
+ expect(recovered!.delivery).toBe('failed');
129
+ client2.disconnect(true);
130
+ });
131
+
132
+ it('does NOT re-surface a message that history confirms was delivered', () => {
133
+ client.sendMessage('this one landed');
134
+ // Reload; history DOES contain it (it was delivered before the drop).
135
+ const ws2 = makeWSFactory();
136
+ const client2 = new WhereverClient({
137
+ host: 'localhost',
138
+ port: 1234,
139
+ secure: false,
140
+ WebSocketCtor: ws2.ctor,
141
+ });
142
+ client2.connect();
143
+ ws2.last().open();
144
+ createAndLoad(ws2, client2, [
145
+ {role: 'user', content: 'this one landed', timestamp: 1_000},
146
+ ]);
147
+
148
+ const msgs = get<WhereverState>(client2.stateStore).messages.filter(
149
+ (x) => x.content === 'this one landed',
150
+ );
151
+ // Exactly one, and delivered (no failed duplicate).
152
+ expect(msgs.length).toBe(1);
153
+ expect(msgs[0].delivery).toBeUndefined();
154
+ client2.disconnect(true);
155
+ });
156
+
157
+ it('resendMessage re-sends a failed message and re-arms confirmation', () => {
158
+ client.sendMessage('retry me');
159
+ vi.advanceTimersByTime(12_000);
160
+ const failed = state().messages.find((x) => x.content === 'retry me')!;
161
+ expect(failed.delivery).toBe('failed');
162
+
163
+ const sock = ws.last();
164
+ const before = sock.sent.filter((f) => f.type === 'message').length;
165
+ const ok = client.resendMessage(failed.id);
166
+ expect(ok).toBe(true);
167
+ expect(sock.sent.filter((f) => f.type === 'message').length).toBe(before + 1);
168
+ expect(
169
+ state().messages.find((x) => x.id === failed.id)!.delivery,
170
+ ).toBe('sending');
171
+
172
+ // The echo now confirms it.
173
+ sock.receive({
174
+ type: 'message_end',
175
+ sessionId: 'sid-1',
176
+ role: 'user',
177
+ content: 'retry me',
178
+ });
179
+ expect(
180
+ state().messages.find((x) => x.id === failed.id)!.delivery,
181
+ ).toBeUndefined();
182
+ });
183
+
184
+ it('discardMessage removes a failed message and clears it from persistence', () => {
185
+ client.sendMessage('drop me');
186
+ vi.advanceTimersByTime(12_000);
187
+ const failed = state().messages.find((x) => x.content === 'drop me')!;
188
+ client.discardMessage(failed.id);
189
+ expect(state().messages.find((x) => x.content === 'drop me')).toBeUndefined();
190
+ expect(
191
+ (globalThis as any).localStorage.getItem('wherever-pending:sid-1'),
192
+ ).toBeNull();
193
+ });
194
+ });
@@ -0,0 +1,91 @@
1
+ import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
2
+ import {get} from 'sveltore';
3
+ import {WhereverClient} from '../src/client.js';
4
+ import {makeWSFactory} from './harness.js';
5
+
6
+ // A message submitted WHILE the agent is streaming must be sent to the relay
7
+ // IMMEDIATELY (the server turns a mid-stream `message` into a steer, injected at
8
+ // the next tool/step boundary). This is the pi-CLI default (Enter -> steer). It
9
+ // must NOT be held locally waiting for the turn to finish -- the old behaviour
10
+ // that also mis-fired mid-turn on the flaky isStreaming debounce (docs/adr/0003).
11
+
12
+ function createAndLoad(
13
+ ws: ReturnType<typeof makeWSFactory>,
14
+ client: WhereverClient,
15
+ {streaming = false}: {streaming?: boolean} = {},
16
+ ) {
17
+ client.joinSession('/tmp/project/session.jsonl');
18
+ ws.last().receive({
19
+ type: 'session_created',
20
+ sessionId: 'sid-1',
21
+ sessionFile: '/tmp/project/session.jsonl',
22
+ cwd: '/tmp/project',
23
+ model: 'fake:model',
24
+ isStreaming: streaming,
25
+ });
26
+ ws.last().receive({
27
+ type: 'message_history',
28
+ sessionId: 'sid-1',
29
+ messages: [{role: 'user', content: 'go build it', timestamp: 1}],
30
+ totalCount: 1,
31
+ offset: 0,
32
+ });
33
+ }
34
+
35
+ describe('mid-stream submit steers immediately', () => {
36
+ let ws: ReturnType<typeof makeWSFactory>;
37
+ let client: WhereverClient;
38
+
39
+ beforeEach(() => {
40
+ vi.useFakeTimers();
41
+ ws = makeWSFactory();
42
+ client = new WhereverClient({
43
+ host: 'localhost',
44
+ port: 1234,
45
+ secure: false,
46
+ WebSocketCtor: ws.ctor,
47
+ });
48
+ client.connect();
49
+ ws.last().open();
50
+ });
51
+
52
+ afterEach(() => {
53
+ client.disconnect(true);
54
+ vi.useRealTimers();
55
+ });
56
+
57
+ it('sends the message frame NOW while the agent is mid-turn', () => {
58
+ createAndLoad(ws, client, {streaming: true});
59
+ const sock = ws.last();
60
+ expect(get(client.stateStore).isStreaming).toBe(true);
61
+
62
+ // User submits mid-stream. sendMessage must hand a `message` frame to the
63
+ // OPEN socket right away, not park it.
64
+ const ok = client.sendMessage('actually, do X instead');
65
+ expect(ok).toBe(true);
66
+
67
+ const frame = sock.lastSentOfType('message');
68
+ expect(frame).toBeTruthy();
69
+ expect(frame.message).toBe('actually, do X instead');
70
+
71
+ // The optimistic user echo is committed immediately (not withheld pending
72
+ // a later drain), and the turn is still in flight.
73
+ const s = get(client.stateStore);
74
+ expect(s.messages.some((m) => m.role === 'user' && m.content === 'actually, do X instead')).toBe(true);
75
+ expect(s.isStreaming).toBe(true);
76
+ });
77
+
78
+ it('returns false and keeps no phantom echo when disconnected mid-stream', () => {
79
+ createAndLoad(ws, client, {streaming: true});
80
+ const sock = ws.last();
81
+ // Socket drops just as the user submits.
82
+ sock.close();
83
+
84
+ const before = get(client.stateStore).messages.length;
85
+ const ok = client.sendMessage('do X instead');
86
+ expect(ok).toBe(false);
87
+ // No optimistic echo for a send that never left; caller keeps the text.
88
+ expect(get(client.stateStore).messages.length).toBe(before);
89
+ expect(get(client.stateStore).sessionError).toBeTruthy();
90
+ });
91
+ });