fix(headless): N3 reject --console for validate mode instead of ignoring it

validate never starts a session, so a silently-ignored --console read as
"it worked" to an operator who typo'd their command. Reject with a clear
message instead.

New test ValidateModeRejectsTheConsoleFlag was shown to fail first
(mutation: the guard absent — HeadlessCommandLine.Parse returned normally
for `validate --config bot.json --console` instead of throwing).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-09-07 07:50:05 +02:00
parent 215442dc1d
commit c01ae15825
2 changed files with 21 additions and 0 deletions

View file

@ -95,6 +95,14 @@ internal sealed record HeadlessCommandLine(
throw new HeadlessCommandLineException(
"Direct credentials are valid only for run mode.");
}
// N3: reject rather than silently ignore --console for validate mode
// — validate never starts a session, so there is nothing for the
// console to attach to.
if (console && command != "run")
{
throw new HeadlessCommandLineException(
"--console is valid only for run mode.");
}
return new HeadlessCommandLine(
command,

View file

@ -69,6 +69,19 @@ public sealed class HeadlessConsoleTests
Assert.False(parsed.ConsoleEnabled);
}
/// <summary>
/// N3: validate mode rejects <c>--console</c> outright (rather than
/// silently ignoring it) — validate never starts a session, so there is
/// nothing for the console to attach to.
/// </summary>
[Fact]
public void ValidateModeRejectsTheConsoleFlag()
{
Assert.Throws<HeadlessCommandLineException>(() =>
HeadlessCommandLine.Parse(
["validate", "--config", "bot.json", "--console"]));
}
// ── HeadlessConsoleInputReader: reader-thread/ordering ───────────────
/// <summary>