Skip to content

Commit 4bde313

Browse files
committed
Add localeCompare tests
1 parent f9f7e69 commit 4bde313

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

test/unit/remote/sshProcess.test.ts

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,27 @@ describe("SshProcessMonitor", () => {
127127
expect(find).toHaveBeenCalledWith("port", 33333);
128128
});
129129

130+
it("sorts output_logging_ directories using localeCompare for consistent ordering", async () => {
131+
// localeCompare differs from default sort() for mixed case
132+
vol.fromJSON({
133+
"/logs/output_logging_a/1-Remote - SSH.log": "-> socksPort 11111 ->",
134+
"/logs/output_logging_Z/1-Remote - SSH.log": "-> socksPort 22222 ->",
135+
});
136+
137+
mockReaddirOrder("/logs", [
138+
"output_logging_a",
139+
"output_logging_Z",
140+
"window1",
141+
]);
142+
143+
const monitor = createMonitor({ codeLogDir: "/logs/window1" });
144+
await waitForEvent(monitor.onPidChange);
145+
146+
// With localeCompare: ["a", "Z"] -> reversed -> "Z" first (port 22222)
147+
// With plain sort(): ["Z", "a"] -> reversed -> "a" first (port 11111)
148+
expect(find).toHaveBeenCalledWith("port", 22222);
149+
});
150+
130151
it("falls back to output_logging_ when extension folder has no SSH log", async () => {
131152
// Extension folder exists but doesn't have Remote SSH log
132153
vol.fromJSON({
@@ -301,6 +322,28 @@ describe("SshProcessMonitor", () => {
301322

302323
expect(logPath).toBe("/proxy-logs/2024-01-03-999.log");
303324
});
325+
326+
it("sorts log files using localeCompare for consistent cross-platform ordering", async () => {
327+
// localeCompare differs from default sort() for mixed case
328+
vol.fromJSON({
329+
"/logs/ms-vscode-remote.remote-ssh/1-Remote - SSH.log":
330+
"-> socksPort 12345 ->",
331+
"/proxy-logs/a-999.log": "",
332+
"/proxy-logs/Z-999.log": "",
333+
});
334+
335+
mockReaddirOrder("/proxy-logs", ["a-999.log", "Z-999.log"]);
336+
337+
const monitor = createMonitor({
338+
codeLogDir: "/logs/window1",
339+
proxyLogDir: "/proxy-logs",
340+
});
341+
const logPath = await waitForEvent(monitor.onLogFilePathChange);
342+
343+
// With localeCompare: ["a", "Z"] -> reversed -> "Z" first
344+
// With plain sort(): ["Z", "a"] -> reversed -> "a" first (WRONG)
345+
expect(logPath).toBe("/proxy-logs/Z-999.log");
346+
});
304347
});
305348

306349
describe("network status", () => {
@@ -483,7 +526,7 @@ function mockReaddirOrder(dirPath: string, files: string[]): void {
483526
if (path === dirPath) {
484527
return Promise.resolve(files);
485528
}
486-
return originalReaddir(path) as Promise<string[]>;
529+
return originalReaddir(path);
487530
};
488531
vi.spyOn(fsPromises, "readdir").mockImplementation(
489532
mockImpl as typeof fsPromises.readdir,

0 commit comments

Comments
 (0)