@firstpick/pi-package-webui 0.11.1 → 0.11.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (310) hide show
  1. package/DEVELOPMENT.md +151 -12
  2. package/README.md +34 -6
  3. package/TECHNICAL.md +75 -8
  4. package/bin/pi-webui.mjs +5390 -11423
  5. package/index.ts +10 -3
  6. package/lib/component-update-state.mjs +2 -2
  7. package/lib/git-workflow-preference-values.mjs +122 -0
  8. package/lib/git-workflow-preferences.mjs +35 -563
  9. package/lib/package-updates.mjs +260 -0
  10. package/lib/rpc-supervisor-client.mjs +8 -4
  11. package/lib/server/app-runners.mjs +1667 -0
  12. package/lib/server/codex-fast-mode.mjs +161 -0
  13. package/lib/server/conversation-mode.mjs +218 -0
  14. package/lib/server/conversation-voice.mjs +318 -0
  15. package/lib/server/extension-ui-requests.mjs +114 -0
  16. package/lib/server/git-generation.mjs +459 -0
  17. package/lib/server/git-mutations.mjs +1827 -0
  18. package/lib/server/git-reads.mjs +608 -0
  19. package/lib/server/git-worktree-sessions.mjs +408 -0
  20. package/lib/server/helper-requests.mjs +82 -0
  21. package/lib/server/no-project-workspaces.mjs +103 -0
  22. package/lib/server/rpc-transports.mjs +394 -0
  23. package/lib/server/settings-store.mjs +544 -0
  24. package/lib/server/sse-delivery.mjs +138 -0
  25. package/lib/server/workspace-files.mjs +563 -0
  26. package/lib/update/supervisor.mjs +4 -0
  27. package/lib/webui-workspaces.mjs +2 -0
  28. package/package.json +4 -4
  29. package/public/activity-agents-controller.mjs +269 -0
  30. package/public/activity-events-controller.mjs +236 -0
  31. package/public/activity-intercom-controller.mjs +627 -0
  32. package/public/activity-queue-controller.mjs +534 -0
  33. package/public/activity-todo-view.mjs +89 -0
  34. package/public/activity-usage-controller.mjs +589 -0
  35. package/public/app.js +3761 -3886
  36. package/public/conversation-overview.css +84 -0
  37. package/public/conversation-overview.mjs +193 -0
  38. package/public/draft-conversations.mjs +135 -0
  39. package/public/focused-composer-controls.css +111 -0
  40. package/public/focused-composer-controls.mjs +143 -0
  41. package/public/focused-composer-disclosure.mjs +223 -0
  42. package/public/focused-shell-adapter.css +264 -0
  43. package/public/focused-shell-adapter.mjs +257 -0
  44. package/public/index.html +137 -80
  45. package/public/model-catalog-order.mjs +63 -0
  46. package/public/platform-event-stream.mjs +64 -0
  47. package/public/project-artifact-controller.mjs +218 -0
  48. package/public/project-file-viewer-controller.mjs +383 -0
  49. package/public/project-git-tools-controller.mjs +181 -0
  50. package/public/project-runners-controller.mjs +220 -0
  51. package/public/service-worker.js +52 -1
  52. package/public/session-attention-scheduler.mjs +182 -0
  53. package/public/session-composer-store.mjs +56 -0
  54. package/public/session-context.mjs +51 -0
  55. package/public/session-extension-requests.mjs +63 -0
  56. package/public/session-shelf-state.mjs +151 -0
  57. package/public/session-shelves.css +171 -0
  58. package/public/session-shelves.mjs +95 -0
  59. package/public/settings-navigation-controller.mjs +249 -0
  60. package/public/settings-navigation.css +61 -0
  61. package/public/settings-resource-controller.mjs +232 -0
  62. package/public/settings-workspace.css +19 -0
  63. package/public/settings-workspace.mjs +175 -0
  64. package/public/shell-actions.mjs +87 -0
  65. package/public/shell-attention-inbox.css +72 -0
  66. package/public/shell-attention-inbox.mjs +198 -0
  67. package/public/shell-context-actions.css +61 -0
  68. package/public/shell-context-actions.mjs +168 -0
  69. package/public/shell-inspector-resize.mjs +124 -0
  70. package/public/shell-navigation-resize.mjs +107 -0
  71. package/public/shell-navigation.mjs +127 -0
  72. package/public/shell-preferences.mjs +108 -0
  73. package/public/shell-surfaces.mjs +99 -0
  74. package/public/shell-tools-launcher.css +97 -0
  75. package/public/shell-tools-launcher.mjs +222 -0
  76. package/public/shell-view-host.mjs +115 -0
  77. package/public/shell-workspace.css +266 -0
  78. package/public/shell-workspace.mjs +402 -0
  79. package/public/sidebar-update-menu.css +190 -0
  80. package/public/sidebar-update-menu.mjs +512 -0
  81. package/public/styles.css +322 -169
  82. package/public/subagent-launch-slot-state.mjs +2 -2
  83. package/public/themed-selects.css +156 -0
  84. package/public/workspace-choices.mjs +104 -0
  85. package/tests/activity-agents-controller.test.mjs +652 -0
  86. package/tests/activity-events-controller.test.mjs +511 -0
  87. package/tests/app-runner-terminal-static.test.mjs +3 -3
  88. package/tests/append-system-http.test.mjs +7 -6
  89. package/tests/append-system-selector-static.test.mjs +6 -6
  90. package/tests/aur-review-widget-static.test.mjs +11 -3
  91. package/tests/boot-failure-diagnostics.test.mjs +8 -3
  92. package/tests/browser/action-feedback-gutter.spec.mjs +251 -0
  93. package/tests/browser/activity-intercom-controller.spec.mjs +457 -0
  94. package/tests/browser/activity-navigation-integration.spec.mjs +45 -0
  95. package/tests/browser/activity-owner-integration.spec.mjs +201 -0
  96. package/tests/browser/activity-queue-controller.spec.mjs +405 -0
  97. package/tests/browser/activity-section-picker.spec.mjs +294 -0
  98. package/tests/browser/activity-todo-view.spec.mjs +60 -0
  99. package/tests/browser/activity-usage-controller.spec.mjs +416 -0
  100. package/tests/browser/compact-layout-integration.spec.mjs +58 -0
  101. package/tests/browser/composer-action-grid-reorder.spec.mjs +16 -0
  102. package/tests/browser/composer-disclosure.spec.mjs +389 -0
  103. package/tests/browser/composer-toolbar-polish.spec.mjs +343 -0
  104. package/tests/browser/control-deck-component-updates.spec.mjs +5 -14
  105. package/tests/browser/control-deck-side-panels.spec.mjs +27 -12
  106. package/tests/browser/control-visibility.spec.mjs +5 -0
  107. package/tests/browser/controls-layout.spec.mjs +21 -2
  108. package/tests/browser/conversation-overview.spec.mjs +251 -0
  109. package/tests/browser/draft-conversations.spec.mjs +276 -0
  110. package/tests/browser/empty-startup-fixture.mjs +135 -0
  111. package/tests/browser/empty-startup.spec.mjs +282 -0
  112. package/tests/browser/events-tree-context-menu.spec.mjs +1 -0
  113. package/tests/browser/focused-composer-more.spec.mjs +127 -0
  114. package/tests/browser/focused-model-shortcuts.spec.mjs +120 -0
  115. package/tests/browser/focused-navigation-fixture.mjs +32 -0
  116. package/tests/browser/focused-project-activity.spec.mjs +111 -0
  117. package/tests/browser/focused-shell-integration.spec.mjs +208 -0
  118. package/tests/browser/folder-picker-layout-fixture.mjs +13 -0
  119. package/tests/browser/folder-picker-layout.spec.mjs +302 -0
  120. package/tests/browser/footer-model-advanced-layout.spec.mjs +27 -14
  121. package/tests/browser/git-setup-cancel.spec.mjs +251 -0
  122. package/tests/browser/guided-git-fallback.spec.mjs +40 -21
  123. package/tests/browser/inspector-header.spec.mjs +221 -0
  124. package/tests/browser/inspector-overview-integration.spec.mjs +104 -0
  125. package/tests/browser/inspector-resize.spec.mjs +227 -0
  126. package/tests/browser/inspector-topic-overflow.spec.mjs +56 -0
  127. package/tests/browser/interaction-action-discovery.spec.mjs +332 -0
  128. package/tests/browser/interaction-attention-inbox.spec.mjs +364 -0
  129. package/tests/browser/interaction-attention-integration.spec.mjs +53 -0
  130. package/tests/browser/interaction-composer-controls.spec.mjs +267 -0
  131. package/tests/browser/interaction-composer-integration.spec.mjs +175 -0
  132. package/tests/browser/interaction-continuity.spec.mjs +50 -26
  133. package/tests/browser/interaction-model-picker.spec.mjs +86 -0
  134. package/tests/browser/last-terminal-close.spec.mjs +280 -0
  135. package/tests/browser/mobile-foundation.spec.mjs +172 -20
  136. package/tests/browser/model-catalog-groups.spec.mjs +104 -0
  137. package/tests/browser/more-row-menus.spec.mjs +258 -0
  138. package/tests/browser/new-tab-hit-target.spec.mjs +228 -0
  139. package/tests/browser/no-project-conversation.spec.mjs +113 -0
  140. package/tests/browser/optimistic-prompt.spec.mjs +3 -0
  141. package/tests/browser/overhaul-w7-accessibility.spec.mjs +227 -0
  142. package/tests/browser/overhaul-w7-capabilities.spec.mjs +298 -0
  143. package/tests/browser/overhaul-w7-companions.spec.mjs +290 -0
  144. package/tests/browser/overhaul-w7-focus-repairs.spec.mjs +210 -0
  145. package/tests/browser/overhaul-w7-layout-repairs.spec.mjs +183 -0
  146. package/tests/browser/overhaul-w7-parent-repairs.spec.mjs +97 -0
  147. package/tests/browser/overhaul-w7-pwa.spec.mjs +247 -0
  148. package/tests/browser/overhaul-w7-responsive.spec.mjs +450 -0
  149. package/tests/browser/overhaul-w7-update.spec.mjs +215 -0
  150. package/tests/browser/overhaul-w7-zoom.spec.mjs +243 -0
  151. package/tests/browser/overview-agent-ownership.spec.mjs +45 -0
  152. package/tests/browser/persistent-ui-layout.spec.mjs +3 -0
  153. package/tests/browser/project-artifact-controller.spec.mjs +324 -0
  154. package/tests/browser/project-artifact-integration.spec.mjs +103 -0
  155. package/tests/browser/project-file-buffer-integration.spec.mjs +230 -0
  156. package/tests/browser/project-git-tools-integration.spec.mjs +369 -0
  157. package/tests/browser/session-fixture.mjs +118 -0
  158. package/tests/browser/session-ownership.spec.mjs +175 -0
  159. package/tests/browser/session-shelves-integration.spec.mjs +219 -0
  160. package/tests/browser/session-shelves.spec.mjs +340 -0
  161. package/tests/browser/session-sidebar-resize.spec.mjs +138 -0
  162. package/tests/browser/session-summary.spec.mjs +17 -12
  163. package/tests/browser/settings-complete-home.spec.mjs +463 -0
  164. package/tests/browser/settings-entrypoint.spec.mjs +104 -0
  165. package/tests/browser/settings-navigation-controller.spec.mjs +383 -0
  166. package/tests/browser/settings-navigation-integration.spec.mjs +348 -0
  167. package/tests/browser/settings-resource-lifetime.spec.mjs +349 -0
  168. package/tests/browser/settings-workspace-integration.spec.mjs +132 -0
  169. package/tests/browser/shell-ownership.spec.mjs +398 -0
  170. package/tests/browser/shell-rollout-fixture.mjs +259 -0
  171. package/tests/browser/shell-rollout.spec.mjs +357 -0
  172. package/tests/browser/shell-tools-launcher.spec.mjs +260 -0
  173. package/tests/browser/shell-workspace.spec.mjs +433 -0
  174. package/tests/browser/side-panel-section-reorder.spec.mjs +3 -1
  175. package/tests/browser/sidebar-floating-tooltips.spec.mjs +37 -0
  176. package/tests/browser/sidebar-update-integration.spec.mjs +277 -0
  177. package/tests/browser/sidebar-update-menu.spec.mjs +402 -0
  178. package/tests/browser/sidebar-update-progress.spec.mjs +472 -0
  179. package/tests/browser/stream-output-isolation.spec.mjs +6 -3
  180. package/tests/browser/themed-selects.spec.mjs +297 -0
  181. package/tests/browser/thread-start-flow.spec.mjs +481 -0
  182. package/tests/browser/ui-polish-activity-controls.spec.mjs +177 -0
  183. package/tests/browser/ui-polish-features.spec.mjs +85 -0
  184. package/tests/browser/ui-polish-file-header.spec.mjs +43 -0
  185. package/tests/browser/ui-polish-local-git.spec.mjs +183 -0
  186. package/tests/browser/ui-polish-mobile-recovery.spec.mjs +36 -0
  187. package/tests/browser/ui-polish-navigation.spec.mjs +127 -0
  188. package/tests/browser/ui-polish-session-actions.spec.mjs +282 -0
  189. package/tests/browser/user-noticeable-fixes.spec.mjs +10 -3
  190. package/tests/browser/windows-drive-parent.spec.mjs +4 -2
  191. package/tests/browser/workspace-draft-selection.spec.mjs +266 -0
  192. package/tests/codex-fast-mode-static.test.mjs +16 -11
  193. package/tests/codex-speed-mode-browser-state.test.mjs +6 -3
  194. package/tests/codex-usage-source.test.mjs +4 -3
  195. package/tests/component-update-api-static.test.mjs +2 -2
  196. package/tests/composer-action-grid-reorder-static.test.mjs +3 -3
  197. package/tests/control-deck-component-updates-static.test.mjs +9 -4
  198. package/tests/control-visibility-static.test.mjs +3 -3
  199. package/tests/controls-layout-static.test.mjs +5 -5
  200. package/tests/conversation-overview-adapter.test.mjs +100 -0
  201. package/tests/document-artifact-static.test.mjs +2 -1
  202. package/tests/draft-conversations.test.mjs +205 -0
  203. package/tests/empty-startup-launcher.test.mjs +197 -0
  204. package/tests/events-tree-context-menu-static.test.mjs +22 -18
  205. package/tests/fake-pi-session-ownership.test.mjs +302 -0
  206. package/tests/fast-mode-client-static.test.mjs +1 -1
  207. package/tests/feature-decision-output-popup-static.test.mjs +2 -2
  208. package/tests/feature-system-prompt-optional-feature-static.test.mjs +1 -1
  209. package/tests/file-viewer-image-static.test.mjs +15 -11
  210. package/tests/file-viewer-search-static.test.mjs +5 -5
  211. package/tests/fixtures/fake-pi.mjs +41 -9
  212. package/tests/footer-provider-usage-visual-static.test.mjs +7 -6
  213. package/tests/foreground-transcript-catch-up-static.test.mjs +7 -4
  214. package/tests/git-footer-context-menu-static.test.mjs +1 -1
  215. package/tests/git-panel-file-preview-static.test.mjs +41 -48
  216. package/tests/git-panel-live-updates-static.test.mjs +2 -1
  217. package/tests/git-workflow-dispatch.test.mjs +66 -0
  218. package/tests/git-workflow-preferences.test.mjs +9 -1
  219. package/tests/guided-git-activation-static.test.mjs +14 -11
  220. package/tests/guided-git-fallback-ui-static.test.mjs +8 -5
  221. package/tests/guided-git-message-reliability-static.test.mjs +10 -6
  222. package/tests/guided-git-publication-backend-static.test.mjs +16 -11
  223. package/tests/http-endpoints-harness.test.mjs +21 -9
  224. package/tests/interaction-state-stability-static.test.mjs +4 -3
  225. package/tests/intercom-conversation-viewer-static.test.mjs +29 -17
  226. package/tests/intercom-tag-layout-static.test.mjs +13 -12
  227. package/tests/intercom-tag-overflow-layout.test.mjs +11 -10
  228. package/tests/main-output-loading-static.test.mjs +4 -4
  229. package/tests/middle-button-drag-scroll-static.test.mjs +3 -3
  230. package/tests/mobile-compact-layout.test.mjs +2 -2
  231. package/tests/mobile-continuity-tablet-static.test.mjs +3 -3
  232. package/tests/mobile-foundation-static.test.mjs +10 -7
  233. package/tests/mobile-phone-experience-static.test.mjs +3 -2
  234. package/tests/mobile-static.test.mjs +173 -135
  235. package/tests/model-catalog-order.test.mjs +103 -0
  236. package/tests/native-parity.test.mjs +6 -4
  237. package/tests/native-session-choice-owner.test.mjs +102 -0
  238. package/tests/native-update-lifecycle.test.mjs +10 -5
  239. package/tests/no-project-http-harness.test.mjs +328 -0
  240. package/tests/no-project-navigation.test.mjs +54 -0
  241. package/tests/no-project-workspaces.test.mjs +77 -0
  242. package/tests/open-issue-wizard-static.test.mjs +1 -1
  243. package/tests/optional-feature-migration-frontend.test.mjs +4 -4
  244. package/tests/optional-feature-prompt-impact-static.test.mjs +3 -3
  245. package/tests/package-updates.test.mjs +630 -0
  246. package/tests/persistent-ui-layout-static.test.mjs +3 -3
  247. package/tests/platform-event-stream.test.mjs +253 -0
  248. package/tests/project-file-viewer-controller.test.mjs +652 -0
  249. package/tests/project-git-tools-adapter.test.mjs +103 -0
  250. package/tests/project-git-tools-controller.test.mjs +577 -0
  251. package/tests/project-runners-controller.test.mjs +453 -0
  252. package/tests/prompt-input-vertical-scroll-static.test.mjs +3 -3
  253. package/tests/prompt-routing-input-clear-static.test.mjs +2 -2
  254. package/tests/questionnaire-dialog.test.mjs +6 -6
  255. package/tests/queue-edit-reorder-static.test.mjs +48 -51
  256. package/tests/rpc-supervisor-host.test.mjs +4 -1
  257. package/tests/safety-guard-auto-review-static.test.mjs +1 -1
  258. package/tests/sampling-native-controls-user-flow.test.mjs +7 -1
  259. package/tests/server-app-runners.test.mjs +536 -0
  260. package/tests/server-codex-fast-mode.test.mjs +346 -0
  261. package/tests/server-conversation-mode.test.mjs +386 -0
  262. package/tests/server-conversation-voice.test.mjs +426 -0
  263. package/tests/server-extension-ui-requests.test.mjs +357 -0
  264. package/tests/server-git-generation.test.mjs +558 -0
  265. package/tests/server-git-mutations.test.mjs +729 -0
  266. package/tests/server-git-reads.test.mjs +381 -0
  267. package/tests/server-git-worktree-sessions.test.mjs +502 -0
  268. package/tests/server-helper-requests.test.mjs +364 -0
  269. package/tests/server-rpc-transports.test.mjs +553 -0
  270. package/tests/server-settings-store.test.mjs +132 -0
  271. package/tests/server-shell-rollout.test.mjs +478 -0
  272. package/tests/server-sse-delivery.test.mjs +410 -0
  273. package/tests/server-workspace-files.test.mjs +546 -0
  274. package/tests/session-attention-scheduler.test.mjs +514 -0
  275. package/tests/session-composer-store.test.mjs +153 -0
  276. package/tests/session-context.test.mjs +134 -0
  277. package/tests/session-extension-requests.test.mjs +193 -0
  278. package/tests/session-ownership-adapter.test.mjs +130 -0
  279. package/tests/session-sampling-ui-static.test.mjs +10 -4
  280. package/tests/session-send-lifetime.test.mjs +140 -0
  281. package/tests/session-shelf-state.test.mjs +348 -0
  282. package/tests/session-shelves-adapter.test.mjs +79 -0
  283. package/tests/session-summary-lifetime.test.mjs +54 -0
  284. package/tests/settings-resource-controller.test.mjs +548 -0
  285. package/tests/shell-action-adapter.test.mjs +169 -0
  286. package/tests/shell-actions.test.mjs +182 -0
  287. package/tests/shell-navigation.test.mjs +348 -0
  288. package/tests/shell-preferences.test.mjs +367 -0
  289. package/tests/side-panel-section-height-removal-static.test.mjs +3 -3
  290. package/tests/stream-output-isolation-static.test.mjs +1 -1
  291. package/tests/subagent-gate-visibility.test.mjs +1 -1
  292. package/tests/subagent-launch-slot-state.test.mjs +2 -2
  293. package/tests/subagent-launch-slots-static.test.mjs +1 -1
  294. package/tests/subagent-observability-static.test.mjs +2 -2
  295. package/tests/subagent-reliability-integration.test.mjs +13 -30
  296. package/tests/syntax-highlighting-static.test.mjs +3 -3
  297. package/tests/tab-close-continuity-static.test.mjs +1 -1
  298. package/tests/tab-metadata-ordering.test.mjs +99 -0
  299. package/tests/terminal-cwd-grouping-static.test.mjs +2 -2
  300. package/tests/terminal-tab-prompt-tooltip-static.test.mjs +2 -0
  301. package/tests/terminal-tab-workspace-static.test.mjs +5 -4
  302. package/tests/terminal-tabs-resize-static.test.mjs +1 -1
  303. package/tests/theme-customizer-static.test.mjs +1 -1
  304. package/tests/thread-display-title.test.mjs +44 -0
  305. package/tests/update-api-harness.test.mjs +15 -14
  306. package/tests/update-tab-restore-harness.test.mjs +3 -0
  307. package/tests/webui-settings-locking.test.mjs +2 -2
  308. package/tests/windows-drive-cwd-picker-static.test.mjs +7 -9
  309. package/tests/workspace-choices.test.mjs +114 -0
  310. package/tests/workspace-save-load-static.test.mjs +7 -4
