@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
package/src/types.ts
CHANGED
|
@@ -227,6 +227,9 @@ export interface WhereverState {
|
|
|
227
227
|
// version), as reported in its `connected` message. null until connected, or
|
|
228
228
|
// when talking to a server old enough not to report it.
|
|
229
229
|
serverVersion: string | null;
|
|
230
|
+
// Version of the pi SDK that server runs its sessions on. null until
|
|
231
|
+
// connected, or when the server is too old to report it.
|
|
232
|
+
piVersion: string | null;
|
|
230
233
|
folderConflict: FolderConflictInfo | null;
|
|
231
234
|
// The active session's working folder is gone from this machine (see
|
|
232
235
|
// FolderMissingInfo). Non-null implies `readOnly`, and no `session_ready` is
|
|
@@ -264,6 +267,18 @@ export interface WhereverState {
|
|
|
264
267
|
historyTotalCount: number;
|
|
265
268
|
historyOffset: number;
|
|
266
269
|
loadingMoreHistory: boolean;
|
|
270
|
+
// True once the server's `message_history` for the active session has landed.
|
|
271
|
+
// False at hydration (the messages came from the on-device cache) and on every
|
|
272
|
+
// reconnect rejoin, so `historyTotalCount` / `historyOffset` may be stale:
|
|
273
|
+
// `loadMoreHistory()` is a no-op while false (ADR 0013).
|
|
274
|
+
historyAuthoritative: boolean;
|
|
275
|
+
// The STAMPED identity (`serverKey(config)`) of the server that delivered the
|
|
276
|
+
// active session: set on `session_created` from the key captured when that
|
|
277
|
+
// socket was opened, and at hydration from the cached record. Never
|
|
278
|
+
// re-derived from the current settings (they can be edited without a
|
|
279
|
+
// reconnect). The web writes its conversation cache under exactly this key.
|
|
280
|
+
// null when there is no stamped session.
|
|
281
|
+
serverKey: string | null;
|
|
267
282
|
// Context-window usage for the active session (drives the "11.3% / 1.0M"
|
|
268
283
|
// indicator). null when unknown (no model, no usage yet, or just compacted).
|
|
269
284
|
contextUsage: ContextUsage | null;
|
|
@@ -283,6 +298,34 @@ export interface WhereverState {
|
|
|
283
298
|
skills: SkillCommand[];
|
|
284
299
|
}
|
|
285
300
|
|
|
301
|
+
/**
|
|
302
|
+
* A conversation read back from the web's on-device cache, handed to
|
|
303
|
+
* `WhereverClient.hydrateCachedSession()` so it can be shown before the socket
|
|
304
|
+
* is up (ADR 0013). Structurally a subset of the web cache's record, so a record
|
|
305
|
+
* can be passed as-is.
|
|
306
|
+
*/
|
|
307
|
+
export interface HydrationSnapshot {
|
|
308
|
+
/** The stamp the record was written under. Defaults to `serverKey(config)`. */
|
|
309
|
+
serverKey?: string;
|
|
310
|
+
sessionId: string;
|
|
311
|
+
sessionFile: string;
|
|
312
|
+
cwd: string | null;
|
|
313
|
+
model: string | null;
|
|
314
|
+
messages: ChatMessage[];
|
|
315
|
+
historyTotalCount?: number;
|
|
316
|
+
historyOffset?: number;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Synthesized by the client (never sent by the server) and delivered to
|
|
321
|
+
* `onMessage` listeners when the server refused the load of a HYDRATED session
|
|
322
|
+
* outright: the cached record is dead and should be evicted.
|
|
323
|
+
*/
|
|
324
|
+
export interface HydrationRejectedMessage {
|
|
325
|
+
type: 'hydration_rejected';
|
|
326
|
+
sessionId: string;
|
|
327
|
+
}
|
|
328
|
+
|
|
286
329
|
export interface SkillCommand {
|
|
287
330
|
name: string;
|
|
288
331
|
description?: string;
|
|
@@ -350,3 +393,57 @@ export function skillInvocationIdentity(content: string): string | null {
|
|
|
350
393
|
if (!parsed) return null;
|
|
351
394
|
return `skill:${parsed.skillName}\u0000${parsed.args}`;
|
|
352
395
|
}
|
|
396
|
+
|
|
397
|
+
// --- Uploads ---------------------------------------------------------------
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* The bytes of a file to upload, without any platform type (`File` / `Blob`):
|
|
401
|
+
* the client package is platform-neutral, so the web implements this over
|
|
402
|
+
* `File.slice().arrayBuffer()`. `read` may throw a `NotReadableError` (iOS and
|
|
403
|
+
* Android can invalidate a picked file once the page was backgrounded); the
|
|
404
|
+
* upload then fails with code `not_readable` ("pick it again").
|
|
405
|
+
*/
|
|
406
|
+
export interface UploadByteSource {
|
|
407
|
+
size: number;
|
|
408
|
+
read(offset: number, length: number): Promise<Uint8Array>;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/**
|
|
412
|
+
* Lifecycle of one upload. `queued` (not sent yet: no socket, held for a rejoin,
|
|
413
|
+
* or the socket's capabilities are not known yet) -> `sending` -> `paused`
|
|
414
|
+
* (its socket was lost; it waits for the next one) -> `finishing` (chunked only:
|
|
415
|
+
* every byte acked, `upload_finish` sent) -> `done` | `failed` | `aborted`.
|
|
416
|
+
*/
|
|
417
|
+
export type UploadState =
|
|
418
|
+
| 'queued'
|
|
419
|
+
| 'sending'
|
|
420
|
+
| 'paused'
|
|
421
|
+
| 'finishing'
|
|
422
|
+
| 'done'
|
|
423
|
+
| 'failed'
|
|
424
|
+
| 'aborted';
|
|
425
|
+
|
|
426
|
+
/** `code` lets a UI react without matching on text. */
|
|
427
|
+
export interface UploadError {
|
|
428
|
+
message: string;
|
|
429
|
+
code?: 'not_readable';
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Progress of one upload: the store entry (`WhereverClient.uploadsStore`, keyed
|
|
434
|
+
* by uploadId) and the `onProgress` payload share this shape. `acked` is the
|
|
435
|
+
* byte count the SERVER acknowledged (never what was merely sent); the legacy
|
|
436
|
+
* one-frame protocol reports 0 until done.
|
|
437
|
+
*/
|
|
438
|
+
export interface UploadProgress {
|
|
439
|
+
acked: number;
|
|
440
|
+
size: number;
|
|
441
|
+
state: UploadState;
|
|
442
|
+
error?: UploadError;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
export interface UploadOptions {
|
|
446
|
+
signal?: AbortSignal;
|
|
447
|
+
mime?: string;
|
|
448
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
449
|
+
}
|
|
@@ -1,107 +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
|
-
// 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
|
-
});
|
|
@@ -1,111 +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 per-turn CONVERSATION-MODE SIGNAL on the wire: a spoken conversation is
|
|
8
|
-
// state that lives in the web app's knobs registry, and a dictated message is
|
|
9
|
-
// byte-identical to a typed one, so the agent could never tell the mode was on
|
|
10
|
-
// and never called `say`. The client now stamps an OPTIONAL `conversationMode`
|
|
11
|
-
// boolean on the EXISTING `message` payload (no new message type, no new chat
|
|
12
|
-
// role); when off the field is absent, so the frame is exactly what it was before
|
|
13
|
-
// and an older server ignores it.
|
|
14
|
-
|
|
15
|
-
function installLocalStorage() {
|
|
16
|
-
const store = new Map<string, string>();
|
|
17
|
-
(globalThis as any).localStorage = {
|
|
18
|
-
getItem: (k: string) => (store.has(k) ? store.get(k)! : null),
|
|
19
|
-
setItem: (k: string, v: string) => void store.set(k, v),
|
|
20
|
-
removeItem: (k: string) => void store.delete(k),
|
|
21
|
-
clear: () => store.clear(),
|
|
22
|
-
};
|
|
23
|
-
return store;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function createAndLoad(ws: ReturnType<typeof makeWSFactory>, client: WhereverClient) {
|
|
27
|
-
client.joinSession('/tmp/project/session.jsonl');
|
|
28
|
-
ws.last().receive({
|
|
29
|
-
type: 'session_created',
|
|
30
|
-
sessionId: 'sid-1',
|
|
31
|
-
sessionFile: '/tmp/project/session.jsonl',
|
|
32
|
-
cwd: '/tmp/project',
|
|
33
|
-
model: 'fake:model',
|
|
34
|
-
isStreaming: false,
|
|
35
|
-
});
|
|
36
|
-
ws.last().receive({
|
|
37
|
-
type: 'message_history',
|
|
38
|
-
sessionId: 'sid-1',
|
|
39
|
-
messages: [],
|
|
40
|
-
totalCount: 0,
|
|
41
|
-
offset: 0,
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
describe('conversation-mode flag on the message payload', () => {
|
|
46
|
-
let ws: ReturnType<typeof makeWSFactory>;
|
|
47
|
-
let client: WhereverClient;
|
|
48
|
-
const state = () => get<WhereverState>(client.stateStore);
|
|
49
|
-
|
|
50
|
-
beforeEach(() => {
|
|
51
|
-
vi.useFakeTimers();
|
|
52
|
-
installLocalStorage();
|
|
53
|
-
(globalThis as any).localStorage.clear();
|
|
54
|
-
ws = makeWSFactory();
|
|
55
|
-
client = new WhereverClient({
|
|
56
|
-
host: 'localhost',
|
|
57
|
-
port: 1234,
|
|
58
|
-
secure: false,
|
|
59
|
-
WebSocketCtor: ws.ctor,
|
|
60
|
-
});
|
|
61
|
-
client.connect();
|
|
62
|
-
ws.last().open();
|
|
63
|
-
createAndLoad(ws, client);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
afterEach(() => {
|
|
67
|
-
client.disconnect(true);
|
|
68
|
-
vi.useRealTimers();
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it('omits the field entirely for a normal send (no options)', () => {
|
|
72
|
-
expect(client.sendMessage('plain send')).toBe(true);
|
|
73
|
-
const frame = ws.last().lastSentOfType('message');
|
|
74
|
-
expect(frame.message).toBe('plain send');
|
|
75
|
-
expect('conversationMode' in frame).toBe(false);
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
it('omits the field when the caller passes conversationMode: false', () => {
|
|
79
|
-
client.sendMessage('mode off', {conversationMode: false});
|
|
80
|
-
const frame = ws.last().lastSentOfType('message');
|
|
81
|
-
expect('conversationMode' in frame).toBe(false);
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('stamps conversationMode: true when the caller asks for it', () => {
|
|
85
|
-
client.sendMessage('speak this back', {conversationMode: true});
|
|
86
|
-
const frame = ws.last().lastSentOfType('message');
|
|
87
|
-
expect(frame.type).toBe('message');
|
|
88
|
-
expect(frame.conversationMode).toBe(true);
|
|
89
|
-
// The user text is untouched: the signal is a field, never a preamble.
|
|
90
|
-
expect(frame.message).toBe('speak this back');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('keeps the local echo free of the flag (nothing user-visible changes)', () => {
|
|
94
|
-
client.sendMessage('echo check', {conversationMode: true});
|
|
95
|
-
const echo = state().messages.find((m) => m.content === 'echo check')!;
|
|
96
|
-
expect(echo.content).toBe('echo check');
|
|
97
|
-
expect((echo as unknown as Record<string, unknown>).conversationMode).toBeUndefined();
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
it('re-stamps the flag on resend, from the caller (a resend is a fresh turn)', () => {
|
|
101
|
-
client.sendMessage('retry me', {conversationMode: true});
|
|
102
|
-
const id = state().messages.find((m) => m.content === 'retry me')!.id;
|
|
103
|
-
// The user flipped the mode OFF before hitting Retry: no flag this time.
|
|
104
|
-
expect(client.resendMessage(id)).toBe(true);
|
|
105
|
-
expect('conversationMode' in ws.last().lastSentOfType('message')).toBe(false);
|
|
106
|
-
|
|
107
|
-
// And with the mode back on, the resend carries it again.
|
|
108
|
-
expect(client.resendMessage(id, {conversationMode: true})).toBe(true);
|
|
109
|
-
expect(ws.last().lastSentOfType('message').conversationMode).toBe(true);
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -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
|
-
// 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
|
-
});
|
|
@@ -1,145 +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 client attached read-only because of a FOLDER CONFLICT can only escape in
|
|
7
|
-
// two ways: click "Continue anyway" (which lives on the conflict banner), or
|
|
8
|
-
// have the conflict resolve on its own. Both hinge on the live `folder_conflict`
|
|
9
|
-
// update, which now carries the server's authoritative `readOnly`:
|
|
10
|
-
// - while the conflict is active, the banner must stay up (it holds the only
|
|
11
|
-
// escape hatch); dropping it strands the user read-only with no affordance;
|
|
12
|
-
// - once it resolves, read-only must be RELEASED, since the banner that could
|
|
13
|
-
// have lifted it is gone.
|
|
14
|
-
|
|
15
|
-
describe('folder-conflict read-only lifecycle', () => {
|
|
16
|
-
let ws: ReturnType<typeof makeWSFactory>;
|
|
17
|
-
let client: WhereverClient;
|
|
18
|
-
|
|
19
|
-
function attachAsConflictObserver() {
|
|
20
|
-
client.createSession('/tmp/project');
|
|
21
|
-
ws.last().receive({
|
|
22
|
-
type: 'session_created',
|
|
23
|
-
sessionId: 'sid-1',
|
|
24
|
-
sessionFile: '/tmp/project/session.jsonl',
|
|
25
|
-
cwd: '/tmp/project',
|
|
26
|
-
model: 'fake:model',
|
|
27
|
-
readOnly: true,
|
|
28
|
-
folderConflict: true,
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
vi.useFakeTimers();
|
|
34
|
-
ws = makeWSFactory();
|
|
35
|
-
client = new WhereverClient({
|
|
36
|
-
host: 'localhost',
|
|
37
|
-
port: 1234,
|
|
38
|
-
secure: false,
|
|
39
|
-
WebSocketCtor: ws.ctor,
|
|
40
|
-
});
|
|
41
|
-
client.connect();
|
|
42
|
-
ws.last().open();
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
afterEach(() => {
|
|
46
|
-
client.disconnect(true);
|
|
47
|
-
vi.useRealTimers();
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('keeps the banner (and its escape hatch) while the conflict is active', () => {
|
|
51
|
-
attachAsConflictObserver();
|
|
52
|
-
expect(get(client.stateStore).readOnly).toBe(true);
|
|
53
|
-
expect(get(client.stateStore).folderConflict).toEqual({
|
|
54
|
-
cwd: '/tmp/project',
|
|
55
|
-
active: true,
|
|
56
|
-
continued: false,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
ws.last().receive({
|
|
60
|
-
type: 'folder_conflict',
|
|
61
|
-
cwd: '/tmp/project',
|
|
62
|
-
active: true,
|
|
63
|
-
readOnly: true,
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
const s = get(client.stateStore);
|
|
67
|
-
expect(s.folderConflict?.active).toBe(true);
|
|
68
|
-
// Not continued: the "Continue anyway" button must still be offered.
|
|
69
|
-
expect(s.folderConflict?.continued).toBe(false);
|
|
70
|
-
expect(s.readOnly).toBe(true);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('releases read-only when the conflict resolves', () => {
|
|
74
|
-
attachAsConflictObserver();
|
|
75
|
-
|
|
76
|
-
ws.last().receive({
|
|
77
|
-
type: 'folder_conflict',
|
|
78
|
-
cwd: '/tmp/project',
|
|
79
|
-
active: false,
|
|
80
|
-
readOnly: false,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
const s = get(client.stateStore);
|
|
84
|
-
expect(s.folderConflict).toBeNull();
|
|
85
|
-
expect(s.readOnly).toBe(false);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('keeps a hard read-only session locked when the server says so', () => {
|
|
89
|
-
attachAsConflictObserver();
|
|
90
|
-
|
|
91
|
-
// A sessions.readOnly folder: the conflict is gone but the server still
|
|
92
|
-
// reports read-only, which is not a dismissible warning.
|
|
93
|
-
ws.last().receive({
|
|
94
|
-
type: 'folder_conflict',
|
|
95
|
-
cwd: '/tmp/project',
|
|
96
|
-
active: false,
|
|
97
|
-
readOnly: true,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const s = get(client.stateStore);
|
|
101
|
-
expect(s.folderConflict).toBeNull();
|
|
102
|
-
expect(s.readOnly).toBe(true);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('converges when a pre-continue broadcast arrives after the optimistic continue', () => {
|
|
106
|
-
attachAsConflictObserver();
|
|
107
|
-
client.continueFolderConflict();
|
|
108
|
-
expect(get(client.stateStore).readOnly).toBe(false);
|
|
109
|
-
|
|
110
|
-
// In flight before the server saw the continue: it still carries the old
|
|
111
|
-
// verdict and re-locks the composer, while `continued` has already removed
|
|
112
|
-
// the banner's button. Only the server's answer to the continue settles it,
|
|
113
|
-
// and same-socket ordering guarantees that answer lands last.
|
|
114
|
-
ws.last().receive({
|
|
115
|
-
type: 'folder_conflict',
|
|
116
|
-
cwd: '/tmp/project',
|
|
117
|
-
active: true,
|
|
118
|
-
readOnly: true,
|
|
119
|
-
});
|
|
120
|
-
expect(get(client.stateStore).readOnly).toBe(true);
|
|
121
|
-
|
|
122
|
-
ws.last().receive({
|
|
123
|
-
type: 'folder_conflict',
|
|
124
|
-
cwd: '/tmp/project',
|
|
125
|
-
active: true,
|
|
126
|
-
readOnly: false,
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
const s = get(client.stateStore);
|
|
130
|
-
expect(s.readOnly).toBe(false);
|
|
131
|
-
expect(s.folderConflict).toEqual({
|
|
132
|
-
cwd: '/tmp/project',
|
|
133
|
-
active: true,
|
|
134
|
-
continued: true,
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
it('leaves read-only untouched when the server omits it (older server)', () => {
|
|
139
|
-
attachAsConflictObserver();
|
|
140
|
-
|
|
141
|
-
ws.last().receive({type: 'folder_conflict', cwd: '/tmp/project', active: false});
|
|
142
|
-
|
|
143
|
-
expect(get(client.stateStore).readOnly).toBe(true);
|
|
144
|
-
});
|
|
145
|
-
});
|
|
@@ -1,114 +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
|
-
// FOLDER MISSING is the third read-only reason: the session's working folder
|
|
7
|
-
// does not exist on this machine, so the server built no live agent and refuses
|
|
8
|
-
// every send. It is HARD -- unlike a folder conflict there is no "Continue
|
|
9
|
-
// anyway" -- and it is cured by restoring the folder and RELOADING, never by a
|
|
10
|
-
// client-side dismiss. The client mirrors it so the UI can replace the composer
|
|
11
|
-
// with a notice naming the absolute path.
|
|
12
|
-
|
|
13
|
-
describe('missing-folder read-only state', () => {
|
|
14
|
-
let ws: ReturnType<typeof makeWSFactory>;
|
|
15
|
-
let client: WhereverClient;
|
|
16
|
-
|
|
17
|
-
function loadMissingFolderSession() {
|
|
18
|
-
client.joinSession('/tmp/gone/session.jsonl');
|
|
19
|
-
ws.last().receive({
|
|
20
|
-
type: 'session_created',
|
|
21
|
-
sessionId: 'sid-1',
|
|
22
|
-
sessionFile: '/tmp/gone/session.jsonl',
|
|
23
|
-
cwd: '/tmp/gone',
|
|
24
|
-
model: 'fake:model',
|
|
25
|
-
readOnly: true,
|
|
26
|
-
folderMissing: true,
|
|
27
|
-
pending: true,
|
|
28
|
-
});
|
|
29
|
-
ws.last().receive({
|
|
30
|
-
type: 'folder_missing',
|
|
31
|
-
sessionId: 'sid-1',
|
|
32
|
-
cwd: '/tmp/gone',
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
vi.useFakeTimers();
|
|
38
|
-
ws = makeWSFactory();
|
|
39
|
-
client = new WhereverClient({
|
|
40
|
-
host: 'localhost',
|
|
41
|
-
port: 1234,
|
|
42
|
-
secure: false,
|
|
43
|
-
WebSocketCtor: ws.ctor,
|
|
44
|
-
});
|
|
45
|
-
client.connect();
|
|
46
|
-
ws.last().open();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
afterEach(() => {
|
|
50
|
-
client.disconnect(true);
|
|
51
|
-
vi.useRealTimers();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
it('locks the session and records the absolute missing path', () => {
|
|
55
|
-
loadMissingFolderSession();
|
|
56
|
-
|
|
57
|
-
const s = get(client.stateStore);
|
|
58
|
-
expect(s.readOnly).toBe(true);
|
|
59
|
-
expect(s.folderMissing).toEqual({cwd: '/tmp/gone'});
|
|
60
|
-
// No agent is coming (the server built none), so the composer stays gated.
|
|
61
|
-
expect(s.agentPending).toBe(true);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it('is not lifted by "Continue anyway"', () => {
|
|
65
|
-
loadMissingFolderSession();
|
|
66
|
-
// A folder conflict is raised on top (or a stale UI still shows its
|
|
67
|
-
// button): continuing answers the CONFLICT, never the missing folder.
|
|
68
|
-
ws.last().receive({
|
|
69
|
-
type: 'folder_conflict',
|
|
70
|
-
cwd: '/tmp/gone',
|
|
71
|
-
active: true,
|
|
72
|
-
readOnly: true,
|
|
73
|
-
});
|
|
74
|
-
client.continueFolderConflict();
|
|
75
|
-
|
|
76
|
-
const s = get(client.stateStore);
|
|
77
|
-
expect(s.readOnly).toBe(true);
|
|
78
|
-
expect(s.folderMissing).toEqual({cwd: '/tmp/gone'});
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('stays locked when a conflict update reports the server verdict', () => {
|
|
82
|
-
loadMissingFolderSession();
|
|
83
|
-
|
|
84
|
-
ws.last().receive({
|
|
85
|
-
type: 'folder_conflict',
|
|
86
|
-
cwd: '/tmp/gone',
|
|
87
|
-
active: false,
|
|
88
|
-
readOnly: true,
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
expect(get(client.stateStore).readOnly).toBe(true);
|
|
92
|
-
expect(get(client.stateStore).folderMissing).toEqual({cwd: '/tmp/gone'});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('clears with the session it belonged to', () => {
|
|
96
|
-
loadMissingFolderSession();
|
|
97
|
-
|
|
98
|
-
client.switchSession('/tmp/present/session.jsonl');
|
|
99
|
-
expect(get(client.stateStore).folderMissing).toBeNull();
|
|
100
|
-
|
|
101
|
-
ws.last().receive({
|
|
102
|
-
type: 'session_created',
|
|
103
|
-
sessionId: 'sid-2',
|
|
104
|
-
sessionFile: '/tmp/present/session.jsonl',
|
|
105
|
-
cwd: '/tmp/present',
|
|
106
|
-
model: 'fake:model',
|
|
107
|
-
pending: true,
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
const s = get(client.stateStore);
|
|
111
|
-
expect(s.folderMissing).toBeNull();
|
|
112
|
-
expect(s.readOnly).toBe(false);
|
|
113
|
-
});
|
|
114
|
-
});
|