@wherever-dev/client 0.5.4 → 0.7.0
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 +33 -0
- package/dist/client.d.ts +40 -0
- package/dist/client.js +386 -9
- package/dist/client.js.map +1 -1
- package/dist/types.d.ts +48 -0
- package/dist/types.js.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +433 -9
- package/src/types.ts +118 -0
- package/test/folder-conflict-read-only.test.ts +145 -0
- package/test/folder-missing-read-only.test.ts +114 -0
- package/test/new-session-clone-progress.test.ts +263 -0
- package/test/queued-steer-restored.test.ts +175 -0
- package/test/restore-panel.test.ts +324 -0
- package/test/session-load-by-id.test.ts +100 -0
- package/test/session-reload.test.ts +82 -0
- package/test/skills-autocomplete.test.ts +113 -0
- package/test/superseded-connection-key.test.ts +70 -0
package/src/types.ts
CHANGED
|
@@ -64,6 +64,14 @@ export interface ChatMessage {
|
|
|
64
64
|
// e.g. one loaded from server history). Confirmed on the server's user echo
|
|
65
65
|
// (message_end role:user) or when it reappears in loaded history.
|
|
66
66
|
delivery?: 'sending' | 'failed';
|
|
67
|
+
// True on a user message this client RESTORED from the server's steer-queue
|
|
68
|
+
// snapshot rather than from history or its own send (see queue_update). Such a
|
|
69
|
+
// message is queued in the agent but not yet in the session file, so when pi
|
|
70
|
+
// finally injects it the server's user echo must RECONCILE onto this bubble
|
|
71
|
+
// (clearing the flag) instead of appending a duplicate. Content-matching the
|
|
72
|
+
// last user message is not enough: with several messages queued they are
|
|
73
|
+
// delivered oldest-first, so the echoed one is usually not the last bubble.
|
|
74
|
+
restoredFromQueue?: boolean;
|
|
67
75
|
}
|
|
68
76
|
|
|
69
77
|
export interface SessionNotice {
|
|
@@ -93,6 +101,101 @@ export interface FolderConflictInfo {
|
|
|
93
101
|
continued: boolean;
|
|
94
102
|
}
|
|
95
103
|
|
|
104
|
+
// State for the MISSING-FOLDER lock. Set when the server reports that this
|
|
105
|
+
// session's working folder does not exist on this machine (the `folderMissing`
|
|
106
|
+
// flag on session_created, and the `folder_missing` frame that names the path).
|
|
107
|
+
// The transcript still paints -- reading never needed the folder -- but the
|
|
108
|
+
// server built no live agent and refuses every send.
|
|
109
|
+
//
|
|
110
|
+
// Unlike a folder conflict this is HARD: there is no "Continue anyway". It is
|
|
111
|
+
// cured by restoring the folder and RELOADING the session (whether a session has
|
|
112
|
+
// a live agent is a load-time decision). `cwd` is the absolute missing path, so
|
|
113
|
+
// the UI can name exactly what to restore where the composer would be.
|
|
114
|
+
export interface FolderMissingInfo {
|
|
115
|
+
cwd: string;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// --- RESTORE (materialising a missing working folder) ----------------------
|
|
119
|
+
//
|
|
120
|
+
// Vocabulary, pinned (see CONTEXT.md): RESTORE here means making a missing
|
|
121
|
+
// working folder exist again -- cloning the repository back, or creating the
|
|
122
|
+
// folder. It is NOT the unrelated in-codebase sense of re-materialising queued
|
|
123
|
+
// steers and drafts after a reload (`restoredFromQueue` above). Every frame and
|
|
124
|
+
// field in this family is namespaced `restore*`.
|
|
125
|
+
//
|
|
126
|
+
// These mirror the server's restore-job snapshot (server/src/restore-jobs.ts)
|
|
127
|
+
// field for field, duplicated here rather than imported so this package keeps no
|
|
128
|
+
// server dependency (the same posture as ContextUsage).
|
|
129
|
+
|
|
130
|
+
// One honest progress reading. `percent` is null exactly when git reports no
|
|
131
|
+
// percentage for the phase, and `indeterminate` says so explicitly rather than
|
|
132
|
+
// leaving the UI to invent a 0. `scope` is the repository itself
|
|
133
|
+
// ('repository') or a submodule's path relative to the target: submodules are
|
|
134
|
+
// counted SEPARATELY, never folded into one fake global percentage.
|
|
135
|
+
export interface RestoreProgressInfo {
|
|
136
|
+
phase: string;
|
|
137
|
+
scope: string;
|
|
138
|
+
percent: number | null;
|
|
139
|
+
indeterminate: boolean;
|
|
140
|
+
/** The git line this was parsed from, for a detail line under the bar. */
|
|
141
|
+
text: string;
|
|
142
|
+
at: number;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// A failed restore, explained. `cause` is the server's mapping onto a named,
|
|
146
|
+
// actionable problem ('no-key' | 'unknown-host' | 'not-found' | 'network' |
|
|
147
|
+
// 'unknown'); `message` is the human sentence for it, and `stderr` is git's raw
|
|
148
|
+
// output, kept UNDERNEATH the mapping and never replaced by it.
|
|
149
|
+
export interface RestoreFailureInfo {
|
|
150
|
+
cause: string;
|
|
151
|
+
message: string;
|
|
152
|
+
stderr: string;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// A restore job as the server reports it. Keyed by `targetPath` on the server,
|
|
156
|
+
// so `id` is what tells a retry apart from the job it replaced.
|
|
157
|
+
export interface RestoreJobInfo {
|
|
158
|
+
id: number;
|
|
159
|
+
kind: 'clone' | 'create';
|
|
160
|
+
targetPath: string;
|
|
161
|
+
/** The url the job is ACTUALLY cloning (clone kind only). */
|
|
162
|
+
url?: string;
|
|
163
|
+
gitInit?: boolean;
|
|
164
|
+
state: 'running' | 'done' | 'failed' | 'cancelled';
|
|
165
|
+
progress: RestoreProgressInfo | null;
|
|
166
|
+
failure?: RestoreFailureInfo;
|
|
167
|
+
startedAt: number;
|
|
168
|
+
endedAt?: number;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// What the restore panel needs to render, for ONE folder. Created as soon as a
|
|
172
|
+
// folder-missing session is loaded (with `job` already set when the server is
|
|
173
|
+
// mid-clone for that path, so a reconnecting phone repaints a running job), and
|
|
174
|
+
// updated by the server's restore frames.
|
|
175
|
+
export interface RestoreInfo {
|
|
176
|
+
/** The absolute folder being restored. Frames for any other path are ignored. */
|
|
177
|
+
targetPath: string;
|
|
178
|
+
/** The server's job for that path, or null while none has been started. */
|
|
179
|
+
job: RestoreJobInfo | null;
|
|
180
|
+
// True when THIS client's last start JOINED a job that was already running.
|
|
181
|
+
// With `requestedUrl` it is what lets the panel say "a clone of <job.url> is
|
|
182
|
+
// already running" instead of pretending the edited url was accepted.
|
|
183
|
+
joined: boolean;
|
|
184
|
+
/** The url this client last asked for, whether or not it was the one used. */
|
|
185
|
+
requestedUrl?: string;
|
|
186
|
+
// A request REFUSED before anything was spawned (an unsafe target, a
|
|
187
|
+
// non-empty folder, a url outside the allowlist). No job exists and no
|
|
188
|
+
// completion is coming, so the panel shows this and stays in its offer state.
|
|
189
|
+
rejection: {reason: string; message: string} | null;
|
|
190
|
+
// True when this restore is the first step of a SESSION CREATE (the
|
|
191
|
+
// new-session clone), not the restore of a loaded session's missing folder.
|
|
192
|
+
// Same job, same frames, same progress display -- what differs is the ENDING:
|
|
193
|
+
// there is no session to reload here (it does not exist until the clone
|
|
194
|
+
// lands), so the server continues into creation itself and the client hands
|
|
195
|
+
// the screen back to the create instead of offering a Reload.
|
|
196
|
+
forSessionCreate?: boolean;
|
|
197
|
+
}
|
|
198
|
+
|
|
96
199
|
export interface WhereverState {
|
|
97
200
|
connected: boolean;
|
|
98
201
|
connecting: boolean;
|
|
@@ -120,7 +223,22 @@ export interface WhereverState {
|
|
|
120
223
|
isStreaming: boolean;
|
|
121
224
|
messages: ChatMessage[];
|
|
122
225
|
clientId: string | null;
|
|
226
|
+
// Version of the server we are connected to (the `wherever-dev` package
|
|
227
|
+
// version), as reported in its `connected` message. null until connected, or
|
|
228
|
+
// when talking to a server old enough not to report it.
|
|
229
|
+
serverVersion: string | null;
|
|
123
230
|
folderConflict: FolderConflictInfo | null;
|
|
231
|
+
// The active session's working folder is gone from this machine (see
|
|
232
|
+
// FolderMissingInfo). Non-null implies `readOnly`, and no `session_ready` is
|
|
233
|
+
// coming: the composer is replaced by a notice naming the path. Cleared with
|
|
234
|
+
// the session it belongs to.
|
|
235
|
+
folderMissing: FolderMissingInfo | null;
|
|
236
|
+
// The restore of the active session's missing folder: the server's job for
|
|
237
|
+
// that path (running, finished or not yet started) plus this client's own last
|
|
238
|
+
// request. Non-null exactly while a folder-missing session is open, so the
|
|
239
|
+
// panel that replaces the composer renders from here. Cleared with the session
|
|
240
|
+
// it belongs to.
|
|
241
|
+
restore: RestoreInfo | null;
|
|
124
242
|
isInterrupted: boolean;
|
|
125
243
|
// A dismissible, non-fatal notice about the active session (e.g. a CLI bridge
|
|
126
244
|
// took over while this session was mid-turn here, discarding the in-flight
|
|
@@ -0,0 +1,145 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,114 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,263 @@
|
|
|
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
|
+
});
|