continue-custom/extensions/cli/vitest.setup.ts
Aditya Mitra df98f99976
fix(cli): load rules into system message (#10408)
* fix(cli): load rules into system message

* show loaded rules in config

* Update extensions/cli/src/systemMessage.ts

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* fix config service tests

* fix tests

---------

Co-authored-by: Nate Sesti <33237525+sestinj@users.noreply.github.com>
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2026-03-20 16:30:11 -07:00

75 lines
2.1 KiB
TypeScript

import { vi } from "vitest";
import { resetConsoleOverrides } from "./src/init.js";
// Disable telemetry for tests
process.env.CONTINUE_CLI_ENABLE_TELEMETRY = "0";
process.env.CONTINUE_ALLOW_ANONYMOUS_TELEMETRY = "0";
// Mock fetch to prevent actual API calls in tests
const originalFetch = global.fetch;
global.fetch = vi
.fn()
.mockImplementation(async (url: string | URL, ...args) => {
const urlString = url.toString();
// Mock the default config API call
if (urlString.includes("get-assistant/continuedev/default-cli-config")) {
return {
ok: true,
status: 200,
json: async () => ({
configResult: {
config: {
name: "Default Config",
version: "0.0.1",
schema: "v1",
models: [
{
provider: "anthropic",
name: "claude-sonnet-4-5",
apiKey: "test-key",
roles: ["chat"],
},
],
rules: [],
mcpServers: [],
},
errors: [],
},
}),
};
}
return originalFetch(url, ...args);
});
// Mock the 'open' package to prevent browser opening during tests
vi.mock("open", () => ({
default: vi.fn().mockResolvedValue(undefined),
}));
// Mock constructSystemMessage to avoid service container issues in tests
vi.mock("./src/systemMessage.js", () => ({
constructSystemMessage: vi
.fn()
.mockResolvedValue(
"You are an agent in the Continue CLI. Given the user's prompt, you should use the tools available to you to answer the user's question.",
),
loadMarkdownRulesWithMetadata: vi.fn().mockReturnValue([]),
}));
// Mock environment for tests
process.env.CONTINUE_GLOBAL_DIR = "/tmp/continue-test";
// Set up global afterEach hook to clear all timers and reset console
afterEach(() => {
// Clear vitest timers
vi.clearAllTimers();
// Reset console overrides to ensure clean state for each test
try {
resetConsoleOverrides();
} catch {
// Ignore errors when resetting console
}
});