@wherever-dev/client 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/README.md +63 -0
- package/dist/client.js +2 -0
- 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 +2 -0
- 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,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
|
-
});
|
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
|
-
}
|