@wherever-dev/client 0.8.0 → 0.8.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +63 -0
  3. package/dist/client.js +2 -0
  4. package/dist/client.js.map +1 -1
  5. package/dist/types.d.ts +1 -0
  6. package/dist/types.js.map +1 -1
  7. package/package.json +23 -3
  8. package/src/client.ts +2 -0
  9. package/src/types.ts +3 -0
  10. package/test/agent-pending.test.ts +0 -107
  11. package/test/chunked-upload.test.ts +0 -483
  12. package/test/conversation-mode-flag.test.ts +0 -111
  13. package/test/creating-session-watchdog.test.ts +0 -82
  14. package/test/folder-conflict-read-only.test.ts +0 -145
  15. package/test/folder-missing-read-only.test.ts +0 -114
  16. package/test/harness.ts +0 -133
  17. package/test/hydration-seam.test.ts +0 -400
  18. package/test/liveness-probe.test.ts +0 -183
  19. package/test/message-delivery-confirmation.test.ts +0 -320
  20. package/test/mid-stream-steer.test.ts +0 -91
  21. package/test/new-session-clone-progress.test.ts +0 -263
  22. package/test/optimistic-force-command.test.ts +0 -127
  23. package/test/queued-steer-restored.test.ts +0 -175
  24. package/test/reconnect-rejoins-session.test.ts +0 -136
  25. package/test/restore-panel.test.ts +0 -324
  26. package/test/resume-keeps-session.test.ts +0 -118
  27. package/test/session-load-by-id.test.ts +0 -100
  28. package/test/session-reload.test.ts +0 -82
  29. package/test/skills-autocomplete.test.ts +0 -113
  30. package/test/steer-queue-cancel.test.ts +0 -130
  31. package/test/superseded-connection-key.test.ts +0 -70
  32. package/test/superseded-session-load.test.ts +0 -180
  33. package/test/tool-aborted-render.test.ts +0 -170
  34. package/test/tool-duration-history.test.ts +0 -93
  35. package/test/tool-duration.test.ts +0 -86
  36. package/test/tool-interrupted-history.test.ts +0 -294
  37. package/test/upload-survives-reconnect.test.ts +0 -482
  38. package/tsconfig.json +0 -16
