Conversation
|
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
WalkthroughUpdate the manifest parsing logic to support Jinja templating via a two-pass process: first, extract global variables with lenient undefined handling; second, render the manifest strictly with these variables injected, then parse as YAML. Add the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ManifestParser
participant JinjaEnv
participant YAMLDeserializer
User->>ManifestParser: Call from_str(yaml)
ManifestParser->>JinjaEnv: Render yaml (lenient undefined)
JinjaEnv-->>ManifestParser: Rendered template (pass 1)
ManifestParser->>YAMLDeserializer: Extract vars mapping
YAMLDeserializer-->>ManifestParser: Vars dictionary
ManifestParser->>JinjaEnv: Inject vars, set strict undefined
ManifestParser->>JinjaEnv: Render yaml (strict undefined)
JinjaEnv-->>ManifestParser: Fully rendered yaml
ManifestParser->>YAMLDeserializer: Deserialize to NetsukeManifest
YAMLDeserializer-->>ManifestParser: NetsukeManifest
ManifestParser-->>User: Return result
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~18 minutes Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (2)
🧰 Additional context used📓 Path-based instructions (3)docs/**/*.md📄 CodeRabbit Inference Engine (AGENTS.md)
Files:
**/*.md📄 CodeRabbit Inference Engine (AGENTS.md)
Files:
⚙️ CodeRabbit Configuration File
Files:
**/*.rs📄 CodeRabbit Inference Engine (AGENTS.md)
Files:
⚙️ CodeRabbit Configuration File
Files:
🔇 Additional comments (6)
✨ 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 (
|
Reviewer's GuideImplements two-pass Jinja templating for manifest parsing via the minijinja crate, updates documentation to reflect the bootstrapping process, adds comprehensive unit and integration tests for Jinja rendering, and marks Jinja integration tasks as complete in the roadmap. Sequence diagram for two-pass Jinja manifest renderingsequenceDiagram
participant Caller
participant ManifestParser as from_str()
participant JinjaEnv as minijinja::Environment
participant SerdeYml
Caller->>ManifestParser: from_str(yaml)
ManifestParser->>JinjaEnv: Create Environment (Lenient)
ManifestParser->>JinjaEnv: render_str(yaml, {})
JinjaEnv-->>ManifestParser: rendered (first pass)
ManifestParser->>SerdeYml: from_str(rendered)
SerdeYml-->>ManifestParser: VarsOnly { vars }
ManifestParser->>JinjaEnv: Add vars as globals
ManifestParser->>JinjaEnv: Set UndefinedBehavior::Strict
ManifestParser->>JinjaEnv: render_str(yaml, {})
JinjaEnv-->>ManifestParser: rendered (second pass)
ManifestParser->>SerdeYml: from_str(rendered)
SerdeYml-->>ManifestParser: NetsukeManifest
ManifestParser-->>Caller: NetsukeManifest
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @leynos - I've reviewed your changes - here's some feedback:
- Consider extracting the two-pass Jinja rendering flow in from_str into a dedicated helper or type to improve readability and testability.
- Differentiate error contexts between the first and second Jinja render passes (e.g., “first-pass render error” vs “second-pass render error”) to help debug failures more easily.
- The Rust code snippets in the docs were collapsed into single-line blocks—please revert to multi-line formatting (separate imports, fields, and enum variants onto their own lines) for better readability.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the two-pass Jinja rendering flow in from_str into a dedicated helper or type to improve readability and testability.
- Differentiate error contexts between the first and second Jinja render passes (e.g., “first-pass render error” vs “second-pass render error”) to help debug failures more easily.
- The Rust code snippets in the docs were collapsed into single-line blocks—please revert to multi-line formatting (separate imports, fields, and enum variants onto their own lines) for better readability.
## Individual Comments
### Comment 1
<location> `src/manifest.rs:13` </location>
<code_context>
+use std::{collections::HashMap, fs, path::Path};
-/// Parse a YAML string into a [`NetsukeManifest`].
+#[derive(Default, Deserialize)]
+struct VarsOnly {
+ #[serde(default)]
</code_context>
<issue_to_address>
Consider simplifying the code by extracting repeated rendering logic into a helper function and directly accessing the 'vars' field from a deserialized YAML value instead of using a custom struct.
```suggestion
You can trim down a lot of the boilerplate by
1. factoring out the duplicated render + error‐context into a small helper
2. dropping the one‐field `VarsOnly` struct and just pulling `"vars"` out of a `serde_yaml::Value`
For example:
```rust
use minijinja::{Environment, UndefinedBehavior, value::Value};
use anyhow::{Context, Result};
fn jinja_render(env: &Environment, tpl: &str) -> Result<String> {
env.render_str(tpl, ())
.context("Jinja render error")
}
pub fn from_str(yaml: &str) -> Result<NetsukeManifest> {
let mut env = Environment::new();
env.set_undefined_behavior(UndefinedBehavior::Lenient);
// first pass → render + extract "vars"
let rendered = jinja_render(&env, yaml)?;
let doc: serde_yaml::Value = serde_yaml::from_str(&rendered)
.context("YAML parse error")?;
let vars = match doc.get("vars") {
Some(serde_yaml::Value::Mapping(m)) => m.iter()
.filter_map(|(k, v)| {
if let (Some(key), serde_yaml::Value::String(val)) = (k.as_str(), v) {
Some((key.to_string(), val.clone()))
} else {
None
}
})
.collect::<std::collections::HashMap<_, _>>(),
_ => Default::default(),
};
// inject globals + strict undefineds
for (k, v) in vars {
env.add_global(k, Value::from(v));
}
env.set_undefined_behavior(UndefinedBehavior::Strict);
// second pass → final YAML
let final_yaml = jinja_render(&env, yaml)?;
Ok(serde_yaml::from_str(&final_yaml).context("YAML parse error")?)
}
```
- removes the extra `VarsOnly` type
- centralises render+error wrapping in `jinja_render`
- keeps both‐pass logic and strict/lenient modes unchanged
```
</issue_to_address>
### Comment 2
<location> `docs/netsuke-design.md:1357` </location>
<code_context>
```rust
-use clap::{Args, Parser, Subcommand};
-use std::path::PathBuf;
+use clap::{Args, Parser, Subcommand}; use std::path::PathBuf;
#[derive(Parser)]
</code_context>
<issue_to_address>
Rust code block line exceeds 120 columns; please wrap to 120 columns as per instructions.
The line combining multiple imports exceeds the 120 column limit for code blocks. Please wrap the line to ensure it does not exceed 120 columns.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (9)
Cargo.toml(1 hunks)docs/netsuke-design.md(3 hunks)docs/roadmap.md(1 hunks)src/manifest.rs(2 hunks)tests/data/jinja_undefined.yml(1 hunks)tests/data/jinja_vars.yml(1 hunks)tests/features/manifest.feature(1 hunks)tests/manifest_jinja_tests.rs(1 hunks)tests/steps/manifest_steps.rs(2 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
Cargo.toml
📄 CodeRabbit Inference Engine (AGENTS.md)
Cargo.toml: Use explicit version ranges inCargo.tomland keep dependencies up-to-date.
Mandate caret requirements for all dependencies: All crate versions specified inCargo.tomlmust use SemVer-compatible caret requirements (e.g.,some-crate = "1.2.3").
Prohibit unstable version specifiers: The use of wildcard (*) or open-ended inequality (>=) version requirements is strictly forbidden. Tilde requirements (~) should only be used where a dependency must be locked to patch-level updates for a specific, documented reason.
Files:
Cargo.toml
**/*.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:
tests/steps/manifest_steps.rstests/manifest_jinja_tests.rssrc/manifest.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:
tests/steps/manifest_steps.rstests/manifest_jinja_tests.rssrc/manifest.rs
docs/**/*.md
📄 CodeRabbit Inference Engine (AGENTS.md)
docs/**/*.md: Use the markdown files within thedocs/directory as a knowledge base and source of truth for project requirements, dependency choices, and architectural decisions.
Proactively update the relevant file(s) in thedocs/directory to reflect the latest state when new decisions are made, requirements change, libraries are added/removed, or architectural patterns evolve.
Files:
docs/roadmap.mddocs/netsuke-design.md
**/*.md
📄 CodeRabbit Inference Engine (AGENTS.md)
**/*.md: Documentation must use en-GB-oxendict spelling and grammar, except for the naming of the "LICENSE" file.
Validate Markdown files usingmake markdownlint.
Runmake fmtafter any documentation changes to format all Markdown files and fix table markup.
Validate Mermaid diagrams in Markdown files by runningmake nixie.
Markdown paragraphs and bullet points must be wrapped at 80 columns.
Code blocks in Markdown must be wrapped at 120 columns.
Tables and headings in Markdown must not be wrapped.
Use dashes (-) for list bullets in Markdown.
Use GitHub-flavoured Markdown footnotes ([^1]) for references and footnotes.
Files:
docs/roadmap.mddocs/netsuke-design.md
⚙️ CodeRabbit Configuration File
**/*.md: * Avoid 2nd person or 1st person pronouns ("I", "you", "we")
- Use en-GB-oxendict (-ize / -our) spelling and grammar
- Paragraphs and bullets must be wrapped to 80 columns, except where a long URL would prevent this (in which case, silence MD013 for that line)
- Code blocks should be wrapped to 120 columns.
- Headings must not be wrapped.
- Documents must start with a level 1 heading
- Headings must correctly increase or decrease by no more than one level at a time
- Use GitHub-flavoured Markdown style for footnotes and endnotes.
- Numbered footnotes must be numbered by order of appearance in the document.
Files:
docs/roadmap.mddocs/netsuke-design.md
🪛 GitHub Actions: CI
src/manifest.rs
[error] 6-6: cargo fmt formatting check failed. Import statements order differs. Run 'cargo fmt --all' to fix code style issues.
🔇 Additional comments (16)
Cargo.toml (1)
10-10: Use explicit caret requirement for consistency.The coding guidelines mandate explicit caret requirements for all dependencies. Update the minijinja dependency specification to be explicit.
-minijinja = "2.11.0" +minijinja = "^2.11.0"Likely an incorrect or invalid review comment.
tests/data/jinja_undefined.yml (1)
1-4: LGTM!The test data file correctly defines a manifest with an undefined Jinja variable to test error handling in the two-pass rendering approach.
tests/data/jinja_vars.yml (1)
1-6: LGTM!The test data file correctly demonstrates Jinja variable substitution with a properly defined vars section and template usage in the command.
tests/features/manifest.feature (1)
49-57: LGTM!The new feature test scenarios comprehensively cover both successful Jinja variable rendering and error handling for undefined variables, using appropriate test data files.
docs/roadmap.md (1)
78-87: LGTM!The roadmap updates accurately reflect the completion of the core Jinja integration tasks, correctly marking the implemented functionality as complete whilst leaving future enhancements unchecked.
tests/steps/manifest_steps.rs (2)
9-12: LGTM: Import expansion supports new test functionality.The explicit import of
Recipefrom theastmodule properly supports the new test step function implementation.
109-118: LGTM: Well-implemented test step function.The function correctly validates the first target's recipe type and command string using appropriate pattern matching and error handling for test assertions.
docs/netsuke-design.md (2)
663-667: Excellent documentation of the two-pass rendering approach.The explanation clearly describes the technical implementation of lenient first pass for variable extraction followed by strict second pass rendering. This aligns perfectly with the code implementation.
1357-1401: LGTM: Improved code formatting and style consistency.The reformatting enhances readability whilst preserving functionality. The compressed struct definitions and merged imports follow Rust conventions effectively.
tests/manifest_jinja_tests.rs (4)
1-1: LGTM: Proper module documentation.The module-level doc comment clearly explains the purpose and utility of the test module as required by the coding guidelines.
6-24: LGTM: Comprehensive test for variable substitution.The test effectively validates the two-pass Jinja rendering by verifying that global variables from the
varssection are correctly substituted into command templates. The pattern matching and error handling are appropriate.
26-36: LGTM: Effective error case validation.The test correctly verifies that manifests referencing undefined variables produce parsing errors, validating the strict undefined variable handling in the second rendering pass.
38-48: LGTM: Important syntax error coverage.The test validates that Jinja syntax errors (unterminated expressions) are properly caught and cause parsing failures, ensuring robust error handling for malformed templates.
src/manifest.rs (3)
13-17: LGTM: Well-designed helper struct.The
VarsOnlystruct effectively supports the two-pass parsing by extracting only the variables section. The use of#[serde(default)]ensures robust handling of manifests without avarssection.
19-44: Excellent documentation updates.The function documentation clearly explains the two-pass Jinja templating approach with a practical example. The error documentation appropriately covers both rendering and parsing failure modes.
45-76: LGTM: Excellent two-pass implementation.The implementation correctly follows the documented approach: lenient first pass for variable extraction, followed by strict second pass with injected variables. Error handling is comprehensive with appropriate context messages for both Jinja rendering and YAML parsing failures.
|
@coderabbitai Have the following now been resolved?
|
|
Tip For best results, initiate chat on the files or code changes. 🧩 Analysis chain@leynos Let me check the current status of each point: Point 1: Two-pass Jinja rendering extraction - ✅ Partially resolved Point 2: Error context differentiation - ✅ Fully resolved fn render(env: &Environment, tpl: &str, pass: &str) -> Result<String> {
let template = env.template_from_str(tpl)
.with_context(|| format!("Failed to compile Jinja template on {}", pass))?;
template.render(())
.with_context(|| format!("Failed to render Jinja template on {}", pass))
}Point 3: Documentation code formatting - ✅ Appears resolved Summary: Points 2 and 3 are fully resolved, while Point 1 shows good progress with the 🏁 Script executed: Length of output: 79873 @leynos After examining the current implementation, here's the status of each point: Point 1: Two-pass Jinja rendering extraction - ✅ Partially resolved fn render(env: &Environment, tpl: &str, pass: &str) -> Result<String> {
env.render_str(tpl, context! {})
.with_context(|| format!("{pass} render error"))
}However, the main two-pass orchestration logic (bootstrap environment, extract vars from first pass, populate environment, second pass) remains embedded in Point 2: Error context differentiation - ✅ Fully resolved
This provides clear debugging context to distinguish between the lenient variable extraction phase and the strict final rendering phase. Point 3: Documentation code formatting - ✅ Fully resolved Summary: Points 2 and 3 are fully addressed. Point 1 shows good progress with the |
Summary
Testing
make fmtmake markdownlintmake lintmake testmake nixie(fails: too many arguments. Expected 0 arguments but got 1.)https://chatgpt.com/codex/tasks/task_e_6893d2e182048322a06c52400009b67d
Summary by Sourcery
Integrate Jinja templating into manifest parsing by implementing a two-pass render pipeline, updating documentation, and adding corresponding tests
New Features:
Enhancements:
Build:
Documentation:
Tests: