|
| 1 | +mod support; |
| 2 | + |
| 3 | +use std::fs; |
| 4 | + |
| 5 | +use support::{current_package_version, not_implemented_message, run_tnmsc, TestDir}; |
| 6 | + |
| 7 | +#[test] |
| 8 | +fn help_lists_supported_commands() { |
| 9 | + let result = run_tnmsc(&["help"], &support::workspace_root()); |
| 10 | + result.assert_success("tnmsc help"); |
| 11 | + |
| 12 | + for expected in ["install", "dry-run", "clean", "plugins", "version", "help"] { |
| 13 | + assert!( |
| 14 | + result.stdout.contains(expected), |
| 15 | + "help output should include `{expected}`.\nstdout:\n{}", |
| 16 | + result.stdout |
| 17 | + ); |
| 18 | + } |
| 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 | +} |
| 28 | + |
| 29 | +#[test] |
| 30 | +fn plugins_lists_core_output_adaptors() { |
| 31 | + let result = run_tnmsc(&["plugins"], &support::workspace_root()); |
| 32 | + result.assert_success("tnmsc plugins"); |
| 33 | + |
| 34 | + for expected in [ |
| 35 | + "CodexCLIOutputAdaptor", |
| 36 | + "ClaudeCodeCLIOutputAdaptor", |
| 37 | + "TraeOutputAdaptor", |
| 38 | + "OpencodeCLIOutputAdaptor", |
| 39 | + ] { |
| 40 | + assert!( |
| 41 | + result.stdout.contains(expected), |
| 42 | + "plugins output should include `{expected}`.\nstdout:\n{}", |
| 43 | + result.stdout |
| 44 | + ); |
| 45 | + } |
| 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(); |
| 53 | + |
| 54 | + let result = run_tnmsc( |
| 55 | + &["schema", "--output", &schema_path_arg], |
| 56 | + &support::workspace_root(), |
| 57 | + ); |
| 58 | + result.assert_success("tnmsc schema --output"); |
| 59 | + |
| 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) |
| 63 | + .unwrap_or_else(|error| panic!("schema output should be valid JSON: {error}")); |
| 64 | + |
| 65 | + let object = parsed |
| 66 | + .as_object() |
| 67 | + .expect("schema output should be a top-level JSON object"); |
| 68 | + |
| 69 | + assert!(object.contains_key("$schema")); |
| 70 | + assert!(object.contains_key("properties")); |
| 71 | +} |
| 72 | + |
| 73 | +#[test] |
| 74 | +fn install_like_commands_fail_with_not_implemented_contract() { |
| 75 | + for (args, command_name, display) in [ |
| 76 | + (&[][..], "install", "tnmsc"), |
| 77 | + (&["install"][..], "install", "tnmsc install"), |
| 78 | + (&["dry-run"][..], "dry-run", "tnmsc dry-run"), |
| 79 | + (&["clean"][..], "clean", "tnmsc clean"), |
| 80 | + ( |
| 81 | + &["clean", "--dry-run"][..], |
| 82 | + "clean", |
| 83 | + "tnmsc clean --dry-run", |
| 84 | + ), |
| 85 | + ] { |
| 86 | + let result = run_tnmsc(args, &support::workspace_root()); |
| 87 | + result.assert_failure(display); |
| 88 | + |
| 89 | + let expected = not_implemented_message(command_name); |
| 90 | + assert!( |
| 91 | + result.stderr.contains(&expected), |
| 92 | + "{display} stderr should contain the not-implemented contract.\nexpected:\n{expected}\nactual:\n{}", |
| 93 | + result.stderr |
| 94 | + ); |
| 95 | + } |
| 96 | +} |
0 commit comments