Skip to content

Commit a054c6d

Browse files
committed
fix(cli): fix test isolation for model-persistence tests
Mock core/util/paths.js to read CONTINUE_GLOBAL_DIR dynamically instead of caching it at module load time. This fixes test isolation issues where tests running in parallel would share the same GlobalContext file path. Root cause: The CONTINUE_GLOBAL_DIR constant in core/util/paths.ts is computed via an IIFE at module load time. When tests set different temp directories in beforeEach, the module had already cached the original value. Solution: Mock getContinueGlobalPath, getIndexFolderPath, and getGlobalContextFilePath to read process.env.CONTINUE_GLOBAL_DIR on each call, allowing proper test isolation. Also fixes prettier formatting in markdown files. Authored by: Aaron Lippold<lippold@gmail.com>
1 parent d90c4eb commit a054c6d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

extensions/cli/vitest.setup.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import * as fs from "fs";
2+
import * as path from "path";
3+
14
import { vi } from "vitest";
25

36
import { resetConsoleOverrides } from "./src/init.js";
@@ -6,6 +9,42 @@ import { resetConsoleOverrides } from "./src/init.js";
69
process.env.CONTINUE_CLI_ENABLE_TELEMETRY = "0";
710
process.env.CONTINUE_ALLOW_ANONYMOUS_TELEMETRY = "0";
811

12+
// Mock core/util/paths to read CONTINUE_GLOBAL_DIR dynamically
13+
// This fixes test isolation issues where the module caches the env var at load time
14+
vi.mock("core/util/paths.js", async (importOriginal) => {
15+
const actual = await importOriginal<typeof import("core/util/paths.js")>();
16+
17+
// Create a dynamic version of getContinueGlobalPath that reads env var each time
18+
const getContinueGlobalPath = () => {
19+
const continuePath =
20+
process.env.CONTINUE_GLOBAL_DIR ||
21+
path.join(process.env.HOME || "", ".continue");
22+
if (!fs.existsSync(continuePath)) {
23+
fs.mkdirSync(continuePath, { recursive: true });
24+
}
25+
return continuePath;
26+
};
27+
28+
const getIndexFolderPath = () => {
29+
const indexPath = path.join(getContinueGlobalPath(), "index");
30+
if (!fs.existsSync(indexPath)) {
31+
fs.mkdirSync(indexPath, { recursive: true });
32+
}
33+
return indexPath;
34+
};
35+
36+
const getGlobalContextFilePath = () => {
37+
return path.join(getIndexFolderPath(), "globalContext.json");
38+
};
39+
40+
return {
41+
...actual,
42+
getContinueGlobalPath,
43+
getIndexFolderPath,
44+
getGlobalContextFilePath,
45+
};
46+
});
47+
948
// Mock fetch to prevent actual API calls in tests
1049
const originalFetch = global.fetch;
1150
global.fetch = vi

0 commit comments

Comments
 (0)