|
| 1 | +// SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +//! Rendered help and command-shape checks for the `openshell` binary. |
| 5 | +
|
| 6 | +mod common; |
| 7 | + |
| 8 | +use common::run_isolated; |
| 9 | + |
| 10 | +#[test] |
| 11 | +fn root_help_shows_top_level_commands() { |
| 12 | + let output = run_isolated(&["--help"]); |
| 13 | + assert_eq!(output.code, 0, "openshell --help:\n{}", output.combined); |
| 14 | + |
| 15 | + for command in ["gateway", "status", "sandbox", "forward", "logs", "policy"] { |
| 16 | + assert!( |
| 17 | + output.combined.contains(command), |
| 18 | + "expected '{command}' in openshell --help:\n{}", |
| 19 | + output.combined |
| 20 | + ); |
| 21 | + } |
| 22 | +} |
| 23 | + |
| 24 | +#[test] |
| 25 | +fn gateway_help_shows_registration_commands_and_omits_lifecycle_commands() { |
| 26 | + let output = run_isolated(&["gateway", "--help"]); |
| 27 | + assert_eq!(output.code, 0, "gateway --help:\n{}", output.combined); |
| 28 | + |
| 29 | + for command in ["add", "remove", "login", "logout", "select", "info", "list"] { |
| 30 | + assert!( |
| 31 | + output.combined.contains(command), |
| 32 | + "expected '{command}' in gateway --help:\n{}", |
| 33 | + output.combined |
| 34 | + ); |
| 35 | + } |
| 36 | + for removed in ["start", "stop", "destroy"] { |
| 37 | + assert!( |
| 38 | + !output.combined.contains(removed), |
| 39 | + "unexpected removed command '{removed}' in gateway --help:\n{}", |
| 40 | + output.combined |
| 41 | + ); |
| 42 | + } |
| 43 | +} |
| 44 | + |
| 45 | +#[test] |
| 46 | +fn sandbox_help_shows_transfer_and_lifecycle_commands() { |
| 47 | + let output = run_isolated(&["sandbox", "--help"]); |
| 48 | + assert_eq!(output.code, 0, "sandbox --help:\n{}", output.combined); |
| 49 | + |
| 50 | + for command in [ |
| 51 | + "upload", "download", "create", "get", "list", "delete", "connect", |
| 52 | + ] { |
| 53 | + assert!( |
| 54 | + output.combined.contains(command), |
| 55 | + "expected '{command}' in sandbox --help:\n{}", |
| 56 | + output.combined |
| 57 | + ); |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +#[test] |
| 62 | +fn sandbox_create_help_shows_creation_flags() { |
| 63 | + let output = run_isolated(&["sandbox", "create", "--help"]); |
| 64 | + assert_eq!( |
| 65 | + output.code, 0, |
| 66 | + "sandbox create --help:\n{}", |
| 67 | + output.combined |
| 68 | + ); |
| 69 | + |
| 70 | + for flag in [ |
| 71 | + "--gpu", |
| 72 | + "--upload", |
| 73 | + "--no-git-ignore", |
| 74 | + "--editor", |
| 75 | + "--auto-providers", |
| 76 | + "--no-auto-providers", |
| 77 | + ] { |
| 78 | + assert!( |
| 79 | + output.combined.contains(flag), |
| 80 | + "expected '{flag}' in sandbox create --help:\n{}", |
| 81 | + output.combined |
| 82 | + ); |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +#[test] |
| 87 | +fn sandbox_connect_help_shows_editor_flag() { |
| 88 | + let output = run_isolated(&["sandbox", "connect", "--help"]); |
| 89 | + assert_eq!( |
| 90 | + output.code, 0, |
| 91 | + "sandbox connect --help:\n{}", |
| 92 | + output.combined |
| 93 | + ); |
| 94 | + assert!(output.combined.contains("--editor"), "{}", output.combined); |
| 95 | +} |
| 96 | + |
| 97 | +#[test] |
| 98 | +fn gateway_add_help_shows_endpoint_and_gateway_type_flags() { |
| 99 | + let output = run_isolated(&["gateway", "add", "--help"]); |
| 100 | + assert_eq!(output.code, 0, "gateway add --help:\n{}", output.combined); |
| 101 | + |
| 102 | + for expected in ["--name", "--remote", "--local"] { |
| 103 | + assert!( |
| 104 | + output.combined.contains(expected), |
| 105 | + "expected '{expected}' in gateway add --help:\n{}", |
| 106 | + output.combined |
| 107 | + ); |
| 108 | + } |
| 109 | + assert!( |
| 110 | + output.combined.contains("endpoint") || output.combined.contains("<ENDPOINT>"), |
| 111 | + "expected endpoint argument in gateway add --help:\n{}", |
| 112 | + output.combined |
| 113 | + ); |
| 114 | +} |
| 115 | + |
| 116 | +#[test] |
| 117 | +fn gateway_login_help_describes_authentication() { |
| 118 | + let output = run_isolated(&["gateway", "login", "--help"]); |
| 119 | + assert_eq!(output.code, 0, "gateway login --help:\n{}", output.combined); |
| 120 | + |
| 121 | + let help = output.combined.to_lowercase(); |
| 122 | + assert!( |
| 123 | + ["authenticat", "cloudflare", "login", "browser"] |
| 124 | + .iter() |
| 125 | + .any(|term| help.contains(term)), |
| 126 | + "expected auth-related gateway login help:\n{}", |
| 127 | + output.combined |
| 128 | + ); |
| 129 | +} |
| 130 | + |
| 131 | +#[test] |
| 132 | +fn removed_gateway_lifecycle_subcommands_fail_to_parse() { |
| 133 | + for command in ["start", "stop", "destroy"] { |
| 134 | + let output = run_isolated(&["gateway", command, "--help"]); |
| 135 | + assert_ne!( |
| 136 | + output.code, 0, |
| 137 | + "gateway {command} should fail after lifecycle command removal" |
| 138 | + ); |
| 139 | + assert!( |
| 140 | + output.combined.contains("unrecognized subcommand") |
| 141 | + || output.combined.contains("error:"), |
| 142 | + "expected parser error for gateway {command}:\n{}", |
| 143 | + output.combined |
| 144 | + ); |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +#[test] |
| 149 | +fn gateway_add_rejects_conflicting_type_flags() { |
| 150 | + let conflicting = run_isolated(&[ |
| 151 | + "gateway", |
| 152 | + "add", |
| 153 | + "https://example.com", |
| 154 | + "--remote", |
| 155 | + "user@host", |
| 156 | + "--local", |
| 157 | + ]); |
| 158 | + assert_ne!( |
| 159 | + conflicting.code, 0, |
| 160 | + "--remote and --local should conflict:\n{}", |
| 161 | + conflicting.combined |
| 162 | + ); |
| 163 | +} |
| 164 | + |
| 165 | +#[test] |
| 166 | +fn gateway_add_rejects_removed_ssh_key_flag() { |
| 167 | + let removed = run_isolated(&[ |
| 168 | + "gateway", |
| 169 | + "add", |
| 170 | + "https://example.com", |
| 171 | + "--ssh-key", |
| 172 | + "/tmp/fake-key", |
| 173 | + ]); |
| 174 | + assert_ne!( |
| 175 | + removed.code, 0, |
| 176 | + "removed --ssh-key flag should fail:\n{}", |
| 177 | + removed.combined |
| 178 | + ); |
| 179 | +} |
0 commit comments