@vantran-se/openchamber-web 1.22.1 → 1.23.0
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/README.md +2 -3
- package/bin/cli.js +11 -1
- package/bin/cli.test.js +92 -0
- package/bin/lib/cli-startup.js +49 -0
- package/bin/lib/commands-startup.js +41 -6
- package/dist/assets/{CodeMirrorCommentWidgets-C53Q7pbX.js → CodeMirrorCommentWidgets-DFg2wnpo.js} +1 -1
- package/dist/assets/DiffView-3Dn4QHbu.js +4 -0
- package/dist/assets/DirtyBranchSwitchDialog-CwOerqVi.js +1 -0
- package/dist/assets/FilesView-BdTOpew9.js +17 -0
- package/dist/assets/GitView-Dqf9vHJh.js +6 -0
- package/dist/assets/{JsonTreeView-Bl0lp9Rs.js → JsonTreeView-BKdsjg5B.js} +1 -1
- package/dist/assets/LinearIssuesView-CmbeL7I6.js +1 -0
- package/dist/assets/MarkdownImageGallery-_5gEVr0X.js +1 -0
- package/dist/assets/MarkdownRendererImpl-wVZlx4dd.js +12 -0
- package/dist/assets/OnboardingScreen-DdP4_nuc.js +1 -0
- package/dist/assets/{PatchDiff-D6NXAfJk.js → PatchDiff-am3SAss2.js} +1 -1
- package/dist/assets/PierreDiffViewer-DCsydlKs.js +161 -0
- package/dist/assets/PlanView-BoJxdRZe.js +5 -0
- package/dist/assets/SettingsView-CcM8pF5O.js +28 -0
- package/dist/assets/{SettingsWindow-BiWDBRvb.js → SettingsWindow-DVTdDSol.js} +1 -1
- package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
- package/dist/assets/{ToolOutputDialog-BQexMQIm.js → ToolOutputDialog-BgfTbDZ4.js} +6 -6
- package/dist/assets/ToolPartDiffPreview-C7WLk5i9.js +8 -0
- package/dist/assets/{VirtualizedFileDiff-Dpz2ra8h.js → VirtualizedFileDiff-DcdgkH-x.js} +1 -1
- package/dist/assets/WalkthroughView-BEVUDxuw.js +4 -0
- package/dist/assets/{computeVirtualFileMetrics-DtyozJdt.js → computeVirtualFileMetrics-C8byMnRh.js} +2 -2
- package/dist/assets/contextPanelEmbeddedChat-CirXEPJq.js +1 -0
- package/dist/assets/de-C8jV7J9y.js +10 -0
- package/dist/assets/es-BI6J1M5R.js +16 -0
- package/dist/assets/fr-D6oDFt7E.js +14 -0
- package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
- package/dist/assets/{index-DmhujXbT.js → index-BB7ryz8y.js} +1 -1
- package/dist/assets/index-BqhiCmYS.js +39 -0
- package/dist/assets/index-FqSOBz0J.css +1 -0
- package/dist/assets/{isDiffPlainText-XyulMHxx.js → isDiffPlainText-45ujMPGb.js} +1 -1
- package/dist/assets/{isFilePlainText-B19Ddps1.js → isFilePlainText-Cc4KFSYi.js} +1 -1
- package/dist/assets/ja-C_4i5EQu.js +16 -0
- package/dist/assets/ko-BFbOTpbq.js +16 -0
- package/dist/assets/{main-B2a_JfKZ.js → main-C9ETLKFc.js} +2 -2
- package/dist/assets/main-CJmb2dF8.js +930 -0
- package/dist/assets/markdownCore-DVuZpnli.js +5 -0
- package/dist/assets/{miniChat-B3CSU_Ps.js → miniChat-B4Ytoq2n.js} +2 -2
- package/dist/assets/{mobile-QNcFIVCW.js → mobile-BUT6-lo1.js} +2 -2
- package/dist/assets/patchFileDiff-8j1apICU.js +13 -0
- package/dist/assets/pl-COFvT56l.js +16 -0
- package/dist/assets/pt-BR-DtVOO2Lj.js +16 -0
- package/dist/assets/renderElectronMiniChatApp-B6vUG-vF.js +2 -0
- package/dist/assets/renderMobileApp-BNgHraq6.js +25 -0
- package/dist/assets/runtimeEndpointReset-B8LYpWvr.js +17 -0
- package/dist/assets/scheduledTasksApi-GC4epIYA.js +1 -0
- package/dist/assets/{shikiHighlight-DE-OwqGw.js → shikiHighlight-BJISeZsQ.js} +1 -1
- package/dist/assets/surface-BvRzS58U.js +1 -0
- package/dist/assets/tr-B8Q0Go2l.js +7 -0
- package/dist/assets/uk-Dk4a-Fn-.js +16 -0
- package/dist/assets/{useAppFontEffects-COAeIX-D.js → useAppFontEffects-DpFNefUA.js} +153 -179
- package/dist/assets/useGitComparison-Dfxaqd0s.js +1 -0
- package/dist/assets/useInlineCommentController-CscsE4t-.js +2 -0
- package/dist/assets/useRootScrollLock-BaCvuRlT.js +1 -0
- package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-DdV8vhHn.js} +1 -1
- package/dist/assets/{vendor-codemirror-language-data-BG3v1Ghq.js → vendor-codemirror-language-data-DzlSIu_W.js} +2 -2
- package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
- package/dist/assets/vendor-zod-BPAANqvH.js +39 -0
- package/dist/assets/{web-components-BNMwa0qm.js → web-components-CdGfR2XJ.js} +1 -1
- package/dist/assets/zh-CN-B_BXxG1Q.js +16 -0
- package/dist/assets/zh-TW-DLrl1SPZ.js +16 -0
- package/dist/index.html +5 -43
- package/dist/mini-chat.html +4 -4
- package/dist/mobile.html +4 -4
- package/package.json +8 -5
- package/server/index.d.ts +15 -0
- package/server/index.js +82 -13
- package/server/lib/agent-tool/runtime.js +2 -19
- package/server/lib/changelog/update-notes.js +82 -0
- package/server/lib/changelog/update-notes.test.js +59 -0
- package/server/lib/data-dir-migration.js +40 -0
- package/server/lib/data-dir-migration.test.js +59 -0
- package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
- package/server/lib/dev-tunnel/runtime.js +4 -4
- package/server/lib/dev-tunnel/tunnel.test.js +20 -0
- package/server/lib/event-stream/runtime.test.js +12 -12
- package/server/lib/fs/DOCUMENTATION.md +5 -0
- package/server/lib/fs/routes.js +63 -21
- package/server/lib/fs/routes.test.js +187 -1
- package/server/lib/git/DOCUMENTATION.md +32 -6
- package/server/lib/git/routes.js +40 -4
- package/server/lib/git/service.js +291 -215
- package/server/lib/git/service.test.js +593 -25
- package/server/lib/inherited-env.js +16 -9
- package/server/lib/inherited-env.test.js +8 -9
- package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
- package/server/lib/mcp-reconnect/runtime.js +122 -0
- package/server/lib/mcp-reconnect/runtime.test.js +140 -0
- package/server/lib/message-queue/DOCUMENTATION.md +161 -0
- package/server/lib/message-queue/runtime.js +870 -0
- package/server/lib/message-queue/runtime.test.js +482 -0
- package/server/lib/network-defaults.js +23 -0
- package/server/lib/network-defaults.test.js +52 -0
- package/server/lib/openchamber-sessions/routes.js +102 -0
- package/server/lib/openchamber-sessions/routes.test.js +88 -0
- package/server/lib/opencode/DOCUMENTATION.md +30 -6
- package/server/lib/opencode/bootstrap-runtime.js +2 -0
- package/server/lib/opencode/config-paths.test.js +116 -0
- package/server/lib/opencode/core-routes.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +7 -0
- package/server/lib/opencode/input-history-scope.js +14 -0
- package/server/lib/opencode/managed-plugin-config.js +35 -0
- package/server/lib/opencode/openchamber-routes.js +64 -4
- package/server/lib/opencode/openchamber-routes.test.js +130 -3
- package/server/lib/opencode/plugins.js +2 -2
- package/server/lib/opencode/providers.js +44 -2
- package/server/lib/opencode/providers.test.js +131 -4
- package/server/lib/opencode/routes.js +9 -7
- package/server/lib/opencode/server-startup-runtime.js +1 -1
- package/server/lib/opencode/settings-files.js +214 -0
- package/server/lib/opencode/settings-helpers.js +113 -41
- package/server/lib/opencode/settings-helpers.test.js +342 -0
- package/server/lib/opencode/settings-registry.json +747 -0
- package/server/lib/opencode/settings-runtime.js +141 -20
- package/server/lib/opencode/settings-runtime.test.js +191 -4
- package/server/lib/opencode/shared.js +4 -1
- package/server/lib/opencode/shutdown-runtime.js +2 -0
- package/server/lib/opencode/skill-routes.js +2 -1
- package/server/lib/opencode/snippets.js +1 -2
- package/server/lib/package-manager.js +4 -29
- package/server/lib/package-manager.test.js +2 -2
- package/server/lib/project-context/DOCUMENTATION.md +25 -1
- package/server/lib/project-context/routes.http.test.js +18 -0
- package/server/lib/project-context/routes.js +15 -0
- package/server/lib/project-context/runtime.js +248 -23
- package/server/lib/project-context/runtime.test.js +106 -3
- package/server/lib/projects/DOCUMENTATION.md +76 -0
- package/server/lib/projects/project-config.js +142 -9
- package/server/lib/projects/project-id.js +17 -0
- package/server/lib/projects/project-setup.js +409 -0
- package/server/lib/projects/project-setup.test.js +557 -0
- package/server/lib/projects/routes.js +59 -0
- package/server/lib/quota/DOCUMENTATION.md +40 -2
- package/server/lib/quota/credentials/providers.js +4 -0
- package/server/lib/quota/credentials/store.js +1 -1
- package/server/lib/quota/credentials/store.test.js +4 -4
- package/server/lib/quota/index.js +1 -0
- package/server/lib/quota/providers/cline-pass.js +125 -0
- package/server/lib/quota/providers/cline-pass.test.js +103 -0
- package/server/lib/quota/providers/exe-dev.js +75 -0
- package/server/lib/quota/providers/exe-dev.test.js +47 -0
- package/server/lib/quota/providers/hyper.js +118 -0
- package/server/lib/quota/providers/hyper.test.js +126 -0
- package/server/lib/quota/providers/index.js +22 -0
- package/server/lib/quota/providers/neuralwatt.js +3 -6
- package/server/lib/quota/providers/neuralwatt.test.js +7 -7
- package/server/lib/quota/providers/ollama-cloud.js +31 -0
- package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
- package/server/lib/quota/providers/opencode-go.js +2 -1
- package/server/lib/quota/providers/opencode-go.test.js +31 -2
- package/server/lib/quota/providers/openrouter.js +119 -24
- package/server/lib/quota/providers/openrouter.test.js +330 -0
- package/server/lib/quota/routes.js +2 -0
- package/server/lib/quota/utils/auth.js +1 -1
- package/server/lib/relay/DOCUMENTATION.md +56 -1
- package/server/lib/relay/cross-compat.test.js +26 -0
- package/server/lib/relay/downstream-scheduler.js +154 -0
- package/server/lib/relay/downstream-scheduler.test.js +162 -0
- package/server/lib/relay/e2ee.js +10 -8
- package/server/lib/relay/flow-control.test.js +177 -0
- package/server/lib/relay/host-client.js +37 -8
- package/server/lib/relay/host-client.test.js +9 -1
- package/server/lib/relay/tunnel-codec.js +9 -0
- package/server/lib/relay/tunnel-host.js +69 -18
- package/server/lib/relay/tunnel-host.test.js +9 -1
- package/server/lib/security/request-security.js +21 -6
- package/server/lib/security/request-security.test.js +42 -8
- package/server/lib/session-assist/runtime.js +7 -10
- package/server/lib/session-goal/DOCUMENTATION.md +20 -7
- package/server/lib/session-goal/create.js +3 -1
- package/server/lib/session-goal/runtime.js +81 -20
- package/server/lib/session-goal/runtime.test.js +426 -0
- package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
- package/server/lib/skills-catalog/install.js +3 -2
- package/server/lib/small-model/DOCUMENTATION.md +7 -2
- package/server/lib/small-model/call.js +17 -6
- package/server/lib/small-model/call.test.js +52 -0
- package/server/lib/small-model/index.js +7 -11
- package/server/lib/small-model/routes.js +2 -1
- package/server/lib/small-model/runtime-providers.js +15 -7
- package/server/lib/small-model/runtime-providers.test.js +7 -1
- package/server/lib/system-prompt/runtime.js +2 -21
- package/server/lib/terminal/DOCUMENTATION.md +14 -10
- package/server/lib/terminal/runtime.js +190 -31
- package/server/lib/terminal/runtime.test.js +571 -37
- package/server/lib/terminal/shells.js +17 -0
- package/server/lib/terminal/shells.test.js +32 -1
- package/server/lib/ui-auth/ui-auth.js +4 -1
- package/server/lib/ui-auth/ui-auth.test.js +16 -0
- package/server/lib/walkthrough/DOCUMENTATION.md +33 -14
- package/server/lib/walkthrough/index.js +1 -0
- package/server/lib/walkthrough/model-settings.js +8 -12
- package/server/lib/walkthrough/prompt.js +3 -1
- package/server/lib/walkthrough/routes.test.js +26 -5
- package/server/lib/walkthrough/sources.js +23 -2
- package/dist/assets/CommitSection-X-f2RgYr.js +0 -1
- package/dist/assets/DiffView-Dh1ey2x9.js +0 -4
- package/dist/assets/FilesView-3ZYP72ki.js +0 -17
- package/dist/assets/GitView-CMuN7z2Z.js +0 -6
- package/dist/assets/LinearIssuesView-CQiUDU8b.js +0 -1
- package/dist/assets/MarkdownImageGallery-bA0PS-tn.js +0 -1
- package/dist/assets/MarkdownRendererImpl-BGQi2PLq.js +0 -12
- package/dist/assets/OnboardingScreen-D3kYJIb6.js +0 -1
- package/dist/assets/PierreDiffViewer-Ct2A13NO.js +0 -157
- package/dist/assets/PlanView-6AUjzNQn.js +0 -5
- package/dist/assets/SettingsView-CHI8fFaK.js +0 -28
- package/dist/assets/ToolPartDiffPreview-DPAATNn6.js +0 -8
- package/dist/assets/WalkthroughView-AX-u2pFg.js +0 -4
- package/dist/assets/contextPanelEmbeddedChat-C9EcRSDF.js +0 -1
- package/dist/assets/de-DqVn5vme.js +0 -9
- package/dist/assets/es-hj43Z53i.js +0 -15
- package/dist/assets/fr-BmkZt2mF.js +0 -13
- package/dist/assets/index-L_ncV-6H.css +0 -1
- package/dist/assets/index-qES19dlJ.js +0 -7
- package/dist/assets/ja-DioMIEGF.js +0 -15
- package/dist/assets/ko-BqPgaQJb.js +0 -15
- package/dist/assets/main-CYgSu6dx.js +0 -928
- package/dist/assets/markdownCore-CWRCqSH2.js +0 -3
- package/dist/assets/patchFileDiff-BpMQZnYu.js +0 -10
- package/dist/assets/pl-slULBF4R.js +0 -15
- package/dist/assets/pt-BR-BqH8fuCH.js +0 -15
- package/dist/assets/renderElectronMiniChatApp-D77bmLqo.js +0 -2
- package/dist/assets/renderMobileApp-BQ3Kdm-d.js +0 -25
- package/dist/assets/runtimeEndpointReset-CRGn1gVj.js +0 -16
- package/dist/assets/scheduledTasksApi-BSRCtP6T.js +0 -1
- package/dist/assets/tr-CjEbw1Aw.js +0 -6
- package/dist/assets/uk-BkkfxbOs.js +0 -15
- package/dist/assets/useInlineCommentController-JsBboQwt.js +0 -2
- package/dist/assets/useRootScrollLock-C0N9mCwz.js +0 -1
- package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
- package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
- package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
- package/dist/assets/zh-CN-C6FMdVgv.js +0 -15
- package/dist/assets/zh-TW-CdcMjDxv.js +0 -15
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import os from 'os';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import fsPromises from 'fs/promises';
|
|
5
|
+
|
|
6
|
+
import { migrateLegacyUserDirs } from './data-dir-migration.js';
|
|
7
|
+
|
|
8
|
+
const setup = async () => {
|
|
9
|
+
const root = await fsPromises.mkdtemp(path.join(os.tmpdir(), 'oc-data-dir-'));
|
|
10
|
+
const legacyRoot = path.join(root, 'legacy');
|
|
11
|
+
const dataDir = path.join(root, 'custom');
|
|
12
|
+
await fsPromises.mkdir(path.join(legacyRoot, 'projects'), { recursive: true });
|
|
13
|
+
await fsPromises.writeFile(path.join(legacyRoot, 'projects', 'p.json'), '{"a":1}');
|
|
14
|
+
await fsPromises.mkdir(path.join(legacyRoot, 'themes'), { recursive: true });
|
|
15
|
+
return { root, legacyRoot, dataDir, cleanup: () => fsPromises.rm(root, { recursive: true, force: true }) };
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
describe('migrateLegacyUserDirs', () => {
|
|
19
|
+
it('copies the user folders once into a custom data dir and leaves the originals', async () => {
|
|
20
|
+
const { legacyRoot, dataDir, cleanup } = await setup();
|
|
21
|
+
try {
|
|
22
|
+
const warnings = [];
|
|
23
|
+
const moved = await migrateLegacyUserDirs({ fsPromises, path, dataDir, legacyRoot, warn: (message) => warnings.push(message) });
|
|
24
|
+
expect(moved).toEqual(['projects', 'themes']);
|
|
25
|
+
expect(warnings).toEqual([]);
|
|
26
|
+
expect(await fsPromises.readFile(path.join(dataDir, 'projects', 'p.json'), 'utf8')).toBe('{"a":1}');
|
|
27
|
+
// The default instance keeps its own copy: a second instance must not strip it.
|
|
28
|
+
expect(await fsPromises.readFile(path.join(legacyRoot, 'projects', 'p.json'), 'utf8')).toBe('{"a":1}');
|
|
29
|
+
// A second start copies nothing more.
|
|
30
|
+
expect(await migrateLegacyUserDirs({ fsPromises, path, dataDir, legacyRoot })).toEqual([]);
|
|
31
|
+
} finally {
|
|
32
|
+
await cleanup();
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('never merges into a folder that already exists in the data dir', async () => {
|
|
37
|
+
const { legacyRoot, dataDir, cleanup } = await setup();
|
|
38
|
+
try {
|
|
39
|
+
await fsPromises.mkdir(path.join(dataDir, 'projects'), { recursive: true });
|
|
40
|
+
await fsPromises.writeFile(path.join(dataDir, 'projects', 'q.json'), '{}');
|
|
41
|
+
const moved = await migrateLegacyUserDirs({ fsPromises, path, dataDir, legacyRoot });
|
|
42
|
+
expect(moved).toEqual(['themes']);
|
|
43
|
+
expect(await fsPromises.readdir(path.join(dataDir, 'projects'))).toEqual(['q.json']);
|
|
44
|
+
expect(await fsPromises.readdir(path.join(legacyRoot, 'projects'))).toEqual(['p.json']);
|
|
45
|
+
} finally {
|
|
46
|
+
await cleanup();
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('is a no-op when the data dir is the default root', async () => {
|
|
51
|
+
const { legacyRoot, cleanup } = await setup();
|
|
52
|
+
try {
|
|
53
|
+
expect(await migrateLegacyUserDirs({ fsPromises, path, dataDir: legacyRoot, legacyRoot })).toEqual([]);
|
|
54
|
+
expect(await fsPromises.readdir(path.join(legacyRoot, 'projects'))).toEqual(['p.json']);
|
|
55
|
+
} finally {
|
|
56
|
+
await cleanup();
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -20,7 +20,13 @@ and what made it fragile per framework.
|
|
|
20
20
|
- `client.js` is the local end: it binds a loopback listener on the user's
|
|
21
21
|
machine and pipes each accepted connection through one WebSocket. It lives in
|
|
22
22
|
this package because it needs a WebSocket client the package already depends
|
|
23
|
-
on; the desktop shell drives it over IPC
|
|
23
|
+
on; the desktop shell drives it over IPC for directly reachable HTTP(S)
|
|
24
|
+
runtimes.
|
|
25
|
+
- Relay-only runtimes use `packages/electron/relay-dev-tunnel.mjs` for the local
|
|
26
|
+
listener. Each accepted connection gets an Electron `MessagePort`; the trusted
|
|
27
|
+
renderer carries its bytes through the active E2EE relay. This keeps relay
|
|
28
|
+
credentials and encryption in their existing renderer owner instead of
|
|
29
|
+
duplicating them in Electron main.
|
|
24
30
|
- Port discovery is not owned here. `runtime.js` is given the reachable set by
|
|
25
31
|
the same dev-server discovery the user's own list is built from.
|
|
26
32
|
- The browser panel decides when to tunnel; this module never chooses a target.
|
|
@@ -40,9 +46,12 @@ and what made it fragile per framework.
|
|
|
40
46
|
usual origin allowlist applies unchanged. That check is a CSRF defence: a
|
|
41
47
|
hostile page can make a browser open a WebSocket carrying ambient cookies,
|
|
42
48
|
and the origin is what exposes it.
|
|
43
|
-
- With no `Origin` the request must carry client-token auth
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
- With no `Origin` the request must carry client-token auth or a short-lived
|
|
50
|
+
URL token. The bearer case is the desktop main process. The URL-token case
|
|
51
|
+
is the trusted renderer carrying the socket through the E2EE relay.
|
|
52
|
+
- Through the E2EE relay, the trusted renderer mints a short-lived URL token
|
|
53
|
+
and includes it in the virtual WebSocket URL. The relay host and URL-token
|
|
54
|
+
allowlists accept exactly `/api/dev-tunnel`, not subpaths.
|
|
46
55
|
- Concurrency is capped per host, not per page, because one page load opens
|
|
47
56
|
many sockets.
|
|
48
57
|
- A connection that cannot be established fails the socket rather than holding
|
|
@@ -20,9 +20,9 @@
|
|
|
20
20
|
*
|
|
21
21
|
* - With an `Origin` header, the request came from a browser context and the
|
|
22
22
|
* usual origin check applies unchanged.
|
|
23
|
-
* - With no `Origin`, the request must carry client-token auth
|
|
24
|
-
*
|
|
25
|
-
*
|
|
23
|
+
* - With no `Origin`, the request must carry client-token auth or a short-lived
|
|
24
|
+
* URL token. The URL-token case is used only by the trusted renderer through
|
|
25
|
+
* the E2EE relay; the UI-auth allowlist limits it to this exact path.
|
|
26
26
|
*/
|
|
27
27
|
import net from 'node:net';
|
|
28
28
|
import { WebSocketServer } from 'ws';
|
|
@@ -133,7 +133,7 @@ export function createDevTunnelRuntime({
|
|
|
133
133
|
void (async () => {
|
|
134
134
|
try {
|
|
135
135
|
if (uiAuthController?.enabled) {
|
|
136
|
-
const auth = await uiAuthController.resolveAuthContext(req, null, { allowUrlToken:
|
|
136
|
+
const auth = await uiAuthController.resolveAuthContext(req, null, { allowUrlToken: true });
|
|
137
137
|
if (!auth) {
|
|
138
138
|
rejectWebSocketUpgrade(socket, 401, 'UI authentication required');
|
|
139
139
|
return;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { afterEach, describe, expect, test } from 'bun:test';
|
|
2
2
|
import http from 'node:http';
|
|
3
3
|
import net from 'node:net';
|
|
4
|
+
import WebSocket from 'ws';
|
|
4
5
|
|
|
5
6
|
import { createDevTunnelClient } from './client.js';
|
|
6
7
|
import { createDevTunnelRuntime, isDevTunnelPath } from './runtime.js';
|
|
@@ -228,6 +229,12 @@ describe('dev tunnel authentication', () => {
|
|
|
228
229
|
enabled: true,
|
|
229
230
|
resolveAuthContext: async () => ({ type: 'session' }),
|
|
230
231
|
};
|
|
232
|
+
const urlTokenAuth = {
|
|
233
|
+
enabled: true,
|
|
234
|
+
resolveAuthContext: async (req, _res, options) => (
|
|
235
|
+
options?.allowUrlToken === true && req.url.includes('oc_url_token=good') ? { type: 'client', token: 'url:authenticated' } : null
|
|
236
|
+
),
|
|
237
|
+
};
|
|
231
238
|
|
|
232
239
|
test('accepts a bearer-authenticated client that sends no origin', async () => {
|
|
233
240
|
const devPort = await startDevServer((_req, res) => res.end('ok'));
|
|
@@ -243,6 +250,19 @@ describe('dev tunnel authentication', () => {
|
|
|
243
250
|
expect((await httpGet(localPort, '/')).body).toBe('ok');
|
|
244
251
|
});
|
|
245
252
|
|
|
253
|
+
test('accepts a URL-token client carried by the E2EE relay', async () => {
|
|
254
|
+
const devPort = await startDevServer((_req, res) => res.end('relay-ok'));
|
|
255
|
+
const host = await startHost({ allowedPorts: [devPort], auth: urlTokenAuth });
|
|
256
|
+
|
|
257
|
+
const body = await new Promise((resolve, reject) => {
|
|
258
|
+
const socket = new WebSocket(`ws://127.0.0.1:${host.port}/api/dev-tunnel?port=${devPort}&oc_url_token=good`);
|
|
259
|
+
socket.on('open', () => socket.send('GET / HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n'));
|
|
260
|
+
socket.on('message', (data) => resolve(Buffer.from(data).toString()));
|
|
261
|
+
socket.on('error', reject);
|
|
262
|
+
});
|
|
263
|
+
expect(body).toContain('relay-ok');
|
|
264
|
+
});
|
|
265
|
+
|
|
246
266
|
test('rejects a client with no credentials', async () => {
|
|
247
267
|
const devPort = await startDevServer((_req, res) => res.end('ok'));
|
|
248
268
|
const host = await startHost({ allowedPorts: [devPort], auth: clientAuth });
|
|
@@ -446,18 +446,18 @@ describe('message stream websocket runtime', () => {
|
|
|
446
446
|
const socket = new FakeSocket();
|
|
447
447
|
runtime.wsServer.emit('connection', socket, { url: '/api/global/event/ws' });
|
|
448
448
|
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
449
|
+
try {
|
|
450
|
+
// Wait for the reconnect event itself; a 35ms sleep raced the event
|
|
451
|
+
// loop when the workspace build and test workers ran together.
|
|
452
|
+
await expect.poll(() => socket.sent.filter((frame) => frame.type === 'ready').length).toBeGreaterThanOrEqual(2);
|
|
453
|
+
const eventFrames = socket.sent.filter((frame) => frame.type === 'event' && frame.payload?.type === 'server.connected');
|
|
454
|
+
expect(eventFrames.length).toBeGreaterThanOrEqual(2);
|
|
455
|
+
expect(fetchCalls.slice(0, 2)).toEqual([null, 'evt-1']);
|
|
456
|
+
expect(triggerHealthCheckCalls).toBe(0);
|
|
457
|
+
} finally {
|
|
458
|
+
socket.close();
|
|
459
|
+
await runtime.close();
|
|
460
|
+
}
|
|
461
461
|
});
|
|
462
462
|
|
|
463
463
|
it('keeps synthetic event processing on forwarded upstream events', async () => {
|
|
@@ -14,6 +14,8 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
|
|
|
14
14
|
- `POST /api/fs/mkdir`
|
|
15
15
|
- `GET /api/fs/read`
|
|
16
16
|
- `GET /api/fs/raw`
|
|
17
|
+
- `GET /api/fs/stat`
|
|
18
|
+
- `GET /api/fs/directory-stat`
|
|
17
19
|
- `GET /api/fs/serve/:path(*)`
|
|
18
20
|
- `POST /api/fs/write`
|
|
19
21
|
- `POST /api/fs/upload`
|
|
@@ -40,7 +42,10 @@ Own filesystem API behavior for the web server runtime, including workspace-boun
|
|
|
40
42
|
|
|
41
43
|
## Notes for contributors
|
|
42
44
|
- Keep filesystem policy (workspace root checks, error mapping, exec timeout behavior) inside this module, not in the composition root.
|
|
45
|
+
- Workspace checks accept, besides the active workspace and its worktrees, the **managed roots**: the OpenChamber config root and the managed chats root (`managedChatsRoot` dependency; `OPENCHAMBER_CHATS_DIR` upstream, default `<config root>/chats`). Chat worktrees may legitimately live outside every project workspace.
|
|
46
|
+
- `GET /api/fs/home` answers `{ home, chatsRoot }`. `chatsRoot` is the server-resolved managed chats root; clients must use it instead of joining `home` + the well-known segment (a relocated root does not contain that segment).
|
|
43
47
|
- Filesystem `EPERM`/`EACCES` failures use the stable `reason: "os-permission"` response marker. Policy denials such as workspace-boundary or missing-grant failures must not use that marker because a native folder picker cannot remediate them.
|
|
48
|
+
- `GET /api/fs/directory-stat?path=...` uses one `stat` without listing contents or resolving project topology. It follows the same authenticated directory-discovery path policy as `/api/fs/list`, including targets outside the active workspace. A directory returns `{ isDirectory: true }`; `ENOENT` returns `not-found`, and a file or `ENOTDIR` returns `not-directory`. Permission and other failures remain distinct from a missing path. VS Code explicitly returns 501, so the shared client treats its probe as unknown.
|
|
44
49
|
- Read-only routes authorize the requested path against the workspace before resolving symlinks. A symlink reached through the workspace may therefore target a file outside it, while a directly requested outside path still requires an exact-path grant. Write routes keep canonical-target boundary checks.
|
|
45
50
|
- If adding new `/api/fs/*` endpoints, add them in `routes.js` and extend this document.
|
|
46
51
|
- `GET /api/fs/list` may resolve symlinks with `realpath` to read directory contents, but the response `path` and each entry `path` must stay in the caller's requested path space (`path.join(requestedPath, name)`). Returning real paths breaks file-tree expansion for directories reached through workspace symlinks.
|
package/server/lib/fs/routes.js
CHANGED
|
@@ -196,7 +196,7 @@ const isPathWithinRoot = (resolvedPath, rootPath, path, os) => {
|
|
|
196
196
|
return true;
|
|
197
197
|
};
|
|
198
198
|
|
|
199
|
-
const resolveWorkspacePath = ({ targetPath, baseDirectory, path, os, normalizeDirectoryPath,
|
|
199
|
+
const resolveWorkspacePath = ({ targetPath, baseDirectory, path, os, normalizeDirectoryPath, managedRoots }) => {
|
|
200
200
|
const normalized = normalizeDirectoryPath(targetPath);
|
|
201
201
|
if (!normalized || typeof normalized !== 'string') {
|
|
202
202
|
return { ok: false, error: 'Path is required' };
|
|
@@ -209,8 +209,12 @@ const resolveWorkspacePath = ({ targetPath, baseDirectory, path, os, normalizeDi
|
|
|
209
209
|
return { ok: true, base: resolvedBase, resolved };
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
// Managed roots (config root, relocated chats root) stay valid targets
|
|
213
|
+
// even outside the active workspace.
|
|
214
|
+
for (const root of managedRoots) {
|
|
215
|
+
if (isPathWithinRoot(resolved, root, path, os)) {
|
|
216
|
+
return { ok: true, base: path.resolve(root), resolved };
|
|
217
|
+
}
|
|
214
218
|
}
|
|
215
219
|
|
|
216
220
|
return { ok: false, error: 'Path is outside of active workspace' };
|
|
@@ -249,7 +253,7 @@ const resolveWorkspacePathFromWorktrees = async ({ targetPath, baseDirectory, pa
|
|
|
249
253
|
return { ok: false, error: 'Path is outside of active workspace' };
|
|
250
254
|
};
|
|
251
255
|
|
|
252
|
-
const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProjectDirectory, path, os, normalizeDirectoryPath,
|
|
256
|
+
const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProjectDirectory, path, os, normalizeDirectoryPath, managedRoots }) => {
|
|
253
257
|
const resolvedProject = await resolveProjectDirectory(req);
|
|
254
258
|
if (!resolvedProject.directory) {
|
|
255
259
|
return { ok: false, error: resolvedProject.error || 'Active workspace is required' };
|
|
@@ -261,7 +265,7 @@ const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProject
|
|
|
261
265
|
path,
|
|
262
266
|
os,
|
|
263
267
|
normalizeDirectoryPath,
|
|
264
|
-
|
|
268
|
+
managedRoots,
|
|
265
269
|
});
|
|
266
270
|
if (resolved.ok || resolved.error !== 'Path is outside of active workspace') {
|
|
267
271
|
return resolved;
|
|
@@ -281,7 +285,7 @@ const resolveWorkspacePathFromContext = async ({ req, targetPath, resolveProject
|
|
|
281
285
|
path,
|
|
282
286
|
os,
|
|
283
287
|
normalizeDirectoryPath,
|
|
284
|
-
|
|
288
|
+
managedRoots,
|
|
285
289
|
});
|
|
286
290
|
if (lexical.ok) {
|
|
287
291
|
return lexical;
|
|
@@ -412,7 +416,7 @@ const escapeCloneSshKeyPath = (sshKeyPath) => {
|
|
|
412
416
|
return `'${normalized.replace(/'/g, "'\\''")}'`;
|
|
413
417
|
};
|
|
414
418
|
|
|
415
|
-
const resolveReadPathFromContext = async ({ req, targetPath, scope, resolveProjectDirectory, path, os, fsPromises, normalizeDirectoryPath,
|
|
419
|
+
const resolveReadPathFromContext = async ({ req, targetPath, scope, resolveProjectDirectory, path, os, fsPromises, normalizeDirectoryPath, managedRoots }) => {
|
|
416
420
|
if (req.query?.allowOutsideWorkspace === 'true') {
|
|
417
421
|
const normalized = normalizeDirectoryPath(targetPath);
|
|
418
422
|
if (!normalized || typeof normalized !== 'string') {
|
|
@@ -434,7 +438,7 @@ const resolveReadPathFromContext = async ({ req, targetPath, scope, resolveProje
|
|
|
434
438
|
path,
|
|
435
439
|
os,
|
|
436
440
|
normalizeDirectoryPath,
|
|
437
|
-
|
|
441
|
+
managedRoots,
|
|
438
442
|
});
|
|
439
443
|
};
|
|
440
444
|
|
|
@@ -520,7 +524,14 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
520
524
|
buildAugmentedPath,
|
|
521
525
|
resolveGitBinaryForSpawn,
|
|
522
526
|
openchamberUserConfigRoot,
|
|
527
|
+
managedChatsRoot,
|
|
523
528
|
} = dependencies;
|
|
529
|
+
// Chat worktrees may live outside every project workspace; both managed
|
|
530
|
+
// roots stay valid filesystem targets.
|
|
531
|
+
const chatsRoot = typeof managedChatsRoot === 'string' && managedChatsRoot.trim()
|
|
532
|
+
? path.resolve(managedChatsRoot.trim())
|
|
533
|
+
: path.join(openchamberUserConfigRoot, 'chats');
|
|
534
|
+
const managedRoots = [path.resolve(openchamberUserConfigRoot), chatsRoot];
|
|
524
535
|
const realpathCache = createRealpathCache({
|
|
525
536
|
realpath: fsPromises.realpath.bind(fsPromises),
|
|
526
537
|
});
|
|
@@ -699,7 +710,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
699
710
|
if (!home || typeof home !== 'string' || home.length === 0) {
|
|
700
711
|
return res.status(500).json({ error: 'Failed to resolve home directory' });
|
|
701
712
|
}
|
|
702
|
-
return res.json({ home });
|
|
713
|
+
return res.json({ home, chatsRoot });
|
|
703
714
|
} catch (error) {
|
|
704
715
|
console.error('Failed to resolve home directory:', error);
|
|
705
716
|
return res.status(500).json({ error: (error && error.message) || 'Failed to resolve home directory' });
|
|
@@ -725,7 +736,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
725
736
|
path,
|
|
726
737
|
os,
|
|
727
738
|
normalizeDirectoryPath,
|
|
728
|
-
|
|
739
|
+
managedRoots,
|
|
729
740
|
});
|
|
730
741
|
if (!resolved.ok) {
|
|
731
742
|
return res.status(400).json({ error: resolved.error });
|
|
@@ -853,6 +864,37 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
853
864
|
}
|
|
854
865
|
});
|
|
855
866
|
|
|
867
|
+
app.get('/api/fs/directory-stat', async (req, res) => {
|
|
868
|
+
res.setHeader('Cache-Control', 'no-store');
|
|
869
|
+
const paths = new URL(req.url, 'http://openchamber.local').searchParams.getAll('path');
|
|
870
|
+
const directoryPath = paths.length === 1 ? paths[0].trim() : '';
|
|
871
|
+
if (!directoryPath) {
|
|
872
|
+
return res.status(400).json({ error: 'Path is required' });
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
try {
|
|
876
|
+
// Directory discovery uses the same path policy as /api/fs/list, including
|
|
877
|
+
// paths outside the current workspace. stat follows symlinks without readdir.
|
|
878
|
+
const resolvedPath = path.resolve(normalizeDirectoryPath(directoryPath));
|
|
879
|
+
const stats = await fsPromises.stat(resolvedPath);
|
|
880
|
+
if (!stats.isDirectory()) {
|
|
881
|
+
return res.status(400).json({ error: 'Specified path is not a directory', reason: 'not-directory' });
|
|
882
|
+
}
|
|
883
|
+
return res.json({ isDirectory: true });
|
|
884
|
+
} catch (error) {
|
|
885
|
+
if (error.code === 'ENOENT' || error.code === 'ENOTDIR') {
|
|
886
|
+
return res.status(error.code === 'ENOENT' ? 404 : 400).json({
|
|
887
|
+
error: error.code === 'ENOENT' ? 'Directory not found' : 'Specified path is not a directory',
|
|
888
|
+
reason: error.code === 'ENOENT' ? 'not-found' : 'not-directory',
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
if (isOsPermissionError(error)) {
|
|
892
|
+
return sendOsPermissionDenied(res, 'Access to directory denied');
|
|
893
|
+
}
|
|
894
|
+
return res.status(500).json({ error: 'Failed to stat directory' });
|
|
895
|
+
}
|
|
896
|
+
});
|
|
897
|
+
|
|
856
898
|
app.get('/api/fs/stat', async (req, res) => {
|
|
857
899
|
const filePath = typeof req.query.path === 'string' ? req.query.path.trim() : '';
|
|
858
900
|
const optional = req.query.optional === 'true';
|
|
@@ -870,7 +912,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
870
912
|
os,
|
|
871
913
|
fsPromises,
|
|
872
914
|
normalizeDirectoryPath,
|
|
873
|
-
|
|
915
|
+
managedRoots,
|
|
874
916
|
});
|
|
875
917
|
if (!resolved.ok) {
|
|
876
918
|
if (req.query?.allowOutsideWorkspace === 'true') {
|
|
@@ -920,7 +962,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
920
962
|
os,
|
|
921
963
|
fsPromises,
|
|
922
964
|
normalizeDirectoryPath,
|
|
923
|
-
|
|
965
|
+
managedRoots,
|
|
924
966
|
});
|
|
925
967
|
if (!resolved.ok) {
|
|
926
968
|
if (req.query?.allowOutsideWorkspace === 'true') {
|
|
@@ -984,7 +1026,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
984
1026
|
os,
|
|
985
1027
|
fsPromises,
|
|
986
1028
|
normalizeDirectoryPath,
|
|
987
|
-
|
|
1029
|
+
managedRoots,
|
|
988
1030
|
});
|
|
989
1031
|
if (!resolved.ok) {
|
|
990
1032
|
if (req.query?.allowOutsideWorkspace === 'true') {
|
|
@@ -1065,7 +1107,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1065
1107
|
path,
|
|
1066
1108
|
os,
|
|
1067
1109
|
normalizeDirectoryPath,
|
|
1068
|
-
|
|
1110
|
+
managedRoots,
|
|
1069
1111
|
});
|
|
1070
1112
|
if (!resolved.ok) {
|
|
1071
1113
|
return res.status(400).json({ error: resolved.error });
|
|
@@ -1117,7 +1159,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1117
1159
|
path,
|
|
1118
1160
|
os,
|
|
1119
1161
|
normalizeDirectoryPath,
|
|
1120
|
-
|
|
1162
|
+
managedRoots,
|
|
1121
1163
|
});
|
|
1122
1164
|
if (!resolved.ok) {
|
|
1123
1165
|
return res.status(400).json({ error: resolved.error });
|
|
@@ -1187,7 +1229,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1187
1229
|
path,
|
|
1188
1230
|
os,
|
|
1189
1231
|
normalizeDirectoryPath,
|
|
1190
|
-
|
|
1232
|
+
managedRoots,
|
|
1191
1233
|
});
|
|
1192
1234
|
if (!resolved.ok) {
|
|
1193
1235
|
return res.status(400).json({ error: resolved.error });
|
|
@@ -1294,7 +1336,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1294
1336
|
path,
|
|
1295
1337
|
os,
|
|
1296
1338
|
normalizeDirectoryPath,
|
|
1297
|
-
|
|
1339
|
+
managedRoots,
|
|
1298
1340
|
});
|
|
1299
1341
|
if (!resolved.ok) {
|
|
1300
1342
|
return res.status(400).json({ error: resolved.error });
|
|
@@ -1332,7 +1374,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1332
1374
|
path,
|
|
1333
1375
|
os,
|
|
1334
1376
|
normalizeDirectoryPath,
|
|
1335
|
-
|
|
1377
|
+
managedRoots,
|
|
1336
1378
|
});
|
|
1337
1379
|
if (!resolvedOld.ok) {
|
|
1338
1380
|
return res.status(400).json({ error: resolvedOld.error });
|
|
@@ -1345,7 +1387,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1345
1387
|
path,
|
|
1346
1388
|
os,
|
|
1347
1389
|
normalizeDirectoryPath,
|
|
1348
|
-
|
|
1390
|
+
managedRoots,
|
|
1349
1391
|
});
|
|
1350
1392
|
if (!resolvedNew.ok) {
|
|
1351
1393
|
return res.status(400).json({ error: resolvedNew.error });
|
|
@@ -1451,7 +1493,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1451
1493
|
path,
|
|
1452
1494
|
os,
|
|
1453
1495
|
normalizeDirectoryPath,
|
|
1454
|
-
|
|
1496
|
+
managedRoots,
|
|
1455
1497
|
});
|
|
1456
1498
|
if (!resolvedForWorkspace.ok) {
|
|
1457
1499
|
console.warn(`Rejected /api/fs/exec outside workspace: ${resolvedForWorkspace.error}`);
|
|
@@ -1689,7 +1731,7 @@ export const registerFsRoutes = (app, dependencies) => {
|
|
|
1689
1731
|
path,
|
|
1690
1732
|
os,
|
|
1691
1733
|
normalizeDirectoryPath,
|
|
1692
|
-
|
|
1734
|
+
managedRoots,
|
|
1693
1735
|
});
|
|
1694
1736
|
if (!resolved.ok) {
|
|
1695
1737
|
return res.status(400).json({ error: resolved.error });
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
2
|
import path from 'path';
|
|
3
|
+
import { copyFile, mkdir, mkdtemp, rm } from 'node:fs/promises';
|
|
4
|
+
import { tmpdir } from 'node:os';
|
|
5
|
+
import { execFileSync } from 'node:child_process';
|
|
6
|
+
import { pathToFileURL } from 'node:url';
|
|
3
7
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
4
8
|
|
|
5
9
|
import { mintOutsideFileGrant, registerFsRoutes } from './routes.js';
|
|
@@ -1385,7 +1389,11 @@ describe('fs stat directory scope (issue 3019)', () => {
|
|
|
1385
1389
|
path: path.posix,
|
|
1386
1390
|
fsPromises: {
|
|
1387
1391
|
realpath: async (targetPath) => targetPath,
|
|
1388
|
-
stat: async () => (
|
|
1392
|
+
stat: async (targetPath) => (
|
|
1393
|
+
targetPath === '/repo-b'
|
|
1394
|
+
? { isDirectory: () => true, mtimeMs: 123 }
|
|
1395
|
+
: { isFile: () => true, size: 12, mtimeMs: 456 }
|
|
1396
|
+
),
|
|
1389
1397
|
},
|
|
1390
1398
|
spawn: vi.fn(),
|
|
1391
1399
|
crypto: { randomUUID: () => 'job-0' },
|
|
@@ -1428,4 +1436,182 @@ describe('fs stat directory scope (issue 3019)', () => {
|
|
|
1428
1436
|
expect(res.statusCode).toBe(200);
|
|
1429
1437
|
expect(res.body.isFile).toBe(true);
|
|
1430
1438
|
});
|
|
1439
|
+
|
|
1440
|
+
});
|
|
1441
|
+
|
|
1442
|
+
describe('fs stat directory error handling', () => {
|
|
1443
|
+
it('loads in Node without workspace node_modules, as packaged desktop does', async () => {
|
|
1444
|
+
const directory = await mkdtemp(path.join(tmpdir(), 'openchamber-fs-import-'));
|
|
1445
|
+
try {
|
|
1446
|
+
await mkdir(path.join(directory, 'fs'));
|
|
1447
|
+
await copyFile(new URL('./routes.js', import.meta.url), path.join(directory, 'fs/routes.mjs'));
|
|
1448
|
+
await copyFile(new URL('../path-realpath-cache.js', import.meta.url), path.join(directory, 'path-realpath-cache.js'));
|
|
1449
|
+
expect(() => execFileSync('node', [
|
|
1450
|
+
'--input-type=module',
|
|
1451
|
+
'--eval',
|
|
1452
|
+
'await import(process.argv[1])',
|
|
1453
|
+
pathToFileURL(path.join(directory, 'fs/routes.mjs')).href,
|
|
1454
|
+
], { cwd: directory, stdio: 'pipe' })).not.toThrow();
|
|
1455
|
+
} finally {
|
|
1456
|
+
await rm(directory, { recursive: true, force: true });
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1459
|
+
|
|
1460
|
+
it('returns directory-missing reasons and permission errors for directory stat', async () => {
|
|
1461
|
+
const { app, getRoute } = createRouteRegistry();
|
|
1462
|
+
const enoent = Object.assign(new Error('missing'), { code: 'ENOENT' });
|
|
1463
|
+
const enotdir = Object.assign(new Error('not a directory'), { code: 'ENOTDIR' });
|
|
1464
|
+
const eacces = Object.assign(new Error('denied'), { code: 'EACCES' });
|
|
1465
|
+
const stat = vi.fn(async (targetPath) => {
|
|
1466
|
+
if (targetPath === '/repo-b') throw enoent;
|
|
1467
|
+
if (targetPath === '/repo-b/file.txt/child') throw enotdir;
|
|
1468
|
+
if (targetPath === '/repo-b/protected') throw eacces;
|
|
1469
|
+
if (targetPath === '/repo-b/file.txt') return { isDirectory: () => false };
|
|
1470
|
+
if (targetPath === '/repo-b/failure') throw new Error('unavailable');
|
|
1471
|
+
return { isDirectory: () => true, mtimeMs: 1 };
|
|
1472
|
+
});
|
|
1473
|
+
const readdir = vi.fn(async () => []);
|
|
1474
|
+
const callStat = async (handler, { headers = {}, query }) => {
|
|
1475
|
+
const res = createMockResponse();
|
|
1476
|
+
const req = {
|
|
1477
|
+
url: `/api/fs/directory-stat?${new URLSearchParams(query)}`,
|
|
1478
|
+
query,
|
|
1479
|
+
get: (name) => headers[name.toLowerCase()] ?? undefined,
|
|
1480
|
+
};
|
|
1481
|
+
await handler(req, res);
|
|
1482
|
+
return res;
|
|
1483
|
+
};
|
|
1484
|
+
registerFsRoutes(app, {
|
|
1485
|
+
os: { homedir: () => '/home/user' },
|
|
1486
|
+
path: path.posix,
|
|
1487
|
+
fsPromises: {
|
|
1488
|
+
realpath: async (targetPath) => targetPath,
|
|
1489
|
+
stat,
|
|
1490
|
+
readdir,
|
|
1491
|
+
},
|
|
1492
|
+
spawn: vi.fn(),
|
|
1493
|
+
crypto: { randomUUID: () => 'job-0' },
|
|
1494
|
+
normalizeDirectoryPath: (p) => p,
|
|
1495
|
+
resolveProjectDirectory: async () => ({ directory: '/repo' }),
|
|
1496
|
+
buildAugmentedPath: () => '/usr/bin',
|
|
1497
|
+
resolveGitBinaryForSpawn: () => 'git',
|
|
1498
|
+
openchamberUserConfigRoot: '/home/user/.config',
|
|
1499
|
+
});
|
|
1500
|
+
const handler = getRoute('GET', '/api/fs/directory-stat');
|
|
1501
|
+
|
|
1502
|
+
const available = await callStat(handler, { query: { path: '/other-project' } });
|
|
1503
|
+
expect(available.statusCode).toBe(200);
|
|
1504
|
+
expect(available.body).toEqual({ isDirectory: true });
|
|
1505
|
+
expect(available.getHeader('Cache-Control')).toBe('no-store');
|
|
1506
|
+
expect(stat).toHaveBeenCalledTimes(1);
|
|
1507
|
+
|
|
1508
|
+
const invalid = await callStat(handler, { query: { path: ' ' } });
|
|
1509
|
+
expect(invalid.statusCode).toBe(400);
|
|
1510
|
+
expect(stat).toHaveBeenCalledTimes(1);
|
|
1511
|
+
|
|
1512
|
+
for (const query of ['path=/repo&path=/other', 'path[]=/repo', '']) {
|
|
1513
|
+
const malformed = createMockResponse();
|
|
1514
|
+
await handler({ url: `/api/fs/directory-stat?${query}` }, malformed);
|
|
1515
|
+
expect(malformed.statusCode).toBe(400);
|
|
1516
|
+
}
|
|
1517
|
+
expect(stat).toHaveBeenCalledTimes(1);
|
|
1518
|
+
|
|
1519
|
+
const missing = await callStat(handler, { headers: { 'x-opencode-directory': '/repo-b' }, query: { path: '/repo-b', directory: 'true' } });
|
|
1520
|
+
expect(missing.statusCode).toBe(404);
|
|
1521
|
+
expect(missing.body).toEqual({ error: 'Directory not found', reason: 'not-found' });
|
|
1522
|
+
|
|
1523
|
+
const notDir = await callStat(handler, { headers: { 'x-opencode-directory': '/repo-b' }, query: { path: '/repo-b/file.txt/child', directory: 'true' } });
|
|
1524
|
+
expect(notDir.statusCode).toBe(400);
|
|
1525
|
+
expect(notDir.body).toEqual({ error: 'Specified path is not a directory', reason: 'not-directory' });
|
|
1526
|
+
|
|
1527
|
+
const denied = await callStat(handler, { headers: { 'x-opencode-directory': '/repo-b' }, query: { path: '/repo-b/protected', directory: 'true' } });
|
|
1528
|
+
expect(denied.statusCode).toBe(403);
|
|
1529
|
+
expect(denied.body).toEqual({ error: 'Access to directory denied', reason: 'os-permission' });
|
|
1530
|
+
|
|
1531
|
+
const file = await callStat(handler, { query: { path: '/repo-b/file.txt' } });
|
|
1532
|
+
expect(file.statusCode).toBe(400);
|
|
1533
|
+
expect(file.body.reason).toBe('not-directory');
|
|
1534
|
+
|
|
1535
|
+
const failure = await callStat(handler, { query: { path: '/repo-b/failure' } });
|
|
1536
|
+
expect(failure.statusCode).toBe(500);
|
|
1537
|
+
expect(failure.body).toEqual({ error: 'Failed to stat directory' });
|
|
1538
|
+
expect(readdir).not.toHaveBeenCalled();
|
|
1539
|
+
});
|
|
1540
|
+
});
|
|
1541
|
+
|
|
1542
|
+
describe('fs managed chats root', () => {
|
|
1543
|
+
const registerWithChatsRoot = ({ managedChatsRoot, fsPromises = {} } = {}) => {
|
|
1544
|
+
const { app, getRoute } = createRouteRegistry();
|
|
1545
|
+
registerFsRoutes(app, {
|
|
1546
|
+
os: { homedir: () => '/home/user' },
|
|
1547
|
+
path: path.posix,
|
|
1548
|
+
fsPromises: {
|
|
1549
|
+
realpath: async (targetPath) => targetPath,
|
|
1550
|
+
mkdir: async () => undefined,
|
|
1551
|
+
...fsPromises,
|
|
1552
|
+
},
|
|
1553
|
+
spawn: vi.fn(),
|
|
1554
|
+
crypto: { randomUUID: () => 'job-0' },
|
|
1555
|
+
normalizeDirectoryPath: (p) => p,
|
|
1556
|
+
resolveProjectDirectory: async () => ({ directory: '/repo' }),
|
|
1557
|
+
buildAugmentedPath: () => '/usr/bin',
|
|
1558
|
+
resolveGitBinaryForSpawn: () => 'git',
|
|
1559
|
+
openchamberUserConfigRoot: '/home/user/.config/openchamber',
|
|
1560
|
+
managedChatsRoot,
|
|
1561
|
+
});
|
|
1562
|
+
return {
|
|
1563
|
+
home: getRoute('GET', '/api/fs/home'),
|
|
1564
|
+
mkdir: getRoute('POST', '/api/fs/mkdir'),
|
|
1565
|
+
};
|
|
1566
|
+
};
|
|
1567
|
+
|
|
1568
|
+
it('exposes the default chats root next to the home directory', async () => {
|
|
1569
|
+
const { home } = registerWithChatsRoot();
|
|
1570
|
+
|
|
1571
|
+
const res = createMockResponse();
|
|
1572
|
+
await home(undefined, res);
|
|
1573
|
+
|
|
1574
|
+
expect(res.statusCode).toBe(200);
|
|
1575
|
+
expect(res.body.home).toBe('/home/user');
|
|
1576
|
+
expect(res.body.chatsRoot).toBe('/home/user/.config/openchamber/chats');
|
|
1577
|
+
});
|
|
1578
|
+
|
|
1579
|
+
it('exposes a relocated chats root when OPENCHAMBER_CHATS_DIR is configured upstream', async () => {
|
|
1580
|
+
const { home } = registerWithChatsRoot({ managedChatsRoot: '/srv/openchamber-chats' });
|
|
1581
|
+
|
|
1582
|
+
const res = createMockResponse();
|
|
1583
|
+
await home(undefined, res);
|
|
1584
|
+
|
|
1585
|
+
expect(res.statusCode).toBe(200);
|
|
1586
|
+
expect(res.body.chatsRoot).toBe('/srv/openchamber-chats');
|
|
1587
|
+
});
|
|
1588
|
+
|
|
1589
|
+
it('allows mkdir inside the relocated chats root outside the active workspace', async () => {
|
|
1590
|
+
const mkdirCalls = [];
|
|
1591
|
+
const { mkdir } = registerWithChatsRoot({
|
|
1592
|
+
managedChatsRoot: '/srv/openchamber-chats',
|
|
1593
|
+
fsPromises: {
|
|
1594
|
+
mkdir: async (targetPath) => {
|
|
1595
|
+
mkdirCalls.push(targetPath);
|
|
1596
|
+
},
|
|
1597
|
+
},
|
|
1598
|
+
});
|
|
1599
|
+
|
|
1600
|
+
const res = createMockResponse();
|
|
1601
|
+
await mkdir({ body: { path: '/srv/openchamber-chats/2026-08-25/session-a' } }, res);
|
|
1602
|
+
|
|
1603
|
+
expect(res.statusCode).toBe(200);
|
|
1604
|
+
expect(res.body.success).toBe(true);
|
|
1605
|
+
expect(mkdirCalls).toEqual(['/srv/openchamber-chats/2026-08-25/session-a']);
|
|
1606
|
+
});
|
|
1607
|
+
|
|
1608
|
+
it('still rejects mkdir outside the workspace and all managed roots', async () => {
|
|
1609
|
+
const { mkdir } = registerWithChatsRoot({ managedChatsRoot: '/srv/openchamber-chats' });
|
|
1610
|
+
|
|
1611
|
+
const res = createMockResponse();
|
|
1612
|
+
await mkdir({ body: { path: '/etc/passwd-holder' } }, res);
|
|
1613
|
+
|
|
1614
|
+
expect(res.statusCode).toBe(400);
|
|
1615
|
+
expect(res.body).toEqual({ error: 'Path is outside of active workspace' });
|
|
1616
|
+
});
|
|
1431
1617
|
});
|