mirror of
https://github.com/stablyai/orca.git
synced 2026-11-15 18:37:24 +00:00
fix(workspace-cleanup): show an unchecked warning when the ignored-files check fails
This commit is contained in:
@@ -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'))
|
||||
|
||||
@@ -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([
|
||||
|
||||
+18
-9
@@ -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(() => {})
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user