@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
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { execFileSync } from 'node:child_process';
|
|
3
|
+
import fs from 'node:fs';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
import express from 'express';
|
|
7
|
+
import request from 'supertest';
|
|
8
|
+
import { registerGitHubRoutes } from './routes.js';
|
|
9
|
+
|
|
10
|
+
const testDir = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-github-pulls-'));
|
|
11
|
+
const previousDataDir = process.env.OPENCHAMBER_DATA_DIR;
|
|
12
|
+
const repository = path.join(testDir, 'project');
|
|
13
|
+
const issue = (number) => ({ number, repository_url: 'https://api.github.com/repos/example/project' });
|
|
14
|
+
const pull = (number) => ({
|
|
15
|
+
number,
|
|
16
|
+
title: `PR ${number}`,
|
|
17
|
+
html_url: `https://github.com/example/project/pull/${number}`,
|
|
18
|
+
state: 'open',
|
|
19
|
+
base: { ref: 'main' },
|
|
20
|
+
head: { ref: `branch-${number}`, sha: `sha-${number}` },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const response = (data, status = 200) => Response.json(data, { status });
|
|
24
|
+
|
|
25
|
+
describe('GET /api/github/pulls/list free-text search', () => {
|
|
26
|
+
let app;
|
|
27
|
+
|
|
28
|
+
beforeAll(async () => {
|
|
29
|
+
process.env.OPENCHAMBER_DATA_DIR = testDir;
|
|
30
|
+
fs.mkdirSync(repository);
|
|
31
|
+
execFileSync('git', ['init', '-q', repository]);
|
|
32
|
+
execFileSync('git', ['-C', repository, 'remote', 'add', 'origin', 'https://github.com/example/project.git']);
|
|
33
|
+
const { setGitHubAuth, setGhCliDisabled } = await import('./auth.js');
|
|
34
|
+
setGhCliDisabled(true);
|
|
35
|
+
setGitHubAuth({ accessToken: 'fake-test-token', accountId: 'test' });
|
|
36
|
+
app = express();
|
|
37
|
+
registerGitHubRoutes(app);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
vi.unstubAllGlobals();
|
|
42
|
+
vi.restoreAllMocks();
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
afterAll(() => {
|
|
46
|
+
if (previousDataDir === undefined) delete process.env.OPENCHAMBER_DATA_DIR;
|
|
47
|
+
else process.env.OPENCHAMBER_DATA_DIR = previousDataDir;
|
|
48
|
+
fs.rmSync(testDir, { recursive: true, force: true });
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const search = () => request(app).get('/api/github/pulls/list').query({ directory: repository, query: 'fix' });
|
|
52
|
+
|
|
53
|
+
const serveGitHub = ({ numbers = [1, 2], failPulls = [], failSearch = false, networkFailure = false } = {}) => {
|
|
54
|
+
const fetch = vi.fn(async (url) => {
|
|
55
|
+
const endpoint = new URL(url);
|
|
56
|
+
if (endpoint.pathname === '/repos/example/project') return response({ full_name: 'example/project' });
|
|
57
|
+
if (endpoint.pathname === '/search/issues') {
|
|
58
|
+
if (failSearch) return response({ message: 'GitHub search unavailable' }, 503);
|
|
59
|
+
return response({ total_count: numbers.length, items: numbers.map(issue) });
|
|
60
|
+
}
|
|
61
|
+
const pullNumber = Number(endpoint.pathname.match(/^\/repos\/example\/project\/pulls\/(\d+)$/)?.[1]);
|
|
62
|
+
if (pullNumber) {
|
|
63
|
+
if (networkFailure && failPulls.includes(pullNumber)) throw new Error('Network unavailable');
|
|
64
|
+
if (failPulls.includes(pullNumber)) return response({ message: 'GitHub enrichment unavailable' }, 503);
|
|
65
|
+
return response(pull(pullNumber));
|
|
66
|
+
}
|
|
67
|
+
throw new Error(`Unexpected GitHub request: ${endpoint.pathname}`);
|
|
68
|
+
});
|
|
69
|
+
vi.stubGlobal('fetch', fetch);
|
|
70
|
+
return fetch;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
it('returns all complete PR summaries in search order', async () => {
|
|
74
|
+
serveGitHub();
|
|
75
|
+
const result = await search().expect(200);
|
|
76
|
+
expect(result.body.prs.map((pr) => ({ number: pr.number, base: pr.base, head: pr.head }))).toEqual([
|
|
77
|
+
{ number: 1, base: 'main', head: 'branch-1' },
|
|
78
|
+
{ number: 2, base: 'main', head: 'branch-2' },
|
|
79
|
+
]);
|
|
80
|
+
expect(result.body.hasMore).toBe(false);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('rejects the page rather than dropping one failed enrichment', async () => {
|
|
84
|
+
const fetch = serveGitHub({ failPulls: [2] });
|
|
85
|
+
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
86
|
+
const result = await search().expect(500);
|
|
87
|
+
expect(result.body).toEqual({ error: 'GitHub enrichment unavailable' });
|
|
88
|
+
expect(result.body).not.toHaveProperty('prs');
|
|
89
|
+
expect(fetch.mock.calls.some(([url]) => String(url).endsWith('/pulls/1'))).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('rejects when every enrichment fails instead of returning an empty success', async () => {
|
|
93
|
+
serveGitHub({ failPulls: [1, 2] });
|
|
94
|
+
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
95
|
+
const result = await search().expect(500);
|
|
96
|
+
expect(result.body).toEqual({ error: 'GitHub enrichment unavailable' });
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('propagates a failed network request without returning a partial page', async () => {
|
|
100
|
+
serveGitHub({ failPulls: [2], networkFailure: true });
|
|
101
|
+
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
102
|
+
expect((await search().expect(500)).body).toEqual({ error: 'Network unavailable' });
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('still returns a genuinely empty search and propagates search-level errors', async () => {
|
|
106
|
+
serveGitHub({ numbers: [] });
|
|
107
|
+
expect((await search().expect(200)).body.prs).toEqual([]);
|
|
108
|
+
serveGitHub({ failSearch: true });
|
|
109
|
+
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
110
|
+
expect((await search().expect(500)).body.error).toBe('GitHub search unavailable');
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -8,6 +8,7 @@ OpenChamber-owned install and static serve for iframe guests. This is not the Op
|
|
|
8
8
|
|
|
9
9
|
- `POST /api/guests/:id/storage` accepts the SDK's `GuestStorageRequest` and returns `GuestStorageResult`. It requires an installed, enabled, fully approved guest with either a panel or background entry, but no additional capability. The UI host supplies the frame's own identity. Guest-scoped asset tokens cannot call this route. Data lives beside `extensions.json` in `guest-storage/<id>.json`. Each key is 1 to 128 characters, each JSON value at most 64 KiB UTF-8, the whole namespace at most 2 MiB and 2,000 keys. `storage.js` owns serialized authorization/read/write/removal; writes are atomic and failures preserve prior bytes. `uninstallGuest` removes storage for every install source. Missing keys return `found: false`, including after removal; stored JSON null returns `found: true`.
|
|
10
10
|
- `GET /api/guests` also exposes `statusEntry` and optional `statusTitle` / `statusHeight` for `contributes.statusSection`, the extension's Work Status section. Its HTML and built scripts pass the same install checks, and it may be the package's only frame: the storage route and the asset route's `hasRuntime` accept `entry`, `backgroundEntry`, or `statusEntry`.
|
|
11
|
+
- `GET /api/guests` also exposes `fileEditors` (`[{ id, title, match, entry }]`, `contributes.fileEditors`) as declared. Each editor's HTML and built scripts pass the same install checks (`invalid-manifest` / `missing-build`), and editors may be the package's only frames. `hasGuestFrame` in `catalog.js` is the one definition of "has a page the host loads" (panel, background, status section, or file editor) used by the storage route and the asset route's `hasRuntime`. No server route reads or writes an editor's file: the Files view owns it and talks to the frame over `postMessage`.
|
|
11
12
|
- `GET /api/guests` also exposes `pageEntry` and optional `pageTitle` for `contributes.page`. Full-screen page HTML and its built scripts pass the same install checks as attach HTML. No new serving/auth path is required.
|
|
12
13
|
|
|
13
14
|
- `GET /api/guests` returns installed guests. `attach` is `"panel"` or `"dialog"` when declared, and `attachEntry` is the dialog's separate HTML. `version` is the package semver. `integration` is the public slice: name, description, `auth`, and settings; OAuth URLs and tokens stay on the server. `service` includes `runtime`, optional `permissions`, optional `socketBindings`, and `granted`. `capabilities` carries `{ requested, granted }`, derived through the SDK's `requestedGuestCapabilities`. `actions`, `commands`, `tools`, and `filesystem` retain their parsed declarations; UI owns menu placement, command collisions, and tool precedence. `entry` is the optional visible panel and `backgroundEntry` is independent on-demand execution HTML. Background-only extensions get no rail surface; tools-only extensions with neither entry mount no frame. A guest without every requested grant is inactive until approval. `enabled: false` pauses it. A failed listing is 500, never an empty list.
|
|
@@ -31,13 +32,13 @@ OpenChamber-owned install and static serve for iframe guests. This is not the Op
|
|
|
31
32
|
- `POST /api/guests/updates/check` — `{ force?: boolean }` → `{ updates: Record<guestId, { version }> }` for every git install whose origin now carries a newer `package.json` `version`. The check runs `git fetch --depth 1 origin <ref|HEAD>` inside the installed clone and reads `FETCH_HEAD:package.json` through the SDK manifest parser; the only signal is semver (`updates.js` `compareSemver`, prerelease below release), no commit hashes. Results sit in a memory cache per store file and guest id for `UPDATE_CHECK_TTL_MS` (one hour); `force` asks the network again. That cache is separate from the catalog cache, so a store write does not drop it. One guest's failed fetch never hides another's update. Folder and zip installs are never checked.
|
|
32
33
|
- `POST /api/guests/:id/update` — replace the installed git copy with a fresh clone of its stored origin. Answers `{ guest }` (the refreshed catalog row) or 400 `{ error }` with `not-git` (folder, zip, or no stored origin), `clone-failed`, `invalid-manifest` (also when the clone declares a different panel id), `missing-build`, `host-too-old` (body may include `required`), or `swap-failed`. Unknown id is 404. Grants, tokens, settings, and the paused flag are keyed by guest id and stay as they were; a version that asks for more capabilities shows up as needs-approval in the catalog and goes through the usual review dialog.
|
|
33
34
|
- `DELETE /api/guests/:id` — drops the store row, any service grant, and socket overrides; stops a running service. Path-install does not delete the user's folder. Zip and git copies under `{openchamberDataDir}/extensions/` are deleted. Unknown id is 404.
|
|
34
|
-
- `GET /api/guests/:id/{*filePath}` serves package-local files. Unknown IDs, escapes, missing files, and unknown types return 404. HTML and JS require `entry`, `backgroundEntry`,
|
|
35
|
+
- `GET /api/guests/:id/{*filePath}` serves package-local files. Unknown IDs, escapes, missing files, and unknown types return 404. HTML and JS require `entry`, `backgroundEntry`, `statusEntry`, or a file editor, expressed by `resolveGuestServedFile`'s `hasRuntime` option. Tools-only extensions still serve their SVG icons but no executable content. Guest HTML propagates the scoped `oc_url_token` onto relative script/link/image URLs. The token is minted for `guest:<id>` and works only under that guest's asset route, never `/api/fs/raw` or event streams. Every response carries `Content-Security-Policy: sandbox allow-scripts`, including direct document navigation. The host serves built files from disk and never compiles guest sources.
|
|
35
36
|
|
|
36
37
|
## Install
|
|
37
38
|
|
|
38
39
|
`contributes.background.entry` is optional package-local `.html`, separate from `panel.entry`. Install validates its HTML and every referenced built script using the same path confinement as visible panels. `backgroundEntry` is exposed on the catalog independently of `entry`; adding it does not create a rail icon or a visible page. Capabilities, services, integrations, and storage work with either execution entry. The SDK refuses visible contributions without `panel.entry` and all runtime contributions when neither entry exists. See `packages/sdk/DOCUMENTATION.md` for on-demand invocation ownership.
|
|
39
40
|
|
|
40
|
-
`html-styles.js` appends the SDK's shared scrollbar stylesheet and its small inline activity script (`GUEST_SCROLLBAR_SCRIPT`: shows a scrollbar while its element scrolls) to served HTML, including requests without an asset token. An authored CSP that blocks inline scripts leaves hover-only scrollbars. This applies to existing panel, page, and attach bundles in direct and relay mode; the relay loader retains the inline style in `srcDoc`. Appending preserves the doctype and avoids rewriting tag-like text inside scripts or comments. Authored CSP stays intact and can block inline styling. Package files on disk and non-HTML responses are unchanged. Scrollbar colors follow the SDK theme variables inside the frame.
|
|
41
|
+
`html-styles.js` appends the SDK's shared scrollbar stylesheet and its small inline activity script (`GUEST_SCROLLBAR_SCRIPT`: shows a scrollbar while its element scrolls) to served HTML, including requests without an asset token. An authored CSP that blocks inline scripts leaves hover-only scrollbars. This applies to existing panel, page, and attach bundles in direct and relay mode; the relay loader retains the inline style in `srcDoc`. Appending preserves the doctype and avoids rewriting tag-like text inside scripts or comments. Authored CSP stays intact and can block inline styling. Package files on disk and non-HTML responses are unchanged. Scrollbar colors follow the SDK theme variables inside the frame. The one insertion before authored content is `<meta name="color-scheme" content="light dark">`, placed right after a leading doctype (or first when there is none): the frame inherits the host's dark scheme, and without that declaration its canvas paints white until the guest's own theme loads, so every panel flashed white on mount.
|
|
41
42
|
|
|
42
43
|
Built-ins ship with the app; user extensions are installed separately. Add a folder, local ZIP, HTTPS Git/ZIP URL, or SSH Git address from Settings → Extensions. The ZIP picker and drop zone upload the archive on web and remote desktop instances. A guest with a page must ship built classic-IIFE JavaScript, for example from `bunx openchamber-guest-bundle panel/main.ts panel/main.js`; the sandbox does not support ESM imports. `package.json` needs a semver version. A missing panel SVG or invalid manifest fails installation; page-less tools-only packages skip HTML/script checks. Optional `engines.openchamber` is checked against this host. Provider accounts are connected separately in Settings → Integrations.
|
|
43
44
|
|
|
@@ -51,6 +52,7 @@ A missing folder is omitted from the list. Other guests stay. A corrupt `extensi
|
|
|
51
52
|
|
|
52
53
|
- Built-in packages come from the app-owned registry bound by `registerBuiltInGuests` at server startup. Source/build/packaging rules are in `packages/extensions/DOCUMENTATION.md`. They receive only their declared grants automatically; ordinary runtime and enabled checks still apply. `openchamber-builtin-` IDs are reserved from user installs, including replacement. DELETE, Git update and grant-edit routes refuse built-ins. Disable preserves account/storage data and stops their services.
|
|
53
54
|
|
|
55
|
+
- Enterprise mode (`enterprise.js`, policy in `../enterprise-mode.js`): a package that asks for `network`, `origins` or `service` installs, updates and keeps those grants only when it comes from a Git repository in `allowedExtensions` (an entry ending in `/` allows everything under it; the match is on `host/path`, so `.git`, a trailing slash, a `#ref` and scp-style SSH spellings compare equal), or from a local folder when `allowLocalExtensions` is set. ZIP installs stay refused. Install and update refuse it with `enterprise-mode` (403 on install); `listInstalledGuests` strips the refused grants after its cache, so a policy change counts at once, and marks the row `enterpriseBlocked`; `PUT /capabilities` refuses to grant them. The list names repositories because a package declares its own id. Built-ins follow the same rule.
|
|
54
56
|
- Grants are narrowed on read, never trusted as stored. `listInstalledGuestsUncached` passes each guest's stored list through `effectiveGrants(granted, storedScope, currentScope)`: `filesystem`, `network`, and `service` only count while the scope recorded at approval equals what the package declares now, and never count without a recorded scope. A newer version that widens its patterns, moves its API origin, or asks for more exec names or sockets shows up as needs-approval and is refused by every proxy meanwhile. Routes and `proxyGuestServiceRequest` take the grant list from the catalog row (`guest.capabilityGrants`), not from the store.
|
|
55
57
|
- Store changes are read-modify-write under one lock per file (`updateExtensionStore`): Allow, Pause, a socket override, an install, and an uninstall landing at the same time all keep each other's result. `guest-auth.json` has the same lock (`withAuthStoreLock`) and every temp file name is unique.
|
|
56
58
|
- ZIP downloads validate and pin each HTTPS hop, at most five. Git clones and update fetches share `prepareGuestGitNetwork`. HTTPS retains `http.followRedirects=false` and `http.curloptResolve` pinning. SSH validates the username/host/path, rejects password-bearing URLs and private DNS answers, pins `Hostname` to a resolved public address, and retains the original host for host-key checks through `HostKeyAlias`. Default SSH options use batch mode and `StrictHostKeyChecking=accept-new`, with ProxyCommand/ProxyJump disabled. Identity key paths are shell-quoted; keys and SSH agent sockets stay on the server. Public Git hosts are supported, not local SSH aliases or private-network targets. Existing user-configured Git/SSH commands remain trusted server configuration.
|
|
@@ -67,7 +67,7 @@ test('background install serves sandboxed assets and storage obeys approval and
|
|
|
67
67
|
const catalog = await request(app).get('/api/guests').expect(200);
|
|
68
68
|
expect(catalog.body.guests[0].backgroundEntry).toBe('index.html');
|
|
69
69
|
const html = await request(app).get('/api/guests/background-test/index.html?oc_url_token=test-scope').expect(200);
|
|
70
|
-
expect(html.headers['content-security-policy']).
|
|
70
|
+
expect(html.headers['content-security-policy']).toMatch(/^sandbox allow-scripts; default-src 'none';/);
|
|
71
71
|
expect(html.text).toContain('main.js?oc_url_token=test-scope');
|
|
72
72
|
expect((await request(app).get('/api/guests/background-test/main.js').expect(200)).text).toBe('void 0;');
|
|
73
73
|
await request(app).post('/api/guests/background-test/storage').send({ op: 'set', key: 'count', value: 1 }).expect(400);
|
|
@@ -6,6 +6,8 @@ import { parseManifestJson } from '@openchamber/sdk/schemas';
|
|
|
6
6
|
|
|
7
7
|
import { listRelativeGuestScriptHrefs, resolveGuestHtmlRelativePath } from './html-tokens.js';
|
|
8
8
|
import { effectiveGrants, guestGrantScope } from './grant-scope.js';
|
|
9
|
+
import { enterpriseBlockedCapabilities } from './enterprise.js';
|
|
10
|
+
import { readEnterprisePolicy } from '../enterprise-mode.js';
|
|
9
11
|
import { onExtensionStoreWrite, readExtensionStore } from './persist.js';
|
|
10
12
|
import { buildPublicSocketBindings } from './sockets.js';
|
|
11
13
|
import { isReservedBuiltInId, readBuiltInRegistry } from './builtins.js';
|
|
@@ -262,6 +264,19 @@ export const inspectGuestPackage = async (packageRoot, { openchamberVersion, ski
|
|
|
262
264
|
if (section !== true && section?.title) guest.statusTitle = section.title;
|
|
263
265
|
if (section !== true && section?.height !== undefined) guest.statusHeight = section.height;
|
|
264
266
|
}
|
|
267
|
+
// File editors are frames of their own too; each entry is checked the same way.
|
|
268
|
+
const fileEditors = parsed.manifest.contributes.fileEditors ?? [];
|
|
269
|
+
for (const editor of fileEditors) {
|
|
270
|
+
if (!await resolveGuestAssetPath(packageRoot, editor.entry)) {
|
|
271
|
+
return { ok: false, code: 'invalid-manifest' };
|
|
272
|
+
}
|
|
273
|
+
if (!await guestBuiltScriptsReady(packageRoot, editor.entry)) {
|
|
274
|
+
return { ok: false, code: 'missing-build' };
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
if (fileEditors.length > 0) {
|
|
278
|
+
guest.fileEditors = fileEditors.map((editor) => ({ ...editor, match: [...editor.match] }));
|
|
279
|
+
}
|
|
265
280
|
if (parsed.manifest.contributes.capabilities?.length) {
|
|
266
281
|
guest.capabilities = [...parsed.manifest.contributes.capabilities];
|
|
267
282
|
}
|
|
@@ -271,6 +286,9 @@ export const inspectGuestPackage = async (packageRoot, { openchamberVersion, ski
|
|
|
271
286
|
if (parsed.manifest.contributes.filesystem?.length) {
|
|
272
287
|
guest.filesystem = [...parsed.manifest.contributes.filesystem];
|
|
273
288
|
}
|
|
289
|
+
if (parsed.manifest.contributes.origins?.length) {
|
|
290
|
+
guest.origins = [...parsed.manifest.contributes.origins];
|
|
291
|
+
}
|
|
274
292
|
if (parsed.manifest.contributes.actions?.length) {
|
|
275
293
|
guest.actions = parsed.manifest.contributes.actions.map((action) => ({ ...action }));
|
|
276
294
|
}
|
|
@@ -301,6 +319,11 @@ const withSource = (guest, source, displayPath) => ({
|
|
|
301
319
|
path: displayPath,
|
|
302
320
|
});
|
|
303
321
|
|
|
322
|
+
/** Whether the package has any page the host loads: panel, background, status section, or file editor. */
|
|
323
|
+
export const hasGuestFrame = (guest) => Boolean(
|
|
324
|
+
guest.entry || guest.backgroundEntry || guest.statusEntry || (Array.isArray(guest.fileEditors) && guest.fileEditors.length > 0),
|
|
325
|
+
);
|
|
326
|
+
|
|
304
327
|
/** Catalog JSON. Drops packageRoot. Keeps attach only when true. `entry` is absent for a page-less guest. */
|
|
305
328
|
export const toPublicGuest = (guest) => {
|
|
306
329
|
const row = {
|
|
@@ -311,6 +334,9 @@ export const toPublicGuest = (guest) => {
|
|
|
311
334
|
path: guest.path ?? null,
|
|
312
335
|
enabled: guest.enabled !== false,
|
|
313
336
|
};
|
|
337
|
+
if (guest.enterpriseBlocked?.length) {
|
|
338
|
+
row.enterpriseBlocked = [...guest.enterpriseBlocked];
|
|
339
|
+
}
|
|
314
340
|
if (guest.entry) {
|
|
315
341
|
row.entry = guest.entry;
|
|
316
342
|
}
|
|
@@ -354,6 +380,10 @@ export const toPublicGuest = (guest) => {
|
|
|
354
380
|
if (Array.isArray(guest.filesystem) && guest.filesystem.length > 0) {
|
|
355
381
|
row.filesystem = [...guest.filesystem];
|
|
356
382
|
}
|
|
383
|
+
// Shown on the approval card: the frame may exchange data with these.
|
|
384
|
+
if (Array.isArray(guest.origins) && guest.origins.length > 0) {
|
|
385
|
+
row.origins = [...guest.origins];
|
|
386
|
+
}
|
|
357
387
|
// Actions, commands, and tools are the parsed manifest entries as they
|
|
358
388
|
// are: the UI decides which ones to apply from the grant and the enabled flag.
|
|
359
389
|
if (Array.isArray(guest.actions) && guest.actions.length > 0) {
|
|
@@ -362,6 +392,9 @@ export const toPublicGuest = (guest) => {
|
|
|
362
392
|
if (Array.isArray(guest.commands) && guest.commands.length > 0) {
|
|
363
393
|
row.commands = guest.commands.map((command) => ({ ...command }));
|
|
364
394
|
}
|
|
395
|
+
if (Array.isArray(guest.fileEditors) && guest.fileEditors.length > 0) {
|
|
396
|
+
row.fileEditors = guest.fileEditors.map((editor) => ({ ...editor, match: [...editor.match] }));
|
|
397
|
+
}
|
|
365
398
|
if (Array.isArray(guest.tools) && guest.tools.length > 0) {
|
|
366
399
|
row.tools = guest.tools.map((tool) => ({ ...tool }));
|
|
367
400
|
}
|
|
@@ -413,17 +446,38 @@ export const invalidateGuestCatalog = (persistPath) => {
|
|
|
413
446
|
};
|
|
414
447
|
onExtensionStoreWrite(invalidateGuestCatalog);
|
|
415
448
|
|
|
449
|
+
/**
|
|
450
|
+
* Enterprise mode, applied on every read after the cache so a policy change
|
|
451
|
+
* counts at once: a package whose gated capabilities the policy refuses keeps
|
|
452
|
+
* none of them, and `enterpriseBlocked` names them for Settings. Every route
|
|
453
|
+
* and proxy takes grants from this row, so none of them can use the refused
|
|
454
|
+
* capabilities.
|
|
455
|
+
*/
|
|
456
|
+
const withEnterprisePolicy = (guests) => {
|
|
457
|
+
const policy = readEnterprisePolicy();
|
|
458
|
+
if (!policy.enterpriseMode) return guests;
|
|
459
|
+
return guests.map((guest) => {
|
|
460
|
+
const blocked = enterpriseBlockedCapabilities(guest, { source: guest.source, gitUrl: guest.gitOrigin?.url }, policy);
|
|
461
|
+
if (blocked.length === 0) return guest;
|
|
462
|
+
return {
|
|
463
|
+
...guest,
|
|
464
|
+
capabilityGrants: guest.capabilityGrants.filter((capability) => !blocked.includes(capability)),
|
|
465
|
+
enterpriseBlocked: blocked,
|
|
466
|
+
};
|
|
467
|
+
});
|
|
468
|
+
};
|
|
469
|
+
|
|
416
470
|
export const listInstalledGuests = async ({ persistPath } = {}) => {
|
|
417
471
|
const cached = persistPath ? catalogCache.get(persistPath) : undefined;
|
|
418
472
|
if (cached && cached.expiresAt > Date.now()) {
|
|
419
|
-
return cached.guests;
|
|
473
|
+
return withEnterprisePolicy(cached.guests);
|
|
420
474
|
}
|
|
421
475
|
const version = persistPath ? catalogVersionOf(persistPath) : 0;
|
|
422
476
|
const guests = await listInstalledGuestsUncached({ persistPath });
|
|
423
477
|
if (persistPath && catalogVersionOf(persistPath) === version) {
|
|
424
478
|
catalogCache.set(persistPath, { guests, expiresAt: Date.now() + CATALOG_CACHE_TTL_MS });
|
|
425
479
|
}
|
|
426
|
-
return guests;
|
|
480
|
+
return withEnterprisePolicy(guests);
|
|
427
481
|
};
|
|
428
482
|
|
|
429
483
|
const listInstalledGuestsUncached = async ({ persistPath } = {}) => {
|
|
@@ -2,7 +2,7 @@ import { describe, expect, test } from 'bun:test';
|
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import os from 'node:os';
|
|
4
4
|
import path from 'node:path';
|
|
5
|
-
import { guestAssetContentType, inspectGuestPackage, listInstalledGuests, resolveGuestAssetPath, resolveGuestServedFile, toPublicGuest } from './catalog.js';
|
|
5
|
+
import { guestAssetContentType, hasGuestFrame, inspectGuestPackage, listInstalledGuests, resolveGuestAssetPath, resolveGuestServedFile, toPublicGuest } from './catalog.js';
|
|
6
6
|
import { setCapabilityGrants, writeExtensionPaths } from './persist.js';
|
|
7
7
|
|
|
8
8
|
const writeBuiltGuest = async (root) => {
|
|
@@ -279,6 +279,29 @@ describe('page-less packages', () => {
|
|
|
279
279
|
} finally { await fs.rm(dir, { recursive: true, force: true }); }
|
|
280
280
|
});
|
|
281
281
|
|
|
282
|
+
test('a file-editor-only package validates each editor page, publishes the editors, and counts as a frame', async () => {
|
|
283
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-file-editor-'));
|
|
284
|
+
try {
|
|
285
|
+
const editor = { id: 'canvas', title: 'Excalidraw', match: ['*.excalidraw'], entry: 'editor/index.html' };
|
|
286
|
+
const sheets = { id: 'sheets', title: 'Sheets', match: ['*.xlsx'], entry: 'editor/index.html', content: 'binary' };
|
|
287
|
+
await fs.writeFile(path.join(dir, 'package.json'), JSON.stringify({ version: '1.0.0', openchamber: {
|
|
288
|
+
apiVersion: 1, contributes: { panel: { id: 'excalidraw', name: 'Excalidraw', icon: 'pencil-ruler-2' }, fileEditors: [editor, sheets] },
|
|
289
|
+
} }));
|
|
290
|
+
expect(await inspectGuestPackage(dir)).toMatchObject({ ok: false, code: 'invalid-manifest' });
|
|
291
|
+
await fs.mkdir(path.join(dir, 'editor'));
|
|
292
|
+
await fs.writeFile(path.join(dir, 'editor/index.html'), '<script src="main.js"></script>');
|
|
293
|
+
expect(await inspectGuestPackage(dir)).toMatchObject({ ok: false, code: 'missing-build' });
|
|
294
|
+
await fs.writeFile(path.join(dir, 'editor/main.js'), 'console.log("editor")');
|
|
295
|
+
const inspected = await inspectGuestPackage(dir);
|
|
296
|
+
expect(inspected.ok).toBe(true);
|
|
297
|
+
expect(hasGuestFrame(inspected.guest)).toBe(true);
|
|
298
|
+
const row = toPublicGuest(inspected.guest);
|
|
299
|
+
expect(row.fileEditors).toEqual([editor, sheets]);
|
|
300
|
+
expect(row).not.toHaveProperty('entry');
|
|
301
|
+
expect(await resolveGuestServedFile(dir, 'editor/main.js', { hasRuntime: hasGuestFrame(inspected.guest) })).not.toBeNull();
|
|
302
|
+
} finally { await fs.rm(dir, { recursive: true, force: true }); }
|
|
303
|
+
});
|
|
304
|
+
|
|
282
305
|
test('installs a tools-only package without entry, omits entry from the row, and never serves it a frame', async () => {
|
|
283
306
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-guest-'));
|
|
284
307
|
const guestRoot = path.join(dir, 'tools-only');
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import os from 'node:os';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from 'vitest';
|
|
5
|
+
import { runGitNetwork } from './clone.js';
|
|
6
|
+
|
|
7
|
+
const dirs = [];
|
|
8
|
+
afterEach(() => {
|
|
9
|
+
for (const dir of dirs.splice(0)) fs.rmSync(dir, { recursive: true, force: true });
|
|
10
|
+
vi.restoreAllMocks();
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// A stand-in git that behaves like a schannel-only Git for Windows whose system
|
|
14
|
+
// config asks for OpenSSL (issue #4040): refuses unless a backend it has is set.
|
|
15
|
+
const fakeGit = (script) => {
|
|
16
|
+
const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'oc-fake-git-'));
|
|
17
|
+
dirs.push(dir);
|
|
18
|
+
const file = path.join(dir, 'git');
|
|
19
|
+
fs.writeFileSync(file, `#!/bin/sh\n${script}\n`, { mode: 0o755 });
|
|
20
|
+
return { gitBinary: file, calls: path.join(dir, 'calls') };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
describe.skipIf(process.platform === 'win32')('runGitNetwork', () => {
|
|
24
|
+
it('retries once on a backend the git build supports', async () => {
|
|
25
|
+
const { gitBinary, calls } = fakeGit(`echo "$*" >> "$(dirname "$0")/calls"
|
|
26
|
+
case "$*" in *http.sslBackend=schannel*) exit 0;; esac
|
|
27
|
+
echo "fatal: Unsupported SSL backend 'openssl'. Supported SSL backends:" >&2
|
|
28
|
+
echo " schannel" >&2
|
|
29
|
+
exit 128`);
|
|
30
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
31
|
+
|
|
32
|
+
const result = await runGitNetwork(['clone', '--', 'https://example.com/r.git', 'dest'], { gitBinary });
|
|
33
|
+
|
|
34
|
+
expect(result.ok).toBe(true);
|
|
35
|
+
const lines = fs.readFileSync(calls, 'utf8').trim().split('\n');
|
|
36
|
+
expect(lines).toHaveLength(2);
|
|
37
|
+
expect(lines[1].startsWith('-c http.sslBackend=schannel clone')).toBe(true);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('does not retry other failures and logs what git said', async () => {
|
|
41
|
+
const { gitBinary, calls } = fakeGit(`echo "$*" >> "$(dirname "$0")/calls"
|
|
42
|
+
echo "fatal: repository not found" >&2
|
|
43
|
+
exit 128`);
|
|
44
|
+
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
45
|
+
|
|
46
|
+
const result = await runGitNetwork(['clone', '--', 'https://example.com/r.git', 'dest'], { gitBinary });
|
|
47
|
+
|
|
48
|
+
expect(result.ok).toBe(false);
|
|
49
|
+
expect(fs.readFileSync(calls, 'utf8').trim().split('\n')).toHaveLength(1);
|
|
50
|
+
expect(String(warn.mock.calls[0]?.[1])).toContain('repository not found');
|
|
51
|
+
});
|
|
52
|
+
});
|
|
@@ -174,11 +174,14 @@ export const parseGitInstallUrl = (value) => {
|
|
|
174
174
|
return ref ? { url, ref } : { url };
|
|
175
175
|
};
|
|
176
176
|
|
|
177
|
+
const STDERR_TAIL_BYTES = 4096;
|
|
178
|
+
|
|
177
179
|
/**
|
|
178
180
|
* Run one git command without a terminal. Resolves `{ ok: true, stdout }` on
|
|
179
|
-
* exit 0 and `{ ok: false }` on a non-zero exit, a spawn error, or the
|
|
181
|
+
* exit 0 and `{ ok: false, stderr }` on a non-zero exit, a spawn error, or the
|
|
180
182
|
* timeout (the child is killed). Never rejects. `stdout` is captured only
|
|
181
|
-
* when `capture` is set so a clone's progress is not buffered
|
|
183
|
+
* when `capture` is set so a clone's progress is not buffered; `stderr` keeps
|
|
184
|
+
* only its tail, for diagnosis.
|
|
182
185
|
*/
|
|
183
186
|
export const runGit = (args, { gitBinary = 'git', cwd, timeoutMs = CLONE_TIMEOUT_MS, capture = false, env = {} } = {}) => (
|
|
184
187
|
new Promise((resolve) => {
|
|
@@ -208,6 +211,11 @@ export const runGit = (args, { gitBinary = 'git', cwd, timeoutMs = CLONE_TIMEOUT
|
|
|
208
211
|
if (capture && child.stdout) {
|
|
209
212
|
child.stdout.on('data', (chunk) => chunks.push(chunk));
|
|
210
213
|
}
|
|
214
|
+
let stderrTail = Buffer.alloc(0);
|
|
215
|
+
child.stderr?.on('data', (chunk) => {
|
|
216
|
+
const joined = Buffer.concat([stderrTail, chunk]);
|
|
217
|
+
stderrTail = joined.subarray(Math.max(0, joined.length - STDERR_TAIL_BYTES));
|
|
218
|
+
});
|
|
211
219
|
let settled = false;
|
|
212
220
|
const finish = (result) => {
|
|
213
221
|
if (settled) {
|
|
@@ -226,7 +234,7 @@ export const runGit = (args, { gitBinary = 'git', cwd, timeoutMs = CLONE_TIMEOUT
|
|
|
226
234
|
});
|
|
227
235
|
child.on('close', (exit) => {
|
|
228
236
|
clearTimeout(timer);
|
|
229
|
-
finish(exit === 0 ? { ok: true, stdout: Buffer.concat(chunks).toString('utf8') } : { ok: false });
|
|
237
|
+
finish(exit === 0 ? { ok: true, stdout: Buffer.concat(chunks).toString('utf8') } : { ok: false, stderr: stderrTail.toString('utf8') });
|
|
230
238
|
});
|
|
231
239
|
})
|
|
232
240
|
);
|
|
@@ -279,6 +287,24 @@ export const prepareGuestGitNetwork = async (source, { gitIdentityId, lookup } =
|
|
|
279
287
|
return sshCommand ? { args, env: { GIT_SSH_COMMAND: sshCommand } } : { args };
|
|
280
288
|
};
|
|
281
289
|
|
|
290
|
+
/**
|
|
291
|
+
* Run a network git command (clone, fetch). The pinned connection options make
|
|
292
|
+
* git honour `http.sslBackend` from the user's config; a Git build that lacks
|
|
293
|
+
* that backend refuses with "Unsupported SSL backend" and names the ones it
|
|
294
|
+
* has, so the command is retried once on the first of those. A failure's
|
|
295
|
+
* stderr is logged: the UI only shows a generic "could not clone".
|
|
296
|
+
*/
|
|
297
|
+
export const runGitNetwork = async (args, options) => {
|
|
298
|
+
const result = await runGit(args, options);
|
|
299
|
+
if (result.ok) return result;
|
|
300
|
+
const supported = /Unsupported SSL backend[\s\S]*?Supported SSL backends:\s*([\w-]+)/i.exec(result.stderr ?? '')?.[1];
|
|
301
|
+
const retried = supported ? await runGit(['-c', `http.sslBackend=${supported}`, ...args], options) : result;
|
|
302
|
+
if (!retried.ok) {
|
|
303
|
+
console.warn('[guests] git network command failed:', (retried.stderr ?? '').trim() || 'no output');
|
|
304
|
+
}
|
|
305
|
+
return retried;
|
|
306
|
+
};
|
|
307
|
+
|
|
282
308
|
export const cloneGitRepository = async (source, dest, { gitBinary = 'git', timeoutMs = CLONE_TIMEOUT_MS, ref, lookup, gitIdentityId } = {}) => {
|
|
283
309
|
if (ref !== undefined && !isGitRef(ref)) {
|
|
284
310
|
return { ok: false, code: 'clone-failed' };
|
|
@@ -292,6 +318,6 @@ export const cloneGitRepository = async (source, dest, { gitBinary = 'git', time
|
|
|
292
318
|
args.push('--branch', ref);
|
|
293
319
|
}
|
|
294
320
|
args.push('--', source, dest);
|
|
295
|
-
const result = await
|
|
321
|
+
const result = await runGitNetwork(args, { gitBinary, timeoutMs, env: network.env });
|
|
296
322
|
return result.ok ? { ok: true } : { ok: false, code: 'clone-failed' };
|
|
297
323
|
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { requestedGuestCapabilities } from '@openchamber/sdk';
|
|
2
|
+
|
|
3
|
+
import { readEnterprisePolicy } from '../enterprise-mode.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Enterprise mode and extensions. An extension that can send what it sees
|
|
7
|
+
* off this machine answers to the administrator:
|
|
8
|
+
* - `network`: host requests to its integration's API origin;
|
|
9
|
+
* - `origins`: its frame fetching approved https origins directly;
|
|
10
|
+
* - `service`: an unsandboxed process with the user's access.
|
|
11
|
+
* Such a package installs and runs only from a Git repository listed in the
|
|
12
|
+
* policy (`allowedExtensions`; an entry ending in `/` allows every
|
|
13
|
+
* repository under it, such as a whole organization), or from a local folder
|
|
14
|
+
* where `allowLocalExtensions` is set for developers. ZIP stays closed:
|
|
15
|
+
* it is how a build gets handed to others. Everything else installs as usual.
|
|
16
|
+
* The list names repositories, not package ids: a package declares its own
|
|
17
|
+
* id, so an id would let a user ship any code under an allowed name.
|
|
18
|
+
*/
|
|
19
|
+
const ENTERPRISE_GATED_CAPABILITIES = ['network', 'origins', 'service'];
|
|
20
|
+
|
|
21
|
+
/** `host/path` of a clone URL (https or scp-style ssh), for comparing two spellings of one repository. */
|
|
22
|
+
const repositoryKey = (value) => {
|
|
23
|
+
const trimmed = String(value).trim().replace(/#.*$/, '');
|
|
24
|
+
const scp = trimmed.match(/^[^@/\s]+@([^:/\s]+):(.+)$/);
|
|
25
|
+
let host;
|
|
26
|
+
let pathname;
|
|
27
|
+
if (scp) {
|
|
28
|
+
[, host, pathname] = scp;
|
|
29
|
+
} else {
|
|
30
|
+
try {
|
|
31
|
+
const url = new URL(trimmed);
|
|
32
|
+
host = url.hostname;
|
|
33
|
+
pathname = url.pathname;
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const cleanPath = pathname.replace(/^\/+/, '').replace(/\/+$/, '').replace(/\.git$/i, '');
|
|
39
|
+
return cleanPath ? `${host.toLowerCase()}/${cleanPath}` : null;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const isAllowedRepository = (gitUrl, allowed) => {
|
|
43
|
+
const key = gitUrl ? repositoryKey(gitUrl) : null;
|
|
44
|
+
if (key === null) return false;
|
|
45
|
+
return allowed.some((entry) => {
|
|
46
|
+
const allowedKey = repositoryKey(entry);
|
|
47
|
+
if (allowedKey === null) return false;
|
|
48
|
+
// A trailing slash allows everything under it; matching on the separator
|
|
49
|
+
// keeps `acme/` from also allowing `acme-other/`.
|
|
50
|
+
return entry.trim().endsWith('/') ? key.startsWith(`${allowedKey}/`) : key === allowedKey;
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The gated capabilities `guest` asks for that enterprise mode refuses, given
|
|
56
|
+
* where it comes from (`source`, and the clone URL for Git installs). Empty
|
|
57
|
+
* outside enterprise mode, for packages that ask for none, and for packages
|
|
58
|
+
* from an allowed repository. A caller checking many packages reads the
|
|
59
|
+
* policy once and passes it in.
|
|
60
|
+
*/
|
|
61
|
+
export const enterpriseBlockedCapabilities = (guest, { source, gitUrl } = {}, policy = readEnterprisePolicy()) => {
|
|
62
|
+
if (!policy.enterpriseMode) return [];
|
|
63
|
+
const gated = requestedGuestCapabilities(guest).filter((capability) => ENTERPRISE_GATED_CAPABILITIES.includes(capability));
|
|
64
|
+
if (gated.length === 0) return [];
|
|
65
|
+
if (source === 'git' && isAllowedRepository(gitUrl, policy.allowedExtensions)) return [];
|
|
66
|
+
if (source === 'path' && policy.allowLocalExtensions) return [];
|
|
67
|
+
return gated;
|
|
68
|
+
};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
|
|
6
|
+
import { listInstalledGuests } from './catalog.js';
|
|
7
|
+
import { enterpriseBlockedCapabilities } from './enterprise.js';
|
|
8
|
+
import { guestGrantScope } from './grant-scope.js';
|
|
9
|
+
import { installGuestFromPath } from './install.js';
|
|
10
|
+
import { setCapabilityGrants } from './persist.js';
|
|
11
|
+
|
|
12
|
+
const enterprise = (allowedExtensions = []) => ({ enterpriseMode: true, allowedExtensions });
|
|
13
|
+
const withOrigins = { origins: ['https://api.acme.test'] };
|
|
14
|
+
|
|
15
|
+
describe('enterpriseBlockedCapabilities', () => {
|
|
16
|
+
test('refuses nothing outside enterprise mode', () => {
|
|
17
|
+
expect(enterpriseBlockedCapabilities({ origins: withOrigins.origins }, { source: 'zip' }, { enterpriseMode: false, allowedExtensions: [] })).toEqual([]);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('refuses what could send data out, from any source but an allowed repository', () => {
|
|
21
|
+
const guest = { origins: ['https://api.acme.test'] };
|
|
22
|
+
expect(enterpriseBlockedCapabilities(guest, { source: 'zip' }, enterprise())).toEqual(['origins']);
|
|
23
|
+
expect(enterpriseBlockedCapabilities(guest, { source: 'path' }, enterprise(['https://github.com/acme/ext']))).toEqual(['origins']);
|
|
24
|
+
expect(enterpriseBlockedCapabilities(guest, { source: 'git', gitUrl: 'https://github.com/other/ext' }, enterprise(['https://github.com/acme/ext']))).toEqual(['origins']);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test('allows a listed repository however its URL is spelled', () => {
|
|
28
|
+
const guest = { origins: ['https://api.acme.test'] };
|
|
29
|
+
const policy = enterprise(['https://github.com/acme/ext']);
|
|
30
|
+
for (const gitUrl of ['https://github.com/acme/ext.git', 'https://GitHub.com/acme/ext/', 'git@github.com:acme/ext.git']) {
|
|
31
|
+
expect(enterpriseBlockedCapabilities(guest, { source: 'git', gitUrl }, policy)).toEqual([]);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('an entry ending in a slash allows every repository under it, and nothing beside it', () => {
|
|
36
|
+
const guest = { origins: ['https://api.acme.test'] };
|
|
37
|
+
const policy = enterprise(['https://github.com/acme/']);
|
|
38
|
+
expect(enterpriseBlockedCapabilities(guest, { source: 'git', gitUrl: 'https://github.com/acme/new-ext#my-branch' }, policy)).toEqual([]);
|
|
39
|
+
expect(enterpriseBlockedCapabilities(guest, { source: 'git', gitUrl: 'git@github.com:acme/team/tool.git' }, policy)).toEqual([]);
|
|
40
|
+
expect(enterpriseBlockedCapabilities(guest, { source: 'git', gitUrl: 'https://github.com/acme-other/ext' }, policy)).toEqual(['origins']);
|
|
41
|
+
expect(enterpriseBlockedCapabilities(guest, { source: 'git', gitUrl: 'https://github.com/acme' }, policy)).toEqual(['origins']);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('allowLocalExtensions opens a local folder for developers, never a ZIP', () => {
|
|
45
|
+
const guest = { origins: ['https://api.acme.test'] };
|
|
46
|
+
const policy = { enterpriseMode: true, allowedExtensions: [], allowLocalExtensions: true };
|
|
47
|
+
expect(enterpriseBlockedCapabilities(guest, { source: 'path' }, policy)).toEqual([]);
|
|
48
|
+
expect(enterpriseBlockedCapabilities(guest, { source: 'zip' }, policy)).toEqual(['origins']);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('leaves packages that cannot send data out alone', () => {
|
|
52
|
+
expect(enterpriseBlockedCapabilities({}, { source: 'zip' }, enterprise())).toEqual([]);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const writeGuest = async (root, id, contributes = {}) => {
|
|
57
|
+
await fs.mkdir(path.join(root, 'panel'), { recursive: true });
|
|
58
|
+
await fs.writeFile(path.join(root, 'panel', 'index.html'), '<html></html>');
|
|
59
|
+
await fs.writeFile(path.join(root, 'package.json'), JSON.stringify({
|
|
60
|
+
name: `@openchamber/${id}`,
|
|
61
|
+
version: '1.0.0',
|
|
62
|
+
openchamber: {
|
|
63
|
+
apiVersion: 1,
|
|
64
|
+
contributes: { panel: { id, name: id, icon: 'window', entry: 'panel/index.html' }, ...contributes },
|
|
65
|
+
},
|
|
66
|
+
}));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
describe('extensions in enterprise mode', () => {
|
|
70
|
+
afterEach(() => {
|
|
71
|
+
delete process.env.OPENCHAMBER_ENTERPRISE_MODE;
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
test('refuses to install a package that could send data out, and installs one that cannot', async () => {
|
|
75
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-ext-enterprise-'));
|
|
76
|
+
const persistPath = path.join(dir, 'extensions.json');
|
|
77
|
+
await writeGuest(path.join(dir, 'reach'), 'reach-out', withOrigins);
|
|
78
|
+
await writeGuest(path.join(dir, 'quiet'), 'stay-home');
|
|
79
|
+
process.env.OPENCHAMBER_ENTERPRISE_MODE = '1';
|
|
80
|
+
|
|
81
|
+
const refused = await installGuestFromPath(path.join(dir, 'reach'), persistPath);
|
|
82
|
+
expect(refused).toEqual({ ok: false, code: 'enterprise-mode', capabilities: ['origins'] });
|
|
83
|
+
expect((await installGuestFromPath(path.join(dir, 'quiet'), persistPath)).ok).toBe(true);
|
|
84
|
+
expect((await listInstalledGuests({ persistPath })).map((guest) => guest.id)).toEqual(['stay-home']);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('drops an installed package\'s approved grants once enterprise mode turns on', async () => {
|
|
88
|
+
const dir = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-ext-enterprise-'));
|
|
89
|
+
const persistPath = path.join(dir, 'extensions.json');
|
|
90
|
+
await writeGuest(path.join(dir, 'reach'), 'reach-later', withOrigins);
|
|
91
|
+
expect((await installGuestFromPath(path.join(dir, 'reach'), persistPath)).ok).toBe(true);
|
|
92
|
+
const [installed] = await listInstalledGuests({ persistPath });
|
|
93
|
+
await setCapabilityGrants(installed.id, persistPath, ['origins'], guestGrantScope(installed));
|
|
94
|
+
expect((await listInstalledGuests({ persistPath }))[0].capabilityGrants).toEqual(['origins']);
|
|
95
|
+
|
|
96
|
+
process.env.OPENCHAMBER_ENTERPRISE_MODE = '1';
|
|
97
|
+
const [guest] = await listInstalledGuests({ persistPath });
|
|
98
|
+
expect(guest.enterpriseBlocked).toEqual(['origins']);
|
|
99
|
+
expect(guest.capabilityGrants).not.toContain('origins');
|
|
100
|
+
|
|
101
|
+
delete process.env.OPENCHAMBER_ENTERPRISE_MODE;
|
|
102
|
+
const [restored] = await listInstalledGuests({ persistPath });
|
|
103
|
+
expect(restored.enterpriseBlocked).toBeUndefined();
|
|
104
|
+
expect(restored.capabilityGrants).toEqual(['origins']);
|
|
105
|
+
});
|
|
106
|
+
});
|