@pi-chamber/web 1.0.8-rc.1 → 1.0.8-rc.3
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-wsW9VCRp.js} +1 -1
- package/dist/assets/{ChoicesArtifact-C71fGOm2.js → ChoicesArtifact-EwCf4Yxu.js} +1 -1
- package/dist/assets/{DiagramView-BZQxoiZu.js → DiagramView-BX6N99cQ.js} +1 -1
- package/dist/assets/{DiffView-C70pbgk-.js → DiffView-CI0eSnPP.js} +1 -1
- package/dist/assets/{FileSaveConflictDialog-Cu8c3gBV.js → FileSaveConflictDialog-GLj2W7VE.js} +1 -1
- package/dist/assets/{FilesView-nFJYEdRw.js → FilesView-CI0tfZQL.js} +1 -1
- package/dist/assets/{GitHubDetailScaffold-Jvv_tgbl.js → GitHubDetailScaffold-B85tZ9m7.js} +1 -1
- package/dist/assets/{GitHubLinkPicker-BXD2ODRi.js → GitHubLinkPicker-Y6AuNiGl.js} +1 -1
- package/dist/assets/{GitHubListPrimitives-BWI706F0.js → GitHubListPrimitives-BJHBud6i.js} +1 -1
- package/dist/assets/{GitView-MIDG5RYW.js → GitView-DueE69kW.js} +5 -5
- package/dist/assets/{IssuesSurface-uNlozeu0.js → IssuesSurface-Cg-xkdIu.js} +3 -3
- package/dist/assets/{JsonTreeView-CSLsTriz.js → JsonTreeView-Cvg6lc40.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Cs-7BfWi.js → MarkdownRendererImpl-DExPx-QM.js} +1 -1
- package/dist/assets/{PatchDiff-axbsnbTJ.js → PatchDiff-_c3HZ34I.js} +1 -1
- package/dist/assets/{PierreDiffViewer-lwn6w_5w.js → PierreDiffViewer-CZnaqO-_.js} +1 -1
- package/dist/assets/{PullRequestsSurface-o_AXDjbO.js → PullRequestsSurface-C9AYPiwo.js} +2 -2
- package/dist/assets/{SessionSwitcherContent-C4CMlcbv.js → SessionSwitcherContent-DOpnN-8S.js} +1 -1
- package/dist/assets/{SessionSwitcherDropdown-DCBVuCoo.js → SessionSwitcherDropdown-CmHMPZ69.js} +2 -2
- package/dist/assets/{SessionUnreadDot-DyeIrsro.js → SessionUnreadDot-CZCQ4t1J.js} +1 -1
- package/dist/assets/SettingsView-D5PO5M3z.js +11 -0
- package/dist/assets/{SettingsWindow-Cb4st5y5.js → SettingsWindow-DXV5UOE8.js} +1 -1
- package/dist/assets/{SubagentsArtifact-BzeMEoFP.js → SubagentsArtifact-CO1ZiI1x.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BP2mOWdV.js → ToolOutputDialog-GOwNLj-y.js} +1 -1
- package/dist/assets/{ToolPartDiffPreview-D49XBR9b.js → ToolPartDiffPreview-BoaiZji6.js} +1 -1
- package/dist/assets/{VirtualizedFileDiff-CLgDONEQ.js → VirtualizedFileDiff-Chq1X8nw.js} +1 -1
- package/dist/assets/VisualFrame-u7aRcX7O.js +22 -0
- package/dist/assets/VisualsArtifact-D9vPjihW.js +1 -0
- package/dist/assets/{collapsible-BeyKtQGB.js → collapsible-BjpDEohv.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DmO6H8u6.js → computeVirtualFileMetrics-DmPCxbok.js} +1 -1
- package/dist/assets/{contextFileOpenGuard-DOK251YW.js → contextFileOpenGuard-CukNcUeY.js} +1 -1
- package/dist/assets/{fileTreeStatus-CnzR7kxA.js → fileTreeStatus-CDyfNPYO.js} +1 -1
- package/dist/assets/{gitStatusPredicates-4kPg2t6j.js → gitStatusPredicates-uI7Y7L5k.js} +1 -1
- package/dist/assets/{githubLink-QvaLfNNT.js → githubLink-B9Mxac4R.js} +1 -1
- package/dist/assets/{index-DMX9wT1Z.js → index-BWq2ibCw.js} +1 -1
- package/dist/assets/index-BxKPJ9uG.js +11 -0
- package/dist/assets/index-C5JgjS20.css +1 -0
- package/dist/assets/{main-BirYxac2.js → main-CWfC-9xT.js} +4 -4
- package/dist/assets/{main-BW9J3Y72.js → main-ckQ0ciIN.js} +2 -2
- package/dist/assets/{markdownCore-CxmcPur8.js → markdownCore-p2q2Kxwo.js} +1 -1
- package/dist/assets/{miniChat-BRB11eEs.js → miniChat-x2TrwRYA.js} +2 -2
- package/dist/assets/{mobile-DJZYYCuB.js → mobile-B0x2G8h1.js} +2 -2
- package/dist/assets/{nativeFileSave-B6QpoPRn.js → nativeFileSave-D542OJlG.js} +1 -1
- package/dist/assets/{pi-session-focus-preference-PWoh3LNA.js → pi-session-focus-preference-Q_RZUCnt.js} +1 -1
- package/dist/assets/{renderDiffWithHighlighter-C48T6YFJ.js → renderDiffWithHighlighter-CSFGSknx.js} +1 -1
- package/dist/assets/{renderElectronMiniChatApp-N-BQdJl0.js → renderElectronMiniChatApp-CFIdesZT.js} +2 -2
- package/dist/assets/{renderFileWithHighlighter-8Kt2MyTN.js → renderFileWithHighlighter-C5JE0mRX.js} +1 -1
- package/dist/assets/renderMobileApp-B1ybjcGM.js +11 -0
- package/dist/assets/runtimeEndpointReset-DyZSKCYM.js +66 -0
- package/dist/assets/{runtimeSurface-kIEoYsPP.js → runtimeSurface-BR_dhe7_.js} +1 -1
- package/dist/assets/{selection-BTEdLRVK.js → selection-CfOpW4rA.js} +1 -1
- package/dist/assets/useAppFontEffects-COMvkffC.js +226 -0
- package/dist/assets/{useGitHubRemoteSearch-DIBHNu8r.js → useGitHubRemoteSearch-M1AE2YuX.js} +1 -1
- package/dist/assets/{useSwitcherItems-DfLbfX37.js → useSwitcherItems-D0i2BYYP.js} +1 -1
- package/dist/assets/{web-components-C_DsTJis.js → web-components-wOQkOurQ.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 +8 -5
- package/plugins/visuals/package.json +1 -1
- package/server/index.js +90 -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 +90 -3
- 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/server/lib/wallpaper/DOCUMENTATION.md +25 -0
- package/server/lib/wallpaper/routes.js +63 -0
- package/server/lib/wallpaper/routes.test.js +109 -0
- package/server/lib/wallpaper/store.js +87 -0
- 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,327 @@
|
|
|
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
|
+
const tick = () => new Promise((resolve) => setTimeout(resolve, 5));
|
|
19
|
+
|
|
20
|
+
// A fake daemon whose event stream the test drives: every subscription is
|
|
21
|
+
// recorded with its options, and `emit` writes a daemon frame to every open
|
|
22
|
+
// subscription.
|
|
23
|
+
const fakeDaemon = (epoch) => {
|
|
24
|
+
const subscriptions = [];
|
|
25
|
+
return {
|
|
26
|
+
epoch,
|
|
27
|
+
subscriptions,
|
|
28
|
+
get open() {
|
|
29
|
+
return subscriptions.filter((s) => !s.closed);
|
|
30
|
+
},
|
|
31
|
+
request: async () => ({}),
|
|
32
|
+
subscribe: async (options) => {
|
|
33
|
+
const record = { options, closed: false };
|
|
34
|
+
subscriptions.push(record);
|
|
35
|
+
return () => { record.closed = true; };
|
|
36
|
+
},
|
|
37
|
+
emit(event, sequence, payload) {
|
|
38
|
+
for (const s of this.open) {
|
|
39
|
+
s.options.onEvent({ protocolVersion: 1, kind: 'event', event, sequence, streamEpoch: epoch, payload });
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
fail() {
|
|
43
|
+
for (const s of this.open) s.options.onError(new Error('socket closed'));
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const title = (sessionId, directory, value) => ({ sessionId, directory, title: value });
|
|
49
|
+
|
|
50
|
+
// Reads SSE `data:` frames from a response as parsed JSON, ignoring heartbeats.
|
|
51
|
+
const sseReader = (response) => {
|
|
52
|
+
const reader = response.body.getReader();
|
|
53
|
+
const decoder = new TextDecoder();
|
|
54
|
+
let buffer = '';
|
|
55
|
+
const frames = [];
|
|
56
|
+
// One read stays pending across timeouts: a read abandoned after a
|
|
57
|
+
// timeout would still take the next chunk and drop it.
|
|
58
|
+
let pending = null;
|
|
59
|
+
return {
|
|
60
|
+
frames,
|
|
61
|
+
async until(predicate, limit = 50) {
|
|
62
|
+
for (let i = 0; i < limit && !predicate(frames); i += 1) {
|
|
63
|
+
pending ??= reader.read();
|
|
64
|
+
const next = await Promise.race([pending, new Promise((r) => setTimeout(() => r({ timeout: true }), 200))]);
|
|
65
|
+
if (next.timeout) continue;
|
|
66
|
+
pending = null;
|
|
67
|
+
if (next.done) break;
|
|
68
|
+
buffer += decoder.decode(next.value);
|
|
69
|
+
let end = buffer.indexOf('\n\n');
|
|
70
|
+
while (end >= 0) {
|
|
71
|
+
const block = buffer.slice(0, end);
|
|
72
|
+
buffer = buffer.slice(end + 2);
|
|
73
|
+
const data = block.split('\n').find((line) => line.startsWith('data: '));
|
|
74
|
+
if (data && !block.startsWith('event: heartbeat')) frames.push(JSON.parse(data.slice(6)));
|
|
75
|
+
end = buffer.indexOf('\n\n');
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return frames;
|
|
79
|
+
},
|
|
80
|
+
cancel: () => reader.cancel(),
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
describe('merged Pi event stream over a daemon pool', () => {
|
|
85
|
+
let server;
|
|
86
|
+
const readers = [];
|
|
87
|
+
afterEach(async () => {
|
|
88
|
+
for (const reader of readers.splice(0)) await reader.cancel().catch(() => undefined);
|
|
89
|
+
await close(server);
|
|
90
|
+
server = undefined;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const start = async (pool) => {
|
|
94
|
+
const app = express();
|
|
95
|
+
registerPiRuntimeRoutes(app, { daemonPool: pool, archiveStore: { read: async () => ({}), set: async () => undefined } });
|
|
96
|
+
server = await listen(app);
|
|
97
|
+
return async (query = '') => {
|
|
98
|
+
const response = await fetch(`http://127.0.0.1:${server.address().port}/api/pi/events?capabilities=events.streamEpoch${query}`);
|
|
99
|
+
if (response.status !== 200) return { status: response.status, body: await response.json() };
|
|
100
|
+
const reader = sseReader(response);
|
|
101
|
+
readers.push(reader);
|
|
102
|
+
await reader.until(() => false, 1);
|
|
103
|
+
return reader;
|
|
104
|
+
};
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
it('keeps main-only frames and subscribe options unchanged', async () => {
|
|
108
|
+
const main = fakeDaemon('epoch-main');
|
|
109
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
110
|
+
const open = await start(pool);
|
|
111
|
+
|
|
112
|
+
const stream = await open('&sessionId=s-1&directory=/work/other&fromSequence=7&streamEpoch=epoch-main');
|
|
113
|
+
main.emit('session.updated', 8, title('s-1', '/work/other', 'Main'));
|
|
114
|
+
await stream.until((frames) => frames.length >= 1);
|
|
115
|
+
|
|
116
|
+
expect(stream.frames).toEqual([{
|
|
117
|
+
protocolVersion: 1, kind: 'event', name: 'session.updated', sequence: 8,
|
|
118
|
+
sessionId: 's-1', directory: '/work/other', streamEpoch: 'epoch-main', payload: { title: 'Main' },
|
|
119
|
+
}]);
|
|
120
|
+
const { onEvent, onError, signal, ...options } = main.subscriptions[0].options;
|
|
121
|
+
expect(options).toEqual({ sessionId: 's-1', directory: '/work/other', fromSequence: 7, streamEpoch: 'epoch-main' });
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('merges every daemon\'s frames, tagging project daemon frames with an opaque stream and cursor', async () => {
|
|
125
|
+
const main = fakeDaemon('epoch-main');
|
|
126
|
+
const sandbox = fakeDaemon('epoch-box');
|
|
127
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
128
|
+
pool.register('/work/a', { runtime: sandbox, directories: ['/work/a'] });
|
|
129
|
+
const open = await start(pool);
|
|
130
|
+
|
|
131
|
+
const stream = await open();
|
|
132
|
+
main.emit('session.updated', 3, title('s-main', '/work/other', 'Main'));
|
|
133
|
+
sandbox.emit('session.updated', 11, title('s-box', '/work/a', 'Box'));
|
|
134
|
+
await stream.until((frames) => frames.length >= 2);
|
|
135
|
+
|
|
136
|
+
const [fromMain, fromBox] = stream.frames;
|
|
137
|
+
expect(fromMain).toEqual({
|
|
138
|
+
protocolVersion: 1, kind: 'event', name: 'session.updated', sequence: 3,
|
|
139
|
+
sessionId: 's-main', directory: '/work/other', streamEpoch: 'epoch-main', payload: { title: 'Main' },
|
|
140
|
+
});
|
|
141
|
+
expect(fromBox).toMatchObject({ name: 'session.updated', sequence: 11, sessionId: 's-box', streamEpoch: 'epoch-box', payload: { title: 'Box' } });
|
|
142
|
+
expect(typeof fromBox.stream).toBe('string');
|
|
143
|
+
expect(typeof fromBox.cursor).toBe('string');
|
|
144
|
+
// Opaque: the pool key (a server path) never appears on the wire.
|
|
145
|
+
expect(fromBox.stream).not.toContain('/work');
|
|
146
|
+
expect(Buffer.from(fromBox.cursor, 'base64url').toString()).not.toContain('/work');
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it('resumes every project daemon from the cursor and main from its own sequence', async () => {
|
|
150
|
+
const main = fakeDaemon('epoch-main');
|
|
151
|
+
const sandbox = fakeDaemon('epoch-box');
|
|
152
|
+
const other = fakeDaemon('epoch-other');
|
|
153
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
154
|
+
pool.register('/work/a', { runtime: sandbox, directories: ['/work/a'] });
|
|
155
|
+
pool.register('/work/b', { runtime: other, directories: ['/work/b'] });
|
|
156
|
+
const open = await start(pool);
|
|
157
|
+
|
|
158
|
+
const first = await open();
|
|
159
|
+
sandbox.emit('session.updated', 11, title('s-box', '/work/a', 'Box'));
|
|
160
|
+
other.emit('session.updated', 4, title('s-other', '/work/b', 'Other'));
|
|
161
|
+
await first.until((frames) => frames.length >= 2);
|
|
162
|
+
const cursor = first.frames[1].cursor;
|
|
163
|
+
|
|
164
|
+
await open(`&fromSequence=30&streamEpoch=epoch-main&cursor=${encodeURIComponent(cursor)}`);
|
|
165
|
+
const pick = ({ fromSequence, streamEpoch }) => ({ fromSequence, streamEpoch });
|
|
166
|
+
expect(pick(main.subscriptions[1].options)).toEqual({ fromSequence: 30, streamEpoch: 'epoch-main' });
|
|
167
|
+
expect(pick(sandbox.subscriptions[1].options)).toEqual({ fromSequence: 11, streamEpoch: 'epoch-box' });
|
|
168
|
+
expect(pick(other.subscriptions[1].options)).toEqual({ fromSequence: 4, streamEpoch: 'epoch-other' });
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('rejects a malformed cursor and a cursor without the epoch capability', async () => {
|
|
172
|
+
const main = fakeDaemon('epoch-main');
|
|
173
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
174
|
+
const open = await start(pool);
|
|
175
|
+
|
|
176
|
+
expect(await open('&cursor=not-a-cursor')).toEqual({ status: 400, body: { error: { code: 'INVALID_ARGUMENT' } } });
|
|
177
|
+
const response = await fetch(`http://127.0.0.1:${server.address().port}/api/pi/events?cursor=e30`);
|
|
178
|
+
expect(response.status).toBe(400);
|
|
179
|
+
expect(main.subscriptions).toEqual([]);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('a restarted project daemon resyncs only its own sessions', async () => {
|
|
183
|
+
const main = fakeDaemon('epoch-main');
|
|
184
|
+
const sandbox = fakeDaemon('epoch-box');
|
|
185
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
186
|
+
pool.register('/work/a', { runtime: sandbox, directories: ['/work/a'] });
|
|
187
|
+
const open = await start(pool);
|
|
188
|
+
|
|
189
|
+
const stream = await open();
|
|
190
|
+
main.emit('session.updated', 3, title('s-main', '/work/other', 'Main'));
|
|
191
|
+
sandbox.emit('session.updated', 11, title('s-box', '/work/a', 'Box'));
|
|
192
|
+
await stream.until((frames) => frames.length >= 2);
|
|
193
|
+
|
|
194
|
+
const restarted = fakeDaemon('epoch-box-2');
|
|
195
|
+
pool.register('/work/a', { runtime: restarted, directories: ['/work/a'] });
|
|
196
|
+
await stream.until((frames) => frames.length >= 3);
|
|
197
|
+
await tick();
|
|
198
|
+
|
|
199
|
+
expect(stream.frames[2]).toEqual({
|
|
200
|
+
protocolVersion: 1, kind: 'event', name: 'session.moved', sequence: 0,
|
|
201
|
+
sessionId: 's-box', directory: '/work/a', payload: {},
|
|
202
|
+
});
|
|
203
|
+
expect(sandbox.open).toEqual([]);
|
|
204
|
+
// The new process is asked to resume from the old lifetime's cursor, which
|
|
205
|
+
// it answers with a resync snapshot.
|
|
206
|
+
const { fromSequence, streamEpoch } = restarted.subscriptions[0].options;
|
|
207
|
+
expect({ fromSequence, streamEpoch }).toEqual({ fromSequence: 11, streamEpoch: 'epoch-box' });
|
|
208
|
+
// Main was never resubscribed and keeps streaming.
|
|
209
|
+
expect(main.subscriptions).toHaveLength(1);
|
|
210
|
+
main.emit('session.updated', 4, title('s-main', '/work/other', 'Still'));
|
|
211
|
+
restarted.emit('session.updated', 1, title('s-box', '/work/a', 'Again'));
|
|
212
|
+
await stream.until((frames) => frames.length >= 5);
|
|
213
|
+
expect(stream.frames.slice(3).map((f) => [f.sessionId, f.streamEpoch])).toEqual([
|
|
214
|
+
['s-main', 'epoch-main'], ['s-box', 'epoch-box-2'],
|
|
215
|
+
]);
|
|
216
|
+
expect(stream.frames.filter((f) => f.name === 'session.moved')).toHaveLength(1);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('a project daemon stopping or failing does not drop the others', async () => {
|
|
220
|
+
const main = fakeDaemon('epoch-main');
|
|
221
|
+
const sandbox = fakeDaemon('epoch-box');
|
|
222
|
+
const other = fakeDaemon('epoch-other');
|
|
223
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
224
|
+
pool.register('/work/a', { runtime: sandbox, directories: ['/work/a'] });
|
|
225
|
+
pool.register('/work/b', { runtime: other, directories: ['/work/b'] });
|
|
226
|
+
const open = await start(pool);
|
|
227
|
+
|
|
228
|
+
const stream = await open();
|
|
229
|
+
sandbox.emit('session.updated', 11, title('s-box', '/work/a', 'Box'));
|
|
230
|
+
other.emit('session.updated', 4, title('s-other', '/work/b', 'Other'));
|
|
231
|
+
await stream.until((frames) => frames.length >= 2);
|
|
232
|
+
|
|
233
|
+
pool.unregister('/work/a');
|
|
234
|
+
other.fail();
|
|
235
|
+
await stream.until((frames) => frames.length >= 4);
|
|
236
|
+
expect(stream.frames.slice(2).map((f) => [f.name, f.sessionId])).toEqual([
|
|
237
|
+
['session.moved', 's-box'], ['session.moved', 's-other'],
|
|
238
|
+
]);
|
|
239
|
+
expect(sandbox.open).toEqual([]);
|
|
240
|
+
|
|
241
|
+
main.emit('session.updated', 5, title('s-main', '/work/other', 'Main'));
|
|
242
|
+
await stream.until((frames) => frames.length >= 5);
|
|
243
|
+
expect(stream.frames[4]).toMatchObject({ sessionId: 's-main', streamEpoch: 'epoch-main' });
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('retries a failed project daemon subscription from its last position and drops a stopped daemon from the cursor', async () => {
|
|
247
|
+
const main = fakeDaemon('epoch-main');
|
|
248
|
+
const sandbox = fakeDaemon('epoch-box');
|
|
249
|
+
const other = fakeDaemon('epoch-other');
|
|
250
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
251
|
+
pool.register('/work/a', { runtime: sandbox, directories: ['/work/a'] });
|
|
252
|
+
pool.register('/work/b', { runtime: other, directories: ['/work/b'] });
|
|
253
|
+
const app = express();
|
|
254
|
+
registerPiRuntimeRoutes(app, { daemonPool: pool, eventStreamRetryBaseMs: 1, archiveStore: { read: async () => ({}), set: async () => undefined } });
|
|
255
|
+
server = await listen(app);
|
|
256
|
+
const response = await fetch(`http://127.0.0.1:${server.address().port}/api/pi/events?capabilities=events.streamEpoch`);
|
|
257
|
+
const stream = sseReader(response);
|
|
258
|
+
readers.push(stream);
|
|
259
|
+
await stream.until(() => false, 1);
|
|
260
|
+
|
|
261
|
+
sandbox.emit('session.updated', 11, title('s-box', '/work/a', 'Box'));
|
|
262
|
+
other.emit('session.updated', 4, title('s-other', '/work/b', 'Other'));
|
|
263
|
+
await stream.until((frames) => frames.length >= 2);
|
|
264
|
+
sandbox.fail();
|
|
265
|
+
for (let i = 0; i < 20 && sandbox.open.length === 0; i += 1) await tick();
|
|
266
|
+
const { fromSequence, streamEpoch } = sandbox.subscriptions.at(-1).options;
|
|
267
|
+
expect({ fromSequence, streamEpoch }).toEqual({ fromSequence: 11, streamEpoch: 'epoch-box' });
|
|
268
|
+
|
|
269
|
+
pool.unregister('/work/a');
|
|
270
|
+
other.emit('session.updated', 5, title('s-other', '/work/b', 'Again'));
|
|
271
|
+
await stream.until((frames) => frames.some((f) => f.payload?.title === 'Again'));
|
|
272
|
+
const last = stream.frames.at(-1);
|
|
273
|
+
const decoded = JSON.parse(Buffer.from(last.cursor, 'base64url').toString());
|
|
274
|
+
expect(Object.values(decoded.d)).toEqual([['epoch-other', 5]]);
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
it('subscribes to a daemon that appears mid-stream without a cursor', async () => {
|
|
278
|
+
const main = fakeDaemon('epoch-main');
|
|
279
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
280
|
+
const open = await start(pool);
|
|
281
|
+
const stream = await open('&fromSequence=2&streamEpoch=epoch-main');
|
|
282
|
+
|
|
283
|
+
const sandbox = fakeDaemon('epoch-box');
|
|
284
|
+
pool.register('/work/a', { runtime: sandbox, directories: ['/work/a'] });
|
|
285
|
+
await tick();
|
|
286
|
+
expect(sandbox.subscriptions).toHaveLength(1);
|
|
287
|
+
expect(sandbox.subscriptions[0].options.fromSequence).toBeUndefined();
|
|
288
|
+
expect(sandbox.subscriptions[0].options.streamEpoch).toBeUndefined();
|
|
289
|
+
sandbox.emit('session.snapshot', 1, { sessionId: 's-box', directory: '/work/a', lifecycle: 'idle', queue: {} });
|
|
290
|
+
await stream.until((frames) => frames.length >= 1);
|
|
291
|
+
expect(stream.frames[0]).toMatchObject({ name: 'session.snapshot', sessionId: 's-box', streamEpoch: 'epoch-box' });
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it('announces a session whose frames move to another daemon', async () => {
|
|
295
|
+
const main = fakeDaemon('epoch-main');
|
|
296
|
+
const sandbox = fakeDaemon('epoch-box');
|
|
297
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
298
|
+
pool.register('/work/a', { runtime: sandbox, directories: ['/work/a'] });
|
|
299
|
+
const open = await start(pool);
|
|
300
|
+
const stream = await open();
|
|
301
|
+
|
|
302
|
+
main.emit('session.updated', 3, title('s-1', '/work/a', 'Before'));
|
|
303
|
+
sandbox.emit('session.updated', 1, title('s-1', '/work/a', 'After'));
|
|
304
|
+
await stream.until((frames) => frames.length >= 3);
|
|
305
|
+
expect(stream.frames.map((f) => [f.name, f.streamEpoch])).toEqual([
|
|
306
|
+
['session.updated', 'epoch-main'], ['session.moved', undefined], ['session.updated', 'epoch-box'],
|
|
307
|
+
]);
|
|
308
|
+
|
|
309
|
+
pool.announceMove('s-2', '/work/a');
|
|
310
|
+
await stream.until((frames) => frames.length >= 4);
|
|
311
|
+
expect(stream.frames[3]).toMatchObject({ name: 'session.moved', sessionId: 's-2', directory: '/work/a' });
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
it('still ends the connection when the main daemon subscription fails', async () => {
|
|
315
|
+
const main = fakeDaemon('epoch-main');
|
|
316
|
+
const sandbox = fakeDaemon('epoch-box');
|
|
317
|
+
const pool = createPiDaemonPool({ getMainRuntime: () => main });
|
|
318
|
+
pool.register('/work/a', { runtime: sandbox, directories: ['/work/a'] });
|
|
319
|
+
const open = await start(pool);
|
|
320
|
+
await open();
|
|
321
|
+
|
|
322
|
+
main.fail();
|
|
323
|
+
await tick();
|
|
324
|
+
expect(main.open).toEqual([]);
|
|
325
|
+
expect(sandbox.open).toEqual([]);
|
|
326
|
+
});
|
|
327
|
+
});
|