Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
8e75e15
Test a generic clp package start up and spin down (default: clp-text).
quinntaylormitchell Oct 17, 2025
44ee20e
Merge branch 'main' into feature branch
quinntaylormitchell Oct 23, 2025
bbe0575
Expand to clp-text and clp-json; store JSON config pairs in temp conf…
quinntaylormitchell Oct 24, 2025
5cd47f8
Merge branch 'main' into feature branch
quinntaylormitchell Oct 30, 2025
c5375eb
Include and employ clp_py_utils.clp_config; refrain from using the us…
quinntaylormitchell Nov 1, 2025
2be837f
Lint.
quinntaylormitchell Nov 1, 2025
bf14b5e
Refactor; move all utility functions to utils files as appropriate.
quinntaylormitchell Nov 2, 2025
27b7f5b
Add comments.
quinntaylormitchell Nov 2, 2025
e041f0e
Streamline logger calls.
quinntaylormitchell Nov 2, 2025
75672fc
Deduplicate fixture code.
quinntaylormitchell Nov 2, 2025
0822a79
Merge branch 'main' into feature branch
quinntaylormitchell Nov 5, 2025
2df9515
Change method of clp_config import; temporary, will change again once…
quinntaylormitchell Nov 5, 2025
63f3ae4
Generalize code so that it's better equipped to handle future CLP_MOD…
quinntaylormitchell Nov 5, 2025
0011447
Merge branch 'main' into feature branch
quinntaylormitchell Nov 6, 2025
0ff9465
Combine PackageConfig, PackageModeConfig, and PackageInstanceConfig i…
quinntaylormitchell Nov 6, 2025
cdcfaee
Employ a 'CLPConfig'-centric approach rather than 'dict'-centric.
quinntaylormitchell Nov 6, 2025
53e7343
Store list of required components for each mode
quinntaylormitchell Nov 6, 2025
796ffe3
Generalize the method by which the mode of operation is determined.
quinntaylormitchell Nov 6, 2025
bae12de
Move all mode-related utilities to their own file.
quinntaylormitchell Nov 6, 2025
9c9ef74
Minor error.
quinntaylormitchell Nov 6, 2025
0f3dcd5
Move load_yaml_to_dict to general utilities file.
quinntaylormitchell Nov 6, 2025
f9865a8
Add taskfile tasks for package tests.
quinntaylormitchell Nov 6, 2025
865e9ed
Address rabbit comments.
quinntaylormitchell Nov 7, 2025
09d5200
Add mariadb_config install for linting purposes (will be unecessary a…
quinntaylormitchell Nov 7, 2025
5fffc32
Lint YAML.
quinntaylormitchell Nov 7, 2025
571f313
Merge branch 'main' into feature branch
quinntaylormitchell Nov 7, 2025
e348be0
Adapt code after #1549 merge.
quinntaylormitchell Nov 7, 2025
30f186f
Merge branch 'main' into feature branch
quinntaylormitchell Nov 10, 2025
e5da7e9
Merge branch 'main' into feature branch
quinntaylormitchell Nov 10, 2025
292ec70
Merge branch 'main' into feature branch
quinntaylormitchell Nov 11, 2025
0c4cfa4
Remove 'python -m'.
quinntaylormitchell Nov 11, 2025
bee738a
Address Bill-hbrhbr comments.
quinntaylormitchell Nov 12, 2025
49eaf97
Brush up docstrings.
quinntaylormitchell Nov 14, 2025
e3c4a3b
Merge branch 'main' into feature branch
quinntaylormitchell Nov 14, 2025
4cd92e6
Adapt to PascalCase ClpConfig.
quinntaylormitchell Nov 14, 2025
87c4809
Merge branch 'main' into feature branch
quinntaylormitchell Nov 17, 2025
baddcfe
Address Bill's comments; add helper function that returns a list of r…
quinntaylormitchell Nov 20, 2025
7cf597d
Rabbit.
quinntaylormitchell Nov 20, 2025
8372a9f
Refactor PackageConfig and PackageInstance classes into three separat…
quinntaylormitchell Nov 20, 2025
b92ee22
Apply suggestions from code review
Bill-hbrhbr Nov 20, 2025
f950df0
Merge branch 'main' into testing-start-stop
Bill-hbrhbr Nov 20, 2025
aac6fcb
lint fix and variable substitution
Bill-hbrhbr Nov 20, 2025
9f995b9
Update according to coderabbit AI suggestion.
Bill-hbrhbr Nov 20, 2025
03cb974
Merge branch 'main' into testing-start-stop
Bill-hbrhbr Nov 20, 2025
0e0567a
Apply Bill's comments.
quinntaylormitchell Nov 21, 2025
d44ab95
Merge branch 'main' into feature branch
quinntaylormitchell Nov 21, 2025
324ade4
Add ClpConfig data member to PackageConfig class; use 'fixt_' at begi…
quinntaylormitchell Nov 21, 2025
e7e79e1
Merge branch 'main' into feature branch
quinntaylormitchell Nov 22, 2025
7116cfc
Post-merge main.
quinntaylormitchell Nov 22, 2025
3471168
Remove return from _write_temp_config_file.
quinntaylormitchell Nov 22, 2025
a324248
Remove unecessary logging statements.
quinntaylormitchell Nov 24, 2025
6caf53a
Move content to other PRs.
quinntaylormitchell Nov 25, 2025
e967175
Add code from 1437 re. component list.
quinntaylormitchell Nov 25, 2025
c15394c
Add validate_package_running and related code.
quinntaylormitchell Nov 25, 2025
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
2 changes: 2 additions & 0 deletions integration-tests/.pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ addopts =
--capture=no
--code-highlight=yes
--color=yes
-rA
--strict-config
--strict-markers
--verbose
Expand All @@ -18,3 +19,4 @@ markers =
clp: mark tests that use the CLP storage engine
clp_s: mark tests that use the CLP-S storage engine
core: mark tests that test the CLP core binaries
package: mark tests that run when the CLP package is active
2 changes: 2 additions & 0 deletions integration-tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ dev = [
"ruff>=0.11.12",
"pytest>=8.4.1",
"pytest-env>=1.1.5",
"PyYAML>=6.0",
"types-PyYAML>=6.0.12.20240808",
]

[tool.mypy]
Expand Down
5 changes: 4 additions & 1 deletion integration-tests/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
"""Make the fixtures defined in `tests/fixtures/` globally available without imports."""
"""Global pytest setup."""

# Make the fixtures defined in `tests/fixtures/` globally available without imports.
pytest_plugins = [
"tests.fixtures.integration_test_logs",
"tests.fixtures.path_configs",
"tests.fixtures.package_instance",
"tests.fixtures.package_config",
]
46 changes: 46 additions & 0 deletions integration-tests/tests/fixtures/package_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""Fixtures that create and remove temporary config files for CLP packages."""

import contextlib
from collections.abc import Iterator

import pytest

from tests.utils.clp_mode_utils import (
get_clp_config_from_mode,
get_required_component_list,
)
from tests.utils.config import PackageConfig, PackagePathConfig


@pytest.fixture
def fixt_package_config(
fixt_package_path_config: PackagePathConfig,
request: pytest.FixtureRequest,
) -> Iterator[PackageConfig]:
"""
Creates and maintains a PackageConfig object for a specific CLP mode.

:param request:
:return: An iterator that yields the PackageConfig object for the specified mode.
"""
mode_name: str = request.param

# Get the ClpConfig for this mode.
clp_config_obj = get_clp_config_from_mode(mode_name)

# Compute the list of required components for this mode.
required_components = get_required_component_list(clp_config_obj)

# Construct PackageConfig.
package_config = PackageConfig(
path_config=fixt_package_path_config,
mode_name=mode_name,
component_list=required_components,
clp_config=clp_config_obj,
)

try:
yield package_config
finally:
with contextlib.suppress(FileNotFoundError):
package_config.temp_config_file_path.unlink()
41 changes: 41 additions & 0 deletions integration-tests/tests/fixtures/package_instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""Fixtures that start and stop CLP package instances for integration tests."""

import subprocess
from collections.abc import Iterator

import pytest

from tests.utils.config import (
PackageConfig,
PackageInstance,
)
from tests.utils.package_utils import (
start_clp_package,
stop_clp_package,
)


@pytest.fixture
def fixt_package_instance(fixt_package_config: PackageConfig) -> Iterator[PackageInstance]:
"""
Starts a CLP package instance for the given configuration and stops it during teardown.

:param fixt_package_config:
:param request:
:return: Iterator that yields the running package instance.
"""
mode_name = fixt_package_config.mode_name
instance: PackageInstance | None = None

try:
start_clp_package(fixt_package_config)
instance = PackageInstance(package_config=fixt_package_config)
yield instance
except RuntimeError:
pytest.fail(f"Failed to start the {mode_name} package.")
finally:
if instance is not None:
stop_clp_package(instance)
else:
# This means setup failed after start; fall back to calling stop script directly
subprocess.run([str(fixt_package_config.path_config.stop_script_path)], check=False)
11 changes: 8 additions & 3 deletions integration-tests/tests/fixtures/path_configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ def integration_test_path_config() -> IntegrationTestPathConfig:


@pytest.fixture(scope="session")
def package_path_config() -> PackagePathConfig:
"""Provides paths for the clp-package directory and its contents."""
return PackagePathConfig(clp_package_dir=resolve_path_env_var("CLP_PACKAGE_DIR"))
def fixt_package_path_config(
integration_test_path_config: IntegrationTestPathConfig,
) -> PackagePathConfig:
"""Fixture that provides a PackagePathConfig shared across tests."""
return PackagePathConfig(
clp_package_dir=resolve_path_env_var("CLP_PACKAGE_DIR"),
test_root_dir=integration_test_path_config.test_root_dir,
)
28 changes: 28 additions & 0 deletions integration-tests/tests/test_package_start.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Integration tests verifying that the CLP package can be started and stopped."""

import logging

import pytest

from tests.utils.asserting_utils import (
validate_package_running,
)
from tests.utils.clp_mode_utils import CLP_MODE_CONFIGS
from tests.utils.config import PackageInstance

TEST_MODES = CLP_MODE_CONFIGS.keys()

logger = logging.getLogger(__name__)


@pytest.mark.package
@pytest.mark.parametrize("fixt_package_config", TEST_MODES, indirect=True)
def test_clp_package(fixt_package_instance: PackageInstance) -> None:
"""
Validate that all of the components of the CLP package start up successfully for the selected
mode of operation.

:param fixt_package_instance:
"""
# Ensure that all package components are running.
validate_package_running(fixt_package_instance)
24 changes: 24 additions & 0 deletions integration-tests/tests/utils/asserting_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import pytest

from tests.utils.config import PackageInstance
from tests.utils.docker_utils import list_running_containers_with_prefix


def run_and_assert(cmd: list[str], **kwargs: Any) -> subprocess.CompletedProcess[Any]:
"""
Expand All @@ -20,3 +23,24 @@ def run_and_assert(cmd: list[str], **kwargs: Any) -> subprocess.CompletedProcess
except subprocess.CalledProcessError as e:
pytest.fail(f"Command failed: {' '.join(cmd)}: {e}")
return proc


def validate_package_running(package_instance: PackageInstance) -> None:
"""
Validate that the given package instance is running. Each required component must have at least
one running container whose name matches the expected prefix. Calls pytest.fail on the first
missing component.

:param package_instance:
"""
instance_id = package_instance.clp_instance_id
required_components = package_instance.package_config.component_list

for component in required_components:
prefix = f"clp-package-{instance_id}-{component}-"
running_matches = list_running_containers_with_prefix(prefix)
if len(running_matches) == 0:
pytest.fail(
f"No running container found for component '{component}' "
f"(expected name prefix '{prefix}')."
)
115 changes: 115 additions & 0 deletions integration-tests/tests/utils/clp_mode_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
"""Provides utilities related to the user-level configurations of CLP's operating modes."""

from collections.abc import Callable

from clp_py_utils.clp_config import (
API_SERVER_COMPONENT_NAME,
ClpConfig,
COMPRESSION_SCHEDULER_COMPONENT_NAME,
COMPRESSION_WORKER_COMPONENT_NAME,
DB_COMPONENT_NAME,
DeploymentType,
GARBAGE_COLLECTOR_COMPONENT_NAME,
MCP_SERVER_COMPONENT_NAME,
Package,
QUERY_SCHEDULER_COMPONENT_NAME,
QUERY_WORKER_COMPONENT_NAME,
QueryEngine,
QUEUE_COMPONENT_NAME,
REDIS_COMPONENT_NAME,
REDUCER_COMPONENT_NAME,
RESULTS_CACHE_COMPONENT_NAME,
StorageEngine,
WEBUI_COMPONENT_NAME,
)

CLP_MODE_CONFIGS: dict[str, Callable[[], ClpConfig]] = {
"clp-text": lambda: ClpConfig(
package=Package(
storage_engine=StorageEngine.CLP,
query_engine=QueryEngine.CLP,
),
),
"clp-json": lambda: ClpConfig(
package=Package(
storage_engine=StorageEngine.CLP_S,
query_engine=QueryEngine.CLP_S,
),
),
}


# TODO: This will eventually be replaced by a formalized mapping between component and service.
def _to_docker_compose_service_name(name: str) -> str:
"""
Convert a component name to a Docker Compose service name.

:param name:
:return: Service name with underscores replaced by hyphens
"""
return name.replace("_", "-")


CLP_BASE_COMPONENTS = [
_to_docker_compose_service_name(DB_COMPONENT_NAME),
_to_docker_compose_service_name(QUEUE_COMPONENT_NAME),
_to_docker_compose_service_name(REDIS_COMPONENT_NAME),
_to_docker_compose_service_name(REDUCER_COMPONENT_NAME),
_to_docker_compose_service_name(RESULTS_CACHE_COMPONENT_NAME),
_to_docker_compose_service_name(COMPRESSION_SCHEDULER_COMPONENT_NAME),
_to_docker_compose_service_name(COMPRESSION_WORKER_COMPONENT_NAME),
_to_docker_compose_service_name(API_SERVER_COMPONENT_NAME),
_to_docker_compose_service_name(WEBUI_COMPONENT_NAME),
]

CLP_QUERY_COMPONENTS = [
_to_docker_compose_service_name(QUERY_SCHEDULER_COMPONENT_NAME),
_to_docker_compose_service_name(QUERY_WORKER_COMPONENT_NAME),
]

CLP_GARBAGE_COLLECTOR_COMPONENT = _to_docker_compose_service_name(GARBAGE_COLLECTOR_COMPONENT_NAME)

CLP_MCP_SERVER_COMPONENT = _to_docker_compose_service_name(MCP_SERVER_COMPONENT_NAME)


def get_clp_config_from_mode(mode_name: str) -> ClpConfig:
"""
Return a ClpConfig object for the given mode name.

:param mode_name:
:return: ClpConfig object corresponding to the mode.
:raise ValueError: If the mode is not supported.
"""
try:
config = CLP_MODE_CONFIGS[mode_name]
except KeyError as err:
err_msg = f"Unsupported mode: {mode_name}"
raise ValueError(err_msg) from err
return config()


def get_required_component_list(config: ClpConfig) -> list[str]:
"""
Constructs a list of the components that the CLP package described in `config` needs to run
properly.

:param config:
:return: List of components required by the package.
"""
component_list: list[str] = []
component_list.extend(CLP_BASE_COMPONENTS)

deployment_type = config.get_deployment_type()
if deployment_type == DeploymentType.FULL:
component_list.extend(CLP_QUERY_COMPONENTS)

if (
config.archive_output.retention_period is not None
or config.results_cache.retention_period is not None
):
component_list.append(CLP_GARBAGE_COLLECTOR_COMPONENT)

if config.mcp_server is not None:
component_list.append(CLP_MCP_SERVER_COMPONENT)

return component_list
Loading
Loading