Skip to content

Commit 6cc002c

Browse files
committed
refactor(pluginlab): split e2e test into e2e_cli_host allow build_command to use C and rust plugins
1 parent 364d91c commit 6cc002c

File tree

2 files changed

+91
-57
lines changed

2 files changed

+91
-57
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
mod utils;
2+
3+
#[cfg(test)]
4+
mod e2e_cli_host {
5+
6+
use crate::utils::*;
7+
8+
use rexpect::spawn;
9+
10+
const TEST_TIMEOUT: u64 = 10000;
11+
12+
/**
13+
* Lets us change the target directory for the plugins and repl logic.
14+
*
15+
* See the justfile for examples where we switch to testing both plugins from the filesystem and from the HTTP server.
16+
*/
17+
fn build_command(plugin_files: &[&str], repl_logic_file: &str) -> String {
18+
let prefix =
19+
std::env::var("WASM_TARGET_DIR").unwrap_or("target/wasm32-wasip1/debug".to_string());
20+
let mut command = String::from("target/debug/pluginlab");
21+
command.push_str(format!(" --repl-logic {}/{}", prefix, repl_logic_file).as_str());
22+
plugin_files.iter().for_each(|file| {
23+
command.push_str(format!(" --plugins {}", file).as_str());
24+
});
25+
println!("Running command: {}", command);
26+
command
27+
}
28+
29+
#[test]
30+
fn test_without_permission_allow_network() {
31+
let project_root = find_project_root();
32+
println!("Setting current directory to: {:?}", project_root);
33+
std::env::set_current_dir(&project_root).unwrap();
34+
let mut session = spawn(
35+
&build_command(
36+
&["target/wasm32-wasip1/debug/plugin_weather.wasm"],
37+
"repl_logic_guest.wasm",
38+
),
39+
Some(TEST_TIMEOUT),
40+
)
41+
.expect("Can't launch pluginlab with plugin greet");
42+
43+
session
44+
.exp_string("[Host] Starting REPL host...")
45+
.expect("Didn't see startup message");
46+
session
47+
.exp_string("[Host] Loading plugin:")
48+
.expect("Didn't see plugin loading message");
49+
session
50+
.exp_string("repl(0)>")
51+
.expect("Didn't see REPL prompt");
52+
session
53+
.send_line("weather Paris")
54+
.expect("Failed to send command");
55+
session
56+
.exp_string("Error fetching weather: PermissionDenied: network access to wttr.in is not allowed")
57+
.expect("Didn't get expected error output");
58+
}
59+
60+
#[test]
61+
fn test_without_permission_allow_read() {
62+
let project_root = find_project_root();
63+
println!("Setting current directory to: {:?}", project_root);
64+
std::env::set_current_dir(&project_root).unwrap();
65+
let mut session = spawn(
66+
&format!(
67+
"{} --dir tmp/filesystem",
68+
&build_command(
69+
&["target/wasm32-wasip1/debug/plugin_ls.wasm"],
70+
"repl_logic_guest.wasm"
71+
)
72+
),
73+
Some(TEST_TIMEOUT),
74+
)
75+
.expect("Can't launch pluginlab with plugin greet");
76+
77+
session
78+
.exp_string("[Host] Starting REPL host...")
79+
.expect("Didn't see startup message");
80+
session
81+
.exp_string("[Host] Loading plugin:")
82+
.expect("Didn't see plugin loading message");
83+
session
84+
.exp_string("repl(0)>")
85+
.expect("Didn't see REPL prompt");
86+
session.send_line("ls").expect("Failed to send command");
87+
session
88+
.exp_string("ls: : Operation not permitted")
89+
.expect("Didn't get expected error output");
90+
}
91+
}

crates/pluginlab/tests/e2e_rust_repl_logic.rs

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -245,63 +245,6 @@ mod e2e_rust_repl_logic {
245245
.expect("Didn't get expected echo output for $0 - should be the same as the last non failingcommand");
246246
}
247247

248-
#[test]
249-
fn test_without_permission_allow_network() {
250-
let project_root = find_project_root();
251-
println!("Setting current directory to: {:?}", project_root);
252-
std::env::set_current_dir(&project_root).unwrap();
253-
let mut session = spawn(
254-
&build_command(&["plugin_weather.wasm"], "repl_logic_guest.wasm"),
255-
Some(TEST_TIMEOUT),
256-
)
257-
.expect("Can't launch pluginlab with plugin greet");
258-
259-
session
260-
.exp_string("[Host] Starting REPL host...")
261-
.expect("Didn't see startup message");
262-
session
263-
.exp_string("[Host] Loading plugin:")
264-
.expect("Didn't see plugin loading message");
265-
session
266-
.exp_string("repl(0)>")
267-
.expect("Didn't see REPL prompt");
268-
session
269-
.send_line("weather Paris")
270-
.expect("Failed to send command");
271-
session
272-
.exp_string("Error fetching weather: PermissionDenied: network access to wttr.in is not allowed")
273-
.expect("Didn't get expected error output");
274-
}
275-
276-
#[test]
277-
fn test_without_permission_allow_read() {
278-
let project_root = find_project_root();
279-
println!("Setting current directory to: {:?}", project_root);
280-
std::env::set_current_dir(&project_root).unwrap();
281-
let mut session = spawn(
282-
&format!(
283-
"{} --dir tmp/filesystem",
284-
&build_command(&["plugin_ls.wasm"], "repl_logic_guest.wasm")
285-
),
286-
Some(TEST_TIMEOUT),
287-
)
288-
.expect("Can't launch pluginlab with plugin greet");
289-
290-
session
291-
.exp_string("[Host] Starting REPL host...")
292-
.expect("Didn't see startup message");
293-
session
294-
.exp_string("[Host] Loading plugin:")
295-
.expect("Didn't see plugin loading message");
296-
session
297-
.exp_string("repl(0)>")
298-
.expect("Didn't see REPL prompt");
299-
session.send_line("ls").expect("Failed to send command");
300-
session
301-
.exp_string("ls: : Operation not permitted")
302-
.expect("Didn't get expected error output");
303-
}
304-
305248
#[test]
306249
fn test_list_commands() {
307250
let project_root = find_project_root();

0 commit comments

Comments
 (0)