Repository navigation
crates/minimal: make minimal update update sideloads as well - #172
Conversation
📝 WalkthroughWalkthroughUpdate command now refreshes git-based upstream sideloads: it checks out each sideload's configured branch, compares the obtained commit ref to the existing Changes
Sequence DiagramsequenceDiagram
participant Cmd as Update Command
participant Git as Git Repo
participant Sideload as Sideload Config
participant TOML as minimal.toml
Cmd->>Sideload: enumerate configured sideloads
loop per sideload
Cmd->>Git: checkout sideload.branch
Git-->>Cmd: commit_ref
Cmd->>Sideload: compare commit_ref vs locked_commit
alt ref differs
Cmd->>Cmd: record new_ref (Some)
Cmd->>Cmd: log "updated from X to Y"
else no change or non-git
Cmd->>Cmd: record None
end
end
alt any upstream or sideload changed
Cmd->>TOML: update upstream and upstream.sideload[i].locked_commit entries
TOML-->>Cmd: file written
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
crates/minimal/src/cmd_update.rs (1)
42-66: Please add a regression test for mixed sideload updates.This path now couples checkout results back to
upstream.sideload[i]by index and only rewrites changed git sideloads. A focused test with mixedGit/Dirsideloads and changed/unchanged branches would make this much safer.As per coding guidelines,
**/*.rs: Frequently runcargo test -p <crate name>when iterating on code changes to spot compilation errors, issues, and test failures.Also applies to: 95-110
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/minimal/src/cmd_update.rs` around lines 42 - 66, The current update logic builds sideload_updates by index and only rewrites changed Git sideloads, which can break when sideloads are mixed types; add a regression test in the crate that constructs an mfile.upstream with mixed sideloads (use both mfile::LinkConfig::Git and a Dir sideload), stub or simulate vcs.checkout_of to return both a changed and an unchanged branch result, call the update path that produces sideload_updates (the code that computes sideload_updates in cmd_update.rs) and assert that only the Git sideload with a changed commit is flagged/rewritten while the Dir and unchanged Git entries remain untouched; reference the functions/types mfile.upstream.sideloads(), LinkConfig::Git, checkout_of, and the sideload_updates outcome to locate and validate the behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/minimal/src/cmd_update.rs`:
- Around line 98-104: The println that builds the "Sideload {}:{} updated..."
message is using as_inline_table() to read locked_commit which fails for
array-of-tables entries; change the lookup to directly index the sideload entry
(doc["upstream"]["sideload"][i]["locked_commit"]) and call
as_str().unwrap_or("<unpinned>") (or equivalent safe as_str handling) so
locked_commit is read correctly for both inline-table and [[upstream.sideload]]
formats; update the expression in the println that currently references
as_inline_table() to use this direct indexing.
---
Nitpick comments:
In `@crates/minimal/src/cmd_update.rs`:
- Around line 42-66: The current update logic builds sideload_updates by index
and only rewrites changed Git sideloads, which can break when sideloads are
mixed types; add a regression test in the crate that constructs an
mfile.upstream with mixed sideloads (use both mfile::LinkConfig::Git and a Dir
sideload), stub or simulate vcs.checkout_of to return both a changed and an
unchanged branch result, call the update path that produces sideload_updates
(the code that computes sideload_updates in cmd_update.rs) and assert that only
the Git sideload with a changed commit is flagged/rewritten while the Dir and
unchanged Git entries remain untouched; reference the functions/types
mfile.upstream.sideloads(), LinkConfig::Git, checkout_of, and the
sideload_updates outcome to locate and validate the behavior.
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: e6a71849-caa0-4c44-afdf-868d0420b6e2
📒 Files selected for processing (1)
crates/minimal/src/cmd_update.rs
39680dd to
30fd0a3
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/minimal/src/cmd_update.rs`:
- Around line 95-109: The loop that updates sideload pins currently always
reads/writes doc["upstream"]["sideload"], which misses the canonical "sideloads"
key and can panic; update the code in the sideload_updates handling (the for (i,
rev) in sideload_updates loop and the place where
doc["upstream"]["sideload"][i]["locked_commit"] is set) to first choose the
correct node: let key = if doc["upstream"].get("sideloads").is_some() {
"sideloads" } else { "sideload" }; then use doc["upstream"][key][i] for
reads/prints and set the locked_commit on that selected node (and avoid direct
unwraps by using get()/and_then(|v| v.as_str()).unwrap_or("<unpinned>") as
already used).
🪄 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: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 7b147af6-72c4-424a-aae1-f5dae5447b2c
📒 Files selected for processing (1)
crates/minimal/src/cmd_update.rs
| // Update sideloads | ||
| for (i, rev) in sideload_updates.into_iter().enumerate() { | ||
| if let Some(new_rev) = rev { | ||
| println!( | ||
| "Sideload {}:{} updated from {} to {}", | ||
| doc["upstream"]["sideload"][i]["repo"].as_str().unwrap(), | ||
| doc["upstream"]["sideload"][i]["branch"].as_str().unwrap(), | ||
| doc["upstream"]["sideload"][i] | ||
| .get("locked_commit") | ||
| .and_then(|s| s.as_str()) | ||
| .unwrap_or("<unpinned>"), | ||
| new_rev | ||
| ); | ||
|
|
||
| doc["upstream"]["sideload"][i]["locked_commit"] = value(new_rev.clone()); |
There was a problem hiding this comment.
Honor both sideloads and legacy sideload keys when writing sideload pins.
mfile::Upstream accepts both TOML spellings, but Lines 100-109 always read and mutate doc["upstream"]["sideload"]. If a minimal.toml uses the canonical sideloads key, this block will update the wrong node and can panic on the unwrap()s even though the sideload was parsed successfully.
Suggested change
+ let sideload_key = if doc["upstream"].get("sideloads").is_some() {
+ "sideloads"
+ } else {
+ "sideload"
+ };
+
// Update sideloads
for (i, rev) in sideload_updates.into_iter().enumerate() {
if let Some(new_rev) = rev {
println!(
"Sideload {}:{} updated from {} to {}",
- doc["upstream"]["sideload"][i]["repo"].as_str().unwrap(),
- doc["upstream"]["sideload"][i]["branch"].as_str().unwrap(),
- doc["upstream"]["sideload"][i]
+ doc["upstream"][sideload_key][i]["repo"].as_str().unwrap(),
+ doc["upstream"][sideload_key][i]["branch"].as_str().unwrap(),
+ doc["upstream"][sideload_key][i]
.get("locked_commit")
.and_then(|s| s.as_str())
.unwrap_or("<unpinned>"),
new_rev
);
- doc["upstream"]["sideload"][i]["locked_commit"] = value(new_rev.clone());
+ doc["upstream"][sideload_key][i]["locked_commit"] = value(new_rev.clone());
}
}📝 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.
| // Update sideloads | |
| for (i, rev) in sideload_updates.into_iter().enumerate() { | |
| if let Some(new_rev) = rev { | |
| println!( | |
| "Sideload {}:{} updated from {} to {}", | |
| doc["upstream"]["sideload"][i]["repo"].as_str().unwrap(), | |
| doc["upstream"]["sideload"][i]["branch"].as_str().unwrap(), | |
| doc["upstream"]["sideload"][i] | |
| .get("locked_commit") | |
| .and_then(|s| s.as_str()) | |
| .unwrap_or("<unpinned>"), | |
| new_rev | |
| ); | |
| doc["upstream"]["sideload"][i]["locked_commit"] = value(new_rev.clone()); | |
| let sideload_key = if doc["upstream"].get("sideloads").is_some() { | |
| "sideloads" | |
| } else { | |
| "sideload" | |
| }; | |
| // Update sideloads | |
| for (i, rev) in sideload_updates.into_iter().enumerate() { | |
| if let Some(new_rev) = rev { | |
| println!( | |
| "Sideload {}:{} updated from {} to {}", | |
| doc["upstream"][sideload_key][i]["repo"].as_str().unwrap(), | |
| doc["upstream"][sideload_key][i]["branch"].as_str().unwrap(), | |
| doc["upstream"][sideload_key][i] | |
| .get("locked_commit") | |
| .and_then(|s| s.as_str()) | |
| .unwrap_or("<unpinned>"), | |
| new_rev | |
| ); | |
| doc["upstream"][sideload_key][i]["locked_commit"] = value(new_rev.clone()); | |
| } | |
| } |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@crates/minimal/src/cmd_update.rs` around lines 95 - 109, The loop that
updates sideload pins currently always reads/writes doc["upstream"]["sideload"],
which misses the canonical "sideloads" key and can panic; update the code in the
sideload_updates handling (the for (i, rev) in sideload_updates loop and the
place where doc["upstream"]["sideload"][i]["locked_commit"] is set) to first
choose the correct node: let key = if doc["upstream"].get("sideloads").is_some()
{ "sideloads" } else { "sideload" }; then use doc["upstream"][key][i] for
reads/prints and set the locked_commit on that selected node (and avoid direct
unwraps by using get()/and_then(|v| v.as_str()).unwrap_or("<unpinned>") as
already used).
Summary by CodeRabbit