Skip to content

Commit 5b53c58

Browse files
committed
refactor: streamline CLI integration tests and enhance command execution
1 parent 4a594bb commit 5b53c58

4 files changed

Lines changed: 56 additions & 57 deletions

File tree

cli/integration-tests/command_contract.rs

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,63 @@
11
mod support;
22

3-
use std::fs;
3+
use serde_json::Value;
44

5-
use support::{current_package_version, not_implemented_message, run_tnmsc, TestDir};
5+
use support::{
6+
current_package_version, install_packaged_cli_container, not_implemented_message, tnmsc_command,
7+
};
68

79
#[test]
8-
fn help_lists_supported_commands() {
9-
let result = run_tnmsc(&["help"], &support::workspace_root());
10-
result.assert_success("tnmsc help");
10+
fn packaged_cli_contract_runs_inside_testcontainer() {
11+
if !support::is_linux_x64_host() {
12+
eprintln!("skipping packaged contract smoke on unsupported host");
13+
return;
14+
}
15+
16+
let container = install_packaged_cli_container();
1117

18+
let help = container.exec(&tnmsc_command(&["help"]));
19+
help.assert_success("global tnmsc help");
1220
for expected in ["install", "dry-run", "clean", "plugins", "version", "help"] {
1321
assert!(
14-
result.stdout.contains(expected),
22+
help.stdout.contains(expected),
1523
"help output should include `{expected}`.\nstdout:\n{}",
16-
result.stdout
24+
help.stdout
1725
);
1826
}
19-
}
20-
21-
#[test]
22-
fn version_matches_workspace_version() {
23-
let result = run_tnmsc(&["version"], &support::workspace_root());
24-
result.assert_success("tnmsc version");
25-
26-
assert_eq!(result.stdout.trim(), current_package_version());
27-
}
2827

29-
#[test]
30-
fn plugins_lists_core_output_adaptors() {
31-
let result = run_tnmsc(&["plugins"], &support::workspace_root());
32-
result.assert_success("tnmsc plugins");
28+
let version = container.exec(&tnmsc_command(&["version"]));
29+
version.assert_success("global tnmsc version");
30+
assert_eq!(version.stdout.trim(), current_package_version());
3331

32+
let plugins = container.exec(&tnmsc_command(&["plugins"]));
33+
plugins.assert_success("global tnmsc plugins");
3434
for expected in [
3535
"CodexCLIOutputAdaptor",
3636
"ClaudeCodeCLIOutputAdaptor",
3737
"TraeOutputAdaptor",
3838
"OpencodeCLIOutputAdaptor",
3939
] {
4040
assert!(
41-
result.stdout.contains(expected),
41+
plugins.stdout.contains(expected),
4242
"plugins output should include `{expected}`.\nstdout:\n{}",
43-
result.stdout
43+
plugins.stdout
4444
);
4545
}
46-
}
47-
48-
#[test]
49-
fn schema_output_writes_valid_json_in_integration_sandbox() {
50-
let temp_dir = TestDir::new("tnmsc-schema-contract");
51-
let schema_path = temp_dir.path().join("tnmsc.schema.json");
52-
let schema_path_arg = schema_path.to_string_lossy().into_owned();
5346

54-
let result = run_tnmsc(
55-
&["schema", "--output", &schema_path_arg],
56-
&support::workspace_root(),
57-
);
58-
result.assert_success("tnmsc schema --output");
47+
let schema_output_path = "/tmp/tnmsc.schema.json";
48+
let schema = container.exec(&tnmsc_command(&["schema", "--output", schema_output_path]));
49+
schema.assert_success("global tnmsc schema --output");
5950

60-
let content = fs::read_to_string(&schema_path)
61-
.unwrap_or_else(|error| panic!("failed to read {}: {error}", schema_path.display()));
62-
let parsed: serde_json::Value = serde_json::from_str(&content)
51+
let schema_file = container.exec(&format!("cat {}", support::quote_shell(schema_output_path)));
52+
schema_file.assert_success("read schema output");
53+
let parsed: Value = serde_json::from_str(&schema_file.stdout)
6354
.unwrap_or_else(|error| panic!("schema output should be valid JSON: {error}"));
64-
6555
let object = parsed
6656
.as_object()
6757
.expect("schema output should be a top-level JSON object");
68-
6958
assert!(object.contains_key("$schema"));
7059
assert!(object.contains_key("properties"));
71-
}
7260

73-
#[test]
74-
fn install_like_commands_fail_with_not_implemented_contract() {
7561
for (args, command_name, display) in [
7662
(&[][..], "install", "tnmsc"),
7763
(&["install"][..], "install", "tnmsc install"),
@@ -83,7 +69,7 @@ fn install_like_commands_fail_with_not_implemented_contract() {
8369
"tnmsc clean --dry-run",
8470
),
8571
] {
86-
let result = run_tnmsc(args, &support::workspace_root());
72+
let result = container.exec(&tnmsc_command(args));
8773
result.assert_failure(display);
8874

8975
let expected = not_implemented_message(command_name);

cli/integration-tests/packaging_smoke.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::fs;
55
#[cfg(unix)]
66
use std::os::unix::fs::PermissionsExt;
77

8-
use support::{pack_cli_artifacts, quote_shell, TestContainer};
8+
use support::install_packaged_cli_container;
99

1010
#[test]
1111
fn packaging_smoke_covers_release_binary_and_global_install() {
@@ -48,16 +48,7 @@ fn packaging_smoke_covers_release_binary_and_global_install() {
4848
);
4949
}
5050

51-
let artifacts = pack_cli_artifacts();
52-
let container = TestContainer::start(&artifacts);
53-
54-
let install_command = format!(
55-
"corepack enable && corepack prepare pnpm@{} --activate && pnpm add -g {} {}",
56-
quote_shell(support::pnpm_version()),
57-
quote_shell("/artifacts/cli.tgz"),
58-
quote_shell("/artifacts/linux-x64-gnu.tgz")
59-
);
60-
container.exec_success(&install_command);
51+
let container = install_packaged_cli_container();
6152

6253
let help = container.exec("tnmsc help");
6354
help.assert_success("global tnmsc help");

cli/integration-tests/support/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,28 @@ pub fn pack_cli_artifacts() -> PackedArtifacts {
329329
}
330330
}
331331

332+
pub fn install_packaged_cli_container() -> TestContainer {
333+
let artifacts = pack_cli_artifacts();
334+
let container = TestContainer::start(&artifacts);
335+
let install_command = format!(
336+
"corepack enable && corepack prepare pnpm@{} --activate && pnpm add -g {} {}",
337+
quote_shell(pnpm_version()),
338+
quote_shell("/artifacts/cli.tgz"),
339+
quote_shell("/artifacts/linux-x64-gnu.tgz")
340+
);
341+
container.exec_success(&install_command);
342+
container
343+
}
344+
345+
pub fn tnmsc_command(args: &[&str]) -> String {
346+
let mut command = String::from("tnmsc");
347+
for arg in args {
348+
command.push(' ');
349+
command.push_str(&quote_shell(arg));
350+
}
351+
command
352+
}
353+
332354
pub fn quote_shell(value: &str) -> String {
333355
format!("'{}'", value.replace('\'', "'\"'\"'"))
334356
}

mcp/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use std::io::{BufRead, Write};
22

3-
use serde_json::{json, Value};
3+
use serde_json::{Value, json};
44
use tnmsc::{
5-
get_prompt, list_prompts, upsert_prompt_source, write_prompt_artifacts, ListPromptsOptions,
6-
PromptServiceOptions, UpsertPromptSourceInput, WritePromptArtifactsInput,
5+
ListPromptsOptions, PromptServiceOptions, UpsertPromptSourceInput, WritePromptArtifactsInput,
6+
get_prompt, list_prompts, upsert_prompt_source, write_prompt_artifacts,
77
};
88

99
const SERVER_NAME: &str = "@truenine/memory-sync-mcp";

0 commit comments

Comments
 (0)