@openchamber/web 2.3.2 → 2.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{AboutDialog-MZbHWRua.js → AboutDialog-Ctk2zvrv.js} +1 -1
- package/dist/assets/{ArchiveView-CkeSWPcI.js → ArchiveView-sbNreasJ.js} +1 -1
- package/dist/assets/{CommandPalette-CtKzNzwW.js → CommandPalette-BICwnwAZ.js} +2 -2
- package/dist/assets/{DiffView-DaXjHTAq.js → DiffView-B5yeuxv8.js} +1 -1
- package/dist/assets/{FilesView-DMNYEydF.js → FilesView-ni2zfAwL.js} +7 -7
- package/dist/assets/{GitView-HXttTpUw.js → GitView-C0QgeC9O.js} +3 -3
- package/dist/assets/{GuestSurfacePane-KzguENQG.js → GuestSurfacePane-D1gLktSj.js} +1 -1
- package/dist/assets/{HelpDialog-9YZGhBgT.js → HelpDialog-CxC6qTaS.js} +1 -1
- package/dist/assets/{InProgressOperationBanner-DzGIwGH2.js → InProgressOperationBanner-JFV70YFh.js} +1 -1
- package/dist/assets/{JsonTreeView-D9rP8jM8.js → JsonTreeView-RsbV4Usa.js} +1 -1
- package/dist/assets/MarkdownRendererImpl-CZK5DoOX.js +1 -0
- package/dist/assets/{MemoryDebugPanel-Ct0h3RWh.js → MemoryDebugPanel-caUWOKiz.js} +1 -1
- package/dist/assets/{OnboardingScreen-B5Zzb1Mp.js → OnboardingScreen-BDT-J2JP.js} +1 -1
- package/dist/assets/{OpenCodeStatusDialog-CXBWWRh8.js → OpenCodeStatusDialog-Cxa2yqOB.js} +1 -1
- package/dist/assets/{PatchDiff-DhDAQ5em.js → PatchDiff-C1pnbAsJ.js} +1 -1
- package/dist/assets/{PierreDiffViewer-DPa08AmN.js → PierreDiffViewer-D0zX2Msu.js} +1 -1
- package/dist/assets/PlanView-BxRCMuGe.js +5 -0
- package/dist/assets/{ProjectActionsDialog-DATu0aBc.js → ProjectActionsDialog-D660By4K.js} +1 -1
- package/dist/assets/{RunOverview-D6xy_vME.js → RunOverview-C1uTMnQS.js} +2 -2
- package/dist/assets/{ScheduledTasksDialog-BWXVnfrf.js → ScheduledTasksDialog-S-gAgo7Z.js} +5 -5
- package/dist/assets/SettingsView-CVpfbdob.js +30 -0
- package/dist/assets/{SettingsWindow-Cx6TrtY0.js → SettingsWindow-Dd1hHvgh.js} +1 -1
- package/dist/assets/SourceBoardView-DbGWAxtS.js +1 -0
- package/dist/assets/SpaceAccessDialog-muTSsEJ9.js +1 -0
- package/dist/assets/{SpaceApplyDialog-BtuwtlaG.js → SpaceApplyDialog-Dsf6MNGm.js} +1 -1
- package/dist/assets/{SpaceRow-MXqvd-dr.js → SpaceRow-7Z6ebRtm.js} +1 -1
- package/dist/assets/{SpaceSetupOutput-Uo5LS7Jy.js → SpaceSetupOutput-BytPfCOC.js} +1 -1
- package/dist/assets/{SpacesView-DvoOh4sM.js → SpacesView-CYCrlp0D.js} +1 -1
- package/dist/assets/{SubmoduleDiffSummary-CyMwDeoP.js → SubmoduleDiffSummary-VrNUbIqF.js} +1 -1
- package/dist/assets/{ToolOutputDialog-BaUZIVzc.js → ToolOutputDialog-DHORjBND.js} +7 -7
- package/dist/assets/{ToolPartDiffPreview-DmMwdcF4.js → ToolPartDiffPreview-BLAXe7C5.js} +1 -1
- package/dist/assets/{UsageStatsView-D7WrDBTC.js → UsageStatsView-BxtYEAa0.js} +1 -1
- package/dist/assets/{Virtualizer-CnU8pYMb.js → Virtualizer-Bl4Cf-H-.js} +1 -1
- package/dist/assets/{WalkthroughView-r0Ho9F4Z.js → WalkthroughView-B2BJJ4u5.js} +2 -2
- package/dist/assets/{WorktreesView-C-t7uxq1.js → WorktreesView-Dv0AO9dF.js} +1 -1
- package/dist/assets/{appThemeRegistry-BUY7Ge9i.js → appThemeRegistry-xm_W0svA.js} +1 -1
- package/dist/assets/{ar-HauNhDvN.js → ar-Cj8UF12m.js} +4 -4
- package/dist/assets/{computeVirtualFileMetrics-CUof18z3.js → computeVirtualFileMetrics-Cx05cmWI.js} +2 -2
- package/dist/assets/{de-fEoJ_Yyp.js → de-fSQ1ho01.js} +4 -4
- package/dist/assets/{decorate-BkTSGAlD.js → decorate-jpF7GA6t.js} +2 -2
- package/dist/assets/{es-CKNTBsZW.js → es-DrdzhSlK.js} +5 -5
- package/dist/assets/{fileContentPoller-BJWgy1fX.js → fileContentPoller-C0f20jNG.js} +3 -3
- package/dist/assets/{flexokiTheme-BArobfXV.js → flexokiTheme-DKNCYSqL.js} +1 -1
- package/dist/assets/{fr-C23655Pi.js → fr-Cmz6Da4q.js} +4 -4
- package/dist/assets/{he-CphXS_Fv.js → he-COJRUNy4.js} +4 -4
- package/dist/assets/{index-B27cSA9V.js → index-C8Mw8uvl.js} +1 -1
- package/dist/assets/{initializeSharedPreferences-CucsmDMw.js → initializeSharedPreferences-U9-v9mfq.js} +1 -1
- package/dist/assets/{isDiffPlainText-DSCjvV0m.js → isDiffPlainText-DW43IghW.js} +1 -1
- package/dist/assets/{isFilePlainText-C7g4UPox.js → isFilePlainText-Duq5CiuG.js} +1 -1
- package/dist/assets/{ja-BmsU2iQe.js → ja-Ce0NvDHZ.js} +4 -4
- package/dist/assets/katex-BZNCT55U.css +1 -0
- package/dist/assets/katex.min-EZjpSwGK.js +65 -0
- package/dist/assets/{ko-CxISpkje.js → ko-BGFcCLLq.js} +4 -4
- package/dist/assets/main-BUetg9hg.js +1048 -0
- package/dist/assets/{main-CGPiw9fS.js → main-Be_jmIlF.js} +2 -2
- package/dist/assets/markdownCore-BkTeS4gA.js +10 -0
- package/dist/assets/{miniChat-DVEKVYKe.js → miniChat-g1RgiLLS.js} +2 -2
- package/dist/assets/{mobile-Q_FVBe4I.js → mobile-DBli3U-T.js} +2 -2
- package/dist/assets/{moveWorkspacePath-CyZJ-2aD.js → moveWorkspacePath-CnYc96Xo.js} +1 -1
- package/dist/assets/{nl-jnTBQ_gU.js → nl-Cu1nxo5t.js} +4 -4
- package/dist/assets/{parseDiffFromFile-OHXXXyzL.js → parseDiffFromFile-DEjkjYod.js} +3 -3
- package/dist/assets/{patchFileDiff-BZrb6h2u.js → patchFileDiff-D__42sau.js} +5 -5
- package/dist/assets/{pierreDiffTint-DHf2xvyt.js → pierreDiffTint-3oatL635.js} +4 -4
- package/dist/assets/pl-4LdEMgWI.js +20 -0
- package/dist/assets/{pt-BR-BfpsFrHv.js → pt-BR-2UbEBNgC.js} +5 -5
- package/dist/assets/{relocateRestoredSession-DInneXVI.js → relocateRestoredSession-pkxyd_lV.js} +1 -1
- package/dist/assets/renderElectronMiniChatApp-D0tKJFBB.js +2 -0
- package/dist/assets/renderMobileApp-D6bOYHuP.js +25 -0
- package/dist/assets/{restartOpenCode-DwBaMPJK.js → restartOpenCode-FYqjpaWc.js} +1 -1
- package/dist/assets/runtimeEndpointReset-6CNNzem4.js +74 -0
- package/dist/assets/{scheduledTasksApi-ClJplEhR.js → scheduledTasksApi-BbnQ4W-W.js} +1 -1
- package/dist/assets/{selectionMarkdown-BuveYuup.js → selectionMarkdown-D8QAxC44.js} +1 -1
- package/dist/assets/sessionOwnership-BBuf0UCB.js +1 -0
- package/dist/assets/{shikiHighlight-DJAESrna.js → shikiHighlight-CweIj1cL.js} +1 -1
- package/dist/assets/{space-apply-DWFLwXbI.js → space-apply-CEi013sa.js} +1 -1
- package/dist/assets/{space-close-BYDbwdWc.js → space-close-BuStkLrZ.js} +1 -1
- package/dist/assets/{spaceNetwork-DHrhfbKM.js → spaceNetwork-tH2d5Mgs.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-DcAZmUlv.js → textMateThemeFromAppTheme-DLJBL6al.js} +1 -1
- package/dist/assets/tr-Bg0Qt-mG.js +11 -0
- package/dist/assets/{uk-C82aEtvs.js → uk-vcnOugr0.js} +5 -5
- package/dist/assets/useAppFontEffects-Cs6k0JKv.js +773 -0
- package/dist/assets/{useCallableModelProviders-BU_455MN.js → useCallableModelProviders-BsGEzsl2.js} +1 -1
- package/dist/assets/{useInlineCommentController-AuUrVz9U.js → useInlineCommentController-CVYaPzfO.js} +2 -2
- package/dist/assets/{useRootScrollLock-Cpk7NmBa.js → useRootScrollLock-Dov-44ov.js} +2 -2
- package/dist/assets/{vendor-codemirror-language-data-BYGweLoh.js → vendor-codemirror-language-data-DBekkZIx.js} +2 -2
- package/dist/assets/vendor-tanstack-react-virtual-Dozz-7fb.js +1 -0
- package/dist/assets/vendor-tanstack-virtual-core-DKBj55Em.js +1 -0
- package/dist/assets/{vendor-yaml-3778uTud.js → vendor-yaml-CE-D_49-.js} +1 -1
- package/dist/assets/{zh-CN-DEq7j9I5.js → zh-CN-C3UhwFsk.js} +5 -5
- package/dist/assets/{zh-TW-DgCN99T-.js → zh-TW-D0CmmMvp.js} +5 -5
- package/dist/index.html +3 -3
- package/dist/mini-chat.html +3 -3
- package/dist/mobile.html +3 -3
- package/package.json +5 -5
- package/server/index.js +13 -1
- package/server/lib/agent-memory/actions.js +22 -9
- package/server/lib/agent-memory/actions.test.js +57 -0
- package/server/lib/agent-memory/runtime.js +8 -5
- package/server/lib/agent-tool/DOCUMENTATION.md +17 -1
- package/server/lib/agent-tool/runtime.js +41 -7
- package/server/lib/agent-tool/runtime.test.js +11 -0
- package/server/lib/git/DOCUMENTATION.md +17 -5
- package/server/lib/git/lfs-discovery.js +7 -4
- package/server/lib/git/lfs-discovery.test.js +60 -0
- package/server/lib/git/network-operations.js +9 -3
- package/server/lib/git/network-operations.test.js +31 -2
- package/server/lib/git/service.js +72 -12
- package/server/lib/git/service.test.js +65 -0
- package/server/lib/github/DOCUMENTATION.md +1 -0
- package/server/lib/github/reference-search.js +49 -18
- package/server/lib/github/reference-search.test.js +28 -6
- package/server/lib/github/routes.js +87 -1
- package/server/lib/github/routes.mutations.test.js +38 -0
- package/server/lib/github/routes.test.js +1 -0
- package/server/lib/gitlab/DOCUMENTATION.md +4 -0
- package/server/lib/gitlab/client.js +23 -0
- package/server/lib/gitlab/client.test.js +28 -1
- package/server/lib/gitlab/mappers.js +9 -0
- package/server/lib/gitlab/resources.js +153 -4
- package/server/lib/gitlab/resources.test.js +107 -0
- package/server/lib/gitlab/routes.js +120 -1
- package/server/lib/gitlab/routes.test.js +59 -0
- package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
- package/server/lib/markdown-image-grants/routes.js +14 -2
- package/server/lib/markdown-image-grants/routes.test.js +23 -0
- package/server/lib/notifications/APNS.md +24 -23
- package/server/lib/notifications/DOCUMENTATION.md +2 -2
- package/server/lib/notifications/apns-runtime.js +8 -5
- package/server/lib/notifications/apns-runtime.test.js +26 -0
- package/server/lib/notifications/message.js +5 -3
- package/server/lib/notifications/message.test.js +9 -0
- package/server/lib/notifications/runtime.js +44 -9
- package/server/lib/notifications/trigger-runtime.test.js +84 -0
- package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
- package/server/lib/openchamber-control/actions.js +18 -2
- package/server/lib/openchamber-control/project-knowledge.js +17 -3
- package/server/lib/openchamber-control/project-knowledge.test.js +14 -0
- package/server/lib/openchamber-control/render-page.js +58 -0
- package/server/lib/openchamber-control/service.js +9 -0
- package/server/lib/openchamber-control/service.test.js +43 -0
- package/server/lib/openchamber-sessions/routes.js +1 -0
- package/server/lib/openchamber-sessions/worktree-move.js +26 -10
- package/server/lib/openchamber-sessions/worktree-move.test.js +36 -0
- package/server/lib/opencode/DOCUMENTATION.md +1 -1
- package/server/lib/opencode/managed-config-file.js +3 -2
- package/server/lib/opencode/managed-config-file.test.js +20 -6
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-helpers.test.js +1 -1
- package/server/lib/opencode/settings-registry.json +3 -0
- package/server/lib/opencode/settings-runtime.js +1 -0
- package/server/lib/project-context/DOCUMENTATION.md +25 -1
- package/server/lib/project-context/plan-progress.js +69 -0
- package/server/lib/project-context/plan-progress.test.js +58 -0
- package/server/lib/project-context/routes.http.test.js +22 -0
- package/server/lib/project-context/routes.js +20 -0
- package/server/lib/project-context/runtime.js +132 -18
- package/server/lib/project-context/runtime.test.js +58 -0
- package/server/lib/provider-read-cache/index.js +7 -1
- package/server/lib/provider-read-cache/index.test.js +12 -0
- package/server/lib/relay/DOCUMENTATION.md +17 -1
- package/server/lib/session-knowledge/DOCUMENTATION.md +17 -0
- package/server/lib/session-knowledge/runtime.js +29 -6
- package/server/lib/session-knowledge/runtime.test.js +26 -1
- package/server/lib/source-control/audit-storage.js +1 -0
- package/server/lib/source-control/mutation-storage.js +3 -0
- package/server/lib/spaces/DOCUMENTATION.md +14 -9
- package/server/lib/spaces/code-out.js +13 -4
- package/server/lib/spaces/code-out.test.js +5 -3
- package/server/lib/spaces/dispatcher.js +12 -5
- package/server/lib/spaces/dispatcher.test.js +19 -1
- package/server/lib/spaces/gatekeeper-channel.js +8 -7
- package/server/lib/spaces/gatekeeper-channel.test.js +10 -0
- package/server/lib/spaces/gatekeeper-program.cjs +38 -3
- package/server/lib/spaces/gatekeeper-program.test.js +20 -0
- package/server/lib/spaces/hardening.js +14 -1
- package/server/lib/spaces/hardening.test.js +5 -0
- package/server/lib/spaces/host-providers.js +165 -0
- package/server/lib/spaces/host-providers.test.js +100 -0
- package/server/lib/spaces/host.js +16 -4
- package/server/lib/spaces/journey.js +87 -17
- package/server/lib/spaces/journey.test.js +90 -2
- package/server/lib/spaces/layout.js +15 -5
- package/server/lib/spaces/places/docker-live-support.js +2 -0
- package/server/lib/spaces/places/docker.test.js +2 -0
- package/server/lib/spaces/places/fake-docker.js +3 -0
- package/server/lib/spaces/places/grants.docker.live.test.js +71 -7
- package/server/lib/spaces/routes.js +9 -0
- package/server/lib/spaces/routes.test.js +4 -2
- package/server/lib/spaces/space-opencode.js +31 -14
- package/server/lib/spaces/space-opencode.test.js +15 -2
- package/server/lib/spaces/space-records.js +8 -0
- package/server/lib/spaces/space-records.test.js +7 -3
- package/server/lib/spaces/websocket.test.js +13 -1
- package/server/lib/ui-auth/ui-auth.js +28 -3
- package/server/lib/ui-auth/ui-auth.test.js +31 -0
- package/dist/assets/MarkdownRendererImpl-B2LsA09C.js +0 -1
- package/dist/assets/PlanView-Dt5EN_JK.js +0 -5
- package/dist/assets/SettingsView-BolP_tuu.js +0 -30
- package/dist/assets/SourceBoardView-yca1qvgB.js +0 -1
- package/dist/assets/SpaceAccessDialog-CZ-u75py.js +0 -1
- package/dist/assets/katex-rNcbfUj4.css +0 -1
- package/dist/assets/katex.min-DQ8qF6NR.js +0 -65
- package/dist/assets/main-CVHM3_8W.js +0 -1048
- package/dist/assets/markdownCore-D5ZOJXeO.js +0 -9
- package/dist/assets/pl-Bj-Hy0X5.js +0 -20
- package/dist/assets/renderElectronMiniChatApp-B_5BeSF6.js +0 -2
- package/dist/assets/renderMobileApp-DGEXUTk-.js +0 -25
- package/dist/assets/runtimeEndpointReset-CIpvn8QG.js +0 -59
- package/dist/assets/sessionOwnership-BZoGed9N.js +0 -1
- package/dist/assets/tr-qMRMBQ8r.js +0 -11
- package/dist/assets/useAppFontEffects-Bih1DxXi.js +0 -745
- package/dist/assets/vendor-tanstack-react-virtual-CvuLsk7D.js +0 -1
- package/dist/assets/vendor-tanstack-virtual-core-DPaNcJcT.js +0 -1
|
@@ -46,6 +46,18 @@ function setup(overrides = {}, options = {}) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
describe('GitLab resource service', () => {
|
|
49
|
+
it('reads an upload from a project in the bound network only', async () => {
|
|
50
|
+
const download = vi.fn(async () => new Response('clip'));
|
|
51
|
+
const { service } = setup({}, { download });
|
|
52
|
+
const upload = { secret: '66dbcd21ec5d24ed6ea225176098d52b', filename: 'demo clip.mp4', range: 'bytes=0-' };
|
|
53
|
+
|
|
54
|
+
await service.readUpload('/repo', { owner: 'team', name: 'repo' }, 'origin', upload);
|
|
55
|
+
expect(download).toHaveBeenCalledWith('projects/2/uploads/66dbcd21ec5d24ed6ea225176098d52b/demo%20clip.mp4', { range: 'bytes=0-', signal: undefined });
|
|
56
|
+
|
|
57
|
+
await expect(service.readUpload('/repo', { owner: 'other', name: 'secret' }, 'origin', upload)).rejects.toMatchObject({ status: 404 });
|
|
58
|
+
expect(download).toHaveBeenCalledOnce();
|
|
59
|
+
});
|
|
60
|
+
|
|
49
61
|
it('finds a fork merge request in its upstream and keeps CI separate', async () => {
|
|
50
62
|
const { service, client } = setup();
|
|
51
63
|
const result = await service.changeRequestStatus('/repo', 'feature');
|
|
@@ -119,6 +131,8 @@ describe('GitLab resource service', () => {
|
|
|
119
131
|
const { service } = setup({
|
|
120
132
|
MergeRequests: { ...setup().client.MergeRequests, allCommits, show: vi.fn(async () => ({ ...openMR, reviewers: [{ id: 7, username: 'ann' }, { username: 'no-id' }] })) },
|
|
121
133
|
MergeRequestNotes: { all: list(notes) },
|
|
134
|
+
// The timeline reads the same notes as their discussions.
|
|
135
|
+
MergeRequestDiscussions: { all: list(notes.map((note) => ({ id: `d${note.id}`, individual_note: true, notes: [note] }))) },
|
|
122
136
|
});
|
|
123
137
|
const plain = await service.changeRequestContext('/repo', 5, {});
|
|
124
138
|
expect(plain).not.toHaveProperty('commits');
|
|
@@ -132,12 +146,105 @@ describe('GitLab resource service', () => {
|
|
|
132
146
|
expect(result.reviewers).toEqual([expect.objectContaining({ id: '7', username: 'ann' })]);
|
|
133
147
|
});
|
|
134
148
|
|
|
149
|
+
it('reads a thread as notes that say which thread they are in and its state', async () => {
|
|
150
|
+
const discussions = [
|
|
151
|
+
{ id: 'abc', individual_note: false, notes: [
|
|
152
|
+
{ id: 10, body: 'Rename this', resolvable: true, resolved: true, author: { id: 3, username: 'sam' } },
|
|
153
|
+
{ id: 11, body: 'Done', resolvable: true, resolved: true, author: { id: 4, username: 'ann' } },
|
|
154
|
+
] },
|
|
155
|
+
{ id: 'def', individual_note: true, notes: [{ id: 12, body: 'Plain comment', author: { id: 3, username: 'sam' } }] },
|
|
156
|
+
];
|
|
157
|
+
const { service } = setup({
|
|
158
|
+
MergeRequests: { ...setup().client.MergeRequests, allCommits: list([]) },
|
|
159
|
+
MergeRequestDiscussions: { all: list(discussions) },
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
const result = await service.changeRequestContext('/repo', 5, { includeTimeline: true });
|
|
163
|
+
expect(result.issueComments.map((note) => [note.body, note.thread ?? null])).toEqual([
|
|
164
|
+
['Rename this', { id: 'abc', resolved: true, resolvable: true, first: true }],
|
|
165
|
+
['Done', { id: 'abc', resolved: true, resolvable: true, first: false }],
|
|
166
|
+
['Plain comment', null],
|
|
167
|
+
]);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
it("says what this account may do with a thread when GitLab's GraphQL answers", async () => {
|
|
171
|
+
const post = vi.fn(async () => ({ body: { data: { project: { mergeRequest: {
|
|
172
|
+
discussionLocked: true,
|
|
173
|
+
userPermissions: { createNote: true },
|
|
174
|
+
discussions: { nodes: [{ id: 'gid://gitlab/Discussion/abc', notes: { nodes: [{ userPermissions: { resolveNote: false } }] } }] },
|
|
175
|
+
} } } } }));
|
|
176
|
+
const { service } = setup({
|
|
177
|
+
MergeRequests: { ...setup().client.MergeRequests, allCommits: list([]), requester: { post } },
|
|
178
|
+
MergeRequestDiscussions: { all: list([{ id: 'abc', individual_note: false, notes: [{ id: 10, body: 'Rename', resolvable: true, resolved: false, author: { id: 3, username: 'sam' } }] }]) },
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
const result = await service.changeRequestContext('/repo', 5, { includeTimeline: true });
|
|
182
|
+
// A locked discussion takes no replies, and this account may not resolve the thread.
|
|
183
|
+
expect(result.issueComments[0].thread).toEqual({ id: 'abc', resolved: false, resolvable: true, first: true, canResolve: false, canReply: false });
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('starts, answers and resolves threads on the merge request the path names', async () => {
|
|
187
|
+
const thread = { id: 'abc', individual_note: false, notes: [{ id: 10, body: 'x', resolvable: true, resolved: true }] };
|
|
188
|
+
const discussions = {
|
|
189
|
+
create: vi.fn(async () => ({ ...thread, notes: [{ id: 10, body: 'x', resolvable: true, resolved: false }] })),
|
|
190
|
+
addNote: vi.fn(async () => ({ id: 11, body: 'y' })),
|
|
191
|
+
resolve: vi.fn(async () => thread),
|
|
192
|
+
show: vi.fn(async () => thread),
|
|
193
|
+
};
|
|
194
|
+
const { service } = setup({ MergeRequestDiscussions: discussions });
|
|
195
|
+
const providerTarget = { projectId: '2', number: 5 };
|
|
196
|
+
|
|
197
|
+
await service.startThread({ providerTarget, body: 'x' });
|
|
198
|
+
await service.replyToThread({ providerTarget, threadId: 'abc', body: 'y' });
|
|
199
|
+
await service.resolveThread({ providerTarget, threadId: 'abc', resolved: true });
|
|
200
|
+
await expect(service.resolveThread({ providerTarget, threadId: 'abc', resolved: false })).rejects.toThrow('invalid thread');
|
|
201
|
+
expect(discussions.create).toHaveBeenCalledWith('2', 5, 'x');
|
|
202
|
+
expect(discussions.addNote).toHaveBeenCalledWith('2', 5, 'abc', 'y');
|
|
203
|
+
expect(discussions.resolve).toHaveBeenCalledWith('2', 5, 'abc', true);
|
|
204
|
+
|
|
205
|
+
await expect(service.reconcileThreadResolve(providerTarget, 'abc', true)).resolves.toEqual({ state: 'succeeded', result: {} });
|
|
206
|
+
await expect(service.reconcileThreadResolve(providerTarget, 'abc', false)).resolves.toEqual({ state: 'outcome-unknown' });
|
|
207
|
+
});
|
|
208
|
+
|
|
135
209
|
it('keeps merge-request context when CI jobs fail', async () => {
|
|
136
210
|
const { service } = setup({ Jobs: { all: vi.fn(async () => { throw new Error('jobs unavailable'); }) } });
|
|
137
211
|
const result = await service.changeRequestContext('/repo', 5, { includeDiff: true, includeCIDetails: true });
|
|
138
212
|
expect(result).toMatchObject({ changeRequest: { number: 5 }, files: [{ path: 'a.ts' }], issueComments: [{ body: 'Looks good' }], ci: null });
|
|
139
213
|
});
|
|
140
214
|
|
|
215
|
+
it('counts the lines of a file too large for GitLab to send its diff', async () => {
|
|
216
|
+
const post = vi.fn(async () => ({ body: { data: { project: { mergeRequest: { diffStats: [
|
|
217
|
+
{ path: 'small.ts', additions: 1, deletions: 1 },
|
|
218
|
+
{ path: 'huge.json', additions: 140, deletions: 2500 },
|
|
219
|
+
] } } } } }));
|
|
220
|
+
const diffs = [
|
|
221
|
+
{ old_path: 'small.ts', new_path: 'small.ts', diff: '@@ -1 +1 @@\n-a\n+b\n' },
|
|
222
|
+
{ old_path: 'huge.json', new_path: 'huge.json', diff: '', too_large: true },
|
|
223
|
+
];
|
|
224
|
+
const { service } = setup({ MergeRequests: { ...setup().client.MergeRequests, allDiffs: list(diffs), requester: { post } } });
|
|
225
|
+
|
|
226
|
+
const result = await service.changeRequestContext('/repo', 5, { includeDiff: true });
|
|
227
|
+
expect(result.files).toMatchObject([
|
|
228
|
+
{ path: 'small.ts', additions: 1, deletions: 1 },
|
|
229
|
+
{ path: 'huge.json', additions: 140, deletions: 2500 },
|
|
230
|
+
]);
|
|
231
|
+
expect(post).toHaveBeenCalledWith('../graphql', { body: { query: expect.stringContaining('diffStats'), variables: { path: 'me/repo', iid: '5' } } });
|
|
232
|
+
|
|
233
|
+
// Without GitLab's counts the hunks are counted, as before.
|
|
234
|
+
post.mockRejectedValueOnce(new Error('GraphQL unavailable'));
|
|
235
|
+
const fallback = await service.changeRequestContext('/repo', 5, { includeDiff: true });
|
|
236
|
+
expect(fallback.files).toMatchObject([{ additions: 1, deletions: 1 }, { additions: 0, deletions: 0 }]);
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
it('carries merge request labels with their colours', async () => {
|
|
240
|
+
const labelled = { ...openMR, labels: [{ name: 'bug', color: '#d73a4a' }, 'docs'] };
|
|
241
|
+
const { service, client } = setup({ MergeRequests: { ...setup().client.MergeRequests, all: list([labelled]) } });
|
|
242
|
+
|
|
243
|
+
const page = await service.listChangeRequests('/repo');
|
|
244
|
+
expect(page.items[0].labels).toEqual([{ name: 'bug', color: 'd73a4a' }, { name: 'docs' }]);
|
|
245
|
+
expect(client.MergeRequests.all).toHaveBeenCalledWith(expect.objectContaining({ withLabelsDetails: true }));
|
|
246
|
+
});
|
|
247
|
+
|
|
141
248
|
it.each([
|
|
142
249
|
{ jobs: [] },
|
|
143
250
|
[{ id: 8, status: 'running' }],
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
2
|
import os from 'node:os';
|
|
3
|
+
import { Readable } from 'node:stream';
|
|
4
|
+
import { pipeline } from 'node:stream/promises';
|
|
3
5
|
|
|
4
6
|
import { createSourceControlAuthStore } from './auth-storage.js';
|
|
5
7
|
import { exchangeGitLabDeviceCode, resolveGitLabClientId, probeGitLabAuth, startGitLabDeviceFlow } from './device-flow.js';
|
|
6
8
|
import { getGlabToken } from './glab-credential.js';
|
|
7
9
|
import { normalizeGitLabInstance } from './instance.js';
|
|
8
10
|
import { classifyGitLabFailure } from './network.js';
|
|
9
|
-
import { createGitLabClient } from './client.js';
|
|
11
|
+
import { createGitLabClient, createGitLabDownloader } from './client.js';
|
|
10
12
|
import { createGitLabResourceService } from './resources.js';
|
|
11
13
|
import { verifyGitLabToken } from './verify.js';
|
|
12
14
|
import { isString } from './validation.js';
|
|
@@ -98,6 +100,21 @@ function requestText(value) {
|
|
|
98
100
|
return isString(value) ? value.trim() : '';
|
|
99
101
|
}
|
|
100
102
|
|
|
103
|
+
// GitLab writes a file attached in Markdown as `/uploads/<32-hex secret>/<name>`.
|
|
104
|
+
const UPLOAD_SECRET_RE = /^[0-9a-f]{32}$/;
|
|
105
|
+
// Only what an `img` or a `video` draws is served; an uploaded page or SVG
|
|
106
|
+
// opened from this server's origin could run script in it.
|
|
107
|
+
const UPLOAD_MEDIA_TYPE_RE = /^(?:image\/(?:png|jpeg|gif|webp|avif)|video\/(?:mp4|webm|quicktime))$/;
|
|
108
|
+
const UPLOAD_PASSED_HEADERS = ['content-length', 'content-range', 'accept-ranges', 'etag', 'last-modified'];
|
|
109
|
+
|
|
110
|
+
/** Express has decoded the name already; a `/`, `.` or `..` would leave the upload's folder. */
|
|
111
|
+
function readUploadParams(params) {
|
|
112
|
+
const secret = requestText(params?.secret);
|
|
113
|
+
const filename = isString(params?.filename) ? params.filename : '';
|
|
114
|
+
const plainName = filename && filename !== '.' && filename !== '..' && !/[/\\]/.test(filename);
|
|
115
|
+
return UPLOAD_SECRET_RE.test(secret) && plainName ? { secret, filename } : null;
|
|
116
|
+
}
|
|
117
|
+
|
|
101
118
|
function requestNumber(value) {
|
|
102
119
|
const number = Number.parseInt(String(value ?? ''), 10);
|
|
103
120
|
return Number.isInteger(number) && number > 0 ? number : null;
|
|
@@ -121,6 +138,7 @@ export function registerGitLabRoutes(app, options = {}) {
|
|
|
121
138
|
const glabToken = (origin) => getGlabToken(origin, { execFile: options.execFile, timeoutMs: options.cliTimeoutMs });
|
|
122
139
|
const verify = (origin, token) => verifyGitLabToken({ origin, token, fetch: fetchImpl, timeoutMs });
|
|
123
140
|
const createClient = options.createClient ?? createGitLabClient;
|
|
141
|
+
const createDownloader = options.createDownloader ?? createGitLabDownloader;
|
|
124
142
|
const identityFor = (origin, accountId) => ({ provider: 'gitlab', instance: origin, accountId });
|
|
125
143
|
/**
|
|
126
144
|
* A connected account is a complete identity waiting to be written: who it
|
|
@@ -283,6 +301,7 @@ export function registerGitLabRoutes(app, options = {}) {
|
|
|
283
301
|
// sign-ins, and the glab login (an OAuth token on gitlab.com, a personal
|
|
284
302
|
// token elsewhere), go as a bearer token, which GitLab accepts for both.
|
|
285
303
|
client: createClient({ origin, token, tokenType: active?.source === 'pat' ? 'token' : 'oauth' }),
|
|
304
|
+
download: createDownloader({ origin, token, tokenType: active?.source === 'pat' ? 'token' : 'oauth' }),
|
|
286
305
|
canonicalReads,
|
|
287
306
|
};
|
|
288
307
|
if (options.resolveProjects) resourceOptions.resolveProjects = options.resolveProjects;
|
|
@@ -825,6 +844,59 @@ export function registerGitLabRoutes(app, options = {}) {
|
|
|
825
844
|
}
|
|
826
845
|
});
|
|
827
846
|
|
|
847
|
+
// A discussion id (a SHA on GitLab); the request path keeps it on the target merge request.
|
|
848
|
+
const threadIdOf = (value) => {
|
|
849
|
+
if (!isString(value) || !/^[A-Za-z0-9_-]{1,100}$/.test(value)) throw invalidMutationContext('threadId is invalid');
|
|
850
|
+
return value;
|
|
851
|
+
};
|
|
852
|
+
|
|
853
|
+
app.post('/api/source-control/gitlab/pr/thread/start', async (req, res) => {
|
|
854
|
+
try {
|
|
855
|
+
const body = req.body ?? {};
|
|
856
|
+
return res.json(await executeMutation(body, 'change-request-thread-start', (input, context) => {
|
|
857
|
+
if (!context.target.number) throw invalidMutationContext('target number is required');
|
|
858
|
+
const text = noteText(input.body, true);
|
|
859
|
+
return { body: text, digest: { body: text } };
|
|
860
|
+
}, (service, normalized, resolved) => service.startThread({ providerTarget: resolved.providerTarget, body: normalized.body }),
|
|
861
|
+
unknownOutcome));
|
|
862
|
+
} catch (error) {
|
|
863
|
+
return sendMutationError(res, error);
|
|
864
|
+
}
|
|
865
|
+
});
|
|
866
|
+
|
|
867
|
+
app.post('/api/source-control/gitlab/pr/thread/reply', async (req, res) => {
|
|
868
|
+
try {
|
|
869
|
+
const body = req.body ?? {};
|
|
870
|
+
return res.json(await executeMutation(body, 'change-request-thread-reply', (input, context) => {
|
|
871
|
+
if (!context.target.number) throw invalidMutationContext('target number is required');
|
|
872
|
+
const threadId = threadIdOf(input.threadId);
|
|
873
|
+
const text = noteText(input.body, true);
|
|
874
|
+
return { threadId, body: text, digest: { threadId, body: text } };
|
|
875
|
+
}, (service, normalized, resolved) => service.replyToThread({
|
|
876
|
+
providerTarget: resolved.providerTarget, threadId: normalized.threadId, body: normalized.body,
|
|
877
|
+
}), unknownOutcome));
|
|
878
|
+
} catch (error) {
|
|
879
|
+
return sendMutationError(res, error);
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
|
|
883
|
+
app.post('/api/source-control/gitlab/pr/thread/resolve', async (req, res) => {
|
|
884
|
+
try {
|
|
885
|
+
const body = req.body ?? {};
|
|
886
|
+
return res.json(await executeMutation(body, 'change-request-thread-resolve', (input, context) => {
|
|
887
|
+
if (!context.target.number || ![true, false].includes(input.resolved)) {
|
|
888
|
+
throw invalidMutationContext('target number and resolved are required');
|
|
889
|
+
}
|
|
890
|
+
const threadId = threadIdOf(input.threadId);
|
|
891
|
+
return { threadId, resolved: input.resolved, digest: { threadId, resolved: input.resolved } };
|
|
892
|
+
}, (service, normalized, resolved) => service.resolveThread({
|
|
893
|
+
providerTarget: resolved.providerTarget, threadId: normalized.threadId, resolved: normalized.resolved,
|
|
894
|
+
}), (service, resolved, normalized) => service.reconcileThreadResolve(resolved.providerTarget, normalized.threadId, normalized.resolved)));
|
|
895
|
+
} catch (error) {
|
|
896
|
+
return sendMutationError(res, error);
|
|
897
|
+
}
|
|
898
|
+
});
|
|
899
|
+
|
|
828
900
|
app.post('/api/source-control/gitlab/issues/comment', async (req, res) => {
|
|
829
901
|
try {
|
|
830
902
|
const body = req.body ?? {};
|
|
@@ -924,6 +996,53 @@ export function registerGitLabRoutes(app, options = {}) {
|
|
|
924
996
|
});
|
|
925
997
|
}
|
|
926
998
|
|
|
999
|
+
// A picture or a clip attached to an issue, a merge request or a note, for
|
|
1000
|
+
// the board. GitLab serves uploads to signed-in project members only, and
|
|
1001
|
+
// writes them as paths the browser would resolve against this server. The
|
|
1002
|
+
// path keeps GitLab's own shape, so the file name ends it.
|
|
1003
|
+
app.get('/api/source-control/gitlab/uploads/:secret/:filename', async (req, res) => {
|
|
1004
|
+
const abort = new AbortController();
|
|
1005
|
+
res.on('close', () => abort.abort());
|
|
1006
|
+
try {
|
|
1007
|
+
const owner = requestText(req.query?.owner);
|
|
1008
|
+
const repo = requestText(req.query?.repo);
|
|
1009
|
+
const upload = readUploadParams(req.params);
|
|
1010
|
+
if (!owner || !repo || !upload) return res.status(400).json({ error: 'a project selector and an upload path are required' });
|
|
1011
|
+
const origin = requestOrigin(req);
|
|
1012
|
+
const directory = requestText(req.query?.directory);
|
|
1013
|
+
const trustedContext = await validateReadContext(req, origin, directory);
|
|
1014
|
+
if (!trustedContext) return res.status(501).json({ error: 'Bound source control status is unavailable' });
|
|
1015
|
+
const service = await getResourceService(origin, trustedContext.accountId, true);
|
|
1016
|
+
const upstream = await service.readUpload(directory, { owner, name: repo }, trustedContext.primaryRemote, {
|
|
1017
|
+
...upload,
|
|
1018
|
+
range: requestText(req.get('range')) || undefined,
|
|
1019
|
+
signal: abort.signal,
|
|
1020
|
+
});
|
|
1021
|
+
const type = (upstream.headers.get('content-type') || '').split(';')[0].trim().toLowerCase();
|
|
1022
|
+
if (!upstream.ok || !upstream.body || !UPLOAD_MEDIA_TYPE_RE.test(type)) {
|
|
1023
|
+
await upstream.body?.cancel().catch(() => {});
|
|
1024
|
+
// A refused read is the file's answer, never the account's: it does not invalidate it.
|
|
1025
|
+
return res.status(upstream.ok ? 415 : upstream.status === 416 ? 416 : 404).end();
|
|
1026
|
+
}
|
|
1027
|
+
res.status(upstream.status);
|
|
1028
|
+
res.setHeader('Content-Type', type);
|
|
1029
|
+
for (const header of UPLOAD_PASSED_HEADERS) {
|
|
1030
|
+
const value = upstream.headers.get(header);
|
|
1031
|
+
if (value) res.setHeader(header, value);
|
|
1032
|
+
}
|
|
1033
|
+
res.setHeader('Cache-Control', 'private, max-age=3600');
|
|
1034
|
+
res.setHeader('X-Content-Type-Options', 'nosniff');
|
|
1035
|
+
res.setHeader('Content-Security-Policy', "default-src 'none'; sandbox");
|
|
1036
|
+
await pipeline(Readable.fromWeb(upstream.body), res);
|
|
1037
|
+
} catch (error) {
|
|
1038
|
+
if (abort.signal.aborted) return undefined;
|
|
1039
|
+
if (res.headersSent) return res.destroy();
|
|
1040
|
+
if (isReadContextError(error)) return res.status(error.status ?? 400).json(sourceControlErrorBody(error));
|
|
1041
|
+
return sendResourceError(res, error);
|
|
1042
|
+
}
|
|
1043
|
+
return undefined;
|
|
1044
|
+
});
|
|
1045
|
+
|
|
927
1046
|
app.post('/api/source-control/gitlab/pr/review', async (req, res) => {
|
|
928
1047
|
try {
|
|
929
1048
|
const body = req.body ?? {};
|
|
@@ -111,6 +111,9 @@ function canonicalMutationOptions(overrides = {}) {
|
|
|
111
111
|
reconcileState: vi.fn(async (_target, _kind, state) => ({ state: 'succeeded', result: { state } })),
|
|
112
112
|
setLabels: vi.fn(async () => ({})),
|
|
113
113
|
setReviewers: vi.fn(async () => ({})),
|
|
114
|
+
startThread: vi.fn(async () => ({})),
|
|
115
|
+
replyToThread: vi.fn(async () => ({})),
|
|
116
|
+
resolveThread: vi.fn(async () => ({})),
|
|
114
117
|
listLabels: vi.fn(async () => [{ name: 'bug', color: 'd73a4a' }]),
|
|
115
118
|
listReviewers: vi.fn(async () => [{ id: '7', login: 'ann' }]),
|
|
116
119
|
resolveIssue: vi.fn(async (context) => ({
|
|
@@ -141,6 +144,10 @@ function canonicalMutationOptions(overrides = {}) {
|
|
|
141
144
|
setLabels: calls.setLabels,
|
|
142
145
|
setReviewers: calls.setReviewers,
|
|
143
146
|
reconcileSetMutation: vi.fn(async () => ({ state: 'outcome-unknown' })),
|
|
147
|
+
startThread: calls.startThread,
|
|
148
|
+
replyToThread: calls.replyToThread,
|
|
149
|
+
resolveThread: calls.resolveThread,
|
|
150
|
+
reconcileThreadResolve: vi.fn(async () => ({ state: 'succeeded', result: {} })),
|
|
144
151
|
listLabels: calls.listLabels,
|
|
145
152
|
listReviewerCandidates: calls.listReviewers,
|
|
146
153
|
};
|
|
@@ -460,6 +467,26 @@ describe('GitLab routes', () => {
|
|
|
460
467
|
expect(setup.calls.comment).toHaveBeenCalledOnce();
|
|
461
468
|
});
|
|
462
469
|
|
|
470
|
+
it('starts, answers and resolves merge request threads through the canonical executor', async () => {
|
|
471
|
+
const setup = canonicalMutationOptions();
|
|
472
|
+
const app = appWith(setup.options);
|
|
473
|
+
const existing = (key) => mutationBody({ idempotencyKey: key, target: { project: { owner: 'team', name: 'repo' }, number: 5 } });
|
|
474
|
+
const providerTarget = { projectId: '2', number: 5 };
|
|
475
|
+
|
|
476
|
+
await request(app).post('/api/source-control/gitlab/pr/thread/start').send({ ...existing('thread-one'), body: 'Please rename' }).expect(200);
|
|
477
|
+
await request(app).post('/api/source-control/gitlab/pr/thread/reply').send({ ...existing('thread-two'), threadId: 'abc123', body: 'Done' }).expect(200);
|
|
478
|
+
await request(app).post('/api/source-control/gitlab/pr/thread/resolve').send({ ...existing('thread-three'), threadId: 'abc123', resolved: true }).expect(200);
|
|
479
|
+
|
|
480
|
+
expect(setup.calls.startThread).toHaveBeenCalledWith({ providerTarget, body: 'Please rename' });
|
|
481
|
+
expect(setup.calls.replyToThread).toHaveBeenCalledWith({ providerTarget, threadId: 'abc123', body: 'Done' });
|
|
482
|
+
expect(setup.calls.resolveThread).toHaveBeenCalledWith({ providerTarget, threadId: 'abc123', resolved: true });
|
|
483
|
+
|
|
484
|
+
await request(app).post('/api/source-control/gitlab/pr/thread/reply').send({ ...existing('thread-four'), threadId: '../x', body: 'Done' }).expect(400);
|
|
485
|
+
await request(app).post('/api/source-control/gitlab/pr/thread/resolve').send({ ...existing('thread-five'), threadId: 'abc123' }).expect(400);
|
|
486
|
+
expect(setup.calls.replyToThread).toHaveBeenCalledOnce();
|
|
487
|
+
expect(setup.calls.resolveThread).toHaveBeenCalledOnce();
|
|
488
|
+
});
|
|
489
|
+
|
|
463
490
|
it('closes and reopens through the canonical executor and reconciles by state after a restart', async () => {
|
|
464
491
|
let failCompletion = false;
|
|
465
492
|
const mutationStore = makeMutationStore([], async () => {
|
|
@@ -623,6 +650,38 @@ describe('GitLab routes', () => {
|
|
|
623
650
|
.query({ instance: origin, directory: '/repo', owner: 'team', repo: 'repo' }).expect(501);
|
|
624
651
|
});
|
|
625
652
|
|
|
653
|
+
it('streams a picture or a clip attached on GitLab, and nothing a page could run from', async () => {
|
|
654
|
+
const account = { id: `${origin}#9`, token: 'stored', user: { id: 9, login: 'user' }, source: 'pat', scope: '' };
|
|
655
|
+
const secret = '66dbcd21ec5d24ed6ea225176098d52b';
|
|
656
|
+
const readUpload = vi.fn(async (_directory, _project, _remote, { filename }) => (filename === 'page.html'
|
|
657
|
+
? new Response('<script>alert(1)</script>', { headers: { 'content-type': 'text/html' } })
|
|
658
|
+
: new Response('clip', { status: 206, headers: { 'content-type': 'video/mp4', 'content-range': 'bytes 0-3/9' } })));
|
|
659
|
+
const app = appWith({ store: makeStore(account), createResourceService: vi.fn(() => ({ readUpload })) });
|
|
660
|
+
const query = {
|
|
661
|
+
instance: origin, directory: '/repo', repositoryId: 'repo_one', bindingRevision: 3,
|
|
662
|
+
accountId: account.id, primaryRemote: 'origin', owner: 'team', repo: 'repo',
|
|
663
|
+
};
|
|
664
|
+
|
|
665
|
+
const uploads = '/api/source-control/gitlab/uploads';
|
|
666
|
+
const clip = await request(app).get(`${uploads}/${secret}/demo%20clip.mp4`)
|
|
667
|
+
.query(query).set('range', 'bytes=0-3').expect(206);
|
|
668
|
+
expect(clip.headers['content-type']).toBe('video/mp4');
|
|
669
|
+
expect(clip.headers['content-range']).toBe('bytes 0-3/9');
|
|
670
|
+
expect(clip.headers['content-security-policy']).toContain('sandbox');
|
|
671
|
+
expect(readUpload).toHaveBeenCalledWith('/repo', { owner: 'team', name: 'repo' }, 'origin', expect.objectContaining({
|
|
672
|
+
secret, filename: 'demo clip.mp4', range: 'bytes=0-3',
|
|
673
|
+
}));
|
|
674
|
+
|
|
675
|
+
await request(app).get(`${uploads}/${secret}/page.html`).query(query).expect(415);
|
|
676
|
+
await request(app).get(`${uploads}/short/x.png`).query(query).expect(400);
|
|
677
|
+
await request(app).get(`${uploads}/${secret}/a%2Fb.png`).query(query).expect(400);
|
|
678
|
+
// Clients may resolve `..` before sending; either way GitLab is not asked.
|
|
679
|
+
const parent = await request(app).get(`${uploads}/${secret}/%2E%2E`).query(query);
|
|
680
|
+
expect(parent.status).toBeGreaterThanOrEqual(400);
|
|
681
|
+
await request(app).get(`${uploads}/${secret}/x.png`).query({ ...query, owner: '' }).expect(400);
|
|
682
|
+
expect(readUpload).toHaveBeenCalledTimes(2);
|
|
683
|
+
});
|
|
684
|
+
|
|
626
685
|
it('uses matching bound context and rejects it before provider creation when stale', async () => {
|
|
627
686
|
const account = { id: `${origin}#9`, token: 'stored', user: { id: 9, login: 'user' }, source: 'pat', scope: '' };
|
|
628
687
|
const store = makeStore(account);
|
|
@@ -21,6 +21,10 @@ UI is on a different machine.
|
|
|
21
21
|
directory. Other absolute paths are accepted only inside
|
|
22
22
|
`os.tmpdir()/opencode` after `realpath` resolution.
|
|
23
23
|
- PNG, JPEG, GIF, and WebP files are signature-checked and limited to 10 MiB.
|
|
24
|
+
MP4, M4V, MOV, and WebM clips are checked by their `ftyp` box or EBML magic
|
|
25
|
+
and limited to 1 GiB: `/api/fs/raw` streams them by byte range, and the chat
|
|
26
|
+
draws them as a player. VS Code keeps a local clip as its file name, since
|
|
27
|
+
its filesystem bridge reads files whole.
|
|
24
28
|
- Prepare requests inspect only file metadata and signatures. Workspace images
|
|
25
29
|
reuse the existing authenticated `/api/fs/raw` asset route directly. Images
|
|
26
30
|
under `os.tmpdir()/opencode` receive the existing path-bound `raw`
|
|
@@ -4,6 +4,9 @@ import { mintOutsideFileGrant } from '../fs/routes.js';
|
|
|
4
4
|
import { unwrapOpenCodeResponse } from '../opencode/response-envelope.js';
|
|
5
5
|
|
|
6
6
|
const MAX_IMAGE_BYTES = 10 * 1024 * 1024;
|
|
7
|
+
// A clip streams by byte ranges on every seek, so it is never read whole.
|
|
8
|
+
const MAX_VIDEO_BYTES = 1024 * 1024 * 1024;
|
|
9
|
+
const VIDEO_EXTENSION_RE = /\.(?:mp4|m4v|mov|webm)$/i;
|
|
7
10
|
const MAX_IMAGE_SOURCES = 12;
|
|
8
11
|
|
|
9
12
|
const asString = (value) => typeof value === 'string' ? value.trim() : '';
|
|
@@ -43,6 +46,10 @@ const hasImageSignature = (bytes) => {
|
|
|
43
46
|
|| (header.startsWith('RIFF') && header.slice(8, 12) === 'WEBP');
|
|
44
47
|
};
|
|
45
48
|
|
|
49
|
+
// MP4 and QuickTime start with an `ftyp` box; WebM with the EBML magic.
|
|
50
|
+
const hasVideoSignature = (bytes) => (bytes.length >= 8 && bytes.subarray(4, 8).toString('ascii') === 'ftyp')
|
|
51
|
+
|| (bytes.length >= 4 && bytes[0] === 0x1a && bytes[1] === 0x45 && bytes[2] === 0xdf && bytes[3] === 0xa3);
|
|
52
|
+
|
|
46
53
|
const normalizeReferenceLabel = (value) => value.trim().replace(/\s+/g, ' ').toLowerCase();
|
|
47
54
|
|
|
48
55
|
const unescapeMarkdownDestination = (value) => value.replace(/\\([!"#$%&'()*+,\-./:;<=>?@[\]^_`{|}~\\])/g, '$1');
|
|
@@ -242,11 +249,16 @@ const inspectImage = async ({ source, directory, approvedTempRoot, fsPromises, p
|
|
|
242
249
|
if (!isWithin(canonicalPath, canonicalRoot, path)) return { status: 'error' };
|
|
243
250
|
const handle = await fsPromises.open(canonicalPath, fsConstants.O_RDONLY | fsConstants.O_NOFOLLOW);
|
|
244
251
|
try {
|
|
252
|
+
// The chat draws a clip or a picture by the name the message gave; a
|
|
253
|
+
// link under one name to a file of the other kind gets neither limit.
|
|
254
|
+
const video = VIDEO_EXTENSION_RE.test(sourcePath);
|
|
255
|
+
if (video !== VIDEO_EXTENSION_RE.test(canonicalPath)) return { status: 'error' };
|
|
245
256
|
const stats = await handle.stat();
|
|
246
|
-
if (!stats.isFile() || stats.size > MAX_IMAGE_BYTES) return { status: 'error' };
|
|
257
|
+
if (!stats.isFile() || stats.size > (video ? MAX_VIDEO_BYTES : MAX_IMAGE_BYTES)) return { status: 'error' };
|
|
247
258
|
const header = Buffer.alloc(12);
|
|
248
259
|
const { bytesRead } = await handle.read(header, 0, header.length, 0);
|
|
249
|
-
|
|
260
|
+
const signed = video ? hasVideoSignature : hasImageSignature;
|
|
261
|
+
if (!signed(header.subarray(0, bytesRead))) return { status: 'error' };
|
|
250
262
|
return {
|
|
251
263
|
status: 'ready',
|
|
252
264
|
path: outsideWorkspace ? canonicalPath : path.resolve(sourcePath),
|
|
@@ -133,6 +133,29 @@ describe('session image assets', () => {
|
|
|
133
133
|
]);
|
|
134
134
|
});
|
|
135
135
|
|
|
136
|
+
it('prepares MP4 and WebM clips past the image size limit, and refuses one with other bytes', async () => {
|
|
137
|
+
const sources = ['clip.mp4', 'clip.webm', 'fake.mp4', 'shot.png'];
|
|
138
|
+
const fixture = await createFixture({ sources });
|
|
139
|
+
const mp4 = Buffer.alloc(11 * 1024 * 1024);
|
|
140
|
+
Buffer.from([0, 0, 0, 0x20, 0x66, 0x74, 0x79, 0x70]).copy(mp4);
|
|
141
|
+
await Promise.all([
|
|
142
|
+
fs.writeFile(path.join(fixture.directory, 'clip.mp4'), mp4),
|
|
143
|
+
fs.writeFile(path.join(fixture.directory, 'clip.webm'), Buffer.from([0x1a, 0x45, 0xdf, 0xa3, 0, 0, 0, 0])),
|
|
144
|
+
fs.writeFile(path.join(fixture.directory, 'fake.mp4'), PNG),
|
|
145
|
+
]);
|
|
146
|
+
// A "picture" that links to the clip would load it whole as an image.
|
|
147
|
+
await fs.symlink(path.join(fixture.directory, 'clip.mp4'), path.join(fixture.directory, 'shot.png'));
|
|
148
|
+
|
|
149
|
+
const response = await prepare(fixture.app, fixture.directory, sources);
|
|
150
|
+
|
|
151
|
+
expect(response.body.results).toEqual([
|
|
152
|
+
expect.objectContaining({ source: 'clip.mp4', status: 'ready' }),
|
|
153
|
+
expect.objectContaining({ source: 'clip.webm', status: 'ready' }),
|
|
154
|
+
{ source: 'fake.mp4', status: 'error' },
|
|
155
|
+
{ source: 'shot.png', status: 'error' },
|
|
156
|
+
]);
|
|
157
|
+
});
|
|
158
|
+
|
|
136
159
|
it('resolves encoded workspace paths without treating query or fragment text as a filename', async () => {
|
|
137
160
|
const source = 'screen%20shot.png?version=1#preview';
|
|
138
161
|
const fixture = await createFixture({ sources: [source] });
|
|
@@ -14,7 +14,7 @@ registered them — so a leaked device token alone can't be used to push.
|
|
|
14
14
|
(`getOrCreateRelayKeypair`, persisted in settings like the VAPID keys). The relay records
|
|
15
15
|
`token → serverId` where `serverId = SHA-256(publicKey)`.
|
|
16
16
|
3. On a trigger (ready/error/question/permission), the server composes **generic, content-free**
|
|
17
|
-
text — a fixed scenario title ("Agent response is ready" / "Agent needs your input" / "Agent
|
|
17
|
+
clear text (a phone with a push key also gets the real text sealed, see *Data confidentiality*) — a fixed scenario title ("Agent response is ready" / "Agent needs your input" / "Agent
|
|
18
18
|
needs permission" / "Agent hit an error") + the **session name** as the body, no model/project/
|
|
19
19
|
message content — plus a **`badge`** count (see below) — and POSTs `{ tokens, title, body,
|
|
20
20
|
badge, env, data:{sessionId}, publicKeyJwk, ts, sig }` to `POST /v1/push/send`
|
|
@@ -107,29 +107,30 @@ binding table is created by `migrations/0002_push_tokens.sql` (applied on deploy
|
|
|
107
107
|
- Residual: trust-on-first-bind (whoever registers a token first owns it) — acceptable, since
|
|
108
108
|
registering already requires possessing the token. Cloudflare rate limiting is defence-in-depth.
|
|
109
109
|
|
|
110
|
-
## Data confidentiality (what the relay / Apple can see)
|
|
110
|
+
## Data confidentiality (what the relay / Apple / Google can see)
|
|
111
111
|
|
|
112
|
-
The
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
112
|
+
The request **signature is authentication**: the relay verifies it and it hides nothing. What
|
|
113
|
+
hides the text is the **push key** (`push-seal.js`). A current iOS or Android app registers a
|
|
114
|
+
32-byte key that stays on the server and the phone. For such a phone the server sends the
|
|
115
|
+
generic scenario title in the clear, an empty body, and `data.enc`: AES-256-GCM of what the
|
|
116
|
+
phone shows. That is the session name as title and what happened as body: the agent's reply,
|
|
117
|
+
the question, the command or file a permission is for, the error, the goal outcome
|
|
118
|
+
(`runtime.js` → `toApnsGenericPayload` → `sealed`, at most 250 characters). The iOS
|
|
119
|
+
Notification Service Extension and Android's `SealedPushMessagingService` open it on the device.
|
|
116
120
|
|
|
117
|
-
Who can read
|
|
121
|
+
Who can read what:
|
|
118
122
|
|
|
119
123
|
- **Network hops:** nothing (TLS).
|
|
120
|
-
- **The relay (Cloudflare):** the generic title
|
|
121
|
-
|
|
122
|
-
- **Apple APNs
|
|
123
|
-
- **The device:**
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
The Android equivalent is **FCM** (not implemented): the same relay would forward to FCM with a
|
|
135
|
-
server key, and the client would register an FCM token (same store/routes + signing).
|
|
124
|
+
- **The relay (Cloudflare):** the generic title, the device token, `sessionId` and the sealed
|
|
125
|
+
blob. It stores only `token → serverId` hashes (no text, no payload).
|
|
126
|
+
- **Apple APNs / Google FCM:** the same as the relay.
|
|
127
|
+
- **The device:** opens the blob and shows the real text.
|
|
128
|
+
|
|
129
|
+
An app that registered without a key gets the generic title and the session name in the clear,
|
|
130
|
+
and no message content. Enterprise mode sends no sealed text and drops the session name, so
|
|
131
|
+
every phone shows only the scenario title.
|
|
132
|
+
|
|
133
|
+
## Android (FCM)
|
|
134
|
+
|
|
135
|
+
The relay forwards Android tokens to FCM. A sealed push goes as a data message, so
|
|
136
|
+
`SealedPushMessagingService` runs in the background and builds the notification itself.
|
|
@@ -7,7 +7,7 @@ This module provides notification message preparation utilities for the web serv
|
|
|
7
7
|
- `packages/web/server/lib/notifications/index.js`: public entrypoint imported by `packages/web/server/index.js`.
|
|
8
8
|
- `packages/web/server/lib/notifications/routes.js`: route registration for push, visibility, and session status/attention endpoints.
|
|
9
9
|
- `packages/web/server/lib/notifications/push-runtime.js`: push subscription persistence, VAPID initialization, and UI visibility runtime.
|
|
10
|
-
- `packages/web/server/lib/notifications/push-seal.js`: end-to-end sealing of native push text. A phone that registers with a `pushKey` (32 bytes, base64; made by the iOS shell in the App Group, by Android's `PushSealKey`) gets each notification as the generic scenario title, an empty body and `data.enc` = `v1.` + base64(nonce || AES-256-GCM ciphertext || tag) of `{ title, body }`. Each such device is its own relay send. The iOS Notification Service Extension and Android's `SealedPushMessagingService` open it; the relay sends a sealed push to Android as a data message (openchamber-website `apps/api/src/lib/fcm.ts`) so that service runs in the background. Phones without a key keep getting
|
|
10
|
+
- `packages/web/server/lib/notifications/push-seal.js`: end-to-end sealing of native push text. A phone that registers with a `pushKey` (32 bytes, base64; made by the iOS shell in the App Group, by Android's `PushSealKey`) gets each notification as the generic scenario title, an empty body and `data.enc` = `v1.` + base64(nonce || AES-256-GCM ciphertext || tag) of `{ title, body }`. Each such device is its own relay send. The iOS Notification Service Extension and Android's `SealedPushMessagingService` open it; the relay sends a sealed push to Android as a data message (openchamber-website `apps/api/src/lib/fcm.ts`) so that service runs in the background. The sealed text is richer than the clear one: `runtime.js` passes `sealed` = the session name as title and what happened as body (the agent's reply; `Question:`, `Wants to run:` / `Wants to edit:` / `Wants to read:` / `Wants permission:`, `Error:` or the goal title before the detail), capped at 250 characters. When there is no such text, the phone opens the generic text. Phones without a key keep getting the generic text in the clear. Enterprise mode sends no `sealed` text and strips the session name, so the phone shows only the scenario title.
|
|
11
11
|
- `packages/web/server/lib/notifications/session-key.js`: the key both push stores group registrations under, a `sha256:` hash of the UI session token, never the token. Files written before the hashing are rewritten with hashed keys on first read. Both stores are written `0600`.
|
|
12
12
|
- `packages/web/server/lib/notifications/apns-runtime.js`: native iOS APNs device-token persistence + delivery. Two modes: **relay** (default — sign + POST tokens + generic text to the central Cloudflare relay `https://api.openchamber.dev/v1/push/send`, which holds the single project APNs key) and **direct** (fallback — sign ES256 JWT with Node crypto + HTTP/2, when `OPENCHAMBER_PUSH_RELAY_DISABLED=true`). Each server has an auto-generated ECDSA P-256 keypair (`getOrCreateRelayKeypair`, persisted in settings); it binds tokens on the relay (`/v1/push/register-token`) and signs every relay request, so the relay only delivers to tokens bound to that server. APNs is the native app's sole notification channel (no local notifications) and is NOT gated on UI visibility — iOS suppresses the foreground banner instead. Mobile push carries only generic text (scenario title + session name) — see `APNS.md`. In enterprise mode (`../enterprise-mode.js`) `fanoutPush` also drops the session name from APNs and sends web push with the scenario title, an empty body and the deep link only, since web push leaves through the browser vendor's push service. Desktop notifications and in-app toasts stay local and keep the full text.
|
|
13
13
|
- `packages/web/server/lib/notifications/emitter-runtime.js`: desktop/stdout + UI SSE notification emission runtime.
|
|
@@ -75,7 +75,7 @@ This module provides notification message preparation utilities for the web serv
|
|
|
75
75
|
- `addOrUpdateApnsToken(uiSessionToken, deviceToken, userAgent, platform, environment)` — also binds a newly-seen token on the relay (signed `/v1/push/register-token`). `environment` is the APNs environment the token was minted for (`sandbox` for Xcode/dev-signed installs, `production` otherwise — reported by the client at registration); delivery groups tokens by it.
|
|
76
76
|
- `removeApnsToken(uiSessionToken, deviceToken)`
|
|
77
77
|
- `removeApnsTokenFromAllSessions(deviceToken)`
|
|
78
|
-
- `sendApnsToAllUiSessions(payload)` —
|
|
78
|
+
- `sendApnsToAllUiSessions(payload)` — `payload.sealed` (`{ title, body }`, optional) is what a phone with a push key opens; it is never sent in the clear. Signs + sends to all registered tokens (no UI-visibility gate; iOS suppresses the foreground banner). No-ops with a single warning when APNs is unconfigured. Drops tokens on `410` / `BadDeviceToken` / `Unregistered`.
|
|
79
79
|
- `resolveApnsConfig()`
|
|
80
80
|
- Configuration (env first, then `settings.apnsConfig`): `OPENCHAMBER_APNS_KEY_ID`, `OPENCHAMBER_APNS_TEAM_ID`, `OPENCHAMBER_APNS_P8` (PEM contents; literal `\n` accepted) or `OPENCHAMBER_APNS_P8_PATH`, `OPENCHAMBER_APNS_BUNDLE_ID` (default `com.openchamber.app`), `OPENCHAMBER_APNS_ENVIRONMENT` (optional override forcing every send to `sandbox` or `production`; when unset, each token is delivered to the environment it registered with, defaulting to `production` for tokens without one).
|
|
81
81
|
|
|
@@ -507,7 +507,10 @@ export const createApnsRuntime = (deps) => {
|
|
|
507
507
|
// background push for short responses. Instead we always send, and rely on iOS to NOT
|
|
508
508
|
// display the alert while the app is foreground (presentationOptions: [] in
|
|
509
509
|
// capacitor.config) — so there is no notification when the app is active, with no race.
|
|
510
|
-
|
|
510
|
+
// `sealed` is the `{ title, body }` a phone with a key shows; without it the
|
|
511
|
+
// phone opens the same text an app without a key gets in the clear.
|
|
512
|
+
const sendApnsToAllUiSessions = async ({ sealed, ...payload } = {}, _options = {}) => {
|
|
513
|
+
const sealedContent = sealed ?? { title: payload.title, body: payload.body };
|
|
511
514
|
const store = await readTokensFromDisk();
|
|
512
515
|
// Tokens are grouped by their registered APNs environment so each batch goes to the
|
|
513
516
|
// endpoint that actually knows the token (Xcode builds → sandbox, TestFlight/App Store
|
|
@@ -538,25 +541,25 @@ export const createApnsRuntime = (deps) => {
|
|
|
538
541
|
await sendViaRelay(deviceTokens, payload, relay, relay.environment ?? environment);
|
|
539
542
|
}
|
|
540
543
|
for (const entry of sealedDevices) {
|
|
541
|
-
await sendViaRelay([entry.deviceToken], sealedPayloadFor(payload, entry.pushKey), relay, relay.environment ?? entry.environment);
|
|
544
|
+
await sendViaRelay([entry.deviceToken], sealedPayloadFor(payload, sealedContent, entry.pushKey), relay, relay.environment ?? entry.environment);
|
|
542
545
|
}
|
|
543
546
|
return;
|
|
544
547
|
}
|
|
545
548
|
await sendViaDirectApns(tokensByEnvironment, payload);
|
|
546
549
|
for (const entry of sealedDevices) {
|
|
547
|
-
await sendViaDirectApns(new Map([[entry.environment, [entry.deviceToken]]]), sealedPayloadFor(payload, entry.pushKey));
|
|
550
|
+
await sendViaDirectApns(new Map([[entry.environment, [entry.deviceToken]]]), sealedPayloadFor(payload, sealedContent, entry.pushKey));
|
|
548
551
|
}
|
|
549
552
|
};
|
|
550
553
|
|
|
551
554
|
// What the relay and the push service see for a device with a key: the
|
|
552
555
|
// generic scenario title and an empty body, with the real title and body
|
|
553
556
|
// sealed in `data.enc` for the phone to open.
|
|
554
|
-
const sealedPayloadFor = (payload, pushKey) => ({
|
|
557
|
+
const sealedPayloadFor = (payload, content, pushKey) => ({
|
|
555
558
|
...payload,
|
|
556
559
|
body: '',
|
|
557
560
|
data: {
|
|
558
561
|
...(payload?.data && typeof payload.data === 'object' ? payload.data : {}),
|
|
559
|
-
enc: sealPushContent(pushKey, { title:
|
|
562
|
+
enc: sealPushContent(pushKey, { title: content.title, body: content.body }),
|
|
560
563
|
},
|
|
561
564
|
});
|
|
562
565
|
|