@cleocode/adapters 2026.11.1-canary.9 → 2026.11.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/dist/.source-stamp.json +1 -1
- package/dist/index.js +1691 -1354
- package/dist/index.js.map +3 -3
- package/dist/orca-execution.d.ts +90 -0
- package/dist/orca-execution.d.ts.map +1 -0
- package/dist/orca-execution.js +843 -0
- package/dist/orca-execution.js.map +6 -0
- package/dist/providers/claude-code/index.js +1689 -1357
- package/dist/providers/claude-code/index.js.map +3 -3
- package/dist/providers/claude-code/lead-session.d.ts +8 -5
- package/dist/providers/claude-code/lead-session.d.ts.map +1 -1
- package/dist/providers/claude-sdk/index.js +1674 -1352
- package/dist/providers/claude-sdk/index.js.map +3 -3
- package/dist/providers/claude-sdk/spawn.d.ts.map +1 -1
- package/dist/providers/codex/index.js +1540 -1233
- package/dist/providers/codex/index.js.map +3 -3
- package/dist/providers/gemini-cli/index.js +1540 -1233
- package/dist/providers/gemini-cli/index.js.map +3 -3
- package/dist/providers/kimi/index.js +1540 -1233
- package/dist/providers/kimi/index.js.map +3 -3
- package/dist/providers/openai-sdk/index.js +1660 -1353
- package/dist/providers/openai-sdk/index.js.map +3 -3
- package/dist/providers/opencode/index.js +1540 -1233
- package/dist/providers/opencode/index.js.map +3 -3
- package/dist/providers/pi/index.js +1540 -1233
- package/dist/providers/pi/index.js.map +3 -3
- package/package.json +10 -6
- package/src/__tests__/orca-execution-fixture.ts +422 -0
- package/src/__tests__/orca-execution.test.ts +1357 -0
- package/src/__tests__/orca-plugin-panel.test.ts +661 -0
- package/src/__tests__/orca-plugin.test.ts +660 -0
- package/src/orca-execution.ts +1193 -0
- package/src/providers/claude-code/__tests__/lead-mcp.test.ts +27 -2
- package/src/providers/claude-code/lead-session.ts +21 -8
- package/src/providers/claude-sdk/__tests__/spawn.test.ts +19 -0
- package/src/providers/claude-sdk/spawn.ts +14 -0
- package/src/providers/shared/__tests__/lead-tool-strip.test.ts +1 -1
|
@@ -0,0 +1,661 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* T14462 — the CLEO Tasks panel's state and behaviour, run in CI.
|
|
3
|
+
*
|
|
4
|
+
* `panel.tsx` only draws; every decision (what is read when, which answer may
|
|
5
|
+
* still be drawn, what a cancel drops) lives in `panel-state.ts`, which has no
|
|
6
|
+
* Orca import. Here plain variables stand in for Orca atoms and controllable
|
|
7
|
+
* promises stand in for the plugin worker, so the order answers arrive in is
|
|
8
|
+
* the test's to choose. The bridge cases also load the real worker and panel
|
|
9
|
+
* over a stand-in for Orca, covering command delivery, drawing and cleanup.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import type { Atom, AtomOptions, PanelContext, PluginBridgeApi, ReadonlyAtom } from 'orca';
|
|
13
|
+
import type { HostCallArgs, HostMethodFor, HostResult } from 'orca/host';
|
|
14
|
+
import type { OrcaWorkerApi, PanelsApi } from 'orca/worker';
|
|
15
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
16
|
+
import {
|
|
17
|
+
type CellFactory,
|
|
18
|
+
createPanelState,
|
|
19
|
+
type PanelRequests,
|
|
20
|
+
} from '../../orca-plugin/src/panel-state.ts';
|
|
21
|
+
import type {
|
|
22
|
+
CleoFailure,
|
|
23
|
+
TaskDetail,
|
|
24
|
+
TaskDetailRequest,
|
|
25
|
+
TaskListRequest,
|
|
26
|
+
TaskPage,
|
|
27
|
+
WorkspaceList,
|
|
28
|
+
WorkspaceOption,
|
|
29
|
+
WorkspaceSelection,
|
|
30
|
+
} from '../../orca-plugin/src/protocol.ts';
|
|
31
|
+
import type { HostWorkspace } from '../../orca-plugin/src/workspaces.ts';
|
|
32
|
+
|
|
33
|
+
const CHOSEN: WorkspaceSelection = { id: 'ws-app', hostId: 'local', path: '/work/app' };
|
|
34
|
+
|
|
35
|
+
function option(overrides: Partial<WorkspaceOption> = {}): WorkspaceOption {
|
|
36
|
+
return {
|
|
37
|
+
...CHOSEN,
|
|
38
|
+
name: 'app',
|
|
39
|
+
branch: 'main',
|
|
40
|
+
label: 'app',
|
|
41
|
+
blocked: null,
|
|
42
|
+
focused: false,
|
|
43
|
+
...overrides,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const OTHER = option({ id: 'ws-other', path: '/work/other', name: 'other', label: 'other' });
|
|
48
|
+
const REMOTE = option({ id: 'ws-ssh', hostId: 'ssh:build', path: '/srv/app', blocked: 'remote' });
|
|
49
|
+
|
|
50
|
+
function listing(workspaces: WorkspaceOption[]): WorkspaceList {
|
|
51
|
+
return { ok: true, workspaces, truncated: false, focus: { name: null, matches: 0 } };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function page(ids: string[], overrides: Partial<TaskPage> = {}): TaskPage {
|
|
55
|
+
return {
|
|
56
|
+
ok: true,
|
|
57
|
+
tasks: ids.map((id) => ({
|
|
58
|
+
id,
|
|
59
|
+
title: `Task ${id}`,
|
|
60
|
+
status: 'active',
|
|
61
|
+
type: 'epic',
|
|
62
|
+
priority: null,
|
|
63
|
+
parentId: null,
|
|
64
|
+
})),
|
|
65
|
+
matched: ids.length,
|
|
66
|
+
truncated: false,
|
|
67
|
+
offset: 0,
|
|
68
|
+
...overrides,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function detailOf(id: string, children = 0): TaskDetail {
|
|
73
|
+
return {
|
|
74
|
+
ok: true,
|
|
75
|
+
task: {
|
|
76
|
+
id,
|
|
77
|
+
title: `Task ${id}`,
|
|
78
|
+
status: 'active',
|
|
79
|
+
type: 'task',
|
|
80
|
+
priority: null,
|
|
81
|
+
parentId: null,
|
|
82
|
+
description: '',
|
|
83
|
+
size: null,
|
|
84
|
+
pipelineStage: null,
|
|
85
|
+
children,
|
|
86
|
+
updatedAt: null,
|
|
87
|
+
},
|
|
88
|
+
acceptance: [],
|
|
89
|
+
gates: [],
|
|
90
|
+
verificationPassed: false,
|
|
91
|
+
claim: null,
|
|
92
|
+
nextAction: null,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const failed = (code: CleoFailure['code']): CleoFailure => ({ ok: false, code, message: code });
|
|
97
|
+
|
|
98
|
+
/** A promise the test settles when it chooses. */
|
|
99
|
+
function deferred<T>() {
|
|
100
|
+
let resolve: (value: T) => void = () => {};
|
|
101
|
+
const promise = new Promise<T>((done) => {
|
|
102
|
+
resolve = done;
|
|
103
|
+
});
|
|
104
|
+
return { promise, resolve };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
type Answers = {
|
|
108
|
+
workspaces?: () => Promise<WorkspaceList | CleoFailure> | WorkspaceList | CleoFailure;
|
|
109
|
+
tasks?: (input: TaskListRequest) => Promise<TaskPage | CleoFailure> | TaskPage | CleoFailure;
|
|
110
|
+
task?: (input: TaskDetailRequest) => Promise<TaskDetail | CleoFailure> | TaskDetail | CleoFailure;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/** A panel state over plain variables, with every worker request recorded. */
|
|
114
|
+
function panel(answers: Answers, saved: Record<string, unknown> = {}) {
|
|
115
|
+
const asked: { tasks: TaskListRequest[]; task: TaskDetailRequest[]; workspaces: number } = {
|
|
116
|
+
tasks: [],
|
|
117
|
+
task: [],
|
|
118
|
+
workspaces: 0,
|
|
119
|
+
};
|
|
120
|
+
const persisted: Record<string, unknown> = { ...saved };
|
|
121
|
+
const cell: CellFactory = <T>(initial: T, persistKey?: string) => {
|
|
122
|
+
let value =
|
|
123
|
+
persistKey !== undefined && persistKey in persisted ? (persisted[persistKey] as T) : initial;
|
|
124
|
+
return {
|
|
125
|
+
get: () => value,
|
|
126
|
+
set: (next: T) => {
|
|
127
|
+
value = next;
|
|
128
|
+
if (persistKey !== undefined) persisted[persistKey] = next;
|
|
129
|
+
},
|
|
130
|
+
};
|
|
131
|
+
};
|
|
132
|
+
const requests: PanelRequests = {
|
|
133
|
+
workspaces: async () => {
|
|
134
|
+
asked.workspaces += 1;
|
|
135
|
+
return (answers.workspaces ?? (() => listing([option(), OTHER, REMOTE])))();
|
|
136
|
+
},
|
|
137
|
+
tasks: async (input) => {
|
|
138
|
+
asked.tasks.push(input);
|
|
139
|
+
return (answers.tasks ?? (() => page([])))(input);
|
|
140
|
+
},
|
|
141
|
+
task: async (input) => {
|
|
142
|
+
asked.task.push(input);
|
|
143
|
+
return (answers.task ?? ((request) => detailOf(request.taskId)))(input);
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
return { state: createPanelState(cell, requests), asked, persisted };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
describe('workspace choice', () => {
|
|
150
|
+
it('reads nothing until a workspace is chosen, then asks with its id, host and path', async () => {
|
|
151
|
+
const { state, asked, persisted } = panel({ tasks: () => page(['T100']) });
|
|
152
|
+
await state.refresh();
|
|
153
|
+
expect(asked.tasks).toEqual([]);
|
|
154
|
+
expect(state.epics.get()).toBeNull();
|
|
155
|
+
|
|
156
|
+
await state.chooseWorkspace('ws-app');
|
|
157
|
+
expect(asked.tasks).toEqual([{ selection: CHOSEN, status: 'active', offset: 0 }]);
|
|
158
|
+
expect(persisted['selection']).toEqual(CHOSEN);
|
|
159
|
+
expect(state.epics.get()?.map((row) => row.id)).toEqual(['T100']);
|
|
160
|
+
expect(state.pending.get()).toBe(0);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
it('ignores a remote or unlisted workspace', async () => {
|
|
164
|
+
const { state, asked } = panel({});
|
|
165
|
+
await state.refresh();
|
|
166
|
+
await state.chooseWorkspace('ws-ssh');
|
|
167
|
+
await state.chooseWorkspace('ws-unknown');
|
|
168
|
+
expect(state.selection.get()).toBeNull();
|
|
169
|
+
expect(asked.tasks).toEqual([]);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it.each([
|
|
173
|
+
['moved to another path', option({ path: '/work/moved' })],
|
|
174
|
+
['moved to another host', option({ hostId: 'ssh:build' })],
|
|
175
|
+
['now blocked', option({ blocked: 'duplicate-id' })],
|
|
176
|
+
['gone', OTHER],
|
|
177
|
+
])('drops a saved choice that is %s before any read', async (_case, listed) => {
|
|
178
|
+
const { state, asked, persisted } = panel(
|
|
179
|
+
{ workspaces: () => listing([listed]), tasks: () => page(['T100']) },
|
|
180
|
+
{ selection: CHOSEN, task: 'T100' },
|
|
181
|
+
);
|
|
182
|
+
await state.refresh();
|
|
183
|
+
expect(asked.tasks).toEqual([]);
|
|
184
|
+
expect(asked.task).toEqual([]);
|
|
185
|
+
expect(persisted['selection']).toBeNull();
|
|
186
|
+
expect(persisted['task']).toBeNull();
|
|
187
|
+
expect(state.notice.get()).toMatch(/no longer available/);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('drops the answer of the workspace that was left', async () => {
|
|
191
|
+
const slow = deferred<TaskPage>();
|
|
192
|
+
const { state } = panel({
|
|
193
|
+
tasks: (input) => (input.selection.id === 'ws-app' ? slow.promise : page(['T200'])),
|
|
194
|
+
});
|
|
195
|
+
await state.refresh();
|
|
196
|
+
const first = state.chooseWorkspace('ws-app');
|
|
197
|
+
await state.chooseWorkspace('ws-other');
|
|
198
|
+
slow.resolve(page(['T100']));
|
|
199
|
+
await first;
|
|
200
|
+
expect(state.selection.get()?.id).toBe('ws-other');
|
|
201
|
+
expect(state.epics.get()?.map((row) => row.id)).toEqual(['T200']);
|
|
202
|
+
expect(state.pending.get()).toBe(0);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe('task tree', () => {
|
|
207
|
+
it('keeps what was loaded when a later read fails', async () => {
|
|
208
|
+
let fail = false;
|
|
209
|
+
const { state } = panel(
|
|
210
|
+
{ tasks: () => (fail ? failed('timeout') : page(['T100'])) },
|
|
211
|
+
{ selection: CHOSEN },
|
|
212
|
+
);
|
|
213
|
+
await state.refresh();
|
|
214
|
+
fail = true;
|
|
215
|
+
await state.refresh();
|
|
216
|
+
expect(state.taskFailure.get()).toEqual(failed('timeout'));
|
|
217
|
+
expect(state.epics.get()?.map((row) => row.id)).toEqual(['T100']);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it('turns a rejected worker request into a failure value', async () => {
|
|
221
|
+
const { state } = panel(
|
|
222
|
+
{
|
|
223
|
+
tasks: () =>
|
|
224
|
+
Promise.reject(Object.assign(new Error('worker took too long'), { code: 'timeout' })),
|
|
225
|
+
workspaces: () => listing([option()]),
|
|
226
|
+
},
|
|
227
|
+
{ selection: CHOSEN },
|
|
228
|
+
);
|
|
229
|
+
await state.refresh();
|
|
230
|
+
expect(state.taskFailure.get()).toEqual({
|
|
231
|
+
ok: false,
|
|
232
|
+
code: 'timeout',
|
|
233
|
+
message: 'worker took too long',
|
|
234
|
+
});
|
|
235
|
+
expect(state.pending.get()).toBe(0);
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
it('loads further pages on request and stops at the last one', async () => {
|
|
239
|
+
const { state, asked } = panel(
|
|
240
|
+
{
|
|
241
|
+
tasks: (input) =>
|
|
242
|
+
input.offset === 2
|
|
243
|
+
? page(['T300'], { matched: 3, offset: 2 })
|
|
244
|
+
: page(['T100', 'T200'], { matched: 3, truncated: true }),
|
|
245
|
+
},
|
|
246
|
+
{ selection: CHOSEN },
|
|
247
|
+
);
|
|
248
|
+
await state.refresh();
|
|
249
|
+
expect(state.epicPage.get()).toEqual({ matched: 3, truncated: true });
|
|
250
|
+
await state.loadMore();
|
|
251
|
+
expect(asked.tasks.at(-1)?.offset).toBe(2);
|
|
252
|
+
expect(state.epics.get()?.map((row) => row.id)).toEqual(['T100', 'T200', 'T300']);
|
|
253
|
+
expect(state.epicPage.get()).toEqual({ matched: 3, truncated: false });
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('loads a branch once when it is opened', async () => {
|
|
257
|
+
const { state, asked } = panel(
|
|
258
|
+
{ tasks: (input) => (input.parentId ? page(['T101']) : page(['T100'])) },
|
|
259
|
+
{ selection: CHOSEN },
|
|
260
|
+
);
|
|
261
|
+
await state.refresh();
|
|
262
|
+
await state.toggle({ key: 'T100', expanded: true });
|
|
263
|
+
await state.toggle({ key: 'T100', expanded: false });
|
|
264
|
+
await state.toggle({ key: 'T100', expanded: true });
|
|
265
|
+
expect(asked.tasks.filter((input) => input.parentId === 'T100')).toHaveLength(1);
|
|
266
|
+
expect(state.children.get()['T100']?.tasks.map((row) => row.id)).toEqual(['T101']);
|
|
267
|
+
expect(state.expanded.get()).toEqual(['T100']);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it('reloads open branches and the open task on refresh', async () => {
|
|
271
|
+
const { state, asked } = panel(
|
|
272
|
+
{ tasks: (input) => (input.parentId ? page(['T101']) : page(['T100'])) },
|
|
273
|
+
{ selection: CHOSEN },
|
|
274
|
+
);
|
|
275
|
+
await state.refresh();
|
|
276
|
+
await state.toggle({ key: 'T100', expanded: true });
|
|
277
|
+
await state.selectTask({ key: 'T100>T101' });
|
|
278
|
+
asked.tasks.length = 0;
|
|
279
|
+
asked.task.length = 0;
|
|
280
|
+
await state.refresh();
|
|
281
|
+
expect(asked.tasks.map((input) => input.parentId ?? 'epics')).toEqual(['epics', 'T100']);
|
|
282
|
+
expect(asked.task).toEqual([{ selection: CHOSEN, taskId: 'T101' }]);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('forgets loaded tasks when the status filter changes', async () => {
|
|
286
|
+
const { state, asked, persisted } = panel(
|
|
287
|
+
{ tasks: () => page(['T100']) },
|
|
288
|
+
{ selection: CHOSEN },
|
|
289
|
+
);
|
|
290
|
+
await state.refresh();
|
|
291
|
+
await state.selectTask({ key: 'T100' });
|
|
292
|
+
await state.chooseStatus('done');
|
|
293
|
+
expect(persisted['status']).toBe('done');
|
|
294
|
+
expect(asked.tasks.at(-1)).toEqual({ selection: CHOSEN, status: 'done', offset: 0 });
|
|
295
|
+
expect(state.detail.get()).toBeNull();
|
|
296
|
+
expect(state.selectedKey.get()).toBeNull();
|
|
297
|
+
await state.chooseStatus('not-a-status');
|
|
298
|
+
expect(persisted['status']).toBe('done');
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
describe('task detail', () => {
|
|
303
|
+
it('shows the task that was selected last, whatever order the answers arrive in', async () => {
|
|
304
|
+
const slow = deferred<TaskDetail>();
|
|
305
|
+
const { state } = panel(
|
|
306
|
+
{ task: (input) => (input.taskId === 'T1' ? slow.promise : detailOf(input.taskId)) },
|
|
307
|
+
{ selection: CHOSEN },
|
|
308
|
+
);
|
|
309
|
+
await state.refresh();
|
|
310
|
+
const first = state.selectTask({ key: 'T1' });
|
|
311
|
+
await state.selectTask({ key: 'T2' });
|
|
312
|
+
expect(state.detail.get()?.task.id).toBe('T2');
|
|
313
|
+
// The answer for T1 arrives after T2 is on screen: it must not replace it.
|
|
314
|
+
slow.resolve(detailOf('T1', 4));
|
|
315
|
+
await first;
|
|
316
|
+
expect(state.selectedKey.get()).toBe('T2');
|
|
317
|
+
expect(state.detail.get()?.task.id).toBe('T2');
|
|
318
|
+
expect(state.parents.get()).toEqual([]);
|
|
319
|
+
expect(state.pending.get()).toBe(0);
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it('marks a task with children as expandable once its detail says so', async () => {
|
|
323
|
+
const { state } = panel({ task: (input) => detailOf(input.taskId, 3) }, { selection: CHOSEN });
|
|
324
|
+
await state.refresh();
|
|
325
|
+
await state.selectTask({ key: 'T100>T101' });
|
|
326
|
+
expect(state.parents.get()).toEqual(['T101']);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('keeps the open task between panel runs', async () => {
|
|
330
|
+
const { state, asked, persisted } = panel({}, { selection: CHOSEN });
|
|
331
|
+
await state.refresh();
|
|
332
|
+
await state.selectTask({ key: 'T100>T101' });
|
|
333
|
+
expect(persisted['task']).toBe('T100>T101');
|
|
334
|
+
const reopened = panel({ tasks: () => page(['T100']) }, persisted);
|
|
335
|
+
await reopened.state.refresh();
|
|
336
|
+
expect(reopened.asked.task).toEqual([{ selection: CHOSEN, taskId: 'T101' }]);
|
|
337
|
+
expect(asked.task).toHaveLength(1);
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it('reports a failed detail read without touching the tree', async () => {
|
|
341
|
+
const { state } = panel(
|
|
342
|
+
{ tasks: () => page(['T100']), task: () => failed('cli-error') },
|
|
343
|
+
{ selection: CHOSEN },
|
|
344
|
+
);
|
|
345
|
+
await state.refresh();
|
|
346
|
+
await state.selectTask({ key: 'T100' });
|
|
347
|
+
expect(state.detailFailure.get()).toEqual(failed('cli-error'));
|
|
348
|
+
expect(state.taskFailure.get()).toBeNull();
|
|
349
|
+
expect(state.epics.get()).toHaveLength(1);
|
|
350
|
+
});
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
describe('cancel', () => {
|
|
354
|
+
it('counts a read in flight and drops its answer once cancelled', async () => {
|
|
355
|
+
const slow = deferred<TaskPage>();
|
|
356
|
+
let hold = false;
|
|
357
|
+
const { state } = panel(
|
|
358
|
+
{ tasks: () => (hold ? slow.promise : page(['T100'])) },
|
|
359
|
+
{ selection: CHOSEN },
|
|
360
|
+
);
|
|
361
|
+
await state.refresh();
|
|
362
|
+
hold = true;
|
|
363
|
+
const refreshing = state.refresh();
|
|
364
|
+
await Promise.resolve();
|
|
365
|
+
await Promise.resolve();
|
|
366
|
+
await Promise.resolve();
|
|
367
|
+
expect(state.pending.get()).toBe(1);
|
|
368
|
+
|
|
369
|
+
state.cancel();
|
|
370
|
+
slow.resolve(page(['T999']));
|
|
371
|
+
await refreshing;
|
|
372
|
+
expect(state.epics.get()?.map((row) => row.id)).toEqual(['T100']);
|
|
373
|
+
expect(state.taskFailure.get()).toBeNull();
|
|
374
|
+
expect(state.notice.get()).toMatch(/Read cancelled/);
|
|
375
|
+
expect(state.pending.get()).toBe(0);
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
it('stops a reload between reads', async () => {
|
|
379
|
+
const slow = deferred<TaskPage>();
|
|
380
|
+
let hold = false;
|
|
381
|
+
const { state, asked } = panel(
|
|
382
|
+
{
|
|
383
|
+
tasks: (input) => {
|
|
384
|
+
if (input.parentId) return page(['T101']);
|
|
385
|
+
return hold ? slow.promise : page(['T100']);
|
|
386
|
+
},
|
|
387
|
+
},
|
|
388
|
+
{ selection: CHOSEN },
|
|
389
|
+
);
|
|
390
|
+
await state.refresh();
|
|
391
|
+
await state.toggle({ key: 'T100', expanded: true });
|
|
392
|
+
await state.selectTask({ key: 'T100' });
|
|
393
|
+
asked.tasks.length = 0;
|
|
394
|
+
asked.task.length = 0;
|
|
395
|
+
hold = true;
|
|
396
|
+
const refreshing = state.refresh();
|
|
397
|
+
await Promise.resolve();
|
|
398
|
+
await Promise.resolve();
|
|
399
|
+
await Promise.resolve();
|
|
400
|
+
state.dispose();
|
|
401
|
+
slow.resolve(page(['T100']));
|
|
402
|
+
await refreshing;
|
|
403
|
+
expect(asked.tasks.map((input) => input.parentId ?? 'epics')).toEqual(['epics']);
|
|
404
|
+
expect(asked.task).toEqual([]);
|
|
405
|
+
});
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
/** What stands in for Orca between the worker and the panel. */
|
|
409
|
+
const orca = vi.hoisted(() => {
|
|
410
|
+
const state = {
|
|
411
|
+
listeners: new Map<string, Set<Parameters<PluginBridgeApi['on']>[1]>>(),
|
|
412
|
+
handlers: new Map<string, Parameters<PanelsApi['handle']>[1]>(),
|
|
413
|
+
commands: new Map<string, Parameters<OrcaWorkerApi['commands']['register']>[1]>(),
|
|
414
|
+
posts: [] as Parameters<PanelsApi['post']>[],
|
|
415
|
+
hostCalls: [] as string[],
|
|
416
|
+
workspaces: [] as HostWorkspace[],
|
|
417
|
+
workspaceRead: Promise.resolve(),
|
|
418
|
+
};
|
|
419
|
+
const unused = () => {
|
|
420
|
+
throw new Error('Unexpected Orca API call');
|
|
421
|
+
};
|
|
422
|
+
const node = (...[type, props]: Parameters<typeof import('orca/jsx-runtime').jsx>) => ({
|
|
423
|
+
$$typeof: Symbol.for('orca.element'),
|
|
424
|
+
type,
|
|
425
|
+
props,
|
|
426
|
+
});
|
|
427
|
+
return {
|
|
428
|
+
state,
|
|
429
|
+
/** What JSX compiles to: a plain `{ type, props }` node. */
|
|
430
|
+
jsxRuntime: { jsx: node, jsxs: node, jsxDEV: node, Fragment: 'Fragment' },
|
|
431
|
+
/** The `orca` object Orca passes to the worker's `activate`. */
|
|
432
|
+
workerApi: {
|
|
433
|
+
api: { major: 1, minor: 3 },
|
|
434
|
+
grantedCapabilities: ['workspace:read'],
|
|
435
|
+
log: unused,
|
|
436
|
+
events: { on: unused },
|
|
437
|
+
hooks: { on: unused },
|
|
438
|
+
storage: {
|
|
439
|
+
get: unused,
|
|
440
|
+
set: unused,
|
|
441
|
+
delete: unused,
|
|
442
|
+
keys: unused,
|
|
443
|
+
onDidChange: unused,
|
|
444
|
+
},
|
|
445
|
+
settings: {
|
|
446
|
+
get: unused,
|
|
447
|
+
set: unused,
|
|
448
|
+
onDidChange: unused,
|
|
449
|
+
},
|
|
450
|
+
secrets: {
|
|
451
|
+
get: unused,
|
|
452
|
+
set: unused,
|
|
453
|
+
delete: unused,
|
|
454
|
+
},
|
|
455
|
+
host: {
|
|
456
|
+
has: unused,
|
|
457
|
+
async call<M extends HostMethodFor<'worker'>>(
|
|
458
|
+
method: M,
|
|
459
|
+
..._args: HostCallArgs<M>
|
|
460
|
+
): Promise<HostResult<M>> {
|
|
461
|
+
state.hostCalls.push(method);
|
|
462
|
+
if (method === 'workspace.list') {
|
|
463
|
+
await state.workspaceRead;
|
|
464
|
+
return { workspaces: state.workspaces, truncated: false } as HostResult<M>;
|
|
465
|
+
}
|
|
466
|
+
if (method === 'workspace.readContext') return null as HostResult<M>;
|
|
467
|
+
return unused();
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
panels: {
|
|
471
|
+
handle: ((name: string, handler: Parameters<PanelsApi['handle']>[1]) => {
|
|
472
|
+
state.handlers.set(name, handler);
|
|
473
|
+
return { dispose: () => state.handlers.delete(name) };
|
|
474
|
+
}) as PanelsApi['handle'],
|
|
475
|
+
post: (...[event, payload = null]: Parameters<PanelsApi['post']>) => {
|
|
476
|
+
state.posts.push([event, payload]);
|
|
477
|
+
for (const listener of state.listeners.get(event) ?? []) listener(payload);
|
|
478
|
+
},
|
|
479
|
+
},
|
|
480
|
+
commands: {
|
|
481
|
+
register: (id: string, run: Parameters<OrcaWorkerApi['commands']['register']>[1]) => {
|
|
482
|
+
state.commands.set(id, run);
|
|
483
|
+
return { dispose: () => state.commands.delete(id) };
|
|
484
|
+
},
|
|
485
|
+
},
|
|
486
|
+
} satisfies OrcaWorkerApi,
|
|
487
|
+
/** The `plugin` bridge a panel imports from `orca`. */
|
|
488
|
+
plugin: {
|
|
489
|
+
request: async (...[name, input, options]: Parameters<PluginBridgeApi['request']>) => {
|
|
490
|
+
const handler = state.handlers.get(name);
|
|
491
|
+
if (!handler) throw Object.assign(new Error(name), { code: 'unknown_method' });
|
|
492
|
+
return handler(input, {
|
|
493
|
+
signal: options?.signal ?? new AbortController().signal,
|
|
494
|
+
panel: { id: 'tasks', surface: 'panel', contributionId: 'tasks' },
|
|
495
|
+
});
|
|
496
|
+
},
|
|
497
|
+
on: (event: string, listener: Parameters<PluginBridgeApi['on']>[1]) => {
|
|
498
|
+
const listeners =
|
|
499
|
+
state.listeners.get(event) ?? new Set<Parameters<PluginBridgeApi['on']>[1]>();
|
|
500
|
+
state.listeners.set(event, listeners.add(listener));
|
|
501
|
+
return { dispose: () => listeners.delete(listener) };
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
};
|
|
505
|
+
});
|
|
506
|
+
|
|
507
|
+
// The panel runtime Orca provides: atoms are plain boxes and every catalog component is its
|
|
508
|
+
// own name, so JSX builds a tree of `{ type, props }` nodes.
|
|
509
|
+
vi.mock('orca', () => {
|
|
510
|
+
const tags = [
|
|
511
|
+
'Badge',
|
|
512
|
+
'Button',
|
|
513
|
+
'Callout',
|
|
514
|
+
'EmptyState',
|
|
515
|
+
'Heading',
|
|
516
|
+
'KeyValue',
|
|
517
|
+
'List',
|
|
518
|
+
'ListItem',
|
|
519
|
+
'RelativeTime',
|
|
520
|
+
'Row',
|
|
521
|
+
'Select',
|
|
522
|
+
'Spinner',
|
|
523
|
+
'Stack',
|
|
524
|
+
'Text',
|
|
525
|
+
'Tree',
|
|
526
|
+
];
|
|
527
|
+
function atom<T>(initial: T): Atom<T>;
|
|
528
|
+
function atom<T>(key: string, initial: T, options?: AtomOptions<T>): Atom<T>;
|
|
529
|
+
function atom<T>(...args: [initial: T] | [key: string, initial: T, options?: AtomOptions<T>]) {
|
|
530
|
+
return { __orcaAtom: args.length === 1 ? args[0] : args[1], __orcaWritable: true };
|
|
531
|
+
}
|
|
532
|
+
return {
|
|
533
|
+
...Object.fromEntries(tags.map((tag) => [tag, tag])),
|
|
534
|
+
atom,
|
|
535
|
+
read: <T>(box: ReadonlyAtom<T>) => box.__orcaAtom,
|
|
536
|
+
set: <T>(box: Atom<T>, value: T) => {
|
|
537
|
+
Object.assign(box, { __orcaAtom: value });
|
|
538
|
+
},
|
|
539
|
+
plugin: orca.plugin,
|
|
540
|
+
};
|
|
541
|
+
});
|
|
542
|
+
|
|
543
|
+
vi.mock('orca/jsx-runtime', () => orca.jsxRuntime);
|
|
544
|
+
vi.mock('orca/jsx-dev-runtime', () => orca.jsxRuntime);
|
|
545
|
+
|
|
546
|
+
const workspace = (id: string, name: string): HostWorkspace => ({
|
|
547
|
+
id,
|
|
548
|
+
kind: 'worktree',
|
|
549
|
+
name,
|
|
550
|
+
path: `/work/${name}`,
|
|
551
|
+
branch: 'main',
|
|
552
|
+
hostId: 'local',
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
/** Loads fresh copies of the two files Orca loads, and opens the panel. */
|
|
556
|
+
async function openPlugin() {
|
|
557
|
+
vi.resetModules();
|
|
558
|
+
const worker = await import('../../orca-plugin/src/worker.ts');
|
|
559
|
+
const panel = await import('../../orca-plugin/src/panel.tsx');
|
|
560
|
+
worker.default(orca.workerApi);
|
|
561
|
+
const subscriptions: PanelContext['subscriptions'] = [];
|
|
562
|
+
const signal = new AbortController().signal;
|
|
563
|
+
const cleanup = panel.setup({
|
|
564
|
+
subscriptions,
|
|
565
|
+
signal,
|
|
566
|
+
visible: { __orcaAtom: true },
|
|
567
|
+
panel: { id: 'tasks' },
|
|
568
|
+
});
|
|
569
|
+
return {
|
|
570
|
+
/** What the panel draws now, as text. */
|
|
571
|
+
drawn: () => JSON.stringify(panel.default()),
|
|
572
|
+
/** What Orca does when the panel closes. */
|
|
573
|
+
close: () => {
|
|
574
|
+
for (const subscription of subscriptions) subscription.dispose();
|
|
575
|
+
cleanup();
|
|
576
|
+
},
|
|
577
|
+
lists: () => orca.state.hostCalls.filter((method) => method === 'workspace.list').length,
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
describe('worker to panel bridge', () => {
|
|
582
|
+
beforeEach(() => {
|
|
583
|
+
orca.state.listeners.clear();
|
|
584
|
+
orca.state.handlers.clear();
|
|
585
|
+
orca.state.commands.clear();
|
|
586
|
+
orca.state.posts.length = 0;
|
|
587
|
+
orca.state.hostCalls.length = 0;
|
|
588
|
+
orca.state.workspaces = [workspace('ws-app', 'app')];
|
|
589
|
+
orca.state.workspaceRead = Promise.resolve();
|
|
590
|
+
});
|
|
591
|
+
|
|
592
|
+
it('registers the three read handlers and the refresh command', async () => {
|
|
593
|
+
await openPlugin();
|
|
594
|
+
expect([...orca.state.handlers.keys()].sort()).toEqual([
|
|
595
|
+
'cleo.task',
|
|
596
|
+
'cleo.tasks',
|
|
597
|
+
'cleo.workspaces',
|
|
598
|
+
]);
|
|
599
|
+
expect([...orca.state.commands.keys()]).toEqual(['cleo.refresh']);
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
it('draws the workspaces the worker reads from Orca when the panel opens', async () => {
|
|
603
|
+
const plugin = await openPlugin();
|
|
604
|
+
await vi.waitFor(() => expect(plugin.drawn()).toContain('"label":"app"'));
|
|
605
|
+
expect(plugin.lists()).toBe(1);
|
|
606
|
+
expect(orca.state.hostCalls).toContain('workspace.readContext');
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
it('the refresh command posts to the open panel, which reloads and draws the update', async () => {
|
|
610
|
+
const plugin = await openPlugin();
|
|
611
|
+
await vi.waitFor(() => expect(plugin.drawn()).toContain('"label":"app"'));
|
|
612
|
+
expect(plugin.drawn()).not.toContain('second');
|
|
613
|
+
|
|
614
|
+
orca.state.workspaces = [workspace('ws-app', 'app'), workspace('ws-second', 'second')];
|
|
615
|
+
const shown = orca.state.commands.get('cleo.refresh')?.(undefined, {
|
|
616
|
+
signal: new AbortController().signal,
|
|
617
|
+
});
|
|
618
|
+
|
|
619
|
+
expect(typeof shown).toBe('string');
|
|
620
|
+
expect(orca.state.posts).toHaveLength(1);
|
|
621
|
+
expect(orca.state.posts[0]).toEqual(['cleo.refresh', { requestedAt: expect.any(Number) }]);
|
|
622
|
+
await vi.waitFor(() => expect(plugin.drawn()).toContain('"label":"second"'));
|
|
623
|
+
expect(plugin.lists()).toBe(2);
|
|
624
|
+
});
|
|
625
|
+
|
|
626
|
+
it('a closed panel no longer hears the refresh command', async () => {
|
|
627
|
+
const plugin = await openPlugin();
|
|
628
|
+
await vi.waitFor(() => expect(plugin.drawn()).toContain('"label":"app"'));
|
|
629
|
+
expect(orca.state.listeners.get('cleo.refresh')?.size).toBe(1);
|
|
630
|
+
|
|
631
|
+
plugin.close();
|
|
632
|
+
expect(orca.state.listeners.get('cleo.refresh')?.size).toBe(0);
|
|
633
|
+
|
|
634
|
+
orca.state.workspaces = [workspace('ws-second', 'second')];
|
|
635
|
+
orca.state.commands.get('cleo.refresh')?.(undefined, { signal: new AbortController().signal });
|
|
636
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
637
|
+
expect(orca.state.posts).toHaveLength(1);
|
|
638
|
+
expect(plugin.lists()).toBe(1);
|
|
639
|
+
expect(plugin.drawn()).not.toContain('second');
|
|
640
|
+
});
|
|
641
|
+
|
|
642
|
+
it('closing the panel drops the answer of a read still in flight', async () => {
|
|
643
|
+
const held = deferred<void>();
|
|
644
|
+
const plugin = await openPlugin();
|
|
645
|
+
await vi.waitFor(() => expect(plugin.drawn()).toContain('"label":"app"'));
|
|
646
|
+
|
|
647
|
+
orca.state.workspaces = [workspace('ws-second', 'second')];
|
|
648
|
+
orca.state.workspaceRead = held.promise;
|
|
649
|
+
try {
|
|
650
|
+
orca.state.commands.get('cleo.refresh')?.(undefined, {
|
|
651
|
+
signal: new AbortController().signal,
|
|
652
|
+
});
|
|
653
|
+
plugin.close();
|
|
654
|
+
held.resolve();
|
|
655
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
656
|
+
expect(plugin.drawn()).not.toContain('second');
|
|
657
|
+
} finally {
|
|
658
|
+
held.resolve();
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
});
|