Skip to content

Commit 053960a

Browse files
committed
fix: cross-platform tests for Windows CI (clipboard + formatHomeRelativePath)
1 parent 89f015f commit 053960a

2 files changed

Lines changed: 47 additions & 37 deletions

File tree

src/tests/clipboard.test.ts

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,40 +36,44 @@ test("readClipboardImage returns null when no clipboard helpers are installed",
3636
assert.equal(result, null);
3737
});
3838

39-
test("readClipboardImage uses osascript fallback on macOS when pngpaste is missing", async () => {
40-
const binDir = fs.mkdtempSync(path.join(os.tmpdir(), "deepcode-clipboard-test-bin-"));
41-
try {
42-
fs.writeFileSync(path.join(binDir, "pngpaste"), "#!/bin/sh\nexit 1\n", { mode: 0o755 });
43-
fs.writeFileSync(
44-
path.join(binDir, "osascript"),
45-
[
46-
"#!/bin/sh",
47-
'for arg in "$@"; do',
48-
' case "$arg" in',
49-
" *'open for access POSIX file " + '"' + "'*)",
50-
' path_part=${arg#*POSIX file \\"}',
51-
' out_path=${path_part%%\\"*}',
52-
' printf fakepng > "$out_path"',
53-
" exit 0",
54-
" ;;",
55-
" esac",
56-
"done",
57-
"exit 1",
58-
"",
59-
].join("\n"),
60-
{ mode: 0o755 }
61-
);
39+
test(
40+
"readClipboardImage uses osascript fallback on macOS when pngpaste is missing",
41+
{ skip: process.platform !== "darwin" },
42+
async () => {
43+
const binDir = fs.mkdtempSync(path.join(os.tmpdir(), "deepcode-clipboard-test-bin-"));
44+
try {
45+
fs.writeFileSync(path.join(binDir, "pngpaste"), "#!/bin/sh\nexit 1\n", { mode: 0o755 });
46+
fs.writeFileSync(
47+
path.join(binDir, "osascript"),
48+
[
49+
"#!/bin/sh",
50+
'for arg in "$@"; do',
51+
' case "$arg" in',
52+
" *'open for access POSIX file " + '"' + "'*)",
53+
' path_part=${arg#*POSIX file \\"}',
54+
' out_path=${path_part%%\\"*}',
55+
' printf fakepng > "$out_path"',
56+
" exit 0",
57+
" ;;",
58+
" esac",
59+
"done",
60+
"exit 1",
61+
"",
62+
].join("\n"),
63+
{ mode: 0o755 }
64+
);
6265

63-
const moduleUrl = new URL(`../ui/clipboard.ts?t=${Date.now()}`, import.meta.url).href;
64-
const { readClipboardImage } = (await import(moduleUrl)) as ClipboardModule;
66+
const moduleUrl = new URL(`../ui/clipboard.ts?t=${Date.now()}`, import.meta.url).href;
67+
const { readClipboardImage } = (await import(moduleUrl)) as ClipboardModule;
6568

66-
process.env.PATH = binDir;
67-
const result = withPlatform("darwin", () => readClipboardImage());
68-
assert.equal(result?.mimeType, "image/png");
69-
assert.equal(result?.dataUrl, `data:image/png;base64,${Buffer.from("fakepng").toString("base64")}`);
70-
} finally {
71-
process.env.PATH = ORIGINAL_PATH;
72-
Object.defineProperty(process, "platform", { value: ORIGINAL_PLATFORM });
73-
fs.rmSync(binDir, { recursive: true, force: true });
69+
process.env.PATH = binDir;
70+
const result = withPlatform("darwin", () => readClipboardImage());
71+
assert.equal(result?.mimeType, "image/png");
72+
assert.equal(result?.dataUrl, `data:image/png;base64,${Buffer.from("fakepng").toString("base64")}`);
73+
} finally {
74+
process.env.PATH = ORIGINAL_PATH;
75+
Object.defineProperty(process, "platform", { value: ORIGINAL_PLATFORM });
76+
fs.rmSync(binDir, { recursive: true, force: true });
77+
}
7478
}
75-
});
79+
);

src/tests/welcomeScreen.test.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
import { test } from "node:test";
22
import assert from "node:assert/strict";
3+
import * as os from "node:os";
4+
import * as path from "node:path";
35
import { buildWelcomeTips, formatHomeRelativePath } from "../ui";
46

7+
const home = os.homedir();
8+
59
test("formatHomeRelativePath returns tilde for the home directory", () => {
6-
assert.equal(formatHomeRelativePath("/Users/example", "/Users/example"), "~");
10+
assert.equal(formatHomeRelativePath(home, home), "~");
711
});
812

913
test("formatHomeRelativePath shortens paths inside the home directory", () => {
10-
assert.equal(formatHomeRelativePath("/Users/example/dev/project", "/Users/example"), "~/dev/project");
14+
const subdir = path.join(home, "dev", "project");
15+
assert.equal(formatHomeRelativePath(subdir, home), `~${path.sep}dev${path.sep}project`);
1116
});
1217

1318
test("formatHomeRelativePath keeps paths outside the home directory absolute", () => {
14-
assert.equal(formatHomeRelativePath("/tmp/project", "/Users/example"), "/tmp/project");
19+
const outside = process.platform === "win32" ? "C:\\tmp\\project" : "/tmp/project";
20+
assert.equal(formatHomeRelativePath(outside, home), path.resolve(outside));
1521
});
1622

1723
test("buildWelcomeTips includes built-in slash commands and loaded skills", () => {

0 commit comments

Comments
 (0)