From 535e096b67fe24c6e219e4b57b75d1e81dec28d0 Mon Sep 17 00:00:00 2001 From: FenjuFu Date: Mon, 27 Jul 2026 20:57:32 +0800 Subject: [PATCH 1/2] fix S3 database initialization path --- burr/tracking/server/s3/initialize_db.py | 7 ++--- tests/tracking/test_s3_initialize_db.py | 35 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 tests/tracking/test_s3_initialize_db.py diff --git a/burr/tracking/server/s3/initialize_db.py b/burr/tracking/server/s3/initialize_db.py index e06528bd4..cfe31f5f9 100644 --- a/burr/tracking/server/s3/initialize_db.py +++ b/burr/tracking/server/s3/initialize_db.py @@ -15,19 +15,16 @@ # specific language governing permissions and limitations # under the License. -import os from pathlib import Path from tortoise import Tortoise, run_async from burr.tracking.server.s3 import settings -DB_PATH = Path("~/.burr_server/db.sqlite3").expanduser() - async def connect(): - if not os.path.exists(DB_PATH): - os.makedirs(os.path.dirname(DB_PATH), exist_ok=True) + db_path = Path(settings.DB_PATH).expanduser() + db_path.parent.mkdir(parents=True, exist_ok=True) await Tortoise.init( config=settings.TORTOISE_ORM, ) diff --git a/tests/tracking/test_s3_initialize_db.py b/tests/tracking/test_s3_initialize_db.py new file mode 100644 index 000000000..e1ebe1c8a --- /dev/null +++ b/tests/tracking/test_s3_initialize_db.py @@ -0,0 +1,35 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. + +import asyncio +from unittest.mock import AsyncMock + +from burr.tracking.server.s3 import initialize_db, settings + + +def test_connect_uses_configured_database_path(tmp_path, monkeypatch): + db_path = tmp_path / "nested" / "custom.sqlite3" + tortoise_config = {"connections": {"default": f"sqlite:///{db_path}"}, "apps": {}} + tortoise_init = AsyncMock() + monkeypatch.setattr(settings, "DB_PATH", str(db_path)) + monkeypatch.setattr(settings, "TORTOISE_ORM", tortoise_config) + monkeypatch.setattr(initialize_db.Tortoise, "init", tortoise_init) + + asyncio.run(initialize_db.connect()) + + assert db_path.parent.is_dir() + tortoise_init.assert_awaited_once_with(config=tortoise_config) From af9ca8bacf1b24c8f7795174ea90015ca6e1c46d Mon Sep 17 00:00:00 2001 From: FenjuFu Date: Mon, 27 Jul 2026 22:42:23 +0800 Subject: [PATCH 2/2] test S3 initialization in dedicated CI job --- .github/workflows/python-package.yml | 4 +++- tests/tracking/test_s3_initialize_db.py | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 8fd3a91e6..4bca9dab3 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -96,7 +96,9 @@ jobs: - name: Run S3 tracking server tests run: | - python -m pytest tests/tracking/test_bip0042_s3_buffering.py -v + python -m pytest \ + tests/tracking/test_bip0042_s3_buffering.py \ + tests/tracking/test_s3_initialize_db.py -v test-bedrock: runs-on: ubuntu-latest diff --git a/tests/tracking/test_s3_initialize_db.py b/tests/tracking/test_s3_initialize_db.py index e1ebe1c8a..197587c72 100644 --- a/tests/tracking/test_s3_initialize_db.py +++ b/tests/tracking/test_s3_initialize_db.py @@ -18,6 +18,9 @@ import asyncio from unittest.mock import AsyncMock +import pytest + +pytest.importorskip("tortoise") from burr.tracking.server.s3 import initialize_db, settings