@openchamber/web 1.23.2 → 1.24.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/bin/cli.test.js +7 -6
- package/bin/lib/cli-http.js +5 -1
- package/dist/assets/{CodeMirrorCommentWidgets-DdNGwbBw.js → CodeMirrorCommentWidgets-DvUH815P.js} +1 -1
- package/dist/assets/DiffView-DkC3xlRJ.js +4 -0
- package/dist/assets/FilesView-D0bM9FVB.js +13 -0
- package/dist/assets/GitView-Bxuv3dfP.js +6 -0
- package/dist/assets/GuestAttachDialog-B0u3Q5uO.js +1 -0
- package/dist/assets/{JsonTreeView-Chzx5Y6N.js → JsonTreeView-BBVPFM5K.js} +1 -1
- package/dist/assets/LinearIssuesView-UI1FcSC8.js +1 -0
- package/dist/assets/{MarkdownImageGallery-CugnrZ6f.js → MarkdownImageGallery-CUJxH8Le.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-D5BZOg8X.js +12 -0
- package/dist/assets/{OnboardingScreen-hH9xcTjA.js → OnboardingScreen-5Gou9cGD.js} +1 -1
- package/dist/assets/{PatchDiff-DRgNYc9l.js → PatchDiff-C4rE5k6z.js} +1 -1
- package/dist/assets/{PierreDiffViewer-ZT2CKuzJ.js → PierreDiffViewer-ByRVu6ss.js} +5 -5
- package/dist/assets/PlanView-u2yi5XGJ.js +5 -0
- package/dist/assets/PluginPane-QxjsKYeO.js +3 -0
- package/dist/assets/SettingsView-Fo5ZqMaT.js +29 -0
- package/dist/assets/{SettingsWindow-DisOghhD.js → SettingsWindow-HVDVANjJ.js} +1 -1
- package/dist/assets/SubmoduleDiffSummary-D3hzkybB.js +1 -0
- package/dist/assets/ToolOutputDialog-3J6IRayW.js +15 -0
- package/dist/assets/{ToolPartDiffPreview-oWxWCu-4.js → ToolPartDiffPreview-DarxPjSd.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-CiyrAq_I.js → VirtualizedFileDiff-CZgXWHjU.js} +4 -4
- package/dist/assets/{WalkthroughView-CKTevaea.js → WalkthroughView-wSpED5L4.js} +2 -2
- package/dist/assets/appThemeRegistry-Cf8KitzT.js +1 -0
- package/dist/assets/commitAndPush-DZnzlhvc.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-SUWoTyPe.js → computeVirtualFileMetrics-VYnT_A2h.js} +1 -1
- package/dist/assets/de-BM_8EDD3.js +10 -0
- package/dist/assets/es-CxZjlqpo.js +16 -0
- package/dist/assets/fr-VCixCnMW.js +14 -0
- package/dist/assets/{index-C4jJ3Ur5.js → index-3U4CtS9b.js} +1 -1
- package/dist/assets/index-B9Hvzjwl.css +1 -0
- package/dist/assets/index-DLHQogv8.js +40 -0
- package/dist/assets/{isDiffPlainText-DfG0cZxr.js → isDiffPlainText-ImDG3Uhg.js} +1 -1
- package/dist/assets/{isFilePlainText-CyNivOCU.js → isFilePlainText-D_YDVYDb.js} +1 -1
- package/dist/assets/ja-CZ5k_GyD.js +16 -0
- package/dist/assets/ko-7YM3A1Xh.js +16 -0
- package/dist/assets/{main-B8cGozKr.js → main-CycplCph.js} +2 -2
- package/dist/assets/main-DFYTCx5o.js +896 -0
- package/dist/assets/{markdown-shiki.worker-D5fBU-lw.js → markdown-shiki.worker-CahLvHIq.js} +5 -5
- package/dist/assets/markdownCore-DHvqMxPn.js +5 -0
- package/dist/assets/{miniChat-Cay99IxR.js → miniChat-DIQKfY2V.js} +2 -2
- package/dist/assets/{mobile-Zfhix7nz.js → mobile-BMwz5q-m.js} +2 -2
- package/dist/assets/{patchFileDiff-CJ5AN9Ql.js → patchFileDiff-DDQ6Rq5e.js} +3 -3
- package/dist/assets/pl-BcgDO_w5.js +16 -0
- package/dist/assets/{pt-BR-CLosVawq.js → pt-BR-CU2u_1q5.js} +4 -4
- package/dist/assets/renderElectronMiniChatApp-3_d6g6CU.js +2 -0
- package/dist/assets/renderMobileApp-D0Y8DtkA.js +25 -0
- package/dist/assets/runtimeEndpointReset-DhC3REb2.js +25 -0
- package/dist/assets/{scheduledTasksApi-CGFV4Pap.js → scheduledTasksApi-D8pq6gQz.js} +1 -1
- package/dist/assets/shikiHighlight-1imXsir9.js +1 -0
- package/dist/assets/textMateThemeFromAppTheme-Dgqc63LZ.js +1 -0
- package/dist/assets/tr-DuYhOzNe.js +7 -0
- package/dist/assets/uk-Cuk7-uvq.js +16 -0
- package/dist/assets/useAppFontEffects-BItUWdo4.js +7333 -0
- package/dist/assets/useInlineCommentController-CkbKsm7m.js +2 -0
- package/dist/assets/useRootScrollLock-vmzxZjWA.js +2 -0
- package/dist/assets/{vendor-base-ui-BY_5qla_.js → vendor-base-ui-CsXYnR5c.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-ES33GhKK.js → vendor-codemirror-language-data-BDyxuqK4.js} +2 -2
- package/dist/assets/vendor-framer-motion-Bq3iTZ6r.js +1 -0
- package/dist/assets/{vendor-motion-dom-D_o3BTI3.js → vendor-motion-dom-DcCgeG69.js} +1 -1
- package/dist/assets/vendor-strip-json-comments-5dJlOkP1.js +4 -0
- package/dist/assets/{vendor-tanstack-react-virtual-g05Cx3z9.js → vendor-tanstack-react-virtual-ClYN8CzB.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-Dubg10g5.js → vendor-tanstack-virtual-core-BewVQryB.js} +1 -1
- package/dist/assets/{vendor-zod-B6551dwG.js → vendor-zod-fZppILAM.js} +4 -4
- package/dist/assets/{web-components-CJZwV5BE.js → web-components-D7FinaeH.js} +2 -2
- package/dist/assets/zh-CN-CUWoiRHd.js +16 -0
- package/dist/assets/zh-TW-CQ8EBSBN.js +16 -0
- package/dist/index.html +4 -4
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +9 -6
- package/server/built-in-extensions/registry.json +4 -0
- package/server/index.d.ts +2 -0
- package/server/index.js +41 -10
- package/server/lib/changelog/update-notes.js +2 -1
- package/server/lib/changelog/update-notes.test.js +19 -0
- package/server/lib/event-stream/DOCUMENTATION.md +23 -0
- package/server/lib/event-stream/delta-coalescer.js +0 -0
- package/server/lib/event-stream/delta-coalescer.test.js +292 -0
- package/server/lib/event-stream/global-hub.js +53 -23
- package/server/lib/event-stream/global-hub.test.js +160 -0
- package/server/lib/event-stream/global-ws-bridge.js +1 -0
- package/server/lib/event-stream/index.js +4 -0
- package/server/lib/fs/DOCUMENTATION.md +8 -0
- package/server/lib/fs/git-process.test.js +77 -0
- package/server/lib/fs/routes.js +2 -1
- package/server/lib/fs/search.js +2 -1
- package/server/lib/git/DOCUMENTATION.md +19 -4
- package/server/lib/git/routes.js +16 -3
- package/server/lib/git/serial-refresh.js +93 -0
- package/server/lib/git/serial-refresh.test.js +112 -0
- package/server/lib/git/service.js +336 -62
- package/server/lib/git/service.test.js +400 -0
- package/server/lib/github/pr-status.js +5 -5
- package/server/lib/github/pr-status.test.js +1 -1
- package/server/lib/github/routes.js +4 -4
- package/server/lib/guests/DOCUMENTATION.md +68 -0
- package/server/lib/guests/auth-store.js +184 -0
- package/server/lib/guests/auth-store.test.js +112 -0
- package/server/lib/guests/background.test.js +83 -0
- package/server/lib/guests/builtins.js +34 -0
- package/server/lib/guests/builtins.test.js +174 -0
- package/server/lib/guests/catalog.js +477 -0
- package/server/lib/guests/catalog.test.js +390 -0
- package/server/lib/guests/clone.js +297 -0
- package/server/lib/guests/extract-zip.js +136 -0
- package/server/lib/guests/extract-zip.test.js +109 -0
- package/server/lib/guests/files.js +308 -0
- package/server/lib/guests/files.test.js +262 -0
- package/server/lib/guests/grant-scope.js +81 -0
- package/server/lib/guests/grant-scope.test.js +75 -0
- package/server/lib/guests/host-session.js +73 -0
- package/server/lib/guests/host-session.test.js +30 -0
- package/server/lib/guests/html-styles.js +6 -0
- package/server/lib/guests/html-styles.test.js +45 -0
- package/server/lib/guests/html-tokens.js +73 -0
- package/server/lib/guests/html-tokens.test.js +53 -0
- package/server/lib/guests/install.js +406 -0
- package/server/lib/guests/install.test.js +338 -0
- package/server/lib/guests/oauth.js +501 -0
- package/server/lib/guests/oauth.test.js +481 -0
- package/server/lib/guests/persist.js +336 -0
- package/server/lib/guests/persist.test.js +288 -0
- package/server/lib/guests/request.js +112 -0
- package/server/lib/guests/request.test.js +206 -0
- package/server/lib/guests/routes.js +838 -0
- package/server/lib/guests/service.js +538 -0
- package/server/lib/guests/service.test.js +277 -0
- package/server/lib/guests/sockets.js +129 -0
- package/server/lib/guests/sockets.test.js +110 -0
- package/server/lib/guests/ssh-install.test.js +188 -0
- package/server/lib/guests/storage.js +68 -0
- package/server/lib/guests/storage.test.js +59 -0
- package/server/lib/guests/updates.js +294 -0
- package/server/lib/guests/updates.test.js +334 -0
- package/server/lib/guests/upload.js +50 -0
- package/server/lib/guests/upload.test.js +131 -0
- package/server/lib/linear/DOCUMENTATION.md +1 -1
- package/server/lib/message-queue/DOCUMENTATION.md +6 -0
- package/server/lib/message-queue/runtime.js +5 -0
- package/server/lib/message-queue/runtime.test.js +32 -1
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -0
- package/server/lib/openchamber-sessions/routes.js +44 -11
- package/server/lib/openchamber-sessions/routes.test.js +47 -0
- package/server/lib/opencode/DOCUMENTATION.md +40 -0
- package/server/lib/opencode/core-routes.js +39 -1
- package/server/lib/opencode/feature-routes-runtime.js +15 -0
- package/server/lib/opencode/lifecycle-process.test.js +84 -0
- package/server/lib/opencode/lifecycle.js +54 -67
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-normalization-runtime.js +2 -0
- package/server/lib/opencode/settings-normalization-runtime.test.js +13 -0
- package/server/lib/opencode/settings-registry.json +12 -0
- package/server/lib/opencode/shutdown-runtime.js +3 -0
- package/server/lib/opencode/shutdown-runtime.test.js +24 -0
- package/server/lib/opencode/theme-archive.js +53 -0
- package/server/lib/opencode/theme-catalog.js +171 -0
- package/server/lib/opencode/theme-catalog.test.js +125 -0
- package/server/lib/opencode/theme-import.test.js +144 -0
- package/server/lib/opencode/theme-runtime.js +100 -28
- package/server/lib/opencode/theme-runtime.test.js +15 -0
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +8 -0
- package/server/lib/permission-auto-accept/runtime.js +13 -0
- package/server/lib/permission-auto-accept/runtime.test.js +37 -1
- package/server/lib/quota/DOCUMENTATION.md +0 -1
- package/server/lib/quota/providers/index.js +0 -7
- package/server/lib/routing/DOCUMENTATION.md +81 -0
- package/server/lib/routing/defaults.js +98 -0
- package/server/lib/routing/feature-flag.js +11 -0
- package/server/lib/routing/history.js +34 -0
- package/server/lib/routing/jev.js +98 -0
- package/server/lib/routing/routes.http.test.js +100 -0
- package/server/lib/routing/routes.js +81 -0
- package/server/lib/routing/runtime.js +217 -0
- package/server/lib/routing/runtime.test.js +188 -0
- package/server/lib/routing/store.js +249 -0
- package/server/lib/routing/store.test.js +96 -0
- package/server/lib/security/request-security.js +9 -5
- package/server/lib/security/request-security.test.js +37 -0
- package/server/lib/terminal/DOCUMENTATION.md +2 -0
- package/server/lib/terminal/runtime.js +17 -2
- package/server/lib/terminal/runtime.test.js +45 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +8 -0
- package/server/lib/ui-auth/session-cookie.js +51 -0
- package/server/lib/ui-auth/session-cookie.test.js +46 -0
- package/server/lib/ui-auth/ui-auth.js +56 -17
- package/server/lib/ui-auth/ui-auth.test.js +96 -0
- package/dist/assets/DiffView-GYriC0Wk.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-Bv0C99hc.js +0 -1
- package/dist/assets/FilesView-2Lin13wx.js +0 -13
- package/dist/assets/GitView-9wKba3UO.js +0 -6
- package/dist/assets/LinearIssuesView-DXS9QJiR.js +0 -1
- package/dist/assets/MarkdownRendererImpl-CaMyct2Q.js +0 -12
- package/dist/assets/PlanView-DiTBm2BD.js +0 -5
- package/dist/assets/SettingsView-CN8VeM99.js +0 -28
- package/dist/assets/ToolOutputDialog-BqiKydxR.js +0 -15
- package/dist/assets/appThemeRegistry-BK0dHKa6.js +0 -1
- package/dist/assets/de-DQWC94VK.js +0 -10
- package/dist/assets/es-DixFUD3m.js +0 -16
- package/dist/assets/fr-D6u8tvfA.js +0 -14
- package/dist/assets/index-BvpFzhLs.js +0 -40
- package/dist/assets/index-n5p3SnES.css +0 -1
- package/dist/assets/ja-4u4pCorB.js +0 -16
- package/dist/assets/ko-C27-LW_b.js +0 -16
- package/dist/assets/main-tEA-fFPg.js +0 -930
- package/dist/assets/markdownCore-kyGrWGsn.js +0 -5
- package/dist/assets/pl-FtCjsNdW.js +0 -16
- package/dist/assets/registerCustomTheme-BBXUCRnG.js +0 -1
- package/dist/assets/renderElectronMiniChatApp-CuHOGlF4.js +0 -2
- package/dist/assets/renderMobileApp-C4X_KUH8.js +0 -25
- package/dist/assets/runtimeEndpointReset-CMg-KUx3.js +0 -41
- package/dist/assets/shikiHighlight-DdKWYWrV.js +0 -1
- package/dist/assets/tr-D2j6wUez.js +0 -7
- package/dist/assets/uk-C6IzmwM_.js +0 -16
- package/dist/assets/useAppFontEffects-DgCHy6Mr.js +0 -7282
- package/dist/assets/useGitComparison-BIaI0WZI.js +0 -1
- package/dist/assets/useInlineCommentController-2wcCtpM3.js +0 -2
- package/dist/assets/useRootScrollLock-CbWA03xR.js +0 -1
- package/dist/assets/vendor-framer-motion-livSKyyV.js +0 -1
- package/dist/assets/zh-CN-Wl6tIDz1.js +0 -16
- package/dist/assets/zh-TW-hgphoWSN.js +0 -16
- package/server/lib/quota/providers/crof.js +0 -96
- package/server/lib/quota/providers/crof.test.js +0 -98
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
|
|
3
|
+
import { createDeltaCoalescer, DELTA_COALESCE_WINDOW_MS, resolveDeltaCoalesceWindowMs } from './delta-coalescer.js';
|
|
4
|
+
|
|
5
|
+
let nextId = 0;
|
|
6
|
+
|
|
7
|
+
const delta = (partID, text, { messageID = 'msg_1', field = 'text', directory = '/repo', sessionID = 'ses_1' } = {}) => {
|
|
8
|
+
nextId += 1;
|
|
9
|
+
const id = String(nextId).padStart(6, '0');
|
|
10
|
+
const payload = { id, type: 'message.part.delta', properties: { sessionID, messageID, partID, field, delta: text } };
|
|
11
|
+
return { envelope: { eventId: id, directory, payload }, payload };
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const other = (type, properties = {}) => {
|
|
15
|
+
nextId += 1;
|
|
16
|
+
const id = String(nextId).padStart(6, '0');
|
|
17
|
+
const payload = { id, type, properties };
|
|
18
|
+
return { envelope: { eventId: id, directory: '/repo', payload }, payload };
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// A clock and timer queue the test advances by hand, so every assertion about
|
|
22
|
+
// the window is exact instead of racing a real timeout.
|
|
23
|
+
const createHarness = (options = {}) => {
|
|
24
|
+
let time = 1_000_000;
|
|
25
|
+
let timers = [];
|
|
26
|
+
let timerSeq = 0;
|
|
27
|
+
const emitted = [];
|
|
28
|
+
const coalescer = createDeltaCoalescer({
|
|
29
|
+
emit: (event) => emitted.push(event),
|
|
30
|
+
now: () => time,
|
|
31
|
+
setTimer: (callback, delay) => {
|
|
32
|
+
timerSeq += 1;
|
|
33
|
+
timers.push({ id: timerSeq, at: time + delay, callback });
|
|
34
|
+
return timerSeq;
|
|
35
|
+
},
|
|
36
|
+
clearTimer: (id) => {
|
|
37
|
+
timers = timers.filter((timer) => timer.id !== id);
|
|
38
|
+
},
|
|
39
|
+
...options,
|
|
40
|
+
});
|
|
41
|
+
const advance = (ms) => {
|
|
42
|
+
const target = time + ms;
|
|
43
|
+
for (;;) {
|
|
44
|
+
const due = timers.filter((timer) => timer.at <= target).sort((left, right) => left.at - right.at)[0];
|
|
45
|
+
if (!due) break;
|
|
46
|
+
timers = timers.filter((timer) => timer !== due);
|
|
47
|
+
time = due.at;
|
|
48
|
+
due.callback();
|
|
49
|
+
}
|
|
50
|
+
time = target;
|
|
51
|
+
};
|
|
52
|
+
return { coalescer, emitted, advance, pendingTimers: () => timers.length };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const isDelta = (event) => event.payload.type === 'message.part.delta';
|
|
56
|
+
const keyOf = (event) => `${event.payload.properties.messageID}:${event.payload.properties.partID}:${event.payload.properties.field}`;
|
|
57
|
+
|
|
58
|
+
const textByKey = (events) => {
|
|
59
|
+
const text = new Map();
|
|
60
|
+
for (const event of events) {
|
|
61
|
+
if (!isDelta(event)) continue;
|
|
62
|
+
text.set(keyOf(event), (text.get(keyOf(event)) ?? '') + event.payload.properties.delta);
|
|
63
|
+
}
|
|
64
|
+
return text;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
describe('delta coalescer', () => {
|
|
68
|
+
it('emits the first delta after a quiet spell at once and unchanged', () => {
|
|
69
|
+
const { coalescer, emitted } = createHarness();
|
|
70
|
+
const first = delta('prt_a', 'He');
|
|
71
|
+
|
|
72
|
+
coalescer.push(first);
|
|
73
|
+
|
|
74
|
+
expect(emitted).toEqual([first]);
|
|
75
|
+
expect(emitted[0]).toBe(first);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('merges following deltas for one part field and carries the last fragment id', () => {
|
|
79
|
+
const { coalescer, emitted, advance, pendingTimers } = createHarness();
|
|
80
|
+
const fragments = [delta('prt_a', 'He'), delta('prt_a', 'll'), delta('prt_a', 'o,'), delta('prt_a', ' wor'), delta('prt_a', 'ld')];
|
|
81
|
+
|
|
82
|
+
for (const fragment of fragments) coalescer.push(fragment);
|
|
83
|
+
expect(emitted).toHaveLength(1);
|
|
84
|
+
advance(50);
|
|
85
|
+
|
|
86
|
+
expect(emitted).toHaveLength(2);
|
|
87
|
+
expect(emitted[1].payload.properties).toEqual({ sessionID: 'ses_1', messageID: 'msg_1', partID: 'prt_a', field: 'text', delta: 'llo, world' });
|
|
88
|
+
expect(emitted[1].envelope.eventId).toBe(fragments[4].envelope.eventId);
|
|
89
|
+
expect(emitted[1].payload.id).toBe(fragments[4].payload.id);
|
|
90
|
+
expect(emitted[1].envelope.payload).toBe(emitted[1].payload);
|
|
91
|
+
expect(pendingTimers()).toBe(0);
|
|
92
|
+
// Upstream objects are never mutated: other hub subscribers may hold them.
|
|
93
|
+
expect(fragments.map((fragment) => fragment.payload.properties.delta)).toEqual(['He', 'll', 'o,', ' wor', 'ld']);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('never holds text longer than the window', () => {
|
|
97
|
+
const { coalescer, emitted, advance } = createHarness();
|
|
98
|
+
coalescer.push(delta('prt_a', 'a'));
|
|
99
|
+
coalescer.push(delta('prt_a', 'b'));
|
|
100
|
+
|
|
101
|
+
advance(49);
|
|
102
|
+
expect(emitted).toHaveLength(1);
|
|
103
|
+
advance(1);
|
|
104
|
+
expect(emitted).toHaveLength(2);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('treats every other event as a barrier, so a delta never crosses a part snapshot', () => {
|
|
108
|
+
const { coalescer, emitted, advance } = createHarness();
|
|
109
|
+
const snapshot = other('message.part.updated', { part: { id: 'prt_a', messageID: 'msg_1', text: 'abc' } });
|
|
110
|
+
|
|
111
|
+
coalescer.push(delta('prt_a', 'a'));
|
|
112
|
+
coalescer.push(delta('prt_a', 'b'));
|
|
113
|
+
coalescer.push(delta('prt_a', 'c'));
|
|
114
|
+
coalescer.push(snapshot);
|
|
115
|
+
coalescer.push(delta('prt_a', 'd'));
|
|
116
|
+
coalescer.push(delta('prt_a', 'e'));
|
|
117
|
+
advance(50);
|
|
118
|
+
|
|
119
|
+
expect(emitted.map((event) => (isDelta(event) ? event.payload.properties.delta : event.payload.type)))
|
|
120
|
+
.toEqual(['a', 'bc', 'message.part.updated', 'de']);
|
|
121
|
+
expect(emitted[2]).toBe(snapshot);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('keeps several part fields pending at once and emits them in upstream id order', () => {
|
|
125
|
+
const { coalescer, emitted, advance } = createHarness();
|
|
126
|
+
coalescer.push(delta('prt_lead', '.'));
|
|
127
|
+
|
|
128
|
+
coalescer.push(delta('prt_a', 'a1'));
|
|
129
|
+
coalescer.push(delta('prt_b', 'b1', { messageID: 'msg_2', sessionID: 'ses_2' }));
|
|
130
|
+
coalescer.push(delta('prt_a', 'a2'));
|
|
131
|
+
const lastB = delta('prt_b', 'b2', { messageID: 'msg_2', sessionID: 'ses_2' });
|
|
132
|
+
coalescer.push(lastB);
|
|
133
|
+
advance(50);
|
|
134
|
+
|
|
135
|
+
const merged = emitted.slice(1);
|
|
136
|
+
expect(merged.map((event) => event.payload.properties.delta)).toEqual(['a1a2', 'b1b2']);
|
|
137
|
+
expect(merged[1].envelope.eventId).toBe(lastB.envelope.eventId);
|
|
138
|
+
const ids = emitted.map((event) => event.envelope.eventId);
|
|
139
|
+
expect(ids).toEqual([...ids].sort());
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('does not merge the same part across directories, sessions, messages, or fields', () => {
|
|
143
|
+
const { coalescer, emitted, advance } = createHarness();
|
|
144
|
+
coalescer.push(delta('prt_lead', '.'));
|
|
145
|
+
|
|
146
|
+
coalescer.push(delta('prt_a', '1'));
|
|
147
|
+
coalescer.push(delta('prt_a', '2', { directory: '/other' }));
|
|
148
|
+
coalescer.push(delta('prt_a', '3', { messageID: 'msg_2' }));
|
|
149
|
+
coalescer.push(delta('prt_a', '4', { field: 'reasoning' }));
|
|
150
|
+
coalescer.push(delta('prt_a', '5', { sessionID: 'ses_2' }));
|
|
151
|
+
advance(50);
|
|
152
|
+
|
|
153
|
+
expect(emitted.slice(1).map((event) => event.payload.properties.delta)).toEqual(['1', '2', '3', '4', '5']);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it('bounds pending text by characters and by part fields, emitting early instead of dropping', () => {
|
|
157
|
+
const { coalescer, emitted } = createHarness({ maxPendingChars: 10, maxPendingKeys: 3 });
|
|
158
|
+
coalescer.push(delta('prt_lead', '.'));
|
|
159
|
+
|
|
160
|
+
let peakChars = 0;
|
|
161
|
+
for (let index = 0; index < 40; index += 1) {
|
|
162
|
+
coalescer.push(delta('prt_a', 'xyz'));
|
|
163
|
+
peakChars = Math.max(peakChars, coalescer.pendingSize().chars);
|
|
164
|
+
}
|
|
165
|
+
expect(peakChars).toBeLessThan(10 + 3);
|
|
166
|
+
expect(textByKey(emitted).get('msg_1:prt_a:text')).toBe('xyz'.repeat(40));
|
|
167
|
+
|
|
168
|
+
let peakKeys = 0;
|
|
169
|
+
for (let index = 0; index < 20; index += 1) {
|
|
170
|
+
coalescer.push(delta(`prt_k${index}`, 'k'));
|
|
171
|
+
peakKeys = Math.max(peakKeys, coalescer.pendingSize().keys);
|
|
172
|
+
}
|
|
173
|
+
expect(peakKeys).toBeLessThanOrEqual(3);
|
|
174
|
+
coalescer.flush();
|
|
175
|
+
expect(emitted.filter((event) => event.payload.properties.delta === 'k')).toHaveLength(20);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it('flushes on demand and leaves nothing pending', () => {
|
|
179
|
+
const { coalescer, emitted, pendingTimers } = createHarness();
|
|
180
|
+
coalescer.push(delta('prt_a', 'a'));
|
|
181
|
+
coalescer.push(delta('prt_a', 'b'));
|
|
182
|
+
|
|
183
|
+
coalescer.flush();
|
|
184
|
+
|
|
185
|
+
expect(emitted.map((event) => event.payload.properties.delta)).toEqual(['a', 'b']);
|
|
186
|
+
expect(coalescer.pendingSize()).toEqual({ keys: 0, chars: 0 });
|
|
187
|
+
expect(pendingTimers()).toBe(0);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('passes a malformed delta through as a barrier instead of guessing', () => {
|
|
191
|
+
const { coalescer, emitted } = createHarness();
|
|
192
|
+
const malformed = other('message.part.delta', { messageID: 'msg_1', partID: 'prt_a', field: 'text', delta: 42 });
|
|
193
|
+
|
|
194
|
+
coalescer.push(delta('prt_a', 'a'));
|
|
195
|
+
coalescer.push(delta('prt_a', 'b'));
|
|
196
|
+
coalescer.push(malformed);
|
|
197
|
+
|
|
198
|
+
expect(emitted.map((event) => event.payload.properties.delta)).toEqual(['a', 'b', 42]);
|
|
199
|
+
expect(emitted[2]).toBe(malformed);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('is a pass-through when the window is zero', () => {
|
|
203
|
+
const { coalescer, emitted } = createHarness({ windowMs: 0 });
|
|
204
|
+
const events = [delta('prt_a', 'a'), delta('prt_a', 'b'), delta('prt_a', 'c')];
|
|
205
|
+
|
|
206
|
+
for (const event of events) coalescer.push(event);
|
|
207
|
+
|
|
208
|
+
expect(emitted).toEqual(events);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
// The properties that make coalescing safe, checked over arbitrary streams
|
|
212
|
+
// rather than the handful of shapes someone thought of.
|
|
213
|
+
it('loses, duplicates, and reorders nothing across randomized streams', () => {
|
|
214
|
+
let seed = 0x5eed;
|
|
215
|
+
const random = () => {
|
|
216
|
+
seed = (seed * 1664525 + 1013904223) % 4294967296;
|
|
217
|
+
return seed / 4294967296;
|
|
218
|
+
};
|
|
219
|
+
|
|
220
|
+
for (let round = 0; round < 40; round += 1) {
|
|
221
|
+
const { coalescer, emitted, advance } = createHarness({ maxPendingChars: 200, maxPendingKeys: 4 });
|
|
222
|
+
const raw = [];
|
|
223
|
+
const partCount = 1 + Math.floor(random() * 6);
|
|
224
|
+
for (let index = 0; index < 600; index += 1) {
|
|
225
|
+
const roll = random();
|
|
226
|
+
let event;
|
|
227
|
+
if (roll < 0.9) {
|
|
228
|
+
const part = Math.floor(random() * partCount);
|
|
229
|
+
event = delta(`prt_${part}`, `${index}|`.repeat(1 + Math.floor(random() * 3)), { messageID: `msg_${part % 2}` });
|
|
230
|
+
} else if (roll < 0.95) {
|
|
231
|
+
event = other('message.part.updated', { part: { id: `prt_${Math.floor(random() * partCount)}`, messageID: 'msg_0' } });
|
|
232
|
+
} else {
|
|
233
|
+
event = other('session.status', { sessionID: 'ses_1', status: { type: 'busy' } });
|
|
234
|
+
}
|
|
235
|
+
raw.push(event);
|
|
236
|
+
coalescer.push(event);
|
|
237
|
+
if (random() < 0.3) advance(Math.floor(random() * 80));
|
|
238
|
+
}
|
|
239
|
+
advance(1_000);
|
|
240
|
+
|
|
241
|
+
// Nothing lost or duplicated: every part field ends with the same text.
|
|
242
|
+
expect(textByKey(emitted)).toEqual(textByKey(raw));
|
|
243
|
+
|
|
244
|
+
// Every other event is delivered once, as the same object, in order.
|
|
245
|
+
expect(emitted.filter((event) => !isDelta(event))).toEqual(raw.filter((event) => !isDelta(event)));
|
|
246
|
+
|
|
247
|
+
// Barrier: the text delivered before each barrier is exactly the text
|
|
248
|
+
// that arrived before it.
|
|
249
|
+
for (const barrier of raw.filter((event) => !isDelta(event))) {
|
|
250
|
+
expect(textByKey(emitted.slice(0, emitted.indexOf(barrier)))).toEqual(textByKey(raw.slice(0, raw.indexOf(barrier))));
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Replay cursors: ids stay unique and in upstream order.
|
|
254
|
+
const ids = emitted.map((event) => event.envelope.eventId);
|
|
255
|
+
expect(new Set(ids).size).toBe(ids.length);
|
|
256
|
+
expect(ids).toEqual([...ids].sort());
|
|
257
|
+
|
|
258
|
+
expect(coalescer.pendingSize()).toEqual({ keys: 0, chars: 0 });
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
it('collapses a dense single-part stream to a few frames per window', () => {
|
|
263
|
+
const { coalescer, emitted, advance } = createHarness();
|
|
264
|
+
|
|
265
|
+
// 150 fragments a second for two seconds, the rate measured from OpenCode.
|
|
266
|
+
for (let index = 0; index < 300; index += 1) {
|
|
267
|
+
coalescer.push(delta('prt_a', 'ab'));
|
|
268
|
+
advance(index % 3 === 2 ? 8 : 6);
|
|
269
|
+
}
|
|
270
|
+
advance(50);
|
|
271
|
+
|
|
272
|
+
expect(textByKey(emitted).get('msg_1:prt_a:text')).toBe('ab'.repeat(300));
|
|
273
|
+
expect(emitted.length).toBeLessThanOrEqual(45);
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
describe('resolveDeltaCoalesceWindowMs', () => {
|
|
278
|
+
it('uses the default when unset and accepts zero as off', () => {
|
|
279
|
+
expect(resolveDeltaCoalesceWindowMs({})).toBe(DELTA_COALESCE_WINDOW_MS);
|
|
280
|
+
expect(resolveDeltaCoalesceWindowMs({ OPENCHAMBER_EVENT_DELTA_COALESCE_MS: ' ' })).toBe(DELTA_COALESCE_WINDOW_MS);
|
|
281
|
+
expect(resolveDeltaCoalesceWindowMs({ OPENCHAMBER_EVENT_DELTA_COALESCE_MS: '0' })).toBe(0);
|
|
282
|
+
expect(resolveDeltaCoalesceWindowMs({ OPENCHAMBER_EVENT_DELTA_COALESCE_MS: '25' })).toBe(25);
|
|
283
|
+
});
|
|
284
|
+
|
|
285
|
+
it('keeps the default and says so for anything that is not 0-1000 whole milliseconds', () => {
|
|
286
|
+
for (const value of ['-1', '1001', '12.5', 'fast', 'NaN', '1e9']) {
|
|
287
|
+
const warnings = [];
|
|
288
|
+
expect(resolveDeltaCoalesceWindowMs({ OPENCHAMBER_EVENT_DELTA_COALESCE_MS: value }, (message) => warnings.push(message))).toBe(DELTA_COALESCE_WINDOW_MS);
|
|
289
|
+
expect(warnings).toHaveLength(1);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
|
|
1
3
|
import { createUpstreamSseReader } from './upstream-reader.js';
|
|
2
4
|
import { serializeMessageStreamWsEvent } from './protocol.js';
|
|
5
|
+
import { createDeltaCoalescer, DELTA_COALESCE_WINDOW_MS } from './delta-coalescer.js';
|
|
3
6
|
|
|
4
7
|
// Raised from 512 → 2048 to improve recovery after brief disconnects during
|
|
5
8
|
// long-running agent sessions where many events accumulate quickly.
|
|
@@ -14,6 +17,7 @@ export function createGlobalMessageStreamHub({
|
|
|
14
17
|
upstreamReconnectDelayMs,
|
|
15
18
|
replayLimit = MESSAGE_STREAM_GLOBAL_REPLAY_LIMIT,
|
|
16
19
|
replayByteLimit = MESSAGE_STREAM_GLOBAL_REPLAY_BYTES,
|
|
20
|
+
deltaCoalesceWindowMs = DELTA_COALESCE_WINDOW_MS,
|
|
17
21
|
}) {
|
|
18
22
|
if (!Number.isSafeInteger(replayLimit) || replayLimit < 0 || !Number.isSafeInteger(replayByteLimit) || replayByteLimit < 0) {
|
|
19
23
|
throw new RangeError('Replay limits must be nonnegative safe integers');
|
|
@@ -23,6 +27,15 @@ export function createGlobalMessageStreamHub({
|
|
|
23
27
|
const replay = [];
|
|
24
28
|
let replayBytes = 0;
|
|
25
29
|
let latestEventId;
|
|
30
|
+
// OpenCode's event stream carries no SSE ids (verified on 1.18.30: not one
|
|
31
|
+
// frame in a full response), and an event without an id never entered the
|
|
32
|
+
// replay buffer, so a reconnecting browser had no cursor and every event in
|
|
33
|
+
// the gap was gone. The replay log is this hub's own, so the hub numbers
|
|
34
|
+
// what upstream leaves unnumbered. The per-process prefix makes a cursor
|
|
35
|
+
// from before a restart miss instead of matching an unrelated sequence
|
|
36
|
+
// number, which reports `replayReset` and sends the client to repair.
|
|
37
|
+
const replayIdPrefix = `oc-${randomUUID().slice(0, 8)}-`;
|
|
38
|
+
let replaySequence = 0;
|
|
26
39
|
|
|
27
40
|
let controller = null;
|
|
28
41
|
let reader = null;
|
|
@@ -52,7 +65,9 @@ export function createGlobalMessageStreamHub({
|
|
|
52
65
|
const normalizeEvent = ({ envelope, payload }) => {
|
|
53
66
|
const directory =
|
|
54
67
|
typeof envelope?.directory === 'string' && envelope.directory.length > 0 ? envelope.directory : 'global';
|
|
55
|
-
const eventId = typeof envelope?.eventId === 'string' && envelope.eventId.length > 0
|
|
68
|
+
const eventId = typeof envelope?.eventId === 'string' && envelope.eventId.length > 0
|
|
69
|
+
? envelope.eventId
|
|
70
|
+
: `${replayIdPrefix}${String(++replaySequence).padStart(12, '0')}`;
|
|
56
71
|
let serializedFrame;
|
|
57
72
|
return {
|
|
58
73
|
envelope,
|
|
@@ -66,6 +81,34 @@ export function createGlobalMessageStreamHub({
|
|
|
66
81
|
};
|
|
67
82
|
};
|
|
68
83
|
|
|
84
|
+
// Replay and fan-out see the same committed sequence: an event enters the
|
|
85
|
+
// replay buffer in the same step that delivers it, so a client's cursor
|
|
86
|
+
// always names a frame the buffer can find.
|
|
87
|
+
const commitEvent = (event) => {
|
|
88
|
+
const normalized = normalizeEvent(event);
|
|
89
|
+
latestEventId = normalized.eventId;
|
|
90
|
+
const serializedFrame = normalized.serialize();
|
|
91
|
+
const bytes = Buffer.byteLength(serializedFrame);
|
|
92
|
+
if (bytes > replayByteLimit) {
|
|
93
|
+
// An oversized live event creates a hole: retain only a contiguous
|
|
94
|
+
// suffix after it, never replay an older prefix across the gap.
|
|
95
|
+
replay.length = 0;
|
|
96
|
+
replayBytes = 0;
|
|
97
|
+
} else {
|
|
98
|
+
replay.push({ eventId: normalized.eventId, serializedFrame, bytes });
|
|
99
|
+
replayBytes += bytes;
|
|
100
|
+
while (replay.length > replayLimit || replayBytes > replayByteLimit) {
|
|
101
|
+
replayBytes -= replay.shift().bytes;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
for (const subscriber of Array.from(eventSubscribers)) {
|
|
106
|
+
notifySubscriber('event', subscriber, normalized);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const coalescer = createDeltaCoalescer({ emit: commitEvent, windowMs: deltaCoalesceWindowMs });
|
|
111
|
+
|
|
69
112
|
const start = () => {
|
|
70
113
|
if (reader) {
|
|
71
114
|
return;
|
|
@@ -98,28 +141,7 @@ export function createGlobalMessageStreamHub({
|
|
|
98
141
|
notifyStatus({ type: 'disconnect', reason });
|
|
99
142
|
},
|
|
100
143
|
onEvent(event) {
|
|
101
|
-
|
|
102
|
-
if (normalized.eventId) {
|
|
103
|
-
latestEventId = normalized.eventId;
|
|
104
|
-
const serializedFrame = normalized.serialize();
|
|
105
|
-
const bytes = Buffer.byteLength(serializedFrame);
|
|
106
|
-
if (bytes > replayByteLimit) {
|
|
107
|
-
// An oversized live event creates a hole: retain only a contiguous
|
|
108
|
-
// suffix after it, never replay an older prefix across the gap.
|
|
109
|
-
replay.length = 0;
|
|
110
|
-
replayBytes = 0;
|
|
111
|
-
} else {
|
|
112
|
-
replay.push({ eventId: normalized.eventId, serializedFrame, bytes });
|
|
113
|
-
replayBytes += bytes;
|
|
114
|
-
while (replay.length > replayLimit || replayBytes > replayByteLimit) {
|
|
115
|
-
replayBytes -= replay.shift().bytes;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
for (const subscriber of Array.from(eventSubscribers)) {
|
|
121
|
-
notifySubscriber('event', subscriber, normalized);
|
|
122
|
-
}
|
|
144
|
+
coalescer.push(event);
|
|
123
145
|
},
|
|
124
146
|
onError(error) {
|
|
125
147
|
if (controller?.signal.aborted) {
|
|
@@ -139,6 +161,8 @@ export function createGlobalMessageStreamHub({
|
|
|
139
161
|
|
|
140
162
|
const stop = () => {
|
|
141
163
|
connected = false;
|
|
164
|
+
// Text that already arrived belongs in the retained replay suffix.
|
|
165
|
+
coalescer.flush();
|
|
142
166
|
reader?.stop();
|
|
143
167
|
if (controller && !controller.signal.aborted) {
|
|
144
168
|
controller.abort();
|
|
@@ -170,6 +194,12 @@ export function createGlobalMessageStreamHub({
|
|
|
170
194
|
statusSubscribers.delete(subscriber);
|
|
171
195
|
};
|
|
172
196
|
},
|
|
197
|
+
// A client that becomes ready must not receive text from before it was
|
|
198
|
+
// ready merged into its first live delta, so the bridge commits pending
|
|
199
|
+
// deltas before it reads the replay tail.
|
|
200
|
+
flushPending() {
|
|
201
|
+
coalescer.flush();
|
|
202
|
+
},
|
|
173
203
|
replayAfter(eventId) {
|
|
174
204
|
if (!eventId) {
|
|
175
205
|
return [];
|
|
@@ -62,6 +62,166 @@ async function waitForAssertion(assertion) {
|
|
|
62
62
|
throw lastError;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
const deltaBlock = (id, text, partID = 'prt_a') => `id: ${id}\ndata: ${JSON.stringify({
|
|
66
|
+
id, type: 'message.part.delta',
|
|
67
|
+
properties: { sessionID: 'ses_1', messageID: 'msg_1', partID, field: 'text', delta: text },
|
|
68
|
+
})}\n\n`;
|
|
69
|
+
|
|
70
|
+
const createDeltaHub = ({ blocks, deltaCoalesceWindowMs }) => createGlobalMessageStreamHub({
|
|
71
|
+
buildOpenCodeUrl: (pathname) => `http://127.0.0.1:4096${pathname}`,
|
|
72
|
+
getOpenCodeAuthHeaders: () => ({}),
|
|
73
|
+
upstreamReconnectDelayMs: 60_000,
|
|
74
|
+
deltaCoalesceWindowMs,
|
|
75
|
+
fetchImpl: async () => createSseResponse({ blocks }),
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// What a browser holds after applying frames in order: text per part, and the
|
|
79
|
+
// text each part had when a snapshot barrier passed.
|
|
80
|
+
const applyFrames = (frames) => {
|
|
81
|
+
const text = {};
|
|
82
|
+
const barriers = [];
|
|
83
|
+
for (const frame of frames) {
|
|
84
|
+
const payload = frame.payload;
|
|
85
|
+
if (payload.type === 'message.part.delta') {
|
|
86
|
+
text[payload.properties.partID] = (text[payload.properties.partID] ?? '') + payload.properties.delta;
|
|
87
|
+
} else {
|
|
88
|
+
barriers.push({ id: payload.id, seen: { ...text } });
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { text, barriers };
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
describe('delta coalescing in the global hub', () => {
|
|
95
|
+
it('delivers the same text in far fewer frames', async () => {
|
|
96
|
+
const words = Array.from({ length: 120 }, (_, index) => `w${index} `);
|
|
97
|
+
const hub = createDeltaHub({ blocks: words.map((word, index) => deltaBlock(`e${String(index).padStart(4, '0')}`, word)) });
|
|
98
|
+
const received = [];
|
|
99
|
+
hub.subscribeEvent((event) => received.push(event));
|
|
100
|
+
try {
|
|
101
|
+
hub.start();
|
|
102
|
+
await waitForAssertion(() => expect(applyFrames(received).text.prt_a).toBe(words.join('')));
|
|
103
|
+
expect(received.length).toBeLessThanOrEqual(3);
|
|
104
|
+
expect(received.at(-1).eventId).toBe('e0119');
|
|
105
|
+
} finally { hub.stop(); }
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('resumes from any cursor without losing or repeating text', async () => {
|
|
109
|
+
const blocks = [];
|
|
110
|
+
let id = 0;
|
|
111
|
+
const nextId = () => `e${String(id++).padStart(4, '0')}`;
|
|
112
|
+
for (let index = 0; index < 40; index += 1) blocks.push(deltaBlock(nextId(), `a${index}.`, index % 3 === 0 ? 'prt_b' : 'prt_a'));
|
|
113
|
+
const snapshotId = nextId();
|
|
114
|
+
blocks.push(`id: ${snapshotId}\ndata: ${JSON.stringify({ id: snapshotId, type: 'message.part.updated', properties: { part: { id: 'prt_a', messageID: 'msg_1' } } })}\n\n`);
|
|
115
|
+
for (let index = 0; index < 40; index += 1) blocks.push(deltaBlock(nextId(), `b${index}.`));
|
|
116
|
+
|
|
117
|
+
const hub = createDeltaHub({ blocks });
|
|
118
|
+
const received = [];
|
|
119
|
+
hub.subscribeEvent((event) => received.push(event));
|
|
120
|
+
try {
|
|
121
|
+
hub.start();
|
|
122
|
+
const expectedA = [...Array(40).keys()].filter((index) => index % 3 !== 0).map((index) => `a${index}.`).join('')
|
|
123
|
+
+ [...Array(40).keys()].map((index) => `b${index}.`).join('');
|
|
124
|
+
await waitForAssertion(() => expect(applyFrames(received).text.prt_a).toBe(expectedA));
|
|
125
|
+
expect(received.length).toBeLessThan(blocks.length / 4);
|
|
126
|
+
|
|
127
|
+
const complete = applyFrames(received);
|
|
128
|
+
// The snapshot barrier saw exactly the text that arrived before it.
|
|
129
|
+
expect(complete.barriers).toHaveLength(1);
|
|
130
|
+
expect(complete.barriers[0].seen.prt_a).toBe([...Array(40).keys()].filter((index) => index % 3 !== 0).map((index) => `a${index}.`).join(''));
|
|
131
|
+
|
|
132
|
+
// A socket that drops after any frame reconnects with that frame's id.
|
|
133
|
+
for (let cut = 0; cut < received.length; cut += 1) {
|
|
134
|
+
const tail = hub.replayAfter(received[cut].eventId);
|
|
135
|
+
expect(tail).not.toBeNull();
|
|
136
|
+
const replayed = tail.map((entry) => JSON.parse(entry.serializedFrame));
|
|
137
|
+
expect(applyFrames([...received.slice(0, cut + 1), ...replayed])).toEqual(complete);
|
|
138
|
+
}
|
|
139
|
+
} finally { hub.stop(); }
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// OpenCode 1.18 sends no SSE ids at all. Before the hub numbered such events
|
|
143
|
+
// itself the replay buffer stayed empty and every reconnect lost its gap.
|
|
144
|
+
it('numbers id-less upstream events so a reconnect resumes from any cursor', async () => {
|
|
145
|
+
const idless = (type, properties) => `data: ${JSON.stringify({ type, properties })}\n\n`;
|
|
146
|
+
const blocks = [];
|
|
147
|
+
for (let index = 0; index < 30; index += 1) {
|
|
148
|
+
blocks.push(idless('message.part.delta', { sessionID: 'ses_1', messageID: 'msg_1', partID: 'prt_a', field: 'text', delta: `a${index}.` }));
|
|
149
|
+
}
|
|
150
|
+
blocks.push(idless('message.part.updated', { part: { id: 'prt_a', messageID: 'msg_1' } }));
|
|
151
|
+
for (let index = 0; index < 30; index += 1) {
|
|
152
|
+
blocks.push(idless('message.part.delta', { sessionID: 'ses_1', messageID: 'msg_1', partID: 'prt_a', field: 'text', delta: `b${index}.` }));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const hub = createDeltaHub({ blocks });
|
|
156
|
+
const received = [];
|
|
157
|
+
hub.subscribeEvent((event) => received.push(event));
|
|
158
|
+
try {
|
|
159
|
+
hub.start();
|
|
160
|
+
const expected = [...Array(30).keys()].map((index) => `a${index}.`).join('') + [...Array(30).keys()].map((index) => `b${index}.`).join('');
|
|
161
|
+
await waitForAssertion(() => expect(applyFrames(received).text.prt_a).toBe(expected));
|
|
162
|
+
|
|
163
|
+
const ids = received.map((event) => event.eventId);
|
|
164
|
+
expect(ids.every((eventId) => typeof eventId === 'string' && eventId.length > 0)).toBe(true);
|
|
165
|
+
expect(new Set(ids).size).toBe(ids.length);
|
|
166
|
+
expect(ids).toEqual([...ids].sort());
|
|
167
|
+
|
|
168
|
+
const complete = applyFrames(received);
|
|
169
|
+
for (let cut = 0; cut < received.length; cut += 1) {
|
|
170
|
+
const tail = hub.replayAfter(received[cut].eventId);
|
|
171
|
+
expect(tail).not.toBeNull();
|
|
172
|
+
const replayed = tail.map((entry) => JSON.parse(entry.serializedFrame));
|
|
173
|
+
expect(replayed.every((frame) => typeof frame.eventId === 'string')).toBe(true);
|
|
174
|
+
expect(applyFrames([...received.slice(0, cut + 1), ...replayed])).toEqual(complete);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// A cursor minted by another server process must miss, never match by
|
|
178
|
+
// sequence number: the bridge then reports replayReset and the client
|
|
179
|
+
// repairs from HTTP instead of trusting a wrong tail.
|
|
180
|
+
const foreign = ids[0].replace(/^oc-[^-]+-/, 'oc-00000000-');
|
|
181
|
+
expect(foreign).not.toBe(ids[0]);
|
|
182
|
+
expect(hub.replayAfter(foreign)).toBeNull();
|
|
183
|
+
} finally { hub.stop(); }
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('keeps pending text for replay when the hub stops', async () => {
|
|
187
|
+
const hub = createDeltaHub({
|
|
188
|
+
deltaCoalesceWindowMs: 60_000,
|
|
189
|
+
blocks: ['one ', 'two ', 'three'].map((text, index) => deltaBlock(`e${index}`, text)),
|
|
190
|
+
});
|
|
191
|
+
const received = [];
|
|
192
|
+
hub.subscribeEvent((event) => received.push(event));
|
|
193
|
+
hub.start();
|
|
194
|
+
// The window is a minute, so only the leading delta has been delivered.
|
|
195
|
+
await waitForAssertion(() => expect(received).toHaveLength(1));
|
|
196
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
197
|
+
|
|
198
|
+
hub.stop();
|
|
199
|
+
|
|
200
|
+
const tail = hub.replayAfter('e0').map((entry) => JSON.parse(entry.serializedFrame));
|
|
201
|
+
expect(applyFrames(tail).text.prt_a).toBe('two three');
|
|
202
|
+
expect(tail.at(-1).eventId).toBe('e2');
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
it('commits pending text on demand, so a client readied later starts after it', async () => {
|
|
206
|
+
const hub = createDeltaHub({
|
|
207
|
+
deltaCoalesceWindowMs: 60_000,
|
|
208
|
+
blocks: ['one ', 'two ', 'three'].map((text, index) => deltaBlock(`e${index}`, text)),
|
|
209
|
+
});
|
|
210
|
+
const received = [];
|
|
211
|
+
hub.subscribeEvent((event) => received.push(event));
|
|
212
|
+
try {
|
|
213
|
+
hub.start();
|
|
214
|
+
await waitForAssertion(() => expect(received).toHaveLength(1));
|
|
215
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
216
|
+
|
|
217
|
+
hub.flushPending();
|
|
218
|
+
|
|
219
|
+
expect(applyFrames(received).text.prt_a).toBe('one two three');
|
|
220
|
+
expect(hub.replayAfter('e2')).toEqual([]);
|
|
221
|
+
} finally { hub.stop(); }
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
65
225
|
describe('createGlobalMessageStreamHub', () => {
|
|
66
226
|
it('continues fanout when an event subscriber throws', async () => {
|
|
67
227
|
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
@@ -46,6 +46,7 @@ export function createGlobalMessageStreamWsBridge({
|
|
|
46
46
|
return;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
globalHub.flushPending();
|
|
49
50
|
const replay = globalHub.replayAfter(requestedLastEventId);
|
|
50
51
|
const ready = { type: 'ready', scope: 'global' };
|
|
51
52
|
if (replay === null) ready.replayReset = true;
|
|
@@ -36,6 +36,14 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
|
|
|
36
36
|
- Returns `{ searchFilesystemFiles(rootPath, options) }`.
|
|
37
37
|
- Supports fuzzy matching, hidden-file handling, and optional `git check-ignore` filtering.
|
|
38
38
|
|
|
39
|
+
Both search and directory listing discard `git check-ignore` stderr at spawn.
|
|
40
|
+
They consume stdout for ignore matches. Never create an unread stderr pipe:
|
|
41
|
+
Git diagnostics can fill it and block the child indefinitely, so repeated
|
|
42
|
+
searches accumulate live Git processes. `git-process.test.js` exercises both
|
|
43
|
+
paths with real OS pipes, twelve concurrent checks, and 2 MiB of diagnostics
|
|
44
|
+
per child. Successful completion must preserve ignore filtering and reap all
|
|
45
|
+
twelve children.
|
|
46
|
+
|
|
39
47
|
## Composition contract with `index.js`
|
|
40
48
|
- `index.js` provides composition-time dependencies only (platform primitives + callbacks such as `resolveProjectDirectory`, `normalizeDirectoryPath`, and `buildAugmentedPath`).
|
|
41
49
|
- `index.js` no longer owns FS route handlers or FS exec job state.
|