惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Jina AI
Jina AI
云风的 BLOG
云风的 BLOG
人人都是产品经理
人人都是产品经理
T
The Blog of Author Tim Ferriss
阮一峰的网络日志
阮一峰的网络日志
罗磊的独立博客
J
Java Code Geeks
博客园 - 聂微东
B
Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
腾讯CDC
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
Microsoft Azure Blog
Microsoft Azure Blog
D
DataBreaches.Net
The GitHub Blog
The GitHub Blog
美团技术团队
博客园 - Franky
Google DeepMind News
Google DeepMind News
V
V2EX
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
The Cloudflare Blog

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix: use fs-safe trash for agent delete (#84394) · opencl...
ferminquant · 2026-05-23 · via Recent Commits to openclaw:main

@@ -1,4 +1,5 @@

11

import * as fs from "node:fs";

2+

import fsPromises from "node:fs/promises";

23

import os from "node:os";

34

import path from "node:path";

45

import { afterEach, describe, expect, it, vi } from "vitest";

@@ -7,6 +8,7 @@ import { withMockedPlatform } from "../test-utils/vitest-spies.js";

78

import {

89

formatControlUiSshHint,

910

handleReset,

11+

moveToTrash,

1012

normalizeGatewayTokenInput,

1113

openUrl,

1214

probeGatewayReachable,

@@ -17,6 +19,7 @@ import {

1719

} from "./onboard-helpers.js";

18201921

const mocks = vi.hoisted(() => ({

22+

movePathToTrash: vi.fn(async (targetPath: string) => `${targetPath}.trashed`),

2023

runCommandWithTimeout: vi.fn<

2124

(

2225

argv: string[],

@@ -33,6 +36,10 @@ const mocks = vi.hoisted(() => ({

3336

probeGateway: vi.fn(),

3437

}));

353839+

vi.mock("../infra/fs-safe.js", () => ({

40+

movePathToTrash: mocks.movePathToTrash,

41+

}));

42+3643

vi.mock("../process/exec.js", () => ({

3744

runCommandWithTimeout: mocks.runCommandWithTimeout,

3845

}));

@@ -89,9 +96,13 @@ describe("handleReset", () => {

89969097

const runtime = { log: vi.fn() } as unknown as RuntimeEnv;

919892-

await handleReset("full", workspaceDir, runtime);

99+

try {

100+

await handleReset("full", workspaceDir, runtime);

101+

} finally {

102+

fs.rmSync(homeDir, { recursive: true, force: true });

103+

}

9310494-

const trashedPaths = mocks.runCommandWithTimeout.mock.calls.map(([argv]) => argv[1]);

105+

const trashedPaths = mocks.movePathToTrash.mock.calls.map(([targetPath]) => targetPath);

95106

expect(trashedPaths).toEqual([

96107

profileConfigPath,

97108

profileCredentialsDir,

@@ -102,6 +113,78 @@ describe("handleReset", () => {

102113

});

103114

});

104115116+

describe("moveToTrash", () => {

117+

it("uses fs-safe trash instead of resolving a PATH trash command", async () => {

118+

const testRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-trash-helper-"));

119+

const targetPath = path.join(testRoot, "target");

120+

fs.mkdirSync(targetPath, { recursive: true });

121+

const runtime = { log: vi.fn() } as unknown as RuntimeEnv;

122+123+

try {

124+

await moveToTrash(targetPath, runtime);

125+

} finally {

126+

fs.rmSync(testRoot, { recursive: true, force: true });

127+

}

128+129+

expect(mocks.movePathToTrash).toHaveBeenCalledWith(targetPath, {

130+

allowedRoots: [path.dirname(targetPath)],

131+

});

132+

expect(mocks.runCommandWithTimeout).not.toHaveBeenCalled();

133+

expect(runtime.log).toHaveBeenCalledWith(`Moved to Trash: ${targetPath}`);

134+

});

135+136+

it("allows fs-safe trash to move a symlink whose target resolves outside the parent", async () => {

137+

const testRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-trash-symlink-"));

138+

const targetPath = path.join(testRoot, "target-link");

139+

const outsideTarget = path.join(os.tmpdir(), "openclaw-trash-symlink-target");

140+

fs.writeFileSync(targetPath, "link placeholder");

141+

vi.spyOn(fsPromises, "lstat").mockResolvedValue({

142+

isSymbolicLink: () => true,

143+

} as fs.Stats);

144+

vi.spyOn(fsPromises, "realpath").mockImplementation(async (candidate) =>

145+

String(candidate) === path.dirname(targetPath) ? path.dirname(targetPath) : outsideTarget,

146+

);

147+

const runtime = { log: vi.fn() } as unknown as RuntimeEnv;

148+149+

try {

150+

await moveToTrash(targetPath, runtime);

151+

} finally {

152+

fs.rmSync(testRoot, { recursive: true, force: true });

153+

}

154+155+

expect(mocks.movePathToTrash).toHaveBeenCalledWith(targetPath, {

156+

allowedRoots: [path.dirname(targetPath), path.dirname(outsideTarget)],

157+

});

158+

});

159+160+

it("canonicalizes a symlinked parent before calling fs-safe trash", async () => {

161+

const testRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-trash-parent-link-"));

162+

const lexicalParent = path.join(testRoot, "state-link");

163+

const realParent = path.join(testRoot, "state-real");

164+

const targetPath = path.join(lexicalParent, "openclaw.json");

165+

const sourcePath = path.join(realParent, "openclaw.json");

166+

fs.mkdirSync(lexicalParent, { recursive: true });

167+

fs.writeFileSync(targetPath, "{}\n");

168+

vi.spyOn(fsPromises, "realpath").mockImplementation(async (candidate) =>

169+

String(candidate) === lexicalParent ? realParent : String(candidate),

170+

);

171+

vi.spyOn(fsPromises, "lstat").mockResolvedValue({

172+

isSymbolicLink: () => false,

173+

} as fs.Stats);

174+

const runtime = { log: vi.fn() } as unknown as RuntimeEnv;

175+176+

try {

177+

await moveToTrash(targetPath, runtime);

178+

} finally {

179+

fs.rmSync(testRoot, { recursive: true, force: true });

180+

}

181+182+

expect(mocks.movePathToTrash).toHaveBeenCalledWith(sourcePath, {

183+

allowedRoots: [realParent],

184+

});

185+

});

186+

});

187+105188

describe("openUrl", () => {

106189

it("passes OAuth URLs to Windows FileProtocolHandler without cmd parsing", async () => {

107190

vi.stubEnv("VITEST", "");