moves relativePath method to fsService

This commit is contained in:
Ben 2025-04-16 09:42:11 +02:00
parent 5f0e410530
commit c811b67807
No known key found for this signature in database
GPG Key ID: 0F16E812E736C24B
6 changed files with 17 additions and 5 deletions

View File

@ -29,6 +29,7 @@ export const mockFsService = {
readJsonFile: vi.fn(),
writeJsonFile: vi.fn(),
writeFile: vi.fn(),
toRelativePath: vi.fn(),
};
export const mockShellService = {

View File

@ -119,7 +119,6 @@ export class ConfigService {
};
toRelative = (str) => {
throw new Error("This code does not belong in this file. Move it.");
return path.relative(this.config.codexInstallPath, str);
return this.fs.toRelativePath(this.config.codexInstallPath, str);
};
}

View File

@ -169,6 +169,9 @@ describe("ConfigService", () => {
it("writes the config file values to the config TOML file", () => {
const publicIp = "1.2.3.4";
const bootstrapNodes = ["boot111", "boot222", "boot333"];
const relativeDataDirPath = "..\\../datadir";
mockFsService.toRelativePath.mockReturnValue(relativeDataDirPath);
configService.writeCodexConfigFile(publicIp, bootstrapNodes);
@ -176,7 +179,7 @@ describe("ConfigService", () => {
expect(mockFsService.writeFile).toHaveBeenCalledWith(
expectedDefaultConfig.codexConfigFilePath,
`data-dir=\"${formatPath(expectedDefaultConfig.dataDir)}"${newLine}` +
`data-dir=\"${formatPath(relativeDataDirPath)}"${newLine}` +
`log-level="DEBUG"${newLine}` +
`log-file="${formatPath(logsPath)}"${newLine}` +
`storage-quota=${expectedDefaultConfig.storageQuota}${newLine}` +
@ -191,6 +194,11 @@ describe("ConfigService", () => {
})
.join(",")}]${newLine}`,
);
expect(mockFsService.toRelativePath).toHaveBeenCalledWith(
expectedDefaultConfig.codexInstallPath,
expectedDefaultConfig.dataDir,
);
});
});
});

View File

@ -66,4 +66,8 @@ export class FsService {
writeFile = (filePath, content) => {
fs.writeFileSync(filePath, content);
};
toRelativePath = (from, to) => {
return path.relative(from, to);
};
}

View File

@ -70,7 +70,7 @@ export class MainMenu {
};
showNotRunningMenu = async () => {
await this.ui.askMultipleChoice("Codex is not running", [
await this.ui.askMultipleChoice("Codex is installed but not running", [
{
label: "Start Codex",
action: this.processControl.startCodexProcess,

View File

@ -127,7 +127,7 @@ describe("mainmenu", () => {
await mainmenu.showNotRunningMenu();
expect(mockUiService.askMultipleChoice).toHaveBeenCalledWith(
"Codex is not running",
"Codex is installed but not running",
[
{
label: "Start Codex",