test: 临时目录清理统一走 removeTree(修 Windows 上的 ENOTEMPTY 竞态)
CI 在 windows lane 上红在**清理**而不是断言:
`rmSync(scratch, { recursive: true, force: true })` 抛
`ENOTEMPTY: rmdir …archives-pvpAWR`——刚被 kill 的 zip/tar 子进程(以及刚关闭的
fs.watch / 刚结束的 git 子进程)还没被系统释放句柄,删除于是失败在一个**已经通过**
的用例的 afterEach 里(那一次 2466 个用例全过,只有清理挂掉,整个 lane 变红)。
`maxRetries` + `retryDelay` 正是 Node 为这种场景提供的对策,因此新增
`tests/temp-tree.ts` 的 `removeTree()`,把 30 份 spec(175 处 `{ recursive, force }`
写法)统一换过去,并清掉随之不再使用的 `rmSync` 导入。POSIX 上首次即成功、不触发
重试,行为不变。
本地:typecheck / lint 干净,全量 210 文件 / 2524 通过。
This commit is contained in:
1 parent
a628bdd1e9
commit
57fe6e657d
32 files changed
+261
-203
No files matched your search
@@ -1,10 +1,11 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { mkdirSync, mkdtempSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, realpathSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { activeWorktreeRootOf } from '../src/active-worktree.ts'
|
||||
import type { Context } from '../src/context-types.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/** The plugin's git probe seam: call order plus an optional canned answer. */
|
||||
const seam = vi.hoisted(() => ({
|
||||
@@ -114,7 +115,7 @@ describe('active worktree root', () => {
|
||||
// `/var` → `/private/var` symlink; same convention as git-worktree.spec).
|
||||
await expect(activeWorktreeRootOf(ctx, 's-cross-repo', repoA)).resolves.toBe(realpathSync.native(worktreeB))
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -126,7 +127,7 @@ describe('active worktree root', () => {
|
||||
const ctx = sessionCtx(repo, [{ cwd: join(repo, 'src') }])
|
||||
await expect(activeWorktreeRootOf(ctx, 's-no-worktree', repo)).resolves.toBe(realpathSync.native(repo))
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -149,7 +150,7 @@ describe('active worktree root', () => {
|
||||
expect(probed).toContain(worktreeB)
|
||||
expect(probed).not.toContain(worktreeB.toLowerCase())
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -176,7 +177,7 @@ describe('active worktree root', () => {
|
||||
// Every concurrent caller still gets the resolved answer.
|
||||
expect(new Set(answers)).toEqual(new Set([realpathSync.native(repo)]))
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -199,7 +200,7 @@ describe('active worktree root', () => {
|
||||
expect(probed).toEqual([repo])
|
||||
expect(lookups()).toBe(6)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -225,7 +226,7 @@ describe('active worktree root', () => {
|
||||
expect(probed).toEqual([])
|
||||
expect(lookups()).toBe(1)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -251,7 +252,7 @@ describe('active worktree root', () => {
|
||||
expect(probed).toEqual([])
|
||||
expect(lookups()).toBe(1)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -284,7 +285,7 @@ describe('active worktree root', () => {
|
||||
expect(probed).toEqual([root])
|
||||
} finally {
|
||||
seam.responder = null
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -5,7 +5,7 @@
|
||||
* schema-valid canonical output, target-tab gating). The registry is real;
|
||||
* no WebSocket or browser is needed — the sender callbacks are captured.
|
||||
*/
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
@@ -13,6 +13,7 @@ import { validateJsonSchemaValue, type ToolDefinition, type ToolRunContext } fro
|
||||
import { AgentOpenRegistry, registerOpenTool } from '../src/agent-opens.ts'
|
||||
import type { Context } from '../src/context-types.ts'
|
||||
import { SIDEBAR_PREFS_DEFAULTS, type SidebarPrefs } from '../src/prefs-shared.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/** One registration captured by the fake tools service. */
|
||||
interface CapturedTool {
|
||||
@@ -171,7 +172,7 @@ describe('sidebar_open tool', () => {
|
||||
expect(received).toHaveLength(1)
|
||||
detach()
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -189,7 +190,7 @@ describe('sidebar_open tool', () => {
|
||||
expect(received).toHaveLength(1)
|
||||
detach()
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -204,7 +205,7 @@ describe('sidebar_open tool', () => {
|
||||
expect(value).toEqual({ kind: 'folder', target: sub, title: 'Sources', delivered: false })
|
||||
expect(validateJsonSchemaValue(tool.output.schema, value, 'value')).toEqual([])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -245,7 +246,7 @@ describe('sidebar_open tool', () => {
|
||||
await expect(fileTool.execute({ target: 'https://example.com/' }, exec('s1'))).resolves.toMatchObject({ kind: 'url' })
|
||||
await expect(fileTool.execute({ target: 'f.txt' }, exec('s1'))).rejects.toThrow(/editor tab is disabled/)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ import {
|
||||
mkdtempSync,
|
||||
openSync,
|
||||
readFileSync,
|
||||
rmSync,
|
||||
|
||||
statSync,
|
||||
symlinkSync,
|
||||
writeFileSync,
|
||||
@@ -44,6 +44,7 @@ import {
|
||||
type ArchiveToolSpec,
|
||||
} from '../src/archive-tools.ts'
|
||||
import { SidebarError } from '../src/wire.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/** What one scripted child answers, per phase. */
|
||||
interface Script {
|
||||
@@ -166,7 +167,7 @@ afterEach(() => {
|
||||
resetArchiveToolCache()
|
||||
vi.useRealTimers()
|
||||
vi.restoreAllMocks()
|
||||
while (roots.length > 0) rmSync(roots.pop()!, { recursive: true, force: true })
|
||||
while (roots.length > 0) removeTree(roots.pop()!)
|
||||
})
|
||||
|
||||
describe('planArchive', () => {
|
||||
@@ -491,7 +492,7 @@ describe('real tool (only when one is installed)', () => {
|
||||
expect(readFileSync(out).includes('loop/loop')).toBe(false)
|
||||
}
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
}, 30_000)
|
||||
})
|
||||
@@ -32,7 +32,7 @@ import {
|
||||
mkdirSync,
|
||||
mkdtempSync,
|
||||
readdirSync,
|
||||
rmSync,
|
||||
|
||||
writeFileSync,
|
||||
writeSync,
|
||||
} from 'node:fs'
|
||||
@@ -59,6 +59,7 @@ import {
|
||||
} from '../src/archive-tools.ts'
|
||||
import { writeError } from '../src/wire.ts'
|
||||
import type { SidebarHttpResponse, SidebarWebRoute, SidebarWebUpgradeRoute } from '../src/context-types.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/** The OS temp directory as it was BEFORE this file points TMPDIR at a scratch dir. */
|
||||
const realTmp = tmpdir()
|
||||
@@ -280,8 +281,8 @@ afterEach(async () => {
|
||||
resetArchiveToolCache()
|
||||
vi.useRealTimers()
|
||||
vi.restoreAllMocks()
|
||||
rmSync(scratch, { recursive: true, force: true })
|
||||
rmSync(tempDir, { recursive: true, force: true })
|
||||
removeTree(scratch)
|
||||
removeTree(tempDir)
|
||||
})
|
||||
|
||||
/** A directory inside the per-test fixture tree (removed with it). */
|
||||
|
||||
@@ -6,11 +6,12 @@
|
||||
* re-downloading.
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http'
|
||||
import { CHUNK_NAMES, createBundleRouteHandler } from '../src/bundle-route.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
interface FakeRes {
|
||||
status: number
|
||||
@@ -44,7 +45,7 @@ function setup(): { handler: (req: IncomingMessage, res: ServerResponse) => Prom
|
||||
const dir = mkdtempSync(join(tmpdir(), 'bundle-route-'))
|
||||
writeFileSync(join(dir, 'client-editor.js'), 'window.__ModuleLoader__ && 0;')
|
||||
const handler = createBundleRouteHandler(() => true, dir)
|
||||
return { handler, dir, cleanup: () => { rmSync(dir, { recursive: true, force: true }) } }
|
||||
return { handler, dir, cleanup: () => { removeTree(dir) } }
|
||||
}
|
||||
|
||||
describe('/sidebar/bundle route', () => {
|
||||
@@ -145,7 +146,7 @@ describe('/sidebar/bundle route', () => {
|
||||
await handler(req('GET', '/sidebar/bundle/editor.js'), res as unknown as ServerResponse)
|
||||
expect(res.status).toBe(403)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -41,11 +41,12 @@
|
||||
* reason the mount lane runs first: a later lane's seeding must not change what
|
||||
* an earlier lane's tree shows.
|
||||
*/
|
||||
import { mkdirSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { test, expect, type APIRequestContext, type Page } from '@playwright/test'
|
||||
import { PAGE_URL, createHostApi, hostRpc, sendFirstMessage } from './host'
|
||||
import { removeTree } from '../temp-tree.ts'
|
||||
|
||||
/** This lane's own workspace: a 40-child directory plus a small sibling. */
|
||||
const WORKSPACE_PATH = process.env.DSH_E2E_EXPAND_WORKSPACE ?? join(tmpdir(), 'dsh-e2e-expand-probe')
|
||||
@@ -64,7 +65,7 @@ function seedWorkspace(): void {
|
||||
// The lane owns this directory and every run starts from the same tree: a
|
||||
// leftover file from an earlier run would already be listed, so the
|
||||
// behind-the-plugin write below would change nothing on screen.
|
||||
rmSync(WORKSPACE_PATH, { recursive: true, force: true })
|
||||
removeTree(WORKSPACE_PATH)
|
||||
mkdirSync(join(WORKSPACE_PATH, BIG), { recursive: true })
|
||||
mkdirSync(join(WORKSPACE_PATH, 'bravo'), { recursive: true })
|
||||
for (let i = 0; i < BIG_CHILDREN; i++) {
|
||||
|
||||
@@ -16,13 +16,14 @@
|
||||
* prevent on the failure side.
|
||||
*/
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, symlinkSync, writeFileSync } from 'node:fs'
|
||||
import { createServer } from 'node:http'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { apply } from '../src/index.ts'
|
||||
import { writeError, writeJson } from '../src/wire.ts'
|
||||
import type { SidebarWebRoute } from '../src/context-types.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
interface FakeContext {
|
||||
webRuntime: { trustedHosts: readonly string[] }
|
||||
@@ -52,7 +53,7 @@ afterEach(async () => {
|
||||
server.closeAllConnections()
|
||||
})
|
||||
}
|
||||
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
|
||||
for (const root of roots.splice(0)) removeTree(root)
|
||||
})
|
||||
|
||||
/** A temp workspace whose session cwd is the returned directory. */
|
||||
|
||||
+14
-13
@@ -3,6 +3,7 @@ import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync,
|
||||
import { join } from 'node:path'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { renameWorkspaceEntry, removeWorkspaceEntry, mkdirWorkspaceEntry, writeWorkspaceUpload } from '../src/fs-operations.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/** The test workspace root (each suite gets its own temp tree). */
|
||||
const root = mkdtempSync(join(tmpdir(), 'dsh-sidebar-upload-'))
|
||||
@@ -16,12 +17,12 @@ const canSymlink = (() => {
|
||||
} catch {
|
||||
return false
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})()
|
||||
|
||||
afterAll(() => {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
})
|
||||
|
||||
/** Names of leftover temp files under `dir` (must be empty after every run). */
|
||||
@@ -145,7 +146,7 @@ describe('writeWorkspaceUpload', () => {
|
||||
expect(result).toEqual({ path: join(outside, 'x.txt'), size: 1 })
|
||||
expect(readFileSync(join(outside, 'x.txt'), 'utf8')).toBe('x')
|
||||
} finally {
|
||||
rmSync(outside, { recursive: true, force: true })
|
||||
removeTree(outside)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -168,7 +169,7 @@ describe('writeWorkspaceUpload', () => {
|
||||
expect(readFileSync(join(outside, 'b.txt'), 'utf8')).toBe('b')
|
||||
} finally {
|
||||
rmSync(link, { force: true })
|
||||
rmSync(outside, { recursive: true, force: true })
|
||||
removeTree(outside)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -318,7 +319,7 @@ describe('removeWorkspaceEntry', () => {
|
||||
expect(existsSync(join(ws, 'link-to-proj'))).toBe(false)
|
||||
expect(existsSync(join(inner, 'src', 'keep.ts'))).toBe(true)
|
||||
} finally {
|
||||
rmSync(ws, { recursive: true, force: true })
|
||||
removeTree(ws)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -338,7 +339,7 @@ describe('session-relative targets (the shared resolution contract, #646)', () =
|
||||
expect(readFileSync(path, 'utf8')).toBe('rel')
|
||||
expect(tmpLeftovers(ws)).toEqual([])
|
||||
} finally {
|
||||
rmSync(ws, { recursive: true, force: true })
|
||||
removeTree(ws)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -350,7 +351,7 @@ describe('session-relative targets (the shared resolution contract, #646)', () =
|
||||
expect(renamed.path).toBe(join(ws, 'b.txt'))
|
||||
expect(existsSync(join(ws, 'b.txt'))).toBe(true)
|
||||
} finally {
|
||||
rmSync(ws, { recursive: true, force: true })
|
||||
removeTree(ws)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -362,7 +363,7 @@ describe('session-relative targets (the shared resolution contract, #646)', () =
|
||||
expect(removed.path).toBe(join(ws, 'gone.txt'))
|
||||
expect(existsSync(join(ws, 'gone.txt'))).toBe(false)
|
||||
} finally {
|
||||
rmSync(ws, { recursive: true, force: true })
|
||||
removeTree(ws)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -373,7 +374,7 @@ describe('session-relative targets (the shared resolution contract, #646)', () =
|
||||
expect(made.path).toBe(join(ws, 'sub'))
|
||||
expect(existsSync(join(ws, 'sub'))).toBe(true)
|
||||
} finally {
|
||||
rmSync(ws, { recursive: true, force: true })
|
||||
removeTree(ws)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -400,7 +401,7 @@ describe.runIf(process.platform === 'win32')('workspace-root guard across path s
|
||||
.rejects.toMatchObject({ code: 'fs-error' })
|
||||
expect(existsSync(join(inner, 'src', 'keep.ts'))).toBe(true)
|
||||
} finally {
|
||||
rmSync(ws, { recursive: true, force: true })
|
||||
removeTree(ws)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -411,7 +412,7 @@ describe.runIf(process.platform === 'win32')('workspace-root guard across path s
|
||||
.rejects.toMatchObject({ code: 'fs-error' })
|
||||
expect(existsSync(join(inner, 'src', 'keep.ts'))).toBe(true)
|
||||
} finally {
|
||||
rmSync(ws, { recursive: true, force: true })
|
||||
removeTree(ws)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -422,7 +423,7 @@ describe.runIf(process.platform === 'win32')('workspace-root guard across path s
|
||||
.rejects.toMatchObject({ code: 'fs-error' })
|
||||
expect(existsSync(join(inner, 'src', 'keep.ts'))).toBe(true)
|
||||
} finally {
|
||||
rmSync(ws, { recursive: true, force: true })
|
||||
removeTree(ws)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -436,7 +437,7 @@ describe.runIf(process.platform === 'win32')('workspace-root guard across path s
|
||||
expect(existsSync(join(inner, 'Sub'))).toBe(false)
|
||||
expect(existsSync(inner)).toBe(true)
|
||||
} finally {
|
||||
rmSync(ws, { recursive: true, force: true })
|
||||
removeTree(ws)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -16,13 +16,14 @@
|
||||
* spellings into one mojibake document.
|
||||
*/
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { apply } from '../src/index.ts'
|
||||
import { encodeText } from '../src/text-encoding.ts'
|
||||
import { PAGE_BYTES } from '../src/editor-limits.ts'
|
||||
import type { SidebarWebRoute } from '../src/context-types.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
interface FakeContext {
|
||||
webRuntime: { trustedHosts: readonly string[] }
|
||||
@@ -40,7 +41,7 @@ interface FakeContext {
|
||||
|
||||
const roots: string[] = []
|
||||
afterEach(() => {
|
||||
for (const root of roots.splice(0)) rmSync(root, { recursive: true, force: true })
|
||||
for (const root of roots.splice(0)) removeTree(root)
|
||||
})
|
||||
|
||||
/** A fresh workspace under the OS temp dir, cleaned up after the test. */
|
||||
|
||||
+28
-27
@@ -14,13 +14,14 @@
|
||||
* cases below inject fake engines so no machine binary is required.
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, symlinkSync, writeFileSync } from 'node:fs'
|
||||
import { homedir, tmpdir } from 'node:os'
|
||||
import { join, resolve as resolvePath } from 'node:path'
|
||||
import { compileExcludePatterns } from '../src/exclude-patterns.ts'
|
||||
import { searchFiles, searchFilesPlain } from '../src/fs-search.ts'
|
||||
import type { EngineProbe } from '../src/search-engines.ts'
|
||||
import { resetEngines, setEngineHooks } from '../src/search-engines.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/**
|
||||
* Symlink creation needs extra privileges on Windows; the symlink case skips
|
||||
@@ -34,7 +35,7 @@ const canSymlink = (() => {
|
||||
} catch {
|
||||
return false
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})()
|
||||
|
||||
@@ -52,7 +53,7 @@ const canBackslashName = (() => {
|
||||
} catch {
|
||||
return false
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})()
|
||||
|
||||
@@ -98,7 +99,7 @@ describe('fs-search', () => {
|
||||
expect(match).not.toContain('\\')
|
||||
}
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -115,7 +116,7 @@ describe('fs-search', () => {
|
||||
expect(dirHit).toEqual({ matches: ['src'], dirs: ['src'], truncated: false })
|
||||
expect((await searchFilesPlain(dir, 'util')).dirs).toEqual([])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -127,7 +128,7 @@ describe('fs-search', () => {
|
||||
expect((await searchFilesPlain(dir, 'config')).matches).toEqual([])
|
||||
expect((await searchFilesPlain(dir, '.git')).matches).toEqual([])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -143,7 +144,7 @@ describe('fs-search', () => {
|
||||
expect(await searchFilesPlain(dir, '.git')).toEqual({ matches: [], dirs: [], truncated: false })
|
||||
expect((await searchFilesPlain(dir, 'util')).matches).toEqual(['util.ts'])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -167,7 +168,7 @@ describe('fs-search', () => {
|
||||
.toEqual(['src/index.ts', 'third_party/index.ts', 'third_party/pkg/index.ts'])
|
||||
expect((await searchFiles(dir, 'third_party')).dirs).toEqual(['third_party'])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -188,7 +189,7 @@ describe('fs-search', () => {
|
||||
expect((await searchFilesPlain(dir, 'node_modules')).matches).toEqual([])
|
||||
expect((await searchFilesPlain(dir, 'dist')).matches).toEqual([])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -209,7 +210,7 @@ describe('fs-search', () => {
|
||||
expect((await searchFilesPlain(dir, 'target')).matches).toEqual([])
|
||||
expect((await searchFilesPlain(dir, 'venv')).matches).toEqual([])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -237,7 +238,7 @@ describe('fs-search', () => {
|
||||
writeFileSync(join(dir, 'node_modules', 'records', 'exp1.txt'), 'dep')
|
||||
expect((await searchFilesPlain(dir, 'records/exp1')).matches).toEqual(['deep/records/exp1.txt'])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -253,7 +254,7 @@ describe('fs-search', () => {
|
||||
expect((await searchFilesPlain(dir, 'back\\slash')).matches).toEqual(['back\\slash.ts'])
|
||||
expect((await searchFilesPlain(dir, 'slash')).matches).toEqual(['back\\slash.ts'])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -263,7 +264,7 @@ describe('fs-search', () => {
|
||||
expect(await searchFilesPlain(dir, '')).toEqual({ matches: [], dirs: [], truncated: false })
|
||||
expect(await searchFilesPlain(dir, ' ')).toEqual({ matches: [], dirs: [], truncated: false })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -277,7 +278,7 @@ describe('fs-search', () => {
|
||||
const result = await searchFilesPlain(dir, 'util')
|
||||
expect(result).toEqual({ matches: ['src/util.ts'], dirs: [], truncated: false })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -294,7 +295,7 @@ describe('fs-search', () => {
|
||||
symlinkSync(join(dir, 'gone'), join(dir, 'dangling-link'))
|
||||
expect(await searchFilesPlain(dir, 'dangling-link')).toEqual({ matches: ['dangling-link'], dirs: [], truncated: false })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -308,7 +309,7 @@ describe('fs-search', () => {
|
||||
expect(result.truncated).toBe(true)
|
||||
expect(result.matches.length).toBe(2)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -323,7 +324,7 @@ describe('fs-search', () => {
|
||||
expect(result.truncated).toBe(true)
|
||||
expect(result.matches).toEqual([])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -333,7 +334,7 @@ describe('fs-search', () => {
|
||||
const missing = join(dir, 'does-not-exist')
|
||||
expect(await searchFilesPlain(missing, 'x')).toEqual({ matches: [], dirs: [], truncated: false })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -424,7 +425,7 @@ describe('fs-search dispatch', () => {
|
||||
expect(await searchFiles(dir, folder)).toEqual({ matches: [folder], dirs: [folder], truncated: false })
|
||||
expect(probed).toBe(false)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -442,7 +443,7 @@ describe('fs-search dispatch', () => {
|
||||
expect(await searchFiles(dir, join(dir, 'gone.md'), { maxVisited: 1 })).toEqual({ matches: [], dirs: [], truncated: false })
|
||||
expect(probed).toBe(false)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -485,7 +486,7 @@ describe('fs-search dispatch', () => {
|
||||
// A missing `~`-anchored target is the same immediate empty.
|
||||
expect(await searchFiles(dir, '~/dsh-sidebar-no-such-entry')).toEqual({ matches: [], dirs: [], truncated: false })
|
||||
} finally {
|
||||
rmSync(parent, { recursive: true, force: true })
|
||||
removeTree(parent)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -517,7 +518,7 @@ describe('fs-search dispatch', () => {
|
||||
expect((await searchFiles(dir, '~$lock')).matches).toEqual(['~$lock.docx'])
|
||||
expect((await searchFiles(dir, '.env')).matches).toEqual(['.env'])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -536,7 +537,7 @@ describe('fs-search dispatch', () => {
|
||||
expect((await searchFiles(dir, 'docs/guide')).matches).toEqual(['docs/guide.md'])
|
||||
expect(probed).toBe(false)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -556,7 +557,7 @@ describe('fs-search dispatch', () => {
|
||||
expect((await searchFiles(dir, 'back\\slash')).matches).toEqual(['back\\slash.ts'])
|
||||
expect(probed).toBe(true)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -576,7 +577,7 @@ describe('fs-search dispatch', () => {
|
||||
expect((await searchFiles(dir, '.\\notes')).matches).toEqual(['.\\notes.md'])
|
||||
expect(probed).toBe(true)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -649,7 +650,7 @@ describe('fs-search dispatch', () => {
|
||||
expect(await searchFiles(dir, 'util')).toEqual({ matches: ['src/util.ts'], dirs: [], truncated: false })
|
||||
expect(attempts).toBe(0)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -659,7 +660,7 @@ describe('fs-search dispatch', () => {
|
||||
setEngineHooks({ prober: async () => [] })
|
||||
expect(await searchFiles(dir, 'util')).toEqual({ matches: ['src/util.ts'], dirs: [], truncated: false })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -6,10 +6,11 @@
|
||||
* otherwise fold forever).
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, symlinkSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { listDirectory } from '../src/fs-tree.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/** Mirror of the symlink spec's capability probe (symlinks need privileges on Windows). */
|
||||
const canSymlink = (() => {
|
||||
@@ -20,7 +21,7 @@ const canSymlink = (() => {
|
||||
} catch {
|
||||
return false
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})()
|
||||
|
||||
@@ -55,7 +56,7 @@ describe('fs-tree compact marking', () => {
|
||||
const levelC = await listDirectory(join(dir, 'a', 'b', 'c'))
|
||||
expect(levelC.entries.find(entry => entry.name === 'leaf.txt')?.compact).toBeUndefined()
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -73,7 +74,7 @@ describe('fs-tree compact marking', () => {
|
||||
const mixed = await listDirectory(join(dir, 'mixed'))
|
||||
expect(mixed.entries.find(entry => entry.name === 'note.txt')?.compact).toBeUndefined()
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -87,7 +88,7 @@ describe('fs-tree compact marking', () => {
|
||||
expect(listing.entries.find(entry => entry.name === 'link')).toMatchObject({ isDir: true, isSymlink: true })
|
||||
expect(listing.entries.find(entry => entry.name === 'link')?.compact).toBeUndefined()
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -121,7 +122,7 @@ describe('fs-tree compact marking', () => {
|
||||
const chain = await listDirectory(join(dir, 'chain'))
|
||||
expect(chain.entries.find(entry => entry.name === '.DS_Store')).toMatchObject({ isDir: false, hidden: true })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -5,11 +5,12 @@
|
||||
* row or an overflow slot, and never block a breadcrumb fold.
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { compileExcludePatterns } from '../src/exclude-patterns.ts'
|
||||
import { listDirectory } from '../src/fs-tree.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/** A scratch tree exercising name, path-anchored and deep patterns. */
|
||||
function makeFixture(): string {
|
||||
@@ -48,7 +49,7 @@ describe('fs-tree exclude filtering', () => {
|
||||
const chain = await listDirectory(join(dir, 'chain'), 1000, exclude)
|
||||
expect(chain.entries.map(entry => entry.name)).toEqual(['inner'])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -65,7 +66,7 @@ describe('fs-tree exclude filtering', () => {
|
||||
const src = await listDirectory(join(dir, 'src'), 1000, exclude)
|
||||
expect(src.entries.map(entry => entry.name)).toEqual(['out'])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -80,7 +81,7 @@ describe('fs-tree exclude filtering', () => {
|
||||
const nested = await listDirectory(join(dir, 'nested'), 1000, exclude)
|
||||
expect(nested.entries.map(entry => entry.name)).toEqual(['keep.txt'])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -98,7 +99,7 @@ describe('fs-tree exclude filtering', () => {
|
||||
expect(unfiltered.entries.find(entry => entry.name === 'chain')?.compact).toBeUndefined()
|
||||
expect(unfiltered.entries.find(entry => entry.name === 'terminal')?.compact).toBeUndefined()
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -115,7 +116,7 @@ describe('fs-tree exclude filtering', () => {
|
||||
// Same level without the probe: the cap trips.
|
||||
expect((await listDirectory(dir, 2)).truncated).toBe(true)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -126,7 +127,7 @@ describe('fs-tree exclude filtering', () => {
|
||||
expect(names).toContain('.DS_Store')
|
||||
expect(names).toContain('node_modules')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -149,7 +150,7 @@ describe('fs-tree exclude filtering', () => {
|
||||
// And the unfiltered level stays reachable under its own key.
|
||||
expect(await listDirectory(dir, 1000)).toBe(unfiltered)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -10,11 +10,12 @@
|
||||
* gate the request was given (and a cache hit spends nothing at all). The
|
||||
* route's per-request gate SHARING is asserted in tests/smoke.spec.ts.
|
||||
*/
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { createProbeGate, listDirectory, type ProbeGate } from '../src/fs-tree.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/** A gate that only COUNTS acquisitions: it bounds nothing of its own, so the
|
||||
* count it reports is exactly the probes the caller routed through it. */
|
||||
@@ -105,7 +106,7 @@ describe('listDirectory probe budget', () => {
|
||||
expect(counted.calls()).toBe(spent)
|
||||
expect(cached).toBe(listing)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -132,7 +133,7 @@ describe('listDirectory probe budget', () => {
|
||||
expect(listing.entries.filter(entry => entry.compact === true)).toHaveLength(3)
|
||||
}
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -164,7 +165,7 @@ describe('listDirectory probe budget', () => {
|
||||
listing.entries.slice(0, 32).map(entry => entry.name),
|
||||
)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -187,7 +188,7 @@ describe('listDirectory probe budget', () => {
|
||||
expect(counted.calls()).toBe(0)
|
||||
expect(listing.entries.every(entry => entry.compact === undefined)).toBe(true)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -5,10 +5,11 @@
|
||||
* only entries that are actually symlinks are stat'ed.
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, symlinkSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { listDirectory } from '../src/fs-tree.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/**
|
||||
* Symlink creation needs extra privileges on Windows; skip the suite there
|
||||
@@ -22,7 +23,7 @@ const canSymlink = (() => {
|
||||
} catch {
|
||||
return false
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})()
|
||||
|
||||
@@ -45,7 +46,7 @@ describe.skipIf(!canSymlink)('fs-tree symlink listing', () => {
|
||||
const row = listing.entries.find(entry => entry.name === 'link-to-dir')
|
||||
expect(row).toMatchObject({ isDir: true, isSymlink: true, broken: false })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -56,7 +57,7 @@ describe.skipIf(!canSymlink)('fs-tree symlink listing', () => {
|
||||
const row = listing.entries.find(entry => entry.name === 'link-to-file')
|
||||
expect(row).toMatchObject({ isDir: false, isSymlink: true, broken: false })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -67,7 +68,7 @@ describe.skipIf(!canSymlink)('fs-tree symlink listing', () => {
|
||||
const row = listing.entries.find(entry => entry.name === 'broken-link')
|
||||
expect(row).toMatchObject({ isDir: false, isSymlink: true, broken: true })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -83,7 +84,7 @@ describe.skipIf(!canSymlink)('fs-tree symlink listing', () => {
|
||||
const dirs = listing.entries.filter(entry => entry.isDir).map(entry => entry.name)
|
||||
expect(dirs).toEqual(['link-to-dir', 'real-dir'])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -107,7 +108,7 @@ describe.skipIf(!canSymlink)('fs-tree symlink listing', () => {
|
||||
.toMatchObject({ isDir: false, isSymlink: true, broken: false })
|
||||
}
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1,9 +1,10 @@
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join, resolve, sep } from 'node:path'
|
||||
import { compareEntries, isWithin, invalidateDirectoryCache, listDirectory, parentOf, requireAbsolute, rootLabel } from '../src/fs-tree.ts'
|
||||
import { isWin32 } from './platform.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
describe('fs-tree', () => {
|
||||
it('sorts directories first, then names case-insensitively', () => {
|
||||
@@ -108,7 +109,7 @@ describe('listDirectory (capped rows + cache)', () => {
|
||||
}
|
||||
afterEach(() => {
|
||||
invalidateDirectoryCache()
|
||||
while (roots.length > 0) rmSync(roots.pop()!, { recursive: true, force: true })
|
||||
while (roots.length > 0) removeTree(roots.pop()!)
|
||||
})
|
||||
|
||||
it('caps the rows and flags truncated', async () => {
|
||||
|
||||
@@ -13,11 +13,12 @@
|
||||
* debounce.
|
||||
*/
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { listDirectory } from '../src/fs-tree.ts'
|
||||
import { createDirectoryWatchers, type DirectoryWatchEvent } from '../src/fs-watch.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/** Generous delivery budget: the module debounces at 150 ms, the OS adds its own latency. */
|
||||
const DELIVERY_TIMEOUT_MS = 15_000
|
||||
@@ -29,7 +30,7 @@ const withScratch = (run: (dir: string) => Promise<void> | void): Promise<void>
|
||||
const root = mkdtempSync(join(tmpdir(), 'dsh-sidebar-watch-'))
|
||||
const dir = join(root, 'watched')
|
||||
mkdirSync(dir)
|
||||
return Promise.resolve(run(dir)).finally(() => { rmSync(root, { recursive: true, force: true }) })
|
||||
return Promise.resolve(run(dir)).finally(() => { removeTree(root) })
|
||||
}
|
||||
|
||||
/** Sleep for a fixed window. */
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { mkdirSync, rmSync } from 'node:fs'
|
||||
import { mkdirSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { ensureWorkspaceWritePath } from '../src/path-security.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
const dirs: string[] = []
|
||||
afterEach(() => { for (const d of dirs.splice(0)) rmSync(d, { recursive: true, force: true }) })
|
||||
afterEach(() => { for (const d of dirs.splice(0)) removeTree(d) })
|
||||
|
||||
describe('fs.write resolves session-relative paths (#646)', () => {
|
||||
it('resolves a relative write path against the session cwd', async () => {
|
||||
|
||||
@@ -29,6 +29,7 @@ import { join } from 'node:path'
|
||||
import { apply } from '../src/index.ts'
|
||||
import { encodeText } from '../src/text-encoding.ts'
|
||||
import type { SidebarWebRoute } from '../src/context-types.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
interface FakeContext {
|
||||
webRuntime: { trustedHosts: readonly string[] }
|
||||
@@ -158,7 +159,7 @@ describe('/sidebar/write route', () => {
|
||||
expect(['first', 'second', 'third']).toContain(readFileSync(target, 'utf8'))
|
||||
expect(tempLeftovers(workspace)).toEqual([])
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -177,7 +178,7 @@ describe('/sidebar/write route', () => {
|
||||
expect(readFileSync(target, 'utf8')).toBe('v3')
|
||||
expect(tempLeftovers(workspace)).toEqual([])
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -207,7 +208,7 @@ describe('/sidebar/write route', () => {
|
||||
expect(readFileSync(target, 'utf8')).toBe('disk-v2')
|
||||
expect(tempLeftovers(workspace)).toEqual([])
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -235,7 +236,7 @@ describe('/sidebar/write route', () => {
|
||||
expect(second).toMatchObject({ ok: true, status: 200 })
|
||||
expect(readFileSync(target, 'utf8')).toBe('disk-v3')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -263,7 +264,7 @@ describe('/sidebar/write route', () => {
|
||||
expect(readFileSync(target, 'utf8')).toBe(content)
|
||||
expect(tempLeftovers(workspace)).toEqual([])
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -299,7 +300,7 @@ describe('/sidebar/write route', () => {
|
||||
expect(existsSync(target)).toBe(false)
|
||||
expect(tempLeftovers(workspace)).toEqual([])
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -325,7 +326,7 @@ describe('/sidebar/write route', () => {
|
||||
expect({ ...JSON.parse(out.body) as Invoked, status: out.status })
|
||||
.toMatchObject({ ok: false, status: 400, error: { code: 'bad-request' } })
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -343,7 +344,7 @@ describe('/sidebar/write route', () => {
|
||||
const baseline = read.value?.mtimeMs
|
||||
// A rename/removal of the parent directory: the writer's `mkdir -p` used
|
||||
// to rebuild the tree for a single file.
|
||||
rmSync(nested, { recursive: true, force: true })
|
||||
removeTree(nested)
|
||||
|
||||
const stale = await invokeWrite(route, {
|
||||
sessionId: 's', path: target, content: 'my-draft', expectedMtimeMs: baseline,
|
||||
@@ -351,7 +352,7 @@ describe('/sidebar/write route', () => {
|
||||
expect(stale).toMatchObject({ ok: false, status: 409, error: { code: 'fs-conflict' } })
|
||||
expect(existsSync(nested)).toBe(false)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -367,7 +368,7 @@ describe('/sidebar/write route', () => {
|
||||
expect(result).toMatchObject({ ok: true, status: 200 })
|
||||
expect(readFileSync(target, 'utf8')).toBe('overwritten')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -395,7 +396,7 @@ describe('/sidebar/write route', () => {
|
||||
// No bare LF may survive — that is precisely the whole-file diff.
|
||||
expect(written.replaceAll('\r\n', '')).not.toContain('\n')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -417,7 +418,7 @@ describe('/sidebar/write route', () => {
|
||||
expect(written).toBe('one\ntwo edited\n')
|
||||
expect(written).not.toContain('\r')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -442,7 +443,7 @@ describe('/sidebar/write route', () => {
|
||||
// that assertion ever gets relaxed.
|
||||
expect(readFileSync(target).toString('utf8')).not.toContain('\r\r')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -13,17 +13,18 @@
|
||||
* time and summary must be carried forward from the first line of that commit.
|
||||
*/
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { blame, diff, diffHead, parseBlamePorcelain } from '../src/git.ts'
|
||||
import { gitLineKinds } from '../src/client/editor-git-gutter.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
const created: string[] = []
|
||||
|
||||
afterEach(() => {
|
||||
for (const dir of created.splice(0)) rmSync(dir, { recursive: true, force: true })
|
||||
for (const dir of created.splice(0)) removeTree(dir)
|
||||
})
|
||||
|
||||
/** A fresh temporary directory (removed after the test). */
|
||||
|
||||
@@ -15,11 +15,12 @@
|
||||
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { apply } from '../src/index.ts'
|
||||
import type { SidebarWebRoute, SidebarWebUpgradeRoute } from '../src/context-types.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/** Fixture commit identity, confined to this process: no git config is touched. */
|
||||
const FIXTURE_IDENTITY = {
|
||||
@@ -148,7 +149,7 @@ describe('git remote routes (real repository + bare origin)', () => {
|
||||
// The remote actually moved — the route ran a real `git push`.
|
||||
expect(gitRun(fixture.origin, ['rev-parse', 'main']).trim()).toBe(local)
|
||||
} finally {
|
||||
rmSync(fixture.scratch, { recursive: true, force: true })
|
||||
removeTree(fixture.scratch)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -164,7 +165,7 @@ describe('git remote routes (real repository + bare origin)', () => {
|
||||
expect(result.error?.code).toBe('git-error')
|
||||
expect(result.error?.message ?? '').not.toBe('')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -182,7 +183,7 @@ describe('git remote routes (real repository + bare origin)', () => {
|
||||
expect(pulled).toMatchObject({ ok: true, value: { ok: true } })
|
||||
expect(readFileSync(join(fixture.work, 'b.txt'), 'utf8')).toBe('from peer\n')
|
||||
} finally {
|
||||
rmSync(fixture.scratch, { recursive: true, force: true })
|
||||
removeTree(fixture.scratch)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -209,7 +210,7 @@ describe('git remote routes (real repository + bare origin)', () => {
|
||||
expect(gitRun(fixture.work, ['status', '--porcelain'])).toBe('')
|
||||
expect(() => readFileSync(join(fixture.work, '.git', 'MERGE_HEAD'), 'utf8')).toThrow()
|
||||
} finally {
|
||||
rmSync(fixture.scratch, { recursive: true, force: true })
|
||||
removeTree(fixture.scratch)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -21,12 +21,13 @@
|
||||
*/
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { spawnSync, type SpawnOptions } from 'node:child_process'
|
||||
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdtempSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { apply } from '../src/index.ts'
|
||||
import { SUGGEST_DIFF_LIMIT, truncateDiff } from '../src/commit-message.ts'
|
||||
import type { SidebarWebRoute, SidebarWebUpgradeRoute } from '../src/context-types.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/** Every git process the plugin spawned, in call order (argv without the
|
||||
* binary). The safety invariant is asserted at the PROCESS BOUNDARY, so it
|
||||
@@ -301,7 +302,7 @@ describe('git.suggest-message: model route fallback chain', () => {
|
||||
expect(harness.calls).toHaveLength(1)
|
||||
expect(harness.calls[0]).toMatchObject({ provider: 'pinned-prov', model: 'model-x' })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -318,7 +319,7 @@ describe('git.suggest-message: model route fallback chain', () => {
|
||||
expect(result.ok).toBe(true)
|
||||
expect(result.value).toMatchObject({ provider: 'conversation-prov', model: 'conversation-model' })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -342,7 +343,7 @@ describe('git.suggest-message: model route fallback chain', () => {
|
||||
expect(result.ok).toBe(true)
|
||||
expect(result.value).toMatchObject({ provider: 'newest-prov', model: 'newest-model' })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -362,7 +363,7 @@ describe('git.suggest-message: model route fallback chain', () => {
|
||||
expect(result.ok).toBe(true)
|
||||
expect(result.value).toMatchObject({ provider: 'harness-prov', model: 'harness-model' })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -382,7 +383,7 @@ describe('git.suggest-message: model route fallback chain', () => {
|
||||
// Nothing was generated and, above all, nothing was committed.
|
||||
expect(harness.calls).toHaveLength(0)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -422,7 +423,7 @@ describe('git.suggest-message: prompt and generation bounds', () => {
|
||||
expect(call?.signal?.aborted).toBe(false)
|
||||
} finally {
|
||||
vi.restoreAllMocks()
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -443,7 +444,7 @@ describe('git.suggest-message: prompt and generation bounds', () => {
|
||||
expect(call).toBeDefined()
|
||||
expect(Object.hasOwn(call ?? {}, 'reasoningEffort')).toBe(false)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -469,7 +470,7 @@ describe('git.suggest-message: prompt and generation bounds', () => {
|
||||
// …and never the whole patch, which is what flooding the model means.
|
||||
expect(user).not.toContain(realDiff)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -486,7 +487,7 @@ describe('git.suggest-message: prompt and generation bounds', () => {
|
||||
expect(harness.calls[1]?.system).toContain('You are a git commit message assistant')
|
||||
expect(userTextOf(harness.calls[1])).toContain('Changed files')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -536,7 +537,7 @@ describe('git.suggest-message: answer shape and error mapping', () => {
|
||||
expect(padded.ok).toBe(true)
|
||||
expect((padded.value as { message: string }).message).toBe('fix: pad the edges')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -565,7 +566,7 @@ describe('git.suggest-message: answer shape and error mapping', () => {
|
||||
expect(failed.status).not.toBe(noRoute.status)
|
||||
expect(failed.error?.code).not.toBe(noRoute.error?.code)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -582,7 +583,7 @@ describe('git.suggest-message: answer shape and error mapping', () => {
|
||||
expect(result.error?.code).toBe('git-suggest-error')
|
||||
expect(result.error?.message).toContain('30s')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -605,7 +606,7 @@ describe('git.suggest-message: answer shape and error mapping', () => {
|
||||
expect(result.error?.message).toContain('empty message')
|
||||
expect(result.error?.message).toContain('finish=stop')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -622,7 +623,7 @@ describe('git.suggest-message: answer shape and error mapping', () => {
|
||||
expect(result.error?.message).toContain('no pending changes')
|
||||
expect(harness.calls).toHaveLength(0)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -645,7 +646,7 @@ describe('git.suggest-message: repository safety', () => {
|
||||
expect(user).toContain('+STAGED-EDIT')
|
||||
expect(user).not.toContain('UNSTAGED-EDIT')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -676,7 +677,7 @@ describe('git.suggest-message: repository safety', () => {
|
||||
expect(gitRun(dir, ['rev-parse', 'HEAD'])).toBe(before.head)
|
||||
expect(readFileSync(join(dir, 'a.txt'), 'utf8')).toBe(before.content)
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1,9 +1,10 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { mkdirSync, mkdtempSync, realpathSync, renameSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, realpathSync, renameSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { parseWorktreeList, resolveWorktree, runGit, status, worktrees } from '../src/git.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
const IDENTITY = {
|
||||
GIT_AUTHOR_NAME: 'dsh-better-sidebar-test',
|
||||
@@ -89,7 +90,7 @@ describe('linked Git worktrees', () => {
|
||||
// Git retains administrative metadata after a checkout directory is
|
||||
// deleted, reporting the record as prunable. It must disappear from both
|
||||
// the selector inventory and the accepted command-target allowlist.
|
||||
rmSync(agent, { recursive: true, force: true })
|
||||
removeTree(agent)
|
||||
const remaining = await worktrees(main)
|
||||
expect(remaining).toHaveLength(1)
|
||||
expect(resolve(remaining[0]!.path)).toBe(resolve(realpathSync.native(main)))
|
||||
@@ -97,7 +98,7 @@ describe('linked Git worktrees', () => {
|
||||
await expect(resolveWorktree(main, agentPath)).rejects.toThrow('unknown linked worktree')
|
||||
} finally {
|
||||
try { git(main, ['worktree', 'remove', '--force', agent]) } catch { /* fixture may not be fully initialized */ }
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -129,7 +130,7 @@ describe('linked Git worktrees', () => {
|
||||
// still expand the same tree file by file.
|
||||
expect((await status(main)).entries).toHaveLength(50)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -186,7 +187,7 @@ describe('linked Git worktrees', () => {
|
||||
}, { additions: 0, deletions: 0 })
|
||||
expect(totals).toEqual({ additions: 3, deletions: 0 })
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -226,7 +227,7 @@ describe('linked Git worktrees', () => {
|
||||
expect(result.entries).toHaveLength(renames)
|
||||
expect(result.truncated).toBe(false)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -245,7 +246,7 @@ describe('linked Git worktrees', () => {
|
||||
// is unaffected without the option.
|
||||
await expect(runGit(root, ['show', 'HEAD:big.txt'])).resolves.toHaveLength(256 * 1024)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -276,7 +277,7 @@ describe('linked Git worktrees', () => {
|
||||
// A complete prefix of the same answer, not a scrambled one.
|
||||
expect(all.startsWith(fields.slice(0, 1_000).join('\0'))).toBe(true)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
})
|
||||
+7
-6
@@ -1,5 +1,5 @@
|
||||
import { execFile, execFileSync } from 'node:child_process'
|
||||
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, readFileSync, realpathSync, writeFileSync } from 'node:fs'
|
||||
import { mkdir, mkdtemp, rm } from 'node:fs/promises'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
@@ -7,6 +7,7 @@ import { promisify } from 'node:util'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { parseUnifiedDiff } from '../src/client/diff/rows.ts'
|
||||
import { checkout, parseLogLines, parseNumstat, parsePorcelainZ, repoRoots, status } from '../src/git.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
const execFileAsync = promisify(execFile)
|
||||
const normalizePath = (path: string): string => path.replaceAll('\\', '/')
|
||||
@@ -78,7 +79,7 @@ describe('git parsing', () => {
|
||||
expect(paths).toContain('newdir/a.ts')
|
||||
expect(paths.some(path => path.endsWith('/'))).toBe(false)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -97,7 +98,7 @@ describe('git parsing', () => {
|
||||
expect(result.entries).toHaveLength(2_000)
|
||||
expect(result.truncated).toBe(true)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -110,7 +111,7 @@ describe('git parsing', () => {
|
||||
expect(result.entries).toHaveLength(3)
|
||||
expect(result.truncated).toBe(false)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -294,7 +295,7 @@ describe('git parsing', () => {
|
||||
expect(execFileSync('git', ['rev-parse', '--abbrev-ref', 'HEAD'], { cwd: root, encoding: 'utf8' }).trim())
|
||||
.toBe('other')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -404,7 +405,7 @@ describe('numstat line counts (#131)', () => {
|
||||
expect(byPath.get('untracked.txt')).toEqual({ path: 'untracked.txt', xy: '??' })
|
||||
expect(byPath.has('renamed.txt')).toBe(false)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1,9 +1,10 @@
|
||||
import { spawnSync } from 'node:child_process'
|
||||
import { mkdtempSync, mkdirSync, readFileSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { delimiter, join, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url)))
|
||||
const INSTALLER = resolve(ROOT, 'scripts/install.ps1')
|
||||
@@ -66,7 +67,7 @@ function assertInMemoryInvocation(executable: string): void {
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
for (const dir of tempDirs.splice(0)) rmSync(dir, { recursive: true, force: true })
|
||||
for (const dir of tempDirs.splice(0)) removeTree(dir)
|
||||
})
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,11 +22,12 @@
|
||||
* script rebuilds the gitignored lib/, like the release flow does).
|
||||
*/
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs'
|
||||
import { existsSync, mkdtempSync, readFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url)))
|
||||
|
||||
@@ -63,7 +64,7 @@ function packedManifest(): Record<string, unknown> {
|
||||
execFileSync('tar', ['-xzf', `${pkg.name}-${pkg.version}.tgz`, 'package/package.json'], { cwd: dir, stdio: 'pipe' })
|
||||
return JSON.parse(readFileSync(join(dir, 'package/package.json'), 'utf8')) as Record<string, unknown>
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
* present on disk but not listed, both look fine in the source tree).
|
||||
*/
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync } from 'node:fs'
|
||||
import { existsSync, mkdtempSync, readFileSync, readdirSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join, resolve } from 'node:path'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
const ROOT = resolve(fileURLToPath(new URL('..', import.meta.url)))
|
||||
|
||||
@@ -126,7 +127,7 @@ describe('DSH plugin presentation metadata', () => {
|
||||
expect(files, `${LOCALE_DIR}/${name} must be published`).toContain(`package/${LOCALE_DIR}/${name}`)
|
||||
}
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
}, 120_000)
|
||||
})
|
||||
@@ -10,7 +10,7 @@
|
||||
* are what the dispatch depends on.
|
||||
*/
|
||||
import { afterEach, describe, expect, it } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import type { ChildProcess } from 'node:child_process'
|
||||
import { PassThrough } from 'node:stream'
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
usableEngines,
|
||||
} from '../src/search-engines.ts'
|
||||
import type { EngineProbe } from '../src/search-engines.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
const fdProbe: EngineProbe = { engine: 'fd', binary: '/fake/fd' }
|
||||
const rgProbe: EngineProbe = { engine: 'rg', binary: '/fake/rg' }
|
||||
@@ -517,7 +518,7 @@ describe('real engines (only when installed)', () => {
|
||||
const literal = await searchFiles(dir, meta.query)
|
||||
expect(literal.matches).toEqual([meta.file])
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
||||
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdirSync, mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { resolveSessionPath } from '../src/session-path.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
const WSL_CWD = '\\\\wsl.localhost\\archlinux\\home\\zdaar\\project'
|
||||
|
||||
@@ -83,7 +84,7 @@ describe('resolveSessionPath (dsh-remote mirror)', () => {
|
||||
})
|
||||
|
||||
afterAll(() => {
|
||||
rmSync(dshHome, { recursive: true, force: true })
|
||||
removeTree(dshHome)
|
||||
})
|
||||
|
||||
fsBackedIt('maps a remote workspace file onto the local mirror', () => {
|
||||
|
||||
+38
-37
@@ -18,6 +18,7 @@ import { downloadUrl, htmlUrl } from '../src/client/api.ts'
|
||||
import * as git from '../src/git.ts'
|
||||
import { listDirectory } from '../src/fs-tree.ts'
|
||||
import type { SidebarWebRoute, SidebarWebUpgradeRoute } from '../src/context-types.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
/**
|
||||
* The probe-budget factory is spied on so a batch's gate SHARING is asserted
|
||||
@@ -48,7 +49,7 @@ const canCreateSymlink = (() => {
|
||||
} catch {
|
||||
return false
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})()
|
||||
|
||||
@@ -237,7 +238,7 @@ describe('host plugin smoke', () => {
|
||||
expect(response.headers.get('content-type')).toBe('text/html; charset=utf-8')
|
||||
} finally {
|
||||
for (const cleanup of effects) cleanup()
|
||||
rmSync(directory, { recursive: true, force: true })
|
||||
removeTree(directory)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -376,7 +377,7 @@ describe('git destructive operations (scratch repository)', () => {
|
||||
expect(staged).toContain('-two')
|
||||
expect(staged).toContain('+CHANGED')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -400,7 +401,7 @@ describe('git destructive operations (scratch repository)', () => {
|
||||
expect(readFileSync(join(dir, 'pkg', 'README.md'), 'utf8')).toBe('pkg-DIRTY\n')
|
||||
expect(gitRun(dir, ['status', '--porcelain'])).toBe(' M pkg/README.md\n')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -415,7 +416,7 @@ describe('git destructive operations (scratch repository)', () => {
|
||||
expect(readFileSync(join(dir, 'a.txt'), 'utf8')).toBe('one\ntwo\nthree\n')
|
||||
expect((await git.log(dir))[0]!.subject).toBe('Revert "change"')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -432,7 +433,7 @@ describe('git destructive operations (scratch repository)', () => {
|
||||
expect(readFileSync(join(dir, 'b.txt'), 'utf8')).toBe('feature work\n')
|
||||
expect((await git.log(dir))[0]!.subject).toBe('feature work')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -443,7 +444,7 @@ describe('git destructive operations (scratch repository)', () => {
|
||||
await expect(git.revert(dir, 'deadbeef00000000000000000000000000000000')).rejects.toThrow()
|
||||
await expect(git.cherryPick(dir, 'deadbeef00000000000000000000000000000000')).rejects.toThrow()
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -466,7 +467,7 @@ describe('git destructive operations (scratch repository)', () => {
|
||||
await expect(git.revert(dir, '--abort')).rejects.toThrow()
|
||||
await expect(git.cherryPick(dir, '--abort')).rejects.toThrow()
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -479,7 +480,7 @@ describe('git destructive operations (scratch repository)', () => {
|
||||
gitRun(dir, ['add', 'a.txt'])
|
||||
await expect(git.show(dir, ':0', 'a.txt')).resolves.toContain('staged-change')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -626,7 +627,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(await invoke(route, 'git.log', { ...base, repoRoot: b, worktree })).toMatchObject({ ok: false })
|
||||
}
|
||||
} finally {
|
||||
rmSync(scratch, { recursive: true, force: true })
|
||||
removeTree(scratch)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -673,7 +674,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(notRepo).toMatchObject({ ok: false, status: 409, error: { code: 'not-repo' } })
|
||||
expect(notRepo.error?.message).not.toContain('internal')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -776,7 +777,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(diff).toContain('+root-DIRTY')
|
||||
expect(diff).not.toContain('pkg-DIRTY')
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -822,7 +823,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(value.path).toBe(outside)
|
||||
expect(value.entries.map(entry => entry.name)).toEqual(['secret.txt'])
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -840,7 +841,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(read.ok).toBe(true)
|
||||
expect((read.value as unknown as { kind: string; content: string }).content).toBe('secret')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -857,7 +858,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(write.ok).toBe(true)
|
||||
expect(readFileSync(written, 'utf8')).toBe('hack')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -901,7 +902,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect((await invokeGet(html, htmlUrl(scope, external))).status).toBe(400)
|
||||
expect((await invokeGet(file, downloadUrl(scope, external))).status).toBe(400)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -926,7 +927,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
const written = readFileSync(target, 'utf8')
|
||||
expect([draftA, draftB]).toContain(written)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -949,7 +950,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(write.ok).toBe(true)
|
||||
expect(readFileSync(target).equals(encodeText(text, 'gbk'))).toBe(true)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -983,7 +984,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(typeof value?.head).toBe('string')
|
||||
expect(Buffer.from(value!.head!, 'base64').length).toBe(4096)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1001,7 +1002,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(await invokeGet(file, downloadUrl({ sessionId: 'home' }, `~/${dirName}/note.txt`)))
|
||||
.toMatchObject({ status: 200, body: 'home sweet home' })
|
||||
} finally {
|
||||
rmSync(dir, { recursive: true, force: true })
|
||||
removeTree(dir)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1032,7 +1033,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(htmlResult).toMatchObject({ status: 200 })
|
||||
expect(htmlResult.body).toContain('outside')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1055,7 +1056,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(res.headers['content-security-policy']).toContain('sandbox')
|
||||
expect(res.headers['x-content-type-options']).toBe('nosniff')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1076,7 +1077,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(res.headers['content-type']).toBe('image/png')
|
||||
expect(res.headers['content-security-policy']).toBeUndefined()
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1089,7 +1090,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
const tree = await invoke(route, 'fs.tree', { sessionId: 'security', path: join(workspace, 'missing') })
|
||||
expect(tree).toMatchObject({ ok: false, status: 400, error: { code: 'fs-error' } })
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1119,7 +1120,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(levels[2]!.truncated).toBe(false)
|
||||
expect(levels[2]!.error).toMatch(/missing/)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1140,7 +1141,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect((single.value as unknown as { entries: Array<{ name: string }> }).entries.map(entry => entry.name))
|
||||
.toEqual(level.entries.map(entry => entry.name))
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1177,7 +1178,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
const plainLevels = (plain.value as unknown as { levels: Array<{ entries: Array<{ name: string }> }> }).levels
|
||||
expect(plainLevels[0]!.entries.map(entry => entry.name)).toEqual(['src', 'third_party', '.DS_Store'])
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1206,7 +1207,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
const anchored = await invoke(route, 'fs.search', { sessionId: 's-search', query: './src/index.ts' })
|
||||
expect(anchored.value).toEqual({ matches: [join(workspace, 'src', 'index.ts')], dirs: [], truncated: false })
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1224,7 +1225,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
})
|
||||
expect(tooMany).toMatchObject({ ok: false, status: 400, error: { code: 'bad-request' } })
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1252,7 +1253,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
}).levels
|
||||
expect(levels.find(entry => entry.path === level)?.entries.filter(row => row.compact === true)).toHaveLength(3)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1273,7 +1274,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
const entries = (answer.value as unknown as { entries: { compact?: boolean }[] }).entries
|
||||
expect(entries.filter(entry => entry.compact === true)).toHaveLength(1)
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1292,7 +1293,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(tree.ok).toBe(true)
|
||||
expect((tree.value as unknown as { entries: Array<{ name: string }> }).entries.map(entry => entry.name)).toEqual(['secret.txt'])
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1310,7 +1311,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
expect(read.ok).toBe(true)
|
||||
expect((read.value as unknown as { content: string }).content).toBe('secret')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1328,7 +1329,7 @@ describe('session cwd resolution over the API route', () => {
|
||||
// The write landed on the link's TARGET (the link is not replaced).
|
||||
expect(readFileSync(join(outside, 'new.txt'), 'utf8')).toBe('hack')
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1598,7 +1599,7 @@ describe('side card settings routes', () => {
|
||||
expect(row?.value).not.toHaveProperty('browserInterceptHttp')
|
||||
expect(row?.revision).toBe(1)
|
||||
} finally {
|
||||
rmSync(home, { recursive: true, force: true })
|
||||
removeTree(home)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1615,7 +1616,7 @@ describe('side card settings routes', () => {
|
||||
expect(row?.value).toMatchObject({ editorExplorer: true, agentOpenTools: false })
|
||||
expect(row?.revision).toBe(0)
|
||||
} finally {
|
||||
rmSync(home, { recursive: true, force: true })
|
||||
removeTree(home)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1646,7 +1647,7 @@ describe('side card settings routes', () => {
|
||||
const stillOpen = await invoke(route, 'fs.read', { sessionId: 'fence', cwd: workspace, path: join(outside, 'secret.txt') })
|
||||
expect(stillOpen).toMatchObject({ ok: true })
|
||||
} finally {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* Temp-tree removal for specs that spawn real child processes or hold OS
|
||||
* handles (zip / tar / git / fd / rg / powershell / `fs.watch`) inside the
|
||||
* tree they are about to delete.
|
||||
*
|
||||
* `rmSync(path, { recursive: true, force: true })` is not enough on Windows:
|
||||
* a child that was just killed, or a watcher that was just closed, can still
|
||||
* hold a handle for a few milliseconds, and the removal then fails with
|
||||
* ENOTEMPTY / EBUSY / EPERM **from the cleanup of a test that had already
|
||||
* passed** — which is how the Windows lane went red on 2026-10-15
|
||||
* (`tests/archive.spec.ts`'s afterEach, `ENOTEMPTY: rmdir …archives-pvpAWR`,
|
||||
* on a run where only that cleanup failed and 2466 tests passed).
|
||||
*
|
||||
* `maxRetries` + `retryDelay` is Node's own remedy for exactly this, so every
|
||||
* risky cleanup goes through here instead of repeating the retry inline.
|
||||
* POSIX runs are unaffected: the first attempt succeeds and no retry happens.
|
||||
*/
|
||||
import { rmSync } from 'node:fs'
|
||||
|
||||
/**
|
||||
* Remove one file or directory tree, retrying while a just-closed handle is
|
||||
* still being released by the OS.
|
||||
* @param path - file or directory to remove (missing paths are ignored).
|
||||
*/
|
||||
export function removeTree(path: string): void {
|
||||
rmSync(path, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 })
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import { afterAll, describe, expect, it } from 'vitest'
|
||||
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { tmpdir } from 'node:os'
|
||||
import {
|
||||
@@ -10,6 +10,7 @@ import {
|
||||
restoreEol,
|
||||
type TextEncoding,
|
||||
} from '../src/text-encoding.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
const root = mkdtempSync(join(tmpdir(), 'dsh-sidebar-encoding-'))
|
||||
|
||||
@@ -25,7 +26,7 @@ const ROUND_TRIPS: [TextEncoding, string][] = [
|
||||
]
|
||||
|
||||
afterAll(() => {
|
||||
rmSync(root, { recursive: true, force: true })
|
||||
removeTree(root)
|
||||
})
|
||||
|
||||
describe('text encoding', () => {
|
||||
|
||||
@@ -15,13 +15,14 @@
|
||||
* name.
|
||||
*/
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { mkdtempSync, rmSync, writeFileSync } from 'node:fs'
|
||||
import { mkdtempSync, writeFileSync } from 'node:fs'
|
||||
import { Writable } from 'node:stream'
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http'
|
||||
import { tmpdir } from 'node:os'
|
||||
import { join } from 'node:path'
|
||||
import { apply } from '../src/index.ts'
|
||||
import type { SidebarWebRoute, SidebarWebUpgradeRoute } from '../src/context-types.ts'
|
||||
import { removeTree } from './temp-tree.ts'
|
||||
|
||||
interface FakeRes {
|
||||
status: number
|
||||
@@ -274,7 +275,7 @@ describe('remote-access trust (webRuntime.trustedHosts)', () => {
|
||||
return { status: res.status, headers: res.headers }
|
||||
} finally {
|
||||
cleanup()
|
||||
rmSync(directory, { recursive: true, force: true })
|
||||
removeTree(directory)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user