Skip to content

Commit 5308795

Browse files
committed
feat(repl-logic): change output of list-commands + tests
1 parent e3a0b02 commit 5308795

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

crates/pluginlab/tests/e2e_test.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,15 @@ mod e2e_test {
410410
}
411411

412412
#[test]
413-
fn test_man_command() {
413+
fn test_list_commands() {
414414
let project_root = find_project_root();
415415
println!("Setting current directory to: {:?}", project_root);
416416
std::env::set_current_dir(&project_root).unwrap();
417417
let mut session = spawn(
418-
&build_command(&["plugin_greet.wasm"], "repl_logic_guest.wasm"),
418+
&build_command(
419+
&["plugin_echo.wasm", "plugin_greet.wasm", "plugin_cat.wasm"],
420+
"repl_logic_guest.wasm",
421+
),
419422
Some(TEST_TIMEOUT),
420423
)
421424
.expect("Can't launch pluginlab with plugin greet");
@@ -426,15 +429,14 @@ mod e2e_test {
426429
session
427430
.exp_string("[Host] Loading plugin:")
428431
.expect("Didn't see plugin loading message");
429-
session.send_line("man").expect("Failed to send command");
430432
session
431-
.exp_string(" man - Show the manual for a command")
432-
.expect("Didn't see man command name");
433+
.exp_string("repl(0)>")
434+
.expect("Didn't see REPL prompt");
433435
session
434-
.send_line("man man")
436+
.send_line("list-commands")
435437
.expect("Failed to send command");
436438
session
437-
.exp_string(" man - Show the manual for a command")
438-
.expect("Didn't see man command name");
439+
.exp_string("cat\tplugin\r\necho\tplugin\r\nexport\treserved\r\ngreet\tplugin\r\nhelp\treserved\r\nlist-commands\treserved\r\nman\treserved\r\n")
440+
.expect("Didn't get expected list of commands");
439441
}
440442
}

crates/repl-logic-guest/src/reserved.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,21 @@ EXAMPLES
114114
run: Some(|_payload| {
115115
let plugins = host_state::get_plugins_names();
116116
let reserved_commands = get_reserved_commands();
117+
let mut commands: Vec<(String, String)> = Vec::new();
118+
for plugin in plugins {
119+
commands.push(("plugin".to_string(), plugin.to_string()));
120+
}
121+
for reserved_command in reserved_commands {
122+
commands.push(("reserved".to_string(), reserved_command.to_string()));
123+
}
124+
commands.sort_by(|a, b| a.1.cmp(&b.1));
125+
let mut output = String::new();
126+
for (category, command) in commands {
127+
output.push_str(&format!("{}\t{}\n", command, category));
128+
}
117129
transport::PluginResponse {
118130
status: transport::ReplStatus::Success,
119-
stdout: Some(format!(
120-
"Plugins: {} - Reserved commands: {}",
121-
plugins.join(", "),
122-
reserved_commands.join(", ")
123-
)),
131+
stdout: Some(output),
124132
stderr: None,
125133
}
126134
}),

packages/web-host/tests/repl-logic.spec.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ test("man for reserved commands", async ({ page }) => {
5656
"list-commands",
5757
"list-commands - List the plugins loaded in the host and the reserved commands (not overridable by plugins) included in the REPL logic.",
5858
],
59+
["man", "man - Show the manual for a command"],
5960
];
6061
await page.goto("/#repl");
6162
for (const [command, partialManpage] of reservedCommands) {
@@ -64,3 +65,20 @@ test("man for reserved commands", async ({ page }) => {
6465
await expect(stdout).toContainText(partialManpage);
6566
}
6667
});
68+
69+
test("list-commands", async ({ page }) => {
70+
await page.goto("/#repl");
71+
await fillAndSubmitCommand(page, "list-commands");
72+
const stdout = await getLastStd(page, "stdout");
73+
await expect(stdout).toContainText(
74+
`cat plugin
75+
echo plugin
76+
export reserved
77+
greet plugin
78+
help reserved
79+
list-commands reserved
80+
ls plugin
81+
man reserved
82+
weather plugin`,
83+
);
84+
});

0 commit comments

Comments
 (0)