acdream/tests/AcDream.Core.Tests/Chat/ChatChannelInfoTests.cs
Erik e07fba5731 fix(chat): CH3 review fixes — phantom UN-9, allegiance-broadcast echo, /a legacy fallback
Applies the Opus review of Campaign CH slice CH3 (614a1e05):

- B1: UN-9 was a phantom divergence — ACE's CharacterOptions1.cs:47
  OR-sum is 0x50C4A54A (its own comment confirms 1355064650), identical
  to acdream's literal. The wrong 0x50C48D4A existed only in the research
  doc. Row deleted, register §5 reverted to 4 rows, research doc corrected
  with dated notes.
- S1/S4: AllegianceBroadcast (0x02000000) is a server-echoing channel —
  ACE's GameActionChatChannel handler includes the sender in its real-name
  Allegiance.Members broadcast (retail's DoAllegianceBroadcast has no
  AddTextToScroll), so the client must skip its local optimistic echo, not
  keep it. ChatChannelInfo.Legacy.IsSelfEchoChannel() now returns true for
  it; RouteLegacyChannel's comment corrected; Turbine.IsSelfEchoChannel()'s
  backwards comment rewritten truthfully.
- S3: retail's /a stays on the legacy AllegianceBroadcast bitflag until
  StartupTurbineChatSystem successfully starts Turbine chat — "never
  started" (TurbineChatState.Enabled == false) now falls back to legacy in
  both LiveSessionCommandRouter.RouteChat and
  DirectGameRuntimeCommandAdapter.TrySendChannel, while "enabled but no
  allegiance room" still correctly refuses locally.
- S5: added a LiveSessionEventRouter test proving the Options.Replace ->
  OnCharacterOptionsChanged seeding order, and RuntimeSettingsTargets /
  GameWindowLiveSessionOwnershipTests tests proving the concrete
  ICommandBus.Publish wiring and the single LiveSessionCommandSurface
  construction site.
- S6: AP-181 rewritten to name both of retail's omitted pre-send checks
  (IsMessageSafe silent-drop, then IsMessageSpam) and stop misattributing
  either to RouteLegacyChannel, which has no such gates.
- N1-N7: CharacterOptionId moved below SocialActions so its doc comment
  re-attaches; TurbineChatMembershipGate reuses TurbineChatDisplayNames
  instead of a duplicate table; the gate-to-refusal-text mapping is now
  shared via TurbineChatMembershipGate.ResolveRefusalText instead of
  duplicated in both hosts; ChatSettings.Default now matches ACE's real
  CharacterOptions2.Default (Roleplay/Society start off); a doc-comment
  clarifies only the five Hear toggles are server-backed; the register's
  §3 header recounted 129 -> 128.

Suite: 11,964 passed / 4 skipped / 0 failed (baseline 11,957/4/0 + 7 new
tests). Campaign ledger CH3 review column updated to APPROVE-WITH-FIXES.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-09 20:24:29 +02:00

67 lines
2.6 KiB
C#

using AcDream.Core.Chat;
using Xunit;
namespace AcDream.Core.Tests.Chat;
/// <summary>
/// Phase I.6: <see cref="ChatChannelInfo"/> + <see cref="ChatChannelSource"/>
/// behaviour. Mirrors holtburger's <c>is_self_echo_channel</c> predicate
/// (chat.rs:492-507) — only the legacy fellowship + allegiance-tree
/// channels echo the sender's own messages back with empty sender.
/// </summary>
public sealed class ChatChannelInfoTests
{
[Fact]
public void Legacy_FellowshipBitflag_IsSelfEcho()
{
var c = new ChatChannelInfo.Legacy(0x00000800u, "Fellowship");
Assert.Equal(ChatChannelSource.Legacy, c.Source);
Assert.Equal("Fellowship", c.DisplayName);
Assert.True(c.IsSelfEchoChannel());
}
[Theory]
[InlineData(0x00001000u)] // Vassals
[InlineData(0x00002000u)] // Patron
[InlineData(0x00004000u)] // Monarch
[InlineData(0x01000000u)] // CoVassals
public void Legacy_AllegianceTreeBitflags_AreSelfEcho(uint id)
{
var c = new ChatChannelInfo.Legacy(id, "Allegiance");
Assert.True(c.IsSelfEchoChannel(), $"channel 0x{id:X8} should self-echo");
}
[Fact]
public void Legacy_AllegianceBroadcastBitflag_IsSelfEcho()
{
// S1 (CH3 Opus review, 2026-08-09): flips this test's original
// (wrong) premise. ACE's GameActionChatChannel handler iterates
// player.Allegiance.Members — the sender IS a member, so their own
// line comes back with their real name through the SAME broadcast
// every other member gets (a different mechanism from holtburger's
// documented empty-sender resend for Fellow/Vassals/Patron/Monarch/
// CoVassals, but the same self-echo consequence). Retail agrees:
// ClientCommunicationSystem::DoAllegianceBroadcast @0x005761F0 has
// no AddTextToScroll of its own.
var c = new ChatChannelInfo.Legacy(0x02000000u, "AllegianceBroadcast");
Assert.True(c.IsSelfEchoChannel());
}
[Fact]
public void Turbine_IsNeverSelfEcho()
{
// Turbine rooms don't echo — caller must emit local optimistic echo.
var t = new ChatChannelInfo.Turbine(
RoomId: 0x12345678u, ChatType: 2u, DispatchType: 2u, DisplayName: "General");
Assert.Equal(ChatChannelSource.Turbine, t.Source);
Assert.Equal("General", t.DisplayName);
Assert.False(t.IsSelfEchoChannel());
}
[Fact]
public void Legacy_UnknownBitflag_IsNotSelfEcho()
{
var c = new ChatChannelInfo.Legacy(0xCAFEF00Du, "WatCha");
Assert.False(c.IsSelfEchoChannel());
}
}