From 8168cd8730e069746ac29e7d3c07b2dfcb90fab2 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Tue, 17 Sep 2024 10:38:27 +0700 Subject: [PATCH 01/22] feat: download pre-release --- engine/commands/engine_init_cmd.cc | 29 +++++++++++++++++++---- engine/controllers/command_line_parser.cc | 7 ++++-- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/engine/commands/engine_init_cmd.cc b/engine/commands/engine_init_cmd.cc index 350f3c6b1..ea528dfe9 100644 --- a/engine/commands/engine_init_cmd.cc +++ b/engine/commands/engine_init_cmd.cc @@ -19,10 +19,12 @@ EngineInitCmd::EngineInitCmd(std::string engineName, std::string version) bool EngineInitCmd::Exec() const { auto system_info = system_info_utils::GetSystemInfo(); constexpr auto gitHubHost = "https://api.github.com"; - std::string version = version_.empty() ? "latest" : version_; + // std::string version = version_.empty() ? "latest" : version_; std::ostringstream engineReleasePath; - engineReleasePath << "/repos/janhq/" << engineName_ << "/releases/" - << version; + engineReleasePath << "/repos/janhq/" << engineName_ << "/releases"; + if (version_ == "latest") { + engineReleasePath << "/latest"; + } CTL_INF("Engine release path: " << gitHubHost << engineReleasePath.str()); using namespace nlohmann; @@ -31,7 +33,26 @@ bool EngineInitCmd::Exec() const { if (res->status == httplib::StatusCode::OK_200) { try { auto jsonResponse = json::parse(res->body); - auto assets = jsonResponse["assets"]; + + nlohmann::json json_data; + if (version_ == "latest") { + json_data = jsonResponse; + } else { + for (auto& jr : jsonResponse) { + // Get the latest or match version + if (auto tag = jr["tag_name"].get(); tag == version_) { + json_data = jr; + break; + } + } + } + + if (json_data.empty()) { + CLI_LOG("Version not found: " << version_); + return false; + } + + auto assets = json_data["assets"]; auto os_arch{system_info.os + "-" + system_info.arch}; std::vector variants; diff --git a/engine/controllers/command_line_parser.cc b/engine/controllers/command_line_parser.cc index b8baf3466..db773c28a 100644 --- a/engine/controllers/command_line_parser.cc +++ b/engine/controllers/command_line_parser.cc @@ -6,6 +6,7 @@ #include "commands/engine_init_cmd.h" #include "commands/engine_list_cmd.h" #include "commands/engine_uninstall_cmd.h" +#include "commands/model_del_cmd.h" #include "commands/model_get_cmd.h" #include "commands/model_list_cmd.h" #include "commands/model_pull_cmd.h" @@ -13,7 +14,6 @@ #include "commands/model_stop_cmd.h" #include "commands/run_cmd.h" #include "commands/server_stop_cmd.h" -#include "commands/model_del_cmd.h" #include "config/yaml_config.h" #include "services/engine_service.h" #include "utils/file_manager_utils.h" @@ -224,7 +224,10 @@ void CommandLineParser::EngineInstall(CLI::App* parent, std::string& version) { auto install_engine_cmd = parent->add_subcommand(engine_name, ""); - install_engine_cmd->callback([=] { + install_engine_cmd->add_option("-v, --version", version, + "Engine version to download"); + + install_engine_cmd->callback([engine_name, &version] { commands::EngineInitCmd eic(engine_name, version); eic.Exec(); }); From 1efc0b62f227b944ad450ff520cf370d8049c0e0 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Tue, 17 Sep 2024 16:09:23 +0700 Subject: [PATCH 02/22] feat: download pre-release --- engine/main.cc | 3 ++- engine/services/engine_service.cc | 28 +++++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/engine/main.cc b/engine/main.cc index 79f1aaa98..06513d638 100644 --- a/engine/main.cc +++ b/engine/main.cc @@ -206,12 +206,13 @@ int main(int argc, char* argv[]) { verbose = true; } } + + trantor::FileLogger asyncFileLogger; if (!verbose) { auto config = file_manager_utils::GetCortexConfig(); std::filesystem::create_directories( std::filesystem::path(config.logFolderPath) / std::filesystem::path(cortex_utils::logs_folder)); - trantor::FileLogger asyncFileLogger; asyncFileLogger.setFileName(config.logFolderPath + "/" + cortex_utils::logs_cli_base_name); asyncFileLogger.setMaxLines( diff --git a/engine/services/engine_service.cc b/engine/services/engine_service.cc index 5691d728c..c4e7044ad 100644 --- a/engine/services/engine_service.cc +++ b/engine/services/engine_service.cc @@ -76,16 +76,42 @@ std::vector EngineService::GetEngineInfoList() const { void EngineService::InstallEngine(const std::string& engine, const std::string& version) { auto system_info = system_info_utils::GetSystemInfo(); + auto get_params = [&engine, &version]() -> std::vector { + if (version == "latest") { + return {"repos", "janhq", engine, "releases", version}; + } else { + return {"repos", "janhq", engine, "releases"}; + } + }; + auto url_obj = url_parser::Url{ .protocol = "https", .host = "api.github.com", - .pathParams = {"repos", "janhq", engine, "releases", version}, + .pathParams = get_params(), }; httplib::Client cli(url_obj.GetProtocolAndHost()); if (auto res = cli.Get(url_obj.GetPathAndQuery()); res->status == httplib::StatusCode::OK_200) { auto body = json::parse(res->body); + auto get_data = + [&version](const nlohmann::json& json_data) -> nlohmann::json { + for (auto& jr : json_data) { + // Get the latest or match version + if (auto tag = jr["tag_name"].get(); tag == version) { + return jr; + } + } + return nlohmann::json(); + }; + + if (version != "latest") { + body = get_data(body); + } + if (body.empty()) { + throw std::runtime_error("No version found for " + version); + } + auto assets = body["assets"]; auto os_arch{system_info.os + "-" + system_info.arch}; From 24cbcf1edeab29e1c8564696a60859c88e37c332 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Tue, 17 Sep 2024 16:13:28 +0700 Subject: [PATCH 03/22] chore: add e2e test --- engine/e2e-test/test_cli_engine_install.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/engine/e2e-test/test_cli_engine_install.py b/engine/e2e-test/test_cli_engine_install.py index be23167be..15cd8deb3 100644 --- a/engine/e2e-test/test_cli_engine_install.py +++ b/engine/e2e-test/test_cli_engine_install.py @@ -28,3 +28,11 @@ def test_engines_install_onnx_on_tensorrt_should_be_failed(self): ) assert "No variant found" in output, "Should display error message" assert exit_code == 0, f"Install engine failed with error: {error}" + + def test_engines_install_pre_release_llamacpp(self): + exit_code, output, error = run( + "Install Engine", ["engines", "install", "cortex.llamacpp", "-v", "v0.1.29"], timeout=60 + ) + assert "Start downloading" in output, "Should display downloading message" + assert exit_code == 0, f"Install engine failed with error: {error}" + From d3c36c106f5b7fe396f4d5eec59c46f0752a889c Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Tue, 17 Sep 2024 16:16:43 +0700 Subject: [PATCH 04/22] fix: m --- engine/services/engine_service.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/services/engine_service.cc b/engine/services/engine_service.cc index c4e7044ad..68368fe4a 100644 --- a/engine/services/engine_service.cc +++ b/engine/services/engine_service.cc @@ -109,7 +109,7 @@ void EngineService::InstallEngine(const std::string& engine, body = get_data(body); } if (body.empty()) { - throw std::runtime_error("No version found for " + version); + throw std::runtime_error("No release found for " + version); } auto assets = body["assets"]; From f729364418c5a14f8e6ff4e70691dc9f7a1344f7 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Tue, 17 Sep 2024 16:33:48 +0700 Subject: [PATCH 05/22] feat: e2e test CI --- .github/workflows/cortex-cpp-quality-gate.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index d9ef1ff8c..6ac205523 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -83,6 +83,18 @@ jobs: run: | cd engine make run-unit-tests + + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Run e2e tests + run: | + python -m pip install --upgrade pip + python -m install pytest + cd engine + python e2e-test/main.py - name: Pre-package run: | From bfde9b9197d7cd384965efb45ff91e6df77d0468 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Tue, 17 Sep 2024 16:38:07 +0700 Subject: [PATCH 06/22] f:m --- .github/workflows/cortex-cpp-quality-gate.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index 6ac205523..9e735ebdb 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -92,7 +92,7 @@ jobs: - name: Run e2e tests run: | python -m pip install --upgrade pip - python -m install pytest + python -m pip install pytest cd engine python e2e-test/main.py From 71a55cc0925e04d49f57bc99eb0334f5830cf826 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Tue, 17 Sep 2024 16:41:31 +0700 Subject: [PATCH 07/22] f:f --- .github/workflows/cortex-cpp-quality-gate.yml | 1 + engine/e2e-test/test_runner.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index 9e735ebdb..9ecfaa56e 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -93,6 +93,7 @@ jobs: run: | python -m pip install --upgrade pip python -m pip install pytest + python -m pip install requests cd engine python e2e-test/main.py diff --git a/engine/e2e-test/test_runner.py b/engine/e2e-test/test_runner.py index bedf8d39d..46a4dbfb9 100644 --- a/engine/e2e-test/test_runner.py +++ b/engine/e2e-test/test_runner.py @@ -7,7 +7,7 @@ from typing import List # You might want to change the path of the executable based on your build directory -executable_windows_path = "build\\Debug\\cortex.exe" +executable_windows_path = "build\\cortex.exe" executable_unix_path = "build/cortex" # Timeout From 10e87e4307fd99a079ea9d1fae3dac0869a1443c Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Tue, 17 Sep 2024 16:51:45 +0700 Subject: [PATCH 08/22] fix: timeout --- engine/e2e-test/test_cli_engine_install.py | 2 +- engine/e2e-test/test_cli_engine_uninstall.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/engine/e2e-test/test_cli_engine_install.py b/engine/e2e-test/test_cli_engine_install.py index 15cd8deb3..70122c8e1 100644 --- a/engine/e2e-test/test_cli_engine_install.py +++ b/engine/e2e-test/test_cli_engine_install.py @@ -8,7 +8,7 @@ class TestCliEngineInstall: def test_engines_install_llamacpp_should_be_successfully(self): exit_code, output, error = run( - "Install Engine", ["engines", "install", "cortex.llamacpp"], timeout=60 + "Install Engine", ["engines", "install", "cortex.llamacpp"], timeout=120 ) assert "Start downloading" in output, "Should display downloading message" assert exit_code == 0, f"Install engine failed with error: {error}" diff --git a/engine/e2e-test/test_cli_engine_uninstall.py b/engine/e2e-test/test_cli_engine_uninstall.py index 03078a1e6..2248f61d2 100644 --- a/engine/e2e-test/test_cli_engine_uninstall.py +++ b/engine/e2e-test/test_cli_engine_uninstall.py @@ -8,7 +8,7 @@ class TestCliEngineUninstall: def setup_and_teardown(self): # Setup # Preinstall llamacpp engine - run("Install Engine", ["engines", "install", "cortex.llamacpp"]) + run("Install Engine", ["engines", "install", "cortex.llamacpp"], timeout=120) yield From 85ef04daf073117217dfa090f968b5464bbf7dae Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 18 Sep 2024 13:58:33 +0700 Subject: [PATCH 09/22] fix: exit code --- engine/e2e-test/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/engine/e2e-test/main.py b/engine/e2e-test/main.py index 1df424e65..595c82fb1 100644 --- a/engine/e2e-test/main.py +++ b/engine/e2e-test/main.py @@ -1,4 +1,5 @@ import pytest +import sys from test_api_engine_list import TestApiEngineList from test_cli_engine_get import TestCliEngineGet from test_cli_engine_install import TestCliEngineInstall @@ -11,4 +12,4 @@ from test_create_log_folder import TestCreateLogFolder if __name__ == "__main__": - pytest.main([__file__, "-v"]) + sys.exit(pytest.main([__file__, "-v"])) From c2d3d92a115ccddfa66df664e5b25bf977d2680c Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Thu, 19 Sep 2024 12:56:50 +0700 Subject: [PATCH 10/22] fix: timeout None --- engine/e2e-test/test_cli_engine_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/e2e-test/test_cli_engine_install.py b/engine/e2e-test/test_cli_engine_install.py index 696a05ac8..e4e331030 100644 --- a/engine/e2e-test/test_cli_engine_install.py +++ b/engine/e2e-test/test_cli_engine_install.py @@ -8,7 +8,7 @@ class TestCliEngineInstall: def test_engines_install_llamacpp_should_be_successfully(self): exit_code, output, error = run( - "Install Engine", ["engines", "install", "cortex.llamacpp"], timeout=120 + "Install Engine", ["engines", "install", "cortex.llamacpp"], timeout=None ) assert "Start downloading" in output, "Should display downloading message" assert exit_code == 0, f"Install engine failed with error: {error}" From 652363ab813ae70ae4cfe8d6e176e758cac845ef Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 2 Oct 2024 06:45:36 +0700 Subject: [PATCH 11/22] fix: test --- .github/workflows/cortex-cpp-quality-gate.yml | 13 ------------- .github/workflows/template-build-macos.yml | 14 +++++++++++++- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index be4b303e3..1d838d0c8 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -106,19 +106,6 @@ jobs: run: | cd engine make run-unit-tests - - - name: Install Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' - - - name: Run e2e tests - run: | - python -m pip install --upgrade pip - python -m pip install pytest - python -m pip install requests - cd engine - python e2e-test/main.py - name: Pre-package run: | diff --git a/.github/workflows/template-build-macos.yml b/.github/workflows/template-build-macos.yml index 467bf14b0..66890a40f 100644 --- a/.github/workflows/template-build-macos.yml +++ b/.github/workflows/template-build-macos.yml @@ -152,7 +152,19 @@ jobs: run: | cd engine make build CMAKE_EXTRA_FLAGS="${{ inputs.cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ inputs.build-deps-cmake-flags }}" - + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Run e2e tests + run: | + python -m pip install --upgrade pip + python -m pip install pytest + python -m pip install requests + cd engine + python e2e-test/main.py + - name: Pre-package run: | cd engine From e10370ffd5da1283c7bfa0b2f84a99ec83a3fcb5 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 2 Oct 2024 06:48:50 +0700 Subject: [PATCH 12/22] f:m --- .github/workflows/template-build-macos.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/template-build-macos.yml b/.github/workflows/template-build-macos.yml index 66890a40f..9289fa2bb 100644 --- a/.github/workflows/template-build-macos.yml +++ b/.github/workflows/template-build-macos.yml @@ -152,10 +152,11 @@ jobs: run: | cd engine make build CMAKE_EXTRA_FLAGS="${{ inputs.cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ inputs.build-deps-cmake-flags }}" - - name: Install Python - uses: actions/setup-python@v4 - with: - python-version: '3.10' + + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' - name: Run e2e tests run: | From 32cef18a489c9ab1616fb95d333294c516465980 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 2 Oct 2024 07:10:15 +0700 Subject: [PATCH 13/22] f:m --- .github/workflows/template-build-linux-x64.yml | 15 ++++++++++++++- .github/workflows/template-build-windows-x64.yml | 13 +++++++++++++ engine/e2e-test/test_runner.py | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/.github/workflows/template-build-linux-x64.yml b/.github/workflows/template-build-linux-x64.yml index 9cefe447e..df67f38c3 100644 --- a/.github/workflows/template-build-linux-x64.yml +++ b/.github/workflows/template-build-linux-x64.yml @@ -127,7 +127,20 @@ jobs: run: | cd engine make build CMAKE_EXTRA_FLAGS="${{ inputs.cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ inputs.build-deps-cmake-flags }}" - + + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Run e2e tests + run: | + python -m pip install --upgrade pip + python -m pip install pytest + python -m pip install requests + cd engine + python e2e-test/main.py + - name: Pre-package run: | cd engine diff --git a/.github/workflows/template-build-windows-x64.yml b/.github/workflows/template-build-windows-x64.yml index 73f3ccb0e..094f4e995 100644 --- a/.github/workflows/template-build-windows-x64.yml +++ b/.github/workflows/template-build-windows-x64.yml @@ -164,6 +164,19 @@ jobs: cd engine make build CMAKE_EXTRA_FLAGS="${{ inputs.cmake-flags }}" BUILD_DEPS_CMAKE_EXTRA_FLAGS="${{ inputs.build-deps-cmake-flags }}" + - name: Install Python + uses: actions/setup-python@v4 + with: + python-version: '3.10' + + - name: Run e2e tests + run: | + python -m pip install --upgrade pip + python -m pip install pytest + python -m pip install requests + cd engine + python e2e-test/main.py + - name: Pre-package run: | cd engine diff --git a/engine/e2e-test/test_runner.py b/engine/e2e-test/test_runner.py index 320b8e332..0a0bb1511 100644 --- a/engine/e2e-test/test_runner.py +++ b/engine/e2e-test/test_runner.py @@ -79,7 +79,7 @@ def start_server_nix() -> bool: start_time = time.time() while time.time() - start_time < timeout: # Use select to check if there's data to read from stdout or stderr - readable, _, _ = select.select([process.stdout, process.stderr], [], [], 0.1) + readable, _, _ = select.select([process.stdout, process.stderr], [], [], 3.0) for stream in readable: line = stream.readline() From 8a71caebcebd6a1b2c76ce0fea21d29b4c174762 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 2 Oct 2024 08:15:27 +0700 Subject: [PATCH 14/22] fix: clone exe --- .github/workflows/template-build-linux-x64.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/template-build-linux-x64.yml b/.github/workflows/template-build-linux-x64.yml index df67f38c3..6cf57ffa3 100644 --- a/.github/workflows/template-build-linux-x64.yml +++ b/.github/workflows/template-build-linux-x64.yml @@ -135,12 +135,16 @@ jobs: - name: Run e2e tests run: | + cp build/cortex build/cortex-nightly + cp build/cortex build/cortex-beta python -m pip install --upgrade pip python -m pip install pytest python -m pip install requests cd engine python e2e-test/main.py - + rm build/cortex-nightly + rm build/cortex-beta + - name: Pre-package run: | cd engine From ad9ac1eef537e9a56e82cafb72edae6ec017d466 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 2 Oct 2024 08:31:54 +0700 Subject: [PATCH 15/22] fix: cd --- .github/workflows/template-build-linux-x64.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/template-build-linux-x64.yml b/.github/workflows/template-build-linux-x64.yml index 6cf57ffa3..2827b2ea2 100644 --- a/.github/workflows/template-build-linux-x64.yml +++ b/.github/workflows/template-build-linux-x64.yml @@ -135,12 +135,12 @@ jobs: - name: Run e2e tests run: | + cd engine cp build/cortex build/cortex-nightly cp build/cortex build/cortex-beta python -m pip install --upgrade pip python -m pip install pytest - python -m pip install requests - cd engine + python -m pip install requests python e2e-test/main.py rm build/cortex-nightly rm build/cortex-beta From 90f5b2648ada145d24efca4e4ac7eedc968fa43b Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 2 Oct 2024 08:32:18 +0700 Subject: [PATCH 16/22] fix: temp comment --- engine/e2e-test/main.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/engine/e2e-test/main.py b/engine/e2e-test/main.py index 37725a2fa..bb76f156f 100644 --- a/engine/e2e-test/main.py +++ b/engine/e2e-test/main.py @@ -1,16 +1,16 @@ import pytest import sys from test_api_engine_list import TestApiEngineList -from test_cli_engine_get import TestCliEngineGet -from test_cli_engine_install import TestCliEngineInstall -from test_cli_engine_list import TestCliEngineList -from test_cli_engine_uninstall import TestCliEngineUninstall -from test_cli_model_delete import TestCliModelDelete -from test_cli_model_pull_direct_url import TestCliModelPullDirectUrl -from test_cli_server_start import TestCliServerStart -from test_cortex_update import TestCortexUpdate -from test_create_log_folder import TestCreateLogFolder -from test_cli_model_import import TestCliModelImport +# from test_cli_engine_get import TestCliEngineGet +# from test_cli_engine_install import TestCliEngineInstall +# from test_cli_engine_list import TestCliEngineList +# from test_cli_engine_uninstall import TestCliEngineUninstall +# from test_cli_model_delete import TestCliModelDelete +# from test_cli_model_pull_direct_url import TestCliModelPullDirectUrl +# from test_cli_server_start import TestCliServerStart +# from test_cortex_update import TestCortexUpdate +# from test_create_log_folder import TestCreateLogFolder +# from test_cli_model_import import TestCliModelImport if __name__ == "__main__": sys.exit(pytest.main([__file__, "-v"])) From b198911392d8355e0dc55dc41a7b11333d56a5ef Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 2 Oct 2024 08:36:26 +0700 Subject: [PATCH 17/22] fix: windows and macos --- .github/workflows/template-build-macos.yml | 8 ++++++-- .../workflows/template-build-windows-x64.yml | 8 ++++++-- engine/e2e-test/main.py | 20 +++++++++---------- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/template-build-macos.yml b/.github/workflows/template-build-macos.yml index 9289fa2bb..70a069dfd 100644 --- a/.github/workflows/template-build-macos.yml +++ b/.github/workflows/template-build-macos.yml @@ -160,11 +160,15 @@ jobs: - name: Run e2e tests run: | + cd engine + cp build/cortex build/cortex-nightly + cp build/cortex build/cortex-beta python -m pip install --upgrade pip python -m pip install pytest - python -m pip install requests - cd engine + python -m pip install requests python e2e-test/main.py + rm build/cortex-nightly + rm build/cortex-beta - name: Pre-package run: | diff --git a/.github/workflows/template-build-windows-x64.yml b/.github/workflows/template-build-windows-x64.yml index 094f4e995..eccb9337a 100644 --- a/.github/workflows/template-build-windows-x64.yml +++ b/.github/workflows/template-build-windows-x64.yml @@ -171,11 +171,15 @@ jobs: - name: Run e2e tests run: | + cd engine + cp build/cortex build/cortex-nightly + cp build/cortex build/cortex-beta python -m pip install --upgrade pip python -m pip install pytest - python -m pip install requests - cd engine + python -m pip install requests python e2e-test/main.py + rm build/cortex-nightly + rm build/cortex-beta - name: Pre-package run: | diff --git a/engine/e2e-test/main.py b/engine/e2e-test/main.py index bb76f156f..37725a2fa 100644 --- a/engine/e2e-test/main.py +++ b/engine/e2e-test/main.py @@ -1,16 +1,16 @@ import pytest import sys from test_api_engine_list import TestApiEngineList -# from test_cli_engine_get import TestCliEngineGet -# from test_cli_engine_install import TestCliEngineInstall -# from test_cli_engine_list import TestCliEngineList -# from test_cli_engine_uninstall import TestCliEngineUninstall -# from test_cli_model_delete import TestCliModelDelete -# from test_cli_model_pull_direct_url import TestCliModelPullDirectUrl -# from test_cli_server_start import TestCliServerStart -# from test_cortex_update import TestCortexUpdate -# from test_create_log_folder import TestCreateLogFolder -# from test_cli_model_import import TestCliModelImport +from test_cli_engine_get import TestCliEngineGet +from test_cli_engine_install import TestCliEngineInstall +from test_cli_engine_list import TestCliEngineList +from test_cli_engine_uninstall import TestCliEngineUninstall +from test_cli_model_delete import TestCliModelDelete +from test_cli_model_pull_direct_url import TestCliModelPullDirectUrl +from test_cli_server_start import TestCliServerStart +from test_cortex_update import TestCortexUpdate +from test_create_log_folder import TestCreateLogFolder +from test_cli_model_import import TestCliModelImport if __name__ == "__main__": sys.exit(pytest.main([__file__, "-v"])) From 14c12f8b485af5480c6395bc5f1a733447c689a1 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 2 Oct 2024 08:49:22 +0700 Subject: [PATCH 18/22] fix: test --- engine/e2e-test/test_create_log_folder.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/engine/e2e-test/test_create_log_folder.py b/engine/e2e-test/test_create_log_folder.py index 3d0236cd7..8b667141b 100644 --- a/engine/e2e-test/test_create_log_folder.py +++ b/engine/e2e-test/test_create_log_folder.py @@ -24,4 +24,8 @@ def setup_and_teardown(self): def test_create_log_folder_run_successfully(self): root = Path.home() - assert os.path.exists(root / "cortexcpp" / "logs") + assert ( + os.path.exists(root / "cortexcpp" / "logs") + or os.path.exists(root / "cortexcpp-beta" / "logs") + or os.path.exists(root / "cortexcpp-nightly" / "logs") + ) From 8af6b785df383b7863b944bd41ef9befdb4ec7a0 Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 2 Oct 2024 08:51:06 +0700 Subject: [PATCH 19/22] fix: windows --- .github/workflows/template-build-windows-x64.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/template-build-windows-x64.yml b/.github/workflows/template-build-windows-x64.yml index eccb9337a..05dc2a0de 100644 --- a/.github/workflows/template-build-windows-x64.yml +++ b/.github/workflows/template-build-windows-x64.yml @@ -172,14 +172,14 @@ jobs: - name: Run e2e tests run: | cd engine - cp build/cortex build/cortex-nightly - cp build/cortex build/cortex-beta + cp build/cortex.exe build/cortex-nightly.exe + cp build/cortex.exe build/cortex-beta.exe python -m pip install --upgrade pip python -m pip install pytest python -m pip install requests python e2e-test/main.py - rm build/cortex-nightly - rm build/cortex-beta + rm build/cortex-nightly.exe + rm build/cortex-beta.exe - name: Pre-package run: | From f7fdd42a111d38827746b3885ff70a1bd147c27b Mon Sep 17 00:00:00 2001 From: vansangpfiev Date: Wed, 2 Oct 2024 08:59:23 +0700 Subject: [PATCH 20/22] fix: readable --- engine/e2e-test/test_runner.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/e2e-test/test_runner.py b/engine/e2e-test/test_runner.py index 0a0bb1511..320b8e332 100644 --- a/engine/e2e-test/test_runner.py +++ b/engine/e2e-test/test_runner.py @@ -79,7 +79,7 @@ def start_server_nix() -> bool: start_time = time.time() while time.time() - start_time < timeout: # Use select to check if there's data to read from stdout or stderr - readable, _, _ = select.select([process.stdout, process.stderr], [], [], 3.0) + readable, _, _ = select.select([process.stdout, process.stderr], [], [], 0.1) for stream in readable: line = stream.readline() From 76e7adf90ad88935796c4781aaad466f9e585e55 Mon Sep 17 00:00:00 2001 From: Hien To Date: Wed, 2 Oct 2024 10:45:29 +0700 Subject: [PATCH 21/22] ci: e2e testing use GITHUB_TOKEN to increase github api rate limit --- .github/workflows/template-build-linux-x64.yml | 2 ++ .github/workflows/template-build-macos.yml | 2 ++ .../workflows/template-build-windows-x64.yml | 2 ++ engine/services/engine_service.cc | 17 ++++++++++++++++- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/template-build-linux-x64.yml b/.github/workflows/template-build-linux-x64.yml index 2827b2ea2..bbd47632a 100644 --- a/.github/workflows/template-build-linux-x64.yml +++ b/.github/workflows/template-build-linux-x64.yml @@ -144,6 +144,8 @@ jobs: python e2e-test/main.py rm build/cortex-nightly rm build/cortex-beta + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Pre-package run: | diff --git a/.github/workflows/template-build-macos.yml b/.github/workflows/template-build-macos.yml index 70a069dfd..327156785 100644 --- a/.github/workflows/template-build-macos.yml +++ b/.github/workflows/template-build-macos.yml @@ -169,6 +169,8 @@ jobs: python e2e-test/main.py rm build/cortex-nightly rm build/cortex-beta + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Pre-package run: | diff --git a/.github/workflows/template-build-windows-x64.yml b/.github/workflows/template-build-windows-x64.yml index 05dc2a0de..e9fe3794f 100644 --- a/.github/workflows/template-build-windows-x64.yml +++ b/.github/workflows/template-build-windows-x64.yml @@ -180,6 +180,8 @@ jobs: python e2e-test/main.py rm build/cortex-nightly.exe rm build/cortex-beta.exe + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Pre-package run: | diff --git a/engine/services/engine_service.cc b/engine/services/engine_service.cc index 54c201db9..913be52f6 100644 --- a/engine/services/engine_service.cc +++ b/engine/services/engine_service.cc @@ -217,6 +217,10 @@ cpp::result EngineService::UninstallEngine( cpp::result EngineService::DownloadEngine( const std::string& engine, const std::string& version) { + + // Check if GITHUB_TOKEN env exist + const char* github_token = std::getenv("GITHUB_TOKEN"); + auto get_params = [&engine, &version]() -> std::vector { if (version == "latest") { return {"repos", "janhq", engine, "releases", version}; @@ -232,7 +236,18 @@ cpp::result EngineService::DownloadEngine( }; httplib::Client cli(url_obj.GetProtocolAndHost()); - if (auto res = cli.Get(url_obj.GetPathAndQuery()); + + httplib::Headers headers; + + if (github_token) { + std::string auth_header = "token " + std::string(github_token); + headers.insert({"Authorization", auth_header}); + CTL_INF("Using authentication with GitHub token."); + } else { + CTL_INF("No GitHub token found. Sending request without authentication."); + } + + if (auto res = cli.Get(url_obj.GetPathAndQuery(), headers); res->status == httplib::StatusCode::OK_200) { auto body = json::parse(res->body); auto get_data = From f6ea8bd5769bb8dabe6cc48cd9f50d5c1e8fbeed Mon Sep 17 00:00:00 2001 From: Hien To Date: Wed, 2 Oct 2024 11:49:16 +0700 Subject: [PATCH 22/22] ci: enable e2e testing in quality gate new PR --- .github/workflows/cortex-cpp-quality-gate.yml | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/.github/workflows/cortex-cpp-quality-gate.yml b/.github/workflows/cortex-cpp-quality-gate.yml index 1d838d0c8..b9fcfe23e 100644 --- a/.github/workflows/cortex-cpp-quality-gate.yml +++ b/.github/workflows/cortex-cpp-quality-gate.yml @@ -2,7 +2,7 @@ name: CI Quality Gate Cortex CPP on: pull_request: - types: [opened, synchronize, reopened] + types: [opened, synchronize, reopened, ready_for_review] paths: [ "engine/**", @@ -53,11 +53,10 @@ jobs: with: submodules: recursive - - name: use python for linux - if: runner.os == 'Linux' - uses: actions/setup-python@v4 + - name: use python + uses: actions/setup-python@v5 with: - python-version: '3.9' + python-version: '3.10' - name: Install tools on Linux if: runner.os == 'Linux' @@ -106,7 +105,38 @@ jobs: run: | cd engine make run-unit-tests - + + - name: Run e2e tests + if: runner.os != 'Windows' && github.event.pull_request.draft == false + run: | + cd engine + cp build/cortex build/cortex-nightly + cp build/cortex build/cortex-beta + python -m pip install --upgrade pip + python -m pip install pytest + python -m pip install requests + python e2e-test/main.py + rm build/cortex-nightly + rm build/cortex-beta + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + + - name: Run e2e tests + if: runner.os == 'Windows' && github.event.pull_request.draft == false + run: | + cd engine + cp build/cortex.exe build/cortex-nightly.exe + cp build/cortex.exe build/cortex-beta.exe + python -m pip install --upgrade pip + python -m pip install pytest + python -m pip install requests + python e2e-test/main.py + rm build/cortex-nightly.exe + rm build/cortex-beta.exe + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Pre-package run: | cd engine