Skip to content
This repository was archived by the owner on Dec 5, 2025. It is now read-only.

Conversation

@jinglemansweep
Copy link
Contributor

This pull request introduces new unit tests for configuration, constants, and database cleanup functionality, while also updating test fixtures to better reflect the current implementation and dependencies. The most significant changes are the addition of comprehensive tests for core modules and improvements to how test dependencies are managed in tests/conftest.py.

New unit tests:

  • Added tests/unit/test_config.py with extensive tests for the Config class, covering default values, custom settings, webhook configuration, mock settings, database and API settings, type hints, dataclass behavior, and immutability of defaults.
  • Added tests/unit/test_constants.py with thorough tests for the constants module, including validation of NODE_TYPE_MAP, the node_type_name function, input edge cases, and immutability checks.
  • Added tests/unit/test_database_cleanup.py to test the DataCleanup class, verifying initialization, cleanup operations, logging, retention validation, and result accuracy using mocks and patches.

Test fixture improvements in tests/conftest.py:

  • Updated imports and usage to reference QueueFullBehavior directly, ensuring enum values are used instead of raw strings. [1] [2]
  • Changed database engine initialization to use the new initialize() method rather than init_db(), reflecting updates in the database API.
  • Refactored CommandQueueManager fixture to pass individual config values as arguments, improving clarity and reducing reliance on the full config object.
  • Simplified test_app and test_app_with_auth fixtures to create FastAPI test clients without requiring explicit dependency injection, making the tests easier to maintain and extend.

Copilot AI review requested due to automatic review settings November 29, 2025 15:44
@jinglemansweep jinglemansweep merged commit bd8c90b into main Nov 29, 2025
3 checks passed
@jinglemansweep jinglemansweep deleted the coverage-analysis branch November 29, 2025 15:44
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces comprehensive unit tests for core modules (configuration, constants, and database cleanup) while updating test fixtures in conftest.py to use explicit enum types instead of raw strings and modernizing the database and API initialization patterns.

Key Changes:

  • Added 3 new unit test files with thorough coverage of Config, constants, and DataCleanup classes
  • Updated test fixtures to use QueueFullBehavior enum values for type safety
  • Modernized database engine initialization from init_db() to initialize()

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.

File Description
tests/unit/test_database_cleanup.py New comprehensive tests for DataCleanup class covering initialization, cleanup operations, logging, and result validation using mocks
tests/unit/test_constants.py New comprehensive tests for constants module including NODE_TYPE_MAP validation, node_type_name function with edge cases, and immutability checks
tests/unit/test_config.py New comprehensive tests for Config dataclass covering all configuration sections (connection, database, API, webhooks, etc.) with type validation
tests/conftest.py Updated fixtures to use QueueFullBehavior enum, refactored CommandQueueManager initialization with explicit parameters, changed database initialization to use new initialize() method, and simplified test_app fixtures
Comments suppressed due to low confidence (4)

tests/conftest.py:4

  • Import of 'json' is not used.
import json

tests/conftest.py:14

  • Import of 'create_engine' is not used.
from sqlalchemy import create_engine

tests/conftest.py:15

  • Import of 'sessionmaker' is not used.
from sqlalchemy.orm import Session, sessionmaker

tests/conftest.py:176

  • Keyword argument 'db_engine' is not a supported parameter name of EventHandler.init.
    handler = EventHandler(
        db_engine=db_engine,
        webhook_handler=mock_webhook_handler,
    )

meshcore=mock_meshcore,
config=test_config,
max_queue_size=test_config.queue_max_size,
queue_full_behavior=test_config.queue_full_behavior,
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type mismatch: test_config.queue_full_behavior is a string (from Config dataclass line 59), but CommandQueueManager.__init__ expects a QueueFullBehavior enum. This will cause a type error at runtime.

The config value should be converted to the enum, e.g.:

queue_full_behavior=QueueFullBehavior(test_config.queue_full_behavior),

This assumes the string values in Config match the enum values ("reject" or "drop_oldest").

Suggested change
queue_full_behavior=test_config.queue_full_behavior,
queue_full_behavior=QueueFullBehavior(test_config.queue_full_behavior),

Copilot uses AI. Check for mistakes.
debounce_window_seconds=test_config.debounce_window_seconds,
debounce_cache_max_size=test_config.debounce_cache_max_size,
debounce_enabled=test_config.debounce_enabled,
debounce_commands=set(test_config.debounce_commands.split(",")),
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type mismatch: CommandQueueManager.__init__ expects debounce_commands to be Optional[set[CommandType]], but this code passes a set of strings. The string values need to be converted to CommandType enum values.

Example fix:

debounce_commands={CommandType(cmd.strip()) for cmd in test_config.debounce_commands.split(",")},

This assumes the string values in Config match CommandType enum values ("send_message", "send_channel_message", etc.).

Copilot uses AI. Check for mistakes.
from meshcore_api.api.app import create_app
from meshcore_api.config import Config
from meshcore_api.database.engine import DatabaseEngine
from meshcore_api.database.models import Base
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'Base' is not used.

Suggested change
from meshcore_api.database.models import Base

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,195 @@
"""Unit tests for configuration module - fixed to match actual implementation."""

import pytest
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'pytest' is not used.

Suggested change
import pytest

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,132 @@
"""Unit tests for constants module - fixed to match actual implementation."""

import pytest
Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'pytest' is not used.

Suggested change
import pytest

Copilot uses AI. Check for mistakes.
Comment on lines +5 to +6
import pytest

Copy link

Copilot AI Nov 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import of 'pytest' is not used.

Suggested change
import pytest

Copilot uses AI. Check for mistakes.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants