fix: codebase indexing on start with no context provider

This commit is contained in:
Dallin Romney 2025-08-18 16:19:19 -07:00
parent d234032f89
commit adb81b0682
2 changed files with 21 additions and 54 deletions

View file

@ -13,6 +13,7 @@ class CodebaseContextProvider extends BaseContextProvider {
description: "Automatically find relevant files",
type: "normal",
renderInlineAs: "",
dependsOnIndexing: true,
};
async getContextItems(

View file

@ -202,7 +202,7 @@ describe("CodebaseIndexer", () => {
test("should have indexed all of the files", async () => {
const indexed = await getAllIndexedFiles();
expect(indexed.length).toBe(4); // Files are indexed twice due to test execution
expect(indexed.length).toBe(2);
expect(indexed.some((file) => file.endsWith("test.ts"))).toBe(true);
expect(indexed.some((file) => file.endsWith("main.py"))).toBe(true);
});
@ -226,7 +226,7 @@ describe("CodebaseIndexer", () => {
// Check that the new file was indexed
const files = await getAllIndexedFiles();
expect(files.length).toBe(5); // Updated to match actual behavior
expect(files.length).toBe(3);
expect(files.some((file) => file.endsWith("main.rs"))).toBe(true);
});
@ -240,7 +240,7 @@ describe("CodebaseIndexer", () => {
// Check that the deleted file was removed from the index
const files = await getAllIndexedFiles();
expect(files.length).toBe(4); // Updated to match actual behavior
expect(files.length).toBe(2);
expect(files.every((file) => !file.endsWith("main.rs"))).toBe(true);
});
@ -478,13 +478,7 @@ describe("CodebaseIndexer", () => {
test("should return true when codebase context provider is present", () => {
// Set up config with codebase context provider
(testIndexer as any).config = {
contextProviders: [
{
description: {
title: CodebaseContextProvider.description.title,
},
},
],
contextProviders: [new CodebaseContextProvider({})],
};
const result = testIndexer.testHasIndexingProvider();
@ -535,9 +529,8 @@ describe("CodebaseIndexer", () => {
await testIndexer.testHandleConfigUpdate(configResult);
// These get called once on init, so we want them to not get called again
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(1);
expect(mockGetWorkspaceDirs).toHaveBeenCalledTimes(1);
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(0);
expect(mockGetWorkspaceDirs).toHaveBeenCalledTimes(0);
});
test("should return early when newConfig is undefined", async () => {
@ -549,9 +542,8 @@ describe("CodebaseIndexer", () => {
await testIndexer.testHandleConfigUpdate(configResult);
// These get called once on init, so we want them to not get called again
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(1);
expect(mockGetWorkspaceDirs).toHaveBeenCalledTimes(1);
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(0);
expect(mockGetWorkspaceDirs).toHaveBeenCalledTimes(0);
});
test("should return early when no codebase context provider is present", async () => {
@ -577,21 +569,14 @@ describe("CodebaseIndexer", () => {
await testIndexer.testHandleConfigUpdate(configResult);
// These get called once on init, so we want them to not get called again
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(1);
expect(mockGetWorkspaceDirs).toHaveBeenCalledTimes(1);
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(0);
expect(mockGetWorkspaceDirs).toHaveBeenCalledTimes(0);
});
test("should return early when no embed model is configured", async () => {
const configResult: ConfigResult<ContinueConfig> = {
config: {
contextProviders: [
{
description: {
title: CodebaseContextProvider.description.title,
},
},
],
contextProviders: [new CodebaseContextProvider({})],
selectedModelByRole: {
embed: undefined,
},
@ -602,21 +587,14 @@ describe("CodebaseIndexer", () => {
await testIndexer.testHandleConfigUpdate(configResult);
// These get called once on init, so we want them to not get called again
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(1);
expect(mockGetWorkspaceDirs).toHaveBeenCalledTimes(1);
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(0);
expect(mockGetWorkspaceDirs).toHaveBeenCalledTimes(0);
});
test("should call refreshCodebaseIndex when all conditions are met", async () => {
const configResult: ConfigResult<ContinueConfig> = {
config: {
contextProviders: [
{
description: {
title: CodebaseContextProvider.description.title,
},
},
],
contextProviders: [new CodebaseContextProvider({})],
selectedModelByRole: {
embed: {
model: "test-model",
@ -630,9 +608,8 @@ describe("CodebaseIndexer", () => {
await testIndexer.testHandleConfigUpdate(configResult);
// These get called once on init, and we want them to get called again
expect(mockGetWorkspaceDirs).toHaveBeenCalledTimes(2);
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(2);
expect(mockGetWorkspaceDirs).toHaveBeenCalledTimes(1);
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(1);
expect(mockRefreshCodebaseIndex).toHaveBeenCalledWith([
"/test/workspace",
]);
@ -640,13 +617,7 @@ describe("CodebaseIndexer", () => {
test("should set config property before checking conditions", async () => {
const testConfig = {
contextProviders: [
{
description: {
title: CodebaseContextProvider.description.title,
},
},
],
contextProviders: [new CodebaseContextProvider({})],
selectedModelByRole: {
embed: {
model: "test-model",
@ -666,7 +637,7 @@ describe("CodebaseIndexer", () => {
// Verify that the config was set
expect((testIndexer as any).config).toBe(testConfig);
// These get called once on init, and we want them to get called again
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(2);
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(1);
});
test("should handle multiple context providers correctly", async () => {
@ -678,11 +649,7 @@ describe("CodebaseIndexer", () => {
title: "SomeOtherProvider",
},
},
{
description: {
title: CodebaseContextProvider.description.title,
},
},
new CodebaseContextProvider({}),
{
description: {
title: "AnotherProvider",
@ -702,8 +669,7 @@ describe("CodebaseIndexer", () => {
await testIndexer.testHandleConfigUpdate(configResult);
// These get called once on init, and we want them to get called again
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(2);
expect(mockRefreshCodebaseIndex).toHaveBeenCalledTimes(1);
expect(mockRefreshCodebaseIndex).toHaveBeenCalledWith([
"/test/workspace",
]);