@openchamber/web 1.18.2 → 1.18.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.
Files changed (140) hide show
  1. package/bin/lib/commands-models.js +1 -1
  2. package/dist/assets/{CodeMirrorCommentWidgets-CxcJ5x9h.js → CodeMirrorCommentWidgets-4qZbrEXU.js} +1 -1
  3. package/dist/assets/{CommitSection-C9sBBYAJ.js → CommitSection-MJmntVPJ.js} +1 -1
  4. package/dist/assets/{DiagramEditor-C7nUw7p3.js → DiagramEditor-jnG3Hbxg.js} +1 -1
  5. package/dist/assets/{DiagramView-cYxZP-HS.js → DiagramView-CFXxgg_a.js} +1 -1
  6. package/dist/assets/{DiffView-1zd0slLu.js → DiffView-DZIoOnV7.js} +2 -2
  7. package/dist/assets/FilesView-BKL6YlKG.js +14 -0
  8. package/dist/assets/{GitView-OSVIn5V1.js → GitView-DBFrDDBv.js} +1 -1
  9. package/dist/assets/{JsonTreeView-Kgepz4pR.js → JsonTreeView-DLW2Wy1g.js} +1 -1
  10. package/dist/assets/MarkdownImageGallery-DKIylIK7.js +1 -0
  11. package/dist/assets/MarkdownRendererImpl-CLv8hxvv.js +12 -0
  12. package/dist/assets/OnboardingScreen-D2Y6djMw.js +1 -0
  13. package/dist/assets/{PatchDiff-Cddz02Ya.js → PatchDiff-BuLPx7AN.js} +1 -1
  14. package/dist/assets/{PierreDiffViewer-B5k0KvPW.js → PierreDiffViewer-BHm4Yr0X.js} +2 -2
  15. package/dist/assets/{PlanView-BYgHBHDt.js → PlanView-ZYEJn8A_.js} +3 -3
  16. package/dist/assets/{SessionSwitcherDropdown-ig2OT22Z.js → SessionSwitcherDropdown-rro-SsaO.js} +1 -1
  17. package/dist/assets/SettingsView-5RmswFZe.js +28 -0
  18. package/dist/assets/{SettingsWindow-CNHM8ifT.js → SettingsWindow-BZhAYFdS.js} +1 -1
  19. package/dist/assets/{ToolOutputDialog-DrGeYq2p.js → ToolOutputDialog-Za6V4VMJ.js} +7 -7
  20. package/dist/assets/{ToolPartDiffPreview-BRmPpe94.js → ToolPartDiffPreview-BL-9ixyC.js} +1 -1
  21. package/dist/assets/{VirtualizedFileDiff-Dcu8Q-5P.js → VirtualizedFileDiff-CwGocYQd.js} +1 -1
  22. package/dist/assets/{WalkthroughView-HStEYdD2.js → WalkthroughView-5DyvN03T.js} +2 -2
  23. package/dist/assets/{computeVirtualFileMetrics-DQE7R9IY.js → computeVirtualFileMetrics-Da00Jg7M.js} +2 -2
  24. package/dist/assets/contextPanelEmbeddedChat-B-bSg3P5.js +1 -0
  25. package/dist/assets/de-u7gSnqWs.js +9 -0
  26. package/dist/assets/es-T9O7aAOr.js +15 -0
  27. package/dist/assets/fr-Oor7ewbE.js +13 -0
  28. package/dist/assets/index-BzIpNlNE.css +1 -0
  29. package/dist/assets/{index-BgQEgA2a.js → index-C0yNhuZw.js} +1 -1
  30. package/dist/assets/index-DRpChWux.js +7 -0
  31. package/dist/assets/{isDiffPlainText-XyBCe4eD.js → isDiffPlainText-D9YpoLrV.js} +1 -1
  32. package/dist/assets/{isFilePlainText-JbqDfa3n.js → isFilePlainText-gTibdNIe.js} +1 -1
  33. package/dist/assets/ja-DHpqbVmr.js +15 -0
  34. package/dist/assets/ko-CwLkS3nx.js +15 -0
  35. package/dist/assets/{main-LfcbGv7C.js → main-D7UcL3VQ.js} +2 -2
  36. package/dist/assets/main-DPMd2iKS.js +915 -0
  37. package/dist/assets/markdownCore-DDrHVneM.js +2 -0
  38. package/dist/assets/{miniChat-CUp_elRz.js → miniChat-O_GVoEbc.js} +2 -2
  39. package/dist/assets/{mobile-CBSN7BsH.js → mobile-Br4TtAqc.js} +2 -2
  40. package/dist/assets/{patchFileDiff-DCIXUHRJ.js → patchFileDiff-KNkxM1C1.js} +2 -2
  41. package/dist/assets/{pl-tHTP6XQx.js → pl-CcZILN8q.js} +4 -4
  42. package/dist/assets/pt-BR-DYHhVK6o.js +15 -0
  43. package/dist/assets/{renderElectronMiniChatApp-eZl-5STF.js → renderElectronMiniChatApp-CJpdxTT1.js} +2 -2
  44. package/dist/assets/renderMobileApp-toj9cXoh.js +25 -0
  45. package/dist/assets/runtimeEndpointReset-BVmispdD.js +13 -0
  46. package/dist/assets/scheduledTasksApi-ByKya3Un.js +1 -0
  47. package/dist/assets/{shikiHighlight-eU8abJ3T.js → shikiHighlight-C7LTbwFx.js} +1 -1
  48. package/dist/assets/uk-BA2kZR38.js +15 -0
  49. package/dist/assets/{useAppFontEffects-Bbpz77To.js → useAppFontEffects-BikB6enL.js} +138 -138
  50. package/dist/assets/useInlineCommentController-CYPvYJDt.js +2 -0
  51. package/dist/assets/{vendor-codemirror-language-data-Dzt9rWZZ.js → vendor-codemirror-language-data-CLHw8NWn.js} +2 -2
  52. package/dist/assets/{vendor-marked-i_gIkIP3.js → vendor-marked-CX41MkDF.js} +1 -1
  53. package/dist/assets/{web-components-DGvnI0zx.js → web-components-GMc3oR3i.js} +1 -1
  54. package/dist/assets/zh-CN-dlOQK6v9.js +15 -0
  55. package/dist/assets/zh-TW-BnqQ-WL5.js +15 -0
  56. package/dist/index.html +4 -4
  57. package/dist/mini-chat.html +3 -3
  58. package/dist/mobile.html +3 -3
  59. package/package.json +2 -2
  60. package/server/index.js +65 -19
  61. package/server/lib/agent-tool/DOCUMENTATION.md +21 -6
  62. package/server/lib/agent-tool/runtime.js +90 -16
  63. package/server/lib/agent-tool/runtime.test.js +86 -0
  64. package/server/lib/browser-control/DOCUMENTATION.md +50 -0
  65. package/server/lib/browser-control/broker.js +154 -0
  66. package/server/lib/browser-control/broker.test.js +191 -0
  67. package/server/lib/browser-control/routes.js +48 -0
  68. package/server/lib/browser-control/routes.test.js +108 -0
  69. package/server/lib/dev-servers/parse.js +203 -0
  70. package/server/lib/dev-servers/parse.test.js +174 -0
  71. package/server/lib/dev-servers/routes.js +135 -0
  72. package/server/lib/dev-tunnel/DOCUMENTATION.md +57 -0
  73. package/server/lib/dev-tunnel/client.js +193 -0
  74. package/server/lib/dev-tunnel/runtime.js +189 -0
  75. package/server/lib/dev-tunnel/tunnel.test.js +291 -0
  76. package/server/lib/git/credentials.js +0 -33
  77. package/server/lib/github/DOCUMENTATION.md +1 -1
  78. package/server/lib/markdown-image-grants/DOCUMENTATION.md +36 -0
  79. package/server/lib/markdown-image-grants/routes.js +340 -0
  80. package/server/lib/markdown-image-grants/routes.test.js +221 -0
  81. package/server/lib/openchamber-control/DOCUMENTATION.md +9 -0
  82. package/server/lib/openchamber-control/actions.js +33 -1
  83. package/server/lib/openchamber-control/screenshots.js +83 -0
  84. package/server/lib/openchamber-control/screenshots.test.js +84 -0
  85. package/server/lib/openchamber-control/service.js +141 -2
  86. package/server/lib/openchamber-control/service.test.js +55 -0
  87. package/server/lib/opencode/core-routes.js +31 -52
  88. package/server/lib/opencode/core-routes.test.js +37 -9
  89. package/server/lib/opencode/feature-routes-runtime.js +15 -0
  90. package/server/lib/opencode/server-startup-runtime.js +22 -1
  91. package/server/lib/opencode/server-startup-runtime.test.js +44 -0
  92. package/server/lib/opencode/settings-helpers.js +3 -9
  93. package/server/lib/projects/project-config.js +181 -2
  94. package/server/lib/projects/project-config.test.js +295 -0
  95. package/server/lib/quota/DOCUMENTATION.md +4 -2
  96. package/server/lib/quota/credentials/providers.js +0 -7
  97. package/server/lib/quota/credentials/store.js +11 -1
  98. package/server/lib/quota/credentials/store.test.js +9 -1
  99. package/server/lib/quota/providers/opencode-go.js +35 -35
  100. package/server/lib/quota/providers/opencode-go.test.js +52 -7
  101. package/server/lib/quota/routes.js +0 -2
  102. package/server/lib/relay/DOCUMENTATION.md +2 -0
  103. package/server/lib/relay/tunnel-host.js +157 -33
  104. package/server/lib/relay/tunnel-host.test.js +147 -0
  105. package/server/lib/scheduled-tasks/DOCUMENTATION.md +49 -0
  106. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +488 -0
  107. package/server/lib/scheduled-tasks/routes.js +6 -0
  108. package/server/lib/scheduled-tasks/runtime.js +369 -108
  109. package/server/lib/scheduled-tasks/service.js +7 -1
  110. package/server/lib/scheduled-tasks/service.test.js +20 -0
  111. package/server/lib/walkthrough/index.js +0 -2
  112. package/server/sse-routes.test.js +3 -0
  113. package/dist/assets/FilesView-WkxsWHBE.js +0 -14
  114. package/dist/assets/MarkdownRendererImpl-CKAsRfIk.js +0 -12
  115. package/dist/assets/OnboardingScreen-BCgYA7J5.js +0 -1
  116. package/dist/assets/SettingsView-e7Fmxnz8.js +0 -28
  117. package/dist/assets/contextPanelEmbeddedChat-5VGWIT_J.js +0 -1
  118. package/dist/assets/de-B6t6T54h.js +0 -9
  119. package/dist/assets/es-DH9NUKge.js +0 -15
  120. package/dist/assets/fr-Do4t2KmA.js +0 -13
  121. package/dist/assets/index-B45s9aAX.css +0 -1
  122. package/dist/assets/index-CNrN5qDs.js +0 -7
  123. package/dist/assets/ja-DJT9EM80.js +0 -15
  124. package/dist/assets/ko-CfWRq2p4.js +0 -15
  125. package/dist/assets/main-B4oBRI9u.js +0 -193
  126. package/dist/assets/markdownCore-A3_L34oS.js +0 -2
  127. package/dist/assets/pt-BR-BDEzzltP.js +0 -15
  128. package/dist/assets/renderMobileApp-DA7wpIBi.js +0 -23
  129. package/dist/assets/runtimeEndpointReset-D5izT-u5.js +0 -13
  130. package/dist/assets/scheduledTasksApi-CTJdfSWc.js +0 -1
  131. package/dist/assets/uk-B6Q32nyk.js +0 -15
  132. package/dist/assets/useInlineCommentController-D7zs7-BQ.js +0 -2
  133. package/dist/assets/vendor-zumer-snapdom-Btyu_Xi2.js +0 -8
  134. package/dist/assets/zh-CN-7MGcwGaC.js +0 -15
  135. package/dist/assets/zh-TW-CFPfqxlL.js +0 -15
  136. package/server/lib/preview/proxy-runtime.js +0 -1604
  137. package/server/lib/preview/proxy-runtime.test.js +0 -528
  138. package/server/lib/quota/opencode-go-credentials.js +0 -11
  139. package/server/lib/quota/opencode-go-credentials.test.js +0 -32
  140. package/server/lib/quota/routes.test.js +0 -40
