This is an automated email from the ASF dual-hosted git repository. imbajin pushed a commit to branch goal-test in repository https://gitbox.apache.org/repos/asf/hugegraph-ai.git
commit ec71a3d5934ec812c33888ad5a58363ed12b1a11 Author: imbajin <[email protected]> AuthorDate: Sun May 31 01:31:02 2026 +0800 test(quality): standardize hugegraph integration harness - add explicit HugeGraph service fixtures and fail/skip semantics - align LLM CI with HugeGraph 1.7.0 health checks - document integration environment and service contract --- .github/workflows/hugegraph-llm.yml | 21 ++++-- .github/workflows/hugegraph-python-client.yml | 6 ++ .../checkpoints/02-service-fixture.md | 60 +++++++++++++++++ .workflow/quality-program/quality-state.json | 35 ++++++++-- docs/quality/hugegraph-integration.md | 20 ++++++ .../2026-05-31-hugegraph-ai-quality-program.md | 16 ++--- hugegraph-llm/src/tests/conftest.py | 4 ++ hugegraph-llm/src/tests/fixtures/__init__.py | 16 +++++ .../src/tests/fixtures/hugegraph_service.py | 74 +++++++++++++++++++++ hugegraph-python-client/src/tests/client_utils.py | 8 ++- hugegraph-python-client/src/tests/conftest.py | 20 ++++++ .../src/tests/fixtures/__init__.py | 16 +++++ .../src/tests/fixtures/hugegraph_service.py | 75 ++++++++++++++++++++++ 13 files changed, 349 insertions(+), 22 deletions(-) diff --git a/.github/workflows/hugegraph-llm.yml b/.github/workflows/hugegraph-llm.yml index b813483c..6b1ba56c 100644 --- a/.github/workflows/hugegraph-llm.yml +++ b/.github/workflows/hugegraph-llm.yml @@ -34,12 +34,16 @@ jobs: matrix: python-version: ["3.10", "3.11"] - steps: - - name: Prepare HugeGraph Server Environment - run: | - docker run -d --name=graph -p 8080:8080 -e PASSWORD=admin hugegraph/hugegraph:1.5.0 - sleep 10 + services: + hugegraph: + image: hugegraph/hugegraph:1.7.0 + env: + PASSWORD: admin + options: --health-cmd="curl -f http://localhost:8080/versions || exit 1" --health-interval=10s --health-timeout=5s --health-retries=8 + ports: + - 8080:8080 + steps: - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} @@ -77,6 +81,11 @@ jobs: - name: Run integration tests working-directory: hugegraph-llm env: - SKIP_EXTERNAL_SERVICES: true + HUGEGRAPH_REQUIRED: true + HUGEGRAPH_URL: http://127.0.0.1:8080 + HUGEGRAPH_GRAPH: hugegraph + HUGEGRAPH_USER: admin + HUGEGRAPH_PASSWORD: admin + SKIP_EXTERNAL_SERVICES: false run: | uv run pytest src/tests/integration/test_graph_rag_pipeline.py src/tests/integration/test_kg_construction.py src/tests/integration/test_rag_pipeline.py -v --tb=short diff --git a/.github/workflows/hugegraph-python-client.yml b/.github/workflows/hugegraph-python-client.yml index 5dcf27c1..436d80d8 100644 --- a/.github/workflows/hugegraph-python-client.yml +++ b/.github/workflows/hugegraph-python-client.yml @@ -58,6 +58,12 @@ jobs: uv run python hugegraph-python-client/src/pyhugegraph/example/hugegraph_example.py - name: Test with pytest + env: + HUGEGRAPH_REQUIRED: true + HUGEGRAPH_URL: http://127.0.0.1:8080 + HUGEGRAPH_GRAPH: hugegraph + HUGEGRAPH_USER: admin + HUGEGRAPH_PASSWORD: admin run: | uv run pytest working-directory: hugegraph-python-client diff --git a/.workflow/quality-program/checkpoints/02-service-fixture.md b/.workflow/quality-program/checkpoints/02-service-fixture.md new file mode 100644 index 00000000..233ebb01 --- /dev/null +++ b/.workflow/quality-program/checkpoints/02-service-fixture.md @@ -0,0 +1,60 @@ +# G1 Service Fixture Checkpoint + +## Files Touched + +- `hugegraph-python-client/src/tests/fixtures/hugegraph_service.py` +- `hugegraph-python-client/src/tests/fixtures/__init__.py` +- `hugegraph-python-client/src/tests/conftest.py` +- `hugegraph-python-client/src/tests/client_utils.py` +- `hugegraph-llm/src/tests/fixtures/hugegraph_service.py` +- `hugegraph-llm/src/tests/fixtures/__init__.py` +- `hugegraph-llm/src/tests/conftest.py` +- `.github/workflows/hugegraph-python-client.yml` +- `.github/workflows/hugegraph-llm.yml` +- `docs/quality/hugegraph-integration.md` + +## Harness Changes + +- Added explicit `HugeGraphService` env contract helpers for client and LLM tests. +- Added `HUGEGRAPH_REQUIRED=true` behavior: selected service tests fail if `/versions` is unavailable after the retry budget. +- Preserved local opt-out semantics: when `HUGEGRAPH_REQUIRED=false`, selected integration tests may skip if no local service is running. +- Adapted `ClientUtils(service=...)` so future client contract tests can use fixture-provided URL, graph, auth, and graphspace values. + +## CI Changes + +- Replaced LLM CI manual `docker run ... hugegraph/hugegraph:1.5.0` plus `sleep 10` with a GitHub Actions service using `hugegraph/hugegraph:1.7.0`. +- Added `/versions` health check for LLM CI with eight retries. +- Added explicit `HUGEGRAPH_REQUIRED`, `HUGEGRAPH_URL`, `HUGEGRAPH_GRAPH`, `HUGEGRAPH_USER`, and `HUGEGRAPH_PASSWORD` env to selected integration jobs. +- Client CI already used HugeGraph `1.7.0`; G1 adds explicit HugeGraph env to its pytest step. + +## Commands Run + +```bash +uv run pytest hugegraph-python-client/src/tests -m "unit or contract" -q +uv run pytest src/tests -m "unit or contract" -q +HUGEGRAPH_REQUIRED=true uv run pytest hugegraph-python-client/src/tests -m "integration and hugegraph" --collect-only -q +HUGEGRAPH_REQUIRED=true uv run pytest src/tests -m "integration and hugegraph" --collect-only -q +uv run ruff format --check hugegraph-python-client/src/tests hugegraph-llm/src/tests +uv run ruff check hugegraph-python-client/src/tests hugegraph-llm/src/tests +git diff --check +uv run python -c "import yaml, pathlib; [yaml.safe_load(pathlib.Path(p).read_text()) for p in ['.github/workflows/hugegraph-llm.yml','.github/workflows/hugegraph-python-client.yml']]" +``` + +## Results + +- Client Layer A: 15 passed, 56 deselected. +- LLM Layer A: 101 passed, 175 deselected. +- Client Layer B collection: 56 selected, 15 deselected. +- LLM Layer B collection: no tests selected yet; pytest returned exit code 5. This is classified as a current coverage gap to be filled by G3, not a service setup failure. +- Ruff format and lint checks passed for touched test files. +- Workflow YAML parsed successfully with PyYAML. + +## Failures or Skips + +- No selected unit/contract test requires Docker. +- LLM `integration and hugegraph` selection is empty before G3 adds real-boundary tests. + +## Next Goal Readiness + +- Ready for G2 pyhugegraph contract hardening. +- G2 should convert client integration tests to consume `hugegraph_service` and should run real HugeGraph tests only with `HUGEGRAPH_REQUIRED=true`. diff --git a/.workflow/quality-program/quality-state.json b/.workflow/quality-program/quality-state.json index 3838517e..385a3954 100644 --- a/.workflow/quality-program/quality-state.json +++ b/.workflow/quality-program/quality-state.json @@ -1,11 +1,12 @@ { - "current_goal": "G1", + "current_goal": "G2", "repo_sha_start": "d048bc9fa07042833549dd1def5ff3222c47be70", "base_branch": "main", "open_pr_snapshot_time": "2026-05-30T17:18:30Z", "goals_completed": [ "P0", - "G0" + "G0", + "G1" ], "files_touched": [ ".workflow/quality-program/README.md", @@ -46,11 +47,22 @@ "hugegraph-python-client/src/tests/api/test_task.py", "hugegraph-python-client/src/tests/api/test_traverser.py", "hugegraph-python-client/src/tests/api/test_variable.py", - "hugegraph-python-client/src/tests/api/test_version.py" + "hugegraph-python-client/src/tests/api/test_version.py", + "hugegraph-python-client/src/tests/fixtures/__init__.py", + "hugegraph-python-client/src/tests/fixtures/hugegraph_service.py", + "hugegraph-python-client/src/tests/conftest.py", + "hugegraph-python-client/src/tests/client_utils.py", + "hugegraph-llm/src/tests/fixtures/__init__.py", + "hugegraph-llm/src/tests/fixtures/hugegraph_service.py", + ".github/workflows/hugegraph-python-client.yml", + ".github/workflows/hugegraph-llm.yml", + "docs/quality/hugegraph-integration.md", + ".workflow/quality-program/checkpoints/02-service-fixture.md" ], "production_changes": [], "tests_added_or_changed": [ - "Added file-level unit/contract/integration/hugegraph markers to selected existing tests for Layer A and Layer B selection." + "Added file-level unit/contract/integration/hugegraph markers to selected existing tests for Layer A and Layer B selection.", + "Added HugeGraph service fixtures and conftest wiring for client and LLM test suites." ], "commands_run": [ "sed -n '1,220p' AGENTS.md", @@ -77,11 +89,20 @@ "uv run pytest src/tests -m \"unit or contract\" --cov=hugegraph_llm --cov-report=term --cov-report=json:../.workflow/quality-program/coverage/llm-baseline.json", "uv run ruff format --check hugegraph-llm/src/tests hugegraph-python-client/src/tests pyproject.toml", "uv run ruff check hugegraph-llm/src/tests hugegraph-python-client/src/tests pyproject.toml", - "uv run ruff check hugegraph-python-client/src/tests/api/test_auth.py hugegraph-python-client/src/tests/api/test_graph.py hugegraph-python-client/src/tests/api/test_task.py --fix" + "uv run ruff check hugegraph-python-client/src/tests/api/test_auth.py hugegraph-python-client/src/tests/api/test_graph.py hugegraph-python-client/src/tests/api/test_task.py --fix", + "uv run pytest hugegraph-python-client/src/tests -m \"unit or contract\" -q", + "uv run pytest src/tests -m \"unit or contract\" -q", + "HUGEGRAPH_REQUIRED=true uv run pytest hugegraph-python-client/src/tests -m \"integration and hugegraph\" --collect-only -q", + "HUGEGRAPH_REQUIRED=true uv run pytest src/tests -m \"integration and hugegraph\" --collect-only -q", + "uv run ruff format --check hugegraph-python-client/src/tests hugegraph-llm/src/tests", + "uv run ruff check hugegraph-python-client/src/tests hugegraph-llm/src/tests", + "git diff --check", + "uv run python -c \"import yaml, pathlib; [yaml.safe_load(pathlib.Path(p).read_text()) for p in ['.github/workflows/hugegraph-llm.yml','.github/workflows/hugegraph-python-client.yml']]\"" ], "known_failures": [ "Root-level LLM collection command fails before collection because existing prompt config requires cwd hugegraph-llm.", - "Initial coverage command failed before uv sync because pytest-cov was missing from the active environment." + "Initial coverage command failed before uv sync because pytest-cov was missing from the active environment.", + "LLM integration and hugegraph collection is empty before G3 adds real-boundary tests; pytest returns exit code 5." ], "deferred_items": [ "Avoid #350/#277 YAML config migration files unless tests require a narrow compatibility assertion.", @@ -90,5 +111,5 @@ "Avoid #240 vector/property embedding abstraction surface.", "Quarantine client/test fixes overlapping #323/#329/#342 until exact changed files are inspected." ], - "next_recommended_action": "Standardize HugeGraph service fixture and CI readiness" + "next_recommended_action": "Harden pyhugegraph contract coverage" } diff --git a/docs/quality/hugegraph-integration.md b/docs/quality/hugegraph-integration.md new file mode 100644 index 00000000..0edbc486 --- /dev/null +++ b/docs/quality/hugegraph-integration.md @@ -0,0 +1,20 @@ +# HugeGraph Integration Test Service + +Default image: `hugegraph/hugegraph:1.7.0` + +## Environment + +```text +HUGEGRAPH_URL=http://127.0.0.1:8080 +HUGEGRAPH_GRAPH=hugegraph +HUGEGRAPH_USER=admin +HUGEGRAPH_PASSWORD=admin +HUGEGRAPH_GRAPHSPACE= +HUGEGRAPH_REQUIRED=true|false +``` + +## Semantics + +- If `HUGEGRAPH_REQUIRED=true`, selected integration tests fail when the service is unavailable. +- If `HUGEGRAPH_REQUIRED=false`, local integration tests may skip when no service is present. +- Default unit/contract tests must not require Docker. diff --git a/docs/superpowers/plans/2026-05-31-hugegraph-ai-quality-program.md b/docs/superpowers/plans/2026-05-31-hugegraph-ai-quality-program.md index 770d356d..51246039 100644 --- a/docs/superpowers/plans/2026-05-31-hugegraph-ai-quality-program.md +++ b/docs/superpowers/plans/2026-05-31-hugegraph-ai-quality-program.md @@ -423,7 +423,7 @@ git commit -m "test(quality): define test taxonomy and baseline" -m "- add stric - Create: `docs/quality/hugegraph-integration.md` - Create/Update: `.workflow/quality-program/checkpoints/02-service-fixture.md` -- [ ] **Step G1.1: Add client HugeGraph service helper** +- [x] **Step G1.1: Add client HugeGraph service helper** Create `hugegraph-python-client/src/tests/fixtures/hugegraph_service.py`: @@ -488,7 +488,7 @@ def hugegraph_service() -> HugeGraphService: return service ``` -- [ ] **Step G1.2: Wire client conftest to helper** +- [x] **Step G1.2: Wire client conftest to helper** Create or update `hugegraph-python-client/src/tests/conftest.py`: @@ -498,7 +498,7 @@ from .fixtures.hugegraph_service import hugegraph_service __all__ = ["hugegraph_service"] ``` -- [ ] **Step G1.3: Adapt client utility to environment contract** +- [x] **Step G1.3: Adapt client utility to environment contract** Modify `hugegraph-python-client/src/tests/client_utils.py` so `ClientUtils` accepts optional service config: @@ -529,7 +529,7 @@ class ClientUtils: Keep the existing initialization methods unchanged. -- [ ] **Step G1.4: Add LLM HugeGraph service wrapper** +- [x] **Step G1.4: Add LLM HugeGraph service wrapper** Create `hugegraph-llm/src/tests/fixtures/hugegraph_service.py`: @@ -592,7 +592,7 @@ def hugegraph_service() -> HugeGraphService: return service ``` -- [ ] **Step G1.5: Update LLM CI to HugeGraph 1.7.0 health checks** +- [x] **Step G1.5: Update LLM CI to HugeGraph 1.7.0 health checks** Modify `.github/workflows/hugegraph-llm.yml`: @@ -620,7 +620,7 @@ Set integration test env for HugeGraph-selected jobs: HUGEGRAPH_PASSWORD: admin ``` -- [ ] **Step G1.6: Document service usage** +- [x] **Step G1.6: Document service usage** Create `docs/quality/hugegraph-integration.md`: @@ -647,7 +647,7 @@ HUGEGRAPH_REQUIRED=true|false - Default unit/contract tests must not require Docker. ``` -- [ ] **Step G1.7: Run harness verification** +- [x] **Step G1.7: Run harness verification** Run: @@ -660,7 +660,7 @@ HUGEGRAPH_REQUIRED=true uv run pytest hugegraph-llm/src/tests -m "integration an Expected: unit/contract tests do not require Docker. Integration collection uses known markers. -- [ ] **Step G1.8: Write checkpoint and commit** +- [x] **Step G1.8: Write checkpoint and commit** Create `.workflow/quality-program/checkpoints/02-service-fixture.md` with files touched, commands run, and failures/skips. diff --git a/hugegraph-llm/src/tests/conftest.py b/hugegraph-llm/src/tests/conftest.py index 8819e515..42033626 100644 --- a/hugegraph-llm/src/tests/conftest.py +++ b/hugegraph-llm/src/tests/conftest.py @@ -29,6 +29,10 @@ sys.path.insert(0, project_root) src_path = os.path.join(project_root, "src") sys.path.insert(0, src_path) +from tests.fixtures.hugegraph_service import hugegraph_service # noqa: E402 + +__all__ = ["hugegraph_service"] + # Download NLTK resources def download_nltk_resources(): diff --git a/hugegraph-llm/src/tests/fixtures/__init__.py b/hugegraph-llm/src/tests/fixtures/__init__.py new file mode 100644 index 00000000..13a83393 --- /dev/null +++ b/hugegraph-llm/src/tests/fixtures/__init__.py @@ -0,0 +1,16 @@ +# 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. diff --git a/hugegraph-llm/src/tests/fixtures/hugegraph_service.py b/hugegraph-llm/src/tests/fixtures/hugegraph_service.py new file mode 100644 index 00000000..a6318eb9 --- /dev/null +++ b/hugegraph-llm/src/tests/fixtures/hugegraph_service.py @@ -0,0 +1,74 @@ +# 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 os +import time +from dataclasses import dataclass + +import pytest +import requests + + +@dataclass(frozen=True) +class HugeGraphService: + url: str + graph: str + user: str + password: str + graphspace: str | None + + +def hugegraph_required() -> bool: + return os.getenv("HUGEGRAPH_REQUIRED", "false").lower() == "true" + + +def hugegraph_service_from_env() -> HugeGraphService: + return HugeGraphService( + url=os.getenv("HUGEGRAPH_URL", "http://127.0.0.1:8080"), + graph=os.getenv("HUGEGRAPH_GRAPH", "hugegraph"), + user=os.getenv("HUGEGRAPH_USER", "admin"), + password=os.getenv("HUGEGRAPH_PASSWORD", "admin"), + graphspace=os.getenv("HUGEGRAPH_GRAPHSPACE") or None, + ) + + +def wait_for_hugegraph(service: HugeGraphService, timeout_seconds: int = 60) -> None: + deadline = time.monotonic() + timeout_seconds + last_error: Exception | None = None + while time.monotonic() < deadline: + try: + response = requests.get(f"{service.url}/versions", timeout=5) + response.raise_for_status() + return + except requests.RequestException as exc: + last_error = exc + time.sleep(2) + raise RuntimeError(f"HugeGraph is not ready at {service.url}/versions") from last_error + + [email protected](scope="session") +def hugegraph_service() -> HugeGraphService: + service = hugegraph_service_from_env() + if hugegraph_required(): + wait_for_hugegraph(service) + return service + + try: + wait_for_hugegraph(service, timeout_seconds=5) + except RuntimeError as exc: + pytest.skip(f"HugeGraph integration tests not selected with required service: {exc}") + return service diff --git a/hugegraph-python-client/src/tests/client_utils.py b/hugegraph-python-client/src/tests/client_utils.py index 1914cdb0..340fb101 100644 --- a/hugegraph-python-client/src/tests/client_utils.py +++ b/hugegraph-python-client/src/tests/client_utils.py @@ -26,7 +26,13 @@ class ClientUtils: GRAPHSPACE = None TIMEOUT = 10 - def __init__(self): + def __init__(self, service=None): + if service is not None: + self.URL = service.url + self.GRAPH = service.graph + self.USERNAME = service.user + self.PASSWORD = service.password + self.GRAPHSPACE = service.graphspace self.client = PyHugeClient( url=self.URL, user=self.USERNAME, diff --git a/hugegraph-python-client/src/tests/conftest.py b/hugegraph-python-client/src/tests/conftest.py new file mode 100644 index 00000000..6adf0295 --- /dev/null +++ b/hugegraph-python-client/src/tests/conftest.py @@ -0,0 +1,20 @@ +# 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. + +from .fixtures.hugegraph_service import hugegraph_service + +__all__ = ["hugegraph_service"] diff --git a/hugegraph-python-client/src/tests/fixtures/__init__.py b/hugegraph-python-client/src/tests/fixtures/__init__.py new file mode 100644 index 00000000..13a83393 --- /dev/null +++ b/hugegraph-python-client/src/tests/fixtures/__init__.py @@ -0,0 +1,16 @@ +# 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. diff --git a/hugegraph-python-client/src/tests/fixtures/hugegraph_service.py b/hugegraph-python-client/src/tests/fixtures/hugegraph_service.py new file mode 100644 index 00000000..324b17ea --- /dev/null +++ b/hugegraph-python-client/src/tests/fixtures/hugegraph_service.py @@ -0,0 +1,75 @@ +# 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 os +import time +from dataclasses import dataclass + +import pytest +import requests + + +@dataclass(frozen=True) +class HugeGraphService: + url: str + graph: str + user: str + password: str + graphspace: str | None + + +def hugegraph_required() -> bool: + return os.getenv("HUGEGRAPH_REQUIRED", "false").lower() == "true" + + +def hugegraph_service_from_env() -> HugeGraphService: + graphspace = os.getenv("HUGEGRAPH_GRAPHSPACE") or None + return HugeGraphService( + url=os.getenv("HUGEGRAPH_URL", "http://127.0.0.1:8080"), + graph=os.getenv("HUGEGRAPH_GRAPH", "hugegraph"), + user=os.getenv("HUGEGRAPH_USER", "admin"), + password=os.getenv("HUGEGRAPH_PASSWORD", "admin"), + graphspace=graphspace, + ) + + +def wait_for_hugegraph(service: HugeGraphService, timeout_seconds: int = 60) -> None: + deadline = time.monotonic() + timeout_seconds + last_error: Exception | None = None + while time.monotonic() < deadline: + try: + response = requests.get(f"{service.url}/versions", timeout=5) + response.raise_for_status() + return + except requests.RequestException as exc: + last_error = exc + time.sleep(2) + raise RuntimeError(f"HugeGraph is not ready at {service.url}/versions") from last_error + + [email protected](scope="session") +def hugegraph_service() -> HugeGraphService: + service = hugegraph_service_from_env() + if hugegraph_required(): + wait_for_hugegraph(service) + return service + + try: + wait_for_hugegraph(service, timeout_seconds=5) + except RuntimeError as exc: + pytest.skip(f"HugeGraph integration tests not selected with required service: {exc}") + return service