@@ -0,0 +1,729 @@
1
+ import assert from "node:assert/strict";
2
+ import { execFileSync } from "node:child_process";
3
+ import { createHash } from "node:crypto";
4
+ import { chmod, link, mkdir, mkdtemp, readFile, rm, stat, symlink, writeFile } from "node:fs/promises";
5
+ import { tmpdir } from "node:os";
6
+ import path from "node:path";
7
+ import { after, test } from "node:test";
8
+ import { setTimeout as delay } from "node:timers/promises";
9
+ import * as mutations from "../lib/server/git-mutations.mjs";
10
+ import { readStableGitMessageArtifactPair } from "../lib/git-message-artifacts.mjs";
11
+
12
+ const gitConfigRoot = await mkdtemp(path.join(tmpdir(), "webui-g2-config-"));
13
+ const previousGitEnvironment = {
14
+ GIT_CONFIG_GLOBAL: process.env.GIT_CONFIG_GLOBAL,
15
+ GIT_CONFIG_NOSYSTEM: process.env.GIT_CONFIG_NOSYSTEM,
16
+ };
17
+ process.env.GIT_CONFIG_GLOBAL = path.join(gitConfigRoot, "empty.gitconfig");
18
+ process.env.GIT_CONFIG_NOSYSTEM = "1";
19
+ after(async () => {
20
+ for (const [name, value] of Object.entries(previousGitEnvironment)) {
21
+ if (value === undefined) delete process.env[name];
22
+ else process.env[name] = value;
23
+ }
24
+ await rm(gitConfigRoot, { recursive: true, force: true });
25
+ });
26
+
27
+ const { createGitMutationService, formatGitCommand } = mutations;
28
+ const realGit = process.platform === "win32" ? "git" : execFileSync("which", ["git"], { encoding: "utf8" }).trim();
29
+ const summary = { staged: 0, unstaged: 0, untracked: 0, conflicted: 0, ahead: 0, behind: 0 };
30
+ const expectedMethods = `addGitignoreEntry switchGitBranch pullGitChanges fetchGitChanges integrateGitUpstream gitOperationStageFile gitOperationAction gitBisectAction saveGitStash applyGitStash dropGitStash stageGitFile unstageGitFile stageAllGitChanges unstageAllGitChanges discardGitFile deleteGitUntrackedFile undoLastGitCommit amendLastGitCommitMessage updateGitSubmodules createGitTag gitAddAllPayload readGitOperationSnapshot readGitStashes readGitStashPreview readGitUndoState readGitReflog readGitSubmodules readGitTags readGitSigningDiagnostics readGitBranches readGitWorkflowBranchName readGitWorkflowMessages readGitWorkflowDefaultCommitMessage readGitWorkflowPrDescription initialRepositoryFilesStatus prepareInitialRepositoryFiles readStagedContentHash stagedContentHashForTab expectedStagedContentHashFromBody assertExpectedStagedContentHash gitWorkflowMessageCwd commitMessagePaths cleanGitBranchName validateGitBranchName requestedRemoteRef verifyRemoteGitBranchIntent runGitWorkflowCommand requireConfirmed initializeGitRepository initialGitCommit renameGitMainBranch addGitOrigin pushInitialGitMain commitGitWorkflow pushGitWorkflow publishGitRepository createGitWorkflowPr cancelGitWorkflowProcess`.split(" ");
31
+
32
+ function git(cwd, ...args) {
33
+ return execFileSync(realGit, args, { cwd, encoding: "utf8", timeout: 5000, stdio: ["ignore", "pipe", "pipe"] });
34
+ }
35
+
36
+ function resolveRelative(root, relative) {
37
+ const resolved = path.resolve(root, relative);
38
+ assert.ok(resolved.startsWith(`${root}${path.sep}`), "test paths must stay inside their disposable repository");
39
+ return resolved;
40
+ }
41
+
42
+ // These are transport adapters and explicit G1 boundary stubs. Parsing remains
43
+ // injected; this suite neither implements nor loads a second status parser.
44
+ function service(root, overrides = {}) {
45
+ const runGitReadCommand = async (cwd, args) => git(cwd, ...args);
46
+ return createGitMutationService({
47
+ runCommand: async (command, args, { cwd }) => {
48
+ assert.equal(command, "git");
49
+ try {
50
+ return { exitCode: 0, stdout: git(cwd, ...args), stderr: "" };
51
+ } catch (error) {
52
+ return { exitCode: error.status, stdout: String(error.stdout || ""), stderr: String(error.stderr || "") };
53
+ }
54
+ },
55
+ makeHttpError: (statusCode, message) => Object.assign(new Error(message), { statusCode }),
56
+ makeUserFacingError: (message) => new Error(message),
57
+ formatBytes: (value) => `${value} bytes`,
58
+ sanitizeError: (error) => error.message,
59
+ formatCliError: (error) => error.message,
60
+ formatCommandSpawnError: (command, error) => `${command}: ${error.code}`,
61
+ getGitRoot: async () => root,
62
+ runGitReadCommand,
63
+ runGitReadCommandDetailed: async (cwd, args) => ({ output: await runGitReadCommand(cwd, args), truncated: false }),
64
+ readGitChanges: async (cwd) => ({ root: cwd, boundary: "G1" }),
65
+ resolveGitRelativePath: resolveRelative,
66
+ normalizeGitRelativePath: (cwd, relative) => path.relative(cwd, resolveRelative(cwd, relative)).split(path.sep).join("/"),
67
+ isLikelyBinaryBuffer: (buffer) => buffer.includes(0),
68
+ parseGitPorcelainZEntries: () => { throw new Error("Supply G1 parser output for this test"); },
69
+ gitBranchFromPorcelainStatus: () => "main",
70
+ summarizeGitPorcelainStatus: () => ({ ...summary }),
71
+ gitUpstreamRef: async () => "",
72
+ ...overrides,
73
+ });
74
+ }
75
+
76
+ async function disposable(t, { initialized = true } = {}) {
77
+ const root = await mkdtemp(path.join(tmpdir(), "webui-g2-"));
78
+ t.after(() => rm(root, { recursive: true, force: true }));
79
+ if (initialized) {
80
+ git(root, "init", "-q", "-b", "main");
81
+ git(root, "config", "user.name", "G2 Test");
82
+ git(root, "config", "user.email", "g2@example.invalid");
83
+ git(root, "config", "commit.gpgsign", "false");
84
+ git(root, "config", "core.autocrlf", "false");
85
+ }
86
+ return root;
87
+ }
88
+
89
+ async function baseCommit(root) {
90
+ await writeFile(path.join(root, "tracked.txt"), "base\n");
91
+ git(root, "add", "--", "tracked.txt");
92
+ git(root, "commit", "-qm", "base");
93
+ }
94
+
95
+ async function waitForFile(file) {
96
+ const deadline = Date.now() + 4000;
97
+ while (Date.now() < deadline) {
98
+ try { return await readFile(file, "utf8"); } catch (error) {
99
+ if (error.code !== "ENOENT") throw error;
100
+ }
101
+ await delay(10);
102
+ }
103
+ throw new Error(`Fake command did not reach its bounded checkpoint: ${file}`);
104
+ }
105
+
106
+ async function fakeCommands(t, initial = {}) {
107
+ const root = await disposable(t, { initialized: false });
108
+ const bin = path.join(root, "bin");
109
+ await mkdir(bin);
110
+ const configFile = path.join(root, "config.json");
111
+ const logFile = path.join(root, "commands.jsonl");
112
+ const executable = `#!${process.execPath}
113
+ const fs = require('node:fs');
114
+ const path = require('node:path');
115
+ const { spawn } = require('node:child_process');
116
+ const root = path.dirname(__dirname);
117
+ const config = JSON.parse(fs.readFileSync(path.join(root, 'config.json'), 'utf8'));
118
+ const args = process.argv.slice(2);
119
+ const command = path.basename(process.argv[1]);
120
+ fs.appendFileSync(path.join(root, 'commands.jsonl'), JSON.stringify({command, args, cwd:process.cwd(), env:{LC_ALL:process.env.LC_ALL,GIT_TERMINAL_PROMPT:process.env.GIT_TERMINAL_PROMPT,GH_PROMPT_DISABLED:process.env.GH_PROMPT_DISABLED,GIT_OPTIONAL_LOCKS:process.env.GIT_OPTIONAL_LOCKS,GIT_CONFIG_NOSYSTEM:process.env.GIT_CONFIG_NOSYSTEM}})+'\\n');
121
+ if (args[0] === 'hold' || (command === 'gh' && config.holdGh) || (args[0] === 'add' && config.holdAdd)) {
122
+ process.on('SIGTERM', () => { fs.writeFileSync(path.join(root,'terminated'),'yes'); if (!config.ignoreTerm) { process.stdout.write('cancel-tail'); process.exit(0); } });
123
+ fs.writeFileSync(path.join(root,'ready'),'yes');
124
+ setTimeout(() => process.exit(90), 5000);
125
+ } else if (args[0] === 'drain') {
126
+ spawn(process.execPath,['-e',"setTimeout(()=>{process.stdout.write('late-tail');process.stderr.write('late-error')},500)"],{stdio:['ignore',1,2]});
127
+ fs.writeFileSync(path.join(root,'ready'),'yes');
128
+ } else if (args[0] === 'flood') {
129
+ process.stdout.write('x'.repeat(120000)+'stdout-tail');
130
+ process.stderr.write('y'.repeat(120000)+'stderr-tail');
131
+ } else if (args.includes('--cached') && args.includes('diff')) {
132
+ process.stdout.write(config.largeHash ? Buffer.alloc(4*1024*1024+1, 120) : Buffer.from(config.hashBytes || '', 'base64'));
133
+ process.exitCode = config.hashExit || 0;
134
+ } else if (args[0] === 'branch' && args[1] === '--show-current') {
135
+ process.stdout.write(config.branch === undefined ? 'main\\n' : config.branch);
136
+ } else if (args[0] === 'remote' && args.length === 1) {
137
+ process.stdout.write((config.remotes || []).join('\\n'));
138
+ } else if (args[0] === 'add' && config.lockFailures) {
139
+ const counter = path.join(root, 'attempts');
140
+ const attempt = fs.existsSync(counter) ? Number(fs.readFileSync(counter,'utf8'))+1 : 1;
141
+ fs.writeFileSync(counter,String(attempt));
142
+ if (attempt <= config.lockFailures) { process.stderr.write('fatal: Unable to create index.lock: File exists'); process.exitCode=128; }
143
+ } else if (config.failure && (args[0] === 'push' || command === 'gh' || args[0] === config.failCommand)) {
144
+ process.stderr.write(config.failure); process.exitCode = 1;
145
+ } else {
146
+ process.stdout.write('done\\n');
147
+ }
148
+ `;
149
+ await writeFile(configFile, JSON.stringify(initial));
150
+ for (const name of ["git", "gh"]) {
151
+ const file = path.join(bin, name);
152
+ await writeFile(file, executable);
153
+ await chmod(file, 0o755);
154
+ }
155
+ const previousPath = process.env.PATH;
156
+ process.env.PATH = bin;
157
+ t.after(() => {
158
+ if (previousPath === undefined) delete process.env.PATH;
159
+ else process.env.PATH = previousPath;
160
+ });
161
+ return {
162
+ root,
163
+ service: service(root),
164
+ configure: (config) => writeFile(configFile, JSON.stringify(config)),
165
+ log: async () => (await readFile(logFile, "utf8")).trim().split("\n").filter(Boolean).map((line) => JSON.parse(line)),
166
+ };
167
+ }
168
+
169
+ const unixOnly = { skip: process.platform === "win32" ? "POSIX fake executable and signal behavior; Windows requires native executable fixtures" : false, timeout: 15000 };
170
+
171
+ test("factory exposes the complete G2 contract and the formatter stays pure", () => {
172
+ assert.deepEqual(Object.keys(mutations).sort(), ["createGitMutationService", "formatGitCommand"]);
173
+ assert.deepEqual(Object.keys(service("/unused")).sort(), [...expectedMethods].sort());
174
+ assert.equal(formatGitCommand(["commit", "-m", "two words\nand a quote\""]), 'git commit -m "two words\\nand a quote\\\""');
175
+ assert.equal(service("/unused").cancelGitWorkflowProcess(), false);
176
+ });
177
+
178
+ test("staged hashes retain exact binary diff bytes, unborn/empty behavior and approval checks", async (t) => {
179
+ const root = await disposable(t);
180
+ const api = service(root);
181
+ assert.deepEqual(await api.readStagedContentHash(root), { stagedDiff: Buffer.alloc(0), hasStagedChanges: false, stagedContentHash: null });
182
+ await writeFile(path.join(root, "raw.bin"), Buffer.from([0, 255, 128, 10]));
183
+ git(root, "add", ".");
184
+ const args = ["-c", "core.quotepath=false", "-c", "diff.external=", "diff", "--cached", "--binary", "--full-index", "--no-ext-diff", "--no-textconv", "--no-renames", "--"];
185
+ const bytes = execFileSync(realGit, args, { cwd: root, timeout: 5000 });
186
+ const expected = createHash("sha256").update("firstpick/aur-review/staged-content/v1\0").update(bytes).digest("hex");
187
+ const captured = await api.readStagedContentHash(root);
188
+ assert.deepEqual(captured.stagedDiff, bytes);
189
+ assert.equal(captured.stagedContentHash, expected);
190
+ assert.equal(await api.assertExpectedStagedContentHash({ cwd: root }, { expectedStagedContentHash: expected }), expected);
191
+ assert.equal(await api.assertExpectedStagedContentHash({ cwd: "/does-not-exist" }), "");
192
+ for (const expectedStagedContentHash of [null, "", 42, "f".repeat(63)]) {
193
+ assert.throws(() => api.expectedStagedContentHashFromBody({ expectedStagedContentHash }), { statusCode: 400 });
194
+ }
195
+ await assert.rejects(api.assertExpectedStagedContentHash({ cwd: root }, { expectedStagedContentHash: "0".repeat(64) }), { statusCode: 409 });
196
+ await api.unstageAllGitChanges(root);
197
+ await assert.rejects(api.assertExpectedStagedContentHash({ cwd: root }, { expectedStagedContentHash: expected }), { statusCode: 409 });
198
+ });
199
+
200
+ test("raw hash subprocess preserves non-UTF8 bytes, limits and independent command admission", unixOnly, async (t) => {
201
+ const raw = Buffer.from([255, 254, 0, 128, 10]);
202
+ const fake = await fakeCommands(t, { hashBytes: raw.toString("base64") });
203
+ const pending = fake.service.runGitWorkflowCommand(["hold"], { cwd: fake.root });
204
+ t.after(() => fake.service.cancelGitWorkflowProcess());
205
+ await waitForFile(path.join(fake.root, "ready"));
206
+ assert.deepEqual((await fake.service.readStagedContentHash(fake.root)).stagedDiff, raw);
207
+ const hashCommand = (await fake.log()).find((entry) => entry.args.includes("--cached"));
208
+ assert.equal(hashCommand.env.GIT_OPTIONAL_LOCKS, "0");
209
+ assert.equal(hashCommand.env.GIT_CONFIG_NOSYSTEM, "1");
210
+ await fake.configure({ largeHash: true });
211
+ await assert.rejects(fake.service.readStagedContentHash(fake.root), /4 MiB staged-content safety limit/);
212
+ await fake.configure({ hashExit: 3 });
213
+ await assert.rejects(fake.service.readStagedContentHash(fake.root), /failed with exit code 3/);
214
+ assert.equal(fake.service.cancelGitWorkflowProcess(), true);
215
+ assert.equal((await pending).cancelled, true);
216
+ });
217
+
218
+ test("gitignore mutations preserve bytes, newline style, escaping and canonical-root serialization", async (t) => {
219
+ const root = await disposable(t);
220
+ const original = Buffer.from([35, 255, 13, 10, 120]);
221
+ await writeFile(path.join(root, ".gitignore"), original);
222
+ const api = service(root);
223
+ const added = await api.addGitignoreEntry(root, { path: "folder/a [b]*?.txt", kind: "file" });
224
+ assert.equal(added.entry, "/folder/a\\ \\[b\\]\\*\\?.txt");
225
+ assert.equal(added.added, true);
226
+ assert.deepEqual(await readFile(path.join(root, ".gitignore")), Buffer.concat([original, Buffer.from(`\r\n${added.entry}\r\n`)]));
227
+ assert.equal((await api.addGitignoreEntry(root, { path: added.path, kind: "file" })).added, false);
228
+ let alias = root;
229
+ if (process.platform !== "win32") {
230
+ alias = `${root}-alias`;
231
+ await symlink(root, alias);
232
+ t.after(() => rm(alias, { force: true }));
233
+ }
234
+ const other = service(alias);
235
+ const same = await Promise.all(Array.from({ length: 12 }, (_, i) => (i % 2 ? api : other).addGitignoreEntry(root, { path: "same", kind: "folder" })));
236
+ assert.equal(same.filter((result) => result.added).length, 1);
237
+ await Promise.all(Array.from({ length: 8 }, (_, i) => api.addGitignoreEntry(root, { path: `unique-${i}`, kind: "file" })));
238
+ const text = await readFile(path.join(root, ".gitignore"), "latin1");
239
+ for (let i = 0; i < 8; i++) assert.ok(text.includes(`/unique-${i}\r\n`));
240
+ for (const invalid of ["../escape", "/absolute", "C:\\absolute", ".", "a\nb", "a/./b"]) {
241
+ await assert.rejects(api.addGitignoreEntry(root, { path: invalid, kind: "file" }), { statusCode: 400 });
242
+ }
243
+ await assert.rejects(api.addGitignoreEntry(root, { path: "valid", kind: "unknown" }), { statusCode: 400 });
244
+ assert.equal((await api.addGitignoreEntry(root, { path: "after-rejection", kind: "file" })).added, true);
245
+ });
246
+
247
+ test("gitignore rejects links and oversized files without changing their content", async (t) => {
248
+ const root = await disposable(t);
249
+ const api = service(root);
250
+ const target = path.join(root, ".gitignore");
251
+ const outside = path.join(root, "outside");
252
+ await writeFile(outside, "preserve\n");
253
+ if (process.platform !== "win32") {
254
+ await symlink(outside, target);
255
+ await assert.rejects(api.addGitignoreEntry(root, { path: "x", kind: "file" }), /symbolic link/);
256
+ await rm(target);
257
+ await link(outside, target);
258
+ await assert.rejects(api.addGitignoreEntry(root, { path: "x", kind: "file" }), /exactly one hard link/);
259
+ assert.equal(await readFile(outside, "utf8"), "preserve\n");
260
+ await rm(target);
261
+ }
262
+ await writeFile(target, Buffer.alloc(5 * 1024 * 1024 + 1, 120));
263
+ const before = await stat(target);
264
+ await assert.rejects(api.addGitignoreEntry(root, { path: "x", kind: "file" }), /safe modification limit/);
265
+ assert.equal((await stat(target)).size, before.size);
266
+ });
267
+
268
+ test("file mutation success and failures retain confirmation and unborn-index behavior", async (t) => {
269
+ const root = await disposable(t);
270
+ const api = service(root);
271
+ await writeFile(path.join(root, "tracked.txt"), "base\n");
272
+ assert.equal((await api.stageGitFile(root, { path: "tracked.txt" })).ok, true);
273
+ assert.equal((await api.unstageGitFile(root, { path: "tracked.txt" })).ok, true);
274
+ assert.equal(git(root, "ls-files"), "");
275
+ assert.equal((await api.stageAllGitChanges(root)).ok, true);
276
+ assert.equal((await api.initialGitCommit(root)).ok, true);
277
+ await writeFile(path.join(root, "tracked.txt"), "changed\n");
278
+ await assert.rejects(api.discardGitFile(root, { path: "tracked.txt" }), { statusCode: 409 });
279
+ assert.equal((await api.discardGitFile(root, { path: "tracked.txt", confirmed: true })).ok, true);
280
+ assert.equal(await readFile(path.join(root, "tracked.txt"), "utf8"), "base\n");
281
+ await assert.rejects(api.deleteGitUntrackedFile(root, { path: "tracked.txt", confirmed: true }), { statusCode: 409 });
282
+ await writeFile(path.join(root, "untracked.txt"), "delete me");
283
+ assert.equal((await api.deleteGitUntrackedFile(root, { path: "untracked.txt", confirmed: true })).data.deleted, true);
284
+ assert.equal((await api.stageGitFile(root, { path: "absent.txt" })).ok, false);
285
+ });
286
+
287
+ test("initialization and initial files preserve existing content and use exact Git mutations", async (t) => {
288
+ const root = await disposable(t, { initialized: false });
289
+ const api = service(root);
290
+ assert.equal((await api.initializeGitRepository(root)).ok, true);
291
+ await assert.rejects(api.initializeGitRepository(root), /Already inside a git repository/);
292
+ await writeFile(path.join(root, "README.md"), "Keep this readme\n");
293
+ await writeFile(path.join(root, "package.json"), JSON.stringify({ dependencies: { react: "*" } }));
294
+ const result = await api.prepareInitialRepositoryFiles(root, { stack: "Python" });
295
+ assert.equal(result.ok, true);
296
+ assert.equal(result.data.readme.created, false);
297
+ assert.equal(await readFile(path.join(root, "README.md"), "utf8"), "Keep this readme\n");
298
+ assert.match(await readFile(path.join(root, ".gitignore"), "utf8"), /node_modules\/.*__pycache__\//s);
299
+ assert.equal((await api.prepareInitialRepositoryFiles(root)).data.gitignore.created, false);
300
+ assert.deepEqual(git(root, "diff", "--cached", "--name-only").trim().split("\n").sort(), [".gitignore", "README.md"]);
301
+ assert.equal((await api.renameGitMainBranch(root)).ok, true);
302
+ const remote = await api.addGitOrigin(root, { username: "@example-user", repoName: "https://github.com/example/repo.git" });
303
+ assert.equal(remote.data.remoteUrl, "https://github.com/example-user/repo.git");
304
+ assert.equal(git(root, "remote", "get-url", "origin").trim(), remote.data.remoteUrl);
305
+ await assert.rejects(api.addGitOrigin(root, { username: "bad--user", repoName: "repo" }), /Invalid GitHub username/);
306
+ });
307
+
308
+ test("commit validates variant before hashing, detects drift and preserves all three message variants", async (t) => {
309
+ const root = await disposable(t);
310
+ let requestedCwd;
311
+ const api = service(root, { getGitRoot: async (cwd) => { requestedCwd = cwd; return root; } });
312
+ await assert.rejects(api.commitGitWorkflow(root, { variant: "wrong", expectedStagedContentHash: null }), /variant must/);
313
+ assert.equal(requestedCwd, undefined);
314
+ await writeFile(path.join(root, "tracked.txt"), "one\n");
315
+ git(root, "add", "tracked.txt");
316
+ const approved = (await api.stagedContentHashForTab({ cwd: root })).stagedContentHash;
317
+ await assert.rejects(api.commitGitWorkflow(root, { variant: "input", message: "blocked", expectedStagedContentHash: "0".repeat(64) }), { statusCode: 409 });
318
+ const subdir = path.join(root, "sub");
319
+ await mkdir(subdir);
320
+ assert.equal((await api.commitGitWorkflow(subdir, { variant: "input", message: "input message", expectedStagedContentHash: approved })).ok, true);
321
+ assert.equal(requestedCwd, subdir);
322
+ assert.equal(git(root, "log", "-1", "--format=%s").trim(), "input message");
323
+ const paths = api.commitMessagePaths(root);
324
+ await mkdir(path.dirname(paths.shortPath), { recursive: true });
325
+ await writeFile(paths.shortPath, "short message\n");
326
+ await writeFile(paths.longPath, "long subject\n\nlong body\n");
327
+ for (const variant of ["short", "long"]) {
328
+ await writeFile(path.join(root, "tracked.txt"), `${variant}\n`);
329
+ git(root, "add", "tracked.txt");
330
+ assert.equal((await api.commitGitWorkflow(root, { variant })).ok, true);
331
+ assert.equal(git(root, "log", "-1", "--format=%s").trim(), variant === "short" ? "short message" : "long subject");
332
+ }
333
+ await writeFile(paths.shortPath, "\n");
334
+ await assert.rejects(api.commitGitWorkflow(root, { variant: "short" }), /is empty/);
335
+ await assert.rejects(api.commitGitWorkflow(root, { variant: "input", message: "a\0b" }), /NUL byte/);
336
+ });
337
+
338
+ test("artifact readers retain root paths, readiness and injected default-message parsing", async (t) => {
339
+ const root = await disposable(t);
340
+ const entries = [{ x: "A", y: " ", path: "file.txt" }];
341
+ const api = service(root, { parseGitPorcelainZEntries: () => entries });
342
+ const paths = api.commitMessagePaths(root);
343
+ await mkdir(path.dirname(paths.shortPath), { recursive: true });
344
+ assert.equal((await api.readGitWorkflowMessages(root, { generationId: "gone" })).expired, true);
345
+ await writeFile(paths.shortPath, "short\n");
346
+ await writeFile(paths.longPath, "long\n");
347
+ await writeFile(paths.branchPath, "\nfeature/example\n");
348
+ assert.equal((await api.readGitWorkflowBranchName(root)).branch, "feature/example");
349
+ await assert.rejects(api.readGitWorkflowBranchName(root, { generationId: "bad" }), /no longer active/);
350
+ const generation = { id: "commit-1", kind: "commit", cwd: root, terminal: false };
351
+ assert.equal((await api.readGitWorkflowMessages(root, { generationId: generation.id, generation })).running, true);
352
+ generation.terminal = true;
353
+ generation.successful = false;
354
+ assert.equal((await api.readGitWorkflowMessages(root, { generationId: generation.id, generation })).expired, true);
355
+ generation.successful = true;
356
+ generation.baseline = await readStableGitMessageArtifactPair(paths);
357
+ assert.equal((await api.readGitWorkflowMessages(root, { generationId: generation.id, generation })).ready, false);
358
+ await writeFile(paths.shortPath, "fresh short\n");
359
+ await writeFile(paths.longPath, "fresh long\n");
360
+ assert.equal((await api.readGitWorkflowMessages(root, { generationId: generation.id, generation })).ready, true);
361
+ assert.equal((await api.readGitWorkflowDefaultCommitMessage(root)).message, "created file.txt");
362
+ entries.push({ x: "M", y: " ", path: "other.txt" });
363
+ assert.equal((await api.readGitWorkflowDefaultCommitMessage(root)).message, "");
364
+ assert.equal(api.gitWorkflowMessageCwd(root, path.join(root, "nested")), root);
365
+ assert.throws(() => api.gitWorkflowMessageCwd(root, path.dirname(root)), /must stay inside/);
366
+ });
367
+
368
+ test("the global Git/gh slot waits for pipe close and retains complete output tails and environment", unixOnly, async (t) => {
369
+ const fake = await fakeCommands(t);
370
+ const second = service(fake.root);
371
+ const pending = fake.service.runGitWorkflowCommand(["drain"], { cwd: fake.root, label: "draining command" });
372
+ await waitForFile(path.join(fake.root, "ready"));
373
+ await assert.rejects(second.runGitWorkflowCommand(["unused"], { cwd: fake.root }), /already running: draining command/);
374
+ const busy = await second.stageGitFile(fake.root, { path: "file" });
375
+ assert.equal(busy.code, "REPO_BUSY");
376
+ const drained = await pending;
377
+ assert.equal(drained.stdout, "late-tail");
378
+ assert.equal(drained.stderr, "late-error");
379
+ assert.equal(drained.exitCode, 0);
380
+ const flood = await second.runGitWorkflowCommand(["flood"], { cwd: fake.root });
381
+ assert.equal(flood.stdout.length, 100000);
382
+ assert.equal(flood.stderr.length, 100000);
383
+ assert.ok(flood.stdout.endsWith("stdout-tail"));
384
+ assert.ok(flood.stderr.endsWith("stderr-tail"));
385
+ const entry = (await fake.log())[0];
386
+ assert.equal(entry.env.LC_ALL, "C");
387
+ assert.equal(entry.env.GIT_TERMINAL_PROMPT, process.env.GIT_TERMINAL_PROMPT || "0");
388
+ assert.equal(entry.env.GH_PROMPT_DISABLED, process.env.GH_PROMPT_DISABLED || "1");
389
+ assert.equal(second.cancelGitWorkflowProcess(), false);
390
+ });
391
+
392
+ test("cancellation is synchronous, returns occupied state and keeps the slot until child close", unixOnly, async (t) => {
393
+ const fake = await fakeCommands(t);
394
+ const pending = fake.service.runGitWorkflowCommand(["hold"], { cwd: fake.root });
395
+ t.after(() => fake.service.cancelGitWorkflowProcess());
396
+ await waitForFile(path.join(fake.root, "ready"));
397
+ const cancelResult = fake.service.cancelGitWorkflowProcess();
398
+ assert.equal(cancelResult, true);
399
+ assert.equal(cancelResult instanceof Promise, false);
400
+ assert.equal(fake.service.cancelGitWorkflowProcess(), true);
401
+ await assert.rejects(service(fake.root).runGitWorkflowCommand(["unused"], { cwd: fake.root }), /already running/);
402
+ const result = await pending;
403
+ assert.equal(result.cancelled, true);
404
+ assert.equal(result.timedOut, false);
405
+ assert.equal(result.stdout, "cancel-tail");
406
+ assert.equal(fake.service.cancelGitWorkflowProcess(), false);
407
+ assert.equal((await fake.service.runGitWorkflowCommand(["next"], { cwd: fake.root })).exitCode, 0);
408
+ });
409
+
410
+ test("timeout escalates after the existing kill grace and releases the slot", unixOnly, async (t) => {
411
+ const fake = await fakeCommands(t, { ignoreTerm: true });
412
+ const pending = fake.service.runGitWorkflowCommand(["hold"], { cwd: fake.root, timeoutMs: 300 });
413
+ t.after(() => fake.service.cancelGitWorkflowProcess());
414
+ await waitForFile(path.join(fake.root, "ready"));
415
+ const started = Date.now();
416
+ await waitForFile(path.join(fake.root, "terminated"));
417
+ await assert.rejects(service(fake.root).runGitWorkflowCommand(["unused"], { cwd: fake.root }), /already running/);
418
+ const result = await pending;
419
+ assert.equal(result.timedOut, true);
420
+ assert.equal(result.cancelled, false);
421
+ assert.equal(result.signal, "SIGKILL");
422
+ assert.ok(Date.now() - started >= 1900, "SIGKILL must retain the two-second grace after SIGTERM");
423
+ assert.equal(fake.service.cancelGitWorkflowProcess(), false);
424
+ });
425
+
426
+ test("Git lock failures retry at most three times and report REPO_BUSY", unixOnly, async (t) => {
427
+ const fake = await fakeCommands(t, { lockFailures: 2 });
428
+ const result = await fake.service.stageGitFile(fake.root, { path: "file" });
429
+ assert.equal(result.ok, true);
430
+ assert.equal((await fake.log()).length, 3);
431
+ await rm(path.join(fake.root, "attempts"));
432
+ await fake.configure({ lockFailures: 10 });
433
+ const busy = await fake.service.stageGitFile(fake.root, { path: "file" });
434
+ assert.equal(busy.ok, false);
435
+ assert.equal(busy.code, "REPO_BUSY");
436
+ assert.match(busy.error, /index.lock/);
437
+ assert.equal((await fake.log()).length, 6);
438
+ await fake.configure({});
439
+ assert.equal((await fake.service.stageGitFile(fake.root, { path: "file" })).ok, true);
440
+ });
441
+
442
+ test("workflow pushes preserve exact flags, guard order and protected-branch metadata without networking", unixOnly, async (t) => {
443
+ const fake = await fakeCommands(t, { remotes: ["backup", "origin"] });
444
+ const api = fake.service;
445
+ await assert.rejects(api.pushGitWorkflow(fake.root, { branch: "other", setUpstream: true }), /Current branch is main/);
446
+ assert.deepEqual((await fake.log()).map((entry) => entry.args), [["branch", "--show-current"]]);
447
+ await assert.rejects(api.pushGitWorkflow(fake.root, { forceWithLease: true }), { statusCode: 409 });
448
+ assert.equal((await fake.log()).length, 2, "confirmation must precede remote lookup and push");
449
+ const upstream = await api.pushGitWorkflow(fake.root, { setUpstream: true, branch: "main", forceWithLease: true });
450
+ assert.equal(upstream.ok, true);
451
+ assert.equal(upstream.data.protectedBranch, true);
452
+ assert.equal(upstream.data.remote, "origin");
453
+ assert.deepEqual((await fake.log()).at(-1).args, ["push", "-u", "origin", "main"]);
454
+ const forced = await api.pushGitWorkflow(fake.root, { forceWithLease: true, confirmed: true });
455
+ assert.equal(forced.data.forceWithLease, true);
456
+ assert.deepEqual((await fake.log()).at(-1).args, ["push", "-u", "--force-with-lease", "origin", "HEAD"]);
457
+ assert.equal((await api.pushInitialGitMain(fake.root)).ok, true);
458
+ assert.deepEqual((await fake.log()).at(-1).args, ["push", "-u", "origin", "main"]);
459
+ await fake.configure({ branch: "feature/x", remotes: ["backup"] });
460
+ const ordinary = await api.pushGitWorkflow(fake.root);
461
+ assert.equal(ordinary.data.protectedBranch, false);
462
+ assert.deepEqual((await fake.log()).at(-1).args, ["push", "-u", "backup", "HEAD"]);
463
+ for (const [failure, code] of [
464
+ ["fatal: No configured push destination.", "NO_REMOTE"],
465
+ ["Authentication failed", "AUTH"],
466
+ ["could not resolve host", "NETWORK"],
467
+ ["GH006 protected branch", "PROTECTED_BRANCH"],
468
+ ["[rejected] non-fast-forward", "NON_FAST_FORWARD"],
469
+ ["has no upstream branch", "NO_UPSTREAM"],
470
+ ]) {
471
+ await fake.configure({ failure });
472
+ const failed = await api.pushGitWorkflow(fake.root);
473
+ assert.equal(failed.code, code);
474
+ assert.equal(failed.data.branch, "main");
475
+ assert.equal(failed.data.repoName, path.basename(fake.root));
476
+ assert.deepEqual((await fake.log()).at(-1).args, ["push"]);
477
+ }
478
+ });
479
+
480
+ test("fetch, pull and integration retain flags, guards and failure classification", unixOnly, async (t) => {
481
+ const fake = await fakeCommands(t);
482
+ const api = service(fake.root, { gitUpstreamRef: async () => "origin/main" });
483
+ assert.equal((await api.fetchGitChanges(fake.root)).ok, true);
484
+ assert.deepEqual((await fake.log()).at(-1).args, ["-c", "credential.interactive=false", "fetch", "--prune"]);
485
+ assert.equal((await api.pullGitChanges(fake.root, { remote: "origin" })).ok, true);
486
+ assert.deepEqual((await fake.log()).at(-1).args, ["pull", "--ff-only", "origin"]);
487
+ await assert.rejects(api.pullGitChanges(fake.root, { remote: "upstream" }), /Unsupported Git pull remote/);
488
+ await assert.rejects(api.integrateGitUpstream(fake.root, { mode: "invalid" }), { statusCode: 400 });
489
+ await assert.rejects(api.integrateGitUpstream(fake.root, { mode: "rebase" }), { statusCode: 409 });
490
+ await assert.rejects(fake.service.integrateGitUpstream(fake.root, { mode: "merge", confirmed: true }), /No upstream/);
491
+ assert.equal((await api.integrateGitUpstream(fake.root, { mode: "rebase", confirmed: true })).ok, true);
492
+ assert.deepEqual((await fake.log()).at(-1).args, ["-c", "core.editor=true", "rebase", "@{upstream}"]);
493
+ await fake.configure({ failCommand: "pull", failure: "fatal: Not possible to fast-forward" });
494
+ assert.equal((await api.pullGitChanges(fake.root)).code, "DIVERGED");
495
+ });
496
+
497
+ test("publication validates visibility, confirmation and no-remotes before fake gh", unixOnly, async (t) => {
498
+ const fake = await fakeCommands(t);
499
+ const api = fake.service;
500
+ await assert.rejects(api.publishGitRepository(fake.root, { visibility: "internal", confirmed: true }), { statusCode: 400 });
501
+ await assert.rejects(api.publishGitRepository(fake.root, { visibility: "public" }), { statusCode: 409 });
502
+ await assert.rejects(readFile(path.join(fake.root, "commands.jsonl")), { code: "ENOENT" });
503
+ await fake.configure({ remotes: ["origin"] });
504
+ await assert.rejects(api.publishGitRepository(fake.root, { visibility: "private", confirmed: true }), /no configured remotes/);
505
+ assert.equal((await fake.log()).some((entry) => entry.command === "gh"), false);
506
+ await fake.configure({});
507
+ const published = await api.publishGitRepository(fake.root, { visibility: "private", confirmed: true });
508
+ assert.equal(published.ok, true);
509
+ assert.equal(published.data.protectedBranch, true);
510
+ assert.equal(published.data.remote, "origin");
511
+ assert.deepEqual((await fake.log()).at(-1).args, ["repo", "create", path.basename(fake.root), "--private", "--source", ".", "--remote", "origin", "--push"]);
512
+ await fake.configure({ failure: "gh auth login" });
513
+ assert.equal((await api.publishGitRepository(fake.root, { visibility: "public", confirmed: true })).code, "AUTH");
514
+ await fake.configure({ failure: "repository example already exists" });
515
+ assert.match((await api.publishGitRepository(fake.root, { visibility: "public", confirmed: true })).hint, /already exists/);
516
+ await rm(path.join(fake.root, "bin", "gh"));
517
+ const missing = await api.publishGitRepository(fake.root, { visibility: "public", confirmed: true });
518
+ assert.equal(missing.data.errorCode, "ENOENT");
519
+ assert.match(missing.hint, /Install GitHub CLI/);
520
+ assert.equal(api.cancelGitWorkflowProcess(), false);
521
+ });
522
+
523
+ test("PR creation validates text and stores the encoded current-branch description before fake gh", unixOnly, async (t) => {
524
+ const fake = await fakeCommands(t, { branch: "feature/one" });
525
+ const api = fake.service;
526
+ await assert.rejects(api.createGitWorkflowPr(fake.root, { title: "", body: "description" }), /PR title is required/);
527
+ await assert.rejects(api.createGitWorkflowPr(fake.root, { title: "title", body: " \n" }), /PR description is required/);
528
+ assert.equal((await fake.log()).some((entry) => entry.command === "gh"), false);
529
+ const created = await api.createGitWorkflowPr(fake.root, { title: " first\nsecond ", body: "description\n\n" });
530
+ assert.equal(created.ok, true);
531
+ assert.equal(created.data.path, path.join(fake.root, "dev", "PR", "feature%2Fone.md"));
532
+ assert.equal(await readFile(created.data.path, "utf8"), "description\n");
533
+ assert.deepEqual((await fake.log()).at(-1).args, ["pr", "create", "--title", "first second", "--body-file", created.data.path, "--head", "feature/one"]);
534
+ assert.equal((await api.readGitWorkflowPrDescription(fake.root)).body, "description");
535
+ await fake.configure({ branch: "feature/one", failure: "PR refused" });
536
+ assert.equal((await api.createGitWorkflowPr(fake.root, { title: "title", body: "changed" })).ok, false);
537
+ assert.equal(await readFile(created.data.path, "utf8"), "changed\n");
538
+ });
539
+
540
+ test("branch reads preserve remote identity, local precedence, occupation and exact requested intent", async (t) => {
541
+ const root = await disposable(t);
542
+ await baseCommit(root);
543
+ git(root, "remote", "add", "origin", "https://example.invalid/origin.git");
544
+ git(root, "remote", "add", "backup", "https://example.invalid/backup.git");
545
+ const head = git(root, "rev-parse", "HEAD").trim();
546
+ for (const ref of ["origin/feature", "backup/feature", "origin/main"]) git(root, "update-ref", `refs/remotes/${ref}`, head);
547
+ git(root, "symbolic-ref", "refs/remotes/origin/HEAD", "refs/remotes/origin/main");
548
+ const worktree = await disposable(t, { initialized: false });
549
+ git(root, "worktree", "add", "-q", "-b", "occupied", worktree);
550
+ const api = service(root);
551
+ const data = await api.readGitBranches(root);
552
+ assert.equal(data.current, "main");
553
+ assert.deepEqual(data.branches.filter((entry) => entry.remote).map((entry) => entry.remoteRef), ["backup/feature", "origin/feature"]);
554
+ assert.equal(data.branches.find((entry) => entry.name === "occupied").worktreePath, worktree);
555
+ assert.equal(data.branches.find((entry) => entry.name === "occupied").occupied, true);
556
+ assert.deepEqual(await api.verifyRemoteGitBranchIntent(root, "feature", "backup/feature"), { root, branch: "feature", remoteRef: "backup/feature" });
557
+ await assert.rejects(api.verifyRemoteGitBranchIntent(root, "feature", "missing/feature"), /Unknown remote/);
558
+ await assert.rejects(api.verifyRemoteGitBranchIntent(root, "other", "origin/feature"), /does not match/);
559
+ await assert.rejects(api.verifyRemoteGitBranchIntent(root, "main", "origin/main"), /Local git branch already exists/);
560
+ assert.equal(api.requestedRemoteRef({}), null);
561
+ assert.equal(api.requestedRemoteRef({ remoteRef: "backup/feature" }), "backup/feature");
562
+ for (const remoteRef of [null, "", " origin/feature", 1]) assert.throws(() => api.requestedRemoteRef({ remoteRef }), /non-empty exact/);
563
+ const truncated = service(root, { runGitReadCommandDetailed: async () => ({ output: "refs/remotes/origin/partial", truncated: true }) });
564
+ const limited = await truncated.readGitBranches(root);
565
+ assert.equal(limited.remoteBranchesTruncated, true);
566
+ assert.equal(limited.branches.some((entry) => entry.remote), false);
567
+ const unavailable = service(root, { runGitReadCommandDetailed: async () => { throw new Error("unavailable"); } });
568
+ assert.equal((await unavailable.readGitBranches(root)).remoteBranchesUnavailable, true);
569
+ });
570
+
571
+ test("stash, recovery, tags, reflog, signing and submodule reads use injected G1 boundaries", async (t) => {
572
+ const root = await disposable(t);
573
+ await baseCommit(root);
574
+ const api = service(root);
575
+ await writeFile(path.join(root, "tracked.txt"), "stash me\n");
576
+ await writeFile(path.join(root, "extra.txt"), "untracked stash\n");
577
+ const saved = await api.saveGitStash(root, { message: "local stash", includeUntracked: true });
578
+ assert.equal(saved.ok, true);
579
+ assert.equal(saved.data.stashes.length, 1);
580
+ assert.match((await api.readGitStashPreview(root, "stash@{0}")).patch, /stash me/);
581
+ await assert.rejects(api.applyGitStash(root, { ref: "--bad" }), { statusCode: 400 });
582
+ assert.equal((await api.applyGitStash(root, { ref: "stash@{0}" })).ok, true);
583
+ await assert.rejects(api.dropGitStash(root, { ref: "stash@{0}" }), { statusCode: 409 });
584
+ assert.equal((await api.dropGitStash(root, { ref: "stash@{0}", confirmed: true })).data.stashes.length, 0);
585
+ assert.equal((await api.readGitUndoState(root)).hasParent, false);
586
+ git(root, "add", "tracked.txt");
587
+ git(root, "commit", "-qm", "second");
588
+ assert.equal((await api.readGitUndoState(root)).canUndoLastCommit, true);
589
+ await assert.rejects(api.undoLastGitCommit(root), { statusCode: 409 });
590
+ const staged = service(root, { summarizeGitPorcelainStatus: () => ({ ...summary, staged: 1 }) });
591
+ await assert.rejects(staged.amendLastGitCommitMessage(root, { message: "bad", confirmed: true }), /Staged changes present/);
592
+ const published = service(root, { gitUpstreamRef: async () => "origin/main" });
593
+ await assert.rejects(published.undoLastGitCommit(root, { confirmed: true }), /already pushed/);
594
+ assert.equal((await api.amendLastGitCommitMessage(root, { message: "renamed", confirmed: true })).ok, true);
595
+ assert.equal(git(root, "log", "-1", "--format=%s").trim(), "renamed");
596
+ const undone = await api.undoLastGitCommit(root, { confirmed: true });
597
+ assert.equal(undone.ok, true);
598
+ assert.equal(undone.data.restoreCommand, "git reset --soft ORIG_HEAD");
599
+ assert.match(git(root, "diff", "--cached"), /stash me/);
600
+ const tag = await api.createGitTag(root, { name: "v-test", message: "tag message", confirmed: true });
601
+ assert.equal(tag.ok, true);
602
+ assert.equal(tag.data.tags[0].annotated, true);
603
+ await assert.rejects(api.createGitTag(root, { name: "bad..tag", confirmed: true }), /Invalid tag name/);
604
+ assert.ok((await api.readGitReflog(root)).entries.length > 0);
605
+ assert.equal((await api.readGitSubmodules(root)).hasSubmodules, false);
606
+ await assert.rejects(api.updateGitSubmodules(root), { statusCode: 409 });
607
+ assert.equal((await api.updateGitSubmodules(root, { confirmed: true })).ok, true);
608
+ git(root, "config", "commit.gpgsign", "true");
609
+ const signing = await api.readGitSigningDiagnostics(root);
610
+ assert.equal(signing.commitSignRequired, true);
611
+ assert.equal(signing.mismatch, true);
612
+ assert.ok(signing.suggestions.some((suggestion) => suggestion.command === "git config user.signingkey <KEY-ID>"));
613
+ });
614
+
615
+ test("operation snapshot, conflict staging, continue and abort preserve actual merge recovery", async (t) => {
616
+ const root = await disposable(t);
617
+ await baseCommit(root);
618
+ git(root, "switch", "-qc", "other");
619
+ await writeFile(path.join(root, "tracked.txt"), "other\n");
620
+ git(root, "commit", "-qam", "other");
621
+ git(root, "switch", "-q", "main");
622
+ await writeFile(path.join(root, "tracked.txt"), "main\n");
623
+ git(root, "commit", "-qam", "main");
624
+ git(root, "config", "branch.main.remote", ".");
625
+ git(root, "config", "branch.main.merge", "refs/heads/other");
626
+ const api = service(root, { gitUpstreamRef: async () => "other" });
627
+ const merged = await api.integrateGitUpstream(root, { mode: "merge", confirmed: true });
628
+ assert.equal(merged.ok, false);
629
+ assert.equal(merged.code, "CONFLICTS");
630
+ const state = await api.readGitOperationSnapshot(root);
631
+ assert.equal(state.operation, "merge");
632
+ assert.equal(state.conflicts[0].path, "tracked.txt");
633
+ assert.equal(state.conflicts[0].preview.hasMarkers, true);
634
+ assert.ok(state.conflicts[0].preview.hunks.length > 0);
635
+ assert.equal((await api.gitOperationAction(root, "continue")).code, "UNMERGED_PATHS");
636
+ await assert.rejects(api.gitOperationAction(root, "skip"), /does not support skip/);
637
+ await assert.rejects(api.gitOperationAction(root, "abort"), { statusCode: 409 });
638
+ await assert.rejects(api.undoLastGitCommit(root, { confirmed: true }), /Cannot undo during a merge/);
639
+ await writeFile(path.join(root, "tracked.txt"), "resolved\n");
640
+ assert.equal((await api.gitOperationStageFile(root, { path: "tracked.txt" })).ok, true);
641
+ assert.equal((await api.gitOperationAction(root, "abort", { confirmed: true })).ok, true);
642
+ assert.equal((await api.readGitOperationSnapshot(root)).operation, null);
643
+ await api.integrateGitUpstream(root, { mode: "merge", confirmed: true });
644
+ await writeFile(path.join(root, "tracked.txt"), "resolved\n");
645
+ await api.gitOperationStageFile(root, { path: "tracked.txt" });
646
+ const continued = await api.gitOperationAction(root, "continue");
647
+ assert.equal(continued.ok, true);
648
+ assert.equal(continued.data.operation.operation, null);
649
+ await assert.rejects(api.gitOperationStageFile(root, { path: "tracked.txt" }), /No git operation/);
650
+ await assert.rejects(api.gitBisectAction(root, { verdict: "bad" }), /No git bisect/);
651
+ await assert.rejects(api.gitBisectAction(root, { verdict: "invalid" }), { statusCode: 400 });
652
+ git(root, "bisect", "start");
653
+ assert.equal((await api.readGitOperationSnapshot(root)).operation, "bisect");
654
+ await assert.rejects(api.gitOperationAction(root, "continue"), /Bisect is controlled/);
655
+ await assert.rejects(api.gitBisectAction(root, { verdict: "reset" }), { statusCode: 409 });
656
+ assert.equal((await api.gitBisectAction(root, { verdict: "reset", confirmed: true })).ok, true);
657
+ });
658
+
659
+
660
+ test("Git and gh mutations share cancellation and cancellation does not trigger lock retries", unixOnly, async (t) => {
661
+ const fake = await fakeCommands(t, { holdGh: true });
662
+ const pr = fake.service.createGitWorkflowPr(fake.root, { title: "title", body: "description" });
663
+ t.after(async () => { fake.service.cancelGitWorkflowProcess(); await pr; });
664
+ await waitForFile(path.join(fake.root, "ready"));
665
+ await assert.rejects(service(fake.root).runGitWorkflowCommand(["unused"], { cwd: fake.root }), /already running: gh pr create/);
666
+ assert.equal(fake.service.cancelGitWorkflowProcess(), true);
667
+ const cancelledPr = await pr;
668
+ assert.equal(cancelledPr.ok, false);
669
+ assert.equal(cancelledPr.error, "Cancelled");
670
+ assert.equal(cancelledPr.data.cancelled, true);
671
+ await rm(path.join(fake.root, "ready"));
672
+ await fake.configure({ holdAdd: true });
673
+ const add = fake.service.stageGitFile(fake.root, { path: "file" });
674
+ t.after(async () => { fake.service.cancelGitWorkflowProcess(); await add; });
675
+ await waitForFile(path.join(fake.root, "ready"));
676
+ assert.equal(fake.service.cancelGitWorkflowProcess(), true);
677
+ const cancelledAdd = await add;
678
+ assert.equal(cancelledAdd.ok, false);
679
+ assert.equal(cancelledAdd.data.cancelled, true);
680
+ assert.equal((await fake.log()).filter((entry) => entry.args[0] === "add").length, 1);
681
+ });
682
+
683
+
684
+ test("branch mutations preserve local switching, creation and occupied-worktree refusals", async (t) => {
685
+ const root = await disposable(t);
686
+ await baseCommit(root);
687
+ const api = service(root);
688
+ const current = await api.switchGitBranch(root, "main");
689
+ assert.equal(current.ok, true);
690
+ assert.equal(current.data.switched, false);
691
+ assert.equal(current.data.created, false);
692
+ await assert.rejects(api.switchGitBranch(root, "unknown"), /Unknown local git branch/);
693
+ await assert.rejects(api.switchGitBranch(root, "main", { create: true }), /already exists/);
694
+ await assert.rejects(api.switchGitBranch(root, "bad..branch", { create: true }), /not a valid branch name/);
695
+ const created = await api.switchGitBranch(root, "new-local", { create: true });
696
+ assert.equal(created.ok, true);
697
+ assert.equal(created.data.created, true);
698
+ assert.equal(created.data.command, "git switch -c new-local");
699
+ assert.equal(git(root, "branch", "--show-current").trim(), "new-local");
700
+ assert.equal((await api.switchGitBranch(root, "main")).data.switched, true);
701
+ const worktree = await disposable(t, { initialized: false });
702
+ git(root, "worktree", "add", "-q", worktree, "new-local");
703
+ const refused = await api.switchGitBranch(root, "new-local");
704
+ assert.equal(refused.ok, false);
705
+ assert.equal(refused.code, "BRANCH_CHECKED_OUT_ELSEWHERE");
706
+ assert.equal(refused.data.worktreePath, worktree);
707
+ assert.equal(git(root, "branch", "--show-current").trim(), "main");
708
+ });
709
+
710
+ test("remote branch mutation validates exact intent then creates tracking without fetching", async (t) => {
711
+ const root = await disposable(t);
712
+ await baseCommit(root);
713
+ const head = git(root, "rev-parse", "HEAD").trim();
714
+ for (const remote of ["origin", "backup"]) {
715
+ git(root, "remote", "add", remote, `https://example.invalid/${remote}.git`);
716
+ git(root, "update-ref", `refs/remotes/${remote}/feature`, head);
717
+ }
718
+ const api = service(root);
719
+ await assert.rejects(api.switchGitBranch(root, "feature", { remoteRef: "unknown/feature" }), /Unknown remote/);
720
+ await assert.rejects(api.switchGitBranch(root, "other", { remoteRef: "backup/feature" }), /does not match/);
721
+ const created = await api.switchGitBranch(root, "feature", { remoteRef: "backup/feature" });
722
+ assert.equal(created.ok, true);
723
+ assert.equal(created.data.created, true);
724
+ assert.equal(created.data.switched, true);
725
+ assert.equal(created.data.command, "git switch --track -c feature backup/feature");
726
+ assert.equal(git(root, "config", "branch.feature.remote").trim(), "backup");
727
+ assert.equal(git(root, "config", "branch.feature.merge").trim(), "refs/heads/feature");
728
+ await assert.rejects(api.switchGitBranch(root, "feature", { remoteRef: "origin/feature" }), /Local git branch already exists/);
729
+ });