mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 21:15:57 +03:00
fix(cli-rs): release the plugin watch borrow before adding watches
The borrow_mut temporary in the for-loop head lived for the whole loop, so pushing a new watch panicked with RefCell already borrowed. The TUI panic test now disables the failed plugin before enabling it, as /plugins offers disable for a plugin that failed while active.
This commit is contained in:
@@ -157,7 +157,8 @@ type Watched<W = opencode_local::watch::Watch> = (PathBuf, Option<u64>, W);
|
||||
/// Watches the loader's directories: keeps the watches that still see them, and replaces one whose directory
|
||||
/// went away or was made again, which the old watch no longer sees.
|
||||
fn watch(tui: &Tui, loader: &Loader<Tui>, watches: &RefCell<Vec<Watched>>) {
|
||||
for (dir, id) in unwatched(&mut watches.borrow_mut(), loader.watch_dirs()) {
|
||||
let fresh = unwatched(&mut watches.borrow_mut(), loader.watch_dirs());
|
||||
for (dir, id) in fresh {
|
||||
let proxy = tui.app.proxy();
|
||||
let watch = opencode_local::watch::watch(
|
||||
&dir,
|
||||
|
||||
@@ -168,6 +168,11 @@ fn a_panicking_command_is_caught_and_enabling_restarts_the_plugin() {
|
||||
let screen = h.wait_for("run-command panicked: sample command panicked");
|
||||
print_excerpt("error details after a panic", &screen);
|
||||
h.app.press("escape");
|
||||
// A plugin that failed while active is still active, as in TS: enter disables it, then enables it afresh.
|
||||
h.wait_for("disable enter");
|
||||
h.app.press("enter");
|
||||
h.app.wait_until(Duration::from_secs(5), || h.status() == opencode_plugin::Status::Inactive);
|
||||
assert_eq!(h.status(), opencode_plugin::Status::Inactive);
|
||||
h.wait_for("enable enter");
|
||||
h.app.press("enter");
|
||||
h.app.wait_until(Duration::from_secs(5), || h.status() == opencode_plugin::Status::Active);
|
||||
|
||||
Reference in New Issue
Block a user