Coverage for src/prosemark/ports/id_generator.py: 100%
5 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-09-24 18:08 +0000
« prev ^ index » next coverage.py v7.8.0, created at 2025-09-24 18:08 +0000
1"""Abstract base class for ID generators."""
3from abc import ABC, abstractmethod
4from typing import TYPE_CHECKING
6if TYPE_CHECKING: # pragma: no cover
7 from prosemark.domain.models import NodeId
10class IdGenerator(ABC):
11 """Abstract base class for ID generators.
13 Defines the minimal interface for generating unique identifiers
14 for nodes in the system. All implementations must generate stable,
15 unique NodeId values.
17 The IdGenerator enables:
18 * Stable, unique identifiers for nodes
19 * Testable ID generation through dependency injection
20 * Support for different ID strategies (UUIDv7 for production, sequential for tests)
21 * Hexagonal architecture compliance by isolating system concerns
23 Examples:
24 >>> class TestIdGenerator(IdGenerator):
25 ... def new(self) -> NodeId:
26 ... return NodeId('0192f0c1-2345-7123-8abc-def012345678')
27 >>> generator = TestIdGenerator()
28 >>> node_id = generator.new()
29 >>> isinstance(node_id, NodeId)
30 True
32 """
34 @abstractmethod
35 def new(self) -> 'NodeId':
36 """Generate a new unique NodeId.
38 This method must be implemented by concrete subclasses to provide
39 specific ID generation strategies (UUIDv7, sequential, etc.).
41 Returns:
42 A new unique NodeId instance
44 Raises:
45 NotImplementedError: If not implemented by a concrete subclass
47 """
48 msg = 'Subclasses must implement the new() method' # pragma: no cover
49 raise NotImplementedError(msg) # pragma: no cover