@openchamber/web 1.24.0 → 1.24.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/cli.test.js +29 -6
- package/bin/lib/cli-http.js +5 -1
- package/bin/lib/commands-status.js +5 -0
- package/dist/assets/{CodeMirrorCommentWidgets-C9kV-n7r.js → CodeMirrorCommentWidgets-B_vBPQYm.js} +1 -1
- package/dist/assets/DiffView-Ce0oBXXQ.js +4 -0
- package/dist/assets/{FilesView-vjJx7VaM.js → FilesView-DtXueAWP.js} +6 -6
- package/dist/assets/GitView-k0hUF8KB.js +6 -0
- package/dist/assets/GuestAttachDialog-DIf2U85Z.js +1 -0
- package/dist/assets/{JsonTreeView-D_4G5X6-.js → JsonTreeView-4AnJ04Pw.js} +1 -1
- package/dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- package/dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- package/dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- package/dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- package/dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- package/dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- package/dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- package/dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- package/dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- package/dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- package/dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-CZnvNsCZ.woff2 +0 -0
- package/dist/assets/KaTeX_Math-BoldItalic-iY-2wyZ7.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-DA0__PXp.woff +0 -0
- package/dist/assets/KaTeX_Math-Italic-flOr_0UB.ttf +0 -0
- package/dist/assets/KaTeX_Math-Italic-t53AETM-.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-CFMepnvq.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-D1sUS0GD.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Bold-DbIhKOiC.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-C3H0VqGB.woff2 +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-DN2j7dab.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Italic-YYjJ1zSn.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-BNo7hRIc.ttf +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-CS6fqUqJ.woff +0 -0
- package/dist/assets/KaTeX_SansSerif-Regular-DDBCnlJ7.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-C5JkGWo-.ttf +0 -0
- package/dist/assets/KaTeX_Script-Regular-D3wIWfF6.woff2 +0 -0
- package/dist/assets/KaTeX_Script-Regular-D5yQViql.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-C195tn64.woff +0 -0
- package/dist/assets/KaTeX_Size1-Regular-Dbsnue_I.ttf +0 -0
- package/dist/assets/KaTeX_Size1-Regular-mCD8mA8B.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-B7gKUWhC.ttf +0 -0
- package/dist/assets/KaTeX_Size2-Regular-Dy4dx90m.woff2 +0 -0
- package/dist/assets/KaTeX_Size2-Regular-oD1tc_U0.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-CTq5MqoE.woff +0 -0
- package/dist/assets/KaTeX_Size3-Regular-DgpXs0kz.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-BF-4gkZK.woff +0 -0
- package/dist/assets/KaTeX_Size4-Regular-DWFBv043.ttf +0 -0
- package/dist/assets/KaTeX_Size4-Regular-Dl5lxZxV.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-C0xS9mPB.woff +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-CO6r4hn1.woff2 +0 -0
- package/dist/assets/KaTeX_Typewriter-Regular-D3Ib7_Hf.ttf +0 -0
- package/dist/assets/{LinearIssuesView-1uKhePfH.js → LinearIssuesView-z_9p2GuO.js} +1 -1
- package/dist/assets/{MarkdownImageGallery-Ix7N_2wp.js → MarkdownImageGallery-BC-BNN-s.js} +1 -1
- package/dist/assets/{MarkdownRendererImpl-Deel_y5S.js → MarkdownRendererImpl-DyaBTUbH.js} +6 -6
- package/dist/assets/{OnboardingScreen-ToIakxb_.js → OnboardingScreen-DKU_yTb6.js} +1 -1
- package/dist/assets/{PatchDiff-BjMgezr1.js → PatchDiff-DpGmHRnV.js} +1 -1
- package/dist/assets/PierreDiffViewer-CgLl_tp7.js +210 -0
- package/dist/assets/{PlanView-BGAzxDwD.js → PlanView-CrfB4qqY.js} +4 -4
- package/dist/assets/PluginPane-B5cn-jPy.js +3 -0
- package/dist/assets/SettingsView-DMKKwezx.js +29 -0
- package/dist/assets/SettingsWindow-DwbnVzOC.js +1 -0
- package/dist/assets/{SubmoduleDiffSummary--YFqK6Ih.js → SubmoduleDiffSummary-hkGcvs0E.js} +1 -1
- package/dist/assets/{ToolOutputDialog-DRWBvdaJ.js → ToolOutputDialog-DuoIOc0j.js} +6 -6
- package/dist/assets/{ToolPartDiffPreview-BxZJCU28.js → ToolPartDiffPreview-t1Bvq_2Y.js} +2 -2
- package/dist/assets/{VirtualizedFileDiff-DCXjBGRf.js → VirtualizedFileDiff-BK4aU5qJ.js} +1 -1
- package/dist/assets/{WalkthroughView-CfIPvWWa.js → WalkthroughView-Bk6TPNFw.js} +2 -2
- package/dist/assets/{appThemeRegistry-DDROzcUO.js → appThemeRegistry-DnOVbJjF.js} +1 -1
- package/dist/assets/commitAndPush-DLWNZkkY.js +1 -0
- package/dist/assets/{computeVirtualFileMetrics-DHgQIkUq.js → computeVirtualFileMetrics-BVTujWSX.js} +1 -1
- package/dist/assets/{de-CX_f-T5U.js → de-zEHaAIi3.js} +4 -4
- package/dist/assets/{es-BERmWNn_.js → es-CBDgEzgk.js} +4 -4
- package/dist/assets/{fr-BjYYE_-z.js → fr-DjiTptT_.js} +4 -4
- package/dist/assets/index-AgOdanig.css +1 -0
- package/dist/assets/index-B-2_X4DD.js +40 -0
- package/dist/assets/{index-WjufPkIV.js → index-CkA4p2IK.js} +1 -1
- package/dist/assets/{isDiffPlainText-D9faP70y.js → isDiffPlainText-D3yX_vx4.js} +1 -1
- package/dist/assets/{isFilePlainText-6qOcz5Ky.js → isFilePlainText-CZR9TcHV.js} +1 -1
- package/dist/assets/ja-CerMgj3r.js +16 -0
- package/dist/assets/{ko-Dty1aUod.js → ko-DHYDAze5.js} +4 -4
- package/dist/assets/main-BDka4W43.js +896 -0
- package/dist/assets/main-Dl7Dyge_.js +2 -0
- package/dist/assets/markdownCore-DFmr0rUR.js +5 -0
- package/dist/assets/miniChat-CLKQPPpO.js +2 -0
- package/dist/assets/mobile--giD2Q1L.js +2 -0
- package/dist/assets/{patchFileDiff-BvU6KOQC.js → patchFileDiff-DRh-AQvd.js} +1 -1
- package/dist/assets/{pl-CX-_ROkr.js → pl-BTB_93bq.js} +6 -6
- package/dist/assets/{pt-BR-DhRR1arx.js → pt-BR-BwA3oyCK.js} +4 -4
- package/dist/assets/renderElectronMiniChatApp-DmB7zpVK.js +2 -0
- package/dist/assets/renderMobileApp-pMfOuQfl.js +25 -0
- package/dist/assets/runtimeEndpointReset-Gqhmkm3U.js +25 -0
- package/dist/assets/{scheduledTasksApi-DW3xqMQ8.js → scheduledTasksApi-CeRAIUmW.js} +1 -1
- package/dist/assets/{shikiHighlight-DsxD9QEa.js → shikiHighlight-BfjuB3CD.js} +1 -1
- package/dist/assets/{textMateThemeFromAppTheme-Da7ed8qM.js → textMateThemeFromAppTheme-BP60t9SX.js} +1 -1
- package/dist/assets/tr-CcPsJoNM.js +7 -0
- package/dist/assets/{uk-CD21CXFV.js → uk-B68WibXi.js} +4 -4
- package/dist/assets/{useAppFontEffects-hfv2s6mZ.js → useAppFontEffects-DcdrFv2Z.js} +147 -147
- package/dist/assets/{useInlineCommentController-BmtfVbo8.js → useInlineCommentController-Cq4SUjsA.js} +2 -2
- package/dist/assets/useRootScrollLock-CSdR6Wnm.js +2 -0
- package/dist/assets/{vendor-codemirror-language-data-BPMJpOpT.js → vendor-codemirror-language-data-BFm1Ju2w.js} +2 -2
- package/dist/assets/vendor-katex-Cp579UoJ.css +1 -0
- package/dist/assets/{vendor-tanstack-react-virtual-g05Cx3z9.js → vendor-tanstack-react-virtual-ClYN8CzB.js} +1 -1
- package/dist/assets/{vendor-tanstack-virtual-core-Dubg10g5.js → vendor-tanstack-virtual-core-BewVQryB.js} +1 -1
- package/dist/assets/{vendor-zod-fZppILAM.js → vendor-zod-CgAdXWZO.js} +4 -4
- package/dist/assets/{web-components-U-hWbgJo.js → web-components-2vo9YsZc.js} +1 -1
- package/dist/assets/zh-CN-DbFHYXwP.js +16 -0
- package/dist/assets/{zh-TW-CRp5dJU2.js → zh-TW-DmXAwdty.js} +4 -4
- package/dist/index.html +6 -4
- package/dist/mini-chat.html +6 -4
- package/dist/mobile.html +6 -4
- package/package.json +6 -5
- package/server/index.js +29 -7
- package/server/lib/agent-tool/DOCUMENTATION.md +17 -4
- package/server/lib/agent-tool/runtime.js +62 -15
- package/server/lib/agent-tool/runtime.test.js +88 -2
- package/server/lib/changelog/update-notes.js +2 -1
- package/server/lib/changelog/update-notes.test.js +19 -0
- package/server/lib/event-stream/DOCUMENTATION.md +23 -0
- package/server/lib/event-stream/delta-coalescer.js +0 -0
- package/server/lib/event-stream/delta-coalescer.test.js +292 -0
- package/server/lib/event-stream/global-hub.js +53 -23
- package/server/lib/event-stream/global-hub.test.js +160 -0
- package/server/lib/event-stream/global-ws-bridge.js +1 -0
- package/server/lib/event-stream/index.js +4 -0
- package/server/lib/fs/DOCUMENTATION.md +2 -1
- package/server/lib/fs/routes.js +56 -4
- package/server/lib/fs/routes.test.js +116 -0
- package/server/lib/git/DOCUMENTATION.md +18 -5
- package/server/lib/git/routes.js +1 -1
- package/server/lib/git/serial-refresh.js +93 -0
- package/server/lib/git/serial-refresh.test.js +112 -0
- package/server/lib/git/service.js +325 -70
- package/server/lib/git/service.test.js +291 -0
- package/server/lib/github/pr-status.js +5 -5
- package/server/lib/github/pr-status.test.js +1 -1
- package/server/lib/github/routes.js +4 -4
- package/server/lib/guests/DOCUMENTATION.md +5 -3
- package/server/lib/guests/background.test.js +83 -0
- package/server/lib/guests/catalog.js +20 -9
- package/server/lib/guests/catalog.test.js +5 -5
- package/server/lib/guests/routes.js +2 -2
- package/server/lib/message-queue/DOCUMENTATION.md +10 -1
- package/server/lib/message-queue/runtime.js +21 -1
- package/server/lib/message-queue/runtime.test.js +52 -5
- package/server/lib/notifications/routes.js +5 -0
- package/server/lib/openchamber-sessions/routes.js +18 -18
- package/server/lib/openchamber-sessions/routes.test.js +49 -0
- package/server/lib/opencode/DOCUMENTATION.md +1 -1
- package/server/lib/opencode/bootstrap-runtime.js +1 -0
- package/server/lib/opencode/feature-routes-runtime.js +5 -0
- package/server/lib/opencode/session-runtime.js +68 -0
- package/server/lib/opencode/session-runtime.test.js +43 -0
- package/server/lib/opencode/settings-helpers.js +3 -0
- package/server/lib/opencode/settings-registry.json +8 -0
- package/server/lib/permission-auto-accept/DOCUMENTATION.md +8 -0
- package/server/lib/permission-auto-accept/runtime.js +13 -0
- package/server/lib/permission-auto-accept/runtime.test.js +37 -1
- package/server/lib/projects/project-config.js +2 -2
- package/server/lib/realtime-proxy-terminal.test.js +150 -0
- package/server/lib/realtime-proxy.js +2 -0
- package/server/lib/routing/DOCUMENTATION.md +83 -0
- package/server/lib/routing/defaults.js +98 -0
- package/server/lib/routing/feature-flag.js +11 -0
- package/server/lib/routing/history.js +34 -0
- package/server/lib/routing/jev.js +98 -0
- package/server/lib/routing/routes.http.test.js +100 -0
- package/server/lib/routing/routes.js +81 -0
- package/server/lib/routing/runtime.js +217 -0
- package/server/lib/routing/runtime.test.js +188 -0
- package/server/lib/routing/store.js +249 -0
- package/server/lib/routing/store.test.js +96 -0
- package/server/lib/scheduled-tasks/runtime.js +2 -2
- package/server/lib/scheduled-tasks/runtime.test.js +14 -0
- package/server/lib/security/request-security.js +9 -5
- package/server/lib/security/request-security.test.js +37 -0
- package/server/lib/small-model/DOCUMENTATION.md +14 -2
- package/server/lib/small-model/call.js +37 -6
- package/server/lib/small-model/call.test.js +182 -0
- package/server/lib/terminal/DOCUMENTATION.md +21 -2
- package/server/lib/terminal/runtime.js +10 -3
- package/server/lib/terminal/runtime.test.js +22 -0
- package/server/lib/terminal/shutdown.js +106 -0
- package/server/lib/terminal/shutdown.test.js +84 -0
- package/server/lib/tts/service.test.js +78 -0
- package/server/lib/ui-auth/DOCUMENTATION.md +8 -0
- package/server/lib/ui-auth/session-cookie.js +51 -0
- package/server/lib/ui-auth/session-cookie.test.js +46 -0
- package/server/lib/ui-auth/ui-auth.js +13 -9
- package/server/lib/ui-auth/ui-auth.test.js +56 -0
- package/dist/assets/DiffView-B7YkbY-u.js +0 -4
- package/dist/assets/DirtyBranchSwitchDialog-CU0A93Zx.js +0 -1
- package/dist/assets/GitView-BLhlMYEY.js +0 -6
- package/dist/assets/GuestAttachDialog-B-fwE8r3.js +0 -3
- package/dist/assets/PierreDiffViewer-53Ghfnlr.js +0 -161
- package/dist/assets/SettingsView-n2X-jfBB.js +0 -29
- package/dist/assets/SettingsWindow-Bi8LE9XI.js +0 -1
- package/dist/assets/index-DpzTz2UH.css +0 -1
- package/dist/assets/index-Dy8xgawx.js +0 -40
- package/dist/assets/ja-DxqeAk9N.js +0 -16
- package/dist/assets/main-BOYSXfYn.js +0 -896
- package/dist/assets/main-Bjcre_GE.js +0 -2
- package/dist/assets/markdownCore-DPrwM1rU.js +0 -5
- package/dist/assets/miniChat-Dz_bPgMc.js +0 -2
- package/dist/assets/mobile-BbZPBJrK.js +0 -2
- package/dist/assets/renderElectronMiniChatApp-uNEUkeAI.js +0 -2
- package/dist/assets/renderMobileApp-BK1kFlcJ.js +0 -25
- package/dist/assets/runtimeEndpointReset-BULHvOwb.js +0 -25
- package/dist/assets/tr-cIQtYBpg.js +0 -7
- package/dist/assets/useRootScrollLock-Cwc4kSl2.js +0 -1
- package/dist/assets/zh-CN-BWvlPHY-.js +0 -16
- /package/dist/assets/{vendor-katex-k3Ppq1Ha.js → vendor-katex-CHD9BdDO.js} +0 -0
|
@@ -8,6 +8,7 @@ import { loadSourceSections, parseSource, sourceKey } from '../walkthrough/sourc
|
|
|
8
8
|
import { registerGitRoutes } from './routes.js';
|
|
9
9
|
|
|
10
10
|
import {
|
|
11
|
+
unsupportedRepositoryRootReason,
|
|
11
12
|
checkoutBranch,
|
|
12
13
|
checkoutCommit,
|
|
13
14
|
cherryPick,
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
getCommitFiles,
|
|
22
23
|
getLog,
|
|
23
24
|
getStatus,
|
|
25
|
+
getTrackingBranch,
|
|
24
26
|
getWorktrees,
|
|
25
27
|
isGitRepository,
|
|
26
28
|
observeWorktreeTopology,
|
|
@@ -44,6 +46,7 @@ import {
|
|
|
44
46
|
validateWorktreeCreate,
|
|
45
47
|
parseBranchCreationSource,
|
|
46
48
|
getRangeFiles,
|
|
49
|
+
push,
|
|
47
50
|
} from './service.js';
|
|
48
51
|
|
|
49
52
|
// ---------------------------------------------------------------------------
|
|
@@ -129,6 +132,23 @@ async function createTempRepo() {
|
|
|
129
132
|
// resolveBaseRefForLog
|
|
130
133
|
// ---------------------------------------------------------------------------
|
|
131
134
|
|
|
135
|
+
describe('unsupportedRepositoryRootReason', () => {
|
|
136
|
+
it('rejects a repository rooted at a filesystem root or the home directory', () => {
|
|
137
|
+
const home = path.join(os.tmpdir(), 'unsupported-root-home');
|
|
138
|
+
expect(unsupportedRepositoryRootReason('/', home)).toBe('filesystem-root');
|
|
139
|
+
expect(unsupportedRepositoryRootReason(path.parse(process.cwd()).root, home)).toBe('filesystem-root');
|
|
140
|
+
expect(unsupportedRepositoryRootReason(home, home)).toBe('home');
|
|
141
|
+
expect(unsupportedRepositoryRootReason(`${home}${path.sep}`, home)).toBe('home');
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('accepts an ordinary project root, including one directly under home', () => {
|
|
145
|
+
const home = path.join(os.tmpdir(), 'unsupported-root-home');
|
|
146
|
+
expect(unsupportedRepositoryRootReason(path.join(home, 'project'), home)).toBeNull();
|
|
147
|
+
expect(unsupportedRepositoryRootReason(path.join(os.tmpdir(), 'repo'), home)).toBeNull();
|
|
148
|
+
expect(unsupportedRepositoryRootReason('', home)).toBeNull();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
|
|
132
152
|
describe('resolveBaseRefForLog', () => {
|
|
133
153
|
it('returns the local ref unchanged when it exists, even if origin also exists', async () => {
|
|
134
154
|
const checkRef = async (ref) => ref === 'main' || ref === 'refs/remotes/origin/main';
|
|
@@ -730,6 +750,142 @@ describe('getStatus', () => {
|
|
|
730
750
|
process.chdir(previousCwd);
|
|
731
751
|
}
|
|
732
752
|
});
|
|
753
|
+
|
|
754
|
+
it('scopes diff stats by staged and working instead of combining a partially staged file', async () => {
|
|
755
|
+
if (!canRunGit()) return;
|
|
756
|
+
|
|
757
|
+
const repo = createTempDir();
|
|
758
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
759
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
760
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
761
|
+
const file = 'test.txt';
|
|
762
|
+
const filePath = path.join(repo, file);
|
|
763
|
+
fs.writeFileSync(filePath, 'one\ntwo\nthree\n');
|
|
764
|
+
runGit(repo, ['add', file]);
|
|
765
|
+
runGit(repo, ['commit', '-m', 'initial']);
|
|
766
|
+
|
|
767
|
+
// Stage one new line, then keep editing without staging another.
|
|
768
|
+
fs.writeFileSync(filePath, 'one\ntwo\nthree\nstaged\n');
|
|
769
|
+
runGit(repo, ['add', file]);
|
|
770
|
+
fs.writeFileSync(filePath, 'one\ntwo\nthree\nstaged\nworking\n');
|
|
771
|
+
|
|
772
|
+
const status = await getStatus(repo);
|
|
773
|
+
|
|
774
|
+
expect(status.diffStats.staged[file]).toEqual({ insertions: 1, deletions: 0 });
|
|
775
|
+
expect(status.diffStats.working[file]).toEqual({ insertions: 1, deletions: 0 });
|
|
776
|
+
});
|
|
777
|
+
|
|
778
|
+
it('scopes untracked files to working stats and staged additions to staged stats', async () => {
|
|
779
|
+
if (!canRunGit()) return;
|
|
780
|
+
|
|
781
|
+
const repo = createTempDir();
|
|
782
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
783
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
784
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
785
|
+
fs.writeFileSync(path.join(repo, 'tracked.txt'), 'tracked\n');
|
|
786
|
+
runGit(repo, ['add', 'tracked.txt']);
|
|
787
|
+
runGit(repo, ['commit', '-m', 'initial']);
|
|
788
|
+
|
|
789
|
+
fs.writeFileSync(path.join(repo, 'untracked.txt'), 'a\nb\n');
|
|
790
|
+
fs.writeFileSync(path.join(repo, 'staged.txt'), 'c\nd\ne\n');
|
|
791
|
+
runGit(repo, ['add', 'staged.txt']);
|
|
792
|
+
|
|
793
|
+
const status = await getStatus(repo);
|
|
794
|
+
|
|
795
|
+
expect(status.diffStats.working['untracked.txt']).toEqual({ insertions: 2, deletions: 0 });
|
|
796
|
+
expect(status.diffStats.staged['staged.txt']).toEqual({ insertions: 3, deletions: 0 });
|
|
797
|
+
expect(status.diffStats.working['staged.txt']).toBeUndefined();
|
|
798
|
+
});
|
|
799
|
+
});
|
|
800
|
+
|
|
801
|
+
describe('push', () => {
|
|
802
|
+
it('publishes the current branch with an upstream and leaves other local branches alone', async () => {
|
|
803
|
+
if (!canRunGit()) return;
|
|
804
|
+
|
|
805
|
+
const remote = createTempDir();
|
|
806
|
+
const repo = createTempDir();
|
|
807
|
+
runGit(remote, ['init', '--bare']);
|
|
808
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
809
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
810
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
811
|
+
fs.writeFileSync(path.join(repo, 'README.md'), '# Test\n');
|
|
812
|
+
runGit(repo, ['add', 'README.md']);
|
|
813
|
+
runGit(repo, ['commit', '-m', 'Initial commit']);
|
|
814
|
+
runGit(repo, ['remote', 'add', 'fork', remote]);
|
|
815
|
+
runGit(repo, ['branch', 'unrelated']);
|
|
816
|
+
runGit(repo, ['checkout', '-b', 'feature']);
|
|
817
|
+
fs.writeFileSync(path.join(repo, 'feature.txt'), 'published\n');
|
|
818
|
+
runGit(repo, ['add', 'feature.txt']);
|
|
819
|
+
runGit(repo, ['commit', '-m', 'Add feature']);
|
|
820
|
+
|
|
821
|
+
const published = await push(repo, { remote: 'fork' });
|
|
822
|
+
expect(published.pushed).toEqual([{ local: 'refs/heads/feature', remote: 'fork' }]);
|
|
823
|
+
|
|
824
|
+
expect(runGit(repo, ['rev-parse', '--abbrev-ref', '--symbolic-full-name', '@{u}']).trim()).toBe('fork/feature');
|
|
825
|
+
expect(runGit(remote, ['rev-parse', 'refs/heads/feature']).trim()).toBe(runGit(repo, ['rev-parse', 'HEAD']).trim());
|
|
826
|
+
expect(() => runGit(remote, ['rev-parse', 'refs/heads/unrelated'])).toThrow();
|
|
827
|
+
expect(() => runGit(remote, ['rev-parse', 'refs/heads/main'])).toThrow();
|
|
828
|
+
|
|
829
|
+
expect((await push(repo)).pushed).toEqual([]);
|
|
830
|
+
fs.appendFileSync(path.join(repo, 'feature.txt'), 'next commit\n');
|
|
831
|
+
runGit(repo, ['commit', '-am', 'Update feature']);
|
|
832
|
+
expect((await push(repo)).pushed).toEqual([{ local: 'refs/heads/feature', remote: 'fork' }]);
|
|
833
|
+
expect(runGit(remote, ['rev-parse', 'feature']).trim()).toBe(runGit(repo, ['rev-parse', 'HEAD']).trim());
|
|
834
|
+
|
|
835
|
+
runGit(repo, ['reset', '--hard', 'HEAD~1']);
|
|
836
|
+
await expect(push(repo)).rejects.toThrow();
|
|
837
|
+
expect((await push(repo, { options: ['--force-with-lease'] })).pushed)
|
|
838
|
+
.toEqual([{ local: 'refs/heads/feature', remote: 'fork' }]);
|
|
839
|
+
expect(runGit(remote, ['rev-parse', 'feature']).trim()).toBe(runGit(repo, ['rev-parse', 'HEAD']).trim());
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
it.each(['remote.pushDefault', 'branch.next.pushRemote'])('preserves the %s destination independently of the fetch remote', async (key) => {
|
|
843
|
+
const { repository, remote: upstream } = createRepositoryWithRemote({ remoteName: 'upstream', defaultBranch: 'next' });
|
|
844
|
+
const fork = createTempDir();
|
|
845
|
+
runGit(fork, ['init', '--bare']);
|
|
846
|
+
runGit(repository, ['remote', 'add', 'fork', fork]);
|
|
847
|
+
runGit(repository, ['branch', '--set-upstream-to=upstream/next']);
|
|
848
|
+
if (key === 'branch.next.pushRemote') runGit(repository, ['config', 'remote.pushDefault', 'upstream']);
|
|
849
|
+
runGit(repository, ['config', key, 'fork']);
|
|
850
|
+
const upstreamHead = runGit(upstream, ['rev-parse', 'next']).trim();
|
|
851
|
+
fs.appendFileSync(path.join(repository, 'README.md'), 'fork change\n');
|
|
852
|
+
runGit(repository, ['commit', '-am', 'Change for fork']);
|
|
853
|
+
|
|
854
|
+
expect((await push(repository)).pushed).toEqual([{ local: 'refs/heads/next', remote: 'fork' }]);
|
|
855
|
+
expect(runGit(fork, ['rev-parse', 'next']).trim()).toBe(runGit(repository, ['rev-parse', 'HEAD']).trim());
|
|
856
|
+
expect(runGit(upstream, ['rev-parse', 'next']).trim()).toBe(upstreamHead);
|
|
857
|
+
expect(readBranchConfig(repository, 'next', 'remote')).toBe('upstream');
|
|
858
|
+
expect((await push(repository)).pushed).toEqual([]);
|
|
859
|
+
});
|
|
860
|
+
|
|
861
|
+
it.each(['remote.pushDefault', 'branch.next.pushRemote'])('uses %s for first publication without an upstream', async (key) => {
|
|
862
|
+
const { repository, remote: origin } = createRepositoryWithRemote();
|
|
863
|
+
const fork = createTempDir();
|
|
864
|
+
runGit(fork, ['init', '--bare']);
|
|
865
|
+
runGit(repository, ['remote', 'add', 'fork', fork]);
|
|
866
|
+
runGit(repository, ['config', key, 'fork']);
|
|
867
|
+
runGit(repository, ['config', 'push.autoSetupRemote', 'false']);
|
|
868
|
+
|
|
869
|
+
expect((await push(repository)).pushed).toEqual([{ local: 'refs/heads/next', remote: 'fork' }]);
|
|
870
|
+
expect(readBranchConfig(repository, 'next', 'remote')).toBe('fork');
|
|
871
|
+
expect(() => runGit(origin, ['rev-parse', 'refs/heads/next'])).toThrow();
|
|
872
|
+
});
|
|
873
|
+
|
|
874
|
+
it('lets an explicit push remote override configured destinations', async () => {
|
|
875
|
+
const { repository, remote: origin } = createRepositoryWithRemote({ defaultBranch: 'next' });
|
|
876
|
+
const fork = createTempDir();
|
|
877
|
+
runGit(fork, ['init', '--bare']);
|
|
878
|
+
runGit(repository, ['remote', 'add', 'fork', fork]);
|
|
879
|
+
runGit(repository, ['branch', '--set-upstream-to=origin/next']);
|
|
880
|
+
runGit(repository, ['config', 'branch.next.pushRemote', 'fork']);
|
|
881
|
+
fs.appendFileSync(path.join(repository, 'README.md'), 'origin change\n');
|
|
882
|
+
runGit(repository, ['commit', '-am', 'Change for origin']);
|
|
883
|
+
|
|
884
|
+
expect((await push(repository, { remote: 'origin' })).pushed)
|
|
885
|
+
.toEqual([{ local: 'refs/heads/next', remote: 'origin' }]);
|
|
886
|
+
expect(runGit(origin, ['rev-parse', 'next']).trim()).toBe(runGit(repository, ['rev-parse', 'HEAD']).trim());
|
|
887
|
+
expect(() => runGit(fork, ['rev-parse', 'next'])).toThrow();
|
|
888
|
+
});
|
|
733
889
|
});
|
|
734
890
|
|
|
735
891
|
// ---------------------------------------------------------------------------
|
|
@@ -2388,3 +2544,138 @@ describe.runIf(canRunGit())('getRangeFiles', () => {
|
|
|
2388
2544
|
expect(copyEntry.path).toBe('copied destination.md');
|
|
2389
2545
|
});
|
|
2390
2546
|
});
|
|
2547
|
+
|
|
2548
|
+
// ---------------------------------------------------------------------------
|
|
2549
|
+
// getTrackingBranch
|
|
2550
|
+
// ---------------------------------------------------------------------------
|
|
2551
|
+
|
|
2552
|
+
describe('getTrackingBranch', () => {
|
|
2553
|
+
const createCommittedRepo = () => {
|
|
2554
|
+
const repo = createTempDir();
|
|
2555
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
2556
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
2557
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
2558
|
+
runGit(repo, ['commit', '--allow-empty', '-m', 'Initial commit']);
|
|
2559
|
+
return repo;
|
|
2560
|
+
};
|
|
2561
|
+
|
|
2562
|
+
it('reports the same upstream name as status, including a gone upstream', async () => {
|
|
2563
|
+
if (!canRunGit()) return;
|
|
2564
|
+
|
|
2565
|
+
const repo = createCommittedRepo();
|
|
2566
|
+
await expect(getTrackingBranch(repo)).resolves.toBeNull();
|
|
2567
|
+
|
|
2568
|
+
runGit(repo, ['remote', 'add', 'origin', 'https://example.invalid/repo.git']);
|
|
2569
|
+
runGit(repo, ['config', 'branch.main.remote', 'origin']);
|
|
2570
|
+
runGit(repo, ['config', 'branch.main.merge', 'refs/heads/main']);
|
|
2571
|
+
await expect(getTrackingBranch(repo)).resolves.toBe('origin/main');
|
|
2572
|
+
expect((await getStatus(repo)).tracking).toBe('origin/main');
|
|
2573
|
+
|
|
2574
|
+
runGit(repo, ['update-ref', 'refs/remotes/origin/main', 'HEAD']);
|
|
2575
|
+
await expect(getTrackingBranch(repo)).resolves.toBe('origin/main');
|
|
2576
|
+
});
|
|
2577
|
+
|
|
2578
|
+
it('is null for a detached HEAD and outside a repository', async () => {
|
|
2579
|
+
if (!canRunGit()) return;
|
|
2580
|
+
|
|
2581
|
+
const repo = createCommittedRepo();
|
|
2582
|
+
runGit(repo, ['checkout', '--detach']);
|
|
2583
|
+
await expect(getTrackingBranch(repo)).resolves.toBeNull();
|
|
2584
|
+
await expect(getTrackingBranch(createTempDir())).resolves.toBeNull();
|
|
2585
|
+
});
|
|
2586
|
+
});
|
|
2587
|
+
|
|
2588
|
+
describe('getStatus concurrency', () => {
|
|
2589
|
+
it('answers overlapping reads of one repository and reflects changes made while a read ran', async () => {
|
|
2590
|
+
if (!canRunGit()) return;
|
|
2591
|
+
|
|
2592
|
+
const repo = createTempDir();
|
|
2593
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
2594
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
2595
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
2596
|
+
runGit(repo, ['commit', '--allow-empty', '-m', 'Initial commit']);
|
|
2597
|
+
|
|
2598
|
+
const first = getStatus(repo);
|
|
2599
|
+
fs.writeFileSync(path.join(repo, 'late.txt'), 'added after the first read was admitted\n');
|
|
2600
|
+
const second = getStatus(repo, { mode: 'light' });
|
|
2601
|
+
const third = getStatus(repo);
|
|
2602
|
+
|
|
2603
|
+
const [firstStatus, secondStatus, thirdStatus] = await Promise.all([first, second, third]);
|
|
2604
|
+
expect(firstStatus.current).toBe('main');
|
|
2605
|
+
expect(secondStatus.files.map((file) => file.path)).toContain('late.txt');
|
|
2606
|
+
expect(thirdStatus.files.map((file) => file.path)).toContain('late.txt');
|
|
2607
|
+
// The follow-up run served both later callers at the widest requested mode.
|
|
2608
|
+
expect(secondStatus.diffStats).toBeDefined();
|
|
2609
|
+
expect(thirdStatus.diffStats).toBeDefined();
|
|
2610
|
+
});
|
|
2611
|
+
});
|
|
2612
|
+
|
|
2613
|
+
describe('getStatus untracked directories', () => {
|
|
2614
|
+
const callDiffRoute = async (endpoint, query) => {
|
|
2615
|
+
const routes = new Map();
|
|
2616
|
+
registerGitRoutes({ get: (url, handler) => routes.set(url, handler), post() {}, put() {}, delete() {} });
|
|
2617
|
+
let status = 200;
|
|
2618
|
+
let body;
|
|
2619
|
+
await routes.get(`/api/git/${endpoint}`)({ query }, {
|
|
2620
|
+
status(value) { status = value; return this; },
|
|
2621
|
+
json(value) { body = value; },
|
|
2622
|
+
});
|
|
2623
|
+
return { status, body };
|
|
2624
|
+
};
|
|
2625
|
+
|
|
2626
|
+
const createCommittedRepo = () => {
|
|
2627
|
+
const repo = createTempDir();
|
|
2628
|
+
runGit(repo, ['init', '-b', 'main']);
|
|
2629
|
+
runGit(repo, ['config', 'user.email', 'test@example.com']);
|
|
2630
|
+
runGit(repo, ['config', 'user.name', 'Test User']);
|
|
2631
|
+
fs.writeFileSync(path.join(repo, 'README.md'), '# Test\n');
|
|
2632
|
+
runGit(repo, ['add', 'README.md']);
|
|
2633
|
+
runGit(repo, ['commit', '-m', 'Initial commit']);
|
|
2634
|
+
return repo;
|
|
2635
|
+
};
|
|
2636
|
+
|
|
2637
|
+
const writeFiles = (root, count) => {
|
|
2638
|
+
fs.mkdirSync(root, { recursive: true });
|
|
2639
|
+
for (let index = 0; index < count; index += 1) {
|
|
2640
|
+
fs.writeFileSync(path.join(root, `file-${String(index).padStart(5, '0')}.txt`), `${index}\n`);
|
|
2641
|
+
}
|
|
2642
|
+
};
|
|
2643
|
+
|
|
2644
|
+
it('lists the files of an ordinary new directory one by one', async () => {
|
|
2645
|
+
if (!canRunGit()) return;
|
|
2646
|
+
|
|
2647
|
+
const repo = createCommittedRepo();
|
|
2648
|
+
writeFiles(path.join(repo, 'feature', 'deep'), 3);
|
|
2649
|
+
fs.writeFileSync(path.join(repo, 'loose.txt'), 'loose\n');
|
|
2650
|
+
|
|
2651
|
+
const paths = (await getStatus(repo)).files.map((file) => file.path);
|
|
2652
|
+
expect(paths).toEqual([
|
|
2653
|
+
'feature/deep/file-00000.txt',
|
|
2654
|
+
'feature/deep/file-00001.txt',
|
|
2655
|
+
'feature/deep/file-00002.txt',
|
|
2656
|
+
'loose.txt',
|
|
2657
|
+
]);
|
|
2658
|
+
});
|
|
2659
|
+
|
|
2660
|
+
it('keeps a directory with more than a thousand new files as one entry the diff routes explain', async () => {
|
|
2661
|
+
if (!canRunGit()) return;
|
|
2662
|
+
|
|
2663
|
+
const repo = createCommittedRepo();
|
|
2664
|
+
writeFiles(path.join(repo, 'node_modules', 'pkg'), 1001);
|
|
2665
|
+
writeFiles(path.join(repo, 'small'), 2);
|
|
2666
|
+
|
|
2667
|
+
const status = await getStatus(repo);
|
|
2668
|
+
expect(status.files.map((file) => file.path)).toEqual([
|
|
2669
|
+
'node_modules/',
|
|
2670
|
+
'small/file-00000.txt',
|
|
2671
|
+
'small/file-00001.txt',
|
|
2672
|
+
]);
|
|
2673
|
+
expect(status.files[0]).toMatchObject({ index: '?', working_dir: '?' });
|
|
2674
|
+
|
|
2675
|
+
for (const endpoint of ['diff', 'file-diff']) {
|
|
2676
|
+
const { status: httpStatus, body } = await callDiffRoute(endpoint, { directory: repo, path: 'node_modules/' });
|
|
2677
|
+
expect(httpStatus).toBe(422);
|
|
2678
|
+
expect(body).toEqual({ code: 'untracked_directory', error: 'Path is a directory of untracked files: node_modules/' });
|
|
2679
|
+
}
|
|
2680
|
+
});
|
|
2681
|
+
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { stat } from 'node:fs/promises';
|
|
2
|
-
import { getRemotes,
|
|
2
|
+
import { getRemotes, getTrackingBranch } from '../git/index.js';
|
|
3
3
|
import { resolveGitHubRepoFromDirectory } from './repo/index.js';
|
|
4
4
|
import { noteIfGitHubRateLimit } from './rate-limit.js';
|
|
5
5
|
|
|
@@ -644,13 +644,13 @@ export async function resolveGitHubPrStatus({ octokit, directory, branch, remote
|
|
|
644
644
|
const normalizedBranch = normalizeText(branch);
|
|
645
645
|
const normalizedRemoteName = normalizeText(remoteName) || 'origin';
|
|
646
646
|
|
|
647
|
-
const [
|
|
648
|
-
|
|
647
|
+
const [tracking, remotes] = await Promise.all([
|
|
648
|
+
getTrackingBranch(directory).catch(() => null),
|
|
649
649
|
getRemotes(directory).catch(() => []),
|
|
650
650
|
]);
|
|
651
651
|
|
|
652
|
-
const trackingRemoteName = parseTrackingRemoteName(
|
|
653
|
-
const trackingBranchName = parseTrackingBranchName(
|
|
652
|
+
const trackingRemoteName = parseTrackingRemoteName(tracking);
|
|
653
|
+
const trackingBranchName = parseTrackingBranchName(tracking);
|
|
654
654
|
const branchCandidates = [];
|
|
655
655
|
pushUnique(branchCandidates, normalizedBranch);
|
|
656
656
|
pushUnique(branchCandidates, trackingBranchName);
|
|
@@ -781,14 +781,14 @@ export function registerGitHubRoutes(app) {
|
|
|
781
781
|
// Determine the source remote for the head branch
|
|
782
782
|
// Priority: 1) explicit headRemote, 2) tracking branch remote, 3) 'origin' if targeting non-origin
|
|
783
783
|
let sourceRemote = headRemote;
|
|
784
|
-
const {
|
|
784
|
+
const { getTrackingBranch, getRemotes } = await import('../git/index.js');
|
|
785
785
|
|
|
786
786
|
// If no explicit headRemote, check the branch's tracking info
|
|
787
787
|
if (!sourceRemote) {
|
|
788
|
-
const
|
|
789
|
-
if (
|
|
788
|
+
const tracking = await getTrackingBranch(directory).catch(() => null);
|
|
789
|
+
if (tracking) {
|
|
790
790
|
// tracking is like "gsxdsm/fix/multi-remote-branch-creation" or "origin/main"
|
|
791
|
-
const trackingRemote =
|
|
791
|
+
const trackingRemote = tracking.split('/')[0];
|
|
792
792
|
if (trackingRemote) {
|
|
793
793
|
sourceRemote = trackingRemote;
|
|
794
794
|
}
|
|
@@ -6,10 +6,10 @@ OpenChamber-owned install and static serve for iframe guests. This is not the Op
|
|
|
6
6
|
|
|
7
7
|
## Routes
|
|
8
8
|
|
|
9
|
-
- `POST /api/guests/:id/storage` accepts the SDK's `GuestStorageRequest` and returns `GuestStorageResult`. It requires an installed, enabled, fully approved guest with a panel entry, but no additional capability. The UI host supplies the frame's own identity. Guest-scoped asset tokens cannot call this route. Data lives beside `extensions.json` in `guest-storage/<id>.json`. Each key is 1 to 128 characters, each JSON value at most 64 KiB UTF-8, the whole namespace at most 2 MiB and 2,000 keys. `storage.js` owns serialized authorization/read/write/removal; writes are atomic and failures preserve prior bytes. `uninstallGuest` removes storage for every install source. Missing keys return `found: false`, including after removal; stored JSON null returns `found: true`.
|
|
9
|
+
- `POST /api/guests/:id/storage` accepts the SDK's `GuestStorageRequest` and returns `GuestStorageResult`. It requires an installed, enabled, fully approved guest with either a panel or background entry, but no additional capability. The UI host supplies the frame's own identity. Guest-scoped asset tokens cannot call this route. Data lives beside `extensions.json` in `guest-storage/<id>.json`. Each key is 1 to 128 characters, each JSON value at most 64 KiB UTF-8, the whole namespace at most 2 MiB and 2,000 keys. `storage.js` owns serialized authorization/read/write/removal; writes are atomic and failures preserve prior bytes. `uninstallGuest` removes storage for every install source. Missing keys return `found: false`, including after removal; stored JSON null returns `found: true`.
|
|
10
10
|
- `GET /api/guests` also exposes `pageEntry` and optional `pageTitle` for `contributes.page`. Full-screen page HTML and its built scripts pass the same install checks as attach HTML. No new serving/auth path is required.
|
|
11
11
|
|
|
12
|
-
- `GET /api/guests`
|
|
12
|
+
- `GET /api/guests` returns installed guests. `attach` is `"panel"` or `"dialog"` when declared, and `attachEntry` is the dialog's separate HTML. `version` is the package semver. `integration` is the public slice: name, description, `auth`, and settings; OAuth URLs and tokens stay on the server. `service` includes `runtime`, optional `permissions`, optional `socketBindings`, and `granted`. `capabilities` carries `{ requested, granted }`, derived through the SDK's `requestedGuestCapabilities`. `actions`, `commands`, `tools`, and `filesystem` retain their parsed declarations; UI owns menu placement, command collisions, and tool precedence. `entry` is the optional visible panel and `backgroundEntry` is independent on-demand execution HTML. Background-only extensions get no rail surface; tools-only extensions with neither entry mount no frame. A guest without every requested grant is inactive until approval. `enabled: false` pauses it. A failed listing is 500, never an empty list.
|
|
13
13
|
- `GET /api/guests/:id/oauth/status` — `{ connected, account, hasClient, settings, redirectUri }`. No secrets. Host Linear merges first-party Linear status. `redirectUri` is empty unless `auth` is `oauth`.
|
|
14
14
|
- `PUT /api/guests/:id/oauth/client` — client id and optional secret from the Integrations form. OAuth guests only.
|
|
15
15
|
- `PUT /api/guests/:id/token` — pasted API token. Token guests only. The host probes the declared account path. The token never goes to the iframe.
|
|
@@ -30,10 +30,12 @@ OpenChamber-owned install and static serve for iframe guests. This is not the Op
|
|
|
30
30
|
- `POST /api/guests/updates/check` — `{ force?: boolean }` → `{ updates: Record<guestId, { version }> }` for every git install whose origin now carries a newer `package.json` `version`. The check runs `git fetch --depth 1 origin <ref|HEAD>` inside the installed clone and reads `FETCH_HEAD:package.json` through the SDK manifest parser; the only signal is semver (`updates.js` `compareSemver`, prerelease below release), no commit hashes. Results sit in a memory cache per store file and guest id for `UPDATE_CHECK_TTL_MS` (one hour); `force` asks the network again. That cache is separate from the catalog cache, so a store write does not drop it. One guest's failed fetch never hides another's update. Folder and zip installs are never checked.
|
|
31
31
|
- `POST /api/guests/:id/update` — replace the installed git copy with a fresh clone of its stored origin. Answers `{ guest }` (the refreshed catalog row) or 400 `{ error }` with `not-git` (folder, zip, or no stored origin), `clone-failed`, `invalid-manifest` (also when the clone declares a different panel id), `missing-build`, `host-too-old` (body may include `required`), or `swap-failed`. Unknown id is 404. Grants, tokens, settings, and the paused flag are keyed by guest id and stay as they were; a version that asks for more capabilities shows up as needs-approval in the catalog and goes through the usual review dialog.
|
|
32
32
|
- `DELETE /api/guests/:id` — drops the store row, any service grant, and socket overrides; stops a running service. Path-install does not delete the user's folder. Zip and git copies under `{openchamberDataDir}/extensions/` are deleted. Unknown id is 404.
|
|
33
|
-
- `GET /api/guests/:id/{*filePath}`
|
|
33
|
+
- `GET /api/guests/:id/{*filePath}` serves package-local files. Unknown IDs, escapes, missing files, and unknown types return 404. HTML and JS require either `entry` or `backgroundEntry`, expressed by `resolveGuestServedFile`'s `hasRuntime` option. Tools-only extensions still serve their SVG icons but no executable content. Guest HTML propagates the scoped `oc_url_token` onto relative script/link/image URLs. The token is minted for `guest:<id>` and works only under that guest's asset route, never `/api/fs/raw` or event streams. Every response carries `Content-Security-Policy: sandbox allow-scripts`, including direct document navigation. The host serves built files from disk and never compiles guest sources.
|
|
34
34
|
|
|
35
35
|
## Install
|
|
36
36
|
|
|
37
|
+
`contributes.background.entry` is optional package-local `.html`, separate from `panel.entry`. Install validates its HTML and every referenced built script using the same path confinement as visible panels. `backgroundEntry` is exposed on the catalog independently of `entry`; adding it does not create a rail icon or a visible page. Capabilities, services, integrations, and storage work with either execution entry. The SDK refuses visible contributions without `panel.entry` and all runtime contributions when neither entry exists. See `packages/sdk/DOCUMENTATION.md` for on-demand invocation ownership.
|
|
38
|
+
|
|
37
39
|
`html-styles.js` appends the SDK's shared scrollbar stylesheet to served HTML, including requests without an asset token. This applies to existing panel, page, and attach bundles in direct and relay mode; the relay loader retains the inline style in `srcDoc`. Appending preserves the doctype and avoids rewriting tag-like text inside scripts or comments. Authored CSP stays intact and can block inline styling. Package files on disk and non-HTML responses are unchanged. Scrollbar colors follow the SDK theme variables inside the frame.
|
|
38
40
|
|
|
39
41
|
Built-ins ship with the app; user extensions are installed separately. Add a folder, local ZIP, HTTPS Git/ZIP URL, or SSH Git address from Settings → Extensions. The ZIP picker and drop zone upload the archive on web and remote desktop instances. A guest with a page must ship built classic-IIFE JavaScript, for example from `bunx openchamber-guest-bundle panel/main.ts panel/main.js`; the sandbox does not support ESM imports. `package.json` needs a semver version. A missing panel SVG or invalid manifest fails installation; page-less tools-only packages skip HTML/script checks. Optional `engines.openchamber` is checked against this host. Provider accounts are connected separately in Settings → Integrations.
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { afterEach, expect, test } from 'bun:test';
|
|
2
|
+
import fs from 'node:fs/promises';
|
|
3
|
+
import os from 'node:os';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
import express from 'express';
|
|
6
|
+
import request from 'supertest';
|
|
7
|
+
import { inspectGuestPackage, toPublicGuest } from './catalog.js';
|
|
8
|
+
import { registerGuestRoutes } from './routes.js';
|
|
9
|
+
|
|
10
|
+
const roots = [];
|
|
11
|
+
afterEach(async () => { await Promise.all(roots.splice(0).map((root) => fs.rm(root, { recursive: true, force: true }))); });
|
|
12
|
+
const fixture = async () => {
|
|
13
|
+
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'oc-background-')); roots.push(root);
|
|
14
|
+
const packageRoot = path.join(root, 'package');
|
|
15
|
+
await fs.mkdir(packageRoot);
|
|
16
|
+
await fs.writeFile(path.join(packageRoot, 'package.json'), JSON.stringify({ name: 'background-test', version: '1.0.0', openchamber: {
|
|
17
|
+
apiVersion: 1, contributes: {
|
|
18
|
+
panel: { id: 'background-test', name: 'Background Test', icon: 'apps' },
|
|
19
|
+
background: { entry: 'index.html' },
|
|
20
|
+
capabilities: ['files'], commands: [{ name: 'test-background' }],
|
|
21
|
+
actions: [{ id: 'count', label: 'Count', where: 'message', mode: 'background' }],
|
|
22
|
+
},
|
|
23
|
+
} }));
|
|
24
|
+
return { root, packageRoot };
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
test('background-only packages validate HTML and built scripts and expose a separate catalog entry', async () => {
|
|
28
|
+
const { packageRoot } = await fixture();
|
|
29
|
+
expect(await inspectGuestPackage(packageRoot)).toMatchObject({ ok: false, code: 'invalid-manifest' });
|
|
30
|
+
await fs.writeFile(path.join(packageRoot, 'index.html'), '<script src="main.js"></script>');
|
|
31
|
+
await fs.writeFile(path.join(packageRoot, 'main.ts'), 'export {};');
|
|
32
|
+
expect(await inspectGuestPackage(packageRoot)).toMatchObject({ ok: false, code: 'missing-build' });
|
|
33
|
+
await fs.writeFile(path.join(packageRoot, 'main.js'), 'void 0;');
|
|
34
|
+
const result = await inspectGuestPackage(packageRoot);
|
|
35
|
+
expect(result.ok).toBe(true);
|
|
36
|
+
if (!result.ok) throw new Error(result.code);
|
|
37
|
+
const row = toPublicGuest(result.guest);
|
|
38
|
+
expect(row.entry).toBeUndefined();
|
|
39
|
+
expect(row.backgroundEntry).toBe('index.html');
|
|
40
|
+
expect(row.attach).toBeUndefined();
|
|
41
|
+
expect(row.actions).toHaveLength(1);
|
|
42
|
+
expect(row.commands).toHaveLength(1);
|
|
43
|
+
expect(row.capabilities).toEqual({ requested: ['files'], granted: [] });
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test('background entry and its scripts cannot escape the installed package through symlinks', async () => {
|
|
47
|
+
const { root, packageRoot } = await fixture();
|
|
48
|
+
const outside = path.join(root, 'outside.html');
|
|
49
|
+
await fs.writeFile(outside, '<p>Outside</p>');
|
|
50
|
+
await fs.symlink(outside, path.join(packageRoot, 'index.html'));
|
|
51
|
+
expect(await inspectGuestPackage(packageRoot)).toMatchObject({ ok: false, code: 'invalid-manifest' });
|
|
52
|
+
await fs.unlink(path.join(packageRoot, 'index.html'));
|
|
53
|
+
await fs.writeFile(path.join(packageRoot, 'index.html'), '<script src="main.js"></script>');
|
|
54
|
+
await fs.writeFile(path.join(root, 'outside.js'), 'void 0;');
|
|
55
|
+
await fs.symlink(path.join(root, 'outside.js'), path.join(packageRoot, 'main.js'));
|
|
56
|
+
expect(await inspectGuestPackage(packageRoot)).toMatchObject({ ok: false, code: 'missing-build' });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('background install serves sandboxed assets and storage obeys approval and enabled state', async () => {
|
|
60
|
+
const { root, packageRoot } = await fixture();
|
|
61
|
+
await fs.writeFile(path.join(packageRoot, 'index.html'), '<script src="main.js"></script>');
|
|
62
|
+
await fs.writeFile(path.join(packageRoot, 'main.js'), 'void 0;');
|
|
63
|
+
const app = express(); registerGuestRoutes(app, { openchamberDataDir: root, resolveGitBinaryForSpawn: () => 'git' });
|
|
64
|
+
const installed = await request(app).post('/api/guests').send({ path: packageRoot }).expect(201);
|
|
65
|
+
expect(installed.body.guest.backgroundEntry).toBe('index.html');
|
|
66
|
+
expect(installed.body.guest.entry).toBeUndefined();
|
|
67
|
+
const catalog = await request(app).get('/api/guests').expect(200);
|
|
68
|
+
expect(catalog.body.guests[0].backgroundEntry).toBe('index.html');
|
|
69
|
+
const html = await request(app).get('/api/guests/background-test/index.html?oc_url_token=test-scope').expect(200);
|
|
70
|
+
expect(html.headers['content-security-policy']).toBe('sandbox allow-scripts');
|
|
71
|
+
expect(html.text).toContain('main.js?oc_url_token=test-scope');
|
|
72
|
+
expect((await request(app).get('/api/guests/background-test/main.js').expect(200)).text).toBe('void 0;');
|
|
73
|
+
await request(app).post('/api/guests/background-test/storage').send({ op: 'set', key: 'count', value: 1 }).expect(400);
|
|
74
|
+
await request(app).put('/api/guests/background-test/capabilities').send({ granted: ['files'] }).expect(200);
|
|
75
|
+
await request(app).post('/api/guests/background-test/storage').send({ op: 'set', key: 'count', value: 1 }).expect(200);
|
|
76
|
+
expect((await request(app).post('/api/guests/background-test/storage').send({ op: 'get', key: 'count' }).expect(200)).body).toMatchObject({ found: true, value: 1 });
|
|
77
|
+
await request(app).put('/api/guests/background-test/enabled').send({ enabled: false }).expect(200);
|
|
78
|
+
await request(app).post('/api/guests/background-test/storage').send({ op: 'set', key: 'count', value: 2 }).expect(400);
|
|
79
|
+
await request(app).put('/api/guests/background-test/enabled').send({ enabled: true }).expect(200);
|
|
80
|
+
expect((await request(app).post('/api/guests/background-test/storage').send({ op: 'get', key: 'count' }).expect(200)).body).toMatchObject({ value: 1 });
|
|
81
|
+
await request(app).put('/api/guests/background-test/capabilities').send({ granted: [] }).expect(200);
|
|
82
|
+
await request(app).post('/api/guests/background-test/storage').send({ op: 'get', key: 'count' }).expect(400);
|
|
83
|
+
});
|
|
@@ -74,27 +74,26 @@ export const guestAssetContentType = (filePath) => {
|
|
|
74
74
|
return MIME_BY_EXT[path.extname(filePath).toLowerCase()] ?? null;
|
|
75
75
|
};
|
|
76
76
|
|
|
77
|
-
/**
|
|
77
|
+
/** Documents and scripts are served only to extensions with an execution entry. */
|
|
78
78
|
const isGuestFrameContentType = (contentType) => (
|
|
79
79
|
contentType.startsWith('text/html') || contentType.startsWith('text/javascript')
|
|
80
80
|
);
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
83
|
* A `.js` URL can be served from a sibling `.ts` that the host compiles.
|
|
84
|
-
* `
|
|
85
|
-
*
|
|
86
|
-
* page-less package can end up mounted in a frame.
|
|
84
|
+
* `hasRuntime` means the guest declared panel.entry or background.entry.
|
|
85
|
+
* Tools-only packages can serve assets, never HTML or JS.
|
|
87
86
|
*/
|
|
88
|
-
export const resolveGuestServedFile = async (packageRoot, relativePath, {
|
|
87
|
+
export const resolveGuestServedFile = async (packageRoot, relativePath, { hasRuntime = true } = {}) => {
|
|
89
88
|
const filePath = await resolveGuestAssetPath(packageRoot, relativePath);
|
|
90
89
|
const contentType = filePath ? guestAssetContentType(filePath) : null;
|
|
91
|
-
if (contentType && !
|
|
90
|
+
if (contentType && !hasRuntime && isGuestFrameContentType(contentType)) {
|
|
92
91
|
return null;
|
|
93
92
|
}
|
|
94
93
|
if (filePath && contentType) {
|
|
95
94
|
return { filePath, contentType };
|
|
96
95
|
}
|
|
97
|
-
if (!
|
|
96
|
+
if (!hasRuntime || !relativePath.endsWith('.js')) {
|
|
98
97
|
return null;
|
|
99
98
|
}
|
|
100
99
|
const tsPath = await resolveGuestAssetPath(packageRoot, `${relativePath.slice(0, -3)}.ts`);
|
|
@@ -173,8 +172,7 @@ export const inspectGuestPackage = async (packageRoot, { openchamberVersion, ski
|
|
|
173
172
|
}
|
|
174
173
|
}
|
|
175
174
|
const panel = parsed.manifest.contributes.panel;
|
|
176
|
-
//
|
|
177
|
-
// refused every contribution that would need a frame.
|
|
175
|
+
// The visible panel and background runtime are optional independent entries.
|
|
178
176
|
if (hasGuestPage(parsed.manifest.contributes)) {
|
|
179
177
|
const entryPath = await resolveGuestAssetPath(packageRoot, panel.entry);
|
|
180
178
|
if (!entryPath) {
|
|
@@ -199,6 +197,16 @@ export const inspectGuestPackage = async (packageRoot, { openchamberVersion, ski
|
|
|
199
197
|
if (panel.entry) {
|
|
200
198
|
guest.entry = panel.entry;
|
|
201
199
|
}
|
|
200
|
+
const backgroundEntry = parsed.manifest.contributes.background?.entry;
|
|
201
|
+
if (backgroundEntry) {
|
|
202
|
+
if (!await resolveGuestAssetPath(packageRoot, backgroundEntry)) {
|
|
203
|
+
return { ok: false, code: 'invalid-manifest' };
|
|
204
|
+
}
|
|
205
|
+
if (!await guestBuiltScriptsReady(packageRoot, backgroundEntry)) {
|
|
206
|
+
return { ok: false, code: 'missing-build' };
|
|
207
|
+
}
|
|
208
|
+
guest.backgroundEntry = backgroundEntry;
|
|
209
|
+
}
|
|
202
210
|
if (parsed.version) {
|
|
203
211
|
guest.version = parsed.version;
|
|
204
212
|
}
|
|
@@ -285,6 +293,9 @@ export const toPublicGuest = (guest) => {
|
|
|
285
293
|
if (guest.entry) {
|
|
286
294
|
row.entry = guest.entry;
|
|
287
295
|
}
|
|
296
|
+
if (guest.backgroundEntry) {
|
|
297
|
+
row.backgroundEntry = guest.backgroundEntry;
|
|
298
|
+
}
|
|
288
299
|
if (typeof guest.version === 'string' && guest.version) {
|
|
289
300
|
row.version = guest.version;
|
|
290
301
|
}
|
|
@@ -263,11 +263,11 @@ describe('page-less packages', () => {
|
|
|
263
263
|
expect(row).not.toHaveProperty('entry');
|
|
264
264
|
expect(row.tools).toEqual([{ match: 'mcp.*', icon: 'icons/tool.svg', output: 'json' }]);
|
|
265
265
|
|
|
266
|
-
const
|
|
267
|
-
expect((await resolveGuestServedFile(guestRoot, 'icons/tool.svg', {
|
|
268
|
-
expect(await resolveGuestServedFile(guestRoot, 'stray.html', {
|
|
269
|
-
expect(await resolveGuestServedFile(guestRoot, 'stray.js', {
|
|
270
|
-
expect((await resolveGuestServedFile(guestRoot, 'stray.html', {
|
|
266
|
+
const hasRuntime = false;
|
|
267
|
+
expect((await resolveGuestServedFile(guestRoot, 'icons/tool.svg', { hasRuntime }))?.contentType).toBe('image/svg+xml');
|
|
268
|
+
expect(await resolveGuestServedFile(guestRoot, 'stray.html', { hasRuntime })).toBeNull();
|
|
269
|
+
expect(await resolveGuestServedFile(guestRoot, 'stray.js', { hasRuntime })).toBeNull();
|
|
270
|
+
expect((await resolveGuestServedFile(guestRoot, 'stray.html', { hasRuntime: true }))?.contentType).toContain('html');
|
|
271
271
|
|
|
272
272
|
await fs.rm(dir, { recursive: true, force: true });
|
|
273
273
|
});
|
|
@@ -575,7 +575,7 @@ export const registerGuestRoutes = (app, {
|
|
|
575
575
|
try {
|
|
576
576
|
const result = await runGuestStorage(persistPath, req.params.id, parsed.data, async () => {
|
|
577
577
|
const guest = await loadGuest(req.params.id);
|
|
578
|
-
if (!guest || guest.enabled === false || !guest.entry) throw new Error('Extension is unavailable.');
|
|
578
|
+
if (!guest || guest.enabled === false || (!guest.entry && !guest.backgroundEntry)) throw new Error('Extension is unavailable.');
|
|
579
579
|
if (!requestedGuestCapabilities(guest).every((capability) => guest.capabilityGrants.includes(capability))) throw new Error('Extension needs approval.');
|
|
580
580
|
});
|
|
581
581
|
return res.json(result);
|
|
@@ -805,7 +805,7 @@ export const registerGuestRoutes = (app, {
|
|
|
805
805
|
return res.status(404).end();
|
|
806
806
|
}
|
|
807
807
|
const served = await resolveGuestServedFile(guest.packageRoot, relativePath, {
|
|
808
|
-
|
|
808
|
+
hasRuntime: Boolean(guest.entry || guest.backgroundEntry),
|
|
809
809
|
});
|
|
810
810
|
if (!served) {
|
|
811
811
|
return res.status(404).end();
|