Skip to content

Commit d10fa1f

Browse files
authored
Merge pull request #2653 from input-output-hk/djo/2580/test-structure-adr+remove-test_tools_flag
chore: add dev adr for guidelines on writting test utilities + remove `test_tools` and `full` features from `mithril-common`
2 parents 8cb3c05 + 68a0017 commit d10fa1f

File tree

25 files changed

+86
-91
lines changed

25 files changed

+86
-91
lines changed

Cargo.lock

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

DEV-ADR.md

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,48 @@ To complete
2323
To complete
2424
-->
2525

26+
### 4. Guidelines for crate test utilities
27+
28+
**Date:** 2025-07-25
29+
**Status:** Accepted
30+
31+
### Context
32+
33+
- Testing requires reusable utilities that may need to be shared across crates
34+
- Test utilities should be isolated from production code while remaining accessible to child crates
35+
- We need to minimize feature flags to optimize Rust compiler artifact reuse and reduce build times
36+
37+
### Decision
38+
39+
Test utilities must follow this organizational structure:
40+
41+
**Core Rules:**
42+
43+
1. All test utilities belong in a dedicated `test` module within each crate
44+
2. Utilities become public only when used by child crates or integration tests
45+
3. Public test utilities must not introduce additional dependencies
46+
4. Private test utilities are gated behind `cfg(test)`
47+
5. Import paths must explicitly include `test` modules to prevent accidental production usage
48+
6. Feature flags are prohibited for test utility isolation
49+
50+
**Module Organization:**
51+
52+
- **Test doubles** (mocks, fakes, stubs): `test::double` module
53+
- **Test data builders**: `test::builder` module
54+
- **Test-only type extensions**: Extension traits in `test` module
55+
- Trait names end with `TestExtension`
56+
- Implementations follow trait definitions, except when accessing private fields
57+
58+
#### Consequences
59+
60+
- Consistent codebase organization across all crates
61+
- Clear separation between production and test code
62+
- Improved discoverability and maintainability of test utilities
63+
- Reduced build times through minimal feature flag usage
64+
- Enhanced reusability of test utilities across child crates
65+
66+
---
67+
2668
### 3. Guidelines for Dummy Test Doubles
2769

2870
**Date:** 2025-07-22
@@ -51,7 +93,7 @@ The following guidelines will be adopted for implementing the `Dummy` trait:
5193

5294
---
5395

54-
## 2. Remove Artifacts serialization support when compiling to WebAssembly
96+
## 2. Remove artifacts serialization support when compiling to WebAssembly
5597

5698
date: 2025-02-26
5799
status: Accepted
@@ -88,7 +130,7 @@ In the future, if we need to serialize and deserialize Artifacts in WebAssembly,
88130

89131
---
90132

91-
## 1. Record Architecture Decisions
133+
## 1. Record architecture decisions
92134

93135
date: 2025-02-26
94136
status: Accepted

flake.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
// args);
101101

102102
mithril-stm = buildPackage ./mithril-stm/Cargo.toml null {};
103-
mithril-common = buildPackage ./mithril-common/Cargo.toml mithril-stm.cargoArtifacts { cargoExtraArgs = "-p mithril-common --features full"; };
103+
mithril-common = buildPackage ./mithril-common/Cargo.toml mithril-stm.cargoArtifacts { cargoExtraArgs = "-p mithril-common"; };
104104
mithril = buildPackage null mithril-common.cargoArtifacts {
105105
doCheck = false;
106106
};

internal/cardano-node/mithril-cardano-node-chain/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-cardano-node-chain"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
authors.workspace = true
55
documentation.workspace = true
66
edition.workspace = true
@@ -35,7 +35,6 @@ kes-summed-ed25519 = { version = "0.2.1", features = [
3535
"serde_enabled",
3636
"sk_clone_enabled",
3737
] }
38-
mithril-common = { path = "../../../mithril-common", features = ["test_tools"] }
3938
mockall = { workspace = true }
4039
pallas-crypto = "0.33.0"
4140
slog-async = { workspace = true }

internal/cardano-node/mithril-cardano-node-internal-database/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-cardano-node-internal-database"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
description = "Mechanisms that allow Mithril nodes to read the files of a Cardano node internal database and compute digests from them"
55
authors.workspace = true
66
documentation.workspace = true
@@ -29,7 +29,6 @@ walkdir = "2.5.0"
2929

3030
[dev-dependencies]
3131
criterion = { version = "0.6.0", features = ["html_reports", "async_tokio"] }
32-
mithril-common = { path = "../../../mithril-common", version = ">=0.5", features = ["test_tools"] }
3332
mockall = { workspace = true }
3433
slog-async = { workspace = true }
3534
slog-term = { workspace = true }

internal/mithril-aggregator-client/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-aggregator-client"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "Client to request data from a Mithril Aggregator"
55
authors.workspace = true
66
documentation.workspace = true
@@ -28,7 +28,6 @@ tokio = { workspace = true }
2828
[dev-dependencies]
2929
http = "1.3.1"
3030
httpmock = "0.7.0"
31-
mithril-common = { path = "../../mithril-common", version = ">=0.5", features = ["test_tools"] }
3231
mockall = { workspace = true }
3332
slog-async = { workspace = true }
3433
slog-term = { workspace = true }

internal/mithril-dmq/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "mithril-dmq"
33
description = "Mechanisms to publish and consume messages of a 'Decentralized Message Queue network' through a DMQ node"
4-
version = "0.1.7"
4+
version = "0.1.8"
55
authors.workspace = true
66
documentation.workspace = true
77
edition.workspace = true
@@ -24,7 +24,6 @@ slog = { workspace = true }
2424
tokio = { workspace = true, features = ["sync"] }
2525

2626
[dev-dependencies]
27-
mithril-common = { path = "../../mithril-common", features = ["test_tools"] }
2827
mockall = { workspace = true }
2928
slog-async = { workspace = true }
3029
slog-term = { workspace = true }

internal/mithril-era/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-era"
3-
version = "0.1.4"
3+
version = "0.1.5"
44
authors.workspace = true
55
documentation.workspace = true
66
edition.workspace = true
@@ -21,5 +21,4 @@ serde_json = { workspace = true }
2121
thiserror = { workspace = true }
2222

2323
[dev-dependencies]
24-
mithril-common = { path = "../../mithril-common", features = ["test_tools"] }
2524
tokio = { workspace = true, features = ["macros"] }

internal/mithril-metric/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-metric"
3-
version = "0.1.18"
3+
version = "0.1.19"
44
description = "Common tools to expose metrics."
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -22,7 +22,6 @@ slog = { workspace = true }
2222
tokio = { workspace = true }
2323

2424
[dev-dependencies]
25-
mithril-common = { path = "../../mithril-common", features = ["test_tools"] }
2625
prometheus-parse = "0.2.5"
2726
slog-async = { workspace = true }
2827
slog-term = { workspace = true }

internal/mithril-persistence/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mithril-persistence"
3-
version = "0.2.58"
3+
version = "0.2.59"
44
description = "Common types, interfaces, and utilities to persist data for Mithril nodes."
55
authors = { workspace = true }
66
edition = { workspace = true }
@@ -26,5 +26,4 @@ thiserror = { workspace = true }
2626
tokio = { workspace = true }
2727

2828
[dev-dependencies]
29-
mithril-common = { path = "../../mithril-common", features = ["test_tools"] }
3029
tokio = { workspace = true, features = ["macros", "time"] }

0 commit comments

Comments
 (0)