Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions core/config/profile/LocalProfileLoader.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfigResult, parseConfigYaml } from "@continuedev/config-yaml";
import fs from "node:fs";

import { ControlPlaneClient } from "../../control-plane/client.js";
import { ContinueConfig, IDE, ILLMLogger } from "../../index.js";
Expand All @@ -21,6 +22,7 @@ export default class LocalProfileLoader implements IProfileLoader {
| { path: string; content: string }
| undefined,
) {
const defaultTitle = "Local Config";
const description: ProfileDescription = {
id: overrideAssistantFile?.path ?? LocalProfileLoader.ID,
profileType: "local",
Expand All @@ -32,20 +34,29 @@ export default class LocalProfileLoader implements IProfileLoader {
iconUrl: "",
title: overrideAssistantFile?.path
? getUriPathBasename(overrideAssistantFile.path)
: "Local Config",
: defaultTitle,
errors: undefined,
uri:
overrideAssistantFile?.path ??
localPathToUri(getPrimaryConfigFilePath()),
rawYaml: undefined,
};
this.description = description;
if (overrideAssistantFile?.content) {
let configContent = overrideAssistantFile?.content;
if (configContent === undefined) {
try {
const parsedAssistant = parseConfigYaml(
overrideAssistantFile?.content ?? "",
);
this.description.title = parsedAssistant.name;
configContent = fs.readFileSync(getPrimaryConfigFilePath(), "utf8");
} catch (e) {
console.error("Failed to read config file: ", e);
}
}
if (configContent) {
try {
const parsedAssistant = parseConfigYaml(configContent);
this.description.title =
parsedAssistant.name?.trim() ||
this.description.title ||
defaultTitle;
} catch (e) {
console.error("Failed to parse config file: ", e);
}
Expand Down
53 changes: 53 additions & 0 deletions core/config/profile/LocalProfileLoader.vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import fs from "node:fs";
import os from "node:os";
import path from "node:path";

import { afterEach, describe, expect, it, vi } from "vitest";

async function createLoader(configYaml?: string) {
const tempDir = fs.mkdtempSync(
path.join(os.tmpdir(), "continue-local-profile-loader-"),
);
process.env.CONTINUE_GLOBAL_DIR = tempDir;

if (configYaml !== undefined) {
fs.writeFileSync(path.join(tempDir, "config.yaml"), configYaml);
}

vi.resetModules();
const { default: LocalProfileLoader } = await import("./LocalProfileLoader");

return {
tempDir,
loader: new LocalProfileLoader({} as any, {} as any, {} as any),
};
}

afterEach(() => {
delete process.env.CONTINUE_GLOBAL_DIR;
vi.restoreAllMocks();
});

describe("LocalProfileLoader", () => {
it("uses name from default local config.yaml for the profile title", async () => {
const { loader, tempDir } = await createLoader(
"name: Custom Local Profile\nversion: '1.0'",
);
expect(loader.description.title).toBe("Custom Local Profile");
fs.rmSync(tempDir, { recursive: true, force: true });
});

it("falls back to Local Config when default config.yaml is malformed", async () => {
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => {});
const { loader, tempDir } = await createLoader("name: [");
expect(loader.description.title).toBe("Local Config");
expect(errorSpy).toHaveBeenCalled();
fs.rmSync(tempDir, { recursive: true, force: true });
});

it("falls back to Local Config when name is missing", async () => {
const { loader, tempDir } = await createLoader("models: []");
expect(loader.description.title).toBe("Local Config");
fs.rmSync(tempDir, { recursive: true, force: true });
});
});
Loading