@openchamber/web 1.22.1 → 1.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (205) hide show
  1. package/bin/cli.js +11 -1
  2. package/bin/cli.test.js +92 -0
  3. package/bin/lib/cli-startup.js +49 -0
  4. package/bin/lib/commands-startup.js +41 -6
  5. package/dist/assets/{CodeMirrorCommentWidgets-BO_2OW4E.js → CodeMirrorCommentWidgets-DbcnxAfY.js} +1 -1
  6. package/dist/assets/DiffView-Dp1tomqK.js +4 -0
  7. package/dist/assets/{DirtyBranchSwitchDialog-jADfXQnR.js → DirtyBranchSwitchDialog-DE2sKIYv.js} +1 -1
  8. package/dist/assets/FilesView-C_of2nIT.js +17 -0
  9. package/dist/assets/{GitView-Cv2xH-S6.js → GitView-CKgUkb5Z.js} +4 -4
  10. package/dist/assets/{JsonTreeView-DUiIpERC.js → JsonTreeView-Bce2ettZ.js} +1 -1
  11. package/dist/assets/{LinearIssuesView-CoZ7pQN5.js → LinearIssuesView-BZVWM2zw.js} +1 -1
  12. package/dist/assets/MarkdownImageGallery-DdROVz29.js +1 -0
  13. package/dist/assets/MarkdownRendererImpl-CenrzmMN.js +12 -0
  14. package/dist/assets/OnboardingScreen-DyqYG_NP.js +1 -0
  15. package/dist/assets/{PatchDiff-BymkP9JA.js → PatchDiff-CR3RVO5I.js} +1 -1
  16. package/dist/assets/PierreDiffViewer-KihzO94X.js +161 -0
  17. package/dist/assets/PlanView-jcQAfr2A.js +5 -0
  18. package/dist/assets/SettingsView-Buvom5A2.js +28 -0
  19. package/dist/assets/{SettingsWindow-COzgfFxM.js → SettingsWindow-CV_hzB5v.js} +1 -1
  20. package/dist/assets/SymbolsNerdFontMono-Regular-aK5vsLov.woff2 +0 -0
  21. package/dist/assets/{ToolOutputDialog-Dlhh_-oe.js → ToolOutputDialog-llKecK_Z.js} +6 -6
  22. package/dist/assets/{ToolPartDiffPreview-b9joNtXH.js → ToolPartDiffPreview-ZDMTdCGn.js} +2 -2
  23. package/dist/assets/{VirtualizedFileDiff-vqW3KKo5.js → VirtualizedFileDiff-ClvqQ4j0.js} +1 -1
  24. package/dist/assets/WalkthroughView-BgpSnSlU.js +4 -0
  25. package/dist/assets/{computeVirtualFileMetrics-DUnyszhW.js → computeVirtualFileMetrics-Nm5_wabb.js} +2 -2
  26. package/dist/assets/contextPanelEmbeddedChat-CirXEPJq.js +1 -0
  27. package/dist/assets/de-DTQDjaiv.js +10 -0
  28. package/dist/assets/es-SOCFd_r-.js +16 -0
  29. package/dist/assets/fr-CP6jqIzw.js +14 -0
  30. package/dist/assets/ghostty-vt-DdA0Zryv.wasm +0 -0
  31. package/dist/assets/index-B68h5S5B.css +1 -0
  32. package/dist/assets/index-CRf2xk51.js +39 -0
  33. package/dist/assets/{index-DLiD86ge.js → index-Du9sZhDb.js} +1 -1
  34. package/dist/assets/{isDiffPlainText-TNageFjy.js → isDiffPlainText-EQERIius.js} +1 -1
  35. package/dist/assets/{isFilePlainText-JPmZOYSp.js → isFilePlainText-BCoVpkQy.js} +1 -1
  36. package/dist/assets/ja-BKfafwsD.js +16 -0
  37. package/dist/assets/ko-BA5xgCYp.js +16 -0
  38. package/dist/assets/main-BNiPEont.js +930 -0
  39. package/dist/assets/{main-DCB4JgVe.js → main-DPf32fO6.js} +2 -2
  40. package/dist/assets/markdownCore-CQ7CAuuV.js +5 -0
  41. package/dist/assets/{miniChat-BtV7N5OF.js → miniChat-CHqVTsgj.js} +2 -2
  42. package/dist/assets/{mobile-DZV_sfX7.js → mobile-BQmgHA57.js} +2 -2
  43. package/dist/assets/patchFileDiff-C4X_trug.js +13 -0
  44. package/dist/assets/pl-B215pG1Y.js +16 -0
  45. package/dist/assets/pt-BR-Bo2pnlEa.js +16 -0
  46. package/dist/assets/renderElectronMiniChatApp-BUcHPOXW.js +2 -0
  47. package/dist/assets/renderMobileApp-BvTmuRE-.js +25 -0
  48. package/dist/assets/runtimeEndpointReset-C8GAA2kS.js +17 -0
  49. package/dist/assets/scheduledTasksApi-BAScWwt3.js +1 -0
  50. package/dist/assets/{shikiHighlight-CRpCl7UT.js → shikiHighlight-BTObuQCR.js} +1 -1
  51. package/dist/assets/surface-BvRzS58U.js +1 -0
  52. package/dist/assets/tr-CUaxHc8X.js +7 -0
  53. package/dist/assets/uk-YTJgyqAZ.js +16 -0
  54. package/dist/assets/{useAppFontEffects-CCgvcQ6u.js → useAppFontEffects-theH_IJL.js} +143 -137
  55. package/dist/assets/useGitComparison-B94I6kOI.js +1 -0
  56. package/dist/assets/useInlineCommentController-Bs3PgeA8.js +2 -0
  57. package/dist/assets/useRootScrollLock-hSYwnxZs.js +1 -0
  58. package/dist/assets/{vendor-base-ui-BeMD8X_w.js → vendor-base-ui-DdV8vhHn.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-language-data-BxpoC5Fp.js → vendor-codemirror-language-data-Cxgr01md.js} +2 -2
  60. package/dist/assets/vendor-legendapp-list-BuBPBC3R.js +1 -0
  61. package/dist/assets/vendor-zod-BPAANqvH.js +39 -0
  62. package/dist/assets/{web-components-B6QgbmTo.js → web-components-CaS0ksnZ.js} +1 -1
  63. package/dist/assets/zh-CN-CZ2BxZS6.js +16 -0
  64. package/dist/assets/zh-TW-BsUrPdXz.js +16 -0
  65. package/dist/index.html +5 -43
  66. package/dist/mini-chat.html +4 -4
  67. package/dist/mobile.html +4 -4
  68. package/package.json +3 -4
  69. package/server/index.d.ts +15 -0
  70. package/server/index.js +52 -10
  71. package/server/lib/changelog/update-notes.js +82 -0
  72. package/server/lib/changelog/update-notes.test.js +59 -0
  73. package/server/lib/data-dir-migration.js +40 -0
  74. package/server/lib/data-dir-migration.test.js +59 -0
  75. package/server/lib/event-stream/runtime.test.js +12 -12
  76. package/server/lib/fs/DOCUMENTATION.md +5 -0
  77. package/server/lib/fs/routes.js +63 -21
  78. package/server/lib/fs/routes.test.js +187 -1
  79. package/server/lib/git/DOCUMENTATION.md +29 -5
  80. package/server/lib/git/routes.js +24 -4
  81. package/server/lib/git/service.js +194 -198
  82. package/server/lib/git/service.test.js +440 -25
  83. package/server/lib/inherited-env.js +16 -9
  84. package/server/lib/inherited-env.test.js +8 -9
  85. package/server/lib/message-queue/DOCUMENTATION.md +20 -7
  86. package/server/lib/message-queue/runtime.js +59 -7
  87. package/server/lib/message-queue/runtime.test.js +59 -3
  88. package/server/lib/network-defaults.js +23 -0
  89. package/server/lib/network-defaults.test.js +52 -0
  90. package/server/lib/opencode/DOCUMENTATION.md +25 -5
  91. package/server/lib/opencode/bootstrap-runtime.js +2 -0
  92. package/server/lib/opencode/config-paths.test.js +116 -0
  93. package/server/lib/opencode/feature-routes-runtime.js +4 -0
  94. package/server/lib/opencode/input-history-scope.js +14 -0
  95. package/server/lib/opencode/openchamber-routes.js +64 -4
  96. package/server/lib/opencode/openchamber-routes.test.js +128 -1
  97. package/server/lib/opencode/plugins.js +2 -2
  98. package/server/lib/opencode/providers.js +44 -2
  99. package/server/lib/opencode/providers.test.js +131 -4
  100. package/server/lib/opencode/routes.js +9 -7
  101. package/server/lib/opencode/server-startup-runtime.js +1 -1
  102. package/server/lib/opencode/settings-files.js +214 -0
  103. package/server/lib/opencode/settings-helpers.js +113 -41
  104. package/server/lib/opencode/settings-helpers.test.js +342 -0
  105. package/server/lib/opencode/settings-registry.json +747 -0
  106. package/server/lib/opencode/settings-runtime.js +139 -18
  107. package/server/lib/opencode/settings-runtime.test.js +163 -5
  108. package/server/lib/opencode/shared.js +4 -1
  109. package/server/lib/opencode/skill-routes.js +2 -1
  110. package/server/lib/opencode/snippets.js +1 -2
  111. package/server/lib/package-manager.js +3 -28
  112. package/server/lib/project-context/DOCUMENTATION.md +25 -1
  113. package/server/lib/project-context/routes.http.test.js +18 -0
  114. package/server/lib/project-context/routes.js +15 -0
  115. package/server/lib/project-context/runtime.js +248 -23
  116. package/server/lib/project-context/runtime.test.js +106 -3
  117. package/server/lib/projects/DOCUMENTATION.md +76 -0
  118. package/server/lib/projects/project-config.js +142 -9
  119. package/server/lib/projects/project-id.js +17 -0
  120. package/server/lib/projects/project-setup.js +409 -0
  121. package/server/lib/projects/project-setup.test.js +557 -0
  122. package/server/lib/projects/routes.js +59 -0
  123. package/server/lib/quota/DOCUMENTATION.md +38 -1
  124. package/server/lib/quota/index.js +1 -0
  125. package/server/lib/quota/providers/cline-pass.js +125 -0
  126. package/server/lib/quota/providers/cline-pass.test.js +103 -0
  127. package/server/lib/quota/providers/hyper.js +118 -0
  128. package/server/lib/quota/providers/hyper.test.js +126 -0
  129. package/server/lib/quota/providers/index.js +15 -0
  130. package/server/lib/quota/providers/neuralwatt.js +3 -6
  131. package/server/lib/quota/providers/neuralwatt.test.js +7 -7
  132. package/server/lib/quota/providers/ollama-cloud.js +31 -0
  133. package/server/lib/quota/providers/ollama-cloud.test.js +33 -1
  134. package/server/lib/quota/providers/opencode-go.js +1 -1
  135. package/server/lib/quota/providers/opencode-go.test.js +26 -1
  136. package/server/lib/quota/providers/openrouter.js +119 -24
  137. package/server/lib/quota/providers/openrouter.test.js +330 -0
  138. package/server/lib/quota/utils/auth.js +1 -1
  139. package/server/lib/relay/DOCUMENTATION.md +55 -0
  140. package/server/lib/relay/cross-compat.test.js +26 -0
  141. package/server/lib/relay/downstream-scheduler.js +154 -0
  142. package/server/lib/relay/downstream-scheduler.test.js +162 -0
  143. package/server/lib/relay/e2ee.js +10 -8
  144. package/server/lib/relay/flow-control.test.js +177 -0
  145. package/server/lib/relay/host-client.js +37 -8
  146. package/server/lib/relay/host-client.test.js +9 -1
  147. package/server/lib/relay/tunnel-codec.js +9 -0
  148. package/server/lib/relay/tunnel-host.js +66 -17
  149. package/server/lib/session-assist/runtime.js +6 -10
  150. package/server/lib/session-goal/DOCUMENTATION.md +20 -7
  151. package/server/lib/session-goal/runtime.js +80 -20
  152. package/server/lib/session-goal/runtime.test.js +426 -0
  153. package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
  154. package/server/lib/skills-catalog/install.js +3 -2
  155. package/server/lib/small-model/DOCUMENTATION.md +3 -2
  156. package/server/lib/small-model/call.js +9 -4
  157. package/server/lib/small-model/call.test.js +29 -0
  158. package/server/lib/small-model/index.js +5 -10
  159. package/server/lib/small-model/runtime-providers.js +15 -7
  160. package/server/lib/small-model/runtime-providers.test.js +7 -1
  161. package/server/lib/terminal/DOCUMENTATION.md +14 -10
  162. package/server/lib/terminal/runtime.js +160 -24
  163. package/server/lib/terminal/runtime.test.js +571 -37
  164. package/server/lib/terminal/shells.js +17 -0
  165. package/server/lib/terminal/shells.test.js +32 -1
  166. package/server/lib/walkthrough/DOCUMENTATION.md +33 -14
  167. package/server/lib/walkthrough/model-settings.js +8 -12
  168. package/server/lib/walkthrough/prompt.js +3 -1
  169. package/server/lib/walkthrough/routes.test.js +26 -5
  170. package/server/lib/walkthrough/sources.js +23 -2
  171. package/dist/assets/DiffView-CNnDxRmO.js +0 -4
  172. package/dist/assets/FilesView-8wdiG2mj.js +0 -17
  173. package/dist/assets/MarkdownImageGallery-DffjmciG.js +0 -1
  174. package/dist/assets/MarkdownRendererImpl-DxqdYDAx.js +0 -12
  175. package/dist/assets/OnboardingScreen-CTZe6HZn.js +0 -1
  176. package/dist/assets/PierreDiffViewer-BvwtCxW4.js +0 -157
  177. package/dist/assets/PlanView-C1qvAm7m.js +0 -5
  178. package/dist/assets/SettingsView-xGONHFGS.js +0 -28
  179. package/dist/assets/WalkthroughView-D-HFgdmM.js +0 -4
  180. package/dist/assets/contextPanelEmbeddedChat-CV-DwAiX.js +0 -1
  181. package/dist/assets/de-Cv_4FoXm.js +0 -10
  182. package/dist/assets/es-BIWNEbnS.js +0 -16
  183. package/dist/assets/fr-SD3OfMHJ.js +0 -14
  184. package/dist/assets/index-CHUT_bDS.css +0 -1
  185. package/dist/assets/index-DDInLQDd.js +0 -40
  186. package/dist/assets/ja-D7I9HofF.js +0 -16
  187. package/dist/assets/ko-BsVJM_PQ.js +0 -16
  188. package/dist/assets/main-De8Z5w49.js +0 -928
  189. package/dist/assets/markdownCore-BoQVG5-a.js +0 -3
  190. package/dist/assets/patchFileDiff-Chmiz6hq.js +0 -10
  191. package/dist/assets/pl-XR9Bs8Be.js +0 -16
  192. package/dist/assets/pt-BR-Due4be8g.js +0 -16
  193. package/dist/assets/renderElectronMiniChatApp-8tXADjfl.js +0 -2
  194. package/dist/assets/renderMobileApp-Cji7Hma5.js +0 -25
  195. package/dist/assets/runtimeEndpointReset-gWt3Lb5D.js +0 -16
  196. package/dist/assets/scheduledTasksApi-9e-UX6im.js +0 -1
  197. package/dist/assets/tr-DBJcAv4y.js +0 -7
  198. package/dist/assets/uk-COYh2BaN.js +0 -16
  199. package/dist/assets/useInlineCommentController-BkfXnjNZ.js +0 -2
  200. package/dist/assets/useRootScrollLock-KzOUytpn.js +0 -1
  201. package/dist/assets/vendor-ghostty-web-CrxinGGH.js +0 -13
  202. package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +0 -1
  203. package/dist/assets/vendor-zod-DVWEh-IS.js +0 -39
  204. package/dist/assets/zh-CN-Cjk6lzhc.js +0 -16
  205. package/dist/assets/zh-TW-Dk0dOg03.js +0 -16
