Skip to content

Commit 245f6d3

Browse files
committed
docs: update dev ADR for crate utilies guidelines
1 parent 6e8db4a commit 245f6d3

File tree

1 file changed

+27
-30
lines changed

1 file changed

+27
-30
lines changed

DEV-ADR.md

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,43 @@ To complete
2525

2626
### 4. Guidelines for crate test utilities
2727

28-
date: 2025-07-25
29-
status: Accepted
28+
**Date:** 2025-07-25
29+
**Status:** Accepted
3030

3131
### Context
3232

33-
- For testing, crates may need to define reusable test utilities
34-
- Some of those utilities may need to be exposed to child crates to enable or facilitate writing tests
35-
- We want to isolate test utilities from production code as much as possible
36-
- We want to limit the number of feature flags so the Rust compiler may reuse built artifacts effectively, reducing build time
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
3736

3837
### Decision
3938

40-
Test utilities should be organized following these rules:
39+
Test utilities must follow this organizational structure:
40+
41+
**Core Rules:**
4142

42-
1. Each crate must define its private and public test utilities in a `test` module
43-
2. A test utility should be made public if it is reused in a child crate or in the crate's integration tests
44-
3. Making a test utility public should not add any dependency to the crate
45-
4. Private test utilities should be behind `cfg(test)`
46-
5. Importing a public test utility should always require an import path that contains a `test` module, so their misuse
47-
in production code can be easily identified
48-
6. No feature flag should be added to isolate test utilities from production code
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
4949

50-
Specific cases:
50+
**Module Organization:**
5151

52-
- Test doubles (fakes, dummies, mocks, stubs, etc.): should be located in a `test::double` module
53-
- Builders of test data should be located in a `test::builder` module
54-
- Extending a type with a test-only method should be done using extension traits located in the `test` module, which
55-
forces the import of a `test`-scoped symbol
56-
- Their name should be suffixed with `TestExtension`
57-
- Implementation of those traits should preferably be below the trait definition, but if some methods need to access
58-
private properties, then the implementation may be located below their extended type
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
5957

6058
#### Consequences
6159

62-
- Enhanced consistency in code organization
63-
- Improved discoverability of test utilities
64-
- Clearer distinction between production and test code
65-
- Simplified maintenance of test utilities
66-
- Child crates can reuse common test utilities when needed
67-
- Feature flag usage is minimized, avoiding unnecessary recompilation
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
6865

6966
---
7067

@@ -96,7 +93,7 @@ The following guidelines will be adopted for implementing the `Dummy` trait:
9693

9794
---
9895

99-
## 2. Remove Artifacts serialization support when compiling to WebAssembly
96+
## 2. Remove artifacts serialization support when compiling to WebAssembly
10097

10198
date: 2025-02-26
10299
status: Accepted
@@ -133,7 +130,7 @@ In the future, if we need to serialize and deserialize Artifacts in WebAssembly,
133130

134131
---
135132

136-
## 1. Record Architecture Decisions
133+
## 1. Record architecture decisions
137134

138135
date: 2025-02-26
139136
status: Accepted

0 commit comments

Comments
 (0)