refactor(op): move init and update code into op crate - #592
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (11)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (10)
📝 WalkthroughWalkthroughAdds shared project-operation traits and a ChangesProject Init/Update Abstraction
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🧹 Nitpick comments (1)
crates/mctx/src/error.rs (1)
222-225: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winPreserve the inner
op::Error::Othererror instead of stringifying it.The fallback converts the error into a new formatted
anyhow::Error, which loses the original source chain. Matchop::Error::Other(e)explicitly and passethrough.Suggested change
match value { op::Error::IO(e) => Self::IO("op", PathBuf::new(), e), op::Error::Plan(graph, e) => Self::Plan(Box::new((graph, e))), + op::Error::Other(e) => Self::Other(e), other => Self::Other(anyhow::anyhow!("{}", other)), }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/mctx/src/error.rs` around lines 222 - 225, The fallback arm in the error conversion currently stringifies the inner error and discards its source chain; update the match in the error mapping logic to handle op::Error::Other explicitly instead of using the generic other case. Preserve the original error by passing the inner value through directly in the same conversion path used by the other op::Error variants, alongside the existing IO and Plan handling.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/minimal/src/cmd_init.rs`:
- Around line 33-36: The confirmation check in cmd_init should accept "yes" as a
valid affirmative input in addition to "y" and empty input. Update the input
validation logic in the init command flow (the block using input.trim() and
eprintln!("Aborted.")) so that any case-insensitive "yes" value is treated as
confirmation and does not trigger the abort path.
In `@crates/op/src/project/init.rs`:
- Around line 53-61: The re-init path in init() is rebuilding the graph from
env.repo_dir() instead of reusing the upstream already stored in minimal.toml,
which can cause graph_from_chain() to resolve the wrong source. Update the
existing branch in crates/op/src/project/init.rs so it preserves and reuses the
upstream link from the current configuration rather than forcing a new
LinkConfig::Dir from the repo directory, and keep the existing origin/file_path
flow intact.
In `@crates/op/src/project/update.rs`:
- Around line 126-129: The migration in update.rs unconditionally overwrites any
existing stack entry when moving data from harness to stack. Update the project
update logic in the update path so the harness migration only populates stack
when stack is absent, or otherwise merges without replacing existing stack
contents. Use the existing update flow around doc.remove("harness") and
report.migrated_harness to preserve current stack config during minimal update.
---
Nitpick comments:
In `@crates/mctx/src/error.rs`:
- Around line 222-225: The fallback arm in the error conversion currently
stringifies the inner error and discards its source chain; update the match in
the error mapping logic to handle op::Error::Other explicitly instead of using
the generic other case. Preserve the original error by passing the inner value
through directly in the same conversion path used by the other op::Error
variants, alongside the existing IO and Plan handling.
🪄 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: CHILL
Plan: Pro
Run ID: f1ae8588-2165-4ca3-ad1a-bf7bf2994429
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (11)
crates/decode/src/lib.rscrates/mctx/src/error.rscrates/mctx/src/lib.rscrates/mctx/src/project_setup.rscrates/minimal/src/cmd_init.rscrates/minimal/src/cmd_update.rscrates/op/Cargo.tomlcrates/op/src/lib.rscrates/op/src/project/init.rscrates/op/src/project/mod.rscrates/op/src/project/update.rs
f4cbef0 to
370b5f1
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@crates/op/src/project/update.rs`:
- Around line 83-85: The update flow in `update()` advances checkout state too
early by calling `env.update_checkouts()` before the pin rewrite in the
read/parse/write path is guaranteed. Change the logic so
`update_checkouts()`/`checkout_branch()` only resolve the new heads without
mutating state, or add rollback handling if the persistence step fails after
`minimal.toml` is updated. Keep the checkout mutation and the pin rewrite in
`update()` consistent so a failed write does not leave the project half-updated.
🪄 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: CHILL
Plan: Pro
Run ID: b86638d5-750c-47a9-a4d9-c5e403acc9f4
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (11)
crates/decode/src/lib.rscrates/mctx/src/error.rscrates/mctx/src/lib.rscrates/mctx/src/project_setup.rscrates/minimal/src/cmd_init.rscrates/minimal/src/cmd_update.rscrates/op/Cargo.tomlcrates/op/src/lib.rscrates/op/src/project/init.rscrates/op/src/project/mod.rscrates/op/src/project/update.rs
🚧 Files skipped from review as they are similar to previous changes (10)
- crates/decode/src/lib.rs
- crates/op/src/project/mod.rs
- crates/mctx/src/error.rs
- crates/op/src/lib.rs
- crates/mctx/src/lib.rs
- crates/op/Cargo.toml
- crates/mctx/src/project_setup.rs
- crates/minimal/src/cmd_update.rs
- crates/minimal/src/cmd_init.rs
- crates/op/src/project/init.rs
| // best effort, yeet any cached remote index so a fresh fetch occurs | ||
| env.invalidate_remote_index(); | ||
| env.update_checkouts()?; |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Avoid mutating checkouts before the pin rewrite is guaranteed.
update_checkouts() / checkout_branch() run before the read/parse/write path at Lines 115-149. If that persistence step fails, the checkout state has already advanced while minimal.toml still points at the old commits, leaving the project half-updated. This needs either a non-mutating way to resolve the new heads first, or a rollback path when persisting the new pins fails.
Also applies to: 115-149
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@crates/op/src/project/update.rs` around lines 83 - 85, The update flow in
`update()` advances checkout state too early by calling `env.update_checkouts()`
before the pin rewrite in the read/parse/write path is guaranteed. Change the
logic so `update_checkouts()`/`checkout_branch()` only resolve the new heads
without mutating state, or add rollback handling if the persistence step fails
after `minimal.toml` is updated. Keep the checkout mutation and the pin rewrite
in `update()` consistent so a failed write does not leave the project
half-updated.
370b5f1 to
5b81b6e
Compare
Moves the logic for
minimal initandminimal updateinto the op crate, generalized by theProjectOptrait.This enables:
Summary by CodeRabbit
minimal.toml.yesin addition toy.