@pi-chamber/web 1.0.8-rc.1 → 1.0.8-rc.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/dist/assets/{AgentsSurface-BmHImX8m.js → AgentsSurface-CcWBqAWV.js} +1 -1
- package/dist/assets/{ChoicesArtifact-C71fGOm2.js → ChoicesArtifact-Kk-qvrSB.js} +1 -1
- package/dist/assets/{DiagramView-BZQxoiZu.js → DiagramView-DZUBo1uP.js} +1 -1
- package/dist/assets/{DiffView-C70pbgk-.js → DiffView-CiZy4jFA.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-Cu8c3gBV.js → FileSaveConflictDialog-DZ9NDwOO.js} +1 -1
- package/dist/assets/{FilesView-nFJYEdRw.js → FilesView-DqiZ9kw9.js} +1 -1
- package/dist/assets/{GitHubDetailScaffold-Jvv_tgbl.js → GitHubDetailScaffold-DM2DH7o8.js} +1 -1
- package/dist/assets/{GitHubLinkPicker-BXD2ODRi.js → GitHubLinkPicker-ChB8NZ1h.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-BWI706F0.js → GitHubListPrimitives-CibDiJGq.js} +1 -1
- package/dist/assets/{GitView-MIDG5RYW.js → GitView--EaZQrBr.js} +5 -5
- package/dist/assets/{IssuesSurface-uNlozeu0.js → IssuesSurface-CySTpaD1.js} +3 -3
- package/dist/assets/{JsonTreeView-CSLsTriz.js → JsonTreeView-_yMHKKQZ.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cs-7BfWi.js → MarkdownRendererImpl-D_-2fQw0.js} +1 -1
- package/dist/assets/{PatchDiff-axbsnbTJ.js → PatchDiff-bHObDlhD.js} +1 -1
- package/dist/assets/{PierreDiffViewer-lwn6w_5w.js → PierreDiffViewer-UY7Cse-s.js} +1 -1
- package/dist/assets/{PullRequestsSurface-o_AXDjbO.js → PullRequestsSurface-iXy6chwc.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-C4CMlcbv.js → SessionSwitcherContent-DJGCa_wN.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-DCBVuCoo.js → SessionSwitcherDropdown-CDOX-5Y2.js} +2 -2
- package/dist/assets/{SessionUnreadDot-DyeIrsro.js → SessionUnreadDot-Dwc3MdvA.js} +1 -1
- package/dist/assets/SettingsView-DA-U9lsj.js +11 -0
- package/dist/assets/{SettingsWindow-Cb4st5y5.js → SettingsWindow-CUg49Mfh.js} +1 -1
- package/dist/assets/{SubagentsArtifact-BzeMEoFP.js → SubagentsArtifact-DUZX9tDe.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BP2mOWdV.js → ToolOutputDialog-BuZZaRw4.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-D49XBR9b.js → ToolPartDiffPreview-CKncG6i2.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-CLgDONEQ.js → VirtualizedFileDiff-BGZiLPe_.js} +1 -1
- package/dist/assets/VisualFrame-DBZkHFnG.js +22 -0
- package/dist/assets/VisualsArtifact-Bq0vMO-i.js +1 -0
- package/dist/assets/{collapsible-BeyKtQGB.js → collapsible-Bro9KrfM.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DmO6H8u6.js → computeVirtualFileMetrics-DJQqK49u.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-DOK251YW.js → contextFileOpenGuard-ByWK3Sru.js} +1 -1
- package/dist/assets/{fileTreeStatus-CnzR7kxA.js → fileTreeStatus-CyJ3TOYD.js} +1 -1
- package/dist/assets/{gitStatusPredicates-4kPg2t6j.js → gitStatusPredicates-BsXrwngT.js} +1 -1
- package/dist/assets/{githubLink-QvaLfNNT.js → githubLink-g2bmC0qi.js} +1 -1
- package/dist/assets/index-B_L9GVYw.css +1 -0
- package/dist/assets/{index-DMX9wT1Z.js → index-C9rUUQ_Y.js} +1 -1
- package/dist/assets/index-CKKWVoND.js +11 -0
- package/dist/assets/{main-BW9J3Y72.js → main-DT-4_fhe.js} +2 -2
- package/dist/assets/{main-BirYxac2.js → main-DsLMU9CT.js} +4 -4
- package/dist/assets/{markdownCore-CxmcPur8.js → markdownCore-QmM_aOnZ.js} +1 -1
- package/dist/assets/{miniChat-BRB11eEs.js → miniChat-BqGslD2z.js} +2 -2
- package/dist/assets/{mobile-DJZYYCuB.js → mobile-C5JOcDIC.js} +2 -2
- package/dist/assets/{nativeFileSave-B6QpoPRn.js → nativeFileSave-DSMsJqXM.js} +1 -1
- package/dist/assets/{pi-session-focus-preference-PWoh3LNA.js → pi-session-focus-preference-Cc_S4zi1.js} +1 -1
- package/dist/assets/{renderDiffWithHighlighter-C48T6YFJ.js → renderDiffWithHighlighter-BXhnIAHg.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-N-BQdJl0.js → renderElectronMiniChatApp-CiSkecEE.js} +2 -2
- package/dist/assets/{renderFileWithHighlighter-8Kt2MyTN.js → renderFileWithHighlighter-CK29YZtC.js} +1 -1
- package/dist/assets/renderMobileApp-C4JuoxsZ.js +11 -0
- package/dist/assets/runtimeEndpointReset-Dwj-jCDS.js +66 -0
- package/dist/assets/{runtimeSurface-kIEoYsPP.js → runtimeSurface-0K7vuUpd.js} +1 -1
- package/dist/assets/{selection-BTEdLRVK.js → selection-CnYkEsu_.js} +1 -1
- package/dist/assets/useAppFontEffects-CV5UyTRw.js +226 -0
- package/dist/assets/{useGitHubRemoteSearch-DIBHNu8r.js → useGitHubRemoteSearch-CgP-zEBj.js} +1 -1
- package/dist/assets/{useSwitcherItems-DfLbfX37.js → useSwitcherItems-C8G5F0hs.js} +1 -1
- package/dist/assets/{web-components-C_DsTJis.js → web-components-BpncHjnV.js} +1 -1
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +1 -1
- package/plugins/featured.json +12 -0
- package/plugins/subagents/package.json +1 -1
- package/plugins/visuals/extension.js +7 -4
- package/plugins/visuals/package.json +1 -1
- package/server/index.js +86 -27
- package/server/lib/git/DOCUMENTATION.md +4 -0
- package/server/lib/git/service.js +70 -5
- package/server/lib/git/service.test.js +179 -0
- package/server/lib/github/DOCUMENTATION.md +2 -0
- package/server/lib/marketplace/DOCUMENTATION.md +95 -0
- package/server/lib/marketplace/featured.js +176 -0
- package/server/lib/marketplace/featured.test.js +207 -0
- package/server/lib/marketplace/npm-registry.js +255 -0
- package/server/lib/marketplace/npm-registry.test.js +227 -0
- package/server/lib/marketplace/routes.js +64 -0
- package/server/lib/marketplace/routes.test.js +119 -0
- package/server/lib/marketplace/service.js +225 -0
- package/server/lib/marketplace/service.test.js +174 -0
- package/server/lib/notifications/DOCUMENTATION.md +10 -4
- package/server/lib/notifications/pi-notification-watcher.js +92 -33
- package/server/lib/notifications/pi-notification-watcher.test.js +79 -0
- package/server/lib/open-url/DOCUMENTATION.md +1 -0
- package/server/lib/pi/merged-event-stream.js +316 -0
- package/server/lib/pi/merged-event-stream.test.js +95 -0
- package/server/lib/pi/routes-daemon-pool.test.js +348 -0
- package/server/lib/pi/routes-merged-events.test.js +327 -0
- package/server/lib/pi/routes-sandbox.test.js +1684 -0
- package/server/lib/pi/routes.js +491 -90
- package/server/lib/pi/routes.test.js +87 -2
- package/server/lib/pi/sandbox/DOCUMENTATION.md +68 -0
- package/server/lib/pi/sandbox/launcher.js +122 -0
- package/server/lib/pi/sandbox/launcher.test.js +91 -0
- package/server/lib/pi/sandbox/nono-launcher.js +455 -0
- package/server/lib/pi/sandbox/nono-launcher.test.js +371 -0
- package/server/lib/pi/sandbox/nono-profile-macos.json +20 -0
- package/server/lib/pi/sandbox/nono-profile-wsl2.json +21 -0
- package/server/lib/pi/sandbox/nono-profile.json +22 -0
- package/server/lib/pi/sandbox/project-sandbox-manager.js +1461 -0
- package/server/lib/pi/sandbox/project-sandbox-setting.js +166 -0
- package/server/lib/pi/sandbox/project-sandbox.js +207 -0
- package/server/lib/pi/sandbox/sandbox-routes.js +110 -0
- package/server/lib/pi/sandbox/sandboxed-folders.js +100 -0
- package/server/lib/pi/sandbox/sandboxed-folders.test.js +65 -0
- package/server/lib/pi/sandbox/trust-ask.js +135 -0
- package/server/lib/pi/sandbox/trust-ask.test.js +54 -0
- package/server/lib/pi/sandbox/worktree-ids.js +96 -0
- package/server/lib/pi/sandbox/worktree-ids.test.js +73 -0
- package/server/lib/pi/session-daemon/DOCUMENTATION.md +26 -6
- package/server/lib/pi/session-daemon/daemon-pool.js +157 -0
- package/server/lib/pi/session-daemon/daemon-process.js +10 -1
- package/server/lib/pi/session-daemon/extension-config.js +206 -23
- package/server/lib/pi/session-daemon/extension-config.test.js +180 -0
- package/server/lib/pi/session-daemon/session-daemon-read-persisted.test.js +167 -0
- package/server/lib/pi/session-daemon/session-daemon.js +368 -56
- package/server/lib/pi/session-daemon/session-daemon.test.js +227 -0
- package/server/lib/pi/session-daemon/session-idle-residency.test.js +98 -1
- package/server/lib/pi/session-daemon/session-jsonl.js +49 -10
- package/server/lib/pi/session-daemon/session-jsonl.test.js +11 -0
- package/server/lib/pi/session-daemon/session-lease.js +93 -15
- package/server/lib/pi/session-daemon/session-lease.test.js +107 -1
- package/server/lib/pi/session-daemon/supervisor-launcher-stop.test.js +295 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox-nono.e2e.test.js +301 -0
- package/server/lib/pi/session-daemon/supervisor-sandbox.test.js +444 -0
- package/server/lib/pi/session-daemon/supervisor.js +386 -35
- package/server/lib/pi/session-daemon/supervisor.test.js +28 -0
- package/server/lib/pi/ui-settings-store.js +88 -2
- package/server/lib/pi/ui-settings-store.test.js +118 -0
- package/server/lib/plugins/DOCUMENTATION.md +17 -5
- package/server/lib/plugins/daemon-sync.js +16 -6
- package/server/lib/plugins/daemon-sync.test.js +12 -0
- package/server/lib/plugins/impact.test.js +2 -1
- package/server/lib/plugins/manifest.js +25 -0
- package/server/lib/plugins/manifest.test.js +9 -0
- package/server/lib/plugins/routes.test.js +28 -0
- package/server/lib/plugins/service.js +24 -2
- package/server/lib/server/cross-process-lock.js +28 -3
- package/dist/assets/SettingsView-BHBpt2Um.js +0 -7
- package/dist/assets/VisualFrame-CJrAvWSo.js +0 -22
- package/dist/assets/VisualsArtifact-DqLGgU-Q.js +0 -1
- package/dist/assets/index-B2v0_mez.js +0 -11
- package/dist/assets/index-D3F4JrPN.css +0 -1
- package/dist/assets/renderMobileApp-B7cT7m5b.js +0 -11
- package/dist/assets/runtimeEndpointReset-BC6yGnxN.js +0 -62
- package/dist/assets/useAppFontEffects-EcTZ_I_I.js +0 -225
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
2
|
+
import express from 'express';
|
|
3
|
+
|
|
4
|
+
import { registerPiRuntimeRoutes } from './routes.js';
|
|
5
|
+
import { createPiDaemonPool } from './session-daemon/daemon-pool.js';
|
|
6
|
+
|
|
7
|
+
const listen = (app) => new Promise((resolve, reject) => {
|
|
8
|
+
const server = app.listen(0, '127.0.0.1', () => resolve(server));
|
|
9
|
+
server.once('error', reject);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const close = (server) => new Promise((resolve) => {
|
|
13
|
+
if (!server) return resolve();
|
|
14
|
+
server.closeAllConnections?.();
|
|
15
|
+
server.close(() => resolve());
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
// A fake daemon records every command it receives and answers from a table
|
|
19
|
+
// keyed by command name (a function receives the payload).
|
|
20
|
+
const fakeDaemon = (name, answers = {}) => {
|
|
21
|
+
const calls = [];
|
|
22
|
+
return {
|
|
23
|
+
name,
|
|
24
|
+
calls,
|
|
25
|
+
commands: () => calls.map((call) => call.command),
|
|
26
|
+
request: async (command, payload) => {
|
|
27
|
+
calls.push({ command, payload });
|
|
28
|
+
const answer = answers[command];
|
|
29
|
+
if (answer instanceof Error) throw answer;
|
|
30
|
+
if (typeof answer === 'function') return answer(payload);
|
|
31
|
+
if (answer !== undefined) return answer;
|
|
32
|
+
return {};
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const daemonError = (code) => Object.assign(new Error(code), { code });
|
|
38
|
+
|
|
39
|
+
const session = (id, directory) => ({ id, directory, createdAt: 1, updatedAt: 2 });
|
|
40
|
+
const detail = (id, directory) => ({ session: session(id, directory), messages: [], lastSequence: 0 });
|
|
41
|
+
const row = (id, directory, extra = {}) => ({ session: session(id, directory), updatedAt: 2, ...extra });
|
|
42
|
+
|
|
43
|
+
describe('Pi routes over a daemon pool', () => {
|
|
44
|
+
let server;
|
|
45
|
+
afterEach(async () => {
|
|
46
|
+
await close(server);
|
|
47
|
+
server = undefined;
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
const start = async (pool) => {
|
|
51
|
+
const app = express();
|
|
52
|
+
app.use(express.json());
|
|
53
|
+
registerPiRuntimeRoutes(app, {
|
|
54
|
+
daemonPool: pool,
|
|
55
|
+
archiveStore: { read: async () => ({}), set: async () => undefined },
|
|
56
|
+
});
|
|
57
|
+
server = await listen(app);
|
|
58
|
+
const base = `http://127.0.0.1:${server.address().port}`;
|
|
59
|
+
return (path, init) => fetch(`${base}${path}`, init?.body
|
|
60
|
+
? { ...init, headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(init.body) }
|
|
61
|
+
: init);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
it('sends session commands to the daemon that owns the project or its worktree', async () => {
|
|
65
|
+
const main = fakeDaemon('main', { 'sessions.open': (p) => detail(p.sessionId, p.directory) });
|
|
66
|
+
const sandbox = fakeDaemon('sandbox', { 'sessions.open': (p) => detail(p.sessionId, p.directory) });
|
|
67
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
68
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a', '/work/a-worktrees/feature'] });
|
|
69
|
+
const call = await start(pool);
|
|
70
|
+
|
|
71
|
+
expect((await call('/api/pi/sessions/s-1?directory=/work/a')).status).toBe(200);
|
|
72
|
+
expect((await call('/api/pi/sessions/s-2?directory=/work/a/packages/ui')).status).toBe(200);
|
|
73
|
+
expect((await call('/api/pi/sessions/s-3?directory=/work/a-worktrees/feature')).status).toBe(200);
|
|
74
|
+
expect((await call('/api/pi/sessions/s-4?directory=/work/ab')).status).toBe(200);
|
|
75
|
+
expect((await call('/api/pi/sessions/s-5?directory=/work/other')).status).toBe(200);
|
|
76
|
+
|
|
77
|
+
expect(sandbox.calls.map((c) => c.payload.sessionId)).toEqual(['s-1', 's-2', 's-3']);
|
|
78
|
+
expect(main.calls.map((c) => c.payload.sessionId)).toEqual(['s-4', 's-5']);
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it('keeps directory-less commands and resource writes on the main daemon', async () => {
|
|
82
|
+
const main = fakeDaemon('main', {
|
|
83
|
+
'projects.list': { projects: [{ directory: '/work/a', selected: true }] },
|
|
84
|
+
'projects.select': { directory: '/work/a' },
|
|
85
|
+
'providers.list': { providers: [] },
|
|
86
|
+
'engines.list': { engines: [] },
|
|
87
|
+
'providers.refresh': { providers: [] },
|
|
88
|
+
'providers.login': { loginId: 'l-1', state: 'pending' },
|
|
89
|
+
'providers.logout': {},
|
|
90
|
+
'settings.get': {},
|
|
91
|
+
'resources.list': { resources: [] },
|
|
92
|
+
'resources.prompts.create': { resources: [] },
|
|
93
|
+
});
|
|
94
|
+
const sandbox = fakeDaemon('sandbox');
|
|
95
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
96
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a'] });
|
|
97
|
+
const call = await start(pool);
|
|
98
|
+
|
|
99
|
+
await call('/api/pi/projects');
|
|
100
|
+
await call('/api/pi/projects/select', { method: 'POST', body: { directory: '/work/a' } });
|
|
101
|
+
await call('/api/pi/providers');
|
|
102
|
+
await call('/api/pi/engines');
|
|
103
|
+
await call('/api/pi/providers/refresh', { method: 'POST', body: { directory: '/work/a' } });
|
|
104
|
+
await call('/api/pi/providers/openai/login', { method: 'POST', body: { type: 'oauth' } });
|
|
105
|
+
await call('/api/pi/providers/openai/logout', { method: 'POST', body: {} });
|
|
106
|
+
await call('/api/pi/settings');
|
|
107
|
+
await call('/api/pi/resources');
|
|
108
|
+
await call('/api/pi/resources/prompts', {
|
|
109
|
+
method: 'POST',
|
|
110
|
+
body: { name: 'review', description: 'd', content: 'c', location: 'global', directory: '/work/a' },
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
expect(sandbox.calls).toEqual([]);
|
|
114
|
+
expect(main.commands()).toEqual([
|
|
115
|
+
'projects.list', 'projects.select', 'providers.list', 'engines.list', 'providers.refresh',
|
|
116
|
+
'providers.login', 'providers.logout', 'settings.get', 'resources.list', 'resources.prompts.create',
|
|
117
|
+
]);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('routes create, list, rename, resources, extensions and receipts by directory', async () => {
|
|
121
|
+
const answers = {
|
|
122
|
+
'sessions.create': (p) => detail('s-new', p.cwd),
|
|
123
|
+
'sessions.list': { sessions: [] },
|
|
124
|
+
'sessions.rename': {},
|
|
125
|
+
'resources.list': { resources: [] },
|
|
126
|
+
'extensions.list': { extensions: [] },
|
|
127
|
+
'extensions.respond': { resolved: true },
|
|
128
|
+
'sessions.sendReceipt': { status: 'unknown' },
|
|
129
|
+
'sessions.bash': {},
|
|
130
|
+
};
|
|
131
|
+
const main = fakeDaemon('main', answers);
|
|
132
|
+
const sandbox = fakeDaemon('sandbox', answers);
|
|
133
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
134
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a', '/work/a-wt'] });
|
|
135
|
+
const call = await start(pool);
|
|
136
|
+
|
|
137
|
+
expect((await call('/api/pi/sessions', { method: 'POST', body: { cwd: '/work/a-wt' } })).status).toBe(201);
|
|
138
|
+
expect((await call('/api/pi/sessions?directory=/work/a')).status).toBe(200);
|
|
139
|
+
expect((await call('/api/pi/sessions/s-1', { method: 'PATCH', body: { title: 't', directory: '/work/a' } })).status).toBe(204);
|
|
140
|
+
// Status codes past this point depend on fake payload shapes; routing is
|
|
141
|
+
// what is asserted below.
|
|
142
|
+
await call('/api/pi/resources?directory=/work/a');
|
|
143
|
+
await call('/api/pi/extensions?directory=/work/a');
|
|
144
|
+
await call('/api/pi/extensions/respond', { method: 'POST', body: { requestId: 'r-1', directory: '/work/a', cancelled: true } });
|
|
145
|
+
await call('/api/pi/sessions/s-1/send-receipt?directory=/work/a', {
|
|
146
|
+
method: 'POST',
|
|
147
|
+
body: { kind: 'prompt', operationId: 'op-123456789abc' },
|
|
148
|
+
});
|
|
149
|
+
await call('/api/pi/sessions/s-1/bash', { method: 'POST', body: { command: 'ls', directory: '/work/a' } });
|
|
150
|
+
|
|
151
|
+
expect(sandbox.commands()).toEqual([
|
|
152
|
+
'sessions.create', 'sessions.list', 'sessions.rename', 'resources.list', 'extensions.list',
|
|
153
|
+
'extensions.respond', 'sessions.sendReceipt', 'sessions.bash',
|
|
154
|
+
]);
|
|
155
|
+
expect(main.calls).toEqual([]);
|
|
156
|
+
// The payload the daemon sees is unchanged by routing.
|
|
157
|
+
expect(sandbox.calls.find((c) => c.command === 'sessions.sendReceipt').payload)
|
|
158
|
+
.toEqual({ kind: 'prompt', sessionId: 's-1', operationId: 'op-123456789abc' });
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
const pending = (sessionId, directory) => ({ sessionId, directory, pending: { count: 1, kind: 'input', since: 5 } });
|
|
162
|
+
|
|
163
|
+
it('merges pending input from every live daemon with each daemon\'s own cursor', async () => {
|
|
164
|
+
const main = fakeDaemon('main', { 'sessions.pendingInput': { sessions: [pending('s-main', '/work/other')], sequence: 40, streamEpoch: 'epoch-main' } });
|
|
165
|
+
const sandbox = fakeDaemon('sandbox', { 'sessions.pendingInput': { sessions: [pending('s-box', '/work/a')], sequence: 7, streamEpoch: 'epoch-box' } });
|
|
166
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
167
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a'] });
|
|
168
|
+
const call = await start(pool);
|
|
169
|
+
|
|
170
|
+
const response = await call('/api/pi/sessions/pending-input');
|
|
171
|
+
expect(response.status).toBe(200);
|
|
172
|
+
const body = await response.json();
|
|
173
|
+
const stream = pool.streamFor('/work/a');
|
|
174
|
+
expect(body).toEqual({
|
|
175
|
+
sessions: [pending('s-main', '/work/other'), { ...pending('s-box', '/work/a'), stream }],
|
|
176
|
+
sequence: 40,
|
|
177
|
+
streamEpoch: 'epoch-main',
|
|
178
|
+
streams: { [stream]: { sequence: 7, streamEpoch: 'epoch-box' } },
|
|
179
|
+
});
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('keeps the other daemons\' pending input when one daemon fails, and marks the list incomplete', async () => {
|
|
183
|
+
const main = fakeDaemon('main', { 'sessions.pendingInput': { sessions: [pending('s-main', '/work/other')], sequence: 40, streamEpoch: 'epoch-main' } });
|
|
184
|
+
const broken = fakeDaemon('broken', { 'sessions.pendingInput': daemonError('DAEMON_UNAVAILABLE') });
|
|
185
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
186
|
+
pool.register('project-a', { runtime: broken, directories: ['/work/a'] });
|
|
187
|
+
const call = await start(pool);
|
|
188
|
+
|
|
189
|
+
const response = await call('/api/pi/sessions/pending-input');
|
|
190
|
+
expect(response.status).toBe(200);
|
|
191
|
+
expect(await response.json()).toEqual({
|
|
192
|
+
sessions: [pending('s-main', '/work/other')],
|
|
193
|
+
sequence: 40,
|
|
194
|
+
streamEpoch: 'epoch-main',
|
|
195
|
+
incomplete: true,
|
|
196
|
+
});
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('serves project daemons\' pending input when the main daemon fails, without a main cursor', async () => {
|
|
200
|
+
const main = fakeDaemon('main', { 'sessions.pendingInput': daemonError('DAEMON_UNAVAILABLE') });
|
|
201
|
+
const sandbox = fakeDaemon('sandbox', { 'sessions.pendingInput': { sessions: [pending('s-box', '/work/a')], sequence: 7, streamEpoch: 'epoch-box' } });
|
|
202
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
203
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a'] });
|
|
204
|
+
const call = await start(pool);
|
|
205
|
+
|
|
206
|
+
const response = await call('/api/pi/sessions/pending-input');
|
|
207
|
+
const stream = pool.streamFor('/work/a');
|
|
208
|
+
expect(await response.json()).toEqual({
|
|
209
|
+
sessions: [{ ...pending('s-box', '/work/a'), stream }],
|
|
210
|
+
streams: { [stream]: { sequence: 7, streamEpoch: 'epoch-box' } },
|
|
211
|
+
incomplete: true,
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('tags responses from a project daemon with its stream, and main responses with none', async () => {
|
|
216
|
+
const answers = {
|
|
217
|
+
'sessions.open': (p) => ({ ...detail(p.sessionId, p.directory), streamEpoch: 'epoch' }),
|
|
218
|
+
'sessions.create': (p) => ({ ...detail('s-new', p.cwd), streamEpoch: 'epoch' }),
|
|
219
|
+
'sessions.list': { streamEpoch: 'epoch', sessions: [] },
|
|
220
|
+
'sessions.navigate': (p) => ({ ...detail(p.sessionId, p.directory), streamEpoch: 'epoch' }),
|
|
221
|
+
'sessions.fork': (p) => ({ ...detail('s-fork', p.directory), streamEpoch: 'epoch' }),
|
|
222
|
+
};
|
|
223
|
+
const main = fakeDaemon('main', answers);
|
|
224
|
+
const sandbox = fakeDaemon('sandbox', answers);
|
|
225
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
226
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a'] });
|
|
227
|
+
const call = await start(pool);
|
|
228
|
+
const stream = pool.streamFor('/work/a');
|
|
229
|
+
expect(stream).toMatch(/^[A-Za-z0-9_-]{16}$/);
|
|
230
|
+
|
|
231
|
+
const read = async (path, init) => (await call(path, init)).json();
|
|
232
|
+
expect((await read('/api/pi/sessions/s-1?directory=/work/a')).stream).toBe(stream);
|
|
233
|
+
expect((await read('/api/pi/sessions', { method: 'POST', body: { cwd: '/work/a' } })).stream).toBe(stream);
|
|
234
|
+
expect((await read('/api/pi/sessions?directory=/work/a')).stream).toBe(stream);
|
|
235
|
+
expect((await read('/api/pi/sessions/s-1/navigate', { method: 'POST', body: { messageId: 'm', directory: '/work/a' } })).stream).toBe(stream);
|
|
236
|
+
expect((await read('/api/pi/sessions/s-1/fork', { method: 'POST', body: { directory: '/work/a' } })).stream).toBe(stream);
|
|
237
|
+
|
|
238
|
+
expect((await read('/api/pi/sessions/s-1?directory=/work/other'))).not.toHaveProperty('stream');
|
|
239
|
+
expect((await read('/api/pi/sessions', { method: 'POST', body: { cwd: '/work/other' } }))).not.toHaveProperty('stream');
|
|
240
|
+
expect((await read('/api/pi/sessions?directory=/work/other'))).not.toHaveProperty('stream');
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('adds project daemons\' live status to the all-sessions list, tagged with their stream', async () => {
|
|
244
|
+
const busy = { lifecycle: 'busy', sequence: 12 };
|
|
245
|
+
const main = fakeDaemon('main', {
|
|
246
|
+
'sessions.list': {
|
|
247
|
+
streamEpoch: 'epoch-main',
|
|
248
|
+
sessions: [row('s-main', '/work/other', { live: { lifecycle: 'idle', sequence: 50 } }), row('s-box', '/work/a'), row('s-cold', '/work/a')],
|
|
249
|
+
},
|
|
250
|
+
});
|
|
251
|
+
const sandbox = fakeDaemon('sandbox', {
|
|
252
|
+
'sessions.list': {
|
|
253
|
+
streamEpoch: 'epoch-box',
|
|
254
|
+
sessions: [row('s-box', '/work/a', { live: busy, inputState: { pending: null, sequence: 12 } }), row('s-cold', '/work/a')],
|
|
255
|
+
},
|
|
256
|
+
});
|
|
257
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
258
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a'] });
|
|
259
|
+
const call = await start(pool);
|
|
260
|
+
const stream = pool.streamFor('/work/a');
|
|
261
|
+
|
|
262
|
+
const response = await call('/api/pi/sessions');
|
|
263
|
+
expect(await response.json()).toEqual({
|
|
264
|
+
streamEpoch: 'epoch-main',
|
|
265
|
+
sessions: [
|
|
266
|
+
row('s-main', '/work/other', { live: { lifecycle: 'idle', sequence: 50 } }),
|
|
267
|
+
row('s-box', '/work/a', { live: busy, inputState: { pending: null, sequence: 12 }, stream, streamEpoch: 'epoch-box' }),
|
|
268
|
+
row('s-cold', '/work/a'),
|
|
269
|
+
],
|
|
270
|
+
});
|
|
271
|
+
expect(sandbox.calls).toEqual([{ command: 'sessions.list', payload: {} }]);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it('fails pending input when every daemon fails', async () => {
|
|
275
|
+
const main = fakeDaemon('main', { 'sessions.pendingInput': daemonError('DAEMON_UNAVAILABLE') });
|
|
276
|
+
const broken = fakeDaemon('broken', { 'sessions.pendingInput': daemonError('DAEMON_UNAVAILABLE') });
|
|
277
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
278
|
+
pool.register('project-a', { runtime: broken, directories: ['/work/a'] });
|
|
279
|
+
const call = await start(pool);
|
|
280
|
+
|
|
281
|
+
const response = await call('/api/pi/sessions/pending-input');
|
|
282
|
+
expect(response.status).toBe(503);
|
|
283
|
+
expect(await response.json()).toEqual({ error: { code: 'DAEMON_UNAVAILABLE' } });
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
it('merges live state from a draining daemon into a directory list by session id', async () => {
|
|
287
|
+
const busy = { lifecycle: 'busy', sequence: 12 };
|
|
288
|
+
const sandbox = fakeDaemon('sandbox', {
|
|
289
|
+
'sessions.list': {
|
|
290
|
+
streamEpoch: 'epoch-box',
|
|
291
|
+
sessions: [row('s-1', '/work/a'), row('s-2', '/work/a', { live: { lifecycle: 'idle', sequence: 3 } })],
|
|
292
|
+
},
|
|
293
|
+
});
|
|
294
|
+
const main = fakeDaemon('main', {
|
|
295
|
+
'sessions.list': {
|
|
296
|
+
streamEpoch: 'epoch-main',
|
|
297
|
+
sessions: [
|
|
298
|
+
row('s-1', '/work/a', { live: busy, inputState: { pending: null, sequence: 12 } }),
|
|
299
|
+
row('s-2', '/work/a', { live: { lifecycle: 'busy', sequence: 9 } }),
|
|
300
|
+
row('s-9', '/work/a', { live: busy }),
|
|
301
|
+
],
|
|
302
|
+
},
|
|
303
|
+
});
|
|
304
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
305
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a'] });
|
|
306
|
+
pool.setDraining('/work/a', ['main']);
|
|
307
|
+
const call = await start(pool);
|
|
308
|
+
|
|
309
|
+
const response = await call('/api/pi/sessions?directory=/work/a');
|
|
310
|
+
expect(response.status).toBe(200);
|
|
311
|
+
expect(await response.json()).toEqual({
|
|
312
|
+
streamEpoch: 'epoch-box',
|
|
313
|
+
stream: pool.streamFor('/work/a'),
|
|
314
|
+
sessions: [
|
|
315
|
+
// Live state from the draining main daemon is in main's sequence space.
|
|
316
|
+
row('s-1', '/work/a', { live: busy, inputState: { pending: null, sequence: 12 }, stream: 'main', streamEpoch: 'epoch-main' }),
|
|
317
|
+
row('s-2', '/work/a', { live: { lifecycle: 'idle', sequence: 3 } }),
|
|
318
|
+
],
|
|
319
|
+
});
|
|
320
|
+
expect(main.calls).toEqual([{ command: 'sessions.list', payload: { directory: '/work/a' } }]);
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it('serves the owner\'s list unchanged when the draining daemon fails', async () => {
|
|
324
|
+
const rows = [row('s-1', '/work/a')];
|
|
325
|
+
const sandbox = fakeDaemon('sandbox', { 'sessions.list': { sessions: rows } });
|
|
326
|
+
const main = fakeDaemon('main', { 'sessions.list': daemonError('DAEMON_UNAVAILABLE') });
|
|
327
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
328
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a'] });
|
|
329
|
+
pool.setDraining('/work/a', ['main']);
|
|
330
|
+
const call = await start(pool);
|
|
331
|
+
|
|
332
|
+
const response = await call('/api/pi/sessions?directory=/work/a');
|
|
333
|
+
expect(response.status).toBe(200);
|
|
334
|
+
expect(await response.json()).toEqual({ sessions: rows, stream: pool.streamFor('/work/a') });
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('fails the list when the owning daemon fails, even if a draining daemon answers', async () => {
|
|
338
|
+
const sandbox = fakeDaemon('sandbox', { 'sessions.list': daemonError('DAEMON_UNAVAILABLE') });
|
|
339
|
+
const main = fakeDaemon('main', { 'sessions.list': { sessions: [row('s-1', '/work/a')] } });
|
|
340
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
341
|
+
pool.register('project-a', { runtime: sandbox, directories: ['/work/a'] });
|
|
342
|
+
pool.setDraining('/work/a', ['main']);
|
|
343
|
+
const call = await start(pool);
|
|
344
|
+
|
|
345
|
+
const response = await call('/api/pi/sessions?directory=/work/a');
|
|
346
|
+
expect(response.status).toBe(503);
|
|
347
|
+
});
|
|
348
|
+
});
|