Retail treats / and @ interchangeably for commands, but two client-side
layers broke the / spelling for server commands:
- ChatCommandRouter refused ANY unknown /verb with a local "Unknown
command" guess — so /tele, /ci, /acehelp never reached ACE even
though ACE supports them. The guard is gone; the server is now the
single authority on what's a valid command (ACE replies "Unknown
command: x" itself).
- ChatInputParser passed unknown /verbs through as literal speech.
ACE's GameActionTalk only intercepts the @ form on the wire (the /
acceptance in CommandManager is the server CONSOLE path), so the
parser now rewrites unknown /xyz -> @xyz.
Both command pass-throughs (@ and rewritten /) now also force the Say
channel: GameActionTalk (0x0015) is the only wire action ACE parses
commands on — previously a command typed with a chat channel active
would broadcast as channel speech.
Phase J Tier 4 ("/-text must never broadcast as speech") still holds:
letter-verbed input goes out as an @command (never speech), and
command-shaped-but-verbless input ("/", "//shrug") is refused locally
by a narrow router guard.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
334 lines
11 KiB
C#
334 lines
11 KiB
C#
using AcDream.Core.Chat;
|
|
using AcDream.UI.Abstractions.Panels.Chat;
|
|
|
|
namespace AcDream.UI.Abstractions.Tests.Panels.Chat;
|
|
|
|
/// <summary>
|
|
/// Phase I.4: when the user submits text via the chat input field, the
|
|
/// panel must publish a <see cref="SendChatCmd"/> to the command bus.
|
|
/// We exercise the full Render path with the <see cref="FakePanelRenderer"/>
|
|
/// pre-loading a "submitted" string and a recording bus capturing the
|
|
/// resulting command.
|
|
/// </summary>
|
|
public sealed class ChatPanelInputTests
|
|
{
|
|
private sealed class RecordingBus : ICommandBus
|
|
{
|
|
public List<object> Published { get; } = new();
|
|
public void Publish<T>(T command) where T : notnull => Published.Add(command);
|
|
}
|
|
|
|
[Fact]
|
|
public void Submit_HelpCommand_RendersLocalHelpAndDoesNotPublish()
|
|
{
|
|
// Phase J follow-up: client-side commands (/help, /?, /h) are
|
|
// intercepted before the parser. They render a local cheat-sheet
|
|
// via ChatLog.OnSystemMessage and do NOT round-trip the server
|
|
// — that's what prevented the "Unknown command: help" duplicate
|
|
// ACE was firing back.
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = "/help",
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
Assert.Empty(bus.Published);
|
|
var entry = Assert.Single(log.Snapshot());
|
|
Assert.Equal(ChatKind.System, entry.Kind);
|
|
// Help text mentions / and @ equivalence and points at @acehelp
|
|
// for the server's full command list.
|
|
Assert.Contains("/tell", entry.Text);
|
|
Assert.Contains("@acehelp", entry.Text);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("/?")]
|
|
[InlineData("/h")]
|
|
[InlineData("/HELP")]
|
|
public void Submit_HelpAliases_AlsoRenderLocalHelp(string raw)
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = raw,
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
Assert.Empty(bus.Published);
|
|
Assert.Single(log.Snapshot());
|
|
}
|
|
|
|
[Fact]
|
|
public void Submit_FramerateCommand_PrintsFpsAndDoesNotPublish()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log) { FpsProvider = () => 60f };
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = "/framerate",
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
Assert.Empty(bus.Published);
|
|
var entry = Assert.Single(log.Snapshot());
|
|
Assert.Contains("60.0 FPS", entry.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void Submit_LocCommand_PrintsPositionAndDoesNotPublish()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log)
|
|
{
|
|
PositionProvider = () => new System.Numerics.Vector3(10f, 20f, 30f),
|
|
};
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = "@loc",
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
Assert.Empty(bus.Published);
|
|
var entry = Assert.Single(log.Snapshot());
|
|
Assert.Contains("(10.0, 20.0, 30.0)", entry.Text);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("/foo", "@foo")]
|
|
[InlineData("/ls", "@ls")]
|
|
[InlineData("/mp /tools/script.py", "@mp /tools/script.py")]
|
|
[InlineData("/genio public", "@genio public")]
|
|
public void Submit_UnknownSlashCommand_RoutesToServerAsAtCommand(string raw, string expectedText)
|
|
{
|
|
// Phase J Tier 4 held: /-prefixed text is still NEVER broadcast
|
|
// as plain speech. Retail treats / and @ as equivalent command
|
|
// prefixes, so unknown verbs now go to the SERVER as @commands
|
|
// (ACE's GameActionTalk intercepts @ on the Say action and
|
|
// answers "Unknown command: x" itself) instead of a local guess.
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = raw,
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
var sendCmd = Assert.IsType<SendChatCmd>(Assert.Single(bus.Published));
|
|
Assert.Equal(ChatChannelKind.Say, sendCmd.Channel);
|
|
Assert.Equal(expectedText, sendCmd.Text);
|
|
Assert.Empty(log.Snapshot()); // no local "Unknown command" guess
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData("/")]
|
|
[InlineData("//shrug")]
|
|
public void Submit_CommandShapedWithoutVerb_ShowsUnknownAndDoesNotPublish(string raw)
|
|
{
|
|
// Command-shaped but no letter verb: refused locally — this is
|
|
// the remaining Tier-4 guard (never broadcast /-text as speech,
|
|
// and don't put junk @-rewrites on the wire either).
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = raw,
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
Assert.Empty(bus.Published);
|
|
var entry = Assert.Single(log.Snapshot());
|
|
Assert.Equal(ChatKind.System, entry.Kind);
|
|
Assert.Contains("Unknown command", entry.Text);
|
|
Assert.Contains("/help", entry.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void Submit_AtAcehelp_PassesThroughToSayWithAtIntact()
|
|
{
|
|
// Unknown @-verb falls through to the default channel with the
|
|
// literal "@acehelp" text intact so ACE's CommandManager
|
|
// intercepts it server-side. We DO publish a SendChatCmd here —
|
|
// the publish is what carries the message to the server.
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = "@acehelp",
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
var sendCmd = Assert.IsType<SendChatCmd>(Assert.Single(bus.Published));
|
|
Assert.Equal(ChatChannelKind.Say, sendCmd.Channel);
|
|
Assert.Equal("@acehelp", sendCmd.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void Submit_ClearCommand_DrainsLog_AndDoesNotPublish()
|
|
{
|
|
var log = new ChatLog();
|
|
log.OnSystemMessage("seed line", chatType: 0);
|
|
var vm = new ChatVM(log);
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = "/clear",
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
Assert.Empty(bus.Published);
|
|
Assert.Empty(log.Snapshot());
|
|
}
|
|
|
|
[Fact]
|
|
public void Submit_PlainText_PublishesSayCommand()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = "hello world",
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
var cmd = Assert.Single(bus.Published);
|
|
var sendCmd = Assert.IsType<SendChatCmd>(cmd);
|
|
Assert.Equal(ChatChannelKind.Say, sendCmd.Channel);
|
|
Assert.Null(sendCmd.TargetName);
|
|
Assert.Equal("hello world", sendCmd.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void Submit_TellSlashCommand_PublishesTellCommand()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = "/t Bestie ping",
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
var sendCmd = Assert.IsType<SendChatCmd>(Assert.Single(bus.Published));
|
|
Assert.Equal(ChatChannelKind.Tell, sendCmd.Channel);
|
|
Assert.Equal("Bestie", sendCmd.TargetName);
|
|
Assert.Equal("ping", sendCmd.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void Submit_ReplySlashCommand_UsesLastIncomingTellSender()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
log.OnTellReceived("Bestie", "ping", senderGuid: 0x5000_00AAu);
|
|
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = "/r back at you",
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
var sendCmd = Assert.IsType<SendChatCmd>(Assert.Single(bus.Published));
|
|
Assert.Equal(ChatChannelKind.Tell, sendCmd.Channel);
|
|
Assert.Equal("Bestie", sendCmd.TargetName);
|
|
Assert.Equal("back at you", sendCmd.Text);
|
|
}
|
|
|
|
[Fact]
|
|
public void Submit_EmptyOrWhitespace_PublishesNothing()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = " ",
|
|
InputTextSubmitNextBufferAfter = "",
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
Assert.Empty(bus.Published);
|
|
}
|
|
|
|
[Fact]
|
|
public void NoSubmit_PublishesNothing()
|
|
{
|
|
// Most frames: user is typing or idle; submitted == null.
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = null,
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
Assert.Empty(bus.Published);
|
|
}
|
|
|
|
[Fact]
|
|
public void Render_AlwaysCallsInputTextSubmit_ToShowTheField()
|
|
{
|
|
var log = new ChatLog();
|
|
var vm = new ChatVM(log);
|
|
var panel = new ChatPanel(vm);
|
|
var bus = new RecordingBus();
|
|
var renderer = new FakePanelRenderer
|
|
{
|
|
InputTextSubmitNextSubmitted = null,
|
|
};
|
|
|
|
panel.Render(new PanelContext(0.016f, bus), renderer);
|
|
|
|
Assert.Contains(renderer.Calls, c => c.Method == "InputTextSubmit");
|
|
}
|
|
}
|