Skip to content

refactor: make ClusterType a Protocol - #3612

Merged
mkoura merged 1 commit into
masterfrom
cluster_type_protocol
Aug 13, 2026
Merged

refactor: make ClusterType a Protocol#3612
mkoura merged 1 commit into
masterfrom
cluster_type_protocol

Conversation

@mkoura

@mkoura mkoura commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

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
mkoura requested a review from saratomaz as a code owner August 13, 2026 10:04
@mkoura
mkoura requested a lite review from Copilot and removed request for saratomaz August 13, 2026 10:04

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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 ClusterKind and convert ClusterType to a Protocol with default helpers (is_local, is_testnet) and abstract members.
  • Convert shared cluster node lists to immutable frozenset and move address-record data to a module constant (TEST_ADDR_RECORDS).
  • Update call sites across utils/tests to use is_local/is_testnet instead 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.

Comment thread cardano_node_tests/tests/test_mir_certs.py Outdated
@mkoura
mkoura force-pushed the cluster_type_protocol branch from 783477e to 0a349af Compare August 13, 2026 10:18
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
mkoura force-pushed the cluster_type_protocol branch from 0a349af to 88e647f Compare August 13, 2026 10:21
@mkoura
mkoura merged commit 0a6b9bc into master Aug 13, 2026
3 checks passed
@mkoura
mkoura deleted the cluster_type_protocol branch August 13, 2026 12:00
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