feat(chat): route retail lifestone commands

Separate retail client actions, ACE server commands, and ordinary chat at the shared router. Port lifestone/lif/ls from the named retail registry through a typed App controller to game action 0x0063, keep unknown verbs on ACE Talk, and cover both UI backends plus exact outbound bytes.

Co-Authored-By: Codex <codex@openai.com>
This commit is contained in:
Erik 2026-07-13 11:43:19 +02:00
parent 5090aa7217
commit 5a45a7ac7f
19 changed files with 604 additions and 78 deletions

View file

@ -0,0 +1,28 @@
using AcDream.App.UI;
using AcDream.UI.Abstractions;
namespace AcDream.App.Tests.UI;
public sealed class ClientCommandControllerTests
{
[Fact]
public void LifestoneRecall_ExecutesSuppliedSessionActionOnce()
{
int recalls = 0;
var controller = new ClientCommandController(() => recalls++);
controller.Execute(new ExecuteClientCommandCmd(
ClientCommandId.LifestoneRecall, Arguments: string.Empty));
Assert.Equal(1, recalls);
}
[Fact]
public void UnknownCommandId_FailsAtApplicationBoundary()
{
var controller = new ClientCommandController(() => { });
var command = new ExecuteClientCommandCmd((ClientCommandId)999, string.Empty);
Assert.Throws<ArgumentOutOfRangeException>(() => controller.Execute(command));
}
}

View file

@ -198,6 +198,21 @@ public class ChatWindowControllerTests
Assert.Equal("hello world", cmd.Text);
}
[Fact]
public void Bind_LifestoneSubmit_PublishesTypedClientCommand()
{
var (rootInfo, layout, vm) = BuildTestTree();
var bus = new CaptureBus();
var ctrl = ChatWindowController.Bind(rootInfo, layout, vm, () => bus, null, null, NoTex);
Assert.NotNull(ctrl);
ctrl!.Input.OnSubmit!.Invoke("/ls");
var command = Assert.IsType<ExecuteClientCommandCmd>(Assert.Single(bus.Published));
Assert.Equal(ClientCommandId.LifestoneRecall, command.Command);
}
// ── Test 5: Channel change updates the channel used by subsequent submits ─
[Fact]

View file

@ -76,4 +76,17 @@ public sealed class WorldSessionChatTests
using var session = NewSession();
Assert.Throws<ArgumentNullException>(() => session.SendTalk(null!));
}
[Fact]
public void SendTeleportToLifestone_EmitsRetailGameAction()
{
using var session = NewSession();
byte[]? captured = null;
session.GameActionCapture = body => captured = body;
session.SendTeleportToLifestone();
Assert.NotNull(captured);
Assert.Equal(InteractRequests.BuildTeleToLifestone(1), captured);
}
}

View file

