refactor: make ClusterType a Protocol - #3612
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors cluster-type handling by replacing the previous stub-only ClusterType base class with a structural Protocol, introducing a ClusterKind StrEnum, and updating consumers to use protocol-provided is_local/is_testnet checks. This better aligns runtime behavior with typing expectations and removes the prior “unknown” placeholder state.
Changes:
- Introduce
ClusterKindand convertClusterTypeto aProtocolwith default helpers (is_local,is_testnet) and abstract members. - Convert shared cluster node lists to immutable
frozensetand move address-record data to a module constant (TEST_ADDR_RECORDS). - Update call sites across utils/tests to use
is_local/is_testnetinstead of.type == ...comparisons.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| cardano_node_tests/utils/logfiles.py | Switch testnet detection to is_testnet. |
| cardano_node_tests/utils/governance_setup.py | Switch testnet detection to is_testnet for default-governance guard. |
| cardano_node_tests/utils/cluster_nodes.py | Introduce ClusterKind, ClusterType protocol, immutable NODES, and TEST_ADDR_RECORDS; update implementations. |
| cardano_node_tests/tests/tests_conway/test_guardrails.py | Use is_local for local-only skip logic. |
| cardano_node_tests/tests/tests_conway/test_drep.py | Use is_local for local-only skips and conditional behavior. |
| cardano_node_tests/tests/test_mir_certs.py | Update shortcut skip condition to use is_local. |
| cardano_node_tests/tests/test_cli.py | Use is_local for local-only error dumping. |
| cardano_node_tests/tests/plutus_common.py | Use is_testnet for testnet early-return. |
| cardano_node_tests/tests/delegation.py | Use is_testnet to select testnet behavior path. |
| cardano_node_tests/tests/conftest.py | Use is_testnet / is_local for cleanup and respin gating. |
| cardano_node_tests/tests/common.py | Update skip markers and local/testnet branching; adjust set type after NODES becomes frozenset. |
| cardano_node_tests/cluster_management/cluster_getter.py | Use is_local for timeout selection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
mkoura
force-pushed
the
cluster_type_protocol
branch
from
August 13, 2026 10:18
783477e to
0a349af
Compare
The base class carried no shared behavior, only stubs raising NotImplementedError. As a structural Protocol: - The `LOCAL`/`TESTNET` constants move to a new `ClusterKind` StrEnum and the `type` attribute is typed by it, eliminating the "unknown" placeholder state. - Consumers use new `is_local`/`is_testnet` properties (concrete protocol defaults) instead of comparing `.type` to constants. - `NODES` becomes a `frozenset`, as it is shared class state exposed on a process-wide cached singleton. - `test_addr_records` moves to a module-level `TEST_ADDR_RECORDS` constant, as it was never used outside the implementations. - `LocalCluster` implements `testnet_type` explicitly instead of inheriting the base default. - Type checkers now treat all protocol members as abstract for the implementations, so a cluster type that forgets to define a method or the `cluster_scripts` attribute is a type error instead of a runtime surprise.
mkoura
force-pushed
the
cluster_type_protocol
branch
from
August 13, 2026 10:21
0a349af to
88e647f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The base class carried no shared behavior, only stubs raising NotImplementedError. As a structural Protocol:
LOCAL/TESTNETconstants move to a newClusterKindStrEnum and thetypeattribute is typed by it, eliminating the "unknown" placeholder state.is_local/is_testnetproperties (concrete protocol defaults) instead of comparing.typeto constants.NODESbecomes afrozenset, as it is shared class state exposed on a process-wide cached singleton.test_addr_recordsmoves to a module-levelTEST_ADDR_RECORDSconstant, as it was never used outside the implementations.LocalClusterimplementstestnet_typeexplicitly instead of inheriting the base default.cluster_scriptsattribute is a type error instead of a runtime surprise.