chore: hasDocs bool

This commit is contained in:
Dallin Romney 2025-08-18 15:41:08 -07:00
parent 9b5893e051
commit 37c1b2001f
6 changed files with 455 additions and 437 deletions

View file

@ -392,6 +392,7 @@ async function intermediateToFinalConfig({
provider: cp.name,
params: cp.params,
})),
!!config.docs?.length,
);
for (const cp of config.contextProviders ?? []) {

View file

@ -6,6 +6,7 @@ import { IContextProvider } from "..";
import { contextProviderClassFromName } from "../context/providers";
import CurrentFileContextProvider from "../context/providers/CurrentFileContextProvider";
import DiffContextProvider from "../context/providers/DiffContextProvider";
import DocsContextProvider from "../context/providers/DocsContextProvider";
import FileContextProvider from "../context/providers/FileContextProvider";
import ProblemsContextProvider from "../context/providers/ProblemsContextProvider";
import RulesContextProvider from "../context/providers/RulesContextProvider";
@ -16,12 +17,11 @@ import TerminalContextProvider from "../context/providers/TerminalContextProvide
- default providers will always be loaded, using config params if present
- other providers will be loaded if configured
Note:
- MCPContextProvider is added in doLoadConfig if any resources are present
- DocsContextProvider is added in doLoadConfig if docs configs are present and it hasn't been added yet
NOTE the MCPContextProvider is added in doLoadConfig if any resources are present
*/
export function loadConfigContextProviders(
configContext: AssistantUnrolledNonNullable["context"],
hasDocs: boolean,
): {
providers: IContextProvider[];
errors: ConfigValidationError[];
@ -68,6 +68,10 @@ export function loadConfigContextProviders(
}
}
if (hasDocs && !providers?.some((cp) => cp.description.title === "docs")) {
providers.push(new DocsContextProvider({}));
}
return {
providers,
errors,

View file

@ -61,14 +61,14 @@ const mockedContextProviderClassFromName =
typeof contextProviderClassFromName
>;
describe("loadConfigContextProviders", () => {
beforeEach(() => {
vi.clearAllMocks();
});
beforeEach(() => {
vi.clearAllMocks();
});
describe("loadConfigContextProviders", () => {
describe("with empty or undefined config", () => {
it("should return only default providers when config is undefined", () => {
const result = loadConfigContextProviders(undefined);
const result = loadConfigContextProviders(undefined, false);
expect(result.errors).toEqual([]);
expect(result.providers).toHaveLength(6);
@ -88,7 +88,7 @@ describe("loadConfigContextProviders", () => {
});
it("should return only default providers when config is empty array", () => {
const result = loadConfigContextProviders([]);
const result = loadConfigContextProviders([], false);
expect(result.errors).toEqual([]);
expect(result.providers).toHaveLength(6);
@ -107,448 +107,468 @@ describe("loadConfigContextProviders", () => {
});
});
describe("with valid config", () => {
it("should load providers from config with correct parameters", () => {
const mockProvider = vi.fn().mockImplementation((options) => ({
description: { title: "custom-provider" },
options,
})) as any;
it("should return default + docs when has docs is true", () => {
const result = loadConfigContextProviders([], true);
mockedContextProviderClassFromName.mockReturnValue(mockProvider);
expect(result.errors).toEqual([]);
expect(result.providers).toHaveLength(7);
const config = [
{
provider: "custom-provider" as any,
name: "my-custom-provider",
params: {
apiKey: "test-key",
baseUrl: "https://api.example.com",
},
},
];
const result = loadConfigContextProviders(config);
expect(result.errors).toEqual([]);
expect(mockedContextProviderClassFromName).toHaveBeenCalledWith(
"custom-provider",
);
expect(mockProvider).toHaveBeenCalledWith({
name: "my-custom-provider",
apiKey: "test-key",
baseUrl: "https://api.example.com",
});
// Should have custom provider + all defaults
expect(result.providers).toHaveLength(7);
const customProvider = result.providers.find(
(p) => p.description.title === "custom-provider",
);
expect(customProvider).toBeDefined();
expect((customProvider as any)?.options).toEqual({
name: "my-custom-provider",
apiKey: "test-key",
baseUrl: "https://api.example.com",
});
});
it("should handle multiple providers in config", () => {
const mockProvider1 = vi.fn().mockImplementation((options) => ({
description: { title: "provider-1" },
options,
})) as any;
const mockProvider2 = vi.fn().mockImplementation((options) => ({
description: { title: "provider-2" },
options,
})) as any;
mockedContextProviderClassFromName
.mockReturnValueOnce(mockProvider1)
.mockReturnValueOnce(mockProvider2);
const config = [
{
provider: "provider-1" as any,
name: "first-provider",
params: { setting1: "value1" },
},
{
provider: "provider-2" as any,
name: "second-provider",
params: { setting2: "value2" },
},
];
const result = loadConfigContextProviders(config);
expect(result.errors).toEqual([]);
expect(result.providers).toHaveLength(8); // 2 custom + 6 defaults
expect(mockProvider1).toHaveBeenCalledWith({
name: "first-provider",
setting1: "value1",
});
expect(mockProvider2).toHaveBeenCalledWith({
name: "second-provider",
setting2: "value2",
});
});
it("should handle config with empty params", () => {
const mockProvider = vi.fn().mockImplementation((options) => ({
description: { title: "no-params-provider" },
options,
})) as any;
mockedContextProviderClassFromName.mockReturnValue(mockProvider);
const config = [
{
provider: "no-params-provider" as any,
name: "simple-provider",
params: {},
},
];
const result = loadConfigContextProviders(config);
expect(result.errors).toEqual([]);
expect(mockProvider).toHaveBeenCalledWith({
name: "simple-provider",
});
});
it("should handle config without params property", () => {
const mockProvider = vi.fn().mockImplementation((options) => ({
description: { title: "provider-without-params" },
options,
})) as any;
mockedContextProviderClassFromName.mockReturnValue(mockProvider);
const config = [
{
provider: "provider-without-params" as any,
name: "minimal-provider",
} as any, // Cast to bypass type checking for test
];
const result = loadConfigContextProviders(config);
expect(result.errors).toEqual([]);
expect(mockProvider).toHaveBeenCalledWith({
name: "minimal-provider",
});
});
});
describe("error handling", () => {
it("should add error for unknown provider", () => {
mockedContextProviderClassFromName.mockReturnValue(undefined);
const config = [
{
provider: "unknown-provider" as any,
name: "test-provider",
params: {},
},
];
const result = loadConfigContextProviders(config);
expect(result.errors).toEqual([
{
fatal: false,
message: "Unknown context provider unknown-provider",
},
]);
// Should still have default providers
expect(result.providers).toHaveLength(6);
expect(mockedContextProviderClassFromName).toHaveBeenCalledWith(
"unknown-provider",
);
});
it("should handle multiple unknown providers", () => {
mockedContextProviderClassFromName.mockReturnValue(undefined);
const config = [
{
provider: "unknown-1" as any,
name: "test-1",
params: {},
},
{
provider: "unknown-2" as any,
name: "test-2",
params: {},
},
];
const result = loadConfigContextProviders(config);
expect(result.errors).toEqual([
{
fatal: false,
message: "Unknown context provider unknown-1",
},
{
fatal: false,
message: "Unknown context provider unknown-2",
},
]);
expect(result.providers).toHaveLength(6); // Only defaults
});
it("should handle mix of valid and invalid providers", () => {
const mockValidProvider = vi.fn().mockImplementation((options) => ({
description: { title: "valid-provider" },
options,
})) as any;
mockedContextProviderClassFromName
.mockReturnValueOnce(mockValidProvider)
.mockReturnValueOnce(undefined);
const config = [
{
provider: "valid-provider" as any,
name: "valid",
params: { key: "value" },
},
{
provider: "invalid-provider" as any,
name: "invalid",
params: {},
},
];
const result = loadConfigContextProviders(config);
expect(result.errors).toEqual([
{
fatal: false,
message: "Unknown context provider invalid-provider",
},
]);
// Should have valid provider + defaults
expect(result.providers).toHaveLength(7);
expect(mockValidProvider).toHaveBeenCalledWith({
name: "valid",
key: "value",
});
});
});
describe("default provider merging", () => {
it("should not duplicate providers when config matches defaults", () => {
// Mock FileContextProvider to be returned by contextProviderClassFromName
mockedContextProviderClassFromName.mockReturnValue(FileContextProvider);
const config = [
{
provider: "file" as any,
name: "custom-file-provider",
params: { maxFiles: 100 },
},
];
const result = loadConfigContextProviders(config);
expect(result.errors).toEqual([]);
// Should have configured file provider + other defaults (not duplicate file)
expect(result.providers).toHaveLength(6);
const fileProviders = result.providers.filter(
(p) => p.description.title === "file",
);
expect(fileProviders).toHaveLength(1);
// The configured one should be used (with custom params)
expect(FileContextProvider).toHaveBeenCalledWith({
name: "custom-file-provider",
maxFiles: 100,
});
});
it("should add default providers not present in config", () => {
const mockCustomProvider = vi.fn().mockImplementation((options) => ({
description: { title: "custom-only" },
options,
})) as any;
mockedContextProviderClassFromName.mockReturnValue(mockCustomProvider);
const config = [
{
provider: "custom-only" as any,
name: "custom",
params: {},
},
];
const result = loadConfigContextProviders(config);
expect(result.errors).toEqual([]);
expect(result.providers).toHaveLength(7); // 1 custom + 6 defaults
// All defaults should be present
const providerTitles = result.providers.map((p) => p.description.title);
expect(providerTitles).toEqual(
expect.arrayContaining([
"custom-only",
"file",
"current-file",
"diff",
"terminal",
"problems",
"rules",
]),
);
});
it("should preserve order with configured providers first", () => {
const mockProvider = vi.fn().mockImplementation((options) => ({
description: { title: "custom-provider" },
options,
})) as any;
mockedContextProviderClassFromName.mockReturnValue(mockProvider);
const config = [
{
provider: "custom-provider" as any,
name: "custom",
params: {},
},
];
const result = loadConfigContextProviders(config);
expect(result.providers[0].description.title).toBe("custom-provider");
// Rest should be defaults in their original order
const defaultTitles = result.providers
.slice(1)
.map((p) => p.description.title);
expect(defaultTitles).toEqual([
const providerTitles = result.providers.map((p) => p.description.title);
expect(providerTitles).toEqual(
expect.arrayContaining([
"file",
"current-file",
"diff",
"terminal",
"problems",
"rules",
]);
"docs",
]),
);
});
});
describe("with valid config", () => {
it("should load providers from config with correct parameters", () => {
const mockProvider = vi.fn().mockImplementation((options) => ({
description: { title: "custom-provider" },
options,
})) as any;
mockedContextProviderClassFromName.mockReturnValue(mockProvider);
const config = [
{
provider: "custom-provider" as any,
name: "my-custom-provider",
params: {
apiKey: "test-key",
baseUrl: "https://api.example.com",
},
},
];
const result = loadConfigContextProviders(config, false);
expect(result.errors).toEqual([]);
expect(mockedContextProviderClassFromName).toHaveBeenCalledWith(
"custom-provider",
);
expect(mockProvider).toHaveBeenCalledWith({
name: "my-custom-provider",
apiKey: "test-key",
baseUrl: "https://api.example.com",
});
// Should have custom provider + all defaults
expect(result.providers).toHaveLength(7);
const customProvider = result.providers.find(
(p) => p.description.title === "custom-provider",
);
expect(customProvider).toBeDefined();
expect((customProvider as any)?.options).toEqual({
name: "my-custom-provider",
apiKey: "test-key",
baseUrl: "https://api.example.com",
});
});
describe("edge cases", () => {
it("should handle provider constructor throwing error", () => {
const mockProvider = vi.fn().mockImplementation(() => {
throw new Error("Provider construction failed");
}) as any;
it("should handle multiple providers in config", () => {
const mockProvider1 = vi.fn().mockImplementation((options) => ({
description: { title: "provider-1" },
options,
})) as any;
mockedContextProviderClassFromName.mockReturnValue(mockProvider);
const mockProvider2 = vi.fn().mockImplementation((options) => ({
description: { title: "provider-2" },
options,
})) as any;
const config = [
{
provider: "failing-provider" as any,
name: "failing",
params: {},
},
];
mockedContextProviderClassFromName
.mockReturnValueOnce(mockProvider1)
.mockReturnValueOnce(mockProvider2);
expect(() => loadConfigContextProviders(config)).toThrow(
"Provider construction failed",
);
const config = [
{
provider: "provider-1" as any,
name: "first-provider",
params: { setting1: "value1" },
},
{
provider: "provider-2" as any,
name: "second-provider",
params: { setting2: "value2" },
},
];
const result = loadConfigContextProviders(config, false);
expect(result.errors).toEqual([]);
expect(result.providers).toHaveLength(8); // 2 custom + 6 defaults
expect(mockProvider1).toHaveBeenCalledWith({
name: "first-provider",
setting1: "value1",
});
it("should handle null provider class", () => {
mockedContextProviderClassFromName.mockReturnValue(null as any);
const config = [
{
provider: "null-provider" as any,
name: "null",
params: {},
},
];
const result = loadConfigContextProviders(config);
expect(result.errors).toEqual([
{
fatal: false,
message: "Unknown context provider null-provider",
},
]);
});
it("should handle provider with same title as default but different implementation", () => {
// Mock a provider with same title as a default
const mockFileProvider = vi.fn().mockImplementation((options) => ({
description: { title: "file" }, // Same title as FileContextProvider
options,
customProperty: "custom-implementation",
})) as any;
mockedContextProviderClassFromName.mockReturnValue(mockFileProvider);
const config = [
{
provider: "custom-file" as any,
name: "my-file-provider",
params: { customParam: "value" },
},
];
const result = loadConfigContextProviders(config);
expect(result.errors).toEqual([]);
// Should not duplicate - custom implementation should be used
const fileProviders = result.providers.filter(
(p) => p.description.title === "file",
);
expect(fileProviders).toHaveLength(1);
const fileProvider = fileProviders[0] as any;
expect(fileProvider.customProperty).toBe("custom-implementation");
expect(fileProvider.options).toEqual({
name: "my-file-provider",
customParam: "value",
});
expect(mockProvider2).toHaveBeenCalledWith({
name: "second-provider",
setting2: "value2",
});
});
describe("provider instantiation", () => {
it("should call default provider constructors with empty options", () => {
loadConfigContextProviders([]);
it("should handle config with empty params", () => {
const mockProvider = vi.fn().mockImplementation((options) => ({
description: { title: "no-params-provider" },
options,
})) as any;
expect(FileContextProvider).toHaveBeenCalledWith({});
expect(CurrentFileContextProvider).toHaveBeenCalledWith({});
expect(DiffContextProvider).toHaveBeenCalledWith({});
expect(TerminalContextProvider).toHaveBeenCalledWith({});
expect(ProblemsContextProvider).toHaveBeenCalledWith({});
expect(RulesContextProvider).toHaveBeenCalledWith({});
mockedContextProviderClassFromName.mockReturnValue(mockProvider);
const config = [
{
provider: "no-params-provider" as any,
name: "simple-provider",
params: {},
},
];
const result = loadConfigContextProviders(config, false);
expect(result.errors).toEqual([]);
expect(mockProvider).toHaveBeenCalledWith({
name: "simple-provider",
});
});
it("should call provider constructors exactly once per provider", () => {
loadConfigContextProviders([]);
it("should handle config without params property", () => {
const mockProvider = vi.fn().mockImplementation((options) => ({
description: { title: "provider-without-params" },
options,
})) as any;
expect(FileContextProvider).toHaveBeenCalledTimes(1);
expect(CurrentFileContextProvider).toHaveBeenCalledTimes(1);
expect(DiffContextProvider).toHaveBeenCalledTimes(1);
expect(TerminalContextProvider).toHaveBeenCalledTimes(1);
expect(ProblemsContextProvider).toHaveBeenCalledTimes(1);
expect(RulesContextProvider).toHaveBeenCalledTimes(1);
mockedContextProviderClassFromName.mockReturnValue(mockProvider);
const config = [
{
provider: "provider-without-params" as any,
name: "minimal-provider",
} as any, // Cast to bypass type checking for test
];
const result = loadConfigContextProviders(config, false);
expect(result.errors).toEqual([]);
expect(mockProvider).toHaveBeenCalledWith({
name: "minimal-provider",
});
});
});
describe("error handling", () => {
it("should add error for unknown provider", () => {
mockedContextProviderClassFromName.mockReturnValue(undefined);
const config = [
{
provider: "unknown-provider" as any,
name: "test-provider",
params: {},
},
];
const result = loadConfigContextProviders(config, false);
expect(result.errors).toEqual([
{
fatal: false,
message: "Unknown context provider unknown-provider",
},
]);
// Should still have default providers
expect(result.providers).toHaveLength(6);
expect(mockedContextProviderClassFromName).toHaveBeenCalledWith(
"unknown-provider",
);
});
it("should handle multiple unknown providers", () => {
mockedContextProviderClassFromName.mockReturnValue(undefined);
const config = [
{
provider: "unknown-1" as any,
name: "test-1",
params: {},
},
{
provider: "unknown-2" as any,
name: "test-2",
params: {},
},
];
const result = loadConfigContextProviders(config, false);
expect(result.errors).toEqual([
{
fatal: false,
message: "Unknown context provider unknown-1",
},
{
fatal: false,
message: "Unknown context provider unknown-2",
},
]);
expect(result.providers).toHaveLength(6); // Only defaults
});
it("should handle mix of valid and invalid providers", () => {
const mockValidProvider = vi.fn().mockImplementation((options) => ({
description: { title: "valid-provider" },
options,
})) as any;
mockedContextProviderClassFromName
.mockReturnValueOnce(mockValidProvider)
.mockReturnValueOnce(undefined);
const config = [
{
provider: "valid-provider" as any,
name: "valid",
params: { key: "value" },
},
{
provider: "invalid-provider" as any,
name: "invalid",
params: {},
},
];
const result = loadConfigContextProviders(config, false);
expect(result.errors).toEqual([
{
fatal: false,
message: "Unknown context provider invalid-provider",
},
]);
// Should have valid provider + defaults
expect(result.providers).toHaveLength(7);
expect(mockValidProvider).toHaveBeenCalledWith({
name: "valid",
key: "value",
});
});
});
describe("default provider merging", () => {
it("should not duplicate providers when config matches defaults", () => {
// Mock FileContextProvider to be returned by contextProviderClassFromName
mockedContextProviderClassFromName.mockReturnValue(FileContextProvider);
const config = [
{
provider: "file" as any,
name: "custom-file-provider",
params: { maxFiles: 100 },
},
];
const result = loadConfigContextProviders(config, false);
expect(result.errors).toEqual([]);
// Should have configured file provider + other defaults (not duplicate file)
expect(result.providers).toHaveLength(6);
const fileProviders = result.providers.filter(
(p) => p.description.title === "file",
);
expect(fileProviders).toHaveLength(1);
// The configured one should be used (with custom params)
expect(FileContextProvider).toHaveBeenCalledWith({
name: "custom-file-provider",
maxFiles: 100,
});
});
it("should add default providers not present in config", () => {
const mockCustomProvider = vi.fn().mockImplementation((options) => ({
description: { title: "custom-only" },
options,
})) as any;
mockedContextProviderClassFromName.mockReturnValue(mockCustomProvider);
const config = [
{
provider: "custom-only" as any,
name: "custom",
params: {},
},
];
const result = loadConfigContextProviders(config, false);
expect(result.errors).toEqual([]);
expect(result.providers).toHaveLength(7); // 1 custom + 6 defaults
// All defaults should be present
const providerTitles = result.providers.map((p) => p.description.title);
expect(providerTitles).toEqual(
expect.arrayContaining([
"custom-only",
"file",
"current-file",
"diff",
"terminal",
"problems",
"rules",
]),
);
});
it("should preserve order with configured providers first", () => {
const mockProvider = vi.fn().mockImplementation((options) => ({
description: { title: "custom-provider" },
options,
})) as any;
mockedContextProviderClassFromName.mockReturnValue(mockProvider);
const config = [
{
provider: "custom-provider" as any,
name: "custom",
params: {},
},
];
const result = loadConfigContextProviders(config, false);
expect(result.providers[0].description.title).toBe("custom-provider");
// Rest should be defaults in their original order
const defaultTitles = result.providers
.slice(1)
.map((p) => p.description.title);
expect(defaultTitles).toEqual([
"file",
"current-file",
"diff",
"terminal",
"problems",
"rules",
]);
});
});
describe("edge cases", () => {
it("should handle provider constructor throwing error", () => {
const mockProvider = vi.fn().mockImplementation(() => {
throw new Error("Provider construction failed");
}) as any;
mockedContextProviderClassFromName.mockReturnValue(mockProvider);
const config = [
{
provider: "failing-provider" as any,
name: "failing",
params: {},
},
];
expect(() => loadConfigContextProviders(config, false)).toThrow(
"Provider construction failed",
);
});
it("should handle null provider class", () => {
mockedContextProviderClassFromName.mockReturnValue(null as any);
const config = [
{
provider: "null-provider" as any,
name: "null",
params: {},
},
];
const result = loadConfigContextProviders(config, false);
expect(result.errors).toEqual([
{
fatal: false,
message: "Unknown context provider null-provider",
},
]);
});
it("should handle provider with same title as default but different implementation", () => {
// Mock a provider with same title as a default
const mockFileProvider = vi.fn().mockImplementation((options) => ({
description: { title: "file" }, // Same title as FileContextProvider
options,
customProperty: "custom-implementation",
})) as any;
mockedContextProviderClassFromName.mockReturnValue(mockFileProvider);
const config = [
{
provider: "custom-file" as any,
name: "my-file-provider",
params: { customParam: "value" },
},
];
const result = loadConfigContextProviders(config, false);
expect(result.errors).toEqual([]);
// Should not duplicate - custom implementation should be used
const fileProviders = result.providers.filter(
(p) => p.description.title === "file",
);
expect(fileProviders).toHaveLength(1);
const fileProvider = fileProviders[0] as any;
expect(fileProvider.customProperty).toBe("custom-implementation");
expect(fileProvider.options).toEqual({
name: "my-file-provider",
customParam: "value",
});
});
});
describe("provider instantiation", () => {
it("should call default provider constructors with empty options", () => {
loadConfigContextProviders([], false);
expect(FileContextProvider).toHaveBeenCalledWith({});
expect(CurrentFileContextProvider).toHaveBeenCalledWith({});
expect(DiffContextProvider).toHaveBeenCalledWith({});
expect(TerminalContextProvider).toHaveBeenCalledWith({});
expect(ProblemsContextProvider).toHaveBeenCalledWith({});
expect(RulesContextProvider).toHaveBeenCalledWith({});
});
it("should call provider constructors exactly once per provider", () => {
loadConfigContextProviders([], false);
expect(FileContextProvider).toHaveBeenCalledTimes(1);
expect(CurrentFileContextProvider).toHaveBeenCalledTimes(1);
expect(DiffContextProvider).toHaveBeenCalledTimes(1);
expect(TerminalContextProvider).toHaveBeenCalledTimes(1);
expect(ProblemsContextProvider).toHaveBeenCalledTimes(1);
expect(RulesContextProvider).toHaveBeenCalledTimes(1);
});
});

View file

@ -21,7 +21,6 @@ import {
import { stringifyMcpPrompt } from "../../commands/slash/mcpSlashCommand";
import { MCPManagerSingleton } from "../../context/mcp/MCPManagerSingleton";
import ContinueProxyContextProvider from "../../context/providers/ContinueProxyContextProvider";
import DocsContextProvider from "../../context/providers/DocsContextProvider";
import MCPContextProvider from "../../context/providers/MCPContextProvider";
import { ControlPlaneProxyInfo } from "../../control-plane/analytics/IAnalyticsProvider.js";
import { ControlPlaneClient } from "../../control-plane/client.js";
@ -158,14 +157,6 @@ export default async function doLoadConfig(options: {
errors.push(...rulesErrors);
newConfig.rules.unshift(...rules);
// Add docs provider if there are docs and no provider
if (
newConfig.docs?.length &&
!newConfig.contextProviders?.some((cp) => cp.description.title === "docs")
) {
newConfig.contextProviders.push(new DocsContextProvider({}));
}
const proxyContextProvider = newConfig.contextProviders?.find(
(cp) => cp.description.title === "continue-proxy",
);

View file

@ -369,6 +369,7 @@ async function configYamlToContinueConfig(options: {
const { providers, errors: contextErrors } = loadConfigContextProviders(
config.context,
!!config.docs?.length,
);
continueConfig.contextProviders = providers;

1
core/index.d.ts vendored
View file

@ -1681,6 +1681,7 @@ export interface Config {
experimental?: ExperimentalConfig;
/** Analytics configuration */
analytics?: AnalyticsConfig;
docs?: SiteIndexingConfig[];
data?: DataDestination[];
}