From ae08e7d3df0358fa46b86d3a2a7ab4aba2ce09b1 Mon Sep 17 00:00:00 2001 From: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com> Date: Thu, 12 Nov 2026 08:04:42 +0000 Subject: [PATCH] fix(workspace-cleanup): show an unchecked warning when the ignored-files check fails --- ...ktree-at-risk-local-files-real-git.test.ts | 37 +++++++++++-------- .../removal/worktree-at-risk-local-files.ts | 3 ++ ...use-delete-worktree-at-risk-local-files.ts | 27 +++++++++----- 3 files changed, 43 insertions(+), 24 deletions(-) diff --git a/src/main/git/worktrees/removal/worktree-at-risk-local-files-real-git.test.ts b/src/main/git/worktrees/removal/worktree-at-risk-local-files-real-git.test.ts index 5b07f31cb62..b9d428a03dd 100644 --- a/src/main/git/worktrees/removal/worktree-at-risk-local-files-real-git.test.ts +++ b/src/main/git/worktrees/removal/worktree-at-risk-local-files-real-git.test.ts @@ -48,24 +48,31 @@ describe('readWorktreeAtRiskLocalFiles (real git)', () => { }) }) - it('ignores regenerable output, identical copies and symlinks', async () => { - await mkdir(join(worktreePath, 'node_modules', 'pkg'), { recursive: true }) - await writeFile(join(worktreePath, 'node_modules', 'pkg', 'index.js'), 'x\n') - await writeFile(join(worktreePath, 'debug.log'), 'x\n') - await writeFile(join(worktreePath, '.env'), 'TOKEN=main\n') - await writeFile(join(mainPath, '.env.local'), 'LOCAL=1\n') - await symlink(join(mainPath, '.env.local'), join(worktreePath, '.env.local')) + // File symlinks need Developer Mode or admin rights on Windows. + it.skipIf(process.platform === 'win32')( + 'ignores regenerable output, identical copies and symlinks', + async () => { + await mkdir(join(worktreePath, 'node_modules', 'pkg'), { recursive: true }) + await writeFile(join(worktreePath, 'node_modules', 'pkg', 'index.js'), 'x\n') + await writeFile(join(worktreePath, 'debug.log'), 'x\n') + await writeFile(join(worktreePath, '.env'), 'TOKEN=main\n') + await writeFile(join(mainPath, '.env.local'), 'LOCAL=1\n') + await symlink(join(mainPath, '.env.local'), join(worktreePath, '.env.local')) - await expect(read()).resolves.toEqual({ count: 0, samplePaths: [], complete: true }) - }) + await expect(read()).resolves.toEqual({ count: 0, samplePaths: [], complete: true }) + } + ) - it('does not count a main-checkout symlink into the worktree as a copy', async () => { - await rm(join(mainPath, '.env')) - await writeFile(join(worktreePath, '.env'), 'TOKEN=feature\n') - await symlink(join(worktreePath, '.env'), join(mainPath, '.env')) + it.skipIf(process.platform === 'win32')( + 'does not count a main-checkout symlink into the worktree as a copy', + async () => { + await rm(join(mainPath, '.env')) + await writeFile(join(worktreePath, '.env'), 'TOKEN=feature\n') + await symlink(join(worktreePath, '.env'), join(mainPath, '.env')) - await expect(read()).resolves.toEqual({ count: 1, samplePaths: ['.env'], complete: true }) - }) + await expect(read()).resolves.toEqual({ count: 1, samplePaths: ['.env'], complete: true }) + } + ) it('reports a directory past its comparison budget as unchecked, not safe', async () => { await mkdir(join(worktreePath, 'local')) diff --git a/src/main/git/worktrees/removal/worktree-at-risk-local-files.ts b/src/main/git/worktrees/removal/worktree-at-risk-local-files.ts index d87d96b7b5f..c3afad70979 100644 --- a/src/main/git/worktrees/removal/worktree-at-risk-local-files.ts +++ b/src/main/git/worktrees/removal/worktree-at-risk-local-files.ts @@ -109,6 +109,9 @@ export async function readWorktreeAtRiskLocalFiles(args: { const signal = abortSignalWithTimeout(parentSignal, deadlineMs) // File reads cannot all take a signal; racing the deadline keeps a stalled mount from hanging the scan. const deadline = new Promise<'unknown'>((resolve) => { + if (signal.aborted) { + resolve('unknown') + } signal.addEventListener('abort', () => resolve('unknown'), { once: true }) }) const worktreeRealPath = await Promise.race([ diff --git a/src/renderer/src/components/sidebar/workspace-actions/deletion/use-delete-worktree-at-risk-local-files.ts b/src/renderer/src/components/sidebar/workspace-actions/deletion/use-delete-worktree-at-risk-local-files.ts index 82e70534020..dffe9badd25 100644 --- a/src/renderer/src/components/sidebar/workspace-actions/deletion/use-delete-worktree-at-risk-local-files.ts +++ b/src/renderer/src/components/sidebar/workspace-actions/deletion/use-delete-worktree-at-risk-local-files.ts @@ -1,6 +1,7 @@ import { useEffect, useEffectEvent, useState } from 'react' import { useAppStore } from '@/store' import { getRuntimeWorktreeAtRiskLocalFiles } from '@/runtime/source-control/git/runtime-git-status-client' +import { RuntimeRpcCallError } from '@/runtime/rpc/calls/runtime-rpc-result' import type { Repo } from '../../../../../../shared/repo-types' import type { Worktree } from '../../../../../../shared/worktree/types' import { @@ -37,20 +38,28 @@ export function useDeleteWorktreeAtRiskLocalFiles({ continue } const identity = getWorktreeHostIdentity(target) - // Older hosts lack the method; their dialog simply shows no ignored-file warning. + const publish = (files: WorktreeAtRiskLocalFiles): void => + setResult((current) => ({ + generation, + files: new Map(current.generation === generation ? current.files : []).set( + identity, + files + ) + })) void getRuntimeWorktreeAtRiskLocalFiles(gitContext, signal) .then((files) => { if (!signal.aborted && hasWorktreeAtRiskLocalFiles(files)) { - setResult((current) => ({ - generation, - files: new Map(current.generation === generation ? current.files : []).set( - identity, - files - ) - })) + publish(files) + } + }) + .catch((error: unknown) => { + // Older hosts lack the method and keep today's dialog; any other failure is an unchecked result. + const unsupported = + error instanceof RuntimeRpcCallError && error.code === 'method_not_found' + if (!signal.aborted && !unsupported) { + publish({ count: 0, samplePaths: [], complete: false }) } }) - .catch(() => {}) } })