@@ -1,324 +0,0 @@
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
- // The RESTORE half of the folder-missing state: the panel that replaces the
7
- // composer clones the repository back into the missing path.
8
- //
9
- // The job is server-owned and keyed by that PATH, so this client is never the
10
- // owner of the operation: it asks, and then paints whatever the server says --
11
- // including a job it did not start (a second device, or its own previous socket
12
- // before the phone dropped off). Frames are addressed by path, so one for a
13
- // folder this client is no longer looking at must be ignored rather than
14
- // repainting the panel of a different session.
15
-
16
- const TARGET = '/home/u/dev/github/owner/repo';
17
- const SESSION_FILE = `${TARGET}/session.jsonl`;
18
-
19
- function runningJob(overrides: Record<string, unknown> = {}) {
20
- return {
21
- id: 7,
22
- kind: 'clone',
23
- targetPath: TARGET,
24
- url: 'git@github.com:owner/repo.git',
25
- state: 'running',
26
- progress: {
27
- phase: 'receiving',
28
- scope: 'repository',
29
- percent: 42,
30
- indeterminate: false,
31
- text: 'Receiving objects: 42% (42/100)',
32
- at: 1,
33
- },
34
- startedAt: 1,
35
- ...overrides,
36
- };
37
- }
38
-
39
- describe('restore panel state', () => {
40
- let ws: ReturnType<typeof makeWSFactory>;
41
- let client: WhereverClient;
42
-
43
- function loadMissingFolderSession(job?: Record<string, unknown>) {
44
- client.joinSession(SESSION_FILE);
45
- ws.last().receive({
46
- type: 'session_created',
47
- sessionId: 'sid-1',
48
- sessionFile: SESSION_FILE,
49
- cwd: TARGET,
50
- model: 'fake:model',
51
- readOnly: true,
52
- folderMissing: true,
53
- pending: true,
54
- });
55
- ws.last().receive({
56
- type: 'folder_missing',
57
- sessionId: 'sid-1',
58
- cwd: TARGET,
59
- ...(job ? {job} : {}),
60
- });
61
- }
62
-
63
- beforeEach(() => {
64
- vi.useFakeTimers();
65
- ws = makeWSFactory();
66
- client = new WhereverClient({
67
- host: 'localhost',
68
- port: 1234,
69
- secure: false,
70
- WebSocketCtor: ws.ctor,
71
- });
72
- client.connect();
73
- ws.last().open();
74
- });
75
-
76
- afterEach(() => {
77
- client.disconnect(true);
78
- vi.useRealTimers();
79
- });
80
-
81
- it('offers a restore for the missing path when nothing is running', () => {
82
- loadMissingFolderSession();
83
-
84
- const s = get(client.stateStore);
85
- expect(s.restore).toEqual({
86
- targetPath: TARGET,
87
- job: null,
88
- joined: false,
89
- rejection: null,
90
- });
91
- });
92
-
93
- it('repaints a job the server was ALREADY running for that path', () => {
94
- // The reconnect / second-device case: the frame carries the running job,
95
- // so the panel shows live progress instead of offering a second clone.
96
- loadMissingFolderSession(runningJob());
97
-
98
- const s = get(client.stateStore);
99
- expect(s.restore?.job?.id).toBe(7);
100
- expect(s.restore?.job?.state).toBe('running');
101
- expect(s.restore?.job?.progress?.percent).toBe(42);
102
- });
103
-
104
- it('sends the target path the server named, and follows the job to completion', () => {
105
- loadMissingFolderSession();
106
-
107
- client.startRestore('clone', ' git@github.com:owner/repo.git ');
108
- const sent = ws.last().lastSentOfType('restore_start');
109
- expect(sent).toEqual({
110
- type: 'restore_start',
111
- targetPath: TARGET,
112
- action: 'clone',
113
- url: 'git@github.com:owner/repo.git',
114
- });
115
-
116
- ws.last().receive({
117
- type: 'restore_started',
118
- targetPath: TARGET,
119
- outcome: 'started',
120
- job: runningJob(),
121
- });
122
- expect(get(client.stateStore).restore?.joined).toBe(false);
123
-
124
- ws.last().receive({
125
- type: 'restore_progress',
126
- targetPath: TARGET,
127
- job: runningJob({
128
- progress: {
129
- phase: 'starting',
130
- scope: 'sub',
131
- percent: null,
132
- indeterminate: true,
133
- text: "Cloning into '/home/u/dev/github/owner/repo/sub'...",
134
- at: 2,
135
- },
136
- }),
137
- });
138
- // Honest progress survives the round trip: an indeterminate phase is
139
- // carried AS indeterminate, and the submodule keeps its own scope.
140
- const mid = get(client.stateStore).restore?.job?.progress;
141
- expect(mid?.indeterminate).toBe(true);
142
- expect(mid?.percent).toBeNull();
143
- expect(mid?.scope).toBe('sub');
144
-
145
- ws.last().receive({
146
- type: 'restore_complete',
147
- targetPath: TARGET,
148
- job: runningJob({state: 'done', endedAt: 3}),
149
- });
150
- expect(get(client.stateStore).restore?.job?.state).toBe('done');
151
- });
152
-
153
- it('sends the CREATE remedy with the git-init choice, in both states', () => {
154
- // The second remedy: a folder that was never a clone. Same frame family,
155
- // same path, no url -- only the checkbox differs, and it must travel as an
156
- // EXPLICIT boolean either way. Omitting it when off would let the server's
157
- // own default decide, which is exactly the surprise repository a user who
158
- // turned `gitInitDefault` off is entitled not to get.
159
- loadMissingFolderSession();
160
-
161
- client.startRestore('create', undefined, true);
162
- expect(ws.last().lastSentOfType('restore_start')).toEqual({
163
- type: 'restore_start',
164
- targetPath: TARGET,
165
- action: 'create',
166
- gitInit: true,
167
- });
168
-
169
- client.startRestore('create', undefined, false);
170
- expect(ws.last().lastSentOfType('restore_start')).toEqual({
171
- type: 'restore_start',
172
- targetPath: TARGET,
173
- action: 'create',
174
- gitInit: false,
175
- });
176
-
177
- // It drives the ONE state machine: the create job is followed exactly as a
178
- // clone is, to the same terminal state the panel's ready-and-reload rests on.
179
- ws.last().receive({
180
- type: 'restore_started',
181
- targetPath: TARGET,
182
- outcome: 'started',
183
- job: runningJob({kind: 'create', url: undefined, gitInit: false}),
184
- });
185
- ws.last().receive({
186
- type: 'restore_complete',
187
- targetPath: TARGET,
188
- job: runningJob({
189
- kind: 'create',
190
- url: undefined,
191
- gitInit: false,
192
- state: 'done',
193
- endedAt: 3,
194
- }),
195
- });
196
- const job = get(client.stateStore).restore?.job;
197
- expect(job?.kind).toBe('create');
198
- expect(job?.state).toBe('done');
199
- expect(job?.gitInit).toBe(false);
200
- });
201
-
202
- it('says when a second tap JOINED a job cloning a DIFFERENT url', () => {
203
- loadMissingFolderSession(runningJob());
204
-
205
- client.startRestore('clone', 'git@github.com:someone/else.git');
206
- expect(get(client.stateStore).restore?.requestedUrl).toBe(
207
- 'git@github.com:someone/else.git',
208
- );
209
-
210
- ws.last().receive({
211
- type: 'restore_started',
212
- targetPath: TARGET,
213
- outcome: 'joined',
214
- job: runningJob(),
215
- });
216
-
217
- const s = get(client.stateStore);
218
- expect(s.restore?.joined).toBe(true);
219
- // The url in flight, NOT the one this client typed: the panel can only
220
- // say so honestly because both are kept.
221
- expect(s.restore?.job?.url).toBe('git@github.com:owner/repo.git');
222
- expect(s.restore?.requestedUrl).toBe('git@github.com:someone/else.git');
223
- });
224
-
225
- it('surfaces a refusal without inventing a job', () => {
226
- loadMissingFolderSession();
227
-
228
- client.startRestore('clone', 'https://github.com/owner/repo.git');
229
- ws.last().receive({
230
- type: 'restore_rejected',
231
- targetPath: TARGET,
232
- reason: 'invalid-url',
233
- message: 'Refusing to clone "https://github.com/owner/repo.git": not a recognised SSH repository URL',
234
- });
235
-
236
- const s = get(client.stateStore);
237
- expect(s.restore?.job).toBeNull();
238
- expect(s.restore?.rejection?.reason).toBe('invalid-url');
239
- // A corrected retry clears the refusal so the panel is not stuck on it.
240
- client.startRestore('clone', 'git@github.com:owner/repo.git');
241
- expect(get(client.stateStore).restore?.rejection).toBeNull();
242
- });
243
-
244
- it('carries a failure with its mapped cause and git raw output', () => {
245
- loadMissingFolderSession();
246
- ws.last().receive({
247
- type: 'restore_complete',
248
- targetPath: TARGET,
249
- job: runningJob({
250
- state: 'failed',
251
- failure: {
252
- cause: 'no-key',
253
- message: 'No SSH key on this machine is accepted by github.com.',
254
- stderr: 'git@github.com: Permission denied (publickey).\nfatal: Could not read from remote repository.\n',
255
- },
256
- }),
257
- });
258
-
259
- const failure = get(client.stateStore).restore?.job?.failure;
260
- expect(failure?.cause).toBe('no-key');
261
- expect(failure?.stderr).toContain('Permission denied (publickey)');
262
-
263
- // Retrying drops the FINISHED job it is retrying, so the panel shows the
264
- // request in flight rather than the previous failure until the server
265
- // answers. (A RUNNING job would be kept: that is the one being joined.)
266
- client.startRestore('clone', 'git@github.com:owner/repo.git');
267
- expect(get(client.stateStore).restore?.job).toBeNull();
268
- });
269
-
270
- it('cancels the job for its own folder, and nothing when there is none', () => {
271
- loadMissingFolderSession(runningJob());
272
- expect(client.cancelRestore()).toBe(true);
273
- expect(ws.last().lastSentOfType('restore_cancel')).toEqual({
274
- type: 'restore_cancel',
275
- targetPath: TARGET,
276
- });
277
-
278
- ws.last().receive({
279
- type: 'restore_complete',
280
- targetPath: TARGET,
281
- job: runningJob({state: 'cancelled', endedAt: 4}),
282
- });
283
- expect(get(client.stateStore).restore?.job?.state).toBe('cancelled');
284
- });
285
-
286
- it('ignores restore frames for a folder it is not looking at', () => {
287
- loadMissingFolderSession(runningJob());
288
-
289
- ws.last().receive({
290
- type: 'restore_progress',
291
- targetPath: '/home/u/dev/github/owner/other',
292
- job: {...runningJob(), id: 99, targetPath: '/home/u/dev/github/owner/other'},
293
- });
294
-
295
- expect(get(client.stateStore).restore?.job?.id).toBe(7);
296
- });
297
-
298
- it('reloads the session to go live, and clears the restore with it', () => {
299
- loadMissingFolderSession();
300
- ws.last().receive({
301
- type: 'restore_complete',
302
- targetPath: TARGET,
303
- job: runningJob({state: 'done', endedAt: 5}),
304
- });
305
-
306
- // A live agent is a LOAD-TIME decision, so going live is a re-load of the
307
- // same session file, not a local unlock.
308
- expect(client.reloadSession()).toBe(true);
309
- expect(ws.last().lastSentOfType('session_load')).toMatchObject({
310
- type: 'session_load',
311
- sessionFile: SESSION_FILE,
312
- });
313
- const s = get(client.stateStore);
314
- expect(s.restore).toBeNull();
315
- expect(s.folderMissing).toBeNull();
316
- });
317
-
318
- it('clears with the session it belonged to', () => {
319
- loadMissingFolderSession(runningJob());
320
-
321
- client.switchSession('/home/u/dev/other/session.jsonl');
322
- expect(get(client.stateStore).restore).toBeNull();
323
- });
324
- });
@@ -1,118 +0,0 @@
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 2 (client-level invariant): on tab-background suspend() and return
7
- // resume(), the client must KEEP the cached session (activeSessionFile +
8
- // messages) and mark it resyncing, NOT drop to a no-session state. The UI keys
9
- // the "new session / search box" empty-state on activeSessionFile being null; if
10
- // suspend/resume nulled it, the search box would flash on every resume. These
11
- // tests pin the client contract the UI relies on.
12
-
13
- function createAndLoad(ws: ReturnType<typeof makeWSFactory>, client: WhereverClient) {
14
- client.joinSession('/tmp/project/session.jsonl');
15
- ws.last().receive({
16
- type: 'session_created',
17
- sessionId: 'sid-1',
18
- sessionFile: '/tmp/project/session.jsonl',
19
- cwd: '/tmp/project',
20
- model: 'fake:model',
21
- isStreaming: false,
22
- });
23
- ws.last().receive({
24
- type: 'message_history',
25
- sessionId: 'sid-1',
26
- messages: [
27
- {role: 'user', content: 'hello', timestamp: 1},
28
- {role: 'assistant', content: 'hi there', timestamp: 2},
29
- ],
30
- totalCount: 2,
31
- offset: 0,
32
- });
33
- }
34
-
35
- describe('suspend/resume keeps the session visible', () => {
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
- createAndLoad(ws, client);
51
- });
52
-
53
- afterEach(() => {
54
- client.disconnect(true);
55
- vi.useRealTimers();
56
- });
57
-
58
- it('starts with an active session and messages', () => {
59
- const s = get(client.stateStore);
60
- expect(s.activeSessionFile).toBe('/tmp/project/session.jsonl');
61
- expect(s.messages.length).toBe(2);
62
- });
63
-
64
- it('suspend() preserves activeSessionFile and messages (does not drop to no-session)', () => {
65
- client.suspend();
66
- const s = get(client.stateStore);
67
- expect(s.connected).toBe(false);
68
- // The cached session and its messages must survive the suspend so the UI
69
- // keeps showing the conversation, not the search/new-session empty-state.
70
- expect(s.activeSessionFile).toBe('/tmp/project/session.jsonl');
71
- expect(s.messages.length).toBe(2);
72
- expect(client.hasSuspendedSession()).toBe(true);
73
- });
74
-
75
- it('resume() marks the session resyncing while keeping it visible', () => {
76
- client.suspend();
77
- client.resume();
78
- const s = get(client.stateStore);
79
- // resyncing drives the "Reconnecting and syncing session..." banner; the
80
- // session must still be present so no search box flashes.
81
- expect(s.resyncing).toBe(true);
82
- expect(s.activeSessionFile).toBe('/tmp/project/session.jsonl');
83
- expect(s.messages.length).toBe(2);
84
- });
85
-
86
- it('resume() rejoins in place and clears resyncing on the fresh history', () => {
87
- client.suspend();
88
- client.resume();
89
- // A brand-new socket was created by resume(); open it.
90
- ws.last().open();
91
- // The client should have re-issued session_load for the cached session.
92
- expect(ws.last().lastSentOfType('session_load')?.sessionFile).toBe(
93
- '/tmp/project/session.jsonl',
94
- );
95
- ws.last().receive({
96
- type: 'session_created',
97
- sessionId: 'sid-1',
98
- sessionFile: '/tmp/project/session.jsonl',
99
- cwd: '/tmp/project',
100
- model: 'fake:model',
101
- isStreaming: false,
102
- });
103
- ws.last().receive({
104
- type: 'message_history',
105
- sessionId: 'sid-1',
106
- messages: [
107
- {role: 'user', content: 'hello', timestamp: 1},
108
- {role: 'assistant', content: 'hi there', timestamp: 2},
109
- ],
110
- totalCount: 2,
111
- offset: 0,
112
- });
113
- const s = get(client.stateStore);
114
- expect(s.resyncing).toBe(false);
115
- expect(s.connected).toBe(true);
116
- expect(s.activeSessionFile).toBe('/tmp/project/session.jsonl');
117
- });
118
- });
@@ -1,100 +0,0 @@
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: opening the app on a deep link like `https://host/#<sessionId>` hung
7
- // forever on "Loading session...", while clicking the SAME session in the
8
- // sidebar loaded instantly.
9
- //
10
- // Cause: the sidebar joins by session FILE path, but the URL hash carries the
11
- // session ID. `session_load` accepts either (the server resolves an ID to its
12
- // file), yet the reply always carries the resolved FILE. The superseded-load
13
- // guard compared `msg.sessionFile === pendingLoadFile`, so an ID-issued load
14
- // never matched its own reply: session_created was dropped as "stale", no
15
- // session ever became active, and the hash-driven spinner never cleared.
16
- //
17
- // Fix: the pending load target matches its reply by sessionFile OR sessionId.
18
-
19
- function newClient(ws: ReturnType<typeof makeWSFactory>) {
20
- const client = new WhereverClient({
21
- host: 'localhost',
22
- port: 1234,
23
- secure: false,
24
- WebSocketCtor: ws.ctor,
25
- });
26
- client.connect();
27
- ws.last().open();
28
- return client;
29
- }
30
-
31
- const SESSION_ID = '019fa1e9-0e62-795f-bee9-f2e1fcdc39d5';
32
- const SESSION_FILE = '/tmp/project/019fa1e9-0e62-795f-bee9-f2e1fcdc39d5.jsonl';
33
-
34
- describe('loading a session by ID (URL hash deep link)', () => {
35
- let ws: ReturnType<typeof makeWSFactory>;
36
- let client: WhereverClient;
37
-
38
- beforeEach(() => {
39
- vi.useFakeTimers();
40
- ws = makeWSFactory();
41
- client = newClient(ws);
42
- });
43
-
44
- afterEach(() => {
45
- client.disconnect(true);
46
- vi.useRealTimers();
47
- });
48
-
49
- it('accepts the reply whose sessionFile is the resolved path of the requested ID', () => {
50
- client.joinSession(SESSION_ID);
51
- expect(get(client.stateStore).loadingSession).toBe(true);
52
-
53
- ws.last().receive({
54
- type: 'session_created',
55
- sessionId: SESSION_ID,
56
- sessionFile: SESSION_FILE,
57
- cwd: '/tmp/project',
58
- model: 'fake:model',
59
- pending: true,
60
- });
61
- ws.last().receive({
62
- type: 'message_history',
63
- sessionId: SESSION_ID,
64
- messages: [{role: 'user', content: 'hello', timestamp: 1}],
65
- totalCount: 1,
66
- offset: 0,
67
- });
68
-
69
- const s = get(client.stateStore);
70
- expect(s.sessionId).toBe(SESSION_ID);
71
- expect(s.activeSessionFile).toBe(SESSION_FILE);
72
- expect(s.loadingSession).toBe(false);
73
- expect(s.messages.map((m) => m.content)).toContain('hello');
74
- });
75
-
76
- it('still drops a late reply for a different session after switching by ID', () => {
77
- client.joinSession('other-session-id');
78
- client.switchSession(SESSION_ID);
79
-
80
- ws.last().receive({
81
- type: 'session_created',
82
- sessionId: SESSION_ID,
83
- sessionFile: SESSION_FILE,
84
- cwd: '/tmp/project',
85
- model: 'fake:model',
86
- });
87
- // The abandoned load finally answers; it must not take over.
88
- ws.last().receive({
89
- type: 'session_created',
90
- sessionId: 'other-session-id',
91
- sessionFile: '/tmp/project/other.jsonl',
92
- cwd: '/tmp/project',
93
- model: 'fake:model',
94
- });
95
-
96
- const s = get(client.stateStore);
97
- expect(s.sessionId).toBe(SESSION_ID);
98
- expect(s.activeSessionFile).toBe(SESSION_FILE);
99
- });
100
- });
@@ -1,82 +0,0 @@
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
- // The web `/reload` reducer contract: reloadResources() only ASKS (one
7
- // session_reload frame for the active session); the server drives the state.
8
- // session_reloading blocks the composer (agentPending) like a cold load, and the
9
- // session_ready that ends the reload unblocks it and re-requests the skill list
10
- // (a reload can change which skills exist). A frame for another session is ignored.
11
-
12
- describe('session reload', () => {
13
- let ws: ReturnType<typeof makeWSFactory>;
14
- let client: WhereverClient;
15
-
16
- beforeEach(() => {
17
- vi.useFakeTimers();
18
- ws = makeWSFactory();
19
- client = new WhereverClient({
20
- host: 'localhost',
21
- port: 1234,
22
- secure: false,
23
- WebSocketCtor: ws.ctor,
24
- });
25
- client.connect();
26
- ws.last().open();
27
- client.joinSession('/tmp/p/session.jsonl');
28
- ws.last().receive({
29
- type: 'session_created',
30
- sessionId: 'sid-1',
31
- sessionFile: '/tmp/p/session.jsonl',
32
- cwd: '/tmp/p',
33
- model: 'fake:a',
34
- isStreaming: false,
35
- });
36
- });
37
-
38
- afterEach(() => {
39
- client.disconnect(true);
40
- vi.useRealTimers();
41
- });
42
-
43
- function sentOfType(type: string): any[] {
44
- return ws.last().sent.filter((m: any) => m.type === type);
45
- }
46
-
47
- it('reloadResources() sends one session_reload for the active session and changes nothing locally', () => {
48
- const before = get(client.stateStore);
49
- client.reloadResources();
50
- expect(sentOfType('session_reload')).toEqual([{type: 'session_reload', sessionId: 'sid-1'}]);
51
- expect(get(client.stateStore).agentPending).toBe(before.agentPending);
52
- });
53
-
54
- it('session_reloading blocks the composer until session_ready, which re-requests skills', () => {
55
- ws.last().receive({type: 'session_reloading', sessionId: 'sid-1'});
56
- expect(get(client.stateStore).agentPending).toBe(true);
57
-
58
- const skillRequestsBefore = sentOfType('skills_request').length;
59
- ws.last().receive({
60
- type: 'session_ready',
61
- sessionId: 'sid-1',
62
- sessionFile: '/tmp/p/session.jsonl',
63
- model: 'fake:a',
64
- isStreaming: false,
65
- });
66
- expect(get(client.stateStore).agentPending).toBe(false);
67
- expect(sentOfType('skills_request').length).toBe(skillRequestsBefore + 1);
68
- });
69
-
70
- it('a failed reload (session_error) unblocks the composer and surfaces the error', () => {
71
- ws.last().receive({type: 'session_reloading', sessionId: 'sid-1'});
72
- ws.last().receive({type: 'session_error', sessionId: 'sid-1', error: 'Reload failed: boom'});
73
- const s = get(client.stateStore);
74
- expect(s.agentPending).toBe(false);
75
- expect(s.sessionError).toBe('Reload failed: boom');
76
- });
77
-
78
- it('ignores session_reloading for a session we are not viewing', () => {
79
- ws.last().receive({type: 'session_reloading', sessionId: 'other'});
80
- expect(get(client.stateStore).agentPending).toBe(false);
81
- });
82
- });