aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-06-16 02:56:06 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-06-16 02:56:25 +0300
commit2fe57a57a2b335c6d300a96b442d428b9b2cadf8 (patch)
tree956126d51bd8f577b88d41532f9e3cf160965d60 /src
parent4cf9f8e958119243b1f648f4d7b9baa335bb8ffd (diff)
fix: stabilize flaky plugin capture tests and auto-trigger website deploy
Diffstat (limited to 'src')
-rw-r--r--src/app/api/plugins/mod.rs43
1 files changed, 27 insertions, 16 deletions
diff --git a/src/app/api/plugins/mod.rs b/src/app/api/plugins/mod.rs
index 1938589c..8c0e4212 100644
--- a/src/app/api/plugins/mod.rs
+++ b/src/app/api/plugins/mod.rs
@@ -695,6 +695,27 @@ mod tests {
.to_string()
}
+ /// Wait for non-empty contents at `path`. Shell `>` creates the file empty
+ /// before the command writes, so waiting on existence alone can read EOF.
+ /// `pump` advances any event loop the command depends on.
+ fn read_capture_when_ready(path: &std::path::Path, mut pump: impl FnMut()) -> String {
+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
+ loop {
+ pump();
+ if let Ok(contents) = std::fs::read_to_string(path) {
+ if !contents.is_empty() {
+ return contents;
+ }
+ }
+ assert!(
+ std::time::Instant::now() < deadline,
+ "plugin command did not write {} within deadline",
+ path.display()
+ );
+ std::thread::sleep(std::time::Duration::from_millis(10));
+ }
+ }
+
fn write_manifest(root: &std::path::Path) -> std::path::PathBuf {
std::fs::create_dir_all(root).unwrap();
let manifest = root.join("herdr-plugin.toml");
@@ -1207,11 +1228,7 @@ command = ["sh", "-c", "printf '%s\n%s\n%s\n%s\n%s\n%s\n%s\n' \"$PWD\" \"$HERDR_
};
assert!(app.state.plugin_panes.contains_key(&opened_pane_id));
- let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
- while !capture.exists() && std::time::Instant::now() < deadline {
- std::thread::sleep(std::time::Duration::from_millis(10));
- }
- let text = std::fs::read_to_string(&capture).expect("plugin pane command should write env");
+ let text = read_capture_when_ready(&capture, || {});
let mut lines = text.lines();
assert_eq!(lines.next(), Some(canonical_path_string(&root).as_str()));
assert_eq!(lines.next(), Some("example.pane"));
@@ -1306,11 +1323,7 @@ command = ["sh", "-c", "printf '%s\n%s\n%s\n' \"$HERDR_PLUGIN_ROOT\" \"$HERDR_PL
panic!("expected plugin pane opened response: {open}");
};
- let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
- while !capture.exists() && std::time::Instant::now() < deadline {
- std::thread::sleep(std::time::Duration::from_millis(10));
- }
- let text = std::fs::read_to_string(&capture).expect("plugin pane command should write env");
+ let text = read_capture_when_ready(&capture, || {});
let mut lines = text.lines();
assert_eq!(lines.next(), Some(canonical_path_string(&root).as_str()));
assert_eq!(
@@ -1792,13 +1805,11 @@ command = ["sh", "-c", "printf '%s' \"$HERDR_PLUGIN_CONTEXT_JSON\" > {}"]
},
});
- let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
- while !capture.exists() && std::time::Instant::now() < deadline {
- app.drain_all_internal_events();
- std::thread::sleep(std::time::Duration::from_millis(10));
- }
let context: PluginInvocationContext =
- serde_json::from_str(&std::fs::read_to_string(&capture).unwrap()).unwrap();
+ serde_json::from_str(&read_capture_when_ready(&capture, || {
+ app.drain_all_internal_events();
+ }))
+ .unwrap();
assert_eq!(
context.workspace_id.as_deref(),
Some(target_workspace.workspace_id.as_str())