Skip to content

Commit bc8fcfa

Browse files
fix(clownfish): address review for symlink-test-repair-autonomous-20260621 (1)
1 parent a0808b8 commit bc8fcfa

2 files changed

Lines changed: 14 additions & 26 deletions

File tree

extensions/qqbot/src/engine/utils/file-utils.test.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,15 @@ describe("qqbot file-utils MIME helpers", () => {
4040
});
4141
});
4242

43-
async function canCreateFileSymlink(): Promise<boolean> {
44-
const probeDir = await fs.promises.mkdtemp(path.join(os.tmpdir(), "qqbot-symlink-probe-"));
45-
const targetPath = path.join(probeDir, "target.txt");
46-
const linkPath = path.join(probeDir, "link.txt");
43+
async function createSymlinkedFile(targetPath: string, linkPath: string): Promise<boolean> {
4744
try {
48-
await fs.promises.writeFile(targetPath, "probe");
45+
await fs.promises.writeFile(targetPath, "image-bytes");
4946
await fs.promises.symlink(targetPath, linkPath, "file");
5047
return true;
5148
} catch {
49+
await fs.promises.rm(linkPath, { force: true });
50+
await fs.promises.rm(targetPath, { force: true });
5251
return false;
53-
} finally {
54-
await fs.promises.rm(probeDir, { recursive: true, force: true });
5552
}
5653
}
5754

@@ -115,14 +112,11 @@ describe("qqbot file-utils downloadFile", () => {
115112
// Keep the local skipIf shape while probing inside the test, avoiding
116113
// import-time filesystem side effects on hosts that cannot create links.
117114
it.skipIf(false)("rejects symlinked local media helpers", async ({ skip }) => {
118-
if (!(await canCreateFileSymlink())) {
119-
skip("file symlinks are unavailable on this host");
120-
}
121-
122115
const targetPath = path.join(tempDir, "target.png");
123116
const linkPath = path.join(tempDir, "link.png");
124-
await fs.promises.writeFile(targetPath, "image-bytes");
125-
await fs.promises.symlink(targetPath, linkPath, "file");
117+
if (!(await createSymlinkedFile(targetPath, linkPath))) {
118+
skip("file symlinks are unavailable on this host");
119+
}
126120

127121
expect(checkFileSize(linkPath).ok).toBe(false);
128122
await expect(readFileAsync(linkPath)).rejects.toThrow(/symbolic link|symlink|regular file/i);

extensions/zalo/src/token.test.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@ import { describe, expect, it } from "vitest";
66
import { resolveZaloToken } from "./token.js";
77
import type { ZaloConfig } from "./types.js";
88

9-
function canCreateFileSymlink(): boolean {
10-
const probeDir = fs.mkdtempSync(path.join(os.tmpdir(), "zalo-symlink-probe-"));
11-
const targetPath = path.join(probeDir, "target.txt");
12-
const linkPath = path.join(probeDir, "link.txt");
9+
function createSymlinkedFile(targetPath: string, linkPath: string): boolean {
1310
try {
14-
fs.writeFileSync(targetPath, "probe", "utf8");
11+
fs.writeFileSync(targetPath, "file-token\n", "utf8");
1512
fs.symlinkSync(targetPath, linkPath, "file");
1613
return true;
1714
} catch {
15+
fs.rmSync(linkPath, { force: true });
16+
fs.rmSync(targetPath, { force: true });
1817
return false;
19-
} finally {
20-
fs.rmSync(probeDir, { recursive: true, force: true });
2118
}
2219
}
2320

@@ -95,14 +92,11 @@ describe("resolveZaloToken", () => {
9592
it.runIf(true)("rejects symlinked token files", ({ skip }) => {
9693
const dir = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-zalo-token-"));
9794
try {
98-
if (!canCreateFileSymlink()) {
99-
skip("file symlinks are unavailable on this host");
100-
}
101-
10295
const tokenFile = path.join(dir, "token.txt");
10396
const tokenLink = path.join(dir, "token-link.txt");
104-
fs.writeFileSync(tokenFile, "file-token\n", "utf8");
105-
fs.symlinkSync(tokenFile, tokenLink, "file");
97+
if (!createSymlinkedFile(tokenFile, tokenLink)) {
98+
skip("file symlinks are unavailable on this host");
99+
}
106100

107101
const cfg = {
108102
tokenFile: tokenLink,

0 commit comments

Comments
 (0)