Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.
Merged
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
5 changes: 3 additions & 2 deletions engine/cli/command_line_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,9 @@ void CommandLineParser::SetupSystemCommands() {
<< " to " << cml_data_.port);
auto config_path = file_manager_utils::GetConfigurationPath();
cml_data_.config.apiServerPort = std::to_string(cml_data_.port);
auto result = config_yaml_utils::DumpYamlConfig(cml_data_.config,
config_path.string());
auto result =
config_yaml_utils::CortexConfigMgr::GetInstance().DumpYamlConfig(
cml_data_.config, config_path.string());
if (result.has_error()) {
CLI_LOG("Error update " << config_path.string() << result.error());
}
Expand Down
5 changes: 3 additions & 2 deletions engine/cli/commands/cortex_upd_cmd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,9 @@ std::optional<std::string> CheckNewUpdate(
CTL_INF("Got the latest release, update to the config file: "
<< latest_version)
config.latestRelease = latest_version;
auto result = config_yaml_utils::DumpYamlConfig(
config, file_manager_utils::GetConfigurationPath().string());
auto result =
config_yaml_utils::CortexConfigMgr::GetInstance().DumpYamlConfig(
config, file_manager_utils::GetConfigurationPath().string());
if (result.has_error()) {
CTL_ERR("Error update "
<< file_manager_utils::GetConfigurationPath().string()
Expand Down
5 changes: 3 additions & 2 deletions engine/cli/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ int main(int argc, char* argv[]) {
.count();
config.latestLlamacppRelease = res.value();

auto upd_config_res = config_yaml_utils::DumpYamlConfig(
config, file_manager_utils::GetConfigurationPath().string());
auto upd_config_res =
config_yaml_utils::CortexConfigMgr::GetInstance().DumpYamlConfig(
config, file_manager_utils::GetConfigurationPath().string());
if (upd_config_res.has_error()) {
CTL_ERR("Failed to update config file: " << upd_config_res.error());
} else {
Expand Down
3 changes: 2 additions & 1 deletion engine/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ void RunServer(std::optional<int> port, bool ignore_cout) {
auto config_path = file_manager_utils::GetConfigurationPath();
config.apiServerPort = std::to_string(*port);
auto result =
config_yaml_utils::DumpYamlConfig(config, config_path.string());
config_yaml_utils::CortexConfigMgr::GetInstance().DumpYamlConfig(
config, config_path.string());
if (result.has_error()) {
CTL_ERR("Error update " << config_path.string() << result.error());
}
Expand Down
18 changes: 13 additions & 5 deletions engine/test/components/test_cortex_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "utils/config_yaml_utils.h"

namespace config_yaml_utils {
namespace cyu = config_yaml_utils;
class CortexConfigTest : public ::testing::Test {
protected:
const std::string test_file_path = "test_config.yaml";
Expand Down Expand Up @@ -43,7 +44,8 @@ TEST_F(CortexConfigTest, DumpYamlConfig_WritesCorrectly) {
123456789,
"v1.0.0"};

auto result = DumpYamlConfig(config, test_file_path);
auto result = cyu::CortexConfigMgr::GetInstance().DumpYamlConfig(
config, test_file_path);
EXPECT_FALSE(result.has_error());

// Verify that the file was created and contains the expected data
Expand Down Expand Up @@ -72,11 +74,13 @@ TEST_F(CortexConfigTest, FromYaml_ReadsCorrectly) {
123456789,
"v1.0.0"};

auto result = DumpYamlConfig(config, test_file_path);
auto result = cyu::CortexConfigMgr::GetInstance().DumpYamlConfig(
config, test_file_path);
EXPECT_FALSE(result.has_error());

// Now read from the YAML file
CortexConfig loaded_config = FromYaml(test_file_path, default_config);
CortexConfig loaded_config = cyu::CortexConfigMgr::GetInstance().FromYaml(
test_file_path, default_config);

// Verify that the loaded configuration matches what was written
EXPECT_EQ(loaded_config.logFolderPath, config.logFolderPath);
Expand All @@ -92,7 +96,10 @@ TEST_F(CortexConfigTest, FromYaml_FileNotFound) {
std::filesystem::remove(test_file_path); // Ensure the file does not exist

EXPECT_THROW(
{ FromYaml(test_file_path, default_config); },
{
cyu::CortexConfigMgr::GetInstance().FromYaml(test_file_path,
default_config);
},
std::runtime_error); // Expect a runtime error due to missing file
}

Expand All @@ -102,7 +109,8 @@ TEST_F(CortexConfigTest, FromYaml_IncompleteConfigUsesDefaults) {
out_file << "logFolderPath: log_path\n"; // Missing other fields
out_file.close();

CortexConfig loaded_config = FromYaml(test_file_path, default_config);
CortexConfig loaded_config = cyu::CortexConfigMgr::GetInstance().FromYaml(
test_file_path, default_config);

// Verify that defaults are used where values are missing
EXPECT_EQ(loaded_config.logFolderPath, "log_path");
Expand Down
7 changes: 5 additions & 2 deletions engine/test/components/test_file_manager_config_yaml_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ TEST_F(FileManagerConfigTest, DumpYamlConfig) {
.apiServerPort = "8080"};

std::string test_file = "test_config.yaml";
auto result = config_yaml_utils::DumpYamlConfig(config, test_file);
auto result =
config_yaml_utils::CortexConfigMgr::GetInstance().DumpYamlConfig(
config, test_file);
EXPECT_FALSE(result.has_error());
EXPECT_TRUE(std::filesystem::exists(test_file));

Expand All @@ -83,7 +85,8 @@ TEST_F(FileManagerConfigTest, FromYaml) {
out_file.close();

config_yaml_utils::CortexConfig default_config{};
auto config = config_yaml_utils::FromYaml(test_file, default_config);
auto config = config_yaml_utils::CortexConfigMgr::GetInstance().FromYaml(
test_file, default_config);

EXPECT_EQ(config.logFolderPath, "/path/to/logs");
EXPECT_EQ(config.dataFolderPath, "/path/to/data");
Expand Down
Loading
Loading