@wherever-dev/client 0.8.0 → 0.8.2

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 (39) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +63 -0
  3. package/dist/client.d.ts +5 -0
  4. package/dist/client.js +102 -44
  5. package/dist/client.js.map +1 -1
  6. package/dist/types.d.ts +1 -0
  7. package/dist/types.js.map +1 -1
  8. package/package.json +23 -3
  9. package/src/client.ts +105 -49
  10. package/src/types.ts +3 -0
  11. package/test/agent-pending.test.ts +0 -107
  12. package/test/chunked-upload.test.ts +0 -483
  13. package/test/conversation-mode-flag.test.ts +0 -111
  14. package/test/creating-session-watchdog.test.ts +0 -82
  15. package/test/folder-conflict-read-only.test.ts +0 -145
  16. package/test/folder-missing-read-only.test.ts +0 -114
  17. package/test/harness.ts +0 -133
  18. package/test/hydration-seam.test.ts +0 -400
  19. package/test/liveness-probe.test.ts +0 -183
  20. package/test/message-delivery-confirmation.test.ts +0 -320
  21. package/test/mid-stream-steer.test.ts +0 -91
  22. package/test/new-session-clone-progress.test.ts +0 -263
  23. package/test/optimistic-force-command.test.ts +0 -127
  24. package/test/queued-steer-restored.test.ts +0 -175
  25. package/test/reconnect-rejoins-session.test.ts +0 -136
  26. package/test/restore-panel.test.ts +0 -324
  27. package/test/resume-keeps-session.test.ts +0 -118
  28. package/test/session-load-by-id.test.ts +0 -100
  29. package/test/session-reload.test.ts +0 -82
  30. package/test/skills-autocomplete.test.ts +0 -113
  31. package/test/steer-queue-cancel.test.ts +0 -130
  32. package/test/superseded-connection-key.test.ts +0 -70
  33. package/test/superseded-session-load.test.ts +0 -180
  34. package/test/tool-aborted-render.test.ts +0 -170
  35. package/test/tool-duration-history.test.ts +0 -93
  36. package/test/tool-duration.test.ts +0 -86
  37. package/test/tool-interrupted-history.test.ts +0 -294
  38. package/test/upload-survives-reconnect.test.ts +0 -482
  39. package/tsconfig.json +0 -16
