Skip to content

Conversation

@grindsa
Copy link
Owner

@grindsa grindsa commented Dec 23, 2025

This PR introduces a major refactor of the Message class and its related test suite. The changes focus on improving maintainability, testability, and clarity, while preserving all public interfaces and backward compatibility.

  • Introduced a configuration dataclass (MessageConfiguration) to encapsulate all configuration options for the Message class.
  • Extracted all database access into an AccountRepository abstraction, decoupling business logic from data access.
    The Message class now delegates all account and permission lookups/updates to this repository.
  • All database and external handler calls are now wrapped in try/except blocks with clear, consistent error logging.
    Error messages and log statements have been standardized for easier debugging and monitoring.
  • All private methods have been renamed to use clear, descriptive names

@grindsa grindsa requested review from Copilot and skcert and removed request for Copilot December 23, 2025 07:00
Copy link
Contributor

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 refactors the Message class to improve maintainability and testability by introducing a configuration dataclass, extracting database operations into a repository pattern, enhancing error handling, and renaming methods for clarity.

  • Introduced MessageConfiguration dataclass to encapsulate configuration options
  • Extracted database operations into AccountRepository abstraction
  • Renamed private methods to use descriptive names and added comprehensive try/except error handling

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 15 comments.

File Description
acme_srv/message.py Implements the main refactoring with new MessageConfiguration dataclass, AccountRepository class, method renaming, and enhanced error handling with try/except blocks
test/test_message.py Updates test suite to use new configuration object structure (config.property_name), new method names, and repository pattern (repo instead of dbstore)
Comments suppressed due to low confidence (1)

acme_srv/message.py:287

  • The debug log statement is incorrectly placed inside the if block at line 285, which only executes when code is 200 and signature check is not skipped. This should be outside all conditional blocks to log the function exit in all cases, ensuring consistent debugging output regardless of the code path taken.
                account_name, content, use_emb_key, protected
            )
            if sig_check:

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 748 to 749
self.message.eab_handler = eab_handler_module.EABhandler
self.message.eab_handler.mac_key_get = MagicMock(return_value="mac_key")
Copy link

Copilot AI Dec 23, 2025

Choose a reason for hiding this comment

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

The test is setting self.message.eab_handler (line 748) but the refactored code expects the eab_handler to be in self.message.config.eab_handler. This test will not work correctly and needs to be updated to use self.message.config.eab_handler instead.

Suggested change
self.message.eab_handler = eab_handler_module.EABhandler
self.message.eab_handler.mac_key_get = MagicMock(return_value="mac_key")
self.message.config.eab_handler = eab_handler_module.EABhandler
self.message.config.eab_handler.mac_key_get = MagicMock(return_value="mac_key")

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants