Skip to content

Commit f6cd721

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 f6cd721

4 files changed

Lines changed: 39 additions & 8 deletions

File tree

extensions/cli/AGENTS.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,25 @@ This is a CLI tool for Continue Dev that provides an interactive AI-assisted dev
1818
### Core Components
1919

2020
1. **Entry Point** (`src/index.ts`): Main CLI logic with two modes:
21-
2221
- **Headless mode**: Non-interactive mode for automation/CI
2322
- **TUI mode**: Terminal User Interface using Ink/React
2423
- **Standard mode**: Traditional readline-based chat interface
2524

2625
2. **Authentication** (`src/auth/`): WorkOS-based authentication system
27-
2826
- `ensureAuth.ts`: Handles authentication flow
2927
- `workos.ts`: WorkOS configuration and token management
3028

3129
3. **Continue SDK Integration** (`src/continueSDK.ts`): Initializes the Continue SDK client with:
32-
3330
- API key authentication
3431
- Assistant configuration (slug-based)
3532
- Organization support
3633

3734
4. **Terminal UI** (`src/ui/`): React/Ink-based TUI components
38-
3935
- `TUIChat.tsx`: Main chat interface component
4036
- `UserInput.tsx`: Input handling with multi-line support
4137
- `TextBuffer.ts`: Text display utilities
4238

4339
5. **Tools System** (`src/tools/`): Built-in development tools including:
44-
4540
- File operations (read, write, list)
4641
- Code search functionality
4742
- Terminal command execution

extensions/cli/spec/config-loading.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,11 @@ This document specifies the behavior of the CLI's configuration loading system,
2323
**When CLI is invoked, config source is determined in this order:**
2424

2525
1. **CLI `--config` Flag** (highest priority)
26-
2726
- File path (starts with `.`, `/`, `~`): Loads local YAML file
2827
- Assistant slug (`owner/package`): Fetches from Continue platform
2928
- Overrides any saved preferences
3029

3130
2. **Saved Config URI** (if no `--config` flag)
32-
3331
- Retrieved from authentication config
3432
- Converts `file://` URIs back to file paths
3533
- Converts `slug://` URIs back to assistant slugs

extensions/cli/spec/onboarding.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ When a user first runs `cn` in interactive mode, they will be taken through "onb
99
1. If the --config flag is provided, load this config
1010
2. If the CONTINUE_USE_BEDROCK environment variable is set to "1", automatically use AWS Bedrock configuration and skip interactive prompts
1111
3. Present the user with available options:
12-
1312
- Log in with Continue: log them in, which will automatically create their assistant and then we can load the first assistant from the first org
1413
- Enter your Anthropic API key: let them enter the key, and then either create a ~/.continue/config.yaml with the following contents OR update the existing config.yaml to add the model
1514

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)