@ -9,11 +9,10 @@ public class ChatCommandRouterTests
{
private sealed class CaptureBus : ICommandBus
{
public SendChatCmd? Last;
public List<object> Published { get; } = new();
public void Publish<T>(T command) where T : notnull
{
if (command is SendChatCmd c) Last = c;
}
=> Published.Add(command);
}
private static (ChatVM vm, ChatLog log, CaptureBus bus) Fixture()
@ -28,10 +27,11 @@ public class ChatCommandRouterTests
{
var (vm, _, bus) = Fixture();
var outcome = ChatCommandRouter.Submit("hello there", vm, bus, ChatChannelKind.Say);
Assert.Equal(SubmitOutcome.Sent, outcome);
Assert.NotNull(bus.Last);
Assert.Equal(ChatChannelKind.Say, bus.Last!.Channel);
Assert.Equal("hello there", bus.Last.Text);
var command = Assert.IsType<SendChatCmd>(Assert.Single(bus.Published));
Assert.Equal(ChatChannelKind.Say, command.Channel);
Assert.Equal("hello there", command.Text);
}
[Fact]
@ -39,7 +39,9 @@ public class ChatCommandRouterTests
{
var (vm, _, bus) = Fixture();
ChatCommandRouter.Submit("hi", vm, bus, ChatChannelKind.Fellowship);
Assert.Equal(ChatChannelKind.Fellowship, bus.Last!.Channel);
var command = Assert.IsType<SendChatCmd>(Assert.Single(bus.Published));
Assert.Equal(ChatChannelKind.Fellowship, command.Channel);
}
[Fact]
@ -47,48 +49,80 @@ public class ChatCommandRouterTests
{
var (vm, log, bus) = Fixture();
log.OnSystemMessage("x", chatType: 0);
var outcome = ChatCommandRouter.Submit("/clear", vm, bus, ChatChannelKind.Say);
Assert.Equal(SubmitOutcome.ClientHandled, outcome);
Assert.Null(bus.Last);
Assert.Empty(bus.Published);
Assert.Empty(log.Snapshot());
}
[Fact]
public void UnknownSlashVerb_RoutesToServerInAtForm()
[Theory]
[InlineData("/lifestone")]
[InlineData("/lif")]
[InlineData("/ls")]
[InlineData("@LS")]
public void LifestoneAliases_PublishTypedClientCommand(string input)
{
var (vm, _, bus) = Fixture();
var outcome = ChatCommandRouter.Submit(input, vm, bus, ChatChannelKind.Fellowship);
Assert.Equal(SubmitOutcome.ClientHandled, outcome);
var command = Assert.IsType<ExecuteClientCommandCmd>(Assert.Single(bus.Published));
Assert.Equal(ClientCommandId.LifestoneRecall, command.Command);
}
[Fact]
public void LifestoneWithArguments_ShowsUsageAndPublishesNothing()
{
// Retail / ≡ @: unknown verbs are the server's to judge. The
// parser rewrites /-form to @-form (ACE's GameActionTalk only
// intercepts @ on the wire); ACE answers "Unknown command: x"
// for verbs it doesn't know — no local guess.
var (vm, log, bus) = Fixture();
var outcome = ChatCommandRouter.Submit("/notacommand", vm, bus, ChatChannelKind.Say);
var outcome = ChatCommandRouter.Submit("/ls now", vm, bus, ChatChannelKind.Say);
Assert.Equal(SubmitOutcome.ClientHandled, outcome);
Assert.Empty(bus.Published);
Assert.Contains(log.Snapshot(), entry => entry.Text == "Usage: /lifestone");
}
[Fact]
public void UnknownSlashVerb_RoutesThroughExplicitServerCommand()
{
var (vm, log, bus) = Fixture();
var outcome = ChatCommandRouter.Submit(
"/notacommand", vm, bus, ChatChannelKind.Say);
Assert.Equal(SubmitOutcome.Sent, outcome);
Assert.NotNull(bus.Last);
Assert.Equal("@notacommand", bus.Last!.Text);
Assert.DoesNotContain(log.Snapshot(), e => e.Text.Contains("Unknown command"));
var command = Assert.IsType<SendServerCommandCmd>(Assert.Single(bus.Published));
Assert.Equal("@notacommand", command.Text);
Assert.DoesNotContain(log.Snapshot(), entry => entry.Text.Contains("Unknown command"));
}
[Theory]
[InlineData("/ci 629 5")]
[InlineData("@ci 629 5")]
public void ServerCommandWithArgs_PublishesCanonicalAtFormAsSay_EvenOnChannelDefault(string command)
public void ServerCommandWithArgs_PublishesCanonicalAtForm_EvenOnChannelDefault(
string input)
{
// Commands resolve before channel routing (retail behavior):
// even with Fellowship as the active input channel, a command
// goes out as Say/Talk — the only wire action ACE parses @ on.
var (vm, _, bus) = Fixture();
var outcome = ChatCommandRouter.Submit(command, vm, bus, ChatChannelKind.Fellowship);
var outcome = ChatCommandRouter.Submit(
input, vm, bus, ChatChannelKind.Fellowship);
Assert.Equal(SubmitOutcome.Sent, outcome);
Assert.Equal(ChatChannelKind.Say, bus.Last!.Channel);
Assert.Equal("@ci 629 5", bus.Last.Text);
var command = Assert.IsType<SendServerCommandCmd>(Assert.Single(bus.Published));
Assert.Equal("@ci 629 5", command.Text);
}
[Fact]
public void EmptyInput_DoesNothing()
{
var (vm, _, bus) = Fixture();
var outcome = ChatCommandRouter.Submit(" ", vm, bus, ChatChannelKind.Say);
Assert.Equal(SubmitOutcome.Empty, outcome);
Assert.Null(bus.Last);
Assert.Empty(bus.Published);
}
}

