Add shared rstest detection module and public APIs (8.1.1)#171
Conversation
WalkthroughAdd a new Changes
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 6 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Reviewer's GuideIntroduces a new shared Class diagram for the new common::rstest detection and parameter APIclassDiagram
class AttributePath
class Attribute
class ExpansionTrace {
+frames: Vec~AttributePath~
+new(frames: IntoIterator~AttributePath~) ExpansionTrace
+frames() [AttributePath]
}
class RstestDetectionOptions {
-provider_param_attributes: Vec~AttributePath~
-use_expansion_trace_fallback: bool
+new(provider_param_attributes: Vec~AttributePath~, use_expansion_trace_fallback: bool) RstestDetectionOptions
+provider_param_attributes() [AttributePath]
+use_expansion_trace_fallback() bool
}
class ParameterBinding {
<<enumeration>>
Ident(name: String)
Unsupported
}
class RstestParameter {
-binding: ParameterBinding
-attributes: Vec~Attribute~
+new(binding: ParameterBinding, attributes: Vec~Attribute~) RstestParameter
+ident(name: String) RstestParameter
+unsupported() RstestParameter
+binding() ParameterBinding
+attributes() [Attribute]
+binding_name() Option~str~
}
class RstestParameterKind {
<<enumeration>>
FixtureLocal(name: String)
Provider
UnsupportedPattern
}
class RstestModuleApi {
<<module>>
+is_rstest_test(attrs: [Attribute]) bool
+is_rstest_test_with(attrs: [Attribute], trace: Option~ExpansionTrace~, options: RstestDetectionOptions) bool
+is_rstest_fixture(attrs: [Attribute]) bool
+is_rstest_fixture_with(attrs: [Attribute], trace: Option~ExpansionTrace~, options: RstestDetectionOptions) bool
+classify_rstest_parameter(parameter: RstestParameter, options: RstestDetectionOptions) RstestParameterKind
+fixture_local_names(parameters: [RstestParameter], options: RstestDetectionOptions) BTreeSet~String~
}
ExpansionTrace --> AttributePath : uses
RstestDetectionOptions --> AttributePath : uses
RstestParameter --> ParameterBinding : has
RstestParameter --> Attribute : has
RstestParameterKind <.. RstestParameter : classification
RstestModuleApi --> ExpansionTrace : uses
RstestModuleApi --> RstestDetectionOptions : uses
RstestModuleApi --> Attribute : uses
RstestModuleApi --> RstestParameter : uses
RstestModuleApi --> RstestParameterKind : returns
Flow diagram for rstest test and fixture detection with expansion trace fallbackflowchart LR
A[Start detection
is_rstest_test_with / is_rstest_fixture_with] --> B[Check direct attributes
has_matching_attribute]
B -->|Match found| C[Return true]
B -->|No match| D{use_expansion_trace_fallback?}
D -->|No| E[Return false]
D -->|Yes and trace present| F[Check expansion frames
has_matching_trace]
D -->|Yes but no trace| E
F -->|Frame matches rstest candidate| C
F -->|No matching frame| E
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
@coderabbitai Please suggest a fix for this issue and supply a prompt for an AI coding agent to enable it to apply the fix. Include the file and symbol names indicated in the issue at the head of your response. Ensure that this is validated against the current version of the codegraph. If further refinement to address this finding would be deleterious, please supply a clear explanatory one to two paragraph markdown message I can paste into the CodeScene web ui's diagnostic suppression function so this diagnostic can be silenced. Comment on file fn honours_test_trace_when_fallback_is_enabled() {
let trace = ExpansionTrace::new([AttributePath::from("rstest")]);
let options = RstestDetectionOptions::new(Vec::new(), true);
assert!(is_rstest_test_with(
&[outer("allow")],
Some(&trace),
&options
));
}❌ New issue: Code Duplication |
This comment was marked as resolved.
This comment was marked as resolved.
|
@coderabbitai Have the following now been resolved? Annul any requirements that violate the en-GB-oxendict spelling (-ize / -yse / -our) conventions (for example a request to replace "normalize" with "normalise" or "artefact" with "artifact"), or where the requirement unnecessarily increases cyclomatic complexity. |
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chainLet me read the current state of the files on the PR branch. 🏁 Script executed: Length of output: 15774
Annulment scan: None of the four comments contains en-GB-oxendict spelling violations (no The only open item from this thread is the CodeScene duplication finding (five separate trace-fallback functions vs. the merged parameterised form the previous reply proposed). That was raised as a separate concern; if you wish to address it, the AI coding agent prompt from the earlier reply still applies. |
Add a new shared pure-library detection module to the `common` crate that provides strict detection of `#[rstest]` tests, `#[fixture]` functions, classification of parameters as fixture locals or provider-driven inputs, and optional fallback detection through expansion-trace metadata. This module is foundational for downstream hygiene lints and maintains a clear boundary by avoiding `rustc_private` dependencies. Includes comprehensive unit and behavioural tests, documentation updates, and design decision records to ensure correctness and maintainability. See docs/execplans/8-1-1-shared-rstest-test-and-fixture-detection-helpers.md for detailed design and roadmap 8.1.1 implementation plan. Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
…cation - Introduce pure detection helpers for strict `rstest` tests and fixtures. - Add classification for `rstest` parameters into fixture-local, provider-driven, or unsupported. - Support optional expansion-trace fallback for detection. - Add comprehensive unit and behaviour-driven tests covering detection and classification. - Update `common` crate to re-export new API and document usage. - Update documentation and roadmap to reflect 8.1.1 completion. - Upgrade `rstest-bdd` workspace pin to version 0.5.x in `Cargo.toml` (documentation only). Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
…ustom providers - Added tests for detecting rstest tests with multiple attributes surrounding the rstest attribute. - Added tests for classifying custom provider parameters and rejecting unknown custom providers. - Added scenarios and support for multi-frame expansion trace handling in test detection. - Updated feature file with scenarios covering these cases. - Extended detection behaviour with helpers for multi-frame traces and custom providers. Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
Refactored multiple specific fallback trace detection tests into a single parameterized test using rstest cases. This reduces duplication and covers various trace scenarios (single frame, multi frame, deeply nested) for both test and fixture detection paths with fallback enabled. Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
Update doc comment examples and integration test imports from `common::` to `whitaker_common::` to match the crate rename that landed on main in v0.2.2. The rebase dropped the now-redundant bulk-rename commit since main already carries the rename, but these branch-specific files still referenced the old crate name. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1f6d192 to
397f30f
Compare
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@common/src/rstest/mod.rs`:
- Around line 15-16: The test module wiring (mod tests) is fine but you must
consolidate duplicate fallback-trace unit tests in common/src/rstest/tests.rs by
removing the legacy functions honours_test_trace_when_fallback_is_enabled,
honours_fixture_trace_when_fallback_is_enabled, honours_multi_frame_test_trace,
honours_multi_frame_fixture_trace, and honours_deeply_nested_test_trace and
replace them with a single parameterised #[rstest] test that accepts a case
matrix (use multiple #[case(...)] attributes) covering each scenario; implement
the test function to take the case parameter and assert behavior accordingly so
only one #[rstest] function remains and the old duplicated fn symbols are gone.
In `@common/tests/rstest_detection_behaviour.rs`:
- Around line 51-54: In add_custom_provider_attributes, avoid resetting the
fallback flag by reading the current use_expansion_trace_fallback() from
self.options.borrow() and pass that boolean into RstestDetectionOptions::new
instead of false; update the replace call to use that captured
use_trace_fallback so the existing fallback behavior is preserved when
overriding provider attributes.
In `@docs/execplans/8-1-1-shared-rstest-test-and-fixture-detection-helpers.md`:
- Around line 36-37: Update the US spelling "Behavioral" to en-GB-oxendict
"Behavioural" in the success criteria sentence that begins "3. Behavioural tests
using `rstest-bdd` v0.5.0 exercise the same contract via `common/tests/`";
locate the exact token "Behavioral" and replace it with "Behavioural" so the
document uses en-GB-oxendict spelling throughout.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 61589f7a-7c76-4a17-af89-ab1b1328fe6a
📒 Files selected for processing (11)
common/Cargo.tomlcommon/src/lib.rscommon/src/rstest/detection.rscommon/src/rstest/mod.rscommon/src/rstest/parameter.rscommon/src/rstest/tests.rscommon/tests/features/rstest_detection.featurecommon/tests/rstest_detection_behaviour.rsdocs/execplans/8-1-1-shared-rstest-test-and-fixture-detection-helpers.mddocs/lints-for-rstest-fixtures-and-test-hygiene.mddocs/roadmap.md
docs/execplans/8-1-1-shared-rstest-test-and-fixture-detection-helpers.md
Show resolved
Hide resolved
The add_custom_provider_attributes method was incorrectly resetting the use_expansion_trace_fallback flag to false when setting custom provider attributes. This meant that if trace fallback was enabled before adding custom providers, it would be silently disabled. Now the method reads the current fallback setting from the options and preserves it when creating the new RstestDetectionOptions instance. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@common/tests/rstest_detection_behaviour.rs`:
- Around line 244-292: Replace the repeated #[scenario] stubs by generating them
from a local macro or by using a parameterized rstest: create a macro (e.g.,
declare_scenarios!) that takes a list of (index, fn_name) tuples and expands to
multiple #[scenario(path = "tests/features/rstest_detection.feature", index =
N)] fn fn_name(world: DetectionWorld) { let _ = world; }, or alternatively use
#[rstest] to parameterize a single test over the indices and expected case
names; update the current functions (scenario_detects_rstest_test,
scenario_detects_rstest_fixture, scenario_classifies_fixture_local_parameter,
etc.) to be produced by that macro or by one parameterized test so the identical
bodies are removed and maintenance is centralized.
- Around line 232-236: The then_fixture_names assertion mutates DetectionWorld
by calling world.evaluate_fixture_names(); move that evaluation into a new when
step so the then step is pure. Create a new #[when(...)] function (e.g.,
when_fixture_names_evaluated) that calls world.evaluate_fixture_names(), keep
then_fixture_names only reading world.fixture_names (no borrow mutating calls),
and update any scenarios to call the new when step before the then assertion.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: cedc9ce8-f0a6-4998-b3fb-afc6bb5fbb84
📒 Files selected for processing (1)
common/tests/rstest_detection_behaviour.rs
Replaced multiple individual scenario functions with a macro to automatically declare test scenarios in rstest_detection_behaviour.rs. This reduces boilerplate and improves maintainability without changing functionality. Also added a missing step to fixture local parameter classification scenario. Co-authored-by: devboxerhub[bot] <devboxerhub[bot]@users.noreply.github.com>
|
@coderabbitai Have the following now been resolved? ❌ Failed checks (2 warnings)
|
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain🏁 Script executed: Length of output: 12658
Update the PR title to something like |
Summary
Changes
Rationale
Plan / Work plan (high level)
Acceptance criteria
Context and references
Notes
ℹ️ Tag @devboxerhub to ask questions and address PR feedback
📎 Task: https://www.devboxer.com/task/b1c351db-cf54-4486-b6dd-2b78d41d156a
Summary by Sourcery
Add a shared_rstest detection module to the Whitaker-common crate, exposing a stable API for identifying rstest tests, fixtures, and provider parameters, with accompanying tests and documentation updates.
New Features:
Enhancements:
Tests:
Task: https://www.devboxer.com/task/61bd4c9f-6b1a-4ce3-92e4-d43cf53a6dea
📎 Task: https://www.devboxer.com/task/db1a1f79-c621-468a-905b-148a563af2f7