Conversation
Support manifest serialisation by implementing Serialize for Recipe and covering all variants with tests.
Reviewer's GuideThis PR extends the Recipe enum with a custom Serialize implementation that flattens each variant into a single-key map for correct manifest output and adds unit tests to verify serialization of command, script, and rule variants. Class diagram for Serialize implementation on RecipeclassDiagram
class Recipe {
+serialize<S>(serializer: S)
}
Recipe ..> Serializer : uses
Recipe ..> SerializeMap : uses
Serializer <|.. SerializeMap
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Summary by CodeRabbit
WalkthroughAdd Changes
Sequence Diagram(s)sequenceDiagram
participant Test as Test Function
participant Recipe as Recipe Enum
participant Serde as Serde Serializer
participant Yaml as YAML Value
Test->>Recipe: Create variant (Command/Script/Rule)
Test->>Serde: Serialize Recipe variant
Serde->>Recipe: Call derived serialize()
Recipe->>Serde: Return single-key map representation
Serde->>Yaml: Convert to YAML Value
Test->>Yaml: Compare with expected YAML
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Hey @leynos - I've reviewed your changes and found some issues that need to be addressed.
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/ast.rs:167` </location>
<code_context>
}
+// Serialise into a single-key map so `#[serde(flatten)]` on parent
+// structs inserts the appropriate recipe field directly.
+impl Serialize for Recipe {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
+ where
</code_context>
<issue_to_address>
Consider removing the manual Serialize implementation and using Serde's #[serde(untagged)] derive instead.
```rust
// Remove the manual Serialize impl and imports:
-use serde::{Deserialize, Serialize, de::Deserializer, ser::{SerializeMap, Serializer}};
+use serde::{Deserialize, Serialize, de::Deserializer};
#[derive(Debug, Deserialize, Serialize)]
-#[serde(deny_unknown_fields)]
+#[serde(deny_unknown_fields, untagged)]
pub enum Recipe {
Command { command: CommandType },
Script { script: ScriptType },
Rule { rule: RuleType },
}
// -> Delete this entire block:
//
// impl Serialize for Recipe {
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
// where
// S: Serializer,
// {
// let mut map = serializer.serialize_map(Some(1))?;
// match self {
// Self::Command { command } => map.serialize_entry("command", command)?,
// Self::Script { script } => map.serialize_entry("script", script)?,
// Self::Rule { rule } => map.serialize_entry("rule", rule)?,
// }
// map.end()
// }
// }
```
This lets Serde’s `#[serde(untagged)]` derive handle the single-key map for you, eliminating the custom `Serialize` implementation and related boilerplate.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| } | ||
| // Serialise into a single-key map so `#[serde(flatten)]` on parent | ||
| // structs inserts the appropriate recipe field directly. | ||
| impl Serialize for Recipe { |
There was a problem hiding this comment.
issue (complexity): Consider removing the manual Serialize implementation and using Serde's #[serde(untagged)] derive instead.
// Remove the manual Serialize impl and imports:
-use serde::{Deserialize, Serialize, de::Deserializer, ser::{SerializeMap, Serializer}};
+use serde::{Deserialize, Serialize, de::Deserializer};
#[derive(Debug, Deserialize, Serialize)]
-#[serde(deny_unknown_fields)]
+#[serde(deny_unknown_fields, untagged)]
pub enum Recipe {
Command { command: CommandType },
Script { script: ScriptType },
Rule { rule: RuleType },
}
// -> Delete this entire block:
//
// impl Serialize for Recipe {
// fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
// where
// S: Serializer,
// {
// let mut map = serializer.serialize_map(Some(1))?;
// match self {
// Self::Command { command } => map.serialize_entry("command", command)?,
// Self::Script { script } => map.serialize_entry("script", script)?,
// Self::Rule { rule } => map.serialize_entry("rule", rule)?,
// }
// map.end()
// }
// }This lets Serde’s #[serde(untagged)] derive handle the single-key map for you, eliminating the custom Serialize implementation and related boilerplate.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (2)
src/ast.rs(1 hunks)src/ir.rs(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit Inference Engine (AGENTS.md)
**/*.rs: Clippy warnings MUST be disallowed.
Fix any warnings emitted during tests in the code itself rather than silencing them.
Where a function is too long, extract meaningfully named helper functions adhering to separation of concerns and CQRS.
Where a function has too many parameters, group related parameters in meaningfully named structs.
Where a function is returning a large error consider usingArcto reduce the amount of data returned.
Write unit and behavioural tests for new functionality. Run both before and after making any change.
Every module must begin with a module level (//!) comment explaining the module's purpose and utility.
Document public APIs using Rustdoc comments (///) so documentation can be generated with cargo doc.
Prefer immutable data and avoid unnecessarymutbindings.
Handle errors with theResulttype instead of panicking where feasible.
Avoidunsafecode unless absolutely necessary and document any usage clearly.
Place function attributes after doc comments.
Do not usereturnin single-line functions.
Use predicate functions for conditional criteria with more than two branches.
Lints must not be silenced except as a last resort.
Lint rule suppressions must be tightly scoped and include a clear reason.
Preferexpectoverallow.
Prefer.expect()over.unwrap().
Useconcat!()to combine long string literals rather than escaping newlines with a backslash.
Prefer semantic error enums: Derivestd::error::Error(via thethiserrorcrate) for any condition the caller might inspect, retry, or map to an HTTP status.
Use an opaque error only at the app boundary: Useeyre::Reportfor human-readable logs; these should not be exposed in public APIs.
Never export the opaque type from a library: Convert to domain enums at API boundaries, and toeyreonly in the mainmain()entrypoint or top-level async task.
Files:
src/ir.rssrc/ast.rs
⚙️ CodeRabbit Configuration File
**/*.rs: * Seek to keep the cyclomatic complexity of functions no more than 12.
Adhere to single responsibility and CQRS
Place function attributes after doc comments.
Do not use
returnin single-line functions.Move conditionals with >2 branches into a predicate function.
Avoid
unsafeunless absolutely necessary.Every module must begin with a
//!doc comment that explains the module's purpose and utility.Comments and docs must follow en-GB-oxendict (-ize / -our) spelling and grammar
Lints must not be silenced except as a last resort.
#[allow]is forbidden.- Only narrowly scoped
#[expect(lint, reason = "...")]is allowed.- No lint groups, no blanket or file-wide suppression.
- Include
FIXME:with link if a fix is expected.Use
rstestfixtures for shared setup and to avoid repetition between tests.Replace duplicated tests with
#[rstest(...)]parameterised cases.Prefer
mockallfor mocks/stubs.Prefer
.expect()over.unwrap()Ensure that any API or behavioural changes are reflected in the documentation in
docs/Ensure that any completed roadmap steps are recorded in the appropriate roadmap in
docs/Files must not exceed 400 lines in length
- Large modules must be decomposed
- Long match statements or dispatch tables should be decomposed by domain and collocated with targets
- Large blocks of inline data (e.g., test fixtures, constants or templates) must be moved to external files and inlined at compile-time or loaded at run-time.
Files:
src/ir.rssrc/ast.rs
🪛 GitHub Check: build-test
src/ir.rs
[failure] 344-344:
this if statement can be collapsed
🪛 GitHub Actions: CI
src/ir.rs
[error] 344-344: Clippy lint error: this if statement can be collapsed.
🔇 Additional comments (1)
src/ast.rs (1)
109-110: Excellent implementation of serialisation support.The addition of
Serializederive and#[serde(untagged)]attribute perfectly addresses the PR objectives. This enables automatic serialisation of eachRecipevariant as a single-key map, allowing serde's flatten behaviour to work correctly in parent structs whilst maintaining consistency with the existing deserialisation logic.
| if targets.contains_key(dep) { | ||
| if let Some(cycle) = visit(targets, dep, stack, states) { | ||
| return Some(cycle); | ||
| } |
There was a problem hiding this comment.
Fix the collapsible if statement flagged by Clippy.
The nested if statement violates the coding guidelines requirement that Clippy warnings must be disallowed. The pipeline failure correctly identifies this can be collapsed.
Apply this diff to collapse the nested conditions:
- if targets.contains_key(dep) {
- if let Some(cycle) = visit(targets, dep, stack, states) {
- return Some(cycle);
- }
- }
+ if targets.contains_key(dep) && let Some(cycle) = visit(targets, dep, stack, states) {
+ return Some(cycle);
+ }📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| if targets.contains_key(dep) { | |
| if let Some(cycle) = visit(targets, dep, stack, states) { | |
| return Some(cycle); | |
| } | |
| if targets.contains_key(dep) && let Some(cycle) = visit(targets, dep, stack, states) { | |
| return Some(cycle); | |
| } |
🧰 Tools
🪛 GitHub Check: build-test
[failure] 344-344:
this if statement can be collapsed
🪛 GitHub Actions: CI
[error] 344-344: Clippy lint error: this if statement can be collapsed.
🤖 Prompt for AI Agents
In src/ir.rs around lines 344 to 347, there is a nested if statement that Clippy
flags for collapsing. To fix this, combine the two conditions into a single if
statement using a logical AND, so that the inner if is merged with the outer
one, eliminating the nested structure and satisfying Clippy's requirement.
|
Stale |
Summary
SerializeforRecipeso rules and targets flatten recipe fields correctlyTesting
make fmtmake lintmake testmake buildhttps://chatgpt.com/codex/tasks/task_e_6891f0dda3348322ace645f18ea027b5
Summary by Sourcery
Implement custom Serialize for Recipe to output each variant as a single-key map so that serde’s flatten behavior works correctly and add serialization tests for command, script, and rule variants
New Features:
Enhancements:
Tests: