Repository navigation
docs: require unit tests in *_tests.rs files #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,7 +11,7 @@ Do not log provider queries, credentials, or result content. Provider credential | |||||||||
| arrive through sensitive module initialization and reinitialization config. | ||||||||||
|
|
||||||||||
| Every public item needs rustdoc. Keep types and behavior in focused modules, | ||||||||||
| with tests in neighboring `test.rs` files. Cover wire representations and real | ||||||||||
| with tests in neighboring `*_tests.rs` files. Cover wire representations and real | ||||||||||
| in-memory TinyBus calls. No placeholders, ignored tests, or lint exemptions. | ||||||||||
|
|
||||||||||
| Run from repository root: | ||||||||||
|
|
@@ -24,3 +24,28 @@ cargo test --all-features | |||||||||
| ``` | ||||||||||
|
|
||||||||||
| PRs go to the canonical upstream repository and should be ready for review. | ||||||||||
|
|
||||||||||
| ## Tests live in `*_tests.rs` files | ||||||||||
|
|
||||||||||
| - Unit tests are never inline. Do not write a `#[cfg(test)] mod tests { ... }` | ||||||||||
| block in a source file. Put the tests in a sibling `<module>_tests.rs` | ||||||||||
| (`mod_tests.rs` beside a `mod.rs`, `lib_tests.rs` beside `lib.rs`) and declare | ||||||||||
| it at the bottom of the module: | ||||||||||
|
|
||||||||||
| ```rust | ||||||||||
| #[cfg(test)] | ||||||||||
| #[path = "foo_tests.rs"] | ||||||||||
| mod tests; | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| - The test file starts with `use super::*;` and carries no `#[cfg(test)]` of its | ||||||||||
| own. It is still a child module, so it reaches private items exactly as an | ||||||||||
| inline module did. | ||||||||||
| - Name test files `<module>_tests.rs`; a second group for the same module is | ||||||||||
| `<module>_<topic>_tests.rs`. Never `test.rs`, `tests.rs` or `<module>_test.rs`. | ||||||||||
| - Integration tests stay in the crate's `tests/` directory. | ||||||||||
| - OpenHuman's `scripts/externalize-inline-tests.mjs <repo-root> --write` moves | ||||||||||
| inline test modules out mechanically; without `--write` it only reports. | ||||||||||
|
Comment on lines
+47
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Replace the unavailable externalizer instruction with manual migration steps.
Suggested fix- OpenHuman's `scripts/externalize-inline-tests.mjs <repo-root> --write` moves
- inline test modules out mechanically; without `--write` it only reports.
+ Move inline test modules manually according to the rules above. The layout
+ checker reports violations but does not perform the migration.📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| - Existing `test.rs` and `<module>_test.rs` files predate this rule. Rename each | ||||||||||
| to `<module>_tests.rs` (keep its `mod` name, add the `#[path]` attribute) the | ||||||||||
| next time you touch it. | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -139,7 +139,7 @@ fn provider_roles_and_defaults_match_the_contract() { | |
| role_provider_tool(Role::Contents, "parallel"), | ||
| Some("parallel_extract") | ||
| ); | ||
| assert!(provider_roles("unknown").is_empty()); | ||
| assert_eq!(provider_roles("unknown").len(), 0); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This commit edits seven legacy AGENTS.md reference: AGENTS.md:L49-L51 Useful? React with 👍 / 👎. |
||
| assert_eq!(provider_roles("gemini"), [Role::Answer]); | ||
| assert_eq!(provider_roles("gemini_deep_research"), [Role::Answer]); | ||
| assert_eq!(provider_roles("tinyfish"), [Role::Search, Role::Contents]); | ||
|
|
@@ -307,10 +307,11 @@ fn roles_mode_without_backend_credential_drops_backend_providers() { | |
| listed.tools[1].parameters["properties"]["provider"]["enum"], | ||
| json!(["tinyfish"]) | ||
| ); | ||
| assert!( | ||
| assert_eq!( | ||
| select_tools(&BTreeMap::new(), &config.presentation) | ||
| .tools | ||
| .is_empty() | ||
| .len(), | ||
| 0 | ||
| ); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_tests.rsWhen human contributors follow
CONTRIBUTING.md:38-40, they are still explicitly told to createtest.rs, while the example plan likewise namessrc/retry/test.rsandsrc/error/test.rs. Those instructions now directly conflict with this repository-wide naming rule, so the same change should update those references to prevent new work from being noncompliant by construction.AGENTS.md reference: AGENTS.md:L44-L45
Useful? React with 👍 / 👎.