@@ -1,320 +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 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('confirms on a message_ack, before any user echo (the steer case)', () => {
97
- // A mid-stream steer is accepted immediately but pi only echoes it back
98
- // (message_end role:user) at the NEXT model call, which can be far beyond
99
- // the confirmation window. The server sends message_ack the moment it hands
100
- // the message to the agent, so delivery is confirmed right away.
101
- client.sendMessage('steer me now');
102
- expect(
103
- state().messages.find((x) => x.content === 'steer me now')!.delivery,
104
- ).toBe('sending');
105
-
106
- ws.last().receive({
107
- type: 'message_ack',
108
- sessionId: 'sid-1',
109
- content: 'steer me now',
110
- });
111
- expect(
112
- state().messages.find((x) => x.content === 'steer me now')!.delivery,
113
- ).toBeUndefined();
114
-
115
- // The watchdog is cleared: even past the window it stays confirmed.
116
- vi.advanceTimersByTime(12_000);
117
- expect(
118
- state().messages.find((x) => x.content === 'steer me now')!.delivery,
119
- ).toBeUndefined();
120
- // No duplicate bubble.
121
- expect(
122
- state().messages.filter((x) => x.content === 'steer me now').length,
123
- ).toBe(1);
124
- });
125
-
126
- it('a message_ack for the same content later (the user echo) adds no duplicate', () => {
127
- client.sendMessage('acked then echoed');
128
- ws.last().receive({
129
- type: 'message_ack',
130
- sessionId: 'sid-1',
131
- content: 'acked then echoed',
132
- });
133
- // The real pi user-echo arrives at the next turn; it must not duplicate.
134
- ws.last().receive({
135
- type: 'message_end',
136
- sessionId: 'sid-1',
137
- role: 'user',
138
- content: 'acked then echoed',
139
- });
140
- expect(
141
- state().messages.filter((x) => x.content === 'acked then echoed').length,
142
- ).toBe(1);
143
- });
144
-
145
- // A `/skill:<name> <args>` invocation is optimistically echoed RAW, but the
146
- // server confirms it via a RAW message_ack (mid-stream steer) and then echoes
147
- // the EXPANDED skill block back as message_end role:user. Both refer to the
148
- // same invocation: the client must confirm the one bubble and rewrite it to
149
- // the expanded form, NEVER leave the raw one orphaned as failed nor append the
150
- // expanded one as a duplicate.
151
- const EXPANDED_SETUP =
152
- '<skill name="setup" location="/a/b/SKILL.md">\nReferences are relative to /a/b.\n\nBody here.\n</skill>';
153
-
154
- it('skill: message_end (expanded) confirms the raw optimistic bubble, no duplicate', () => {
155
- client.sendMessage('/skill:setup');
156
- expect(
157
- state().messages.find((x) => x.content === '/skill:setup')!.delivery,
158
- ).toBe('sending');
159
-
160
- // Server echoes the EXPANDED block (no prior message_ack, e.g. not streaming).
161
- ws.last().receive({
162
- type: 'message_end',
163
- sessionId: 'sid-1',
164
- role: 'user',
165
- content: EXPANDED_SETUP,
166
- });
167
-
168
- const users = state().messages.filter((x) => x.role === 'user');
169
- expect(users.length).toBe(1);
170
- expect(users[0].delivery).toBeUndefined();
171
- // Rewritten to the expanded form so the skill chip renders.
172
- expect(users[0].content).toBe(EXPANDED_SETUP);
173
-
174
- // Even past the window it stays confirmed (watchdog cleared).
175
- vi.advanceTimersByTime(12_000);
176
- expect(
177
- state().messages.find((x) => x.role === 'user')!.delivery,
178
- ).toBeUndefined();
179
- });
180
-
181
- it('skill: raw message_ack then expanded message_end yields one confirmed chip', () => {
182
- client.sendMessage('/skill:setup');
183
- // Mid-stream steer path: server acks the RAW content immediately.
184
- ws.last().receive({
185
- type: 'message_ack',
186
- sessionId: 'sid-1',
187
- content: '/skill:setup',
188
- });
189
- expect(
190
- state().messages.find((x) => x.role === 'user')!.delivery,
191
- ).toBeUndefined();
192
-
193
- // Later, pi echoes the EXPANDED block at the next model call.
194
- ws.last().receive({
195
- type: 'message_end',
196
- sessionId: 'sid-1',
197
- role: 'user',
198
- content: EXPANDED_SETUP,
199
- });
200
-
201
- const users = state().messages.filter((x) => x.role === 'user');
202
- expect(users.length).toBe(1);
203
- expect(users[0].delivery).toBeUndefined();
204
- expect(users[0].content).toBe(EXPANDED_SETUP);
205
- });
206
-
207
- it('skill: preserves the trailing args when matching raw to expanded', () => {
208
- client.sendMessage('/skill:setup do the thing');
209
- const expandedWithArgs = `${EXPANDED_SETUP}\n\ndo the thing`;
210
- ws.last().receive({
211
- type: 'message_end',
212
- sessionId: 'sid-1',
213
- role: 'user',
214
- content: expandedWithArgs,
215
- });
216
- const users = state().messages.filter((x) => x.role === 'user');
217
- expect(users.length).toBe(1);
218
- expect(users[0].delivery).toBeUndefined();
219
- expect(users[0].content).toBe(expandedWithArgs);
220
- });
221
-
222
- it('flips to failed when no echo arrives within the window (half-open loss)', () => {
223
- // Half-open: send() reports success but the server never processes it, so
224
- // no echo is ever received.
225
- client.sendMessage('lost message');
226
- expect(
227
- state().messages.find((x) => x.content === 'lost message')!.delivery,
228
- ).toBe('sending');
229
-
230
- vi.advanceTimersByTime(12_000);
231
- const m = state().messages.find((x) => x.content === 'lost message')!;
232
- expect(m.delivery).toBe('failed');
233
- });
234
-
235
- it('persists an unconfirmed message so a reload can recover it', () => {
236
- client.sendMessage('recover me on reload');
237
- // Simulate a reload: a fresh client instance against the same localStorage.
238
- const ws2 = makeWSFactory();
239
- const client2 = new WhereverClient({
240
- host: 'localhost',
241
- port: 1234,
242
- secure: false,
243
- WebSocketCtor: ws2.ctor,
244
- });
245
- client2.connect();
246
- ws2.last().open();
247
- // History comes back WITHOUT the message (the server never got it).
248
- createAndLoad(ws2, client2, []);
249
-
250
- const recovered = get<WhereverState>(client2.stateStore).messages.find(
251
- (x) => x.content === 'recover me on reload',
252
- );
253
- expect(recovered).toBeTruthy();
254
- expect(recovered!.delivery).toBe('failed');
255
- client2.disconnect(true);
256
- });
257
-
258
- it('does NOT re-surface a message that history confirms was delivered', () => {
259
- client.sendMessage('this one landed');
260
- // Reload; history DOES contain it (it was delivered before the drop).
261
- const ws2 = makeWSFactory();
262
- const client2 = new WhereverClient({
263
- host: 'localhost',
264
- port: 1234,
265
- secure: false,
266
- WebSocketCtor: ws2.ctor,
267
- });
268
- client2.connect();
269
- ws2.last().open();
270
- createAndLoad(ws2, client2, [
271
- {role: 'user', content: 'this one landed', timestamp: 1_000},
272
- ]);
273
-
274
- const msgs = get<WhereverState>(client2.stateStore).messages.filter(
275
- (x) => x.content === 'this one landed',
276
- );
277
- // Exactly one, and delivered (no failed duplicate).
278
- expect(msgs.length).toBe(1);
279
- expect(msgs[0].delivery).toBeUndefined();
280
- client2.disconnect(true);
281
- });
282
-
283
- it('resendMessage re-sends a failed message and re-arms confirmation', () => {
284
- client.sendMessage('retry me');
285
- vi.advanceTimersByTime(12_000);
286
- const failed = state().messages.find((x) => x.content === 'retry me')!;
287
- expect(failed.delivery).toBe('failed');
288
-
289
- const sock = ws.last();
290
- const before = sock.sent.filter((f) => f.type === 'message').length;
291
- const ok = client.resendMessage(failed.id);
292
- expect(ok).toBe(true);
293
- expect(sock.sent.filter((f) => f.type === 'message').length).toBe(before + 1);
294
- expect(
295
- state().messages.find((x) => x.id === failed.id)!.delivery,
296
- ).toBe('sending');
297
-
298
- // The echo now confirms it.
299
- sock.receive({
300
- type: 'message_end',
301
- sessionId: 'sid-1',
302
- role: 'user',
303
- content: 'retry me',
304
- });
305
- expect(
306
- state().messages.find((x) => x.id === failed.id)!.delivery,
307
- ).toBeUndefined();
308
- });
309
-
310
- it('discardMessage removes a failed message and clears it from persistence', () => {
311
- client.sendMessage('drop me');
312
- vi.advanceTimersByTime(12_000);
313
- const failed = state().messages.find((x) => x.content === 'drop me')!;
314
- client.discardMessage(failed.id);
315
- expect(state().messages.find((x) => x.content === 'drop me')).toBeUndefined();
316
- expect(
317
- (globalThis as any).localStorage.getItem('wherever-pending:sid-1'),
318
- ).toBeNull();
319
- });
320
- });
@@ -1,91 +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
- // 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
- });
@@ -1,263 +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 CLIENT half of "create a session in a folder that has to be cloned
7
- // first". The server runs that clone as an ordinary path-keyed restore job, so
8
- // the frames here are the panel's frames -- what differs is the ENDING, and the
9
- // watchdog.
10
- //
11
- // The watchdog is the whole point: `createSession` arms a 25s timer so a lost
12
- // reply can never strand the blocking "Creating session..." overlay, and a
13
- // clone of any real repository outruns it. So a create that becomes a WATCHED
14
- // job must disarm it (a job reporting progress is not something to time out),
15
- // then re-arm it for the last, ordinary step the server performs by itself once
16
- // the clone is done. There is no Reload here, unlike the restore panel: the
17
- // session does not exist until the clone lands.
18
-
19
- const TARGET = '/home/u/dev/github/owner/repo';
20
-
21
- function cloneJob(overrides: Record<string, unknown> = {}) {
22
- return {
23
- id: 3,
24
- kind: 'clone',
25
- targetPath: TARGET,
26
- url: 'git@github.com:owner/repo.git',
27
- state: 'running',
28
- progress: {
29
- phase: 'receiving',
30
- scope: 'repository',
31
- percent: 12,
32
- indeterminate: false,
33
- text: 'Receiving objects: 12% (12/100)',
34
- at: 1,
35
- },
36
- startedAt: 1,
37
- ...overrides,
38
- };
39
- }
40
-
41
- describe('new-session clone progress', () => {
42
- let ws: ReturnType<typeof makeWSFactory>;
43
- let client: WhereverClient;
44
-
45
- /** What the dashboard's "Clone Repository" answer sends. */
46
- function createWithClone() {
47
- client.createSession(TARGET, undefined, false, false, undefined, true);
48
- }
49
-
50
- beforeEach(() => {
51
- vi.useFakeTimers();
52
- ws = makeWSFactory();
53
- client = new WhereverClient({
54
- host: 'localhost',
55
- port: 1234,
56
- secure: false,
57
- WebSocketCtor: ws.ctor,
58
- });
59
- client.connect();
60
- ws.last().open();
61
- });
62
-
63
- afterEach(() => {
64
- client.disconnect(true);
65
- vi.useRealTimers();
66
- });
67
-
68
- it('adopts the clone job as the create, dropping the blocking overlay', () => {
69
- createWithClone();
70
- expect(get(client.stateStore).creatingSession).toBe(true);
71
-
72
- ws.last().receive({
73
- type: 'restore_started',
74
- targetPath: TARGET,
75
- outcome: 'started',
76
- job: cloneJob(),
77
- });
78
-
79
- const s = get(client.stateStore);
80
- // The overlay gives way to the same progress display the panel renders...
81
- expect(s.creatingSession).toBe(false);
82
- expect(s.restore).toEqual({
83
- targetPath: TARGET,
84
- job: cloneJob(),
85
- joined: false,
86
- rejection: null,
87
- // ...marked as a create's first step, because it ends differently:
88
- // the server continues into creation instead of offering a Reload.
89
- forSessionCreate: true,
90
- });
91
- });
92
-
93
- it('does not time out a clone that outruns the 25s create watchdog', () => {
94
- createWithClone();
95
- ws.last().receive({
96
- type: 'restore_started',
97
- targetPath: TARGET,
98
- outcome: 'started',
99
- job: cloneJob(),
100
- });
101
-
102
- // A large repository: minutes of real progress, and the watchdog would
103
- // have fired four times over. This is exactly what the old synchronous
104
- // clone could not survive.
105
- for (const percent of [30, 60, 90]) {
106
- vi.advanceTimersByTime(60_000);
107
- ws.last().receive({
108
- type: 'restore_progress',
109
- targetPath: TARGET,
110
- job: cloneJob({progress: {...cloneJob().progress, percent}}),
111
- });
112
- }
113
-
114
- const s = get(client.stateStore);
115
- expect(s.sessionError).toBeFalsy();
116
- expect(s.creatingSession).toBe(false);
117
- expect(s.restore?.job?.progress?.percent).toBe(90);
118
- });
119
-
120
- it('hands the screen back to the create when the clone is done', () => {
121
- createWithClone();
122
- ws.last().receive({
123
- type: 'restore_started',
124
- targetPath: TARGET,
125
- outcome: 'started',
126
- job: cloneJob(),
127
- });
128
- ws.last().receive({
129
- type: 'restore_complete',
130
- targetPath: TARGET,
131
- job: cloneJob({state: 'done'}),
132
- });
133
-
134
- // No Reload offer, no lingering panel: the server is already creating the
135
- // session, so the ordinary overlay (and its watchdog) covers that step.
136
- let s = get(client.stateStore);
137
- expect(s.restore).toBeNull();
138
- expect(s.creatingSession).toBe(true);
139
- expect(s.sessionError).toBeFalsy();
140
-
141
- ws.last().receive({
142
- type: 'session_created',
143
- sessionId: 'sid-1',
144
- sessionFile: `${TARGET}/session.jsonl`,
145
- cwd: TARGET,
146
- model: 'fake:model',
147
- isStreaming: false,
148
- });
149
-
150
- s = get(client.stateStore);
151
- expect(s.creatingSession).toBe(false);
152
- expect(s.activeSessionFile).toBe(`${TARGET}/session.jsonl`);
153
-
154
- // The re-armed watchdog was disarmed again by the reply.
155
- vi.advanceTimersByTime(30_000);
156
- expect(get(client.stateStore).sessionError).toBeFalsy();
157
- });
158
-
159
- it('re-arms the watchdog for the creation step the server still owes', () => {
160
- createWithClone();
161
- ws.last().receive({
162
- type: 'restore_started',
163
- targetPath: TARGET,
164
- outcome: 'started',
165
- job: cloneJob(),
166
- });
167
- ws.last().receive({
168
- type: 'restore_complete',
169
- targetPath: TARGET,
170
- job: cloneJob({state: 'done'}),
171
- });
172
-
173
- // The clone landed but the create reply never comes: the safety net the
174
- // clone suspended is back, so the overlay still cannot hang forever.
175
- vi.advanceTimersByTime(30_000);
176
- const s = get(client.stateStore);
177
- expect(s.creatingSession).toBe(false);
178
- expect(s.sessionError).toBeTruthy();
179
- });
180
-
181
- it('ends the create when the clone fails, letting session_error speak', () => {
182
- createWithClone();
183
- ws.last().receive({
184
- type: 'restore_started',
185
- targetPath: TARGET,
186
- outcome: 'started',
187
- job: cloneJob(),
188
- });
189
- ws.last().receive({
190
- type: 'restore_complete',
191
- targetPath: TARGET,
192
- job: cloneJob({
193
- state: 'failed',
194
- failure: {
195
- cause: 'not-found',
196
- message: 'Repository not found.',
197
- stderr: 'fatal: repository not found',
198
- },
199
- }),
200
- });
201
-
202
- // The panel would stay on screen in its failed state; a create has no
203
- // panel to stay in, so the mapped cause arrives on the create's own
204
- // channel and the restore state goes away with the create.
205
- let s = get(client.stateStore);
206
- expect(s.restore).toBeNull();
207
- expect(s.creatingSession).toBe(false);
208
-
209
- ws.last().receive({
210
- type: 'session_error',
211
- error: 'Repository not found.',
212
- });
213
- s = get(client.stateStore);
214
- expect(s.sessionError).toBe('Repository not found.');
215
-
216
- // And no watchdog is left armed to speak over it.
217
- vi.advanceTimersByTime(30_000);
218
- expect(get(client.stateStore).sessionError).toBe('Repository not found.');
219
- });
220
-
221
- it('leaves the restore PANEL path alone: no create, no adoption', () => {
222
- // A loaded session whose folder is missing: same frame, but there IS a
223
- // session, the panel owns the outcome, and the ending is a Reload.
224
- const sessionFile = `${TARGET}/session.jsonl`;
225
- client.joinSession(sessionFile);
226
- ws.last().receive({
227
- type: 'session_created',
228
- sessionId: 'sid-1',
229
- sessionFile,
230
- cwd: TARGET,
231
- model: 'fake:model',
232
- readOnly: true,
233
- folderMissing: true,
234
- pending: true,
235
- });
236
- ws.last().receive({
237
- type: 'folder_missing',
238
- sessionId: 'sid-1',
239
- cwd: TARGET,
240
- });
241
- ws.last().receive({
242
- type: 'restore_started',
243
- targetPath: TARGET,
244
- outcome: 'started',
245
- job: cloneJob(),
246
- });
247
-
248
- let s = get(client.stateStore);
249
- expect(s.restore?.forSessionCreate).toBeUndefined();
250
- expect(s.restore?.job?.id).toBe(3);
251
-
252
- // Completion keeps the panel, which offers the Reload; it does not hand
253
- // back to a create that never existed.
254
- ws.last().receive({
255
- type: 'restore_complete',
256
- targetPath: TARGET,
257
- job: cloneJob({state: 'done'}),
258
- });
259
- s = get(client.stateStore);
260
- expect(s.restore?.job?.state).toBe('done');
261
- expect(s.creatingSession).toBe(false);
262
- });
263
- });