@@ -4,6 +4,8 @@ import os from 'node:os';
4
4
  import path from 'node:path';
5
5
  import { afterAll, afterEach, describe, expect, it, vi } from 'vitest';
6
6
  import simpleGit from 'simple-git';
7
+ import { loadSourceSections, parseSource, sourceKey } from '../walkthrough/sources.js';
8
+ import { registerGitRoutes } from './routes.js';
7
9
 
8
10
  import {
9
11
  checkoutBranch,
@@ -14,6 +16,10 @@ import {
14
16
  getBranches,
15
17
  getUnpushedBranchCounts,
16
18
  getRangeDiff,
19
+ getBranchBase,
20
+ getCommitDiff,
21
+ getCommitFiles,
22
+ getLog,
17
23
  getStatus,
18
24
  getWorktrees,
19
25
  isGitRepository,
@@ -29,6 +35,7 @@ import {
29
35
  unstageFiles,
30
36
  applyHunk,
31
37
  getDiff,
38
+ getUntrackedDiffs,
32
39
  getFileDiff,
33
40
  validateWorktreeCreate,
34
41
  parseBranchCreationSource,
@@ -183,28 +190,49 @@ describe.runIf(canRunGit())('setLocalIdentity', () => {
183
190
  "ssh -i '/tmp/test key' -o IdentitiesOnly=yes"
184
191
  );
185
192
  });
193
+
194
+ it('configures the stored credential helper for token auth with the targeted simple-git opt-in', async () => {
195
+ const { tmpDir } = await createTempRepo();
196
+
197
+ await setLocalIdentity(tmpDir, {
198
+ userName: 'Token User',
199
+ userEmail: 'token@example.com',
200
+ authType: 'token',
201
+ host: 'github.com',
202
+ });
203
+
204
+ expect(runGit(tmpDir, ['config', '--local', '--get', 'credential.helper']).trim()).toBe('store');
205
+ });
206
+
207
+ it('clears the stored credential helper when switching to SSH auth', async () => {
208
+ const { tmpDir } = await createTempRepo();
209
+
210
+ await setLocalIdentity(tmpDir, {
211
+ userName: 'Token User',
212
+ userEmail: 'token@example.com',
213
+ authType: 'token',
214
+ host: 'github.com',
215
+ });
216
+ await setLocalIdentity(tmpDir, {
217
+ userName: 'SSH User',
218
+ userEmail: 'ssh@example.com',
219
+ authType: 'ssh',
220
+ sshKey: '/tmp/test key',
221
+ });
222
+
223
+ expect(runGit(tmpDir, ['config', '--local', '--get', 'core.sshCommand']).trim()).toBe(
224
+ "ssh -i '/tmp/test key' -o IdentitiesOnly=yes"
225
+ );
226
+ expect(() => runGit(tmpDir, ['config', '--local', '--get', 'credential.helper'])).toThrow();
227
+ });
186
228
  });
