@openchamber/web 2.0.0 → 2.0.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/{CodeMirrorCommentWidgets-hJbl3JX4.js → CodeMirrorCommentWidgets-CmKmyb9T.js} +1 -1
- package/dist/assets/DiffView-8-PFpZ2p.js +4 -0
- package/dist/assets/FilesView-0Ie20mEk.js +17 -0
- package/dist/assets/{GitView-DY4pelsO.js → GitView-DNUSu00w.js} +4 -4
- package/dist/assets/{GuestAttachDialog-D6mHDTB2.js → GuestAttachDialog-Cv6QzjHC.js} +1 -1
- package/dist/assets/GuestSurfacePane-Bt3jB_Ye.js +1 -0
- package/dist/assets/{JsonTreeView-DEXI2NvJ.js → JsonTreeView-BlyHTRhM.js} +1 -1
- package/dist/assets/{LinearIssuesView-BTNc-4dN.js → LinearIssuesView-CSl2MUfA.js} +1 -1
- package/dist/assets/MarkdownImageGallery-2UXJF-5B.js +1 -0
- package/dist/assets/MarkdownRendererImpl-DVHqZoug.js +12 -0
- package/dist/assets/{OnboardingScreen-FJUreEgI.js → OnboardingScreen-CIdXJpfc.js} +1 -1
- package/dist/assets/{PatchDiff-C0oOkKnO.js → PatchDiff-ByvnbG5T.js} +1 -1
- package/dist/assets/{PierreDiffViewer-asuSQAsf.js → PierreDiffViewer-BXieg0mH.js} +3 -3
- package/dist/assets/{PlanView-DGbasNHP.js → PlanView-DEIi3Q7M.js} +4 -4
- package/dist/assets/PluginPane-BEPUWVho.js +3 -0
- package/dist/assets/SettingsView-CiNh-RbW.js +30 -0
- package/dist/assets/{SettingsWindow-By4cqnqy.js → SettingsWindow-BIz224xs.js} +1 -1
- package/dist/assets/{SubmoduleDiffSummary-C0P2tXLU.js → SubmoduleDiffSummary-CXKmlps9.js} +1 -1
- package/dist/assets/{ToolOutputDialog-Cayc-yIM.js → ToolOutputDialog-BsgAK8xu.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-B0jmpPQz.js → ToolPartDiffPreview-vdPObXOf.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-DsOpvWZD.js → VirtualizedFileDiff-BkFNKWS5.js} +1 -1
- package/dist/assets/{WalkthroughView-CCakjyn9.js → WalkthroughView-6oE-MuDL.js} +2 -2
- package/dist/assets/{appThemeRegistry-Bw5oTm41.js → appThemeRegistry-aHUNHoqP.js} +1 -1
- package/dist/assets/changesTree-CePHbFcj.js +1 -0
- package/dist/assets/commitAndPush-Bon9r94r.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-B-4aLf4A.js → computeVirtualFileMetrics-DKqr_1AQ.js} +2 -2
- package/dist/assets/de-CgAJ51z7.js +10 -0
- package/dist/assets/es-zGi_ravM.js +16 -0
- package/dist/assets/fr-CPfogrWx.js +14 -0
- package/dist/assets/index-CHfphYL3.js +41 -0
- package/dist/assets/{index-B6r0Kv-B.js → index-DpFttslC.js} +1 -1
- package/dist/assets/index-DvMJ3w6V.css +1 -0
- package/dist/assets/{isDiffPlainText-Ok-kgtJA.js → isDiffPlainText-kzAgpIgi.js} +1 -1
- package/dist/assets/{isFilePlainText-0dLnkYm8.js → isFilePlainText-Uj6y-jzz.js} +1 -1
- package/dist/assets/ja-DMk6wd-U.js +16 -0
- package/dist/assets/ko-BFpzJ8jc.js +16 -0
- package/dist/assets/{main-CjXBM_Xe.js → main-CbfMxn-I.js} +2 -2
- package/dist/assets/main-anyZFMIs.js +896 -0
- package/dist/assets/{markdown-shiki.worker-CahLvHIq.js → markdown-shiki.worker-Bg8SoAJJ.js} +8 -5
- package/dist/assets/markdownCore-CmM47cAE.js +7 -0
- package/dist/assets/{miniChat-DZ3OAeLN.js → miniChat-CiAKBC10.js} +2 -2
- package/dist/assets/{mobile-CH0LOIF-.js → mobile-CsT4sJwC.js} +2 -2
- package/dist/assets/patchFileDiff-DeaE08W0.js +13 -0
- package/dist/assets/pl-VdRPcZrB.js +16 -0
- package/dist/assets/pt-BR-BRys_lOW.js +16 -0
- package/dist/assets/{renderElectronMiniChatApp-CB1uLYvh.js → renderElectronMiniChatApp-C5677jy0.js} +2 -2
- package/dist/assets/renderMobileApp-D4dBBAqQ.js +25 -0
- package/dist/assets/runtimeEndpointReset-5r0hkd-2.js +27 -0
- package/dist/assets/scheduledTasksApi-BZCNJ588.js +1 -0
- package/dist/assets/{shikiHighlight-CocY80VR.js → shikiHighlight-BSUEa3yF.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-CF77r8FA.js → textMateThemeFromAppTheme-CsATFZIV.js} +1 -1
- package/dist/assets/tr-CA9ckNnm.js +7 -0
- package/dist/assets/uk-byjR-y8D.js +16 -0
- package/dist/assets/{useAppFontEffects-Dc5nTHi8.js → useAppFontEffects-BWQZ5DeI.js} +161 -157
- package/dist/assets/{useInlineCommentController-Dbza5c8l.js → useInlineCommentController-DlFyVfBu.js} +2 -2
- package/dist/assets/{useRootScrollLock-CSCLv396.js → useRootScrollLock-Cp1eFoM2.js} +2 -2
- package/dist/assets/{vendor-codemirror-language-data-CkmYWcRI.js → vendor-codemirror-language-data-BwwommM0.js} +2 -2
- package/dist/assets/{vendor-opencode-client-_BAHQo4R.js → vendor-opencode-client-DYdsLbCM.js} +2 -2
- package/dist/assets/vendor-zod-BSoePkpP.js +39 -0
- package/dist/assets/{web-components-nsStrYq9.js → web-components-D3Yjr4Zx.js} +1 -1
- package/dist/assets/zh-CN-DRabgxdG.js +16 -0
- package/dist/assets/zh-TW-rbY5c9UK.js +16 -0
- package/dist/index.html +5 -5
- package/dist/mini-chat.html +5 -5
- package/dist/mobile.html +5 -5
- package/package.json +4 -4
- package/server/index.js +82 -0
- package/server/lib/agent-tool/DOCUMENTATION.md +5 -0
- package/server/lib/agent-tool/runtime.js +34 -6
- package/server/lib/agent-tool/runtime.test.js +15 -0
- package/server/lib/browser-control/DOCUMENTATION.md +14 -2
- package/server/lib/event-stream/global-hub.js +23 -1
- package/server/lib/event-stream/global-hub.test.js +35 -0
- package/server/lib/event-stream/global-ws-bridge.js +3 -1
- package/server/lib/event-stream/upstream-reader.js +3 -2
- package/server/lib/git/DOCUMENTATION.md +1 -1
- package/server/lib/git/service.js +22 -0
- package/server/lib/git/service.test.js +8 -0
- package/server/lib/guests/DOCUMENTATION.md +4 -3
- package/server/lib/guests/catalog.js +19 -1
- package/server/lib/guests/catalog.test.js +22 -0
- package/server/lib/guests/html-styles.js +5 -3
- package/server/lib/guests/html-styles.test.js +3 -1
- package/server/lib/guests/routes.js +11 -3
- package/server/lib/guests/service.js +5 -0
- package/server/lib/guests/surface.js +55 -9
- package/server/lib/guests/surface.test.js +56 -6
- package/server/lib/notifications/DOCUMENTATION.md +10 -0
- package/server/lib/notifications/emit-route.js +118 -0
- package/server/lib/notifications/emit-route.test.js +112 -0
- package/server/lib/openchamber-control/actions.js +16 -2
- package/server/lib/openchamber-control/service.js +23 -0
- package/server/lib/openchamber-control/service.test.js +31 -0
- package/server/lib/openchamber-sessions/fork-inheritance.js +103 -0
- package/server/lib/openchamber-sessions/fork-inheritance.test.js +69 -0
- package/server/lib/openchamber-sessions/routes.js +11 -0
- package/server/lib/openchamber-sessions/routes.test.js +18 -0
- package/server/lib/opencode/DOCUMENTATION.md +37 -24
- package/server/lib/opencode/bootstrap-runtime.js +14 -1
- package/server/lib/opencode/compatibility.js +6 -3
- package/server/lib/opencode/compatibility.test.js +8 -0
- package/server/lib/opencode/config-entity-v2.test.js +27 -0
- package/server/lib/opencode/config-paths.test.js +12 -0
- package/server/lib/opencode/config-v2.d.ts +2 -0
- package/server/lib/opencode/config-v2.js +42 -0
- package/server/lib/opencode/config-v2.test.js +17 -0
- package/server/lib/opencode/core-routes.js +20 -4
- package/server/lib/opencode/core-routes.test.js +41 -0
- package/server/lib/opencode/env-runtime.js +1 -8
- package/server/lib/opencode/feature-routes-runtime.js +2 -1
- package/server/lib/opencode/lifecycle.js +30 -2
- package/server/lib/opencode/lifecycle.test.js +27 -0
- package/server/lib/opencode/managed-config-file.js +18 -6
- package/server/lib/opencode/managed-config-file.test.js +23 -7
- package/server/lib/opencode/mcp.js +7 -2
- package/server/lib/opencode/openchamber-routes.js +29 -11
- package/server/lib/opencode/openchamber-routes.test.js +18 -0
- package/server/lib/opencode/project-directory-runtime.js +8 -0
- package/server/lib/opencode/project-directory-runtime.test.js +13 -0
- package/server/lib/opencode/provider-source-route.test.js +59 -0
- package/server/lib/opencode/providers.js +3 -0
- package/server/lib/opencode/providers.test.js +62 -0
- package/server/lib/opencode/proxy.js +38 -2
- package/server/lib/opencode/routes-upgrade.test.js +1 -1
- package/server/lib/opencode/routes.js +36 -1
- package/server/lib/opencode/server-utils-runtime.js +5 -0
- package/server/lib/opencode/settings-helpers.js +10 -0
- package/server/lib/opencode/settings-helpers.test.js +2 -2
- package/server/lib/opencode/settings-registry.json +17 -0
- package/server/lib/opencode/settings-runtime.js +1 -0
- package/server/lib/opencode/shared.js +49 -4
- package/server/lib/opencode/shared.test.js +79 -1
- package/server/lib/opencode/shutdown-runtime.js +3 -0
- package/server/lib/opencode/skill-routes.js +28 -12
- package/server/lib/opencode/skill-routes.test.js +121 -1
- package/server/lib/opencode/upgrade-capability.js +0 -14
- package/server/lib/opencode/v1-migration-topup.js +21 -15
- package/server/lib/opencode/v1-migration-topup.test.js +14 -6
- package/server/lib/opencode/v2-install.d.ts +1 -0
- package/server/lib/opencode/v2-install.js +8 -7
- package/server/lib/opencode/v2-install.test.js +13 -4
- package/server/lib/opencode/watcher.js +3 -1
- package/server/lib/opencode/websearch-config.js +13 -1
- package/server/lib/quota/providers/kimi.js +1 -1
- package/server/lib/realtime-proxy.js +5 -1
- package/server/lib/realtime-proxy.test.js +29 -0
- package/server/lib/relay/tunnel-host.js +4 -1
- package/server/lib/relay/tunnel-host.test.js +11 -0
- package/server/lib/session-assist/DOCUMENTATION.md +17 -5
- package/server/lib/session-assist/runtime.js +19 -2
- package/server/lib/session-assist/runtime.test.js +8 -0
- package/server/lib/session-goal/DOCUMENTATION.md +11 -0
- package/server/lib/small-model/DOCUMENTATION.md +11 -10
- package/server/lib/small-model/index.js +27 -32
- package/server/lib/small-model/index.test.js +28 -16
- package/server/lib/spaces/DOCUMENTATION.md +381 -20
- package/server/lib/spaces/code-in-bait.js +145 -6
- package/server/lib/spaces/code-in.js +10 -150
- package/server/lib/spaces/code-in.test.js +7 -83
- package/server/lib/spaces/code-out.js +1819 -0
- package/server/lib/spaces/code-out.test.js +3945 -0
- package/server/lib/spaces/code-transfer.js +173 -0
- package/server/lib/spaces/command-stream.test.js +181 -0
- package/server/lib/spaces/dispatcher.js +670 -0
- package/server/lib/spaces/dispatcher.test.js +582 -0
- package/server/lib/spaces/gatekeeper-channel.js +2 -0
- package/server/lib/spaces/gatekeeper-channel.test.js +9 -3
- package/server/lib/spaces/gatekeeper-program.cjs +4 -1
- package/server/lib/spaces/gatekeeper-program.test.js +3 -0
- package/server/lib/spaces/hardening.js +20 -4
- package/server/lib/spaces/hardening.test.js +18 -3
- package/server/lib/spaces/host-git.js +7 -4
- package/server/lib/spaces/host-git.test.js +6 -2
- package/server/lib/spaces/host.js +304 -0
- package/server/lib/spaces/host.test.js +273 -0
- package/server/lib/spaces/journey.js +393 -0
- package/server/lib/spaces/journey.test.js +384 -0
- package/server/lib/spaces/layout.js +26 -2
- package/server/lib/spaces/manager.js +4 -3
- package/server/lib/spaces/manager.test.js +6 -0
- package/server/lib/spaces/places/code-out.docker.live.test.js +412 -0
- package/server/lib/spaces/places/contract-suite.js +36 -0
- package/server/lib/spaces/places/dispatcher.docker.live.test.js +296 -0
- package/server/lib/spaces/places/docker.js +15 -3
- package/server/lib/spaces/places/docker.test.js +33 -2
- package/server/lib/spaces/places/escape-suite.js +86 -14
- package/server/lib/spaces/places/memory-place.js +24 -1
- package/server/lib/spaces/places/registry.js +1 -1
- package/server/lib/spaces/places/server.docker.live.test.js +69 -33
- package/server/lib/spaces/places/sessions.docker.live.test.js +220 -0
- package/server/lib/spaces/routes.js +207 -0
- package/server/lib/spaces/routes.test.js +211 -0
- package/server/lib/spaces/run-command.js +261 -8
- package/server/lib/spaces/run-command.test.js +193 -3
- package/server/lib/spaces/space-events.js +153 -0
- package/server/lib/spaces/space-events.test.js +160 -0
- package/server/lib/spaces/space-records.js +98 -0
- package/server/lib/spaces/space-records.test.js +73 -0
- package/server/lib/spaces/space-sessions.js +210 -0
- package/server/lib/spaces/space-sessions.test.js +161 -0
- package/server/lib/spaces/websocket.js +329 -0
- package/server/lib/spaces/websocket.test.js +345 -0
- package/server/lib/ui-auth/ui-auth.js +8 -2
- package/server/lib/ui-auth/ui-auth.test.js +29 -0
- package/server/opencode-proxy.test.js +113 -0
- package/dist/assets/DiffView-BucGEJYa.js +0 -4
- package/dist/assets/FilesView-CQcaaAVP.js +0 -17
- package/dist/assets/GuestSurfacePane--DJ7rsmY.js +0 -1
- package/dist/assets/MarkdownImageGallery-wcUUcf8l.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BPe2TVV2.js +0 -12
- package/dist/assets/PluginPane-DImv8hV2.js +0 -3
- package/dist/assets/SettingsView-DOjuOljf.js +0 -29
- package/dist/assets/commitAndPush-sGEelpjh.js +0 -1
- package/dist/assets/de-CD9utsNj.js +0 -10
- package/dist/assets/es-NNum2rX8.js +0 -16
- package/dist/assets/fr-CJLGmduQ.js +0 -14
- package/dist/assets/index-DjGPR5vW.js +0 -41
- package/dist/assets/index-fCXJ-8Qt.css +0 -1
- package/dist/assets/ja-BuddHNi6.js +0 -16
- package/dist/assets/ko-BrwMbHmf.js +0 -16
- package/dist/assets/main-CxVyUDU_.js +0 -896
- package/dist/assets/markdownCore-B6PpX409.js +0 -5
- package/dist/assets/patchFileDiff-BFRGKaGH.js +0 -13
- package/dist/assets/pl-BwN4TNlP.js +0 -16
- package/dist/assets/pt-BR-BhMtownO.js +0 -16
- package/dist/assets/renderMobileApp-nQ4sjQtb.js +0 -25
- package/dist/assets/runtimeEndpointReset-9ZGlXU4J.js +0 -27
- package/dist/assets/scheduledTasksApi-6DsL_SwM.js +0 -1
- package/dist/assets/tr-DRzvqMdi.js +0 -7
- package/dist/assets/uk-b2aYOSNh.js +0 -16
- package/dist/assets/vendor-zod-Gea9uBlY.js +0 -39
- package/dist/assets/zh-CN-DZeUThm_.js +0 -16
- package/dist/assets/zh-TW-2fRE7uc6.js +0 -16
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
|
|
5
|
+
import { afterEach, describe, expect, it } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { createSpaceRecords, networkSchema } from './space-records.js';
|
|
8
|
+
|
|
9
|
+
const ID = 'a1b2c3d4e5f6';
|
|
10
|
+
const folders = [];
|
|
11
|
+
const temporary = () => {
|
|
12
|
+
const folder = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-space-records-'));
|
|
13
|
+
folders.push(folder);
|
|
14
|
+
return folder;
|
|
15
|
+
};
|
|
16
|
+
const quiet = { warn: () => {} };
|
|
17
|
+
|
|
18
|
+
afterEach(() => {
|
|
19
|
+
for (const folder of folders.splice(0)) fs.rmSync(folder, { recursive: true, force: true });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe('space records', () => {
|
|
23
|
+
it('writes a record readable by the user only, reads it back, changes a field and removes it', () => {
|
|
24
|
+
const dataDir = temporary();
|
|
25
|
+
const records = createSpaceRecords({ dataDir, logger: quiet });
|
|
26
|
+
expect(records.read(ID)).toEqual({ status: 'missing', record: null });
|
|
27
|
+
|
|
28
|
+
const written = records.write(ID, { network: { mode: 'allowlist', domains: ['api.anthropic.com'] }, repository: '/home/me/project' });
|
|
29
|
+
expect(written).toEqual({ version: 1, network: { mode: 'allowlist', domains: ['api.anthropic.com'] }, repository: '/home/me/project', spacePath: null, base: null, history: 'pending' });
|
|
30
|
+
const file = path.join(dataDir, 'spaces', 'records', `${ID}.json`);
|
|
31
|
+
if (process.platform !== 'win32') expect(fs.statSync(file).mode & 0o777).toBe(0o600);
|
|
32
|
+
expect(fs.readdirSync(path.dirname(file))).toEqual([`${ID}.json`]);
|
|
33
|
+
|
|
34
|
+
expect(records.update(ID, { spacePath: `/spaces/${ID}/project`, base: 'a'.repeat(40) }).record).toMatchObject({ spacePath: `/spaces/${ID}/project`, base: 'a'.repeat(40), history: 'pending' });
|
|
35
|
+
expect(records.update(ID, { history: 'sent' }).record.history).toBe('sent');
|
|
36
|
+
expect(records.read(ID)).toEqual({ status: 'ok', record: expect.objectContaining({ history: 'sent', network: { mode: 'allowlist', domains: ['api.anthropic.com'] } }) });
|
|
37
|
+
|
|
38
|
+
records.remove(ID);
|
|
39
|
+
expect(records.read(ID)).toEqual({ status: 'missing', record: null });
|
|
40
|
+
records.remove(ID);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('reports a file it cannot read as unreadable, never as a fresh record, and does not write over it', () => {
|
|
44
|
+
const dataDir = temporary();
|
|
45
|
+
const records = createSpaceRecords({ dataDir, logger: quiet });
|
|
46
|
+
const directory = path.join(dataDir, 'spaces', 'records');
|
|
47
|
+
fs.mkdirSync(directory, { recursive: true });
|
|
48
|
+
fs.writeFileSync(path.join(directory, `${ID}.json`), '{ "version": 1, "network": { "mode": "everything" } }');
|
|
49
|
+
expect(records.read(ID)).toEqual({ status: 'unreadable', record: null });
|
|
50
|
+
fs.writeFileSync(path.join(directory, `${ID}.json`), 'not json');
|
|
51
|
+
expect(records.read(ID)).toEqual({ status: 'unreadable', record: null });
|
|
52
|
+
expect(records.update(ID, { history: 'sent' })).toEqual({ status: 'unreadable', record: null });
|
|
53
|
+
expect(fs.readFileSync(path.join(directory, `${ID}.json`), 'utf8')).toBe('not json');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('refuses a record that is not one, and an id that is not a space id', () => {
|
|
57
|
+
const records = createSpaceRecords({ dataDir: temporary(), logger: quiet });
|
|
58
|
+
expect(() => records.write(ID, { network: { mode: 'open', domains: ['not a name'] } })).toThrow();
|
|
59
|
+
expect(() => records.write('../etc', { network: { mode: 'open' } })).toThrow(/space id/i);
|
|
60
|
+
expect(() => records.read('../etc')).toThrow(/space id/i);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('takes domain names the allowlist takes, and nothing else', () => {
|
|
64
|
+
const accepted = (domains) => networkSchema.safeParse({ mode: 'allowlist', domains }).success;
|
|
65
|
+
expect(accepted(['api.anthropic.com', 'registry.npmjs.org', 'a-b.example'])).toBe(true);
|
|
66
|
+
expect(accepted([])).toBe(true);
|
|
67
|
+
for (const bad of [['localhost'], ['10.0.0.1'], ['Api.Example.com'], ['a_b.example'], ['-a.example'], ['a.example.'], ['a..example'], ['https://a.example'], ['a.example/path']]) {
|
|
68
|
+
expect(accepted(bad), bad[0]).toBe(false);
|
|
69
|
+
}
|
|
70
|
+
expect(networkSchema.safeParse({ mode: 'open' }).data).toEqual({ mode: 'open', domains: [] });
|
|
71
|
+
expect(networkSchema.safeParse({ mode: 'all' }).success).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
});
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// The merged session list and the rules for what a space may claim in it or in its events.
|
|
2
|
+
// Pure: no Express, no transport. `host.js` feeds it what the spaces answered and the proxy
|
|
3
|
+
// asks it for the merged answer.
|
|
4
|
+
//
|
|
5
|
+
// A space's list and events are untrusted. A record or an event may name a directory under
|
|
6
|
+
// that space's own root only, and never a session id the host has: the host's id wins, the
|
|
7
|
+
// space's record is dropped and logged as a code, without its body. A space that does not
|
|
8
|
+
// answer keeps its last known sessions, marked stale; a missing answer never means deletion.
|
|
9
|
+
|
|
10
|
+
import { z } from 'zod';
|
|
11
|
+
|
|
12
|
+
import { sanitizeSessionListItem } from '../opencode/proxy.js';
|
|
13
|
+
import { isDirectoryOfSpace } from './dispatcher.js';
|
|
14
|
+
|
|
15
|
+
// How many host session ids are remembered for the collision rule. Older ones are forgotten
|
|
16
|
+
// first; a session the host listed or created recently is always among them.
|
|
17
|
+
const HOST_ID_MEMORY = 50_000;
|
|
18
|
+
|
|
19
|
+
/** Why a record or an event of a space was dropped. Logged as a code, never with the body. */
|
|
20
|
+
export const SPACE_DROP_CODES = Object.freeze({
|
|
21
|
+
malformed: 'space_session_malformed',
|
|
22
|
+
outsideRoot: 'space_session_outside_root',
|
|
23
|
+
hostId: 'space_session_host_id',
|
|
24
|
+
claimed: 'space_session_claimed',
|
|
25
|
+
eventHostSession: 'space_event_host_session',
|
|
26
|
+
eventOutsideRoot: 'space_event_outside_root',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// What the host reads of a record or an event before it decides; every other field is carried, not read.
|
|
30
|
+
const directorySchema = z.string().min(1);
|
|
31
|
+
const idSchema = z.string().min(1);
|
|
32
|
+
const recordSchema = z.object({ id: idSchema, location: z.object({ directory: directorySchema }).passthrough() }).passthrough();
|
|
33
|
+
const eventSchema = z.object({
|
|
34
|
+
type: z.string(),
|
|
35
|
+
data: z.object({ sessionID: idSchema.optional(), location: z.object({ directory: z.unknown() }).passthrough().optional() }).passthrough().optional(),
|
|
36
|
+
location: z.object({ directory: z.unknown() }).passthrough().optional(),
|
|
37
|
+
}).passthrough();
|
|
38
|
+
const isRecord = (value) => z.object({}).passthrough().safeParse(value).success;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* The records of one space's list, kept or dropped one by one. `isHostSessionId` answers the
|
|
42
|
+
* host's ids, `claimedBy` names the space that already listed an id. Duplicates within the list
|
|
43
|
+
* keep the first. Resolves `{ records, dropped }`, `dropped` counting each code.
|
|
44
|
+
*/
|
|
45
|
+
export function filterSpaceSessionRecords({ spaceId, records, isHostSessionId, claimedBy }) {
|
|
46
|
+
const kept = [];
|
|
47
|
+
const dropped = {};
|
|
48
|
+
const seen = new Set();
|
|
49
|
+
const drop = (code) => { dropped[code] = (dropped[code] ?? 0) + 1; };
|
|
50
|
+
for (const record of records) {
|
|
51
|
+
const parsed = recordSchema.safeParse(record);
|
|
52
|
+
if (!parsed.success) {
|
|
53
|
+
// A record without an id is malformed; one with an id and no usable directory lies outside every root.
|
|
54
|
+
drop(idSchema.safeParse(record?.id).success ? SPACE_DROP_CODES.outsideRoot : SPACE_DROP_CODES.malformed);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
const { id, location } = parsed.data;
|
|
58
|
+
if (!isDirectoryOfSpace(location.directory, spaceId)) { drop(SPACE_DROP_CODES.outsideRoot); continue; }
|
|
59
|
+
if (isHostSessionId(id)) { drop(SPACE_DROP_CODES.hostId); continue; }
|
|
60
|
+
const owner = claimedBy(id);
|
|
61
|
+
if (owner !== null && owner !== spaceId) { drop(SPACE_DROP_CODES.claimed); continue; }
|
|
62
|
+
if (seen.has(id)) continue;
|
|
63
|
+
seen.add(id);
|
|
64
|
+
kept.push(sanitizeSessionListItem(record));
|
|
65
|
+
}
|
|
66
|
+
return { records: kept, dropped };
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Whether one event of a space may pass: the session it names is not the host's, and every
|
|
71
|
+
* directory it carries, on the event or on the created session, lies under the space's root.
|
|
72
|
+
* Execution events carry no location and pass on their session id alone. Answers the drop
|
|
73
|
+
* code, or null when the event passes.
|
|
74
|
+
*/
|
|
75
|
+
export function spaceEventDropCode({ spaceId, payload, isHostSessionId }) {
|
|
76
|
+
const parsed = eventSchema.safeParse(payload);
|
|
77
|
+
if (!parsed.success) return SPACE_DROP_CODES.malformed;
|
|
78
|
+
const { data, location } = parsed.data;
|
|
79
|
+
for (const directory of [location?.directory, data?.location?.directory]) {
|
|
80
|
+
if (directory === undefined || directory === null) continue;
|
|
81
|
+
if (!directorySchema.safeParse(directory).success || !isDirectoryOfSpace(directory, spaceId)) return SPACE_DROP_CODES.eventOutsideRoot;
|
|
82
|
+
}
|
|
83
|
+
if (data?.sessionID !== undefined && isHostSessionId(data.sessionID)) return SPACE_DROP_CODES.eventHostSession;
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* The host's list with every space's records after it. `spaces` marks each space's answer:
|
|
89
|
+
* `complete`, `partial` when the space had more pages than the host read, `stale` when the
|
|
90
|
+
* last known list stands in for an answer that did not come, and `unknown` when the space
|
|
91
|
+
* never answered. A host payload without spaces goes back as it came, untouched.
|
|
92
|
+
*/
|
|
93
|
+
export function mergeSessionLists(hostPayload, spaceLists) {
|
|
94
|
+
if (spaceLists.length === 0) return hostPayload;
|
|
95
|
+
const records = spaceLists.flatMap((entry) => entry.records);
|
|
96
|
+
// The mark names the space for the client: its label name, the host project it was made for,
|
|
97
|
+
// as the host resolved it from the label, and the project's path inside, or null for both when
|
|
98
|
+
// the project is no longer registered on this host.
|
|
99
|
+
const spaces = spaceLists.map((entry) => ({
|
|
100
|
+
id: entry.spaceId,
|
|
101
|
+
name: entry.name ?? '',
|
|
102
|
+
state: entry.state,
|
|
103
|
+
sessions: entry.records.length,
|
|
104
|
+
projectDirectory: entry.projectDirectory ?? null,
|
|
105
|
+
directory: entry.directory ?? null,
|
|
106
|
+
}));
|
|
107
|
+
if (Array.isArray(hostPayload)) return [...hostPayload, ...records];
|
|
108
|
+
if (isRecord(hostPayload) && Array.isArray(hostPayload.data)) {
|
|
109
|
+
return { ...hostPayload, data: [...hostPayload.data, ...records], spaces };
|
|
110
|
+
}
|
|
111
|
+
return hostPayload;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* What the host knows about sessions across the boundary: the host's own ids, and per space
|
|
116
|
+
* the last list it accepted and the state of that answer. One per host process.
|
|
117
|
+
*/
|
|
118
|
+
export function createSpaceSessionIndex({ logger = console } = {}) {
|
|
119
|
+
const hostIds = new Map();
|
|
120
|
+
const spaces = new Map();
|
|
121
|
+
const claims = new Map();
|
|
122
|
+
|
|
123
|
+
const rememberHostId = (id) => {
|
|
124
|
+
if (!idSchema.safeParse(id).success) return;
|
|
125
|
+
hostIds.delete(id);
|
|
126
|
+
hostIds.set(id, true);
|
|
127
|
+
if (hostIds.size > HOST_ID_MEMORY) hostIds.delete(hostIds.keys().next().value);
|
|
128
|
+
};
|
|
129
|
+
const isHostSessionId = (id) => hostIds.has(id);
|
|
130
|
+
const claimedBy = (id) => claims.get(id) ?? null;
|
|
131
|
+
|
|
132
|
+
const logDropped = (spaceId, dropped) => {
|
|
133
|
+
for (const [code, count] of Object.entries(dropped)) {
|
|
134
|
+
logger.warn?.(`[spaces] dropped ${count} record(s) of space ${spaceId}: ${code}`);
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
const entryOf = (spaceId) => {
|
|
139
|
+
let entry = spaces.get(spaceId);
|
|
140
|
+
if (!entry) {
|
|
141
|
+
entry = { spaceId, records: [], state: 'unknown' };
|
|
142
|
+
spaces.set(spaceId, entry);
|
|
143
|
+
}
|
|
144
|
+
return entry;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const releaseClaims = (spaceId) => {
|
|
148
|
+
for (const [id, owner] of claims) if (owner === spaceId) claims.delete(id);
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
isHostSessionId,
|
|
153
|
+
claimedBy,
|
|
154
|
+
/** The host's list passed through the proxy: its ids are the host's from now on. */
|
|
155
|
+
observeHostRecords(records) {
|
|
156
|
+
for (const record of records) if (isRecord(record)) rememberHostId(record.id);
|
|
157
|
+
},
|
|
158
|
+
/** A host event that names a session: a created one is the host's from now on. */
|
|
159
|
+
observeHostEvent(payload) {
|
|
160
|
+
const parsed = eventSchema.safeParse(payload);
|
|
161
|
+
if (!parsed.success || parsed.data.type !== 'session.created') return;
|
|
162
|
+
rememberHostId(parsed.data.data?.sessionID);
|
|
163
|
+
},
|
|
164
|
+
/** A space answered its list, whole or in part. The records that pass replace the last known ones. */
|
|
165
|
+
acceptSpaceList(spaceId, records, { complete }) {
|
|
166
|
+
const filtered = filterSpaceSessionRecords({ spaceId, records, isHostSessionId, claimedBy });
|
|
167
|
+
logDropped(spaceId, filtered.dropped);
|
|
168
|
+
releaseClaims(spaceId);
|
|
169
|
+
for (const record of filtered.records) claims.set(record.id, spaceId);
|
|
170
|
+
const entry = entryOf(spaceId);
|
|
171
|
+
entry.records = filtered.records;
|
|
172
|
+
entry.state = complete ? 'complete' : 'partial';
|
|
173
|
+
return entry;
|
|
174
|
+
},
|
|
175
|
+
/** A space did not answer: its last known list stands, marked stale. */
|
|
176
|
+
markUnreachable(spaceId) {
|
|
177
|
+
const entry = entryOf(spaceId);
|
|
178
|
+
if (entry.state !== 'unknown') entry.state = 'stale';
|
|
179
|
+
return entry;
|
|
180
|
+
},
|
|
181
|
+
/** A space is gone: nothing of it is listed or claimed any more. */
|
|
182
|
+
forget(spaceId) {
|
|
183
|
+
spaces.delete(spaceId);
|
|
184
|
+
releaseClaims(spaceId);
|
|
185
|
+
},
|
|
186
|
+
/** Whether one event of a space passes. A created session that passes is claimed for the space. */
|
|
187
|
+
acceptSpaceEvent(spaceId, payload) {
|
|
188
|
+
const code = spaceEventDropCode({ spaceId, payload, isHostSessionId });
|
|
189
|
+
if (code !== null) {
|
|
190
|
+
logger.warn?.(`[spaces] dropped an event of space ${spaceId}: ${code}`);
|
|
191
|
+
return false;
|
|
192
|
+
}
|
|
193
|
+
const sessionID = payload.data?.sessionID;
|
|
194
|
+
if (idSchema.safeParse(sessionID).success) {
|
|
195
|
+
// A session another space listed or made is that space's: no other space speaks for it.
|
|
196
|
+
const owner = claimedBy(sessionID);
|
|
197
|
+
if (owner !== null && owner !== spaceId) {
|
|
198
|
+
logger.warn?.(`[spaces] dropped an event of space ${spaceId}: ${SPACE_DROP_CODES.claimed}`);
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
if (payload.type === 'session.created') claims.set(sessionID, spaceId);
|
|
202
|
+
}
|
|
203
|
+
return true;
|
|
204
|
+
},
|
|
205
|
+
/** Every space's last accepted list with its state, for the merge. */
|
|
206
|
+
snapshot() {
|
|
207
|
+
return Array.from(spaces.values(), (entry) => ({ spaceId: entry.spaceId, state: entry.state, records: entry.records }));
|
|
208
|
+
},
|
|
209
|
+
};
|
|
210
|
+
}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// The rules of the merged session list: what a space may claim in its list and in its events.
|
|
2
|
+
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
SPACE_DROP_CODES,
|
|
7
|
+
createSpaceSessionIndex,
|
|
8
|
+
filterSpaceSessionRecords,
|
|
9
|
+
mergeSessionLists,
|
|
10
|
+
spaceEventDropCode,
|
|
11
|
+
} from './space-sessions.js';
|
|
12
|
+
|
|
13
|
+
const ID = 'a1b2c3d4e5f6';
|
|
14
|
+
const OTHER = '0f0f0f0f0f0f';
|
|
15
|
+
const record = (id, directory, extra = {}) => ({ id, location: { directory }, title: id, ...extra });
|
|
16
|
+
const never = () => false;
|
|
17
|
+
const nobody = () => null;
|
|
18
|
+
|
|
19
|
+
describe('filterSpaceSessionRecords', () => {
|
|
20
|
+
it.each([
|
|
21
|
+
['its own root', record('s1', `/spaces/${ID}/repo`), true],
|
|
22
|
+
['its own root, deeper', record('s2', `/spaces/${ID}/repo/src`), true],
|
|
23
|
+
['the root itself', record('s3', `/spaces/${ID}`), true],
|
|
24
|
+
['a path outside every space', record('s4', '/home/me/project'), false],
|
|
25
|
+
['another space', record('s5', `/spaces/${OTHER}/repo`), false],
|
|
26
|
+
['a climb out of its root', record('s6', `/spaces/${ID}/../${OTHER}/repo`), false],
|
|
27
|
+
['a sibling with the same prefix', record('s7', `/spaces/${ID}x/repo`), false],
|
|
28
|
+
['no directory at all', { id: 's8', title: 'no location' }, false],
|
|
29
|
+
['a directory that is not text', record('s9', 42), false],
|
|
30
|
+
['no id', { location: { directory: `/spaces/${ID}/repo` } }, false],
|
|
31
|
+
['not an object', 'text', false],
|
|
32
|
+
])('keeps a record only when its directory lies under the space\'s root: %s', (_name, entry, kept) => {
|
|
33
|
+
const result = filterSpaceSessionRecords({ spaceId: ID, records: [entry], isHostSessionId: never, claimedBy: nobody });
|
|
34
|
+
expect(result.records.map((item) => item.id)).toEqual(kept ? [entry.id] : []);
|
|
35
|
+
if (!kept) expect(Object.values(result.dropped).reduce((sum, count) => sum + count, 0)).toBe(1);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('never lets a space record overwrite a host session id, and logs it as a code', () => {
|
|
39
|
+
const result = filterSpaceSessionRecords({
|
|
40
|
+
spaceId: ID,
|
|
41
|
+
records: [record('host-1', `/spaces/${ID}/repo`, { title: 'I am the host session now' }), record('mine', `/spaces/${ID}/repo`)],
|
|
42
|
+
isHostSessionId: (id) => id === 'host-1',
|
|
43
|
+
claimedBy: nobody,
|
|
44
|
+
});
|
|
45
|
+
expect(result.records.map((item) => item.id)).toEqual(['mine']);
|
|
46
|
+
expect(result.dropped).toEqual({ [SPACE_DROP_CODES.hostId]: 1 });
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('drops a record whose id another space already listed, and a duplicate within the list', () => {
|
|
50
|
+
const result = filterSpaceSessionRecords({
|
|
51
|
+
spaceId: ID,
|
|
52
|
+
records: [record('theirs', `/spaces/${ID}/repo`), record('mine', `/spaces/${ID}/repo`), record('mine', `/spaces/${ID}/repo`)],
|
|
53
|
+
isHostSessionId: never,
|
|
54
|
+
claimedBy: (id) => (id === 'theirs' ? OTHER : id === 'mine' ? ID : null),
|
|
55
|
+
});
|
|
56
|
+
expect(result.records.map((item) => item.id)).toEqual(['mine']);
|
|
57
|
+
expect(result.dropped).toEqual({ [SPACE_DROP_CODES.claimed]: 1 });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('keeps only the fields a session list may carry', () => {
|
|
61
|
+
const result = filterSpaceSessionRecords({
|
|
62
|
+
spaceId: ID,
|
|
63
|
+
records: [record('s1', `/spaces/${ID}/repo`, { permissions: { edit: 'allow' }, revert: { messageID: 'm', files: ['x'] } })],
|
|
64
|
+
isHostSessionId: never,
|
|
65
|
+
claimedBy: nobody,
|
|
66
|
+
});
|
|
67
|
+
expect(result.records[0]).toEqual({ id: 's1', location: { directory: `/spaces/${ID}/repo` }, title: 's1', revert: { messageID: 'm' } });
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
describe('spaceEventDropCode', () => {
|
|
72
|
+
const event = (type, data, location) => {
|
|
73
|
+
const payload = { type, data };
|
|
74
|
+
if (location) payload.location = { directory: location };
|
|
75
|
+
return payload;
|
|
76
|
+
};
|
|
77
|
+
it.each([
|
|
78
|
+
['an event of its own directory', event('session.created', { sessionID: 's1', location: { directory: `/spaces/${ID}/repo` } }, `/spaces/${ID}/repo`), null],
|
|
79
|
+
['an execution event with no location', event('session.execution.started', { sessionID: 's1' }), null],
|
|
80
|
+
['an event of another space', event('session.created', { sessionID: 's1' }, `/spaces/${OTHER}/repo`), SPACE_DROP_CODES.eventOutsideRoot],
|
|
81
|
+
['an event of a host directory', event('session.renamed', { sessionID: 's1' }, '/home/me/project'), SPACE_DROP_CODES.eventOutsideRoot],
|
|
82
|
+
['a created session that lands outside', event('session.created', { sessionID: 's1', location: { directory: '/home/me' } }, `/spaces/${ID}/repo`), SPACE_DROP_CODES.eventOutsideRoot],
|
|
83
|
+
['a moved session that lands outside', event('session.moved', { sessionID: 's1', location: { directory: `/spaces/${OTHER}` } }, `/spaces/${ID}/repo`), SPACE_DROP_CODES.eventOutsideRoot],
|
|
84
|
+
['an event that names a host session', event('session.execution.started', { sessionID: 'host-1' }), SPACE_DROP_CODES.eventHostSession],
|
|
85
|
+
['not an object', 'text', SPACE_DROP_CODES.malformed],
|
|
86
|
+
])('%s', (_name, payload, code) => {
|
|
87
|
+
expect(spaceEventDropCode({ spaceId: ID, payload, isHostSessionId: (id) => id === 'host-1' })).toBe(code);
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe('mergeSessionLists', () => {
|
|
92
|
+
const host = { data: [record('h1', '/home/me')], cursor: { next: 'abc' } };
|
|
93
|
+
it('returns the host payload untouched, the same object, when there is no space', () => {
|
|
94
|
+
expect(mergeSessionLists(host, [])).toBe(host);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('lists the host first, then each space, with a mark per space', () => {
|
|
98
|
+
const merged = mergeSessionLists(host, [
|
|
99
|
+
{ spaceId: ID, state: 'complete', records: [record('s1', `/spaces/${ID}/repo`)], name: 'First', projectDirectory: '/home/me/repo', directory: `/spaces/${ID}/repo` },
|
|
100
|
+
{ spaceId: OTHER, state: 'stale', records: [record('s2', `/spaces/${OTHER}/repo`), record('s3', `/spaces/${OTHER}/repo`)] },
|
|
101
|
+
]);
|
|
102
|
+
expect(merged.data.map((item) => item.id)).toEqual(['h1', 's1', 's2', 's3']);
|
|
103
|
+
expect(merged.cursor).toEqual({ next: 'abc' });
|
|
104
|
+
// A space whose project is not registered on this host is marked with no project and no directory.
|
|
105
|
+
expect(merged.spaces).toEqual([
|
|
106
|
+
{ id: ID, name: 'First', state: 'complete', sessions: 1, projectDirectory: '/home/me/repo', directory: `/spaces/${ID}/repo` },
|
|
107
|
+
{ id: OTHER, name: '', state: 'stale', sessions: 2, projectDirectory: null, directory: null },
|
|
108
|
+
]);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe('createSpaceSessionIndex', () => {
|
|
113
|
+
const quiet = { warn: () => {} };
|
|
114
|
+
|
|
115
|
+
it('answers empty for a space that answered empty, and keeps the last list for one that did not answer', () => {
|
|
116
|
+
const index = createSpaceSessionIndex({ logger: quiet });
|
|
117
|
+
index.acceptSpaceList(ID, [record('s1', `/spaces/${ID}/repo`)], { complete: true });
|
|
118
|
+
expect(index.snapshot()).toEqual([{ spaceId: ID, state: 'complete', records: [expect.objectContaining({ id: 's1' })] }]);
|
|
119
|
+
index.markUnreachable(ID);
|
|
120
|
+
expect(index.snapshot()).toEqual([{ spaceId: ID, state: 'stale', records: [expect.objectContaining({ id: 's1' })] }]);
|
|
121
|
+
index.acceptSpaceList(ID, [], { complete: true });
|
|
122
|
+
expect(index.snapshot()).toEqual([{ spaceId: ID, state: 'complete', records: [] }]);
|
|
123
|
+
// A space that never answered is unknown, with nothing to show, and is not an empty answer.
|
|
124
|
+
index.markUnreachable(OTHER);
|
|
125
|
+
expect(index.snapshot()[1]).toEqual({ spaceId: OTHER, state: 'unknown', records: [] });
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('marks a list that had more pages than were read as partial', () => {
|
|
129
|
+
const index = createSpaceSessionIndex({ logger: quiet });
|
|
130
|
+
index.acceptSpaceList(ID, [record('s1', `/spaces/${ID}/repo`)], { complete: false });
|
|
131
|
+
expect(index.snapshot()[0].state).toBe('partial');
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('learns the host\'s ids from its list and its events, and lets no space take them', () => {
|
|
135
|
+
const logs = [];
|
|
136
|
+
const index = createSpaceSessionIndex({ logger: { warn: (line) => logs.push(line) } });
|
|
137
|
+
index.observeHostRecords([record('h1', '/home/me')]);
|
|
138
|
+
index.observeHostEvent({ type: 'session.created', data: { sessionID: 'h2' } });
|
|
139
|
+
const entry = index.acceptSpaceList(ID, [record('h1', `/spaces/${ID}/repo`, { title: 'stolen' }), record('h2', `/spaces/${ID}/repo`), record('s1', `/spaces/${ID}/repo`)], { complete: true });
|
|
140
|
+
expect(entry.records.map((item) => item.id)).toEqual(['s1']);
|
|
141
|
+
expect(index.acceptSpaceEvent(ID, { type: 'session.execution.started', data: { sessionID: 'h1' } })).toBe(false);
|
|
142
|
+
expect(index.acceptSpaceEvent(ID, { type: 'session.execution.started', data: { sessionID: 's1' } })).toBe(true);
|
|
143
|
+
expect(logs.join('\n')).toContain(SPACE_DROP_CODES.hostId);
|
|
144
|
+
expect(logs.join('\n')).toContain(SPACE_DROP_CODES.eventHostSession);
|
|
145
|
+
expect(logs.join('\n')).not.toContain('stolen');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('claims a created session for the space that made it, and releases claims when the space is forgotten', () => {
|
|
149
|
+
const index = createSpaceSessionIndex({ logger: quiet });
|
|
150
|
+
expect(index.acceptSpaceEvent(ID, { type: 'session.created', data: { sessionID: 's1', location: { directory: `/spaces/${ID}/repo` } } })).toBe(true);
|
|
151
|
+
expect(index.claimedBy('s1')).toBe(ID);
|
|
152
|
+
expect(index.acceptSpaceEvent(OTHER, { type: 'session.created', data: { sessionID: 's1', location: { directory: `/spaces/${OTHER}/repo` } } })).toBe(false);
|
|
153
|
+
// Nor may another space speak for it in any other event.
|
|
154
|
+
expect(index.acceptSpaceEvent(OTHER, { type: 'session.execution.started', data: { sessionID: 's1' } })).toBe(false);
|
|
155
|
+
expect(index.acceptSpaceEvent(ID, { type: 'session.execution.started', data: { sessionID: 's1' } })).toBe(true);
|
|
156
|
+
expect(index.acceptSpaceList(OTHER, [record('s1', `/spaces/${OTHER}/repo`)], { complete: true }).records).toEqual([]);
|
|
157
|
+
index.forget(ID);
|
|
158
|
+
expect(index.claimedBy('s1')).toBeNull();
|
|
159
|
+
expect(index.snapshot().map((entry) => entry.spaceId)).toEqual([OTHER]);
|
|
160
|
+
});
|
|
161
|
+
});
|