View file

@ -5,7 +5,7 @@ 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.
/// panel must publish the appropriate typed intent 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.
@ -114,10 +114,9 @@ public sealed class ChatPanelInputTests
[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)
public void Submit_UnknownSlashCommand_RoutesToExplicitServerCommand(string raw, string expectedText)
{
// Phase J Tier 4 held: /-prefixed text is still NEVER broadcast
// as plain speech. Retail treats / and @ as equivalent command
@ -136,12 +135,33 @@ public sealed class ChatPanelInputTests
panel.Render(new PanelContext(0.016f, bus), renderer);
var sendCmd = Assert.IsType<SendChatCmd>(Assert.Single(bus.Published));
Assert.Equal(ChatChannelKind.Say, sendCmd.Channel);
var sendCmd = Assert.IsType<SendServerCommandCmd>(Assert.Single(bus.Published));
Assert.Equal(expectedText, sendCmd.Text);
Assert.Empty(log.Snapshot()); // no local "Unknown command" guess
}
[Theory]
[InlineData("/lifestone")]
[InlineData("/lif")]
[InlineData("/ls")]
[InlineData("@LS")]
public void Submit_LifestoneAlias_PublishesTypedClientCommand(string raw)
{
var vm = new ChatVM(new ChatLog());
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 command = Assert.IsType<ExecuteClientCommandCmd>(Assert.Single(bus.Published));
Assert.Equal(ClientCommandId.LifestoneRecall, command.Command);
}
[Theory]
[InlineData("/")]
[InlineData("//shrug")]
@ -170,12 +190,12 @@ public sealed class ChatPanelInputTests
}
[Fact]
public void Submit_AtAcehelp_PassesThroughToSayWithAtIntact()
public void Submit_AtAcehelp_PublishesExplicitServerCommand()
{
// 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.
// intercepts it server-side. The explicit server-command record keeps
// it distinct from ordinary Say text.
var log = new ChatLog();
var vm = new ChatVM(log);
var panel = new ChatPanel(vm);
@ -188,8 +208,7 @@ public sealed class ChatPanelInputTests
panel.Render(new PanelContext(0.016f, bus), renderer);
var sendCmd = Assert.IsType<SendChatCmd>(Assert.Single(bus.Published));
Assert.Equal(ChatChannelKind.Say, sendCmd.Channel);
var sendCmd = Assert.IsType<SendServerCommandCmd>(Assert.Single(bus.Published));
Assert.Equal("@acehelp", sendCmd.Text);
}

View file

@ -0,0 +1,38 @@
using AcDream.UI.Abstractions;
using AcDream.UI.Abstractions.Panels.Chat;
namespace AcDream.UI.Abstractions.Tests.Panels.Chat;
public sealed class RetailClientCommandCatalogTests
{
[Theory]
[InlineData("/lifestone")]
[InlineData("@lifestone")]
[InlineData("/lif")]
[InlineData("@LIF")]
[InlineData("/ls")]
[InlineData("@LS")]
public void RetailAliases_ResolveCaseInsensitively(string input)
{
Assert.True(RetailClientCommandCatalog.TryMatch(input, out var match));
Assert.Equal(ClientCommandId.LifestoneRecall, match.Command);
Assert.True(match.HasValidArguments);
Assert.Empty(match.Arguments);
}
[Fact]
public void LifestoneArgument_IsRecognizedButInvalid()
{
Assert.True(RetailClientCommandCatalog.TryMatch("/ls now", out var match));
Assert.Equal("now", match.Arguments);
Assert.False(match.HasValidArguments);
Assert.Equal("/lifestone", match.Usage);
}
[Theory]
[InlineData("/ci 629")]
[InlineData("@acehelp")]
[InlineData("ordinary speech")]
public void NonClientCommands_DoNotMatch(string input)
=> Assert.False(RetailClientCommandCatalog.TryMatch(input, out _));
}