@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.
- package/CHANGELOG.md +12 -0
- package/README.md +63 -0
- package/dist/client.d.ts +5 -0
- package/dist/client.js +102 -44
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +1 -0
- package/dist/types.js.map +1 -1
- package/package.json +23 -3
- package/src/client.ts +105 -49
- package/src/types.ts +3 -0
- package/test/agent-pending.test.ts +0 -107
- package/test/chunked-upload.test.ts +0 -483
- 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 -133
- package/test/hydration-seam.test.ts +0 -400
- package/test/liveness-probe.test.ts +0 -183
- 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/test/upload-survives-reconnect.test.ts +0 -482
- package/tsconfig.json +0 -16
|
@@ -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
|
-
});
|
package/test/harness.ts
DELETED
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
// Minimal fake WebSocket for driving WhereverClient.handleMessage deterministically
|
|
2
|
-
// in unit tests. It records outbound frames and lets a test push inbound frames
|
|
3
|
-
// (server -> client) synchronously. No real network. Mirrors the tiny slice of
|
|
4
|
-
// the WHATWG WebSocket API that the client uses (readyState, addEventListener for
|
|
5
|
-
// open/message/close/error, send, close).
|
|
6
|
-
|
|
7
|
-
export type WSListener = (event: any) => void;
|
|
8
|
-
|
|
9
|
-
/** A decoded `upload.v1` chunk frame (see docs/USAGE.md). */
|
|
10
|
-
export interface BinaryChunk {
|
|
11
|
-
kind: number;
|
|
12
|
-
version: number;
|
|
13
|
-
uploadId: string;
|
|
14
|
-
offset: number;
|
|
15
|
-
payload: Uint8Array;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// [u8 kind][u8 version][u8 idLen][uploadId ascii][u64 offset BE][payload]
|
|
19
|
-
export function decodeChunkFrame(bytes: Uint8Array): BinaryChunk {
|
|
20
|
-
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
21
|
-
const idLen = bytes[2];
|
|
22
|
-
const uploadId = String.fromCharCode(...bytes.subarray(3, 3 + idLen));
|
|
23
|
-
const at = 3 + idLen;
|
|
24
|
-
const offset = view.getUint32(at) * 2 ** 32 + view.getUint32(at + 4);
|
|
25
|
-
return {
|
|
26
|
-
kind: bytes[0],
|
|
27
|
-
version: bytes[1],
|
|
28
|
-
uploadId,
|
|
29
|
-
offset,
|
|
30
|
-
payload: bytes.slice(at + 8),
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export class FakeWebSocket {
|
|
35
|
-
// WHATWG readyState constants.
|
|
36
|
-
static CONNECTING = 0;
|
|
37
|
-
static OPEN = 1;
|
|
38
|
-
static CLOSING = 2;
|
|
39
|
-
static CLOSED = 3;
|
|
40
|
-
|
|
41
|
-
url: string;
|
|
42
|
-
readyState = FakeWebSocket.CONNECTING;
|
|
43
|
-
sent: any[] = [];
|
|
44
|
-
// Binary frames (upload.v1 chunks), decoded, in send order. Kept apart from
|
|
45
|
-
// `sent` because they are not JSON.
|
|
46
|
-
binary: BinaryChunk[] = [];
|
|
47
|
-
private listeners: Record<string, Set<WSListener>> = {
|
|
48
|
-
open: new Set(),
|
|
49
|
-
message: new Set(),
|
|
50
|
-
close: new Set(),
|
|
51
|
-
error: new Set(),
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
constructor(url: string) {
|
|
55
|
-
this.url = url;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
addEventListener(type: string, cb: WSListener) {
|
|
59
|
-
this.listeners[type]?.add(cb);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
removeEventListener(type: string, cb: WSListener) {
|
|
63
|
-
this.listeners[type]?.delete(cb);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
removeAllListeners() {
|
|
67
|
-
for (const key of Object.keys(this.listeners)) {
|
|
68
|
-
this.listeners[key].clear();
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
send(data: string | ArrayBufferView | ArrayBuffer) {
|
|
73
|
-
if (typeof data === 'string') {
|
|
74
|
-
this.sent.push(JSON.parse(data));
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
const bytes =
|
|
78
|
-
data instanceof ArrayBuffer
|
|
79
|
-
? new Uint8Array(data)
|
|
80
|
-
: new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
81
|
-
this.binary.push(decodeChunkFrame(bytes));
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
close() {
|
|
85
|
-
if (this.readyState === FakeWebSocket.CLOSED) return;
|
|
86
|
-
this.readyState = FakeWebSocket.CLOSED;
|
|
87
|
-
this.emit('close', {});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// terminate() is used by the liveness watchdog's forcible teardown path.
|
|
91
|
-
terminate() {
|
|
92
|
-
this.close();
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// --- test-only helpers -------------------------------------------------
|
|
96
|
-
|
|
97
|
-
/** Simulate the socket opening (server accepted the connection). */
|
|
98
|
-
open() {
|
|
99
|
-
this.readyState = FakeWebSocket.OPEN;
|
|
100
|
-
this.emit('open', {});
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/** Push a server -> client frame. */
|
|
104
|
-
receive(msg: any) {
|
|
105
|
-
this.emit('message', {data: JSON.stringify(msg)});
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/** Last outbound frame of a given type, or undefined. */
|
|
109
|
-
lastSentOfType(type: string) {
|
|
110
|
-
return [...this.sent].reverse().find((m) => m.type === type);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private emit(type: string, event: any) {
|
|
114
|
-
for (const cb of this.listeners[type] ?? []) cb(event);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// A WebSocket constructor that records every instance it creates, so a test can
|
|
119
|
-
// grab the live socket the client just opened and drive it. Assigned to
|
|
120
|
-
// config.WebSocketCtor.
|
|
121
|
-
export function makeWSFactory() {
|
|
122
|
-
const instances: FakeWebSocket[] = [];
|
|
123
|
-
const ctor = function (url: string) {
|
|
124
|
-
const ws = new FakeWebSocket(url);
|
|
125
|
-
instances.push(ws);
|
|
126
|
-
return ws;
|
|
127
|
-
} as unknown as {new (url: string): FakeWebSocket};
|
|
128
|
-
return {
|
|
129
|
-
ctor,
|
|
130
|
-
instances,
|
|
131
|
-
last: () => instances[instances.length - 1],
|
|
132
|
-
};
|
|
133
|
-
}
|