Handles the presense of previous versions of the config file

This commit is contained in:
Ben 2025-06-03 09:24:53 +02:00
parent 25000aa807
commit 367b889055
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
2 changed files with 23 additions and 0 deletions

View File

@ -55,6 +55,12 @@ export class ConfigService {
this.saveConfig();
} else {
this.config = this.fs.readJsonFile(filePath);
if (this.config.codexRoot == undefined) {
this.config = defaultConfig;
this.saveConfig();
}
}
} catch (error) {
console.error(

View File

@ -53,6 +53,7 @@ describe("ConfigService", () => {
it("loads the config.json file when it does exist", () => {
mockFsService.isFile.mockReturnValue(true);
const savedConfig = {
codexRoot: "defined",
isTestConfig: "Yes, very",
};
mockFsService.readJsonFile.mockReturnValue(savedConfig);
@ -64,6 +65,22 @@ describe("ConfigService", () => {
expect(mockFsService.writeJsonFile).not.toHaveBeenCalled();
expect(service.config).toEqual(savedConfig);
});
it("saves the default config when config.json exists but doesn't define the codexRoot", () => {
mockFsService.isFile.mockReturnValue(true);
const savedConfig = {
codexRoot: undefined, // it still blows my mind we have a language in which we can define things to be undefined.
isTestConfig: "Yes, very",
};
mockFsService.readJsonFile.mockReturnValue(savedConfig);
const service = new ConfigService(mockFsService, mockOsService);
expect(mockFsService.isFile).toHaveBeenCalledWith(configPath);
expect(mockFsService.readJsonFile).toHaveBeenCalledWith(configPath);
expect(mockFsService.writeJsonFile).toHaveBeenCalled();
expect(service.config).toEqual(expectedDefaultConfig);
});
});
describe("getCodexExe", () => {