187
229
 
188
230
  // ---------------------------------------------------------------------------
189
231
  // applyHunk (per-hunk stage / unstage / discard)
190
232
  // ---------------------------------------------------------------------------
191
233
 
192
- /** Minimal unified-diff splitter: returns standalone per-hunk patches. */
193
- const splitHunks = (patch) => {
194
- const lines = patch.split(/\r?\n/);
195
- const headerEnd = lines.findIndex((line) => /^@@\s/.test(line));
196
- if (headerEnd === -1) return [];
197
- const header = lines.slice(0, headerEnd);
198
- const hunks = [];
199
- for (let i = headerEnd; i < lines.length; i += 1) {
200
- const line = lines[i];
201
- if (/^@@\s/.test(line)) hunks.push([...header, line]);
202
- else if (hunks.length > 0) hunks[hunks.length - 1].push(line);
203
- }
204
- return hunks.map((hunk) => hunk.join('\n'))
205
- .filter((hunk) => hunk.trim().length > 0)
206
- .map((hunk) => (hunk.endsWith('\n') ? hunk : `${hunk}\n`));
207
- };
234
+ // Exercise the actual client splitter against the server apply boundary.
235
+ import { splitPatchIntoHunks as splitHunks } from '../../../../ui/src/lib/diff/patchFileDiff.ts';
208
236
 
209
237
  const writeFile = (repo, name, contents) =>
210
238
  fs.promises.writeFile(path.join(repo, name), contents, 'utf8');
