@openchamber/web 2.0.2 → 2.0.4
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/lib/DOCUMENTATION.md +1 -1
- package/bin/lib/commands-connect-url.js +6 -5
- package/bin/lib/commands-tunnel.js +24 -5
- package/dist/assets/{CodeMirrorCommentWidgets-CmKmyb9T.js → CodeMirrorCommentWidgets-C_zL-eri.js} +1 -1
- package/dist/assets/{DiffView-8-PFpZ2p.js → DiffView-BeN2_YYF.js} +3 -3
- package/dist/assets/FilesView-CN34wm_N.js +17 -0
- package/dist/assets/{GitView-DNUSu00w.js → GitView-DLDazOo1.js} +4 -4
- package/dist/assets/{GuestAttachDialog-Cv6QzjHC.js → GuestAttachDialog-C0xe_Lyy.js} +1 -1
- package/dist/assets/{GuestSurfacePane-Bt3jB_Ye.js → GuestSurfacePane-BdaurnDr.js} +1 -1
- package/dist/assets/{JsonTreeView-BlyHTRhM.js → JsonTreeView-B1Xq-k2t.js} +1 -1
- package/dist/assets/LinearIssuesView-BryoAHow.js +1 -0
- package/dist/assets/{MarkdownImageGallery-2UXJF-5B.js → MarkdownImageGallery-DfuEoaGq.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-B_ZcWOvX.js +12 -0
- package/dist/assets/OnboardingScreen-C22bGmnP.js +1 -0
- package/dist/assets/{PatchDiff-ByvnbG5T.js → PatchDiff-0xd6UeFB.js} +1 -1
- package/dist/assets/{PierreDiffViewer-BXieg0mH.js → PierreDiffViewer-BC950e3F.js} +3 -3
- package/dist/assets/PlanView-B7Xgihqk.js +5 -0
- package/dist/assets/PluginPane-2C71F8uF.js +3 -0
- package/dist/assets/SettingsView-m_zoFiaT.js +30 -0
- package/dist/assets/{SettingsWindow-BIz224xs.js → SettingsWindow-CofS020b.js} +1 -1
- package/dist/assets/{SubmoduleDiffSummary-CXKmlps9.js → SubmoduleDiffSummary-BSA9gnIO.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BsgAK8xu.js → ToolOutputDialog-DprkVKcj.js} +7 -7
- package/dist/assets/{ToolPartDiffPreview-vdPObXOf.js → ToolPartDiffPreview-Dq0go_fX.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-BkFNKWS5.js → VirtualizedFileDiff-Kp8hKJdT.js} +1 -1
- package/dist/assets/WalkthroughView-DGnTzqIU.js +4 -0
- package/dist/assets/{appThemeRegistry-aHUNHoqP.js → appThemeRegistry-BdEHBA4s.js} +1 -1
- package/dist/assets/{commitAndPush-Bon9r94r.js → commitAndPush-LwtVa2Oc.js} +1 -1
- package/dist/assets/{computeVirtualFileMetrics-DKqr_1AQ.js → computeVirtualFileMetrics-6V1xNpO9.js} +2 -2
- package/dist/assets/de-DlgBHUAI.js +10 -0
- package/dist/assets/es-BC8G41U8.js +16 -0
- package/dist/assets/fr-I0z3vVjy.js +14 -0
- package/dist/assets/index-CgR5rJq_.js +41 -0
- package/dist/assets/{index-DpFttslC.js → index-CmNPYddV.js} +1 -1
- package/dist/assets/index-adyy_sEk.css +1 -0
- package/dist/assets/{isDiffPlainText-kzAgpIgi.js → isDiffPlainText-1bXcWCrw.js} +1 -1
- package/dist/assets/{isFilePlainText-Uj6y-jzz.js → isFilePlainText-CBAppvy1.js} +1 -1
- package/dist/assets/ja-BIElEsY8.js +16 -0
- package/dist/assets/ko-DRnnHetA.js +16 -0
- package/dist/assets/{main-CbfMxn-I.js → main-CzjTMTfW.js} +2 -2
- package/dist/assets/main-DVX34beR.js +886 -0
- package/dist/assets/markdownCore-Cxbkn5NR.js +7 -0
- package/dist/assets/{miniChat-CiAKBC10.js → miniChat-CP68IL8Q.js} +2 -2
- package/dist/assets/{mobile-CsT4sJwC.js → mobile-BrlBrNfZ.js} +2 -2
- package/dist/assets/nl-DzUV-kwp.js +16 -0
- package/dist/assets/{patchFileDiff-DeaE08W0.js → patchFileDiff-pqRSHLHI.js} +2 -2
- package/dist/assets/pl-Bb-cb7k7.js +16 -0
- package/dist/assets/pt-BR-CyIWrTcE.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-DKIilR7N.js +2 -0
- package/dist/assets/renderMobileApp-B0z6-x58.js +25 -0
- package/dist/assets/runtimeEndpointReset-uu1DBwLL.js +52 -0
- package/dist/assets/{scheduledTasksApi-BZCNJ588.js → scheduledTasksApi-BuzWT445.js} +1 -1
- package/dist/assets/{shikiHighlight-BSUEa3yF.js → shikiHighlight-BWGrY5YU.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-CsATFZIV.js → textMateThemeFromAppTheme-BSUFChBY.js} +1 -1
- package/dist/assets/tr-DXEDSoYO.js +7 -0
- package/dist/assets/uk-C8hN--q_.js +16 -0
- package/dist/assets/useAppFontEffects-Dsl_sLrj.js +7366 -0
- package/dist/assets/useInlineCommentController-d5vntsQ_.js +2 -0
- package/dist/assets/{useRootScrollLock-Cp1eFoM2.js → useRootScrollLock-2rd5Y6gR.js} +2 -2
- package/dist/assets/{vendor-base-ui-CsXYnR5c.js → vendor-base-ui-DnNniUWp.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-BwwommM0.js → vendor-codemirror-language-data-B1EetJur.js} +2 -2
- package/dist/assets/vendor-opencode-client-DSZl7jSi.js +12 -0
- package/dist/assets/{vendor-tanstack-react-virtual-ClYN8CzB.js → vendor-tanstack-react-virtual--0sBrLRh.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-BewVQryB.js → vendor-tanstack-virtual-core-BoA4iGMw.js} +1 -1
- package/dist/assets/{vendor-zod-BSoePkpP.js → vendor-zod-CxRSdNoV.js} +4 -4
- package/dist/assets/{web-components-D3Yjr4Zx.js → web-components-ngpHPEDU.js} +1 -1
- package/dist/assets/zh-CN-CtzXdjMZ.js +16 -0
- package/dist/assets/zh-TW-Ds0CADSz.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 +5 -5
- package/server/index.js +82 -4
- package/server/lib/agent-tool/DOCUMENTATION.md +8 -1
- package/server/lib/agent-tool/runtime.js +13 -4
- package/server/lib/agent-tool/runtime.test.js +15 -0
- package/server/lib/context-obligatory/DOCUMENTATION.md +10 -7
- package/server/lib/context-obligatory/runtime.js +2 -1
- package/server/lib/context-obligatory/runtime.test.js +76 -30
- package/server/lib/dictation/DOCUMENTATION.md +4 -1
- package/server/lib/dictation/openai-compatible-session.js +7 -0
- package/server/lib/enterprise-mode.d.ts +30 -0
- package/server/lib/enterprise-mode.js +253 -0
- package/server/lib/enterprise-mode.test.js +247 -0
- package/server/lib/event-stream/translate-v2.js +6 -0
- package/server/lib/event-stream/translate-v2.test.js +6 -0
- package/server/lib/git/DOCUMENTATION.md +2 -1
- package/server/lib/git/routes.js +44 -1
- package/server/lib/git/routes.test.js +98 -1
- package/server/lib/git/service.js +146 -11
- package/server/lib/git/service.test.js +195 -0
- package/server/lib/github/routes.js +9 -19
- package/server/lib/github/routes.test.js +112 -0
- package/server/lib/guests/DOCUMENTATION.md +4 -2
- package/server/lib/guests/background.test.js +1 -1
- package/server/lib/guests/catalog.js +56 -2
- package/server/lib/guests/catalog.test.js +24 -1
- package/server/lib/guests/clone-network.test.js +52 -0
- package/server/lib/guests/clone.js +30 -4
- package/server/lib/guests/enterprise.js +68 -0
- package/server/lib/guests/enterprise.test.js +106 -0
- package/server/lib/guests/grant-scope.js +8 -2
- package/server/lib/guests/grant-scope.test.js +9 -0
- package/server/lib/guests/html-styles.js +16 -2
- package/server/lib/guests/html-styles.test.js +53 -4
- package/server/lib/guests/install.js +10 -0
- package/server/lib/guests/persist.js +1 -0
- package/server/lib/guests/routes.js +40 -5
- package/server/lib/guests/updates.js +9 -2
- package/server/lib/notifications/DOCUMENTATION.md +1 -1
- package/server/lib/notifications/runtime.js +22 -8
- package/server/lib/notifications/trigger-runtime.test.js +45 -0
- package/server/lib/openchamber-sessions/session-metadata-store.js +27 -0
- package/server/lib/openchamber-sessions/session-metadata-store.test.js +18 -0
- package/server/lib/opencode/DOCUMENTATION.md +13 -9
- package/server/lib/opencode/auth-state-runtime.js +2 -2
- package/server/lib/opencode/config-paths.test.js +1 -0
- package/server/lib/opencode/env-runtime.js +26 -3
- package/server/lib/opencode/env-runtime.test.js +57 -0
- package/server/lib/opencode/feature-routes-runtime.js +2 -0
- package/server/lib/opencode/hmr-state-runtime.js +4 -3
- package/server/lib/opencode/lifecycle.js +10 -5
- package/server/lib/opencode/lifecycle.test.js +6 -2
- package/server/lib/opencode/managed-config-file.js +2 -1
- package/server/lib/opencode/managed-config-file.test.js +18 -0
- package/server/lib/opencode/npm-registry-config.d.ts +1 -0
- package/server/lib/opencode/npm-registry-config.js +123 -0
- package/server/lib/opencode/npm-registry-config.test.js +167 -0
- package/server/lib/opencode/npm-registry.js +5 -6
- package/server/lib/opencode/npm-registry.test.js +30 -0
- package/server/lib/opencode/openchamber-routes.js +8 -0
- package/server/lib/opencode/project-icon-routes.js +2 -2
- package/server/lib/opencode/project-icon-routes.test.js +44 -0
- package/server/lib/opencode/provider-source-route.test.js +32 -0
- package/server/lib/opencode/routes.js +17 -2
- package/server/lib/opencode/settings-helpers.js +26 -3
- package/server/lib/opencode/settings-helpers.test.js +12 -5
- package/server/lib/opencode/settings-registry.json +35 -1
- package/server/lib/opencode/settings-runtime.js +1 -0
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/static-routes-runtime.js +9 -1
- package/server/lib/opencode/static-routes-runtime.test.js +58 -1
- package/server/lib/package-manager.js +4 -1
- package/server/lib/package-manager.test.js +24 -0
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +23 -15
- package/server/lib/permission-auto-accept/modes.js +26 -0
- package/server/lib/permission-auto-accept/runtime.js +146 -40
- package/server/lib/permission-auto-accept/runtime.test.js +93 -9
- package/server/lib/quota/DOCUMENTATION.md +6 -0
- package/server/lib/quota/providers/zhipuai-coding-plan.js +74 -30
- package/server/lib/quota/providers/zhipuai-coding-plan.test.js +124 -0
- package/server/lib/relay/DOCUMENTATION.md +1 -1
- package/server/lib/relay/service.js +32 -12
- package/server/lib/relay/service.test.js +30 -0
- package/server/lib/routing/DOCUMENTATION.md +150 -41
- package/server/lib/routing/classifier.js +156 -0
- package/server/lib/routing/defaults.js +27 -0
- package/server/lib/routing/jev.js +5 -17
- package/server/lib/routing/routes.http.test.js +9 -0
- package/server/lib/routing/routes.js +27 -1
- package/server/lib/routing/runtime.js +199 -33
- package/server/lib/routing/runtime.test.js +299 -15
- package/server/lib/routing/store.js +57 -0
- package/server/lib/routing/store.test.js +37 -0
- package/server/lib/session-assist/DOCUMENTATION.md +17 -7
- package/server/lib/session-assist/context.js +42 -2
- package/server/lib/session-assist/context.test.js +38 -1
- package/server/lib/session-assist/runtime.js +57 -13
- package/server/lib/session-assist/runtime.test.js +45 -0
- package/server/lib/session-goal/DOCUMENTATION.md +47 -22
- package/server/lib/session-goal/audit.js +112 -0
- package/server/lib/session-goal/audit.test.js +58 -0
- package/server/lib/session-goal/runtime.js +113 -134
- package/server/lib/session-goal/runtime.test.js +146 -13
- package/server/lib/session-lineage.js +52 -0
- package/server/lib/session-lineage.test.js +45 -0
- package/server/lib/session-work/DOCUMENTATION.md +108 -0
- package/server/lib/session-work/questions.js +126 -0
- package/server/lib/session-work/runtime.js +278 -0
- package/server/lib/session-work/runtime.test.js +255 -0
- package/server/lib/session-work/state.js +48 -0
- package/server/lib/session-work/state.test.js +34 -0
- package/server/lib/small-model/DOCUMENTATION.md +14 -7
- package/server/lib/small-model/client.js +7 -4
- package/server/lib/small-model/index.js +11 -21
- package/server/lib/small-model/index.test.js +13 -26
- package/server/lib/spaces/DOCUMENTATION.md +79 -25
- package/server/lib/spaces/gatekeeper-channel.js +63 -11
- package/server/lib/spaces/gatekeeper-channel.test.js +34 -4
- package/server/lib/spaces/gatekeeper-program.cjs +64 -13
- package/server/lib/spaces/gatekeeper-program.test.js +115 -3
- package/server/lib/spaces/host.js +58 -13
- package/server/lib/spaces/host.test.js +34 -1
- package/server/lib/spaces/idle-stop.js +98 -0
- package/server/lib/spaces/idle-stop.test.js +130 -0
- package/server/lib/spaces/journey.js +427 -17
- package/server/lib/spaces/journey.test.js +592 -5
- package/server/lib/spaces/layout.js +27 -6
- package/server/lib/spaces/manager.test.js +1 -1
- package/server/lib/spaces/places/contract-suite.js +4 -2
- package/server/lib/spaces/places/docker-live-support.js +27 -4
- package/server/lib/spaces/places/docker.js +32 -5
- package/server/lib/spaces/places/docker.test.js +38 -8
- package/server/lib/spaces/places/escape-suite.js +32 -0
- package/server/lib/spaces/places/fake-docker.js +3 -1
- package/server/lib/spaces/places/grants.docker.live.test.js +197 -0
- package/server/lib/spaces/places/memory-place.js +3 -3
- package/server/lib/spaces/places/sessions.docker.live.test.js +4 -2
- package/server/lib/spaces/routes.js +49 -1
- package/server/lib/spaces/routes.test.js +31 -3
- package/server/lib/spaces/space-opencode.js +52 -0
- package/server/lib/spaces/space-opencode.test.js +41 -0
- package/server/lib/spaces/space-records.js +90 -2
- package/server/lib/spaces/space-records.test.js +58 -1
- package/server/lib/spaces/space-server.js +13 -1
- package/server/lib/spaces/space-server.test.js +13 -0
- package/server/lib/spaces/space-setup.js +173 -0
- package/server/lib/spaces/space-setup.test.js +174 -0
- package/server/lib/tts/DOCUMENTATION.md +3 -0
- package/server/lib/tts/base-url.js +8 -0
- package/server/lib/tts/routes.js +13 -1
- package/server/lib/tts/routes.test.js +26 -0
- package/server/lib/tunnels/DOCUMENTATION.md +2 -0
- package/server/lib/tunnels/routes.js +14 -0
- package/server/lib/tunnels/routes.test.js +26 -0
- package/server/lib/walkthrough/index.js +11 -7
- package/server/lib/walkthrough/jobs.test.js +8 -0
- package/server/lib/walkthrough/languages.js +1 -0
- package/server/lib/walkthrough/routes.js +7 -1
- package/dist/assets/FilesView-0Ie20mEk.js +0 -17
- package/dist/assets/LinearIssuesView-CSl2MUfA.js +0 -1
- package/dist/assets/MarkdownRendererImpl-DVHqZoug.js +0 -12
- package/dist/assets/OnboardingScreen-CIdXJpfc.js +0 -1
- package/dist/assets/PlanView-DEIi3Q7M.js +0 -5
- package/dist/assets/PluginPane-BEPUWVho.js +0 -3
- package/dist/assets/SettingsView-CiNh-RbW.js +0 -30
- package/dist/assets/WalkthroughView-6oE-MuDL.js +0 -4
- package/dist/assets/de-CgAJ51z7.js +0 -10
- package/dist/assets/es-zGi_ravM.js +0 -16
- package/dist/assets/fr-CPfogrWx.js +0 -14
- package/dist/assets/index-CHfphYL3.js +0 -41
- package/dist/assets/index-DvMJ3w6V.css +0 -1
- package/dist/assets/ja-DMk6wd-U.js +0 -16
- package/dist/assets/ko-BFpzJ8jc.js +0 -16
- package/dist/assets/main-anyZFMIs.js +0 -896
- package/dist/assets/markdownCore-CmM47cAE.js +0 -7
- package/dist/assets/pl-VdRPcZrB.js +0 -16
- package/dist/assets/pt-BR-BRys_lOW.js +0 -16
- package/dist/assets/renderElectronMiniChatApp-C5677jy0.js +0 -2
- package/dist/assets/renderMobileApp-D4dBBAqQ.js +0 -25
- package/dist/assets/runtimeEndpointReset-5r0hkd-2.js +0 -27
- package/dist/assets/tr-CA9ckNnm.js +0 -7
- package/dist/assets/uk-byjR-y8D.js +0 -16
- package/dist/assets/useAppFontEffects-BWQZ5DeI.js +0 -7341
- package/dist/assets/useInlineCommentController-DlFyVfBu.js +0 -2
- package/dist/assets/vendor-opencode-client-DYdsLbCM.js +0 -12
- package/dist/assets/zh-CN-DRabgxdG.js +0 -16
- package/dist/assets/zh-TW-rbY5c9UK.js +0 -16
|
@@ -10,6 +10,8 @@ import { afterEach, describe, expect, it } from 'vitest';
|
|
|
10
10
|
|
|
11
11
|
import { SpaceError } from './errors.js';
|
|
12
12
|
import { createSpaceJourney } from './journey.js';
|
|
13
|
+
import { ROLE_GATEKEEPER, spaceResourceName } from './labels.js';
|
|
14
|
+
import { IMAGE_TIMEOUT } from './layout.js';
|
|
13
15
|
import { createSpaceManager } from './manager.js';
|
|
14
16
|
import { createMemoryPlace } from './places/memory-place.js';
|
|
15
17
|
import { createPlaceRegistry } from './places/registry.js';
|
|
@@ -32,22 +34,41 @@ afterEach(() => {
|
|
|
32
34
|
});
|
|
33
35
|
|
|
34
36
|
/** A journey on fresh stand-ins. `failAt` names a stand-in step that rejects. */
|
|
35
|
-
const journeyWith = ({ failAt = null, place = createMemoryPlace(), projects = [PROJECT], historyStatus = 'sent', holdCodeIn = false, holdCodeOut = false } = {}) => {
|
|
37
|
+
const journeyWith = ({ failAt = null, place = createMemoryPlace(), projects = [PROJECT], historyStatus = 'sent', holdCodeIn = false, holdCodeOut = false, holdIdleSave = false, hostEnvironment = {}, dataDir = null } = {}) => {
|
|
36
38
|
// With `holdCodeIn`, code in waits until the test lets it go, so a creation stays under way;
|
|
37
39
|
// `holdCodeOut` does the same for the fetch of an apply.
|
|
38
40
|
let releaseCodeIn = () => {};
|
|
39
41
|
const codeInHeld = new Promise((resolve) => { releaseCodeIn = resolve; });
|
|
40
42
|
let releaseCodeOut = () => {};
|
|
41
43
|
const codeOutHeld = new Promise((resolve) => { releaseCodeOut = resolve; });
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
if (dataDir === null) {
|
|
45
|
+
dataDir = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-journey-'));
|
|
46
|
+
folders.push(dataDir);
|
|
47
|
+
}
|
|
44
48
|
const calls = [];
|
|
45
49
|
const events = [];
|
|
46
50
|
const changes = { count: 0 };
|
|
47
51
|
const fail = (step) => { if (failAt === step) throw new SpaceError(`${step}_failed`, `the stand-in for ${step} failed`); };
|
|
52
|
+
// The stand-in gatekeeper holds grant ids per space, like the program's memory: a stop forgets them.
|
|
53
|
+
const held = new Map();
|
|
48
54
|
const gatekeeper = {
|
|
49
55
|
setNetwork: async (spaceId, network) => { calls.push(['setNetwork', spaceId, network]); fail('setNetwork'); },
|
|
56
|
+
addGrant: async (spaceId, grant) => { calls.push(['addGrant', spaceId, grant]); fail('addGrant'); if (!held.has(spaceId)) held.set(spaceId, new Set()); held.get(spaceId).add(grant.id); },
|
|
57
|
+
readPolicy: async (spaceId) => { calls.push(['readPolicy', spaceId]); fail('readPolicy'); return { mode: 'allowlist', domains: [], grants: Array.from(held.get(spaceId) ?? []) }; },
|
|
50
58
|
readJournal: async (spaceId) => { calls.push(['readJournal', spaceId]); return { records: [], dropped: 0, since: '2026-09-26T10:00:00.000Z' }; },
|
|
59
|
+
forget: (spaceId) => { held.delete(spaceId); },
|
|
60
|
+
};
|
|
61
|
+
// The idle stop setting as the host keeps it, and each one said to a server inside, apart from
|
|
62
|
+
// `calls` so the order of the other steps reads as it did before 5d-3.
|
|
63
|
+
const idle = { saved: null, writes: [], release: () => {} };
|
|
64
|
+
const idleSaveHeld = new Promise((resolve) => { idle.release = resolve; });
|
|
65
|
+
const serverInside = {
|
|
66
|
+
writeToken: async (spaceId, token) => { calls.push(['writeToken', spaceId, token]); fail('writeToken'); },
|
|
67
|
+
writeIdleStop: async (spaceId, setting) => { fail('writeIdleStop'); idle.writes.push([spaceId, setting]); },
|
|
68
|
+
};
|
|
69
|
+
const restartOpenCodeInside = async (spaceId) => { calls.push(['restartOpenCodeInside', spaceId]); fail('restartOpenCodeInside'); };
|
|
70
|
+
const spaceOpenCode = {
|
|
71
|
+
writeProviderConfig: async (spaceId, grants) => { calls.push(['writeProviderConfig', spaceId, grants]); fail('writeProviderConfig'); },
|
|
51
72
|
};
|
|
52
73
|
const codeIn = {
|
|
53
74
|
bringCodeIn: async (request) => {
|
|
@@ -68,14 +89,17 @@ const journeyWith = ({ failAt = null, place = createMemoryPlace(), projects = [P
|
|
|
68
89
|
const records = createSpaceRecords({ dataDir, logger: quiet });
|
|
69
90
|
const manager = createSpaceManager({ registry: createPlaceRegistry([place]), now: () => new Date('2026-09-26T10:00:00.000Z') });
|
|
70
91
|
const journey = createSpaceJourney({
|
|
71
|
-
manager, place, gatekeeper, codeIn, codeOut, records,
|
|
92
|
+
manager, place, gatekeeper, codeIn, codeOut, records, spaceOpenCode, serverInside, restartOpenCodeInside,
|
|
72
93
|
listProjectDirectories: async () => projects,
|
|
94
|
+
readHostSecret: (name) => hostEnvironment[name],
|
|
95
|
+
readIdleStop: async () => idle.saved ?? { enabled: true, hours: 4 },
|
|
96
|
+
saveIdleStop: async (setting) => { if (holdIdleSave) await idleSaveHeld; fail('saveIdleStop'); idle.saved = setting; },
|
|
73
97
|
announce: (spaceId, payload) => { events.push({ spaceId, ...payload.properties }); },
|
|
74
98
|
onSpacesChanged: () => { changes.count += 1; },
|
|
75
99
|
logger: quiet,
|
|
76
100
|
now: () => new Date('2026-09-26T10:00:00.000Z'),
|
|
77
101
|
});
|
|
78
|
-
return { journey, place, records, calls, events, changes, manager, releaseCodeIn, releaseCodeOut };
|
|
102
|
+
return { journey, place, records, calls, events, changes, manager, releaseCodeIn, releaseCodeOut, gatekeeper, dataDir, idle };
|
|
79
103
|
};
|
|
80
104
|
|
|
81
105
|
const REQUEST = { projectDirectory: PROJECT, name: ' Fix login ', start: 'uncommitted', network: NETWORK };
|
|
@@ -253,6 +277,13 @@ describe('the journey: start, stop, remove', () => {
|
|
|
253
277
|
expect((await place.list()).map((space) => space.state).sort()).toEqual(['exited', 'exited', 'running']);
|
|
254
278
|
});
|
|
255
279
|
|
|
280
|
+
it('turns off without the list when the place cannot give one, and says it does not know what runs', async () => {
|
|
281
|
+
const { journey, place } = await ready();
|
|
282
|
+
place.list = async () => { throw new SpaceError('docker_command_failed', 'docker ps exited 1'); };
|
|
283
|
+
expect(await journey.stopAllSpaces()).toEqual({ stopped: [], stillRunning: [], unknown: { code: 'docker_command_failed', message: 'docker ps exited 1', details: null } });
|
|
284
|
+
await expect(journey.createSpace(REQUEST)).rejects.toMatchObject({ code: 'isolated_spaces_off' });
|
|
285
|
+
});
|
|
286
|
+
|
|
256
287
|
it('does not turn the switch off while a space is being made', async () => {
|
|
257
288
|
const { journey, events, releaseCodeIn } = journeyWith({ holdCodeIn: true });
|
|
258
289
|
const { id } = await journey.createSpace(REQUEST);
|
|
@@ -296,6 +327,335 @@ describe('the journey: start, stop, remove', () => {
|
|
|
296
327
|
});
|
|
297
328
|
});
|
|
298
329
|
|
|
330
|
+
describe('the journey: repair', () => {
|
|
331
|
+
const ready = async (options) => {
|
|
332
|
+
const made = journeyWith(options);
|
|
333
|
+
const { id } = await made.journey.createSpace(REQUEST);
|
|
334
|
+
await until(() => steps(made.events, id).includes('ready'));
|
|
335
|
+
await until(() => made.records.read(id).record?.history !== 'pending');
|
|
336
|
+
made.calls.splice(0);
|
|
337
|
+
return { ...made, id };
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
/** Damages the one space of a memory place after it was made: its gatekeeper missing, and gone for good or only stopped. */
|
|
341
|
+
const damage = (place, gatekeeper) => {
|
|
342
|
+
const list = place.list;
|
|
343
|
+
place.list = async () => (await list()).map((space) => ({ ...space, damaged: true, missing: [spaceResourceName(space.id, ROLE_GATEKEEPER)] }));
|
|
344
|
+
place.verify = async () => {
|
|
345
|
+
if (gatekeeper === 'unverifiable') throw new SpaceError('command_failed', 'docker did not answer');
|
|
346
|
+
return gatekeeper === 'gone' ? [{ check: 'gatekeeper_missing', message: 'The space has no gatekeeper container' }] : [];
|
|
347
|
+
};
|
|
348
|
+
};
|
|
349
|
+
|
|
350
|
+
it('restarts OpenCode inside a running space and nothing else', async () => {
|
|
351
|
+
const { journey, calls, id } = await ready();
|
|
352
|
+
expect(await journey.restartOpenCode(id)).toMatchObject({ id, state: 'running' });
|
|
353
|
+
expect(calls).toEqual([['restartOpenCodeInside', id]]);
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it('restarts the container with a fresh token written first, then stops and starts it with its network said again', async () => {
|
|
357
|
+
const { journey, place, calls, id } = await ready();
|
|
358
|
+
// The place's own steps, in the order they came, beside the stand-ins': the server inside
|
|
359
|
+
// reads the new token only when the container starts again after a stop.
|
|
360
|
+
for (const step of ['stop', 'start']) {
|
|
361
|
+
const run = place[step];
|
|
362
|
+
place[step] = async (spaceId) => { calls.push([step, spaceId]); return run(spaceId); };
|
|
363
|
+
}
|
|
364
|
+
const started = await journey.restartSpace(id);
|
|
365
|
+
expect(started).toMatchObject({ id, state: 'running', networkRestored: true });
|
|
366
|
+
expect(calls.map(([name]) => name)).toEqual(['writeToken', 'stop', 'start', 'setNetwork']);
|
|
367
|
+
expect(calls[0][2]).toMatch(/^[A-Za-z0-9_-]{43}$/);
|
|
368
|
+
expect(await place.list()).toEqual([expect.objectContaining({ state: 'running' })]);
|
|
369
|
+
// A second restart writes another token.
|
|
370
|
+
const first = calls[0][2];
|
|
371
|
+
calls.splice(0);
|
|
372
|
+
await journey.restartSpace(id);
|
|
373
|
+
expect(calls[0][0]).toBe('writeToken');
|
|
374
|
+
expect(calls[0][2]).not.toBe(first);
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
it('restarts the container even when the token could not be written, because the token is no secret from the agent', async () => {
|
|
378
|
+
const { journey, calls, id } = await ready({ failAt: 'writeToken' });
|
|
379
|
+
expect(await journey.restartSpace(id)).toMatchObject({ id, state: 'running', networkRestored: true });
|
|
380
|
+
expect(calls.map(([name]) => name)).toEqual(['writeToken', 'setNetwork']);
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it('refuses both restarts for a stopped space, and says why OpenCode did not restart', async () => {
|
|
384
|
+
const { journey, calls, id } = await ready();
|
|
385
|
+
await journey.stopSpace(id);
|
|
386
|
+
await expect(journey.restartSpace(id)).rejects.toMatchObject({ code: 'space_not_running' });
|
|
387
|
+
await expect(journey.restartOpenCode(id)).rejects.toMatchObject({ code: 'space_not_running' });
|
|
388
|
+
expect(calls).toEqual([]);
|
|
389
|
+
|
|
390
|
+
const failing = await ready({ failAt: 'restartOpenCodeInside' });
|
|
391
|
+
await expect(failing.journey.restartOpenCode(failing.id)).rejects.toMatchObject({ code: 'restartOpenCodeInside_failed' });
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it('lists what is broken: nothing, a gatekeeper that a restart brings back, or one that is gone for good', async () => {
|
|
395
|
+
const healthy = await ready();
|
|
396
|
+
expect((await healthy.journey.listSpaces())[0]).toMatchObject({ damaged: false, damage: null });
|
|
397
|
+
|
|
398
|
+
for (const [gatekeeper, expected] of [['stopped', 'repairable'], ['gone', 'gatekeeper_gone'], ['unverifiable', 'repairable']]) {
|
|
399
|
+
const { journey, place } = await ready();
|
|
400
|
+
damage(place, gatekeeper);
|
|
401
|
+
expect((await journey.listSpaces())[0]).toMatchObject({ damaged: true, damage: expected });
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
describe('the journey: opening a domain', () => {
|
|
407
|
+
const ready = async (options = {}, request = REQUEST) => {
|
|
408
|
+
const made = journeyWith(options);
|
|
409
|
+
const { id } = await made.journey.createSpace(request);
|
|
410
|
+
await until(() => steps(made.events, id).includes('ready'));
|
|
411
|
+
made.calls.splice(0);
|
|
412
|
+
return { ...made, id };
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
it('tells the gatekeeper the allowlist with the domain, then remembers it for the next start', async () => {
|
|
416
|
+
const { journey, records, calls, id } = await ready();
|
|
417
|
+
expect(await journey.openDomain(id, { domain: ' Registry.NPMJS.org ' })).toEqual({ network: { mode: 'allowlist', domains: ['api.anthropic.com', 'registry.npmjs.org'] } });
|
|
418
|
+
expect(calls).toEqual([['setNetwork', id, { mode: 'allowlist', domains: ['api.anthropic.com', 'registry.npmjs.org'] }]]);
|
|
419
|
+
expect(records.read(id).record.network.domains).toEqual(['api.anthropic.com', 'registry.npmjs.org']);
|
|
420
|
+
|
|
421
|
+
// A domain already on the list changes nothing.
|
|
422
|
+
calls.splice(0);
|
|
423
|
+
expect(await journey.openDomain(id, { domain: 'registry.npmjs.org' })).toEqual({ network: { mode: 'allowlist', domains: ['api.anthropic.com', 'registry.npmjs.org'] } });
|
|
424
|
+
expect(calls).toEqual([]);
|
|
425
|
+
|
|
426
|
+
// The next start says the list with the opened domain again.
|
|
427
|
+
await journey.stopSpace(id);
|
|
428
|
+
calls.splice(0);
|
|
429
|
+
await journey.startSpace(id);
|
|
430
|
+
expect(calls.find(([name]) => name === 'setNetwork')).toEqual(['setNetwork', id, { mode: 'allowlist', domains: ['api.anthropic.com', 'registry.npmjs.org'] }]);
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
it('refuses what is not a name, a stopped space, an open network, and a record it cannot read, telling the gatekeeper nothing', async () => {
|
|
434
|
+
const { journey, records, calls, id } = await ready();
|
|
435
|
+
for (const domain of ['', 'localhost', '10.0.0.1', '1746020849', 'a_b.example.com', 'example.com/path', 'https://example.com', '*.example.com']) {
|
|
436
|
+
await expect(journey.openDomain(id, { domain }), domain).rejects.toMatchObject({ code: 'invalid_domain' });
|
|
437
|
+
}
|
|
438
|
+
await expect(journey.openDomain(id, { domain: 'example.com', extra: 1 })).rejects.toMatchObject({ code: 'invalid_domain' });
|
|
439
|
+
await expect(journey.openDomain(id, null)).rejects.toMatchObject({ code: 'invalid_domain' });
|
|
440
|
+
records.update(id, { network: { mode: 'open', domains: [] } });
|
|
441
|
+
await expect(journey.openDomain(id, { domain: 'example.com' })).rejects.toMatchObject({ code: 'network_is_open' });
|
|
442
|
+
records.remove(id);
|
|
443
|
+
await expect(journey.openDomain(id, { domain: 'example.com' })).rejects.toMatchObject({ code: 'space_record_unreadable' });
|
|
444
|
+
await journey.stopSpace(id);
|
|
445
|
+
await expect(journey.openDomain(id, { domain: 'example.com' })).rejects.toMatchObject({ code: 'space_not_running' });
|
|
446
|
+
expect(calls.filter(([name]) => name === 'setNetwork')).toEqual([]);
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
it('does not remember a domain the gatekeeper did not take', async () => {
|
|
450
|
+
const { records, place, dataDir, id } = await ready();
|
|
451
|
+
// A second journey over the same place and records, whose gatekeeper refuses the change.
|
|
452
|
+
const failing = journeyWith({ place, dataDir, failAt: 'setNetwork' });
|
|
453
|
+
await expect(failing.journey.openDomain(id, { domain: 'example.com' })).rejects.toMatchObject({ code: 'setNetwork_failed' });
|
|
454
|
+
expect(records.read(id).record.network.domains).toEqual(['api.anthropic.com']);
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
it('refuses a domain past the size of a list', async () => {
|
|
458
|
+
const { journey, records, calls, id } = await ready();
|
|
459
|
+
records.update(id, { network: { mode: 'allowlist', domains: Array.from({ length: 200 }, (_, index) => `d${index}.example.com`) } });
|
|
460
|
+
await expect(journey.openDomain(id, { domain: 'one-more.example.com' })).rejects.toMatchObject({ code: 'too_many_domains' });
|
|
461
|
+
expect(calls).toEqual([]);
|
|
462
|
+
});
|
|
463
|
+
});
|
|
464
|
+
|
|
465
|
+
describe('the journey: grants', () => {
|
|
466
|
+
const KEY = 'sk-live-typed-once';
|
|
467
|
+
const ENV_KEY = 'sk-live-from-the-host-environment';
|
|
468
|
+
const ready = async (options) => {
|
|
469
|
+
const made = journeyWith(options);
|
|
470
|
+
const { id } = await made.journey.createSpace(REQUEST);
|
|
471
|
+
await until(() => steps(made.events, id).includes('ready'));
|
|
472
|
+
await until(() => made.records.read(id).record?.history !== 'pending');
|
|
473
|
+
made.calls.splice(0);
|
|
474
|
+
return { ...made, id };
|
|
475
|
+
};
|
|
476
|
+
const anthropic = { kind: 'model', provider: 'anthropic', upstream: 'https://api.anthropic.com/v1', secret: { kind: 'typed', value: KEY } };
|
|
477
|
+
const openai = { kind: 'model', provider: 'openai', upstream: 'https://api.openai.com/v1', secret: { kind: 'env', name: 'OPENAI_API_KEY' } };
|
|
478
|
+
const registry = { kind: 'domain', upstream: 'https://registry.example.com/npm/' };
|
|
479
|
+
|
|
480
|
+
it('gives a model key to the gatekeeper, remembers the grant without the key, and points OpenCode inside at the window', async () => {
|
|
481
|
+
const { journey, records, calls, id } = await ready({ hostEnvironment: { OPENAI_API_KEY: ENV_KEY } });
|
|
482
|
+
const typed = await journey.grantAccess(id, anthropic);
|
|
483
|
+
expect(typed).toEqual({ grant: { kind: 'model', id: 'anthropic', provider: 'anthropic', upstream: 'https://api.anthropic.com/v1', header: 'x-api-key', source: { kind: 'typed' }, url: 'http://gatekeeper:8080/model/anthropic' } });
|
|
484
|
+
const fromEnv = await journey.grantAccess(id, openai);
|
|
485
|
+
expect(fromEnv.grant).toMatchObject({ id: 'openai', header: 'authorization', source: { kind: 'env', name: 'OPENAI_API_KEY' } });
|
|
486
|
+
|
|
487
|
+
expect(calls).toEqual([
|
|
488
|
+
['addGrant', id, { id: 'anthropic', upstream: 'https://api.anthropic.com/v1', header: 'x-api-key', secret: KEY }],
|
|
489
|
+
['writeProviderConfig', id, [expect.objectContaining({ id: 'anthropic' })]],
|
|
490
|
+
['addGrant', id, { id: 'openai', upstream: 'https://api.openai.com/v1', header: 'authorization', secret: ENV_KEY }],
|
|
491
|
+
['writeProviderConfig', id, [expect.objectContaining({ id: 'anthropic' }), expect.objectContaining({ id: 'openai' })]],
|
|
492
|
+
]);
|
|
493
|
+
// The record holds both grants and neither key, in the file as on the way out.
|
|
494
|
+
const { record } = records.read(id);
|
|
495
|
+
expect(record.grants.map((grant) => grant.id)).toEqual(['anthropic', 'openai']);
|
|
496
|
+
const onDisk = JSON.stringify(record);
|
|
497
|
+
expect(onDisk).not.toContain(KEY);
|
|
498
|
+
expect(onDisk).not.toContain(ENV_KEY);
|
|
499
|
+
expect(JSON.stringify(await journey.listSpaces({ access: true }))).not.toContain(KEY);
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
it('replaces the grant of the same provider, and opens a domain with no key and no header', async () => {
|
|
503
|
+
const { journey, records, calls, id } = await ready();
|
|
504
|
+
await journey.grantAccess(id, anthropic);
|
|
505
|
+
await journey.grantAccess(id, { ...anthropic, secret: { kind: 'typed', value: 'sk-live-newer' } });
|
|
506
|
+
expect(records.read(id).record.grants).toHaveLength(1);
|
|
507
|
+
expect(calls.filter(([name]) => name === 'addGrant').at(-1)[2].secret).toBe('sk-live-newer');
|
|
508
|
+
|
|
509
|
+
calls.splice(0);
|
|
510
|
+
const opened = await journey.grantAccess(id, registry);
|
|
511
|
+
expect(opened.grant).toEqual({ kind: 'domain', id: expect.stringMatching(/^open-[0-9a-f]{12}$/), upstream: 'https://registry.example.com/npm/', url: `http://gatekeeper:8080/model/${opened.grant.id}` });
|
|
512
|
+
// No header, no secret, and OpenCode inside is not told about a domain.
|
|
513
|
+
expect(calls).toEqual([['addGrant', id, { id: opened.grant.id, upstream: 'https://registry.example.com/npm/', header: null, secret: null }]]);
|
|
514
|
+
expect(records.read(id).record.grants.map((grant) => grant.kind)).toEqual(['model', 'domain']);
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
it('refuses a grant it cannot give: a bad request, a stopped space, a key the host cannot find, a record it cannot read', async () => {
|
|
518
|
+
const { journey, records, calls, id } = await ready();
|
|
519
|
+
for (const bad of [
|
|
520
|
+
{ kind: 'model', provider: 'anthropic', upstream: 'https://api.anthropic.com/v1' },
|
|
521
|
+
{ kind: 'model', provider: 'anthropic', upstream: 'ftp://api.anthropic.com/v1', secret: { kind: 'typed', value: KEY } },
|
|
522
|
+
{ kind: 'model', provider: 'anthropic', upstream: 'not a url', secret: { kind: 'typed', value: KEY } },
|
|
523
|
+
{ kind: 'domain', upstream: 'not a url' },
|
|
524
|
+
{ kind: 'model', provider: '../x', upstream: 'https://api.anthropic.com/v1', secret: { kind: 'typed', value: KEY } },
|
|
525
|
+
{ kind: 'model', provider: 'anthropic', upstream: 'https://api.anthropic.com/v1', secret: { kind: 'typed', value: '' } },
|
|
526
|
+
{ kind: 'model', provider: 'anthropic', upstream: 'https://api.anthropic.com/v1', secret: { kind: 'env', name: 'not a name' } },
|
|
527
|
+
{ kind: 'model', provider: 'anthropic', upstream: 'https://api.anthropic.com/v1', secret: { kind: 'file', name: '/tmp/key' } },
|
|
528
|
+
{ kind: 'domain', upstream: 'https://registry.example.com/', secret: { kind: 'typed', value: KEY } },
|
|
529
|
+
{ kind: 'ssh' },
|
|
530
|
+
null,
|
|
531
|
+
]) {
|
|
532
|
+
await expect(journey.grantAccess(id, bad), JSON.stringify(bad)).rejects.toMatchObject({ code: 'invalid_grant_request' });
|
|
533
|
+
}
|
|
534
|
+
await expect(journey.grantAccess(id, openai)).rejects.toMatchObject({ code: 'secret_source_missing', message: expect.stringContaining('OPENAI_API_KEY') });
|
|
535
|
+
// A provider that reads its key another way is refused, never accepted to fail every turn.
|
|
536
|
+
await expect(journey.grantAccess(id, { ...anthropic, provider: 'azure' })).rejects.toMatchObject({ code: 'provider_not_supported' });
|
|
537
|
+
expect(calls).toEqual([]);
|
|
538
|
+
expect(records.read(id).record.grants).toEqual([]);
|
|
539
|
+
|
|
540
|
+
records.remove(id);
|
|
541
|
+
await expect(journey.grantAccess(id, anthropic)).rejects.toMatchObject({ code: 'space_record_unreadable' });
|
|
542
|
+
await journey.stopSpace(id);
|
|
543
|
+
await expect(journey.grantAccess(id, anthropic)).rejects.toMatchObject({ code: 'space_not_running' });
|
|
544
|
+
expect(calls.filter(([name]) => name === 'addGrant')).toEqual([]);
|
|
545
|
+
await expect(journey.grantAccess('0f0f0f0f0f0f', anthropic)).rejects.toMatchObject({ code: 'space_not_found' });
|
|
546
|
+
});
|
|
547
|
+
|
|
548
|
+
it('keeps a grant whose configuration inside was not written, and writes it again at the next start', async () => {
|
|
549
|
+
const { journey, records, calls, place, dataDir, id } = await ready();
|
|
550
|
+
// A second journey over the same place and records, whose write inside fails.
|
|
551
|
+
const failing = journeyWith({ place, dataDir, failAt: 'writeProviderConfig' });
|
|
552
|
+
await expect(failing.journey.grantAccess(id, anthropic)).rejects.toMatchObject({ code: 'writeProviderConfig_failed' });
|
|
553
|
+
// The key reached the gatekeeper and the grant is remembered: only the cooperation inside is missing.
|
|
554
|
+
expect(records.read(id).record.grants.map((grant) => grant.id)).toEqual(['anthropic']);
|
|
555
|
+
|
|
556
|
+
await journey.stopSpace(id);
|
|
557
|
+
calls.splice(0);
|
|
558
|
+
await journey.startSpace(id);
|
|
559
|
+
expect(calls.filter(([name]) => name === 'writeProviderConfig')).toEqual([['writeProviderConfig', id, [expect.objectContaining({ id: 'anthropic' })]]]);
|
|
560
|
+
// And a start whose write fails still starts.
|
|
561
|
+
await failing.journey.stopSpace(id);
|
|
562
|
+
expect(await failing.journey.startSpace(id)).toMatchObject({ state: 'running', networkRestored: true });
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it('says nothing about access while an action holds the space', async () => {
|
|
566
|
+
const { journey, id, releaseCodeOut } = await ready({ holdCodeOut: true });
|
|
567
|
+
await journey.grantAccess(id, registry);
|
|
568
|
+
expect((await journey.listSpaces({ access: true }))[0]).toMatchObject({ access: 'granted' });
|
|
569
|
+
const applying = journey.applySpace(id, { as: 'changes' });
|
|
570
|
+
await sleep(20);
|
|
571
|
+
expect((await journey.listSpaces({ access: true }))[0]).toMatchObject({ access: null, needsAccess: [] });
|
|
572
|
+
releaseCodeOut();
|
|
573
|
+
await applying;
|
|
574
|
+
expect((await journey.listSpaces({ access: true }))[0]).toMatchObject({ access: 'granted' });
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
it('does not remember a grant the gatekeeper refused', async () => {
|
|
578
|
+
const { journey, records, id } = await ready({ failAt: 'addGrant' });
|
|
579
|
+
await expect(journey.grantAccess(id, anthropic)).rejects.toMatchObject({ code: 'addGrant_failed' });
|
|
580
|
+
expect(records.read(id).record.grants).toEqual([]);
|
|
581
|
+
});
|
|
582
|
+
|
|
583
|
+
it('says the grants again after a start: from the host environment yes, a typed key no, a domain yes', async () => {
|
|
584
|
+
const { journey, calls, gatekeeper, id } = await ready({ hostEnvironment: { OPENAI_API_KEY: ENV_KEY } });
|
|
585
|
+
await journey.grantAccess(id, anthropic);
|
|
586
|
+
await journey.grantAccess(id, openai);
|
|
587
|
+
const opened = await journey.grantAccess(id, registry);
|
|
588
|
+
expect((await journey.listSpaces({ access: true }))[0]).toMatchObject({ access: 'granted', needsAccess: [] });
|
|
589
|
+
|
|
590
|
+
await journey.stopSpace(id);
|
|
591
|
+
gatekeeper.forget(id);
|
|
592
|
+
calls.splice(0);
|
|
593
|
+
const started = await journey.startSpace(id);
|
|
594
|
+
expect(started).toMatchObject({ networkRestored: true, grantsRestored: ['openai', opened.grant.id], needsAccess: ['anthropic'], access: null });
|
|
595
|
+
expect(calls.filter(([name]) => name === 'addGrant')).toEqual([
|
|
596
|
+
['addGrant', id, { id: 'openai', upstream: 'https://api.openai.com/v1', header: 'authorization', secret: ENV_KEY }],
|
|
597
|
+
['addGrant', id, { id: opened.grant.id, upstream: 'https://registry.example.com/npm/', header: null, secret: null }],
|
|
598
|
+
]);
|
|
599
|
+
// The typed key is not in anything the start sent or wrote.
|
|
600
|
+
expect(JSON.stringify(calls)).not.toContain(KEY);
|
|
601
|
+
// OpenCode's configuration inside is written again from the record, with both model grants,
|
|
602
|
+
// so a write that failed at the grant is repaired here. It holds no key.
|
|
603
|
+
expect(calls.filter(([name]) => name === 'writeProviderConfig')).toEqual([['writeProviderConfig', id, [expect.objectContaining({ id: 'anthropic' }), expect.objectContaining({ id: 'openai' }), expect.objectContaining({ id: opened.grant.id })]]]);
|
|
604
|
+
|
|
605
|
+
// The list asks the gatekeeper and says which grant needs the user again.
|
|
606
|
+
const listed = (await journey.listSpaces({ access: true }))[0];
|
|
607
|
+
expect(listed).toMatchObject({ access: 'needs_access', needsAccess: ['anthropic'] });
|
|
608
|
+
expect(listed.grants.map((grant) => grant.id)).toEqual(['anthropic', 'openai', opened.grant.id]);
|
|
609
|
+
// Granting once more clears it.
|
|
610
|
+
await journey.grantAccess(id, anthropic);
|
|
611
|
+
expect((await journey.listSpaces({ access: true }))[0]).toMatchObject({ access: 'granted', needsAccess: [] });
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
it('needs the user again after a start when the host environment no longer has the key, and when the gatekeeper refuses', async () => {
|
|
615
|
+
const withKey = await ready({ hostEnvironment: { OPENAI_API_KEY: ENV_KEY } });
|
|
616
|
+
await withKey.journey.grantAccess(withKey.id, openai);
|
|
617
|
+
await withKey.journey.stopSpace(withKey.id);
|
|
618
|
+
withKey.gatekeeper.forget(withKey.id);
|
|
619
|
+
// The same records, read by a journey whose host has no such variable now: nothing is sent, and the start says so.
|
|
620
|
+
const without = journeyWith({ place: withKey.place, dataDir: withKey.dataDir, hostEnvironment: {} });
|
|
621
|
+
expect(await without.journey.startSpace(withKey.id)).toMatchObject({ state: 'running', networkRestored: true, grantsRestored: [], needsAccess: ['openai'] });
|
|
622
|
+
expect(without.calls.filter(([name]) => name === 'addGrant')).toEqual([]);
|
|
623
|
+
expect((await without.journey.listSpaces({ access: true }))[0]).toMatchObject({ access: 'needs_access', needsAccess: ['openai'] });
|
|
624
|
+
|
|
625
|
+
// A gatekeeper that refuses the grant at the start leaves the space running and the grant missing, never "restored".
|
|
626
|
+
const refusing = await ready({ hostEnvironment: { OPENAI_API_KEY: ENV_KEY } });
|
|
627
|
+
await refusing.journey.grantAccess(refusing.id, openai);
|
|
628
|
+
await refusing.journey.stopSpace(refusing.id);
|
|
629
|
+
refusing.gatekeeper.forget(refusing.id);
|
|
630
|
+
refusing.gatekeeper.addGrant = async () => { throw new SpaceError('gatekeeper_refused', 'The gatekeeper refused to add the grant'); };
|
|
631
|
+
expect(await refusing.journey.startSpace(refusing.id)).toMatchObject({ state: 'running', grantsRestored: [], needsAccess: ['openai'] });
|
|
632
|
+
expect((await refusing.journey.listSpaces({ access: true }))[0]).toMatchObject({ access: 'needs_access', needsAccess: ['openai'] });
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
it('asks the gatekeeper only where there is something to ask, and never calls a failed read "granted"', async () => {
|
|
636
|
+
const { journey, calls, id, manager, place } = await ready();
|
|
637
|
+
const empty = await manager.createSpace({ placeId: 'memory', projectDirectory: PROJECT, name: 'No grants' });
|
|
638
|
+
await place.stop(empty.id);
|
|
639
|
+
calls.splice(0);
|
|
640
|
+
// Not asked: no grants on the first, the second is stopped, and nobody asked for access.
|
|
641
|
+
expect((await journey.listSpaces()).map((space) => space.access)).toEqual([null, null]);
|
|
642
|
+
expect((await journey.listSpaces({ access: true })).map((space) => space.access)).toEqual([null, null]);
|
|
643
|
+
expect(calls.filter(([name]) => name === 'readPolicy')).toEqual([]);
|
|
644
|
+
|
|
645
|
+
await journey.grantAccess(id, anthropic);
|
|
646
|
+
calls.splice(0);
|
|
647
|
+
expect((await journey.listSpaces({ access: true }))[0]).toMatchObject({ access: 'granted' });
|
|
648
|
+
expect(calls.filter(([name]) => name === 'readPolicy')).toEqual([['readPolicy', id]]);
|
|
649
|
+
// A stopped space with grants is not asked either: its gatekeeper holds nothing and the next start says the grants again.
|
|
650
|
+
await journey.stopSpace(id);
|
|
651
|
+
expect((await journey.listSpaces({ access: true }))[0]).toMatchObject({ state: 'exited', access: null, grants: [expect.objectContaining({ id: 'anthropic' })] });
|
|
652
|
+
|
|
653
|
+
const failing = await ready({ failAt: 'readPolicy' });
|
|
654
|
+
await failing.journey.grantAccess(failing.id, anthropic);
|
|
655
|
+
expect((await failing.journey.listSpaces({ access: true }))[0]).toMatchObject({ access: 'unknown', needsAccess: [] });
|
|
656
|
+
});
|
|
657
|
+
});
|
|
658
|
+
|
|
299
659
|
describe('the journey: journal and apply', () => {
|
|
300
660
|
const ready = async (options) => {
|
|
301
661
|
const made = journeyWith(options);
|
|
@@ -382,3 +742,230 @@ describe('the journey: journal and apply', () => {
|
|
|
382
742
|
expect((await orphan.journey.listSpaces())[0]).toMatchObject({ id: other.id, projectDirectory: null, directory: null });
|
|
383
743
|
});
|
|
384
744
|
});
|
|
745
|
+
|
|
746
|
+
describe('the journey: idle stop', () => {
|
|
747
|
+
const ready = async (options) => {
|
|
748
|
+
const made = journeyWith(options);
|
|
749
|
+
const { id } = await made.journey.createSpace(REQUEST);
|
|
750
|
+
await until(() => steps(made.events, id).includes('ready'));
|
|
751
|
+
await until(() => made.records.read(id).record?.history !== 'pending');
|
|
752
|
+
made.calls.splice(0);
|
|
753
|
+
return { ...made, id };
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
/** The place's own stops, recorded, and its list as an idle stop leaves it: the space exited, its gatekeeper running. */
|
|
757
|
+
const idleStopped = (place, { gatekeeperRunning = true } = {}) => {
|
|
758
|
+
const stops = [];
|
|
759
|
+
const { list, stop } = place;
|
|
760
|
+
let stray = gatekeeperRunning;
|
|
761
|
+
place.list = async () => (await list()).map((space) => ({ ...space, state: 'exited', stoppedIdle: true, gatekeeperRunning: stray }));
|
|
762
|
+
place.stop = async (spaceId) => { stops.push(spaceId); stray = false; return stop(spaceId); };
|
|
763
|
+
return stops;
|
|
764
|
+
};
|
|
765
|
+
|
|
766
|
+
it('tells the server inside the setting when the space is made and at every start and restart', async () => {
|
|
767
|
+
const { journey, id, idle } = await ready();
|
|
768
|
+
expect(idle.writes).toEqual([[id, { enabled: true, hours: 4 }]]);
|
|
769
|
+
idle.saved = { enabled: true, hours: 9 };
|
|
770
|
+
await journey.stopSpace(id);
|
|
771
|
+
await journey.startSpace(id);
|
|
772
|
+
await journey.restartSpace(id);
|
|
773
|
+
expect(idle.writes.slice(1)).toEqual([[id, { enabled: true, hours: 9 }], [id, { enabled: true, hours: 9 }]]);
|
|
774
|
+
});
|
|
775
|
+
|
|
776
|
+
it('makes and starts a space whose setting could not be written, because the setting guards nothing', async () => {
|
|
777
|
+
const { journey, id, idle } = await ready({ failAt: 'writeIdleStop' });
|
|
778
|
+
expect((await journey.listSpaces())[0]).toMatchObject({ id, state: 'running' });
|
|
779
|
+
await journey.stopSpace(id);
|
|
780
|
+
expect(await journey.startSpace(id)).toMatchObject({ id, state: 'running', networkRestored: true });
|
|
781
|
+
expect(idle.writes).toEqual([]);
|
|
782
|
+
});
|
|
783
|
+
|
|
784
|
+
it('keeps a changed setting and tells every running space, and only the running ones', async () => {
|
|
785
|
+
const { journey, id, idle } = await ready();
|
|
786
|
+
const { id: other } = await journey.createSpace(REQUEST);
|
|
787
|
+
await until(() => idle.writes.some(([spaceId]) => spaceId === other));
|
|
788
|
+
await journey.stopSpace(other);
|
|
789
|
+
idle.writes.splice(0);
|
|
790
|
+
|
|
791
|
+
expect(await journey.changeIdleStop({ enabled: false, hours: 12 })).toEqual({ enabled: false, hours: 12 });
|
|
792
|
+
expect(idle.saved).toEqual({ enabled: false, hours: 12 });
|
|
793
|
+
expect(idle.writes).toEqual([[id, { enabled: false, hours: 12 }]]);
|
|
794
|
+
expect(await journey.readIdleStopSetting()).toEqual({ enabled: false, hours: 12 });
|
|
795
|
+
});
|
|
796
|
+
|
|
797
|
+
it('applies changes one after the other, so a space ends with the last one', async () => {
|
|
798
|
+
const { journey, id, idle } = await ready();
|
|
799
|
+
idle.writes.splice(0);
|
|
800
|
+
await Promise.all([1, 2, 3].map((hours) => journey.changeIdleStop({ enabled: true, hours })));
|
|
801
|
+
expect(idle.writes).toEqual([1, 2, 3].map((hours) => [id, { enabled: true, hours }]));
|
|
802
|
+
expect(idle.saved).toEqual({ enabled: true, hours: 3 });
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
it('refuses a setting outside the whole hours from 1 to 168, and keeps nothing of it', async () => {
|
|
806
|
+
const { journey, idle } = await ready();
|
|
807
|
+
for (const request of [{ enabled: true, hours: 0 }, { enabled: true, hours: 169 }, { enabled: true, hours: 1.5 }, { enabled: 'yes', hours: 4 }, { enabled: true }, { enabled: true, hours: 4, extra: 1 }, null]) {
|
|
808
|
+
await expect(journey.changeIdleStop(request)).rejects.toMatchObject({ code: 'invalid_idle_stop' });
|
|
809
|
+
}
|
|
810
|
+
expect(idle.saved).toBeNull();
|
|
811
|
+
});
|
|
812
|
+
|
|
813
|
+
it('writes nothing to the spaces when the setting could not be kept', async () => {
|
|
814
|
+
const { journey, idle } = await ready({ failAt: 'saveIdleStop' });
|
|
815
|
+
idle.writes.splice(0);
|
|
816
|
+
await expect(journey.changeIdleStop({ enabled: true, hours: 2 })).rejects.toMatchObject({ code: 'saveIdleStop_failed' });
|
|
817
|
+
expect(idle.writes).toEqual([]);
|
|
818
|
+
});
|
|
819
|
+
|
|
820
|
+
it('lists a space that stopped itself as such, and stops the gatekeeper it left running once', async () => {
|
|
821
|
+
const { journey, place, id } = await ready();
|
|
822
|
+
const stops = idleStopped(place);
|
|
823
|
+
expect((await journey.listSpaces())[0]).toMatchObject({ id, state: 'exited', stoppedIdle: true });
|
|
824
|
+
expect(await until(() => stops.length === 1)).toBe(true);
|
|
825
|
+
await journey.listSpaces();
|
|
826
|
+
await sleep(20);
|
|
827
|
+
expect(stops).toEqual([id]);
|
|
828
|
+
});
|
|
829
|
+
|
|
830
|
+
it('leaves a stopped space alone when its gatekeeper is down already, or while another action holds it', async () => {
|
|
831
|
+
const quietSpace = await ready();
|
|
832
|
+
const quietStops = idleStopped(quietSpace.place, { gatekeeperRunning: false });
|
|
833
|
+
await quietSpace.journey.listSpaces();
|
|
834
|
+
await sleep(20);
|
|
835
|
+
expect(quietStops).toEqual([]);
|
|
836
|
+
|
|
837
|
+
const held = await ready({ holdCodeOut: true });
|
|
838
|
+
const heldStops = idleStopped(held.place);
|
|
839
|
+
const apply = held.journey.previewApply(held.id);
|
|
840
|
+
await held.journey.listSpaces();
|
|
841
|
+
await sleep(20);
|
|
842
|
+
expect(heldStops).toEqual([]);
|
|
843
|
+
held.releaseCodeOut();
|
|
844
|
+
await apply;
|
|
845
|
+
});
|
|
846
|
+
|
|
847
|
+
it('lets a start wait for a gatekeeper being stopped beside its space, rather than refusing it as busy', async () => {
|
|
848
|
+
const { journey, place, id } = await ready();
|
|
849
|
+
idleStopped(place);
|
|
850
|
+
const order = [];
|
|
851
|
+
const { stop, start } = place;
|
|
852
|
+
let letGo = () => {};
|
|
853
|
+
place.stop = (spaceId) => new Promise((resolve) => { letGo = resolve; }).then(() => stop(spaceId)).then(() => { order.push('gatekeeper stopped'); });
|
|
854
|
+
place.start = async (spaceId) => { order.push('start'); return start(spaceId); };
|
|
855
|
+
await journey.listSpaces();
|
|
856
|
+
const started = journey.startSpace(id);
|
|
857
|
+
await sleep(20);
|
|
858
|
+
expect(order).toEqual([]);
|
|
859
|
+
letGo();
|
|
860
|
+
await expect(started).resolves.toMatchObject({ id, networkRestored: true });
|
|
861
|
+
expect(order).toEqual(['gatekeeper stopped', 'start']);
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
it('gives a space made or started during a change the changed setting, never the one before it', async () => {
|
|
865
|
+
const { journey, id, idle } = await ready({ holdIdleSave: true });
|
|
866
|
+
await journey.stopSpace(id);
|
|
867
|
+
idle.writes.splice(0);
|
|
868
|
+
const change = journey.changeIdleStop({ enabled: true, hours: 9 });
|
|
869
|
+
const started = journey.startSpace(id);
|
|
870
|
+
await sleep(20);
|
|
871
|
+
idle.release();
|
|
872
|
+
await Promise.all([change, started]);
|
|
873
|
+
expect(idle.writes.at(-1)).toEqual([id, { enabled: true, hours: 9 }]);
|
|
874
|
+
expect(idle.writes.every(([, setting]) => setting.hours === 9)).toBe(true);
|
|
875
|
+
});
|
|
876
|
+
|
|
877
|
+
it('stops a gatekeeper left by an idle stop when the switch goes off, without counting its space as stopped', async () => {
|
|
878
|
+
const { journey, place, id } = await ready();
|
|
879
|
+
const stops = idleStopped(place);
|
|
880
|
+
expect(await journey.stopAllSpaces()).toEqual({ stopped: [], stillRunning: [] });
|
|
881
|
+
expect(stops).toEqual([id]);
|
|
882
|
+
});
|
|
883
|
+
});
|
|
884
|
+
|
|
885
|
+
describe('the journey: setup commands', () => {
|
|
886
|
+
/** A memory place whose space answers the setup commands from `answers`, by the command, and holds the named one. */
|
|
887
|
+
const setupPlace = (answers = {}) => {
|
|
888
|
+
const place = createMemoryPlace();
|
|
889
|
+
const exec = place.exec;
|
|
890
|
+
const ran = [];
|
|
891
|
+
let release = () => {};
|
|
892
|
+
const held = new Promise((resolve) => { release = resolve; });
|
|
893
|
+
place.exec = async (spaceId, argv, options) => {
|
|
894
|
+
if (argv[0] !== IMAGE_TIMEOUT) return exec(spaceId, argv, options);
|
|
895
|
+
const command = argv.at(-1);
|
|
896
|
+
ran.push({ spaceId, cwd: argv.at(-2), command });
|
|
897
|
+
if (command === 'hold') await held;
|
|
898
|
+
return answers[command] ?? { code: 0, stdout: '', stderr: '' };
|
|
899
|
+
};
|
|
900
|
+
return { place, ran, release: () => release() };
|
|
901
|
+
};
|
|
902
|
+
const setupEvents = (events, spaceId) => events.filter((event) => event.spaceId === spaceId && event.step === undefined);
|
|
903
|
+
|
|
904
|
+
it('runs the setup commands in the project inside once the space is ready, and lists how they went', async () => {
|
|
905
|
+
const { place, ran } = setupPlace({ 'npm ci': { code: 1, stdout: 'npm ERR! 403 Forbidden\n', stderr: '' } });
|
|
906
|
+
const { journey, events } = journeyWith({ place });
|
|
907
|
+
const answer = await journey.createSpace({ ...REQUEST, setupCommands: ['echo hi', 'npm ci', ' ', 'npm run build'] });
|
|
908
|
+
// The answer says a setup will run, so the client knows to wait for it when the project asks.
|
|
909
|
+
expect(answer.setup).toEqual({ state: 'queued', total: 3 });
|
|
910
|
+
const { id } = answer;
|
|
911
|
+
expect(await until(() => ran.length === 2)).toBe(true);
|
|
912
|
+
expect(await until(() => journey.listSpaces().then((spaces) => spaces[0].setup?.state === 'failed'))).toBe(true);
|
|
913
|
+
expect(ran).toEqual([{ spaceId: id, cwd: `/spaces/${id}/project`, command: 'echo hi' }, { spaceId: id, cwd: `/spaces/${id}/project`, command: 'npm ci' }]);
|
|
914
|
+
// Only after the space was ready: the agent can already start.
|
|
915
|
+
const mine = events.filter((event) => event.spaceId === id);
|
|
916
|
+
expect(mine.findIndex((event) => event.step === 'ready')).toBeLessThan(mine.findIndex((event) => event.step === undefined));
|
|
917
|
+
const listed = (await journey.listSpaces()).find((space) => space.id === id);
|
|
918
|
+
expect(listed.setup).toEqual({ state: 'failed', index: 1, total: 3, command: 'npm ci', exitCode: 1, timedOut: false });
|
|
919
|
+
expect(await journey.readSetup(id)).toEqual({ setup: listed.setup, output: 'npm ERR! 403 Forbidden' });
|
|
920
|
+
expect(setupEvents(events, id).length).toBeGreaterThanOrEqual(2);
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
it('runs nothing and lists no setup for a project without setup commands', async () => {
|
|
924
|
+
const { place, ran } = setupPlace();
|
|
925
|
+
const { journey, events } = journeyWith({ place });
|
|
926
|
+
const { id, setup } = await journey.createSpace(REQUEST);
|
|
927
|
+
expect(setup).toBeNull();
|
|
928
|
+
expect(await until(() => steps(events, id).includes('ready'))).toBe(true);
|
|
929
|
+
expect(ran).toEqual([]);
|
|
930
|
+
expect((await journey.listSpaces()).find((space) => space.id === id).setup).toBeNull();
|
|
931
|
+
expect(await journey.readSetup(id)).toEqual({ setup: null, output: null });
|
|
932
|
+
});
|
|
933
|
+
|
|
934
|
+
it('refuses a list of setup commands the host would not keep, and makes no space for it', async () => {
|
|
935
|
+
const { journey, place } = journeyWith();
|
|
936
|
+
await expect(journey.createSpace({ ...REQUEST, setupCommands: 'npm ci' })).rejects.toMatchObject({ code: 'invalid_setup_commands' });
|
|
937
|
+
await expect(journey.createSpace({ ...REQUEST, setupCommands: Array.from({ length: 101 }, () => 'true') })).rejects.toMatchObject({ code: 'invalid_setup_commands' });
|
|
938
|
+
expect(await place.list()).toEqual([]);
|
|
939
|
+
});
|
|
940
|
+
|
|
941
|
+
it('runs them again in a running space when asked, once at a time, and never in a stopped one', async () => {
|
|
942
|
+
const { place, ran, release } = setupPlace();
|
|
943
|
+
const { journey, events } = journeyWith({ place });
|
|
944
|
+
const { id } = await journey.createSpace(REQUEST);
|
|
945
|
+
expect(await until(() => steps(events, id).includes('ready'))).toBe(true);
|
|
946
|
+
|
|
947
|
+
const answer = await journey.runSetup(id, { commands: ['hold', 'npm ci'] });
|
|
948
|
+
expect(answer.setup).toEqual({ state: 'running', index: 0, total: 2, command: 'hold' });
|
|
949
|
+
await expect(journey.runSetup(id, { commands: ['npm ci'] })).rejects.toMatchObject({ code: 'space_setup_running' });
|
|
950
|
+
release();
|
|
951
|
+
expect(await until(() => ran.length === 2)).toBe(true);
|
|
952
|
+
expect(await until(() => journey.listSpaces().then((spaces) => spaces[0].setup?.state === 'done'))).toBe(true);
|
|
953
|
+
|
|
954
|
+
await expect(journey.runSetup(id, { commands: [] })).rejects.toMatchObject({ code: 'invalid_setup_commands' });
|
|
955
|
+
await expect(journey.runSetup(id, {})).rejects.toMatchObject({ code: 'invalid_setup_commands' });
|
|
956
|
+
await journey.stopSpace(id);
|
|
957
|
+
await expect(journey.runSetup(id, { commands: ['npm ci'] })).rejects.toMatchObject({ code: 'space_not_running' });
|
|
958
|
+
expect(ran).toHaveLength(2);
|
|
959
|
+
});
|
|
960
|
+
|
|
961
|
+
it('lists a run that a restart of the host cut off as interrupted', async () => {
|
|
962
|
+
const { place } = setupPlace();
|
|
963
|
+
const first = journeyWith({ place });
|
|
964
|
+
const { id } = await first.journey.createSpace(REQUEST);
|
|
965
|
+
expect(await until(() => steps(first.events, id).includes('ready'))).toBe(true);
|
|
966
|
+
first.records.update(id, { setup: { state: 'running', total: 2, startedAt: '2026-09-26T09:00:00.000Z' } });
|
|
967
|
+
// Another process on the same data: it has no run in its memory.
|
|
968
|
+
const second = journeyWith({ place, dataDir: first.dataDir });
|
|
969
|
+
expect((await second.journey.listSpaces()).find((space) => space.id === id).setup).toEqual({ state: 'interrupted', total: 2 });
|
|
970
|
+
});
|
|
971
|
+
});
|