fix(secrets-cli): shell — contain UnauthorizedAccess, flow-title guard, cancel-path test
This commit is contained in:
+60
@@ -256,6 +256,66 @@ public sealed class InteractiveShellTests : IDisposable
|
||||
Assert.Contains("KEK doctor", console.Output, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Flow_throwing_UnauthorizedAccess_is_contained_and_returns_to_menu()
|
||||
{
|
||||
var flow = new FakeFlow(
|
||||
"Read key file",
|
||||
requiresKek: false,
|
||||
onRun: _ => throw new UnauthorizedAccessException("permission denied"));
|
||||
|
||||
TestConsole console = NewConsole();
|
||||
InteractiveShell shell = NewShell(console, NewRecents(), flow);
|
||||
|
||||
ScriptManualEntry(console, UnsetEnvVarName());
|
||||
SelectIndex(console, 0); // run the throwing flow
|
||||
SelectIndex(console, 2); // loop returned to menu → Quit
|
||||
|
||||
int result = await shell.RunAsync(CancellationToken.None);
|
||||
|
||||
Assert.Equal(0, result);
|
||||
Assert.Equal(1, flow.InvocationCount);
|
||||
Assert.Contains("KEK doctor", console.Output, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_rejects_duplicate_flow_titles()
|
||||
{
|
||||
var first = new FakeFlow("Same title");
|
||||
var second = new FakeFlow("Same title");
|
||||
|
||||
Assert.Throws<ArgumentException>(() => NewShell(NewConsole(), NewRecents(), first, second));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Constructor_rejects_flow_title_colliding_with_a_builtin()
|
||||
{
|
||||
var reserved = new FakeFlow("Quit");
|
||||
|
||||
Assert.Throws<ArgumentException>(() => NewShell(NewConsole(), NewRecents(), reserved));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Cancelled_token_exits_menu_loop_cleanly_with_zero()
|
||||
{
|
||||
using var cts = new CancellationTokenSource();
|
||||
// The flow cancels the shell's own token mid-action; the menu loop's top-of-loop cancellation
|
||||
// check must then exit 0 without prompting for (unscripted) further input or throwing. This is
|
||||
// the testable stand-in for a menu-level Ctrl-C, which TestConsole cannot inject into a prompt.
|
||||
var flow = new FakeFlow("Cancel the shell", requiresKek: false, onRun: _ => cts.Cancel());
|
||||
|
||||
TestConsole console = NewConsole();
|
||||
InteractiveShell shell = NewShell(console, NewRecents(), flow);
|
||||
|
||||
ScriptManualEntry(console, UnsetEnvVarName());
|
||||
SelectIndex(console, 0); // run the flow, which cancels the token — no more input is scripted
|
||||
|
||||
int result = await shell.RunAsync(cts.Token);
|
||||
|
||||
Assert.Equal(0, result);
|
||||
Assert.Equal(1, flow.InvocationCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Switch_target_reopens_picker()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user