@@ -220,6 +248,77 @@ const readWorking = (repo) => fs.promises.readFile(path.join(repo, 'file.txt'),
220
248
  const readStaged = async (git) => (await git.raw(['show', ':file.txt'])).replace(/\r\n/g, '\n');
221
249
 
222
250
  describe('applyHunk', () => {
251
+ it('stages successive hunks and never discards a stale staged or committed patch', async () => {
252
+ if (!canRunGit()) return;
253
+ const { tmpDir, git } = await createTempRepo();
254
+ const original = Array.from({ length: 60 }, (_, index) => `line${index}`);
255
+ const changed = [...original];
256
+ changed[1] = 'FIRST'; changed[25] = 'SECOND'; changed[50] = 'THIRD';
257
+ await writeFile(tmpDir, 'file.txt', original.join('\n') + '\n');
258
+ await git.add('file.txt'); await git.commit('Initial');
259
+ await writeFile(tmpDir, 'file.txt', changed.join('\n') + '\n');
260
+ const historical = splitHunks(await getDiff(tmpDir, { path: 'file.txt' }));
261
+ expect(historical).toHaveLength(3);
262
+ await applyHunk(tmpDir, 'file.txt', { patch: historical[0], action: 'stage' });
263
+ const remaining = splitHunks(await getDiff(tmpDir, { path: 'file.txt' }));
264
+ expect(remaining).toHaveLength(2);
265
+ await applyHunk(tmpDir, 'file.txt', { patch: remaining[0], action: 'stage' });
266
+ const stalePath = path.join(tmpDir, 'stale.patch');
267
+ await fs.promises.writeFile(stalePath, historical[0]);
268
+ // Git's reverse applicability check accepts it, but it is no longer an
269
+ // unstaged hunk. The server must reject it before touching the working file.
270
+ await git.raw(['apply', '--reverse', '--check', stalePath]);
271
+ await expect(applyHunk(tmpDir, 'file.txt', { patch: historical[0], action: 'discard' })).rejects.toThrow('refresh and try again');
272
+ expect(await readWorking(tmpDir)).toBe(changed.join('\n') + '\n');
273
+ const last = splitHunks(await getDiff(tmpDir, { path: 'file.txt' }));
274
+ expect(last).toHaveLength(1);
275
+ await applyHunk(tmpDir, 'file.txt', { patch: last[0], action: 'discard' });
276
+ changed[50] = original[50];
277
+ expect(await readWorking(tmpDir)).toBe(changed.join('\n') + '\n');
278
+ expect(await readStaged(git)).toBe(changed.join('\n') + '\n');
279
+ const staged = splitHunks(await getDiff(tmpDir, { path: 'file.txt', staged: true }));
280
+ await applyHunk(tmpDir, 'file.txt', { patch: staged[0], action: 'unstage' });
281
+ expect(await readWorking(tmpDir)).toBe(changed.join('\n') + '\n');
282
+ await git.add('file.txt'); await git.commit('Committed changes');
283
+ await expect(applyHunk(tmpDir, 'file.txt', { patch: historical[0], action: 'discard' })).rejects.toThrow('refresh and try again');
284
+ });
285
+
286
+ it.each(['crlf', 'mixed'])('preserves %s file bytes through stage, unstage and discard', async (endings) => {
287
+ if (!canRunGit()) return;
288
+ const { tmpDir, git } = await createTempRepo();
289
+ await git.addConfig('core.autocrlf', 'false');
290
+ const serialize = (first, last) => Array.from({ length: 30 }, (_, index) => {
291
+ const text = index === 0 ? first : index === 29 ? last : `line${index}`;
292
+ return text + (endings === 'crlf' || index % 2 === 0 ? '\r\n' : '\n');
293
+ }).join('');
294
+ const original = serialize('first', 'last');
295
+ const edited = serialize('FIRST', 'LAST');
296
+ await writeFile(tmpDir, 'file.txt', original);
297
+ await git.add('file.txt'); await git.commit('Initial');
298
+ await writeFile(tmpDir, 'file.txt', edited);
299
+ const hunks = splitHunks(await getDiff(tmpDir, { path: 'file.txt' }));
300
+ await applyHunk(tmpDir, 'file.txt', { patch: hunks[0], action: 'stage' });
301
+ expect(await git.raw(['show', ':file.txt'])).toBe(serialize('FIRST', 'last'));
302
+ const staged = splitHunks(await getDiff(tmpDir, { path: 'file.txt', staged: true }));
303
+ await applyHunk(tmpDir, 'file.txt', { patch: staged[0], action: 'unstage' });
304
+ expect(await git.raw(['show', ':file.txt'])).toBe(original);
305
+ const working = splitHunks(await getDiff(tmpDir, { path: 'file.txt' }));
306
+ await applyHunk(tmpDir, 'file.txt', { patch: working[0], action: 'discard' });
307
+ expect(await fs.promises.readFile(path.join(tmpDir, 'file.txt'), 'utf8')).toBe(serialize('first', 'LAST'));
308
+ });
309
+
310
+ it('rejects extra files hidden before the requested patch', async () => {
311
+ if (!canRunGit()) return;
312
+ const { tmpDir, git } = await createTempRepo();
313
+ for (const name of ['file.txt', 'other.txt']) await writeFile(tmpDir, name, ORIGINAL_FILE);
314
+ await git.add('.'); await git.commit('Initial');
315
+ for (const name of ['file.txt', 'other.txt']) await writeFile(tmpDir, name, EDITED_FILE);
316
+ const other = splitHunks(await getDiff(tmpDir, { path: 'other.txt' }))[0];
317
+ const requested = splitHunks(await getDiff(tmpDir, { path: 'file.txt' }))[0];
318
+ await expect(applyHunk(tmpDir, 'file.txt', { patch: requested + other, action: 'stage' })).rejects.toThrow('refresh and try again');
319
+ expect(await git.raw(['diff', '--cached'])).toBe('');
320
+ });
321
+
223
322
  it('rejects an invalid action or a patch without a hunk header', async () => {
224
323
  const { tmpDir } = await createTempRepo();
225
324
  await expect(applyHunk(tmpDir, 'file.txt', { patch: '@@ -1 +1 @@\n a\n', action: 'bogus' })).rejects.toThrow(
@@ -302,10 +401,9 @@ describe('applyHunk', () => {
302
401
  );
303
402
  });
304
403
 
305
- it('accepts hunk patches for files with spaces in their path', async () => {
404
+ it.each(['file name.txt', 'зміни.txt'])('accepts hunk patches for %s', async (filePath) => {
306
405
  if (!canRunGit()) return;
307
406
  const { tmpDir, git } = await createTempRepo();
308
- const filePath = 'file name.txt';
309
407
  await writeFile(tmpDir, filePath, ORIGINAL_FILE);
310
408
  await git.add(filePath);
311
409
  await git.commit('Initial');
@@ -322,6 +420,71 @@ describe('applyHunk', () => {
322
420
  });
323
421
  });
324
422
 
423
+ describe.runIf(canRunGit())('untracked diffs', () => {
424
+ it.each(['false', 'warn'])('returns only the patch with core.safecrlf=%s', async (safecrlf) => {
425
+ const { tmpDir, git } = await createTempRepo();
426
+ await git.addConfig('core.autocrlf', 'true');
427
+ await git.addConfig('core.safecrlf', safecrlf);
428
+ fs.writeFileSync(path.join(tmpDir, 'new file.txt'), 'first\nsecond\n');
429
+
430
+ // Confirm this fixture produces a real diff exit, including stderr in the warning case.
431
+ let expectedPatch;
432
+ try {
433
+ runGit(tmpDir, ['diff', '--no-color', '--full-index', '--no-index', '--', '/dev/null', 'new file.txt']);
434
+ throw new Error('Expected git diff to exit with differences');
435
+ } catch (error) {
436
+ expect(error.status).toBe(1);
437
+ expectedPatch = error.stdout;
438
+ if (safecrlf === 'warn') {
439
+ expect(error.stderr).toContain('LF will be replaced by CRLF');
440
+ }
441
+ }
442
+
443
+ const diff = await getDiff(tmpDir, { path: 'new file.txt' });
444
+ expect(diff).toBe(expectedPatch);
445
+ expect(diff).toContain('+first\n+second\n');
446
+ expect(diff).not.toContain('warning:');
447
+ expect(await getUntrackedDiffs(tmpDir, ['new file.txt'])).toEqual([diff]);
448
+ });
449
+
450
+ it('accepts an empty untracked file without a process error', async () => {
451
+ const { tmpDir } = await createTempRepo();
452
+ fs.writeFileSync(path.join(tmpDir, 'empty.txt'), '');
453
+ const diff = await getDiff(tmpDir, { path: 'empty.txt' });
454
+ expect(diff).toContain('new file mode 100644');
455
+ expect(diff).not.toContain('@@');
456
+ expect(await getUntrackedDiffs(tmpDir, ['empty.txt'])).toEqual([diff]);
457
+ });
458
+
459
+ it('rejects fatal conversion errors while preserving other batch entries', async () => {
460
+ const { tmpDir } = await createTempRepo();
461
+ runGit(tmpDir, ['config', 'diff.broken.textconv', 'false']);
462
+ fs.writeFileSync(path.join(tmpDir, '.gitattributes'), 'bad.txt diff=broken\n');
463
+ fs.writeFileSync(path.join(tmpDir, 'first.safe'), 'first\n');
464
+ fs.writeFileSync(path.join(tmpDir, 'bad.txt'), 'bad\n');
465
+ fs.writeFileSync(path.join(tmpDir, 'last.safe'), 'last\n');
466
+
467
+ await expect(getDiff(tmpDir, { path: 'bad.txt' })).rejects.toThrow('unable to read files to diff');
468
+ const diffs = await getUntrackedDiffs(tmpDir, ['first.safe', 'bad.txt', 'last.safe'], { concurrency: 1 });
469
+ expect(diffs).toHaveLength(3);
470
+ expect(diffs[0]).toContain('+first\n');
471
+ expect(diffs[1]).toBe('');
472
+ expect(diffs[2]).toContain('+last\n');
473
+ });
474
+
475
+ it('rejects truncated patches when the process output exceeds the buffer limit', async () => {
476
+ const { tmpDir } = await createTempRepo();
477
+ fs.writeFileSync(path.join(tmpDir, 'large.txt'), 'x'.repeat(21 * 1024 * 1024) + '\n');
478
+ const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
479
+ try {
480
+ await expect(getDiff(tmpDir, { path: 'large.txt' })).rejects.toThrow('maxBuffer');
481
+ expect(await getUntrackedDiffs(tmpDir, ['large.txt'])).toEqual(['']);
482
+ } finally {
483
+ errorSpy.mockRestore();
484
+ }
485
+ });
486
+ });
487
+
325
488
  describe('symlink diffs', () => {
326
489
  it('treats an untracked directory symlink as a link in patch and split diffs', async () => {
327
490
  if (!canRunGit() || process.platform === 'win32') return;
@@ -517,6 +680,24 @@ describe('getWorktrees', () => {
517
680
  expect(Array.isArray(result)).toBe(true);
518
681
  expect(warnSpy).not.toHaveBeenCalled();
519
682
  });
683
+ it('flags a worktree whose directory was deleted outside git as prunable', async () => {
684
+ const repo = createTempDir();
685
+ runGit(repo, ['init', '-b', 'main']);
686
+ runGit(repo, ['config', 'user.email', 'test@example.com']);
687
+ runGit(repo, ['config', 'user.name', 'Test User']);
688
+ runGit(repo, ['commit', '--allow-empty', '-m', 'init']);
689
+ const worktreePath = path.join(createTempDir(), 'feature');
690
+ runGit(repo, ['worktree', 'add', worktreePath, '-b', 'feature']);
691
+
692
+ const before = await getWorktrees(repo);
693
+ expect(before.find((entry) => entry.branch === 'feature')).toMatchObject({ prunable: false });
694
+
695
+ fs.rmSync(worktreePath, { recursive: true, force: true });
696
+
697
+ const after = await getWorktrees(repo);
698
+ expect(after.find((entry) => entry.branch === 'feature')).toMatchObject({ path: expect.any(String), prunable: true });
699
+ expect(after.find((entry) => entry.branch === 'main')).toMatchObject({ prunable: false });
700
+ });
520
701
  });
521
702
 
522
703
  // ---------------------------------------------------------------------------
@@ -1651,18 +1832,249 @@ describe.runIf(canRunGit())('getUnpushedBranchCounts', () => {
1651
1832
  });
1652
1833
  });
1653
1834
 
1835
+ describe.runIf(canRunGit())('commit comparisons', () => {
1836
+ it('shows only the selected commit and gives walkthrough the identical patch', async () => {
1837
+ const { repository } = createRepositoryWithRemote();
1838
+ fs.writeFileSync(path.join(repository, 'README.md'), 'selected version\n');
1839
+ runGit(repository, ['add', '.']);
1840
+ runGit(repository, ['commit', '-m', 'selected']);
1841
+ const hash = runGit(repository, ['rev-parse', 'HEAD']).trim();
1842
+ fs.writeFileSync(path.join(repository, 'README.md'), 'later version\n');
1843
+ runGit(repository, ['add', '.']);
1844
+ runGit(repository, ['commit', '-m', 'later']);
1845
+ fs.writeFileSync(path.join(repository, 'README.md'), 'uncommitted version\n');
1846
+ const patch = await getCommitDiff(repository, { hash, path: 'README.md' });
1847
+ expect(patch).toContain('+selected version');
1848
+ expect(patch).not.toContain('later version');
1849
+ expect(patch).not.toContain('uncommitted version');
1850
+ expect((await getCommitFiles(repository, hash)).files).toEqual([
1851
+ { path: 'README.md', insertions: 1, deletions: 1, isBinary: false, changeType: 'M' },
1852
+ ]);
1853
+ const source = parseSource({ kind: 'commit', hash });
1854
+ expect(sourceKey(source)).toBe(`commit:${hash}`);
1855
+ expect((await loadSourceSections(repository, source)).sections).toEqual([{ scope: 'commit', patch }]);
1856
+ const routes = new Map();
1857
+ registerGitRoutes({
1858
+ get: (url, handler) => routes.set(url, handler), post() {}, put() {}, delete() {},
1859
+ });
1860
+ let response;
1861
+ await routes.get('/api/git/commit-diff')(
1862
+ { query: { directory: repository, hash, path: 'README.md' } },
1863
+ { json: (body) => { response = body; }, status: (code) => { throw new Error(`Unexpected status ${code}`); } },
1864
+ );
1865
+ expect(response).toEqual({ diff: patch });
1866
+ });
1867
+
1868
+ it('handles root and empty commits and rejects invalid hashes', async () => {
1869
+ const { repository } = createRepositoryWithRemote();
1870
+ const root = runGit(repository, ['rev-parse', 'HEAD']).trim();
1871
+ expect(await getCommitDiff(repository, { hash: root })).toContain('+# Test');
1872
+ expect((await getCommitFiles(repository, root)).files[0].changeType).toBe('A');
1873
+ runGit(repository, ['commit', '--allow-empty', '-m', 'empty']);
1874
+ const empty = runGit(repository, ['rev-parse', 'HEAD']).trim();
1875
+ expect(await getCommitDiff(repository, { hash: empty })).toBe('');
1876
+ expect(await getCommitFiles(repository, empty)).toEqual({ files: [] });
1877
+ expect(() => parseSource({ kind: 'commit', hash: 'HEAD' })).toThrow();
1878
+ expect(() => parseSource({ kind: 'commit', hash: [root] })).toThrow();
1879
+ await expect(getCommitDiff(repository, { hash: 'HEAD' })).rejects.toThrow();
1880
+ await expect(getCommitFiles(repository, '0'.repeat(40))).rejects.toThrow();
1881
+ });
1882
+
1883
+ it('keeps rename paths and original contents together, including whitespace in names', async () => {
1884
+ const { repository } = createRepositoryWithRemote();
1885
+ const destination = ' new\nname.md';
1886
+ runGit(repository, ['mv', 'README.md', destination]);
1887
+ runGit(repository, ['commit', '-m', 'rename']);
1888
+ const hash = runGit(repository, ['rev-parse', 'HEAD']).trim();
1889
+ const { files } = await getCommitFiles(repository, hash);
1890
+ expect(files).toEqual([{ path: destination, previousPath: 'README.md', changeType: 'R', insertions: 0, deletions: 0, isBinary: false }]);
1891
+ const patch = await getCommitDiff(repository, { hash, path: destination, previousPath: files[0].previousPath });
1892
+ expect(patch).toContain('rename from README.md');
1893
+ expect(patch).toContain('similarity index 100%');
1894
+ });
1895
+
1896
+ it('compares a merge commit against its first parent', async () => {
1897
+ const { repository } = createRepositoryWithRemote();
1898
+ runGit(repository, ['checkout', '-b', 'side']);
1899
+ fs.writeFileSync(path.join(repository, 'side.txt'), 'side\n');
1900
+ runGit(repository, ['add', '.']);
1901
+ runGit(repository, ['commit', '-m', 'side']);
1902
+ runGit(repository, ['checkout', 'next']);
1903
+ fs.writeFileSync(path.join(repository, 'main.txt'), 'main\n');
1904
+ runGit(repository, ['add', '.']);
1905
+ runGit(repository, ['commit', '-m', 'main']);
1906
+ runGit(repository, ['merge', '--no-ff', 'side', '-m', 'merge']);
1907
+ const hash = runGit(repository, ['rev-parse', 'HEAD']).trim();
1908
+ expect((await getCommitFiles(repository, hash)).files.map((file) => file.path)).toEqual(['side.txt']);
1909
+ const patch = await getCommitDiff(repository, { hash });
1910
+ expect(patch).toContain('+side');
1911
+ expect(patch).not.toContain('main.txt');
1912
+ });
1913
+
1914
+ it('limits current-branch history to 50 commits without including another branch', async () => {
1915
+ const { repository } = createRepositoryWithRemote();
1916
+ runGit(repository, ['checkout', '-b', 'other']);
1917
+ runGit(repository, ['commit', '--allow-empty', '-m', 'other branch only']);
1918
+ runGit(repository, ['checkout', 'next']);
1919
+ for (let index = 0; index < 51; index += 1) runGit(repository, ['commit', '--allow-empty', '-m', `current ${index}`]);
1920
+ const history = await getLog(repository, { maxCount: 50, to: 'refs/heads/next' });
1921
+ expect(history.all).toHaveLength(50);
1922
+ expect(history.all[0].message).toBe('current 50');
1923
+ expect(history.all.some((commit) => commit.message === 'other branch only')).toBe(false);
1924
+ });
1925
+ });
1926
+
1654
1927
  describe.runIf(canRunGit())('getRangeDiff', () => {
1655
- it('resolves a base that exists only on a remote other than origin', async () => {
1928
+ it('loads a committed deletion that no longer exists in HEAD or the working tree', async () => {
1929
+ const { repository } = createRepositoryWithRemote();
1930
+ runGit(repository, ['rm', 'README.md']);
1931
+ runGit(repository, ['commit', '-m', 'delete file']);
1932
+ const diff = await getRangeDiff(repository, { base: 'origin/react', head: 'next', path: 'README.md', includeWorkingTree: true });
1933
+ expect(diff).toContain('deleted file mode');
1934
+ expect(diff).toContain('-# Test');
1935
+ });
1936
+
1937
+ it('carries the working-tree option through the actual HTTP route handlers', async () => {
1938
+ const { repository } = createRepositoryWithRemote();
1939
+ fs.writeFileSync(path.join(repository, 'local.txt'), 'current local work\n');
1940
+ const routes = new Map();
1941
+ registerGitRoutes({
1942
+ get: (url, handler) => routes.set(url, handler),
1943
+ post() {},
1944
+ put() {},
1945
+ delete() {},
1946
+ });
1947
+ const query = { directory: repository, base: 'origin/react', head: 'next', includeWorkingTree: 'true' };
1948
+ for (const endpoint of ['range-diff', 'range-files']) {
1949
+ let status = 200;
1950
+ let body;
1951
+ const response = {
1952
+ status(value) { status = value; return this; },
1953
+ json(value) { body = value; },
1954
+ };
1955
+ await routes.get(`/api/git/${endpoint}`)({ query }, response);
1956
+ expect(status).toBe(200);
1957
+ if (endpoint === 'range-diff') expect(body.diff).toContain('+current local work');
1958
+ else expect(body.files).toEqual([{ path: 'local.txt', status: 'A' }]);
1959
+ }
1960
+ });
1961
+
1962
+ it('asks for a new base after restacking and compares against the selected parent', async () => {
1963
+ const { repository } = createRepositoryWithRemote();
1964
+ runGit(repository, ['checkout', '-b', 'child', 'origin/react']);
1965
+ fs.writeFileSync(path.join(repository, 'child.txt'), 'child\n');
1966
+ runGit(repository, ['add', '.']);
1967
+ runGit(repository, ['commit', '-m', 'child']);
1968
+ expect(await getBranchBase(repository, 'child')).toEqual({ base: 'origin/react' });
1969
+ runGit(repository, ['checkout', '-b', 'parent', 'origin/react']);
1970
+ fs.writeFileSync(path.join(repository, 'parent.txt'), 'parent\n');
1971
+ runGit(repository, ['add', '.']);
1972
+ runGit(repository, ['commit', '-m', 'parent']);
1973
+ runGit(repository, ['checkout', 'child']);
1974
+ runGit(repository, ['rebase', 'parent']);
1975
+ expect(await getBranchBase(repository, 'child')).toEqual({ base: null });
1976
+ fs.writeFileSync(path.join(repository, 'child.txt'), 'current child\n');
1977
+ const options = { base: 'refs/heads/parent', head: 'child', includeWorkingTree: true };
1978
+ expect(await getRangeFiles(repository, options)).toEqual([{ path: 'child.txt', status: 'A' }]);
1979
+ const diff = await getRangeDiff(repository, options);
1980
+ expect(diff).toContain('+current child');
1981
+ expect(diff).not.toContain('parent.txt');
1982
+ });
1983
+
1984
+ it('combines committed, staged, unstaged and untracked work without changing the real index', async () => {
1985
+ const { repository } = createRepositoryWithRemote();
1986
+ fs.writeFileSync(path.join(repository, 'README.md'), '# Committed\n');
1987
+ runGit(repository, ['add', 'README.md']);
1988
+ runGit(repository, ['commit', '-m', 'branch change']);
1989
+ fs.writeFileSync(path.join(repository, 'README.md'), '# Staged\n');
1990
+ fs.writeFileSync(path.join(repository, 'staged.txt'), 'staged only\n');
1991
+ runGit(repository, ['add', '.']);
1992
+ fs.writeFileSync(path.join(repository, 'README.md'), '# Current\n');
1993
+ fs.writeFileSync(path.join(repository, 'untracked.txt'), 'new local file\n');
1994
+ fs.writeFileSync(path.join(repository, ' leading space.txt'), 'space path\n');
1995
+ const indexBefore = fs.readFileSync(path.join(repository, '.git/index'));
1996
+ const options = { base: 'origin/react', head: 'next', includeWorkingTree: true };
1997
+
1998
+ const diff = await getRangeDiff(repository, options);
1999
+ expect(diff).toContain('-# Test');
2000
+ expect(diff).toContain('+# Current');
2001
+ expect(diff).not.toContain('+# Staged');
2002
+ expect(diff).not.toContain('+# Committed');
2003
+ expect(diff).toContain('+new local file');
2004
+ expect(diff).toContain('+staged only');
2005
+ expect(await getRangeFiles(repository, options)).toEqual(expect.arrayContaining([
2006
+ { path: 'README.md', status: 'M' },
2007
+ { path: 'staged.txt', status: 'A' },
2008
+ { path: 'untracked.txt', status: 'A' },
2009
+ { path: ' leading space.txt', status: 'A' },
2010
+ ]));
2011
+ const { sections } = await loadSourceSections(repository, { kind: 'branch', baseRef: options.base, headRef: options.head });
2012
+ expect(sections).toEqual([{ scope: 'branch', patch: diff }]);
2013
+ expect(fs.readFileSync(path.join(repository, '.git/index'))).toEqual(indexBefore);
2014
+
2015
+ const committed = await getRangeDiff(repository, { base: options.base, head: options.head });
2016
+ expect(committed).toContain('+# Committed');
2017
+ expect(committed).not.toContain('+new local file');
2018
+ fs.writeFileSync(path.join(repository, 'README.md'), '# Latest\n');
2019
+ expect(await getRangeDiff(repository, { ...options, path: 'README.md' })).toContain('+# Latest');
2020
+ });
2021
+
2022
+ it('reports the final file after a staged deletion is recreated, and omits undone branch changes', async () => {
2023
+ const { repository } = createRepositoryWithRemote();
2024
+ runGit(repository, ['rm', 'README.md']);
2025
+ fs.writeFileSync(path.join(repository, 'README.md'), '# Recreated\n');
2026
+ const options = { base: 'origin/react', head: 'next', includeWorkingTree: true };
2027
+ expect(await getRangeFiles(repository, options)).toEqual([{ path: 'README.md', status: 'M' }]);
2028
+ const diff = await getRangeDiff(repository, options);
2029
+ expect(diff).toContain('-# Test');
2030
+ expect(diff).toContain('+# Recreated');
2031
+ expect(diff.match(/diff --git/g)).toHaveLength(1);
2032
+ fs.writeFileSync(path.join(repository, 'README.md'), '# Test\n');
2033
+ expect(await getRangeFiles(repository, options)).toEqual([]);
2034
+ expect(await getRangeDiff(repository, options)).toBe('');
2035
+ });
2036
+
2037
+ it('keeps local and remote bases distinct and rejects a different checked-out branch', async () => {
2038
+ const { repository } = createRepositoryWithRemote();
2039
+ runGit(repository, ['branch', 'react']);
2040
+ fs.writeFileSync(path.join(repository, 'parent.txt'), 'parent work\n');
2041
+ runGit(repository, ['add', '.']);
2042
+ runGit(repository, ['commit', '-m', 'parent work']);
2043
+ runGit(repository, ['branch', '-f', 'react', 'HEAD']);
2044
+ fs.writeFileSync(path.join(repository, 'child.txt'), 'child work\n');
2045
+ const options = { head: 'next', includeWorkingTree: true };
2046
+ const local = await getRangeDiff(repository, { ...options, base: 'react' });
2047
+ const remote = await getRangeDiff(repository, { ...options, base: 'origin/react' });
2048
+ expect(local).not.toContain('parent.txt');
2049
+ expect(remote).toContain('parent.txt');
2050
+ expect(local).toContain('child.txt');
2051
+ expect(await getRangeFiles(repository, { ...options, base: 'react' })).toEqual([{ path: 'child.txt', status: 'A' }]);
2052
+ runGit(repository, ['checkout', 'react']);
2053
+ await expect(getRangeDiff(repository, { ...options, base: 'origin/react' })).rejects.toThrow(/checked-out branch/);
2054
+ });
2055
+
2056
+ it('includes untracked symlinks as links without reading their targets', async () => {
2057
+ const { repository } = createRepositoryWithRemote();
2058
+ const outside = path.join(createTempDir(), 'outside.txt');
2059
+ fs.writeFileSync(outside, 'must not be in a diff\n');
2060
+ fs.symlinkSync(outside, path.join(repository, 'link.txt'));
2061
+ const diff = await getRangeDiff(repository, { base: 'origin/react', head: 'next', includeWorkingTree: true });
2062
+ expect(diff).toContain('new file mode 120000');
2063
+ expect(diff).toContain(outside);
2064
+ expect(diff).not.toContain('must not be in a diff');
2065
+ });
2066
+
2067
+ it('uses an explicitly selected base on a remote other than origin', async () => {
1656
2068
  const { repository } = createRepositoryWithRemote({ remoteName: 'upstream', defaultBranch: 'react' });
1657
- // Only refs/remotes/upstream/react carries the base — git cannot resolve the
1658
- // bare name, so an unqualified `react...next` fails with "ambiguous argument".
2069
+ // The selected remote ref must work without a local branch of that name.
1659
2070
  fs.writeFileSync(path.join(repository, 'feature.txt'), 'work\n');
1660
2071
  runGit(repository, ['add', 'feature.txt']);
1661
2072
  runGit(repository, ['commit', '-m', 'feature']);
1662
2073
 
1663
- const diff = await getRangeDiff(repository, { base: 'react', head: 'next' });
2074
+ const diff = await getRangeDiff(repository, { base: 'upstream/react', head: 'next' });
1664
2075
 
1665
2076
  expect(diff).toContain('feature.txt');
2077
+ await expect(getRangeDiff(repository, { base: 'react', head: 'next' })).rejects.toThrow(/is not available locally/);
1666
2078
  });
1667
2079
 
1668
2080
  it('names an unfetched remote-only ref instead of failing with git\'s ambiguous argument (#2735)', async () => {
@@ -1675,6 +2087,9 @@ describe.runIf(canRunGit())('getRangeDiff', () => {
1675
2087
  });
1676
2088
 
1677
2089
  describe('parseBranchCreationSource', () => {
2090
+ it('does not reuse the creation base after a rebase', () => {
2091
+ expect(parseBranchCreationSource('rebase (finish): refs/heads/feature onto abc123\nbranch: Created from main')).toBeNull();
2092
+ });
1678
2093
  it('returns the source ref from the oldest creation entry', () => {
1679
2094
  // Reflog lists newest entries first; creation is the last line.
1680
2095
  const reflog = [
@@ -1721,7 +2136,7 @@ describe.runIf(canRunGit())('getRangeFiles', () => {
1721
2136
  runGit(repository, ['add', 'added.txt', 'README.md']);
1722
2137
  runGit(repository, ['commit', '-m', 'changes']);
1723
2138
 
1724
- const files = await getRangeFiles(repository, { base: 'react', head: 'next' });
2139
+ const files = await getRangeFiles(repository, { base: 'origin/react', head: 'next' });
1725
2140
 
1726
2141
  expect(files).toEqual(expect.arrayContaining([
1727
2142
  { path: 'added.txt', status: 'A' },
@@ -1743,7 +2158,7 @@ describe.runIf(canRunGit())('getRangeFiles', () => {
1743
2158
  runGit(repository, ['add', '-A']);
1744
2159
  runGit(repository, ['commit', '-m', 'rename']);
1745
2160
 
1746
- const files = await getRangeFiles(repository, { base: 'react', head: 'next' });
2161
+ const files = await getRangeFiles(repository, { base: 'origin/react', head: 'next' });
1747
2162
 
1748
2163
  const renameEntry = files.find((file) => file.status === 'R');
1749
2164
  expect(renameEntry).toBeDefined();
@@ -1765,7 +2180,7 @@ describe.runIf(canRunGit())('getRangeFiles', () => {
1765
2180
  runGit(repository, ['add', '-A']);
1766
2181
  runGit(repository, ['commit', '-m', 'copy']);
1767
2182
 
1768
- const files = await getRangeFiles(repository, { base: 'react', head: 'next' });
2183
+ const files = await getRangeFiles(repository, { base: 'origin/react', head: 'next' });
1769
2184
 
1770
2185
  const copyEntry = files.find((file) => file.status === 'C');
1771
2186
  expect(copyEntry).toBeDefined();
@@ -12,7 +12,9 @@
12
12
  import { createRequire } from 'node:module';
13
13
  import { existsSync } from 'node:fs';
14
14
 
15
- const LINUX_ENV_BINARIES = ['/usr/bin/env', '/bin/env'];
15
+ const POSIX_ENV_BINARIES = ['/usr/bin/env', '/bin/env'];
16
+ /** Variables a PTY shell must never inherit from the OpenChamber host process. */
17
+ const PTY_HOST_PRIVATE_VARIABLES = Object.freeze(['ARGV0', 'NODE_CHANNEL_FD']);
16
18
 
17
19
  /**
18
20
  * Remove AppImage `ARGV0` from a mutable env object (or `process.env`).
@@ -49,26 +51,31 @@ export function clearAppImageArgv0FromProcessEnv() {
49
51
  }
50
52
 
51
53
  /**
52
- * Resolve a Linux PTY launch that drops native `ARGV0` before the shell starts.
54
+ * Resolve a POSIX PTY launch that unsets host-private variables before the
55
+ * shell starts.
53
56
  *
54
- * `bun-pty` merges the OS environ into the child, so deleting `ARGV0` from the
55
- * JS env object alone is not enough. Wrapping with `env -u ARGV0` unsets it
56
- * before execing the real shell. No-op on non-Linux platforms.
57
+ * `bun-pty` merges the OS environ into the child, so deleting a variable from
58
+ * the JS env object alone is not enough: AppImage `ARGV0` came back on Linux,
59
+ * and the daemon's `NODE_CHANNEL_FD` came back everywhere (Node then warns
60
+ * "Failed to parse IPC channel number" when a CLI such as opencode exits).
61
+ * Wrapping with `env -u NAME ...` unsets them before execing the real shell.
62
+ * No-op on Windows and when no `env` binary is found.
57
63
  *
58
64
  * @param {string} executable
59
65
  * @param {string[]} args
66
+ * @param {readonly string[]} variables
60
67
  * @returns {{ executable: string, args: string[] }}
61
68
  */
62
- export function resolveLinuxPtyLaunch(executable, args = []) {
63
- if (process.platform !== 'linux') {
69
+ export function resolvePosixPtyLaunch(executable, args = [], variables = PTY_HOST_PRIVATE_VARIABLES) {
70
+ if (process.platform === 'win32' || variables.length === 0) {
64
71
  return { executable, args };
65
72
  }
66
- const envBinary = LINUX_ENV_BINARIES.find((candidate) => existsSync(candidate));
73
+ const envBinary = POSIX_ENV_BINARIES.find((candidate) => existsSync(candidate));
67
74
  if (!envBinary) {
68
75
  return { executable, args };
69
76
  }
70
77
  return {
71
78
  executable: envBinary,
72
- args: ['-u', 'ARGV0', executable, ...args],
79
+ args: [...variables.flatMap((name) => ['-u', name]), executable, ...args],
73
80
  };
74
81
  }
@@ -1,7 +1,7 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  import {
3
3
  clearAppImageArgv0FromProcessEnv,
4
- resolveLinuxPtyLaunch,
4
+ resolvePosixPtyLaunch,
5
5
  stripAppImageArgv0Leak,
6
6
  } from './inherited-env.js';
7
7
 
@@ -46,18 +46,17 @@ describe('clearAppImageArgv0FromProcessEnv', () => {
46
46
  });
47
47
  });
48
48
 
49
- describe('resolveLinuxPtyLaunch', () => {
50
- it('wraps the shell with env -u ARGV0 on Linux', () => {
51
- if (process.platform !== 'linux') return;
52
- expect(resolveLinuxPtyLaunch('/bin/zsh', ['-l'])).toEqual({
49
+ describe('resolvePosixPtyLaunch', () => {
50
+ it('wraps the shell with env -u for every host-private variable on POSIX', () => {
51
+ if (process.platform === 'win32') return;
52
+ expect(resolvePosixPtyLaunch('/bin/zsh', ['-l'])).toEqual({
53
53
  executable: expect.stringMatching(/\/env$/),
54
- args: ['-u', 'ARGV0', '/bin/zsh', '-l'],
54
+ args: ['-u', 'ARGV0', '-u', 'NODE_CHANNEL_FD', '/bin/zsh', '-l'],
55
55
  });
56
56
  });
57
57
 
58
- it('leaves non-Linux launches unchanged', () => {
59
- if (process.platform === 'linux') return;
60
- expect(resolveLinuxPtyLaunch('/bin/zsh', ['-l'])).toEqual({
58
+ it('leaves the launch unchanged with nothing to unset', () => {
59
+ expect(resolvePosixPtyLaunch('/bin/zsh', ['-l'], [])).toEqual({
61
60
  executable: '/bin/zsh',
62
61
  args: ['-l'],
63
62
  });