Opus dual-lens review of CT2 (bcfddc97) found 4 SHOULD-FIX + notes; this
applies the campaign lead's rulings.
F1 (the important one): retail's client-side table add is DEDUPED —
gmCharacterTitleUI::RecvNotice_AddCharacterTitle @0x0049a990 walks
mTitleList and returns without effect when the id is already present,
only inserting on a miss. The server-side SendNotice_AddCharacterTitle
broadcast is unconditional, but RuntimeCharacterTitleState.ApplyUpdateTitle
models the CLIENT receive side, so TitleAdded now fires only on a genuine
new membership. Inverted the pin:
ApplyUpdateTitle_AlreadyEarnedId_DoesNotFireTitleAddedOrBumpRevision.
F3: removed the send-side titleId==0 rejection from both command
adapters. Retail's own send path (Event_SetDisplayCharacterTitle
@0x006a5720) packs whatever id it is handed, and ACE accepts id 0
(CharacterTitle.Invalid is a defined enum value) — retail's real
protection is the UI ghost-when-current gate (CT3's job), not a
send-side rejection. No register row: this makes acdream MORE
retail-exact.
A2: ResetSession now publishes TableReplaced unconditionally and
DisplayTitleChanged when the display id was non-zero before the clear,
matching the LocalPlayerState.Clear() precedent (publish every category
even when Clear is repeated, so a failed reset can converge on retry).
A3: RuntimeCharacterState.CaptureOwnership reads the new non-allocating
Titles.Count instead of EarnedTitleIds.Count; EarnedTitleIds now carries
an XML warning that every read allocates.
A4/A5: ReplaceTable/ApplyUpdateTitle now mutate under one _gate hold with
change flags computed inside the lock and events raised after release;
every revision bump is gated on an actual state change (a no-op wire
resend produces zero revision edges), matching the change-gated
RuntimeMovementSkillState precedent. TableReplaced itself still fires
unconditionally per retail's own Refresh() dispatch on 0x0029.
A1/A6/A7/A8: CharacterTitleResolverLiveDatTests honors ACDREAM_DAT_DIR
first (CT1 fix-round pattern); documented the EmitResult
primaryObjectId-as-title-id precedent inline; corrected the "third
consumer" comment (CT1 §5 already records gmAttributeUI::PostInit's
icon-DID lookup — CT5 factors the shared GetDIDByEnum helper); added a
titleId -> resolved-string memo to CharacterTitleResolver, the DAT-static
equivalent of retail's lazy-hash cache on the string buffer.
Appended a "CT3 anchors from the CT2 review" list to the plan doc's CT2
ledger entry for CT3 to consume.
Build green. Runtime (102), Core.Net (12), and App (27 + 3 InstalledDat
pins under ACDREAM_RUN_INSTALLED_DAT_TESTS=1) title-scoped tests pass.
Full hermetic solution suite (Lane exclusions per the release gate) is
green: 0 failures across all 15 test projects.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
303 lines
11 KiB
C#
303 lines
11 KiB
C#
using AcDream.Runtime.Gameplay;
|
|
|
|
namespace AcDream.Runtime.Tests.Gameplay;
|
|
|
|
/// <summary>
|
|
/// Campaign CT slice CT2 (2026-08-24): unit tests for
|
|
/// <see cref="RuntimeCharacterTitleState"/> — the retail
|
|
/// <c>CharacterTitleTable</c> port. Covers the full table replace
|
|
/// (<c>0x0029 CharacterTitle</c>), the incremental add/set-display notice
|
|
/// (<c>0x002B UpdateTitle</c>), the retail-verified unconditional-add /
|
|
/// gated-display-set contract, and generation-reset clearing.
|
|
/// </summary>
|
|
public sealed class RuntimeCharacterTitleStateTests
|
|
{
|
|
[Fact]
|
|
public void InitialState_IsEmptyWithDefaultDisplayTitle()
|
|
{
|
|
var titles = new RuntimeCharacterTitleState();
|
|
|
|
Assert.Equal(0u, titles.DisplayTitleId);
|
|
Assert.Empty(titles.EarnedTitleIds);
|
|
Assert.False(titles.HasEarnedTitle(13u));
|
|
}
|
|
|
|
[Fact]
|
|
public void ReplaceTable_SetsEarnedIdsAndDisplayTitle_FiresTableReplaced()
|
|
{
|
|
var titles = new RuntimeCharacterTitleState();
|
|
int tableReplacedCount = 0;
|
|
titles.TableReplaced += () => tableReplacedCount++;
|
|
|
|
titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
|
|
|
Assert.Equal(13u, titles.DisplayTitleId);
|
|
Assert.Equal(new HashSet<uint> { 1u, 5u, 13u }, titles.EarnedTitleIds.ToHashSet());
|
|
Assert.True(titles.HasEarnedTitle(5u));
|
|
Assert.False(titles.HasEarnedTitle(99u));
|
|
Assert.Equal(1, tableReplacedCount);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReplaceTable_IsAWholesaleReplace_DropsIdsMissingFromTheNewTable()
|
|
{
|
|
var titles = new RuntimeCharacterTitleState();
|
|
titles.ReplaceTable(1u, [1u, 2u, 3u]);
|
|
|
|
titles.ReplaceTable(1u, [1u]);
|
|
|
|
Assert.Equal(new uint[] { 1u }, titles.EarnedTitleIds.ToArray());
|
|
Assert.False(titles.HasEarnedTitle(2u));
|
|
Assert.False(titles.HasEarnedTitle(3u));
|
|
}
|
|
|
|
[Fact]
|
|
public void ReplaceTable_DisplayTitleIdUnchanged_DoesNotFireDisplayTitleChanged()
|
|
{
|
|
var titles = new RuntimeCharacterTitleState();
|
|
titles.ReplaceTable(13u, [13u]);
|
|
var fired = new List<uint>();
|
|
titles.DisplayTitleChanged += id => fired.Add(id);
|
|
|
|
titles.ReplaceTable(13u, [13u, 14u]);
|
|
|
|
Assert.Empty(fired);
|
|
Assert.Equal(13u, titles.DisplayTitleId);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReplaceTable_DisplayTitleIdChanges_FiresDisplayTitleChangedWithNewId()
|
|
{
|
|
var titles = new RuntimeCharacterTitleState();
|
|
titles.ReplaceTable(13u, [13u, 14u]);
|
|
var fired = new List<uint>();
|
|
titles.DisplayTitleChanged += id => fired.Add(id);
|
|
|
|
titles.ReplaceTable(14u, [13u, 14u]);
|
|
|
|
Assert.Equal([14u], fired);
|
|
Assert.Equal(14u, titles.DisplayTitleId);
|
|
}
|
|
|
|
// ── 0x002B UpdateTitle: unconditional add, gated display-set ─────────
|
|
// Retail's Handle_Social__AddOrSetCharacterTitle @0x00564260 ALWAYS
|
|
// calls SendNotice_AddCharacterTitle, and additionally calls
|
|
// SendNotice_SetDisplayCharacterTitle only when setAsDisplay != 0.
|
|
|
|
[Fact]
|
|
public void ApplyUpdateTitle_AlwaysAddsAndFiresTitleAdded_EvenWhenNotSetAsDisplay()
|
|
{
|
|
var titles = new RuntimeCharacterTitleState();
|
|
var added = new List<uint>();
|
|
titles.TitleAdded += id => added.Add(id);
|
|
var displayChanged = new List<uint>();
|
|
titles.DisplayTitleChanged += id => displayChanged.Add(id);
|
|
|
|
titles.ApplyUpdateTitle(7u, setAsDisplay: false);
|
|
|
|
Assert.True(titles.HasEarnedTitle(7u));
|
|
Assert.Equal([7u], added);
|
|
Assert.Empty(displayChanged);
|
|
Assert.Equal(0u, titles.DisplayTitleId);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyUpdateTitle_SetAsDisplayTrue_AddsAndUpdatesDisplayTitle()
|
|
{
|
|
var titles = new RuntimeCharacterTitleState();
|
|
var added = new List<uint>();
|
|
titles.TitleAdded += id => added.Add(id);
|
|
var displayChanged = new List<uint>();
|
|
titles.DisplayTitleChanged += id => displayChanged.Add(id);
|
|
|
|
titles.ApplyUpdateTitle(13u, setAsDisplay: true);
|
|
|
|
Assert.True(titles.HasEarnedTitle(13u));
|
|
Assert.Equal([13u], added);
|
|
Assert.Equal([13u], displayChanged);
|
|
Assert.Equal(13u, titles.DisplayTitleId);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyUpdateTitle_AlreadyEarnedId_DoesNotFireTitleAddedOrBumpRevision()
|
|
{
|
|
// F1 (CT2 fix round, 2026-08-24): the SERVER-side broadcast
|
|
// (SendNotice_AddCharacterTitle) is unconditional, but this method
|
|
// models the CLIENT-side receive handler
|
|
// (gmCharacterTitleUI::RecvNotice_AddCharacterTitle @0x0049a990),
|
|
// which walks mTitleList and returns without effect when the id is
|
|
// already present — only a genuine miss inserts + adds the row.
|
|
var titles = new RuntimeCharacterTitleState();
|
|
titles.ApplyUpdateTitle(7u, setAsDisplay: false);
|
|
long revisionAfterFirstAdd = titles.Revision;
|
|
var added = new List<uint>();
|
|
titles.TitleAdded += id => added.Add(id);
|
|
|
|
titles.ApplyUpdateTitle(7u, setAsDisplay: false);
|
|
|
|
Assert.Empty(added);
|
|
Assert.Single(titles.EarnedTitleIds);
|
|
Assert.Equal(revisionAfterFirstAdd, titles.Revision);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyUpdateTitle_SetAsDisplayOnAlreadyCurrentId_DoesNotFireDisplayTitleChangedOrBumpRevision()
|
|
{
|
|
// A5 (CT2 fix round): a re-notice for the id that is ALREADY the
|
|
// display title is a no-op wire message — it must not produce a
|
|
// revision edge or a spurious DisplayTitleChanged.
|
|
var titles = new RuntimeCharacterTitleState();
|
|
titles.ApplyUpdateTitle(13u, setAsDisplay: true);
|
|
long revisionAfterFirst = titles.Revision;
|
|
var displayChanged = new List<uint>();
|
|
titles.DisplayTitleChanged += id => displayChanged.Add(id);
|
|
var added = new List<uint>();
|
|
titles.TitleAdded += id => added.Add(id);
|
|
|
|
titles.ApplyUpdateTitle(13u, setAsDisplay: true);
|
|
|
|
Assert.Empty(displayChanged);
|
|
Assert.Empty(added);
|
|
Assert.Equal(revisionAfterFirst, titles.Revision);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyUpdateTitle_AddsNewIdAndSetsDisplay_BumpsRevisionTwice()
|
|
{
|
|
// A5: a single 0x002B that both adds a NEW id and changes the
|
|
// display title bumps the revision once per real half-change.
|
|
var titles = new RuntimeCharacterTitleState();
|
|
long before = titles.Revision;
|
|
|
|
titles.ApplyUpdateTitle(13u, setAsDisplay: true);
|
|
|
|
Assert.Equal(before + 2, titles.Revision);
|
|
}
|
|
|
|
[Fact]
|
|
public void ApplyUpdateTitle_SetAsDisplayOnAnUnearnedId_AddsItAndSetsDisplay()
|
|
{
|
|
// Retail sends UpdateTitle for a title the player just earned — the
|
|
// id is not necessarily already in the earned set beforehand.
|
|
var titles = new RuntimeCharacterTitleState();
|
|
|
|
titles.ApplyUpdateTitle(99u, setAsDisplay: true);
|
|
|
|
Assert.True(titles.HasEarnedTitle(99u));
|
|
Assert.Equal(99u, titles.DisplayTitleId);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReplaceTable_IdenticalResend_DoesNotBumpRevision_ButStillFiresTableReplaced()
|
|
{
|
|
// A5: a byte-identical 0x0029 resend (same table, same display id)
|
|
// is a no-op wire message for the revision counter. TableReplaced
|
|
// itself still fires unconditionally — retail's own
|
|
// RecvNotice_UpdateCharacterTitleTable always Refresh()es.
|
|
var titles = new RuntimeCharacterTitleState();
|
|
titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
|
long revisionAfterFirst = titles.Revision;
|
|
int tableReplacedCount = 0;
|
|
titles.TableReplaced += () => tableReplacedCount++;
|
|
|
|
titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
|
|
|
Assert.Equal(revisionAfterFirst, titles.Revision);
|
|
Assert.Equal(1, tableReplacedCount);
|
|
}
|
|
|
|
[Fact]
|
|
public void ResetSession_ClearsEarnedIdsAndDisplayTitle()
|
|
{
|
|
var titles = new RuntimeCharacterTitleState();
|
|
titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
|
|
|
titles.ResetSession();
|
|
|
|
Assert.Equal(0u, titles.DisplayTitleId);
|
|
Assert.Empty(titles.EarnedTitleIds);
|
|
}
|
|
|
|
[Fact]
|
|
public void ResetSession_BumpsRevisionEvenWhenAlreadyEmpty()
|
|
{
|
|
var titles = new RuntimeCharacterTitleState();
|
|
long before = titles.Revision;
|
|
|
|
titles.ResetSession();
|
|
|
|
Assert.True(titles.Revision > before);
|
|
}
|
|
|
|
[Fact]
|
|
public void ResetSession_NonEmptyState_FiresTableReplacedAndDisplayTitleChanged()
|
|
{
|
|
// A2 (CT2 fix round): matches the LocalPlayerState.Clear() precedent
|
|
// — publish every category even when Clear is repeated, so a failed
|
|
// reset attempt can safely converge on retry.
|
|
var titles = new RuntimeCharacterTitleState();
|
|
titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
|
int tableReplacedCount = 0;
|
|
titles.TableReplaced += () => tableReplacedCount++;
|
|
var displayChanged = new List<uint>();
|
|
titles.DisplayTitleChanged += id => displayChanged.Add(id);
|
|
|
|
titles.ResetSession();
|
|
|
|
Assert.Equal(1, tableReplacedCount);
|
|
Assert.Equal([0u], displayChanged);
|
|
}
|
|
|
|
[Fact]
|
|
public void ResetSession_RepeatedReset_StillFiresTableReplacedButNotDisplayTitleChanged()
|
|
{
|
|
// A2: TableReplaced publishes unconditionally on every reset; a
|
|
// SECOND reset (display id already 0) must not re-fire
|
|
// DisplayTitleChanged — there is no real transition to report.
|
|
var titles = new RuntimeCharacterTitleState();
|
|
titles.ResetSession();
|
|
int tableReplacedCount = 0;
|
|
titles.TableReplaced += () => tableReplacedCount++;
|
|
var displayChanged = new List<uint>();
|
|
titles.DisplayTitleChanged += id => displayChanged.Add(id);
|
|
|
|
titles.ResetSession();
|
|
|
|
Assert.Equal(1, tableReplacedCount);
|
|
Assert.Empty(displayChanged);
|
|
}
|
|
|
|
[Fact]
|
|
public void Count_ReflectsEarnedTitleIdsWithoutAllocatingTheArray()
|
|
{
|
|
// A3 (CT2 fix round): non-allocating count accessor for hot paths
|
|
// like RuntimeCharacterState.CaptureOwnership.
|
|
var titles = new RuntimeCharacterTitleState();
|
|
Assert.Equal(0, titles.Count);
|
|
|
|
titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
|
|
|
Assert.Equal(3, titles.Count);
|
|
}
|
|
|
|
[Fact]
|
|
public void Snapshot_ReflectsDisplayTitleAndCount()
|
|
{
|
|
var titles = new RuntimeCharacterTitleState();
|
|
titles.ReplaceTable(13u, [1u, 5u, 13u]);
|
|
|
|
RuntimeCharacterTitleSnapshot snapshot = titles.Snapshot;
|
|
|
|
Assert.Equal(13u, snapshot.DisplayTitleId);
|
|
Assert.Equal(3, snapshot.TitleCount);
|
|
Assert.Equal(titles.Revision, snapshot.Revision);
|
|
}
|
|
|
|
[Fact]
|
|
public void ReplaceTable_NullTitleIds_Throws()
|
|
{
|
|
var titles = new RuntimeCharacterTitleState();
|
|
Assert.Throws<ArgumentNullException>(
|
|
() => titles.ReplaceTable(1u, null!));
|
|
}
|
|
}
|