diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index e9a087a7cb5..4d16c67520b 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -630,8 +630,8 @@ jobs: fi pnpm exec vitest run --config config/vitest.config.ts \ src/shared/git-binary-compatibility.test.ts \ - src/main/git/worktree-safety-real-git.test.ts \ - src/main/git/worktree-rebase-update-refs-real-git.test.ts + src/main/git/worktrees/creation/worktree-safety-real-git.test.ts \ + src/main/git/worktrees/removal/worktree-rebase-update-refs-real-git.test.ts # Run pinned real Codex: thread/read must repair an unindexed rollout’s threads row; stub-only units cannot detect upstream removal of this behavior. codex_index_heal_contract: diff --git a/config/flaky-test-pattern-baseline.txt b/config/flaky-test-pattern-baseline.txt index 8051d0d99f6..3f23e46a817 100644 --- a/config/flaky-test-pattern-baseline.txt +++ b/config/flaky-test-pattern-baseline.txt @@ -86,8 +86,8 @@ 1 test-no-polling-loop:src/main/daemon/headless-emulator-snapshot-cost.bench.test.ts 1 test-no-polling-loop:src/main/daemon/node-pty-conout-worker-errors.test.ts 1 test-no-polling-loop:src/main/daemon/repro-12101-mouse-tracking-survives-agent-death.test.ts -2 test-no-polling-loop:src/main/git/repo-ref-maintenance-real-git.test.ts -1 test-no-polling-loop:src/main/git/worktree-removal-large-tree.bench.test.ts +2 test-no-polling-loop:src/main/git/refs/maintenance/repo-ref-maintenance-real-git.test.ts +1 test-no-polling-loop:src/main/git/worktrees/removal/worktree-removal-large-tree.bench.test.ts 1 test-no-polling-loop:src/main/ipc/folder-repo-git-upgrade.test.ts 1 test-no-polling-loop:src/main/ipc/native-chat.test.ts 1 test-no-polling-loop:src/main/ipc/runtime-environments/runtime-environment-request-connections.test.ts @@ -302,13 +302,13 @@ 1 test-no-real-time-wait:src/main/daemon/terminal-shell-recovery-barrier.test.ts 1 test-no-real-time-wait:src/main/foreign-sqlite-readers/foreign-sqlite-reader-client-worker-lifecycle.test.ts 2 test-no-real-time-wait:src/main/foreign-sqlite-readers/foreign-sqlite-reader-event-loop.test.ts -1 test-no-real-time-wait:src/main/git/local-repo-ref-maintenance.test.ts -1 test-no-real-time-wait:src/main/git/remove-worktree-branch-cleanup.test.ts -4 test-no-real-time-wait:src/main/git/repo-ref-maintenance-real-git.test.ts -1 test-no-real-time-wait:src/main/git/status-submodule.test.ts -1 test-no-real-time-wait:src/main/git/worktree-configured-paths-concurrency.test.ts -1 test-no-real-time-wait:src/main/git/worktree-prune-guard.test.ts -1 test-no-real-time-wait:src/main/git/worktree-removal-large-tree.bench.test.ts +1 test-no-real-time-wait:src/main/git/refs/maintenance/local-repo-ref-maintenance.test.ts +1 test-no-real-time-wait:src/main/git/worktrees/removal/remove-worktree-branch-cleanup.test.ts +4 test-no-real-time-wait:src/main/git/refs/maintenance/repo-ref-maintenance-real-git.test.ts +1 test-no-real-time-wait:src/main/git/source-control/status-submodule.test.ts +1 test-no-real-time-wait:src/main/git/worktrees/creation/worktree-configured-paths-concurrency.test.ts +1 test-no-real-time-wait:src/main/git/worktrees/removal/worktree-prune-guard.test.ts +1 test-no-real-time-wait:src/main/git/worktrees/removal/worktree-removal-large-tree.bench.test.ts 1 test-no-real-time-wait:src/main/gitlab/work-item-details.test.ts 1 test-no-real-time-wait:src/main/grok/grok-hook-stdin-no-eof.test.ts 1 test-no-real-time-wait:src/main/ipc/created-worktree-reconciliation.test.ts @@ -788,15 +788,15 @@ 2 test-no-wall-clock:src/main/git/command-runner/git-command-resolution-windows-checkout.test.ts 1 test-no-wall-clock:src/main/git/command-runner/git-command-timeout-behavior.test.ts 4 test-no-wall-clock:src/main/git/gh-rate-limit-breaker.test.ts -1 test-no-wall-clock:src/main/git/pack-refs-lock-ownership.test.ts -2 test-no-wall-clock:src/main/git/repo-ref-maintenance-real-git.test.ts +1 test-no-wall-clock:src/main/git/refs/maintenance/pack-refs-lock-ownership.test.ts +2 test-no-wall-clock:src/main/git/refs/maintenance/repo-ref-maintenance-real-git.test.ts 2 test-no-wall-clock:src/main/git/runner-gh-account-binding.test.ts 6 test-no-wall-clock:src/main/git/runner-gh-rate-limit-breaker.test.ts -2 test-no-wall-clock:src/main/git/settled-diff-cache-bounds.test.ts +2 test-no-wall-clock:src/main/git/source-control/settled-diff-cache-bounds.test.ts 1 test-no-wall-clock:src/main/git/source-control/blob-absence-real-git.test.ts -2 test-no-wall-clock:src/main/git/status-diff-settled-cache.test.ts -1 test-no-wall-clock:src/main/git/status-upstream-negative-cache.test.ts -2 test-no-wall-clock:src/main/git/worktree-created-description-real-git.test.ts +2 test-no-wall-clock:src/main/git/source-control/status-diff-settled-cache.test.ts +1 test-no-wall-clock:src/main/git/source-control/status-upstream-negative-cache.test.ts +2 test-no-wall-clock:src/main/git/worktrees/catalog/worktree-created-description-real-git.test.ts 1 test-no-wall-clock:src/main/git/wsl-windows-checkout-git-probe.test.ts 2 test-no-wall-clock:src/main/github/client-pr-fallback-number.test.ts 1 test-no-wall-clock:src/main/github/client-work-items.test.ts @@ -1179,10 +1179,10 @@ 1 test-timeout-needs-reason:src/main/daemon/terminal-history-large-checkpoint-cold-restore.test.ts 1 test-timeout-needs-reason:src/main/foreign-sqlite-readers/foreign-sqlite-reader-event-loop.test.ts 1 test-timeout-needs-reason:src/main/git/command-runner/git-command-timeout-behavior.test.ts -6 test-timeout-needs-reason:src/main/git/repo-ref-maintenance-real-git.test.ts -1 test-timeout-needs-reason:src/main/git/worktree-preparation-cancel-latency.bench.test.ts -1 test-timeout-needs-reason:src/main/git/worktree-removal-large-tree.bench.test.ts -1 test-timeout-needs-reason:src/main/git/worktree-removal-real-git.test.ts +6 test-timeout-needs-reason:src/main/git/refs/maintenance/repo-ref-maintenance-real-git.test.ts +1 test-timeout-needs-reason:src/main/git/worktrees/creation/worktree-preparation-cancel-latency.bench.test.ts +1 test-timeout-needs-reason:src/main/git/worktrees/removal/worktree-removal-large-tree.bench.test.ts +1 test-timeout-needs-reason:src/main/git/worktrees/removal/worktree-removal-real-git.test.ts 1 test-timeout-needs-reason:src/main/hermes/hook-service.test.ts 2 test-timeout-needs-reason:src/main/workspace-hooks/hook-archive-timeout-observation.test.ts 2 test-timeout-needs-reason:src/main/workspace-hooks/hook-termination-real-process.test.ts diff --git a/config/scripts/ci-shard-timings.json b/config/scripts/ci-shard-timings.json index 4292b7c964e..b3ce85deba2 100644 --- a/config/scripts/ci-shard-timings.json +++ b/config/scripts/ci-shard-timings.json @@ -2557,13 +2557,13 @@ "src/main/ghostty/theme-import.test.ts": 100, "src/main/ghostty/theme-resolution.test.ts": 62, "src/main/pty/shell-startup/git-bash.test.ts": 60, - "src/main/git/add-sparse-worktree.test.ts": 259, + "src/main/git/worktrees/creation/add-sparse-worktree.test.ts": 259, "src/main/git/base-ref-search-selector.test.ts": 257, "src/main/git/branch-rename.test.ts": 66, "src/main/git/canonical-repo-key.test.ts": 221, - "src/main/git/check-ignored-paths.test.ts": 52, + "src/main/git/source-control/check-ignored-paths.test.ts": 52, "src/main/git/checkout-branch-identity-real-git.test.ts": 378, - "src/main/git/coalesced-probe.test.ts": 43, + "src/main/git/remotes/coalesced-probe.test.ts": 43, "src/main/git/command-runner/exec-file-capture-bytes.test.ts": 4698, "src/main/git/command-runner/exec-file-capture-stdin.test.ts": 287, "src/main/git/command-runner/gh-exec-file-deadline.test.ts": 182, @@ -2590,45 +2590,45 @@ "src/main/git/command-runner/wsl-host-failure.test.ts": 241, "src/main/git/command-runner/wsl-service-failure-direct-git.test.ts": 259, "src/main/git/commit-object-ref.test.ts": 37, - "src/main/git/create-event-repo-probe.test.ts": 108, + "src/main/git/worktrees/creation/create-event-repo-probe.test.ts": 108, "src/main/git/current-branch-identity-real-git.test.ts": 431, "src/main/git/default-wsl-cli-fallback-gate.test.ts": 465, "src/main/git/exact-ref-probe.test.ts": 62, "src/main/git/fetch-error-classification.test.ts": 47, - "src/main/git/fork-remote-refspec.test.ts": 51, - "src/main/git/fork-remote-stale-branch-refspec.test.ts": 46, + "src/main/git/refs/fork-remotes/fork-remote-refspec.test.ts": 51, + "src/main/git/refs/fork-remotes/fork-remote-stale-branch-refspec.test.ts": 46, "src/main/git/gh-rate-limit-breaker.test.ts": 50, - "src/main/git/git-capability-state.test.ts": 60, + "src/main/git/command-runner/git-capability-state.test.ts": 60, "src/main/git/git-network-safety-real-git.test.ts": 378, - "src/main/git/git-status-read-lease-owner.test.ts": 49, - "src/main/git/git-upstream-status-read-owner.test.ts": 45, - "src/main/git/git-worktree-mutation-state.test.ts": 74, - "src/main/git/hosted-remote-url.test.ts": 43, + "src/shared/git-status-read-lease-owner.test.ts": 49, + "src/main/git/source-control/git-upstream-status-read-owner.test.ts": 45, + "src/main/git/command-runner/git-worktree-mutation-state.test.ts": 74, + "src/main/git/remotes/hosted-remote-url.test.ts": 43, "src/main/git/huge-folder-ignore.test.ts": 58, "src/main/git/local-git-object-quarantine.test.ts": 108, - "src/main/git/local-repo-ref-maintenance-probe-retry.test.ts": 277, - "src/main/git/local-repo-ref-maintenance-wsl-stopped.test.ts": 271, - "src/main/git/local-repo-ref-maintenance.test.ts": 339, + "src/main/git/refs/maintenance/local-repo-ref-maintenance-probe-retry.test.ts": 277, + "src/main/git/refs/maintenance/local-repo-ref-maintenance-wsl-stopped.test.ts": 271, + "src/main/git/refs/maintenance/local-repo-ref-maintenance.test.ts": 339, "src/main/git/merge-tree-object-quarantine-real-git.test.ts": 2561, - "src/main/git/pack-refs-lock-ownership.test.ts": 59, - "src/main/git/porcelain-v1-records.test.ts": 138, - "src/main/git/remote-name-listing.test.ts": 398, - "src/main/git/remote-ref-probe-cache.test.ts": 414, + "src/main/git/refs/maintenance/pack-refs-lock-ownership.test.ts": 59, + "src/main/git/source-control/porcelain-v1-records.test.ts": 138, + "src/main/git/remotes/remote-name-listing.test.ts": 398, + "src/main/git/remotes/remote-ref-probe-cache.test.ts": 414, "src/main/git/remote.test.ts": 352, - "src/main/git/remove-worktree-branch-cleanup.test.ts": 409, - "src/main/git/remove-worktree-clean-preflight.test.ts": 248, - "src/main/git/remove-worktree.test.ts": 310, + "src/main/git/worktrees/removal/remove-worktree-branch-cleanup.test.ts": 409, + "src/main/git/worktrees/removal/remove-worktree-clean-preflight.test.ts": 248, + "src/main/git/worktrees/removal/remove-worktree.test.ts": 310, "src/main/git/repo-branch-conflict-real-git.test.ts": 348, "src/main/git/repo-branch-conflict.test.ts": 308, "src/main/git/repo-detection-async.test.ts": 612, "src/main/git/repo-detection-batching.test.ts": 494, "src/main/git/repo-detection-command.test.ts": 49, "src/main/git/repo-detection.test.ts": 842, - "src/main/git/repo-maintenance-admission.test.ts": 757, - "src/main/git/repo-pack-index-maintenance.test.ts": 152, - "src/main/git/repo-pack-index-state.test.ts": 67, - "src/main/git/repo-ref-maintenance-real-git.test.ts": 2096, - "src/main/git/repo-remote-drift-real.test.ts": 357, + "src/main/git/refs/maintenance/repo-maintenance-admission.test.ts": 757, + "src/main/git/refs/maintenance/repo-pack-index-maintenance.test.ts": 152, + "src/main/git/refs/maintenance/repo-pack-index-state.test.ts": 67, + "src/main/git/refs/maintenance/repo-ref-maintenance-real-git.test.ts": 2096, + "src/main/git/remotes/repo-remote-drift-real.test.ts": 357, "src/main/git/repo-search-ref-compat.test.ts": 125, "src/main/git/repo-username.test.ts": 303, "src/main/git/repo.test.ts": 2318, @@ -2649,7 +2649,7 @@ "src/main/git/runner.test.ts": 284, "src/main/git/saved-clone-probe-budget.test.ts": 71, "src/main/git/saved-clone-target.test.ts": 890, - "src/main/git/settled-diff-cache-bounds.test.ts": 71, + "src/main/git/source-control/settled-diff-cache-bounds.test.ts": 71, "src/main/git/source-control/blob-absence-real-git.test.ts": 629, "src/main/git/source-control/bulk-pathspec-command-line-budget.test.ts": 233, "src/main/git/source-control/complete-merge-real-git.test.ts": 958, @@ -2666,99 +2666,99 @@ "src/main/git/source-control/submodule-gitlink-pathspec-real-git.test.ts": 337, "src/main/git/source-control/submodule-restore-recurse-real-git.test.ts": 398, "src/main/git/source-control/wsl-tracked-pathspec-banner.test.ts": 264, - "src/main/git/status-branch-compare-real-ref.test.ts": 593, - "src/main/git/status-branch-compare.test.ts": 251, - "src/main/git/status-branch-line-total-exec-contract.test.ts": 1033, - "src/main/git/status-branch-line-total-real-git.test.ts": 785, - "src/main/git/status-branch-line-total-untracked-base.test.ts": 700, - "src/main/git/status-conflict-operations.test.ts": 250, - "src/main/git/status-cquoted-paths.test.ts": 348, - "src/main/git/status-diff-settled-cache.test.ts": 364, - "src/main/git/status-diff.test.ts": 327, - "src/main/git/status-discard-and-bulk-staging.test.ts": 289, - "src/main/git/status-discard-symlink.test.ts": 456, - "src/main/git/status-line-stats-host-paths.test.ts": 77, - "src/main/git/status-line-stats-renames-real-git.test.ts": 631, - "src/main/git/status-pathspec-literals.test.ts": 442, - "src/main/git/status-porcelain-parser.test.ts": 52, - "src/main/git/status-read-coalescing.test.ts": 258, - "src/main/git/status-read-failure-real-git.test.ts": 307, - "src/main/git/status-shared-symlinks.test.ts": 746, - "src/main/git/status-submodule-path-cache.test.ts": 423, - "src/main/git/status-submodule.test.ts": 306, - "src/main/git/status-symlink-probe-budget.test.ts": 238, - "src/main/git/status-upstream-negative-cache.test.ts": 963, - "src/main/git/status-upstream-probe-churn.test.ts": 261, - "src/main/git/status-upstream-ref.test.ts": 52, - "src/main/git/status.test.ts": 316, - "src/main/git/upstream-deferred-fork-remote-real.test.ts": 319, - "src/main/git/upstream.test.ts": 406, - "src/main/git/worktree-add-local-base-refresh.test.ts": 362, - "src/main/git/worktree-add-pending-removal.test.ts": 346, - "src/main/git/worktree-add-remote-branch-upstream-real-git.test.ts": 786, - "src/main/git/worktree-add-timeout-override.test.ts": 334, - "src/main/git/worktree-base-divergence-real-git.test.ts": 707, - "src/main/git/worktree-base-divergence.test.ts": 102, - "src/main/git/worktree-base-ref-probe.test.ts": 52, - "src/main/git/worktree-base-refresh-contention.test.ts": 269, - "src/main/git/worktree-base-refresh-lock-real-git.test.ts": 1588, - "src/main/git/worktree-checkout-progress-real-git.test.ts": 769, - "src/main/git/worktree-common-dir-comparison.test.ts": 236, - "src/main/git/worktree-configured-paths-concurrency.test.ts": 80, - "src/main/git/worktree-create-git-executor-real-git.test.ts": 528, - "src/main/git/worktree-create-preparation-real-git.test.ts": 1858, - "src/main/git/worktree-create-preparation-real-wsl.test.ts": 382, - "src/main/git/worktree-created-description-real-git.test.ts": 1119, - "src/main/git/worktree-created-disk-witness.test.ts": 259, - "src/main/git/worktree-delete-limit.test.ts": 33, - "src/main/git/worktree-diff-stamp-guest-gitdir.test.ts": 53, - "src/main/git/worktree-diff-stamp-host-paths.test.ts": 52, - "src/main/git/worktree-git-capabilities.test.ts": 297, - "src/main/git/worktree-git-path.test.ts": 77, - "src/main/git/worktree-graph-listing.test.ts": 302, - "src/main/git/worktree-include-file.test.ts": 126, - "src/main/git/worktree-list-paths.test.ts": 755, - "src/main/git/worktree-list-porcelain.test.ts": 285, - "src/main/git/worktree-list-reader-cancellation.test.ts": 84, - "src/main/git/worktree-listing-created-sparse-distro.test.ts": 325, - "src/main/git/worktree-listing-sparse-cancellation.test.ts": 229, - "src/main/git/worktree-listing-unc-drvfs-identity.test.ts": 242, - "src/main/git/worktree-move.test.ts": 318, - "src/main/git/worktree-mutation-route-invalidation.test.ts": 287, - "src/main/git/worktree-path-deduplication.test.ts": 220, - "src/main/git/worktree-porcelain-parsing.test.ts": 357, - "src/main/git/worktree-posix-path-case-sensitivity.test.ts": 279, - "src/main/git/worktree-preparation-add.test.ts": 233, - "src/main/git/worktree-preparation-base-oid.test.ts": 322, - "src/main/git/worktree-preparation-cancel-latency.bench.test.ts": 361, - "src/main/git/worktree-preparation-discard-real-git.test.ts": 547, - "src/main/git/worktree-preparation-fallback-cleanup-real-git.test.ts": 737, - "src/main/git/worktree-preparation-lock-real-git.test.ts": 1352, - "src/main/git/worktree-preparation-lock.test.ts": 102, - "src/main/git/worktree-preparation-tip-refresh-real-git.test.ts": 844, - "src/main/git/worktree-preparation-tip-refresh.test.ts": 113, - "src/main/git/worktree-prune-guard.test.ts": 159, - "src/main/git/worktree-rebase-update-refs-real-git.test.ts": 284, - "src/main/git/worktree-removal-large-tree.bench.test.ts": 486, - "src/main/git/worktree-removal-real-git.test.ts": 3365, - "src/main/git/worktree-remove-branch-deletion.test.ts": 353, - "src/main/git/worktree-safety-real-git.test.ts": 549, - "src/main/git/worktree-scan-cache-annotation-reuse.test.ts": 361, - "src/main/git/worktree-scan-cache-sharing.test.ts": 404, - "src/main/git/worktree-separate-git-dir.test.ts": 689, - "src/main/git/worktree-shared-directories.test.ts": 1045, - "src/main/git/worktree-sparse-checkout-cache.test.ts": 283, - "src/main/git/worktree-sparse-checkout.test.ts": 851, - "src/main/git/worktree-sparse-state-host-paths.test.ts": 321, - "src/main/git/worktree-symlink-detection.test.ts": 51, + "src/main/git/source-control/status-branch-compare-real-ref.test.ts": 593, + "src/main/git/source-control/status-branch-compare.test.ts": 251, + "src/main/git/source-control/status-branch-line-total-exec-contract.test.ts": 1033, + "src/main/git/source-control/status-branch-line-total-real-git.test.ts": 785, + "src/main/git/source-control/status-branch-line-total-untracked-base.test.ts": 700, + "src/main/git/source-control/status-conflict-operations.test.ts": 250, + "src/main/git/source-control/status-cquoted-paths.test.ts": 348, + "src/main/git/source-control/status-diff-settled-cache.test.ts": 364, + "src/main/git/source-control/status-diff.test.ts": 327, + "src/main/git/source-control/status-discard-and-bulk-staging.test.ts": 289, + "src/main/git/source-control/status-discard-symlink.test.ts": 456, + "src/main/git/source-control/status-line-stats-host-paths.test.ts": 77, + "src/main/git/source-control/status-line-stats-renames-real-git.test.ts": 631, + "src/main/git/source-control/status-pathspec-literals.test.ts": 442, + "src/shared/git-status-porcelain-parser.test.ts": 52, + "src/main/git/source-control/status-read-coalescing.test.ts": 258, + "src/main/git/source-control/status-read-failure-real-git.test.ts": 307, + "src/main/git/source-control/status-shared-symlinks.test.ts": 746, + "src/main/git/source-control/status-submodule-path-cache.test.ts": 423, + "src/main/git/source-control/status-submodule.test.ts": 306, + "src/main/git/source-control/status-symlink-probe-budget.test.ts": 238, + "src/main/git/source-control/status-upstream-negative-cache.test.ts": 963, + "src/main/git/source-control/status-upstream-probe-churn.test.ts": 261, + "src/main/git/source-control/status-upstream-ref.test.ts": 52, + "src/main/git/source-control/status.test.ts": 316, + "src/main/git/source-control/upstream-deferred-fork-remote-real.test.ts": 319, + "src/main/git/source-control/upstream.test.ts": 406, + "src/main/git/worktrees/creation/worktree-add-local-base-refresh.test.ts": 362, + "src/main/git/worktrees/creation/worktree-add-pending-removal.test.ts": 346, + "src/main/git/worktrees/creation/worktree-add-remote-branch-upstream-real-git.test.ts": 786, + "src/main/git/worktrees/creation/worktree-add-timeout-override.test.ts": 334, + "src/main/git/worktrees/creation/worktree-base-divergence-real-git.test.ts": 707, + "src/main/git/worktrees/creation/worktree-base-divergence.test.ts": 102, + "src/main/git/worktrees/creation/worktree-base-ref-probe.test.ts": 52, + "src/main/git/worktrees/creation/worktree-base-refresh-contention.test.ts": 269, + "src/main/git/worktrees/creation/worktree-base-refresh-lock-real-git.test.ts": 1588, + "src/main/git/worktrees/creation/worktree-checkout-progress-real-git.test.ts": 769, + "src/main/git/worktrees/catalog/worktree-common-dir-comparison.test.ts": 236, + "src/main/git/worktrees/creation/worktree-configured-paths-concurrency.test.ts": 80, + "src/main/git/worktrees/creation/worktree-create-git-executor-real-git.test.ts": 528, + "src/main/git/worktrees/creation/worktree-create-preparation-real-git.test.ts": 1858, + "src/main/git/worktrees/creation/worktree-create-preparation-real-wsl.test.ts": 382, + "src/main/git/worktrees/catalog/worktree-created-description-real-git.test.ts": 1119, + "src/main/git/worktrees/catalog/worktree-created-disk-witness.test.ts": 259, + "src/main/git/worktrees/removal/worktree-delete-limit.test.ts": 33, + "src/main/git/source-control/worktree-diff-stamp-guest-gitdir.test.ts": 53, + "src/main/git/source-control/worktree-diff-stamp-host-paths.test.ts": 52, + "src/main/git/worktrees/catalog/worktree-git-capabilities.test.ts": 297, + "src/main/git/worktrees/catalog/worktree-git-path.test.ts": 77, + "src/main/git/worktrees/catalog/worktree-graph-listing.test.ts": 302, + "src/main/git/worktrees/content-paths/worktree-include-file.test.ts": 126, + "src/main/git/worktrees/catalog/worktree-list-paths.test.ts": 755, + "src/main/git/worktrees/catalog/worktree-list-porcelain.test.ts": 285, + "src/main/git/worktrees/catalog/worktree-list-reader-cancellation.test.ts": 84, + "src/main/git/worktrees/catalog/worktree-listing-created-sparse-distro.test.ts": 325, + "src/main/git/worktrees/catalog/worktree-listing-sparse-cancellation.test.ts": 229, + "src/main/git/worktrees/catalog/worktree-listing-unc-drvfs-identity.test.ts": 242, + "src/main/git/worktrees/movement/worktree-move.test.ts": 318, + "src/main/git/worktrees/movement/worktree-mutation-route-invalidation.test.ts": 287, + "src/main/git/worktrees/catalog/worktree-path-deduplication.test.ts": 220, + "src/main/git/worktrees/catalog/worktree-porcelain-parsing.test.ts": 357, + "src/main/git/worktrees/removal/worktree-posix-path-case-sensitivity.test.ts": 279, + "src/main/git/worktrees/creation/worktree-preparation-add.test.ts": 233, + "src/main/git/worktrees/creation/worktree-preparation-base-oid.test.ts": 322, + "src/main/git/worktrees/creation/worktree-preparation-cancel-latency.bench.test.ts": 361, + "src/main/git/worktrees/creation/worktree-preparation-discard-real-git.test.ts": 547, + "src/main/git/worktrees/creation/worktree-preparation-fallback-cleanup-real-git.test.ts": 737, + "src/main/git/worktrees/creation/worktree-preparation-lock-real-git.test.ts": 1352, + "src/main/git/worktrees/creation/worktree-preparation-lock.test.ts": 102, + "src/main/git/worktrees/creation/worktree-preparation-tip-refresh-real-git.test.ts": 844, + "src/main/git/worktrees/creation/worktree-preparation-tip-refresh.test.ts": 113, + "src/main/git/worktrees/removal/worktree-prune-guard.test.ts": 159, + "src/main/git/worktrees/removal/worktree-rebase-update-refs-real-git.test.ts": 284, + "src/main/git/worktrees/removal/worktree-removal-large-tree.bench.test.ts": 486, + "src/main/git/worktrees/removal/worktree-removal-real-git.test.ts": 3365, + "src/main/git/worktrees/removal/worktree-remove-branch-deletion.test.ts": 353, + "src/main/git/worktrees/creation/worktree-safety-real-git.test.ts": 549, + "src/main/git/worktrees/catalog/worktree-scan-cache-annotation-reuse.test.ts": 361, + "src/main/git/worktrees/catalog/worktree-scan-cache-sharing.test.ts": 404, + "src/main/git/worktrees/catalog/worktree-separate-git-dir.test.ts": 689, + "src/main/git/worktrees/content-paths/worktree-shared-directories.test.ts": 1045, + "src/main/git/worktrees/sparse-checkout/worktree-sparse-checkout-cache.test.ts": 283, + "src/main/git/worktrees/sparse-checkout/worktree-sparse-checkout.test.ts": 851, + "src/main/git/worktrees/sparse-checkout/worktree-sparse-state-host-paths.test.ts": 321, + "src/main/git/worktrees/content-paths/worktree-symlink-detection.test.ts": 51, "src/main/git/wsl-direct-git-read-commands.test.ts": 74, - "src/main/git/wsl-linked-worktree-git-route-invalidation.test.ts": 48, - "src/main/git/wsl-linked-worktree-git-routing.test.ts": 93, + "src/main/git/command-runner/wsl-linked-worktree-git-route-invalidation.test.ts": 48, + "src/main/git/command-runner/wsl-linked-worktree-git-routing.test.ts": 93, "src/main/git/wsl-process-group-termination.test.ts": 109, "src/main/git/wsl-windows-checkout-git-config.test.ts": 64, "src/main/git/wsl-windows-checkout-git-probe.test.ts": 273, "src/main/git/wsl-windows-checkout-sample-script.test.ts": 165, - "src/main/git/wsl-worktree-git-path.test.ts": 88, + "src/main/git/worktrees/catalog/wsl-worktree-git-path.test.ts": 88, "src/main/gitea/client-scan-invalidation.test.ts": 474, "src/main/gitea/client.test.ts": 472, "src/main/github/auth-diagnose.test.ts": 43, diff --git a/config/scripts/git-diff-blob-concurrency-benchmark.mjs b/config/scripts/git-diff-blob-concurrency-benchmark.mjs index b0228bcd962..802f4ca8bfa 100644 --- a/config/scripts/git-diff-blob-concurrency-benchmark.mjs +++ b/config/scripts/git-diff-blob-concurrency-benchmark.mjs @@ -70,7 +70,7 @@ const parent = `${head}~1` // Span file sizes to cover both fixed spawn and size-dependent read costs. const CANDIDATES = [ - 'src/main/git/status.ts', + 'src/main/git/source-control/file-diff.ts', 'src/shared/agent-hook-listener.ts', 'src/renderer/src/components/task-page/TaskPage.tsx' ] diff --git a/config/scripts/github-opened-issue-repository.test.ts b/config/scripts/github-opened-issue-repository.test.ts index bd7d10b56bc..d63b51fc149 100644 --- a/config/scripts/github-opened-issue-repository.test.ts +++ b/config/scripts/github-opened-issue-repository.test.ts @@ -65,7 +65,7 @@ vi.mock('../../src/main/github/gh-utils', async (original) => ({ repo: 'widgets' }) })) -vi.mock('../../src/main/git/remote-name-listing', () => ({ +vi.mock('../../src/main/git/remotes/remote-name-listing', () => ({ shouldProbeGitRemote: async () => true })) diff --git a/config/scripts/github-pr-assignee-repository.test.ts b/config/scripts/github-pr-assignee-repository.test.ts index c65089dfc1d..0d0260e0f30 100644 --- a/config/scripts/github-pr-assignee-repository.test.ts +++ b/config/scripts/github-pr-assignee-repository.test.ts @@ -87,7 +87,7 @@ vi.mock('../../src/main/github/gh-utils', async (original) => ({ repo: 'widgets' }) })) -vi.mock('../../src/main/git/remote-name-listing', () => ({ +vi.mock('../../src/main/git/remotes/remote-name-listing', () => ({ shouldProbeGitRemote: async () => true })) diff --git a/config/scripts/vitest-node-runtime-files.mjs b/config/scripts/vitest-node-runtime-files.mjs index 8b6b07f89cb..d9b581133e0 100644 --- a/config/scripts/vitest-node-runtime-files.mjs +++ b/config/scripts/vitest-node-runtime-files.mjs @@ -131,10 +131,10 @@ const NODE_RUNTIME_INCLUDE = [ // Asserts Node's spawn-failure close signal and that a dead worker closes its children's pipes. 'src/main/worker-thread-child-process/worker-thread-child-process.test.ts', 'src/main/git/command-runner/worker-exec-file.test.ts', - 'src/main/git/worktree-removal-real-git.test.ts', - 'src/main/git/worktree-list-paths.test.ts', - 'src/main/git/worktree-sparse-checkout.test.ts', - 'src/main/git/worktree-removal-large-tree.bench.test.ts', + 'src/main/git/worktrees/removal/worktree-removal-real-git.test.ts', + 'src/main/git/worktrees/catalog/worktree-list-paths.test.ts', + 'src/main/git/worktrees/sparse-checkout/worktree-sparse-checkout.test.ts', + 'src/main/git/worktrees/removal/worktree-removal-large-tree.bench.test.ts', 'src/main/runtime/runtime-failed-local-worktree-removal.test.ts', 'src/main/runtime/runtime-interrupted-local-worktree-removal.test.ts', 'src/main/workspaces/removal/local-worktree-removal-recovery-live.test.ts', diff --git a/src/main/__mocks__/worktree-create-preparation.ts b/src/main/__mocks__/worktree-create-preparation.ts index b426a618ae7..56ca76c48c4 100644 --- a/src/main/__mocks__/worktree-create-preparation.ts +++ b/src/main/__mocks__/worktree-create-preparation.ts @@ -36,24 +36,24 @@ export { mocks } vi.mock('node:fs/promises', () => ({ mkdir: mocks.mkdir })) vi.mock('../orcad/orcad-data-root-locality', () => ({ orcadDataRootIsOnLocalDisk: () => true })) -vi.mock('../git/worktree', () => ({ listWorktreeGraph: mocks.listWorktreeGraph })) -vi.mock('../git/worktree-scan-cache', async (importOriginal) => ({ + +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ ...(await importOriginal>()), listWorktreeGraph: mocks.listWorktreeGraph })) -vi.mock('../git/worktree-create-preparation', () => ({ +vi.mock('../git/worktrees/creation/worktree-create-preparation', () => ({ prepareWorktreeCreateCheckout: mocks.prepareCheckout, finalizePreparedWorktree: mocks.finalize, discardPreparedWorktree: mocks.discard, unlockPreparedWorktree: mocks.unlock })) -vi.mock('../git/worktree-preparation-tip-refresh', () => ({ +vi.mock('../git/worktrees/creation/worktree-preparation-tip-refresh', () => ({ refreshPreparedWorktreeTip: mocks.refreshTip })) -vi.mock('../git/worktree-base-ref-probe', () => ({ +vi.mock('../git/worktrees/creation/worktree-base-ref-probe', () => ({ resolveLocalWorktreeBaseRef: mocks.resolveBaseRef })) -vi.mock('../git/worktree-base-divergence', () => ({ +vi.mock('../git/worktrees/creation/worktree-base-divergence', () => ({ measureRetargetDivergence: mocks.measureDivergence })) vi.mock('../workspaces/execution-host/project-runtime-git-options', () => ({ diff --git a/src/main/agent-hooks/first-work-branch-rename-wsl-move.test.ts b/src/main/agent-hooks/first-work-branch-rename-wsl-move.test.ts index 9c45b1f432f..d0c7b69f929 100644 --- a/src/main/agent-hooks/first-work-branch-rename-wsl-move.test.ts +++ b/src/main/agent-hooks/first-work-branch-rename-wsl-move.test.ts @@ -17,7 +17,10 @@ const { gitExecFileAsyncMock, generateBranchNameMock, resolveTextGenerationParam resolveTextGenerationParamsMock: vi.fn() })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) vi.mock('../git/git-username', () => ({ resolveLocalGitUsername: vi.fn(async () => 'you') })) vi.mock('../text-generation/commit-message-text-generation', () => ({ generateBranchNameFromContext: generateBranchNameMock, diff --git a/src/main/agent-hooks/first-work-branch-rename.test.ts b/src/main/agent-hooks/first-work-branch-rename.test.ts index b0d5c4a167d..ac992c1e675 100644 --- a/src/main/agent-hooks/first-work-branch-rename.test.ts +++ b/src/main/agent-hooks/first-work-branch-rename.test.ts @@ -25,7 +25,10 @@ const { getConfiguredBranchPrefixMock: vi.fn((_settings: unknown, username: string | null) => username) })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) vi.mock('../git/git-username', () => ({ resolveLocalGitUsername: resolveLocalGitUsernameMock })) vi.mock('../text-generation/commit-message-text-generation', () => ({ generateBranchNameFromContext: generateBranchNameMock, diff --git a/src/main/agent-hooks/first-work-rename-runtime.ts b/src/main/agent-hooks/first-work-rename-runtime.ts index c77ba7da79e..ae32731631d 100644 --- a/src/main/agent-hooks/first-work-rename-runtime.ts +++ b/src/main/agent-hooks/first-work-rename-runtime.ts @@ -4,7 +4,7 @@ import { getRepoIdFromWorktreeId } from '../../shared/worktree/id' import type { FirstWorkBranchRenameDeps } from './first-work-branch-rename' import { rememberBranchRenameFailureOutput } from './branch-rename-failure-output' import { renameWorktreeFolderOnFirstWork } from './first-work-folder-rename' -import { moveWorktree } from '../git/worktree' +import { moveWorktree } from '../git/worktrees/movement/worktree-move' import { isWslMoveFolderWorkspaceBlocked } from '../persistence/moving-wsl-projects/wsl-move-background-backoff' import type { Store } from '../persistence/loading-store/store' import type { RuntimeStore } from '../runtime/runtime-store-contract' diff --git a/src/main/azure-devops/client.test.ts b/src/main/azure-devops/client.test.ts index 84febf605b1..5771ac311b0 100644 --- a/src/main/azure-devops/client.test.ts +++ b/src/main/azure-devops/client.test.ts @@ -11,7 +11,8 @@ import { __resetRepoDefaultBranchCacheForTests } from '../source-control/repo-de const gitExecFileAsyncMock = vi.hoisted(() => vi.fn()) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/azure-devops/pull-request-creation.test.ts b/src/main/azure-devops/pull-request-creation.test.ts index 3fee8ef0213..259babc325a 100644 --- a/src/main/azure-devops/pull-request-creation.test.ts +++ b/src/main/azure-devops/pull-request-creation.test.ts @@ -2,13 +2,14 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { createAzureDevOpsPullRequest } from './pull-request-creation' import { _resetAzureDevOpsApiVersionCache } from './azure-devops-api-request' import { _resetAzureDevOpsRepoRefCache } from './repository-ref' -import { REMOTE_URL_PROBE_TIMEOUT_MS } from '../git/remote-url-probe' +import { REMOTE_URL_PROBE_TIMEOUT_MS } from '../git/remotes/remote-url-probe' const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/azure-devops/repository-ref.test.ts b/src/main/azure-devops/repository-ref.test.ts index e8c7bcac4a6..803a96edf0e 100644 --- a/src/main/azure-devops/repository-ref.test.ts +++ b/src/main/azure-devops/repository-ref.test.ts @@ -4,7 +4,8 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) @@ -14,7 +15,7 @@ import { getAzureDevOpsRepoRefForRemote, parseAzureDevOpsRepoRef } from './repository-ref' -import { REMOTE_URL_PROBE_TIMEOUT_MS } from '../git/remote-url-probe' +import { REMOTE_URL_PROBE_TIMEOUT_MS } from '../git/remotes/remote-url-probe' describe('parseAzureDevOpsRepoRef', () => { beforeEach(() => { diff --git a/src/main/azure-devops/repository-ref.ts b/src/main/azure-devops/repository-ref.ts index 3573c62fa3b..086ceaca7b6 100644 --- a/src/main/azure-devops/repository-ref.ts +++ b/src/main/azure-devops/repository-ref.ts @@ -1,4 +1,4 @@ -import { createRemoteRefProbeCache } from '../git/remote-ref-probe-cache' +import { createRemoteRefProbeCache } from '../git/remotes/remote-ref-probe-cache' export type AzureDevOpsRepoRef = { host: string diff --git a/src/main/bitbucket/client.test.ts b/src/main/bitbucket/client.test.ts index cdbd3eb77a3..612fe554f66 100644 --- a/src/main/bitbucket/client.test.ts +++ b/src/main/bitbucket/client.test.ts @@ -5,7 +5,8 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/bitbucket/pull-request-creation.test.ts b/src/main/bitbucket/pull-request-creation.test.ts index 02a1257aa02..4340aea378a 100644 --- a/src/main/bitbucket/pull-request-creation.test.ts +++ b/src/main/bitbucket/pull-request-creation.test.ts @@ -6,7 +6,8 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/bitbucket/repository-ref.test.ts b/src/main/bitbucket/repository-ref.test.ts index 139204eb9ad..ab93caaef2f 100644 --- a/src/main/bitbucket/repository-ref.test.ts +++ b/src/main/bitbucket/repository-ref.test.ts @@ -4,7 +4,8 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) @@ -14,7 +15,7 @@ import { getBitbucketRepoRef, parseBitbucketRepoRef } from './repository-ref' -import { REMOTE_URL_PROBE_TIMEOUT_MS } from '../git/remote-url-probe' +import { REMOTE_URL_PROBE_TIMEOUT_MS } from '../git/remotes/remote-url-probe' describe('Bitbucket repository refs', () => { beforeEach(() => { diff --git a/src/main/bitbucket/repository-ref.ts b/src/main/bitbucket/repository-ref.ts index 0dc70b2d73a..48f0949afca 100644 --- a/src/main/bitbucket/repository-ref.ts +++ b/src/main/bitbucket/repository-ref.ts @@ -1,5 +1,5 @@ import { normalizeBitbucketRemoteHost } from '../../shared/git-remote-host-alias' -import { createRemoteRefProbeCache } from '../git/remote-ref-probe-cache' +import { createRemoteRefProbeCache } from '../git/remotes/remote-ref-probe-cache' export type BitbucketRepoRef = { workspace: string diff --git a/src/main/bitbucket/status-no-decrypt.test.ts b/src/main/bitbucket/status-no-decrypt.test.ts index d168440a294..b54ae20eb64 100644 --- a/src/main/bitbucket/status-no-decrypt.test.ts +++ b/src/main/bitbucket/status-no-decrypt.test.ts @@ -9,7 +9,10 @@ const OLD_ENV = process.env const OLD_FETCH = globalThis.fetch let tempHome = '' -vi.mock('../git/runner', () => ({ gitExecFileAsync: vi.fn() })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: vi.fn() +})) async function loadModules() { vi.resetModules() diff --git a/src/main/browser/cdp-bridge-integration.test.ts b/src/main/browser/cdp-bridge-integration.test.ts index 4c0313fbde6..10018fb16d9 100644 --- a/src/main/browser/cdp-bridge-integration.test.ts +++ b/src/main/browser/cdp-bridge-integration.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import '../runtime/desktop-browser-bridge/desktop-browser-bridge-allowlist.spec' import { mkdtempSync } from 'node:fs' import { RuntimeBrowserCommands } from '../runtime/browser/browser-commands' @@ -13,16 +13,16 @@ const { webContentsFromIdMock } = vi.hoisted(() => ({ webContentsFromIdMock: vi.fn() })) -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict @@ -36,10 +36,14 @@ vi.mock('electron', () => ({ app: { getPath: vi.fn(() => '/tmp'), isPackaged: false } })) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) import { BrowserManager } from './browser-manager' import { CdpBridge } from './cdp-bridge' diff --git a/src/main/codex-usage/scanner-attribution-memo.test.ts b/src/main/codex-usage/scanner-attribution-memo.test.ts index 41925ed3df5..c6d0001766b 100644 --- a/src/main/codex-usage/scanner-attribution-memo.test.ts +++ b/src/main/codex-usage/scanner-attribution-memo.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os' import type * as NodeOs from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, expect, it, vi } from 'vitest' -import type * as WorktreePathComparison from '../git/worktree-path-comparison' +import type * as WorktreePathComparison from '../git/worktrees/catalog/worktree-path-comparison' const { getPathMock, homedirMock, worktreePathComparisons } = vi.hoisted(() => ({ getPathMock: vi.fn<(name: string) => string>(), @@ -25,7 +25,7 @@ vi.mock('node:os', async () => { } }) -vi.mock('../git/worktree-path-comparison', async (importOriginal) => { +vi.mock('../git/worktrees/catalog/worktree-path-comparison', async (importOriginal) => { const actual = await importOriginal() return { ...actual, diff --git a/src/main/filesystem/host-tree-removal.ts b/src/main/filesystem/host-tree-removal.ts index 563bee871cc..87d12eb9951 100644 --- a/src/main/filesystem/host-tree-removal.ts +++ b/src/main/filesystem/host-tree-removal.ts @@ -1,6 +1,6 @@ // Host deletion needs bounded Windows lock retries and unpatched fs for Electron’s .asar handling. -import { getErrorCode } from '../git/worktree-operation-options' +import { getErrorCode } from '../git/worktrees/worktree-operation-options' import { unregisteredFolderRefusal } from '../../shared/worktree/removal' import { join, win32 } from 'node:path' import { lstat, readdir, rm, rmdir, unlink } from './asar-transparent-fs' diff --git a/src/main/git/canonical-repo-key.test.ts b/src/main/git/canonical-repo-key.test.ts index 5e06a9b1e0b..a9b8e8410ae 100644 --- a/src/main/git/canonical-repo-key.test.ts +++ b/src/main/git/canonical-repo-key.test.ts @@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const gitExecFileAsyncMock = vi.hoisted(() => vi.fn()) -vi.mock('./runner', async (importOriginal) => ({ +vi.mock('./command-runner/git-exec-file', async (importOriginal) => ({ ...((await importOriginal()) as Record), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/git/canonical-repo-key.ts b/src/main/git/canonical-repo-key.ts index 7c923435fcb..aefe55ee633 100644 --- a/src/main/git/canonical-repo-key.ts +++ b/src/main/git/canonical-repo-key.ts @@ -2,7 +2,7 @@ import type { LocalGitExecOptions } from './repo-default-base-ref' import type { GitExecOptions } from './command-runner/git-exec-options' import { toWslExecutionSpace } from '../../shared/wsl-paths' import { gitExecFileAsync } from './runner' -import { resolveRevParsePath } from './worktree-path-comparison' +import { resolveRevParsePath } from './worktrees/catalog/worktree-path-comparison' /** Fetch serialization and ref maintenance share a host-scoped Git common-dir identity across worktrees. */ diff --git a/src/main/git/checkout.ts b/src/main/git/checkout.ts index 557a99531ef..44ba402439b 100644 --- a/src/main/git/checkout.ts +++ b/src/main/git/checkout.ts @@ -1,7 +1,7 @@ import type { GitRuntimeOptions } from './git-runtime-options' import { gitOptionsForWorktree } from './git-runtime-options' import { gitExecFileAsync } from './runner' -import { runWithGitReadCacheInvalidation } from './status' +import { runWithGitReadCacheInvalidation } from './source-control/git-read-cache-invalidation' /** Reject empty and option-like names here too: relay callers can bypass RPC schema validation. */ export function assertValidBranchName(branch: string): void { diff --git a/src/main/git/checkout-workers-git-args.ts b/src/main/git/command-runner/checkout-workers-git-args.ts similarity index 88% rename from src/main/git/checkout-workers-git-args.ts rename to src/main/git/command-runner/checkout-workers-git-args.ts index fb13ff13a25..51b47ebd779 100644 --- a/src/main/git/checkout-workers-git-args.ts +++ b/src/main/git/command-runner/checkout-workers-git-args.ts @@ -1,9 +1,9 @@ -import { gitExecFileAsync } from './runner' +import { gitExecFileAsync } from './git-exec-file' import { getErrorCode, gitExecOptions, type GitWorktreeExecOptions -} from './worktree-operation-options' +} from '../worktrees/worktree-operation-options' // Git checks out with one worker by default; 0 means one per core (Git 2.32+; older Git ignores the key). const PARALLEL_CHECKOUT_GIT_ARGS = ['-c', 'checkout.workers=0'] as const diff --git a/src/main/git/git-capability-state.test.ts b/src/main/git/command-runner/git-capability-state.test.ts similarity index 100% rename from src/main/git/git-capability-state.test.ts rename to src/main/git/command-runner/git-capability-state.test.ts diff --git a/src/main/git/git-capability-state.ts b/src/main/git/command-runner/git-capability-state.ts similarity index 93% rename from src/main/git/git-capability-state.ts rename to src/main/git/command-runner/git-capability-state.ts index d2369b22836..b0375f59691 100644 --- a/src/main/git/git-capability-state.ts +++ b/src/main/git/command-runner/git-capability-state.ts @@ -1,5 +1,5 @@ -import { GitCapabilityCache } from '../../shared/git-capability-cache' -import { parseWslUncPath } from '../../shared/wsl-paths' +import { GitCapabilityCache } from '../../../shared/git-capability-cache' +import { parseWslUncPath } from '../../../shared/wsl-paths' import { isWslLinkedWorktreeGitRoutingCandidate, prepareWslLinkedWorktreeGitRouting diff --git a/src/main/git/command-runner/git-command-resolution-windows-checkout.test.ts b/src/main/git/command-runner/git-command-resolution-windows-checkout.test.ts index 74b64fc13ad..60d5cdffd1c 100644 --- a/src/main/git/command-runner/git-command-resolution-windows-checkout.test.ts +++ b/src/main/git/command-runner/git-command-resolution-windows-checkout.test.ts @@ -9,7 +9,7 @@ import { import { resetWslLinkedWorktreeGitRoutingForTests, seedWslLinkedWorktreeGitRoutingForTests -} from '../wsl-linked-worktree-git-routing' +} from './wsl-linked-worktree-git-routing' import { bulkPathspecCommands } from '../source-control/git-pathspec' import { commandLineLength, diff --git a/src/main/git/command-runner/git-command-resolution.ts b/src/main/git/command-runner/git-command-resolution.ts index 337e22d1bf3..9f33dcf6cad 100644 --- a/src/main/git/command-runner/git-command-resolution.ts +++ b/src/main/git/command-runner/git-command-resolution.ts @@ -11,7 +11,7 @@ import { peekWslGitReadEnvironment, WSL_GIT_READ_ENVIRONMENT_WAIT_MS } from '../wsl-git-read-environment' -import { usesHostGitForWslLinkedWorktree } from '../wsl-linked-worktree-git-routing' +import { usesHostGitForWslLinkedWorktree } from './wsl-linked-worktree-git-routing' import { withWslWindowsCheckoutGitConfig } from '../wsl-windows-checkout-git-config' import { resolveCommand, type ResolvedCommand } from './wsl-command-resolution' import type { GitExecOptions } from './git-exec-options' diff --git a/src/main/git/command-runner/git-exec-admission-lifetime.test.ts b/src/main/git/command-runner/git-exec-admission-lifetime.test.ts index 5b18a31e606..7b95ac99367 100644 --- a/src/main/git/command-runner/git-exec-admission-lifetime.test.ts +++ b/src/main/git/command-runner/git-exec-admission-lifetime.test.ts @@ -46,7 +46,7 @@ vi.mock('../../../shared/git-fetch-head-lock', async (importOriginal) => { import { RuntimeRemoteFetchController } from '../../runtime/runtime-remote-fetch-controller' import { gitExecFileAsync, gitExecFileAsyncBuffer } from './git-exec-file' import { execFileCapture } from './exec-file-capture' -import { isGitWorktreeMutationInFlight } from '../git-worktree-mutation-state' +import { isGitWorktreeMutationInFlight } from './git-worktree-mutation-state' import { acquireGitAdmission, GitAdmissionScheduler, diff --git a/src/main/git/command-runner/git-exec-file.ts b/src/main/git/command-runner/git-exec-file.ts index f6359218d81..8c1f00902cf 100644 --- a/src/main/git/command-runner/git-exec-file.ts +++ b/src/main/git/command-runner/git-exec-file.ts @@ -25,7 +25,7 @@ import { classifyGitCommand } from '../../../shared/git-command-classification' import { createAbortError } from './abort-error' import { readCapturedGitBuffer, readCapturedGitString } from './captured-git-output' import { runUnlessGitCwdKnownMissing } from './missing-git-spawn-cwd' -import { trackGitWorktreeMutation } from '../git-worktree-mutation-state' +import { trackGitWorktreeMutation } from './git-worktree-mutation-state' import { routeLocalGitOptions, runAdmittedWslGit } from './local-git-runtime-route' import { gitRunsIn } from './git-runs-in' diff --git a/src/main/git/command-runner/git-operation-executor.test.ts b/src/main/git/command-runner/git-operation-executor.test.ts index f3f48ea7e47..68b68d95211 100644 --- a/src/main/git/command-runner/git-operation-executor.test.ts +++ b/src/main/git/command-runner/git-operation-executor.test.ts @@ -6,7 +6,10 @@ import { _resetGitAdmissionForTests, _gitAdmissionSnapshotForTests } from './git-subprocess-admission' -import { worktreeCreateGit, worktreePreparationGit } from '../worktree-create-git-executor' +import { + worktreeCreateGit, + worktreePreparationGit +} from '../worktrees/creation/worktree-create-git-executor' afterEach(() => _resetGitAdmissionForTests()) diff --git a/src/main/git/git-worktree-mutation-state.test.ts b/src/main/git/command-runner/git-worktree-mutation-state.test.ts similarity index 100% rename from src/main/git/git-worktree-mutation-state.test.ts rename to src/main/git/command-runner/git-worktree-mutation-state.test.ts diff --git a/src/main/git/git-worktree-mutation-state.ts b/src/main/git/command-runner/git-worktree-mutation-state.ts similarity index 80% rename from src/main/git/git-worktree-mutation-state.ts rename to src/main/git/command-runner/git-worktree-mutation-state.ts index 8a50dccd609..db3adb95e44 100644 --- a/src/main/git/git-worktree-mutation-state.ts +++ b/src/main/git/command-runner/git-worktree-mutation-state.ts @@ -1,11 +1,14 @@ import { realpath } from 'node:fs/promises' import { resolve } from 'node:path' -import { classifyGitCommand, findGitSubcommandIndex } from '../../shared/git-command-classification' -import { normalizeRuntimePathForComparison } from '../../shared/cross-platform-path' -import { resolveWorktreeHostPath } from '../../shared/git-metadata-path' -import { resolveGitFetchHeadCommand } from '../../shared/git-fetch-head-lock' -import { resolveGitDir } from './source-control/resolve-git-dir' -import type { GitRuntimeOptions } from './git-runtime-options' +import { + classifyGitCommand, + findGitSubcommandIndex +} from '../../../shared/git-command-classification' +import { normalizeRuntimePathForComparison } from '../../../shared/cross-platform-path' +import { resolveWorktreeHostPath } from '../../../shared/git-metadata-path' +import { resolveGitFetchHeadCommand } from '../../../shared/git-fetch-head-lock' +import { resolveGitDir } from '../source-control/resolve-git-dir' +import type { GitRuntimeOptions } from '../git-runtime-options' // These can write refs or objects without changing HEAD, the index, or the working tree. const WORKTREE_NEUTRAL_SUBCOMMANDS = new Set(['fetch', 'push', 'ls-remote', 'merge-tree']) diff --git a/src/main/git/wsl-linked-worktree-git-route-invalidation.test.ts b/src/main/git/command-runner/wsl-linked-worktree-git-route-invalidation.test.ts similarity index 96% rename from src/main/git/wsl-linked-worktree-git-route-invalidation.test.ts rename to src/main/git/command-runner/wsl-linked-worktree-git-route-invalidation.test.ts index 6790b6be45d..2f4117bd6cd 100644 --- a/src/main/git/wsl-linked-worktree-git-route-invalidation.test.ts +++ b/src/main/git/command-runner/wsl-linked-worktree-git-route-invalidation.test.ts @@ -2,9 +2,9 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import { invalidateWslLinkedWorktreeGitRouting, prepareWslLinkedWorktreeGitRouting, - resetWslLinkedWorktreeGitRoutingForTests, - type WslLinkedWorktreeRoutingFileSystem + resetWslLinkedWorktreeGitRoutingForTests } from './wsl-linked-worktree-git-routing' +import type { WslLinkedWorktreeRoutingFileSystem } from './wsl-linked-worktree-git-route-probe' afterEach(() => resetWslLinkedWorktreeGitRoutingForTests()) diff --git a/src/main/git/wsl-linked-worktree-git-route-probe.ts b/src/main/git/command-runner/wsl-linked-worktree-git-route-probe.ts similarity index 100% rename from src/main/git/wsl-linked-worktree-git-route-probe.ts rename to src/main/git/command-runner/wsl-linked-worktree-git-route-probe.ts diff --git a/src/main/git/wsl-linked-worktree-git-routing.test.ts b/src/main/git/command-runner/wsl-linked-worktree-git-routing.test.ts similarity index 99% rename from src/main/git/wsl-linked-worktree-git-routing.test.ts rename to src/main/git/command-runner/wsl-linked-worktree-git-routing.test.ts index 62c2ebae8a8..8797ea845aa 100644 --- a/src/main/git/wsl-linked-worktree-git-routing.test.ts +++ b/src/main/git/command-runner/wsl-linked-worktree-git-routing.test.ts @@ -1,6 +1,9 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import { parseWindowsLinkedGitdir, + type WslLinkedWorktreeRoutingFileSystem +} from './wsl-linked-worktree-git-route-probe' +import { prepareWslLinkedWorktreeGitRouting, resetWslLinkedWorktreeGitRoutingForTests, seedWslLinkedWorktreeGitRoutingForTests, @@ -10,8 +13,7 @@ import { WSL_LINKED_WORKTREE_ROUTE_MAX_PROBES_TOTAL, WSL_LINKED_WORKTREE_ROUTE_PROBE_TIMEOUT_MS, WSL_LINKED_WORKTREE_ROUTE_RETRY_BASE_MS, - WSL_LINKED_WORKTREE_ROUTE_TTL_MS, - type WslLinkedWorktreeRoutingFileSystem + WSL_LINKED_WORKTREE_ROUTE_TTL_MS } from './wsl-linked-worktree-git-routing' afterEach(() => resetWslLinkedWorktreeGitRoutingForTests()) diff --git a/src/main/git/wsl-linked-worktree-git-routing.ts b/src/main/git/command-runner/wsl-linked-worktree-git-routing.ts similarity index 98% rename from src/main/git/wsl-linked-worktree-git-routing.ts rename to src/main/git/command-runner/wsl-linked-worktree-git-routing.ts index 8ae73d072bc..3edd61ec7b8 100644 --- a/src/main/git/wsl-linked-worktree-git-routing.ts +++ b/src/main/git/command-runner/wsl-linked-worktree-git-routing.ts @@ -5,11 +5,6 @@ import { type WslLinkedWorktreeRoutingFileSystem } from './wsl-linked-worktree-git-route-probe' -export { - parseWindowsLinkedGitdir, - type WslLinkedWorktreeRoutingFileSystem -} from './wsl-linked-worktree-git-route-probe' - type CachedRoute = { usesHostGit: boolean; expiresAt: number } type TransientRouteFailure = { count: number; retryAfter: number } diff --git a/src/main/git/git-status-read-lease-owner.ts b/src/main/git/git-status-read-lease-owner.ts deleted file mode 100644 index 05916a1838c..00000000000 --- a/src/main/git/git-status-read-lease-owner.ts +++ /dev/null @@ -1,2 +0,0 @@ -// Preserve main import paths while sharing read ownership with relay hosts. -export { GitStatusReadLeaseOwner } from '../../shared/git-status-read-lease-owner' diff --git a/src/main/git/git-username.ts b/src/main/git/git-username.ts index a200a54ecaa..ead682403d5 100644 --- a/src/main/git/git-username.ts +++ b/src/main/git/git-username.ts @@ -1,5 +1,5 @@ import { extractExecError, ghExecFileAsync, gitExecFileAsync } from './runner' -import { parseHostedRemote } from './hosted-remote-url' +import { parseHostedRemote } from './remotes/hosted-remote-url' import { resolveDefaultBaseRefViaExec } from './repo' import { createGitConfigSnapshotRunner } from '../../shared/git-config-snapshot-runner' diff --git a/src/main/git/huge-folder-ignore.test.ts b/src/main/git/huge-folder-ignore.test.ts index bee10d24aee..cee1922ebcd 100644 --- a/src/main/git/huge-folder-ignore.test.ts +++ b/src/main/git/huge-folder-ignore.test.ts @@ -8,7 +8,7 @@ const { checkIgnoredPathsMock } = vi.hoisted(() => ({ checkIgnoredPathsMock: vi.fn<(worktreePath: string, paths: string[]) => Promise>() })) -vi.mock('./check-ignored-paths', () => ({ +vi.mock('./source-control/check-ignored-paths', () => ({ checkIgnoredPaths: checkIgnoredPathsMock })) diff --git a/src/main/git/huge-folder-ignore.ts b/src/main/git/huge-folder-ignore.ts index 5651f9d9521..a9e6fd0a064 100644 --- a/src/main/git/huge-folder-ignore.ts +++ b/src/main/git/huge-folder-ignore.ts @@ -1,7 +1,7 @@ import { existsSync } from 'node:fs' import { appendFile, readFile, stat } from 'node:fs/promises' import * as path from 'node:path' -import { checkIgnoredPaths } from './check-ignored-paths' +import { checkIgnoredPaths } from './source-control/check-ignored-paths' import type { GitRuntimeOptions } from './git-runtime-options' // Offer common dependency/build folders when unignored content saturates status. diff --git a/src/main/git/local-git-object-quarantine.test.ts b/src/main/git/local-git-object-quarantine.test.ts index 28ebcb03e36..c7bdaec50de 100644 --- a/src/main/git/local-git-object-quarantine.test.ts +++ b/src/main/git/local-git-object-quarantine.test.ts @@ -9,13 +9,13 @@ import { import { resetWslLinkedWorktreeGitRoutingForTests, seedWslLinkedWorktreeGitRoutingForTests -} from './wsl-linked-worktree-git-routing' +} from './command-runner/wsl-linked-worktree-git-routing' const { readRepoCommonDirFromGitMock } = vi.hoisted(() => ({ readRepoCommonDirFromGitMock: vi.fn() })) -vi.mock('./worktree-list-reader', () => ({ +vi.mock('./worktrees/catalog/worktree-list-reader', () => ({ readRepoCommonDirFromGit: readRepoCommonDirFromGitMock })) vi.mock('../../shared/git-object-quarantine', async (importOriginal) => ({ diff --git a/src/main/git/local-git-object-quarantine.ts b/src/main/git/local-git-object-quarantine.ts index 13dfaa24f0c..7fb17f97a1a 100644 --- a/src/main/git/local-git-object-quarantine.ts +++ b/src/main/git/local-git-object-quarantine.ts @@ -8,8 +8,8 @@ import { } from '../../shared/git-object-quarantine' import { toLinuxPath, toWindowsWslPath } from '../../shared/wsl-paths' import { parseWslPath } from '../wsl/filesystem/unc-path-access' -import { usesHostGitForWslLinkedWorktree } from './wsl-linked-worktree-git-routing' -import { readRepoCommonDirFromGit } from './worktree-list-reader' +import { usesHostGitForWslLinkedWorktree } from './command-runner/wsl-linked-worktree-git-routing' +import { readRepoCommonDirFromGit } from './worktrees/catalog/worktree-list-reader' export type LocalGitObjectQuarantine = { /** `env` is a full process env for `gitExecFileAsync`, or undefined to run unquarantined. */ diff --git a/src/main/git/merge-tree-object-quarantine-real-git.test.ts b/src/main/git/merge-tree-object-quarantine-real-git.test.ts index cbf7bc94953..6a1b52e9144 100644 --- a/src/main/git/merge-tree-object-quarantine-real-git.test.ts +++ b/src/main/git/merge-tree-object-quarantine-real-git.test.ts @@ -12,10 +12,10 @@ import { getPRConflictSummary } from '../github/conflict-summary' import { __resetPRConflictSummaryDerivationCachesForTests } from '../github/conflict-summary-cache' -import { getLocalGitCapabilityCache } from './git-capability-state' +import { getLocalGitCapabilityCache } from './command-runner/git-capability-state' import { createLocalGitObjectQuarantine } from './local-git-object-quarantine' import { gitExecFileAsync } from './runner' -import { deleteBranchAfterWorktreeRemoval } from './worktree-branch-removal' +import { deleteBranchAfterWorktreeRemoval } from './worktrees/removal/worktree-branch-removal' const scratchFoldersMade = vi.hoisted((): string[] => []) diff --git a/src/main/git/fork-remote-refspec.test.ts b/src/main/git/refs/fork-remotes/fork-remote-refspec.test.ts similarity index 100% rename from src/main/git/fork-remote-refspec.test.ts rename to src/main/git/refs/fork-remotes/fork-remote-refspec.test.ts diff --git a/src/main/git/fork-remote-refspec.ts b/src/main/git/refs/fork-remotes/fork-remote-refspec.ts similarity index 100% rename from src/main/git/fork-remote-refspec.ts rename to src/main/git/refs/fork-remotes/fork-remote-refspec.ts diff --git a/src/main/git/fork-remote-stale-branch-refspec.test.ts b/src/main/git/refs/fork-remotes/fork-remote-stale-branch-refspec.test.ts similarity index 100% rename from src/main/git/fork-remote-stale-branch-refspec.test.ts rename to src/main/git/refs/fork-remotes/fork-remote-stale-branch-refspec.test.ts diff --git a/src/main/git/fork-remote-stale-branch-refspec.ts b/src/main/git/refs/fork-remotes/fork-remote-stale-branch-refspec.ts similarity index 96% rename from src/main/git/fork-remote-stale-branch-refspec.ts rename to src/main/git/refs/fork-remotes/fork-remote-stale-branch-refspec.ts index bd242c0c0df..7b95b2c32f5 100644 --- a/src/main/git/fork-remote-stale-branch-refspec.ts +++ b/src/main/git/refs/fork-remotes/fork-remote-stale-branch-refspec.ts @@ -1,5 +1,5 @@ // Literal stale refspecs can fail the entire fetch; wildcard zero-match tolerance does not cover them. -import { extractExecError } from './exec-error' +import { extractExecError } from '../../exec-error' import { removeStaleForkFetchRefspec, type GitExecFn } from './fork-remote-refspec' const MISSING_REMOTE_REF_PATTERN = /couldn't find remote ref (refs\/heads\/\S+)/ diff --git a/src/main/git/local-repo-ref-maintenance-probe-retry.test.ts b/src/main/git/refs/maintenance/local-repo-ref-maintenance-probe-retry.test.ts similarity index 96% rename from src/main/git/local-repo-ref-maintenance-probe-retry.test.ts rename to src/main/git/refs/maintenance/local-repo-ref-maintenance-probe-retry.test.ts index 2c944b2f46b..5a7924bd2b4 100644 --- a/src/main/git/local-repo-ref-maintenance-probe-retry.test.ts +++ b/src/main/git/refs/maintenance/local-repo-ref-maintenance-probe-retry.test.ts @@ -1,13 +1,13 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import type * as GitRunner from './runner' -import { RepoRefMaintenance } from '../../shared/repo-ref-maintenance' +import type * as GitRunner from '../../command-runner/git-exec-file' +import { RepoRefMaintenance } from '../../../../shared/repo-ref-maintenance' import { REF_MAINTENANCE_ATTEMPT_DEADLINE_MS, REF_MAINTENANCE_CLEAN_COOLDOWN_MS -} from '../../shared/repo-ref-maintenance-policy' +} from '../../../../shared/repo-ref-maintenance-policy' const gitExecFileAsyncMock = vi.hoisted(() => vi.fn()) -vi.mock('./runner', async (importOriginal) => ({ +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ ...(await importOriginal()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/git/local-repo-ref-maintenance-wsl-stopped.test.ts b/src/main/git/refs/maintenance/local-repo-ref-maintenance-wsl-stopped.test.ts similarity index 89% rename from src/main/git/local-repo-ref-maintenance-wsl-stopped.test.ts rename to src/main/git/refs/maintenance/local-repo-ref-maintenance-wsl-stopped.test.ts index 0acc7c715aa..2ecf3845f1a 100644 --- a/src/main/git/local-repo-ref-maintenance-wsl-stopped.test.ts +++ b/src/main/git/refs/maintenance/local-repo-ref-maintenance-wsl-stopped.test.ts @@ -1,21 +1,21 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import type * as GitRunner from './runner' -import type * as WslUncAccessGate from '../wsl/filesystem/wsl-unc-access-gate' -import { RepoRefMaintenance } from '../../shared/repo-ref-maintenance' +import type * as GitRunner from '../../command-runner/git-exec-file' +import type * as WslUncAccessGate from '../../../wsl/filesystem/wsl-unc-access-gate' +import { RepoRefMaintenance } from '../../../../shared/repo-ref-maintenance' import { WslDistroStoppedError, WslDistroUnverifiableError -} from '../wsl/filesystem/wsl-unc-access-gate' +} from '../../../wsl/filesystem/wsl-unc-access-gate' const mocks = vi.hoisted(() => ({ gitExecFileAsync: vi.fn(), assertWslUncPathRunning: vi.fn() })) -vi.mock('./runner', async (importOriginal) => ({ +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ ...(await importOriginal()), gitExecFileAsync: mocks.gitExecFileAsync })) -vi.mock('../wsl/filesystem/wsl-unc-access-gate', async (importOriginal) => ({ +vi.mock('../../../wsl/filesystem/wsl-unc-access-gate', async (importOriginal) => ({ ...(await importOriginal()), assertWslUncPathRunning: mocks.assertWslUncPathRunning, // Off Windows no path maps to a distro; stand in for the WSL repo's UNC root. diff --git a/src/main/git/local-repo-ref-maintenance.test.ts b/src/main/git/refs/maintenance/local-repo-ref-maintenance.test.ts similarity index 94% rename from src/main/git/local-repo-ref-maintenance.test.ts rename to src/main/git/refs/maintenance/local-repo-ref-maintenance.test.ts index 57bb29d7fbc..0a12c8afc96 100644 --- a/src/main/git/local-repo-ref-maintenance.test.ts +++ b/src/main/git/refs/maintenance/local-repo-ref-maintenance.test.ts @@ -3,17 +3,17 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const gitExecFileAsyncMock = vi.hoisted(() => vi.fn()) const readRepoCommonDirFromGitMock = vi.hoisted(() => vi.fn()) -vi.mock('./runner', async (importOriginal) => ({ +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ ...((await importOriginal()) as Record), gitExecFileAsync: gitExecFileAsyncMock })) -vi.mock('./worktree-list-reader', async (importOriginal) => ({ +vi.mock('../../worktrees/catalog/worktree-list-reader', async (importOriginal) => ({ ...((await importOriginal()) as Record), readRepoCommonDirFromGit: readRepoCommonDirFromGitMock })) -import { _resetCanonicalRepoKeyCacheForTests } from './canonical-repo-key' +import { _resetCanonicalRepoKeyCacheForTests } from '../../canonical-repo-key' import { _resetLocalRepoRefMaintenanceForTests, createLocalRepoRefMaintenanceTarget, diff --git a/src/main/git/local-repo-ref-maintenance.ts b/src/main/git/refs/maintenance/local-repo-ref-maintenance.ts similarity index 93% rename from src/main/git/local-repo-ref-maintenance.ts rename to src/main/git/refs/maintenance/local-repo-ref-maintenance.ts index b61612dadc2..ced6f231913 100644 --- a/src/main/git/local-repo-ref-maintenance.ts +++ b/src/main/git/refs/maintenance/local-repo-ref-maintenance.ts @@ -1,6 +1,6 @@ import { posix, win32 } from 'node:path' -import { isWindowsAbsolutePathLike } from '../../shared/cross-platform-path' -import { RepoRefMaintenance } from '../../shared/repo-ref-maintenance' +import { isWindowsAbsolutePathLike } from '../../../../shared/cross-platform-path' +import { RepoRefMaintenance } from '../../../../shared/repo-ref-maintenance' import { PACK_REFS_ARGS, PACK_REFS_TIMEOUT_MS, @@ -8,18 +8,21 @@ import { type PackedRefsLockReporter, type RepoRefMaintenanceOptions, type RepoRefMaintenanceTarget -} from '../../shared/repo-ref-maintenance-policy' -import { isWslUncPath, toWindowsWslPath } from '../../shared/wsl-paths' -import { withSpan } from '../observability/tracer' +} from '../../../../shared/repo-ref-maintenance-policy' +import { isWslUncPath, toWindowsWslPath } from '../../../../shared/wsl-paths' +import { withSpan } from '../../../observability/tracer' import { PackRefsLockOwnership } from './pack-refs-lock-ownership' import { clearRepoPackIndexMaintenanceCache, isUnsetGitConfigError, maintainRepoPackIndex } from './repo-pack-index-maintenance' -import { gitExecFileAsync } from './runner' -import { assertWslUncPathRunning, wslDistroForPath } from '../wsl/filesystem/wsl-unc-access-gate' -import { readRepoCommonDirFromGit } from './worktree-list-reader' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { + assertWslUncPathRunning, + wslDistroForPath +} from '../../../wsl/filesystem/wsl-unc-access-gate' +import { readRepoCommonDirFromGit } from '../../worktrees/catalog/worktree-list-reader' // Maintain native/WSL repos locally; SSH maintenance belongs on its execution host. diff --git a/src/main/git/pack-refs-lock-ownership.test.ts b/src/main/git/refs/maintenance/pack-refs-lock-ownership.test.ts similarity index 100% rename from src/main/git/pack-refs-lock-ownership.test.ts rename to src/main/git/refs/maintenance/pack-refs-lock-ownership.test.ts diff --git a/src/main/git/pack-refs-lock-ownership.ts b/src/main/git/refs/maintenance/pack-refs-lock-ownership.ts similarity index 96% rename from src/main/git/pack-refs-lock-ownership.ts rename to src/main/git/refs/maintenance/pack-refs-lock-ownership.ts index 6925912d650..a6ddae0fc51 100644 --- a/src/main/git/pack-refs-lock-ownership.ts +++ b/src/main/git/refs/maintenance/pack-refs-lock-ownership.ts @@ -1,10 +1,10 @@ import { readFile, rm, stat, writeFile } from 'node:fs/promises' import { posix, win32 } from 'node:path' -import { isWindowsAbsolutePathLike } from '../../shared/cross-platform-path' +import { isWindowsAbsolutePathLike } from '../../../../shared/cross-platform-path' import { PACK_REFS_TIMEOUT_MS, PACKED_REFS_LOCK_POLL_MS -} from '../../shared/repo-ref-maintenance-policy' +} from '../../../../shared/repo-ref-maintenance-policy' // Minimum lock age before recovery considers an attributed pack abandoned. const ABANDONED_LOCK_AGE_MS = PACK_REFS_TIMEOUT_MS diff --git a/src/main/git/repo-maintenance-admission.test.ts b/src/main/git/refs/maintenance/repo-maintenance-admission.test.ts similarity index 96% rename from src/main/git/repo-maintenance-admission.test.ts rename to src/main/git/refs/maintenance/repo-maintenance-admission.test.ts index 2eda10f5f50..7cb868878db 100644 --- a/src/main/git/repo-maintenance-admission.test.ts +++ b/src/main/git/refs/maintenance/repo-maintenance-admission.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { REF_MAINTENANCE_ATTEMPT_DEADLINE_MS } from '../../shared/repo-ref-maintenance-policy' +import { REF_MAINTENANCE_ATTEMPT_DEADLINE_MS } from '../../../../shared/repo-ref-maintenance-policy' type CaptureOptions = { signal?: AbortSignal; onChildTerminated?: () => void } const { capture, probe, stamp, count, claimOwner, releaseOwner, stopWatch } = vi.hoisted(() => ({ @@ -19,8 +19,8 @@ const { capture, probe, stamp, count, claimOwner, releaseOwner, stopWatch } = vi stopWatch: vi.fn() })) -vi.mock('../../shared/loose-ref-count', () => ({ countLooseRefs: count })) -vi.mock('./worktree-list-reader', () => ({ +vi.mock('../../../../shared/loose-ref-count', () => ({ countLooseRefs: count })) +vi.mock('../../worktrees/catalog/worktree-list-reader', () => ({ readRepoCommonDirFromGit: async () => '/repo/.git' })) vi.mock('./pack-refs-lock-ownership', () => ({ @@ -30,7 +30,7 @@ vi.mock('./pack-refs-lock-ownership', () => ({ release = releaseOwner } })) -vi.mock('../observability/tracer', () => ({ +vi.mock('../../../observability/tracer', () => ({ withSpan: async (_name: string, run: (span: unknown) => unknown) => run({ setAttribute: () => {} }) })) @@ -38,27 +38,27 @@ vi.mock('./repo-pack-index-state', () => ({ probeRepoPackIndexDirectory: probe, readRepoPackDirectoryStamp: stamp })) -vi.mock('./runner', async () => import('./command-runner/git-exec-file')) -vi.mock('./command-runner/exec-file-capture', () => ({ +vi.mock('../../runner', async () => import('../../command-runner/git-exec-file')) +vi.mock('../../command-runner/exec-file-capture', () => ({ execFileCapture: capture, execFileCaptureToTermination: capture })) -vi.mock('../observability/instrumentation', () => ({ +vi.mock('../../../observability/instrumentation', () => ({ withGitSpan: async (_args: unknown, run: (span: unknown) => unknown) => run({ setAttribute: () => {} }) })) -import { RepoRefMaintenance } from '../../shared/repo-ref-maintenance' +import { RepoRefMaintenance } from '../../../../shared/repo-ref-maintenance' import { createLocalRepoRefMaintenanceTarget } from './local-repo-ref-maintenance' import { clearRepoPackIndexMaintenanceCache } from './repo-pack-index-maintenance' -import { gitExecFileAsync } from './command-runner/git-exec-file' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { GENERAL_CAP } from '../../../../shared/git-admission-state' +import { GitAdmissionScheduler } from '../../../../shared/git-admission-scheduler' import { - GENERAL_CAP, - GitAdmissionScheduler, acquireGitAdmission, _gitAdmissionSnapshotForTests, _resetGitAdmissionForTests -} from './command-runner/git-subprocess-admission' +} from '../../command-runner/git-subprocess-admission' beforeEach(() => { vi.resetAllMocks() diff --git a/src/main/git/repo-pack-index-maintenance.test.ts b/src/main/git/refs/maintenance/repo-pack-index-maintenance.test.ts similarity index 98% rename from src/main/git/repo-pack-index-maintenance.test.ts rename to src/main/git/refs/maintenance/repo-pack-index-maintenance.test.ts index 3abd6b4c626..2f77d5c306b 100644 --- a/src/main/git/repo-pack-index-maintenance.test.ts +++ b/src/main/git/refs/maintenance/repo-pack-index-maintenance.test.ts @@ -7,7 +7,10 @@ const { gitExecFileAsyncMock, opendirMock, statMock, openMock } = vi.hoisted(() openMock: vi.fn() })) -vi.mock('./runner', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) vi.mock('node:fs/promises', () => ({ opendir: opendirMock, stat: statMock, open: openMock })) import { diff --git a/src/main/git/repo-pack-index-maintenance.ts b/src/main/git/refs/maintenance/repo-pack-index-maintenance.ts similarity index 91% rename from src/main/git/repo-pack-index-maintenance.ts rename to src/main/git/refs/maintenance/repo-pack-index-maintenance.ts index 578586f281b..9b11bc808c1 100644 --- a/src/main/git/repo-pack-index-maintenance.ts +++ b/src/main/git/refs/maintenance/repo-pack-index-maintenance.ts @@ -1,10 +1,10 @@ import { posix, win32 } from 'node:path' -import { BoundedMap } from '../../shared/bounded-map' -import { isWindowsAbsolutePathLike } from '../../shared/cross-platform-path' -import type { PackIndexMaintenanceOutcome } from '../../shared/repo-pack-index-maintenance-policy' -import type { RefMaintenanceSpan } from '../../shared/repo-ref-maintenance-policy' +import { BoundedMap } from '../../../../shared/bounded-map' +import { isWindowsAbsolutePathLike } from '../../../../shared/cross-platform-path' +import type { PackIndexMaintenanceOutcome } from '../../../../shared/repo-pack-index-maintenance-policy' +import type { RefMaintenanceSpan } from '../../../../shared/repo-ref-maintenance-policy' import { probeRepoPackIndexDirectory, readRepoPackDirectoryStamp } from './repo-pack-index-state' -import { gitExecFileAsync } from './runner' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' // Git's default auto-GC pack limit is 50; defer indexing until fragmentation is clear. export const PACK_INDEX_THRESHOLD = 64 diff --git a/src/main/git/repo-pack-index-state.test.ts b/src/main/git/refs/maintenance/repo-pack-index-state.test.ts similarity index 100% rename from src/main/git/repo-pack-index-state.test.ts rename to src/main/git/refs/maintenance/repo-pack-index-state.test.ts diff --git a/src/main/git/repo-pack-index-state.ts b/src/main/git/refs/maintenance/repo-pack-index-state.ts similarity index 97% rename from src/main/git/repo-pack-index-state.ts rename to src/main/git/refs/maintenance/repo-pack-index-state.ts index 92ba425d8fd..0fc147b1d9f 100644 --- a/src/main/git/repo-pack-index-state.ts +++ b/src/main/git/refs/maintenance/repo-pack-index-state.ts @@ -1,6 +1,6 @@ import { open, opendir, stat } from 'node:fs/promises' import { posix, win32 } from 'node:path' -import { isWindowsAbsolutePathLike } from '../../shared/cross-platform-path' +import { isWindowsAbsolutePathLike } from '../../../../shared/cross-platform-path' export const PACK_INDEX_PROBE_ENTRY_LIMIT = 65_536 export const PACK_INDEX_PROBE_TIMEOUT_MS = 1_000 diff --git a/src/main/git/repo-ref-maintenance-real-git.test.ts b/src/main/git/refs/maintenance/repo-ref-maintenance-real-git.test.ts similarity index 97% rename from src/main/git/repo-ref-maintenance-real-git.test.ts rename to src/main/git/refs/maintenance/repo-ref-maintenance-real-git.test.ts index 49b7fbaf2ee..1b5dcde35ba 100644 --- a/src/main/git/repo-ref-maintenance-real-git.test.ts +++ b/src/main/git/refs/maintenance/repo-ref-maintenance-real-git.test.ts @@ -3,16 +3,16 @@ import { cp, mkdir, mkdtemp, readFile, readdir, rm, writeFile } from 'node:fs/pr import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest' -import { countLooseRefs } from '../../shared/loose-ref-count' -import { RepoRefMaintenance } from '../../shared/repo-ref-maintenance' -import { PACK_INDEX_MAINTENANCE_COOLDOWN_MS } from '../../shared/repo-pack-index-maintenance-policy' +import { countLooseRefs } from '../../../../shared/loose-ref-count' +import { RepoRefMaintenance } from '../../../../shared/repo-ref-maintenance' +import { PACK_INDEX_MAINTENANCE_COOLDOWN_MS } from '../../../../shared/repo-pack-index-maintenance-policy' import { _resetLocalRepoRefMaintenanceForTests, createLocalRepoRefMaintenanceTarget, getLocalRepoRefMaintenance, setRepoMaintenanceActivityProbe } from './local-repo-ref-maintenance' -import { forceDeleteLocalBranch } from './worktree-branch-removal' +import { forceDeleteLocalBranch } from '../../worktrees/removal/worktree-branch-removal' import { maintainRepoPackIndex, PACK_INDEX_THRESHOLD } from './repo-pack-index-maintenance' const roots: string[] = [] diff --git a/src/main/git/remote-rebase.ts b/src/main/git/remote-rebase.ts index edce789c490..66a7f624349 100644 --- a/src/main/git/remote-rebase.ts +++ b/src/main/git/remote-rebase.ts @@ -8,9 +8,9 @@ import { } from '../../shared/git-rebase-source' import type { GitRuntimeOptions } from './git-runtime-options' import { gitOptionsForWorktree } from './git-runtime-options' -import { withLocalGitCapabilityCacheForExecution } from './git-capability-state' +import { withLocalGitCapabilityCacheForExecution } from './command-runner/git-capability-state' import { gitExecFileAsync } from './runner' -import { runWithGitReadCacheInvalidation } from './status' +import { runWithGitReadCacheInvalidation } from './source-control/git-read-cache-invalidation' export async function gitPullRebaseFromBase( worktreePath: string, diff --git a/src/main/git/remote.test.ts b/src/main/git/remote.test.ts index f2c01a355ff..32a904d7d15 100644 --- a/src/main/git/remote.test.ts +++ b/src/main/git/remote.test.ts @@ -4,12 +4,13 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('./runner', () => ({ +vi.mock('./command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) import { REBASE_SOURCE_FETCH_TIMEOUT_MS } from '../../shared/git-rebase-source' -import { clearGitCapabilityStateForTests } from './git-capability-state' +import { clearGitCapabilityStateForTests } from './command-runner/git-capability-state' import { gitFastForward, gitFetch, gitPull, gitPullRebaseFromBase, gitPush } from './remote' const REBASE_OPERATION_OPTIONS = { diff --git a/src/main/git/remote.ts b/src/main/git/remote.ts index 248670a7f3d..2b82971e0bf 100644 --- a/src/main/git/remote.ts +++ b/src/main/git/remote.ts @@ -10,11 +10,11 @@ import { gitOptionsForWorktree } from './git-runtime-options' import { postponeRepoRefMaintenance, withRepoRefMaintenancePaused -} from './local-repo-ref-maintenance' +} from './refs/maintenance/local-repo-ref-maintenance' import { validateGitPushTarget } from './push-target-validation' import { gitExecFileAsync } from './runner' -import { fetchForkRemoteWithStaleRefspecRepair } from './fork-remote-stale-branch-refspec' -import { runWithGitReadCacheInvalidation } from './status' +import { fetchForkRemoteWithStaleRefspecRepair } from './refs/fork-remotes/fork-remote-stale-branch-refspec' +import { runWithGitReadCacheInvalidation } from './source-control/git-read-cache-invalidation' import { runWithGitWorktreeOperationLock } from '../../shared/git-worktree-operation-lock' export { gitPullRebaseFromBase } from './remote-rebase' diff --git a/src/main/git/coalesced-probe.test.ts b/src/main/git/remotes/coalesced-probe.test.ts similarity index 100% rename from src/main/git/coalesced-probe.test.ts rename to src/main/git/remotes/coalesced-probe.test.ts diff --git a/src/main/git/coalesced-probe.ts b/src/main/git/remotes/coalesced-probe.ts similarity index 100% rename from src/main/git/coalesced-probe.ts rename to src/main/git/remotes/coalesced-probe.ts diff --git a/src/main/git/hosted-remote-url.test.ts b/src/main/git/remotes/hosted-remote-url.test.ts similarity index 100% rename from src/main/git/hosted-remote-url.test.ts rename to src/main/git/remotes/hosted-remote-url.test.ts diff --git a/src/main/git/hosted-remote-url.ts b/src/main/git/remotes/hosted-remote-url.ts similarity index 98% rename from src/main/git/hosted-remote-url.ts rename to src/main/git/remotes/hosted-remote-url.ts index 500fbd2c1d8..a708d372b10 100644 --- a/src/main/git/hosted-remote-url.ts +++ b/src/main/git/remotes/hosted-remote-url.ts @@ -1,4 +1,4 @@ -import { normalizeForgeWebHost } from '../../shared/git-remote-host-alias' +import { normalizeForgeWebHost } from '../../../shared/git-remote-host-alias' // Scoped local fork of the hosted-git-info@9.0.3 behavior Orca used. // Keep only the provider parsing and file/commit URL construction needed by source links. diff --git a/src/main/git/remote-name-listing.test.ts b/src/main/git/remotes/remote-name-listing.test.ts similarity index 95% rename from src/main/git/remote-name-listing.test.ts rename to src/main/git/remotes/remote-name-listing.test.ts index dc60a8c36cb..f66100cf5f6 100644 --- a/src/main/git/remote-name-listing.test.ts +++ b/src/main/git/remotes/remote-name-listing.test.ts @@ -5,8 +5,11 @@ const { gitExecFileAsyncMock, readLocalGitConfigSignatureMock } = vi.hoisted(() readLocalGitConfigSignatureMock: vi.fn<() => Promise>(async () => 'sig-1') })) -vi.mock('./runner', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) -vi.mock('../github/local-git-config-signature', () => ({ +vi.mock('../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) +vi.mock('../../github/local-git-config-signature', () => ({ readLocalGitConfigSignature: readLocalGitConfigSignatureMock })) diff --git a/src/main/git/remote-name-listing.ts b/src/main/git/remotes/remote-name-listing.ts similarity index 95% rename from src/main/git/remote-name-listing.ts rename to src/main/git/remotes/remote-name-listing.ts index 66856b42c42..03f2d723817 100644 --- a/src/main/git/remote-name-listing.ts +++ b/src/main/git/remotes/remote-name-listing.ts @@ -1,8 +1,8 @@ -import { readLocalGitConfigSignature } from '../github/local-git-config-signature' +import { readLocalGitConfigSignature } from '../../github/local-git-config-signature' import { runCoalescedProbe, type CoalescedProbes } from './coalesced-probe' -import type { GitAdmissionTier } from './command-runner/git-exec-options' +import type { GitAdmissionTier } from '../../../shared/rpc-contract/git-admission-tier-params' import { REMOTE_URL_PROBE_TIMEOUT_MS } from './remote-url-probe' -import { gitExecFileAsync } from './runner' +import { gitExecFileAsync } from '../command-runner/git-exec-file' export type RemoteNameListingGitOptions = { wslDistro?: string diff --git a/src/main/git/remote-ref-probe-cache.test.ts b/src/main/git/remotes/remote-ref-probe-cache.test.ts similarity index 95% rename from src/main/git/remote-ref-probe-cache.test.ts rename to src/main/git/remotes/remote-ref-probe-cache.test.ts index 88f2b5ce2a0..79e1c5068bb 100644 --- a/src/main/git/remote-ref-probe-cache.test.ts +++ b/src/main/git/remotes/remote-ref-probe-cache.test.ts @@ -4,7 +4,10 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('./runner', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) +vi.mock('../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) import { PROBE_COALESCE_STALE_MS } from './coalesced-probe' import { createRemoteRefProbeCache, NEGATIVE_ENTRY_TTL_MS } from './remote-ref-probe-cache' diff --git a/src/main/git/remote-ref-probe-cache.ts b/src/main/git/remotes/remote-ref-probe-cache.ts similarity index 97% rename from src/main/git/remote-ref-probe-cache.ts rename to src/main/git/remotes/remote-ref-probe-cache.ts index 1c6ed35ed39..053f9658aec 100644 --- a/src/main/git/remote-ref-probe-cache.ts +++ b/src/main/git/remotes/remote-ref-probe-cache.ts @@ -1,6 +1,6 @@ import { runCoalescedProbe, type CoalescedProbes } from './coalesced-probe' import { isTransientGitProbeError, readRemoteUrl } from './remote-url-probe' -import type { GitAdmissionTier } from './command-runner/git-exec-options' +import type { GitAdmissionTier } from '../../../shared/rpc-contract/git-admission-tier-params' const REPO_REF_CACHE_MAX_ENTRIES = 512 diff --git a/src/main/git/remote-url-probe.ts b/src/main/git/remotes/remote-url-probe.ts similarity index 88% rename from src/main/git/remote-url-probe.ts rename to src/main/git/remotes/remote-url-probe.ts index e50b15ba1a5..2e3dc2f62cf 100644 --- a/src/main/git/remote-url-probe.ts +++ b/src/main/git/remotes/remote-url-probe.ts @@ -1,8 +1,8 @@ -import { gitExecFileAsync } from './runner' +import { gitExecFileAsync } from '../command-runner/git-exec-file' import { isStableMissingGitRemoteError } from './stable-missing-git-remote-error' -import type { GitAdmissionTier } from './command-runner/git-exec-options' -import { requireReachableGitRoute } from '../providers/execution-host-provider-dispatch' -import { getConnectionExecutionHostId } from '../../shared/execution-host' +import type { GitAdmissionTier } from '../../../shared/rpc-contract/git-admission-tier-params' +import { requireReachableGitRoute } from '../../providers/execution-host-provider-dispatch' +import { getConnectionExecutionHostId } from '../../../shared/execution-host' // Bound config probes so stalled mounts or WSL cannot hold every forge lookup indefinitely. export const REMOTE_URL_PROBE_TIMEOUT_MS = 30_000 diff --git a/src/main/git/repo-remote-drift-real.test.ts b/src/main/git/remotes/repo-remote-drift-real.test.ts similarity index 97% rename from src/main/git/repo-remote-drift-real.test.ts rename to src/main/git/remotes/repo-remote-drift-real.test.ts index 3ee2f7c45c9..6fb27ad2e7c 100644 --- a/src/main/git/repo-remote-drift-real.test.ts +++ b/src/main/git/remotes/repo-remote-drift-real.test.ts @@ -3,7 +3,7 @@ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it } from 'vitest' -import { getRecentDriftSubjects, getRemoteDrift } from './repo' +import { getRecentDriftSubjects, getRemoteDrift } from '../repo' describe('remote drift real Git contract', () => { const tempPaths: string[] = [] diff --git a/src/main/git/repo-remote-file-target.ts b/src/main/git/remotes/repo-remote-file-target.ts similarity index 93% rename from src/main/git/repo-remote-file-target.ts rename to src/main/git/remotes/repo-remote-file-target.ts index 4c69acf569b..11a75332dfe 100644 --- a/src/main/git/repo-remote-file-target.ts +++ b/src/main/git/remotes/repo-remote-file-target.ts @@ -1,10 +1,10 @@ import { parseHostedRemote } from './hosted-remote-url' -import { parseGitRemoteFetchUrls } from '../../shared/git-remote-url-index' -import { sourceRefsForTarget } from '../../shared/git-branch-cleanup-fetch' -import { waitForPromiseWithSignal } from '../../shared/abort-signal-reason' -import { DEFAULT_BASE_REF_PROBES } from '../../shared/git-default-base-ref' -import { gitExecOptions, type LocalGitExecOptions } from './repo-default-base-ref' -import { gitExecFileAsync } from './runner' +import { parseGitRemoteFetchUrls } from '../../../shared/git-remote-url-index' +import { sourceRefsForTarget } from '../../../shared/git-branch-cleanup-fetch' +import { waitForPromiseWithSignal } from '../../../shared/abort-signal-reason' +import { DEFAULT_BASE_REF_PROBES } from '../../../shared/git-default-base-ref' +import { gitExecOptions, type LocalGitExecOptions } from '../repo-default-base-ref' +import { gitExecFileAsync } from '../command-runner/git-exec-file' export async function getRemoteFileTarget( repoPath: string, diff --git a/src/main/git/stable-missing-git-remote-error.ts b/src/main/git/remotes/stable-missing-git-remote-error.ts similarity index 100% rename from src/main/git/stable-missing-git-remote-error.ts rename to src/main/git/remotes/stable-missing-git-remote-error.ts diff --git a/src/main/git/repo-base-ref-search.ts b/src/main/git/repo-base-ref-search.ts index 560b312bfa6..1fb9f01b97d 100644 --- a/src/main/git/repo-base-ref-search.ts +++ b/src/main/git/repo-base-ref-search.ts @@ -9,7 +9,7 @@ import { } from '../../shared/repo-search-limits' import { isSafeGitRefName } from '../../shared/git-status-upstream-ref' import { isRemoteHeadRef } from '../../shared/hosted-review-refs' -import { getLocalGitCapabilityCache } from './git-capability-state' +import { getLocalGitCapabilityCache } from './command-runner/git-capability-state' import { gitExecOptions, type LocalGitExecOptions } from './repo-default-base-ref' import { gitExecFileAsync } from './runner' import { isQualifiedBaseRef, resolveBaseRefSearchSelector } from './base-ref-search-selector' diff --git a/src/main/git/repo-detection-command.test.ts b/src/main/git/repo-detection-command.test.ts index 318356a7346..082428555f8 100644 --- a/src/main/git/repo-detection-command.test.ts +++ b/src/main/git/repo-detection-command.test.ts @@ -2,7 +2,15 @@ import { afterEach, describe, expect, it, vi } from 'vitest' import { gitExecFileAsync, gitExecFileSync } from './runner' import { gitRepoOutput, runGitRepoCommands, runGitRepoCommandsSync } from './repo-detection-command' -vi.mock('./runner', () => ({ gitExecFileAsync: vi.fn(), gitExecFileSync: vi.fn() })) +vi.mock('./command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: vi.fn() +})) + +vi.mock('./command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: vi.fn() +})) afterEach(() => vi.resetAllMocks()) describe('repository command execution', () => { diff --git a/src/main/git/repo-search-ref-compat.test.ts b/src/main/git/repo-search-ref-compat.test.ts index 226f3278317..1e04079cc0e 100644 --- a/src/main/git/repo-search-ref-compat.test.ts +++ b/src/main/git/repo-search-ref-compat.test.ts @@ -4,12 +4,17 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, +vi.mock('./command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('./command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileSync: vi.fn() })) -import { clearGitCapabilityStateForTests } from './git-capability-state' +import { clearGitCapabilityStateForTests } from './command-runner/git-capability-state' import { searchBaseRefs } from './repo' describe('searchBaseRefs git compatibility', () => { diff --git a/src/main/git/repo-username.test.ts b/src/main/git/repo-username.test.ts index 10c5609dac1..0c59d09cb6c 100644 --- a/src/main/git/repo-username.test.ts +++ b/src/main/git/repo-username.test.ts @@ -1,14 +1,22 @@ +import type * as GitExecFileModule from './command-runner/git-exec-file' +import type * as GhExecFileModule from './command-runner/gh-exec-file' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import type * as RunnerModule from './runner' const gitExecFileAsyncMock = vi.hoisted(() => vi.fn()) const ghExecFileAsyncMock = vi.hoisted(() => vi.fn()) -vi.mock('./runner', async () => { - const actual = await vi.importActual('./runner') +vi.mock('./command-runner/git-exec-file', async () => { + const actual = await vi.importActual('./command-runner/git-exec-file') + return { + ...actual, + gitExecFileAsync: gitExecFileAsyncMock + } +}) + +vi.mock('./command-runner/gh-exec-file', async () => { + const actual = await vi.importActual('./command-runner/gh-exec-file') return { ...actual, - gitExecFileAsync: gitExecFileAsyncMock, ghExecFileAsync: ghExecFileAsyncMock } }) diff --git a/src/main/git/repo.ts b/src/main/git/repo.ts index 5af732258af..63e24e95c3c 100644 --- a/src/main/git/repo.ts +++ b/src/main/git/repo.ts @@ -1,7 +1,7 @@ import { basename } from 'node:path' import { parseGitRevListAheadBehindCounts } from '../../shared/git-rev-list-output' -import { buildHostedRemoteCommitUrl, buildHostedRemoteFileUrl } from './hosted-remote-url' -import { getRemoteFileTarget } from './repo-remote-file-target' +import { buildHostedRemoteCommitUrl, buildHostedRemoteFileUrl } from './remotes/hosted-remote-url' +import { getRemoteFileTarget } from './remotes/repo-remote-file-target' import { DEFAULT_BASE_REF_PROBE_TIMEOUT_MS, getDefaultBaseRefAsync, diff --git a/src/main/git/runner-wsl-direct-read.test.ts b/src/main/git/runner-wsl-direct-read.test.ts index 523d2355b30..5005407a53e 100644 --- a/src/main/git/runner-wsl-direct-read.test.ts +++ b/src/main/git/runner-wsl-direct-read.test.ts @@ -33,9 +33,9 @@ import { } from './wsl-git-read-environment' import { prepareWslLinkedWorktreeGitRouting, - resetWslLinkedWorktreeGitRoutingForTests, - type WslLinkedWorktreeRoutingFileSystem -} from './wsl-linked-worktree-git-routing' + resetWslLinkedWorktreeGitRoutingForTests +} from './command-runner/wsl-linked-worktree-git-routing' +import type { WslLinkedWorktreeRoutingFileSystem } from './command-runner/wsl-linked-worktree-git-route-probe' afterEach(() => _resetGitAdmissionForTests()) diff --git a/src/main/git/runner-wsl-linked-gitdir-timeout.test.ts b/src/main/git/runner-wsl-linked-gitdir-timeout.test.ts index 527c5e9b99f..8af227578ae 100644 --- a/src/main/git/runner-wsl-linked-gitdir-timeout.test.ts +++ b/src/main/git/runner-wsl-linked-gitdir-timeout.test.ts @@ -27,7 +27,7 @@ afterEach(() => _resetGitAdmissionForTests()) import { resetWslLinkedWorktreeGitRoutingForTests, WSL_LINKED_WORKTREE_ROUTE_PROBE_TIMEOUT_MS -} from './wsl-linked-worktree-git-routing' +} from './command-runner/wsl-linked-worktree-git-routing' function createMockChild(): EventEmitter & { pid: number; kill: ReturnType } { const child = new EventEmitter() as EventEmitter & { diff --git a/src/main/git/runner-wsl-linked-gitdir-windows.test.ts b/src/main/git/runner-wsl-linked-gitdir-windows.test.ts index c3d77c1d7cd..bb8b6f4aefe 100644 --- a/src/main/git/runner-wsl-linked-gitdir-windows.test.ts +++ b/src/main/git/runner-wsl-linked-gitdir-windows.test.ts @@ -4,8 +4,8 @@ import { join } from 'node:path' import { afterEach, describe, expect, it } from 'vitest' import { gitExecFileAsync, gitExecFileAsyncBuffer, gitStreamStdout } from './runner' import { toLinuxPath, toWindowsWslPath } from '../../shared/wsl-paths' -import { listWorktrees } from './worktree' -import { resetWslLinkedWorktreeGitRoutingForTests } from './wsl-linked-worktree-git-routing' +import { listWorktrees } from './worktrees/catalog/worktree-scan-cache' +import { resetWslLinkedWorktreeGitRoutingForTests } from './command-runner/wsl-linked-worktree-git-routing' const distro = process.env.ORCA_TEST_WSL_DISTRO?.trim() const fixtureRoots: string[] = [] diff --git a/src/main/git/source-control/branch-compare.ts b/src/main/git/source-control/branch-compare.ts index d0415365124..3853fc1c592 100644 --- a/src/main/git/source-control/branch-compare.ts +++ b/src/main/git/source-control/branch-compare.ts @@ -5,7 +5,7 @@ import type { import { readBranchCompareHead } from '../../../shared/git-branch-compare-head' import { resolveWorktreeAddBaseRef } from '../../../shared/worktree/base-ref' import type { GitRuntimeOptions } from '../git-runtime-options' -import { resolveWorktreeBaseCommitOid } from '../worktree-base-ref-probe' +import { resolveWorktreeBaseCommitOid } from '../worktrees/creation/worktree-base-ref-probe' import { loadBranchChanges } from './branch-change-entries' import { countCompareDivergence, diff --git a/src/main/git/source-control/bulk-pathspec-command-line-budget.test.ts b/src/main/git/source-control/bulk-pathspec-command-line-budget.test.ts index 81150602a26..551604adc9d 100644 --- a/src/main/git/source-control/bulk-pathspec-command-line-budget.test.ts +++ b/src/main/git/source-control/bulk-pathspec-command-line-budget.test.ts @@ -10,7 +10,8 @@ const gitExecFileAsync = vi.fn(async (_args: string[], _options: { stdin?: strin stderr: '' })) -vi.mock('../runner', () => ({ +vi.mock('../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: (args: string[], options: { stdin?: string }) => gitExecFileAsync(args, options) })) vi.mock('./git-read-cache-invalidation', () => ({ invalidateGitReadCaches: vi.fn() })) diff --git a/src/main/git/check-ignored-paths.test.ts b/src/main/git/source-control/check-ignored-paths.test.ts similarity index 87% rename from src/main/git/check-ignored-paths.test.ts rename to src/main/git/source-control/check-ignored-paths.test.ts index 398d7c18650..0e6ab900ea7 100644 --- a/src/main/git/check-ignored-paths.test.ts +++ b/src/main/git/source-control/check-ignored-paths.test.ts @@ -1,9 +1,10 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { checkIgnoredPaths } from './check-ignored-paths' -import { gitExecFileAsync } from './runner' -import { GIT_CHECK_IGNORE_TIMEOUT_MS } from '../../shared/git-check-ignore-stdio' +import { gitExecFileAsync } from '../command-runner/git-exec-file' +import { GIT_CHECK_IGNORE_TIMEOUT_MS } from '../../../shared/git-check-ignore-stdio' -vi.mock('./runner', () => ({ +vi.mock('../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: vi.fn() })) diff --git a/src/main/git/check-ignored-paths.ts b/src/main/git/source-control/check-ignored-paths.ts similarity index 84% rename from src/main/git/check-ignored-paths.ts rename to src/main/git/source-control/check-ignored-paths.ts index 65e2a88f73d..136dff6270b 100644 --- a/src/main/git/check-ignored-paths.ts +++ b/src/main/git/source-control/check-ignored-paths.ts @@ -1,13 +1,13 @@ -import type { GitRuntimeOptions } from './git-runtime-options' -import { gitOptionsForWorktree } from './git-runtime-options' -import { gitExecFileAsync } from './runner' +import type { GitRuntimeOptions } from '../git-runtime-options' +import { gitOptionsForWorktree } from '../git-runtime-options' +import { gitExecFileAsync } from '../command-runner/git-exec-file' import { encodeGitCheckIgnorePaths, GIT_CHECK_IGNORE_STDIN_ARGS, GIT_CHECK_IGNORE_TIMEOUT_MS, parseGitCheckIgnorePaths, splitGitCheckIgnorePathsByStdinBytes -} from '../../shared/git-check-ignore-stdio' +} from '../../../shared/git-check-ignore-stdio' type GitExecError = Error & { stdout?: string; code?: number | string } diff --git a/src/main/git/source-control/drive-checkout-suspect-real-git.test.ts b/src/main/git/source-control/drive-checkout-suspect-real-git.test.ts index 21015a2acd5..48251357f09 100644 --- a/src/main/git/source-control/drive-checkout-suspect-real-git.test.ts +++ b/src/main/git/source-control/drive-checkout-suspect-real-git.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type * as CheckoutGitConfig from '../wsl-windows-checkout-git-config' -import type * as GitRunner from '../runner' +import type * as GitRunner from '../command-runner/git-stream-stdout' import { runProcess } from '@orca/process-host' import { createDebouncedBatch } from '../../ipc/filesystem/watchers/filesystem-watcher-batch-control' import { watcherLifecycleState } from '../../ipc/filesystem/watchers/filesystem-watcher-lifecycle-state' @@ -31,7 +31,7 @@ vi.mock('../wsl-windows-checkout-git-config', async (importOriginal) => { } }) -vi.mock('../runner', async (importOriginal) => { +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => { const actual = await importOriginal() return { ...actual, diff --git a/src/main/git/source-control/drive-checkout-suspect-status.test.ts b/src/main/git/source-control/drive-checkout-suspect-status.test.ts index 172a06726ed..e8330f7c947 100644 --- a/src/main/git/source-control/drive-checkout-suspect-status.test.ts +++ b/src/main/git/source-control/drive-checkout-suspect-status.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type * as CheckoutGitConfig from '../wsl-windows-checkout-git-config' -import type * as GitRunner from '../runner' +import type * as GitRunner from '../command-runner/git-stream-stdout' import type * as WatcherObservers from '../../ipc/filesystem/watchers/local-watcher-event-observers' import type { GitStatusEntry } from '../../../shared/git-status-types' import { notifyLocalWatcherEvents } from '../../ipc/filesystem/watchers/local-watcher-event-observers' @@ -38,7 +38,7 @@ vi.mock('../../ipc/filesystem/watchers/local-watcher-event-observers', async (im return { ...actual, findCoveringLocalWatchRoot: () => mocks.coveringRoot } }) -vi.mock('../runner', async (importOriginal) => { +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => { const actual = await importOriginal() return { ...actual, gitStreamStdout: mocks.gitStreamStdout } }) diff --git a/src/main/git/source-control/drive-checkout-suspect-status.ts b/src/main/git/source-control/drive-checkout-suspect-status.ts index 303436d8f2a..82f714d0e10 100644 --- a/src/main/git/source-control/drive-checkout-suspect-status.ts +++ b/src/main/git/source-control/drive-checkout-suspect-status.ts @@ -9,7 +9,7 @@ import { observeLocalWatcherEvents } from '../../ipc/filesystem/watchers/local-watcher-event-observers' import { gitOptionalLocksDisabledEnv, gitStreamStdout } from '../runner' -import { usesHostGitForWslLinkedWorktree } from '../wsl-linked-worktree-git-routing' +import { usesHostGitForWslLinkedWorktree } from '../command-runner/wsl-linked-worktree-git-routing' import { withWslWindowsCheckoutGitConfig, wslWindowsCheckoutKey diff --git a/src/main/git/source-control/drive-checkout-suspect-writes-real-git.test.ts b/src/main/git/source-control/drive-checkout-suspect-writes-real-git.test.ts index 8dfa2ee900e..83305b1784b 100644 --- a/src/main/git/source-control/drive-checkout-suspect-writes-real-git.test.ts +++ b/src/main/git/source-control/drive-checkout-suspect-writes-real-git.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type * as CheckoutGitConfig from '../wsl-windows-checkout-git-config' -import type * as GitRunner from '../runner' +import type * as GitRunner from '../command-runner/git-exec-file' import { runProcess } from '@orca/process-host' import { createDebouncedBatch } from '../../ipc/filesystem/watchers/filesystem-watcher-batch-control' import { watcherLifecycleState } from '../../ipc/filesystem/watchers/filesystem-watcher-lifecycle-state' @@ -31,7 +31,7 @@ vi.mock('../wsl-windows-checkout-git-config', async (importOriginal) => { } }) -vi.mock('../runner', async (importOriginal) => { +vi.mock('../command-runner/git-exec-file', async (importOriginal) => { const actual = await importOriginal() return { ...actual, diff --git a/src/main/git/source-control/git-read-cache-invalidation.ts b/src/main/git/source-control/git-read-cache-invalidation.ts index 02b2ae039a8..078883c24ad 100644 --- a/src/main/git/source-control/git-read-cache-invalidation.ts +++ b/src/main/git/source-control/git-read-cache-invalidation.ts @@ -3,8 +3,8 @@ import type { GitStatusResult } from '../../../shared/git-status-types' import { InFlightPromiseDedupe } from '../../../shared/in-flight-promise-dedupe' import { clearGitStatusLineStatsCache } from '../../../shared/git-status-line-stats-cache' import { invalidateGitBranchLineTotalInFlight } from '../../../shared/git-branch-line-total' -import { GitStatusReadLeaseOwner } from '../git-status-read-lease-owner' -import { invalidateGitUpstreamStatusReads } from '../upstream' +import { GitStatusReadLeaseOwner } from '../../../shared/git-status-read-lease-owner' +import { invalidateGitUpstreamStatusReads } from './upstream' import { clearSubmodulePathsCache } from './submodule-paths' import { resolvedUpstreamNameCache } from './resolved-upstream-name-cache' import { SettledDiffCache } from './settled-diff-cache' diff --git a/src/main/git/git-upstream-status-read-owner.test.ts b/src/main/git/source-control/git-upstream-status-read-owner.test.ts similarity index 96% rename from src/main/git/git-upstream-status-read-owner.test.ts rename to src/main/git/source-control/git-upstream-status-read-owner.test.ts index 92c174778c9..7ace150653f 100644 --- a/src/main/git/git-upstream-status-read-owner.test.ts +++ b/src/main/git/source-control/git-upstream-status-read-owner.test.ts @@ -1,6 +1,6 @@ import { describe, expect, it, vi } from 'vitest' -import type { GitUpstreamStatus } from '../../shared/git-status-types' -import type { GitPushTarget } from '../../shared/worktree/types' +import type { GitUpstreamStatus } from '../../../shared/git-status-types' +import type { GitPushTarget } from '../../../shared/worktree/types' import { GitUpstreamStatusReadOwner, type GitUpstreamStatusExecutionIdentity diff --git a/src/main/git/git-upstream-status-read-owner.ts b/src/main/git/source-control/git-upstream-status-read-owner.ts similarity index 88% rename from src/main/git/git-upstream-status-read-owner.ts rename to src/main/git/source-control/git-upstream-status-read-owner.ts index ec745248e0b..b4eb0de93bb 100644 --- a/src/main/git/git-upstream-status-read-owner.ts +++ b/src/main/git/source-control/git-upstream-status-read-owner.ts @@ -1,6 +1,6 @@ -import type { GitUpstreamStatus } from '../../shared/git-status-types' -import type { GitPushTarget } from '../../shared/worktree/types' -import { InFlightPromiseDedupe, stableInFlightKey } from '../../shared/in-flight-promise-dedupe' +import type { GitUpstreamStatus } from '../../../shared/git-status-types' +import type { GitPushTarget } from '../../../shared/worktree/types' +import { InFlightPromiseDedupe, stableInFlightKey } from '../../../shared/in-flight-promise-dedupe' /** Fix key order for JSON.stringify and make new push-target fields fail the exhaustive type check. */ function pushTargetKeyParts(pushTarget: GitPushTarget): readonly unknown[] { diff --git a/src/main/git/porcelain-v1-records.test.ts b/src/main/git/source-control/porcelain-v1-records.test.ts similarity index 100% rename from src/main/git/porcelain-v1-records.test.ts rename to src/main/git/source-control/porcelain-v1-records.test.ts diff --git a/src/main/git/porcelain-v1-records.ts b/src/main/git/source-control/porcelain-v1-records.ts similarity index 100% rename from src/main/git/porcelain-v1-records.ts rename to src/main/git/source-control/porcelain-v1-records.ts diff --git a/src/main/git/settled-diff-cache-bounds.test.ts b/src/main/git/source-control/settled-diff-cache-bounds.test.ts similarity index 94% rename from src/main/git/settled-diff-cache-bounds.test.ts rename to src/main/git/source-control/settled-diff-cache-bounds.test.ts index 1252dc18c0b..6cea877d6f7 100644 --- a/src/main/git/settled-diff-cache-bounds.test.ts +++ b/src/main/git/source-control/settled-diff-cache-bounds.test.ts @@ -1,12 +1,12 @@ import { describe, expect, it } from 'vitest' -import type { GitDiffResult } from '../../shared/git-diff-compare-types' +import type { GitDiffResult } from '../../../shared/git-diff-compare-types' import { MAX_SETTLED_DIFF_CACHE_ENTRIES, MAX_SETTLED_DIFF_CACHE_RESULT_CHARACTERS, MAX_SETTLED_DIFF_CACHE_TOTAL_CHARACTERS, SettledDiffCache -} from './source-control/settled-diff-cache' -import type { WorktreeDiffStamp } from './source-control/worktree-diff-stamp' +} from './settled-diff-cache' +import type { WorktreeDiffStamp } from './worktree-diff-stamp' function settledStamp(value: string): WorktreeDiffStamp { // Old enough that the racy-write margin is satisfied. diff --git a/src/main/git/source-control/stage-worktree-changes.test.ts b/src/main/git/source-control/stage-worktree-changes.test.ts index c7d6c47551b..f10bdb44095 100644 --- a/src/main/git/source-control/stage-worktree-changes.test.ts +++ b/src/main/git/source-control/stage-worktree-changes.test.ts @@ -4,7 +4,7 @@ import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, describe, expect, it } from 'vitest' import { DEFAULT_GIT_STATUS_LIMIT } from '../../../shared/git-status-limit' -import { getStatus } from '../status' +import { getStatus } from './status-read' import { bulkStageFiles, stageWorktreeChanges } from './staging' const tempRoots: string[] = [] diff --git a/src/main/git/source-control/staging.ts b/src/main/git/source-control/staging.ts index d67dbc3edb7..dfdbaf36bbb 100644 --- a/src/main/git/source-control/staging.ts +++ b/src/main/git/source-control/staging.ts @@ -14,7 +14,7 @@ import { type GitStageWorktreeScope, type GitStageWorktreeScopeReceipt } from '../../../shared/git-stage-worktree-scope' -import { findExistingWorktreeSymlinkPaths } from '../worktree-symlink-detection' +import { findExistingWorktreeSymlinkPaths } from '../worktrees/content-paths/worktree-symlink-detection' import { redoWriteForDriveCheckoutSuspects } from './drive-checkout-suspect-writes' import { runWithGitWorktreeOperationLock } from '../../../shared/git-worktree-operation-lock' diff --git a/src/main/git/status-branch-compare-real-ref.test.ts b/src/main/git/source-control/status-branch-compare-real-ref.test.ts similarity index 98% rename from src/main/git/status-branch-compare-real-ref.test.ts rename to src/main/git/source-control/status-branch-compare-real-ref.test.ts index 07854c1ea6f..c5e865a9bfa 100644 --- a/src/main/git/status-branch-compare-real-ref.test.ts +++ b/src/main/git/source-control/status-branch-compare-real-ref.test.ts @@ -3,7 +3,7 @@ import { mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, describe, expect, it } from 'vitest' -import { getBranchCompare } from './status' +import { getBranchCompare } from './branch-compare' const tempRoots: string[] = [] diff --git a/src/main/git/status-branch-compare.test.ts b/src/main/git/source-control/status-branch-compare.test.ts similarity index 91% rename from src/main/git/status-branch-compare.test.ts rename to src/main/git/source-control/status-branch-compare.test.ts index 589ab4e034a..a190d1e0bae 100644 --- a/src/main/git/status-branch-compare.test.ts +++ b/src/main/git/source-control/status-branch-compare.test.ts @@ -1,5 +1,9 @@ +import type * as RunnerModule from '../runner' +import type * as GitExecFileModule from '../command-runner/git-exec-file' +import type * as GitStreamStdoutModule from '../command-runner/git-stream-stdout' +import type * as GitProcessEnvModule from '../command-runner/git-process-env' import { beforeEach, describe, expect, it, vi } from 'vitest' -import type * as BoundedFileReader from '../../shared/node-bounded-file-reader' +import type * as BoundedFileReader from '../../../shared/node-bounded-file-reader' import { createBoundedFileReaderModuleMock, createFsPromisesModuleMock, @@ -28,7 +32,7 @@ const { existsSyncMock: vi.fn() })) -vi.mock('./runner', () => +vi.mock('../runner', () => createGitRunnerModuleMock({ gitExecFileAsyncMock, gitExecFileAsyncBufferMock, @@ -36,6 +40,31 @@ vi.mock('./runner', () => }) ) +vi.mock('../command-runner/git-exec-file', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitExecFileAsync: runnerMocks.gitExecFileAsync, + gitExecFileAsyncBuffer: runnerMocks.gitExecFileAsyncBuffer + } +}) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitStreamStdout: runnerMocks.gitStreamStdout + } +}) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitOptionalLocksDisabledEnv: runnerMocks.gitOptionalLocksDisabledEnv + } +}) + vi.mock('fs/promises', () => createFsPromisesModuleMock({ lstatMock, realpathMock, readFileMock, statMock, rmMock }) ) @@ -44,14 +73,15 @@ vi.mock('fs', () => ({ existsSync: existsSyncMock })) -vi.mock('../../shared/node-bounded-file-reader', async (importOriginal) => +vi.mock('../../../shared/node-bounded-file-reader', async (importOriginal) => createBoundedFileReaderModuleMock(await importOriginal(), { readFileMock, statMock }) ) -import { getBranchCompare, getCommitCompare } from './status' +import { getBranchCompare } from './branch-compare' +import { getCommitCompare } from './commit-compare' describe('getBranchCompare', () => { beforeEach(() => { diff --git a/src/main/git/status-branch-line-total-exec-contract.test.ts b/src/main/git/source-control/status-branch-line-total-exec-contract.test.ts similarity index 90% rename from src/main/git/status-branch-line-total-exec-contract.test.ts rename to src/main/git/source-control/status-branch-line-total-exec-contract.test.ts index ff5b347adb7..e5b57968097 100644 --- a/src/main/git/status-branch-line-total-exec-contract.test.ts +++ b/src/main/git/source-control/status-branch-line-total-exec-contract.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../command-runner/git-exec-file' +import type * as GitStreamStdoutModule from '../command-runner/git-stream-stdout' import { execFileSync } from 'node:child_process' import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' @@ -6,10 +8,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { buildGitBranchLineTotalDiffArgs, invalidateGitBranchLineTotalInFlight -} from '../../shared/git-branch-line-total' +} from '../../../shared/git-branch-line-total' -import type * as BranchLineTotal from '../../shared/git-branch-line-total' -import type * as GitRunner from './runner' +import type * as BranchLineTotal from '../../../shared/git-branch-line-total' // Spy on real Git argv to validate opt-in and coalescing without stubbing results. const { gitExecCalls, execHooks, coalescerJoins } = vi.hoisted(() => ({ @@ -18,7 +19,7 @@ const { gitExecCalls, execHooks, coalescerJoins } = vi.hoisted(() => ({ coalescerJoins: { count: 0, onJoin: undefined as undefined | (() => void) } })) -vi.mock('../../shared/git-branch-line-total', async (importOriginal) => { +vi.mock('../../../shared/git-branch-line-total', async (importOriginal) => { const actual = await importOriginal() return { ...actual, @@ -34,34 +35,37 @@ vi.mock('../../shared/git-branch-line-total', async (importOriginal) => { } }) -vi.mock('./runner', async (importOriginal) => { - const actual = await importOriginal() +vi.mock('../command-runner/git-exec-file', async (importOriginal) => { + const actual = await importOriginal() return { ...actual, - gitExecFileAsync: async (...args: Parameters) => { + gitExecFileAsync: async (...args: Parameters) => { gitExecCalls.push(args[0]) await execHooks.beforeExec?.(args[0]) return actual.gitExecFileAsync(...args) }, - gitExecFileAsyncBuffer: async ( - ...args: Parameters - ) => { + gitExecFileAsyncBuffer: async (...args: Parameters) => { gitExecCalls.push(args[0]) return actual.gitExecFileAsyncBuffer(...args) - }, - gitStreamStdout: async (...args: Parameters) => { + } + } +}) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => { + const actual = await importOriginal() + return { + ...actual, + gitStreamStdout: async (...args: Parameters) => { gitExecCalls.push(args[0]) return actual.gitStreamStdout(...args) } } }) -import { - clearEffectiveUpstreamStatusCacheForTests, - clearSubmodulePathsCacheForTests, - getStatus, - invalidateGitReadCaches -} from './status' +import { clearEffectiveUpstreamStatusCacheForTests } from './effective-upstream-status-cache' +import { clearSubmodulePathsCacheForTests } from './submodule-paths' +import { getStatus } from './status-read' +import { invalidateGitReadCaches } from './git-read-cache-invalidation' const BOGUS_MERGE_BASE = 'deadbeef'.repeat(5) const NO_LINES = { added: 0, removed: 0 } diff --git a/src/main/git/status-branch-line-total-real-git.test.ts b/src/main/git/source-control/status-branch-line-total-real-git.test.ts similarity index 97% rename from src/main/git/status-branch-line-total-real-git.test.ts rename to src/main/git/source-control/status-branch-line-total-real-git.test.ts index 297381b55ee..9aaa52d4783 100644 --- a/src/main/git/status-branch-line-total-real-git.test.ts +++ b/src/main/git/source-control/status-branch-line-total-real-git.test.ts @@ -3,8 +3,9 @@ import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' -import { invalidateGitBranchLineTotalInFlight } from '../../shared/git-branch-line-total' -import { getStatus, invalidateGitReadCaches } from './status' +import { invalidateGitBranchLineTotalInFlight } from '../../../shared/git-branch-line-total' +import { getStatus } from './status-read' +import { invalidateGitReadCaches } from './git-read-cache-invalidation' const tempRoots: string[] = [] diff --git a/src/main/git/status-branch-line-total-untracked-base.test.ts b/src/main/git/source-control/status-branch-line-total-untracked-base.test.ts similarity index 95% rename from src/main/git/status-branch-line-total-untracked-base.test.ts rename to src/main/git/source-control/status-branch-line-total-untracked-base.test.ts index 4415e4bcf5e..ea242f4ae88 100644 --- a/src/main/git/status-branch-line-total-untracked-base.test.ts +++ b/src/main/git/source-control/status-branch-line-total-untracked-base.test.ts @@ -3,7 +3,9 @@ import { mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, expect, it } from 'vitest' -import { getBranchCompare, getStatus, invalidateGitReadCaches } from './status' +import { getBranchCompare } from './branch-compare' +import { getStatus } from './status-read' +import { invalidateGitReadCaches } from './git-read-cache-invalidation' const roots: string[] = [] diff --git a/src/main/git/status-conflict-operations.test.ts b/src/main/git/source-control/status-conflict-operations.test.ts similarity index 84% rename from src/main/git/status-conflict-operations.test.ts rename to src/main/git/source-control/status-conflict-operations.test.ts index 1060779283f..7da1c5821e5 100644 --- a/src/main/git/status-conflict-operations.test.ts +++ b/src/main/git/source-control/status-conflict-operations.test.ts @@ -1,5 +1,9 @@ +import type * as RunnerModule from '../runner' +import type * as GitExecFileModule from '../command-runner/git-exec-file' +import type * as GitStreamStdoutModule from '../command-runner/git-stream-stdout' +import type * as GitProcessEnvModule from '../command-runner/git-process-env' import { beforeEach, describe, expect, it, vi } from 'vitest' -import type * as BoundedFileReader from '../../shared/node-bounded-file-reader' +import type * as BoundedFileReader from '../../../shared/node-bounded-file-reader' import { createBoundedFileReaderModuleMock, createFsPromisesModuleMock, @@ -28,7 +32,7 @@ const { accessMock: vi.fn() })) -vi.mock('./runner', () => +vi.mock('../runner', () => createGitRunnerModuleMock({ gitExecFileAsyncMock, gitExecFileAsyncBufferMock, @@ -36,6 +40,31 @@ vi.mock('./runner', () => }) ) +vi.mock('../command-runner/git-exec-file', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitExecFileAsync: runnerMocks.gitExecFileAsync, + gitExecFileAsyncBuffer: runnerMocks.gitExecFileAsyncBuffer + } +}) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitStreamStdout: runnerMocks.gitStreamStdout + } +}) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitOptionalLocksDisabledEnv: runnerMocks.gitOptionalLocksDisabledEnv + } +}) + vi.mock('fs/promises', () => createFsPromisesModuleMock({ lstatMock, @@ -47,14 +76,14 @@ vi.mock('fs/promises', () => }) ) -vi.mock('../../shared/node-bounded-file-reader', async (importOriginal) => +vi.mock('../../../shared/node-bounded-file-reader', async (importOriginal) => createBoundedFileReaderModuleMock(await importOriginal(), { readFileMock, statMock }) ) -import { abortMerge, abortRebase, detectConflictOperation } from './status' +import { abortMerge, abortRebase, detectConflictOperation } from './git-conflict-operation' describe('abortMerge', () => { beforeEach(() => { diff --git a/src/main/git/status-cquoted-paths.test.ts b/src/main/git/source-control/status-cquoted-paths.test.ts similarity index 94% rename from src/main/git/status-cquoted-paths.test.ts rename to src/main/git/source-control/status-cquoted-paths.test.ts index af77dcc2ff2..55ff7ebe166 100644 --- a/src/main/git/status-cquoted-paths.test.ts +++ b/src/main/git/source-control/status-cquoted-paths.test.ts @@ -3,7 +3,8 @@ import { mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, describe, expect, it } from 'vitest' -import { getStatus, stageFile } from './status' +import { getStatus } from './status-read' +import { stageFile } from './staging' const tempRoots: string[] = [] diff --git a/src/main/git/status-diff-settled-cache.test.ts b/src/main/git/source-control/status-diff-settled-cache.test.ts similarity index 89% rename from src/main/git/status-diff-settled-cache.test.ts rename to src/main/git/source-control/status-diff-settled-cache.test.ts index afb2771a063..3e5c110eb29 100644 --- a/src/main/git/status-diff-settled-cache.test.ts +++ b/src/main/git/source-control/status-diff-settled-cache.test.ts @@ -1,6 +1,10 @@ +import type * as RunnerModule from '../runner' +import type * as GitExecFileModule from '../command-runner/git-exec-file' +import type * as GitStreamStdoutModule from '../command-runner/git-stream-stdout' +import type * as GitProcessEnvModule from '../command-runner/git-process-env' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import * as path from 'node:path' -import type * as BoundedFileReader from '../../shared/node-bounded-file-reader' +import type * as BoundedFileReader from '../../../shared/node-bounded-file-reader' import { createBoundedFileReaderModuleMock, createGitRunnerModuleMock } from './status-test-harness' const { @@ -57,7 +61,7 @@ const { readFileMock, statMock, accessMock } = vi.hoisted(() => { } }) -vi.mock('./runner', () => +vi.mock('../runner', () => createGitRunnerModuleMock({ gitExecFileAsyncMock, gitExecFileAsyncBufferMock, @@ -65,6 +69,31 @@ vi.mock('./runner', () => }) ) +vi.mock('../command-runner/git-exec-file', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitExecFileAsync: runnerMocks.gitExecFileAsync, + gitExecFileAsyncBuffer: runnerMocks.gitExecFileAsyncBuffer + } +}) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitStreamStdout: runnerMocks.gitStreamStdout + } +}) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitOptionalLocksDisabledEnv: runnerMocks.gitOptionalLocksDisabledEnv + } +}) + vi.mock('fs/promises', () => ({ lstat: lstatMock, realpath: realpathMock, @@ -76,15 +105,17 @@ vi.mock('fs/promises', () => ({ vi.mock('fs', () => ({ existsSync: existsSyncMock })) -vi.mock('../../shared/node-bounded-file-reader', async (importOriginal) => +vi.mock('../../../shared/node-bounded-file-reader', async (importOriginal) => createBoundedFileReaderModuleMock(await importOriginal(), { readFileMock, statMock }) ) -import { getDiff, getStatus, invalidateGitReadCaches, stageFile } from './status' -import { settledDiffCache } from './source-control/git-read-cache-invalidation' +import { getDiff } from './file-diff' +import { getStatus } from './status-read' +import { invalidateGitReadCaches, settledDiffCache } from './git-read-cache-invalidation' +import { stageFile } from './staging' const REPO = '/repo' const FILE = 'src/file.ts' diff --git a/src/main/git/status-diff.test.ts b/src/main/git/source-control/status-diff.test.ts similarity index 92% rename from src/main/git/status-diff.test.ts rename to src/main/git/source-control/status-diff.test.ts index 37b778ecdae..d65a4b213d9 100644 --- a/src/main/git/status-diff.test.ts +++ b/src/main/git/source-control/status-diff.test.ts @@ -1,10 +1,14 @@ +import type * as RunnerModule from '../runner' +import type * as GitExecFileModule from '../command-runner/git-exec-file' +import type * as GitStreamStdoutModule from '../command-runner/git-stream-stdout' +import type * as GitProcessEnvModule from '../command-runner/git-process-env' import { beforeEach, describe, expect, it, vi } from 'vitest' -import type * as BoundedFileReader from '../../shared/node-bounded-file-reader' +import type * as BoundedFileReader from '../../../shared/node-bounded-file-reader' import path from 'node:path' import { MAX_RENDERED_DIFF_COMBINED_CHARACTERS, MAX_RENDERED_DIFF_LINES_PER_SIDE -} from '../../shared/large-diff-render-limit' +} from '../../../shared/large-diff-render-limit' import { createBoundedFileReaderModuleMock, createFsPromisesModuleMock, @@ -33,7 +37,7 @@ const { existsSyncMock: vi.fn() })) -vi.mock('./runner', () => +vi.mock('../runner', () => createGitRunnerModuleMock({ gitExecFileAsyncMock, gitExecFileAsyncBufferMock, @@ -41,6 +45,31 @@ vi.mock('./runner', () => }) ) +vi.mock('../command-runner/git-exec-file', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitExecFileAsync: runnerMocks.gitExecFileAsync, + gitExecFileAsyncBuffer: runnerMocks.gitExecFileAsyncBuffer + } +}) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitStreamStdout: runnerMocks.gitStreamStdout + } +}) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitOptionalLocksDisabledEnv: runnerMocks.gitOptionalLocksDisabledEnv + } +}) + vi.mock('fs/promises', () => createFsPromisesModuleMock({ lstatMock, realpathMock, readFileMock, statMock, rmMock }) ) @@ -49,14 +78,18 @@ vi.mock('fs', () => ({ existsSync: existsSyncMock })) -vi.mock('../../shared/node-bounded-file-reader', async (importOriginal) => +vi.mock('../../../shared/node-bounded-file-reader', async (importOriginal) => createBoundedFileReaderModuleMock(await importOriginal(), { readFileMock, statMock }) ) -import { getBranchDiff, getCommitDiff, getDiff, getStagedCommitContext, stageFile } from './status' +import { getBranchDiff } from './branch-diff' +import { getCommitDiff } from './commit-diff' +import { getDiff } from './file-diff' +import { getStagedCommitContext } from './staged-commit-context' +import { stageFile } from './staging' function deferredBuffer(content: string): { promise: Promise<{ stdout: Buffer }> diff --git a/src/main/git/status-discard-and-bulk-staging.test.ts b/src/main/git/source-control/status-discard-and-bulk-staging.test.ts similarity index 79% rename from src/main/git/status-discard-and-bulk-staging.test.ts rename to src/main/git/source-control/status-discard-and-bulk-staging.test.ts index 22fdd22ff13..3ef78e867a1 100644 --- a/src/main/git/status-discard-and-bulk-staging.test.ts +++ b/src/main/git/source-control/status-discard-and-bulk-staging.test.ts @@ -1,5 +1,9 @@ +import type * as RunnerModule from '../runner' +import type * as GitExecFileModule from '../command-runner/git-exec-file' +import type * as GitStreamStdoutModule from '../command-runner/git-stream-stdout' +import type * as GitProcessEnvModule from '../command-runner/git-process-env' import { beforeEach, describe, expect, it, vi } from 'vitest' -import type * as BoundedFileReader from '../../shared/node-bounded-file-reader' +import type * as BoundedFileReader from '../../../shared/node-bounded-file-reader' import path from 'node:path' import { createBoundedFileReaderModuleMock, @@ -29,7 +33,7 @@ const { existsSyncMock: vi.fn() })) -vi.mock('./runner', () => +vi.mock('../runner', () => createGitRunnerModuleMock({ gitExecFileAsyncMock, gitExecFileAsyncBufferMock, @@ -37,6 +41,31 @@ vi.mock('./runner', () => }) ) +vi.mock('../command-runner/git-exec-file', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitExecFileAsync: runnerMocks.gitExecFileAsync, + gitExecFileAsyncBuffer: runnerMocks.gitExecFileAsyncBuffer + } +}) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitStreamStdout: runnerMocks.gitStreamStdout + } +}) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitOptionalLocksDisabledEnv: runnerMocks.gitOptionalLocksDisabledEnv + } +}) + vi.mock('fs/promises', () => createFsPromisesModuleMock({ lstatMock, realpathMock, readFileMock, statMock, rmMock }) ) @@ -45,14 +74,15 @@ vi.mock('fs', () => ({ existsSync: existsSyncMock })) -vi.mock('../../shared/node-bounded-file-reader', async (importOriginal) => +vi.mock('../../../shared/node-bounded-file-reader', async (importOriginal) => createBoundedFileReaderModuleMock(await importOriginal(), { readFileMock, statMock }) ) -import { bulkDiscardChanges, bulkStageFiles, bulkUnstageFiles, discardChanges } from './status' +import { bulkDiscardChanges, discardChanges } from './discard-changes' +import { bulkStageFiles, bulkUnstageFiles } from './staging' describe('discardChanges', () => { beforeEach(() => { diff --git a/src/main/git/status-discard-symlink.test.ts b/src/main/git/source-control/status-discard-symlink.test.ts similarity index 99% rename from src/main/git/status-discard-symlink.test.ts rename to src/main/git/source-control/status-discard-symlink.test.ts index 439ee3c7615..611ccf73398 100644 --- a/src/main/git/status-discard-symlink.test.ts +++ b/src/main/git/source-control/status-discard-symlink.test.ts @@ -3,7 +3,7 @@ import { execFileSync } from 'node:child_process' import { mkdtemp, mkdir, rm, symlink, writeFile, access, readFile } from 'node:fs/promises' import * as path from 'node:path' import { tmpdir } from 'node:os' -import { bulkDiscardChanges, discardChanges } from './status' +import { bulkDiscardChanges, discardChanges } from './discard-changes' const tempRoots: string[] = [] diff --git a/src/main/git/status-line-stats-host-paths.test.ts b/src/main/git/source-control/status-line-stats-host-paths.test.ts similarity index 81% rename from src/main/git/status-line-stats-host-paths.test.ts rename to src/main/git/source-control/status-line-stats-host-paths.test.ts index 65920074db3..419d2806daa 100644 --- a/src/main/git/status-line-stats-host-paths.test.ts +++ b/src/main/git/source-control/status-line-stats-host-paths.test.ts @@ -2,9 +2,9 @@ import * as path from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type * as FsPromises from 'node:fs/promises' -import type * as BoundedFileReader from '../../shared/node-bounded-file-reader' -import type { GitStatusEntry } from '../../shared/git-status-types' -import { invalidateGitBranchLineTotalInFlight } from '../../shared/git-branch-line-total' +import type * as BoundedFileReader from '../../../shared/node-bounded-file-reader' +import type { GitStatusEntry } from '../../../shared/git-status-types' +import { invalidateGitBranchLineTotalInFlight } from '../../../shared/git-branch-line-total' const { lstatPaths, untrackedFiles } = vi.hoisted(() => ({ lstatPaths: [] as string[], @@ -33,7 +33,7 @@ vi.mock('node:fs/promises', async (importOriginal) => { } }) -vi.mock('../../shared/node-bounded-file-reader', async (importOriginal) => { +vi.mock('../../../shared/node-bounded-file-reader', async (importOriginal) => { const actual = await importOriginal() return { ...actual, @@ -49,15 +49,24 @@ vi.mock('../../shared/node-bounded-file-reader', async (importOriginal) => { const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('./runner', () => ({ +vi.mock('../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileAsyncBuffer: vi.fn(), - gitOptionalLocksDisabledEnv: (env: NodeJS.ProcessEnv = process.env) => env, + gitExecFileAsyncBuffer: vi.fn() +})) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => ({ + ...(await importOriginal>()), + gitOptionalLocksDisabledEnv: (env: NodeJS.ProcessEnv = process.env) => env +})) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => ({ + ...(await importOriginal>()), gitStreamStdout: vi.fn() })) -import { attachLineStats } from './source-control/status-line-stats' -import { createBranchLineTotalInput } from './source-control/status-branch-line-total-input' +import { attachLineStats } from './status-line-stats' +import { createBranchLineTotalInput } from './status-branch-line-total-input' const GUEST_WORKTREE = '/home/me/repo' const UNC_WORKTREE = String.raw`\\wsl.localhost\Ubuntu\home\me\repo` diff --git a/src/main/git/status-line-stats-renames-real-git.test.ts b/src/main/git/source-control/status-line-stats-renames-real-git.test.ts similarity index 95% rename from src/main/git/status-line-stats-renames-real-git.test.ts rename to src/main/git/source-control/status-line-stats-renames-real-git.test.ts index 6ed01a27423..1107be7f120 100644 --- a/src/main/git/status-line-stats-renames-real-git.test.ts +++ b/src/main/git/source-control/status-line-stats-renames-real-git.test.ts @@ -3,7 +3,8 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { runProcessSync } from '@orca/process-host' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { getStatus, invalidateGitReadCaches } from './status' +import { getStatus } from './status-read' +import { invalidateGitReadCaches } from './git-read-cache-invalidation' let root: string let repo: string diff --git a/src/main/git/status-pathspec-literals.test.ts b/src/main/git/source-control/status-pathspec-literals.test.ts similarity index 99% rename from src/main/git/status-pathspec-literals.test.ts rename to src/main/git/source-control/status-pathspec-literals.test.ts index ba777bfcfa8..76bc0845a7f 100644 --- a/src/main/git/status-pathspec-literals.test.ts +++ b/src/main/git/source-control/status-pathspec-literals.test.ts @@ -3,7 +3,7 @@ import { mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, describe, expect, it } from 'vitest' -import { bulkStageFiles, bulkUnstageFiles, stageFile, unstageFile } from './status' +import { bulkStageFiles, bulkUnstageFiles, stageFile, unstageFile } from './staging' const tempRoots: string[] = [] const globNamedFile = '[k]eep.log' diff --git a/src/main/git/status-read-coalescing.test.ts b/src/main/git/source-control/status-read-coalescing.test.ts similarity index 88% rename from src/main/git/status-read-coalescing.test.ts rename to src/main/git/source-control/status-read-coalescing.test.ts index 5dc78ac28b2..3b556b0e0f1 100644 --- a/src/main/git/status-read-coalescing.test.ts +++ b/src/main/git/source-control/status-read-coalescing.test.ts @@ -1,5 +1,9 @@ +import type * as RunnerModule from '../runner' +import type * as GitExecFileModule from '../command-runner/git-exec-file' +import type * as GitStreamStdoutModule from '../command-runner/git-stream-stdout' +import type * as GitProcessEnvModule from '../command-runner/git-process-env' import { beforeEach, describe, expect, it, vi } from 'vitest' -import type * as BoundedFileReader from '../../shared/node-bounded-file-reader' +import type * as BoundedFileReader from '../../../shared/node-bounded-file-reader' import { createBoundedFileReaderModuleMock, createFsPromisesModuleMock, @@ -28,7 +32,7 @@ const { existsSyncMock: vi.fn() })) -vi.mock('./runner', () => +vi.mock('../runner', () => createGitRunnerModuleMock({ gitExecFileAsyncMock, gitExecFileAsyncBufferMock, @@ -36,6 +40,31 @@ vi.mock('./runner', () => }) ) +vi.mock('../command-runner/git-exec-file', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitExecFileAsync: runnerMocks.gitExecFileAsync, + gitExecFileAsyncBuffer: runnerMocks.gitExecFileAsyncBuffer + } +}) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitStreamStdout: runnerMocks.gitStreamStdout + } +}) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitOptionalLocksDisabledEnv: runnerMocks.gitOptionalLocksDisabledEnv + } +}) + vi.mock('fs/promises', () => createFsPromisesModuleMock({ lstatMock, realpathMock, readFileMock, statMock, rmMock }) ) @@ -44,14 +73,16 @@ vi.mock('fs', () => ({ existsSync: existsSyncMock })) -vi.mock('../../shared/node-bounded-file-reader', async (importOriginal) => +vi.mock('../../../shared/node-bounded-file-reader', async (importOriginal) => createBoundedFileReaderModuleMock(await importOriginal(), { readFileMock, statMock }) ) -import { clearEffectiveUpstreamStatusCacheForTests, getStatus, stageFile } from './status' +import { clearEffectiveUpstreamStatusCacheForTests } from './effective-upstream-status-cache' +import { getStatus } from './status-read' +import { stageFile } from './staging' describe('getStatus', () => { beforeEach(() => { diff --git a/src/main/git/status-read-failure-real-git.test.ts b/src/main/git/source-control/status-read-failure-real-git.test.ts similarity index 93% rename from src/main/git/status-read-failure-real-git.test.ts rename to src/main/git/source-control/status-read-failure-real-git.test.ts index 65a442f8e8c..f313c354d6e 100644 --- a/src/main/git/status-read-failure-real-git.test.ts +++ b/src/main/git/source-control/status-read-failure-real-git.test.ts @@ -3,7 +3,8 @@ import { tmpdir } from 'node:os' import * as path from 'node:path' import { runProcessSync } from '@orca/process-host' import { afterEach, expect, it } from 'vitest' -import { getStatus, invalidateGitReadCaches } from './status' +import { getStatus } from './status-read' +import { invalidateGitReadCaches } from './git-read-cache-invalidation' let root: string | undefined diff --git a/src/main/git/source-control/status-read.ts b/src/main/git/source-control/status-read.ts index d516c81fd29..8d0670929b8 100644 --- a/src/main/git/source-control/status-read.ts +++ b/src/main/git/source-control/status-read.ts @@ -18,7 +18,7 @@ import { gitOptionalLocksDisabledEnv, gitStreamStdout } from '../runner' import { findExistingWorktreeSymlinkPaths, getSafeRelativePath -} from '../worktree-symlink-detection' +} from '../worktrees/content-paths/worktree-symlink-detection' import type { GetStatusOptions } from './get-status-options' import { statusReadLeaseOwner } from './git-read-cache-invalidation' import { detectConflictOperation } from './git-conflict-operation' diff --git a/src/main/git/status-shared-symlinks.test.ts b/src/main/git/source-control/status-shared-symlinks.test.ts similarity index 99% rename from src/main/git/status-shared-symlinks.test.ts rename to src/main/git/source-control/status-shared-symlinks.test.ts index 6f08dd125d9..6bf5283d84d 100644 --- a/src/main/git/status-shared-symlinks.test.ts +++ b/src/main/git/source-control/status-shared-symlinks.test.ts @@ -3,7 +3,7 @@ import { mkdirSync, mkdtempSync, rmSync, symlinkSync, unlinkSync, writeFileSync import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' -import { getStatus } from './status' +import { getStatus } from './status-read' // Directory-only ignore rules cannot hide shared symlinks; status must filter configured links. const git = (args: string[], cwd: string): string => diff --git a/src/main/git/status-submodule-path-cache.test.ts b/src/main/git/source-control/status-submodule-path-cache.test.ts similarity index 90% rename from src/main/git/status-submodule-path-cache.test.ts rename to src/main/git/source-control/status-submodule-path-cache.test.ts index 1de1354a8c9..108b580c810 100644 --- a/src/main/git/status-submodule-path-cache.test.ts +++ b/src/main/git/source-control/status-submodule-path-cache.test.ts @@ -8,10 +8,19 @@ const { gitExecFileAsyncMock, gitExecFileAsyncBufferMock, gitStreamStdoutMock } }) ) -vi.mock('./runner', () => ({ +vi.mock('../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileAsyncBuffer: gitExecFileAsyncBufferMock, - gitStreamStdout: gitStreamStdoutMock, + gitExecFileAsyncBuffer: gitExecFileAsyncBufferMock +})) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => ({ + ...(await importOriginal>()), + gitStreamStdout: gitStreamStdoutMock +})) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => ({ + ...(await importOriginal>()), gitOptionalLocksDisabledEnv: (env: NodeJS.ProcessEnv = process.env) => ({ ...env, GIT_OPTIONAL_LOCKS: '0' @@ -20,15 +29,16 @@ vi.mock('./runner', () => ({ import { MAX_SUBMODULE_PATHS_CACHE_ENTRIES, - abortMerge, - abortRebase, clearSubmodulePathsCacheForTests, getSubmodulePathsCacheCountForTests, listSubmodulePaths -} from './status' -import { checkoutBranch } from './checkout' -import { gitPull, gitPullRebaseFromBase } from './remote' -import { addWorktree, removeWorktree } from './worktree' +} from './submodule-paths' +import { abortMerge, abortRebase } from './git-conflict-operation' +import { checkoutBranch } from '../checkout' +import { gitPull } from '../remote' +import { gitPullRebaseFromBase } from '../remote-rebase' +import { addWorktree } from '../worktrees/creation/worktree-add' +import { removeWorktree } from '../worktrees/removal/worktree-removal' describe('submodule path cache', () => { beforeEach(() => { diff --git a/src/main/git/status-submodule.test.ts b/src/main/git/source-control/status-submodule.test.ts similarity index 90% rename from src/main/git/status-submodule.test.ts rename to src/main/git/source-control/status-submodule.test.ts index bcf599f5363..41f31280966 100644 --- a/src/main/git/status-submodule.test.ts +++ b/src/main/git/source-control/status-submodule.test.ts @@ -1,5 +1,9 @@ +import type * as RunnerModule from '../runner' +import type * as GitExecFileModule from '../command-runner/git-exec-file' +import type * as GitStreamStdoutModule from '../command-runner/git-stream-stdout' +import type * as GitProcessEnvModule from '../command-runner/git-process-env' import { beforeEach, describe, expect, it, vi } from 'vitest' -import type * as BoundedFileReader from '../../shared/node-bounded-file-reader' +import type * as BoundedFileReader from '../../../shared/node-bounded-file-reader' import path from 'node:path' import { createBoundedFileReaderModuleMock, @@ -29,7 +33,7 @@ const { existsSyncMock: vi.fn() })) -vi.mock('./runner', () => +vi.mock('../runner', () => createGitRunnerModuleMock({ gitExecFileAsyncMock, gitExecFileAsyncBufferMock, @@ -37,6 +41,31 @@ vi.mock('./runner', () => }) ) +vi.mock('../command-runner/git-exec-file', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitExecFileAsync: runnerMocks.gitExecFileAsync, + gitExecFileAsyncBuffer: runnerMocks.gitExecFileAsyncBuffer + } +}) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitStreamStdout: runnerMocks.gitStreamStdout + } +}) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitOptionalLocksDisabledEnv: runnerMocks.gitOptionalLocksDisabledEnv + } +}) + vi.mock('fs/promises', () => createFsPromisesModuleMock({ lstatMock, realpathMock, readFileMock, statMock, rmMock }) ) @@ -45,21 +74,21 @@ vi.mock('fs', () => ({ existsSync: existsSyncMock })) -vi.mock('../../shared/node-bounded-file-reader', async (importOriginal) => +vi.mock('../../../shared/node-bounded-file-reader', async (importOriginal) => createBoundedFileReaderModuleMock(await importOriginal(), { readFileMock, statMock }) ) +import { clearEffectiveUpstreamStatusCacheForTests } from './effective-upstream-status-cache' import { - clearEffectiveUpstreamStatusCacheForTests, clearSubmodulePathsCacheForTests, - getDiff, - getSubmoduleStatus, listSubmodulePaths, resolveSubmoduleWorktreePath -} from './status' +} from './submodule-paths' +import { getDiff } from './file-diff' +import { getSubmoduleStatus } from './submodule-status' describe('submodule diff routing', () => { const OLD_OID = 'a'.repeat(40) diff --git a/src/main/git/status-symlink-probe-budget.test.ts b/src/main/git/source-control/status-symlink-probe-budget.test.ts similarity index 80% rename from src/main/git/status-symlink-probe-budget.test.ts rename to src/main/git/source-control/status-symlink-probe-budget.test.ts index 9021f1306c3..f3ae64db10f 100644 --- a/src/main/git/status-symlink-probe-budget.test.ts +++ b/src/main/git/source-control/status-symlink-probe-budget.test.ts @@ -1,5 +1,5 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' -import { getStatus } from './source-control/status-read' +import { getStatus } from './status-read' const { lstat, stream, conflict } = vi.hoisted(() => ({ lstat: vi.fn(), @@ -7,9 +7,14 @@ const { lstat, stream, conflict } = vi.hoisted(() => ({ conflict: vi.fn() })) vi.mock('node:fs/promises', () => ({ lstat })) -vi.mock('./source-control/git-conflict-operation', () => ({ detectConflictOperation: conflict })) -vi.mock('./runner', () => ({ - gitStreamStdout: stream, +vi.mock('./git-conflict-operation', () => ({ detectConflictOperation: conflict })) +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => ({ + ...(await importOriginal>()), + gitStreamStdout: stream +})) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => ({ + ...(await importOriginal>()), gitOptionalLocksDisabledEnv: () => ({ GIT_OPTIONAL_LOCKS: '0' }) })) diff --git a/src/main/git/status-test-harness.ts b/src/main/git/source-control/status-test-harness.ts similarity index 97% rename from src/main/git/status-test-harness.ts rename to src/main/git/source-control/status-test-harness.ts index f3b829979ab..0db2d777f20 100644 --- a/src/main/git/status-test-harness.ts +++ b/src/main/git/source-control/status-test-harness.ts @@ -1,5 +1,5 @@ import type { Mock } from 'vitest' -import type * as BoundedFileReader from '../../shared/node-bounded-file-reader' +import type * as BoundedFileReader from '../../../shared/node-bounded-file-reader' type MockFn = Mock diff --git a/src/main/git/status-upstream-negative-cache.test.ts b/src/main/git/source-control/status-upstream-negative-cache.test.ts similarity index 96% rename from src/main/git/status-upstream-negative-cache.test.ts rename to src/main/git/source-control/status-upstream-negative-cache.test.ts index b82b3bf83eb..cd3db8d5564 100644 --- a/src/main/git/status-upstream-negative-cache.test.ts +++ b/src/main/git/source-control/status-upstream-negative-cache.test.ts @@ -6,8 +6,13 @@ const { existsSyncMock, gitExecFileAsyncMock, readFileMock } = vi.hoisted(() => readFileMock: vi.fn() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, +vi.mock('../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => ({ + ...(await importOriginal>()), gitStreamStdout: async ( args: string[], options: { onStdout: (chunk: string) => boolean | void } @@ -15,7 +20,11 @@ vi.mock('./runner', () => ({ const { stdout } = await gitExecFileAsyncMock(args) const stoppedEarly = options.onStdout(stdout ?? '') === true return { stoppedEarly } - }, + } +})) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => ({ + ...(await importOriginal>()), gitOptionalLocksDisabledEnv: (env: NodeJS.ProcessEnv = process.env) => ({ ...env, GIT_OPTIONAL_LOCKS: '0' @@ -43,13 +52,11 @@ import { clearEffectiveUpstreamStatusCacheForTests, getEffectiveUpstreamStatusCacheCountForTests, getEffectiveUpstreamStatusGenerationCountForTests, - getStatus -} from './status' -import { getEffectiveUpstreamStatusWriteGeneration, readCachedEffectiveUpstreamStatus, rememberEffectiveUpstreamStatus -} from './source-control/effective-upstream-status-cache' +} from './effective-upstream-status-cache' +import { getStatus } from './status-read' describe('local upstream negative cache', () => { beforeEach(() => { diff --git a/src/main/git/status-upstream-probe-churn.test.ts b/src/main/git/source-control/status-upstream-probe-churn.test.ts similarity index 95% rename from src/main/git/status-upstream-probe-churn.test.ts rename to src/main/git/source-control/status-upstream-probe-churn.test.ts index b0bd802bc68..655054bb748 100644 --- a/src/main/git/status-upstream-probe-churn.test.ts +++ b/src/main/git/source-control/status-upstream-probe-churn.test.ts @@ -6,8 +6,13 @@ const { existsSyncMock, gitExecFileAsyncMock, readFileMock } = vi.hoisted(() => readFileMock: vi.fn() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, +vi.mock('../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => ({ + ...(await importOriginal>()), gitStreamStdout: async ( args: string[], options: { onStdout: (chunk: string) => boolean | void } @@ -15,7 +20,11 @@ vi.mock('./runner', () => ({ const { stdout } = await gitExecFileAsyncMock(args) const stoppedEarly = options.onStdout(stdout ?? '') === true return { stoppedEarly } - }, + } +})) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => ({ + ...(await importOriginal>()), gitOptionalLocksDisabledEnv: (env: NodeJS.ProcessEnv = process.env) => ({ ...env, GIT_OPTIONAL_LOCKS: '0' @@ -30,7 +39,8 @@ vi.mock('fs', () => ({ existsSync: existsSyncMock })) -import { clearEffectiveUpstreamStatusCacheForTests, getStatus } from './status' +import { clearEffectiveUpstreamStatusCacheForTests } from './effective-upstream-status-cache' +import { getStatus } from './status-read' function getGitArgs(call: unknown[]): string[] { return call[0] as string[] diff --git a/src/main/git/status-upstream-ref.test.ts b/src/main/git/source-control/status-upstream-ref.test.ts similarity index 100% rename from src/main/git/status-upstream-ref.test.ts rename to src/main/git/source-control/status-upstream-ref.test.ts diff --git a/src/main/git/status-upstream-ref.ts b/src/main/git/source-control/status-upstream-ref.ts similarity index 94% rename from src/main/git/status-upstream-ref.ts rename to src/main/git/source-control/status-upstream-ref.ts index 3ad5237d312..54f882ab585 100644 --- a/src/main/git/status-upstream-ref.ts +++ b/src/main/git/source-control/status-upstream-ref.ts @@ -1,4 +1,4 @@ -import { isSafeGitRefName } from '../../shared/git-status-upstream-ref' +import { isSafeGitRefName } from '../../../shared/git-status-upstream-ref' type GitStatusUpstreamRefExec = ( args: string[], diff --git a/src/main/git/status.test.ts b/src/main/git/source-control/status.test.ts similarity index 94% rename from src/main/git/status.test.ts rename to src/main/git/source-control/status.test.ts index e4b26a8b1bf..a929d126cbe 100644 --- a/src/main/git/status.test.ts +++ b/src/main/git/source-control/status.test.ts @@ -1,5 +1,9 @@ +import type * as RunnerModule from '../runner' +import type * as GitExecFileModule from '../command-runner/git-exec-file' +import type * as GitStreamStdoutModule from '../command-runner/git-stream-stdout' +import type * as GitProcessEnvModule from '../command-runner/git-process-env' import { beforeEach, describe, expect, it, vi } from 'vitest' -import type * as BoundedFileReader from '../../shared/node-bounded-file-reader' +import type * as BoundedFileReader from '../../../shared/node-bounded-file-reader' import { createBoundedFileReaderModuleMock, createFsPromisesModuleMock, @@ -28,7 +32,7 @@ const { accessMock: vi.fn() })) -vi.mock('./runner', () => +vi.mock('../runner', () => createGitRunnerModuleMock({ gitExecFileAsyncMock, gitExecFileAsyncBufferMock, @@ -36,6 +40,31 @@ vi.mock('./runner', () => }) ) +vi.mock('../command-runner/git-exec-file', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitExecFileAsync: runnerMocks.gitExecFileAsync, + gitExecFileAsyncBuffer: runnerMocks.gitExecFileAsyncBuffer + } +}) + +vi.mock('../command-runner/git-stream-stdout', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitStreamStdout: runnerMocks.gitStreamStdout + } +}) + +vi.mock('../command-runner/git-process-env', async (importOriginal) => { + const runnerMocks = await vi.importMock('../runner') + return { + ...(await importOriginal()), + gitOptionalLocksDisabledEnv: runnerMocks.gitOptionalLocksDisabledEnv + } +}) + vi.mock('fs/promises', () => createFsPromisesModuleMock({ lstatMock, @@ -47,14 +76,16 @@ vi.mock('fs/promises', () => }) ) -vi.mock('../../shared/node-bounded-file-reader', async (importOriginal) => +vi.mock('../../../shared/node-bounded-file-reader', async (importOriginal) => createBoundedFileReaderModuleMock(await importOriginal(), { readFileMock, statMock }) ) -import { clearEffectiveUpstreamStatusCacheForTests, getStatus, stageFile } from './status' +import { clearEffectiveUpstreamStatusCacheForTests } from './effective-upstream-status-cache' +import { getStatus } from './status-read' +import { stageFile } from './staging' describe('getStatus', () => { beforeEach(() => { diff --git a/src/main/git/upstream-deferred-fork-remote-real.test.ts b/src/main/git/source-control/upstream-deferred-fork-remote-real.test.ts similarity index 96% rename from src/main/git/upstream-deferred-fork-remote-real.test.ts rename to src/main/git/source-control/upstream-deferred-fork-remote-real.test.ts index b4bd5c52afc..6f59d317328 100644 --- a/src/main/git/upstream-deferred-fork-remote-real.test.ts +++ b/src/main/git/source-control/upstream-deferred-fork-remote-real.test.ts @@ -3,7 +3,7 @@ import { mkdtempSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it } from 'vitest' -import type { GitPushTarget } from '../../shared/worktree/types' +import type { GitPushTarget } from '../../../shared/worktree/types' import { getUpstreamStatus } from './upstream' // Real Git verifies missing-ref exit/stderr handling before a fork remote is materialized. diff --git a/src/main/git/upstream.test.ts b/src/main/git/source-control/upstream.test.ts similarity index 99% rename from src/main/git/upstream.test.ts rename to src/main/git/source-control/upstream.test.ts index 06646fc6b60..778182c9d2b 100644 --- a/src/main/git/upstream.test.ts +++ b/src/main/git/source-control/upstream.test.ts @@ -4,12 +4,13 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('./runner', () => ({ +vi.mock('../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) import { getUpstreamStatus, invalidateGitUpstreamStatusReads } from './upstream' -import { runWithGitReadCacheInvalidation } from './status' +import { runWithGitReadCacheInvalidation } from './git-read-cache-invalidation' const missingTrackingRefError = new Error( "fatal: ambiguous argument 'HEAD@{u}': unknown revision or path not in the working tree.\n" + diff --git a/src/main/git/upstream.ts b/src/main/git/source-control/upstream.ts similarity index 81% rename from src/main/git/upstream.ts rename to src/main/git/source-control/upstream.ts index aec315c7541..e289a5f07fc 100644 --- a/src/main/git/upstream.ts +++ b/src/main/git/source-control/upstream.ts @@ -1,13 +1,13 @@ -import type { GitUpstreamStatus } from '../../shared/git-status-types' -import type { GitPushTarget } from '../../shared/worktree/types' -import { upstreamOnlyCommitsArePatchEquivalent } from '../../shared/git-upstream-status' -import { isNoUpstreamError, normalizeGitErrorMessage } from '../../shared/git-remote-error' -import { getEffectiveGitUpstreamStatus } from '../../shared/git-effective-upstream' -import { getPublishTargetStatus } from '../../shared/git-publish-target-status' -import { gitExecFileAsync } from './runner' -import { validateGitPushTarget } from './push-target-validation' +import type { GitUpstreamStatus } from '../../../shared/git-status-types' +import type { GitPushTarget } from '../../../shared/worktree/types' +import { upstreamOnlyCommitsArePatchEquivalent } from '../../../shared/git-upstream-status' +import { isNoUpstreamError, normalizeGitErrorMessage } from '../../../shared/git-remote-error' +import { getEffectiveGitUpstreamStatus } from '../../../shared/git-effective-upstream' +import { getPublishTargetStatus } from '../../../shared/git-publish-target-status' +import { gitExecFileAsync } from '../command-runner/git-exec-file' +import { validateGitPushTarget } from '../push-target-validation' import { nativeAndWslGitUpstreamStatusReadOwner } from './git-upstream-status-read-owner' -import type { GitAdmissionTier } from './command-runner/git-exec-options' +import type { GitAdmissionTier } from '../../../shared/rpc-contract/git-admission-tier-params' type GitExecOptions = { wslDistro?: string diff --git a/src/main/git/worktree-diff-stamp-guest-gitdir.test.ts b/src/main/git/source-control/worktree-diff-stamp-guest-gitdir.test.ts similarity index 95% rename from src/main/git/worktree-diff-stamp-guest-gitdir.test.ts rename to src/main/git/source-control/worktree-diff-stamp-guest-gitdir.test.ts index bb4e99bff88..bb2302f4cdc 100644 --- a/src/main/git/worktree-diff-stamp-guest-gitdir.test.ts +++ b/src/main/git/source-control/worktree-diff-stamp-guest-gitdir.test.ts @@ -7,7 +7,7 @@ const { readFileMock, statMock } = vi.hoisted(() => ({ vi.mock('node:fs/promises', () => ({ readFile: readFileMock, stat: statMock })) -import { readWorktreeDiffStamp } from './source-control/worktree-diff-stamp' +import { readWorktreeDiffStamp } from './worktree-diff-stamp' const slashed = (value: unknown): string => String(value).replaceAll('\\', '/') const missing = () => Object.assign(new Error('ENOENT'), { code: 'ENOENT' }) diff --git a/src/main/git/worktree-diff-stamp-host-paths.test.ts b/src/main/git/source-control/worktree-diff-stamp-host-paths.test.ts similarity index 95% rename from src/main/git/worktree-diff-stamp-host-paths.test.ts rename to src/main/git/source-control/worktree-diff-stamp-host-paths.test.ts index 37414672494..18c134a2659 100644 --- a/src/main/git/worktree-diff-stamp-host-paths.test.ts +++ b/src/main/git/source-control/worktree-diff-stamp-host-paths.test.ts @@ -10,7 +10,7 @@ vi.mock('fs/promises', () => ({ stat: statMock })) -import { readWorktreeDiffStamp } from './source-control/worktree-diff-stamp' +import { readWorktreeDiffStamp } from './worktree-diff-stamp' const slashed = (value: unknown): string => String(value).replaceAll('\\', '/') const missing = () => Object.assign(new Error('ENOENT'), { code: 'ENOENT' }) diff --git a/src/main/git/status.ts b/src/main/git/status.ts deleted file mode 100644 index 922782186d9..00000000000 --- a/src/main/git/status.ts +++ /dev/null @@ -1,47 +0,0 @@ -// Preserve the source-control import/mocking entry point; implementation lives in source-control. -export { getStatus } from './source-control/status-read' -export type { GetStatusOptions } from './source-control/get-status-options' -export { getSubmoduleStatus } from './source-control/submodule-status' -export { - MAX_SUBMODULE_PATHS_CACHE_ENTRIES, - clearSubmodulePathsCacheForTests, - getSubmodulePathsCacheCountForTests, - listSubmodulePaths, - resolveSubmoduleWorktreePath -} from './source-control/submodule-paths' -export { - invalidateGitReadCaches, - runWithGitReadCacheInvalidation -} from './source-control/git-read-cache-invalidation' -export { - clearEffectiveUpstreamNegativeStatusCache, - clearEffectiveUpstreamStatusCacheForTests, - getEffectiveUpstreamStatusCacheCountForTests, - getEffectiveUpstreamStatusGenerationCountForTests -} from './source-control/effective-upstream-status-cache' -export { - abortMerge, - abortRebase, - detectConflictOperation -} from './source-control/git-conflict-operation' -export { resolveGitDir } from './source-control/resolve-git-dir' -export { getDiff } from './source-control/file-diff' -export { getBranchCompare } from './source-control/branch-compare' -export { getBranchDiff } from './source-control/branch-diff' -export { getCommitCompare } from './source-control/commit-compare' -export { getCommitDiff } from './source-control/commit-diff' -export { - bulkStageFiles, - bulkUnstageFiles, - resolveConflict, - stageFile, - stageWorktreeChanges, - unstageFile -} from './source-control/staging' -export { getStagedCommitContext } from './source-control/staged-commit-context' -export { commitChanges, completeMerge } from './source-control/commit-changes' -export { - bulkDiscardChanges, - discardChanges, - isWithinWorktree -} from './source-control/discard-changes' diff --git a/src/main/git/task-repository-eligibility.ts b/src/main/git/task-repository-eligibility.ts index 97fb829ab46..652afee881f 100644 --- a/src/main/git/task-repository-eligibility.ts +++ b/src/main/git/task-repository-eligibility.ts @@ -3,9 +3,9 @@ import { isDefaultGitHubHost } from '../../shared/github/repository-identity-key import { isGitHubHostAuthenticated } from '../github/github-enterprise-repository' import { parseGitHubRemoteIdentity } from '../github/github-remote-identity-parsing' import { parseGitLabProjectRef } from '../gitlab/project-ref-parser' -import { REMOTE_URL_PROBE_TIMEOUT_MS } from './remote-url-probe' +import { REMOTE_URL_PROBE_TIMEOUT_MS } from './remotes/remote-url-probe' import { gitExecFileAsync } from './runner' -import type { RemoteRefLocalGitOptions } from './remote-ref-probe-cache' +import type { RemoteRefLocalGitOptions } from './remotes/remote-ref-probe-cache' /** Call only after the requested provider found no usable source; unknown is never exclusion evidence. */ export async function isTaskRepositoryIneligible( diff --git a/src/main/git/worktree.ts b/src/main/git/worktree.ts deleted file mode 100644 index da319217747..00000000000 --- a/src/main/git/worktree.ts +++ /dev/null @@ -1,39 +0,0 @@ -export { addWorktree } from './worktree-add' -export { - configurePushAutoSetupRemote, - persistWorktreeCreationBase, - resolveWorktreeAddBaseContext, - trackSameNameRemoteBase -} from './worktree-add' -export { forceDeleteLocalBranch } from './worktree-branch-removal' -export { parseWorktreeList } from '../../shared/git-worktree-porcelain-parser' -// Post-mutation verification must not join pre-prune scans; opt into coalescing via listWorktreesSharedStrict. -export { describeCreatedWorktree, listWorktreesStrict } from './worktree-listing' -export { moveWorktree } from './worktree-move' -export { - WORKTREE_ADD_TIMEOUT_MAX_MS, - WORKTREE_ADD_TIMEOUT_MS, - WORKTREE_LIST_TIMEOUT_MS, - WORKTREE_REMOVAL_PREFLIGHT_TIMEOUT_MS, - WORKTREE_REMOVAL_REGISTRATION_TIMEOUT_MS, - resolveWorktreeAddTimeoutMs -} from './worktree-operation-options' -export type { - AddWorktreeOptions, - AddWorktreeResult, - GitWorktreeExecOptions, - RemoveWorktreeOptions -} from './worktree-operation-options' -export { assertWorktreeCleanForRemoval } from './worktree-removal-preflight' -export { removeWorktree } from './worktree-removal' -export { - _getWorktreeScanCacheSizesForTests, - _resetWorktreeScanCacheForTests, - listWorktreeGraph, - listWorktrees, - listWorktreesSharedStrict, - listWorktreesSharedStrictAllowingTrueEmpty -} from './worktree-scan-cache' -export { bumpWorktreeScanGeneration as notifyPreparedWorktreeMutation } from './worktree-scan-cache' -export { addSparseWorktree } from './worktree-sparse-add' -export { parseCoreSparseCheckoutFlag } from './worktree-sparse-state' diff --git a/src/main/git/worktree-common-dir-comparison.test.ts b/src/main/git/worktrees/catalog/worktree-common-dir-comparison.test.ts similarity index 100% rename from src/main/git/worktree-common-dir-comparison.test.ts rename to src/main/git/worktrees/catalog/worktree-common-dir-comparison.test.ts diff --git a/src/main/git/worktree-created-description-real-git.test.ts b/src/main/git/worktrees/catalog/worktree-created-description-real-git.test.ts similarity index 97% rename from src/main/git/worktree-created-description-real-git.test.ts rename to src/main/git/worktrees/catalog/worktree-created-description-real-git.test.ts index ee7c2e88d68..8680d97c3e3 100644 --- a/src/main/git/worktree-created-description-real-git.test.ts +++ b/src/main/git/worktrees/catalog/worktree-created-description-real-git.test.ts @@ -5,8 +5,11 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { promisify } from 'node:util' import { afterEach, beforeEach, describe, expect, it } from 'vitest' -import { clearGitCapabilityStateForTests, getLocalGitCapabilityCache } from './git-capability-state' -import { describeCreatedWorktree, listWorktreesStrict } from './worktree' +import { + clearGitCapabilityStateForTests, + getLocalGitCapabilityCache +} from '../../command-runner/git-capability-state' +import { describeCreatedWorktree, listWorktreesStrict } from './worktree-listing' const execFileAsync = promisify(execFile) diff --git a/src/main/git/worktree-created-disk-witness.test.ts b/src/main/git/worktrees/catalog/worktree-created-disk-witness.test.ts similarity index 98% rename from src/main/git/worktree-created-disk-witness.test.ts rename to src/main/git/worktrees/catalog/worktree-created-disk-witness.test.ts index b7cc2502b4d..5ed675b2373 100644 --- a/src/main/git/worktree-created-disk-witness.test.ts +++ b/src/main/git/worktrees/catalog/worktree-created-disk-witness.test.ts @@ -11,7 +11,7 @@ vi.mock('./worktree-list-reader', () => ({ readTranslatedWorktreeGraph: vi.fn(), readWorktreeList: vi.fn() })) -vi.mock('./worktree-sparse-checkout-cache', () => ({ +vi.mock('../sparse-checkout/worktree-sparse-checkout-cache', () => ({ detectSparseCheckoutCached: vi.fn(async () => false) })) diff --git a/src/main/git/worktree-git-capabilities.test.ts b/src/main/git/worktrees/catalog/worktree-git-capabilities.test.ts similarity index 84% rename from src/main/git/worktree-git-capabilities.test.ts rename to src/main/git/worktrees/catalog/worktree-git-capabilities.test.ts index d59174702f0..11802a3d696 100644 --- a/src/main/git/worktree-git-capabilities.test.ts +++ b/src/main/git/worktrees/catalog/worktree-git-capabilities.test.ts @@ -4,14 +4,23 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: vi.fn(), +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: vi.fn() +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: (output: string) => output })) -import { clearGitCapabilityStateForTests } from './git-capability-state' -import { listWorktrees } from './worktree' +import { clearGitCapabilityStateForTests } from '../../command-runner/git-capability-state' +import { listWorktrees } from './worktree-scan-cache' const WORKTREE_LIST_OUTPUT = `worktree /repo HEAD abc123 diff --git a/src/main/git/worktree-git-path.test.ts b/src/main/git/worktrees/catalog/worktree-git-path.test.ts similarity index 100% rename from src/main/git/worktree-git-path.test.ts rename to src/main/git/worktrees/catalog/worktree-git-path.test.ts diff --git a/src/main/git/worktree-git-path.ts b/src/main/git/worktrees/catalog/worktree-git-path.ts similarity index 93% rename from src/main/git/worktree-git-path.ts rename to src/main/git/worktrees/catalog/worktree-git-path.ts index db63870a9e3..b6d36731000 100644 --- a/src/main/git/worktree-git-path.ts +++ b/src/main/git/worktrees/catalog/worktree-git-path.ts @@ -6,8 +6,8 @@ */ import { readFileSync, statSync } from 'node:fs' import { join, resolve, win32 } from 'node:path' -import { parseWslUncPath, toWindowsWslUncPath } from '../../shared/wsl-paths' -import { wslDrivePathUnderRoots } from '../wsl/filesystem/wsl-automount-root' +import { parseWslUncPath, toWindowsWslUncPath } from '../../../../shared/wsl-paths' +import { wslDrivePathUnderRoots } from '../../../wsl/filesystem/wsl-automount-root' // Git keeps these per worktree; everything else under the git dir (`hooks/`, `info/`, `objects/`, // `refs/`, `config`, `packed-refs`, …) lives in the common dir, which only real Git resolves. diff --git a/src/main/git/worktree-graph-listing.test.ts b/src/main/git/worktrees/catalog/worktree-graph-listing.test.ts similarity index 74% rename from src/main/git/worktree-graph-listing.test.ts rename to src/main/git/worktrees/catalog/worktree-graph-listing.test.ts index 266159a1eae..622e5a72f02 100644 --- a/src/main/git/worktree-graph-listing.test.ts +++ b/src/main/git/worktrees/catalog/worktree-graph-listing.test.ts @@ -8,18 +8,28 @@ const { gitExecFileAsyncMock, gitExecFileSyncMock, translateWslOutputPathsMock } }) ) -vi.mock('../../shared/git-worktree-admin', () => ({ +vi.mock('../../../../shared/git-worktree-admin', () => ({ annotateWorktreeLocksFromAdmin: async (_repoPath: string, rows: unknown[]) => rows })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) -import { listWorktreeGraph, WORKTREE_LIST_TIMEOUT_MS } from './worktree' -import { registerWorktreeSuiteHooks } from './worktree-test-harness' +import { listWorktreeGraph } from './worktree-scan-cache' +import { WORKTREE_LIST_TIMEOUT_MS } from '../worktree-operation-options' +import { registerWorktreeSuiteHooks } from '../testing/worktree-test-harness' registerWorktreeSuiteHooks() diff --git a/src/main/git/worktree-list-paths.test.ts b/src/main/git/worktrees/catalog/worktree-list-paths.test.ts similarity index 95% rename from src/main/git/worktree-list-paths.test.ts rename to src/main/git/worktrees/catalog/worktree-list-paths.test.ts index ef4213fc90a..c3da5ac5f66 100644 --- a/src/main/git/worktree-list-paths.test.ts +++ b/src/main/git/worktrees/catalog/worktree-list-paths.test.ts @@ -1,10 +1,11 @@ -import { installRealWorkerThreadChildProcesses } from '../worker-thread-child-process/worker-thread-child-process-real.test-fixtures' +import { installRealWorkerThreadChildProcesses } from '../../../worker-thread-child-process/worker-thread-child-process-real.test-fixtures' import { execFileSync } from 'node:child_process' import { mkdtemp, realpath, rm } from 'node:fs/promises' import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, describe, expect, it } from 'vitest' -import { listWorktrees, removeWorktree } from './worktree' +import { listWorktrees } from './worktree-scan-cache' +import { removeWorktree } from '../removal/worktree-removal' const tempRoots: string[] = [] diff --git a/src/main/git/worktree-list-porcelain.test.ts b/src/main/git/worktrees/catalog/worktree-list-porcelain.test.ts similarity index 93% rename from src/main/git/worktree-list-porcelain.test.ts rename to src/main/git/worktrees/catalog/worktree-list-porcelain.test.ts index b4c7d4bc232..3ae8474e7ea 100644 --- a/src/main/git/worktree-list-porcelain.test.ts +++ b/src/main/git/worktrees/catalog/worktree-list-porcelain.test.ts @@ -17,18 +17,30 @@ const { resolveGitDirMock: vi.fn() })) -vi.mock('../../shared/git-worktree-admin', () => ({ +vi.mock('../../../../shared/git-worktree-admin', () => ({ annotateWorktreeLocksFromAdmin: async (_repoPath: string, rows: unknown[]) => rows })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) -vi.mock('./status', () => ({ - resolveGitDir: resolveGitDirMock, +vi.mock('../../source-control/resolve-git-dir', () => ({ + resolveGitDir: resolveGitDirMock +})) + +vi.mock('../../source-control/git-read-cache-invalidation', () => ({ runWithGitReadCacheInvalidation: (run: () => Promise) => run() })) @@ -42,9 +54,10 @@ import { createGitCommandMocker, resetWorktreeGitMocks, resetWorktreeRemovalState -} from './remove-worktree-test-harness' +} from '../removal/remove-worktree-test-harness' -import { listWorktrees, WORKTREE_LIST_TIMEOUT_MS } from './worktree' +import { listWorktrees } from './worktree-scan-cache' +import { WORKTREE_LIST_TIMEOUT_MS } from '../worktree-operation-options' const mockGitCommands = createGitCommandMocker(gitExecFileAsyncMock) const getGitCalls = createGitCallReader(gitExecFileAsyncMock) diff --git a/src/main/git/worktree-list-reader-cancellation.test.ts b/src/main/git/worktrees/catalog/worktree-list-reader-cancellation.test.ts similarity index 89% rename from src/main/git/worktree-list-reader-cancellation.test.ts rename to src/main/git/worktrees/catalog/worktree-list-reader-cancellation.test.ts index d5a46730e5d..75b99593cf4 100644 --- a/src/main/git/worktree-list-reader-cancellation.test.ts +++ b/src/main/git/worktrees/catalog/worktree-list-reader-cancellation.test.ts @@ -1,7 +1,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as FsPromises from 'node:fs/promises' -import type { GitWorktreeInfo } from '../../shared/worktree/types' -import type { gitExecFileAsync } from './runner' +import type { GitWorktreeInfo } from '../../../../shared/worktree/types' +import type { gitExecFileAsync } from '../../command-runner/git-exec-file' const { statProbe, gitExec } = vi.hoisted(() => ({ statProbe: vi.fn<(worktreePath: string) => Promise>(), @@ -12,15 +12,20 @@ vi.mock('node:fs/promises', async (importOriginal) => ({ ...(await importOriginal()), stat: statProbe })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExec, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExec +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: (output: string) => output })) -vi.mock('../../shared/git-worktree-admin', () => ({ +vi.mock('../../../../shared/git-worktree-admin', () => ({ annotateWorktreeLocksFromAdmin: async (_repoPath: string, rows: GitWorktreeInfo[]) => rows })) -import { clearGitCapabilityStateForTests } from './git-capability-state' +import { clearGitCapabilityStateForTests } from '../../command-runner/git-capability-state' import { readWorktreeList } from './worktree-list-reader' function porcelainRow(worktreePath: string, markers: string[] = []): string { diff --git a/src/main/git/worktree-list-reader.ts b/src/main/git/worktrees/catalog/worktree-list-reader.ts similarity index 92% rename from src/main/git/worktree-list-reader.ts rename to src/main/git/worktrees/catalog/worktree-list-reader.ts index 2d9900fb9ba..5b35b8f4bf1 100644 --- a/src/main/git/worktree-list-reader.ts +++ b/src/main/git/worktrees/catalog/worktree-list-reader.ts @@ -1,27 +1,30 @@ -import { throwIfSignalAborted, waitForPromiseWithSignal } from '../../shared/abort-signal-reason' -import { annotateWorktreeLocksFromAdmin } from '../../shared/git-worktree-admin' +import { + throwIfSignalAborted, + waitForPromiseWithSignal +} from '../../../../shared/abort-signal-reason' +import { annotateWorktreeLocksFromAdmin } from '../../../../shared/git-worktree-admin' import { stat } from 'node:fs/promises' -import type { GitWorktreeInfo } from '../../shared/worktree/types' -import { toWslExecutionSpace } from '../../shared/wsl-paths' +import type { GitWorktreeInfo } from '../../../../shared/worktree/types' +import { toWslExecutionSpace } from '../../../../shared/wsl-paths' import { hasUnsupportedRevParsePathFormatEcho, isUnsupportedRevParsePathFormatError, isUnsupportedWorktreeListZError -} from '../../shared/git-worktree-command-capabilities' -import { withLocalGitCapabilityCacheForExecution } from './git-capability-state' -import { parseWorktreeList } from '../../shared/git-worktree-porcelain-parser' -import type { GitWorktreeExecOptions } from './worktree-operation-options' +} from '../../../../shared/git-worktree-command-capabilities' +import { withLocalGitCapabilityCacheForExecution } from '../../command-runner/git-capability-state' +import { parseWorktreeList } from '../../../../shared/git-worktree-porcelain-parser' +import type { GitWorktreeExecOptions } from '../worktree-operation-options' import { WORKTREE_LIST_TIMEOUT_MS, getErrorCode, gitExecOptions -} from './worktree-operation-options' +} from '../worktree-operation-options' import { areWorktreePathsEqual, resolveRevParsePath, translateWorktreePath } from './worktree-path-comparison' -import { gitExecFileAsync } from './runner' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' const PRUNABLE_EXISTENCE_PROBE_CONCURRENCY = 8 diff --git a/src/main/git/worktree-listing-created-sparse-distro.test.ts b/src/main/git/worktrees/catalog/worktree-listing-created-sparse-distro.test.ts similarity index 100% rename from src/main/git/worktree-listing-created-sparse-distro.test.ts rename to src/main/git/worktrees/catalog/worktree-listing-created-sparse-distro.test.ts diff --git a/src/main/git/worktree-listing-sparse-cancellation.test.ts b/src/main/git/worktrees/catalog/worktree-listing-sparse-cancellation.test.ts similarity index 94% rename from src/main/git/worktree-listing-sparse-cancellation.test.ts rename to src/main/git/worktrees/catalog/worktree-listing-sparse-cancellation.test.ts index 128829dc79c..513b3f53a8c 100644 --- a/src/main/git/worktree-listing-sparse-cancellation.test.ts +++ b/src/main/git/worktrees/catalog/worktree-listing-sparse-cancellation.test.ts @@ -1,6 +1,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' -import type { GitWorktreeInfo } from '../../shared/worktree/types' -import type { GitWorktreeExecOptions } from './worktree-operation-options' +import type { GitWorktreeInfo } from '../../../../shared/worktree/types' +import type { GitWorktreeExecOptions } from '../worktree-operation-options' const { sparseProbe } = vi.hoisted(() => ({ sparseProbe: @@ -9,7 +9,7 @@ const { sparseProbe } = vi.hoisted(() => ({ >() })) -vi.mock('./worktree-sparse-checkout-cache', () => ({ +vi.mock('../sparse-checkout/worktree-sparse-checkout-cache', () => ({ detectSparseCheckoutCached: sparseProbe })) vi.mock('./worktree-list-reader', () => ({ diff --git a/src/main/git/worktree-listing-unc-drvfs-identity.test.ts b/src/main/git/worktrees/catalog/worktree-listing-unc-drvfs-identity.test.ts similarity index 80% rename from src/main/git/worktree-listing-unc-drvfs-identity.test.ts rename to src/main/git/worktrees/catalog/worktree-listing-unc-drvfs-identity.test.ts index 5268f75ae47..e2d30698238 100644 --- a/src/main/git/worktree-listing-unc-drvfs-identity.test.ts +++ b/src/main/git/worktrees/catalog/worktree-listing-unc-drvfs-identity.test.ts @@ -1,6 +1,6 @@ import type * as FsPromises from 'node:fs/promises' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { getRepoMainWorktreeId } from '../../shared/worktree/id' +import { getRepoMainWorktreeId } from '../../../../shared/worktree/id' const { gitExecFileAsyncMock, gitExecFileSyncMock, statMock, readFileMock, resolveGitDirMock } = vi.hoisted(() => ({ @@ -11,19 +11,24 @@ const { gitExecFileAsyncMock, gitExecFileSyncMock, statMock, readFileMock, resol resolveGitDirMock: vi.fn() })) -vi.mock('../../shared/git-worktree-admin', () => ({ +vi.mock('../../../../shared/git-worktree-admin', () => ({ annotateWorktreeLocksFromAdmin: async (_repoPath: string, rows: unknown[]) => rows })) -vi.mock('./runner', async () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, - translateWslOutputPaths: (await import('./command-runner/wsl-path-translation')) - .translateWslOutputPaths +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock })) -vi.mock('./status', () => ({ - resolveGitDir: resolveGitDirMock, +vi.mock('../../source-control/resolve-git-dir', () => ({ + resolveGitDir: resolveGitDirMock +})) + +vi.mock('../../source-control/git-read-cache-invalidation', () => ({ runWithGitReadCacheInvalidation: (run: () => Promise) => run() })) @@ -32,8 +37,8 @@ vi.mock('fs/promises', async () => { return { ...actual, stat: statMock, readFile: readFileMock } }) -import { resetWorktreeRemovalState } from './remove-worktree-test-harness' -import { listWorktreesStrict } from './worktree' +import { resetWorktreeRemovalState } from '../removal/remove-worktree-test-harness' +import { listWorktreesStrict } from './worktree-listing' const REPO_ID = 'repo-1' const UNC_REPO = String.raw`\\wsl.localhost\Ubuntu\mnt\c\src\app` diff --git a/src/main/git/worktree-listing.ts b/src/main/git/worktrees/catalog/worktree-listing.ts similarity index 92% rename from src/main/git/worktree-listing.ts rename to src/main/git/worktrees/catalog/worktree-listing.ts index 906745545d3..5bc06daf2ed 100644 --- a/src/main/git/worktree-listing.ts +++ b/src/main/git/worktrees/catalog/worktree-listing.ts @@ -1,12 +1,15 @@ -import { throwIfSignalAborted, waitForPromiseWithSignal } from '../../shared/abort-signal-reason' +import { + throwIfSignalAborted, + waitForPromiseWithSignal +} from '../../../../shared/abort-signal-reason' import { readFile, realpath, stat } from 'node:fs/promises' import { join } from 'node:path' -import { isDefinitiveAbsence } from '../../shared/definitive-filesystem-absence' -import { resolveGitMetadataPath } from '../../shared/git-metadata-path' -import { parseGitdirMarkerPayload } from '../../shared/gitdir-marker-payload' -import { isWorktreeCreatePreparation } from '../../shared/worktree/create-preparation' -import { toWslExecutionSpace } from '../../shared/wsl-paths' -import type { GitWorktreeInfo } from '../../shared/worktree/types' +import { isDefinitiveAbsence } from '../../../../shared/definitive-filesystem-absence' +import { resolveGitMetadataPath } from '../../../../shared/git-metadata-path' +import { parseGitdirMarkerPayload } from '../../../../shared/gitdir-marker-payload' +import { isWorktreeCreatePreparation } from '../../../../shared/worktree/create-preparation' +import { toWslExecutionSpace } from '../../../../shared/wsl-paths' +import type { GitWorktreeInfo } from '../../../../shared/worktree/types' import { readCheckedOutBranchRef, readRepoCommonDirFromGit, @@ -15,15 +18,15 @@ import { readWorktreeHeadOid, readWorktreeList } from './worktree-list-reader' -import type { GitWorktreeExecOptions } from './worktree-operation-options' +import type { GitWorktreeExecOptions } from '../worktree-operation-options' import { WORKTREE_LIST_TIMEOUT_MS, getErrorCode, isNotGitRepositoryError, normalizeLocalBranchRef -} from './worktree-operation-options' +} from '../worktree-operation-options' import { areWorktreePathsEqual, translateWorktreePath } from './worktree-path-comparison' -import { detectSparseCheckoutCached } from './worktree-sparse-checkout-cache' +import { detectSparseCheckoutCached } from '../sparse-checkout/worktree-sparse-checkout-cache' const SPARSE_CHECKOUT_DETECTION_CONCURRENCY = 8 diff --git a/src/main/git/worktree-path-comparison.ts b/src/main/git/worktrees/catalog/worktree-path-comparison.ts similarity index 93% rename from src/main/git/worktree-path-comparison.ts rename to src/main/git/worktrees/catalog/worktree-path-comparison.ts index ace9f110cb3..f4e3ab1cb09 100644 --- a/src/main/git/worktree-path-comparison.ts +++ b/src/main/git/worktrees/catalog/worktree-path-comparison.ts @@ -1,8 +1,8 @@ import { posix, win32 } from 'node:path' -import { isWindowsAbsolutePathLike } from '../../shared/cross-platform-path' -import { foldWslUncPathCaseInsensitiveParts } from '../../shared/wsl-paths' -import type { GitWorktreeExecOptions } from './worktree-operation-options' -import { translateWslOutputPaths } from './runner' +import { isWindowsAbsolutePathLike } from '../../../../shared/cross-platform-path' +import { foldWslUncPathCaseInsensitiveParts } from '../../../../shared/wsl-paths' +import type { GitWorktreeExecOptions } from '../worktree-operation-options' +import { translateWslOutputPaths } from '../../command-runner/wsl-path-translation' /** Path syntax determines case folding: preserve POSIX and WSL ext4 tails even on Windows to avoid merging checkouts. */ export function canonicalWorktreePath(pathValue: string, platform = process.platform): string { diff --git a/src/main/git/worktree-path-deduplication.test.ts b/src/main/git/worktrees/catalog/worktree-path-deduplication.test.ts similarity index 100% rename from src/main/git/worktree-path-deduplication.test.ts rename to src/main/git/worktrees/catalog/worktree-path-deduplication.test.ts diff --git a/src/main/git/worktree-porcelain-parsing.test.ts b/src/main/git/worktrees/catalog/worktree-porcelain-parsing.test.ts similarity index 91% rename from src/main/git/worktree-porcelain-parsing.test.ts rename to src/main/git/worktrees/catalog/worktree-porcelain-parsing.test.ts index 98488bde974..22652d189ca 100644 --- a/src/main/git/worktree-porcelain-parsing.test.ts +++ b/src/main/git/worktrees/catalog/worktree-porcelain-parsing.test.ts @@ -8,14 +8,23 @@ const { gitExecFileAsyncMock, gitExecFileSyncMock, translateWslOutputPathsMock } }) ) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) -import { parseWorktreeList } from './worktree' -import { registerWorktreeSuiteHooks } from './worktree-test-harness' +import { parseWorktreeList } from '../../../../shared/git-worktree-porcelain-parser' +import { registerWorktreeSuiteHooks } from '../testing/worktree-test-harness' registerWorktreeSuiteHooks() diff --git a/src/main/git/worktree-scan-cache-annotation-reuse.test.ts b/src/main/git/worktrees/catalog/worktree-scan-cache-annotation-reuse.test.ts similarity index 89% rename from src/main/git/worktree-scan-cache-annotation-reuse.test.ts rename to src/main/git/worktrees/catalog/worktree-scan-cache-annotation-reuse.test.ts index bfe11e6259c..118fb6571a2 100644 --- a/src/main/git/worktree-scan-cache-annotation-reuse.test.ts +++ b/src/main/git/worktrees/catalog/worktree-scan-cache-annotation-reuse.test.ts @@ -1,6 +1,6 @@ // Probe-free graph readers share the Git listing without waiting for sparse annotation. import { beforeEach, describe, expect, it, vi } from 'vitest' -import type { GitWorktreeInfo } from '../../shared/worktree/types' +import type { GitWorktreeInfo } from '../../../../shared/worktree/types' const { detectSparseCheckoutMock, readWorktreeListMock, readTranslatedWorktreeGraphMock } = vi.hoisted(() => ({ @@ -9,7 +9,7 @@ const { detectSparseCheckoutMock, readWorktreeListMock, readTranslatedWorktreeGr readTranslatedWorktreeGraphMock: vi.fn() })) -vi.mock('./worktree-sparse-state', () => ({ +vi.mock('../sparse-checkout/worktree-sparse-state', () => ({ detectSparseCheckout: detectSparseCheckoutMock, resolveGitCommonDir: vi.fn() })) @@ -22,8 +22,12 @@ vi.mock('./worktree-list-reader', () => ({ readWorktreeList: readWorktreeListMock })) -import { _resetWorktreeScanCacheForTests, listWorktreeGraph, listWorktrees } from './worktree' -import { __resetSparseCheckoutStateCacheForTests } from './worktree-sparse-checkout-cache' +import { + _resetWorktreeScanCacheForTests, + listWorktreeGraph, + listWorktrees +} from './worktree-scan-cache' +import { __resetSparseCheckoutStateCacheForTests } from '../sparse-checkout/worktree-sparse-checkout-cache' const REPO = '\\\\wsl.localhost\\Ubuntu\\home\\me\\repo' const ROW: GitWorktreeInfo = { diff --git a/src/main/git/worktree-scan-cache-sharing.test.ts b/src/main/git/worktrees/catalog/worktree-scan-cache-sharing.test.ts similarity index 94% rename from src/main/git/worktree-scan-cache-sharing.test.ts rename to src/main/git/worktrees/catalog/worktree-scan-cache-sharing.test.ts index 5b6dde77836..86cd01f3864 100644 --- a/src/main/git/worktree-scan-cache-sharing.test.ts +++ b/src/main/git/worktrees/catalog/worktree-scan-cache-sharing.test.ts @@ -1,4 +1,4 @@ -import { worktreeCreateGit } from './worktree-create-git-executor' +import { worktreeCreateGit } from '../creation/worktree-create-git-executor' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const { gitExecFileAsyncMock, gitExecFileSyncMock, translateWslOutputPathsMock } = vi.hoisted( @@ -9,9 +9,18 @@ const { gitExecFileAsyncMock, gitExecFileSyncMock, translateWslOutputPathsMock } }) ) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) @@ -21,13 +30,13 @@ import { listWorktreeGraph, listWorktrees, listWorktreesSharedStrict, - listWorktreesStrict, - moveWorktree, - removeWorktree, - notifyPreparedWorktreeMutation, - WORKTREE_LIST_TIMEOUT_MS -} from './worktree' -import { registerWorktreeSuiteHooks } from './worktree-test-harness' + bumpWorktreeScanGeneration as notifyPreparedWorktreeMutation +} from './worktree-scan-cache' +import { listWorktreesStrict } from './worktree-listing' +import { moveWorktree } from '../movement/worktree-move' +import { removeWorktree } from '../removal/worktree-removal' +import { WORKTREE_LIST_TIMEOUT_MS } from '../worktree-operation-options' +import { registerWorktreeSuiteHooks } from '../testing/worktree-test-harness' registerWorktreeSuiteHooks() diff --git a/src/main/git/worktree-scan-cache.ts b/src/main/git/worktrees/catalog/worktree-scan-cache.ts similarity index 93% rename from src/main/git/worktree-scan-cache.ts rename to src/main/git/worktrees/catalog/worktree-scan-cache.ts index 981d099a7ea..db33e4875ec 100644 --- a/src/main/git/worktree-scan-cache.ts +++ b/src/main/git/worktrees/catalog/worktree-scan-cache.ts @@ -1,13 +1,13 @@ -import type { GitWorktreeInfo } from '../../shared/worktree/types' +import type { GitWorktreeInfo } from '../../../../shared/worktree/types' import { annotateSparseCheckoutStatus, listWorktreeGraph as listWorktreeGraphUnshared, listWorktreesStrict as listWorktreesStrictUnshared, listWorktreesStrictAllowingTrueEmpty as listWorktreesStrictAllowingTrueEmptyUnshared } from './worktree-listing' -import type { GitWorktreeExecOptions } from './worktree-operation-options' -import { WORKTREE_LIST_TIMEOUT_MS } from './worktree-operation-options' -import { resolveGitAdmissionTier } from './command-runner/git-operation-executor' +import type { GitWorktreeExecOptions } from '../worktree-operation-options' +import { WORKTREE_LIST_TIMEOUT_MS } from '../worktree-operation-options' +import { resolveGitAdmissionTier } from '../../command-runner/git-operation-executor' const inFlightWorktreeScans = new Map>() diff --git a/src/main/git/worktree-separate-git-dir.test.ts b/src/main/git/worktrees/catalog/worktree-separate-git-dir.test.ts similarity index 96% rename from src/main/git/worktree-separate-git-dir.test.ts rename to src/main/git/worktrees/catalog/worktree-separate-git-dir.test.ts index fa61818770d..60a8f50ecdd 100644 --- a/src/main/git/worktree-separate-git-dir.test.ts +++ b/src/main/git/worktrees/catalog/worktree-separate-git-dir.test.ts @@ -3,12 +3,12 @@ import { mkdir, mkdtemp, realpath, rm, symlink, writeFile } from 'node:fs/promis import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, describe, expect, it, vi } from 'vitest' -import type * as GitRunner from './runner' +import type * as GitRunner from '../../command-runner/git-exec-file' // Spy on real Git to count extra rev-parse calls without replacing path behavior. const revParseTopLevelCalls = { count: 0 } -vi.mock('./runner', async () => { - const actual = await vi.importActual('./runner') +vi.mock('../../command-runner/git-exec-file', async () => { + const actual = await vi.importActual('../../command-runner/git-exec-file') return { ...actual, gitExecFileAsync: (args: string[], options?: unknown) => { @@ -23,7 +23,7 @@ vi.mock('./runner', async () => { } }) -const { listWorktrees } = await import('./worktree') +const { listWorktrees } = await import('./worktree-scan-cache') const tempRoots: string[] = [] diff --git a/src/main/git/wsl-worktree-git-path.test.ts b/src/main/git/worktrees/catalog/wsl-worktree-git-path.test.ts similarity index 95% rename from src/main/git/wsl-worktree-git-path.test.ts rename to src/main/git/worktrees/catalog/wsl-worktree-git-path.test.ts index c388fce34cc..775b84949f6 100644 --- a/src/main/git/wsl-worktree-git-path.test.ts +++ b/src/main/git/worktrees/catalog/wsl-worktree-git-path.test.ts @@ -5,9 +5,9 @@ const { gitExecFileAsyncMock, readWorktreeGitPathMock } = vi.hoisted(() => ({ readWorktreeGitPathMock: vi.fn() })) -vi.mock('./command-runner/git-exec-file', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) +vi.mock('../../command-runner/git-exec-file', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) vi.mock('./worktree-git-path', () => ({ readWorktreeGitPath: readWorktreeGitPathMock })) -vi.mock('../wsl/filesystem/wsl-automount-root', async (importOriginal) => ({ +vi.mock('../../../wsl/filesystem/wsl-automount-root', async (importOriginal) => ({ ...(await importOriginal()), knownWslAutomountRoots: () => ['/mnt/'] })) diff --git a/src/main/git/wsl-worktree-git-path.ts b/src/main/git/worktrees/catalog/wsl-worktree-git-path.ts similarity index 89% rename from src/main/git/wsl-worktree-git-path.ts rename to src/main/git/worktrees/catalog/wsl-worktree-git-path.ts index 416e85ec2f9..e7e69b2aa03 100644 --- a/src/main/git/wsl-worktree-git-path.ts +++ b/src/main/git/worktrees/catalog/wsl-worktree-git-path.ts @@ -1,10 +1,10 @@ import { win32 } from 'node:path' -import { parseWslUncPath, toWindowsWslUncPath } from '../../shared/wsl-paths' +import { parseWslUncPath, toWindowsWslUncPath } from '../../../../shared/wsl-paths' import { knownWslAutomountRoots, wslDrivePathUnderRoots -} from '../wsl/filesystem/wsl-automount-root' -import { gitExecFileAsync } from './command-runner/git-exec-file' +} from '../../../wsl/filesystem/wsl-automount-root' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' import { readWorktreeGitPath } from './worktree-git-path' /** diff --git a/src/main/git/worktree-include-file.test.ts b/src/main/git/worktrees/content-paths/worktree-include-file.test.ts similarity index 94% rename from src/main/git/worktree-include-file.test.ts rename to src/main/git/worktrees/content-paths/worktree-include-file.test.ts index 886bd85bad1..ee16aaf0440 100644 --- a/src/main/git/worktree-include-file.test.ts +++ b/src/main/git/worktrees/content-paths/worktree-include-file.test.ts @@ -5,9 +5,10 @@ import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { resolveWorktreeIncludePaths } from './worktree-include-file' -import { gitExecFileAsync } from './runner' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' -vi.mock('./runner', () => ({ +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: vi.fn() })) diff --git a/src/main/git/worktree-include-file.ts b/src/main/git/worktrees/content-paths/worktree-include-file.ts similarity index 94% rename from src/main/git/worktree-include-file.ts rename to src/main/git/worktrees/content-paths/worktree-include-file.ts index 32f1b087970..53d57e8b27b 100644 --- a/src/main/git/worktree-include-file.ts +++ b/src/main/git/worktrees/content-paths/worktree-include-file.ts @@ -1,8 +1,8 @@ import { lstat, readFile } from 'node:fs/promises' import { isAbsolute, join } from 'node:path' -import { checkIgnoredPaths } from './check-ignored-paths' -import type { GitRuntimeOptions } from './git-runtime-options' -import { mapWithConcurrency } from '../../shared/map-with-concurrency' +import { checkIgnoredPaths } from '../../source-control/check-ignored-paths' +import type { GitRuntimeOptions } from '../../git-runtime-options' +import { mapWithConcurrency } from '../../../../shared/map-with-concurrency' /** Cross-tool convention for copying selected gitignored paths into new worktrees (#7549). */ export const WORKTREE_INCLUDE_FILE = '.worktreeinclude' diff --git a/src/main/git/worktree-shared-directories.test.ts b/src/main/git/worktrees/content-paths/worktree-shared-directories.test.ts similarity index 97% rename from src/main/git/worktree-shared-directories.test.ts rename to src/main/git/worktrees/content-paths/worktree-shared-directories.test.ts index 155bcc49428..eb0e4e3e67d 100644 --- a/src/main/git/worktree-shared-directories.test.ts +++ b/src/main/git/worktrees/content-paths/worktree-shared-directories.test.ts @@ -11,12 +11,10 @@ import { getWorktreeSharedLinkPaths, resolveWorktreeSharedDirectories } from './worktree-shared-directories' -import { - createWorktreeSharedPaths, - findExistingWorktreeSymlinkPaths -} from '../ipc/worktree-symlinks' -import { assertWorktreeCleanForRemoval } from './worktree' -import { getStatus } from './status' +import { createWorktreeSharedPaths } from '../../../ipc/worktree-symlinks' +import { findExistingWorktreeSymlinkPaths } from './worktree-symlink-detection' +import { assertWorktreeCleanForRemoval } from '../removal/worktree-removal-preflight' +import { getStatus } from '../../source-control/status-read' // An empty config file works with Windows Git (os.devNull does not) and isolates the production runner too. let gitConfigRoot: string diff --git a/src/main/git/worktree-shared-directories.ts b/src/main/git/worktrees/content-paths/worktree-shared-directories.ts similarity index 92% rename from src/main/git/worktree-shared-directories.ts rename to src/main/git/worktrees/content-paths/worktree-shared-directories.ts index c5597f7f124..1415a414798 100644 --- a/src/main/git/worktree-shared-directories.ts +++ b/src/main/git/worktrees/content-paths/worktree-shared-directories.ts @@ -1,10 +1,10 @@ import { stat } from 'node:fs/promises' import { join } from 'node:path' -import { checkIgnoredPaths } from './check-ignored-paths' -import type { GitRuntimeOptions } from './git-runtime-options' -import { loadHooks } from '../workspace-hooks/hooks' -import type { Repo } from '../../shared/repo-types' -import { mapWithConcurrency } from '../../shared/map-with-concurrency' +import { checkIgnoredPaths } from '../../source-control/check-ignored-paths' +import type { GitRuntimeOptions } from '../../git-runtime-options' +import { loadHooks } from '../../../workspace-hooks/hooks' +import type { Repo } from '../../../../shared/repo-types' +import { mapWithConcurrency } from '../../../../shared/map-with-concurrency' const CONFIGURED_SHARED_DIRECTORIES_CACHE_TTL_MS = 30_000 export const MAX_CONFIGURED_SHARED_DIRECTORIES_CACHE_ENTRIES = 512 diff --git a/src/main/git/worktree-symlink-detection.test.ts b/src/main/git/worktrees/content-paths/worktree-symlink-detection.test.ts similarity index 100% rename from src/main/git/worktree-symlink-detection.test.ts rename to src/main/git/worktrees/content-paths/worktree-symlink-detection.test.ts diff --git a/src/main/git/worktree-symlink-detection.ts b/src/main/git/worktrees/content-paths/worktree-symlink-detection.ts similarity index 96% rename from src/main/git/worktree-symlink-detection.ts rename to src/main/git/worktrees/content-paths/worktree-symlink-detection.ts index 3235496b529..cc54d41899e 100644 --- a/src/main/git/worktree-symlink-detection.ts +++ b/src/main/git/worktrees/content-paths/worktree-symlink-detection.ts @@ -1,6 +1,6 @@ import { lstat } from 'node:fs/promises' import { resolve, sep } from 'node:path' -import { resolveWorktreeHostPath } from '../../shared/git-metadata-path' +import { resolveWorktreeHostPath } from '../../../../shared/git-metadata-path' // Keep read-only symlink detection independent of APFS materialization and child-process imports. diff --git a/src/main/git/add-sparse-worktree.test.ts b/src/main/git/worktrees/creation/add-sparse-worktree.test.ts similarity index 86% rename from src/main/git/add-sparse-worktree.test.ts rename to src/main/git/worktrees/creation/add-sparse-worktree.test.ts index cee97ea0a52..d04bfb709bc 100644 --- a/src/main/git/add-sparse-worktree.test.ts +++ b/src/main/git/worktrees/creation/add-sparse-worktree.test.ts @@ -17,14 +17,26 @@ const { resolveGitDirMock: vi.fn() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) -vi.mock('./status', () => ({ - resolveGitDir: resolveGitDirMock, +vi.mock('../../source-control/resolve-git-dir', () => ({ + resolveGitDir: resolveGitDirMock +})) + +vi.mock('../../source-control/git-read-cache-invalidation', () => ({ runWithGitReadCacheInvalidation: (run: () => Promise) => run() })) @@ -39,9 +51,9 @@ import { expectGitCallOrder, resetWorktreeGitMocks, resetWorktreeRemovalState -} from './remove-worktree-test-harness' +} from '../removal/remove-worktree-test-harness' -import { addSparseWorktree } from './worktree' +import { addSparseWorktree } from './worktree-sparse-add' const mockGitCommands = createGitCommandMocker(gitExecFileAsyncMock) const getGitCalls = createGitCallReader(gitExecFileAsyncMock) diff --git a/src/main/git/create-event-repo-probe.test.ts b/src/main/git/worktrees/creation/create-event-repo-probe.test.ts similarity index 98% rename from src/main/git/create-event-repo-probe.test.ts rename to src/main/git/worktrees/creation/create-event-repo-probe.test.ts index a03829c8bdd..c230a3d463e 100644 --- a/src/main/git/create-event-repo-probe.test.ts +++ b/src/main/git/worktrees/creation/create-event-repo-probe.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os' import path from 'node:path' import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { probeCreateEventRepoFacts } from './create-event-repo-probe' -import { createWorktreePreparationLockReason } from '../../shared/worktree/create-preparation' +import { createWorktreePreparationLockReason } from '../../../../shared/worktree/create-preparation' async function hookPresence(repoPath: string, platform: NodeJS.Platform): Promise { return (await probeCreateEventRepoFacts(repoPath, platform)).postCheckoutHook diff --git a/src/main/git/create-event-repo-probe.ts b/src/main/git/worktrees/creation/create-event-repo-probe.ts similarity index 97% rename from src/main/git/create-event-repo-probe.ts rename to src/main/git/worktrees/creation/create-event-repo-probe.ts index b607b144e8e..d92bf1fa678 100644 --- a/src/main/git/create-event-repo-probe.ts +++ b/src/main/git/worktrees/creation/create-event-repo-probe.ts @@ -1,7 +1,7 @@ import { open, readFile, readdir, stat } from 'node:fs/promises' import path from 'node:path' -import { getErrorCode } from './worktree-operation-options' -import { parseWorktreePreparationOwnerPid } from '../../shared/worktree/create-preparation' +import { getErrorCode } from '../worktree-operation-options' +import { parseWorktreePreparationOwnerPid } from '../../../../shared/worktree/create-preparation' /** Existence only: the hook's content is never read. */ export type PostCheckoutHookPresence = 'present' | 'absent' | 'custom_hooks_path' | 'unknown' diff --git a/src/main/git/worktree-add-local-base-refresh.test.ts b/src/main/git/worktrees/creation/worktree-add-local-base-refresh.test.ts similarity index 96% rename from src/main/git/worktree-add-local-base-refresh.test.ts rename to src/main/git/worktrees/creation/worktree-add-local-base-refresh.test.ts index 55362e91d4b..58dc98ed135 100644 --- a/src/main/git/worktree-add-local-base-refresh.test.ts +++ b/src/main/git/worktrees/creation/worktree-add-local-base-refresh.test.ts @@ -14,17 +14,29 @@ const { translateWslOutputPathsMock: vi.fn((output: string) => output) })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) // Keep the ordered runner queues; worktree-checkout-progress-real-git covers the checkout.workers read. -vi.mock('./checkout-workers-git-args', () => ({ checkoutWorkersGitArgs: async () => [] })) +vi.mock('../../command-runner/checkout-workers-git-args', () => ({ + checkoutWorkersGitArgs: async () => [] +})) -import { addWorktree, WORKTREE_ADD_TIMEOUT_MS } from './worktree' -import { registerWorktreeSuiteHooks } from './worktree-test-harness' +import { addWorktree } from './worktree-add' +import { WORKTREE_ADD_TIMEOUT_MS } from '../worktree-operation-options' +import { registerWorktreeSuiteHooks } from '../testing/worktree-test-harness' registerWorktreeSuiteHooks() diff --git a/src/main/git/worktree-add-pending-removal.test.ts b/src/main/git/worktrees/creation/worktree-add-pending-removal.test.ts similarity index 72% rename from src/main/git/worktree-add-pending-removal.test.ts rename to src/main/git/worktrees/creation/worktree-add-pending-removal.test.ts index f2441fd9afc..c08689a5b20 100644 --- a/src/main/git/worktree-add-pending-removal.test.ts +++ b/src/main/git/worktrees/creation/worktree-add-pending-removal.test.ts @@ -8,18 +8,27 @@ const { gitExecFileAsyncMock, gitExecFileSyncMock, translateWslOutputPathsMock } }) ) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) -import { addWorktree } from './worktree' -import { registerWorktreeSuiteHooks } from './worktree-test-harness' +import { addWorktree } from './worktree-add' +import { registerWorktreeSuiteHooks } from '../testing/worktree-test-harness' import { _resetPendingWorktreeRemovalsForTests, startBackgroundWorktreeRemoval -} from '../workspaces/removal/worktree-background-removal' +} from '../../../workspaces/removal/worktree-background-removal' registerWorktreeSuiteHooks() diff --git a/src/main/git/worktree-add-remote-branch-upstream-real-git.test.ts b/src/main/git/worktrees/creation/worktree-add-remote-branch-upstream-real-git.test.ts similarity index 94% rename from src/main/git/worktree-add-remote-branch-upstream-real-git.test.ts rename to src/main/git/worktrees/creation/worktree-add-remote-branch-upstream-real-git.test.ts index a7b64c807cf..2a33dae5f06 100644 --- a/src/main/git/worktree-add-remote-branch-upstream-real-git.test.ts +++ b/src/main/git/worktrees/creation/worktree-add-remote-branch-upstream-real-git.test.ts @@ -2,16 +2,16 @@ import { mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, expect, it } from 'vitest' -import { gitExecFileAsync } from './runner' -import { addWorktree } from './worktree' -import { getBranchConflictKind } from './repo-branch-conflict' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { addWorktree } from './worktree-add' +import { getBranchConflictKind } from '../../repo-branch-conflict' import { finalizePreparedWorktree } from './worktree-create-preparation' import { _resetPreparationPoolForTests, listPreparations, startPreparation, takePreparation -} from '../workspaces/creation/preparation/worktree-create-preparation-pool' +} from '../../../workspaces/creation/preparation/worktree-create-preparation-pool' const roots: string[] = [] afterEach(async () => { diff --git a/src/main/git/worktree-add-timeout-override.test.ts b/src/main/git/worktrees/creation/worktree-add-timeout-override.test.ts similarity index 86% rename from src/main/git/worktree-add-timeout-override.test.ts rename to src/main/git/worktrees/creation/worktree-add-timeout-override.test.ts index aa5961e11dd..2a921431684 100644 --- a/src/main/git/worktree-add-timeout-override.test.ts +++ b/src/main/git/worktrees/creation/worktree-add-timeout-override.test.ts @@ -8,21 +8,30 @@ const { gitExecFileAsyncMock, gitExecFileSyncMock, translateWslOutputPathsMock } }) ) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) -import { GitCommandTimeoutError } from '../../shared/git-command-timeout' -import { addWorktree } from './worktree' +import { GitCommandTimeoutError } from '../../../../shared/git-command-timeout' +import { addWorktree } from './worktree-add' import { resolveWorktreeAddTimeoutMs, WORKTREE_ADD_TIMEOUT_MAX_MS, WORKTREE_ADD_TIMEOUT_MS, worktreeAddTimeoutMessage -} from './worktree-operation-options' -import { registerWorktreeSuiteHooks } from './worktree-test-harness' +} from '../worktree-operation-options' +import { registerWorktreeSuiteHooks } from '../testing/worktree-test-harness' registerWorktreeSuiteHooks() diff --git a/src/main/git/worktree-add.ts b/src/main/git/worktrees/creation/worktree-add.ts similarity index 91% rename from src/main/git/worktree-add.ts rename to src/main/git/worktrees/creation/worktree-add.ts index a318de5c79a..621347c3163 100644 --- a/src/main/git/worktree-add.ts +++ b/src/main/git/worktrees/creation/worktree-add.ts @@ -1,15 +1,15 @@ -import { GitCommandTimeoutError } from '../../shared/git-command-timeout' -import { resolveWorktreeAddBaseRef } from '../../shared/worktree/base-ref' +import { GitCommandTimeoutError } from '../../../../shared/git-command-timeout' +import { resolveWorktreeAddBaseRef } from '../../../../shared/worktree/base-ref' import type { LocalBaseRefRefreshResult, LocalBaseRefUpdateSuggestion -} from '../../shared/worktree/base-ref-drift-types' -import { windowsLongPathGitArgs } from '../../shared/windows-long-path-git-args' -import { checkoutWorkersGitArgs } from './checkout-workers-git-args' -import { withRepoRefMaintenancePaused } from './local-repo-ref-maintenance' -import { gitExecFileAsync } from './runner' -import { runWithGitReadCacheInvalidation } from './status' -import { invalidateWslLinkedWorktreeGitRouting } from './wsl-linked-worktree-git-routing' +} from '../../../../shared/worktree/base-ref-drift-types' +import { windowsLongPathGitArgs } from '../../../../shared/windows-long-path-git-args' +import { checkoutWorkersGitArgs } from '../../command-runner/checkout-workers-git-args' +import { withRepoRefMaintenancePaused } from '../../refs/maintenance/local-repo-ref-maintenance' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { runWithGitReadCacheInvalidation } from '../../source-control/git-read-cache-invalidation' +import { invalidateWslLinkedWorktreeGitRouting } from '../../command-runner/wsl-linked-worktree-git-routing' import { getLocalBaseRefUpdateSuggestionForWorktreeCreate, parseRemoteTrackingLocalBaseRef, @@ -20,14 +20,14 @@ import type { AddWorktreeOptions, AddWorktreeResult, GitWorktreeExecOptions -} from './worktree-operation-options' +} from '../worktree-operation-options' import { gitExecOptions, resolveWorktreeAddTimeoutMs, worktreeAddTimeoutMessage -} from './worktree-operation-options' -import { bumpWorktreeScanGeneration } from './worktree-scan-cache' -import { assertNoPendingWorktreeRemovalConflict } from '../workspaces/removal/worktree-removal-table' +} from '../worktree-operation-options' +import { bumpWorktreeScanGeneration } from '../catalog/worktree-scan-cache' +import { assertNoPendingWorktreeRemovalConflict } from '../../../workspaces/removal/worktree-removal-table' import { createWorktreeCheckoutProgressReader } from './worktree-checkout-progress' export type WorktreeAddBaseContext = Pick & { diff --git a/src/main/git/worktree-base-divergence-real-git.test.ts b/src/main/git/worktrees/creation/worktree-base-divergence-real-git.test.ts similarity index 98% rename from src/main/git/worktree-base-divergence-real-git.test.ts rename to src/main/git/worktrees/creation/worktree-base-divergence-real-git.test.ts index c63bfb16bee..9858c9307ee 100644 --- a/src/main/git/worktree-base-divergence-real-git.test.ts +++ b/src/main/git/worktrees/creation/worktree-base-divergence-real-git.test.ts @@ -3,7 +3,7 @@ import { mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it } from 'vitest' -import { GIT_FETCH_SKIP_AUTO_MAINTENANCE_CONFIG_ARGS } from '../../shared/git-fetch-auto-maintenance' +import { GIT_FETCH_SKIP_AUTO_MAINTENANCE_CONFIG_ARGS } from '../../../../shared/git-fetch-auto-maintenance' import { measureRetargetDivergence, RETARGET_MAX_COMMIT_DIVERGENCE diff --git a/src/main/git/worktree-base-divergence.test.ts b/src/main/git/worktrees/creation/worktree-base-divergence.test.ts similarity index 93% rename from src/main/git/worktree-base-divergence.test.ts rename to src/main/git/worktrees/creation/worktree-base-divergence.test.ts index 123e935952b..b8083ff8896 100644 --- a/src/main/git/worktree-base-divergence.test.ts +++ b/src/main/git/worktrees/creation/worktree-base-divergence.test.ts @@ -2,10 +2,13 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' const mocks = vi.hoisted(() => ({ gitExecFileAsync: vi.fn() })) -vi.mock('./runner', () => ({ gitExecFileAsync: mocks.gitExecFileAsync })) +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: mocks.gitExecFileAsync +})) -import { GitAdmissionScheduler } from './command-runner/git-subprocess-admission' -import type { GitAdmissionTier } from './command-runner/git-exec-options' +import { GitAdmissionScheduler } from '../../../../shared/git-admission-scheduler' +import type { GitAdmissionTier } from '../../../../shared/rpc-contract/git-admission-tier-params' import { measureRetargetDivergence } from './worktree-base-divergence' diff --git a/src/main/git/worktree-base-divergence.ts b/src/main/git/worktrees/creation/worktree-base-divergence.ts similarity index 92% rename from src/main/git/worktree-base-divergence.ts rename to src/main/git/worktrees/creation/worktree-base-divergence.ts index 9fd69048769..36f9a40caac 100644 --- a/src/main/git/worktree-base-divergence.ts +++ b/src/main/git/worktrees/creation/worktree-base-divergence.ts @@ -1,7 +1,7 @@ -import { WSL_GIT_READ_ENVIRONMENT_WAIT_MS } from './wsl-git-read-environment' -import { gitExecFileAsync } from './runner' -import { abortSignalWithTimeout } from '../lib/abort-signal-with-timeout' -import type { GitAdmissionTier } from './command-runner/git-exec-options' +import { WSL_GIT_READ_ENVIRONMENT_WAIT_MS } from '../../wsl-git-read-environment' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { abortSignalWithTimeout } from '../../../lib/abort-signal-with-timeout' +import type { GitAdmissionTier } from '../../../../shared/rpc-contract/git-admission-tier-params' export type RetargetDivergenceOptions = { wslDistro?: string diff --git a/src/main/git/worktree-base-ref-probe.test.ts b/src/main/git/worktrees/creation/worktree-base-ref-probe.test.ts similarity index 87% rename from src/main/git/worktree-base-ref-probe.test.ts rename to src/main/git/worktrees/creation/worktree-base-ref-probe.test.ts index ee9819499a3..80ba17e625c 100644 --- a/src/main/git/worktree-base-ref-probe.test.ts +++ b/src/main/git/worktrees/creation/worktree-base-ref-probe.test.ts @@ -2,7 +2,10 @@ import { describe, expect, it, vi } from 'vitest' const gitExecFileAsync = vi.hoisted(() => vi.fn()) -vi.mock('./runner', () => ({ gitExecFileAsync })) +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync +})) import { probeWorktreeBaseRefPresence } from './worktree-base-ref-probe' diff --git a/src/main/git/worktree-base-ref-probe.ts b/src/main/git/worktrees/creation/worktree-base-ref-probe.ts similarity index 84% rename from src/main/git/worktree-base-ref-probe.ts rename to src/main/git/worktrees/creation/worktree-base-ref-probe.ts index cec608ad90f..d795880ddeb 100644 --- a/src/main/git/worktree-base-ref-probe.ts +++ b/src/main/git/worktrees/creation/worktree-base-ref-probe.ts @@ -1,9 +1,9 @@ -import type { GitAdmissionTier } from '../../shared/rpc-contract/git-admission-tier-params' -import { gitExecFileAsync } from './runner' -import { isShowRefNoMatchError } from './exact-ref-probe' -import { hasCommitObjectViaGitExec } from './commit-object-ref' -import { isSafeGitRefName } from '../../shared/git-status-upstream-ref' -import { resolveWorktreeAddBaseRef } from '../../shared/worktree/base-ref' +import type { GitAdmissionTier } from '../../../../shared/rpc-contract/git-admission-tier-params' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { isShowRefNoMatchError } from '../../../../shared/git-show-ref-no-match' +import { hasCommitObjectViaGitExec } from '../../commit-object-ref' +import { isSafeGitRefName } from '../../../../shared/git-status-upstream-ref' +import { resolveWorktreeAddBaseRef } from '../../../../shared/worktree/base-ref' type GitExecOptions = { wslDistro?: string diff --git a/src/main/git/worktree-base-refresh-contention.test.ts b/src/main/git/worktrees/creation/worktree-base-refresh-contention.test.ts similarity index 97% rename from src/main/git/worktree-base-refresh-contention.test.ts rename to src/main/git/worktrees/creation/worktree-base-refresh-contention.test.ts index 567782bce7a..324afbfa7ce 100644 --- a/src/main/git/worktree-base-refresh-contention.test.ts +++ b/src/main/git/worktrees/creation/worktree-base-refresh-contention.test.ts @@ -5,8 +5,13 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ vi.fn<(args: string[], opts: { cwd: string }) => Promise<{ stdout: string }>>() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: (output: string) => output })) diff --git a/src/main/git/worktree-base-refresh-lock-real-git.test.ts b/src/main/git/worktrees/creation/worktree-base-refresh-lock-real-git.test.ts similarity index 99% rename from src/main/git/worktree-base-refresh-lock-real-git.test.ts rename to src/main/git/worktrees/creation/worktree-base-refresh-lock-real-git.test.ts index 8d67a26bb9c..76602012f68 100644 --- a/src/main/git/worktree-base-refresh-lock-real-git.test.ts +++ b/src/main/git/worktrees/creation/worktree-base-refresh-lock-real-git.test.ts @@ -3,7 +3,7 @@ import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import * as gitRunner from './runner' +import * as gitRunner from '../../command-runner/git-exec-file' import { refreshLocalBaseRefForWorktreeCreate } from './worktree-base-refresh' const tempRoots: string[] = [] diff --git a/src/main/git/worktree-base-refresh.ts b/src/main/git/worktrees/creation/worktree-base-refresh.ts similarity index 87% rename from src/main/git/worktree-base-refresh.ts rename to src/main/git/worktrees/creation/worktree-base-refresh.ts index 00b16b99413..124e0b4f8a1 100644 --- a/src/main/git/worktree-base-refresh.ts +++ b/src/main/git/worktrees/creation/worktree-base-refresh.ts @@ -1,20 +1,21 @@ import type { LocalBaseRefRefreshResult, LocalBaseRefUpdateSuggestion -} from '../../shared/worktree/base-ref-drift-types' -import { normalizeRuntimePathForComparison } from '../../shared/cross-platform-path' -import { createCoalescingKeyedRunner } from '../../shared/coalescing-keyed-runner' -import { parseWorktreeList } from '../../shared/git-worktree-porcelain-parser' +} from '../../../../shared/worktree/base-ref-drift-types' +import { normalizeRuntimePathForComparison } from '../../../../shared/cross-platform-path' +import { createCoalescingKeyedRunner } from '../../../../shared/coalescing-keyed-runner' +import { parseWorktreeList } from '../../../../shared/git-worktree-porcelain-parser' import { fastForwardLocalBaseBranch, inspectLocalBaseBranch, toLocalBaseRefRefreshResult, type LocalBaseBranchFastForwardOutcome, type LocalBaseBranchGit -} from '../../shared/worktree/local-base-branch-fast-forward' -import { gitExecFileAsync, translateWslOutputPaths } from './runner' -import { runWithGitReadCacheInvalidation } from './status' -import type { AddWorktreeOptions, GitWorktreeExecOptions } from './worktree-operation-options' +} from '../../../../shared/worktree/local-base-branch-fast-forward' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { translateWslOutputPaths } from '../../command-runner/wsl-path-translation' +import { runWithGitReadCacheInvalidation } from '../../source-control/git-read-cache-invalidation' +import type { AddWorktreeOptions, GitWorktreeExecOptions } from '../worktree-operation-options' // Bound the create's wait without cancelling the mutating refresh that still owns its checkout. export const LOCAL_BASE_REF_REFRESH_WAIT_MS = 30_000 diff --git a/src/main/git/worktree-checkout-progress-real-git.test.ts b/src/main/git/worktrees/creation/worktree-checkout-progress-real-git.test.ts similarity index 96% rename from src/main/git/worktree-checkout-progress-real-git.test.ts rename to src/main/git/worktrees/creation/worktree-checkout-progress-real-git.test.ts index 92d88dd075c..e56ea532901 100644 --- a/src/main/git/worktree-checkout-progress-real-git.test.ts +++ b/src/main/git/worktrees/creation/worktree-checkout-progress-real-git.test.ts @@ -2,9 +2,9 @@ import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import type { WorktreeCheckoutProgress } from '../../shared/worktree/create-types' -import { gitExecFileAsync } from './runner' -import { addWorktree } from './worktree' +import type { WorktreeCheckoutProgress } from '../../../../shared/worktree/create-types' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { addWorktree } from './worktree-add' const FILE_COUNT = 150 diff --git a/src/main/git/worktree-checkout-progress.ts b/src/main/git/worktrees/creation/worktree-checkout-progress.ts similarity index 86% rename from src/main/git/worktree-checkout-progress.ts rename to src/main/git/worktrees/creation/worktree-checkout-progress.ts index 6310bcfa191..05a26c86af2 100644 --- a/src/main/git/worktree-checkout-progress.ts +++ b/src/main/git/worktrees/creation/worktree-checkout-progress.ts @@ -1,5 +1,5 @@ -import type { WorktreeCheckoutProgress } from '../../shared/worktree/create-types' -import { createGitProgressRecordReader } from '../../shared/git-progress-records' +import type { WorktreeCheckoutProgress } from '../../../../shared/worktree/create-types' +import { createGitProgressRecordReader } from '../../../../shared/git-progress-records' /** Receives checkout progress; `null` means git finished writing the files. */ export type WorktreeCheckoutProgressListener = (progress: WorktreeCheckoutProgress | null) => void diff --git a/src/main/git/worktree-configured-paths-concurrency.test.ts b/src/main/git/worktrees/creation/worktree-configured-paths-concurrency.test.ts similarity index 89% rename from src/main/git/worktree-configured-paths-concurrency.test.ts rename to src/main/git/worktrees/creation/worktree-configured-paths-concurrency.test.ts index 475f5300279..22974ae4fa0 100644 --- a/src/main/git/worktree-configured-paths-concurrency.test.ts +++ b/src/main/git/worktrees/creation/worktree-configured-paths-concurrency.test.ts @@ -16,16 +16,16 @@ vi.mock('node:fs/promises', () => ({ readFile: readFileMock })) -vi.mock('../workspace-hooks/hooks', () => ({ +vi.mock('../../../workspace-hooks/hooks', () => ({ loadHooks: loadHooksMock })) -vi.mock('./check-ignored-paths', () => ({ +vi.mock('../../source-control/check-ignored-paths', () => ({ checkIgnoredPaths: checkIgnoredPathsMock })) -import { resolveWorktreeIncludePaths } from './worktree-include-file' -import { resolveWorktreeSharedDirectories } from './worktree-shared-directories' +import { resolveWorktreeIncludePaths } from '../content-paths/worktree-include-file' +import { resolveWorktreeSharedDirectories } from '../content-paths/worktree-shared-directories' const PATH_COUNT = 16 const configuredPaths = Array.from({ length: PATH_COUNT }, (_, index) => `path-${index}`) diff --git a/src/main/git/worktree-create-git-executor-real-git.test.ts b/src/main/git/worktrees/creation/worktree-create-git-executor-real-git.test.ts similarity index 86% rename from src/main/git/worktree-create-git-executor-real-git.test.ts rename to src/main/git/worktrees/creation/worktree-create-git-executor-real-git.test.ts index 6198d7e3283..71364f6e890 100644 --- a/src/main/git/worktree-create-git-executor-real-git.test.ts +++ b/src/main/git/worktrees/creation/worktree-create-git-executor-real-git.test.ts @@ -2,8 +2,9 @@ import { mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, expect, it } from 'vitest' -import { gitExecFileAsync } from './runner' -import { addWorktree, listWorktrees } from './worktree' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { addWorktree } from './worktree-add' +import { listWorktrees } from '../catalog/worktree-scan-cache' import { finalizePreparedWorktree } from './worktree-create-preparation' import { worktreeCreateGit } from './worktree-create-git-executor' import { @@ -11,13 +12,13 @@ import { listPreparations, startPreparation, takePreparation -} from '../workspaces/creation/preparation/worktree-create-preparation-pool' +} from '../../../workspaces/creation/preparation/worktree-create-preparation-pool' import { acquireGitAdmission, - GitAdmissionScheduler, - _resetGitAdmissionForTests, - type GitAdmissionEvent -} from './command-runner/git-subprocess-admission' + _resetGitAdmissionForTests +} from '../../command-runner/git-subprocess-admission' +import { GitAdmissionScheduler } from '../../../../shared/git-admission-scheduler' +import type { GitAdmissionEvent } from '../../../../shared/git-admission-state' const roots: string[] = [] afterEach(async () => { diff --git a/src/main/git/worktree-create-git-executor.ts b/src/main/git/worktrees/creation/worktree-create-git-executor.ts similarity index 63% rename from src/main/git/worktree-create-git-executor.ts rename to src/main/git/worktrees/creation/worktree-create-git-executor.ts index 481fcdeed30..a2ae07bc713 100644 --- a/src/main/git/worktree-create-git-executor.ts +++ b/src/main/git/worktrees/creation/worktree-create-git-executor.ts @@ -1,4 +1,4 @@ -import { createGitOperationExecutor } from './command-runner/git-operation-executor' +import { createGitOperationExecutor } from '../../command-runner/git-operation-executor' export const worktreeCreateGit = createGitOperationExecutor('interactive') diff --git a/src/main/git/worktree-create-preparation-real-git.test.ts b/src/main/git/worktrees/creation/worktree-create-preparation-real-git.test.ts similarity index 98% rename from src/main/git/worktree-create-preparation-real-git.test.ts rename to src/main/git/worktrees/creation/worktree-create-preparation-real-git.test.ts index 74eb4a988b6..9fb55c51203 100644 --- a/src/main/git/worktree-create-preparation-real-git.test.ts +++ b/src/main/git/worktrees/creation/worktree-create-preparation-real-git.test.ts @@ -4,26 +4,26 @@ import { mkdir, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promi import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it, vi } from 'vitest' -import * as gitRunner from './runner' +import * as gitRunner from '../../command-runner/git-exec-file' import { createWorktreePreparationLockReason, isWorktreeCreatePreparation, WORKTREE_CREATE_PREPARATION_DIRECTORY -} from '../../shared/worktree/create-preparation' -import { listWorktrees } from './worktree' +} from '../../../../shared/worktree/create-preparation' +import { listWorktrees } from '../catalog/worktree-scan-cache' import { discardPreparedWorktree, finalizePreparedWorktree, prepareWorktreeCreateCheckout } from './worktree-create-preparation' -import { areWorktreePathsEqual } from './worktree-path-comparison' +import { areWorktreePathsEqual } from '../catalog/worktree-path-comparison' import { _resetPreparationPoolForTests, listPreparations, startPreparation, takePreparation -} from '../workspaces/creation/preparation/worktree-create-preparation-pool' -import { hasPendingStalePreparationCleanup } from '../workspaces/creation/preparation/worktree-create-preparation-stale-cleanup' +} from '../../../workspaces/creation/preparation/worktree-create-preparation-pool' +import { hasPendingStalePreparationCleanup } from '../../../workspaces/creation/preparation/worktree-create-preparation-stale-cleanup' const tempRoots: string[] = [] diff --git a/src/main/git/worktree-create-preparation-real-wsl.test.ts b/src/main/git/worktrees/creation/worktree-create-preparation-real-wsl.test.ts similarity index 93% rename from src/main/git/worktree-create-preparation-real-wsl.test.ts rename to src/main/git/worktrees/creation/worktree-create-preparation-real-wsl.test.ts index 50f46342502..f13a78d6f98 100644 --- a/src/main/git/worktree-create-preparation-real-wsl.test.ts +++ b/src/main/git/worktrees/creation/worktree-create-preparation-real-wsl.test.ts @@ -1,13 +1,13 @@ import { mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' import { join } from 'node:path' import { expect, it } from 'vitest' -import { createWorktreePreparationLockReason } from '../../shared/worktree/create-preparation' -import { gitExecFileAsync } from './runner' +import { createWorktreePreparationLockReason } from '../../../../shared/worktree/create-preparation' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' import { finalizePreparedWorktree, prepareWorktreeCreateCheckout } from './worktree-create-preparation' -import { removeWorktree } from './worktree-removal' +import { removeWorktree } from '../removal/worktree-removal' // Opt in on Windows with a running distro; all Git commands use the production WSL router. const wslDistro = process.env.ORCA_TEST_WSL_DISTRO diff --git a/src/main/git/worktree-create-preparation.ts b/src/main/git/worktrees/creation/worktree-create-preparation.ts similarity index 90% rename from src/main/git/worktree-create-preparation.ts rename to src/main/git/worktrees/creation/worktree-create-preparation.ts index ff110544c6f..ce6cec69d06 100644 --- a/src/main/git/worktree-create-preparation.ts +++ b/src/main/git/worktrees/creation/worktree-create-preparation.ts @@ -1,28 +1,34 @@ -import { windowsLongPathGitArgs } from '../../shared/windows-long-path-git-args' -import { checkoutWorkersGitArgs } from './checkout-workers-git-args' -import { waitForPromiseWithSignal } from '../../shared/abort-signal-reason' -import { resolveWorktreeAddBaseRef } from '../../shared/worktree/base-ref' -import type { AddWorktreeOptions, AddWorktreeResult, GitWorktreeExecOptions } from './worktree' -import { gitExecOptions } from './worktree-operation-options' +import { windowsLongPathGitArgs } from '../../../../shared/windows-long-path-git-args' +import { checkoutWorkersGitArgs } from '../../command-runner/checkout-workers-git-args' +import { waitForPromiseWithSignal } from '../../../../shared/abort-signal-reason' +import { resolveWorktreeAddBaseRef } from '../../../../shared/worktree/base-ref' +import type { + AddWorktreeOptions, + AddWorktreeResult, + GitWorktreeExecOptions +} from '../worktree-operation-options' +import { + gitExecOptions, + resolveWorktreeAddTimeoutMs, + WORKTREE_REMOVAL_REGISTRATION_TIMEOUT_MS +} from '../worktree-operation-options' import { configurePushAutoSetupRemote, - notifyPreparedWorktreeMutation, persistWorktreeCreationBase, resolveWorktreeAddBaseContext, - resolveWorktreeAddTimeoutMs, - trackSameNameRemoteBase, - WORKTREE_REMOVAL_REGISTRATION_TIMEOUT_MS -} from './worktree' + trackSameNameRemoteBase +} from './worktree-add' +import { bumpWorktreeScanGeneration as notifyPreparedWorktreeMutation } from '../catalog/worktree-scan-cache' import { gitCleanupOptions, performDiscardPreparedWorktree, removeFailedFinalization } from './worktree-preparation-discard' import { hasWorktreeBaseCommitRef } from './worktree-base-ref-probe' -import { withRepoRefMaintenancePaused } from './local-repo-ref-maintenance' -import { gitExecFileAsync } from './runner' -import { runWithGitReadCacheInvalidation } from './status' -import { invalidateWslLinkedWorktreeGitRouting } from './wsl-linked-worktree-git-routing' +import { withRepoRefMaintenancePaused } from '../../refs/maintenance/local-repo-ref-maintenance' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { runWithGitReadCacheInvalidation } from '../../source-control/git-read-cache-invalidation' +import { invalidateWslLinkedWorktreeGitRouting } from '../../command-runner/wsl-linked-worktree-git-routing' import { unlockWorktreePreparation, unlockWorktreePreparationAtPath, diff --git a/src/main/git/worktree-preparation-add.test.ts b/src/main/git/worktrees/creation/worktree-preparation-add.test.ts similarity index 95% rename from src/main/git/worktree-preparation-add.test.ts rename to src/main/git/worktrees/creation/worktree-preparation-add.test.ts index f96db71aebb..82c7eb3aa68 100644 --- a/src/main/git/worktree-preparation-add.test.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-add.test.ts @@ -1,7 +1,7 @@ import { beforeEach, expect, it, vi } from 'vitest' import type * as FilePromises from 'node:fs/promises' import type * as PreparationLock from './worktree-preparation-lock' -import { isUnsupportedWorktreeAddLockReasonError } from '../../shared/git-worktree-command-capabilities' +import { isUnsupportedWorktreeAddLockReasonError } from '../../../../shared/git-worktree-command-capabilities' const mocks = vi.hoisted(() => ({ git: vi.fn(), @@ -10,7 +10,10 @@ const mocks = vi.hoisted(() => ({ verify: vi.fn(), discard: vi.fn() })) -vi.mock('./runner', () => ({ gitExecFileAsync: mocks.git })) +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: mocks.git +})) vi.mock('node:fs/promises', async (importOriginal) => ({ ...(await importOriginal()), lstat: mocks.lstat @@ -23,13 +26,16 @@ vi.mock('./worktree-preparation-lock', async (importOriginal) => ({ vi.mock('./worktree-preparation-discard', () => ({ performDiscardPreparedWorktree: mocks.discard })) import { addLockedWorktreePreparation } from './worktree-preparation-add' -import { clearGitCapabilityStateForTests, getLocalGitCapabilityCache } from './git-capability-state' +import { + clearGitCapabilityStateForTests, + getLocalGitCapabilityCache +} from '../../command-runner/git-capability-state' import { WorktreePreparationLockOwnershipError } from './worktree-preparation-lock' -import { WORKTREE_REMOVAL_REGISTRATION_TIMEOUT_MS } from './worktree-operation-options' +import { WORKTREE_REMOVAL_REGISTRATION_TIMEOUT_MS } from '../worktree-operation-options' import { resetWslLinkedWorktreeGitRoutingForTests, seedWslLinkedWorktreeGitRoutingForTests -} from './wsl-linked-worktree-git-routing' +} from '../../command-runner/wsl-linked-worktree-git-routing' const reason = 'orca-create-preparation:v1:123:atomic' const unsupported = Object.assign(new Error("error: unknown option 'reason'"), { code: 129 }) diff --git a/src/main/git/worktree-preparation-add.ts b/src/main/git/worktrees/creation/worktree-preparation-add.ts similarity index 83% rename from src/main/git/worktree-preparation-add.ts rename to src/main/git/worktrees/creation/worktree-preparation-add.ts index 3bc606fd893..04bf1a1cc5a 100644 --- a/src/main/git/worktree-preparation-add.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-add.ts @@ -1,23 +1,23 @@ import { lstat } from 'node:fs/promises' -import { isUnsupportedWorktreeAddLockReasonError } from '../../shared/git-worktree-command-capabilities' -import { resolveWorktreeHostPath } from '../../shared/git-metadata-path' -import { windowsLongPathGitArgs } from '../../shared/windows-long-path-git-args' -import { toHostFilesystemPath } from '../filesystem/host-tree-removal' -import { withLocalGitCapabilityCacheForExecution } from './git-capability-state' -import { gitExecFileAsync } from './runner' +import { isUnsupportedWorktreeAddLockReasonError } from '../../../../shared/git-worktree-command-capabilities' +import { resolveWorktreeHostPath } from '../../../../shared/git-metadata-path' +import { windowsLongPathGitArgs } from '../../../../shared/windows-long-path-git-args' +import { toHostFilesystemPath } from '../../../filesystem/host-tree-removal' +import { withLocalGitCapabilityCacheForExecution } from '../../command-runner/git-capability-state' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' import { getErrorCode, gitExecOptions, WORKTREE_REMOVAL_REGISTRATION_TIMEOUT_MS, type GitWorktreeExecOptions -} from './worktree-operation-options' +} from '../worktree-operation-options' import { performDiscardPreparedWorktree } from './worktree-preparation-discard' import { lockWorktreePreparation, verifyWorktreePreparationLock, WorktreePreparationLockOwnershipError } from './worktree-preparation-lock' -import { invalidateWslLinkedWorktreeGitRouting } from './wsl-linked-worktree-git-routing' +import { invalidateWslLinkedWorktreeGitRouting } from '../../command-runner/wsl-linked-worktree-git-routing' async function isAbsent(worktreePath: string, options: GitWorktreeExecOptions): Promise { const hostPath = resolveWorktreeHostPath(worktreePath, options) diff --git a/src/main/git/worktree-preparation-base-oid.test.ts b/src/main/git/worktrees/creation/worktree-preparation-base-oid.test.ts similarity index 91% rename from src/main/git/worktree-preparation-base-oid.test.ts rename to src/main/git/worktrees/creation/worktree-preparation-base-oid.test.ts index 508707dbd9e..e39121c40db 100644 --- a/src/main/git/worktree-preparation-base-oid.test.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-base-oid.test.ts @@ -3,7 +3,10 @@ import type * as WorktreeBaseRefresh from './worktree-base-refresh' import type * as WorktreePreparationLock from './worktree-preparation-lock' const gitExec = vi.hoisted(() => vi.fn()) -vi.mock('./runner', () => ({ gitExecFileAsync: gitExec })) +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExec +})) vi.mock('./worktree-preparation-lock', async (importOriginal) => ({ ...(await importOriginal()), verifyWorktreePreparationLock: vi.fn(async () => '/owned-lock'), @@ -15,8 +18,10 @@ vi.mock('./worktree-base-refresh', async (importOriginal) => ({ refreshLocalBaseRefForWorktreeCreate: vi.fn(async () => undefined), getLocalBaseRefUpdateSuggestionForWorktreeCreate: vi.fn() })) -vi.mock('./status', () => ({ runWithGitReadCacheInvalidation: (run: () => unknown) => run() })) -vi.mock('./wsl-linked-worktree-git-routing', () => ({ +vi.mock('../../source-control/git-read-cache-invalidation', () => ({ + runWithGitReadCacheInvalidation: (run: () => unknown) => run() +})) +vi.mock('../../command-runner/wsl-linked-worktree-git-routing', () => ({ invalidateWslLinkedWorktreeGitRouting: vi.fn() })) diff --git a/src/main/git/worktree-preparation-cancel-latency.bench.test.ts b/src/main/git/worktrees/creation/worktree-preparation-cancel-latency.bench.test.ts similarity index 97% rename from src/main/git/worktree-preparation-cancel-latency.bench.test.ts rename to src/main/git/worktrees/creation/worktree-preparation-cancel-latency.bench.test.ts index 579d608115f..7e1dd79d875 100644 --- a/src/main/git/worktree-preparation-cancel-latency.bench.test.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-cancel-latency.bench.test.ts @@ -1,4 +1,4 @@ -// Opt in: ORCA_WORKTREE_PREPARATION_CANCEL_BENCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/git/worktree-preparation-cancel-latency.bench.test.ts +// Opt in: ORCA_WORKTREE_PREPARATION_CANCEL_BENCH=1 pnpm exec vitest run --config config/vitest.config.ts src/main/git/worktrees/creation/worktree-preparation-cancel-latency.bench.test.ts // // Compare fresh-checkout latency while obsolete preparations keep running or are aborted. import { execFileSync } from 'node:child_process' @@ -11,7 +11,7 @@ import { afterAll, beforeAll, describe, expect, it } from 'vitest' import { createWorktreePreparationLockReason, WORKTREE_CREATE_PREPARATION_DIRECTORY -} from '../../shared/worktree/create-preparation' +} from '../../../../shared/worktree/create-preparation' import { discardPreparedWorktree, prepareWorktreeCreateCheckout diff --git a/src/main/git/worktree-preparation-discard-real-git.test.ts b/src/main/git/worktrees/creation/worktree-preparation-discard-real-git.test.ts similarity index 96% rename from src/main/git/worktree-preparation-discard-real-git.test.ts rename to src/main/git/worktrees/creation/worktree-preparation-discard-real-git.test.ts index 90fb41af1c8..73adf59e55b 100644 --- a/src/main/git/worktree-preparation-discard-real-git.test.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-discard-real-git.test.ts @@ -2,10 +2,10 @@ import { mkdir, mkdtemp, readFile, realpath, rm, symlink, writeFile } from 'node import { tmpdir } from 'node:os' import { dirname, join } from 'node:path' import { afterEach, expect, it, vi } from 'vitest' -import { createWorktreePreparationLockReason } from '../../shared/worktree/create-preparation' -import * as runner from './runner' +import { createWorktreePreparationLockReason } from '../../../../shared/worktree/create-preparation' +import * as runner from '../../command-runner/git-exec-file' import { performDiscardPreparedWorktree } from './worktree-preparation-discard' -import { WORKTREE_REMOVAL_REGISTRATION_TIMEOUT_MS } from './worktree-operation-options' +import { WORKTREE_REMOVAL_REGISTRATION_TIMEOUT_MS } from '../worktree-operation-options' const roots: string[] = [] afterEach(async () => { diff --git a/src/main/git/worktree-preparation-discard.ts b/src/main/git/worktrees/creation/worktree-preparation-discard.ts similarity index 86% rename from src/main/git/worktree-preparation-discard.ts rename to src/main/git/worktrees/creation/worktree-preparation-discard.ts index 0af4524b0c3..7859336bba5 100644 --- a/src/main/git/worktree-preparation-discard.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-discard.ts @@ -1,24 +1,24 @@ import { lstat } from 'node:fs/promises' import { join } from 'node:path' -import { waitForPromiseWithSignal } from '../../shared/abort-signal-reason' -import { resolveWorktreeHostPath } from '../../shared/git-metadata-path' -import { findLinkedWorktreeGitDirectory } from '../../shared/git-worktree-admin' -import { windowsLongPathGitArgs } from '../../shared/windows-long-path-git-args' -import { toHostFilesystemPath } from '../filesystem/host-tree-removal' -import { gitExecFileAsync } from './runner' +import { waitForPromiseWithSignal } from '../../../../shared/abort-signal-reason' +import { resolveWorktreeHostPath } from '../../../../shared/git-metadata-path' +import { findLinkedWorktreeGitDirectory } from '../../../../shared/git-worktree-admin' +import { windowsLongPathGitArgs } from '../../../../shared/windows-long-path-git-args' +import { toHostFilesystemPath } from '../../../filesystem/host-tree-removal' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' import { getErrorCode, gitExecOptions, WORKTREE_REMOVAL_REGISTRATION_TIMEOUT_MS, type GitExecOptionsForWorktree, type GitWorktreeExecOptions -} from './worktree-operation-options' +} from '../worktree-operation-options' import { verifyWorktreePreparationLock, verifyWorktreePreparationLockAtPath, WorktreePreparationLockOwnershipError } from './worktree-preparation-lock' -import { invalidateWslLinkedWorktreeGitRouting } from './wsl-linked-worktree-git-routing' +import { invalidateWslLinkedWorktreeGitRouting } from '../../command-runner/wsl-linked-worktree-git-routing' export function gitCleanupOptions( cwd: string, diff --git a/src/main/git/worktree-preparation-fallback-cleanup-real-git.test.ts b/src/main/git/worktrees/creation/worktree-preparation-fallback-cleanup-real-git.test.ts similarity index 95% rename from src/main/git/worktree-preparation-fallback-cleanup-real-git.test.ts rename to src/main/git/worktrees/creation/worktree-preparation-fallback-cleanup-real-git.test.ts index 2f2e7b05590..6a7ed85a233 100644 --- a/src/main/git/worktree-preparation-fallback-cleanup-real-git.test.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-fallback-cleanup-real-git.test.ts @@ -3,11 +3,14 @@ import { mkdir, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promi import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, expect, it, vi } from 'vitest' -import { createWorktreePreparationLockReason } from '../../shared/worktree/create-preparation' -import { clearGitCapabilityStateForTests, getLocalGitCapabilityCache } from './git-capability-state' -import * as runner from './runner' +import { createWorktreePreparationLockReason } from '../../../../shared/worktree/create-preparation' +import { + clearGitCapabilityStateForTests, + getLocalGitCapabilityCache +} from '../../command-runner/git-capability-state' +import * as runner from '../../command-runner/git-exec-file' import { prepareWorktreeCreateCheckout } from './worktree-create-preparation' -import { WORKTREE_REMOVAL_REGISTRATION_TIMEOUT_MS } from './worktree-operation-options' +import { WORKTREE_REMOVAL_REGISTRATION_TIMEOUT_MS } from '../worktree-operation-options' const roots: string[] = [] const unsupported = Object.assign(new Error("error: unknown option 'reason'"), { code: 129 }) diff --git a/src/main/git/worktree-preparation-lock-real-git.test.ts b/src/main/git/worktrees/creation/worktree-preparation-lock-real-git.test.ts similarity index 98% rename from src/main/git/worktree-preparation-lock-real-git.test.ts rename to src/main/git/worktrees/creation/worktree-preparation-lock-real-git.test.ts index 9e91055c615..6256c71f752 100644 --- a/src/main/git/worktree-preparation-lock-real-git.test.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-lock-real-git.test.ts @@ -2,21 +2,21 @@ import { mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join, relative } from 'node:path' import { afterEach, expect, it, vi } from 'vitest' -import { createWorktreePreparationLockReason } from '../../shared/worktree/create-preparation' -import * as runner from './runner' +import { createWorktreePreparationLockReason } from '../../../../shared/worktree/create-preparation' +import * as runner from '../../command-runner/git-exec-file' import { discardPreparedWorktree, finalizePreparedWorktree, prepareWorktreeCreateCheckout } from './worktree-create-preparation' import { unlockWorktreePreparation } from './worktree-preparation-lock' -import { readWorktreeList } from './worktree-list-reader' +import { readWorktreeList } from '../catalog/worktree-list-reader' import { _resetPreparationPoolForTests, listPreparations, startPreparation, WORKTREE_CREATE_PREPARATION_TTL_MS -} from '../workspaces/creation/preparation/worktree-create-preparation-pool' +} from '../../../workspaces/creation/preparation/worktree-create-preparation-pool' const roots: string[] = [] afterEach(async () => { diff --git a/src/main/git/worktree-preparation-lock.test.ts b/src/main/git/worktrees/creation/worktree-preparation-lock.test.ts similarity index 98% rename from src/main/git/worktree-preparation-lock.test.ts rename to src/main/git/worktrees/creation/worktree-preparation-lock.test.ts index 843e0e74059..998fd7bc593 100644 --- a/src/main/git/worktree-preparation-lock.test.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-lock.test.ts @@ -1,7 +1,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { tmpdir } from 'node:os' import { join } from 'node:path' -import { toHostFilesystemPath } from '../filesystem/host-tree-removal' +import { toHostFilesystemPath } from '../../../filesystem/host-tree-removal' import type * as FilePromises from 'node:fs/promises' const mocks = vi.hoisted(() => ({ @@ -10,7 +10,10 @@ const mocks = vi.hoisted(() => ({ writeFile: vi.fn(), unlink: vi.fn() })) -vi.mock('./runner', () => ({ gitExecFileAsync: mocks.git })) +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: mocks.git +})) vi.mock('node:fs/promises', async (importOriginal) => ({ ...(await importOriginal()), readFile: mocks.readFile, diff --git a/src/main/git/worktree-preparation-lock.ts b/src/main/git/worktrees/creation/worktree-preparation-lock.ts similarity index 91% rename from src/main/git/worktree-preparation-lock.ts rename to src/main/git/worktrees/creation/worktree-preparation-lock.ts index 6c93e325a5a..637717395c5 100644 --- a/src/main/git/worktree-preparation-lock.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-lock.ts @@ -1,14 +1,17 @@ import { readFile, unlink, writeFile } from 'node:fs/promises' import { posix, win32 } from 'node:path' -import { isWindowsAbsolutePathLike } from '../../shared/cross-platform-path' -import { resolveGitMetadataPath, type GitMetadataPathOptions } from '../../shared/git-metadata-path' -import { toHostFilesystemPath } from '../filesystem/host-tree-removal' -import { gitExecFileAsync } from './runner' +import { isWindowsAbsolutePathLike } from '../../../../shared/cross-platform-path' +import { + resolveGitMetadataPath, + type GitMetadataPathOptions +} from '../../../../shared/git-metadata-path' +import { toHostFilesystemPath } from '../../../filesystem/host-tree-removal' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' import { getErrorCode, gitExecOptions, type GitWorktreeExecOptions -} from './worktree-operation-options' +} from '../worktree-operation-options' export class WorktreePreparationLockOwnershipError extends Error { constructor(cause?: unknown) { diff --git a/src/main/git/worktree-preparation-tip-refresh-real-git.test.ts b/src/main/git/worktrees/creation/worktree-preparation-tip-refresh-real-git.test.ts similarity index 94% rename from src/main/git/worktree-preparation-tip-refresh-real-git.test.ts rename to src/main/git/worktrees/creation/worktree-preparation-tip-refresh-real-git.test.ts index 90081594108..cc3b9db1b20 100644 --- a/src/main/git/worktree-preparation-tip-refresh-real-git.test.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-tip-refresh-real-git.test.ts @@ -3,8 +3,8 @@ import { mkdir, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promi import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, expect, it, vi } from 'vitest' -import { createWorktreePreparationLockReason } from '../../shared/worktree/create-preparation' -import * as runner from './runner' +import { createWorktreePreparationLockReason } from '../../../../shared/worktree/create-preparation' +import * as runner from '../../command-runner/git-exec-file' import { finalizePreparedWorktree, prepareWorktreeCreateCheckout @@ -15,8 +15,8 @@ import { listPreparations, startPreparation, takePreparation -} from '../workspaces/creation/preparation/worktree-create-preparation-pool' -import { releasePreparationClaim } from '../workspaces/creation/preparation/worktree-create-preparation-claim-registry' +} from '../../../workspaces/creation/preparation/worktree-create-preparation-pool' +import { releasePreparationClaim } from '../../../workspaces/creation/preparation/worktree-create-preparation-claim-registry' const roots: string[] = [] afterEach(async () => { diff --git a/src/main/git/worktree-preparation-tip-refresh.test.ts b/src/main/git/worktrees/creation/worktree-preparation-tip-refresh.test.ts similarity index 90% rename from src/main/git/worktree-preparation-tip-refresh.test.ts rename to src/main/git/worktrees/creation/worktree-preparation-tip-refresh.test.ts index 0e377e1bc77..5570a38fccc 100644 --- a/src/main/git/worktree-preparation-tip-refresh.test.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-tip-refresh.test.ts @@ -7,10 +7,17 @@ const mocks = vi.hoisted(() => ({ mutation: vi.fn(), invalidation: vi.fn() })) -vi.mock('./runner', () => ({ gitExecFileAsync: mocks.git })) -vi.mock('./worktree', () => ({ notifyPreparedWorktreeMutation: mocks.mutation })) -vi.mock('./status', () => ({ runWithGitReadCacheInvalidation: mocks.invalidation })) -vi.mock('./local-repo-ref-maintenance', () => ({ +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: mocks.git +})) +vi.mock('../catalog/worktree-scan-cache', () => ({ + bumpWorktreeScanGeneration: mocks.mutation +})) +vi.mock('../../source-control/git-read-cache-invalidation', () => ({ + runWithGitReadCacheInvalidation: mocks.invalidation +})) +vi.mock('../../refs/maintenance/local-repo-ref-maintenance', () => ({ withRepoRefMaintenancePaused: (_reason: string, run: () => Promise) => run() })) vi.mock('./worktree-preparation-lock', () => ({ diff --git a/src/main/git/worktree-preparation-tip-refresh.ts b/src/main/git/worktrees/creation/worktree-preparation-tip-refresh.ts similarity index 77% rename from src/main/git/worktree-preparation-tip-refresh.ts rename to src/main/git/worktrees/creation/worktree-preparation-tip-refresh.ts index f5f4011e1d2..45c0e328fb4 100644 --- a/src/main/git/worktree-preparation-tip-refresh.ts +++ b/src/main/git/worktrees/creation/worktree-preparation-tip-refresh.ts @@ -1,14 +1,14 @@ -import { windowsLongPathGitArgs } from '../../shared/windows-long-path-git-args' -import { checkoutWorkersGitArgs } from './checkout-workers-git-args' -import { withRepoRefMaintenancePaused } from './local-repo-ref-maintenance' -import { gitExecFileAsync } from './runner' -import { runWithGitReadCacheInvalidation } from './status' -import { notifyPreparedWorktreeMutation } from './worktree' +import { windowsLongPathGitArgs } from '../../../../shared/windows-long-path-git-args' +import { checkoutWorkersGitArgs } from '../../command-runner/checkout-workers-git-args' +import { withRepoRefMaintenancePaused } from '../../refs/maintenance/local-repo-ref-maintenance' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { runWithGitReadCacheInvalidation } from '../../source-control/git-read-cache-invalidation' +import { bumpWorktreeScanGeneration as notifyPreparedWorktreeMutation } from '../catalog/worktree-scan-cache' import { gitExecOptions, resolveWorktreeAddTimeoutMs, type GitWorktreeExecOptions -} from './worktree-operation-options' +} from '../worktree-operation-options' import { verifyWorktreePreparationLock, verifyWorktreePreparationLockAtPath diff --git a/src/main/git/worktree-safety-real-git.test.ts b/src/main/git/worktrees/creation/worktree-safety-real-git.test.ts similarity index 79% rename from src/main/git/worktree-safety-real-git.test.ts rename to src/main/git/worktrees/creation/worktree-safety-real-git.test.ts index c32f546d309..c949a7321ed 100644 --- a/src/main/git/worktree-safety-real-git.test.ts +++ b/src/main/git/worktrees/creation/worktree-safety-real-git.test.ts @@ -4,16 +4,27 @@ import { join } from 'node:path' import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' const { runner } = vi.hoisted(() => ({ runner: vi.fn() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: runner, - gitExecFileSync: vi.fn(), +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: runner +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: vi.fn() +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: (value: string) => value })) -vi.mock('./status', () => ({ runWithGitReadCacheInvalidation: (run: () => unknown) => run() })) +vi.mock('../../source-control/git-read-cache-invalidation', () => ({ + runWithGitReadCacheInvalidation: (run: () => unknown) => run() +})) -import { getBranchConflictKind, getBranchConflictKindViaExec } from './repo-branch-conflict' -import { clearGitCapabilityStateForTests } from './git-capability-state' -import { GitBinaryTestFixture } from '../../shared/git-binary.test-fixture' +import { getBranchConflictKind, getBranchConflictKindViaExec } from '../../repo-branch-conflict' +import { clearGitCapabilityStateForTests } from '../../command-runner/git-capability-state' +import { GitBinaryTestFixture } from '../../../../shared/git-binary.test-fixture' const expectedVersion = process.env.ORCA_GIT_COMPAT_VERSION let fixture: GitBinaryTestFixture diff --git a/src/main/git/worktree-sparse-add.ts b/src/main/git/worktrees/creation/worktree-sparse-add.ts similarity index 85% rename from src/main/git/worktree-sparse-add.ts rename to src/main/git/worktrees/creation/worktree-sparse-add.ts index 3e9229e733f..4dffa3eabe7 100644 --- a/src/main/git/worktree-sparse-add.ts +++ b/src/main/git/worktrees/creation/worktree-sparse-add.ts @@ -1,14 +1,14 @@ -import { windowsLongPathGitArgs } from '../../shared/windows-long-path-git-args' -import { checkoutWorkersGitArgs } from './checkout-workers-git-args' -import { gitExecFileAsync } from './runner' +import { windowsLongPathGitArgs } from '../../../../shared/windows-long-path-git-args' +import { checkoutWorkersGitArgs } from '../../command-runner/checkout-workers-git-args' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' import { addWorktree, unsetWorktreeCreationBase } from './worktree-add' import type { AddWorktreeOptions, AddWorktreeResult, SparseWorktreeCreateError -} from './worktree-operation-options' -import { gitExecOptions } from './worktree-operation-options' -import { removeWorktree } from './worktree-removal' +} from '../worktree-operation-options' +import { gitExecOptions } from '../worktree-operation-options' +import { removeWorktree } from '../removal/worktree-removal' export async function addSparseWorktree( repoPath: string, diff --git a/src/main/git/worktree-move.test.ts b/src/main/git/worktrees/movement/worktree-move.test.ts similarity index 77% rename from src/main/git/worktree-move.test.ts rename to src/main/git/worktrees/movement/worktree-move.test.ts index ccf0113f562..26a47b1e80f 100644 --- a/src/main/git/worktree-move.test.ts +++ b/src/main/git/worktrees/movement/worktree-move.test.ts @@ -12,23 +12,32 @@ const { detectSparseCheckoutMock: vi.fn() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) -vi.mock('./worktree-sparse-state', () => ({ +vi.mock('../sparse-checkout/worktree-sparse-state', () => ({ detectSparseCheckout: detectSparseCheckoutMock, resolveGitCommonDir: vi.fn() })) -import { moveWorktree } from './worktree' -import { registerWorktreeSuiteHooks } from './worktree-test-harness' +import { moveWorktree } from './worktree-move' +import { registerWorktreeSuiteHooks } from '../testing/worktree-test-harness' import { __getSparseCheckoutStateCacheSizeForTests, detectSparseCheckoutCached -} from './worktree-sparse-checkout-cache' +} from '../sparse-checkout/worktree-sparse-checkout-cache' registerWorktreeSuiteHooks() diff --git a/src/main/git/worktree-move.ts b/src/main/git/worktrees/movement/worktree-move.ts similarity index 61% rename from src/main/git/worktree-move.ts rename to src/main/git/worktrees/movement/worktree-move.ts index ad92717b231..7b171f920bc 100644 --- a/src/main/git/worktree-move.ts +++ b/src/main/git/worktrees/movement/worktree-move.ts @@ -1,8 +1,8 @@ -import { gitExecFileAsync } from './runner' -import { runWithGitReadCacheInvalidation } from './status' -import { invalidateWslLinkedWorktreeGitRouting } from './wsl-linked-worktree-git-routing' -import { bumpWorktreeScanGeneration } from './worktree-scan-cache' -import { invalidateSparseCheckoutState } from './worktree-sparse-checkout-cache' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { runWithGitReadCacheInvalidation } from '../../source-control/git-read-cache-invalidation' +import { invalidateWslLinkedWorktreeGitRouting } from '../../command-runner/wsl-linked-worktree-git-routing' +import { bumpWorktreeScanGeneration } from '../catalog/worktree-scan-cache' +import { invalidateSparseCheckoutState } from '../sparse-checkout/worktree-sparse-checkout-cache' /** Git repairs marker back-pointers during a move; callers migrate Orca identity and check the destination. */ export async function moveWorktree( diff --git a/src/main/git/worktree-mutation-route-invalidation.test.ts b/src/main/git/worktrees/movement/worktree-mutation-route-invalidation.test.ts similarity index 80% rename from src/main/git/worktree-mutation-route-invalidation.test.ts rename to src/main/git/worktrees/movement/worktree-mutation-route-invalidation.test.ts index 4520ac44224..e8016852f73 100644 --- a/src/main/git/worktree-mutation-route-invalidation.test.ts +++ b/src/main/git/worktrees/movement/worktree-mutation-route-invalidation.test.ts @@ -1,7 +1,7 @@ // Worktree add/move/remove/rollback rewrite the `.git` marker the WSL Git route was derived from. import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import type * as WorktreeModule from './worktree' -import type * as WorktreePreparationLock from './worktree-preparation-lock' + +import type * as WorktreePreparationLock from '../creation/worktree-preparation-lock' const { gitExecFileAsyncMock, @@ -15,34 +15,47 @@ const { listWorktreesMock: vi.fn() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) // Keep the ordered runner queues; worktree-checkout-progress-real-git covers the checkout.workers read. -vi.mock('./checkout-workers-git-args', () => ({ checkoutWorkersGitArgs: async () => [] })) +vi.mock('../../command-runner/checkout-workers-git-args', () => ({ + checkoutWorkersGitArgs: async () => [] +})) -vi.mock('./status', () => ({ - resolveGitDir: vi.fn(), +vi.mock('../../source-control/resolve-git-dir', () => ({ + resolveGitDir: vi.fn() +})) + +vi.mock('../../source-control/git-read-cache-invalidation', () => ({ runWithGitReadCacheInvalidation: (run: () => Promise) => run() })) -vi.mock('./worktree', async (importOriginal) => ({ - ...(await importOriginal()), +vi.mock('../creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), resolveWorktreeAddBaseContext: vi.fn(async () => ({ effectiveBase: 'origin/main' })), persistWorktreeCreationBase: vi.fn(), - configurePushAutoSetupRemote: vi.fn(), - notifyPreparedWorktreeMutation: vi.fn() + configurePushAutoSetupRemote: vi.fn() })) -vi.mock('./worktree-scan-cache', () => ({ +vi.mock('../catalog/worktree-scan-cache', () => ({ bumpWorktreeScanGeneration: vi.fn(), listWorktrees: listWorktreesMock })) -vi.mock('./worktree-preparation-lock', async (importOriginal) => ({ +vi.mock('../creation/worktree-preparation-lock', async (importOriginal) => ({ ...(await importOriginal()), lockWorktreePreparation: vi.fn(async () => '/owned-lock'), verifyWorktreePreparationLock: vi.fn(async () => '/owned-lock'), @@ -50,19 +63,19 @@ vi.mock('./worktree-preparation-lock', async (importOriginal) => ({ unlockWorktreePreparationAtPath: vi.fn() })) -import { addWorktree } from './worktree-add' +import { addWorktree } from '../creation/worktree-add' import { discardPreparedWorktree, finalizePreparedWorktree, prepareWorktreeCreateCheckout -} from './worktree-create-preparation' +} from '../creation/worktree-create-preparation' import { moveWorktree } from './worktree-move' -import { removeWorktree } from './worktree-removal' +import { removeWorktree } from '../removal/worktree-removal' import { resetWslLinkedWorktreeGitRoutingForTests, seedWslLinkedWorktreeGitRoutingForTests, usesHostGitForWslLinkedWorktree -} from './wsl-linked-worktree-git-routing' +} from '../../command-runner/wsl-linked-worktree-git-routing' const REPO = String.raw`C:\repo` const LINKED = String.raw`C:\ws\linked` diff --git a/src/main/git/remove-worktree-branch-cleanup.test.ts b/src/main/git/worktrees/removal/remove-worktree-branch-cleanup.test.ts similarity index 94% rename from src/main/git/remove-worktree-branch-cleanup.test.ts rename to src/main/git/worktrees/removal/remove-worktree-branch-cleanup.test.ts index f339d4de7bf..726cca0bd63 100644 --- a/src/main/git/remove-worktree-branch-cleanup.test.ts +++ b/src/main/git/worktrees/removal/remove-worktree-branch-cleanup.test.ts @@ -1,5 +1,5 @@ // Ref mutation tests use fictitious repositories; administrative reservations have real-Git coverage. -vi.mock('../../shared/git-worktree-admin', () => ({ +vi.mock('../../../../shared/git-worktree-admin', () => ({ isBranchReservedByWorktreeOperation: vi.fn().mockResolvedValue(false) })) @@ -22,14 +22,26 @@ const { resolveGitDirMock: vi.fn() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) -vi.mock('./status', () => ({ - resolveGitDir: resolveGitDirMock, +vi.mock('../../source-control/resolve-git-dir', () => ({ + resolveGitDir: resolveGitDirMock +})) + +vi.mock('../../source-control/git-read-cache-invalidation', () => ({ runWithGitReadCacheInvalidation: (run: () => Promise) => run() })) @@ -46,7 +58,8 @@ import { resetWorktreeRemovalState } from './remove-worktree-test-harness' -import { forceDeleteLocalBranch, removeWorktree } from './worktree' +import { forceDeleteLocalBranch } from './worktree-branch-removal' +import { removeWorktree } from './worktree-removal' const mockGitCommands = createGitCommandMocker(gitExecFileAsyncMock) const getGitCalls = createGitCallReader(gitExecFileAsyncMock) diff --git a/src/main/git/remove-worktree-clean-preflight.test.ts b/src/main/git/worktrees/removal/remove-worktree-clean-preflight.test.ts similarity index 73% rename from src/main/git/remove-worktree-clean-preflight.test.ts rename to src/main/git/worktrees/removal/remove-worktree-clean-preflight.test.ts index d14d46bc71f..dda7218a1d7 100644 --- a/src/main/git/remove-worktree-clean-preflight.test.ts +++ b/src/main/git/worktrees/removal/remove-worktree-clean-preflight.test.ts @@ -17,14 +17,26 @@ const { resolveGitDirMock: vi.fn() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) -vi.mock('./status', () => ({ - resolveGitDir: resolveGitDirMock, +vi.mock('../../source-control/resolve-git-dir', () => ({ + resolveGitDir: resolveGitDirMock +})) + +vi.mock('../../source-control/git-read-cache-invalidation', () => ({ runWithGitReadCacheInvalidation: (run: () => Promise) => run() })) @@ -35,7 +47,8 @@ vi.mock('fs/promises', async () => { import { resetWorktreeRemovalState } from './remove-worktree-test-harness' -import { assertWorktreeCleanForRemoval, WORKTREE_REMOVAL_PREFLIGHT_TIMEOUT_MS } from './worktree' +import { assertWorktreeCleanForRemoval } from './worktree-removal-preflight' +import { WORKTREE_REMOVAL_PREFLIGHT_TIMEOUT_MS } from '../worktree-operation-options' beforeEach(() => { resetWorktreeRemovalState() diff --git a/src/main/git/remove-worktree-test-harness.ts b/src/main/git/worktrees/removal/remove-worktree-test-harness.ts similarity index 92% rename from src/main/git/remove-worktree-test-harness.ts rename to src/main/git/worktrees/removal/remove-worktree-test-harness.ts index 3977c82e69c..f6163547587 100644 --- a/src/main/git/remove-worktree-test-harness.ts +++ b/src/main/git/worktrees/removal/remove-worktree-test-harness.ts @@ -1,8 +1,8 @@ import { expect, type Mock } from 'vitest' -import { clearGitCapabilityStateForTests } from './git-capability-state' -import { _resetWorktreeScanCacheForTests } from './worktree' -import { __resetSparseCheckoutStateCacheForTests } from './worktree-sparse-checkout-cache' +import { clearGitCapabilityStateForTests } from '../../command-runner/git-capability-state' +import { _resetWorktreeScanCacheForTests } from '../catalog/worktree-scan-cache' +import { __resetSparseCheckoutStateCacheForTests } from '../sparse-checkout/worktree-sparse-checkout-cache' export type MockResult = { error?: Error diff --git a/src/main/git/remove-worktree.test.ts b/src/main/git/worktrees/removal/remove-worktree.test.ts similarity index 95% rename from src/main/git/remove-worktree.test.ts rename to src/main/git/worktrees/removal/remove-worktree.test.ts index cd75f91058d..9c3de8b0565 100644 --- a/src/main/git/remove-worktree.test.ts +++ b/src/main/git/worktrees/removal/remove-worktree.test.ts @@ -21,14 +21,26 @@ const { resolveGitDirMock: vi.fn() })) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) -vi.mock('./status', () => ({ - resolveGitDir: resolveGitDirMock, +vi.mock('../../source-control/resolve-git-dir', () => ({ + resolveGitDir: resolveGitDirMock +})) + +vi.mock('../../source-control/git-read-cache-invalidation', () => ({ runWithGitReadCacheInvalidation: (run: () => Promise) => run() })) @@ -45,11 +57,11 @@ import { resetWorktreeRemovalState } from './remove-worktree-test-harness' -import { removeWorktree } from './worktree' +import { removeWorktree } from './worktree-removal' import { __getSparseCheckoutStateCacheSizeForTests, detectSparseCheckoutCached -} from './worktree-sparse-checkout-cache' +} from '../sparse-checkout/worktree-sparse-checkout-cache' const mockGitCommands = createGitCommandMocker(gitExecFileAsyncMock) const getGitCalls = createGitCallReader(gitExecFileAsyncMock) diff --git a/src/main/git/windows-worktree-removal.ts b/src/main/git/worktrees/removal/windows-worktree-removal.ts similarity index 88% rename from src/main/git/windows-worktree-removal.ts rename to src/main/git/worktrees/removal/windows-worktree-removal.ts index 78420b1c409..0a440a0b5fe 100644 --- a/src/main/git/windows-worktree-removal.ts +++ b/src/main/git/worktrees/removal/windows-worktree-removal.ts @@ -1,23 +1,23 @@ import { join, resolve } from 'node:path' import { readFile } from 'node:fs/promises' -import { lstat, readdir } from '../filesystem/asar-transparent-fs' -import { removeHostCheckout } from '../filesystem/host-tree-removal' -import { parseWslPath } from '../wsl/filesystem/unc-path-access' -import { CLIENT_REMOVAL_HOME } from '../workspaces/removal/worktree-removal-home-guard' +import { lstat, readdir } from '../../../filesystem/asar-transparent-fs' +import { removeHostCheckout } from '../../../filesystem/host-tree-removal' +import { parseWslPath } from '../../../wsl/filesystem/unc-path-access' +import { CLIENT_REMOVAL_HOME } from '../../../workspaces/removal/worktree-removal-home-guard' import { assertWorktreeUnlockedForRemoval, unregisteredFolderRefusal -} from '../../shared/worktree/removal' +} from '../../../../shared/worktree/removal' import { assertWorktreeDoesNotContainRegisteredWorktree, canSafelyRemoveOrphanedWorktreeDirectory, findRegisteredDeletableWorktree, isDangerousWorktreeRemovalPath, ORPHANED_WORKTREE_DIRECTORY_MESSAGE -} from '../workspaces/removal/worktree-removal-safety' -import { readTranslatedWorktreeGraph } from './worktree-list-reader' +} from '../../../workspaces/removal/worktree-removal-safety' +import { readTranslatedWorktreeGraph } from '../catalog/worktree-list-reader' import { assertWorktreeCleanForRemoval } from './worktree-removal-preflight' -import { getErrorCode, type RemoveWorktreeOptions } from './worktree-operation-options' +import { getErrorCode, type RemoveWorktreeOptions } from '../worktree-operation-options' export function usesNativeWindowsRemoval(path: string, options: { wslDistro?: string }): boolean { return process.platform === 'win32' && !options.wslDistro && !parseWslPath(path) diff --git a/src/main/git/worktree-branch-removal.ts b/src/main/git/worktrees/removal/worktree-branch-removal.ts similarity index 88% rename from src/main/git/worktree-branch-removal.ts rename to src/main/git/worktrees/removal/worktree-branch-removal.ts index 3710eee95df..776bd07bcff 100644 --- a/src/main/git/worktree-branch-removal.ts +++ b/src/main/git/worktrees/removal/worktree-branch-removal.ts @@ -3,17 +3,17 @@ import { branchHasNoUnmergedChangesWithLazyTargetRefresh, getBranchCleanupTargetRefs, type GitBranchCleanupExecOptions -} from '../../shared/git-branch-cleanup' -import type { RemoveWorktreeResult } from '../../shared/worktree/create-types' -import { withLocalGitCapabilityCacheForExecution } from './git-capability-state' -import { withRepoRefMaintenancePaused } from './local-repo-ref-maintenance' -import { gitExecFileAsync } from './runner' -import { createLocalGitObjectQuarantine } from './local-git-object-quarantine' -import { isBranchReservedByWorktreeOperation } from '../../shared/git-worktree-admin' -import { parseWorktreeList } from '../../shared/git-worktree-porcelain-parser' -import { isBranchCheckedOutInWorktreeError } from '../../shared/git-branch-delete-refusal' -import type { GitWorktreeExecOptions, RemoveWorktreeOptions } from './worktree-operation-options' -import { gitExecOptions, normalizeLocalBranchRef } from './worktree-operation-options' +} from '../../../../shared/git-branch-cleanup' +import type { RemoveWorktreeResult } from '../../../../shared/worktree/create-types' +import { withLocalGitCapabilityCacheForExecution } from '../../command-runner/git-capability-state' +import { withRepoRefMaintenancePaused } from '../../refs/maintenance/local-repo-ref-maintenance' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { createLocalGitObjectQuarantine } from '../../local-git-object-quarantine' +import { isBranchReservedByWorktreeOperation } from '../../../../shared/git-worktree-admin' +import { parseWorktreeList } from '../../../../shared/git-worktree-porcelain-parser' +import { isBranchCheckedOutInWorktreeError } from '../../../../shared/git-branch-delete-refusal' +import type { GitWorktreeExecOptions, RemoveWorktreeOptions } from '../worktree-operation-options' +import { gitExecOptions, normalizeLocalBranchRef } from '../worktree-operation-options' export async function deleteBranchAfterWorktreeRemoval( repoPath: string, diff --git a/src/main/git/worktree-delete-limit.test.ts b/src/main/git/worktrees/removal/worktree-delete-limit.test.ts similarity index 100% rename from src/main/git/worktree-delete-limit.test.ts rename to src/main/git/worktrees/removal/worktree-delete-limit.test.ts diff --git a/src/main/git/worktree-delete-limit.ts b/src/main/git/worktrees/removal/worktree-delete-limit.ts similarity index 100% rename from src/main/git/worktree-delete-limit.ts rename to src/main/git/worktrees/removal/worktree-delete-limit.ts diff --git a/src/main/git/worktree-posix-path-case-sensitivity.test.ts b/src/main/git/worktrees/removal/worktree-posix-path-case-sensitivity.test.ts similarity index 87% rename from src/main/git/worktree-posix-path-case-sensitivity.test.ts rename to src/main/git/worktrees/removal/worktree-posix-path-case-sensitivity.test.ts index d66ea4d2fab..4b0cd818d91 100644 --- a/src/main/git/worktree-posix-path-case-sensitivity.test.ts +++ b/src/main/git/worktrees/removal/worktree-posix-path-case-sensitivity.test.ts @@ -1,7 +1,6 @@ // Exercise the real Linux-to-UNC translator: an identity mock would hide ext4-tail case folding. import type * as FsPromises from 'node:fs/promises' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import type * as WslPathTranslation from './command-runner/wsl-path-translation' const { gitExecFileAsyncMock, gitExecFileSyncMock, statMock, readFileMock, resolveGitDirMock } = vi.hoisted(() => ({ @@ -12,19 +11,20 @@ const { gitExecFileAsyncMock, gitExecFileSyncMock, statMock, readFileMock, resol resolveGitDirMock: vi.fn() })) -vi.mock('./runner', async () => { - const translation = await vi.importActual( - './command-runner/wsl-path-translation' - ) - return { - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, - translateWslOutputPaths: translation.translateWslOutputPaths - } -}) +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) -vi.mock('./status', () => ({ - resolveGitDir: resolveGitDirMock, +vi.mock('../../source-control/resolve-git-dir', () => ({ + resolveGitDir: resolveGitDirMock +})) + +vi.mock('../../source-control/git-read-cache-invalidation', () => ({ runWithGitReadCacheInvalidation: (run: () => Promise) => run() })) @@ -38,8 +38,8 @@ import { createGitCommandMocker, resetWorktreeRemovalState } from './remove-worktree-test-harness' -import { areWorktreePathsEqual } from './worktree-path-comparison' -import { removeWorktree } from './worktree' +import { areWorktreePathsEqual } from '../catalog/worktree-path-comparison' +import { removeWorktree } from './worktree-removal' const mockGitCommands = createGitCommandMocker(gitExecFileAsyncMock) const getGitCalls = createGitCallReader(gitExecFileAsyncMock) diff --git a/src/main/git/worktree-prune-guard.test.ts b/src/main/git/worktrees/removal/worktree-prune-guard.test.ts similarity index 93% rename from src/main/git/worktree-prune-guard.test.ts rename to src/main/git/worktrees/removal/worktree-prune-guard.test.ts index c9253a62f89..6cd92f94f2d 100644 --- a/src/main/git/worktree-prune-guard.test.ts +++ b/src/main/git/worktrees/removal/worktree-prune-guard.test.ts @@ -25,15 +25,19 @@ const git = vi.hoisted(() => { return { recordLocksAtPrune, mock: vi.fn(recordLocksAtPrune) } }) const gitExecFileAsyncMock = git.mock -vi.mock('./runner', () => ({ gitExecFileAsync: git.mock })) +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: git.mock +})) const wslDistroForCommandMock = vi.hoisted(() => vi.fn((): string | null => null)) -vi.mock('./command-runner/git-command-resolution', () => ({ +vi.mock('../../../../shared/wsl-paths', async (importOriginal) => ({ + ...(await importOriginal>()), wslDistroForCommand: wslDistroForCommandMock })) -vi.mock('./wsl-linked-worktree-git-routing', () => ({ +vi.mock('../../command-runner/wsl-linked-worktree-git-routing', () => ({ usesHostGitForWslLinkedWorktree: () => false })) -vi.mock('./wsl-drive-checkout-git-routing', () => ({ +vi.mock('../../wsl-drive-checkout-git-routing', () => ({ pendingWslDriveCheckoutGitRouting: () => null })) diff --git a/src/main/git/worktree-prune-guard.ts b/src/main/git/worktrees/removal/worktree-prune-guard.ts similarity index 91% rename from src/main/git/worktree-prune-guard.ts rename to src/main/git/worktrees/removal/worktree-prune-guard.ts index 0768cc3949b..10696a93e71 100644 --- a/src/main/git/worktree-prune-guard.ts +++ b/src/main/git/worktrees/removal/worktree-prune-guard.ts @@ -4,13 +4,13 @@ import { isAbsolute, join } from 'node:path' import { isDrvfsLinuxPath, toWindowsWslDrivePath, - toWindowsWslUncPath -} from '../../shared/wsl-paths' -import type { GitExecOptions } from './command-runner/git-exec-options' -import { wslDistroForCommand } from './command-runner/git-command-resolution' -import { gitExecFileAsync } from './runner' -import { pendingWslDriveCheckoutGitRouting } from './wsl-drive-checkout-git-routing' -import { usesHostGitForWslLinkedWorktree } from './wsl-linked-worktree-git-routing' + toWindowsWslUncPath, + wslDistroForCommand +} from '../../../../shared/wsl-paths' +import type { GitExecOptions } from '../../command-runner/git-exec-options' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { pendingWslDriveCheckoutGitRouting } from '../../wsl-drive-checkout-git-routing' +import { usesHostGitForWslLinkedWorktree } from '../../command-runner/wsl-linked-worktree-git-routing' /** Marks only the locks this module writes, so it never removes a user's own lock. */ export const PRUNE_GUARD_LOCK_REASON = diff --git a/src/main/git/worktree-rebase-update-refs-real-git.test.ts b/src/main/git/worktrees/removal/worktree-rebase-update-refs-real-git.test.ts similarity index 88% rename from src/main/git/worktree-rebase-update-refs-real-git.test.ts rename to src/main/git/worktrees/removal/worktree-rebase-update-refs-real-git.test.ts index c655836f415..c1d7803f3d6 100644 --- a/src/main/git/worktree-rebase-update-refs-real-git.test.ts +++ b/src/main/git/worktrees/removal/worktree-rebase-update-refs-real-git.test.ts @@ -2,10 +2,18 @@ import { mkdir, mkdtemp, readFile, realpath, rm, writeFile } from 'node:fs/promi import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import { GitBinaryTestFixture } from '../../shared/git-binary.test-fixture' +import { GitBinaryTestFixture } from '../../../../shared/git-binary.test-fixture' -vi.mock('./runner', () => ({ gitExecFileAsync: vi.fn(), gitExecFileSync: vi.fn() })) -vi.mock('./local-repo-ref-maintenance', () => ({ +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: vi.fn() +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: vi.fn() +})) +vi.mock('../../refs/maintenance/local-repo-ref-maintenance', () => ({ withRepoRefMaintenancePaused: (_reason: string, run: () => unknown) => run() })) diff --git a/src/main/git/worktree-removal-large-tree.bench.test.ts b/src/main/git/worktrees/removal/worktree-removal-large-tree.bench.test.ts similarity index 95% rename from src/main/git/worktree-removal-large-tree.bench.test.ts rename to src/main/git/worktrees/removal/worktree-removal-large-tree.bench.test.ts index 10a791bd6ec..0c3187a0755 100644 --- a/src/main/git/worktree-removal-large-tree.bench.test.ts +++ b/src/main/git/worktrees/removal/worktree-removal-large-tree.bench.test.ts @@ -1,5 +1,5 @@ -import { installRealWorkerThreadChildProcesses } from '../worker-thread-child-process/worker-thread-child-process-real.test-fixtures' -// Opt in (~100k files): ORCA_WORKTREE_REMOVAL_BENCH=1 pnpm test src/main/git/worktree-removal-large-tree.bench.test.ts +import { installRealWorkerThreadChildProcesses } from '../../../worker-thread-child-process/worker-thread-child-process-real.test-fixtures' +// Opt in (~100k files): ORCA_WORKTREE_REMOVAL_BENCH=1 pnpm test src/main/git/worktrees/removal/worktree-removal-large-tree.bench.test.ts import { execFile } from 'node:child_process' import { appendFileSync, existsSync, statSync } from 'node:fs' import { link, mkdir, mkdtemp, open, readFile, rename, rm, writeFile } from 'node:fs/promises' @@ -8,7 +8,7 @@ import { join } from 'node:path' import { performance } from 'node:perf_hooks' import { promisify } from 'node:util' import { afterAll, beforeAll, describe, expect, it } from 'vitest' -import { removeWorktree } from './worktree' +import { removeWorktree } from './worktree-removal' const execFileAsync = promisify(execFile) const describeBench = process.env.ORCA_WORKTREE_REMOVAL_BENCH ? describe : describe.skip diff --git a/src/main/git/worktree-removal-preflight.ts b/src/main/git/worktrees/removal/worktree-removal-preflight.ts similarity index 88% rename from src/main/git/worktree-removal-preflight.ts rename to src/main/git/worktrees/removal/worktree-removal-preflight.ts index 15c73778f98..4d4cf74da51 100644 --- a/src/main/git/worktree-removal-preflight.ts +++ b/src/main/git/worktrees/removal/worktree-removal-preflight.ts @@ -1,14 +1,17 @@ import { join } from 'node:path' -import { resolveWorktreeHostPath } from '../../shared/git-metadata-path' -import { isWorktreePathMissing } from '../workspaces/removal/worktree-removal-safety' +import { resolveWorktreeHostPath } from '../../../../shared/git-metadata-path' +import { isWorktreePathMissing } from '../../../workspaces/removal/worktree-removal-safety' import { SUBMODULE_DIRTY_REMOVAL_DETAIL, SUBMODULE_REMOVAL_REFUSAL -} from '../../shared/worktree/removal' -import { gitExecFileAsync } from './runner' -import { resolveGitDir } from './source-control/resolve-git-dir' -import type { WorktreeRemovalPreflightOptions } from './worktree-operation-options' -import { WORKTREE_REMOVAL_PREFLIGHT_TIMEOUT_MS, gitExecOptions } from './worktree-operation-options' +} from '../../../../shared/worktree/removal' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { resolveGitDir } from '../../source-control/resolve-git-dir' +import type { WorktreeRemovalPreflightOptions } from '../worktree-operation-options' +import { + WORKTREE_REMOVAL_PREFLIGHT_TIMEOUT_MS, + gitExecOptions +} from '../worktree-operation-options' export async function assertWorktreeCleanForRemoval( worktreePath: string, diff --git a/src/main/git/worktree-removal-real-git.test.ts b/src/main/git/worktrees/removal/worktree-removal-real-git.test.ts similarity index 94% rename from src/main/git/worktree-removal-real-git.test.ts rename to src/main/git/worktrees/removal/worktree-removal-real-git.test.ts index 238a4deb337..069eec1cb99 100644 --- a/src/main/git/worktree-removal-real-git.test.ts +++ b/src/main/git/worktrees/removal/worktree-removal-real-git.test.ts @@ -7,27 +7,29 @@ import { join } from 'node:path' import { performance } from 'node:perf_hooks' import { promisify } from 'node:util' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import * as nativeFs from '../filesystem/asar-transparent-fs' +import * as nativeFs from '../../../filesystem/asar-transparent-fs' import * as diskFs from 'node:fs/promises' -import * as runner from './runner' +import * as runner from '../../command-runner/git-exec-file' import { runUnderWorktreeDeleteLimit, _worktreeDeleteLimitSnapshotForTests } from './worktree-delete-limit' -import { installRealWorkerThreadChildProcesses } from '../worker-thread-child-process/worker-thread-child-process-real.test-fixtures' -import { removeTree } from '../../shared/windows-transient-lock-removal' -import { canSafelyRemoveOrphanedWorktreeDirectory } from '../workspaces/removal/worktree-removal-safety' -import { CLIENT_REMOVAL_HOME } from '../workspaces/removal/worktree-removal-home-guard' -import { classifyWorktreeForceDeleteReason } from '../../shared/worktree/removal' -import { formatWorktreeRemovalError } from '../ipc/worktree-logic' -import { assertWorktreeCleanForRemoval, listWorktreesStrict, removeWorktree } from './worktree' -import { areWorktreePathsEqual } from './worktree-path-comparison' -import { isPrunableGitFileWorktree } from '../workspaces/removal/worktree-prunable-git-file' -import { removeStaleLocalWorktreeRegistration } from '../workspaces/removal/local-worktree-removal-recovery' +import { installRealWorkerThreadChildProcesses } from '../../../worker-thread-child-process/worker-thread-child-process-real.test-fixtures' +import { removeTree } from '../../../../shared/windows-transient-lock-removal' +import { canSafelyRemoveOrphanedWorktreeDirectory } from '../../../workspaces/removal/worktree-removal-safety' +import { CLIENT_REMOVAL_HOME } from '../../../workspaces/removal/worktree-removal-home-guard' +import { classifyWorktreeForceDeleteReason } from '../../../../shared/worktree/removal' +import { formatWorktreeRemovalError } from '../../../ipc/worktree-logic' +import { assertWorktreeCleanForRemoval } from './worktree-removal-preflight' +import { listWorktreesStrict } from '../catalog/worktree-listing' +import { removeWorktree } from './worktree-removal' +import { areWorktreePathsEqual } from '../catalog/worktree-path-comparison' +import { isPrunableGitFileWorktree } from '../../../workspaces/removal/worktree-prunable-git-file' +import { removeStaleLocalWorktreeRegistration } from '../../../workspaces/removal/local-worktree-removal-recovery' import { sweepStaleWorktreeTrash, WORKTREE_TRASH_DIR_NAME -} from '../workspaces/removal/worktree-trash' +} from '../../../workspaces/removal/worktree-trash' const execFileAsync = promisify(execFile) diff --git a/src/main/git/worktree-removal.ts b/src/main/git/worktrees/removal/worktree-removal.ts similarity index 82% rename from src/main/git/worktree-removal.ts rename to src/main/git/worktrees/removal/worktree-removal.ts index 94d08c2441a..2138d87e52e 100644 --- a/src/main/git/worktree-removal.ts +++ b/src/main/git/worktrees/removal/worktree-removal.ts @@ -1,26 +1,30 @@ import { lstat } from 'node:fs/promises' import { pruneGitWorktrees } from './worktree-prune-guard' -import type { RemoveWorktreeResult } from '../../shared/worktree/create-types' -import { assertWorktreeUnlockedForRemoval } from '../../shared/worktree/removal' -import { windowsLongPathGitArgs } from '../../shared/windows-long-path-git-args' -import { removeHostTree } from '../filesystem/host-tree-removal' -import { withSpan } from '../observability/tracer' -import { parseWslPath } from '../wsl/filesystem/unc-path-access' -import { gitExecFileAsync } from './runner' -import { runWithGitReadCacheInvalidation } from './status' +import type { RemoveWorktreeResult } from '../../../../shared/worktree/create-types' +import { assertWorktreeUnlockedForRemoval } from '../../../../shared/worktree/removal' +import { windowsLongPathGitArgs } from '../../../../shared/windows-long-path-git-args' +import { removeHostTree } from '../../../filesystem/host-tree-removal' +import { withSpan } from '../../../observability/tracer' +import { parseWslPath } from '../../../wsl/filesystem/unc-path-access' +import { gitExecFileAsync } from '../../command-runner/git-exec-file' +import { runWithGitReadCacheInvalidation } from '../../source-control/git-read-cache-invalidation' import { deleteBranchAfterWorktreeRemoval } from './worktree-branch-removal' -import { invalidateWslLinkedWorktreeGitRouting } from './wsl-linked-worktree-git-routing' -import type { RemoveWorktreeOptions } from './worktree-operation-options' -import { getErrorCode, gitExecOptions, normalizeLocalBranchRef } from './worktree-operation-options' -import { areWorktreePathsEqual } from './worktree-path-comparison' -import { withRepoRefMaintenancePaused } from './local-repo-ref-maintenance' -import { bumpWorktreeScanGeneration, listWorktrees } from './worktree-scan-cache' -import { invalidateSparseCheckoutState } from './worktree-sparse-checkout-cache' +import { invalidateWslLinkedWorktreeGitRouting } from '../../command-runner/wsl-linked-worktree-git-routing' +import type { RemoveWorktreeOptions } from '../worktree-operation-options' +import { + getErrorCode, + gitExecOptions, + normalizeLocalBranchRef +} from '../worktree-operation-options' +import { areWorktreePathsEqual } from '../catalog/worktree-path-comparison' +import { withRepoRefMaintenancePaused } from '../../refs/maintenance/local-repo-ref-maintenance' +import { bumpWorktreeScanGeneration, listWorktrees } from '../catalog/worktree-scan-cache' +import { invalidateSparseCheckoutState } from '../sparse-checkout/worktree-sparse-checkout-cache' import { runUnderWorktreeDeleteLimit } from './worktree-delete-limit' import { removeWindowsCheckout, usesNativeWindowsRemoval } from './windows-worktree-removal' -import { listWorktreesStrict } from './worktree-listing' -import { isWorktreePathMissing } from '../workspaces/removal/worktree-removal-safety' -import { runKeyedSerializedOperation } from '../cli/keyed-promise-queue' +import { listWorktreesStrict } from '../catalog/worktree-listing' +import { isWorktreePathMissing } from '../../../workspaces/removal/worktree-removal-safety' +import { runKeyedSerializedOperation } from '../../../cli/keyed-promise-queue' const branchCleanupQueueByRepo = new Map>() diff --git a/src/main/git/worktree-remove-branch-deletion.test.ts b/src/main/git/worktrees/removal/worktree-remove-branch-deletion.test.ts similarity index 85% rename from src/main/git/worktree-remove-branch-deletion.test.ts rename to src/main/git/worktrees/removal/worktree-remove-branch-deletion.test.ts index b908c100e46..c2f90bba427 100644 --- a/src/main/git/worktree-remove-branch-deletion.test.ts +++ b/src/main/git/worktrees/removal/worktree-remove-branch-deletion.test.ts @@ -8,14 +8,23 @@ const { gitExecFileAsyncMock, gitExecFileSyncMock, translateWslOutputPathsMock } }) ) -vi.mock('./runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - gitExecFileSync: gitExecFileSyncMock, +vi.mock('../../command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../../command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: gitExecFileSyncMock +})) + +vi.mock('../../command-runner/wsl-path-translation', async (importOriginal) => ({ + ...(await importOriginal>()), translateWslOutputPaths: translateWslOutputPathsMock })) -import { removeWorktree } from './worktree' -import { registerWorktreeSuiteHooks } from './worktree-test-harness' +import { removeWorktree } from './worktree-removal' +import { registerWorktreeSuiteHooks } from '../testing/worktree-test-harness' registerWorktreeSuiteHooks() diff --git a/src/main/git/worktree-sparse-checkout-cache.test.ts b/src/main/git/worktrees/sparse-checkout/worktree-sparse-checkout-cache.test.ts similarity index 100% rename from src/main/git/worktree-sparse-checkout-cache.test.ts rename to src/main/git/worktrees/sparse-checkout/worktree-sparse-checkout-cache.test.ts diff --git a/src/main/git/worktree-sparse-checkout-cache.ts b/src/main/git/worktrees/sparse-checkout/worktree-sparse-checkout-cache.ts similarity index 97% rename from src/main/git/worktree-sparse-checkout-cache.ts rename to src/main/git/worktrees/sparse-checkout/worktree-sparse-checkout-cache.ts index b8453dbc0d5..4219b67253b 100644 --- a/src/main/git/worktree-sparse-checkout-cache.ts +++ b/src/main/git/worktrees/sparse-checkout/worktree-sparse-checkout-cache.ts @@ -1,5 +1,5 @@ -import type { GitRuntimeOptions } from './git-runtime-options' -import { canonicalWorktreePath } from './worktree-path-comparison' +import type { GitRuntimeOptions } from '../../git-runtime-options' +import { canonicalWorktreePath } from '../catalog/worktree-path-comparison' import { detectSparseCheckout } from './worktree-sparse-state' // Cache filesystem sparse probes; mutations and config.worktree changes invalidate entries. diff --git a/src/main/git/worktree-sparse-checkout.test.ts b/src/main/git/worktrees/sparse-checkout/worktree-sparse-checkout.test.ts similarity index 96% rename from src/main/git/worktree-sparse-checkout.test.ts rename to src/main/git/worktrees/sparse-checkout/worktree-sparse-checkout.test.ts index f428063f5d3..a720e4877a3 100644 --- a/src/main/git/worktree-sparse-checkout.test.ts +++ b/src/main/git/worktrees/sparse-checkout/worktree-sparse-checkout.test.ts @@ -1,10 +1,12 @@ -import { installRealWorkerThreadChildProcesses } from '../worker-thread-child-process/worker-thread-child-process-real.test-fixtures' +import { installRealWorkerThreadChildProcesses } from '../../../worker-thread-child-process/worker-thread-child-process-real.test-fixtures' import { execFileSync } from 'node:child_process' import { mkdtemp, mkdir, realpath, rm, stat, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import * as path from 'node:path' import { afterEach, describe, expect, it } from 'vitest' -import { listWorktrees, parseCoreSparseCheckoutFlag, removeWorktree } from './worktree' +import { listWorktrees } from '../catalog/worktree-scan-cache' +import { parseCoreSparseCheckoutFlag } from './worktree-sparse-state' +import { removeWorktree } from '../removal/worktree-removal' const tempRoots: string[] = [] diff --git a/src/main/git/worktree-sparse-state-host-paths.test.ts b/src/main/git/worktrees/sparse-checkout/worktree-sparse-state-host-paths.test.ts similarity index 100% rename from src/main/git/worktree-sparse-state-host-paths.test.ts rename to src/main/git/worktrees/sparse-checkout/worktree-sparse-state-host-paths.test.ts diff --git a/src/main/git/worktree-sparse-state.ts b/src/main/git/worktrees/sparse-checkout/worktree-sparse-state.ts similarity index 96% rename from src/main/git/worktree-sparse-state.ts rename to src/main/git/worktrees/sparse-checkout/worktree-sparse-state.ts index ed6aeca07f2..08f98d16e92 100644 --- a/src/main/git/worktree-sparse-state.ts +++ b/src/main/git/worktrees/sparse-checkout/worktree-sparse-state.ts @@ -1,7 +1,7 @@ import { readFile, stat } from 'node:fs/promises' import { isAbsolute, join, resolve } from 'node:path' -import type { GitRuntimeOptions } from './git-runtime-options' -import { resolveGitDir } from './status' +import type { GitRuntimeOptions } from '../../git-runtime-options' +import { resolveGitDir } from '../../source-control/resolve-git-dir' export async function detectSparseCheckout( worktreePath: string, diff --git a/src/main/git/worktree-test-harness.ts b/src/main/git/worktrees/testing/worktree-test-harness.ts similarity index 67% rename from src/main/git/worktree-test-harness.ts rename to src/main/git/worktrees/testing/worktree-test-harness.ts index e202f2434ae..9c00fc06739 100644 --- a/src/main/git/worktree-test-harness.ts +++ b/src/main/git/worktrees/testing/worktree-test-harness.ts @@ -1,7 +1,7 @@ import { afterEach, beforeEach, vi } from 'vitest' -import { clearGitCapabilityStateForTests } from './git-capability-state' -import { __resetSparseCheckoutStateCacheForTests } from './worktree-sparse-checkout-cache' +import { clearGitCapabilityStateForTests } from '../../command-runner/git-capability-state' +import { __resetSparseCheckoutStateCacheForTests } from '../sparse-checkout/worktree-sparse-checkout-cache' export function registerWorktreeSuiteHooks(): void { beforeEach(() => { diff --git a/src/main/git/worktree-operation-options.ts b/src/main/git/worktrees/worktree-operation-options.ts similarity index 89% rename from src/main/git/worktree-operation-options.ts rename to src/main/git/worktrees/worktree-operation-options.ts index cb37922dc65..3d68f91844d 100644 --- a/src/main/git/worktree-operation-options.ts +++ b/src/main/git/worktrees/worktree-operation-options.ts @@ -1,12 +1,11 @@ import type { LocalBaseRefRefreshResult, LocalBaseRefUpdateSuggestion -} from '../../shared/worktree/base-ref-drift-types' -import { readGitCommandFailureText } from '../../shared/git-command-failure-text' -import type { RemoveWorktreeResult } from '../../shared/worktree/create-types' -import type { GitAdmissionTier } from '../../shared/rpc-contract/git-admission-tier-params' -import type { GitWorktreeInfo } from '../../shared/worktree/types' -import type { WorktreeCheckoutProgressListener } from './worktree-checkout-progress' +} from '../../../shared/worktree/base-ref-drift-types' +import { readGitCommandFailureText } from '../../../shared/git-command-failure-text' +import type { GitAdmissionTier } from '../../../shared/rpc-contract/git-admission-tier-params' +import type { GitWorktreeInfo } from '../../../shared/worktree/types' +import type { WorktreeCheckoutProgressListener } from './creation/worktree-checkout-progress' export type AddWorktreeResult = { localBaseRefRefresh?: LocalBaseRefRefreshResult @@ -126,5 +125,3 @@ export function isNotGitRepositoryError(error: unknown): boolean { export function normalizeLocalBranchRef(branch: string): string { return branch.replace(/^refs\/heads\//, '') } - -export type { LocalBaseRefRefreshResult, LocalBaseRefUpdateSuggestion, RemoveWorktreeResult } diff --git a/src/main/git/wsl-drive-checkout-git-routing.ts b/src/main/git/wsl-drive-checkout-git-routing.ts index b922697d778..658820dbaa8 100644 --- a/src/main/git/wsl-drive-checkout-git-routing.ts +++ b/src/main/git/wsl-drive-checkout-git-routing.ts @@ -3,7 +3,7 @@ import { isWslLinkedWorktreeGitRoutingCandidate, prepareWslLinkedWorktreeGitRouting, usesHostGitForWslLinkedWorktree -} from './wsl-linked-worktree-git-routing' +} from './command-runner/wsl-linked-worktree-git-routing' import { pendingWslWindowsCheckoutGitConfig } from './wsl-windows-checkout-git-probe' /** Settle checkout ownership and Windows-Git config before synchronous routing; null means no drive-checkout command. */ diff --git a/src/main/gitea/client-scan-invalidation.test.ts b/src/main/gitea/client-scan-invalidation.test.ts index 3c85776408e..094152998e9 100644 --- a/src/main/gitea/client-scan-invalidation.test.ts +++ b/src/main/gitea/client-scan-invalidation.test.ts @@ -1,6 +1,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: vi.fn(async () => ({ stdout: 'https://git.example.com/team/repo.git\n', stderr: '' diff --git a/src/main/gitea/client.test.ts b/src/main/gitea/client.test.ts index b87339067c2..74ca7a82708 100644 --- a/src/main/gitea/client.test.ts +++ b/src/main/gitea/client.test.ts @@ -5,7 +5,8 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/gitea/repository-ref.ts b/src/main/gitea/repository-ref.ts index 8ab57367afc..89162701eda 100644 --- a/src/main/gitea/repository-ref.ts +++ b/src/main/gitea/repository-ref.ts @@ -1,4 +1,4 @@ -import { createRemoteRefProbeCache } from '../git/remote-ref-probe-cache' +import { createRemoteRefProbeCache } from '../git/remotes/remote-ref-probe-cache' export type GiteaRepoRef = { host: string diff --git a/src/main/github/auth-diagnose.test.ts b/src/main/github/auth-diagnose.test.ts index d93869656d9..7fe72ccc14a 100644 --- a/src/main/github/auth-diagnose.test.ts +++ b/src/main/github/auth-diagnose.test.ts @@ -2,7 +2,8 @@ import { describe, expect, it, vi } from 'vitest' const { ghExecFileAsyncMock } = vi.hoisted(() => ({ ghExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), ghExecFileAsync: ghExecFileAsyncMock })) import { diagnoseGhAuth, parseAuthStatus } from './auth-diagnose' diff --git a/src/main/github/client-create-pr.test.ts b/src/main/github/client-create-pr.test.ts index 1e9900376e1..bd6a861b790 100644 --- a/src/main/github/client-create-pr.test.ts +++ b/src/main/github/client-create-pr.test.ts @@ -49,7 +49,8 @@ vi.mock('./gh-utils', () => ({ _resetOwnerRepoCache: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: vi.fn() })) diff --git a/src/main/github/client-merge-queue-auto-merge.test.ts b/src/main/github/client-merge-queue-auto-merge.test.ts index 1e9d75ac4b7..58ccdda7d7a 100644 --- a/src/main/github/client-merge-queue-auto-merge.test.ts +++ b/src/main/github/client-merge-queue-auto-merge.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('../git/local-git-object-quarantine', () => moduleMocks.localGitObjectQuarantineModuleMock() ) diff --git a/src/main/github/client-merged-pr-visibility.test.ts b/src/main/github/client-merged-pr-visibility.test.ts index 0ac3e7ab418..4ec67913953 100644 --- a/src/main/github/client-merged-pr-visibility.test.ts +++ b/src/main/github/client-merged-pr-visibility.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-pr-branch-discovery.test.ts b/src/main/github/client-pr-branch-discovery.test.ts index 5c6aeddcd66..fc8ddecaa48 100644 --- a/src/main/github/client-pr-branch-discovery.test.ts +++ b/src/main/github/client-pr-branch-discovery.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-pr-check-details.test.ts b/src/main/github/client-pr-check-details.test.ts index 77af603a52b..1eaed6fa6d4 100644 --- a/src/main/github/client-pr-check-details.test.ts +++ b/src/main/github/client-pr-check-details.test.ts @@ -32,7 +32,8 @@ vi.mock('./gh-utils', () => ({ _resetOwnerRepoCache: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: vi.fn() })) diff --git a/src/main/github/client-pr-checks.test.ts b/src/main/github/client-pr-checks.test.ts index f140023665b..f2f46a1f065 100644 --- a/src/main/github/client-pr-checks.test.ts +++ b/src/main/github/client-pr-checks.test.ts @@ -72,7 +72,8 @@ vi.mock('./gh-utils', () => ({ _resetOwnerRepoCache: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/github/client-pr-comment-reactions.test.ts b/src/main/github/client-pr-comment-reactions.test.ts index 31436e42139..edb90d43779 100644 --- a/src/main/github/client-pr-comment-reactions.test.ts +++ b/src/main/github/client-pr-comment-reactions.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-pr-conflict-summary.test.ts b/src/main/github/client-pr-conflict-summary.test.ts index 024e80031c3..722df01221f 100644 --- a/src/main/github/client-pr-conflict-summary.test.ts +++ b/src/main/github/client-pr-conflict-summary.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('../git/local-git-object-quarantine', () => moduleMocks.localGitObjectQuarantineModuleMock() ) diff --git a/src/main/github/client-pr-conversation-requests.test.ts b/src/main/github/client-pr-conversation-requests.test.ts index 5787c5389f6..16fc85b10ba 100644 --- a/src/main/github/client-pr-conversation-requests.test.ts +++ b/src/main/github/client-pr-conversation-requests.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-pr-fallback-number.test.ts b/src/main/github/client-pr-fallback-number.test.ts index a09b06dac97..463405cf1d1 100644 --- a/src/main/github/client-pr-fallback-number.test.ts +++ b/src/main/github/client-pr-fallback-number.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-pr-foreign-head-cache.test.ts b/src/main/github/client-pr-foreign-head-cache.test.ts index 39a6698137f..6e8934a044f 100644 --- a/src/main/github/client-pr-foreign-head-cache.test.ts +++ b/src/main/github/client-pr-foreign-head-cache.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-pr-linked-lookup.test.ts b/src/main/github/client-pr-linked-lookup.test.ts index e3840917139..44941276ec1 100644 --- a/src/main/github/client-pr-linked-lookup.test.ts +++ b/src/main/github/client-pr-linked-lookup.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-pr-local-runtime.test.ts b/src/main/github/client-pr-local-runtime.test.ts index 57dc3d8c094..a49478bbcdb 100644 --- a/src/main/github/client-pr-local-runtime.test.ts +++ b/src/main/github/client-pr-local-runtime.test.ts @@ -74,7 +74,8 @@ vi.mock('./gh-utils', () => ({ _resetOwnerRepoCache: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/github/client-pr-push-target.test.ts b/src/main/github/client-pr-push-target.test.ts index 7b193541e57..45268fbf158 100644 --- a/src/main/github/client-pr-push-target.test.ts +++ b/src/main/github/client-pr-push-target.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-pr-rest-revalidation.test.ts b/src/main/github/client-pr-rest-revalidation.test.ts index 8a659e2a30d..217346571d4 100644 --- a/src/main/github/client-pr-rest-revalidation.test.ts +++ b/src/main/github/client-pr-rest-revalidation.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-rate-limit-block.test.ts b/src/main/github/client-rate-limit-block.test.ts index 54c695607ff..1100a174c87 100644 --- a/src/main/github/client-rate-limit-block.test.ts +++ b/src/main/github/client-rate-limit-block.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-ssh-provider-execution-boundary.test.ts b/src/main/github/client-ssh-provider-execution-boundary.test.ts index 1c2dc5fa33f..48193886725 100644 --- a/src/main/github/client-ssh-provider-execution-boundary.test.ts +++ b/src/main/github/client-ssh-provider-execution-boundary.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-stack-merge-guard.test.ts b/src/main/github/client-stack-merge-guard.test.ts index 7aaac723470..26f8d9816d8 100644 --- a/src/main/github/client-stack-merge-guard.test.ts +++ b/src/main/github/client-stack-merge-guard.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-starred.test.ts b/src/main/github/client-starred.test.ts index c78a54c33a0..93988c7c369 100644 --- a/src/main/github/client-starred.test.ts +++ b/src/main/github/client-starred.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-tracked-upstream-default-branch.test.ts b/src/main/github/client-tracked-upstream-default-branch.test.ts index 6e81ed28677..86f2132e5bd 100644 --- a/src/main/github/client-tracked-upstream-default-branch.test.ts +++ b/src/main/github/client-tracked-upstream-default-branch.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-tracked-upstream-fork-owner.test.ts b/src/main/github/client-tracked-upstream-fork-owner.test.ts index cfbad59c66b..f61b785ef22 100644 --- a/src/main/github/client-tracked-upstream-fork-owner.test.ts +++ b/src/main/github/client-tracked-upstream-fork-owner.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-tracked-upstream-snapshot.test.ts b/src/main/github/client-tracked-upstream-snapshot.test.ts index 7e34207b6bf..cbad94cc847 100644 --- a/src/main/github/client-tracked-upstream-snapshot.test.ts +++ b/src/main/github/client-tracked-upstream-snapshot.test.ts @@ -1,3 +1,5 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GithubApiRepositoryModule from './github-api-repository' import type * as GitHubEnterpriseRepositoryModule from './github-enterprise-repository' @@ -9,6 +11,16 @@ const { clientMocks, moduleMocks } = await vi.hoisted(async () => { vi.mock('./gh-utils', () => moduleMocks.ghUtilsModuleMock(clientMocks)) vi.mock('../git/runner', () => moduleMocks.gitRunnerModuleMock(clientMocks)) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: clientMocks.gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + ghExecFileAsync: clientMocks.ghExecFileAsyncMock +})) vi.mock('./local-git-config-signature', () => moduleMocks.localGitConfigSignatureModuleMock(clientMocks) ) diff --git a/src/main/github/client-work-item-check-summary.test.ts b/src/main/github/client-work-item-check-summary.test.ts index 82552b6d7b5..08160a0d093 100644 --- a/src/main/github/client-work-item-check-summary.test.ts +++ b/src/main/github/client-work-item-check-summary.test.ts @@ -34,7 +34,8 @@ vi.mock('./gh-utils', () => ({ classifyListIssuesError: (stderr: string) => ({ type: 'unknown', message: stderr }) })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: vi.fn() })) diff --git a/src/main/github/client-work-items-query-paging.test.ts b/src/main/github/client-work-items-query-paging.test.ts index 8a7affe1d33..a6c16eec51c 100644 --- a/src/main/github/client-work-items-query-paging.test.ts +++ b/src/main/github/client-work-items-query-paging.test.ts @@ -70,7 +70,8 @@ vi.mock('./gh-utils', () => ({ classifyListPrsError: (stderr: string) => ({ type: 'unknown', message: stderr }) })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/github/client-work-items.test.ts b/src/main/github/client-work-items.test.ts index 4d2fa394b7f..1bdecd3e748 100644 --- a/src/main/github/client-work-items.test.ts +++ b/src/main/github/client-work-items.test.ts @@ -62,7 +62,8 @@ vi.mock('./gh-utils', () => ({ classifyListPrsError: (stderr: string) => ({ type: 'unknown', message: stderr }) })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) @@ -112,7 +113,7 @@ import { listWorkItems } from './client/list/list-work-items' import { _resetMergeQueueCacheForTests } from './client/detect/repository-merge-metadata-cache' import { _resetOwnerRepoCache } from './gh-utils' import { GITHUB_WORK_ITEMS_QUERY_MAX_BYTES } from '../../shared/github/work-items-query-bounds' -import { _resetRemoteNameListingCache } from '../git/remote-name-listing' +import { _resetRemoteNameListingCache } from '../git/remotes/remote-name-listing' import { _resetOriginGitHubApiRepositoryCache } from './github-api-repository' diff --git a/src/main/github/client/check/get-pr-checks.ts b/src/main/github/client/check/get-pr-checks.ts index 57e74ffd105..41d2911882f 100644 --- a/src/main/github/client/check/get-pr-checks.ts +++ b/src/main/github/client/check/get-pr-checks.ts @@ -3,7 +3,7 @@ import { githubRepoContext, ghRepoExecOptions } from '../../github-repository-identity' -import { runCoalescedProbe, type CoalescedProbes } from '../../../git/coalesced-probe' +import { runCoalescedProbe, type CoalescedProbes } from '../../../git/remotes/coalesced-probe' import { githubReadExecutionScope } from '../../github-read-execution-scope' import type { PRCheckDetail } from '../../../../shared/github/check-types' import { GITHUB_WORK_ITEMS_SSH_REMOTE_REQUIRED_MESSAGE } from '../../../../shared/work-items' diff --git a/src/main/github/client/detect/repository-merge-metadata-cache.ts b/src/main/github/client/detect/repository-merge-metadata-cache.ts index 816edb3af18..2e09fa243e0 100644 --- a/src/main/github/client/detect/repository-merge-metadata-cache.ts +++ b/src/main/github/client/detect/repository-merge-metadata-cache.ts @@ -1,5 +1,5 @@ import type { GitHubPRMergeMethodSettings } from '../../../../shared/github/pull-request-types' -import type { CoalescedProbes } from '../../../git/coalesced-probe' +import type { CoalescedProbes } from '../../../git/remotes/coalesced-probe' export const MERGE_QUEUE_CACHE_TTL_MS = 10 * 60 * 1000 export const MERGE_QUEUE_UNKNOWN_CACHE_TTL_MS = 60 * 1000 diff --git a/src/main/github/client/detect/repository-merge-metadata.ts b/src/main/github/client/detect/repository-merge-metadata.ts index 067afa7bcab..bfaad9c165f 100644 --- a/src/main/github/client/detect/repository-merge-metadata.ts +++ b/src/main/github/client/detect/repository-merge-metadata.ts @@ -6,7 +6,7 @@ import { githubHostExecOptions, type GitHubApiRepository } from '../../github-ap import { githubRepoIdentityKey } from '../../../../shared/github/repository-identity-key' import { noteRepositoryRateLimitSpend, repositoryRateLimitGuard } from '../../rate-limit' import { githubReadExecutionScope } from '../../github-read-execution-scope' -import { runCoalescedProbe } from '../../../git/coalesced-probe' +import { runCoalescedProbe } from '../../../git/remotes/coalesced-probe' import { parseWslUncPath } from '../../../../shared/wsl-paths' import type { GhExecOptions } from './../github-exec-scope' import { diff --git a/src/main/github/client/fetch/get-pr-comments.ts b/src/main/github/client/fetch/get-pr-comments.ts index 907451ab711..6ef2f5e46ed 100644 --- a/src/main/github/client/fetch/get-pr-comments.ts +++ b/src/main/github/client/fetch/get-pr-comments.ts @@ -1,5 +1,5 @@ import type { PRComment } from '../../../../shared/github/comment-types' -import { runCoalescedProbe, type CoalescedProbes } from '../../../git/coalesced-probe' +import { runCoalescedProbe, type CoalescedProbes } from '../../../git/remotes/coalesced-probe' import { extractExecError } from '../../../git/exec-error' import { githubReadExecutionScope } from '../../github-read-execution-scope' import { GITHUB_WORK_ITEMS_SSH_REMOTE_REQUIRED_MESSAGE } from '../../../../shared/work-items' diff --git a/src/main/github/client/list/work-item-list-request.ts b/src/main/github/client/list/work-item-list-request.ts index 1a7207e654f..c7972d264b0 100644 --- a/src/main/github/client/list/work-item-list-request.ts +++ b/src/main/github/client/list/work-item-list-request.ts @@ -2,7 +2,7 @@ import type { ClassifiedError } from '../../../../shared/classified-error' import type { IssueSourcePreference } from '../../../../shared/repo-types' import type { ParsedTaskQuery } from '../../../../shared/task-query' import { GITHUB_WORK_ITEMS_SSH_REMOTE_REQUIRED_MESSAGE } from '../../../../shared/work-items' -import { shouldProbeGitRemote } from '../../../git/remote-name-listing' +import { shouldProbeGitRemote } from '../../../git/remotes/remote-name-listing' import type { LocalGitExecOptions, OwnerRepo } from '../../gh-utils' import { getGitHubApiRepositoryForRemote, diff --git a/src/main/github/client/list/work-item-search-batch.ts b/src/main/github/client/list/work-item-search-batch.ts index d4550ad2f57..d74c022bc0e 100644 --- a/src/main/github/client/list/work-item-search-batch.ts +++ b/src/main/github/client/list/work-item-search-batch.ts @@ -2,7 +2,7 @@ import { z } from 'zod' import { githubReadExecutionScope as workItemSearchScope } from '../../github-read-execution-scope' export { githubReadExecutionScope as workItemSearchScope } from '../../github-read-execution-scope' import { BoundedMap } from '../../../../shared/bounded-map' -import { runCoalescedProbe, type CoalescedProbes } from '../../../git/coalesced-probe' +import { runCoalescedProbe, type CoalescedProbes } from '../../../git/remotes/coalesced-probe' import { createGhRateLimitBlockedError } from '../../../git/gh-rate-limit-breaker' import { extractExecError, ghExecFileAsync } from '../../gh-utils' import { noteRepositoryRateLimitSpend, repositoryRateLimitGuard } from '../../rate-limit' diff --git a/src/main/github/client/lookup/pr-for-branch-outcome.ts b/src/main/github/client/lookup/pr-for-branch-outcome.ts index a6ec90effc6..87fc39f99fa 100644 --- a/src/main/github/client/lookup/pr-for-branch-outcome.ts +++ b/src/main/github/client/lookup/pr-for-branch-outcome.ts @@ -4,7 +4,7 @@ import { hostedReviewRepoScope, scopeGeneration } from '../../../source-control/hosted-review-scope-generations' -import { runCoalescedProbe, type CoalescedProbes } from '../../../git/coalesced-probe' +import { runCoalescedProbe, type CoalescedProbes } from '../../../git/remotes/coalesced-probe' import { githubReadExecutionScope } from '../../github-read-execution-scope' import type { PRRefreshOutcome } from '../../../../shared/github/pull-request-refresh-types' import { acquire, release, ghRepoExecOptions, githubRepoContext } from '../../gh-utils' diff --git a/src/main/github/conflict-summary.test.ts b/src/main/github/conflict-summary.test.ts index a6c15d80710..212b2041ee1 100644 --- a/src/main/github/conflict-summary.test.ts +++ b/src/main/github/conflict-summary.test.ts @@ -9,7 +9,10 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const gitExecFileAsyncMock = vi.hoisted(() => vi.fn()) const scratchFolderPrefixes = vi.hoisted((): string[] => []) -vi.mock('../git/runner', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) // Why: off Windows a WSL objects path is relative, so a real scratch dir would land in the cwd. vi.mock('node:fs/promises', async (importOriginal) => { const actual = await importOriginal() @@ -27,7 +30,7 @@ vi.mock('node:fs/promises', async (importOriginal) => { import { findGitSubcommandIndex } from '../../shared/git-command-classification' import { GIT_CAPABILITY_RETRY_INTERVAL_MS } from '../../shared/git-capability-cache' -import { getLocalGitCapabilityCache } from '../git/git-capability-state' +import { getLocalGitCapabilityCache } from '../git/command-runner/git-capability-state' import { CONFLICT_SUMMARY_BASE_FETCH_WINDOW_MS } from './conflict-summary-cache' import { __resetPRConflictSummaryCachesForTests, getPRConflictSummary } from './conflict-summary' diff --git a/src/main/github/conflict-summary.ts b/src/main/github/conflict-summary.ts index e5635c9afd8..2d7cc6a7b38 100644 --- a/src/main/github/conflict-summary.ts +++ b/src/main/github/conflict-summary.ts @@ -11,7 +11,7 @@ import { RuntimeRemoteFetchController } from '../runtime/runtime-remote-fetch-co import { clearGitCapabilityStateForTests, withLocalGitCapabilityCacheForExecution -} from '../git/git-capability-state' +} from '../git/command-runner/git-capability-state' import { __resetPRConflictSummaryDerivationCachesForTests, buildConflictSummaryCacheKey, diff --git a/src/main/github/default-branch-stale-pr.test.ts b/src/main/github/default-branch-stale-pr.test.ts index 868f687d08e..2a2b46f72ab 100644 --- a/src/main/github/default-branch-stale-pr.test.ts +++ b/src/main/github/default-branch-stale-pr.test.ts @@ -86,7 +86,8 @@ vi.mock('./gh-utils', () => ({ _resetOwnerRepoCache: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/github/gh-account-token.test.ts b/src/main/github/gh-account-token.test.ts index 2c4a33c997e..e8e9aed2c46 100644 --- a/src/main/github/gh-account-token.test.ts +++ b/src/main/github/gh-account-token.test.ts @@ -5,7 +5,8 @@ const { ghExecFileAsyncMock, getGhMultiAccountCapabilityMock } = vi.hoisted(() = getGhMultiAccountCapabilityMock: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), ghExecFileAsync: ghExecFileAsyncMock })) diff --git a/src/main/github/gh-capability-state.test.ts b/src/main/github/gh-capability-state.test.ts index 14898c2eb3c..7d2ab3905d6 100644 --- a/src/main/github/gh-capability-state.test.ts +++ b/src/main/github/gh-capability-state.test.ts @@ -4,7 +4,8 @@ const { ghExecFileAsyncMock } = vi.hoisted(() => ({ ghExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), ghExecFileAsync: ghExecFileAsyncMock })) diff --git a/src/main/github/gh-utils.test.ts b/src/main/github/gh-utils.test.ts index 12ce1c55611..dbf9b6f41e0 100644 --- a/src/main/github/gh-utils.test.ts +++ b/src/main/github/gh-utils.test.ts @@ -7,12 +7,17 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), ghExecFileAsync: vi.fn() })) -import { _resetRemoteNameListingCache } from '../git/remote-name-listing' +import { _resetRemoteNameListingCache } from '../git/remotes/remote-name-listing' import { _getOwnerRepoCacheSize, _resetOwnerRepoCache, diff --git a/src/main/github/github-api-repository.test.ts b/src/main/github/github-api-repository.test.ts index 9ce5f9cb4eb..0eddd19e02f 100644 --- a/src/main/github/github-api-repository.test.ts +++ b/src/main/github/github-api-repository.test.ts @@ -28,7 +28,7 @@ vi.mock('./github-enterprise-repository', async (importOriginal) => ({ isGitHubHostAuthenticated: isGitHubHostAuthenticatedMock })) -vi.mock('../git/remote-name-listing', () => ({ +vi.mock('../git/remotes/remote-name-listing', () => ({ shouldProbeGitRemote: shouldProbeGitRemoteMock })) diff --git a/src/main/github/github-api-repository.ts b/src/main/github/github-api-repository.ts index 143dd9b7297..10177d912e0 100644 --- a/src/main/github/github-api-repository.ts +++ b/src/main/github/github-api-repository.ts @@ -6,7 +6,7 @@ import { githubRepoIdentityKey, isDefaultGitHubHost } from '../../shared/github/repository-identity-key' -import { shouldProbeGitRemote } from '../git/remote-name-listing' +import { shouldProbeGitRemote } from '../git/remotes/remote-name-listing' import { ghRepoExecOptions, githubRepoContext, type LocalGitExecOptions } from './gh-utils' import { isGitHubHostAuthenticated } from './github-enterprise-repository' import { githubHostExecOptions } from './github-repository-host' diff --git a/src/main/github/github-enterprise-repository.test.ts b/src/main/github/github-enterprise-repository.test.ts index 37d0bafa9db..3db08f43670 100644 --- a/src/main/github/github-enterprise-repository.test.ts +++ b/src/main/github/github-enterprise-repository.test.ts @@ -9,9 +9,18 @@ const { commandExecFileAsyncMock, ghExecFileAsyncMock, gitExecFileAsyncMock, res })) // Mock only execution so identity, runtime and auth-status parsing remain real. -vi.mock('../git/runner', () => ({ - commandExecFileAsync: commandExecFileAsyncMock, - ghExecFileAsync: ghExecFileAsyncMock, +vi.mock('../git/command-runner/command-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + commandExecFileAsync: commandExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + ghExecFileAsync: ghExecFileAsyncMock +})) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/github/github-enterprise-repository.ts b/src/main/github/github-enterprise-repository.ts index 0d75c5903d6..a0d590a6fb7 100644 --- a/src/main/github/github-enterprise-repository.ts +++ b/src/main/github/github-enterprise-repository.ts @@ -19,7 +19,7 @@ import { } from './github-remote-identity-parsing' import { resolveSshConfigHostname } from './github-ssh-host-alias-resolution' import { parseWslPath } from '../wsl/filesystem/unc-path-access' -import { isStableMissingGitRemoteError } from '../git/stable-missing-git-remote-error' +import { isStableMissingGitRemoteError } from '../git/remotes/stable-missing-git-remote-error' import { requireReachableGitRoute } from '../providers/execution-host-provider-dispatch' import { getConnectionExecutionHostId } from '../../shared/execution-host' diff --git a/src/main/github/github-owner-repo-selection.ts b/src/main/github/github-owner-repo-selection.ts index 649d57bfa68..e41aadad2d7 100644 --- a/src/main/github/github-owner-repo-selection.ts +++ b/src/main/github/github-owner-repo-selection.ts @@ -1,6 +1,6 @@ import type { IssueSourcePreference } from '../../shared/repo-types' import { githubRepoIdentityKey } from '../../shared/github/repository-identity-key' -import { shouldProbeGitRemote } from '../git/remote-name-listing' +import { shouldProbeGitRemote } from '../git/remotes/remote-name-listing' import { getOwnerRepoForRemote, type LocalGitExecOptions, diff --git a/src/main/github/github-pr-stack.test.ts b/src/main/github/github-pr-stack.test.ts index 2bfac0f8827..0168ddd2774 100644 --- a/src/main/github/github-pr-stack.test.ts +++ b/src/main/github/github-pr-stack.test.ts @@ -7,7 +7,10 @@ const { ghExecFileAsyncMock, rateLimitGuardMock, noteRateLimitSpendMock } = vi.h noteRateLimitSpendMock: vi.fn() })) -vi.mock('../git/runner', () => ({ ghExecFileAsync: ghExecFileAsyncMock })) +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + ghExecFileAsync: ghExecFileAsyncMock +})) vi.mock('./rate-limit', () => ({ repositoryRateLimitGuard: rateLimitGuardMock, noteRepositoryRateLimitSpend: noteRateLimitSpendMock diff --git a/src/main/github/github-repository-identity.fork-owner-repo.test.ts b/src/main/github/github-repository-identity.fork-owner-repo.test.ts index 22ebb9342fe..fed49ecc170 100644 --- a/src/main/github/github-repository-identity.fork-owner-repo.test.ts +++ b/src/main/github/github-repository-identity.fork-owner-repo.test.ts @@ -1,5 +1,6 @@ +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' +import type * as GhExecFileModule from '../git/command-runner/gh-exec-file' import { beforeEach, describe, expect, it, vi } from 'vitest' -import type * as GitRunner from '../git/runner' // Fork PR reads prefer upstream while origin-only probes retain the checkout identity. @@ -11,9 +12,13 @@ const { gitExecFileAsyncMock, ghExecFileAsyncMock, readLocalGitConfigSignatureMo }) ) -vi.mock('../git/runner', async (importOriginal) => ({ - ...(await importOriginal()), - gitExecFileAsync: gitExecFileAsyncMock, +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), ghExecFileAsync: ghExecFileAsyncMock })) @@ -21,7 +26,7 @@ vi.mock('./local-git-config-signature', () => ({ readLocalGitConfigSignature: readLocalGitConfigSignatureMock })) -import { _resetRemoteNameListingCache } from '../git/remote-name-listing' +import { _resetRemoteNameListingCache } from '../git/remotes/remote-name-listing' import { getOwnerRepoForRemote, _resetOwnerRepoCache } from './github-repository-identity' import { getOwnerRepo } from './github-owner-repo-selection' import { getRepoUpstream } from './client/fetch/repo-slug-upstream' diff --git a/src/main/github/github-repository-identity.signed-cache.test.ts b/src/main/github/github-repository-identity.signed-cache.test.ts index 44553fab99f..2cd8252f856 100644 --- a/src/main/github/github-repository-identity.signed-cache.test.ts +++ b/src/main/github/github-repository-identity.signed-cache.test.ts @@ -1,12 +1,12 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' -import type * as GitRunner from '../git/runner' +import type * as GitRunner from '../git/command-runner/git-exec-file' const { gitExecFileAsyncMock, readLocalGitConfigSignatureMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn(), readLocalGitConfigSignatureMock: vi.fn<() => Promise>(async () => 'sig-1') })) -vi.mock('../git/runner', async (importOriginal) => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ ...(await importOriginal()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/github/github-repository-identity.ssh-host-alias.test.ts b/src/main/github/github-repository-identity.ssh-host-alias.test.ts index cbc8cb99523..e72b4ad6fa5 100644 --- a/src/main/github/github-repository-identity.ssh-host-alias.test.ts +++ b/src/main/github/github-repository-identity.ssh-host-alias.test.ts @@ -1,5 +1,6 @@ +import type * as CommandExecFileModule from '../git/command-runner/command-exec-file' +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import type * as GitRunner from '../git/runner' const { commandExecFileAsyncMock, @@ -13,9 +14,13 @@ const { readLocalGitConfigSignatureMock: vi.fn(async () => 'sig-10284') })) -vi.mock('../git/runner', async (importOriginal) => ({ - ...(await importOriginal()), - commandExecFileAsync: commandExecFileAsyncMock, +vi.mock('../git/command-runner/command-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + commandExecFileAsync: commandExecFileAsyncMock +})) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/github/github-repository-identity.ts b/src/main/github/github-repository-identity.ts index a5fc35fa8a0..c5d731bb03e 100644 --- a/src/main/github/github-repository-identity.ts +++ b/src/main/github/github-repository-identity.ts @@ -1,6 +1,6 @@ import { AsyncLocalStorage } from 'node:async_hooks' -import { runCoalescedProbe, type CoalescedProbes } from '../git/coalesced-probe' -import { readRemoteUrl } from '../git/remote-url-probe' +import { runCoalescedProbe, type CoalescedProbes } from '../git/remotes/coalesced-probe' +import { readRemoteUrl } from '../git/remotes/remote-url-probe' import { ghAccountBindingsEqual, normalizeGhAccountBinding, @@ -14,7 +14,7 @@ import { type GitHubRemoteIdentity } from './github-remote-identity-parsing' import { classifyGitHubOwnerRepoFromRemoteUrl } from './github-ssh-host-alias-resolution' -import { isStableMissingGitRemoteError } from '../git/stable-missing-git-remote-error' +import { isStableMissingGitRemoteError } from '../git/remotes/stable-missing-git-remote-error' import type { GitAdmissionTier } from '../git/command-runner/git-exec-options' import { requireReachableGitRoute } from '../providers/execution-host-provider-dispatch' import { getConnectionExecutionHostId } from '../../shared/execution-host' diff --git a/src/main/github/local-git-config-signature.ts b/src/main/github/local-git-config-signature.ts index 655bc99a050..7d20e2e2b66 100644 --- a/src/main/github/local-git-config-signature.ts +++ b/src/main/github/local-git-config-signature.ts @@ -1,7 +1,7 @@ import { readFile, stat } from 'node:fs/promises' import { homedir } from 'node:os' import { dirname, isAbsolute, join, resolve } from 'node:path' -import { runCoalescedProbe, type CoalescedProbes } from '../git/coalesced-probe' +import { runCoalescedProbe, type CoalescedProbes } from '../git/remotes/coalesced-probe' import type { GitHubRepoContext } from './github-repository-identity' type LocalGitConfigPaths = { diff --git a/src/main/github/pr-head-tracking-ref.test.ts b/src/main/github/pr-head-tracking-ref.test.ts index abbf8b97fb5..04064d52669 100644 --- a/src/main/github/pr-head-tracking-ref.test.ts +++ b/src/main/github/pr-head-tracking-ref.test.ts @@ -1,7 +1,10 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) import { fetchGitHubPullRequestHeadRef, fetchPrHeadTrackingRef } from './pr-head-tracking-ref' diff --git a/src/main/github/pr-refresh-coordinator-completion-order.test.ts b/src/main/github/pr-refresh-coordinator-completion-order.test.ts index b9208d22771..782ab7d2711 100644 --- a/src/main/github/pr-refresh-coordinator-completion-order.test.ts +++ b/src/main/github/pr-refresh-coordinator-completion-order.test.ts @@ -1,6 +1,6 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { PRRefreshOutcome } from '../../shared/github/pull-request-refresh-types' -import { runCoalescedProbe, type CoalescedProbes } from '../git/coalesced-probe' +import { runCoalescedProbe, type CoalescedProbes } from '../git/remotes/coalesced-probe' import { makeCandidate, makePR } from './pr-refresh-coordinator-test-harness' const { coordinatorMocks, moduleMocks } = await vi.hoisted(async () => { diff --git a/src/main/github/project-account-operations.test.ts b/src/main/github/project-account-operations.test.ts index 506cff00969..3d782e4e202 100644 --- a/src/main/github/project-account-operations.test.ts +++ b/src/main/github/project-account-operations.test.ts @@ -17,7 +17,7 @@ vi.mock('./github-api-repository-remote-probe', () => ({ getOriginGitHubApiRepository: remote, getGitHubApiRepositoryForRemote: remote })) -vi.mock('../git/remote-name-listing', () => ({ shouldProbeGitRemote: async () => false })) +vi.mock('../git/remotes/remote-name-listing', () => ({ shouldProbeGitRemote: async () => false })) vi.mock('./rate-limit', () => ({ repositoryRateLimitGuard: () => ({ blocked: false }), noteRepositoryRateLimitSpend: () => {}, diff --git a/src/main/github/project-view-host-auth.test.ts b/src/main/github/project-view-host-auth.test.ts index 7377b8e6063..5fea0e22f77 100644 --- a/src/main/github/project-view-host-auth.test.ts +++ b/src/main/github/project-view-host-auth.test.ts @@ -19,8 +19,13 @@ vi.mock('./gh-utils', () => ({ release: releaseMock })) -vi.mock('../git/runner', () => ({ - extractExecError: vi.fn(() => ({ stdout: '', stderr: '' })), +vi.mock('../git/exec-error', async (importOriginal) => ({ + ...(await importOriginal>()), + extractExecError: vi.fn(() => ({ stdout: '', stderr: '' })) +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), ghExecFileAsync: ghExecFileAsyncMock })) diff --git a/src/main/github/pull-request-sidebar-query.test.ts b/src/main/github/pull-request-sidebar-query.test.ts index 1652d10dd20..b4c6d188572 100644 --- a/src/main/github/pull-request-sidebar-query.test.ts +++ b/src/main/github/pull-request-sidebar-query.test.ts @@ -1,7 +1,15 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' const { exec, spend } = vi.hoisted(() => ({ exec: vi.fn(), spend: vi.fn() })) -vi.mock('../git/runner', () => ({ ghExecFileAsync: exec, gitExecFileAsync: vi.fn() })) +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + ghExecFileAsync: exec +})) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: vi.fn() +})) vi.mock('./rate-limit', () => ({ noteRepositoryRateLimitSpend: spend, repositoryRateLimitGuard: () => ({ blocked: false }) diff --git a/src/main/github/rate-limit.test.ts b/src/main/github/rate-limit.test.ts index a94cf0ce9dd..9771d3afa7c 100644 --- a/src/main/github/rate-limit.test.ts +++ b/src/main/github/rate-limit.test.ts @@ -4,7 +4,8 @@ const { ghExecFileAsyncMock } = vi.hoisted(() => ({ ghExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), ghExecFileAsync: ghExecFileAsyncMock })) diff --git a/src/main/github/work-item-search-test-harness.ts b/src/main/github/work-item-search-test-harness.ts index d3783f0afe1..b328f5bf53d 100644 --- a/src/main/github/work-item-search-test-harness.ts +++ b/src/main/github/work-item-search-test-harness.ts @@ -3,6 +3,7 @@ import type { Mock } from 'vitest' import { randomUUID } from 'node:crypto' import { basename } from 'node:path' import type * as GithubApiRepositoryModule from './github-api-repository' +import type * as GitExecFileModule from '../git/command-runner/git-exec-file' import { WorkItemSearchApi } from './__fixtures__/work-item-search-api' const { @@ -15,6 +16,7 @@ const { capture: vi.fn(), sourceContext: { host: 'github.com', available: true } })) +const gitExecFileAsync = vi.hoisted(() => vi.fn()) vi.mock('../git/command-runner/exec-file-capture', () => ({ execFileCaptureToTermination: capture })) @@ -30,7 +32,11 @@ vi.mock('../git/command-runner/wsl-command-resolution', () => ({ })) vi.mock('../git/runner', async () => ({ ghExecFileAsync: (await import('../git/command-runner/gh-exec-file')).ghExecFileAsync, - gitExecFileAsync: vi.fn() + gitExecFileAsync +})) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal()), + gitExecFileAsync })) vi.mock('./github-api-repository', async (importOriginal) => { const actual = await importOriginal() diff --git a/src/main/gitlab/client-mr-auth-rate-limit.test.ts b/src/main/gitlab/client-mr-auth-rate-limit.test.ts index 6d76bea52a5..52166f4d402 100644 --- a/src/main/gitlab/client-mr-auth-rate-limit.test.ts +++ b/src/main/gitlab/client-mr-auth-rate-limit.test.ts @@ -23,7 +23,8 @@ const { // Why: the #9171 default-branch guard resolves the repo default branch via // git; keep those probes hermetic instead of spawning real git processes. -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/gitlab/client-mr-branch-lookup.test.ts b/src/main/gitlab/client-mr-branch-lookup.test.ts index 3ae00222b19..ac7e5f41b98 100644 --- a/src/main/gitlab/client-mr-branch-lookup.test.ts +++ b/src/main/gitlab/client-mr-branch-lookup.test.ts @@ -30,7 +30,8 @@ const { // Why: the #9171 default-branch guard resolves the repo default branch via // git; keep those probes hermetic instead of spawning real git processes. -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/gitlab/client-mr-listing.test.ts b/src/main/gitlab/client-mr-listing.test.ts index 3c1d1292b7e..4b46cdc6dc3 100644 --- a/src/main/gitlab/client-mr-listing.test.ts +++ b/src/main/gitlab/client-mr-listing.test.ts @@ -23,7 +23,8 @@ const { // Why: the #9171 default-branch guard resolves the repo default branch via // git; keep those probes hermetic instead of spawning real git processes. -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/gitlab/client-mr-review-actions.test.ts b/src/main/gitlab/client-mr-review-actions.test.ts index cd905c30170..11fcf90049b 100644 --- a/src/main/gitlab/client-mr-review-actions.test.ts +++ b/src/main/gitlab/client-mr-review-actions.test.ts @@ -23,7 +23,8 @@ const { // Why: the #9171 default-branch guard resolves the repo default branch via // git; keep those probes hermetic instead of spawning real git processes. -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/gitlab/gitlab-issue-source-resolution.ts b/src/main/gitlab/gitlab-issue-source-resolution.ts index b7f5da4b1d5..195e331cda7 100644 --- a/src/main/gitlab/gitlab-issue-source-resolution.ts +++ b/src/main/gitlab/gitlab-issue-source-resolution.ts @@ -1,4 +1,4 @@ -import { listCachedRemoteNames, shouldProbeGitRemote } from '../git/remote-name-listing' +import { listCachedRemoteNames, shouldProbeGitRemote } from '../git/remotes/remote-name-listing' import type { IssueSourcePreference } from '../../shared/repo-types' import { readLocalGitConfigSignature } from '../github/local-git-config-signature' import { diff --git a/src/main/gitlab/gitlab-known-host-backoff.test.ts b/src/main/gitlab/gitlab-known-host-backoff.test.ts index a1981ff74f3..5802f530447 100644 --- a/src/main/gitlab/gitlab-known-host-backoff.test.ts +++ b/src/main/gitlab/gitlab-known-host-backoff.test.ts @@ -1,7 +1,10 @@ import { afterEach, beforeEach, expect, it, vi } from 'vitest' const { execute } = vi.hoisted(() => ({ execute: vi.fn() })) -vi.mock('../git/runner', () => ({ glabExecFileAsync: execute })) +vi.mock('../git/command-runner/glab-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + glabExecFileAsync: execute +})) import { _resetKnownHostsCache, @@ -9,7 +12,7 @@ import { KNOWN_HOSTS_FAILURE_INITIAL_BACKOFF_MS, rememberGlabKnownHosts } from './gitlab-known-host-probe' -import { NEGATIVE_ENTRY_TTL_MS } from '../git/remote-ref-probe-cache' +import { NEGATIVE_ENTRY_TTL_MS } from '../git/remotes/remote-ref-probe-cache' const RECOVERED = { stdout: 'Logged in to recovered.test as user', stderr: '' } diff --git a/src/main/gitlab/gitlab-known-host-probe.test.ts b/src/main/gitlab/gitlab-known-host-probe.test.ts index f468d7eefc8..80b96cc9742 100644 --- a/src/main/gitlab/gitlab-known-host-probe.test.ts +++ b/src/main/gitlab/gitlab-known-host-probe.test.ts @@ -2,7 +2,10 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' const { glabExecFileAsyncMock } = vi.hoisted(() => ({ glabExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ glabExecFileAsync: glabExecFileAsyncMock })) +vi.mock('../git/command-runner/glab-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + glabExecFileAsync: glabExecFileAsyncMock +})) import { _getKnownHostsCacheSize, diff --git a/src/main/gitlab/gitlab-known-host-probe.ts b/src/main/gitlab/gitlab-known-host-probe.ts index 309022af813..039c87cdf30 100644 --- a/src/main/gitlab/gitlab-known-host-probe.ts +++ b/src/main/gitlab/gitlab-known-host-probe.ts @@ -1,7 +1,7 @@ import { stripAnsiEscapeSequences } from '../../shared/ansi-escape-sequences' -import { runCoalescedProbe, type CoalescedProbes } from '../git/coalesced-probe' +import { runCoalescedProbe, type CoalescedProbes } from '../git/remotes/coalesced-probe' import { extractExecError } from '../git/exec-error' -import { NEGATIVE_ENTRY_TTL_MS } from '../git/remote-ref-probe-cache' +import { NEGATIVE_ENTRY_TTL_MS } from '../git/remotes/remote-ref-probe-cache' import { glabExecFileAsync } from '../git/runner' import { DEFAULT_GITLAB_HOSTS, normalizeGitLabHost } from './project-ref-parser' import type { GitAdmissionTier } from '../git/command-runner/git-exec-options' diff --git a/src/main/gitlab/gitlab-known-host-retirement.test.ts b/src/main/gitlab/gitlab-known-host-retirement.test.ts index fe2a75fd85c..08e009a1d9b 100644 --- a/src/main/gitlab/gitlab-known-host-retirement.test.ts +++ b/src/main/gitlab/gitlab-known-host-retirement.test.ts @@ -1,10 +1,13 @@ import { afterEach, beforeEach, expect, it, vi } from 'vitest' const { execute } = vi.hoisted(() => ({ execute: vi.fn() })) -vi.mock('../git/runner', () => ({ glabExecFileAsync: execute })) +vi.mock('../git/command-runner/glab-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + glabExecFileAsync: execute +})) import { _resetKnownHostsCache, getGlabKnownHosts } from './gitlab-known-host-probe' -import { PROBE_COALESCE_STALE_MS } from '../git/coalesced-probe' +import { PROBE_COALESCE_STALE_MS } from '../git/remotes/coalesced-probe' const response = (host: string) => ({ stdout: `Logged in to ${host} as user`, stderr: '' }) const deferred = () => Promise.withResolvers>() diff --git a/src/main/gitlab/gitlab-partial-auth-recovery.test.ts b/src/main/gitlab/gitlab-partial-auth-recovery.test.ts index d8072a4c4cc..a6acd670466 100644 --- a/src/main/gitlab/gitlab-partial-auth-recovery.test.ts +++ b/src/main/gitlab/gitlab-partial-auth-recovery.test.ts @@ -6,7 +6,15 @@ const { git, execute, scan, signature } = vi.hoisted(() => ({ scan: vi.fn(), signature: vi.fn() })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: git, glabExecFileAsync: execute })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: git +})) + +vi.mock('../git/command-runner/glab-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + glabExecFileAsync: execute +})) vi.mock('../github/local-git-config-signature', () => ({ readLocalGitConfigSignature: signature })) vi.mock('../../shared/ansi-escape-sequences', async (original) => { const actual = await original() @@ -28,8 +36,8 @@ import { parseGlabAuthStatusHosts, KNOWN_HOSTS_CACHE_MAX_ENTRIES } from './gitlab-known-host-probe' -import { PROBE_COALESCE_STALE_MS } from '../git/coalesced-probe' -import { NEGATIVE_ENTRY_TTL_MS } from '../git/remote-ref-probe-cache' +import { PROBE_COALESCE_STALE_MS } from '../git/remotes/coalesced-probe' +import { NEGATIVE_ENTRY_TTL_MS } from '../git/remotes/remote-ref-probe-cache' const completed = { code: 1, killed: false, signal: null, outputTruncated: false } const failure = (stderr = '', metadata = {}) => Object.assign(new Error('auth failed'), completed, { stdout: '', stderr }, metadata) diff --git a/src/main/gitlab/gitlab-project-ref-resolution.ts b/src/main/gitlab/gitlab-project-ref-resolution.ts index cb3d37ab107..755119dcc65 100644 --- a/src/main/gitlab/gitlab-project-ref-resolution.ts +++ b/src/main/gitlab/gitlab-project-ref-resolution.ts @@ -1,8 +1,8 @@ import { glabExecFileAsync } from '../git/runner' import type { GitAdmissionTier } from '../git/command-runner/git-exec-options' import { addWslEnvKeys } from '../../shared/wsl-env' -import { isTransientGitProbeError, readRemoteUrl } from '../git/remote-url-probe' -import { NEGATIVE_ENTRY_TTL_MS } from '../git/remote-ref-probe-cache' +import { isTransientGitProbeError, readRemoteUrl } from '../git/remotes/remote-url-probe' +import { NEGATIVE_ENTRY_TTL_MS } from '../git/remotes/remote-ref-probe-cache' import { readLocalGitConfigSignature } from '../github/local-git-config-signature' import { clearProjectRefInFlight, runProjectRefProbeOnce } from './project-ref-inflight' import { diff --git a/src/main/gitlab/gl-utils.test.ts b/src/main/gitlab/gl-utils.test.ts index 1a4c1c117c8..77790e95cdc 100644 --- a/src/main/gitlab/gl-utils.test.ts +++ b/src/main/gitlab/gl-utils.test.ts @@ -8,8 +8,13 @@ const { gitExecFileAsyncMock, glabExecFileAsyncMock, readLocalGitConfigSignature }) ) -vi.mock('../git/runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/glab-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), glabExecFileAsync: glabExecFileAsyncMock })) @@ -39,9 +44,9 @@ import { resolveIssueSource } from './gl-utils' import { GlabNonListResponseError } from './glab-api-response' -import { _resetRemoteNameListingCache } from '../git/remote-name-listing' -import { REMOTE_URL_PROBE_TIMEOUT_MS } from '../git/remote-url-probe' -import { NEGATIVE_ENTRY_TTL_MS } from '../git/remote-ref-probe-cache' +import { _resetRemoteNameListingCache } from '../git/remotes/remote-name-listing' +import { REMOTE_URL_PROBE_TIMEOUT_MS } from '../git/remotes/remote-url-probe' +import { NEGATIVE_ENTRY_TTL_MS } from '../git/remotes/remote-ref-probe-cache' function mockGitRemoteCommands(remotes: Record): void { gitExecFileAsyncMock.mockImplementation(async (args: string[]) => { diff --git a/src/main/gitlab/mr-head-tracking-ref.test.ts b/src/main/gitlab/mr-head-tracking-ref.test.ts index 61ce5d96dc0..f7e2173fc5e 100644 --- a/src/main/gitlab/mr-head-tracking-ref.test.ts +++ b/src/main/gitlab/mr-head-tracking-ref.test.ts @@ -1,7 +1,10 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) import { gitlabMergeRequestHeadLocalRef, diff --git a/src/main/gitlab/project-ref-inflight.ts b/src/main/gitlab/project-ref-inflight.ts index 5def629a595..d24624c079f 100644 --- a/src/main/gitlab/project-ref-inflight.ts +++ b/src/main/gitlab/project-ref-inflight.ts @@ -1,4 +1,4 @@ -import { runCoalescedProbe, type CoalescedProbes } from '../git/coalesced-probe' +import { runCoalescedProbe, type CoalescedProbes } from '../git/remotes/coalesced-probe' import type { ProjectRef } from './gl-utils' const projectRefInFlight: CoalescedProbes = new Map() diff --git a/src/main/gitlab/task-project-eligibility.test.ts b/src/main/gitlab/task-project-eligibility.test.ts index f7e45494d47..0e3add1d85b 100644 --- a/src/main/gitlab/task-project-eligibility.test.ts +++ b/src/main/gitlab/task-project-eligibility.test.ts @@ -11,16 +11,25 @@ vi.mock('node:fs/promises', async (importOriginal) => { const { git, glab, gh } = vi.hoisted(() => ({ git: vi.fn(), glab: vi.fn(), gh: vi.fn() })) -vi.mock('../git/runner', () => ({ - gitExecFileAsync: git, - glabExecFileAsync: glab, +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: git +})) + +vi.mock('../git/command-runner/glab-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + glabExecFileAsync: glab +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), ghExecFileAsync: gh })) import { listMergeRequests } from './merge-request-list' import { listIssues } from './issues' import { _resetProjectRefCache, _resetKnownHostsCache } from './gitlab-project-ref-resolution' -import { _resetRemoteNameListingCache } from '../git/remote-name-listing' +import { _resetRemoteNameListingCache } from '../git/remotes/remote-name-listing' import { resolveIssueSource } from './gitlab-issue-source-resolution' function serveRemotes(repos: Record>): void { diff --git a/src/main/ipc/created-worktree-reconciliation.test.ts b/src/main/ipc/created-worktree-reconciliation.test.ts index 8d72742920e..65aea2ba7d4 100644 --- a/src/main/ipc/created-worktree-reconciliation.test.ts +++ b/src/main/ipc/created-worktree-reconciliation.test.ts @@ -1,9 +1,13 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' -import { describeCreatedWorktree, listWorktreesSharedStrict } from '../git/worktree' +import { describeCreatedWorktree } from '../git/worktrees/catalog/worktree-listing' +import { listWorktreesSharedStrict } from '../git/worktrees/catalog/worktree-scan-cache' import { findCreatedWorktree, resolveCreatedWorktree } from './created-worktree-reconciliation' -vi.mock('../git/worktree', () => ({ - listWorktreesSharedStrict: vi.fn(), +vi.mock('../git/worktrees/catalog/worktree-scan-cache', () => ({ + listWorktreesSharedStrict: vi.fn() +})) + +vi.mock('../git/worktrees/catalog/worktree-listing', () => ({ describeCreatedWorktree: vi.fn() })) diff --git a/src/main/ipc/created-worktree-reconciliation.ts b/src/main/ipc/created-worktree-reconciliation.ts index 4f1ee5f2fe0..ed3d4e09bf6 100644 --- a/src/main/ipc/created-worktree-reconciliation.ts +++ b/src/main/ipc/created-worktree-reconciliation.ts @@ -1,9 +1,10 @@ -import { describeCreatedWorktree, listWorktreesSharedStrict } from '../git/worktree' +import { describeCreatedWorktree } from '../git/worktrees/catalog/worktree-listing' +import { listWorktreesSharedStrict } from '../git/worktrees/catalog/worktree-scan-cache' // Import directly because suites mock the worktree barrel wholesale. -import { WORKTREE_LIST_TIMEOUT_MS } from '../git/worktree-operation-options' -import type { GitWorktreeExecOptions } from '../git/worktree' +import { WORKTREE_LIST_TIMEOUT_MS } from '../git/worktrees/worktree-operation-options' +import type { GitWorktreeExecOptions } from '../git/worktrees/worktree-operation-options' import type { GitWorktreeInfo } from '../../shared/worktree/types' -import { areWorktreePathsEqual } from '../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../git/worktrees/catalog/worktree-path-comparison' export function findCreatedWorktree( worktrees: readonly T[], diff --git a/src/main/ipc/filesystem/filesystem-branch-compare-diff.test.ts b/src/main/ipc/filesystem/filesystem-branch-compare-diff.test.ts index 63e0c191339..a884aac8d0d 100644 --- a/src/main/ipc/filesystem/filesystem-branch-compare-diff.test.ts +++ b/src/main/ipc/filesystem/filesystem-branch-compare-diff.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import path from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' import { @@ -14,20 +14,20 @@ import { resetFilesystemIpcMocks } from './filesystem-test-harness' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -41,18 +41,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-commit-message-generation.test.ts b/src/main/ipc/filesystem/filesystem-commit-message-generation.test.ts index 26083d014d0..d109bba2d60 100644 --- a/src/main/ipc/filesystem/filesystem-commit-message-generation.test.ts +++ b/src/main/ipc/filesystem/filesystem-commit-message-generation.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import path from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' import { @@ -16,20 +16,20 @@ import { resetFilesystemIpcMocks } from './filesystem-test-harness' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -43,18 +43,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-commit-message-model-discovery.test.ts b/src/main/ipc/filesystem/filesystem-commit-message-model-discovery.test.ts index e622f13a94d..0170c2dc8af 100644 --- a/src/main/ipc/filesystem/filesystem-commit-message-model-discovery.test.ts +++ b/src/main/ipc/filesystem/filesystem-commit-message-model-discovery.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import path from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' import { @@ -12,20 +12,20 @@ import { resetFilesystemIpcMocks } from './filesystem-test-harness' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -39,18 +39,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-conflict-operation-routing.test.ts b/src/main/ipc/filesystem/filesystem-conflict-operation-routing.test.ts index 40c9f30c8bd..b26bcf2178f 100644 --- a/src/main/ipc/filesystem/filesystem-conflict-operation-routing.test.ts +++ b/src/main/ipc/filesystem/filesystem-conflict-operation-routing.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import { beforeEach, describe, expect, it, vi } from 'vitest' import { handlers, @@ -12,20 +12,20 @@ import { const getLocalGitOptionsForRegisteredWorktreeMock = vi.hoisted(() => vi.fn()) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -39,18 +39,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock('../local-worktree-runtime-options', () => ({ getLocalGitOptionsForRegisteredWorktree: getLocalGitOptionsForRegisteredWorktreeMock, getLocalGitOptionsForRepo: vi.fn(() => ({})), diff --git a/src/main/ipc/filesystem/filesystem-content-search-cancellation.test.ts b/src/main/ipc/filesystem/filesystem-content-search-cancellation.test.ts index 7b0115edfc4..e924b51901c 100644 --- a/src/main/ipc/filesystem/filesystem-content-search-cancellation.test.ts +++ b/src/main/ipc/filesystem/filesystem-content-search-cancellation.test.ts @@ -34,8 +34,13 @@ vi.mock('electron', () => ({ } })) -vi.mock('../../git/runner', () => ({ - gitExecFileAsync: vi.fn(), +vi.mock('../../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: vi.fn() +})) + +vi.mock('../../git/command-runner/wsl-aware-spawn', async (importOriginal) => ({ + ...(await importOriginal>()), wslAwareSpawn: wslAwareSpawnMock })) diff --git a/src/main/ipc/filesystem/filesystem-download-transfers.test.ts b/src/main/ipc/filesystem/filesystem-download-transfers.test.ts index 709bf63d7c6..668eee480b0 100644 --- a/src/main/ipc/filesystem/filesystem-download-transfers.test.ts +++ b/src/main/ipc/filesystem/filesystem-download-transfers.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import path from 'node:path' import { EventEmitter } from 'node:events' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -17,20 +17,20 @@ import { resetFilesystemIpcMocks } from './filesystem-test-harness' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -44,18 +44,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-file-content-unc-drive.test.ts b/src/main/ipc/filesystem/filesystem-file-content-unc-drive.test.ts index 498a564ea75..9a3a3361151 100644 --- a/src/main/ipc/filesystem/filesystem-file-content-unc-drive.test.ts +++ b/src/main/ipc/filesystem/filesystem-file-content-unc-drive.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import path from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' import { @@ -15,20 +15,20 @@ import { } from './filesystem-test-harness' const diskPreconditionMock = vi.hoisted(() => ({ writeLocalTextFileWithDiskPrecondition: vi.fn() })) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -56,18 +56,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-git-commit-dispatch.test.ts b/src/main/ipc/filesystem/filesystem-git-commit-dispatch.test.ts index 7f972e87bb6..ef0ab1dd8ef 100644 --- a/src/main/ipc/filesystem/filesystem-git-commit-dispatch.test.ts +++ b/src/main/ipc/filesystem/filesystem-git-commit-dispatch.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import path from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import * as gitRunner from '../../git/command-runner/git-exec-file' @@ -18,20 +18,20 @@ import { resetFilesystemIpcMocks } from './filesystem-test-harness' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -45,18 +45,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-git-commit-generation-handlers.ts b/src/main/ipc/filesystem/filesystem-git-commit-generation-handlers.ts index 0ca4cbcb003..aba555cb77d 100644 --- a/src/main/ipc/filesystem/filesystem-git-commit-generation-handlers.ts +++ b/src/main/ipc/filesystem/filesystem-git-commit-generation-handlers.ts @@ -12,7 +12,7 @@ import { type GenerateCommitMessageResult } from '../../text-generation/commit-message-text-generation' import { getCommitMessageModelDiscoveryHostKey } from '../../../shared/commit-message-host-key' -import { getStagedCommitContext } from '../../git/status' +import { getStagedCommitContext } from '../../git/source-control/staged-commit-context' import { SSH_HOST_NOT_SERVED_MESSAGE } from '../../providers/ssh-host-not-served-error' import { resolveRegisteredWorktreePath } from '../worktrees/removal/registered-worktree-roots-cache' import { getLocalGitOptionsForRegisteredWorktree } from '../local-worktree-runtime-options' diff --git a/src/main/ipc/filesystem/filesystem-git-commit-handlers.ts b/src/main/ipc/filesystem/filesystem-git-commit-handlers.ts index 1a790a69c7e..c805fe4a7a5 100644 --- a/src/main/ipc/filesystem/filesystem-git-commit-handlers.ts +++ b/src/main/ipc/filesystem/filesystem-git-commit-handlers.ts @@ -1,5 +1,5 @@ import { ipcMain } from 'electron' -import { commitChanges, completeMerge } from '../../git/status' +import { commitChanges, completeMerge } from '../../git/source-control/commit-changes' import { resolveRegisteredWorktreePath } from '../worktrees/removal/registered-worktree-roots-cache' import { getLocalGitOptionsForRegisteredWorktree } from '../local-worktree-runtime-options' import type { FilesystemHandlerContext } from './filesystem-handler-context' diff --git a/src/main/ipc/filesystem/filesystem-git-diff-handlers.ts b/src/main/ipc/filesystem/filesystem-git-diff-handlers.ts index c7d5a9c6042..ba09f4c36be 100644 --- a/src/main/ipc/filesystem/filesystem-git-diff-handlers.ts +++ b/src/main/ipc/filesystem/filesystem-git-diff-handlers.ts @@ -1,6 +1,7 @@ import { ipcMain } from 'electron' import type { GitDiffResult } from '../../../shared/git-diff-compare-types' -import { getBranchDiff, getCommitDiff } from '../../git/status' +import { getBranchDiff } from '../../git/source-control/branch-diff' +import { getCommitDiff } from '../../git/source-control/commit-diff' import { validateFullGitObjectId, validateGitRelativeFilePath } from './filesystem-path-containment' import type { FilesystemHandlerContext } from './filesystem-handler-context' import { requireReachableGitRoute } from '../../providers/execution-host-provider-dispatch' diff --git a/src/main/ipc/filesystem/filesystem-git-index-handlers.ts b/src/main/ipc/filesystem/filesystem-git-index-handlers.ts index ced4f7c324c..321a1b6e106 100644 --- a/src/main/ipc/filesystem/filesystem-git-index-handlers.ts +++ b/src/main/ipc/filesystem/filesystem-git-index-handlers.ts @@ -3,18 +3,17 @@ import { resolveConflict, stageFile, unstageFile, - discardChanges, - bulkDiscardChanges, bulkStageFiles, bulkUnstageFiles, stageWorktreeChanges -} from '../../git/status' +} from '../../git/source-control/staging' +import { discardChanges, bulkDiscardChanges } from '../../git/source-control/discard-changes' import { resolveRegisteredWorktreePath } from '../worktrees/removal/registered-worktree-roots-cache' import { getLocalGitOptionsForRegisteredWorktree, getLocalRepoForRegisteredWorktree } from '../local-worktree-runtime-options' -import { getWorktreeSharedLinkPaths } from '../../git/worktree-shared-directories' +import { getWorktreeSharedLinkPaths } from '../../git/worktrees/content-paths/worktree-shared-directories' import { validateGitRelativeFilePath } from './filesystem-path-containment' import type { FilesystemHandlerContext } from './filesystem-handler-context' import { parseGitStageWorktreeScope } from '../../../shared/git-stage-worktree-scope' diff --git a/src/main/ipc/filesystem/filesystem-git-status-handlers.ts b/src/main/ipc/filesystem/filesystem-git-status-handlers.ts index 1678d093416..799b8fa2cc9 100644 --- a/src/main/ipc/filesystem/filesystem-git-status-handlers.ts +++ b/src/main/ipc/filesystem/filesystem-git-status-handlers.ts @@ -8,18 +8,18 @@ import type { GitDiffResult } from '../../../shared/git-diff-compare-types' import type { GitHistoryOptions, GitHistoryResult } from '../../../shared/git-history' import type { GitStatusUpstreamRefWatchRequest } from '../git-status-upstream-ref-watch-request' import type { GitAdmissionTier } from '../../git/command-runner/git-exec-options' +import { getStatus } from '../../git/source-control/status-read' +import { getSubmoduleStatus } from '../../git/source-control/submodule-status' import { - getStatus, - getSubmoduleStatus, abortMerge, abortRebase, - detectConflictOperation, - getDiff -} from '../../git/status' + detectConflictOperation +} from '../../git/source-control/git-conflict-operation' +import { getDiff } from '../../git/source-control/file-diff' import { getHistory } from '../../git/history' -import { isGitWorktreeMutationInFlight } from '../../git/git-worktree-mutation-state' +import { isGitWorktreeMutationInFlight } from '../../git/command-runner/git-worktree-mutation-state' import type { GitMutationInFlight } from '../../../shared/git-mutation-in-flight' -import { checkIgnoredPaths } from '../../git/check-ignored-paths' +import { checkIgnoredPaths } from '../../git/source-control/check-ignored-paths' import { appendFolderToGitignore, findKnownHugeFolderPathsToIgnore @@ -31,7 +31,7 @@ import { getLocalGitOptionsForRepo, getLocalRepoForRegisteredWorktree } from '../local-worktree-runtime-options' -import { getWorktreeSharedLinkPaths } from '../../git/worktree-shared-directories' +import { getWorktreeSharedLinkPaths } from '../../git/worktrees/content-paths/worktree-shared-directories' import { applyGitStatusUpstreamRefWatchRequest } from '../git-status-upstream-ref-watch-request' import type { FilesystemHandlerContext } from './filesystem-handler-context' import { readWorktreeGitUnlessWslStopped } from './wsl-gated-worktree-git-read' diff --git a/src/main/ipc/filesystem/filesystem-git-status-staging.test.ts b/src/main/ipc/filesystem/filesystem-git-status-staging.test.ts index 32698d4d813..c25089f669f 100644 --- a/src/main/ipc/filesystem/filesystem-git-status-staging.test.ts +++ b/src/main/ipc/filesystem/filesystem-git-status-staging.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import { EventEmitter } from 'node:events' import path from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -23,20 +23,20 @@ import { resetFilesystemIpcMocks } from './filesystem-test-harness' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -50,18 +50,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-list-files-handler-name-filter.test.ts b/src/main/ipc/filesystem/filesystem-list-files-handler-name-filter.test.ts index 3c0a6018ddd..38ec06df703 100644 --- a/src/main/ipc/filesystem/filesystem-list-files-handler-name-filter.test.ts +++ b/src/main/ipc/filesystem/filesystem-list-files-handler-name-filter.test.ts @@ -1,25 +1,25 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import { EventEmitter } from 'node:events' import { beforeEach, describe, expect, it, vi } from 'vitest' import { handlers, store, resetFilesystemIpcMocks } from './filesystem-test-harness' const { listQuickOpenFilesMock } = vi.hoisted(() => ({ listQuickOpenFilesMock: vi.fn() })) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -33,18 +33,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-list-files-name-filter.test.ts b/src/main/ipc/filesystem/filesystem-list-files-name-filter.test.ts index f728e1b8d3e..d8f1968fe96 100644 --- a/src/main/ipc/filesystem/filesystem-list-files-name-filter.test.ts +++ b/src/main/ipc/filesystem/filesystem-list-files-name-filter.test.ts @@ -1,7 +1,7 @@ import { EventEmitter } from 'node:events' import { afterEach, describe, expect, it, vi } from 'vitest' import type { Store } from '../../persistence/loading-store/store' -import type * as GitRunner from '../../git/runner' +import type * as GitRunner from '../../git/command-runner/wsl-aware-spawn' import { pathMatchesFileNameFilterTokens, splitFileNameFilterTokens @@ -11,7 +11,7 @@ const { wslAwareSpawnMock } = vi.hoisted(() => ({ wslAwareSpawnMock: vi.fn() })) -vi.mock('../../git/runner', async (importOriginal) => ({ +vi.mock('../../git/command-runner/wsl-aware-spawn', async (importOriginal) => ({ ...(await importOriginal()), wslAwareSpawn: wslAwareSpawnMock })) diff --git a/src/main/ipc/filesystem/filesystem-markdown-document-listing.test.ts b/src/main/ipc/filesystem/filesystem-markdown-document-listing.test.ts index 3650f272472..cc6fe41d40a 100644 --- a/src/main/ipc/filesystem/filesystem-markdown-document-listing.test.ts +++ b/src/main/ipc/filesystem/filesystem-markdown-document-listing.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import path from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as MarkdownDocumentsModule from '../markdown-documents' @@ -18,20 +18,20 @@ const { listMarkdownDocumentsMock, localOptionsMock } = vi.hoisted(() => ({ localOptionsMock: vi.fn() })) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -53,18 +53,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-pull-request-linked-issue-lifetime.test.ts b/src/main/ipc/filesystem/filesystem-pull-request-linked-issue-lifetime.test.ts index 9b624cca90a..35bbb271639 100644 --- a/src/main/ipc/filesystem/filesystem-pull-request-linked-issue-lifetime.test.ts +++ b/src/main/ipc/filesystem/filesystem-pull-request-linked-issue-lifetime.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import { setImmediate as nextTurn } from 'node:timers/promises' import { beforeEach, describe, expect, it, vi } from 'vitest' import { @@ -16,20 +16,20 @@ import { const linkedLookup = vi.hoisted(() => ({ run: (): Promise => Promise.resolve(null) })) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -43,18 +43,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-read-dir-unc-drive.test.ts b/src/main/ipc/filesystem/filesystem-read-dir-unc-drive.test.ts index 990e705af52..f52d95328ee 100644 --- a/src/main/ipc/filesystem/filesystem-read-dir-unc-drive.test.ts +++ b/src/main/ipc/filesystem/filesystem-read-dir-unc-drive.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import path from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' import { @@ -12,20 +12,20 @@ import { } from './filesystem-test-harness' const diskPreconditionMock = vi.hoisted(() => ({ writeLocalTextFileWithDiskPrecondition: vi.fn() })) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -46,18 +46,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-search-file-paths.test.ts b/src/main/ipc/filesystem/filesystem-search-file-paths.test.ts index 15959e4eda8..43941eaf9e1 100644 --- a/src/main/ipc/filesystem/filesystem-search-file-paths.test.ts +++ b/src/main/ipc/filesystem/filesystem-search-file-paths.test.ts @@ -2,7 +2,7 @@ import { EventEmitter } from 'node:events' import type { ChildProcess } from 'node:child_process' import { beforeEach, describe, expect, it, vi } from 'vitest' import type { Store } from '../../persistence/loading-store/store' -import type * as GitRunner from '../../git/runner' +import type * as GitRunner from '../../git/command-runner/wsl-aware-spawn' import type * as BundledRipgrepPath from '../../ripgrep/bundled-ripgrep-path' import { isFileListingCancellation } from '../../../shared/file-listing-cancellation' import { RipgrepUnavailableError } from '../../../shared/ripgrep-process-availability' @@ -19,7 +19,7 @@ const { wslAwareSpawnMock: vi.fn() })) -vi.mock('../../git/runner', async (importOriginal) => ({ +vi.mock('../../git/command-runner/wsl-aware-spawn', async (importOriginal) => ({ ...(await importOriginal()), wslAwareSpawn: wslAwareSpawnMock })) diff --git a/src/main/ipc/filesystem/filesystem-search-rg-timeout.test.ts b/src/main/ipc/filesystem/filesystem-search-rg-timeout.test.ts index 766ffd82e28..1b27ab70fbe 100644 --- a/src/main/ipc/filesystem/filesystem-search-rg-timeout.test.ts +++ b/src/main/ipc/filesystem/filesystem-search-rg-timeout.test.ts @@ -34,8 +34,13 @@ vi.mock('electron', () => ({ } })) -vi.mock('../../git/runner', () => ({ - gitExecFileAsync: vi.fn(), +vi.mock('../../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: vi.fn() +})) + +vi.mock('../../git/command-runner/wsl-aware-spawn', async (importOriginal) => ({ + ...(await importOriginal>()), wslAwareSpawn: wslAwareSpawnMock })) diff --git a/src/main/ipc/filesystem/filesystem-wsl-stopped-distro-git.test.ts b/src/main/ipc/filesystem/filesystem-wsl-stopped-distro-git.test.ts index 3bb508f0897..22b390d80e2 100644 --- a/src/main/ipc/filesystem/filesystem-wsl-stopped-distro-git.test.ts +++ b/src/main/ipc/filesystem/filesystem-wsl-stopped-distro-git.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { handlers, @@ -15,20 +15,20 @@ import { } from './filesystem-test-harness' const diskPreconditionMock = vi.hoisted(() => ({ writeLocalTextFileWithDiskPrecondition: vi.fn() })) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -52,18 +52,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem-wsl-stopped-distro-reads.test.ts b/src/main/ipc/filesystem/filesystem-wsl-stopped-distro-reads.test.ts index 7716a9946af..dea514a2ada 100644 --- a/src/main/ipc/filesystem/filesystem-wsl-stopped-distro-reads.test.ts +++ b/src/main/ipc/filesystem/filesystem-wsl-stopped-distro-reads.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { handlers, @@ -12,20 +12,20 @@ import { } from './filesystem-test-harness' const diskPreconditionMock = vi.hoisted(() => ({ writeLocalTextFileWithDiskPrecondition: vi.fn() })) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -48,18 +48,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/filesystem.test.ts b/src/main/ipc/filesystem/filesystem.test.ts index 5ead7b05585..c6a6ba5adb0 100644 --- a/src/main/ipc/filesystem/filesystem.test.ts +++ b/src/main/ipc/filesystem/filesystem.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import path from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' import { TRASH_DELETE_FAILED_MESSAGE } from '../../../shared/trash-delete-failure' @@ -25,20 +25,20 @@ import { } from './filesystem-test-harness' const diskPreconditionMock = vi.hoisted(() => ({ writeLocalTextFileWithDiskPrecondition: vi.fn() })) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreeGraph: facade.listWorktreeGraph, - listWorktrees: facade.listWorktrees + listWorktreeGraph: listWorktreesMock, + listWorktrees: listWorktreesMock } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const { listWorktreesMock } = await import('./filesystem-test-harness') return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listWorktreesMock } }) @@ -59,18 +59,62 @@ vi.mock( '../../crash-reporting/crash-breadcrumb-store', async () => (await import('./filesystem-test-harness')).crashBreadcrumbMock ) +vi.mock('../../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: (await import('./filesystem-test-harness')).commitChangesMock +})) + +vi.mock('../../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: (await import('./filesystem-test-harness')).getStatusMock +})) + +vi.mock('../../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: (await import('./filesystem-test-harness')).detectConflictOperationMock, + abortMerge: (await import('./filesystem-test-harness')).abortMergeMock, + abortRebase: (await import('./filesystem-test-harness')).abortRebaseMock +})) + +vi.mock('../../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: (await import('./filesystem-test-harness')).getDiffMock +})) + +vi.mock('../../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: (await import('./filesystem-test-harness')).getBranchCompareMock +})) + +vi.mock('../../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: (await import('./filesystem-test-harness')).getBranchDiffMock +})) + +vi.mock('../../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: (await import('./filesystem-test-harness')).getStagedCommitContextMock +})) + +vi.mock('../../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: (await import('./filesystem-test-harness')).stageFileMock, + bulkStageFiles: (await import('./filesystem-test-harness')).bulkStageFilesMock, + stageWorktreeChanges: (await import('./filesystem-test-harness')).stageWorktreeChangesMock, + unstageFile: (await import('./filesystem-test-harness')).unstageFileMock, + bulkUnstageFiles: (await import('./filesystem-test-harness')).bulkUnstageFilesMock +})) + +vi.mock('../../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + bulkDiscardChanges: (await import('./filesystem-test-harness')).bulkDiscardChangesMock, + discardChanges: (await import('./filesystem-test-harness')).discardChangesMock +})) vi.mock( - '../../git/status', - async () => (await import('./filesystem-test-harness')).gitStatusModuleMock -) -vi.mock( - '../../git/check-ignored-paths', + '../../git/source-control/check-ignored-paths', async () => (await import('./filesystem-test-harness')).gitIgnoredPathsMock ) -vi.mock( - '../../git/worktree', - async () => (await import('./filesystem-test-harness')).gitWorktreeMock -) + vi.mock( '../../text-generation/commit-message-text-generation', async () => (await import('./filesystem-test-harness')).textGenerationModuleMock diff --git a/src/main/ipc/filesystem/git-remote/compare-handlers.ts b/src/main/ipc/filesystem/git-remote/compare-handlers.ts index b7d2937c0b7..5c45c023a71 100644 --- a/src/main/ipc/filesystem/git-remote/compare-handlers.ts +++ b/src/main/ipc/filesystem/git-remote/compare-handlers.ts @@ -3,7 +3,8 @@ import type { GitBranchCompareResult, GitCommitCompareResult } from '../../../../shared/git-diff-compare-types' -import { getBranchCompare, getCommitCompare } from '../../../git/status' +import { getBranchCompare } from '../../../git/source-control/branch-compare' +import { getCommitCompare } from '../../../git/source-control/commit-compare' import { resolveRegisteredWorktreePath } from '../../worktrees/removal/registered-worktree-roots-cache' import { getLocalGitOptionsForRegisteredWorktree } from '../../local-worktree-runtime-options' import { validateFullGitObjectId } from '../filesystem-path-containment' diff --git a/src/main/ipc/filesystem/git-remote/sync-handlers.ts b/src/main/ipc/filesystem/git-remote/sync-handlers.ts index eaa98891c3a..9fd0aeeea5d 100644 --- a/src/main/ipc/filesystem/git-remote/sync-handlers.ts +++ b/src/main/ipc/filesystem/git-remote/sync-handlers.ts @@ -7,7 +7,7 @@ import type { GitPushTarget } from '../../../../shared/worktree/types' import type { GitUpstreamStatus } from '../../../../shared/git-status-types' import { gitFetch } from '../../../git/remote' import { gitSyncForkDefaultBranch } from '../../../git/fork-sync' -import { getUpstreamStatus } from '../../../git/upstream' +import { getUpstreamStatus } from '../../../git/source-control/upstream' import { validateGitPushTarget } from '../../../git/push-target-validation' import { resolveRegisteredWorktreePath } from '../../worktrees/removal/registered-worktree-roots-cache' import { getLocalGitOptionsForRegisteredWorktree } from '../../local-worktree-runtime-options' diff --git a/src/main/ipc/git-status-upstream-ref-watch-request.test.ts b/src/main/ipc/git-status-upstream-ref-watch-request.test.ts index c2e7aa55368..d3ecb854cd9 100644 --- a/src/main/ipc/git-status-upstream-ref-watch-request.test.ts +++ b/src/main/ipc/git-status-upstream-ref-watch-request.test.ts @@ -15,7 +15,10 @@ vi.mock('../wsl/discovery/wsl-background-distro-gate', async (importOriginal) => (await mocks.isWslDistroRunning()) ? 'running' : 'stopped' })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: mocks.gitExec })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: mocks.gitExec +})) vi.mock('./worktrees/removal/registered-worktree-roots-cache', () => ({ resolveRegisteredWorktreePath: mocks.resolveRegisteredPath })) diff --git a/src/main/ipc/git-status-upstream-ref-watch-request.ts b/src/main/ipc/git-status-upstream-ref-watch-request.ts index 9284a588297..e61a6ee54c3 100644 --- a/src/main/ipc/git-status-upstream-ref-watch-request.ts +++ b/src/main/ipc/git-status-upstream-ref-watch-request.ts @@ -1,5 +1,5 @@ import type { Store } from '../persistence/loading-store/store' -import { resolveGitStatusUpstreamRef } from '../git/status-upstream-ref' +import { resolveGitStatusUpstreamRef } from '../git/source-control/status-upstream-ref' import { gitExecFileAsync } from '../git/runner' import { abortSignalWithTimeout } from '../lib/abort-signal-with-timeout' import { resolveRegisteredWorktreePath } from './worktrees/removal/registered-worktree-roots-cache' diff --git a/src/main/ipc/hosted-review.ts b/src/main/ipc/hosted-review.ts index 5d979a20637..d152bec119f 100644 --- a/src/main/ipc/hosted-review.ts +++ b/src/main/ipc/hosted-review.ts @@ -22,7 +22,7 @@ import { getLocalProjectGhExecOptions, getLocalProjectWorktreeGitOptions } from '../workspaces/execution-host/project-runtime-git-options' -import { getWorktreeSharedLinkPaths } from '../git/worktree-shared-directories' +import { getWorktreeSharedLinkPaths } from '../git/worktrees/content-paths/worktree-shared-directories' import { getRepoExecutionHostId, getRepoSshConnectionId } from '../../shared/execution-host' import { getStoredRepoExecutionHostId } from '../workspaces/execution-host/repo-execution-host' import { guardWslUncPathAccess } from '../wsl/filesystem/wsl-unc-access-gate' diff --git a/src/main/ipc/repos-execution-host-catalog.test.ts b/src/main/ipc/repos-execution-host-catalog.test.ts index 66d1cf5ec88..3bfc66e405f 100644 --- a/src/main/ipc/repos-execution-host-catalog.test.ts +++ b/src/main/ipc/repos-execution-host-catalog.test.ts @@ -35,7 +35,10 @@ vi.mock('../git/repo', async (importOriginal) => vi.mock('../git/runner', async (importOriginal) => moduleMocks.gitRunnerModuleMock(reposMocks, await importOriginal()) ) -vi.mock('../git/worktree', () => moduleMocks.gitWorktreeModuleMock(reposMocks)) +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreeGraph: reposMocks.listWorktreeGraphMock +})) vi.mock('./worktrees/removal/registered-worktree-roots-cache', () => moduleMocks.registeredWorktreeRootsCacheModuleMock(reposMocks) ) @@ -44,7 +47,7 @@ vi.mock('../workspaces/creation/worktree-root-preparation', () => ) import { registerRepoHandlers } from './repos' -import { clearGitCapabilityStateForTests } from '../git/git-capability-state' +import { clearGitCapabilityStateForTests } from '../git/command-runner/git-capability-state' import { resetSshProviderAuthorities } from '../ssh/ssh-provider-authority' import { getGitRepoRoot, isGitRepo } from '../git/repo' import { createRepoHandlerHarness, resetProjectGroupMocks } from './repos-remote-test-harness' diff --git a/src/main/ipc/repos-local-add-and-project-setup.test.ts b/src/main/ipc/repos-local-add-and-project-setup.test.ts index b354fa550c2..ecf8ac8aebd 100644 --- a/src/main/ipc/repos-local-add-and-project-setup.test.ts +++ b/src/main/ipc/repos-local-add-and-project-setup.test.ts @@ -35,7 +35,10 @@ vi.mock('../git/repo', async (importOriginal) => vi.mock('../git/runner', async (importOriginal) => moduleMocks.gitRunnerModuleMock(reposMocks, await importOriginal()) ) -vi.mock('../git/worktree', () => moduleMocks.gitWorktreeModuleMock(reposMocks)) +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreeGraph: reposMocks.listWorktreeGraphMock +})) vi.mock('./worktrees/removal/registered-worktree-roots-cache', () => moduleMocks.registeredWorktreeRootsCacheModuleMock(reposMocks) ) @@ -44,7 +47,7 @@ vi.mock('../workspaces/creation/worktree-root-preparation', () => ) import { registerRepoHandlers } from './repos' -import { clearGitCapabilityStateForTests } from '../git/git-capability-state' +import { clearGitCapabilityStateForTests } from '../git/command-runner/git-capability-state' import { resetSshProviderAuthorities } from '../ssh/ssh-provider-authority' import { getGitRepoRoot } from '../git/repo' import { DEFAULT_REPO_BADGE_COLOR } from '../../shared/constants' diff --git a/src/main/ipc/repos-local-clone-lifecycle.test.ts b/src/main/ipc/repos-local-clone-lifecycle.test.ts index e4991b223d3..696f19f5742 100644 --- a/src/main/ipc/repos-local-clone-lifecycle.test.ts +++ b/src/main/ipc/repos-local-clone-lifecycle.test.ts @@ -39,7 +39,10 @@ vi.mock('../git/repo', async (importOriginal) => vi.mock('../git/runner', async (importOriginal) => moduleMocks.gitRunnerModuleMock(reposMocks, await importOriginal()) ) -vi.mock('../git/worktree', () => moduleMocks.gitWorktreeModuleMock(reposMocks)) +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreeGraph: reposMocks.listWorktreeGraphMock +})) vi.mock('./worktrees/removal/registered-worktree-roots-cache', () => moduleMocks.registeredWorktreeRootsCacheModuleMock(reposMocks) ) @@ -48,11 +51,11 @@ vi.mock('../workspaces/creation/worktree-root-preparation', () => ) import { registerRepoHandlers } from './repos' -import { clearGitCapabilityStateForTests } from '../git/git-capability-state' +import { clearGitCapabilityStateForTests } from '../git/command-runner/git-capability-state' import { resetSshProviderAuthorities } from '../ssh/ssh-provider-authority' import { DEFAULT_REPO_BADGE_COLOR } from '../../shared/constants' import { isGitRepoAsync } from '../git/repo' -import { listSubmodulePaths } from '../git/status' +import { listSubmodulePaths } from '../git/source-control/submodule-paths' import { createMockCloneProcess, createRepoHandlerHarness, diff --git a/src/main/ipc/repos-nested-import.test.ts b/src/main/ipc/repos-nested-import.test.ts index 319bc0b15fc..140637372e8 100644 --- a/src/main/ipc/repos-nested-import.test.ts +++ b/src/main/ipc/repos-nested-import.test.ts @@ -38,7 +38,10 @@ vi.mock('../git/repo', async (importOriginal) => vi.mock('../git/runner', async (importOriginal) => moduleMocks.gitRunnerModuleMock(reposMocks, await importOriginal()) ) -vi.mock('../git/worktree', () => moduleMocks.gitWorktreeModuleMock(reposMocks)) +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreeGraph: reposMocks.listWorktreeGraphMock +})) vi.mock('./worktrees/removal/registered-worktree-roots-cache', () => moduleMocks.registeredWorktreeRootsCacheModuleMock(reposMocks) ) @@ -47,7 +50,7 @@ vi.mock('../workspaces/creation/worktree-root-preparation', () => ) import { registerRepoHandlers } from './repos' -import { clearGitCapabilityStateForTests } from '../git/git-capability-state' +import { clearGitCapabilityStateForTests } from '../git/command-runner/git-capability-state' import { resetSshProviderAuthorities } from '../ssh/ssh-provider-authority' import { getGitRepoRoot, isGitRepo } from '../git/repo' import { createRepoHandlerHarness, resetProjectGroupMocks } from './repos-remote-test-harness' diff --git a/src/main/ipc/repos-nested-scan.test.ts b/src/main/ipc/repos-nested-scan.test.ts index 161672d063c..15ae074c798 100644 --- a/src/main/ipc/repos-nested-scan.test.ts +++ b/src/main/ipc/repos-nested-scan.test.ts @@ -38,7 +38,10 @@ vi.mock('../git/repo', async (importOriginal) => vi.mock('../git/runner', async (importOriginal) => moduleMocks.gitRunnerModuleMock(reposMocks, await importOriginal()) ) -vi.mock('../git/worktree', () => moduleMocks.gitWorktreeModuleMock(reposMocks)) +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreeGraph: reposMocks.listWorktreeGraphMock +})) vi.mock('./worktrees/removal/registered-worktree-roots-cache', () => moduleMocks.registeredWorktreeRootsCacheModuleMock(reposMocks) ) @@ -47,7 +50,7 @@ vi.mock('../workspaces/creation/worktree-root-preparation', () => ) import { registerRepoHandlers } from './repos' -import { clearGitCapabilityStateForTests } from '../git/git-capability-state' +import { clearGitCapabilityStateForTests } from '../git/command-runner/git-capability-state' import { resetSshProviderAuthorities } from '../ssh/ssh-provider-authority' import { getGitRepoRoot, isGitRepo } from '../git/repo' import { createRepoHandlerHarness, resetProjectGroupMocks } from './repos-remote-test-harness' diff --git a/src/main/ipc/repos-remote-base-ref-queries.test.ts b/src/main/ipc/repos-remote-base-ref-queries.test.ts index 732441100d4..6a2432b805c 100644 --- a/src/main/ipc/repos-remote-base-ref-queries.test.ts +++ b/src/main/ipc/repos-remote-base-ref-queries.test.ts @@ -36,7 +36,10 @@ vi.mock('../git/repo', async (importOriginal) => vi.mock('../git/runner', async (importOriginal) => moduleMocks.gitRunnerModuleMock(reposMocks, await importOriginal()) ) -vi.mock('../git/worktree', () => moduleMocks.gitWorktreeModuleMock(reposMocks)) +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreeGraph: reposMocks.listWorktreeGraphMock +})) vi.mock('./worktrees/removal/registered-worktree-roots-cache', () => moduleMocks.registeredWorktreeRootsCacheModuleMock(reposMocks) ) @@ -51,7 +54,7 @@ vi.mock('../wsl/filesystem/wsl-unc-access-gate', async (importOriginal) => ({ import { registerRepoHandlers } from './repos' import { WSL_HOSTS_INTERNAL_GATE_ENV } from '../../shared/wsl-host-internal-gate' -import { clearGitCapabilityStateForTests } from '../git/git-capability-state' +import { clearGitCapabilityStateForTests } from '../git/command-runner/git-capability-state' import { resetSshProviderAuthorities } from '../ssh/ssh-provider-authority' import { createRepoHandlerHarness } from './repos-remote-test-harness' import { getBaseRefDefault, getRemoteCount } from '../git/repo' diff --git a/src/main/ipc/repos/clone-path-lock.ts b/src/main/ipc/repos/clone-path-lock.ts index 9bf623d48c1..c46eb95fda7 100644 --- a/src/main/ipc/repos/clone-path-lock.ts +++ b/src/main/ipc/repos/clone-path-lock.ts @@ -1,4 +1,4 @@ -import { runWithGitReadCacheInvalidation } from '../../git/status' +import { runWithGitReadCacheInvalidation } from '../../git/source-control/git-read-cache-invalidation' const cloneInFlightByPath = new Map>() diff --git a/src/main/ipc/watcher-removal-gate.test.ts b/src/main/ipc/watcher-removal-gate.test.ts index 89b6f4ca1fc..f60ecb8892d 100644 --- a/src/main/ipc/watcher-removal-gate.test.ts +++ b/src/main/ipc/watcher-removal-gate.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi } from 'vitest' -import * as worktreePaths from '../git/worktree-path-comparison' +import * as worktreePaths from '../git/worktrees/catalog/worktree-path-comparison' import { acquireWatcherRemovalGate, beginTerminalInstall, diff --git a/src/main/ipc/watcher-removal-gate.ts b/src/main/ipc/watcher-removal-gate.ts index 67db925b1dc..97e59886ec3 100644 --- a/src/main/ipc/watcher-removal-gate.ts +++ b/src/main/ipc/watcher-removal-gate.ts @@ -1,4 +1,4 @@ -import { canonicalWorktreePath } from '../git/worktree-path-comparison' +import { canonicalWorktreePath } from '../git/worktrees/catalog/worktree-path-comparison' import { isPathInsideOrEqual, normalizeRuntimePathForComparison diff --git a/src/main/ipc/workspace-cleanup/workspace-cleanup-git-evidence.ts b/src/main/ipc/workspace-cleanup/workspace-cleanup-git-evidence.ts index 476abaaad09..a8c5c9b8160 100644 --- a/src/main/ipc/workspace-cleanup/workspace-cleanup-git-evidence.ts +++ b/src/main/ipc/workspace-cleanup/workspace-cleanup-git-evidence.ts @@ -9,7 +9,7 @@ import { WorkspaceCleanupScanCancelledError, withWorkspaceCleanupTimeout } from './workspace-cleanup-scan-primitives' -import { getWorktreeSharedLinkPaths } from '../../git/worktree-shared-directories' +import { getWorktreeSharedLinkPaths } from '../../git/worktrees/content-paths/worktree-shared-directories' import { resolveWorkspaceCleanupWorktreeGitRoute, type WorkspaceCleanupGitRoute diff --git a/src/main/ipc/worktree-logic.test.ts b/src/main/ipc/worktree-logic.test.ts index e5ae26cb77a..9e21efd1a6f 100644 --- a/src/main/ipc/worktree-logic.test.ts +++ b/src/main/ipc/worktree-logic.test.ts @@ -27,7 +27,7 @@ import { computeValidatedBranchName } from './worktree-branch-name' import { mergeWorktree } from './worktree-metadata-merge' -import { areWorktreePathsEqual } from '../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../git/worktrees/catalog/worktree-path-comparison' describe('sanitizeWorktreeName', () => { it('replaces spaces with hyphens', () => { diff --git a/src/main/ipc/worktree-push-target-reconciliation.ts b/src/main/ipc/worktree-push-target-reconciliation.ts index 96b47e7c05b..da3d2ca8ea2 100644 --- a/src/main/ipc/worktree-push-target-reconciliation.ts +++ b/src/main/ipc/worktree-push-target-reconciliation.ts @@ -1,7 +1,7 @@ // Sweep all fork remotes with cleanup's shared predicates to reclaim leaks from legacy metadata or external worktree removal. import { gitExecFileAsync } from '../git/runner' -import { listWorktrees } from '../git/worktree' +import { listWorktrees } from '../git/worktrees/catalog/worktree-scan-cache' import type { GitPushTarget } from '../../shared/worktree/types' import { WORKTREE_ID_SEPARATOR, worktreeIdentityKey } from '../../shared/worktree/id' import { parseGitRemoteFetchUrls } from '../../shared/git-remote-url-index' diff --git a/src/main/ipc/worktree-push-target-refspec-migration.ts b/src/main/ipc/worktree-push-target-refspec-migration.ts index aeef482ca58..7b61aecdab4 100644 --- a/src/main/ipc/worktree-push-target-refspec-migration.ts +++ b/src/main/ipc/worktree-push-target-refspec-migration.ts @@ -9,7 +9,7 @@ import { pruneUntrackedForkRemoteRefs, remoteHasUrl, wildcardForkFetchRefspec -} from '../git/fork-remote-refspec' +} from '../git/refs/fork-remotes/fork-remote-refspec' import { getRepoIdFromWorktreeId } from '../../shared/worktree/id' import { iterateProcessOutputLines } from '../../shared/process-output-field-scanner' import type { GitRemoteExec, WorktreePushTargetStore } from './worktree-push-target-cleanup' diff --git a/src/main/ipc/worktree-push-target-setup.ts b/src/main/ipc/worktree-push-target-setup.ts index cf74380786e..142c3731293 100644 --- a/src/main/ipc/worktree-push-target-setup.ts +++ b/src/main/ipc/worktree-push-target-setup.ts @@ -5,7 +5,7 @@ import { sameGitHubRemoteUrl, type GitRemoteExec } from './worktree-push-target- import { buildNarrowForkFetchRefspec, ensureRemoteTracksBranchNarrowly -} from '../git/fork-remote-refspec' +} from '../git/refs/fork-remotes/fork-remote-refspec' // One remote -v avoids a subprocess per configured remote (#17914). export async function findRemoteForUrl( diff --git a/src/main/ipc/worktree-remote-push-target-materialization.test.ts b/src/main/ipc/worktree-remote-push-target-materialization.test.ts index 63052a86e7a..447b1ade257 100644 --- a/src/main/ipc/worktree-remote-push-target-materialization.test.ts +++ b/src/main/ipc/worktree-remote-push-target-materialization.test.ts @@ -3,7 +3,10 @@ import type { GitPushTarget } from '../../shared/worktree/types' import type { WorktreePushTargetStore } from './worktree-push-target-cleanup' const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) import { ipcGitWorktreeTarget, materializeWorktreePushTargetRemote } from './worktree-remote' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' diff --git a/src/main/ipc/worktree-remote.ts b/src/main/ipc/worktree-remote.ts index c2082bd4831..2f0c85a00ea 100644 --- a/src/main/ipc/worktree-remote.ts +++ b/src/main/ipc/worktree-remote.ts @@ -2,7 +2,7 @@ import { readableWslDistroHoldText } from '../../shared/wsl-distro-stopped-hold' import { canCheckoutExistingLocalBranch } from '../runtime/runtime-worktree-create-git' /* eslint-disable max-lines */ -import { worktreeCreateGit } from '../git/worktree-create-git-executor' +import { worktreeCreateGit } from '../git/worktrees/creation/worktree-create-git-executor' import { getStoredRepoExecutionHostId } from '../workspaces/execution-host/repo-execution-host' import type { BrowserWindow } from 'electron' import { existsSync } from 'node:fs' @@ -27,8 +27,12 @@ import type { WorktreeHeadIdentity } from '../../shared/worktree/types' import { getPRForBranch } from '../github/client' -import { addWorktree, addSparseWorktree } from '../git/worktree' -import type { AddWorktreeOptions, AddWorktreeResult } from '../git/worktree' +import { addWorktree } from '../git/worktrees/creation/worktree-add' +import { addSparseWorktree } from '../git/worktrees/creation/worktree-sparse-add' +import type { + AddWorktreeOptions, + AddWorktreeResult +} from '../git/worktrees/worktree-operation-options' import { consumePreparedWorktreeCreate, type PreparationRearmHolder @@ -36,7 +40,7 @@ import { import { getBranchConflictKind, resolveDefaultBaseRefWithLocalGit } from '../git/repo' import { WorktreeCreateCollisionError } from '../../shared/new-workspace/worktree-create-collision' import { resolveLocalGitUsername } from '../git/git-username' -import { hasLocalWorktreeBaseRef } from '../git/worktree-base-ref-probe' +import { hasLocalWorktreeBaseRef } from '../git/worktrees/creation/worktree-base-ref-probe' import { resolveWorktreeCreateBase } from '../workspaces/creation/worktree-create-base' import { getHostedReviewForBranch } from '../source-control/hosted-review' import type { ForgeProviderId } from '../source-control/forge-provider' @@ -107,7 +111,7 @@ import { buildNarrowForkFetchRefspec, ensureRemoteTracksBranchNarrowly, forkRemoteTrackingRefExists -} from '../git/fork-remote-refspec' +} from '../git/refs/fork-remotes/fork-remote-refspec' import { migrateForkRemoteRefspecs } from './worktree-push-target-refspec-migration' import { registerCreatedWorktreeRoot, @@ -119,8 +123,8 @@ import { createWorktreeSharedPaths } from './worktree-symlinks' import { formatWorktreeIncludeCopyWarning } from './worktree-include-copy-budget' -import { resolveWorktreeIncludePaths } from '../git/worktree-include-file' -import { resolveWorktreeSharedDirectories } from '../git/worktree-shared-directories' +import { resolveWorktreeIncludePaths } from '../git/worktrees/content-paths/worktree-include-file' +import { resolveWorktreeSharedDirectories } from '../git/worktrees/content-paths/worktree-shared-directories' import { normalizeSparseDirectories } from './sparse-checkout-directories' import { attributedSparsePresetId } from './sparse-preset-attribution' import { diff --git a/src/main/ipc/worktree-symlink-reconciliation.real.test.ts b/src/main/ipc/worktree-symlink-reconciliation.real.test.ts index b8c464dbf3f..9aff1b38798 100644 --- a/src/main/ipc/worktree-symlink-reconciliation.real.test.ts +++ b/src/main/ipc/worktree-symlink-reconciliation.real.test.ts @@ -3,7 +3,7 @@ import { mkdtemp, mkdir, realpath, rm, symlink, writeFile } from 'node:fs/promis import { join } from 'node:path' import { afterEach, describe, expect, it } from 'vitest' import { findCreatedWorktree } from './created-worktree-reconciliation' -import { areWorktreePathsEqual } from '../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../git/worktrees/catalog/worktree-path-comparison' type ListedWorktree = { path: string; branch?: string } diff --git a/src/main/ipc/worktree-symlinks.test.ts b/src/main/ipc/worktree-symlinks.test.ts index cd96e6b8046..00048f391db 100644 --- a/src/main/ipc/worktree-symlinks.test.ts +++ b/src/main/ipc/worktree-symlinks.test.ts @@ -20,10 +20,10 @@ import { createWorktreeSharedPaths, createWorktreeSymlinks, worktreeSymlinkTypeCandidates, - findExistingWorktreeSymlinkPaths, removeWorktreeLinkedPaths, removeWorktreeSymlinks } from './worktree-symlinks' +import { findExistingWorktreeSymlinkPaths } from '../git/worktrees/content-paths/worktree-symlink-detection' type WorktreeLinkedPathOptionsForTest = NonNullable[3]> type ApfsCloneDepsForTest = NonNullable diff --git a/src/main/ipc/worktree-symlinks.ts b/src/main/ipc/worktree-symlinks.ts index bc31bdfa367..75c3a22e449 100644 --- a/src/main/ipc/worktree-symlinks.ts +++ b/src/main/ipc/worktree-symlinks.ts @@ -14,10 +14,7 @@ import { type SkippedWorktreeCopyPath, type WorktreeCopyBudget } from './worktree-include-copy-budget' -import { - findExistingWorktreeSymlinkPaths, - getSafeRelativePath -} from '../git/worktree-symlink-detection' +import { getSafeRelativePath } from '../git/worktrees/content-paths/worktree-symlink-detection' type WorktreeLinkedPathOptions = { platform?: NodeJS.Platform @@ -320,8 +317,6 @@ export async function removeWorktreeLinkedPaths( } } -export { findExistingWorktreeSymlinkPaths } - /** Unlink configured symlinks before Git removal so shared paths do not look untracked. * * Safety: only removes entries that are actually symbolic links. A regular diff --git a/src/main/ipc/worktrees-authoritative-local-metadata-pruning.test.ts b/src/main/ipc/worktrees-authoritative-local-metadata-pruning.test.ts index 00f57a4a340..51ad53f1aef 100644 --- a/src/main/ipc/worktrees-authoritative-local-metadata-pruning.test.ts +++ b/src/main/ipc/worktrees-authoritative-local-metadata-pruning.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import type { GitWorktreeInfo } from '../../shared/worktree/types' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' @@ -24,12 +24,13 @@ import { const localWorktreePathPresenceMock = vi.hoisted(() => vi.fn()) // The WSL distros these fixtures route through count as running, so the boot gate lets Git run. -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) @@ -40,16 +41,59 @@ vi.mock('../wsl/discovery/wsl-background-distro-gate', async (importOriginal) => vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -71,6 +115,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-automation-create-terminals.test.ts b/src/main/ipc/worktrees-automation-create-terminals.test.ts index 6cde16aed88..c1f22145881 100644 --- a/src/main/ipc/worktrees-automation-create-terminals.test.ts +++ b/src/main/ipc/worktrees-automation-create-terminals.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { listWorktreesMock, @@ -10,28 +10,72 @@ import { import { handlers, setupWorktreeHandlers } from './worktrees-test-harness' import { createdWorktreeList } from './worktrees-test-fixtures' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -53,6 +97,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-background-removal.test.ts b/src/main/ipc/worktrees-background-removal.test.ts index 195902c38f5..a8723fa03b4 100644 --- a/src/main/ipc/worktrees-background-removal.test.ts +++ b/src/main/ipc/worktrees-background-removal.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { addWorktreeMock, @@ -16,28 +16,72 @@ import { } from '../workspaces/removal/worktree-background-removal' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -59,6 +103,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-canonical-ssh-listing.test.ts b/src/main/ipc/worktrees-canonical-ssh-listing.test.ts index d61c7e0758e..99587150352 100644 --- a/src/main/ipc/worktrees-canonical-ssh-listing.test.ts +++ b/src/main/ipc/worktrees-canonical-ssh-listing.test.ts @@ -19,7 +19,7 @@ vi.mock('electron', () => ({ }, app: { getPath: () => '/test' } })) -vi.mock('../git/runner', async (original) => ({ +vi.mock('../git/command-runner/git-exec-file', async (original) => ({ ...(await original>()), gitExecFileAsync: mocks.git })) diff --git a/src/main/ipc/worktrees-create-event-timing.test.ts b/src/main/ipc/worktrees-create-event-timing.test.ts index ab10fe79e6f..17e1266f0ef 100644 --- a/src/main/ipc/worktrees-create-event-timing.test.ts +++ b/src/main/ipc/worktrees-create-event-timing.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { addWorktreeMock, @@ -8,7 +8,7 @@ import { } from './worktrees-test-module-mocks' import { handlers, mainWindow, setupWorktreeHandlers, store } from './worktrees-test-harness' import { beginPreparationWork } from '../workspaces/creation/worktree-create-concurrency' -import { addWorktree } from '../git/worktree' +import { addWorktree } from '../git/worktrees/creation/worktree-add' const { trackMock, probeHookMock, telemetryEnabledMock } = vi.hoisted(() => ({ trackMock: vi.fn<(name: string, props: Record) => void>(), @@ -16,28 +16,72 @@ const { trackMock, probeHookMock, telemetryEnabledMock } = vi.hoisted(() => ({ telemetryEnabledMock: vi.fn(() => true) })) -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -59,6 +103,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) @@ -116,7 +166,7 @@ vi.mock('../telemetry/client', () => ({ track: trackMock, isTelemetryEnabled: telemetryEnabledMock })) -vi.mock('../git/create-event-repo-probe', () => ({ +vi.mock('../git/worktrees/creation/create-event-repo-probe', () => ({ probeCreateEventRepoFacts: probeHookMock })) diff --git a/src/main/ipc/worktrees-create-label-only-first-work.test.ts b/src/main/ipc/worktrees-create-label-only-first-work.test.ts index 2627a07fb06..37488a396de 100644 --- a/src/main/ipc/worktrees-create-label-only-first-work.test.ts +++ b/src/main/ipc/worktrees-create-label-only-first-work.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { generatedNameCreateRequest, renameCreatedWorktreeOnFirstWork, @@ -10,12 +10,13 @@ import { describeCreatedWorktreeMock, gitExecFileAsyncMock } from './worktrees-t import { handlers, setupWorktreeHandlers, store } from './worktrees-test-harness' import type { WorktreeMeta } from '../../shared/worktree/meta-types' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) @@ -33,16 +34,59 @@ vi.mock('../text-generation/commit-message-agent-environment', () => ({ vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -64,6 +108,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-create-metadata-persistence.test.ts b/src/main/ipc/worktrees-create-metadata-persistence.test.ts index 4afb1229337..b6e4917eb09 100644 --- a/src/main/ipc/worktrees-create-metadata-persistence.test.ts +++ b/src/main/ipc/worktrees-create-metadata-persistence.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { REVIEW_HEAD_FETCH_TIMEOUT_MS } from '../../shared/review-head-tracking-ref' import { @@ -54,12 +54,13 @@ const WORKTREE_HANDLER_CHANNELS = [ 'hooks:writeIssueCommand' ] as const -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) @@ -77,16 +78,59 @@ vi.mock('../text-generation/commit-message-agent-environment', () => ({ vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -108,6 +152,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-create-registry.test.ts b/src/main/ipc/worktrees-create-registry.test.ts index 10883668af5..277927fcc6c 100644 --- a/src/main/ipc/worktrees-create-registry.test.ts +++ b/src/main/ipc/worktrees-create-registry.test.ts @@ -1,15 +1,16 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { addWorktreeMock, listWorktreesMock } from './worktrees-test-module-mocks' import { handlers, mainWindow, setupWorktreeHandlers } from './worktrees-test-harness' import type { WorktreeRuntimeStub } from './worktrees-test-runtime-stub' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) @@ -17,16 +18,59 @@ vi.mock('../../shared/sidebar-inputs-switch', () => ({ ORCA_SIDEBAR_INPUTS_IS_MA vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -48,6 +92,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-delete-pty-teardown.test.ts b/src/main/ipc/worktrees-delete-pty-teardown.test.ts index 3b4060dce1d..05acafb63b2 100644 --- a/src/main/ipc/worktrees-delete-pty-teardown.test.ts +++ b/src/main/ipc/worktrees-delete-pty-teardown.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { listWorktreesMock, @@ -15,28 +15,72 @@ import { mockKnownFeatureWorktree } from './worktrees-test-fixtures' import { SshHostNotServedError } from '../providers/ssh-host-not-served-error' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -58,6 +102,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-detected-scan-cache.test.ts b/src/main/ipc/worktrees-detected-scan-cache.test.ts index 0a44d56e596..56ef1beefc4 100644 --- a/src/main/ipc/worktrees-detected-scan-cache.test.ts +++ b/src/main/ipc/worktrees-detected-scan-cache.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { resolve } from 'node:path' import type { GitWorktreeInfo, Worktree } from '../../shared/worktree/types' @@ -10,12 +10,13 @@ import { handlers, mainWindow, setupWorktreeHandlers, store } from './worktrees- import { makeWorktreeMeta } from './worktrees-test-fixtures' // The WSL distros these fixtures route through count as running, so the boot gate lets Git run. -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) @@ -26,16 +27,59 @@ vi.mock('../wsl/discovery/wsl-background-distro-gate', async (importOriginal) => vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -57,6 +101,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-discovery-metadata-backfill.test.ts b/src/main/ipc/worktrees-discovery-metadata-backfill.test.ts index 8b85d11f60b..671fb4bea57 100644 --- a/src/main/ipc/worktrees-discovery-metadata-backfill.test.ts +++ b/src/main/ipc/worktrees-discovery-metadata-backfill.test.ts @@ -1,32 +1,76 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { listWorktreesMock } from './worktrees-test-module-mocks' import { handlers, setupWorktreeHandlers, store } from './worktrees-test-harness' import { makeWorktreeMeta, expectDetectedWorktreeListResult } from './worktrees-test-fixtures' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -48,6 +92,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-existing-branch-checkout.test.ts b/src/main/ipc/worktrees-existing-branch-checkout.test.ts index ee07ab64ee3..f5c44808ca7 100644 --- a/src/main/ipc/worktrees-existing-branch-checkout.test.ts +++ b/src/main/ipc/worktrees-existing-branch-checkout.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { listWorktreesMock, @@ -10,28 +10,72 @@ import { import { handlers, setupWorktreeHandlers } from './worktrees-test-harness' import type { WorktreeRuntimeStub } from './worktrees-test-runtime-stub' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -53,6 +97,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-failed-removal.test.ts b/src/main/ipc/worktrees-failed-removal.test.ts index deac5aaa4ad..7496f270352 100644 --- a/src/main/ipc/worktrees-failed-removal.test.ts +++ b/src/main/ipc/worktrees-failed-removal.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' // Mocked desktop removal failures; runtime-failed-local-worktree-removal.test.ts covers real Git and filesystem behavior. import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { @@ -11,9 +11,9 @@ import { handlers, setupWorktreeHandlers, store } from './worktrees-test-harness import { makeWorktreeMeta, mockKnownFeatureWorktree } from './worktrees-test-fixtures' import type { RemoveWorktreeResult } from '../../shared/worktree/create-types' import type { DetectedWorktree, DetectedWorktreeListResult } from '../../shared/worktree/types' -import { finishUnregisteredWorktreeRemoval } from '../git/worktree-removal' +import { finishUnregisteredWorktreeRemoval } from '../git/worktrees/removal/worktree-removal' import { worktreeCheckoutExists } from '../workspaces/removal/worktree-removal-table' -import type * as WorktreeRemovalModule from '../git/worktree-removal' +import type * as WorktreeRemovalModule from '../git/worktrees/removal/worktree-removal' import type * as WorktreeRemovalTable from '../workspaces/removal/worktree-removal-table' import type * as WorktreeRemovalLeftover from '../workspaces/removal/worktree-removal-leftover' import { removeLocalWorktreePath } from '../workspaces/removal/local-worktree-filesystem' @@ -26,28 +26,67 @@ import { } from '../workspaces/removal/worktree-background-removal' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -69,6 +108,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) @@ -122,9 +167,10 @@ vi.mock('./pty/provider/state-cleanup', async () => (await import('./worktrees-test-module-mocks')).ptyStateCleanupModuleMock() ) -vi.mock('../git/worktree-removal', async (importOriginal) => ({ +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ ...(await importOriginal()), - finishUnregisteredWorktreeRemoval: vi.fn(async () => ({})) + finishUnregisteredWorktreeRemoval: vi.fn(async () => ({})), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock })) vi.mock('../workspaces/removal/worktree-removal-table', async (importOriginal) => ({ ...(await importOriginal()), diff --git a/src/main/ipc/worktrees-forget-local.test.ts b/src/main/ipc/worktrees-forget-local.test.ts index 7e6e6c716da..a26a90ba491 100644 --- a/src/main/ipc/worktrees-forget-local.test.ts +++ b/src/main/ipc/worktrees-forget-local.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { resolve } from 'node:path' import { @@ -20,28 +20,72 @@ import type { WorktreeRuntimeStub } from './worktrees-test-runtime-stub' import { SshHostNotServedError } from '../providers/ssh-host-not-served-error' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -63,6 +107,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-issue-command-overrides.test.ts b/src/main/ipc/worktrees-issue-command-overrides.test.ts index 209ebe8669f..4994c83d312 100644 --- a/src/main/ipc/worktrees-issue-command-overrides.test.ts +++ b/src/main/ipc/worktrees-issue-command-overrides.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' @@ -9,28 +9,72 @@ import { addWorktreeMock, listWorktreesMock } from './worktrees-test-module-mock import { handlers, setupWorktreeHandlers, store } from './worktrees-test-harness' import { SshHostNotServedError } from '../providers/ssh-host-not-served-error' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -52,6 +96,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-lineage-hydration.test.ts b/src/main/ipc/worktrees-lineage-hydration.test.ts index 38ef5abdccf..ff7691ab5c6 100644 --- a/src/main/ipc/worktrees-lineage-hydration.test.ts +++ b/src/main/ipc/worktrees-lineage-hydration.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import type { WorktreeMeta } from '../../shared/worktree/meta-types' import { listWorktreesMock } from './worktrees-test-module-mocks' @@ -9,28 +9,72 @@ import { type HostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -52,6 +96,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-listing-fallback-rows.test.ts b/src/main/ipc/worktrees-listing-fallback-rows.test.ts index 9bc2e6c74a2..754121d8064 100644 --- a/src/main/ipc/worktrees-listing-fallback-rows.test.ts +++ b/src/main/ipc/worktrees-listing-fallback-rows.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { listWorktreesMock } from './worktrees-test-module-mocks' import { handlers, setupWorktreeHandlers, store } from './worktrees-test-harness' @@ -8,28 +8,72 @@ import type { Store } from '../persistence/loading-store/store' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' import type { DetectedWorktree } from '../../shared/worktree/types' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -51,6 +95,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-local-base-ref-resolution.test.ts b/src/main/ipc/worktrees-local-base-ref-resolution.test.ts index 429cd7915ce..7d44783c086 100644 --- a/src/main/ipc/worktrees-local-base-ref-resolution.test.ts +++ b/src/main/ipc/worktrees-local-base-ref-resolution.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { resolveGitAdmissionTier } from '../git/command-runner/git-operation-executor' import { beforeEach, describe, expect, it, vi } from 'vitest' import type { CreateWorktreeResult } from '../../shared/worktree/create-types' @@ -13,28 +13,72 @@ import { handlers, setupWorktreeHandlers, store } from './worktrees-test-harness import type { WorktreeRuntimeStub } from './worktrees-test-runtime-stub' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -56,6 +100,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-local-create-flow.test.ts b/src/main/ipc/worktrees-local-create-flow.test.ts index e002ded6185..a5d6d106cd9 100644 --- a/src/main/ipc/worktrees-local-create-flow.test.ts +++ b/src/main/ipc/worktrees-local-create-flow.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { resolve } from 'node:path' import { SETUP_AGENT_SEQUENCE_SETUP_SCRIPT_ENV } from '../../shared/setup-agent-sequencing' @@ -28,28 +28,72 @@ import { type HostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -71,6 +115,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-local-create-path-claim.test.ts b/src/main/ipc/worktrees-local-create-path-claim.test.ts index 1baac3f5761..3425eb0d690 100644 --- a/src/main/ipc/worktrees-local-create-path-claim.test.ts +++ b/src/main/ipc/worktrees-local-create-path-claim.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { basename } from 'node:path' import { beforeEach, describe, expect, it, vi } from 'vitest' import { creatureNameTier } from '../../shared/worktree/retired-name-registry' @@ -6,28 +6,72 @@ import type * as WorktreeLogic from './worktree-logic' import { addWorktreeMock, describeCreatedWorktreeMock } from './worktrees-test-module-mocks' import { handlers, setupWorktreeHandlers } from './worktrees-test-harness' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -49,6 +93,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-mutation-scan-generation-order.test.ts b/src/main/ipc/worktrees-mutation-scan-generation-order.test.ts index fef05d009bb..9d7a4e70277 100644 --- a/src/main/ipc/worktrees-mutation-scan-generation-order.test.ts +++ b/src/main/ipc/worktrees-mutation-scan-generation-order.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' // Bump catalog generation before post-mutation awaits so clients can reject listings from before a create or removal. import { beforeEach, describe, expect, it, vi } from 'vitest' import { isWorktreeCatalogVersion } from '../../shared/worktree/catalog-version' @@ -12,28 +12,72 @@ import { handlers, setupWorktreeHandlers, store } from './worktrees-test-harness import { mockKnownFeatureWorktree } from './worktrees-test-fixtures' import type { WorktreeRuntimeStub } from './worktrees-test-runtime-stub' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -55,6 +99,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-orphan-directory-cleanup.test.ts b/src/main/ipc/worktrees-orphan-directory-cleanup.test.ts index 01f45c10719..54d3a3dfab6 100644 --- a/src/main/ipc/worktrees-orphan-directory-cleanup.test.ts +++ b/src/main/ipc/worktrees-orphan-directory-cleanup.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { lstat, mkdir, mkdtemp, readFile, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' @@ -16,28 +16,72 @@ import { makeWorktreeMeta, mockKnownFeatureWorktree } from './worktrees-test-fix import type { WorktreeRuntimeStub } from './worktrees-test-runtime-stub' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -59,6 +103,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-removal-recovery.test.ts b/src/main/ipc/worktrees-removal-recovery.test.ts index b2bc20b8678..c44067ce46b 100644 --- a/src/main/ipc/worktrees-removal-recovery.test.ts +++ b/src/main/ipc/worktrees-removal-recovery.test.ts @@ -1,12 +1,15 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeRemovalModule from '../git/worktrees/removal/worktree-removal' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { execFile } from 'node:child_process' import { promisify } from 'node:util' import * as diskFs from 'node:fs/promises' import * as gitRunner from '../git/runner' -import { removeWorktree } from '../git/worktree' -import { removeWorktree as removeNativeWorktree } from '../git/worktree-removal' -import { readTranslatedWorktreeGraph } from '../git/worktree-list-reader' +import { removeWorktree } from '../git/worktrees/removal/worktree-removal' +const { removeWorktree: removeNativeWorktree } = await vi.importActual< + typeof WorktreeRemovalModule +>('../git/worktrees/removal/worktree-removal') +import { readTranslatedWorktreeGraph } from '../git/worktrees/catalog/worktree-list-reader' import { toHostFilesystemPath } from '../filesystem/host-tree-removal' import { removeTree } from '../../shared/windows-transient-lock-removal' import * as scopedRootsInvalidation from './worktrees/removal/registered-worktree-roots-scoped-invalidation' @@ -44,28 +47,71 @@ import { makeWorktreeMeta, mockKnownFeatureWorktree } from './worktrees-test-fix import type { WorktreeRuntimeStub } from './worktrees-test-runtime-stub' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock })) -vi.mock('../git/runner', async (importOriginal) => ({ - ...(await importOriginal()), - ...(await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() @@ -88,6 +134,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) @@ -141,7 +193,9 @@ vi.mock('./pty/provider/state-cleanup', async () => (await import('./worktrees-test-module-mocks')).ptyStateCleanupModuleMock() ) -const actualGitRunner = await vi.importActual('../git/runner') +const actualGitRunner = await vi.importActual( + '../git/command-runner/git-exec-file' +) const anyCatalogVersion = { epoch: expect.any(String), sequence: expect.any(Number) } describe('registerWorktreeHandlers', () => { diff --git a/src/main/ipc/worktrees-remove-archive-hooks.test.ts b/src/main/ipc/worktrees-remove-archive-hooks.test.ts index 27563e75031..d141f32c145 100644 --- a/src/main/ipc/worktrees-remove-archive-hooks.test.ts +++ b/src/main/ipc/worktrees-remove-archive-hooks.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { removeWorktreeLinkedPathsMock, @@ -21,28 +21,72 @@ import type { RemoveWorktreeResult } from '../../shared/worktree/create-types' import type { RemoveWorktreeArgs } from './worktrees/ipc-context-schemas' import type { WorktreeRuntimeStub } from './worktrees-test-runtime-stub' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -64,6 +108,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-remove-preflight.test.ts b/src/main/ipc/worktrees-remove-preflight.test.ts index da550722985..902a0861940 100644 --- a/src/main/ipc/worktrees-remove-preflight.test.ts +++ b/src/main/ipc/worktrees-remove-preflight.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import * as scopedRootsInvalidation from './worktrees/removal/registered-worktree-roots-scoped-invalidation' import * as authorizedRootsCache from './worktrees/removal/registered-worktree-roots-cache' @@ -16,28 +16,72 @@ import { handlers, setupWorktreeHandlers, store } from './worktrees-test-harness import { mockKnownFeatureWorktree } from './worktrees-test-fixtures' import type { WorktreeRuntimeStub } from './worktrees-test-runtime-stub' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -59,6 +103,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-setup-launch-sparse-checkout.test.ts b/src/main/ipc/worktrees-setup-launch-sparse-checkout.test.ts index 694ab506cfc..d4b9935c5e3 100644 --- a/src/main/ipc/worktrees-setup-launch-sparse-checkout.test.ts +++ b/src/main/ipc/worktrees-setup-launch-sparse-checkout.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { listWorktreesMock, @@ -13,28 +13,72 @@ import { handlers, mainWindow, setupWorktreeHandlers, store } from './worktrees- import { createdWorktreeList } from './worktrees-test-fixtures' import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -56,6 +100,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-ssh-pr-head-fetch.test.ts b/src/main/ipc/worktrees-ssh-pr-head-fetch.test.ts index 2e2a32eb002..03dbbd333e2 100644 --- a/src/main/ipc/worktrees-ssh-pr-head-fetch.test.ts +++ b/src/main/ipc/worktrees-ssh-pr-head-fetch.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import { REVIEW_HEAD_FETCH_TIMEOUT_MS } from '../../shared/review-head-tracking-ref' import { gitExecFileAsyncMock } from './worktrees-test-module-mocks' @@ -6,28 +6,72 @@ import { gitExecFileAsyncMock } from './worktrees-test-module-mocks' import { handlers, harnessRepo, setupWorktreeHandlers, store } from './worktrees-test-harness' import { ORIGIN_HEAD_COMPONENT, ORIGIN_REMOTE_URL } from './worktrees-test-fixtures' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -49,6 +93,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-ssh-repo-owner-resolution.test.ts b/src/main/ipc/worktrees-ssh-repo-owner-resolution.test.ts index 2a97f23e27d..70ac4e6d675 100644 --- a/src/main/ipc/worktrees-ssh-repo-owner-resolution.test.ts +++ b/src/main/ipc/worktrees-ssh-repo-owner-resolution.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import type { Worktree } from '../../shared/worktree/types' import type { ProviderRequestId } from '../../shared/detected-worktree-provider-contract' @@ -20,28 +20,72 @@ import { type HostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -63,6 +107,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees-test-harness.ts b/src/main/ipc/worktrees-test-harness.ts index ea49448b1b1..c5ad9af6ec9 100644 --- a/src/main/ipc/worktrees-test-harness.ts +++ b/src/main/ipc/worktrees-test-harness.ts @@ -4,7 +4,7 @@ import { } from './worktrees/removal/registered-worktree-roots-cache' import { registerWorktreeHandlers } from './worktrees' import { __resetDetectedWorktreeScanCacheForTests } from './worktrees/listing/detected-worktree-scan-cache' -import { clearConfiguredWorktreeSharedDirectoriesCacheForTests } from '../git/worktree-shared-directories' +import { clearConfiguredWorktreeSharedDirectoriesCacheForTests } from '../git/worktrees/content-paths/worktree-shared-directories' import { resetRetirementCollisionKeyCacheForTests } from '../workspaces/removal/retirement/worktree-name-retirement' import { resetSshProviderAuthorities } from '../ssh/ssh-provider-authority' import { createWorktreeRuntimeStub, type WorktreeRuntimeStub } from './worktrees-test-runtime-stub' diff --git a/src/main/ipc/worktrees-test-module-mocks.ts b/src/main/ipc/worktrees-test-module-mocks.ts index 03964646e2a..0316a7a983f 100644 --- a/src/main/ipc/worktrees-test-module-mocks.ts +++ b/src/main/ipc/worktrees-test-module-mocks.ts @@ -1,5 +1,5 @@ import { type Mock, vi } from 'vitest' -import type { describeCreatedWorktree } from '../git/worktree' +import type { describeCreatedWorktree } from '../git/worktrees/catalog/worktree-listing' import type { computeWorktreePath } from './worktree-logic' import type { HandlerMap } from './worktrees-test-ipc-surface' diff --git a/src/main/ipc/worktrees-windows.test.ts b/src/main/ipc/worktrees-windows.test.ts index 7413f15529a..576a29e5b60 100644 --- a/src/main/ipc/worktrees-windows.test.ts +++ b/src/main/ipc/worktrees-windows.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { beforeEach, describe, expect, it, vi } from 'vitest' import type * as GitUsernameModule from '../git/git-username' @@ -62,12 +62,13 @@ const { deleteWorktreeHistoryDirMock: vi.fn() })) -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = await getWorktreeOwnerMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty, + listWorktreesSharedStrict: (await getWorktreeOwnerMocks()).listWorktreesSharedStrict } }) @@ -78,24 +79,51 @@ vi.mock('electron', () => ({ } })) -vi.mock('../git/worktree', () => ({ - listWorktrees: listWorktreesMock, - listWorktreesStrict: listWorktreesMock, - listWorktreesSharedStrict: listWorktreesMock, - listWorktreesSharedStrictAllowingTrueEmpty: listWorktreesMock, - describeCreatedWorktree: vi.fn().mockResolvedValue(undefined), - assertWorktreeCleanForRemoval: assertWorktreeCleanForRemovalMock, - addWorktree: addWorktreeMock, - removeWorktree: removeWorktreeMock -})) +const { getWorktreeOwnerMocks } = vi.hoisted(() => { + function createWorktreeOwnerMocks() { + return (() => ({ + listWorktrees: listWorktreesMock, + listWorktreesStrict: listWorktreesMock, + listWorktreesSharedStrict: listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: listWorktreesMock, + describeCreatedWorktree: vi.fn().mockResolvedValue(undefined), + assertWorktreeCleanForRemoval: assertWorktreeCleanForRemovalMock, + addWorktree: addWorktreeMock, + removeWorktree: removeWorktreeMock + }))() + } + let fixture: ReturnType | undefined + return { getWorktreeOwnerMocks: () => (fixture ??= createWorktreeOwnerMocks()) } +}) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: listWorktreesMock + assertWorktreeCleanForRemoval: (await getWorktreeOwnerMocks()).assertWorktreeCleanForRemoval })) -vi.mock('../git/runner', () => ({ - gitExecFileAsync: vi.fn().mockResolvedValue({ stdout: '', stderr: '' }), +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await getWorktreeOwnerMocks()).addWorktree +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await getWorktreeOwnerMocks()).removeWorktree +})) + +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: listWorktreesMock, + describeCreatedWorktree: (await getWorktreeOwnerMocks()).describeCreatedWorktree +})) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: vi.fn().mockResolvedValue({ stdout: '', stderr: '' }) +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileSync: vi.fn() })) diff --git a/src/main/ipc/worktrees-wsl-move-fence.test.ts b/src/main/ipc/worktrees-wsl-move-fence.test.ts index 99eea674d0d..05bdc4a7604 100644 --- a/src/main/ipc/worktrees-wsl-move-fence.test.ts +++ b/src/main/ipc/worktrees-wsl-move-fence.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { mkdtempSync, rmSync } from 'node:fs' import type { WorktreeMeta } from '../../shared/worktree/meta-types' import { tmpdir } from 'node:os' @@ -25,28 +25,72 @@ import { rememberPreservedBranchCleanupTarget } from './worktrees/removal/preser import { hostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) diff --git a/src/main/ipc/worktrees-wsl-runtime-routing.test.ts b/src/main/ipc/worktrees-wsl-runtime-routing.test.ts index 21f067ce0ee..0dc2b6e9b8a 100644 --- a/src/main/ipc/worktrees-wsl-runtime-routing.test.ts +++ b/src/main/ipc/worktrees-wsl-runtime-routing.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { REVIEW_HEAD_FETCH_TIMEOUT_MS } from '../../shared/review-head-tracking-ref' import { beforeEach, describe, expect, it, vi } from 'vitest' import { @@ -32,12 +32,13 @@ import type { HostWorktreeTarget } from '../../shared/worktree/host-qualified-id const runningStateMock = vi.hoisted(() => vi.fn(async (_distro: string, _options?: unknown) => 'running') ) -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees, - listWorktreesSharedStrictAllowingTrueEmpty: facade.listWorktreesSharedStrictAllowingTrueEmpty + listWorktrees: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + listWorktreesSharedStrictAllowingTrueEmpty: (await import('./worktrees-test-module-mocks')) + .listWorktreesMock, + listWorktreesSharedStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock } }) @@ -48,16 +49,59 @@ vi.mock('../wsl/discovery/wsl-background-distro-gate', async (importOriginal) => vi.mock('electron', async () => (await import('./worktrees-test-module-mocks')).electronModuleMock() ) -vi.mock('../git/worktree', async () => - (await import('./worktrees-test-module-mocks')).gitWorktreeModuleMock() -) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../shared/git-worktree-porcelain-parser', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock + parseWorktreeList: (await import('./worktrees-test-module-mocks')).parseWorktreeListMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await import('./worktrees-test-module-mocks')) + .assertWorktreeCleanForRemovalMock +})) + +vi.mock('../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await import('./worktrees-test-module-mocks')).addWorktreeMock +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await import('./worktrees-test-module-mocks')).addSparseWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await import('./worktrees-test-module-mocks')).removeWorktreeMock +})) + +vi.mock('../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await import('./worktrees-test-module-mocks')).forceDeleteLocalBranchMock +})) +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: (await import('./worktrees-test-module-mocks')).listWorktreesMock, + describeCreatedWorktree: (await import('./worktrees-test-module-mocks')) + .describeCreatedWorktreeMock +})) +const { getWorktreeRunnerMocks } = vi.hoisted(() => { + function createWorktreeRunnerMocks() { + return (async () => (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock())() + } + let runner: ReturnType | undefined + return { getWorktreeRunnerMocks: () => (runner ??= createWorktreeRunnerMocks()) } +}) + +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: (await getWorktreeRunnerMocks()).gitExecFileAsync +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileSync: (await getWorktreeRunnerMocks()).gitExecFileSync })) -vi.mock('../git/runner', async () => - (await import('./worktrees-test-module-mocks')).gitRunnerModuleMock() -) vi.mock('../git/repo', async () => (await import('./worktrees-test-module-mocks')).gitRepoModuleMock() ) @@ -79,6 +123,12 @@ vi.mock('../source-control/hosted-review', async () => vi.mock('./worktree-symlinks', async () => (await import('./worktrees-test-module-mocks')).worktreeSymlinksModuleMock() ) + +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: (await import('./worktrees-test-module-mocks')) + .findExistingWorktreeSymlinkPathsMock +})) vi.mock('../workspace-hooks/hooks', async () => (await import('./worktrees-test-module-mocks')).hooksModuleMock() ) diff --git a/src/main/ipc/worktrees/listing/detected-scan-failure-authority.test.ts b/src/main/ipc/worktrees/listing/detected-scan-failure-authority.test.ts index 4c953395b9f..7eb5d738d03 100644 --- a/src/main/ipc/worktrees/listing/detected-scan-failure-authority.test.ts +++ b/src/main/ipc/worktrees/listing/detected-scan-failure-authority.test.ts @@ -8,14 +8,15 @@ vi.mock('electron', () => ({ ipcMain: { handle: vi.fn(), removeHandler: vi.fn() }, app: { getPath: () => '/tmp/orca-test' } })) -vi.mock('../../../git/runner', async (importOriginal) => ({ +vi.mock('../../../git/command-runner/git-exec-file', async (importOriginal) => ({ ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) const { listDetectedWorktreesForCapturedRepo } = await import('./detected-provider-listing') const { __resetDetectedWorktreeScanCacheForTests } = await import('./detected-worktree-scan-cache') -const { _resetWorktreeScanCacheForTests } = await import('../../../git/worktree-scan-cache') +const { _resetWorktreeScanCacheForTests } = + await import('../../../git/worktrees/catalog/worktree-scan-cache') const { isRegisteredWorktreePath, invalidateAuthorizedRootsCache } = await import('../removal/registered-worktree-roots-cache') diff --git a/src/main/ipc/worktrees/listing/register-sparse-checkout-cache-invalidation.ts b/src/main/ipc/worktrees/listing/register-sparse-checkout-cache-invalidation.ts index 70b46010bd0..52266e8c855 100644 --- a/src/main/ipc/worktrees/listing/register-sparse-checkout-cache-invalidation.ts +++ b/src/main/ipc/worktrees/listing/register-sparse-checkout-cache-invalidation.ts @@ -4,8 +4,8 @@ import { clearSparseCheckoutStateCache, clearSparseCheckoutStateCacheForRepo, onSparseCheckoutStateChanged -} from '../../../git/worktree-sparse-checkout-cache' -import { areWorktreePathsEqual } from '../../../git/worktree-path-comparison' +} from '../../../git/worktrees/sparse-checkout/worktree-sparse-checkout-cache' +import { areWorktreePathsEqual } from '../../../git/worktrees/catalog/worktree-path-comparison' import { registerWorktreeChangeInvalidator } from '../../worktree-change-invalidators' import { notifyWorktreesChanged } from '../../worktree-remote' diff --git a/src/main/ipc/worktrees/listing/ssh-worktree-fallback.ts b/src/main/ipc/worktrees/listing/ssh-worktree-fallback.ts index 6f75711e5db..794916325ae 100644 --- a/src/main/ipc/worktrees/listing/ssh-worktree-fallback.ts +++ b/src/main/ipc/worktrees/listing/ssh-worktree-fallback.ts @@ -18,7 +18,10 @@ import { isLegacyRepoForExternalWorktreeVisibility, toDetectedWorktree } from '../../../../shared/worktree/ownership' -import { areWorktreePathsEqual, dedupeWorktreesByPath } from '../../../git/worktree-path-comparison' +import { + areWorktreePathsEqual, + dedupeWorktreesByPath +} from '../../../git/worktrees/catalog/worktree-path-comparison' import { createWorktreeVisibilitySourceMatcher, resolveCustomWorktreeVisibilitySources diff --git a/src/main/ipc/worktrees/listing/wsl-stopped-worktree-listing.ts b/src/main/ipc/worktrees/listing/wsl-stopped-worktree-listing.ts index 45fc94c52ac..f81391a0fa9 100644 --- a/src/main/ipc/worktrees/listing/wsl-stopped-worktree-listing.ts +++ b/src/main/ipc/worktrees/listing/wsl-stopped-worktree-listing.ts @@ -5,7 +5,7 @@ import type { } from '../../../../shared/worktree/types' import type { WorktreeMeta } from '../../../../shared/worktree/meta-types' import type { Store } from '../../../persistence/loading-store/store' -import { areWorktreePathsEqual } from '../../../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../../../git/worktrees/catalog/worktree-path-comparison' import { deferUntilWslDistroRunning, onWslDistroGateNote diff --git a/src/main/ipc/worktrees/removal/execute-worktree-removal.ts b/src/main/ipc/worktrees/removal/execute-worktree-removal.ts index a76cb45cd7b..deed7b0be72 100644 --- a/src/main/ipc/worktrees/removal/execute-worktree-removal.ts +++ b/src/main/ipc/worktrees/removal/execute-worktree-removal.ts @@ -6,7 +6,7 @@ import { isFolderRepo } from '../../../../shared/repo-kind' import { assertWorktreeUnlockedForRemoval } from '../../../../shared/worktree/removal' import { isWindowsAbsolutePathLike } from '../../../../shared/cross-platform-path' import { getLocalProjectWorktreeGitOptions } from '../../../workspaces/execution-host/project-runtime-git-options' -import { listWorktreesStrict as listGitWorktreesStrict } from '../../../git/worktree' +import { listWorktreesStrict as listGitWorktreesStrict } from '../../../git/worktrees/catalog/worktree-listing' import { SshHostNotServedError, SSH_WORKTREE_REMOVAL_NOT_SERVED_MESSAGE @@ -16,7 +16,7 @@ import { authorizeUnregisteredWindowsRemoval, nativeWindowsMarkerMissing, usesNativeWindowsRemoval -} from '../../../git/windows-worktree-removal' +} from '../../../git/worktrees/removal/windows-worktree-removal' import { isPrunableGitFileWorktree } from '../../../workspaces/removal/worktree-prunable-git-file' import { findRegisteredDeletableWorktree } from '../../../workspaces/removal/worktree-removal-safety' import { assertNestedWorktreeRemovalApproval } from '../../../workspaces/removal/nested-worktree-removal-plan' diff --git a/src/main/ipc/worktrees/removal/nested-worktree-removal.ts b/src/main/ipc/worktrees/removal/nested-worktree-removal.ts index 19a7f83d662..7457e9bd12c 100644 --- a/src/main/ipc/worktrees/removal/nested-worktree-removal.ts +++ b/src/main/ipc/worktrees/removal/nested-worktree-removal.ts @@ -3,7 +3,7 @@ import type { ExecutionHostId } from '../../../../shared/execution-host' import type { GitWorktreeInfo } from '../../../../shared/worktree/types' import type { RemoveWorktreeResult } from '../../../../shared/worktree/create-types' import { isFolderRepo } from '../../../../shared/repo-kind' -import { listWorktreesStrict } from '../../../git/worktree' +import { listWorktreesStrict } from '../../../git/worktrees/catalog/worktree-listing' import { getLocalProjectWorktreeGitOptions } from '../../../workspaces/execution-host/project-runtime-git-options' import { SshHostNotServedError, diff --git a/src/main/ipc/worktrees/removal/register-worktree-forget-handlers.ts b/src/main/ipc/worktrees/removal/register-worktree-forget-handlers.ts index ad09fe25c6d..b6efd2d6332 100644 --- a/src/main/ipc/worktrees/removal/register-worktree-forget-handlers.ts +++ b/src/main/ipc/worktrees/removal/register-worktree-forget-handlers.ts @@ -20,7 +20,7 @@ import { } from '../../worktree-remote' import { SshHostNotServedError } from '../../../providers/ssh-host-not-served-error' import { getLocalProjectWorktreeGitOptions } from '../../../workspaces/execution-host/project-runtime-git-options' -import { forceDeleteLocalBranch } from '../../../git/worktree' +import { forceDeleteLocalBranch } from '../../../git/worktrees/removal/worktree-branch-removal' import { gitExecFileAsync } from '../../../git/runner' import type { RemoveWorktreeArgs } from '../ipc-context-schemas' import { getWorktreeRemovalInFlightKey } from './worktree-removal-coordinator' diff --git a/src/main/ipc/worktrees/removal/register-worktree-removal-handlers.ts b/src/main/ipc/worktrees/removal/register-worktree-removal-handlers.ts index b0a15480f1f..1956970733b 100644 --- a/src/main/ipc/worktrees/removal/register-worktree-removal-handlers.ts +++ b/src/main/ipc/worktrees/removal/register-worktree-removal-handlers.ts @@ -3,7 +3,7 @@ import { getLocalWorktreeCatalogVersion } from '../../../workspaces/catalog/loca import type { RemoveWorktreeResult } from '../../../../shared/worktree/create-types' import { getRepoExecutionHostId } from '../../../../shared/execution-host' import { withWorktreeSpan } from '../../../observability/instrumentation' -import { areWorktreePathsEqual } from '../../../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../../../git/worktrees/catalog/worktree-path-comparison' import { parseWorktreeId } from '../../worktree-logic' import type { RemoveWorktreeArgs } from '../ipc-context-schemas' import type { WorktreeIpcContext } from '../worktree-ipc-context' diff --git a/src/main/ipc/worktrees/removal/registered-local-worktree-preflight.ts b/src/main/ipc/worktrees/removal/registered-local-worktree-preflight.ts index b7644e9df2b..abdf13b8c21 100644 --- a/src/main/ipc/worktrees/removal/registered-local-worktree-preflight.ts +++ b/src/main/ipc/worktrees/removal/registered-local-worktree-preflight.ts @@ -3,8 +3,8 @@ import type { LocalProjectWorktreeGitOptions } from '../../../workspaces/executi import { authorizeWindowsCheckout, usesNativeWindowsRemoval -} from '../../../git/windows-worktree-removal' -import { assertWorktreeCleanForRemoval } from '../../../git/worktree' +} from '../../../git/worktrees/removal/windows-worktree-removal' +import { assertWorktreeCleanForRemoval } from '../../../git/worktrees/removal/worktree-removal-preflight' import { formatWorktreeRemovalError, isOrphanCompatiblePreflightError } from '../../worktree-logic' export async function assertRegisteredLocalWorktreePreflight( diff --git a/src/main/ipc/worktrees/removal/registered-worktree-root-probes.ts b/src/main/ipc/worktrees/removal/registered-worktree-root-probes.ts index e539353f764..9ad6626b780 100644 --- a/src/main/ipc/worktrees/removal/registered-worktree-root-probes.ts +++ b/src/main/ipc/worktrees/removal/registered-worktree-root-probes.ts @@ -2,7 +2,7 @@ import { stat } from 'node:fs/promises' import { resolve } from 'node:path' import { withTimeout } from '../../../../shared/promise-timeout-fallback' import type { Repo } from '../../../../shared/repo-types' -import { getErrorCode } from '../../../git/worktree-operation-options' +import { getErrorCode } from '../../../git/worktrees/worktree-operation-options' import { resolveLocalProjectRuntimesForRepos } from '../../../workspaces/execution-host/local-project-runtime-resolution' import type { RegisteredWorktreeRootStore as RootStore } from './registered-worktree-root-store' import { getWorktreeMirrorDistroForRuntime } from '../../../workspaces/execution-host/project-runtime-git-options' diff --git a/src/main/ipc/worktrees/removal/remove-registered-local-worktree.ts b/src/main/ipc/worktrees/removal/remove-registered-local-worktree.ts index 4f69404d4ac..b7e2c43c377 100644 --- a/src/main/ipc/worktrees/removal/remove-registered-local-worktree.ts +++ b/src/main/ipc/worktrees/removal/remove-registered-local-worktree.ts @@ -3,18 +3,16 @@ import type { Repo } from '../../../../shared/repo-types' import { nativeWindowsMarkerMissing, usesNativeWindowsRemoval -} from '../../../git/windows-worktree-removal' -import { pruneGitWorktrees } from '../../../git/worktree-prune-guard' +} from '../../../git/worktrees/removal/windows-worktree-removal' +import { pruneGitWorktrees } from '../../../git/worktrees/removal/worktree-prune-guard' import type { ExecutionHostId } from '../../../../shared/execution-host' import type { RemoveWorktreeResult } from '../../../../shared/worktree/create-types' import type { GitPushTarget, GitWorktreeInfo } from '../../../../shared/worktree/types' import { assertWorktreeUnlockedForRemoval } from '../../../../shared/worktree/removal' import type { LocalProjectWorktreeGitOptions } from '../../../workspaces/execution-host/project-runtime-git-options' -import { - listWorktreesStrict as listGitWorktreesStrict, - removeWorktree -} from '../../../git/worktree' -import { getWorktreeSharedLinkPaths } from '../../../git/worktree-shared-directories' +import { listWorktreesStrict as listGitWorktreesStrict } from '../../../git/worktrees/catalog/worktree-listing' +import { removeWorktree } from '../../../git/worktrees/removal/worktree-removal' +import { getWorktreeSharedLinkPaths } from '../../../git/worktrees/content-paths/worktree-shared-directories' import { cleanupLocalOrphanedWorktreeDirectory } from '../../../workspaces/removal/local-orphaned-worktree-cleanup' import { recoverPartialLocalWorktreeRemoval } from '../../../workspaces/removal/local-worktree-removal-recovery' import { withWorktreeRemoveStageSpan } from '../../../observability/instrumentation' @@ -22,10 +20,8 @@ import { assertNestedWorktreeRemovalApproval } from '../../../workspaces/removal import { findRegisteredDeletableWorktree } from '../../../workspaces/removal/worktree-removal-safety' import { CLIENT_REMOVAL_HOME } from '../../../workspaces/removal/worktree-removal-home-guard' import { cleanupUnusedWorktreePushTargetRemote } from '../../worktree-remote' -import { - findExistingWorktreeSymlinkPaths, - removeWorktreeLinkedPaths -} from '../../worktree-symlinks' +import { findExistingWorktreeSymlinkPaths } from '../../../git/worktrees/content-paths/worktree-symlink-detection' +import { removeWorktreeLinkedPaths } from '../../worktree-symlinks' import { invalidateAuthorizedRootsCacheForRepo } from './registered-worktree-roots-scoped-invalidation' import { runWorktreeChangeInvalidators } from '../../worktree-change-invalidators' import { formatWorktreeRemovalError, isOrphanedWorktreeError } from '../../worktree-logic' diff --git a/src/main/ipc/worktrees/removal/remove-unregistered-worktree.ts b/src/main/ipc/worktrees/removal/remove-unregistered-worktree.ts index ed4ea37deb4..55916349cef 100644 --- a/src/main/ipc/worktrees/removal/remove-unregistered-worktree.ts +++ b/src/main/ipc/worktrees/removal/remove-unregistered-worktree.ts @@ -1,5 +1,5 @@ -import { removeWorktree } from '../../../git/worktree-removal' -import { usesNativeWindowsRemoval } from '../../../git/windows-worktree-removal' +import { removeWorktree } from '../../../git/worktrees/removal/worktree-removal' +import { usesNativeWindowsRemoval } from '../../../git/worktrees/removal/windows-worktree-removal' import type { Repo } from '../../../../shared/repo-types' import type { ExecutionHostId } from '../../../../shared/execution-host' import type { RemoveWorktreeResult } from '../../../../shared/worktree/create-types' diff --git a/src/main/ipc/wsl-drive-project-handlers.ts b/src/main/ipc/wsl-drive-project-handlers.ts index b5fc948f75b..6de846255c7 100644 --- a/src/main/ipc/wsl-drive-project-handlers.ts +++ b/src/main/ipc/wsl-drive-project-handlers.ts @@ -8,7 +8,7 @@ import type { Store } from '../persistence/loading-store/store' import type { OrcaRuntimeService } from '../runtime/orca-runtime' import { registerWslDriveUncConversionHandlers } from './wsl-drive-unc-conversion-handlers' import { gitExecFileAsync } from '../git/command-runner/git-exec-file' -import { readWorktreeLinks as readWorktreeAdminLinks } from '../git/worktree-prune-guard' +import { readWorktreeLinks as readWorktreeAdminLinks } from '../git/worktrees/removal/worktree-prune-guard' import { resolveLocalProjectRuntimeForProject } from '../workspaces/execution-host/local-project-runtime-resolution' import { wslHostsOptedIn } from '../wsl/host-lifecycle/wsl-host-gate' import { diff --git a/src/main/managed-server/lifecycle/orcad-managed-pairing-repair-restart.test.ts b/src/main/managed-server/lifecycle/orcad-managed-pairing-repair-restart.test.ts index e031a7a3f4c..f0d632fbf02 100644 --- a/src/main/managed-server/lifecycle/orcad-managed-pairing-repair-restart.test.ts +++ b/src/main/managed-server/lifecycle/orcad-managed-pairing-repair-restart.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' @@ -24,26 +24,30 @@ import { } from './orcad-managed-tunnel-identity' import { unusedOrcadHostTransport } from '../../ssh/unused-host-transport.test-fixture' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) const servers: OrcaRuntimeRpcServer[] = [] afterEach(async () => { diff --git a/src/main/managed-server/lifecycle/orcad-managed-tunnel-identity-restart.test.ts b/src/main/managed-server/lifecycle/orcad-managed-tunnel-identity-restart.test.ts index 063cd1f7590..892fafe5aa3 100644 --- a/src/main/managed-server/lifecycle/orcad-managed-tunnel-identity-restart.test.ts +++ b/src/main/managed-server/lifecycle/orcad-managed-tunnel-identity-restart.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import { pairedRuntimeConnectionFromOffer } from '../../../shared/paired-runtime-connection' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -24,26 +24,30 @@ import { import { buildServePairingReadiness } from '../../server/serve-pairing-readiness' import { WslOrcadConnectionManager } from '../../wsl/orcad/wsl-orcad-connection' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) const servers: OrcaRuntimeRpcServer[] = [] afterEach(async () => { diff --git a/src/main/persistence/moving-wsl-projects/wsl-move-incidental-writes.test.ts b/src/main/persistence/moving-wsl-projects/wsl-move-incidental-writes.test.ts index 452bf7dd3db..2491076730c 100644 --- a/src/main/persistence/moving-wsl-projects/wsl-move-incidental-writes.test.ts +++ b/src/main/persistence/moving-wsl-projects/wsl-move-incidental-writes.test.ts @@ -12,7 +12,10 @@ import type * as LinearCurrentIssueContext from '../../linear/issue-context/curr import type { ResolvedWorktree } from '../../runtime/runtime-worktree-path-identity' const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../../git/runner', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) +vi.mock('../../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) vi.mock('../../linear/issue-context/current', async (importOriginal) => ({ ...(await importOriginal()), resolveLegacyLinearLinkWorkspace: () => ({ workspaceId: 'ws-1', organizationUrlKey: 'acme' }) diff --git a/src/main/project-groups/nested-repo-import-target.test.ts b/src/main/project-groups/nested-repo-import-target.test.ts index 865464e853d..300a6429575 100644 --- a/src/main/project-groups/nested-repo-import-target.test.ts +++ b/src/main/project-groups/nested-repo-import-target.test.ts @@ -1,13 +1,13 @@ import { describe, expect, it, vi, beforeEach } from 'vitest' import { join } from 'node:path' import type { GitWorktreeInfo } from '../../shared/worktree/types' -import { listWorktreeGraph } from '../git/worktree' +import { listWorktreeGraph } from '../git/worktrees/catalog/worktree-scan-cache' import { createNestedRepoImportTargetResolver, resolveLocalNestedRepoImportTargetPath } from './nested-repo-import-target' -vi.mock('../git/worktree', () => ({ +vi.mock('../git/worktrees/catalog/worktree-scan-cache', () => ({ listWorktreeGraph: vi.fn() })) diff --git a/src/main/project-groups/nested-repo-import-target.ts b/src/main/project-groups/nested-repo-import-target.ts index 338c7e6fb80..9f4a36bd8d9 100644 --- a/src/main/project-groups/nested-repo-import-target.ts +++ b/src/main/project-groups/nested-repo-import-target.ts @@ -1,6 +1,6 @@ import type { GitWorktreeInfo } from '../../shared/worktree/types' import { normalizeRuntimePathForComparison } from '../../shared/cross-platform-path' -import { listWorktreeGraph } from '../git/worktree' +import { listWorktreeGraph } from '../git/worktrees/catalog/worktree-scan-cache' export type NestedRepoImportTargetResolver = { resolveLocal: (repoPath: string) => Promise diff --git a/src/main/providers/local-git-provider.test.ts b/src/main/providers/local-git-provider.test.ts index bda09eb9312..42273bfdfd6 100644 --- a/src/main/providers/local-git-provider.test.ts +++ b/src/main/providers/local-git-provider.test.ts @@ -40,8 +40,70 @@ const { git } = vi.hoisted(() => ({ } })) -vi.mock('../git/status', () => git) -vi.mock('../git/check-ignored-paths', () => ({ checkIgnoredPaths: git.checkIgnoredPaths })) +vi.mock('../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: git.getStatus +})) + +vi.mock('../git/source-control/submodule-status', async (importOriginal) => ({ + ...(await importOriginal>()), + getSubmoduleStatus: git.getSubmoduleStatus +})) + +vi.mock('../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + commitChanges: git.commitChanges +})) + +vi.mock('../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: git.getStagedCommitContext +})) + +vi.mock('../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: git.getDiff +})) + +vi.mock('../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), + stageFile: git.stageFile, + unstageFile: git.unstageFile, + bulkStageFiles: git.bulkStageFiles, + stageWorktreeChanges: git.stageWorktreeChanges, + bulkUnstageFiles: git.bulkUnstageFiles +})) + +vi.mock('../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + discardChanges: git.discardChanges, + bulkDiscardChanges: git.bulkDiscardChanges +})) + +vi.mock('../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), + detectConflictOperation: git.detectConflictOperation, + abortMerge: git.abortMerge, + abortRebase: git.abortRebase +})) + +vi.mock('../git/source-control/branch-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchCompare: git.getBranchCompare +})) + +vi.mock('../git/source-control/commit-compare', async (importOriginal) => ({ + ...(await importOriginal>()), + getCommitCompare: git.getCommitCompare +})) + +vi.mock('../git/source-control/commit-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getCommitDiff: git.getCommitDiff +})) +vi.mock('../git/source-control/check-ignored-paths', () => ({ + checkIgnoredPaths: git.checkIgnoredPaths +})) vi.mock('../git/checkout', () => ({ checkoutBranch: git.checkoutBranch, listLocalBranches: git.listLocalBranches @@ -49,10 +111,20 @@ vi.mock('../git/checkout', () => ({ vi.mock('../git/history', () => ({ getHistory: git.getHistory })) vi.mock('../git/remote', () => git) vi.mock('../git/fork-sync', () => ({ gitSyncForkDefaultBranch: git.gitSyncForkDefaultBranch })) -vi.mock('../git/upstream', () => ({ getUpstreamStatus: git.getUpstreamStatus })) -vi.mock('../git/worktree', () => ({ listWorktrees: git.listWorktrees })) +vi.mock('../git/source-control/upstream', () => ({ getUpstreamStatus: git.getUpstreamStatus })) +vi.mock('../git/worktrees/catalog/worktree-scan-cache', () => ({ + listWorktrees: git.listWorktrees +})) vi.mock('../git/repo', () => git) -vi.mock('../git/runner', () => git) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: git.gitExecFileAsync +})) + +vi.mock('../git/command-runner/windows-host-git-environment', async (importOriginal) => ({ + ...(await importOriginal>()), + awaitWindowsHostGitEnvironmentReady: git.awaitWindowsHostGitEnvironmentReady +})) import { createLocalGitProvider, type LocalGitProvider } from './local-git-provider' diff --git a/src/main/providers/local-git-provider.ts b/src/main/providers/local-git-provider.ts index e9f428c8a31..4493b0ec0a0 100644 --- a/src/main/providers/local-git-provider.ts +++ b/src/main/providers/local-git-provider.ts @@ -1,6 +1,6 @@ import { gitSyncForkDefaultBranch } from '../git/fork-sync' import type { GitRuntimeOptions } from '../git/git-runtime-options' -import { checkIgnoredPaths } from '../git/check-ignored-paths' +import { checkIgnoredPaths } from '../git/source-control/check-ignored-paths' import { checkoutBranch, listLocalBranches } from '../git/checkout' import { getHistory } from '../git/history' import { gitFastForward, gitFetch, gitPull, gitPullRebaseFromBase, gitPush } from '../git/remote' @@ -9,27 +9,27 @@ import { awaitWindowsHostGitEnvironmentReady, gitExecFileAsync } from '../git/ru import { abortMerge, abortRebase, - bulkDiscardChanges, + detectConflictOperation +} from '../git/source-control/git-conflict-operation' +import { bulkDiscardChanges, discardChanges } from '../git/source-control/discard-changes' +import { bulkStageFiles, bulkUnstageFiles, - commitChanges, - completeMerge, - detectConflictOperation, - discardChanges, - getBranchCompare, - getCommitCompare, - getCommitDiff, - getDiff, - getStagedCommitContext, - getStatus, - getSubmoduleStatus, resolveConflict, stageFile, stageWorktreeChanges, unstageFile -} from '../git/status' -import { getUpstreamStatus } from '../git/upstream' -import { listWorktrees } from '../git/worktree' +} from '../git/source-control/staging' +import { commitChanges, completeMerge } from '../git/source-control/commit-changes' +import { getBranchCompare } from '../git/source-control/branch-compare' +import { getCommitCompare } from '../git/source-control/commit-compare' +import { getCommitDiff } from '../git/source-control/commit-diff' +import { getDiff } from '../git/source-control/file-diff' +import { getStagedCommitContext } from '../git/source-control/staged-commit-context' +import { getStatus } from '../git/source-control/status-read' +import { getSubmoduleStatus } from '../git/source-control/submodule-status' +import { getUpstreamStatus } from '../git/source-control/upstream' +import { listWorktrees } from '../git/worktrees/catalog/worktree-scan-cache' import type { IGitProvider } from './git-provider-contract' /** Per-worktree execution options; build one provider per call and never cache it (WSL routing). */ diff --git a/src/main/runtime/agent-prompt-line-settle.test.ts b/src/main/runtime/agent-prompt-line-settle.test.ts index aad54dce781..69b488a5dac 100644 --- a/src/main/runtime/agent-prompt-line-settle.test.ts +++ b/src/main/runtime/agent-prompt-line-settle.test.ts @@ -1,45 +1,49 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { afterEach, describe, expect, it, vi } from 'vitest' import { resolveAgentPromptSubmitDelayForAgent } from '../../shared/agent-prompt-injection' import { createAgentPromptSubmissionRuntime } from './agent-prompt-submission-runtime-test-fixture' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-line-settle', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-line-settle', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-line-settle', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-line-settle', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) describe('agent prompt line-settle scheduling', () => { afterEach(() => vi.useRealTimers()) diff --git a/src/main/runtime/agent-prompt-permission-wait.test.ts b/src/main/runtime/agent-prompt-permission-wait.test.ts index 817cdcec397..4f296985640 100644 --- a/src/main/runtime/agent-prompt-permission-wait.test.ts +++ b/src/main/runtime/agent-prompt-permission-wait.test.ts @@ -1,45 +1,49 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { afterEach, describe, expect, it, vi } from 'vitest' import { createAgentPromptSubmissionRuntime } from './agent-prompt-submission-runtime-test-fixture' import { AGENT_PROMPT_PERMISSION_RECHECK_MS } from './terminal/input/agent-prompt-permission-hold' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-verification', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-verification', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-verification', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-verification', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) const PERMISSION_TITLE = '\x1b]0;Codex waiting for permission\x07' const IDLE_TITLE = '\x1b]0;Codex idle\x07' diff --git a/src/main/runtime/agent-prompt-receipt-correlation.test.ts b/src/main/runtime/agent-prompt-receipt-correlation.test.ts index 39fcd1e5e3f..c084e62a2c5 100644 --- a/src/main/runtime/agent-prompt-receipt-correlation.test.ts +++ b/src/main/runtime/agent-prompt-receipt-correlation.test.ts @@ -1,44 +1,48 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { afterEach, describe, expect, it, vi } from 'vitest' import { createAgentPromptSubmissionRuntime } from './agent-prompt-submission-runtime-test-fixture' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-correlation', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-correlation', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-correlation', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-correlation', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) describe('agent prompt receipt correlation', () => { afterEach(() => vi.useRealTimers()) diff --git a/src/main/runtime/agent-prompt-submission-runtime-hook-and-generation.test.ts b/src/main/runtime/agent-prompt-submission-runtime-hook-and-generation.test.ts index 7c6ba83f881..b53aeba0b02 100644 --- a/src/main/runtime/agent-prompt-submission-runtime-hook-and-generation.test.ts +++ b/src/main/runtime/agent-prompt-submission-runtime-hook-and-generation.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { deliverFollowUp } from '../external-conversations/external-conversation-send' import { ConversationChain } from '../external-conversations/external-conversation-chain' import { afterEach, describe, expect, it, vi } from 'vitest' @@ -17,42 +17,46 @@ import { makeStore } from './runtime-rpc-worktree-store-fixtures' const createPromptRuntime = createAgentPromptSubmissionRuntime -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-verification', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-verification', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-verification', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-verification', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) describe('agent prompt submission runtime hook and generation cases', () => { afterEach(() => vi.useRealTimers()) diff --git a/src/main/runtime/agent-prompt-submission-runtime.test.ts b/src/main/runtime/agent-prompt-submission-runtime.test.ts index 279b4653134..e481a77f188 100644 --- a/src/main/runtime/agent-prompt-submission-runtime.test.ts +++ b/src/main/runtime/agent-prompt-submission-runtime.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { afterEach, describe, expect, it, vi } from 'vitest' import { AGENT_PROMPT_BRACKETED_PASTE_END } from '../../shared/agent-prompt-injection' import { @@ -13,42 +13,46 @@ import { settledWriteStub } from '../providers/settled-pty-write-stub' const createPromptRuntime = createAgentPromptSubmissionRuntime -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-verification', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-verification', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-verification', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-verification', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) describe('agent prompt submission runtime', () => { afterEach(() => vi.useRealTimers()) diff --git a/src/main/runtime/agent-prompt-submission-windows-submit-delay.test.ts b/src/main/runtime/agent-prompt-submission-windows-submit-delay.test.ts index bea9d9e74bf..6b1f19ac1dd 100644 --- a/src/main/runtime/agent-prompt-submission-windows-submit-delay.test.ts +++ b/src/main/runtime/agent-prompt-submission-windows-submit-delay.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { afterEach, describe, expect, it, vi } from 'vitest' import { buildAgentPromptPasteBytes, @@ -19,42 +19,46 @@ function useHostPlatform(platform: NodeJS.Platform): void { Object.defineProperty(process, 'platform', { configurable: true, value: platform }) } -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-verification', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-verification', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-verification', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-verification', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) // aider uses open-loop submission, exposing the delay under test. async function createPromptRuntime(): Promise<{ diff --git a/src/main/runtime/delegated-mobile-device.integration.test.ts b/src/main/runtime/delegated-mobile-device.integration.test.ts index 41511ee453b..b4bfa2f679b 100644 --- a/src/main/runtime/delegated-mobile-device.integration.test.ts +++ b/src/main/runtime/delegated-mobile-device.integration.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { pairedRuntimeConnectionFromOffer } from '../../shared/paired-runtime-connection' import { mkdtempSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -27,26 +27,30 @@ import { import { makeStore } from './runtime-rpc-worktree-store-fixtures' import { partialRuntimeStore } from './runtime-store-partial-fixture' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) type DelegatedDevice = DelegatedMobileDeviceSyncResult['devices'][number] diff --git a/src/main/runtime/dsb-terminal-runtime.test.ts b/src/main/runtime/dsb-terminal-runtime.test.ts index 1f2f22e0bda..c8b8d5381e1 100644 --- a/src/main/runtime/dsb-terminal-runtime.test.ts +++ b/src/main/runtime/dsb-terminal-runtime.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { readFileSync } from 'node:fs' import { join } from 'node:path' import { afterEach, describe, expect, expectTypeOf, it, vi } from 'vitest' @@ -10,42 +10,46 @@ import { OrcaRuntimeService } from './orca-runtime' import { makeStore } from './runtime-rpc-worktree-store-fixtures' import { partialRuntimeStore } from './runtime-store-partial-fixture' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/dsb', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/dsb', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/dsb', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/dsb', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) describe('manually started DeepSeek Build terminals', () => { afterEach(() => vi.useRealTimers()) diff --git a/src/main/runtime/dsh-launch-prompt-resubmit.test.ts b/src/main/runtime/dsh-launch-prompt-resubmit.test.ts index 349d0646f4a..efaaebdc4bd 100644 --- a/src/main/runtime/dsh-launch-prompt-resubmit.test.ts +++ b/src/main/runtime/dsh-launch-prompt-resubmit.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { readFileSync } from 'node:fs' import { join } from 'node:path' import { afterEach, describe, expect, it, vi } from 'vitest' @@ -7,36 +7,40 @@ import { AGENT_PROMPT_BRACKETED_PASTE_END } from '../../shared/agent-prompt-inje import { createAgentPromptSubmissionRuntime } from './agent-prompt-submission-runtime-test-fixture' import { dispatchPreambleSendOptions } from './orchestration/preamble' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-verification', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-verification', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) const fixture = (name: string): string => diff --git a/src/main/runtime/external-worktree-paired-client-discovery.integration.test.ts b/src/main/runtime/external-worktree-paired-client-discovery.integration.test.ts index eed3e69eded..26bfc0f5779 100644 --- a/src/main/runtime/external-worktree-paired-client-discovery.integration.test.ts +++ b/src/main/runtime/external-worktree-paired-client-discovery.integration.test.ts @@ -1,10 +1,11 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { mkdtempSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, describe, expect, it, vi } from 'vitest' -import { listWorktrees, listWorktreesStrict } from '../git/worktree' +import { listWorktrees } from '../git/worktrees/catalog/worktree-scan-cache' +import { listWorktreesStrict } from '../git/worktrees/catalog/worktree-listing' import { scheduleWorktreeBaseNotification } from '../ipc/worktrees/creation/worktree-base-directory-notifications' import { createWorktreeHeadIdentityRefreshState } from '../ipc/worktrees/creation/worktree-head-identity-refresh' import { EMPTY_HEAD_IDENTITY_SCOPE } from '../ipc/worktrees/creation/worktree-head-identity-scope' @@ -22,26 +23,30 @@ import { } from './paired-client-navigation-test-harness' import { OrcaRuntimeRpcServer } from './runtime-rpc' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn(), - listWorktreesStrict: vi.fn() -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn(), + listWorktreesStrict: vi.fn() + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) const initialWorktreePath = join(tmpdir(), 'repo') const externalWorktreePath = join(tmpdir(), 'external-worktree') diff --git a/src/main/runtime/fetch-remote-cache.test.ts b/src/main/runtime/fetch-remote-cache.test.ts index cabf0f36ef2..2d3512c696b 100644 --- a/src/main/runtime/fetch-remote-cache.test.ts +++ b/src/main/runtime/fetch-remote-cache.test.ts @@ -1,5 +1,5 @@ import type * as GitExecFileModule from '../git/command-runner/git-exec-file' -import { worktreeCreateGit } from '../git/worktree-create-git-executor' +import { worktreeCreateGit } from '../git/worktrees/creation/worktree-create-git-executor' import { resolveGitAdmissionTier } from '../git/command-runner/git-operation-executor' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' diff --git a/src/main/runtime/fit-override-integration.test.ts b/src/main/runtime/fit-override-integration.test.ts index d3541fbf242..1dd7f879d45 100644 --- a/src/main/runtime/fit-override-integration.test.ts +++ b/src/main/runtime/fit-override-integration.test.ts @@ -1,37 +1,41 @@ -import type * as WorktreeListingModule from '../git/worktree-listing' -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' import { describe, expect, it, vi } from 'vitest' import type * as GitUsernameModule from '../git/git-username' import { OrcaRuntimeService } from './orca-runtime' -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) vi.mock('../workspace-hooks/hooks', () => ({ getEffectiveHooks: vi.fn().mockReturnValue(null), diff --git a/src/main/runtime/managed-worktree-create-registry.test.ts b/src/main/runtime/managed-worktree-create-registry.test.ts index e5639ab9b99..31373d5fffa 100644 --- a/src/main/runtime/managed-worktree-create-registry.test.ts +++ b/src/main/runtime/managed-worktree-create-registry.test.ts @@ -18,7 +18,9 @@ const mocks = vi.hoisted(() => ({ })) vi.mock('../telemetry/client', () => ({ track: mocks.track, isTelemetryEnabled: () => true })) -vi.mock('../git/create-event-repo-probe', () => ({ probeCreateEventRepoFacts: mocks.probe })) +vi.mock('../git/worktrees/creation/create-event-repo-probe', () => ({ + probeCreateEventRepoFacts: mocks.probe +})) vi.mock('./runtime-local-worktree-create', () => ({ createRuntimeLocalManagedWorktree: mocks.createLocal })) diff --git a/src/main/runtime/managed-worktree-create-telemetry.test.ts b/src/main/runtime/managed-worktree-create-telemetry.test.ts index 2ff3c6fab49..c70b40c8a15 100644 --- a/src/main/runtime/managed-worktree-create-telemetry.test.ts +++ b/src/main/runtime/managed-worktree-create-telemetry.test.ts @@ -17,7 +17,9 @@ const mocks = vi.hoisted(() => ({ })) vi.mock('../telemetry/client', () => ({ track: mocks.track, isTelemetryEnabled: () => true })) -vi.mock('../git/create-event-repo-probe', () => ({ probeCreateEventRepoFacts: mocks.probe })) +vi.mock('../git/worktrees/creation/create-event-repo-probe', () => ({ + probeCreateEventRepoFacts: mocks.probe +})) vi.mock('./runtime-local-worktree-create', () => ({ createRuntimeLocalManagedWorktree: mocks.createLocal })) diff --git a/src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.integration.test.ts b/src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.integration.test.ts index b4b2c212945..006c12f9e5b 100644 --- a/src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.integration.test.ts +++ b/src/main/runtime/mobile-desktop-relay/mobile-desktop-relay.integration.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import { GITHUB_REPO_WORK_ITEM_METHODS } from '../rpc/methods/github-repo-work-item-methods' import { GITHUB_EXACT_OPERATION_UNSUPPORTED } from '../../../shared/github/work-item-target' import { GITHUB_EXACT_DETAILS_READ_INTENT_RUNTIME_CAPABILITY } from '../../../shared/task-source-runtime-capabilities' @@ -56,16 +56,14 @@ const passthroughOpens = vi.hoisted(() => { heldStatus } }) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => ({ +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ ...(await importOriginal()), - listWorktrees: (await vi.importMock('../../git/worktree')) - .listWorktrees + listWorktrees: (await getWorktreeOwnerMocks()).listWorktrees })) -vi.mock('../../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ ...(await importOriginal()), - listWorktreesStrict: (await vi.importMock('../../git/worktree')) - .listWorktreesStrict + listWorktreesStrict: (await getWorktreeOwnerMocks()).listWorktreesStrict })) vi.mock( @@ -107,9 +105,14 @@ vi.mock( } ) -vi.mock('../../git/worktree', async () => - (await import('../runtime-rpc-worktree-store-fixtures')).createWorktreeListingMocks() -) +const { getWorktreeOwnerMocks } = vi.hoisted(() => { + function createWorktreeOwnerMocks() { + return (async () => + (await import('../runtime-rpc-worktree-store-fixtures')).createWorktreeListingMocks())() + } + let fixture: ReturnType | undefined + return { getWorktreeOwnerMocks: () => (fixture ??= createWorktreeOwnerMocks()) } +}) class SeatObservableRuntime extends OrcaRuntimeService { seatClientIds(ptyId: string): string[] { diff --git a/src/main/runtime/mobile-desktop-relay/mobile-relay-host-catalog.integration.test.ts b/src/main/runtime/mobile-desktop-relay/mobile-relay-host-catalog.integration.test.ts index 57b4624a627..351496502d5 100644 --- a/src/main/runtime/mobile-desktop-relay/mobile-relay-host-catalog.integration.test.ts +++ b/src/main/runtime/mobile-desktop-relay/mobile-relay-host-catalog.integration.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import { pairedRuntimeConnectionFromOffer } from '../../../shared/paired-runtime-connection' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -25,36 +25,40 @@ import { makeStore } from '../runtime-rpc-worktree-store-fixtures' import type { MobileDesktopRelayHosts } from './mobile-desktop-relay-hosts' import { partialRuntimeStore } from '../runtime-store-partial-fixture' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) type Contact = 'live' | 'unreachable' diff --git a/src/main/runtime/mobile-presence-lock.test.ts b/src/main/runtime/mobile-presence-lock.test.ts index 2ea74d7703a..ed2306304a1 100644 --- a/src/main/runtime/mobile-presence-lock.test.ts +++ b/src/main/runtime/mobile-presence-lock.test.ts @@ -1,34 +1,38 @@ import { mobilePresenceStore as store } from './orca-runtime-test-mocks/mobile-presence-store' -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import * as inputAdmission from './terminal-input-admission' import './mobile-subscribe-integration.spec' import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' -import { listWorktrees } from '../git/worktree' +import { listWorktrees } from '../git/worktrees/catalog/worktree-scan-cache' import type * as GitUsernameModule from '../git/git-username' import { OrcaRuntimeService } from './orca-runtime' import type { RuntimePtyController } from './runtime-pty-controller-contract' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) vi.mock('../workspace-hooks/hooks', () => ({ getEffectiveHooks: vi.fn().mockReturnValue(null), runHook: vi.fn().mockResolvedValue({ success: true, output: '' }) diff --git a/src/main/runtime/mobile-session-tabs-churn-coalescing.test.ts b/src/main/runtime/mobile-session-tabs-churn-coalescing.test.ts index ef5f1dc2380..19ab8534920 100644 --- a/src/main/runtime/mobile-session-tabs-churn-coalescing.test.ts +++ b/src/main/runtime/mobile-session-tabs-churn-coalescing.test.ts @@ -1,30 +1,34 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' import type * as GitUsernameModule from '../git/git-username' import type { RuntimeMobileSessionTabsSnapshot } from '../../shared/runtime-types' import { OrcaRuntimeService } from './orca-runtime' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) vi.mock('../workspace-hooks/hooks', () => ({ getEffectiveHooks: vi.fn().mockReturnValue(null), diff --git a/src/main/runtime/mobile-subscribe-integration.spec.ts b/src/main/runtime/mobile-subscribe-integration.spec.ts index 069306da9c3..6e585b54ea7 100644 --- a/src/main/runtime/mobile-subscribe-integration.spec.ts +++ b/src/main/runtime/mobile-subscribe-integration.spec.ts @@ -1,5 +1,5 @@ import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' -import { listWorktrees } from '../git/worktree' +import { listWorktrees } from '../git/worktrees/catalog/worktree-scan-cache' import { OrcaRuntimeService } from './orca-runtime' // Legacy restore cases need finite 5s (the clamp floor); production defaults to indefinite hold. diff --git a/src/main/runtime/multi-client-navigation-isolation.integration.test.ts b/src/main/runtime/multi-client-navigation-isolation.integration.test.ts index 02be3a4fa14..4f62664925c 100644 --- a/src/main/runtime/multi-client-navigation-isolation.integration.test.ts +++ b/src/main/runtime/multi-client-navigation-isolation.integration.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { mkdtempSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' @@ -30,34 +30,38 @@ import { type ResponseReader } from './paired-client-navigation-test-harness' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = ['host', 'client-a', 'client-a2', 'client-b', 'session'].map((name) => ({ - path: `/tmp/${name}`, - head: name, - branch: name, - isBare: false, - isMainWorktree: false - })) - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = ['host', 'client-a', 'client-a2', 'client-b', 'session'].map((name) => ({ + path: `/tmp/${name}`, + head: name, + branch: name, + isBare: false, + isMainWorktree: false + })) + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) + } } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) describe('paired runtime navigation isolation', () => { diff --git a/src/main/runtime/omp-user-bubble-launch-authority.test.ts b/src/main/runtime/omp-user-bubble-launch-authority.test.ts index 08250cb966e..6f07944a9ef 100644 --- a/src/main/runtime/omp-user-bubble-launch-authority.test.ts +++ b/src/main/runtime/omp-user-bubble-launch-authority.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { readFileSync } from 'node:fs' import { join } from 'node:path' import { describe, expect, it, vi } from 'vitest' @@ -15,30 +15,40 @@ const OMP_TRANSCRIPT = readFileSync( 'utf8' ) -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { path: '/tmp/worktree-omp', head: 'abc', branch: 'omp', isBare: false, isMainWorktree: false } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-omp', + head: 'abc', + branch: 'omp', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) + } } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) async function launchOmpPane(): Promise<{ diff --git a/src/main/runtime/opencode-finished-session-authority.test.ts b/src/main/runtime/opencode-finished-session-authority.test.ts index 18b588f7b38..1e679e485c5 100644 --- a/src/main/runtime/opencode-finished-session-authority.test.ts +++ b/src/main/runtime/opencode-finished-session-authority.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { createHash } from 'node:crypto' import { mkdtempSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -22,42 +22,46 @@ const WORKTREE = { isMainWorktree: false } -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/opencode-authority', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/opencode-authority', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/opencode-authority', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/opencode-authority', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) type LaunchedOpenCodePane = { runtime: OrcaRuntimeService diff --git a/src/main/runtime/orca-runtime-git-diff-budget.test.ts b/src/main/runtime/orca-runtime-git-diff-budget.test.ts index b9998638a3d..d41942bf4f2 100644 --- a/src/main/runtime/orca-runtime-git-diff-budget.test.ts +++ b/src/main/runtime/orca-runtime-git-diff-budget.test.ts @@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { REMOTE_RPC_MAX_CONTENT_BYTES } from '../../shared/remote-rpc-content-budget' import type { GitDiffResult } from '../../shared/git-diff-compare-types' import type { GlobalSettings } from '../../shared/global-settings-types' -import type * as GitStatusModule from '../git/status' + import { RuntimeGitCommands } from './orca-runtime-git' import type { ResolvedRuntimeGitWorktree } from './runtime-git-command-target' @@ -12,10 +12,18 @@ const mocks = vi.hoisted(() => ({ getCommitDiff: vi.fn() })) -vi.mock('../git/status', async () => ({ - ...(await vi.importActual('../git/status')), - getDiff: mocks.getDiff, - getBranchDiff: mocks.getBranchDiff, +vi.mock('../git/source-control/file-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getDiff: mocks.getDiff +})) + +vi.mock('../git/source-control/branch-diff', async (importOriginal) => ({ + ...(await importOriginal>()), + getBranchDiff: mocks.getBranchDiff +})) + +vi.mock('../git/source-control/commit-diff', async (importOriginal) => ({ + ...(await importOriginal>()), getCommitDiff: mocks.getCommitDiff })) diff --git a/src/main/runtime/orca-runtime-git.test.ts b/src/main/runtime/orca-runtime-git.test.ts index 7010242b513..0cc35eee851 100644 --- a/src/main/runtime/orca-runtime-git.test.ts +++ b/src/main/runtime/orca-runtime-git.test.ts @@ -3,7 +3,7 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { GlobalSettings } from '../../shared/global-settings-types' -import type * as GitStatusModule from '../git/status' + import type * as CommitMessageTextGenerationModule from '../text-generation/commit-message-text-generation' import type * as PullRequestContextModule from '../text-generation/pull-request-context' import { @@ -27,10 +27,18 @@ const mocks = vi.hoisted(() => ({ getStatus: vi.fn() })) -vi.mock('../git/status', async () => ({ - ...(await vi.importActual('../git/status')), - discardChanges: mocks.discardChanges, - getStagedCommitContext: mocks.getStagedCommitContext, +vi.mock('../git/source-control/discard-changes', async (importOriginal) => ({ + ...(await importOriginal>()), + discardChanges: mocks.discardChanges +})) + +vi.mock('../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), + getStagedCommitContext: mocks.getStagedCommitContext +})) + +vi.mock('../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), getStatus: mocks.getStatus })) diff --git a/src/main/runtime/orca-runtime-linked-issue-live-meta.integration.test.ts b/src/main/runtime/orca-runtime-linked-issue-live-meta.integration.test.ts index 1c1957a55e6..613080e9688 100644 --- a/src/main/runtime/orca-runtime-linked-issue-live-meta.integration.test.ts +++ b/src/main/runtime/orca-runtime-linked-issue-live-meta.integration.test.ts @@ -1,13 +1,13 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { mkdtempSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { WorktreeMeta } from '../../shared/worktree/meta-types' -import type * as GitStatusModule from '../git/status' + import type * as CommitMessageTextGenerationModule from '../text-generation/commit-message-text-generation' -import type * as WorktreeModule from '../git/worktree' + import { OrcaRuntimeService } from './orca-runtime' import type { HostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' @@ -18,28 +18,22 @@ const mocks = vi.hoisted(() => ({ resolveCommitMessageSettings: vi.fn() })) -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { return { ...(await importOriginal()), listWorktrees: mocks.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { return { ...(await importOriginal()), listWorktreesStrict: mocks.listWorktrees } }) -vi.mock('../git/worktree', async () => ({ - ...(await vi.importActual('../git/worktree')), - listWorktrees: mocks.listWorktrees, - listWorktreesStrict: mocks.listWorktrees -})) - -vi.mock('../git/status', async () => ({ - ...(await vi.importActual('../git/status')), +vi.mock('../git/source-control/staged-commit-context', async (importOriginal) => ({ + ...(await importOriginal>()), getStagedCommitContext: mocks.getStagedCommitContext })) diff --git a/src/main/runtime/orca-runtime-test-mocks.spec.ts b/src/main/runtime/orca-runtime-test-mocks.spec.ts index 2e8957c7b21..06aff4faf51 100644 --- a/src/main/runtime/orca-runtime-test-mocks.spec.ts +++ b/src/main/runtime/orca-runtime-test-mocks.spec.ts @@ -81,7 +81,7 @@ export const getEffectiveHooks = importedValues.exportedGetEffectiveHooks export const getEffectiveHooksFromConfig = importedValues.exportedGetEffectiveHooksFromConfig export const getRuntimeBrowserPageRegistry = importedValues.exportedGetRuntimeBrowserPageRegistry export const getTerminalPasteIngestMs = importedValues.exportedGetTerminalPasteIngestMs -export const gitRunner = importedValues.exportedGitRunner + export const hasHooksFile = importedValues.exportedHasHooksFile export const headlessBrowserTabsUnchanged = importedValues.exportedHeadlessBrowserTabsUnchanged export const homedir = importedValues.exportedHomedir diff --git a/src/main/runtime/orca-runtime-test-mocks/imported-values.spec.ts b/src/main/runtime/orca-runtime-test-mocks/imported-values.spec.ts index 41593fc8ede..d12561c8b4a 100644 --- a/src/main/runtime/orca-runtime-test-mocks/imported-values.spec.ts +++ b/src/main/runtime/orca-runtime-test-mocks/imported-values.spec.ts @@ -26,20 +26,25 @@ import { REVIEW_HEAD_FETCH_TIMEOUT_MS } from '../../../shared/review-head-tracking-ref' import { detectAgentStatusFromTitle, MAX_OSC_TITLE_CHARS } from '../../../shared/agent-detection' +import { addSparseWorktree } from '../../git/worktrees/creation/worktree-sparse-add' +import { addWorktree } from '../../git/worktrees/creation/worktree-add' +import { assertWorktreeCleanForRemoval } from '../../git/worktrees/removal/worktree-removal-preflight' import { - addSparseWorktree, - addWorktree, - assertWorktreeCleanForRemoval, describeCreatedWorktree, + listWorktreesStrict +} from '../../git/worktrees/catalog/worktree-listing' +import { listWorktrees, - listWorktreesSharedStrict, - listWorktreesStrict, - removeWorktree -} from '../../git/worktree' -import * as gitRunner from '../../git/runner' + listWorktreesSharedStrict +} from '../../git/worktrees/catalog/worktree-scan-cache' +import { removeWorktree } from '../../git/worktrees/removal/worktree-removal' + import { WORKTREE_PROCESS_SWEEP_TIMEOUT_MS } from '../worktree-teardown' import { WORKTREE_TEARDOWN_RPC_MARGIN_MS } from '../worktree-teardown-deadline' -import { clearSubmodulePathsCacheForTests, listSubmodulePaths } from '../../git/status' +import { + clearSubmodulePathsCacheForTests, + listSubmodulePaths +} from '../../git/source-control/submodule-paths' import { getEffectiveHooks, hasHooksFile, loadHooks, runHook } from '../../workspace-hooks/hooks' import { parseOrcaYaml } from '../../../shared/orca-yaml' import { @@ -115,7 +120,7 @@ import { _resetTerminalViewAttributesForTest, setTerminalViewAttributes } from '../terminal-view-attribute-store' -import { clearConfiguredWorktreeSharedDirectoriesCacheForTests } from '../../git/worktree-shared-directories' +import { clearConfiguredWorktreeSharedDirectoriesCacheForTests } from '../../git/worktrees/content-paths/worktree-shared-directories' import { setWorktreeWatcherRemoval } from '../../ipc/worktree-watcher-removal' import { createRootDispatch } from '../orchestration/db/root-dispatch-test-fixture' @@ -187,7 +192,7 @@ export const exportedGetEffectiveHooks = getEffectiveHooks export const exportedGetEffectiveHooksFromConfig = getEffectiveHooksFromConfig export const exportedGetRuntimeBrowserPageRegistry = getRuntimeBrowserPageRegistry export const exportedGetTerminalPasteIngestMs = getTerminalPasteIngestMs -export const exportedGitRunner = gitRunner + export const exportedHasHooksFile = hasHooksFile export const exportedHeadlessBrowserTabsUnchanged = headlessBrowserTabsUnchanged export const exportedHomedir = homedir diff --git a/src/main/runtime/orca-runtime-test-mocks/setup.spec.ts b/src/main/runtime/orca-runtime-test-mocks/setup.spec.ts index 5b198234cd5..0281ad4ca8d 100644 --- a/src/main/runtime/orca-runtime-test-mocks/setup.spec.ts +++ b/src/main/runtime/orca-runtime-test-mocks/setup.spec.ts @@ -1,4 +1,4 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' import { expect, vi } from 'vitest' import type { Mock } from 'vitest' import type * as GitUsernameModule from '../../git/git-username' @@ -16,11 +16,12 @@ import { setWorktreeWatcherRemoval } from '../../ipc/worktree-watcher-removal' type TestMock = Mock const reconcileClaudeAgentViewMock = vi.hoisted(() => vi.fn(async () => {})) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = await getWorktreeOwnerMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: facade.listWorktrees, + listWorktreesSharedStrict: (await getWorktreeOwnerMocks()).listWorktreesSharedStrict } }) @@ -48,6 +49,11 @@ vi.mock('../../ipc/worktree-symlinks', () => ({ removeWorktreeLinkedPaths: removeWorktreeLinkedPathsMock })) +vi.mock('../../git/worktrees/content-paths/worktree-symlink-detection', async (importOriginal) => ({ + ...(await importOriginal>()), + findExistingWorktreeSymlinkPaths: findExistingWorktreeSymlinkPathsMock +})) + export async function waitForMobileSessionTabsEvents( events: RuntimeMobileSessionTabsResult[], count: number @@ -288,21 +294,53 @@ const { const listWorktreesStrictMock = vi.hoisted(() => vi.fn().mockResolvedValue(MOCK_GIT_WORKTREES)) -vi.mock('../../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ ...(await importOriginal>()), - listWorktreesStrict: listWorktreesStrictMock + listWorktreesStrict: listWorktreesStrictMock, + describeCreatedWorktree: (await getWorktreeOwnerMocks()).describeCreatedWorktree })) -vi.mock('../../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue(MOCK_GIT_WORKTREES), - listWorktreesSharedStrict: vi.fn().mockResolvedValue(MOCK_GIT_WORKTREES), - listWorktreesStrict: listWorktreesStrictMock, - describeCreatedWorktree: vi.fn().mockResolvedValue(undefined), - assertWorktreeCleanForRemoval: vi.fn().mockResolvedValue(undefined), - addSparseWorktree: addSparseWorktreeMock, - addWorktree: addWorktreeMock, - removeWorktree: removeWorktreeMock, - forceDeleteLocalBranch: forceDeleteLocalBranchMock +const { getWorktreeOwnerMocks } = vi.hoisted(() => { + function createWorktreeOwnerMocks() { + return (() => ({ + listWorktrees: vi.fn().mockResolvedValue(MOCK_GIT_WORKTREES), + listWorktreesSharedStrict: vi.fn().mockResolvedValue(MOCK_GIT_WORKTREES), + listWorktreesStrict: listWorktreesStrictMock, + describeCreatedWorktree: vi.fn().mockResolvedValue(undefined), + assertWorktreeCleanForRemoval: vi.fn().mockResolvedValue(undefined), + addSparseWorktree: addSparseWorktreeMock, + addWorktree: addWorktreeMock, + removeWorktree: removeWorktreeMock, + forceDeleteLocalBranch: forceDeleteLocalBranchMock + }))() + } + let fixture: ReturnType | undefined + return { getWorktreeOwnerMocks: () => (fixture ??= createWorktreeOwnerMocks()) } +}) + +vi.mock('../../git/worktrees/removal/worktree-removal-preflight', async (importOriginal) => ({ + ...(await importOriginal>()), + assertWorktreeCleanForRemoval: (await getWorktreeOwnerMocks()).assertWorktreeCleanForRemoval +})) + +vi.mock('../../git/worktrees/creation/worktree-sparse-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addSparseWorktree: (await getWorktreeOwnerMocks()).addSparseWorktree +})) + +vi.mock('../../git/worktrees/creation/worktree-add', async (importOriginal) => ({ + ...(await importOriginal>()), + addWorktree: (await getWorktreeOwnerMocks()).addWorktree +})) + +vi.mock('../../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + removeWorktree: (await getWorktreeOwnerMocks()).removeWorktree +})) + +vi.mock('../../git/worktrees/removal/worktree-branch-removal', async (importOriginal) => ({ + ...(await importOriginal>()), + forceDeleteLocalBranch: (await getWorktreeOwnerMocks()).forceDeleteLocalBranch })) vi.mock('../repo-worktree-resolution-scan', () => ({ diff --git a/src/main/runtime/orca-runtime-test-scenario-builders.spec.ts b/src/main/runtime/orca-runtime-test-scenario-builders.spec.ts index 9327c1a5a51..51d14fb8d39 100644 --- a/src/main/runtime/orca-runtime-test-scenario-builders.spec.ts +++ b/src/main/runtime/orca-runtime-test-scenario-builders.spec.ts @@ -1,3 +1,4 @@ +import * as gitExecFile from '../git/command-runner/git-exec-file' import { CrewChanges } from './orchestration/crew/crew-changes' import { withDurableRuntimeStore } from './runtime-durable-store-fixture' import * as mocks from './orca-runtime-test-mocks.spec' @@ -6,7 +7,7 @@ import type { Mock } from 'vitest' const { HEADLESS_RUNTIME_WINDOW_ID, OrcaRuntimeService, electronMocks } = mocks const { getBrowserHostLeaseRegistry, getDefaultWorkspaceSession, getRuntimeBrowserPageRegistry } = mocks -const { gitRunner, vi } = mocks +const { vi } = mocks import * as fixtures from './orca-runtime-test-fixtures.spec' @@ -389,7 +390,7 @@ function mockReconcileGit(options: { }) { const { postFetchSha = 'new-base-sha', ancestor = true, baseRefMissing = false } = options - return vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args, options) => { + return vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args, options) => { const command = args as string[] const cwd = (options as { cwd?: string } | undefined)?.cwd if ( diff --git a/src/main/runtime/orca-runtime-tests/gitlab-and-pr-bases-part-02.spec.ts b/src/main/runtime/orca-runtime-tests/gitlab-and-pr-bases-part-02.spec.ts index 6b47581d527..5d0da20cf93 100644 --- a/src/main/runtime/orca-runtime-tests/gitlab-and-pr-bases-part-02.spec.ts +++ b/src/main/runtime/orca-runtime-tests/gitlab-and-pr-bases-part-02.spec.ts @@ -1,3 +1,4 @@ +import * as gitExecFile from '../../git/command-runner/git-exec-file' import { SshHostNotServedError } from '../../providers/ssh-host-not-served-error' import { describe, expect, it, vi } from 'vitest' import { @@ -9,7 +10,6 @@ import { getGitLabWorkItemByProjectRefMock, getGlabKnownHostsMock, getPullRequestPushTargetMock, - gitRunner, setPlatform } from '../orca-runtime-test-mocks.spec' import { @@ -106,7 +106,7 @@ describe('OrcaRuntimeService', () => { }) } const runtime = new OrcaRuntimeService(runtimeStore as never) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'symbolic-ref') { return { stdout: 'refs/remotes/origin/main\n', stderr: '' } } @@ -224,7 +224,7 @@ describe('OrcaRuntimeService', () => { path: 'group/repo' }) const runtime = new OrcaRuntimeService(runtimeStore as never) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'remote' && args[1] === 'get-url') { return { stdout: `${ORIGIN_REMOTE_URL}\n`, stderr: '' } } @@ -296,7 +296,7 @@ describe('OrcaRuntimeService', () => { }) const runtime = new OrcaRuntimeService(runtimeStore as never) // Concurrent fetch overwrites FETCH_HEAD; durable Orca MR refs must retain compare-base authority. - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'remote' && args[1] === 'get-url') { return { stdout: `${ORIGIN_REMOTE_URL}\n`, stderr: '' } } @@ -358,7 +358,7 @@ describe('OrcaRuntimeService', () => { path: 'group/repo' }) const runtime = new OrcaRuntimeService(runtimeStore as never) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'remote' && args[1] === 'get-url') { return { stdout: `${ORIGIN_REMOTE_URL}\n`, stderr: '' } } @@ -424,7 +424,7 @@ describe('OrcaRuntimeService', () => { path: 'group/repo' }) const runtime = new OrcaRuntimeService(runtimeStore as never) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'remote' && args[1] === 'get-url') { return { stdout: `${ORIGIN_REMOTE_URL}\n`, stderr: '' } } @@ -498,7 +498,7 @@ describe('OrcaRuntimeService', () => { }) } const runtime = new OrcaRuntimeService(runtimeStore as never) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'remote' && args[1] === 'get-url') { return { stdout: `${ORIGIN_REMOTE_URL}\n`, stderr: '' } } diff --git a/src/main/runtime/orca-runtime-tests/gitlab-and-pr-bases-part-03.spec.ts b/src/main/runtime/orca-runtime-tests/gitlab-and-pr-bases-part-03.spec.ts index f2aab1bfaa8..c1379d2c10a 100644 --- a/src/main/runtime/orca-runtime-tests/gitlab-and-pr-bases-part-03.spec.ts +++ b/src/main/runtime/orca-runtime-tests/gitlab-and-pr-bases-part-03.spec.ts @@ -1,10 +1,10 @@ +import * as gitExecFile from '../../git/command-runner/git-exec-file' import { SshHostNotServedError } from '../../providers/ssh-host-not-served-error' import { describe, expect, it, vi } from 'vitest' import { OrcaRuntimeService, getGitLabProjectRefForRemoteMock, - getGlabKnownHostsMock, - gitRunner + getGlabKnownHostsMock } from '../orca-runtime-test-mocks.spec' import { TEST_REPO_ID, TEST_REPO_PATH, store } from '../orca-runtime-test-fixtures.spec' @@ -24,7 +24,7 @@ describe('OrcaRuntimeService', () => { getRepos: () => [remoteRepo], getRepo: (id: string) => (id === remoteRepo.id ? remoteRepo : undefined) } - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync') + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync') const runtime = new OrcaRuntimeService(runtimeStore as never) await expect( @@ -61,7 +61,7 @@ describe('OrcaRuntimeService', () => { path: 'group/repo' }) const runtime = new OrcaRuntimeService(runtimeStore as never) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if ( args[0] === 'fetch' && args[2] === '+refs/heads/feature/fix:refs/remotes/origin/feature/fix' @@ -118,7 +118,7 @@ describe('OrcaRuntimeService', () => { path: 'group/repo' }) const runtime = new OrcaRuntimeService(runtimeStore as never) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if ( args[0] === 'fetch' && args[2] === '+refs/heads/feature/fix:refs/remotes/origin/feature/fix' diff --git a/src/main/runtime/orca-runtime-tests/hooks-and-hosted-review-part-03.spec.ts b/src/main/runtime/orca-runtime-tests/hooks-and-hosted-review-part-03.spec.ts index d243b99c082..9bc2ddbfde1 100644 --- a/src/main/runtime/orca-runtime-tests/hooks-and-hosted-review-part-03.spec.ts +++ b/src/main/runtime/orca-runtime-tests/hooks-and-hosted-review-part-03.spec.ts @@ -1,5 +1,6 @@ +import * as gitExecFile from '../../git/command-runner/git-exec-file' import { describe, expect, it, vi } from 'vitest' -import { OrcaRuntimeService, gitRunner, setPlatform } from '../orca-runtime-test-mocks.spec' +import { OrcaRuntimeService, setPlatform } from '../orca-runtime-test-mocks.spec' import { readHostedReviewForBranch } from '../../source-control/hosted-review' import type { HostedReviewInfo } from '../../../shared/hosted-review' import { @@ -35,30 +36,32 @@ describe('OrcaRuntimeService', () => { const runtime = new OrcaRuntimeService(runtimeStore as never) const wslGitOptions = { cwd: TEST_REPO_PATH, wslDistro: 'Ubuntu' } let driftCounts = '1\t2\n' - const asyncGitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { - if (args[0] === 'for-each-ref' && args.includes('--format=%(refname)%00%(symref)')) { - return { stdout: 'refs/remotes/origin/HEAD\0refs/remotes/origin/main\n', stderr: '' } - } - if (isOriginMainBaseRefProbe(args)) { - return { stdout: 'main-sha\n', stderr: '' } - } - if (args[0] === 'remote') { - return { stdout: 'origin\n', stderr: '' } - } - if (args[0] === 'rev-parse' && args.includes('--git-common-dir')) { - return { stdout: `${TEST_REPO_PATH}/.git\n`, stderr: '' } - } - if (args[0] === 'fetch') { - return { stdout: '', stderr: '' } - } - if (args[0] === 'rev-list') { - return { stdout: driftCounts, stderr: '' } - } - if (args[0] === 'log') { - return { stdout: 'base commit 2\nbase commit 1\n', stderr: '' } - } - throw new Error(`unexpected git call: ${args.join(' ')}`) - }) + const asyncGitSpy = vi + .spyOn(gitExecFile, 'gitExecFileAsync') + .mockImplementation(async (args) => { + if (args[0] === 'for-each-ref' && args.includes('--format=%(refname)%00%(symref)')) { + return { stdout: 'refs/remotes/origin/HEAD\0refs/remotes/origin/main\n', stderr: '' } + } + if (isOriginMainBaseRefProbe(args)) { + return { stdout: 'main-sha\n', stderr: '' } + } + if (args[0] === 'remote') { + return { stdout: 'origin\n', stderr: '' } + } + if (args[0] === 'rev-parse' && args.includes('--git-common-dir')) { + return { stdout: `${TEST_REPO_PATH}/.git\n`, stderr: '' } + } + if (args[0] === 'fetch') { + return { stdout: '', stderr: '' } + } + if (args[0] === 'rev-list') { + return { stdout: driftCounts, stderr: '' } + } + if (args[0] === 'log') { + return { stdout: 'base commit 2\nbase commit 1\n', stderr: '' } + } + throw new Error(`unexpected git call: ${args.join(' ')}`) + }) try { const result = await runtime.probeWorktreeDrift(`id:${TEST_WORKTREE_ID}`) diff --git a/src/main/runtime/orca-runtime-tests/local-worktree-creation-part-02.spec.ts b/src/main/runtime/orca-runtime-tests/local-worktree-creation-part-02.spec.ts index 3218947baa2..374cc069615 100644 --- a/src/main/runtime/orca-runtime-tests/local-worktree-creation-part-02.spec.ts +++ b/src/main/runtime/orca-runtime-tests/local-worktree-creation-part-02.spec.ts @@ -1,3 +1,4 @@ +import * as gitExecFile from '../../git/command-runner/git-exec-file' import { describe, expect, it, vi } from 'vitest' import { OrcaRuntimeService, @@ -7,7 +8,6 @@ import { getBranchConflictKind, getHostedReviewForBranchMock, getPRForBranchMock, - gitRunner, listWorktrees } from '../orca-runtime-test-mocks.spec' import { TEST_REPO_PATH, store } from '../orca-runtime-test-fixtures.spec' @@ -36,7 +36,7 @@ describe('OrcaRuntimeService', () => { updatedAt: '2026-05-21T00:00:00Z', mergeable: 'UNKNOWN' }) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockResolvedValue({ + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockResolvedValue({ stdout: '', stderr: '' }) @@ -95,7 +95,7 @@ describe('OrcaRuntimeService', () => { ensurePathWithinWorkspaceMock.mockReturnValue(createdWorktree.path) vi.mocked(getBranchConflictKind).mockResolvedValueOnce(null) vi.mocked(listWorktrees).mockResolvedValueOnce([createdWorktree]) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'remote') { return { stdout: 'origin\n', stderr: '' } } @@ -158,7 +158,7 @@ describe('OrcaRuntimeService', () => { updatedAt: '2026-05-21T00:00:00Z', mergeable: 'UNKNOWN' }) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockResolvedValue({ + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockResolvedValue({ stdout: '', stderr: '' }) @@ -231,7 +231,7 @@ describe('OrcaRuntimeService', () => { updatedAt: '2026-05-21T00:00:00Z', mergeable: 'UNKNOWN' }) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'rev-parse' && args.includes('refs/heads/feature/fix^{commit}')) { throw new Error('missing local branch') } @@ -280,7 +280,7 @@ describe('OrcaRuntimeService', () => { ensurePathWithinWorkspaceMock.mockImplementation((pathValue: string) => pathValue) vi.mocked(getBranchConflictKind).mockResolvedValueOnce('remote') vi.mocked(listWorktrees).mockResolvedValueOnce([createdWorktree]) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'rev-parse' && args.includes('refs/heads/feature/fix^{commit}')) { throw new Error('missing local branch') } @@ -338,7 +338,7 @@ describe('OrcaRuntimeService', () => { updatedAt: '2026-05-21T00:00:00Z', mergeable: 'UNKNOWN' }) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'rev-parse' && args.includes('refs/heads/feature/fix^{commit}')) { throw new Error('missing local branch') } @@ -389,7 +389,7 @@ describe('OrcaRuntimeService', () => { vi.mocked(getBranchConflictKind).mockResolvedValueOnce('remote') vi.mocked(listWorktrees).mockResolvedValueOnce([createdWorktree]) getPRForBranchMock.mockRejectedValueOnce(new Error('gh unavailable')) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'rev-parse' && args.includes('refs/heads/feature/fix^{commit}')) { throw new Error('missing local branch') } @@ -447,7 +447,7 @@ describe('OrcaRuntimeService', () => { } ]) .mockResolvedValueOnce([createdWorktree]) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'rev-parse' && args.includes('refs/heads/feature/fix^{commit}')) { return { stdout: 'abc123\n', stderr: '' } } @@ -514,7 +514,7 @@ describe('OrcaRuntimeService', () => { } ]) .mockResolvedValueOnce([createdWorktree]) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'rev-parse' && args.includes('refs/heads/feature/fix^{commit}')) { return { stdout: 'abc123\n', stderr: '' } } diff --git a/src/main/runtime/orca-runtime-tests/local-worktree-creation.spec.ts b/src/main/runtime/orca-runtime-tests/local-worktree-creation.spec.ts index e223e3d80bf..dc50ef102cb 100644 --- a/src/main/runtime/orca-runtime-tests/local-worktree-creation.spec.ts +++ b/src/main/runtime/orca-runtime-tests/local-worktree-creation.spec.ts @@ -1,3 +1,4 @@ +import * as gitExecFile from '../../git/command-runner/git-exec-file' import { describe, expect, it, onTestFinished, vi } from 'vitest' import { OrcaRuntimeService, @@ -9,7 +10,6 @@ import { resolveDefaultBaseRefWithLocalGit, getBranchConflictKind, getPRForBranchMock, - gitRunner, listWorktrees, resolveLocalGitUsernameMock } from '../orca-runtime-test-mocks.spec' @@ -167,7 +167,7 @@ describe('OrcaRuntimeService', () => { computeWorktreePathMock.mockReturnValue(createdWorktree.path) ensurePathWithinWorkspaceMock.mockReturnValue(createdWorktree.path) vi.mocked(listWorktrees).mockResolvedValueOnce([createdWorktree]) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'rev-parse' && args.includes('refs/heads/cli-fresh-base^{commit}')) { throw new Error('branch not found') } @@ -262,7 +262,7 @@ describe('OrcaRuntimeService', () => { } }) vi.mocked(listWorktrees).mockResolvedValueOnce([createdWorktree]) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'rev-parse' && args.includes('refs/heads/cli-stale-main^{commit}')) { throw new Error('branch not found') } @@ -308,7 +308,7 @@ describe('OrcaRuntimeService', () => { ensurePathWithinWorkspaceMock.mockReturnValue(createdWorktree.path) vi.mocked(addWorktree).mockResolvedValueOnce({}) vi.mocked(listWorktrees).mockResolvedValue([createdWorktree]) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'remote') { return { stdout: 'origin\n', stderr: '' } } @@ -373,7 +373,7 @@ describe('OrcaRuntimeService', () => { ensurePathWithinWorkspaceMock.mockReturnValue(createdWorktree.path) vi.mocked(addWorktree).mockResolvedValueOnce({}) vi.mocked(listWorktrees).mockResolvedValue([createdWorktree]) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'remote') { return { stdout: 'origin\n', stderr: '' } } @@ -426,7 +426,7 @@ describe('OrcaRuntimeService', () => { ensurePathWithinWorkspaceMock.mockReturnValue(createdWorktree.path) vi.mocked(addWorktree).mockResolvedValueOnce({}) vi.mocked(listWorktrees).mockResolvedValue([createdWorktree]) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'remote') { return { stdout: 'team\norigin\n', stderr: '' } } @@ -486,7 +486,7 @@ describe('OrcaRuntimeService', () => { const runtime = new OrcaRuntimeService(store) computeWorktreePathMock.mockReturnValue('/tmp/workspaces/cli-refresh-no-local') ensurePathWithinWorkspaceMock.mockReturnValue('/tmp/workspaces/cli-refresh-no-local') - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'remote') { return { stdout: 'origin\n', stderr: '' } } @@ -530,7 +530,7 @@ describe('OrcaRuntimeService', () => { ensurePathWithinWorkspaceMock.mockReturnValue(createdWorktree.path) vi.mocked(addWorktree).mockResolvedValueOnce({}) vi.mocked(listWorktrees).mockResolvedValue([createdWorktree]) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'remote') { return { stdout: 'origin\n', stderr: '' } } @@ -586,7 +586,7 @@ describe('OrcaRuntimeService', () => { it('creates a branchNameOverride worktree from the selected matching remote base ref', async () => { const runtime = new OrcaRuntimeService(store) const gitSpy = vi - .spyOn(gitRunner, 'gitExecFileAsync') + .spyOn(gitExecFile, 'gitExecFileAsync') .mockResolvedValue({ stdout: '', stderr: '' }) onTestFinished(() => gitSpy.mockRestore()) computeWorktreePathMock.mockReturnValue('/tmp/workspaces/feature-something') @@ -664,7 +664,7 @@ describe('OrcaRuntimeService', () => { } ]) .mockResolvedValueOnce([createdWorktree]) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'rev-parse' && args[1] === '--verify') { return { stdout: 'branch-sha\n', stderr: '' } } diff --git a/src/main/runtime/orca-runtime-tests/repository-project-operations-part-02.spec.ts b/src/main/runtime/orca-runtime-tests/repository-project-operations-part-02.spec.ts index 12dff525eb2..6837b45b050 100644 --- a/src/main/runtime/orca-runtime-tests/repository-project-operations-part-02.spec.ts +++ b/src/main/runtime/orca-runtime-tests/repository-project-operations-part-02.spec.ts @@ -1,3 +1,4 @@ +import * as gitSpawn from '../../git/command-runner/git-spawn' import { realpath } from 'node:fs/promises' import { describe, expect, it, vi } from 'vitest' import { @@ -7,7 +8,6 @@ import { clearSubmodulePathsCacheForTests, execFileSync, getRepoUpstreamMock, - gitRunner, invalidateAuthorizedRootsCacheMock, join, listSubmodulePaths, @@ -33,7 +33,7 @@ describe('OrcaRuntimeService', () => { it('adopts public clone repos into host-qualified project setup', async () => { const destination = await mkdtemp(join(tmpdir(), 'orca-runtime-project-clone-')) const clonePath = join(destination, 'orca') - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const repos: Record[] = [] getRepoUpstreamMock.mockResolvedValue({ owner: 'stablyai', repo: 'orca' }) const runtimeStore = { @@ -103,7 +103,7 @@ describe('OrcaRuntimeService', () => { it('keeps project clone repos split by runtime host on the same clone path', async () => { const destination = await mkdtemp(join(tmpdir(), 'orca-runtime-project-clone-')) const clonePath = join(destination, 'orca') - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const repos: Record[] = [ { id: 'repo-host-a', @@ -275,7 +275,7 @@ describe('OrcaRuntimeService', () => { }) it('defaults runtime cloneRepo badgeColor to DEFAULT_REPO_BADGE_COLOR', async () => { - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const added: Record[] = [] const colorStore = { ...store, @@ -314,7 +314,7 @@ describe('OrcaRuntimeService', () => { }) it('drops a same-path negative submodule cache before runtime cloneRepo', async () => { - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const destination = await mkdtemp(join(tmpdir(), 'orca-runtime-reclone-')) const clonePath = join(destination, 'reclone') const added: Record[] = [] @@ -355,7 +355,7 @@ describe('OrcaRuntimeService', () => { join(await realpath(tmpdir()), 'orca-runtime-folder-upgrade-') ) const clonePath = join(destination, 'repo-badge-color') - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') spawnSpy.mockImplementation(() => { const proc = new EventEmitter() as EventEmitter & { stderr: EventEmitter } proc.stderr = new EventEmitter() @@ -466,7 +466,7 @@ describe('OrcaRuntimeService', () => { }) it('rejects runtime cloneRepo dot-segment URLs before spawning git', async () => { - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const runtime = createRuntime() const tempRoot = await mkdtemp(join(tmpdir(), 'orca-runtime-clone-')) const destination = join(tempRoot, 'destination') @@ -483,7 +483,7 @@ describe('OrcaRuntimeService', () => { }) it('rejects runtime cloneRepo parent-segment URLs before spawning git', async () => { - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const runtime = createRuntime() const tempRoot = await mkdtemp(join(tmpdir(), 'orca-runtime-clone-')) const destination = join(tempRoot, 'destination') @@ -500,7 +500,7 @@ describe('OrcaRuntimeService', () => { }) it('removes an owned runtime clone target when git exits unsuccessfully', async () => { - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const proc = new EventEmitter() as EventEmitter & { stderr: EventEmitter } proc.stderr = new EventEmitter() spawnSpy.mockResolvedValue(proc as never) @@ -527,7 +527,7 @@ describe('OrcaRuntimeService', () => { }) it('preserves an existing runtime clone target when git exits unsuccessfully', async () => { - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const proc = new EventEmitter() as EventEmitter & { stderr: EventEmitter } proc.stderr = new EventEmitter() spawnSpy.mockResolvedValue(proc as never) @@ -554,7 +554,7 @@ describe('OrcaRuntimeService', () => { }) it('skips runtime clone failure cleanup when the owned target is replaced', async () => { - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const proc = new EventEmitter() as EventEmitter & { stderr: EventEmitter } proc.stderr = new EventEmitter() spawnSpy.mockResolvedValue(proc as never) @@ -583,7 +583,7 @@ describe('OrcaRuntimeService', () => { }) it('serializes concurrent runtime clones for the same target', async () => { - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const firstProc = new EventEmitter() as EventEmitter & { stderr: EventEmitter } firstProc.stderr = new EventEmitter() spawnSpy.mockResolvedValueOnce(firstProc as never) @@ -639,7 +639,7 @@ describe('OrcaRuntimeService', () => { }) it('refuses a saved project at the clone path whose folder is not a clone of the URL', async () => { - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const destination = await mkdtemp(join(tmpdir(), 'orca-runtime-clone-')) const saved = { id: 'saved-project', @@ -663,7 +663,7 @@ describe('OrcaRuntimeService', () => { }) it('clones past a saved SSH project that shares the clone path', async () => { - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const destination = await mkdtemp(join(tmpdir(), 'orca-runtime-clone-')) const sshProject = { id: 'ssh-project', diff --git a/src/main/runtime/orca-runtime-tests/repository-project-operations.spec.ts b/src/main/runtime/orca-runtime-tests/repository-project-operations.spec.ts index 20219a930f8..75e10297bdf 100644 --- a/src/main/runtime/orca-runtime-tests/repository-project-operations.spec.ts +++ b/src/main/runtime/orca-runtime-tests/repository-project-operations.spec.ts @@ -1,3 +1,4 @@ +import * as gitSpawn from '../../git/command-runner/git-spawn' import { describe, expect, it, vi } from 'vitest' import { realpath } from 'node:fs/promises' import * as folderPathStatus from '../../project-groups/folder-workspace-path-status' @@ -7,7 +8,6 @@ import { OrcaRuntimeService, execFileSync, getRepoUpstreamMock, - gitRunner, join, mkdir, mkdirSync, @@ -555,7 +555,7 @@ describe('OrcaRuntimeService', () => { it('keeps project clone setup on the cloned host-qualified repo', async () => { const destination = await mkdtemp(join(tmpdir(), 'orca-runtime-project-clone-')) const clonePath = join(destination, 'orca') - const spawnSpy = vi.spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + const spawnSpy = vi.spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') const repos: Record[] = [] getRepoUpstreamMock.mockResolvedValue({ owner: 'stablyai', repo: 'orca' }) const runtimeStore = { @@ -621,7 +621,7 @@ describe('OrcaRuntimeService', () => { mkdirSync(existingFolder, { recursive: true }) execFileSync('git', ['init'], { cwd: existingFolder, stdio: 'ignore' }) const spawnSpy = vi - .spyOn(gitRunner, 'gitSpawnAfterWindowsEnvironmentReady') + .spyOn(gitSpawn, 'gitSpawnAfterWindowsEnvironmentReady') .mockImplementation(() => { // If the guard regresses, record the attempted clone without reaching the network. const proc = new EventEmitter() as EventEmitter & { stderr: EventEmitter } diff --git a/src/main/runtime/orca-runtime-tests/ssh-worktree-lifecycle.spec.ts b/src/main/runtime/orca-runtime-tests/ssh-worktree-lifecycle.spec.ts index 366c5c3d4e5..e64ca92070c 100644 --- a/src/main/runtime/orca-runtime-tests/ssh-worktree-lifecycle.spec.ts +++ b/src/main/runtime/orca-runtime-tests/ssh-worktree-lifecycle.spec.ts @@ -1,3 +1,4 @@ +import * as gitExecFile from '../../git/command-runner/git-exec-file' import { describe, expect, it, vi } from 'vitest' import { OrcaRuntimeService, @@ -5,7 +6,6 @@ import { computeWorktreePathMock, ensurePathWithinWorkspaceMock, getBranchConflictKind, - gitRunner, listWorktrees } from '../orca-runtime-test-mocks.spec' import { SshHostNotServedError } from '../../providers/ssh-host-not-served-error' @@ -26,7 +26,7 @@ describe('OrcaRuntimeService', () => { computeWorktreePathMock.mockReturnValue(process.cwd()) ensurePathWithinWorkspaceMock.mockImplementation((pathValue: string) => pathValue) vi.mocked(getBranchConflictKind).mockResolvedValueOnce(null) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'rev-parse' && args.includes('refs/heads/feature/fix^{commit}')) { throw new Error('missing local branch') } diff --git a/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-02.spec.ts b/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-02.spec.ts index f4d532d2dfb..79fce4fa8f5 100644 --- a/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-02.spec.ts +++ b/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-02.spec.ts @@ -1,6 +1,10 @@ +import type * as WorktreeRemovalModule from '../../git/worktrees/removal/worktree-removal' +import * as gitExecFile from '../../git/command-runner/git-exec-file' import { describe, expect, it, vi } from 'vitest' import { readFile } from 'node:fs/promises' -import { removeWorktree as removeNativeWorktree } from '../../git/worktree-removal' +const { removeWorktree: removeNativeWorktree } = await vi.importActual< + typeof WorktreeRemovalModule +>('../../git/worktrees/removal/worktree-removal') import { MOCK_GIT_WORKTREES, @@ -13,7 +17,6 @@ import { forceDeleteLocalBranchMock, forgetLocalWatcherRemovalSnapshotMock, getEffectiveHooks, - gitRunner, join, listWorktrees, listWorktreesStrict, @@ -265,7 +268,7 @@ describe('OrcaRuntimeService', () => { const warning = vi.spyOn(console, 'warn').mockImplementation(() => {}) await mkdir(TEST_WORKTREE_PATH, { recursive: true }) await writeFile(join(TEST_WORKTREE_PATH, 'scratch.txt'), 'delete me') - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockResolvedValue({ + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockResolvedValue({ stdout: '', stderr: '' }) @@ -316,7 +319,7 @@ describe('OrcaRuntimeService', () => { removeWorktreeMeta } const runtime = createWorktreeRemovalRuntime(runtimeStore) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockResolvedValue({ + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockResolvedValue({ stdout: '', stderr: '' }) @@ -370,7 +373,7 @@ describe('OrcaRuntimeService', () => { isMainWorktree: false } ] - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'branch') { throw new Error('branch is not fully merged') } diff --git a/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-03.spec.ts b/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-03.spec.ts index 96fb164b70f..e26b432d4b9 100644 --- a/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-03.spec.ts +++ b/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-03.spec.ts @@ -1,3 +1,4 @@ +import * as gitExecFile from '../../git/command-runner/git-exec-file' import { describe, expect, it, vi, type MockInstance } from 'vitest' import { readFile } from 'node:fs/promises' import { _settlePendingWorktreeRemovalsForTests } from '../../workspaces/removal/worktree-background-removal' @@ -7,7 +8,6 @@ import { closeLocalWatcherForWorktreePathMock, deleteWorktreeHistoryDirMock, forceDeleteLocalBranchMock, - gitRunner, invalidateAuthorizedRootsCacheMock, join, listWorktrees, @@ -59,7 +59,7 @@ describe('OrcaRuntimeService', () => { vi.mocked(removeWorktree).mockResolvedValue({ preservedBranch: { branchName: 'feature/test', head: 'def456' } }) - const gitExec = vi.spyOn(gitRunner, 'gitExecFileAsync').mockResolvedValue({ + const gitExec = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockResolvedValue({ stdout: '', stderr: '' }) @@ -357,7 +357,7 @@ describe('OrcaRuntimeService', () => { const runtime = createWorktreeRemovalRuntime(runtimeStoreWithRepoPath) const notifier = { worktreesChanged: vi.fn() } runtime.setNotifier(notifier as never) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'status') { throw new Error('fatal: not a git repository') } diff --git a/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-04.spec.ts b/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-04.spec.ts index 9de55056192..969b7a43286 100644 --- a/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-04.spec.ts +++ b/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation-part-04.spec.ts @@ -1,3 +1,4 @@ +import * as gitExecFile from '../../git/command-runner/git-exec-file' import { describe, expect, it, onTestFinished, vi } from 'vitest' import { MOCK_GIT_WORKTREES, @@ -7,7 +8,6 @@ import { computeWorktreePathMock, ensurePathWithinWorkspaceMock, getEffectiveHooks, - gitRunner, join, listWorktrees, listWorktreesStrict, @@ -333,7 +333,7 @@ describe('OrcaRuntimeService', () => { stderr: 'fatal: not a git repository (or any of the parent directories): .git\n' }) ) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockResolvedValue({ + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockResolvedValue({ stdout: '', stderr: '' }) @@ -418,7 +418,7 @@ describe('OrcaRuntimeService', () => { const removePathSpy = vi .spyOn(localWorktreeFilesystem, 'removeLocalWorktreePath') .mockRejectedValue(new Error('injected removal failure')) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockResolvedValue({ + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockResolvedValue({ stdout: '', stderr: '' }) @@ -452,7 +452,7 @@ describe('OrcaRuntimeService', () => { }) ) const gitSpy = vi - .spyOn(gitRunner, 'gitExecFileAsync') + .spyOn(gitExecFile, 'gitExecFileAsync') .mockResolvedValue({ stdout: '', stderr: '' }) onTestFinished(() => gitSpy.mockRestore()) diff --git a/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation.spec.ts b/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation.spec.ts index 3e5594772b0..df3bd273a46 100644 --- a/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation.spec.ts +++ b/src/main/runtime/orca-runtime-tests/worktree-removal-and-reconciliation.spec.ts @@ -1,3 +1,4 @@ +import * as gitExecFile from '../../git/command-runner/git-exec-file' import { describe, expect, it, vi } from 'vitest' import { OrcaRuntimeService, @@ -13,7 +14,6 @@ import { getBranchConflictKind, getEffectiveHooks, getPRForBranchMock, - gitRunner, invalidateAuthorizedRootsCacheMock, listWorktrees, loadHooks, @@ -330,7 +330,7 @@ describe('OrcaRuntimeService', () => { computeWorktreePathMock.mockReturnValue(createdWorktree.path) ensurePathWithinWorkspaceMock.mockReturnValue(createdWorktree.path) vi.mocked(describeCreatedWorktree).mockResolvedValue(createdWorktree) - const gitSpy = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => { + const gitSpy = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => { if (args[0] === 'for-each-ref' && args.includes('--format=%(refname)%00%(symref)')) { return { stdout: 'refs/remotes/origin/HEAD\0refs/remotes/origin/main\n', stderr: '' } } diff --git a/src/main/runtime/orca-runtime-windowless-terminal-activity.test.ts b/src/main/runtime/orca-runtime-windowless-terminal-activity.test.ts index 7cf91838c9f..1d9fff33ab4 100644 --- a/src/main/runtime/orca-runtime-windowless-terminal-activity.test.ts +++ b/src/main/runtime/orca-runtime-windowless-terminal-activity.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { describe, expect, it, vi } from 'vitest' import { OrcaRuntimeService } from './orca-runtime' import { makeStore } from './runtime-rpc-worktree-store-fixtures' @@ -8,30 +8,34 @@ import { publishHeadlessRuntimeGraph } from './headless-runtime-graph' const WORKTREE_PATH = '/tmp/worktree-a' const WORKTREE_ID = 'repo-1::/tmp/worktree-a' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { path: '/tmp/worktree-a', head: 'abc', branch: 'main', isBare: false, isMainWorktree: false } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { path: '/tmp/worktree-a', head: 'abc', branch: 'main', isBare: false, isMainWorktree: false } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) + } } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) function createRuntime(attach: 'headless' | 'window') { diff --git a/src/main/runtime/orca-runtime-worktree-change-invalidation.test.ts b/src/main/runtime/orca-runtime-worktree-change-invalidation.test.ts index d001ee00970..ccd48aef531 100644 --- a/src/main/runtime/orca-runtime-worktree-change-invalidation.test.ts +++ b/src/main/runtime/orca-runtime-worktree-change-invalidation.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' // Headless hosts never load ipc/worktrees; runtime changes must invalidate both scan generation and cache. import { beforeEach, describe, expect, it, vi } from 'vitest' import type { Repo } from '../../shared/repo-types' @@ -17,7 +17,7 @@ const electronMocks = vi.hoisted(() => { app: { getPath: vi.fn(() => '/tmp'), isPackaged: false } } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { return { ...(await importOriginal()), listWorktreesStrict: listWorktreesStrictMock @@ -27,10 +27,6 @@ vi.mock('../git/worktree-listing', async (importOriginal) => { vi.mock('electron', () => electronMocks) const listWorktreesStrictMock = vi.hoisted(() => vi.fn()) -vi.mock('../git/worktree', async (importOriginal) => ({ - ...(await importOriginal>()), - listWorktreesStrict: listWorktreesStrictMock -})) vi.mock('./repo-worktree-admin-fingerprint', () => ({ readRepoWorktreeAdminFingerprint: vi.fn(async () => null) diff --git a/src/main/runtime/peer-desktops.integration.test.ts b/src/main/runtime/peer-desktops.integration.test.ts index bd8cf77687b..e24ae6dfa4e 100644 --- a/src/main/runtime/peer-desktops.integration.test.ts +++ b/src/main/runtime/peer-desktops.integration.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' @@ -27,26 +27,30 @@ import { makeStore } from './runtime-rpc-worktree-store-fixtures' import { DECLARED_CLIENT_RECONNECT_GRACE_MS } from './declared-desktop-clients' import { partialRuntimeStore } from './runtime-store-partial-fixture' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) const STABLE = 'stable-installation-id' const DEV = 'dev-installation-id-01' diff --git a/src/main/runtime/remote-desktop-driver.test.ts b/src/main/runtime/remote-desktop-driver.test.ts index f20e24a0d4b..d8f6ca88037 100644 --- a/src/main/runtime/remote-desktop-driver.test.ts +++ b/src/main/runtime/remote-desktop-driver.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' /** Desktop viewers suppress host resize, never input; mobile drivers retain priority and the final viewer releases its floor. */ import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest' import type * as GitUsernameModule from '../git/git-username' @@ -8,16 +8,16 @@ import { createPtyWriteInput } from '../ipc/pty/ipc/write-input' import { ptyOwnership } from '../ipc/pty/provider/ownership-state' const { hostProviderWrite } = vi.hoisted(() => ({ hostProviderWrite: vi.fn(() => true) })) -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict @@ -29,10 +29,14 @@ vi.mock('../ipc/pty/provider/registry', async (importOriginal) => ({ tryGetProviderForPty: () => ({ write: hostProviderWrite, hasPty: () => true }) })) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) vi.mock('../workspace-hooks/hooks', () => ({ getEffectiveHooks: vi.fn().mockReturnValue(null), runHook: vi.fn().mockResolvedValue({ success: true, output: '' }) diff --git a/src/main/runtime/repo-worktree-resolution-scan.test.ts b/src/main/runtime/repo-worktree-resolution-scan.test.ts index 9d85d07fd58..6604fe0948f 100644 --- a/src/main/runtime/repo-worktree-resolution-scan.test.ts +++ b/src/main/runtime/repo-worktree-resolution-scan.test.ts @@ -1,8 +1,10 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' -import { listWorktreesStrict } from '../git/worktree' +import { listWorktreesStrict } from '../git/worktrees/catalog/worktree-listing' import { scanLocalRepoWorktreesForResolution } from './repo-worktree-resolution-scan' -vi.mock('../git/worktree', () => ({ listWorktreesStrict: vi.fn() })) +vi.mock('../git/worktrees/catalog/worktree-listing', () => ({ + listWorktreesStrict: vi.fn() +})) describe('scanLocalRepoWorktreesForResolution', () => { beforeEach(() => { diff --git a/src/main/runtime/repo-worktree-resolution-scan.ts b/src/main/runtime/repo-worktree-resolution-scan.ts index 0d9130371b3..9753fa6044a 100644 --- a/src/main/runtime/repo-worktree-resolution-scan.ts +++ b/src/main/runtime/repo-worktree-resolution-scan.ts @@ -1,5 +1,5 @@ import type { GitWorktreeInfo } from '../../shared/worktree/types' -import { listWorktreesStrict } from '../git/worktree' +import { listWorktreesStrict } from '../git/worktrees/catalog/worktree-listing' import type { LocalProjectWorktreeGitOptions } from '../workspaces/execution-host/project-runtime-git-options' export type RuntimeWorktreeScanResult = diff --git a/src/main/runtime/repo-worktree-row-resolution.ts b/src/main/runtime/repo-worktree-row-resolution.ts index d5b591df4d5..340c00f6e45 100644 --- a/src/main/runtime/repo-worktree-row-resolution.ts +++ b/src/main/runtime/repo-worktree-row-resolution.ts @@ -24,7 +24,7 @@ import type { WorktreeMeta } from '../../shared/worktree/meta-types' import type { ProjectExecutionRuntimeResolution } from '../../shared/project-execution-runtime' import type { RuntimeStore } from './runtime-store-contract' -import { areWorktreePathsEqual } from '../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../git/worktrees/catalog/worktree-path-comparison' import { mergeWorktree } from '../ipc/worktree-metadata-merge' import { pruneLineageForMissingRepoWorktrees } from '../workspaces/catalog/worktree-lineage-pruning' import { getRepoOwnedWorktreeMeta } from '../workspaces/catalog/worktree-metadata-ownership' diff --git a/src/main/runtime/rpc/methods/agent-launch-terminal-prompt-writer.test.ts b/src/main/runtime/rpc/methods/agent-launch-terminal-prompt-writer.test.ts index e71b7c52e3a..716b3ff4c07 100644 --- a/src/main/runtime/rpc/methods/agent-launch-terminal-prompt-writer.test.ts +++ b/src/main/runtime/rpc/methods/agent-launch-terminal-prompt-writer.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../../git/worktrees/catalog/worktree-listing' /** A cancelled launch prompt against the real writer: text whose Enter was written is delivered, * whichever later check the abort then trips. */ @@ -8,34 +8,38 @@ import type { TuiAgent } from '../../../../shared/tui-agent' import { createAgentPromptSubmissionRuntime } from '../../agent-prompt-submission-runtime-test-fixture' import { deliverTerminalAgentLaunchPrompt } from './agent-launch-terminal-prompt' -vi.mock('../../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../../git/worktree') +vi.mock('../../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../../git/worktree') +vi.mock('../../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../../../git/worktree', () => ({ - listWorktrees: vi - .fn() - .mockResolvedValue([ - { path: '/tmp/worktree-a', head: 'abc', branch: 'b', isBare: false, isMainWorktree: false } - ]), - listWorktreesStrict: vi - .fn() - .mockResolvedValue([ - { path: '/tmp/worktree-a', head: 'abc', branch: 'b', isBare: false, isMainWorktree: false } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi + .fn() + .mockResolvedValue([ + { path: '/tmp/worktree-a', head: 'abc', branch: 'b', isBare: false, isMainWorktree: false } + ]), + listWorktreesStrict: vi + .fn() + .mockResolvedValue([ + { path: '/tmp/worktree-a', head: 'abc', branch: 'b', isBare: false, isMainWorktree: false } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) async function deliverAbortingAt(agent: TuiAgent, abortWhen: (data: string) => boolean) { const controller = new AbortController() diff --git a/src/main/runtime/rpc/methods/managed-cwd-launch.test-fixture.ts b/src/main/runtime/rpc/methods/managed-cwd-launch.test-fixture.ts index a8d99985901..98966197375 100644 --- a/src/main/runtime/rpc/methods/managed-cwd-launch.test-fixture.ts +++ b/src/main/runtime/rpc/methods/managed-cwd-launch.test-fixture.ts @@ -1,6 +1,7 @@ import { vi } from 'vitest' import { join } from 'node:path' import { randomUUID } from 'node:crypto' +import * as gitExecFile from '../../../git/command-runner/git-exec-file' import type { Worktree } from '../../../../shared/worktree/types' import type { WorktreeLineage } from '../../../../shared/worktree/lineage-types' import type { Repo } from '../../../../shared/repo-types' @@ -11,8 +12,7 @@ import { addWorktree, computeWorktreePathMock, ensurePathWithinWorkspaceMock, - listWorktrees, - gitRunner + listWorktrees } from '../../orca-runtime-test-mocks.spec' import { store, makeWorktreeMeta } from '../../orca-runtime-test-fixtures.spec' import { registerLivePty } from '../../bind-first-pane.test-fixture' @@ -133,7 +133,7 @@ export function managedCwdLaunchFixture( const showRepo = vi.spyOn(runtime, 'showRepo') const showTerminal = vi.spyOn(runtime, 'showTerminal') const catalog = vi.spyOn(runtime, 'listManagedWorktrees') - const git = vi.spyOn(gitRunner, 'gitExecFileAsync').mockImplementation(async (args) => ({ + const git = vi.spyOn(gitExecFile, 'gitExecFileAsync').mockImplementation(async (args) => ({ stdout: args[0] === 'rev-parse' && args.includes('--verify') ? `${'a'.repeat(40)}\n` : '', stderr: '' })) diff --git a/src/main/runtime/rpc/methods/orchestration/worker/agent-status-producer-census.test.ts b/src/main/runtime/rpc/methods/orchestration/worker/agent-status-producer-census.test.ts index 62ebf485e01..66f1d5a1ade 100644 --- a/src/main/runtime/rpc/methods/orchestration/worker/agent-status-producer-census.test.ts +++ b/src/main/runtime/rpc/methods/orchestration/worker/agent-status-producer-census.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeListingModule from '../../../../../git/worktree-listing' +import type * as WorktreeListingModule from '../../../../../git/worktrees/catalog/worktree-listing' import { describe, expect, it, vi } from 'vitest' const { ipcHandlers } = vi.hoisted(() => ({ @@ -6,7 +6,7 @@ const { ipcHandlers } = vi.hoisted(() => ({ })) // Partially mock Electron: snapshot-pull is registered through ipcMain.handle, which is absent outside Electron. -vi.mock('../../../../../git/worktree-listing', async (importOriginal) => { +vi.mock('../../../../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { return { ...(await importOriginal()), listWorktreesStrict: listWorktreesStrict @@ -25,10 +25,6 @@ vi.mock('electron', async (importOriginal) => ({ })) const { listWorktreesStrict } = vi.hoisted(() => ({ listWorktreesStrict: vi.fn() })) // The git binary is the external boundary for worktree.ps; everything above it stays real. -vi.mock('../../../../../git/worktree', async (importOriginal) => ({ - ...(await importOriginal>()), - listWorktreesStrict -})) import type Database from '../../../../../sqlite/sync-database' import type { AgentStatusIpcPayload } from '../../../../../../shared/agent-status-ipc-payload' diff --git a/src/main/runtime/rpc/methods/orchestration/worker/worker-start-prompt-contract.test.ts b/src/main/runtime/rpc/methods/orchestration/worker/worker-start-prompt-contract.test.ts index 6922114fe3f..0933d4bc120 100644 --- a/src/main/runtime/rpc/methods/orchestration/worker/worker-start-prompt-contract.test.ts +++ b/src/main/runtime/rpc/methods/orchestration/worker/worker-start-prompt-contract.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../../../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../../../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../../../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../../../../git/worktrees/catalog/worktree-listing' import '../../../unused-default-rpc-methods.test-fixture' import { mkdtempSync, rmSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -18,42 +18,46 @@ import { ORCHESTRATION_METHODS } from '../../orchestration' import type { TuiAgent } from '../../../../../../shared/tui-agent' import * as FailedStartTeardown from './failed-worker-start-teardown' -vi.mock('../../../../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../../../../git/worktree') +vi.mock('../../../../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../../../../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../../../../git/worktree') +vi.mock('../../../../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../../../../../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-contract', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-contract', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-contract', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-contract', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) const COORDINATOR_PANE_KEY = 'tab_coord:aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa' const WORKER_PANE_KEY = 'tab_worker:bbbbbbbb-bbbb-4bbb-8bbb-bbbbbbbbbbbb' diff --git a/src/main/runtime/rpc/terminal-agent-prompt-send.test.ts b/src/main/runtime/rpc/terminal-agent-prompt-send.test.ts index 537befeed34..88f0bba1dc7 100644 --- a/src/main/runtime/rpc/terminal-agent-prompt-send.test.ts +++ b/src/main/runtime/rpc/terminal-agent-prompt-send.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import './unused-default-rpc-methods.test-fixture' import { describe, expect, it, vi } from 'vitest' import type { OrcaRuntimeService } from '../orca-runtime' @@ -7,19 +7,23 @@ import { RpcDispatcher } from './dispatcher' import { createAgentPromptSubmissionRuntime } from '../agent-prompt-submission-runtime-test-fixture' import { TERMINAL_METHODS } from './methods/terminal' -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../../git/worktree', () => ({ - listWorktreesStrict: async () => [ - { path: '/tmp/worktree-a', head: 'abc', branch: 'test', isBare: false, isMainWorktree: false } - ] -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktreesStrict: async () => [ + { path: '/tmp/worktree-a', head: 'abc', branch: 'test', isBare: false, isMainWorktree: false } + ] + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) function makeRequest(params: unknown): RpcRequest { return { id: 'request', authToken: 'token', method: 'terminal.send', params } diff --git a/src/main/runtime/rpc/terminal-agent-prompt-socket.test.ts b/src/main/runtime/rpc/terminal-agent-prompt-socket.test.ts index f97621c4cbf..e9185a9cf26 100644 --- a/src/main/runtime/rpc/terminal-agent-prompt-socket.test.ts +++ b/src/main/runtime/rpc/terminal-agent-prompt-socket.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import './unused-default-rpc-methods.test-fixture' import { spawn } from 'node:child_process' import { once } from 'node:events' @@ -22,27 +22,37 @@ import * as inputAdmission from '../terminal-input-admission' import { writePtyFromRuntimeController } from '../../ipc/pty/runtime/operations' import { getLocalPtyProvider } from '../../ipc/pty/provider/registry' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../../git/worktree', () => { - const read = async () => [ - { path: '/tmp/worktree-a', head: 'abc', branch: 'prompt', isBare: false, isMainWorktree: false } - ] - return { listWorktrees: read, listWorktreesStrict: read } +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const read = async () => [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'prompt', + isBare: false, + isMainWorktree: false + } + ] + return { listWorktrees: read, listWorktreesStrict: read } + } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) it.each(['before', 'after', 'paired', 'orchestration'] as const)( diff --git a/src/main/runtime/rpc/terminal-multiplex-input-sequence-replay.test.ts b/src/main/runtime/rpc/terminal-multiplex-input-sequence-replay.test.ts index 3e712fa37c1..65d4d1ca951 100644 --- a/src/main/runtime/rpc/terminal-multiplex-input-sequence-replay.test.ts +++ b/src/main/runtime/rpc/terminal-multiplex-input-sequence-replay.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import './unused-default-rpc-methods.test-fixture' import { describe, expect, it, vi } from 'vitest' import { RpcDispatcher } from './dispatcher' @@ -19,19 +19,23 @@ import { } from '../../../shared/terminal-stream-protocol' import { makeRequest, stubRuntime } from './terminal-multiplex-test-harness' -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../../git/worktree', () => ({ - listWorktreesStrict: async () => [ - { path: '/tmp/worktree-a', head: 'abc', branch: 'test', isBare: false, isMainWorktree: false } - ] -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktreesStrict: async () => [ + { path: '/tmp/worktree-a', head: 'abc', branch: 'test', isBare: false, isMainWorktree: false } + ] + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) type FrameHandler = (frame: NonNullable>) => void diff --git a/src/main/runtime/rpc/terminal-prompt-delivery-receipt.test.ts b/src/main/runtime/rpc/terminal-prompt-delivery-receipt.test.ts index e60f996aea4..c7aa8ea008b 100644 --- a/src/main/runtime/rpc/terminal-prompt-delivery-receipt.test.ts +++ b/src/main/runtime/rpc/terminal-prompt-delivery-receipt.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import './unused-default-rpc-methods.test-fixture' import { afterEach, describe, expect, it, vi } from 'vitest' import type { TuiAgent } from '../../../shared/tui-agent' @@ -9,42 +9,46 @@ import type { RpcRequest, RpcResponse } from './core' import { RpcDispatcher } from './dispatcher' import { TERMINAL_METHODS } from './methods/terminal' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-receipt', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-receipt', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-receipt', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-receipt', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) function request( terminal: string, diff --git a/src/main/runtime/rpc/terminal-send-launch-composer.test.ts b/src/main/runtime/rpc/terminal-send-launch-composer.test.ts index 322d88e779b..a21b5a18c7c 100644 --- a/src/main/runtime/rpc/terminal-send-launch-composer.test.ts +++ b/src/main/runtime/rpc/terminal-send-launch-composer.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import './unused-default-rpc-methods.test-fixture' import { afterEach, describe, expect, it, vi } from 'vitest' import { OrcaRuntimeService } from '../orca-runtime' @@ -8,42 +8,46 @@ import { AGENT_PROMPT_TEST_WORKTREE_PATH } from '../agent-prompt-submission-runt import { RpcDispatcher } from './dispatcher' import { TERMINAL_METHODS } from './methods/terminal' -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/launch-composer', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/launch-composer', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/launch-composer', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/launch-composer', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) // Claude's palette-report anchor, then its composer prompt row (draft-paste-ready-scanner.ts). const CLAUDE_COMPOSER_READY_OUTPUT = '\x1b[?2031h\x1b[?2004h❯\u00a0' diff --git a/src/main/runtime/runtime-branch-reuse-real-git.test.ts b/src/main/runtime/runtime-branch-reuse-real-git.test.ts index 829d1582d83..2fc565c5321 100644 --- a/src/main/runtime/runtime-branch-reuse-real-git.test.ts +++ b/src/main/runtime/runtime-branch-reuse-real-git.test.ts @@ -5,7 +5,8 @@ import { afterEach, describe, expect, it } from 'vitest' import type { Repo } from '../../shared/repo-types' import type { CreateWorktreeArgs } from '../../shared/worktree/create-types' import { gitExecFileAsync } from '../git/runner' -import { addSparseWorktree, addWorktree } from '../git/worktree' +import { addSparseWorktree } from '../git/worktrees/creation/worktree-sparse-add' +import { addWorktree } from '../git/worktrees/creation/worktree-add' import { openWorktreeCreatePathClaim } from '../workspaces/creation/worktree-create-in-flight' import { WorktreeCreate } from '../../shared/rpc-contract/worktree-create-params' import { buildManagedWorktreeCreateArgs } from './rpc/methods/worktree-create-args' diff --git a/src/main/runtime/runtime-failed-local-worktree-removal.test.ts b/src/main/runtime/runtime-failed-local-worktree-removal.test.ts index a29164646b3..84c504a89c8 100644 --- a/src/main/runtime/runtime-failed-local-worktree-removal.test.ts +++ b/src/main/runtime/runtime-failed-local-worktree-removal.test.ts @@ -14,8 +14,9 @@ import { removeTree } from '../../shared/windows-transient-lock-removal' import type { Store } from '../persistence/loading-store/store' import type * as HostTreeRemoval from '../filesystem/host-tree-removal' import { removeHostTree } from '../filesystem/host-tree-removal' -import { listWorktreesStrict, removeWorktree } from '../git/worktree' -import { areWorktreePathsEqual } from '../git/worktree-path-comparison' +import { listWorktreesStrict } from '../git/worktrees/catalog/worktree-listing' +import { removeWorktree } from '../git/worktrees/removal/worktree-removal' +import { areWorktreePathsEqual } from '../git/worktrees/catalog/worktree-path-comparison' import { acquireWatcherRemovalGate, beginTerminalInstall } from '../ipc/watcher-removal-gate' import { _resetPendingWorktreeRemovalsForTests, diff --git a/src/main/runtime/runtime-git-command-target.ts b/src/main/runtime/runtime-git-command-target.ts index 9eb8c9f6d0d..509d0a7dad0 100644 --- a/src/main/runtime/runtime-git-command-target.ts +++ b/src/main/runtime/runtime-git-command-target.ts @@ -3,7 +3,7 @@ import { LOCAL_EXECUTION_HOST_ID, type ExecutionHostId } from '../../shared/exec import type { Repo } from '../../shared/repo-types' import type { GitPushTarget, GitWorktreeInfo, Worktree } from '../../shared/worktree/types' import type { GitRuntimeOptions } from '../git/git-runtime-options' -import { getWorktreeSharedLinkPaths } from '../git/worktree-shared-directories' +import { getWorktreeSharedLinkPaths } from '../git/worktrees/content-paths/worktree-shared-directories' import { ExecutionHostNotDispatchableError, resolveGitRouteForHost diff --git a/src/main/runtime/runtime-git-conflict-operation-routing.test.ts b/src/main/runtime/runtime-git-conflict-operation-routing.test.ts index f9bfd53a0a5..e0bc21650b0 100644 --- a/src/main/runtime/runtime-git-conflict-operation-routing.test.ts +++ b/src/main/runtime/runtime-git-conflict-operation-routing.test.ts @@ -1,10 +1,9 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' -import type * as GitStatusModule from '../git/status' const detectConflictOperationMock = vi.hoisted(() => vi.fn()) -vi.mock('../git/status', async () => ({ - ...(await vi.importActual('../git/status')), +vi.mock('../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), detectConflictOperation: detectConflictOperationMock })) diff --git a/src/main/runtime/runtime-git-diff-commands.ts b/src/main/runtime/runtime-git-diff-commands.ts index c713750da59..eb1dff94836 100644 --- a/src/main/runtime/runtime-git-diff-commands.ts +++ b/src/main/runtime/runtime-git-diff-commands.ts @@ -4,7 +4,7 @@ import type { GitDiffResult } from '../../shared/git-diff-compare-types' import { assertGitDiffWithinTransportBudget } from '../../shared/git-diff-transport-budget' -import { getBranchDiff } from '../git/status' +import { getBranchDiff } from '../git/source-control/branch-diff' import type { GitAdmissionTier } from '../git/command-runner/git-exec-options' import { normalizeRuntimeRelativePath } from './runtime-relative-paths' import { diff --git a/src/main/runtime/runtime-git-execution-host-ownership.test.ts b/src/main/runtime/runtime-git-execution-host-ownership.test.ts index 0dc58b7a580..499feadb70c 100644 --- a/src/main/runtime/runtime-git-execution-host-ownership.test.ts +++ b/src/main/runtime/runtime-git-execution-host-ownership.test.ts @@ -1,7 +1,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import type { GlobalSettings } from '../../shared/global-settings-types' import type * as GitRemoteModule from '../git/remote' -import type * as GitStatusModule from '../git/status' + import type { ResolvedRuntimeGitWorktree } from './runtime-git-command-target' import { RuntimeGitCommands } from './orca-runtime-git' import { SSH_HOST_NOT_SERVED_MESSAGE } from '../providers/ssh-host-not-served-error' @@ -12,9 +12,13 @@ const mocks = vi.hoisted(() => ({ stageFile: vi.fn() })) -vi.mock('../git/status', async () => ({ - ...(await vi.importActual('../git/status')), - getStatus: mocks.getStatus, +vi.mock('../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), + getStatus: mocks.getStatus +})) + +vi.mock('../git/source-control/staging', async (importOriginal) => ({ + ...(await importOriginal>()), stageFile: mocks.stageFile })) diff --git a/src/main/runtime/runtime-git-generation-admission.test.ts b/src/main/runtime/runtime-git-generation-admission.test.ts index 010047d9450..ec7f8ebd9ea 100644 --- a/src/main/runtime/runtime-git-generation-admission.test.ts +++ b/src/main/runtime/runtime-git-generation-admission.test.ts @@ -16,8 +16,13 @@ const mocks = vi.hoisted(() => ({ const linkedLookup = vi.hoisted(() => ({ run: (): Promise => Promise.resolve(null) })) -vi.mock('../git/status', () => ({ getStagedCommitContext: mocks.getStagedCommitContext })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: mocks.gitExecFileAsync })) +vi.mock('../git/source-control/staged-commit-context', () => ({ + getStagedCommitContext: mocks.getStagedCommitContext +})) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: mocks.gitExecFileAsync +})) vi.mock('../text-generation/pull-request-context', () => ({ getPullRequestDraftContext: mocks.getPullRequestDraftContext })) diff --git a/src/main/runtime/runtime-git-generation-commands.ts b/src/main/runtime/runtime-git-generation-commands.ts index 95a3d3cbdbc..7174fa3cf38 100644 --- a/src/main/runtime/runtime-git-generation-commands.ts +++ b/src/main/runtime/runtime-git-generation-commands.ts @@ -7,7 +7,7 @@ import { getCommitMessageModelDiscoveryHostKey } from '../../shared/commit-messa import type { HostedReviewProvider } from '../../shared/hosted-review' import { withLinkedIssueDraftContext } from '../../shared/source-control-ai-action-variables' import type { TuiAgent } from '../../shared/tui-agent' -import { getStagedCommitContext } from '../git/status' +import { getStagedCommitContext } from '../git/source-control/staged-commit-context' import { SSH_HOST_NOT_SERVED_MESSAGE } from '../providers/ssh-host-not-served-error' import { loadPullRequestLinkedIssue } from '../source-control/pull-request-linked-issue' import { resolveHostedReviewBodyForGeneration } from '../source-control/pull-request-template' diff --git a/src/main/runtime/runtime-git-status-commands.ts b/src/main/runtime/runtime-git-status-commands.ts index 8fa5a907cf6..9bd98f7e1f6 100644 --- a/src/main/runtime/runtime-git-status-commands.ts +++ b/src/main/runtime/runtime-git-status-commands.ts @@ -1,6 +1,6 @@ import type { GitHistoryOptions, GitHistoryResult } from '../../shared/git-history' import type { GitMutationInFlight } from '../../shared/git-mutation-in-flight' -import { isGitWorktreeMutationInFlight } from '../git/git-worktree-mutation-state' +import { isGitWorktreeMutationInFlight } from '../git/command-runner/git-worktree-mutation-state' import type { GitConflictOperation, GitStagingArea, diff --git a/src/main/runtime/runtime-git-sync-commands.test.ts b/src/main/runtime/runtime-git-sync-commands.test.ts index d2405bea95b..f2f58380ad7 100644 --- a/src/main/runtime/runtime-git-sync-commands.test.ts +++ b/src/main/runtime/runtime-git-sync-commands.test.ts @@ -2,7 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import type { GlobalSettings } from '../../shared/global-settings-types' import type { GitPushTarget } from '../../shared/worktree/types' import type * as GitRemoteModule from '../git/remote' -import type * as GitStatusModule from '../git/status' + import type * as GitForkSyncModule from '../git/fork-sync' import type { ResolvedRuntimeGitWorktree } from './runtime-git-command-target' import { RuntimeGitSyncCommands } from './runtime-git-sync-commands' @@ -23,10 +23,14 @@ vi.mock('../git/fork-sync', async () => ({ gitSyncForkDefaultBranch: mocks.gitSyncForkDefaultBranch })) -vi.mock('../git/status', async () => ({ - ...(await vi.importActual('../git/status')), +vi.mock('../git/source-control/git-conflict-operation', async (importOriginal) => ({ + ...(await importOriginal>()), abortMerge: mocks.abortMerge, - abortRebase: mocks.abortRebase, + abortRebase: mocks.abortRebase +})) + +vi.mock('../git/source-control/commit-changes', async (importOriginal) => ({ + ...(await importOriginal>()), commitChanges: mocks.commitChanges })) diff --git a/src/main/runtime/runtime-git-target-execution-host.test.ts b/src/main/runtime/runtime-git-target-execution-host.test.ts index e6cc5c8b44f..b4ca74e51e6 100644 --- a/src/main/runtime/runtime-git-target-execution-host.test.ts +++ b/src/main/runtime/runtime-git-target-execution-host.test.ts @@ -8,12 +8,10 @@ vi.mock('electron', () => ({ app: { getPath: vi.fn(() => '/tmp'), isPackaged: false } })) -import type * as GitStatusModule from '../git/status' - const mocks = vi.hoisted(() => ({ getStatus: vi.fn() })) -vi.mock('../git/status', async () => ({ - ...(await vi.importActual('../git/status')), +vi.mock('../git/source-control/status-read', async (importOriginal) => ({ + ...(await importOriginal>()), getStatus: mocks.getStatus })) diff --git a/src/main/runtime/runtime-interrupted-local-worktree-removal.test.ts b/src/main/runtime/runtime-interrupted-local-worktree-removal.test.ts index 31dfd712270..4cfea6904ba 100644 --- a/src/main/runtime/runtime-interrupted-local-worktree-removal.test.ts +++ b/src/main/runtime/runtime-interrupted-local-worktree-removal.test.ts @@ -19,8 +19,8 @@ import type * as HostTreeRemoval from '../filesystem/host-tree-removal' import { removeHostTree } from '../filesystem/host-tree-removal' import * as nativeFs from '../filesystem/asar-transparent-fs' import * as diskFs from 'node:fs/promises' -import * as nativeRemoval from '../git/windows-worktree-removal' -import * as graphReader from '../git/worktree-list-reader' +import * as nativeRemoval from '../git/worktrees/removal/windows-worktree-removal' +import * as graphReader from '../git/worktrees/catalog/worktree-list-reader' import { cleanupLocalOrphanedWorktreeDirectory } from '../workspaces/removal/local-orphaned-worktree-cleanup' import * as removalOwnership from '../ipc/worktrees/removal/worktree-removal-ownership' import { executeWorktreeRemoval } from '../ipc/worktrees/removal/execute-worktree-removal' @@ -28,12 +28,12 @@ import { RuntimeWorktreeRemovalInFlight } from './runtime-worktree-removal-in-fl import { OrcaRuntimeWithResolveWorktreeRemovalTarget } from './workspaces/workspace-removal-target' import type { WorktreeIpcContext } from '../ipc/worktrees/worktree-ipc-context' import * as backgroundRemoval from '../workspaces/removal/worktree-background-removal' -import * as worktreeGit from '../git/worktree-listing' +import * as worktreeGit from '../git/worktrees/catalog/worktree-listing' import * as worktreeRemote from '../ipc/worktree-remote' import { getLocalProjectWorktreeGitOptions } from '../workspaces/execution-host/project-runtime-git-options' import * as removalTable from '../workspaces/removal/worktree-removal-table' -import { listWorktreesStrict } from '../git/worktree' -import { areWorktreePathsEqual } from '../git/worktree-path-comparison' +import { listWorktreesStrict } from '../git/worktrees/catalog/worktree-listing' +import { areWorktreePathsEqual } from '../git/worktrees/catalog/worktree-path-comparison' import { acquireWatcherRemovalGate, beginTerminalInstall, diff --git a/src/main/runtime/runtime-interrupted-local-worktree-removal.ts b/src/main/runtime/runtime-interrupted-local-worktree-removal.ts index 1512eda2a47..4aa0de77df2 100644 --- a/src/main/runtime/runtime-interrupted-local-worktree-removal.ts +++ b/src/main/runtime/runtime-interrupted-local-worktree-removal.ts @@ -7,16 +7,19 @@ import { } from '../workspaces/removal/worktree-background-removal' import { resolveWorktreeRemovalMetadata } from '../workspaces/removal/worktree-removal-repo-owner' import type { RuntimePreservedBranchCleanup } from './runtime-preserved-branch-cleanup' -import { listWorktreesStrict } from '../git/worktree' +import { listWorktreesStrict } from '../git/worktrees/catalog/worktree-listing' import { cleanupUnusedWorktreePushTargetRemote } from '../ipc/worktree-remote' -import { authorizeWindowsCheckout, usesNativeWindowsRemoval } from '../git/windows-worktree-removal' +import { + authorizeWindowsCheckout, + usesNativeWindowsRemoval +} from '../git/worktrees/removal/windows-worktree-removal' import { deleteBranchOfUnregisteredWorktree, finishUnregisteredWorktreeRemoval, removeWorktree -} from '../git/worktree-removal' -import { getErrorCode } from '../git/worktree-operation-options' -import { areWorktreePathsEqual } from '../git/worktree-path-comparison' +} from '../git/worktrees/removal/worktree-removal' +import { getErrorCode } from '../git/worktrees/worktree-operation-options' +import { areWorktreePathsEqual } from '../git/worktrees/catalog/worktree-path-comparison' import { getLocalProjectWorktreeGitOptions } from '../workspaces/execution-host/project-runtime-git-options' import { findRegisteredDeletableWorktree } from '../workspaces/removal/worktree-removal-safety' import { diff --git a/src/main/runtime/runtime-local-git-worktree-create.ts b/src/main/runtime/runtime-local-git-worktree-create.ts index fb32558d6fd..6cb74d2239e 100644 --- a/src/main/runtime/runtime-local-git-worktree-create.ts +++ b/src/main/runtime/runtime-local-git-worktree-create.ts @@ -5,12 +5,12 @@ import type { Repo } from '../../shared/repo-types' import { resolveCreatedWorktree } from '../ipc/created-worktree-reconciliation' import { normalizeSparseDirectories } from '../ipc/sparse-checkout-directories' import { configureCreatedWorktreePushTarget } from '../ipc/worktree-remote' -import { - addSparseWorktree, - addWorktree, - type AddWorktreeOptions, - type AddWorktreeResult -} from '../git/worktree' +import { addSparseWorktree } from '../git/worktrees/creation/worktree-sparse-add' +import { addWorktree } from '../git/worktrees/creation/worktree-add' +import type { + AddWorktreeOptions, + AddWorktreeResult +} from '../git/worktrees/worktree-operation-options' import type { RuntimeStore } from './runtime-store-contract' import type { RuntimeManagedWorktreeCreateArgs } from './runtime-managed-worktree-create-types' import type { RemoteFetchResult, RemoteTrackingBase } from './runtime-remote-fetch-controller' diff --git a/src/main/runtime/runtime-local-worktree-create-base.ts b/src/main/runtime/runtime-local-worktree-create-base.ts index f11788b5b15..2ae4cade1e9 100644 --- a/src/main/runtime/runtime-local-worktree-create-base.ts +++ b/src/main/runtime/runtime-local-worktree-create-base.ts @@ -1,6 +1,6 @@ import type { LocalGitExecOptions } from '../git/repo-default-base-ref' import type { WorktreeCreateBaseFallback } from '../../shared/worktree/create-types' -import { hasLocalWorktreeBaseRef } from '../git/worktree-base-ref-probe' +import { hasLocalWorktreeBaseRef } from '../git/worktrees/creation/worktree-base-ref-probe' import type { WorktreeCreateTimingRecorder } from '../workspaces/creation/worktree-create-timing' import type { RemoteFetchResult, RemoteTrackingBase } from './runtime-remote-fetch-controller' diff --git a/src/main/runtime/runtime-local-worktree-create-pr-conflict.test.ts b/src/main/runtime/runtime-local-worktree-create-pr-conflict.test.ts index 07d3c205c4f..d51606d8b7d 100644 --- a/src/main/runtime/runtime-local-worktree-create-pr-conflict.test.ts +++ b/src/main/runtime/runtime-local-worktree-create-pr-conflict.test.ts @@ -20,7 +20,10 @@ vi.mock('../text-generation/commit-message-agent-environment', () => ({ prepareLocalCommitMessageAgentEnv: async () => ({ ok: true }) })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: mocks.git })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: mocks.git +})) vi.mock('../workspaces/execution-host/project-runtime-git-options', () => ({ getLocalProjectGitExecOptions: () => ({ cwd: '/repo', ...mocks.routing() }), getLocalProjectWorktreeGitOptions: mocks.routing, @@ -33,7 +36,9 @@ vi.mock('../git/repo', () => ({ })) vi.mock('../git/git-username', () => ({ resolveLocalGitUsername: async () => '' })) vi.mock('../workspace-hooks/hooks', () => ({ getEffectiveHooks: mocks.effectiveHooks })) -vi.mock('../git/worktree-base-ref-probe', () => ({ hasLocalWorktreeBaseRef: mocks.hasBase })) +vi.mock('../git/worktrees/creation/worktree-base-ref-probe', () => ({ + hasLocalWorktreeBaseRef: mocks.hasBase +})) vi.mock('./runtime-worktree-create-git', () => ({ resolveCreateBranchName: mocks.branchName, canCheckoutExistingLocalBranch: mocks.canCheckout, @@ -44,17 +49,23 @@ vi.mock('./runtime-worktree-filesystem', () => ({ runtimePathExists: mocks.pathE vi.mock('../workspaces/creation/preparation/worktree-create-preparation', () => ({ consumePreparedWorktreeCreate: mocks.consume })) -vi.mock('../git/worktree', () => ({ addWorktree: mocks.add, addSparseWorktree: mocks.addSparse })) +vi.mock('../git/worktrees/creation/worktree-add', () => ({ + addWorktree: mocks.add +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', () => ({ + addSparseWorktree: mocks.addSparse +})) vi.mock('../ipc/worktree-remote', () => ({ configureCreatedWorktreePushTarget: mocks.pushTarget })) vi.mock('../ipc/created-worktree-reconciliation', () => ({ resolveCreatedWorktree: mocks.listing })) vi.mock('../workspaces/removal/retirement/worktree-name-retirement', () => ({ failedWorktreeCreationNeedsRetirement: vi.fn(), retireGeneratedWorktreeName: vi.fn() })) -vi.mock('../git/worktree-shared-directories', () => ({ +vi.mock('../git/worktrees/content-paths/worktree-shared-directories', () => ({ resolveWorktreeSharedDirectories: mocks.resolveShared })) -vi.mock('../git/worktree-include-file', () => ({ +vi.mock('../git/worktrees/content-paths/worktree-include-file', () => ({ resolveWorktreeIncludePaths: mocks.resolveInclude })) vi.mock('../ipc/worktree-symlinks', () => ({ diff --git a/src/main/runtime/runtime-local-worktree-create-pr-conflicts.test.ts b/src/main/runtime/runtime-local-worktree-create-pr-conflicts.test.ts index 23f5a0b0f10..159af732fe9 100644 --- a/src/main/runtime/runtime-local-worktree-create-pr-conflicts.test.ts +++ b/src/main/runtime/runtime-local-worktree-create-pr-conflicts.test.ts @@ -51,7 +51,10 @@ vi.mock('../text-generation/commit-message-agent-environment', () => ({ prepareLocalCommitMessageAgentEnv: async () => ({ ok: true }) })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: mocks.git })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: mocks.git +})) vi.mock('../workspaces/execution-host/project-runtime-git-options', () => ({ getLocalProjectGitExecOptions: () => ({ cwd: '/repo', ...mocks.routing() }), getLocalProjectWorktreeGitOptions: mocks.routing, @@ -64,7 +67,9 @@ vi.mock('../git/repo', () => ({ })) vi.mock('../git/git-username', () => ({ resolveLocalGitUsername: async () => '' })) vi.mock('../workspace-hooks/hooks', () => ({ getEffectiveHooks: mocks.effectiveHooks })) -vi.mock('../git/worktree-base-ref-probe', () => ({ hasLocalWorktreeBaseRef: mocks.hasBase })) +vi.mock('../git/worktrees/creation/worktree-base-ref-probe', () => ({ + hasLocalWorktreeBaseRef: mocks.hasBase +})) vi.mock('./runtime-worktree-create-git', () => ({ resolveCreateBranchName: mocks.branchName, canCheckoutExistingLocalBranch: mocks.canCheckout, @@ -75,17 +80,23 @@ vi.mock('./runtime-worktree-filesystem', () => ({ runtimePathExists: mocks.pathE vi.mock('../workspaces/creation/preparation/worktree-create-preparation', () => ({ consumePreparedWorktreeCreate: mocks.consume })) -vi.mock('../git/worktree', () => ({ addWorktree: mocks.add, addSparseWorktree: mocks.addSparse })) +vi.mock('../git/worktrees/creation/worktree-add', () => ({ + addWorktree: mocks.add +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', () => ({ + addSparseWorktree: mocks.addSparse +})) vi.mock('../ipc/worktree-remote', () => ({ configureCreatedWorktreePushTarget: mocks.pushTarget })) vi.mock('../ipc/created-worktree-reconciliation', () => ({ resolveCreatedWorktree: mocks.listing })) vi.mock('../workspaces/removal/retirement/worktree-name-retirement', () => ({ failedWorktreeCreationNeedsRetirement: vi.fn(), retireGeneratedWorktreeName: vi.fn() })) -vi.mock('../git/worktree-shared-directories', () => ({ +vi.mock('../git/worktrees/content-paths/worktree-shared-directories', () => ({ resolveWorktreeSharedDirectories: mocks.resolveShared })) -vi.mock('../git/worktree-include-file', () => ({ +vi.mock('../git/worktrees/content-paths/worktree-include-file', () => ({ resolveWorktreeIncludePaths: mocks.resolveInclude })) vi.mock('../ipc/worktree-symlinks', () => ({ diff --git a/src/main/runtime/runtime-local-worktree-create.test.ts b/src/main/runtime/runtime-local-worktree-create.test.ts index ad72dbb668f..65995534b69 100644 --- a/src/main/runtime/runtime-local-worktree-create.test.ts +++ b/src/main/runtime/runtime-local-worktree-create.test.ts @@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { basename } from 'node:path' import type { Repo } from '../../shared/repo-types' import { getDefaultRepoHookSettings } from '../../shared/constants' -import type { AddWorktreeOptions } from '../git/worktree' +import type { AddWorktreeOptions } from '../git/worktrees/worktree-operation-options' import { acquireGitAdmission, GitAdmissionScheduler, @@ -28,7 +28,10 @@ vi.mock('../text-generation/commit-message-agent-environment', () => ({ prepareLocalCommitMessageAgentEnv: async () => ({ ok: true }) })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: mocks.git })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: mocks.git +})) vi.mock('../workspaces/execution-host/project-runtime-git-options', () => ({ getLocalProjectGitExecOptions: () => ({ cwd: '/repo', ...mocks.routing() }), getLocalProjectWorktreeGitOptions: mocks.routing, @@ -41,7 +44,9 @@ vi.mock('../git/repo', () => ({ })) vi.mock('../git/git-username', () => ({ resolveLocalGitUsername: async () => '' })) vi.mock('../workspace-hooks/hooks', () => ({ getEffectiveHooks: mocks.effectiveHooks })) -vi.mock('../git/worktree-base-ref-probe', () => ({ hasLocalWorktreeBaseRef: mocks.hasBase })) +vi.mock('../git/worktrees/creation/worktree-base-ref-probe', () => ({ + hasLocalWorktreeBaseRef: mocks.hasBase +})) vi.mock('./runtime-worktree-create-git', () => ({ resolveCreateBranchName: mocks.branchName, canCheckoutExistingLocalBranch: mocks.canCheckout, @@ -52,17 +57,23 @@ vi.mock('./runtime-worktree-filesystem', () => ({ runtimePathExists: mocks.pathE vi.mock('../workspaces/creation/preparation/worktree-create-preparation', () => ({ consumePreparedWorktreeCreate: mocks.consume })) -vi.mock('../git/worktree', () => ({ addWorktree: mocks.add, addSparseWorktree: mocks.addSparse })) +vi.mock('../git/worktrees/creation/worktree-add', () => ({ + addWorktree: mocks.add +})) + +vi.mock('../git/worktrees/creation/worktree-sparse-add', () => ({ + addSparseWorktree: mocks.addSparse +})) vi.mock('../ipc/worktree-remote', () => ({ configureCreatedWorktreePushTarget: mocks.pushTarget })) vi.mock('../ipc/created-worktree-reconciliation', () => ({ resolveCreatedWorktree: mocks.listing })) vi.mock('../workspaces/removal/retirement/worktree-name-retirement', () => ({ failedWorktreeCreationNeedsRetirement: vi.fn(), retireGeneratedWorktreeName: vi.fn() })) -vi.mock('../git/worktree-shared-directories', () => ({ +vi.mock('../git/worktrees/content-paths/worktree-shared-directories', () => ({ resolveWorktreeSharedDirectories: mocks.resolveShared })) -vi.mock('../git/worktree-include-file', () => ({ +vi.mock('../git/worktrees/content-paths/worktree-include-file', () => ({ resolveWorktreeIncludePaths: mocks.resolveInclude })) vi.mock('../ipc/worktree-symlinks', () => ({ diff --git a/src/main/runtime/runtime-local-worktree-create.ts b/src/main/runtime/runtime-local-worktree-create.ts index 08c8abdbeef..8a7e91233f1 100644 --- a/src/main/runtime/runtime-local-worktree-create.ts +++ b/src/main/runtime/runtime-local-worktree-create.ts @@ -1,4 +1,4 @@ -import { worktreeCreateGit } from '../git/worktree-create-git-executor' +import { worktreeCreateGit } from '../git/worktrees/creation/worktree-create-git-executor' import { shouldRunSetupForCreate } from '../workspace-hooks/effective-hook-config' import { getEffectiveHooks } from '../workspace-hooks/hooks' import type { Repo } from '../../shared/repo-types' @@ -17,7 +17,7 @@ import { resolveWorktreeCreateBase } from '../workspaces/creation/worktree-creat import type { RuntimeManagedWorktreeCreateArgs } from './runtime-managed-worktree-create-types' import type { RemoteFetchResult, RemoteTrackingBase } from './runtime-remote-fetch-controller' import type { HostedReviewExecutionOptions } from '../source-control/hosted-review-git-options' -import { hasLocalWorktreeBaseRef } from '../git/worktree-base-ref-probe' +import { hasLocalWorktreeBaseRef } from '../git/worktrees/creation/worktree-base-ref-probe' import { resolveRuntimeLocalWorktreeCreateCandidate } from './runtime-local-worktree-create-candidate' import { createRuntimeLocalGitWorktree, diff --git a/src/main/runtime/runtime-local-worktree-materialization.ts b/src/main/runtime/runtime-local-worktree-materialization.ts index b7857f4f976..1554773112e 100644 --- a/src/main/runtime/runtime-local-worktree-materialization.ts +++ b/src/main/runtime/runtime-local-worktree-materialization.ts @@ -6,7 +6,7 @@ import type { GitWorktreeInfo, GitPushTarget, Worktree } from '../../shared/work import type { Repo } from '../../shared/repo-types' import type { CreateWorktreeArgs } from '../../shared/worktree/create-types' import type { TuiAgent } from '../../shared/tui-agent' -import { resolveWorktreeIncludePaths } from '../git/worktree-include-file' +import { resolveWorktreeIncludePaths } from '../git/worktrees/content-paths/worktree-include-file' import { formatWorktreeIncludeCopyWarning } from '../ipc/worktree-include-copy-budget' import { getWorktreeCreationLayout } from '../ipc/worktree-logic' import { mergeWorktree } from '../ipc/worktree-metadata-merge' @@ -16,7 +16,7 @@ import { createWorktreeLinkedPaths, createWorktreeSharedPaths } from '../ipc/worktree-symlinks' -import { resolveWorktreeSharedDirectories } from '../git/worktree-shared-directories' +import { resolveWorktreeSharedDirectories } from '../git/worktrees/content-paths/worktree-shared-directories' import type { RuntimeManagedWorktreeCreateArgs } from './runtime-managed-worktree-create-types' import type { RemoteTrackingBase } from './runtime-remote-fetch-controller' import type { RuntimeStore } from './runtime-store-contract' diff --git a/src/main/runtime/runtime-nested-repo-import-host-twin.test.ts b/src/main/runtime/runtime-nested-repo-import-host-twin.test.ts index 819fd5390b4..254fafd6d14 100644 --- a/src/main/runtime/runtime-nested-repo-import-host-twin.test.ts +++ b/src/main/runtime/runtime-nested-repo-import-host-twin.test.ts @@ -5,7 +5,10 @@ import type { RuntimeStore } from './runtime-store-contract' const PARENT = '/work/platform' const CHILD = '/work/platform/api' -vi.mock('../git/runner', () => ({ awaitWindowsHostGitEnvironmentReady: vi.fn(async () => {}) })) +vi.mock('../git/command-runner/windows-host-git-environment', async (importOriginal) => ({ + ...(await importOriginal>()), + awaitWindowsHostGitEnvironmentReady: vi.fn(async () => {}) +})) vi.mock('../git/repo', () => ({ isGitRepoAsync: vi.fn(async () => true), getRepoName: (path: string) => path.split('/').pop() diff --git a/src/main/runtime/runtime-preserved-branch-cleanup.ts b/src/main/runtime/runtime-preserved-branch-cleanup.ts index 0079b84347b..f88e9404755 100644 --- a/src/main/runtime/runtime-preserved-branch-cleanup.ts +++ b/src/main/runtime/runtime-preserved-branch-cleanup.ts @@ -10,7 +10,7 @@ import { type ExecutionHostId } from '../../shared/execution-host' import { isFolderRepo } from '../../shared/repo-kind' -import { forceDeleteLocalBranch } from '../git/worktree' +import { forceDeleteLocalBranch } from '../git/worktrees/removal/worktree-branch-removal' import { gitExecFileAsync } from '../git/runner' import { cleanupUnusedWorktreePushTargetRemote } from '../ipc/worktree-remote' import { getLocalProjectWorktreeGitOptions } from '../workspaces/execution-host/project-runtime-git-options' diff --git a/src/main/runtime/runtime-registered-local-worktree-removal.ts b/src/main/runtime/runtime-registered-local-worktree-removal.ts index fa9a5e4fa57..1767d02c492 100644 --- a/src/main/runtime/runtime-registered-local-worktree-removal.ts +++ b/src/main/runtime/runtime-registered-local-worktree-removal.ts @@ -3,21 +3,21 @@ import { authorizeWindowsCheckout, nativeWindowsMarkerMissing, usesNativeWindowsRemoval -} from '../git/windows-worktree-removal' -import { pruneGitWorktrees } from '../git/worktree-prune-guard' +} from '../git/worktrees/removal/windows-worktree-removal' +import { pruneGitWorktrees } from '../git/worktrees/removal/worktree-prune-guard' import type { RemoveWorktreeResult } from '../../shared/worktree/create-types' import type { ArchiveHookOverride } from '../../shared/worktree/archive-hook-removal-gate' import { gateWorktreeRemovalOnArchiveHook } from '../workspaces/removal/worktree-archive-hook-gate' import type { Repo } from '../../shared/repo-types' import { assertWorktreeUnlockedForRemoval } from '../../shared/worktree/removal' import type { LocalProjectWorktreeGitOptions } from '../workspaces/execution-host/project-runtime-git-options' -import { assertWorktreeCleanForRemoval, listWorktreesStrict, removeWorktree } from '../git/worktree' -import { getWorktreeSharedLinkPaths } from '../git/worktree-shared-directories' +import { assertWorktreeCleanForRemoval } from '../git/worktrees/removal/worktree-removal-preflight' +import { listWorktreesStrict } from '../git/worktrees/catalog/worktree-listing' +import { removeWorktree } from '../git/worktrees/removal/worktree-removal' +import { getWorktreeSharedLinkPaths } from '../git/worktrees/content-paths/worktree-shared-directories' import { runHook, getEffectiveHooks } from '../workspace-hooks/hooks' -import { - findExistingWorktreeSymlinkPaths, - removeWorktreeLinkedPaths -} from '../ipc/worktree-symlinks' +import { findExistingWorktreeSymlinkPaths } from '../git/worktrees/content-paths/worktree-symlink-detection' +import { removeWorktreeLinkedPaths } from '../ipc/worktree-symlinks' import { cleanupUnusedWorktreePushTargetRemote } from '../ipc/worktree-remote' import { runWorktreeChangeInvalidators } from '../ipc/worktree-change-invalidators' import { diff --git a/src/main/runtime/runtime-remote-fetch-controller.ts b/src/main/runtime/runtime-remote-fetch-controller.ts index fc0cd4eebb9..9184a750234 100644 --- a/src/main/runtime/runtime-remote-fetch-controller.ts +++ b/src/main/runtime/runtime-remote-fetch-controller.ts @@ -6,7 +6,7 @@ import { getCanonicalRepoKey, type CanonicalRepoKeyOptions } from '../git/canoni import { armLocalRepoRefMaintenance, setRepoRefMaintenanceBusyProbe -} from '../git/local-repo-ref-maintenance' +} from '../git/refs/maintenance/local-repo-ref-maintenance' import { gitExecFileAsync } from '../git/runner' import { setBoundedMapEntry } from './runtime-async-boundaries' diff --git a/src/main/runtime/runtime-remote-fetch-ref-maintenance.test.ts b/src/main/runtime/runtime-remote-fetch-ref-maintenance.test.ts index b2f9a092601..ebf7934ec29 100644 --- a/src/main/runtime/runtime-remote-fetch-ref-maintenance.test.ts +++ b/src/main/runtime/runtime-remote-fetch-ref-maintenance.test.ts @@ -6,12 +6,12 @@ const gitExecFileAsyncMock = vi.hoisted(() => vi.fn()) const armMock = vi.hoisted(() => vi.fn()) const busyProbeMock = vi.hoisted(() => vi.fn()) -vi.mock('../git/runner', async (importOriginal) => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ ...((await importOriginal()) as Record), gitExecFileAsync: gitExecFileAsyncMock })) -vi.mock('../git/local-repo-ref-maintenance', async (importOriginal) => ({ +vi.mock('../git/refs/maintenance/local-repo-ref-maintenance', async (importOriginal) => ({ ...((await importOriginal()) as Record), armLocalRepoRefMaintenance: armMock, setRepoRefMaintenanceBusyProbe: busyProbeMock diff --git a/src/main/runtime/runtime-repository-clone-controller.ts b/src/main/runtime/runtime-repository-clone-controller.ts index 7a7ab3795c5..eea50066d13 100644 --- a/src/main/runtime/runtime-repository-clone-controller.ts +++ b/src/main/runtime/runtime-repository-clone-controller.ts @@ -14,7 +14,7 @@ import { } from '../git/repo-clone-path' import { gitSpawnAfterWindowsEnvironmentReady, promptGuardGitEnv } from '../git/runner' import { reuseSavedCloneTarget } from '../git/saved-clone-target' -import { runWithGitReadCacheInvalidation } from '../git/status' +import { runWithGitReadCacheInvalidation } from '../git/source-control/git-read-cache-invalidation' import { invalidateAuthorizedRootsCache } from '../ipc/worktrees/removal/registered-worktree-roots-cache' import { detectRepoIconAndUpstream } from '../repository-icons/repo-icon-autodetect' import { getRepoName } from '../git/repo' diff --git a/src/main/runtime/runtime-repository-issue-command.test.ts b/src/main/runtime/runtime-repository-issue-command.test.ts index ed28f4e6f97..a90d03ffdcc 100644 --- a/src/main/runtime/runtime-repository-issue-command.test.ts +++ b/src/main/runtime/runtime-repository-issue-command.test.ts @@ -6,7 +6,9 @@ import { RuntimeRepositoryIssueCommand } from './runtime-repository-issue-comman const mocks = vi.hoisted(() => ({ localCheck: vi.fn() })) -vi.mock('../git/check-ignored-paths', () => ({ checkIgnoredPaths: mocks.localCheck })) +vi.mock('../git/source-control/check-ignored-paths', () => ({ + checkIgnoredPaths: mocks.localCheck +})) describe('local issue command runtime routing', () => { it.each(['command', ' '])( diff --git a/src/main/runtime/runtime-review-worktree-base-execution-host.test.ts b/src/main/runtime/runtime-review-worktree-base-execution-host.test.ts index d69880101b4..5836e05e648 100644 --- a/src/main/runtime/runtime-review-worktree-base-execution-host.test.ts +++ b/src/main/runtime/runtime-review-worktree-base-execution-host.test.ts @@ -4,8 +4,13 @@ import { SshHostNotServedError } from '../providers/ssh-host-not-served-error' const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/git-exec-file-sync', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileSync: vi.fn() })) diff --git a/src/main/runtime/runtime-rpc-delegated-device-sync.test.ts b/src/main/runtime/runtime-rpc-delegated-device-sync.test.ts index fbcebfddbba..119bb449072 100644 --- a/src/main/runtime/runtime-rpc-delegated-device-sync.test.ts +++ b/src/main/runtime/runtime-rpc-delegated-device-sync.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' // A phone's delegated child removed on disk must come back fresh in the same sync, not the next one. import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -9,26 +9,30 @@ import { OrcaRuntimeService } from './orca-runtime' import { OrcaRuntimeRpcServer } from './runtime-rpc' import type { DeviceRegistry } from './device-registry' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) let server: OrcaRuntimeRpcServer let registry: DeviceRegistry diff --git a/src/main/runtime/runtime-rpc-device-revocation.test.ts b/src/main/runtime/runtime-rpc-device-revocation.test.ts index 59b705fe117..8ba0cabbf13 100644 --- a/src/main/runtime/runtime-rpc-device-revocation.test.ts +++ b/src/main/runtime/runtime-rpc-device-revocation.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' @@ -16,36 +16,40 @@ import { authenticateMobileWs } from './runtime-rpc-mobile-ws-test-harness' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) describe('OrcaRuntimeRpcServer', () => { diff --git a/src/main/runtime/runtime-rpc-long-poll-transport.test.ts b/src/main/runtime/runtime-rpc-long-poll-transport.test.ts index 3622e2e16d2..5785c1e7dff 100644 --- a/src/main/runtime/runtime-rpc-long-poll-transport.test.ts +++ b/src/main/runtime/runtime-rpc-long-poll-transport.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import './rpc/unused-default-rpc-methods.test-fixture' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -9,7 +9,7 @@ import { describe, expect, it, vi } from 'vitest' import { OrcaRuntimeService } from './orca-runtime' import { OrchestrationDb } from './orchestration/db' import { readRuntimeMetadata } from './runtime-metadata' -import { classifyRuntimeLongPoll } from './runtime-rpc/runtime-rpc-long-poll' + import { createLongPollServer as createServer } from './runtime-rpc-long-poll-server.test-fixture' import { sendRequest, @@ -21,96 +21,26 @@ import { import { createRootDispatch } from './orchestration/db/root-dispatch-test-fixture' import { createTranscriptPane, TRANSCRIPT_PANE_PTY_ID } from './agent-transcript-pane-test-harness' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => ({ +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ ...(await importOriginal()), - listWorktrees: (await vi.importMock('../git/worktree')) - .listWorktrees + listWorktrees: (await getWorktreeOwnerMocks()).listWorktrees })) -vi.mock('../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ ...(await importOriginal()), - listWorktreesStrict: (await vi.importMock('../git/worktree')) - .listWorktreesStrict + listWorktreesStrict: (await getWorktreeOwnerMocks()).listWorktreesStrict })) -vi.mock('../git/worktree', async () => - (await import('./runtime-rpc-worktree-store-fixtures')).createWorktreeListingMocks() -) +const { getWorktreeOwnerMocks } = vi.hoisted(() => { + function createWorktreeOwnerMocks() { + return (async () => + (await import('./runtime-rpc-worktree-store-fixtures')).createWorktreeListingMocks())() + } + let fixture: ReturnType | undefined + return { getWorktreeOwnerMocks: () => (fixture ??= createWorktreeOwnerMocks()) } +}) describe('OrcaRuntimeRpcServer', () => { - it('classifies worker-start as a keepalive-backed long poll', () => { - expect( - classifyRuntimeLongPoll({ - id: 'req_worker_start', - authToken: 'token', - method: 'orchestration.workerStart', - params: { task: 'task_1', timeoutMs: 60_000 } - }) - ).toBe('wait') - }) - - it.each(['agent.launch', 'agent.launchReplay'])( - 'keeps a prompted %s alive while it waits for the agent to be ready', - (method) => { - const prompt = { text: 'fix the build', delivery: 'submit' } - expect( - classifyRuntimeLongPoll({ - id: 'req_launch', - authToken: 'token', - method, - params: { prompt } - }) - ).toBe('wait') - // An existing workspace without a prompt remains a short call. - expect( - classifyRuntimeLongPoll({ id: 'req_launch', authToken: 'token', method, params: {} }) - ).toBeNull() - } - ) - - it.each(['agent.launch', 'agent.launchReplay'])( - 'keeps unprompted %s workspace setup alive', - (method) => { - expect( - classifyRuntimeLongPoll({ - id: 'req_setup', - authToken: 'token', - method, - params: { - target: { kind: 'create-worktree', create: { repo: 'id:repo-1', name: 'task' } } - } - }) - ).toBe('wait') - expect( - classifyRuntimeLongPoll({ - id: 'req_existing', - authToken: 'token', - method, - params: { target: { kind: 'existing', worktree: 'id:wt-7' } } - }) - ).toBeNull() - } - ) - - it('keeps agent-prompt submission sockets alive during verification', () => { - expect( - classifyRuntimeLongPoll({ - id: 'req_prompt', - authToken: 'token', - method: 'terminal.send', - params: { agentPrompt: true } - }) - ).toBe('wait') - expect( - classifyRuntimeLongPoll({ - id: 'req_direct', - authToken: 'token', - method: 'terminal.send', - params: { agentPrompt: false } - }) - ).toBeNull() - }) - it('rejects oversized RPC frames instead of buffering them indefinitely', async () => { const userDataPath = mkdtempSync(join(tmpdir(), 'orca-runtime-rpc-')) const runtime = new OrcaRuntimeService() diff --git a/src/main/runtime/runtime-rpc-metadata-lifecycle.test.ts b/src/main/runtime/runtime-rpc-metadata-lifecycle.test.ts index 2b1e55ebaa3..07700e9c746 100644 --- a/src/main/runtime/runtime-rpc-metadata-lifecycle.test.ts +++ b/src/main/runtime/runtime-rpc-metadata-lifecycle.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import './rpc/unused-default-rpc-methods.test-fixture' import { existsSync, mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -13,36 +13,40 @@ import { OrcaRuntimeRpcServer } from './runtime-rpc' import type { DeviceRegistry } from './device-registry' import type { RuntimeMetadata } from '../../shared/runtime-bootstrap' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) describe('OrcaRuntimeRpcServer', () => { diff --git a/src/main/runtime/runtime-rpc-mobile-terminal-streaming.test.ts b/src/main/runtime/runtime-rpc-mobile-terminal-streaming.test.ts index 1ee8d890347..56370504653 100644 --- a/src/main/runtime/runtime-rpc-mobile-terminal-streaming.test.ts +++ b/src/main/runtime/runtime-rpc-mobile-terminal-streaming.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { z } from 'zod' import { pairedRuntimeConnectionFromOffer } from '../../shared/paired-runtime-connection' import { mkdtempSync } from 'node:fs' @@ -29,36 +29,40 @@ import { import { makeStore } from './runtime-rpc-worktree-store-fixtures' import { committingSpawn } from './bind-first-pane.test-fixture' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) describe('OrcaRuntimeRpcServer', () => { diff --git a/src/main/runtime/runtime-rpc-orchestration-db-migration.test.ts b/src/main/runtime/runtime-rpc-orchestration-db-migration.test.ts index 6272e9c2963..db6a043e492 100644 --- a/src/main/runtime/runtime-rpc-orchestration-db-migration.test.ts +++ b/src/main/runtime/runtime-rpc-orchestration-db-migration.test.ts @@ -5,22 +5,36 @@ import { describe, expect, it, vi } from 'vitest' import Database from '../sqlite/sync-database' import { OrchestrationDb } from './orchestration/db' -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktrees: getWorktreeListingMocks().listWorktrees +})) + +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ + ...(await importOriginal>()), + listWorktreesStrict: getWorktreeListingMocks().listWorktreesStrict +})) + describe('OrcaRuntimeRpcServer', () => { // Migration must be idempotent and fail startup loudly rather than serve a schema missing delivered_at (design §6). describe('orchestration DB migration (§3.2)', () => { diff --git a/src/main/runtime/runtime-rpc-pairing-mode-persistence.test.ts b/src/main/runtime/runtime-rpc-pairing-mode-persistence.test.ts index 33805148398..19ff52a7ada 100644 --- a/src/main/runtime/runtime-rpc-pairing-mode-persistence.test.ts +++ b/src/main/runtime/runtime-rpc-pairing-mode-persistence.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' @@ -14,36 +14,40 @@ import { createEncryptedWsResponseReader } from './runtime-rpc-mobile-ws-test-harness' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) describe('OrcaRuntimeRpcServer', () => { diff --git a/src/main/runtime/runtime-rpc-pairing-offer.test.ts b/src/main/runtime/runtime-rpc-pairing-offer.test.ts index 7215d3ef9f9..80061538e0e 100644 --- a/src/main/runtime/runtime-rpc-pairing-offer.test.ts +++ b/src/main/runtime/runtime-rpc-pairing-offer.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import './rpc/unused-default-rpc-methods.test-fixture' import { mkdirSync, mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -11,36 +11,40 @@ import { parsePairingCode } from '../../shared/pairing' import { DEVICE_REGISTRY_FILENAME, E2EE_KEYPAIR_FILENAME } from './mobile-pairing-files' import { STATUS_METHODS } from './rpc/methods/status' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) describe('OrcaRuntimeRpcServer', () => { diff --git a/src/main/runtime/runtime-rpc-relay-pairing.test.ts b/src/main/runtime/runtime-rpc-relay-pairing.test.ts index c81b15f621a..1857ab81689 100644 --- a/src/main/runtime/runtime-rpc-relay-pairing.test.ts +++ b/src/main/runtime/runtime-rpc-relay-pairing.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import './rpc/unused-default-rpc-methods.test-fixture' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -9,36 +9,40 @@ import { OrcaRuntimeService } from './orca-runtime' import { OrcaRuntimeRpcServer } from './runtime-rpc' import { parsePairingCode } from '../../shared/pairing' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) describe('OrcaRuntimeRpcServer', () => { diff --git a/src/main/runtime/runtime-rpc-relay-provider-install.test.ts b/src/main/runtime/runtime-rpc-relay-provider-install.test.ts index a4b4d7c529f..d2278619352 100644 --- a/src/main/runtime/runtime-rpc-relay-provider-install.test.ts +++ b/src/main/runtime/runtime-rpc-relay-provider-install.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import './rpc/unused-default-rpc-methods.test-fixture' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -8,26 +8,30 @@ import { describe, expect, it, vi } from 'vitest' import { OrcaRuntimeService } from './orca-runtime' import { OrcaRuntimeRpcServer } from './runtime-rpc' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) describe('automatic mobile pairing with a missing Relay provider (#20005)', () => { it('installs the provider on demand instead of failing provider_missing', async () => { diff --git a/src/main/runtime/runtime-rpc-request-authorization.test.ts b/src/main/runtime/runtime-rpc-request-authorization.test.ts index 1ef7f505816..a8ca8c092e2 100644 --- a/src/main/runtime/runtime-rpc-request-authorization.test.ts +++ b/src/main/runtime/runtime-rpc-request-authorization.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import './rpc/unused-default-rpc-methods.test-fixture' import { mkdtempSync } from 'node:fs' import { createHash } from 'node:crypto' @@ -28,36 +28,40 @@ const methods = [ ...GIT_METHODS ] -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) describe('OrcaRuntimeRpcServer', () => { diff --git a/src/main/runtime/runtime-rpc-terminal-list.test.ts b/src/main/runtime/runtime-rpc-terminal-list.test.ts index 746a123fd86..eaae79954af 100644 --- a/src/main/runtime/runtime-rpc-terminal-list.test.ts +++ b/src/main/runtime/runtime-rpc-terminal-list.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' @@ -10,36 +10,40 @@ import { OrcaRuntimeRpcServer } from './runtime-rpc' import { sendRequest } from './runtime-rpc-test-harness' import { makeStore } from './runtime-rpc-worktree-store-fixtures' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) describe('OrcaRuntimeRpcServer', () => { diff --git a/src/main/runtime/runtime-rpc-websocket-bind-host.test.ts b/src/main/runtime/runtime-rpc-websocket-bind-host.test.ts index f4b500df170..9df39d2d72e 100644 --- a/src/main/runtime/runtime-rpc-websocket-bind-host.test.ts +++ b/src/main/runtime/runtime-rpc-websocket-bind-host.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import './rpc/unused-default-rpc-methods.test-fixture' import { mkdtempSync } from 'node:fs' import { writeFile } from 'node:fs/promises' @@ -13,36 +13,40 @@ import { WebSocketTransport } from './rpc/ws-transport' import { DeviceRegistry } from './device-registry' import { DEVICE_REGISTRY_FILENAME } from './mobile-pairing-files' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) describe('OrcaRuntimeRpcServer WebSocket bind host (STA-2370)', () => { diff --git a/src/main/runtime/runtime-rpc-websocket-fallback-port.test.ts b/src/main/runtime/runtime-rpc-websocket-fallback-port.test.ts index 7301d145d44..1b45f57df13 100644 --- a/src/main/runtime/runtime-rpc-websocket-fallback-port.test.ts +++ b/src/main/runtime/runtime-rpc-websocket-fallback-port.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import './rpc/unused-default-rpc-methods.test-fixture' import { existsSync, mkdtempSync, writeFileSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -9,26 +9,30 @@ import { OrcaRuntimeService } from './orca-runtime' import { OrcaRuntimeRpcServer } from './runtime-rpc' import { WebSocketTransport } from './rpc/ws-transport' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([]), - listWorktreesStrict: vi.fn().mockResolvedValue([]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([]), + listWorktreesStrict: vi.fn().mockResolvedValue([]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) const FALLBACK_FILE = 'mobile-ws-fallback-port.json' diff --git a/src/main/runtime/runtime-rpc-websocket-long-poll-caps.test.ts b/src/main/runtime/runtime-rpc-websocket-long-poll-caps.test.ts index ccf34601f04..57011bfe490 100644 --- a/src/main/runtime/runtime-rpc-websocket-long-poll-caps.test.ts +++ b/src/main/runtime/runtime-rpc-websocket-long-poll-caps.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import './rpc/unused-default-rpc-methods.test-fixture' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' @@ -19,36 +19,40 @@ import { seedSupervisedAskWorkers } from './runtime-rpc-test-harness' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) class FakeWebSocket extends EventEmitter { diff --git a/src/main/runtime/runtime-rpc-worktree-queries.test.ts b/src/main/runtime/runtime-rpc-worktree-queries.test.ts index ab1f85d19bf..928041428f7 100644 --- a/src/main/runtime/runtime-rpc-worktree-queries.test.ts +++ b/src/main/runtime/runtime-rpc-worktree-queries.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { mkdtempSync } from 'node:fs' import { tmpdir } from 'node:os' import { join } from 'node:path' @@ -10,36 +10,40 @@ import { OrcaRuntimeRpcServer } from './runtime-rpc' import { sendRequest } from './runtime-rpc-test-harness' import { makeStore } from './runtime-rpc-worktree-store-fixtures' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/foo', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/foo', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) describe('OrcaRuntimeRpcServer', () => { diff --git a/src/main/runtime/runtime-rpc-worktree-store-fixtures.ts b/src/main/runtime/runtime-rpc-worktree-store-fixtures.ts index e98d1003f08..b5e49ebb8f2 100644 --- a/src/main/runtime/runtime-rpc-worktree-store-fixtures.ts +++ b/src/main/runtime/runtime-rpc-worktree-store-fixtures.ts @@ -1,8 +1,8 @@ import { vi } from 'vitest' import type { Mock } from 'vitest' import type { HostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' -import type { listWorktrees } from '../git/worktree-scan-cache' -import type { listWorktreesStrict } from '../git/worktree-listing' +import type { listWorktrees } from '../git/worktrees/catalog/worktree-scan-cache' +import type { listWorktreesStrict } from '../git/worktrees/catalog/worktree-listing' export const makeStore = (overrides?: { isUnread?: boolean }) => ({ getRepo: (id: string) => makeStore(overrides) diff --git a/src/main/runtime/runtime-rpc/runtime-rpc-long-poll.test.ts b/src/main/runtime/runtime-rpc/runtime-rpc-long-poll.test.ts new file mode 100644 index 00000000000..b982786d829 --- /dev/null +++ b/src/main/runtime/runtime-rpc/runtime-rpc-long-poll.test.ts @@ -0,0 +1,77 @@ +import { describe, expect, it } from 'vitest' +import { classifyRuntimeLongPoll } from './runtime-rpc-long-poll' + +describe('OrcaRuntimeRpcServer', () => { + it('classifies worker-start as a keepalive-backed long poll', () => { + expect( + classifyRuntimeLongPoll({ + id: 'req_worker_start', + authToken: 'token', + method: 'orchestration.workerStart', + params: { task: 'task_1', timeoutMs: 60_000 } + }) + ).toBe('wait') + }) + + it.each(['agent.launch', 'agent.launchReplay'])( + 'keeps a prompted %s alive while it waits for the agent to be ready', + (method) => { + const prompt = { text: 'fix the build', delivery: 'submit' } + expect( + classifyRuntimeLongPoll({ + id: 'req_launch', + authToken: 'token', + method, + params: { prompt } + }) + ).toBe('wait') + // An existing workspace without a prompt remains a short call. + expect( + classifyRuntimeLongPoll({ id: 'req_launch', authToken: 'token', method, params: {} }) + ).toBeNull() + } + ) + + it.each(['agent.launch', 'agent.launchReplay'])( + 'keeps unprompted %s workspace setup alive', + (method) => { + expect( + classifyRuntimeLongPoll({ + id: 'req_setup', + authToken: 'token', + method, + params: { + target: { kind: 'create-worktree', create: { repo: 'id:repo-1', name: 'task' } } + } + }) + ).toBe('wait') + expect( + classifyRuntimeLongPoll({ + id: 'req_existing', + authToken: 'token', + method, + params: { target: { kind: 'existing', worktree: 'id:wt-7' } } + }) + ).toBeNull() + } + ) + + it('keeps agent-prompt submission sockets alive during verification', () => { + expect( + classifyRuntimeLongPoll({ + id: 'req_prompt', + authToken: 'token', + method: 'terminal.send', + params: { agentPrompt: true } + }) + ).toBe('wait') + expect( + classifyRuntimeLongPoll({ + id: 'req_direct', + authToken: 'token', + method: 'terminal.send', + params: { agentPrompt: false } + }) + ).toBeNull() + }) +}) diff --git a/src/main/runtime/runtime-unregistered-worktree-removal.ts b/src/main/runtime/runtime-unregistered-worktree-removal.ts index 83feb8da60d..d0b5e01348d 100644 --- a/src/main/runtime/runtime-unregistered-worktree-removal.ts +++ b/src/main/runtime/runtime-unregistered-worktree-removal.ts @@ -1,5 +1,5 @@ -import { removeWorktree } from '../git/worktree-removal' -import { usesNativeWindowsRemoval } from '../git/windows-worktree-removal' +import { removeWorktree } from '../git/worktrees/removal/worktree-removal' +import { usesNativeWindowsRemoval } from '../git/worktrees/removal/windows-worktree-removal' import type { GitPushTarget, GitWorktreeInfo } from '../../shared/worktree/types' import type { Repo } from '../../shared/repo-types' import type { WorktreeMeta } from '../../shared/worktree/meta-types' diff --git a/src/main/runtime/runtime-worktree-create-git.test.ts b/src/main/runtime/runtime-worktree-create-git.test.ts index f0ad38cab4d..3e32ff785dc 100644 --- a/src/main/runtime/runtime-worktree-create-git.test.ts +++ b/src/main/runtime/runtime-worktree-create-git.test.ts @@ -4,8 +4,13 @@ import type * as GitHubClient from '../github/client' const getPRForBranchMock = vi.hoisted(() => vi.fn()) const git = vi.hoisted(() => vi.fn()) const worktrees = vi.hoisted(() => vi.fn()) -vi.mock('../git/runner', () => ({ gitExecFileAsync: git })) -vi.mock('../git/worktree', () => ({ listWorktrees: worktrees })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: git +})) +vi.mock('../git/worktrees/catalog/worktree-scan-cache', () => ({ + listWorktrees: worktrees +})) vi.mock('../github/client', async (importOriginal) => ({ ...(await importOriginal()), diff --git a/src/main/runtime/runtime-worktree-create-git.ts b/src/main/runtime/runtime-worktree-create-git.ts index 3e4fca56211..72846e5aa54 100644 --- a/src/main/runtime/runtime-worktree-create-git.ts +++ b/src/main/runtime/runtime-worktree-create-git.ts @@ -5,7 +5,7 @@ import { getPRForBranch } from '../github/client' import type { GitAdmissionTier } from '../../shared/rpc-contract/git-admission-tier-params' import { gitExecFileAsync } from '../git/runner' import { foldGitRefNameCase } from '../git/repo-branch-conflict' -import { listWorktrees } from '../git/worktree' +import { listWorktrees } from '../git/worktrees/catalog/worktree-scan-cache' import { computeValidatedBranchName } from '../ipc/worktree-branch-name' import { getHostedReviewForBranch } from '../source-control/hosted-review' import { diff --git a/src/main/runtime/session-tabs/structured-workspace-authority.ts b/src/main/runtime/session-tabs/structured-workspace-authority.ts index 648439e42bc..77c78982972 100644 --- a/src/main/runtime/session-tabs/structured-workspace-authority.ts +++ b/src/main/runtime/session-tabs/structured-workspace-authority.ts @@ -16,7 +16,7 @@ import { withTimeout } from '../../../shared/promise-timeout-fallback' import { parseWorkspaceKey } from '../../../shared/workspace-scope' import { splitWorktreeIdForFilesystem } from '../../../shared/worktree/id' import { beginWatcherInstall } from '../../ipc/watcher-removal-gate' -import { areWorktreePathsEqual } from '../../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../../git/worktrees/catalog/worktree-path-comparison' import { resolveFloatingWorkspacePath } from '../../persistence/restoring-sessions/floating-workspace-normalization' import { getAppEnvironment } from '../../../shared/app-environment' import { resolveLocalProjectRuntimeForRepo } from '../../workspaces/execution-host/local-project-runtime-resolution' diff --git a/src/main/runtime/terminal-run-facts-input.test.ts b/src/main/runtime/terminal-run-facts-input.test.ts index 59bdb106021..4c670c52ed1 100644 --- a/src/main/runtime/terminal-run-facts-input.test.ts +++ b/src/main/runtime/terminal-run-facts-input.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { afterEach, describe, expect, it, vi } from 'vitest' import type { TerminalInputKind } from '../../shared/terminal-input-kind' import { writePtyFromRuntimeController } from '../ipc/pty/runtime/operations' @@ -16,36 +16,40 @@ import { type WorktreeStartupReadinessHost } from './runtime-worktree-startup-readiness' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/run-facts', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/run-facts', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) const PTY_ID = 'pty-run-facts-input' diff --git a/src/main/runtime/terminal-send-idle-shell-settle.test.ts b/src/main/runtime/terminal-send-idle-shell-settle.test.ts index 6e0bc14c10a..bb477002ffd 100644 --- a/src/main/runtime/terminal-send-idle-shell-settle.test.ts +++ b/src/main/runtime/terminal-send-idle-shell-settle.test.ts @@ -1,40 +1,44 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { afterEach, describe, expect, it, vi } from 'vitest' import type { AgentStatusIpcPayload } from '../../shared/agent-status-ipc-payload' import { OrcaRuntimeService } from './orca-runtime' import { makeStore } from './runtime-rpc-worktree-store-fixtures' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktrees: facade.listWorktrees + listWorktrees: listings.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const listings = getWorktreeListingMocks() return { ...(await importOriginal()), - listWorktreesStrict: facade.listWorktreesStrict + listWorktreesStrict: listings.listWorktreesStrict } }) -vi.mock('../git/worktree', () => { - const worktrees = [ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/idle-shell-settle', - isBare: false, - isMainWorktree: false +const { getWorktreeListingMocks } = vi.hoisted(() => { + function createWorktreeListingMocks() { + const worktrees = [ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/idle-shell-settle', + isBare: false, + isMainWorktree: false + } + ] + return { + listWorktrees: vi.fn().mockResolvedValue(worktrees), + listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } - ] - return { - listWorktrees: vi.fn().mockResolvedValue(worktrees), - listWorktreesStrict: vi.fn().mockResolvedValue(worktrees) } + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } }) const PTY_ID = 'pty-idle-shell' diff --git a/src/main/runtime/windows-codex-held-prompt-resubmit.test.ts b/src/main/runtime/windows-codex-held-prompt-resubmit.test.ts index 1e3eccaa61c..fb75f8d8df4 100644 --- a/src/main/runtime/windows-codex-held-prompt-resubmit.test.ts +++ b/src/main/runtime/windows-codex-held-prompt-resubmit.test.ts @@ -1,44 +1,48 @@ -import type * as WorktreeScanCacheModule from '../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { afterEach, describe, expect, it, vi } from 'vitest' import { createAgentPromptSubmissionRuntime } from './agent-prompt-submission-runtime-test-fixture' -vi.mock('../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../git/worktree') +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = getWorktreeListingMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../git/worktree', () => ({ - listWorktrees: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-verification', - isBare: false, - isMainWorktree: false - } - ]), - listWorktreesStrict: vi.fn().mockResolvedValue([ - { - path: '/tmp/worktree-a', - head: 'abc', - branch: 'feature/prompt-verification', - isBare: false, - isMainWorktree: false - } - ]) -})) +const { getWorktreeListingMocks } = vi.hoisted(() => { + const createWorktreeListingMocks = () => ({ + listWorktrees: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-verification', + isBare: false, + isMainWorktree: false + } + ]), + listWorktreesStrict: vi.fn().mockResolvedValue([ + { + path: '/tmp/worktree-a', + head: 'abc', + branch: 'feature/prompt-verification', + isBare: false, + isMainWorktree: false + } + ]) + }) + let listings: ReturnType | undefined + return { getWorktreeListingMocks: () => (listings ??= createWorktreeListingMocks()) } +}) describe('a Windows Codex prompt held in its paste burst', () => { afterEach(() => vi.useRealTimers()) diff --git a/src/main/runtime/workspaces/stale-worktree-registration-preflight.ts b/src/main/runtime/workspaces/stale-worktree-registration-preflight.ts index 1ef21187e96..4016bba7a73 100644 --- a/src/main/runtime/workspaces/stale-worktree-registration-preflight.ts +++ b/src/main/runtime/workspaces/stale-worktree-registration-preflight.ts @@ -3,7 +3,7 @@ import type { WorktreeMeta } from '../../../shared/worktree/meta-types' import type { LocalProjectWorktreeGitOptions } from '../../workspaces/execution-host/project-runtime-git-options' import { assertWorktreeUnlockedForRemoval } from '../../../shared/worktree/removal' import { formatWorktreeRemovalError } from '../../ipc/worktree-logic' -import { usesNativeWindowsRemoval } from '../../git/windows-worktree-removal' +import { usesNativeWindowsRemoval } from '../../git/worktrees/removal/windows-worktree-removal' import { isPrunableGitFileWorktree } from '../../workspaces/removal/worktree-prunable-git-file' import { isWindowsAbsolutePathLike } from '../../../shared/cross-platform-path' import { isLocalRuntimeWorktreePathMissing } from '../runtime-worktree-filesystem' diff --git a/src/main/runtime/workspaces/workspace-metadata.ts b/src/main/runtime/workspaces/workspace-metadata.ts index 24d80ed7865..3db7848b52f 100644 --- a/src/main/runtime/workspaces/workspace-metadata.ts +++ b/src/main/runtime/workspaces/workspace-metadata.ts @@ -18,7 +18,7 @@ import { resolveRuntimeGitLabWorktreeBase, type RuntimeGitLabWorktreeBaseArgs } from '../runtime-gitlab-worktree-base' -import { listWorktreesStrict } from '../../git/worktree-listing' +import { listWorktreesStrict } from '../../git/worktrees/catalog/worktree-listing' import { adoptRuntimeProvisionedRoot, readLocalSparseCheckoutEnabled, diff --git a/src/main/runtime/workspaces/workspace-removal.ts b/src/main/runtime/workspaces/workspace-removal.ts index a8a12bf6582..d9562d25c10 100644 --- a/src/main/runtime/workspaces/workspace-removal.ts +++ b/src/main/runtime/workspaces/workspace-removal.ts @@ -26,7 +26,7 @@ import { resolveWorktreeRemovalRoute } from '../../workspaces/removal/worktree-removal-execution-host-route' import { listWorktreesOnRemovalRoute } from '../worktree-removal-route-listing' -import { authorizeUnregisteredWindowsRemoval } from '../../git/windows-worktree-removal' +import { authorizeUnregisteredWindowsRemoval } from '../../git/worktrees/removal/windows-worktree-removal' import { findRegisteredDeletableWorktree } from '../../workspaces/removal/worktree-removal-safety' import { removeRuntimeUnregisteredWorktree } from '../runtime-unregistered-worktree-removal' import { removeStaleLocalWorktreeRegistration } from '../../workspaces/removal/local-worktree-removal-recovery' diff --git a/src/main/runtime/workspaces/workspace-selectors.ts b/src/main/runtime/workspaces/workspace-selectors.ts index 2dfba078f39..d3f71d47b23 100644 --- a/src/main/runtime/workspaces/workspace-selectors.ts +++ b/src/main/runtime/workspaces/workspace-selectors.ts @@ -24,7 +24,7 @@ import type { WorkspaceKey } from '../../../shared/folder-workspace-types' import type { Repo } from '../../../shared/repo-types' import type { RuntimeStore } from '../runtime-store-contract' import type { RuntimeWorkspaceCatalog } from './workspace-catalog' -import { areWorktreePathsEqual } from '../../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../../git/worktrees/catalog/worktree-path-comparison' import { resolveWorktreeMetaOwner } from '../../persistence/host-qualified-worktree-meta' import { resolveWorktreeHostRouting } from '../worktree-launch-host-repo' import { createRepoRowExecutionHostLookup } from '../../../shared/worktree-execution-host-resolution' diff --git a/src/main/runtime/worktree-path-selector-wsl-posix.test.ts b/src/main/runtime/worktree-path-selector-wsl-posix.test.ts index 9998a0df042..aac7b5bba0f 100644 --- a/src/main/runtime/worktree-path-selector-wsl-posix.test.ts +++ b/src/main/runtime/worktree-path-selector-wsl-posix.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' /** Translate WSL POSIX selectors to stored UNC paths using the caller's distro. Delete shares this resolver, so matching only the path tail could remove another distro's copy (#16628). */ import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -15,7 +15,7 @@ const electronMocks = vi.hoisted(() => { app: { getPath: vi.fn(() => '/tmp'), isPackaged: false } } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { return { ...(await importOriginal()), listWorktreesStrict: listWorktreesStrictMock @@ -25,10 +25,6 @@ vi.mock('../git/worktree-listing', async (importOriginal) => { vi.mock('electron', () => electronMocks) const listWorktreesStrictMock = vi.hoisted(() => vi.fn()) -vi.mock('../git/worktree', async (importOriginal) => ({ - ...(await importOriginal>()), - listWorktreesStrict: listWorktreesStrictMock -})) import { isWslUncPathForCallerLinuxPath } from '../../shared/cross-platform-path' import { parseWslUncPath } from '../../shared/wsl-paths' diff --git a/src/main/runtime/worktree-ps-degraded-repo-scan.test.ts b/src/main/runtime/worktree-ps-degraded-repo-scan.test.ts index fd86570c642..4d51be60726 100644 --- a/src/main/runtime/worktree-ps-degraded-repo-scan.test.ts +++ b/src/main/runtime/worktree-ps-degraded-repo-scan.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { beforeEach, describe, expect, it, vi } from 'vitest' const electronMocks = vi.hoisted(() => { @@ -14,7 +14,7 @@ const electronMocks = vi.hoisted(() => { app: { getPath: vi.fn(() => '/tmp'), isPackaged: false } } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { return { ...(await importOriginal()), listWorktreesStrict: listWorktreesStrictMock @@ -27,10 +27,6 @@ vi.mock('./repo-worktree-admin-fingerprint', () => ({ })) const listWorktreesStrictMock = vi.hoisted(() => vi.fn()) -vi.mock('../git/worktree', async (importOriginal) => ({ - ...(await importOriginal>()), - listWorktreesStrict: listWorktreesStrictMock -})) import { LOCAL_EXECUTION_HOST_ID, toSshExecutionHostId } from '../../shared/execution-host' import type { WorktreeMeta } from '../../shared/worktree/meta-types' diff --git a/src/main/runtime/worktree-ps-host-scope.test.ts b/src/main/runtime/worktree-ps-host-scope.test.ts index d2ae9376f75..203436b9c5d 100644 --- a/src/main/runtime/worktree-ps-host-scope.test.ts +++ b/src/main/runtime/worktree-ps-host-scope.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' import { beforeEach, describe, expect, it, vi } from 'vitest' const electronMocks = vi.hoisted(() => { @@ -14,7 +14,7 @@ const electronMocks = vi.hoisted(() => { app: { getPath: vi.fn(() => '/tmp'), isPackaged: false } } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { return { ...(await importOriginal()), listWorktreesStrict: listWorktreesStrictMock @@ -24,10 +24,6 @@ vi.mock('../git/worktree-listing', async (importOriginal) => { vi.mock('electron', () => electronMocks) const listWorktreesStrictMock = vi.hoisted(() => vi.fn()) -vi.mock('../git/worktree', async (importOriginal) => ({ - ...(await importOriginal>()), - listWorktreesStrict: listWorktreesStrictMock -})) import { OrcaRuntimeService } from './orca-runtime' import type { HostWorktreeTarget } from '../../shared/worktree/host-qualified-identity' diff --git a/src/main/runtime/worktree-removal-route-listing.ts b/src/main/runtime/worktree-removal-route-listing.ts index 6aaee40a158..d972af2eb48 100644 --- a/src/main/runtime/worktree-removal-route-listing.ts +++ b/src/main/runtime/worktree-removal-route-listing.ts @@ -4,7 +4,7 @@ import type { GitWorktreeInfo } from '../../shared/worktree/types' import type { WorktreeRemovalRoute } from '../workspaces/removal/worktree-removal-execution-host-route' import type { LocalProjectWorktreeGitOptions } from '../workspaces/execution-host/project-runtime-git-options' import { getLocalProjectWorktreeGitOptions } from '../workspaces/execution-host/project-runtime-git-options' -import { listWorktreesStrict } from '../git/worktree' +import { listWorktreesStrict } from '../git/worktrees/catalog/worktree-listing' /** Require a validated local removal route before listing, preventing reads before non-local hosts are refused. */ export async function listWorktreesOnRemovalRoute( diff --git a/src/main/runtime/worktree-rm-id-selector-path-spelling.test.ts b/src/main/runtime/worktree-rm-id-selector-path-spelling.test.ts index af48f15d4a3..88e76da4024 100644 --- a/src/main/runtime/worktree-rm-id-selector-path-spelling.test.ts +++ b/src/main/runtime/worktree-rm-id-selector-path-spelling.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' /** Preserve id/path spelling parity, while id remains ambiguous for same-host duplicate rows that path deduplicates. This resolver also deletes workspaces (#16243). */ import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -15,7 +15,7 @@ const electronMocks = vi.hoisted(() => { app: { getPath: vi.fn(() => '/tmp'), isPackaged: false } } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { return { ...(await importOriginal()), listWorktreesStrict: listWorktreesStrictMock @@ -25,10 +25,6 @@ vi.mock('../git/worktree-listing', async (importOriginal) => { vi.mock('electron', () => electronMocks) const listWorktreesStrictMock = vi.hoisted(() => vi.fn()) -vi.mock('../git/worktree', async (importOriginal) => ({ - ...(await importOriginal>()), - listWorktreesStrict: listWorktreesStrictMock -})) import { LOCAL_EXECUTION_HOST_ID } from '../../shared/execution-host' import { OrcaRuntimeService } from './orca-runtime' diff --git a/src/main/runtime/worktree-scan-admin-fingerprint-gate.test.ts b/src/main/runtime/worktree-scan-admin-fingerprint-gate.test.ts index a6f34b0f76c..34b9ea6cd6f 100644 --- a/src/main/runtime/worktree-scan-admin-fingerprint-gate.test.ts +++ b/src/main/runtime/worktree-scan-admin-fingerprint-gate.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' // Check scan-cache gating here; real-Git fingerprint behavior lives in repo-worktree-admin-fingerprint.test.ts. Windows CI also exercises repo-path handling. import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -15,7 +15,7 @@ const electronMocks = vi.hoisted(() => { app: { getPath: vi.fn(() => '/tmp'), isPackaged: false } } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { return { ...(await importOriginal()), listWorktreesStrict: listWorktreesStrictMock @@ -25,10 +25,6 @@ vi.mock('../git/worktree-listing', async (importOriginal) => { vi.mock('electron', () => electronMocks) const listWorktreesStrictMock = vi.hoisted(() => vi.fn()) -vi.mock('../git/worktree', async (importOriginal) => ({ - ...(await importOriginal>()), - listWorktreesStrict: listWorktreesStrictMock -})) const readRepoWorktreeAdminFingerprintMock = vi.hoisted(() => vi.fn()) vi.mock('./repo-worktree-admin-fingerprint', () => ({ diff --git a/src/main/runtime/worktree-scan-execution-host-routing.test.ts b/src/main/runtime/worktree-scan-execution-host-routing.test.ts index 223438688e8..feba34fe7e9 100644 --- a/src/main/runtime/worktree-scan-execution-host-routing.test.ts +++ b/src/main/runtime/worktree-scan-execution-host-routing.test.ts @@ -1,4 +1,4 @@ -import type * as WorktreeListingModule from '../git/worktree-listing' +import type * as WorktreeListingModule from '../git/worktrees/catalog/worktree-listing' // An executionHostId-only SSH repo must route scans and subsequent terminal launches remotely (#11163). import { beforeEach, describe, expect, it, vi } from 'vitest' @@ -15,7 +15,7 @@ const electronMocks = vi.hoisted(() => { app: { getPath: vi.fn(() => '/tmp'), isPackaged: false } } }) -vi.mock('../git/worktree-listing', async (importOriginal) => { +vi.mock('../git/worktrees/catalog/worktree-listing', async (importOriginal) => { return { ...(await importOriginal()), listWorktreesStrict: listWorktreesStrictMock @@ -25,10 +25,6 @@ vi.mock('../git/worktree-listing', async (importOriginal) => { vi.mock('electron', () => electronMocks) const listWorktreesStrictMock = vi.hoisted(() => vi.fn()) -vi.mock('../git/worktree', async (importOriginal) => ({ - ...(await importOriginal>()), - listWorktreesStrict: listWorktreesStrictMock -})) vi.mock('./repo-worktree-admin-fingerprint', () => ({ readRepoWorktreeAdminFingerprint: vi.fn(async () => null) diff --git a/src/main/source-control/hosted-review-creation-eligibility.test.ts b/src/main/source-control/hosted-review-creation-eligibility.test.ts index 89303217102..488d79486fd 100644 --- a/src/main/source-control/hosted-review-creation-eligibility.test.ts +++ b/src/main/source-control/hosted-review-creation-eligibility.test.ts @@ -101,7 +101,7 @@ vi.mock('../gitlab/gl-utils', () => ({ connectionId ? {} : { cwd: repoPath } })) -vi.mock('../git/upstream', () => ({ getUpstreamStatus: getUpstreamStatusMock })) +vi.mock('../git/source-control/upstream', () => ({ getUpstreamStatus: getUpstreamStatusMock })) vi.mock('./hosted-review', () => ({ getHostedReviewForBranch: getHostedReviewForBranchMock diff --git a/src/main/source-control/hosted-review-creation-git-state.ts b/src/main/source-control/hosted-review-creation-git-state.ts index 82fd9adc537..55929906e4c 100644 --- a/src/main/source-control/hosted-review-creation-git-state.ts +++ b/src/main/source-control/hosted-review-creation-git-state.ts @@ -8,10 +8,13 @@ import type { GitUpstreamStatus } from '../../shared/git-status-types' import { gitExecFileAsync } from '../github/gh-utils' import { isShowRefNoMatchError, probeExactRefsViaForEachRef } from '../git/exact-ref-probe' import { gitOptionalLocksDisabledEnv } from '../git/runner' -import { parsePorcelainV1Records, type PorcelainV1Record } from '../git/porcelain-v1-records' +import { + parsePorcelainV1Records, + type PorcelainV1Record +} from '../git/source-control/porcelain-v1-records' import { resolveDefaultBaseRefViaExec } from '../git/repo' -import { getUpstreamStatus } from '../git/upstream' -import { findExistingWorktreeSymlinkPaths } from '../git/worktree-symlink-detection' +import { getUpstreamStatus } from '../git/source-control/upstream' +import { findExistingWorktreeSymlinkPaths } from '../git/worktrees/content-paths/worktree-symlink-detection' import { requireReachableGitRoute } from '../providers/execution-host-provider-dispatch' import type { ExecutionHostId } from '../../shared/execution-host' import { diff --git a/src/main/source-control/hosted-review-creation-gitlab-self-hosted.test.ts b/src/main/source-control/hosted-review-creation-gitlab-self-hosted.test.ts index 181e06e77e0..bdd3a654baa 100644 --- a/src/main/source-control/hosted-review-creation-gitlab-self-hosted.test.ts +++ b/src/main/source-control/hosted-review-creation-gitlab-self-hosted.test.ts @@ -20,10 +20,23 @@ const { getRepoSlugMock: vi.fn() })) -vi.mock('../git/runner', () => ({ - gitExecFileAsync: gitExecFileAsyncMock, - glabExecFileAsync: glabExecFileAsyncMock, - ghExecFileAsync: ghExecFileAsyncMock, +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) + +vi.mock('../git/command-runner/glab-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + glabExecFileAsync: glabExecFileAsyncMock +})) + +vi.mock('../git/command-runner/gh-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + ghExecFileAsync: ghExecFileAsyncMock +})) + +vi.mock('../git/exec-error', async (importOriginal) => ({ + ...(await importOriginal>()), extractExecError: vi.fn() })) diff --git a/src/main/source-control/hosted-review-creation-shared-symlinks.test.ts b/src/main/source-control/hosted-review-creation-shared-symlinks.test.ts index 3180942a80d..15d649ba5f9 100644 --- a/src/main/source-control/hosted-review-creation-shared-symlinks.test.ts +++ b/src/main/source-control/hosted-review-creation-shared-symlinks.test.ts @@ -80,7 +80,7 @@ vi.mock('../gitlab/gl-utils', () => ({ glabExecFileAsync: glabExecFileAsyncMock, glabRepoExecOptions: (repoPath: string) => ({ cwd: repoPath }) })) -vi.mock('../git/upstream', () => ({ +vi.mock('../git/source-control/upstream', () => ({ getUpstreamStatus: getUpstreamStatusMock })) vi.mock('./hosted-review', () => ({ diff --git a/src/main/source-control/hosted-review-creation.test.ts b/src/main/source-control/hosted-review-creation.test.ts index 5298f081c63..384082a907b 100644 --- a/src/main/source-control/hosted-review-creation.test.ts +++ b/src/main/source-control/hosted-review-creation.test.ts @@ -101,7 +101,7 @@ vi.mock('../gitlab/gl-utils', () => ({ connectionId ? {} : { cwd: repoPath } })) -vi.mock('../git/upstream', () => ({ +vi.mock('../git/source-control/upstream', () => ({ getUpstreamStatus: getUpstreamStatusMock })) diff --git a/src/main/source-control/hosted-review-execution-host-routing.test.ts b/src/main/source-control/hosted-review-execution-host-routing.test.ts index 9e7745af945..b06991e0dd4 100644 --- a/src/main/source-control/hosted-review-execution-host-routing.test.ts +++ b/src/main/source-control/hosted-review-execution-host-routing.test.ts @@ -67,11 +67,12 @@ vi.mock('../gitlab/gl-utils', () => ({ glabRepoExecOptions: vi.fn(() => ({})) })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-process-env', async (importOriginal) => ({ + ...(await importOriginal>()), gitOptionalLocksDisabledEnv: vi.fn(() => ({})) })) -vi.mock('../git/upstream', () => ({ getUpstreamStatus: getUpstreamStatusMock })) +vi.mock('../git/source-control/upstream', () => ({ getUpstreamStatus: getUpstreamStatusMock })) vi.mock('../git/repo', () => ({ resolveDefaultBaseRefViaExec: resolveDefaultBaseRefViaExecMock @@ -82,11 +83,11 @@ vi.mock('../git/exact-ref-probe', () => ({ isShowRefNoMatchError: vi.fn(() => false) })) -vi.mock('../git/worktree-symlink-detection', () => ({ +vi.mock('../git/worktrees/content-paths/worktree-symlink-detection', () => ({ findExistingWorktreeSymlinkPaths: vi.fn(async () => []) })) -vi.mock('../git/remote-url-probe', () => ({ +vi.mock('../git/remotes/remote-url-probe', () => ({ assertRemoteUrlReadable: assertRemoteUrlReadableMock })) diff --git a/src/main/source-control/hosted-review-project-account.test.ts b/src/main/source-control/hosted-review-project-account.test.ts index 71c1190472f..084615bc392 100644 --- a/src/main/source-control/hosted-review-project-account.test.ts +++ b/src/main/source-control/hosted-review-project-account.test.ts @@ -14,7 +14,7 @@ const { read, detect, probe } = vi.hoisted(() => ({ detect: vi.fn(), probe: vi.fn() })) -vi.mock('../git/remote-url-probe', () => ({ assertRemoteUrlReadable: probe })) +vi.mock('../git/remotes/remote-url-probe', () => ({ assertRemoteUrlReadable: probe })) vi.mock('./forge-provider', () => ({ getForgeProviderForRepository: detect })) let release: () => void let repo: Repo diff --git a/src/main/source-control/hosted-review.ts b/src/main/source-control/hosted-review.ts index 14e58c0a504..4174e6e63e1 100644 --- a/src/main/source-control/hosted-review.ts +++ b/src/main/source-control/hosted-review.ts @@ -5,7 +5,7 @@ import { type HostedReviewForBranchOutcome, type HostedReviewInfo } from '../../shared/hosted-review' -import { assertRemoteUrlReadable } from '../git/remote-url-probe' +import { assertRemoteUrlReadable } from '../git/remotes/remote-url-probe' import { forgetGiteaPullRequestReads } from '../gitea/pull-request-read-forgetting' import { getForgeProviderForRepository, type ForgeProviderId } from './forge-provider' import { hostedReviewSshConnectionId } from './hosted-review-execution-host' diff --git a/src/main/source-control/repo-default-branch.test.ts b/src/main/source-control/repo-default-branch.test.ts index 648c20783ba..ddf89363c17 100644 --- a/src/main/source-control/repo-default-branch.test.ts +++ b/src/main/source-control/repo-default-branch.test.ts @@ -4,7 +4,8 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) diff --git a/src/main/source-control/repo-remote-head-branch.test.ts b/src/main/source-control/repo-remote-head-branch.test.ts index ff30e4ae66d..e12e221287c 100644 --- a/src/main/source-control/repo-remote-head-branch.test.ts +++ b/src/main/source-control/repo-remote-head-branch.test.ts @@ -4,7 +4,10 @@ const { gitExecFileAsyncMock } = vi.hoisted(() => ({ gitExecFileAsyncMock: vi.fn() })) -vi.mock('../git/runner', () => ({ gitExecFileAsync: gitExecFileAsyncMock })) +vi.mock('../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: gitExecFileAsyncMock +})) import { bumpScopeGeneration, hostedReviewRepoScope } from './hosted-review-scope-generations' import { LOCAL_EXECUTION_HOST_ID } from '../../shared/execution-host' diff --git a/src/main/startup/main-process-quit-pending-writer.test.ts b/src/main/startup/main-process-quit-pending-writer.test.ts index 97937776692..5d6c52fbc70 100644 --- a/src/main/startup/main-process-quit-pending-writer.test.ts +++ b/src/main/startup/main-process-quit-pending-writer.test.ts @@ -45,7 +45,7 @@ const dependencies: Record> = { '../browser/local-ssh-browser-route': { closeAllLocalSshBrowserRoutes: settled() }, '../codex/codex-state-db-backfill-recovery': { stopCodexStateDbBackfillRecoveries: settled() }, '../codex/codex-account-session-bridge': { stopCodexAccountSessionBridges: idle() }, - '../git/local-repo-ref-maintenance': { awaitPackedRefsLockRelease: settled() }, + '../git/refs/maintenance/local-repo-ref-maintenance': { awaitPackedRefsLockRelease: settled() }, '../worktree-background-removal': { stopBackgroundWorktreeRemovals: idle() }, '../dock/unread-badge': { setUnreadDockBadgeCount: idle() }, '../tray/system-tray': { destroySystemTray: idle() }, diff --git a/src/main/startup/main-process-quit-update-veto.test.ts b/src/main/startup/main-process-quit-update-veto.test.ts index 42256d17276..eb00ac0b9f6 100644 --- a/src/main/startup/main-process-quit-update-veto.test.ts +++ b/src/main/startup/main-process-quit-update-veto.test.ts @@ -31,7 +31,7 @@ const dependencyExports: [string, string[]][] = [ ['../browser/browser-session-registry', ['browserSessionRegistry']], ['../codex/codex-state-db-backfill-recovery', ['stopCodexStateDbBackfillRecoveries']], ['../codex/codex-account-session-bridge', ['stopCodexAccountSessionBridges']], - ['../git/local-repo-ref-maintenance', ['awaitPackedRefsLockRelease']], + ['../git/refs/maintenance/local-repo-ref-maintenance', ['awaitPackedRefsLockRelease']], ['../worktree-background-removal', ['stopBackgroundWorktreeRemovals']], ['./quit/quit-teardown-deadline', ['settleTeardownWithinDeadline', 'settleWithinMs']], ['./quit/quit-teardown-start-gate', ['quitTeardownStartGate']], diff --git a/src/main/startup/main-process-quit.ts b/src/main/startup/main-process-quit.ts index ecba79b70c0..819afba4c1b 100644 --- a/src/main/startup/main-process-quit.ts +++ b/src/main/startup/main-process-quit.ts @@ -19,7 +19,7 @@ import { disposeDesktopBrowserBridge } from '../ipc/desktop-browser-bridge-wirin import { browserManager } from '../browser/browser-manager' import { stopCodexStateDbBackfillRecoveries } from '../codex/codex-state-db-backfill-recovery' import { stopCodexAccountSessionBridges } from '../codex/codex-account-session-bridge' -import { awaitPackedRefsLockRelease } from '../git/local-repo-ref-maintenance' +import { awaitPackedRefsLockRelease } from '../git/refs/maintenance/local-repo-ref-maintenance' import { stopBackgroundWorktreeRemovals } from '../workspaces/removal/worktree-background-removal' import { settleTeardownWithinDeadline, settleWithinMs } from './quit/quit-teardown-deadline' import { quitTeardownStartGate } from './quit/quit-teardown-start-gate' diff --git a/src/main/startup/main-process-ready-identity-write.test.ts b/src/main/startup/main-process-ready-identity-write.test.ts index a6a7cceb6ff..f8596dca84a 100644 --- a/src/main/startup/main-process-ready-identity-write.test.ts +++ b/src/main/startup/main-process-ready-identity-write.test.ts @@ -148,8 +148,13 @@ vi.mock('./windows-shell-path-hydration', () => ({ whenReady: Promise.resolve() }) })) -vi.mock('../git/runner', () => ({ - configureWindowsHostGitEnvironmentReadiness: vi.fn(), +vi.mock('../git/command-runner/windows-host-git-environment', async (importOriginal) => ({ + ...(await importOriginal>()), + configureWindowsHostGitEnvironmentReadiness: vi.fn() +})) + +vi.mock('../git/command-runner/wsl-command-resolution', async (importOriginal) => ({ + ...(await importOriginal>()), setDefaultWslDistroOverride: vi.fn() })) vi.mock('../agent-hooks/wsl-hook-relay-manager', () => ({ diff --git a/src/main/telemetry/wsl-usage-reporter.ts b/src/main/telemetry/wsl-usage-reporter.ts index c82c3444438..87db580fbb0 100644 --- a/src/main/telemetry/wsl-usage-reporter.ts +++ b/src/main/telemetry/wsl-usage-reporter.ts @@ -21,7 +21,7 @@ import { wslHostsGateOpen, wslHostsGateState } from '../wsl/host-lifecycle/wsl-host-gate' -import { isForeignLink, readWorktreeLinks } from '../git/worktree-prune-guard' +import { isForeignLink, readWorktreeLinks } from '../git/worktrees/removal/worktree-prune-guard' import { isTelemetryEnabled, track } from './client' import { buildWslUsageSnapshot, diff --git a/src/main/text-generation/command-environment-wsl.test.ts b/src/main/text-generation/command-environment-wsl.test.ts index e7408a2e059..3f971ccd7f8 100644 --- a/src/main/text-generation/command-environment-wsl.test.ts +++ b/src/main/text-generation/command-environment-wsl.test.ts @@ -4,7 +4,10 @@ import { spawnSourceControlAgent } from './source-control-agent-launch' import { withPlatform } from './commit-message-text-generation-test-harness' import { resolveCodexHomeProcessLockKeyForSpawnEnv } from '../codex-cli/codex-home-process-lock' -vi.mock('../git/runner', () => ({ wslAwareSpawn: vi.fn() })) +vi.mock('../git/command-runner/wsl-aware-spawn', async (importOriginal) => ({ + ...(await importOriginal>()), + wslAwareSpawn: vi.fn() +})) afterEach(() => vi.unstubAllEnvs()) describe('command environment on WSL', () => { diff --git a/src/main/usage/usage-worktree-resolver.test.ts b/src/main/usage/usage-worktree-resolver.test.ts index e1a9cd2e378..b707090e606 100644 --- a/src/main/usage/usage-worktree-resolver.test.ts +++ b/src/main/usage/usage-worktree-resolver.test.ts @@ -1,12 +1,12 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' -import type * as WorktreePathComparison from '../git/worktree-path-comparison' +import type * as WorktreePathComparison from '../git/worktrees/catalog/worktree-path-comparison' import type { UsageScanWorktreeRef } from './usage-provider-contract' const { worktreePathComparisons } = vi.hoisted(() => ({ worktreePathComparisons: { count: 0 } })) -vi.mock('../git/worktree-path-comparison', async (importOriginal) => { +vi.mock('../git/worktrees/catalog/worktree-path-comparison', async (importOriginal) => { const actual = await importOriginal() return { ...actual, diff --git a/src/main/usage/usage-worktree-resolver.ts b/src/main/usage/usage-worktree-resolver.ts index fe34021e2d8..2a3e128d623 100644 --- a/src/main/usage/usage-worktree-resolver.ts +++ b/src/main/usage/usage-worktree-resolver.ts @@ -1,6 +1,6 @@ import { realpath } from 'node:fs/promises' import { posix, win32 } from 'node:path' -import { areWorktreePathsEqual } from '../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../git/worktrees/catalog/worktree-path-comparison' import { canonicalizeUsageWorktreePaths } from './usage-worktree-canonicalizer' import { looksLikeWindowsPath, normalizeFsPath } from './usage-path-comparison' import type { UsageScanWorktreeRef } from './usage-provider-contract' diff --git a/src/main/workspace-hooks/issue-command-file.ts b/src/main/workspace-hooks/issue-command-file.ts index 224e2e18e7f..0c62818d9a1 100644 --- a/src/main/workspace-hooks/issue-command-file.ts +++ b/src/main/workspace-hooks/issue-command-file.ts @@ -3,7 +3,7 @@ import { readFileSync, existsSync, mkdirSync, writeFileSync, rmSync } from 'node import { join } from 'node:path' import { loadHooks } from './hooks' import type { GitRuntimeOptions } from '../git/git-runtime-options' -import { checkIgnoredPaths } from '../git/check-ignored-paths' +import { checkIgnoredPaths } from '../git/source-control/check-ignored-paths' import { guardWslUncPathAccess, WslDistroStoppedError, diff --git a/src/main/workspace-hooks/issue-command-wsl-stopped-distro.test.ts b/src/main/workspace-hooks/issue-command-wsl-stopped-distro.test.ts index f4b67c768c4..1e627036ae7 100644 --- a/src/main/workspace-hooks/issue-command-wsl-stopped-distro.test.ts +++ b/src/main/workspace-hooks/issue-command-wsl-stopped-distro.test.ts @@ -23,7 +23,7 @@ vi.mock('node:fs', async (importOriginal) => ({ mkdirSync: mocks.mkdirSync, rmSync: mocks.rmSync })) -vi.mock('../git/check-ignored-paths', () => ({ +vi.mock('../git/source-control/check-ignored-paths', () => ({ checkIgnoredPaths: vi.fn(async () => new Set([''])) })) vi.mock('./hooks', () => ({ loadHooks: mocks.loadHooks })) diff --git a/src/main/workspace-hooks/worktree-runner-script.ts b/src/main/workspace-hooks/worktree-runner-script.ts index 59c77929026..2df8d189306 100644 --- a/src/main/workspace-hooks/worktree-runner-script.ts +++ b/src/main/workspace-hooks/worktree-runner-script.ts @@ -7,8 +7,8 @@ import { resolveWindowsShellStartupFamily } from '../../shared/windows-terminal- import { resolveWindowsGitBashShellPath } from '../pty/shell-startup/git-bash' import { gitExecFileSync } from '../git/command-runner/git-exec-file-sync' import { isLocalGitRuntimeRouterInstalled } from '../git/command-runner/local-git-runtime-route' -import { readWorktreeGitPath } from '../git/worktree-git-path' -import { resolveWslWorktreeGitPath } from '../git/wsl-worktree-git-path' +import { readWorktreeGitPath } from '../git/worktrees/catalog/worktree-git-path' +import { resolveWslWorktreeGitPath } from '../git/worktrees/catalog/wsl-worktree-git-path' import { knownWslAutomountRoots } from '../wsl/filesystem/wsl-automount-root' import { isWslPath } from '../wsl/filesystem/unc-path-access' import { toWindowsWslPath, toLinuxPath } from '../../shared/wsl-paths' diff --git a/src/main/workspaces/catalog/folder-upgrade-worktree-path.ts b/src/main/workspaces/catalog/folder-upgrade-worktree-path.ts index 66375979446..6516c5e224d 100644 --- a/src/main/workspaces/catalog/folder-upgrade-worktree-path.ts +++ b/src/main/workspaces/catalog/folder-upgrade-worktree-path.ts @@ -2,7 +2,10 @@ import { realpathSync } from 'node:fs' import type { Repo } from '../../../shared/repo-types' import type { GitWorktreeInfo } from '../../../shared/worktree/types' import { getRepoExecutionHostId, LOCAL_EXECUTION_HOST_ID } from '../../../shared/execution-host' -import { areWorktreePathsEqual, dedupeWorktreesByPath } from '../../git/worktree-path-comparison' +import { + areWorktreePathsEqual, + dedupeWorktreesByPath +} from '../../git/worktrees/catalog/worktree-path-comparison' function stillNamesRegisteredCheckout(repo: Repo, gitRoot: string): boolean { if (areWorktreePathsEqual(repo.path, gitRoot)) { diff --git a/src/main/workspaces/catalog/repo-maintenance-idle-gate.ts b/src/main/workspaces/catalog/repo-maintenance-idle-gate.ts index 3bc73311bc7..1d022caa576 100644 --- a/src/main/workspaces/catalog/repo-maintenance-idle-gate.ts +++ b/src/main/workspaces/catalog/repo-maintenance-idle-gate.ts @@ -3,7 +3,7 @@ import { disposeLocalRepoRefMaintenance, postponeRepoRefMaintenance, setRepoMaintenanceActivityProbe -} from '../../git/local-repo-ref-maintenance' +} from '../../git/refs/maintenance/local-repo-ref-maintenance' import { hasWorktreeRemovalsInFlight } from '../../ipc/worktrees/worktree-ipc-context' import { hasPendingWorktreeCreatePreparations } from '../creation/preparation/worktree-create-preparation' import { hasPendingWorktreeRemovals } from '../removal/worktree-removal-table' diff --git a/src/main/workspaces/catalog/repo-worktrees.test.ts b/src/main/workspaces/catalog/repo-worktrees.test.ts index 21190223c20..e2b17ade11c 100644 --- a/src/main/workspaces/catalog/repo-worktrees.test.ts +++ b/src/main/workspaces/catalog/repo-worktrees.test.ts @@ -1,5 +1,5 @@ -import type * as WorktreeScanCacheModule from '../../git/worktree-scan-cache' -import type * as WorktreeListingModule from '../../git/worktree-listing' +import type * as WorktreeScanCacheModule from '../../git/worktrees/catalog/worktree-scan-cache' +import type * as WorktreeListingModule from '../../git/worktrees/catalog/worktree-listing' import { beforeEach, describe, expect, it, vi } from 'vitest' const { listWorktreeGraphMock, listWorktreesMock, listWorktreesStrictMock } = vi.hoisted(() => ({ @@ -8,8 +8,8 @@ const { listWorktreeGraphMock, listWorktreesMock, listWorktreesStrictMock } = vi listWorktreesStrictMock: vi.fn() })) -vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => { + const facade = await getWorktreeOwnerMocks() return { ...(await importOriginal()), listWorktrees: facade.listWorktrees, @@ -18,20 +18,26 @@ vi.mock('../../git/worktree-scan-cache', async (importOriginal) => { } }) -vi.mock('../../git/worktree-listing', async (importOriginal) => { - const facade = await vi.importMock('../../git/worktree') +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => { + const facade = await getWorktreeOwnerMocks() return { ...(await importOriginal()), listWorktreesStrict: facade.listWorktreesStrict } }) -vi.mock('../../git/worktree', () => ({ - listWorktreeGraph: listWorktreeGraphMock, - listWorktrees: listWorktreesMock, - listWorktreesStrict: listWorktreesStrictMock, - listWorktreesSharedStrictAllowingTrueEmpty: listWorktreesStrictMock -})) +const { getWorktreeOwnerMocks } = vi.hoisted(() => { + function createWorktreeOwnerMocks() { + return (() => ({ + listWorktreeGraph: listWorktreeGraphMock, + listWorktrees: listWorktreesMock, + listWorktreesStrict: listWorktreesStrictMock, + listWorktreesSharedStrictAllowingTrueEmpty: listWorktreesStrictMock + }))() + } + let fixture: ReturnType | undefined + return { getWorktreeOwnerMocks: () => (fixture ??= createWorktreeOwnerMocks()) } +}) import { createFolderWorktree, diff --git a/src/main/workspaces/catalog/repo-worktrees.ts b/src/main/workspaces/catalog/repo-worktrees.ts index b1f70f43516..1918d0f7d55 100644 --- a/src/main/workspaces/catalog/repo-worktrees.ts +++ b/src/main/workspaces/catalog/repo-worktrees.ts @@ -5,12 +5,12 @@ import { listWorktreeGraph, listWorktrees, listWorktreesSharedStrictAllowingTrueEmpty -} from '../../git/worktree-scan-cache' -import { listWorktreesStrict } from '../../git/worktree-listing' +} from '../../git/worktrees/catalog/worktree-scan-cache' +import { listWorktreesStrict } from '../../git/worktrees/catalog/worktree-listing' import { isFolderRepo } from '../../../shared/repo-kind' import { getRepoExecutionHostId, LOCAL_EXECUTION_HOST_ID } from '../../../shared/execution-host' import { resolveGitRouteForHost } from '../../providers/execution-host-provider-dispatch' -import { areWorktreePathsEqual } from '../../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../../git/worktrees/catalog/worktree-path-comparison' import { WorktreeCatalogUnavailableError } from '../../../shared/worktree/worktree-catalog-availability' type LocalRepoWorktreeListOptions = { diff --git a/src/main/workspaces/catalog/worktree-lineage-host-peers.ts b/src/main/workspaces/catalog/worktree-lineage-host-peers.ts index 174532debfc..02454399cfe 100644 --- a/src/main/workspaces/catalog/worktree-lineage-host-peers.ts +++ b/src/main/workspaces/catalog/worktree-lineage-host-peers.ts @@ -8,7 +8,7 @@ import { projectResolvedWorktreeLineage } from '../../../shared/resolved-worktree-lineage' import { readAllWorktreeMetaForHost } from '../../persistence/host-qualified-worktree-meta' -import { areWorktreePathsEqual } from '../../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../../git/worktrees/catalog/worktree-path-comparison' import { mergeWorktree } from '../../ipc/worktree-metadata-merge' import { resolveRepoOwnershipEvidence } from '../../ipc/worktrees/listing/worktree-host-ownership' import { diff --git a/src/main/workspaces/catalog/worktree-path-comparison-key.ts b/src/main/workspaces/catalog/worktree-path-comparison-key.ts index fa9cea07901..0301653c45b 100644 --- a/src/main/workspaces/catalog/worktree-path-comparison-key.ts +++ b/src/main/workspaces/catalog/worktree-path-comparison-key.ts @@ -3,7 +3,7 @@ import { isWindowsAbsolutePathLike } from '../../../shared/cross-platform-path' import { canonicalWorktreePath, looksLikePosixAbsolutePath -} from '../../git/worktree-path-comparison' +} from '../../git/worktrees/catalog/worktree-path-comparison' /** Persisted namespace bytes are frozen, including WSL case folding; use areWorktreePathsEqual for equality. */ export function worktreePathComparisonKey(pathValue: string, platform = process.platform): string { diff --git a/src/main/workspaces/creation/preparation/worktree-create-preparation-cancellation.test.ts b/src/main/workspaces/creation/preparation/worktree-create-preparation-cancellation.test.ts index 400bd064142..c7ec6cc731c 100644 --- a/src/main/workspaces/creation/preparation/worktree-create-preparation-cancellation.test.ts +++ b/src/main/workspaces/creation/preparation/worktree-create-preparation-cancellation.test.ts @@ -20,21 +20,21 @@ const mocks = vi.hoisted(() => ({ })) vi.mock('node:fs/promises', () => ({ mkdir: mocks.mkdir })) -vi.mock('../../../git/worktree', () => ({ listWorktreeGraph: mocks.listWorktreeGraph })) -vi.mock('../../../git/worktree-scan-cache', async (importOriginal) => ({ + +vi.mock('../../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ ...(await importOriginal>()), listWorktreeGraph: mocks.listWorktreeGraph })) -vi.mock('../../../git/worktree-create-preparation', () => ({ +vi.mock('../../../git/worktrees/creation/worktree-create-preparation', () => ({ prepareWorktreeCreateCheckout: mocks.prepareCheckout, finalizePreparedWorktree: mocks.finalize, discardPreparedWorktree: mocks.discard, unlockPreparedWorktree: mocks.unlock })) -vi.mock('../../../git/worktree-base-ref-probe', () => ({ +vi.mock('../../../git/worktrees/creation/worktree-base-ref-probe', () => ({ resolveLocalWorktreeBaseRef: mocks.resolveBaseRef })) -vi.mock('../../../git/worktree-base-divergence', () => ({ +vi.mock('../../../git/worktrees/creation/worktree-base-divergence', () => ({ measureRetargetDivergence: mocks.measureDivergence })) vi.mock('../../execution-host/project-runtime-git-options', () => ({ diff --git a/src/main/workspaces/creation/preparation/worktree-create-preparation-contention.test.ts b/src/main/workspaces/creation/preparation/worktree-create-preparation-contention.test.ts index ad7f68e982c..3de778f72f8 100644 --- a/src/main/workspaces/creation/preparation/worktree-create-preparation-contention.test.ts +++ b/src/main/workspaces/creation/preparation/worktree-create-preparation-contention.test.ts @@ -1,7 +1,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { Store } from '../../../persistence/loading-store/store' import type { Repo } from '../../../../shared/repo-types' -import type { AddWorktreeResult } from '../../../git/worktree-operation-options' +import type { AddWorktreeResult } from '../../../git/worktrees/worktree-operation-options' const mocks = vi.hoisted(() => ({ mkdir: vi.fn(), @@ -16,21 +16,21 @@ const mocks = vi.hoisted(() => ({ })) vi.mock('node:fs/promises', () => ({ mkdir: mocks.mkdir })) -vi.mock('../../../git/worktree', () => ({ listWorktreeGraph: mocks.listWorktreeGraph })) -vi.mock('../../../git/worktree-scan-cache', async (importOriginal) => ({ + +vi.mock('../../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ ...(await importOriginal>()), listWorktreeGraph: mocks.listWorktreeGraph })) -vi.mock('../../../git/worktree-create-preparation', () => ({ +vi.mock('../../../git/worktrees/creation/worktree-create-preparation', () => ({ prepareWorktreeCreateCheckout: mocks.prepare, finalizePreparedWorktree: mocks.finalize, discardPreparedWorktree: mocks.discard, unlockPreparedWorktree: vi.fn() })) -vi.mock('../../../git/worktree-base-ref-probe', () => ({ +vi.mock('../../../git/worktrees/creation/worktree-base-ref-probe', () => ({ resolveLocalWorktreeBaseRef: mocks.resolveBaseRef })) -vi.mock('../../../git/worktree-base-divergence', () => ({ +vi.mock('../../../git/worktrees/creation/worktree-base-divergence', () => ({ measureRetargetDivergence: mocks.measureDivergence })) vi.mock('../../execution-host/project-runtime-git-options', () => ({ diff --git a/src/main/workspaces/creation/preparation/worktree-create-preparation-pool.ts b/src/main/workspaces/creation/preparation/worktree-create-preparation-pool.ts index 55ce27ab6a0..a9c1de5e7c5 100644 --- a/src/main/workspaces/creation/preparation/worktree-create-preparation-pool.ts +++ b/src/main/workspaces/creation/preparation/worktree-create-preparation-pool.ts @@ -1,4 +1,4 @@ -import { worktreePreparationGit } from '../../../git/worktree-create-git-executor' +import { worktreePreparationGit } from '../../../git/worktrees/creation/worktree-create-git-executor' import { randomUUID } from 'node:crypto' import { mkdir } from 'node:fs/promises' import { posix, win32 } from 'node:path' @@ -7,9 +7,9 @@ import { WORKTREE_CREATE_PREPARATION_DIRECTORY, createWorktreePreparationLockReason } from '../../../../shared/worktree/create-preparation' -import type { AddWorktreeOptions } from '../../../git/worktree-operation-options' -import { prepareWorktreeCreateCheckout } from '../../../git/worktree-create-preparation' -import { WorktreePreparationLockOwnershipError } from '../../../git/worktree-preparation-lock' +import type { AddWorktreeOptions } from '../../../git/worktrees/worktree-operation-options' +import { prepareWorktreeCreateCheckout } from '../../../git/worktrees/creation/worktree-create-preparation' +import { WorktreePreparationLockOwnershipError } from '../../../git/worktrees/creation/worktree-preparation-lock' import { queuePreparedWorktreeTipRefresh } from './worktree-preparation-refresh-queue' import { toHostFilesystemPath } from '../../../filesystem/host-tree-removal' import { createPreparationActivity } from './worktree-create-preparation-activity' diff --git a/src/main/workspaces/creation/preparation/worktree-create-preparation-reservation.ts b/src/main/workspaces/creation/preparation/worktree-create-preparation-reservation.ts index d734278fcaf..d5f320a03ed 100644 --- a/src/main/workspaces/creation/preparation/worktree-create-preparation-reservation.ts +++ b/src/main/workspaces/creation/preparation/worktree-create-preparation-reservation.ts @@ -1,7 +1,7 @@ import type { PreparedCheckoutMissReason } from '../../../../shared/worktree/create-timing-vocabulary' -import type { AddWorktreeOptions } from '../../../git/worktree-operation-options' -import { measureRetargetDivergence } from '../../../git/worktree-base-divergence' -import { resolveLocalWorktreeBaseRef } from '../../../git/worktree-base-ref-probe' +import type { AddWorktreeOptions } from '../../../git/worktrees/worktree-operation-options' +import { measureRetargetDivergence } from '../../../git/worktrees/creation/worktree-base-divergence' +import { resolveLocalWorktreeBaseRef } from '../../../git/worktrees/creation/worktree-base-ref-probe' import { preparationPathKey, selectPreparationForCreate } from './worktree-create-preparation-claim' import { listPreparations, diff --git a/src/main/workspaces/creation/preparation/worktree-create-preparation-stale-cleanup.ts b/src/main/workspaces/creation/preparation/worktree-create-preparation-stale-cleanup.ts index 0eaafca83a8..7ac8fea5ffa 100644 --- a/src/main/workspaces/creation/preparation/worktree-create-preparation-stale-cleanup.ts +++ b/src/main/workspaces/creation/preparation/worktree-create-preparation-stale-cleanup.ts @@ -6,12 +6,12 @@ import { } from '../../../../shared/worktree/create-preparation' import { orcadDataRootIsOnLocalDisk } from '../../../orcad/orcad-data-root-locality' import { profileStateAccessMachineIdentity } from '../../../persistence/profile-state/profile-state-access-identity' -import type { AddWorktreeOptions } from '../../../git/worktree-operation-options' -import { listWorktreeGraph } from '../../../git/worktree-scan-cache' +import type { AddWorktreeOptions } from '../../../git/worktrees/worktree-operation-options' +import { listWorktreeGraph } from '../../../git/worktrees/catalog/worktree-scan-cache' import { discardPreparedWorktree, unlockPreparedWorktree -} from '../../../git/worktree-create-preparation' +} from '../../../git/worktrees/creation/worktree-create-preparation' import { retryPendingPreparationDiscards } from './worktree-preparation-discard-retry' const STALE_PREPARATION_CLEANUP_CONCURRENCY = 4 diff --git a/src/main/workspaces/creation/preparation/worktree-create-preparation-timing.test.ts b/src/main/workspaces/creation/preparation/worktree-create-preparation-timing.test.ts index f6d643c45f9..d5a819cc4c3 100644 --- a/src/main/workspaces/creation/preparation/worktree-create-preparation-timing.test.ts +++ b/src/main/workspaces/creation/preparation/worktree-create-preparation-timing.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' -import type { AddWorktreeResult } from '../../../git/worktree-operation-options' +import type { AddWorktreeResult } from '../../../git/worktrees/worktree-operation-options' const mocks = vi.hoisted(() => ({ mkdir: vi.fn(), @@ -11,21 +11,23 @@ const mocks = vi.hoisted(() => ({ })) vi.mock('node:fs/promises', () => ({ mkdir: mocks.mkdir })) -vi.mock('../../../git/worktree', () => ({ listWorktreeGraph: mocks.listWorktreeGraph })) -vi.mock('../../../git/worktree-scan-cache', async (importOriginal) => ({ + +vi.mock('../../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ ...(await importOriginal>()), listWorktreeGraph: mocks.listWorktreeGraph })) -vi.mock('../../../git/worktree-create-preparation', () => ({ +vi.mock('../../../git/worktrees/creation/worktree-create-preparation', () => ({ prepareWorktreeCreateCheckout: mocks.prepare, finalizePreparedWorktree: mocks.finalize, discardPreparedWorktree: mocks.discard, unlockPreparedWorktree: vi.fn() })) -vi.mock('../../../git/worktree-base-ref-probe', () => ({ +vi.mock('../../../git/worktrees/creation/worktree-base-ref-probe', () => ({ resolveLocalWorktreeBaseRef: mocks.resolveBaseRef })) -vi.mock('../../../git/worktree-base-divergence', () => ({ measureRetargetDivergence: vi.fn() })) +vi.mock('../../../git/worktrees/creation/worktree-base-divergence', () => ({ + measureRetargetDivergence: vi.fn() +})) vi.mock('../../execution-host/project-runtime-git-options', () => ({ getLocalProjectWorktreeGitOptions: vi.fn(), getWorktreeMirrorDistro: vi.fn() diff --git a/src/main/workspaces/creation/preparation/worktree-create-preparation-wsl-root.test.ts b/src/main/workspaces/creation/preparation/worktree-create-preparation-wsl-root.test.ts index 362703ac379..6011bf4860e 100644 --- a/src/main/workspaces/creation/preparation/worktree-create-preparation-wsl-root.test.ts +++ b/src/main/workspaces/creation/preparation/worktree-create-preparation-wsl-root.test.ts @@ -19,18 +19,18 @@ const mocks = vi.hoisted(() => ({ })) vi.mock('node:fs/promises', () => ({ mkdir: mocks.mkdir })) -vi.mock('../../../git/worktree', () => ({ listWorktreeGraph: mocks.listWorktreeGraph })) -vi.mock('../../../git/worktree-scan-cache', async (importOriginal) => ({ + +vi.mock('../../../git/worktrees/catalog/worktree-scan-cache', async (importOriginal) => ({ ...(await importOriginal>()), listWorktreeGraph: mocks.listWorktreeGraph })) -vi.mock('../../../git/worktree-create-preparation', () => ({ +vi.mock('../../../git/worktrees/creation/worktree-create-preparation', () => ({ prepareWorktreeCreateCheckout: mocks.prepareCheckout, finalizePreparedWorktree: mocks.finalize, discardPreparedWorktree: mocks.discard, unlockPreparedWorktree: mocks.unlock })) -vi.mock('../../../git/worktree-base-ref-probe', () => ({ +vi.mock('../../../git/worktrees/creation/worktree-base-ref-probe', () => ({ resolveLocalWorktreeBaseRef: mocks.resolveBaseRef })) vi.mock('../../execution-host/project-runtime-git-options', () => ({ diff --git a/src/main/workspaces/creation/preparation/worktree-create-preparation.test.ts b/src/main/workspaces/creation/preparation/worktree-create-preparation.test.ts index 011073c1b8c..05168b334ff 100644 --- a/src/main/workspaces/creation/preparation/worktree-create-preparation.test.ts +++ b/src/main/workspaces/creation/preparation/worktree-create-preparation.test.ts @@ -8,7 +8,7 @@ import { describe, expect, it } from 'vitest' import type { Repo } from '../../../../shared/repo-types' import { hasPendingStalePreparationCleanup } from './worktree-create-preparation-stale-cleanup' import { WORKTREE_CREATE_PREPARATION_DIRECTORY } from '../../../../shared/worktree/create-preparation' -import { WorktreePreparationLockOwnershipError } from '../../../git/worktree-preparation-lock' +import { WorktreePreparationLockOwnershipError } from '../../../git/worktrees/creation/worktree-preparation-lock' import { _resetWorktreeCreatePreparationsForTests, consumePreparedWorktreeCreate, diff --git a/src/main/workspaces/creation/preparation/worktree-create-preparation.ts b/src/main/workspaces/creation/preparation/worktree-create-preparation.ts index ad7ddafddef..0a15b13a51d 100644 --- a/src/main/workspaces/creation/preparation/worktree-create-preparation.ts +++ b/src/main/workspaces/creation/preparation/worktree-create-preparation.ts @@ -1,4 +1,4 @@ -import { worktreePreparationGit } from '../../../git/worktree-create-git-executor' +import { worktreePreparationGit } from '../../../git/worktrees/creation/worktree-create-git-executor' import { mkdir } from 'node:fs/promises' import { posix, win32 } from 'node:path' import type { ProjectRuntimeResolutionStore } from '../../execution-host/local-project-runtime-resolution' @@ -11,8 +11,11 @@ import type { PreparedCheckoutReset, WorktreeCreatePhase } from '../../../../shared/worktree/create-timing-vocabulary' -import type { AddWorktreeOptions, AddWorktreeResult } from '../../../git/worktree-operation-options' -import { WorktreePreparationLockOwnershipError } from '../../../git/worktree-preparation-lock' +import type { + AddWorktreeOptions, + AddWorktreeResult +} from '../../../git/worktrees/worktree-operation-options' +import { WorktreePreparationLockOwnershipError } from '../../../git/worktrees/creation/worktree-preparation-lock' import { _resetPreparationPoolForTests, hasPendingPreparations, @@ -32,7 +35,7 @@ import { import { discardPreparedWorktree, finalizePreparedWorktree -} from '../../../git/worktree-create-preparation' +} from '../../../git/worktrees/creation/worktree-create-preparation' import { getLocalProjectWorktreeGitOptions, getWorktreeMirrorDistro diff --git a/src/main/workspaces/creation/preparation/worktree-preparation-discard-retry.ts b/src/main/workspaces/creation/preparation/worktree-preparation-discard-retry.ts index 775f3a89cb0..165954b70f0 100644 --- a/src/main/workspaces/creation/preparation/worktree-preparation-discard-retry.ts +++ b/src/main/workspaces/creation/preparation/worktree-preparation-discard-retry.ts @@ -1,6 +1,6 @@ -import type { AddWorktreeOptions } from '../../../git/worktree-operation-options' -import { discardPreparedWorktree } from '../../../git/worktree-create-preparation' -import { WorktreePreparationLockOwnershipError } from '../../../git/worktree-preparation-lock' +import type { AddWorktreeOptions } from '../../../git/worktrees/worktree-operation-options' +import { discardPreparedWorktree } from '../../../git/worktrees/creation/worktree-create-preparation' +import { WorktreePreparationLockOwnershipError } from '../../../git/worktrees/creation/worktree-preparation-lock' import { isOrphanedWorktreeError } from '../../../ipc/worktree-logic' import { trackPreparationWork } from '../worktree-create-concurrency' import type { PreparationEntry } from './worktree-create-preparation-pool' diff --git a/src/main/workspaces/creation/preparation/worktree-preparation-refresh-queue.ts b/src/main/workspaces/creation/preparation/worktree-preparation-refresh-queue.ts index 94beb43dd33..9858fd05531 100644 --- a/src/main/workspaces/creation/preparation/worktree-preparation-refresh-queue.ts +++ b/src/main/workspaces/creation/preparation/worktree-preparation-refresh-queue.ts @@ -1,6 +1,6 @@ -import { worktreePreparationGit } from '../../../git/worktree-create-git-executor' -import { refreshPreparedWorktreeTip } from '../../../git/worktree-preparation-tip-refresh' -import { WorktreePreparationLockOwnershipError } from '../../../git/worktree-preparation-lock' +import { worktreePreparationGit } from '../../../git/worktrees/creation/worktree-create-git-executor' +import { refreshPreparedWorktreeTip } from '../../../git/worktrees/creation/worktree-preparation-tip-refresh' +import { WorktreePreparationLockOwnershipError } from '../../../git/worktrees/creation/worktree-preparation-lock' import type { PreparationEntry } from './worktree-create-preparation-pool' import { waitForPromiseWithSignal } from '../../../../shared/abort-signal-reason' diff --git a/src/main/workspaces/creation/preparation/worktree-preparation-tip-refresh.test.ts b/src/main/workspaces/creation/preparation/worktree-preparation-tip-refresh.test.ts index c109db6e90a..63722791ce6 100644 --- a/src/main/workspaces/creation/preparation/worktree-preparation-tip-refresh.test.ts +++ b/src/main/workspaces/creation/preparation/worktree-preparation-tip-refresh.test.ts @@ -5,7 +5,7 @@ import { repo, store } from '../../../__mocks__/worktree-create-preparation' -import { WorktreePreparationLockOwnershipError } from '../../../git/worktree-preparation-lock' +import { WorktreePreparationLockOwnershipError } from '../../../git/worktrees/creation/worktree-preparation-lock' import { consumePreparedWorktreeCreate, prepareWorktreeCreateForRepo diff --git a/src/main/workspaces/creation/workspace-create-event-fields.ts b/src/main/workspaces/creation/workspace-create-event-fields.ts index d7b12c931b4..5a2330a16f9 100644 --- a/src/main/workspaces/creation/workspace-create-event-fields.ts +++ b/src/main/workspaces/creation/workspace-create-event-fields.ts @@ -13,7 +13,7 @@ import type { } from '../../../shared/telemetry-workspace-create-schemas' import type { WorktreeCreateTimingRecorder } from './worktree-create-timing' import type { WorktreeCreateConcurrency } from './worktree-create-concurrency' -import type { CreateEventRepoFacts } from '../../git/create-event-repo-probe' +import type { CreateEventRepoFacts } from '../../git/worktrees/creation/create-event-repo-probe' import { worktreeCreateUnattributedMs } from '../../observability/instrumentation' type OptionalEventFields

> = { [K in keyof P]?: z.infer } diff --git a/src/main/workspaces/creation/workspace-create-telemetry.ts b/src/main/workspaces/creation/workspace-create-telemetry.ts index 7bd8106e29e..3ef852c43df 100644 --- a/src/main/workspaces/creation/workspace-create-telemetry.ts +++ b/src/main/workspaces/creation/workspace-create-telemetry.ts @@ -6,7 +6,7 @@ import type { WorkspaceSource } from '../../../shared/workspace-source' import { isTelemetryEnabled, track } from '../../telemetry/client' import { getCohortAtEmit } from '../../telemetry/cohort-classifier' import { classifyWorkspaceCreateError } from '../../ipc/workspace-create-error-classifier' -import { probeCreateEventRepoFacts } from '../../git/create-event-repo-probe' +import { probeCreateEventRepoFacts } from '../../git/worktrees/creation/create-event-repo-probe' import { createWorktreeCreateTimingRecorder, type WorktreeCreateTimingRecorder diff --git a/src/main/workspaces/creation/worktree-create-base-prefetch.test.ts b/src/main/workspaces/creation/worktree-create-base-prefetch.test.ts index b7f083d240f..0807bc35eb0 100644 --- a/src/main/workspaces/creation/worktree-create-base-prefetch.test.ts +++ b/src/main/workspaces/creation/worktree-create-base-prefetch.test.ts @@ -10,7 +10,10 @@ const mocks = vi.hoisted(() => ({ })) vi.mock('../../git/repo-default-base-ref', () => ({ getBaseRefDefault: mocks.getBaseRefDefault })) -vi.mock('../../git/runner', () => ({ gitExecFileAsync: mocks.gitExecFileAsync })) +vi.mock('../../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), + gitExecFileAsync: mocks.gitExecFileAsync +})) import { prefetchWorktreeCreateBase } from './worktree-create-base-prefetch' diff --git a/src/main/workspaces/creation/worktree-create-base-prefetch.ts b/src/main/workspaces/creation/worktree-create-base-prefetch.ts index fd2b3493e7c..37cf86b4ea9 100644 --- a/src/main/workspaces/creation/worktree-create-base-prefetch.ts +++ b/src/main/workspaces/creation/worktree-create-base-prefetch.ts @@ -1,7 +1,7 @@ import { isFolderRepo } from '../../../shared/repo-kind' import type { Repo } from '../../../shared/repo-types' import { isFullGitObjectId } from '../../git/commit-object-ref' -import { hasLocalWorktreeBaseRef } from '../../git/worktree-base-ref-probe' +import { hasLocalWorktreeBaseRef } from '../../git/worktrees/creation/worktree-base-ref-probe' import { getBaseRefDefault } from '../../git/repo-default-base-ref' import { resolveWorktreeCreateBase } from './worktree-create-base' diff --git a/src/main/workspaces/creation/worktree-create-in-flight.ts b/src/main/workspaces/creation/worktree-create-in-flight.ts index 0277bc54401..30c7d15c324 100644 --- a/src/main/workspaces/creation/worktree-create-in-flight.ts +++ b/src/main/workspaces/creation/worktree-create-in-flight.ts @@ -1,7 +1,7 @@ import { realpath } from 'node:fs/promises' import { basename, dirname, resolve } from 'node:path' import { toWindowsWslPath } from '../../../shared/wsl-paths' -import { areWorktreePathsEqual } from '../../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../../git/worktrees/catalog/worktree-path-comparison' type InFlightWorktreeCreate = { repoId: string; paths: string[] } diff --git a/src/main/workspaces/removal/local-worktree-removal-recovery.test.ts b/src/main/workspaces/removal/local-worktree-removal-recovery.test.ts index c6f51f1bfb0..a5b42a2e84a 100644 --- a/src/main/workspaces/removal/local-worktree-removal-recovery.test.ts +++ b/src/main/workspaces/removal/local-worktree-removal-recovery.test.ts @@ -9,7 +9,8 @@ const { gitExecFileAsyncMock, listWorktreesStrictMock, removeLocalWorktreePathMo hostRmMock: vi.fn() })) -vi.mock('../../git/runner', () => ({ +vi.mock('../../git/command-runner/git-exec-file', async (importOriginal) => ({ + ...(await importOriginal>()), gitExecFileAsync: gitExecFileAsyncMock })) @@ -19,10 +20,7 @@ vi.mock('./local-worktree-filesystem', () => ({ vi.mock('../../filesystem/asar-transparent-fs', () => ({ rm: hostRmMock })) -vi.mock('../../git/worktree', () => ({ - listWorktreesStrict: listWorktreesStrictMock -})) -vi.mock('../../git/worktree-listing', async (importOriginal) => ({ +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ ...(await importOriginal>()), listWorktreesStrict: listWorktreesStrictMock })) diff --git a/src/main/workspaces/removal/local-worktree-removal-recovery.ts b/src/main/workspaces/removal/local-worktree-removal-recovery.ts index 68ea6961b38..783c00a2405 100644 --- a/src/main/workspaces/removal/local-worktree-removal-recovery.ts +++ b/src/main/workspaces/removal/local-worktree-removal-recovery.ts @@ -1,15 +1,15 @@ import type { RemoveWorktreeResult } from '../../../shared/worktree/create-types' -import { pruneGitWorktrees } from '../../git/worktree-prune-guard' +import { pruneGitWorktrees } from '../../git/worktrees/removal/worktree-prune-guard' import type { GitWorktreeInfo } from '../../../shared/worktree/types' import { assertWorktreeUnlockedForRemoval } from '../../../shared/worktree/removal' -import { areWorktreePathsEqual } from '../../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../../git/worktrees/catalog/worktree-path-comparison' import { formatWorktreeRemovalError, isOrphanedWorktreeError } from '../../ipc/worktree-logic' -import { listWorktreesStrict } from '../../git/worktree-listing' +import { listWorktreesStrict } from '../../git/worktrees/catalog/worktree-listing' import { normalizeLocalBranchRef, type GitWorktreeExecOptions -} from '../../git/worktree-operation-options' -import { deleteBranchOfUnregisteredWorktree } from '../../git/worktree-removal' +} from '../../git/worktrees/worktree-operation-options' +import { deleteBranchOfUnregisteredWorktree } from '../../git/worktrees/removal/worktree-removal' import { removeLocalWorktreePath } from './local-worktree-filesystem' import { assertWorktreeDoesNotContainRegisteredWorktree } from './worktree-removal-safety' diff --git a/src/main/workspaces/removal/nested-worktree-removal-plan.ts b/src/main/workspaces/removal/nested-worktree-removal-plan.ts index b1f854fd588..d74f6814a0b 100644 --- a/src/main/workspaces/removal/nested-worktree-removal-plan.ts +++ b/src/main/workspaces/removal/nested-worktree-removal-plan.ts @@ -1,7 +1,7 @@ import type { GitWorktreeInfo } from '../../../shared/worktree/types' import type { NestedWorktreeRemovalApproval } from '../../../shared/worktree/nested-removal' import { assertWorktreeUnlockedForRemoval } from '../../../shared/worktree/removal' -import { areWorktreePathsEqual } from '../../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../../git/worktrees/catalog/worktree-path-comparison' import { containsPath, getPathOps, diff --git a/src/main/workspaces/removal/worktree-background-removal.ts b/src/main/workspaces/removal/worktree-background-removal.ts index d7b65befb94..bc32538497b 100644 --- a/src/main/workspaces/removal/worktree-background-removal.ts +++ b/src/main/workspaces/removal/worktree-background-removal.ts @@ -1,7 +1,7 @@ import { LOCAL_EXECUTION_HOST_ID, type ExecutionHostId } from '../../../shared/execution-host' import type { RemoveWorktreeResult } from '../../../shared/worktree/create-types' import type { GitWorktreeInfo } from '../../../shared/worktree/types' -import { normalizeLocalBranchRef } from '../../git/worktree-operation-options' +import { normalizeLocalBranchRef } from '../../git/worktrees/worktree-operation-options' import { acquireWatcherRemovalGate, type WatcherRemovalGate } from '../../ipc/watcher-removal-gate' import { runWorktreeChangeInvalidators } from '../../ipc/worktree-change-invalidators' import { parseWslPath } from '../../wsl/filesystem/unc-path-access' diff --git a/src/main/workspaces/removal/worktree-failed-removal.test.ts b/src/main/workspaces/removal/worktree-failed-removal.test.ts index be6d78afc12..0c164de7495 100644 --- a/src/main/workspaces/removal/worktree-failed-removal.test.ts +++ b/src/main/workspaces/removal/worktree-failed-removal.test.ts @@ -4,9 +4,9 @@ import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import type { GitWorktreeInfo } from '../../../shared/worktree/types' -import { listWorktreesStrict } from '../../git/worktree-listing' -import type * as WorktreeRemovalModule from '../../git/worktree-removal' -import { deleteBranchOfUnregisteredWorktree } from '../../git/worktree-removal' +import { listWorktreesStrict } from '../../git/worktrees/catalog/worktree-listing' +import type * as WorktreeRemovalModule from '../../git/worktrees/removal/worktree-removal' +import { deleteBranchOfUnregisteredWorktree } from '../../git/worktrees/removal/worktree-removal' import { beginTerminalInstall } from '../../ipc/watcher-removal-gate' import { formatWorktreeRemovalError } from '../../ipc/worktree-logic' import { registerWorktreeChangeInvalidator } from '../../ipc/worktree-change-invalidators' @@ -29,12 +29,12 @@ import { readWorktreeRemovalRecords } from './worktree-removal-records' import { loadWorktreeRemovalRecordsForStore } from '../../startup/worktree-removal-records-load' const listWorktreesStrictMock = vi.hoisted(() => vi.fn(async () => [])) -vi.mock('../../git/worktree', () => ({ listWorktreesStrict: listWorktreesStrictMock })) -vi.mock('../../git/worktree-listing', async (importOriginal) => ({ + +vi.mock('../../git/worktrees/catalog/worktree-listing', async (importOriginal) => ({ ...(await importOriginal>()), listWorktreesStrict: listWorktreesStrictMock })) -vi.mock('../../git/worktree-removal', async (importOriginal) => ({ +vi.mock('../../git/worktrees/removal/worktree-removal', async (importOriginal) => ({ ...(await importOriginal()), deleteBranchOfUnregisteredWorktree: vi.fn(async () => ({})) })) diff --git a/src/main/workspaces/removal/worktree-removal-failure.ts b/src/main/workspaces/removal/worktree-removal-failure.ts index 29bcf45b283..0aea6fbd3f2 100644 --- a/src/main/workspaces/removal/worktree-removal-failure.ts +++ b/src/main/workspaces/removal/worktree-removal-failure.ts @@ -1,4 +1,4 @@ -import { deleteBranchOfUnregisteredWorktree } from '../../git/worktree-removal' +import { deleteBranchOfUnregisteredWorktree } from '../../git/worktrees/removal/worktree-removal' import { isRecordedCheckout, registeredRemovalCheckout, diff --git a/src/main/workspaces/removal/worktree-removal-leftover.ts b/src/main/workspaces/removal/worktree-removal-leftover.ts index 82175f2fe8a..3ec38498863 100644 --- a/src/main/workspaces/removal/worktree-removal-leftover.ts +++ b/src/main/workspaces/removal/worktree-removal-leftover.ts @@ -1,14 +1,17 @@ import { unregisteredFolderRefusal } from '../../../shared/worktree/removal' -import { usesNativeWindowsRemoval } from '../../git/windows-worktree-removal' +import { usesNativeWindowsRemoval } from '../../git/worktrees/removal/windows-worktree-removal' import type { LocalProjectWorktreeGitOptions } from '../execution-host/project-runtime-git-options' import { lstat } from 'node:fs/promises' import { join } from 'node:path' import type { RemoveWorktreeResult } from '../../../shared/worktree/create-types' import type { GitWorktreeInfo } from '../../../shared/worktree/types' -import { listWorktreesStrict } from '../../git/worktree-listing' -import { getErrorCode, normalizeLocalBranchRef } from '../../git/worktree-operation-options' +import { listWorktreesStrict } from '../../git/worktrees/catalog/worktree-listing' +import { + getErrorCode, + normalizeLocalBranchRef +} from '../../git/worktrees/worktree-operation-options' import type { WorktreeRemovalRecord } from './worktree-removal-records' -import { areWorktreePathsEqual } from '../../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../../git/worktrees/catalog/worktree-path-comparison' import { CLIENT_REMOVAL_HOME } from './worktree-removal-home-guard' import { failedWorktreeRemovals, worktreeCheckoutExists } from './worktree-removal-table' import { diff --git a/src/main/workspaces/removal/worktree-removal-listing.ts b/src/main/workspaces/removal/worktree-removal-listing.ts index 2899d5f1c06..6ff79174512 100644 --- a/src/main/workspaces/removal/worktree-removal-listing.ts +++ b/src/main/workspaces/removal/worktree-removal-listing.ts @@ -1,6 +1,9 @@ import { LOCAL_EXECUTION_HOST_ID, type ExecutionHostId } from '../../../shared/execution-host' import type { GitWorktreeInfo } from '../../../shared/worktree/types' -import { areWorktreePathsEqual, canonicalWorktreePath } from '../../git/worktree-path-comparison' +import { + areWorktreePathsEqual, + canonicalWorktreePath +} from '../../git/worktrees/catalog/worktree-path-comparison' import { isRecordedCheckout, isUnregisteredRemovalLeftover } from './worktree-removal-leftover' import type { WorktreeRemovalRecord } from './worktree-removal-records' import { diff --git a/src/main/workspaces/removal/worktree-removal-safety.ts b/src/main/workspaces/removal/worktree-removal-safety.ts index f0269a09186..accbeb8cf4e 100644 --- a/src/main/workspaces/removal/worktree-removal-safety.ts +++ b/src/main/workspaces/removal/worktree-removal-safety.ts @@ -2,7 +2,7 @@ import { lstat, stat, readFile, realpath } from 'node:fs/promises' import type { WorktreeMeta } from '../../../shared/worktree/meta-types' import type { GitWorktreeInfo } from '../../../shared/worktree/types' import { NESTED_WORKTREE_REMOVAL_PREFIX } from '../../../shared/worktree/nested-removal' -import { areWorktreePathsEqual } from '../../git/worktree-path-comparison' +import { areWorktreePathsEqual } from '../../git/worktrees/catalog/worktree-path-comparison' import { containsPath, getPathOps, diff --git a/src/main/workspaces/removal/worktree-removal-table.ts b/src/main/workspaces/removal/worktree-removal-table.ts index e3fcf127662..069bfea06df 100644 --- a/src/main/workspaces/removal/worktree-removal-table.ts +++ b/src/main/workspaces/removal/worktree-removal-table.ts @@ -1,6 +1,6 @@ import { lstat } from 'node:fs/promises' -import { getErrorCode } from '../../git/worktree-operation-options' -import { areWorktreePathsEqual } from '../../git/worktree-path-comparison' +import { getErrorCode } from '../../git/worktrees/worktree-operation-options' +import { areWorktreePathsEqual } from '../../git/worktrees/catalog/worktree-path-comparison' import { writeWorktreeRemovalRecords, type WorktreeRemovalRecord } from './worktree-removal-records' export const pendingWorktreeRemovals = new Map() diff --git a/src/main/wsl/filesystem/wsl-drive-project-new-default.ts b/src/main/wsl/filesystem/wsl-drive-project-new-default.ts index 79971f7305e..ac32b6214d3 100644 --- a/src/main/wsl/filesystem/wsl-drive-project-new-default.ts +++ b/src/main/wsl/filesystem/wsl-drive-project-new-default.ts @@ -14,7 +14,7 @@ import type { GlobalSettings } from '../../../shared/global-settings-types' import type { Project } from '../../../shared/project-types' import { isFolderRepo } from '../../../shared/repo-kind' import type { Repo } from '../../../shared/repo-types' -import { isForeignLink } from '../../git/worktree-prune-guard' +import { isForeignLink } from '../../git/worktrees/removal/worktree-prune-guard' import { wslHostsOptedIn } from '../host-lifecycle/wsl-host-gate' export type NewWindowsDriveProjectDefaultArgs = { diff --git a/src/main/wsl/filesystem/wsl-drive-project-windows-git.ts b/src/main/wsl/filesystem/wsl-drive-project-windows-git.ts index f28639e68ce..8a00c3ec647 100644 --- a/src/main/wsl/filesystem/wsl-drive-project-windows-git.ts +++ b/src/main/wsl/filesystem/wsl-drive-project-windows-git.ts @@ -10,7 +10,7 @@ import type { Project } from '../../../shared/project-types' import type { Repo } from '../../../shared/repo-types' import { isFolderRepo } from '../../../shared/repo-kind' import { isWslUncPath } from '../../../shared/wsl-paths' -import { isForeignLink } from '../../git/worktree-prune-guard' +import { isForeignLink } from '../../git/worktrees/removal/worktree-prune-guard' import type { WslDriveProjectConversionResult, WslDriveProjectPreview diff --git a/src/renderer/src/components/github-item-dialog/load-item-details/work-item-details-target-contract.test.tsx b/src/renderer/src/components/github-item-dialog/load-item-details/work-item-details-target-contract.test.tsx index 9f992dc8ffa..32d339f9e16 100644 --- a/src/renderer/src/components/github-item-dialog/load-item-details/work-item-details-target-contract.test.tsx +++ b/src/renderer/src/components/github-item-dialog/load-item-details/work-item-details-target-contract.test.tsx @@ -1,4 +1,4 @@ -import type * as GitRunner from '../../../../../main/git/runner' +import type * as GitRunner from '../../../../../main/git/command-runner/gh-exec-file' import type { GitHubRepoContext } from '../../../../../main/github/github-repository-identity' import type { PRComment } from '../../../../../shared/github/comment-types' // @vitest-environment happy-dom @@ -89,7 +89,7 @@ const io = vi.hoisted(() => { unexpected: new Array() } }) -vi.mock('../../../../../main/git/runner', async (original) => ({ +vi.mock('../../../../../main/git/command-runner/gh-exec-file', async (original) => ({ ...(await original()), ghExecFileAsync: io.gh })) @@ -115,7 +115,7 @@ vi.mock('../../../../../main/github/github-enterprise-repository', () => ({ isGitHubHostAuthenticated: async () => true, isGitHubHostAuthenticatedForGlobalCli: async () => true })) -vi.mock('../../../../../main/git/remote-name-listing', () => ({ +vi.mock('../../../../../main/git/remotes/remote-name-listing', () => ({ shouldProbeGitRemote: async () => true })) vi.mock('../../../../../main/github/rate-limit', () => ({ diff --git a/src/shared/git-binary-compatibility.test.ts b/src/shared/git-binary-compatibility.test.ts index da3b3be22b0..fefbf7385cf 100644 --- a/src/shared/git-binary-compatibility.test.ts +++ b/src/shared/git-binary-compatibility.test.ts @@ -11,7 +11,7 @@ import { import { tmpdir } from 'node:os' import { join } from 'node:path' import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest' -import * as gitRunner from '../main/git/runner' +import * as gitRunner from '../main/git/command-runner/git-exec-file' import { getRemoteFileUrl } from '../main/git/repo' import { isUnsupportedMergeTreeMergeBaseError, diff --git a/src/main/git/status-porcelain-parser.test.ts b/src/shared/git-status-porcelain-parser.test.ts similarity index 97% rename from src/main/git/status-porcelain-parser.test.ts rename to src/shared/git-status-porcelain-parser.test.ts index 86813cf6b5b..ba1dc427567 100644 --- a/src/main/git/status-porcelain-parser.test.ts +++ b/src/shared/git-status-porcelain-parser.test.ts @@ -1,5 +1,5 @@ import { describe, expect, it } from 'vitest' -import { StatusPorcelainParser } from '../../shared/git-status-porcelain-parser' +import { StatusPorcelainParser } from './git-status-porcelain-parser' describe('StatusPorcelainParser', () => { it('parses branch headers and changed/untracked/ignored records', () => { diff --git a/src/main/git/git-status-read-lease-owner.test.ts b/src/shared/git-status-read-lease-owner.test.ts similarity index 100% rename from src/main/git/git-status-read-lease-owner.test.ts rename to src/shared/git-status-read-lease-owner.test.ts diff --git a/src/shared/remote-runtime/requests/remote-runtime-request-connection.test.ts b/src/shared/remote-runtime/requests/remote-runtime-request-connection.test.ts index 4ba692bccdf..dcdab77eda2 100644 --- a/src/shared/remote-runtime/requests/remote-runtime-request-connection.test.ts +++ b/src/shared/remote-runtime/requests/remote-runtime-request-connection.test.ts @@ -18,7 +18,7 @@ import { RemoteRuntimeRequestConnection } from './remote-runtime-request-connect import { remoteRuntimeClientCapabilities } from '../remote-runtime-client-capabilities' import { createFakeSpawnedChild } from '../../__fixtures__/fake-spawned-child' import * as commandResolution from '../../../main/git/command-runner/git-command-resolution' -import * as gitRunner from '../../../main/git/runner' +import * as gitRunner from '../../../main/git/command-runner/git-exec-file' import { acquireGitAdmission, _gitAdmissionSnapshotForTests, diff --git a/tests/e2e/paired-external-worktree-discovery.spec.ts b/tests/e2e/paired-external-worktree-discovery.spec.ts index dc99668509a..2242f03b713 100644 --- a/tests/e2e/paired-external-worktree-discovery.spec.ts +++ b/tests/e2e/paired-external-worktree-discovery.spec.ts @@ -2,8 +2,8 @@ import { rmSync } from 'node:fs' import path from 'node:path' import type { Page } from '@stablyai/playwright-test' import { gitExecFileAsync } from '../../src/main/git/runner' -import { listWorktreesStrict } from '../../src/main/git/worktree' -import { areWorktreePathsEqual } from '../../src/main/git/worktree-path-comparison' +import { listWorktreesStrict } from '../../src/main/git/worktrees/catalog/worktree-listing' +import { areWorktreePathsEqual } from '../../src/main/git/worktrees/catalog/worktree-path-comparison' import { expect, test } from './helpers/orca-app' import { createRuntimeDesktopPairingOffer, diff --git a/tests/e2e/structured-session-workspace-authority.unit.test.ts b/tests/e2e/structured-session-workspace-authority.unit.test.ts index 1ce61d92522..ef36f7a9c4e 100644 --- a/tests/e2e/structured-session-workspace-authority.unit.test.ts +++ b/tests/e2e/structured-session-workspace-authority.unit.test.ts @@ -4,8 +4,8 @@ import * as folderTeardown from '../../src/main/runtime/folder-workspace-pty-tea import * as pathPresence from '../../src/main/workspaces/catalog/local-worktree-path-presence' import { mkdir } from 'node:fs/promises' import { basename } from 'node:path' -import * as worktreePaths from '../../src/main/git/worktree-path-comparison' -import * as gitRemoval from '../../src/main/git/worktree-removal' +import * as worktreePaths from '../../src/main/git/worktrees/catalog/worktree-path-comparison' +import * as gitRemoval from '../../src/main/git/worktrees/removal/worktree-removal' import * as pushTargetCleanup from '../../src/main/ipc/worktree-remote' import { finishRuntimeLocalWorktreeRemoval } from '../../src/main/runtime/runtime-registered-local-worktree-removal' import { getRuntimeFolderWorkspaceInstanceId } from '../../src/main/runtime/runtime-folder-workspace' diff --git a/tests/tools/branch-line-total-renderer.test.mjs b/tests/tools/branch-line-total-renderer.test.mjs index c62ace97b97..95a3bdb5e11 100644 --- a/tests/tools/branch-line-total-renderer.test.mjs +++ b/tests/tools/branch-line-total-renderer.test.mjs @@ -3,7 +3,9 @@ import { mkdtemp, rm, writeFile } from 'node:fs/promises' import { tmpdir } from 'node:os' import { join } from 'node:path' import { expect, it } from 'vitest' -import { getBranchCompare, getStatus, invalidateGitReadCaches } from '../../src/main/git/status' +import { getBranchCompare } from '../../src/main/git/source-control/branch-compare' +import { getStatus } from '../../src/main/git/source-control/status-read' +import { invalidateGitReadCaches } from '../../src/main/git/source-control/git-read-cache-invalidation' import { createEditorStore } from '../../src/renderer/src/store/slices/editor-slice-test-harness' async function git(repo, ...args) {