@@ -1,528 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
-
3
- import {
4
- applyPreviewPassthroughRequestHeaders,
5
- applyPreviewPassthroughResponseHeaders,
6
- classifyPreviewNavigation,
7
- classifyPreviewResourceError,
8
- createPreviewProxyRuntime,
9
- normalizeProxyTargetUrl,
10
- PREVIEW_TARGET_ERROR_HEADER,
11
- rewritePreviewBody,
12
- rewritePreviewCspHeader,
13
- rewritePreviewRedirectLocation,
14
- } from './proxy-runtime.js';
15
-
16
- const createResponse = () => {
17
- const headers = new Map();
18
- return {
19
- body: null,
20
- statusCode: 200,
21
- headers,
22
- setHeader(name, value) {
23
- headers.set(name.toLowerCase(), value);
24
- },
25
- removeHeader(name) {
26
- headers.delete(name.toLowerCase());
27
- },
28
- status(code) {
29
- this.statusCode = code;
30
- return this;
31
- },
32
- json(body) {
33
- this.body = body;
34
- return body;
35
- },
36
- };
37
- };
38
-
39
- const createAttachedPreviewRuntime = () => {
40
- let proxyOptions;
41
- const postRoutes = new Map();
42
- const useRoutes = new Map();
43
- let randomByte = 0;
44
- const runtime = createPreviewProxyRuntime({
45
- crypto: {
46
- randomBytes(size) {
47
- randomByte += 1;
48
- return Buffer.alloc(size, randomByte);
49
- },
50
- },
51
- URL,
52
- createProxyMiddleware(options) {
53
- proxyOptions = options;
54
- const middleware = () => {};
55
- middleware.upgrade = () => {};
56
- return middleware;
57
- },
58
- responseInterceptor: (handler) => handler,
59
- });
60
- const app = {
61
- post(path, ...handlers) {
62
- postRoutes.set(path, handlers);
63
- },
64
- use(path, ...handlers) {
65
- useRoutes.set(path, handlers);
66
- },
67
- };
68
- runtime.attach(app, {
69
- server: { on() {} },
70
- express: { json: () => (_req, _res, next) => next() },
71
- uiAuthController: null,
72
- isRequestOriginAllowed: async () => true,
73
- rejectWebSocketUpgrade() {},
74
- });
75
-
76
- return { postRoutes, proxyOptions: () => proxyOptions, useRoutes };
77
- };
78
-
79
- const rewrite = (bodyText, kind) => rewritePreviewBody({
80
- bodyText,
81
- kind,
82
- proxyBasePath: '/api/preview/proxy/abc123',
83
- targetOrigin: 'http://127.0.0.1:3000',
84
- });
85
-
86
- describe('preview target failure signaling', () => {
87
- it('marks missing and expired targets instead of relying on the HTTP status alone', () => {
88
- const { useRoutes } = createAttachedPreviewRuntime();
89
- const [guard] = useRoutes.get('/api/preview/proxy');
90
- for (const [originalUrl, code, error] of [
91
- ['/api/preview/proxy/', 'missing', 'Preview target not found'],
92
- [`/api/preview/proxy/${'a'.repeat(32)}/`, 'expired', 'Preview target expired'],
93
- ]) {
94
- const response = createResponse();
95
- guard({ originalUrl, headers: {} }, response, () => {});
96
- expect(response.statusCode).toBe(404);
97
- expect(response.headers.get(PREVIEW_TARGET_ERROR_HEADER)).toBe(code);
98
- expect(response.body).toEqual({ error });
99
- }
100
- });
101
-
102
- it('marks invalid target tokens and accepts a registered target token', async () => {
103
- const { postRoutes, useRoutes } = createAttachedPreviewRuntime();
104
- const [, registerTarget] = postRoutes.get('/api/preview/targets');
105
- const [guard] = useRoutes.get('/api/preview/proxy');
106
- const registrationResponse = createResponse();
107
- await registerTarget({ body: { url: 'http://127.0.0.1:4323/' }, secure: false }, registrationResponse);
108
-
109
- const { id, previewToken } = registrationResponse.body;
110
- const invalidResponse = createResponse();
111
- guard({ originalUrl: `/api/preview/proxy/${id}/`, headers: {} }, invalidResponse, () => {});
112
- expect(invalidResponse.statusCode).toBe(403);
113
- expect(invalidResponse.headers.get(PREVIEW_TARGET_ERROR_HEADER)).toBe('invalid-token');
114
-
115
- const validResponse = createResponse();
116
- let continued = false;
117
- guard({
118
- originalUrl: `/api/preview/proxy/${id}/?oc_preview_token=${previewToken}`,
119
- headers: {},
120
- }, validResponse, () => {
121
- continued = true;
122
- });
123
- expect(continued).toBe(true);
124
- expect(validResponse.headers.has(PREVIEW_TARGET_ERROR_HEADER)).toBe(false);
125
- });
126
-
127
- it('removes the reserved target-error marker from upstream responses', async () => {
128
- const { postRoutes, proxyOptions, useRoutes } = createAttachedPreviewRuntime();
129
- const [, registerTarget] = postRoutes.get('/api/preview/targets');
130
- const registrationResponse = createResponse();
131
- await registerTarget({ body: { url: 'http://127.0.0.1:4323/' }, secure: false }, registrationResponse);
132
- const { id, previewToken } = registrationResponse.body;
133
- const request = {
134
- originalUrl: `/api/preview/proxy/${id}/missing?oc_preview_token=${previewToken}`,
135
- headers: {},
136
- };
137
- const response = createResponse();
138
- response.setHeader(PREVIEW_TARGET_ERROR_HEADER, 'expired');
139
-
140
- await proxyOptions().on.proxyRes(
141
- Buffer.from('{"error":"upstream missing"}'),
142
- { headers: { 'content-type': 'application/json' } },
143
- request,
144
- response,
145
- );
146
-
147
- expect(response.headers.has(PREVIEW_TARGET_ERROR_HEADER)).toBe(false);
148
- const [guard] = useRoutes.get('/api/preview/proxy');
149
- let continued = false;
150
- guard(request, createResponse(), () => {
151
- continued = true;
152
- });
153
- expect(continued).toBe(true);
154
- });
155
- });
156
-
157
- describe('preview Inertia header passthrough', () => {
158
- it('forwards Inertia request headers to the preview target', () => {
159
- const forwarded = new Map();
160
- const proxyReq = {
161
- setHeader: (name, value) => forwarded.set(name, value),
162
- };
163
-
164
- applyPreviewPassthroughRequestHeaders({
165
- headers: {
166
- 'x-inertia': 'true',
167
- 'x-inertia-version': 'asset-hash',
168
- 'x-unrelated': 'ignored',
169
- },
170
- }, proxyReq);
171
-
172
- expect(forwarded.get('x-inertia')).toBe('true');
173
- expect(forwarded.get('x-inertia-version')).toBe('asset-hash');
174
- expect(forwarded.has('x-unrelated')).toBe(false);
175
- });
176
-
177
- it('forwards Inertia response headers back to the preview client', () => {
178
- const forwarded = new Map();
179
- const res = {
180
- headersSent: false,
181
- setHeader: (name, value) => forwarded.set(name, value),
182
- };
183
-
184
- applyPreviewPassthroughResponseHeaders({
185
- headers: {
186
- 'x-inertia': 'true',
187
- 'x-inertia-location': 'http://127.0.0.1:8000/login',
188
- 'x-unrelated': 'ignored',
189
- },
190
- }, res);
191
-
192
- expect(forwarded.get('x-inertia')).toBe('true');
193
- expect(forwarded.get('x-inertia-location')).toBe('http://127.0.0.1:8000/login');
194
- expect(forwarded.has('x-unrelated')).toBe(false);
195
- });
196
- });
197
-
198
- describe('preview resource error classification', () => {
199
- it('suppresses Astro/Vite stylesheet modules reported as failed scripts', () => {
200
- expect(classifyPreviewResourceError({
201
- tagName: 'script',
202
- url: 'http://127.0.0.1:57123/api/preview/proxy/f4af70b4261d77706743959516f9cecc/src/styles/global.css',
203
- })).toBe('suppress');
204
-
205
- expect(classifyPreviewResourceError({
206
- tagName: 'script',
207
- url: 'http://127.0.0.1:57123/api/preview/proxy/f4af70b4261d77706743959516f9cecc/src/pages/support.astro?astro&type=style&index=0&lang.css',
208
- })).toBe('suppress');
209
- });
210
-
211
- it('suppresses framework virtual modules reported by dev servers', () => {
212
- expect(classifyPreviewResourceError({
213
- tagName: 'script',
214
- url: 'http://127.0.0.1:57123/api/preview/proxy/f4af70b4261d77706743959516f9cecc/src/layouts/BaseLayout.astro?astro&type=script&index=0&lang.ts',
215
- })).toBe('suppress');
216
-
217
- expect(classifyPreviewResourceError({
218
- tagName: 'script',
219
- url: 'http://127.0.0.1:57123/api/preview/proxy/f4af70b4261d77706743959516f9cecc/@vite/client',
220
- })).toBe('suppress');
221
-
222
- expect(classifyPreviewResourceError({
223
- tagName: 'link',
224
- url: 'http://127.0.0.1:57123/api/preview/proxy/f4af70b4261d77706743959516f9cecc/@id/astro:scripts/page.js',
225
- })).toBe('suppress');
226
- });
227
-
228
- it('suppresses conservative ecosystem dev-runtime resources', () => {
229
- const noisyResources = [
230
- '/_next/static/chunks/webpack.js',
231
- '/_next/static/chunks/react-refresh.js',
232
- '/.svelte-kit/generated/client/app.js',
233
- '/@id/__x00__virtual:sveltekit:browser',
234
- '/@remix-run/dev/dist/browser.js',
235
- '/__hmr?runtime=remix',
236
- '/_nuxt/@vite/client',
237
- '/_nuxt/@id/virtual:nuxt:%2FUsers%2Fapp',
238
- '/webpack-dev-server/client/index.js',
239
- '/webpack/hot/dev-server.js',
240
- '/__webpack_hmr',
241
- ];
242
-
243
- for (const resource of noisyResources) {
244
- expect(classifyPreviewResourceError({
245
- tagName: 'script',
246
- url: `http://127.0.0.1:57123/api/preview/proxy/f4af70b4261d77706743959516f9cecc${resource}`,
247
- })).toBe('suppress');
248
- }
249
- });
250
-
251
- it('keeps ordinary application resource failures visible', () => {
252
- expect(classifyPreviewResourceError({
253
- tagName: 'script',
254
- url: 'http://127.0.0.1:57123/api/preview/proxy/f4af70b4261d77706743959516f9cecc/assets/app.js',
255
- })).toBe('report');
256
-
257
- expect(classifyPreviewResourceError({
258
- tagName: 'img',
259
- url: 'http://127.0.0.1:57123/api/preview/proxy/f4af70b4261d77706743959516f9cecc/missing.png',
260
- })).toBe('report');
261
-
262
- expect(classifyPreviewResourceError({
263
- tagName: 'link',
264
- url: 'http://127.0.0.1:57123/api/preview/proxy/f4af70b4261d77706743959516f9cecc/styles/missing.css',
265
- })).toBe('report');
266
- });
267
- });
268
-
269
- describe('preview body URL rewriting', () => {
270
- it('rewrites only HTML resource attributes in HTML responses', () => {
271
- const input = '<img src="/logo.png"><a href="/docs">Docs</a><script>const url = "/api/data";</script>';
272
- const output = rewrite(input, 'html');
273
-
274
- expect(output).toContain('src="/api/preview/proxy/abc123/logo.png"');
275
- expect(output).toContain('href="/api/preview/proxy/abc123/docs"');
276
- expect(output).toContain('const url = "/api/data";');
277
- });
278
-
279
- it('rewrites inline module imports in HTML responses', () => {
280
- const input = [
281
- '<script type="module">',
282
- 'import RefreshRuntime from "/@react-refresh";',
283
- 'window.__vite_plugin_react_preamble_installed__ = true;',
284
- '</script>',
285
- '<script type=module>',
286
- 'import { injectIntoGlobalHook } from "/@react-refresh";',
287
- 'import value from "/module.js";',
288
- 'const url = "/api/data";',
289
- '</script>',
290
- '<script type=\'module\'>',
291
- 'import "/entry.js";',
292
- '</script>',
293
- '<script type="text/javascript">',
294
- 'import "/not-rewritten.js";',
295
- '</script>',
296
- '<script>const refreshUrl = "/@react-refresh";</script>',
297
- ].join('');
298
- const output = rewrite(input, 'html');
299
-
300
- expect(output).toContain('from "/api/preview/proxy/abc123/@react-refresh"');
301
- expect(output).toContain('import { injectIntoGlobalHook } from "/api/preview/proxy/abc123/@react-refresh";');
302
- expect(output).toContain('import value from "/api/preview/proxy/abc123/module.js";');
303
- expect(output).toContain('const url = "/api/data";');
304
- expect(output).toContain('import "/api/preview/proxy/abc123/entry.js";');
305
- expect(output).toContain('import "/not-rewritten.js";');
306
- expect(output).toContain('window.__vite_plugin_react_preamble_installed__ = true;');
307
- expect(output).toContain('const refreshUrl = "/@react-refresh";');
308
- });
309
-
310
- it('removes CSP meta tags that block the preview bridge', () => {
311
- const input = '<meta http-equiv="Content-Security-Policy" content="script-src \'self\'"><div>Preview</div>';
312
- const output = rewrite(input, 'html');
313
-
314
- expect(output).not.toContain('Content-Security-Policy');
315
- expect(output).toContain('<div>Preview</div>');
316
- });
317
-
318
- it('adds preview and URL auth tokens to rewritten proxy resources when provided', () => {
319
- const output = rewritePreviewBody({
320
- bodyText: '<script src="/entry.js"></script><script type="module">import RefreshRuntime from "/@react-refresh";</script><a href="http://localhost:3000/docs?x=1&oc_client_token=legacy">Docs</a>',
321
- kind: 'html',
322
- proxyBasePath: '/api/preview/proxy/abc123',
323
- targetOrigin: 'http://127.0.0.1:3000',
324
- previewToken: 'preview-secret',
325
- urlAuthToken: 'url-secret',
326
- });
327
-
328
- expect(output).toContain('src="/api/preview/proxy/abc123/entry.js?oc_preview_token=preview-secret&oc_url_token=url-secret"');
329
- expect(output).toContain('from "/api/preview/proxy/abc123/@react-refresh?oc_preview_token=preview-secret&oc_url_token=url-secret"');
330
- expect(output).toContain('href="/api/preview/proxy/abc123/docs?x=1&oc_preview_token=preview-secret&oc_url_token=url-secret"');
331
- expect(output).not.toContain('oc_client_token');
332
- });
333
-
334
- it('rewrites only CSS imports and url references in CSS responses', () => {
335
- const input = '@import "/theme.css"; .hero { background: url(/hero.png); } .copy::after { content: "/not-a-url"; }';
336
- const output = rewrite(input, 'css');
337
-
338
- expect(output).toContain('@import "/api/preview/proxy/abc123/theme.css"');
339
- expect(output).toContain('url(/api/preview/proxy/abc123/hero.png)');
340
- expect(output).toContain('content: "/not-a-url"');
341
- });
342
-
343
- it('rewrites only JavaScript static import specifiers in JavaScript responses', () => {
344
- const input = 'import "/entry.js"; import value from "/module.js"; const url = "/api/data"; fetch("/api/data");';
345
- const output = rewrite(input, 'javascript');
346
-
347
- expect(output).toContain('import "/api/preview/proxy/abc123/entry.js"');
348
- expect(output).toContain('from "/api/preview/proxy/abc123/module.js"');
349
- expect(output).toContain('const url = "/api/data"');
350
- expect(output).toContain('fetch("/api/data")');
351
- });
352
-
353
- it('adds URL auth tokens to CSS and JavaScript rewritten resources', () => {
354
- const cssOutput = rewritePreviewBody({
355
- bodyText: '@import "/theme.css"; .hero { background: url(/hero.png); }',
356
- kind: 'css',
357
- proxyBasePath: '/api/preview/proxy/abc123',
358
- targetOrigin: 'http://127.0.0.1:3000',
359
- previewToken: 'preview-secret',
360
- urlAuthToken: 'url-secret',
361
- });
362
- const jsOutput = rewritePreviewBody({
363
- bodyText: 'import("/entry.js"); import value from "/module.js";',
364
- kind: 'javascript',
365
- proxyBasePath: '/api/preview/proxy/abc123',
366
- targetOrigin: 'http://127.0.0.1:3000',
367
- previewToken: 'preview-secret',
368
- urlAuthToken: 'url-secret',
369
- });
370
-
371
- expect(cssOutput).toContain('@import "/api/preview/proxy/abc123/theme.css?oc_preview_token=preview-secret&oc_url_token=url-secret"');
372
- expect(cssOutput).toContain('url(/api/preview/proxy/abc123/hero.png?oc_preview_token=preview-secret&oc_url_token=url-secret)');
373
- expect(jsOutput).toContain('import("/api/preview/proxy/abc123/entry.js?oc_preview_token=preview-secret&oc_url_token=url-secret")');
374
- expect(jsOutput).toContain('from "/api/preview/proxy/abc123/module.js?oc_preview_token=preview-secret&oc_url_token=url-secret"');
375
- });
376
- });
377
-
378
- describe('preview redirect URL rewriting', () => {
379
- it('rewrites loopback redirects through the preview proxy', () => {
380
- expect(rewritePreviewRedirectLocation({
381
- location: 'http://localhost:3000/login?next=%2F#top',
382
- proxyBasePath: '/api/preview/proxy/abc123',
383
- targetOrigin: 'http://127.0.0.1:3000',
384
- })).toBe('/api/preview/proxy/abc123/login?next=%2F#top');
385
- });
386
-
387
- it('leaves external redirects unchanged', () => {
388
- expect(rewritePreviewRedirectLocation({
389
- location: 'https://example.com/login',
390
- proxyBasePath: '/api/preview/proxy/abc123',
391
- targetOrigin: 'http://127.0.0.1:3000',
392
- })).toBe('https://example.com/login');
393
- });
394
-
395
- it('adds proxy auth tokens to loopback redirects when provided', () => {
396
- expect(rewritePreviewRedirectLocation({
397
- location: 'http://localhost:3000/login?next=%2F#top',
398
- proxyBasePath: '/api/preview/proxy/abc123',
399
- targetOrigin: 'http://127.0.0.1:3000',
400
- previewToken: 'preview-secret',
401
- urlAuthToken: 'url-secret',
402
- })).toBe('/api/preview/proxy/abc123/login?next=%2F&oc_preview_token=preview-secret&oc_url_token=url-secret#top');
403
- });
404
-
405
- it('leaves redirects unchanged when no target origin is provided', () => {
406
- expect(rewritePreviewRedirectLocation({
407
- location: 'http://localhost:5174/callback',
408
- proxyBasePath: '/api/preview/proxy/abc123',
409
- previewToken: 'preview-secret',
410
- })).toBe('http://localhost:5174/callback');
411
- });
412
- });
413
-
414
- describe('preview navigation policy', () => {
415
- const currentUrl = 'http://127.0.0.1:57123/api/preview/proxy/f4af70b4261d77706743959516f9cecc/docs';
416
-
417
- it('keeps same-page hash and already-proxied links in the iframe', () => {
418
- expect(classifyPreviewNavigation({ url: '#section', currentUrl }).action).toBe('allow');
419
- expect(classifyPreviewNavigation({
420
- url: 'http://127.0.0.1:57123/api/preview/proxy/f4af70b4261d77706743959516f9cecc/roadmap',
421
- currentUrl,
422
- }).action).toBe('allow');
423
- });
424
-
425
- it('routes loopback absolute links through the preview proxy', () => {
426
- expect(classifyPreviewNavigation({ url: 'http://localhost:3000/roadmap', currentUrl })).toEqual({
427
- action: 'proxy',
428
- url: 'http://localhost:3000/roadmap',
429
- });
430
- });
431
-
432
- it('maps app-origin root links back to the upstream origin while proxied', () => {
433
- expect(classifyPreviewNavigation({
434
- url: 'http://127.0.0.1:57123/support',
435
- currentUrl,
436
- targetOrigin: 'https://openchamber.dev',
437
- })).toEqual({
438
- action: 'proxy',
439
- url: 'https://openchamber.dev/support',
440
- });
441
- });
442
-
443
- it('sends non-loopback http links outside the preview iframe', () => {
444
- expect(classifyPreviewNavigation({ url: 'https://example.com/docs', currentUrl })).toEqual({
445
- action: 'external',
446
- url: 'https://example.com/docs',
447
- });
448
- });
449
-
450
- it('leaves non-http links to browser defaults', () => {
451
- expect(classifyPreviewNavigation({ url: 'mailto:test@example.com', currentUrl })).toEqual({
452
- action: 'allow',
453
- url: 'mailto:test@example.com',
454
- });
455
- });
456
- });
457
-
458
- describe('proxy target normalization (SSRF guard)', () => {
459
- it('allows ordinary external hosts when allowExternal is set', () => {
460
- expect(normalizeProxyTargetUrl('https://docs.openchamber.dev/security/', { allowExternal: true }))
461
- .toEqual({ ok: true, origin: 'https://docs.openchamber.dev' });
462
- });
463
-
464
- it('rejects non-loopback hosts without allowExternal', () => {
465
- expect(normalizeProxyTargetUrl('https://example.com/', {}).ok).toBe(false);
466
- });
467
-
468
- it('refuses private, loopback and link-local literals on the external path', () => {
469
- for (const url of [
470
- 'http://127.0.0.1/',
471
- 'http://10.0.0.5/',
472
- 'http://172.16.9.9/',
473
- 'http://192.168.1.1/',
474
- 'http://169.254.169.254/latest/meta-data/',
475
- 'http://100.64.0.1/',
476
- 'http://localhost/',
477
- 'http://service.local/',
478
- 'http://[::1]/',
479
- 'http://[fd00::1]/',
480
- 'http://[fe80::1]/',
481
- 'http://2130706433/', // decimal form of 127.0.0.1, normalized by WHATWG URL
482
- ]) {
483
- expect(normalizeProxyTargetUrl(url, { allowExternal: true }).ok, url).toBe(false);
484
- }
485
- });
486
-
487
- it('still blocks private hosts even via IPv4-mapped IPv6', () => {
488
- expect(normalizeProxyTargetUrl('http://[::ffff:127.0.0.1]/', { allowExternal: true }).ok).toBe(false);
489
- });
490
- });
491
-
492
- describe('preview CSP rewrite', () => {
493
- it('drops frame-ancestors and require-trusted-types-for but keeps the rest', () => {
494
- const result = rewritePreviewCspHeader(
495
- "default-src 'self'; frame-ancestors 'none'; require-trusted-types-for 'script'",
496
- 'abc123',
497
- );
498
- expect(result).not.toContain('frame-ancestors');
499
- expect(result).not.toContain('require-trusted-types-for');
500
- expect(result).toContain("default-src 'self'");
501
- });
502
-
503
- it('adds the nonce to an existing script-src instead of removing it', () => {
504
- const result = rewritePreviewCspHeader("script-src 'self'", 'abc123');
505
- expect(result).toContain("script-src 'self' 'nonce-abc123'");
506
- });
507
-
508
- it('adds the nonce to script-src-elem when present', () => {
509
- const result = rewritePreviewCspHeader("script-src-elem 'self'", 'abc123');
510
- expect(result).toContain("script-src-elem 'self' 'nonce-abc123'");
511
- });
512
-
513
- it('synthesizes script-src from default-src when no script directive exists', () => {
514
- const result = rewritePreviewCspHeader("default-src 'self' https://cdn.example.com", 'abc123');
515
- expect(result).toContain("default-src 'self' https://cdn.example.com");
516
- expect(result).toContain("script-src 'self' https://cdn.example.com 'nonce-abc123'");
517
- });
518
-
519
- it("drops a lone 'none' so the nonce takes effect", () => {
520
- const result = rewritePreviewCspHeader("script-src 'none'", 'abc123');
521
- expect(result).toBe("script-src 'nonce-abc123'");
522
- });
523
-
524
- it('returns empty/unset CSP values unchanged', () => {
525
- expect(rewritePreviewCspHeader('', 'abc123')).toBe('');
526
- expect(rewritePreviewCspHeader(undefined, 'abc123')).toBe(undefined);
527
- });
528
- });
@@ -1,11 +0,0 @@
1
- import { deleteManagedCredential, getManagedCredentialStatus, normalizers, readManagedCredential, writeManagedCredential } from './credentials/providers.js';
2
-
3
- export const normalizeOpenCodeGoCredential = normalizers['opencode-go'];
4
-
5
- export const readOpenCodeGoCredential = () => readManagedCredential('opencode-go');
6
-
7
- export const getOpenCodeGoCredentialStatus = () => getManagedCredentialStatus('opencode-go');
8
-
9
- export const writeOpenCodeGoCredential = (value) => writeManagedCredential('opencode-go', value);
10
-
11
- export const deleteOpenCodeGoCredential = () => deleteManagedCredential('opencode-go');
@@ -1,32 +0,0 @@
1
- import { afterAll, afterEach, describe, expect, it } from 'bun:test';
2
- import fs from 'node:fs';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import { deleteOpenCodeGoCredential, getOpenCodeGoCredentialStatus, readOpenCodeGoCredential, writeOpenCodeGoCredential } from './opencode-go-credentials.js';
6
-
7
- const previousDataDir = process.env.OPENCHAMBER_DATA_DIR;
8
- const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-go-'));
9
- process.env.OPENCHAMBER_DATA_DIR = temporaryDirectory;
10
-
11
- afterEach(() => deleteOpenCodeGoCredential());
12
-
13
- describe('OpenCode Go credential store', () => {
14
- it('normalizes, masks, and stores credentials with owner-only permissions', () => {
15
- const status = writeOpenCodeGoCredential({ workspaceId: ' wrk_test ', authCookie: ' auth=secret ' });
16
- expect(status).toEqual({ configured: true, workspaceId: 'wrk_test', secretMasked: '••••••••' });
17
- expect(readOpenCodeGoCredential()).toEqual({ workspaceId: 'wrk_test', authCookie: 'secret' });
18
- expect(fs.statSync(path.join(temporaryDirectory, 'quota', 'opencode-go.json')).mode & 0o777).toBe(0o600);
19
- });
20
-
21
- it('removes credentials without exposing prior values', () => {
22
- writeOpenCodeGoCredential({ workspaceId: 'wrk_test', authCookie: 'secret' });
23
- deleteOpenCodeGoCredential();
24
- expect(getOpenCodeGoCredentialStatus()).toEqual({ configured: false });
25
- });
26
- });
27
-
28
- afterAll(() => {
29
- if (previousDataDir === undefined) delete process.env.OPENCHAMBER_DATA_DIR;
30
- else process.env.OPENCHAMBER_DATA_DIR = previousDataDir;
31
- fs.rmSync(temporaryDirectory, { recursive: true, force: true });
32
- });
@@ -1,40 +0,0 @@
1
- import { afterAll, describe, expect, it, mock } from 'bun:test';
2
- import express from 'express';
3
- import fs from 'node:fs';
4
- import os from 'node:os';
5
- import path from 'node:path';
6
- import { registerQuotaRoutes } from './routes.js';
7
-
8
- const previousDataDir = process.env.OPENCHAMBER_DATA_DIR;
9
- const temporaryDirectory = fs.mkdtempSync(path.join(os.tmpdir(), 'openchamber-go-routes-'));
10
- process.env.OPENCHAMBER_DATA_DIR = temporaryDirectory;
11
-
12
- afterAll(() => {
13
- if (previousDataDir === undefined) delete process.env.OPENCHAMBER_DATA_DIR;
14
- else process.env.OPENCHAMBER_DATA_DIR = previousDataDir;
15
- fs.rmSync(temporaryDirectory, { recursive: true, force: true });
16
- });
17
-
18
- describe('OpenCode Go credential routes', () => {
19
- it('parses a JSON credential payload before validation', async () => {
20
- const originalFetch = globalThis.fetch;
21
- globalThis.fetch = mock(async () => new Response('rollingUsage:$R[1]={usagePercent:25,resetInSec:60}'));
22
- const app = express();
23
- registerQuotaRoutes(app, { getQuotaProviders: async () => ({}) });
24
- const server = app.listen(0);
25
- try {
26
- const address = server.address();
27
- if (!address || typeof address === 'string') throw new Error('Test server did not start');
28
- const response = await originalFetch(`http://127.0.0.1:${address.port}/api/quota/credentials/opencode-go`, {
29
- method: 'PUT',
30
- headers: { 'Content-Type': 'application/json' },
31
- body: JSON.stringify({ workspaceId: 'wrk_test', authCookie: 'auth=secret' }),
32
- });
33
- expect(response.status).toBe(200);
34
- expect(await response.json()).toEqual({ configured: true, workspaceId: 'wrk_test', secretMasked: '••••••••' });
35
- } finally {
36
- globalThis.fetch = originalFetch;
37
- server.close();
38
- }
39
- });
40
- });