@wherever-dev/client 0.7.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.
- package/CHANGELOG.md +25 -0
- package/README.md +63 -0
- package/dist/client.d.ts +93 -2
- package/dist/client.js +960 -63
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +69 -0
- package/dist/types.js.map +1 -1
- package/package.json +23 -3
- package/src/client.ts +1031 -63
- package/src/types.ts +97 -0
- package/test/agent-pending.test.ts +0 -107
- package/test/conversation-mode-flag.test.ts +0 -111
- package/test/creating-session-watchdog.test.ts +0 -82
- package/test/folder-conflict-read-only.test.ts +0 -145
- package/test/folder-missing-read-only.test.ts +0 -114
- package/test/harness.ts +0 -97
- package/test/message-delivery-confirmation.test.ts +0 -320
- package/test/mid-stream-steer.test.ts +0 -91
- package/test/new-session-clone-progress.test.ts +0 -263
- package/test/optimistic-force-command.test.ts +0 -127
- package/test/queued-steer-restored.test.ts +0 -175
- package/test/reconnect-rejoins-session.test.ts +0 -136
- package/test/restore-panel.test.ts +0 -324
- package/test/resume-keeps-session.test.ts +0 -118
- package/test/session-load-by-id.test.ts +0 -100
- package/test/session-reload.test.ts +0 -82
- package/test/skills-autocomplete.test.ts +0 -113
- package/test/steer-queue-cancel.test.ts +0 -130
- package/test/superseded-connection-key.test.ts +0 -70
- package/test/superseded-session-load.test.ts +0 -180
- package/test/tool-aborted-render.test.ts +0 -170
- package/test/tool-duration-history.test.ts +0 -93
- package/test/tool-duration.test.ts +0 -86
- package/test/tool-interrupted-history.test.ts +0 -294
- package/tsconfig.json +0 -16
|
@@ -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
|
-
});
|
|
@@ -1,127 +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
|
-
// A web `!command` / `!!command` (force command) is intercepted by the server
|
|
8
|
-
// and run as a bash tool call; it is NOT echoed back as a user message. Without
|
|
9
|
-
// any local feedback the tool bubble only appeared after a full server
|
|
10
|
-
// round-trip (client -> server -> tool_start -> client), so the command did not
|
|
11
|
-
// show up instantly. The client now renders an OPTIMISTIC bash tool bubble at
|
|
12
|
-
// send time and RECONCILES the server's real tool_start onto it (no duplicate).
|
|
13
|
-
|
|
14
|
-
function setup(ws: ReturnType<typeof makeWSFactory>, isStreaming = false) {
|
|
15
|
-
const client = new WhereverClient({
|
|
16
|
-
host: 'localhost',
|
|
17
|
-
port: 1234,
|
|
18
|
-
secure: false,
|
|
19
|
-
WebSocketCtor: ws.ctor,
|
|
20
|
-
});
|
|
21
|
-
client.connect();
|
|
22
|
-
ws.last().open();
|
|
23
|
-
client.joinSession('/tmp/project/session.jsonl');
|
|
24
|
-
ws.last().receive({
|
|
25
|
-
type: 'session_created',
|
|
26
|
-
sessionId: 'sid-1',
|
|
27
|
-
sessionFile: '/tmp/project/session.jsonl',
|
|
28
|
-
cwd: '/tmp/project',
|
|
29
|
-
model: 'fake:model',
|
|
30
|
-
isStreaming,
|
|
31
|
-
});
|
|
32
|
-
return client;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
describe('optimistic force-command tool bubble', () => {
|
|
36
|
-
let ws: ReturnType<typeof makeWSFactory>;
|
|
37
|
-
let client: WhereverClient;
|
|
38
|
-
const state = () => get<WhereverState>(client.stateStore);
|
|
39
|
-
const tools = () => state().messages.filter((m) => m.role === 'tool');
|
|
40
|
-
|
|
41
|
-
beforeEach(() => {
|
|
42
|
-
vi.useFakeTimers();
|
|
43
|
-
ws = makeWSFactory();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
afterEach(() => {
|
|
47
|
-
client.disconnect(true);
|
|
48
|
-
vi.useRealTimers();
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('renders an optimistic bash bubble instantly on a !command (no user echo)', () => {
|
|
52
|
-
client = setup(ws);
|
|
53
|
-
client.sendMessage('!ls -la');
|
|
54
|
-
|
|
55
|
-
const t = tools();
|
|
56
|
-
expect(t.length).toBe(1);
|
|
57
|
-
expect(t[0].toolName).toBe('bash');
|
|
58
|
-
expect(t[0].forceCommand).toBe(true);
|
|
59
|
-
expect(t[0].optimistic).toBe(true);
|
|
60
|
-
expect(t[0].isStreaming).toBe(true);
|
|
61
|
-
expect(t[0].content).toBe('$ bash command="ls -la"');
|
|
62
|
-
// It is NOT a user message (no user echo, no delivery tracking).
|
|
63
|
-
expect(state().messages.some((m) => m.role === 'user')).toBe(false);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it('strips the !! prefix for an excluded-from-context command', () => {
|
|
67
|
-
client = setup(ws);
|
|
68
|
-
client.sendMessage('!!git status');
|
|
69
|
-
const t = tools();
|
|
70
|
-
expect(t.length).toBe(1);
|
|
71
|
-
expect(t[0].content).toBe('$ bash command="git status"');
|
|
72
|
-
expect(t[0].optimistic).toBe(true);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('reconciles the server tool_start onto the optimistic bubble (no duplicate)', () => {
|
|
76
|
-
client = setup(ws);
|
|
77
|
-
client.sendMessage('!ls -la');
|
|
78
|
-
expect(tools().length).toBe(1);
|
|
79
|
-
|
|
80
|
-
// The server runs it and emits the real tool_start (forceCommand).
|
|
81
|
-
ws.last().receive({
|
|
82
|
-
type: 'tool_start',
|
|
83
|
-
sessionId: 'sid-1',
|
|
84
|
-
toolName: 'bash',
|
|
85
|
-
args: {command: 'ls -la'},
|
|
86
|
-
forceCommand: true,
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const t = tools();
|
|
90
|
-
expect(t.length).toBe(1); // reconciled, not duplicated
|
|
91
|
-
expect(t[0].optimistic).toBeFalsy(); // flag cleared
|
|
92
|
-
expect(t[0].forceCommand).toBe(true);
|
|
93
|
-
expect(t[0].isStreaming).toBe(true);
|
|
94
|
-
|
|
95
|
-
// Output then streams and settles onto the SAME bubble.
|
|
96
|
-
ws.last().receive({type: 'tool_update', sessionId: 'sid-1', toolName: 'bash', delta: 'total 0\n'});
|
|
97
|
-
ws.last().receive({
|
|
98
|
-
type: 'tool_end',
|
|
99
|
-
sessionId: 'sid-1',
|
|
100
|
-
toolName: 'bash',
|
|
101
|
-
isError: false,
|
|
102
|
-
result: 'total 0\n',
|
|
103
|
-
forceCommand: true,
|
|
104
|
-
});
|
|
105
|
-
const done = tools();
|
|
106
|
-
expect(done.length).toBe(1);
|
|
107
|
-
expect(done[0].isStreaming).toBe(false);
|
|
108
|
-
expect(done[0].toolOutput).toContain('total 0');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('does NOT render an optimistic bubble for !sudo (deferred behind a password prompt)', () => {
|
|
112
|
-
client = setup(ws);
|
|
113
|
-
client.sendMessage('!sudo apt update');
|
|
114
|
-
expect(tools().length).toBe(0);
|
|
115
|
-
expect(state().sessionError).toBeNull();
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it('an agent-issued bash tool_start still appends its own bubble', () => {
|
|
119
|
-
client = setup(ws);
|
|
120
|
-
// No optimistic bubble exists; a plain agent tool_start (no forceCommand).
|
|
121
|
-
ws.last().receive({type: 'tool_start', sessionId: 'sid-1', toolName: 'bash', args: {command: 'echo hi'}});
|
|
122
|
-
const t = tools();
|
|
123
|
-
expect(t.length).toBe(1);
|
|
124
|
-
expect(t[0].forceCommand).toBeFalsy();
|
|
125
|
-
expect(t[0].optimistic).toBeFalsy();
|
|
126
|
-
});
|
|
127
|
-
});
|
|
@@ -1,175 +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: after a reload, a message queued mid-stream (a STEER) was invisible. The
|
|
7
|
-
// server now snapshots pi's queue on attach (queue_update), but the queued text
|
|
8
|
-
// is NOT in the session file yet, so message_history cannot contain it: with
|
|
9
|
-
// only `pendingSteering` set and no matching message, the UI had nothing to
|
|
10
|
-
// badge and the user's text simply vanished until pi injected it at the next
|
|
11
|
-
// step.
|
|
12
|
-
//
|
|
13
|
-
// Fix: queue_update re-materializes any queued text with no matching user
|
|
14
|
-
// message, so a reloaded client shows the queued messages (badged "Queued") and
|
|
15
|
-
// can still cancel them.
|
|
16
|
-
|
|
17
|
-
function newClient(ws: ReturnType<typeof makeWSFactory>) {
|
|
18
|
-
const 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
|
-
return client;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function attach(ws: ReturnType<typeof makeWSFactory>, client: WhereverClient) {
|
|
30
|
-
client.joinSession('/tmp/project/session.jsonl');
|
|
31
|
-
ws.last().receive({
|
|
32
|
-
type: 'session_created',
|
|
33
|
-
sessionId: 'sid-1',
|
|
34
|
-
sessionFile: '/tmp/project/session.jsonl',
|
|
35
|
-
cwd: '/tmp/project',
|
|
36
|
-
model: 'fake:model',
|
|
37
|
-
});
|
|
38
|
-
ws.last().receive({
|
|
39
|
-
type: 'message_history',
|
|
40
|
-
sessionId: 'sid-1',
|
|
41
|
-
messages: [{role: 'user', content: 'do the first thing', timestamp: 1}],
|
|
42
|
-
totalCount: 1,
|
|
43
|
-
offset: 0,
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
describe('a queued steer is restored into the conversation on reload', () => {
|
|
48
|
-
let ws: ReturnType<typeof makeWSFactory>;
|
|
49
|
-
let client: WhereverClient;
|
|
50
|
-
|
|
51
|
-
beforeEach(() => {
|
|
52
|
-
vi.useFakeTimers();
|
|
53
|
-
ws = makeWSFactory();
|
|
54
|
-
client = newClient(ws);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
afterEach(() => {
|
|
58
|
-
client.disconnect(true);
|
|
59
|
-
vi.useRealTimers();
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('renders a queued message the freshly-loaded history does not contain', () => {
|
|
63
|
-
attach(ws, client);
|
|
64
|
-
|
|
65
|
-
ws.last().receive({
|
|
66
|
-
type: 'queue_update',
|
|
67
|
-
sessionId: 'sid-1',
|
|
68
|
-
steering: ['actually do X instead'],
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
const s = get(client.stateStore);
|
|
72
|
-
expect(s.pendingSteering).toEqual(['actually do X instead']);
|
|
73
|
-
const restored = s.messages.filter(
|
|
74
|
-
(m) => m.role === 'user' && m.content === 'actually do X instead',
|
|
75
|
-
);
|
|
76
|
-
expect(restored).toHaveLength(1);
|
|
77
|
-
// It is server-side queued, not an unconfirmed local send: no retry banner.
|
|
78
|
-
expect(restored[0].delivery).toBeUndefined();
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('does not duplicate a queued message we sent ourselves this session', () => {
|
|
82
|
-
attach(ws, client);
|
|
83
|
-
client.sendMessage('actually do X instead');
|
|
84
|
-
|
|
85
|
-
ws.last().receive({
|
|
86
|
-
type: 'queue_update',
|
|
87
|
-
sessionId: 'sid-1',
|
|
88
|
-
steering: ['actually do X instead'],
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
const s = get(client.stateStore);
|
|
92
|
-
expect(
|
|
93
|
-
s.messages.filter((m) => m.content === 'actually do X instead'),
|
|
94
|
-
).toHaveLength(1);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('does not duplicate when the queued message is finally delivered', () => {
|
|
98
|
-
attach(ws, client);
|
|
99
|
-
ws.last().receive({
|
|
100
|
-
type: 'queue_update',
|
|
101
|
-
sessionId: 'sid-1',
|
|
102
|
-
steering: ['actually do X instead'],
|
|
103
|
-
});
|
|
104
|
-
// pi injects it: the queue empties and the server echoes the user message.
|
|
105
|
-
ws.last().receive({type: 'queue_update', sessionId: 'sid-1', steering: []});
|
|
106
|
-
ws.last().receive({
|
|
107
|
-
type: 'message_end',
|
|
108
|
-
sessionId: 'sid-1',
|
|
109
|
-
role: 'user',
|
|
110
|
-
content: 'actually do X instead',
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
const s = get(client.stateStore);
|
|
114
|
-
expect(s.pendingSteering).toEqual([]);
|
|
115
|
-
expect(
|
|
116
|
-
s.messages.filter((m) => m.content === 'actually do X instead'),
|
|
117
|
-
).toHaveLength(1);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it('restores every queued message, including repeats of the same text', () => {
|
|
121
|
-
attach(ws, client);
|
|
122
|
-
ws.last().receive({
|
|
123
|
-
type: 'queue_update',
|
|
124
|
-
sessionId: 'sid-1',
|
|
125
|
-
steering: ['ping', 'ping'],
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
const s = get(client.stateStore);
|
|
129
|
-
expect(s.messages.filter((m) => m.content === 'ping')).toHaveLength(2);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it('does not duplicate when the OLDER of two queued messages is delivered', () => {
|
|
133
|
-
attach(ws, client);
|
|
134
|
-
ws.last().receive({
|
|
135
|
-
type: 'queue_update',
|
|
136
|
-
sessionId: 'sid-1',
|
|
137
|
-
steering: ['first queued', 'second queued'],
|
|
138
|
-
});
|
|
139
|
-
// pi injects the oldest: the queue drops it and the server echoes it. The
|
|
140
|
-
// echoed message is NOT the last user bubble ('second queued' is), so a
|
|
141
|
-
// naive last-message dedupe would append a duplicate.
|
|
142
|
-
ws.last().receive({
|
|
143
|
-
type: 'queue_update',
|
|
144
|
-
sessionId: 'sid-1',
|
|
145
|
-
steering: ['second queued'],
|
|
146
|
-
});
|
|
147
|
-
ws.last().receive({
|
|
148
|
-
type: 'message_end',
|
|
149
|
-
sessionId: 'sid-1',
|
|
150
|
-
role: 'user',
|
|
151
|
-
content: 'first queued',
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
const s = get(client.stateStore);
|
|
155
|
-
expect(s.messages.filter((m) => m.content === 'first queued')).toHaveLength(1);
|
|
156
|
-
expect(s.messages.filter((m) => m.content === 'second queued')).toHaveLength(1);
|
|
157
|
-
expect(s.pendingSteering).toEqual(['second queued']);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it('leaves an already-restored queue alone on a repeated snapshot', () => {
|
|
161
|
-
attach(ws, client);
|
|
162
|
-
const snapshot = {
|
|
163
|
-
type: 'queue_update',
|
|
164
|
-
sessionId: 'sid-1',
|
|
165
|
-
steering: ['actually do X instead'],
|
|
166
|
-
};
|
|
167
|
-
ws.last().receive(snapshot);
|
|
168
|
-
ws.last().receive(snapshot);
|
|
169
|
-
|
|
170
|
-
const s = get(client.stateStore);
|
|
171
|
-
expect(
|
|
172
|
-
s.messages.filter((m) => m.content === 'actually do X instead'),
|
|
173
|
-
).toHaveLength(1);
|
|
174
|
-
});
|
|
175
|
-
});
|
|
@@ -1,136 +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: after an UNSOLICITED reconnect (the socket dropped on its own -- tab
|
|
7
|
-
// switch, network blip, laptop sleep, half-open reap -- NOT via suspend()), the
|
|
8
|
-
// client reconnected to the relay but did NOT re-issue session_load, so the new
|
|
9
|
-
// socket was attached to NO session server-side. The frontend kept showing the
|
|
10
|
-
// stale conversation (a frozen tool call as the last message, "Abort" disabled)
|
|
11
|
-
// and followed nothing, with no "connecting"/"loading" affordance, while the
|
|
12
|
-
// agent kept running behind the scenes. Only a full reload recovered it.
|
|
13
|
-
//
|
|
14
|
-
// The server is stateless per-connection: every new socket gets a fresh clientId
|
|
15
|
-
// with sessionId=null and the old socket's close removes the client from the
|
|
16
|
-
// pool. So the CLIENT must re-attach by re-issuing session_load on ANY reconnect
|
|
17
|
-
// that still holds an active session -- not only on the suspend/resume path.
|
|
18
|
-
|
|
19
|
-
function createAndLoad(
|
|
20
|
-
ws: ReturnType<typeof makeWSFactory>,
|
|
21
|
-
client: WhereverClient,
|
|
22
|
-
{streaming = false}: {streaming?: boolean} = {},
|
|
23
|
-
) {
|
|
24
|
-
client.joinSession('/tmp/project/session.jsonl');
|
|
25
|
-
ws.last().receive({
|
|
26
|
-
type: 'session_created',
|
|
27
|
-
sessionId: 'sid-1',
|
|
28
|
-
sessionFile: '/tmp/project/session.jsonl',
|
|
29
|
-
cwd: '/tmp/project',
|
|
30
|
-
model: 'fake:model',
|
|
31
|
-
isStreaming: streaming,
|
|
32
|
-
});
|
|
33
|
-
ws.last().receive({
|
|
34
|
-
type: 'message_history',
|
|
35
|
-
sessionId: 'sid-1',
|
|
36
|
-
messages: [{role: 'user', content: 'go build it', timestamp: 1}],
|
|
37
|
-
totalCount: 1,
|
|
38
|
-
offset: 0,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
describe('unsolicited reconnect re-attaches to the active session', () => {
|
|
43
|
-
let ws: ReturnType<typeof makeWSFactory>;
|
|
44
|
-
let client: WhereverClient;
|
|
45
|
-
|
|
46
|
-
beforeEach(() => {
|
|
47
|
-
vi.useFakeTimers();
|
|
48
|
-
ws = makeWSFactory();
|
|
49
|
-
client = new WhereverClient({
|
|
50
|
-
host: 'localhost',
|
|
51
|
-
port: 1234,
|
|
52
|
-
secure: false,
|
|
53
|
-
WebSocketCtor: ws.ctor,
|
|
54
|
-
});
|
|
55
|
-
client.connect();
|
|
56
|
-
ws.last().open();
|
|
57
|
-
createAndLoad(ws, client, {streaming: true});
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
afterEach(() => {
|
|
61
|
-
client.disconnect(true);
|
|
62
|
-
vi.useRealTimers();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('re-issues session_load after the socket drops and reconnects', () => {
|
|
66
|
-
const firstWs = ws.last();
|
|
67
|
-
// The socket dies on its own (no suspend). onClose schedules a reconnect.
|
|
68
|
-
firstWs.close();
|
|
69
|
-
|
|
70
|
-
// The reconnect backoff timer fires and opens a brand-new socket.
|
|
71
|
-
vi.advanceTimersByTime(5000);
|
|
72
|
-
const secondWs = ws.last();
|
|
73
|
-
expect(secondWs).not.toBe(firstWs);
|
|
74
|
-
secondWs.open();
|
|
75
|
-
|
|
76
|
-
// The client MUST re-attach to the previously-active session so the live
|
|
77
|
-
// stream resumes; otherwise it is silently detached and frozen.
|
|
78
|
-
const load = secondWs.lastSentOfType('session_load');
|
|
79
|
-
expect(load).toBeTruthy();
|
|
80
|
-
expect(load.sessionFile).toBe('/tmp/project/session.jsonl');
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it('shows a resyncing affordance during the reconnect, not a silent frozen view', () => {
|
|
84
|
-
const firstWs = ws.last();
|
|
85
|
-
firstWs.close();
|
|
86
|
-
vi.advanceTimersByTime(5000);
|
|
87
|
-
const secondWs = ws.last();
|
|
88
|
-
secondWs.open();
|
|
89
|
-
|
|
90
|
-
// While re-attaching, resyncing is true (drives the "Reconnecting and
|
|
91
|
-
// syncing session..." banner + blocks sending) and the cached conversation
|
|
92
|
-
// stays visible.
|
|
93
|
-
const s = get(client.stateStore);
|
|
94
|
-
expect(s.resyncing).toBe(true);
|
|
95
|
-
expect(s.activeSessionFile).toBe('/tmp/project/session.jsonl');
|
|
96
|
-
expect(s.messages.length).toBeGreaterThan(0);
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
it('clears resyncing and resumes the stream once fresh history arrives', () => {
|
|
100
|
-
ws.last().close();
|
|
101
|
-
vi.advanceTimersByTime(5000);
|
|
102
|
-
const secondWs = ws.last();
|
|
103
|
-
secondWs.open();
|
|
104
|
-
|
|
105
|
-
secondWs.receive({
|
|
106
|
-
type: 'session_created',
|
|
107
|
-
sessionId: 'sid-1',
|
|
108
|
-
sessionFile: '/tmp/project/session.jsonl',
|
|
109
|
-
cwd: '/tmp/project',
|
|
110
|
-
model: 'fake:model',
|
|
111
|
-
isStreaming: true,
|
|
112
|
-
});
|
|
113
|
-
secondWs.receive({
|
|
114
|
-
type: 'message_history',
|
|
115
|
-
sessionId: 'sid-1',
|
|
116
|
-
messages: [
|
|
117
|
-
{role: 'user', content: 'go build it', timestamp: 1},
|
|
118
|
-
{role: 'assistant', content: 'on it', timestamp: 2},
|
|
119
|
-
],
|
|
120
|
-
totalCount: 2,
|
|
121
|
-
offset: 0,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
const s = get(client.stateStore);
|
|
125
|
-
expect(s.resyncing).toBe(false);
|
|
126
|
-
expect(s.connected).toBe(true);
|
|
127
|
-
// Re-attach restores the true streaming state from the server, so "Abort"
|
|
128
|
-
// re-enables if the agent is still working (the reported symptom: Abort
|
|
129
|
-
// disabled with a stale tool call as last message).
|
|
130
|
-
expect(s.isStreaming).toBe(true);
|
|
131
|
-
// Live stream is following again: a new event after resync lands.
|
|
132
|
-
secondWs.receive({type: 'agent_end'});
|
|
133
|
-
vi.advanceTimersByTime(400);
|
|
134
|
-
expect(get(client.stateStore).isStreaming).toBe(false);
|
|
135
|
-
});
|
|
136
|
-
});
|