From 3de3436d94263a0f1dee3b35d99a1da4f1e8e243 Mon Sep 17 00:00:00 2001 From: kerthcet Date: Tue, 23 Dec 2025 05:33:30 +0800 Subject: [PATCH 1/6] add ci workflow Signed-off-by: kerthcet --- .github/workflows/ci-test.yaml | 55 +++++++++++++++++++ .gitignore | 2 + Makefile | 30 ++-------- bindings/python/Makefile | 31 +++++++++++ bindings/python/README.md | 1 + {amrs => bindings/python/amrs}/__init__.py | 0 {amrs => bindings/python/amrs}/config.py | 0 .../python/amrs}/router/__init__.py | 0 .../python/amrs}/router/random.py | 0 .../python/amrs}/router/router.py | 0 .../python/amrs}/store/__init__.py | 0 {amrs => bindings/python/amrs}/store/store.py | 0 .../python/pyproject.toml | 0 start.sh => bindings/python/start.sh | 0 {tests => bindings/python/tests}/__init__.py | 0 .../python/tests/integration}/__init__.py | 0 .../python/tests/integration/config_test.py | 3 + .../python/tests}/unit/__init__.py | 0 .../python/tests}/unit/config_test.py | 0 bindings/python/tests/unit/conftest.py | 3 + uv.lock => bindings/python/uv.lock | 0 tests/unit/conftest.py | 3 - 22 files changed, 99 insertions(+), 29 deletions(-) create mode 100644 .github/workflows/ci-test.yaml create mode 100644 bindings/python/Makefile create mode 100644 bindings/python/README.md rename {amrs => bindings/python/amrs}/__init__.py (100%) rename {amrs => bindings/python/amrs}/config.py (100%) rename {amrs => bindings/python/amrs}/router/__init__.py (100%) rename {amrs => bindings/python/amrs}/router/random.py (100%) rename {amrs => bindings/python/amrs}/router/router.py (100%) rename {amrs => bindings/python/amrs}/store/__init__.py (100%) rename {amrs => bindings/python/amrs}/store/store.py (100%) rename pyproject.toml => bindings/python/pyproject.toml (100%) rename start.sh => bindings/python/start.sh (100%) rename {tests => bindings/python/tests}/__init__.py (100%) rename {tests/integration_tests => bindings/python/tests/integration}/__init__.py (100%) create mode 100644 bindings/python/tests/integration/config_test.py rename {tests => bindings/python/tests}/unit/__init__.py (100%) rename {tests => bindings/python/tests}/unit/config_test.py (100%) create mode 100644 bindings/python/tests/unit/conftest.py rename uv.lock => bindings/python/uv.lock (100%) delete mode 100644 tests/unit/conftest.py diff --git a/.github/workflows/ci-test.yaml b/.github/workflows/ci-test.yaml new file mode 100644 index 0000000..10dcbc0 --- /dev/null +++ b/.github/workflows/ci-test.yaml @@ -0,0 +1,55 @@ +name: CI Test + +on: + pull_request: + types: + - opened + - synchronize + +jobs: + test-python: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.12" + + - name: Install uv + run: pip install uv + + - name: Install dependencies + run: source start.sh + + - name: cd into backend directory + run: cd bindings/python + + - name: Run tests + run: make test + + - name: Install docker-compose + run: | + sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + sudo chmod +x /usr/local/bin/docker-compose + docker-compose --version + + - name: Run integration tests + run: | + make test-integration + + test-rust: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Run tests + run: make test \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0bd1d11..fcfc13f 100644 --- a/.gitignore +++ b/.gitignore @@ -18,3 +18,5 @@ dist/ # Added by cargo /target +.ruff_cache/ +.venv/ diff --git a/Makefile b/Makefile index c9633f7..8a8c246 100644 --- a/Makefile +++ b/Makefile @@ -1,31 +1,9 @@ -POETRY := poetry -RUFF := .venv/bin/ruff -PYTEST := .venv/bin/pytest - -.PHONY: build -build: lint - $(POETRY) build - -.PHONY: publish -publish: build - $(POETRY) publish --username=__token__ --password=$(INFTYAI_PYPI_TOKEN) - -.PHONY: lint -lint: - $(RUFF) check . +CARGO := cargo .PHONY: format format: - $(RUFF) format . - $(RUFF) check --fix . + $(CARGO) fmt .PHONY: test -test: lint - $(PYTEST) tests/unit --timeout=15 - -.PHONY: test-integration -test-integration: lint - $(PYTEST) tests/integration --timeout=30 - ' -.PHONY: test-all -test-all: test test-integration +test: format + $(CARGO) test diff --git a/bindings/python/Makefile b/bindings/python/Makefile new file mode 100644 index 0000000..9db814d --- /dev/null +++ b/bindings/python/Makefile @@ -0,0 +1,31 @@ +POETRY := poetry +RUFF := .venv/bin/ruff +PYTEST := .venv/bin/pytest + +.PHONY: build +build: lint + $(POETRY) build + +.PHONY: publish +publish: build + $(POETRY) publish --username=__token__ --password=$(INFTYAI_PYPI_TOKEN) + +.PHONY: lint +lint: + $(RUFF) check . + +.PHONY: format +format: + $(RUFF) format . + $(RUFF) check --fix . + +.PHONY: test +test: lint + $(PYTEST) tests/unit --timeout=15 + +.PHONY: test-integration +test-integration: lint + $(PYTEST) tests/integration --timeout=30 + +.PHONY: test-all +test-all: test test-integration diff --git a/bindings/python/README.md b/bindings/python/README.md new file mode 100644 index 0000000..34f4514 --- /dev/null +++ b/bindings/python/README.md @@ -0,0 +1 @@ +# Python Binding for AMRS diff --git a/amrs/__init__.py b/bindings/python/amrs/__init__.py similarity index 100% rename from amrs/__init__.py rename to bindings/python/amrs/__init__.py diff --git a/amrs/config.py b/bindings/python/amrs/config.py similarity index 100% rename from amrs/config.py rename to bindings/python/amrs/config.py diff --git a/amrs/router/__init__.py b/bindings/python/amrs/router/__init__.py similarity index 100% rename from amrs/router/__init__.py rename to bindings/python/amrs/router/__init__.py diff --git a/amrs/router/random.py b/bindings/python/amrs/router/random.py similarity index 100% rename from amrs/router/random.py rename to bindings/python/amrs/router/random.py diff --git a/amrs/router/router.py b/bindings/python/amrs/router/router.py similarity index 100% rename from amrs/router/router.py rename to bindings/python/amrs/router/router.py diff --git a/amrs/store/__init__.py b/bindings/python/amrs/store/__init__.py similarity index 100% rename from amrs/store/__init__.py rename to bindings/python/amrs/store/__init__.py diff --git a/amrs/store/store.py b/bindings/python/amrs/store/store.py similarity index 100% rename from amrs/store/store.py rename to bindings/python/amrs/store/store.py diff --git a/pyproject.toml b/bindings/python/pyproject.toml similarity index 100% rename from pyproject.toml rename to bindings/python/pyproject.toml diff --git a/start.sh b/bindings/python/start.sh similarity index 100% rename from start.sh rename to bindings/python/start.sh diff --git a/tests/__init__.py b/bindings/python/tests/__init__.py similarity index 100% rename from tests/__init__.py rename to bindings/python/tests/__init__.py diff --git a/tests/integration_tests/__init__.py b/bindings/python/tests/integration/__init__.py similarity index 100% rename from tests/integration_tests/__init__.py rename to bindings/python/tests/integration/__init__.py diff --git a/bindings/python/tests/integration/config_test.py b/bindings/python/tests/integration/config_test.py new file mode 100644 index 0000000..0885f81 --- /dev/null +++ b/bindings/python/tests/integration/config_test.py @@ -0,0 +1,3 @@ + +def test_fake(): + print("This is a fake test to ensure the test suite runs.") diff --git a/tests/unit/__init__.py b/bindings/python/tests/unit/__init__.py similarity index 100% rename from tests/unit/__init__.py rename to bindings/python/tests/unit/__init__.py diff --git a/tests/unit/config_test.py b/bindings/python/tests/unit/config_test.py similarity index 100% rename from tests/unit/config_test.py rename to bindings/python/tests/unit/config_test.py diff --git a/bindings/python/tests/unit/conftest.py b/bindings/python/tests/unit/conftest.py new file mode 100644 index 0000000..3f02a29 --- /dev/null +++ b/bindings/python/tests/unit/conftest.py @@ -0,0 +1,3 @@ +from dotenv import load_dotenv + +load_dotenv(dotenv_path="../../.env.test") diff --git a/uv.lock b/bindings/python/uv.lock similarity index 100% rename from uv.lock rename to bindings/python/uv.lock diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py deleted file mode 100644 index eae9640..0000000 --- a/tests/unit/conftest.py +++ /dev/null @@ -1,3 +0,0 @@ -from dotenv import load_dotenv - -load_dotenv(dotenv_path=".env.test") From f10b29c127823502cfc49e22c06a1f1fb905d478 Mon Sep 17 00:00:00 2001 From: kerthcet Date: Tue, 23 Dec 2025 05:34:54 +0800 Subject: [PATCH 2/6] fix workflow Signed-off-by: kerthcet --- .github/workflows/ci-test.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-test.yaml b/.github/workflows/ci-test.yaml index 10dcbc0..42a5d66 100644 --- a/.github/workflows/ci-test.yaml +++ b/.github/workflows/ci-test.yaml @@ -21,12 +21,12 @@ jobs: - name: Install uv run: pip install uv - - name: Install dependencies - run: source start.sh - - name: cd into backend directory run: cd bindings/python + - name: Install dependencies + run: source start.sh + - name: Run tests run: make test From 98c3459a7fcf0d435aa32f1d956e27d2c7241a4b Mon Sep 17 00:00:00 2001 From: kerthcet Date: Tue, 23 Dec 2025 05:38:44 +0800 Subject: [PATCH 3/6] fix env error Signed-off-by: kerthcet --- src/client/client.rs | 3 +++ src/config.rs | 2 ++ 2 files changed, 5 insertions(+) diff --git a/src/client/client.rs b/src/client/client.rs index a7b9123..36a72b3 100644 --- a/src/client/client.rs +++ b/src/client/client.rs @@ -40,9 +40,12 @@ impl Client { mod tests { use super::*; use crate::config::{Config, ModelConfig, RoutingMode}; + use dotenvy::from_filename; #[test] fn test_client_new() { + from_filename(".env.test").ok(); + struct TestCase { name: &'static str, config: Config, diff --git a/src/config.rs b/src/config.rs index 521e3e4..7756be0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -289,6 +289,8 @@ mod tests { #[test] fn test_populate_config() { + from_filename(".env.test").ok(); + let mut valid_cfg = Config::builder() .temperature(0.5) .max_output_tokens(1500) From 8a19f3ced82d1cec288d5343112a0453322a05cc Mon Sep 17 00:00:00 2001 From: kerthcet Date: Tue, 23 Dec 2025 05:40:30 +0800 Subject: [PATCH 4/6] fix test error Signed-off-by: kerthcet --- .github/workflows/ci-test.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci-test.yaml b/.github/workflows/ci-test.yaml index 42a5d66..43f7477 100644 --- a/.github/workflows/ci-test.yaml +++ b/.github/workflows/ci-test.yaml @@ -21,13 +21,12 @@ jobs: - name: Install uv run: pip install uv - - name: cd into backend directory - run: cd bindings/python - - name: Install dependencies + working-directory: bindings/python run: source start.sh - name: Run tests + working-directory: bindings/python run: make test - name: Install docker-compose @@ -37,6 +36,7 @@ jobs: docker-compose --version - name: Run integration tests + working-directory: bindings/python run: | make test-integration From b7ab87a2a72c5ac1b71e75d2c7a3801330f9d2e9 Mon Sep 17 00:00:00 2001 From: kerthcet Date: Tue, 23 Dec 2025 05:42:54 +0800 Subject: [PATCH 5/6] fix test error Signed-off-by: kerthcet --- src/config.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 7756be0..876144d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -315,7 +315,7 @@ mod tests { assert!(valid_cfg.as_ref().unwrap().models[0].weight == -1); let mut valid_specified_cfg = Config::builder() - .provider("DEEPINFRA".to_string()) + .provider("AMRS".to_string()) .base_url("http://custom-api.ai".to_string()) .model( ModelConfig::builder() @@ -327,7 +327,7 @@ mod tests { valid_specified_cfg.as_mut().unwrap().populate(); assert!(valid_specified_cfg.is_ok()); - assert!(valid_specified_cfg.as_ref().unwrap().provider == "DEEPINFRA".to_string()); + assert!(valid_specified_cfg.as_ref().unwrap().provider == "AMRS".to_string()); assert!( valid_specified_cfg.as_ref().unwrap().models[0].base_url == Some("http://custom-api.ai".to_string()) From 1ff193c3dab2be781754180187164cbf9edab33b Mon Sep 17 00:00:00 2001 From: kerthcet Date: Tue, 23 Dec 2025 05:43:43 +0800 Subject: [PATCH 6/6] change job name in ci Signed-off-by: kerthcet --- .github/workflows/ci-test.yaml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/ci-test.yaml b/.github/workflows/ci-test.yaml index 43f7477..e405b36 100644 --- a/.github/workflows/ci-test.yaml +++ b/.github/workflows/ci-test.yaml @@ -7,7 +7,21 @@ on: - synchronize jobs: - test-python: + test-rust-core: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Run tests + run: make test + + test-python-binding: runs-on: ubuntu-latest steps: @@ -39,17 +53,3 @@ jobs: working-directory: bindings/python run: | make test-integration - - test-rust: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - - name: Set up Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - - name: Run tests - run: make test \ No newline at end of file