acdream/tests/AcDream.App.Tests/UI/Layout/OP2ReworkBlastRadiusConformanceTests.cs
Erik b236a44279 fix(ui): OP2 rework — dormant UiDatElement subclasses, fixed Panel/CheckboxBitfield64 mechanism
OP2 (df9c7a35) was double-REJECTed: an unconditional Type-8/Type-5 factory
mapping silently re-classed 15 elements across 7 shipped panels (vendor
backdrop lost its fill, character/spellbook roots stopped passing clicks
through, combat gained a phantom import-time tab takeover, ten ListBoxes
gained a spurious hit-testable viewport) because the stale 27 pre-existing
fixtures never exercised the new fields — and the mechanism itself cited a
nonexistent "UIElement_TabControl" class, inverted UiCheckboxBitfield64's
checked-state predicate, and synthesized fake per-row geometry instead of
using the widget's own authored template.

Shape change: UiTabPanel (renamed from UiTabControl) and UiTemplateListBox
now derive from UiDatElement (unsealed) and stay DORMANT by default — an
imported Type-8/Type-5 element gets authored-media drawing, ClickThrough
generic-decoration default, and IUiDatStateful propagation identical to the
pre-OP2 UiDatElement fallback, with zero import-time side effects. The
factory's Type-8/Type-5 arms are unconditional again (no more guard whose
premise the blast-radius sweep proved false), because dormancy makes an
unactivated instance behaviorally indistinguishable from the old fallback.
UiTabPanel.ActivateTabBehavior() and UiTemplateListBox's lazy viewport
creation are the explicit, controller-driven opt-ins Campaign OP slice OP3+
will call; today nothing does, so the four pre-existing shipped Type-8
hosts (character/spellbook/vendor/combat) and ten pre-existing Type-5
ListBoxes keep their pre-OP2 behavior exactly. Filed AD-73 for this
dormant-vs-retail's-unconditional-activation adaptation.

Mechanism fixes (docs/research/2026-08-11-op2-review-mechanism.md):
- UiTabPanel cites UIElement_Panel (Type 8 is UIElement_Panel; no
  UIElement_TabControl exists in the PDB), resolves buttons/pages via a
  GetChildRecursive-equivalent descendant search (not direct-children-only),
  performs no switch when no entry authors 0x32 (deleted the _tabs[0]
  fallback), and surfaces unresolved tab-table entries via UnresolvedEntries
  + a diagnostic line instead of a silent no-op.
- ElementReader.ReadTabTable skips entries missing 0x30/0x31, matching
  retail's SetupTabPageHash @0x0046C2E0 entry filter.
- UiCheckboxBitfield64 now builds every row from its OWN authored template
  (property 0x64 -> {0x2100002B, 0x10000521}) via AddItemFromTemplateList,
  deleting the synthesized ElementInfo + invented RowHeight=14 — matching
  retail's CreateChildren @0x00485DF0, which is itself a UIElement_ListBox
  call. IsSet is now retail's ANY-bit-set predicate (Refresh @0x004859C0),
  not all-bits-set. TS-72 retired: the click-toggle bit math is now fully
  decomp-confirmed (SetBitsOnOrOff via ListenToElementMessage @0x00485AE0).

Regenerated all 32 UI fixtures against real DAT (ACDREAM_REGENERATE_UI_FIXTURES=1)
and committed them — 27 pre-existing fixtures now carry Outline/OutlineColor/
TabTable/TemplateList/ScrollbarElementId; the 5 Options fixtures were already
current. Updated EffectsUiControllerTests' now-correct UiTemplateListBox
class-identity assertion. Added: 6 built-widget behavior pins for all five
pre-existing Type-8 elements + a representative Type-5 element the dormancy
model protects (OP2ReworkBlastRadiusConformanceTests.cs); 5 reader-level
tests driving ReadTabTable/ReadTemplateList/the 0x72 reader from raw
property bags (ElementReaderTests.cs); a multi-bit-mask UiCheckboxBitfield64
test proving the any-bit predicate (the prior single-bit test couldn't
distinguish it from all-bits); an activation-idempotency test and a
before-activation click-is-inert test for UiTabPanel.

Full Release suite: 12,868 passed / 4 skipped / 0 failed (baseline 12,853/4/0
post-OP1-fixes; +15 net new tests, zero regressions).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-11 01:08:08 +02:00

157 lines
7.4 KiB
C#

using AcDream.App.UI;
using AcDream.App.UI.Layout;
namespace AcDream.App.Tests.UI.Layout;
/// <summary>
/// Built-widget behavior pins for the pre-existing, already-shipped Type-8/Type-5
/// elements the OP2 double-REJECT findings named
/// (`docs/research/2026-08-11-op2-review-blast.md` §1.1/§1.2,
/// `docs/research/2026-08-11-op2-review-mechanism.md` §2.1/§2.2). These fixtures are
/// NOT Options-panel data — they are the character sheet, spellbook, vendor, and
/// combat panels' own committed fixtures — and every assertion here is a regression
/// guard for the OP2 rework's dormancy model: a Type-8/Type-5 element that reaches
/// <see cref="DatWidgetFactory"/> without a controller opting it into the new
/// mechanism must render and hit-test EXACTLY like the pre-OP2
/// <see cref="UiDatElement"/> fallback.
///
/// <para>
/// Before this rework, these five Type-8 elements and every pre-existing Type-5
/// element silently re-classed to a bare-<see cref="UiElement"/>-derived
/// <c>UiTabControl</c>/<c>UiTemplateListBox</c> in production while every fixture-
/// driven test still exercised the OLD stale-fixture shape (empty TabTable/
/// TemplateList) — a structural false negative the blast-radius review named as the
/// root enabler. These tests build through the REAL (regenerated) fixtures, so a
/// future regression that reintroduces eager wiring, media loss, or a ClickThrough
/// flip WILL fail here.
/// </para>
/// </summary>
public class OP2ReworkBlastRadiusConformanceTests
{
// ── Type 8 — vendor's media-bearing, tab-table-less backdrop ────────────
/// <summary>
/// Vendor `0x1000008D` (800x20) authors a DirectState fill and NO tab table —
/// `RetailUiRuntime.cs` documents it by name as the vendor panel's own backdrop
/// fill. Blast-review MUST-FIX 1(a): the OP2-as-landed unconditional-but-bare
/// mapping stopped this drawing entirely.
/// </summary>
[Fact]
public void Vendor_BackdropElement_DrawsItsAuthoredMedia_AndStaysClickThrough()
{
var layout = FixtureLoader.LoadVendor();
var backdrop = Assert.IsType<UiTabPanel>(layout.FindElement(0x1000008Du));
Assert.Empty(backdrop.Tabs); // no authored 0x2E on this element
Assert.False(backdrop.BehaviorActive); // nobody activates it — dormant
Assert.True(backdrop.ClickThrough); // UiDatElement's generic-decoration default
(uint file, int _) = backdrop.ActiveMedia();
Assert.NotEqual(0u, file); // the authored fill still draws
}
/// <summary>
/// Vendor `0x100000B8` (the ACTUAL tab host, distinct from the `0x1000008D`
/// backdrop above) authors a 3-entry tab table that `VendorUiController`
/// already switches end-to-end. Same claim as the character/spellbook roots
/// below: dormant on import, controller owns activation.
/// </summary>
[Fact]
public void Vendor_TabHost_StaysDormant_ControllerOwnsSwitching()
{
var layout = FixtureLoader.LoadVendor();
var host = Assert.IsType<UiTabPanel>(layout.FindElement(0x100000B8u));
Assert.Equal(3, host.Tabs.Count); // the authored table IS present…
Assert.False(host.BehaviorActive); // …but nobody has activated it
Assert.Equal(0u, host.ActivePageElementId);
Assert.True(host.ClickThrough);
}
// ── Type 8 — panel roots with their own controller-owned switching ──────
/// <summary>
/// Character sheet root `0x10000227` authors a 3-entry tab table but
/// `CharacterStatController` already owns tab switching for this panel
/// end-to-end. Blast-review MUST-FIX 1(b)/(c): the OP2-as-landed mapping made
/// this element claim every unclaimed click in its bounds
/// (<c>ClickThrough</c> false→ silently) and stop propagating
/// <see cref="IUiDatStateful"/> state into its children.
/// </summary>
[Fact]
public void CharacterRoot_StaysClickThrough_AndPropagatesState_WithoutActivation()
{
var layout = FixtureLoader.LoadCharacter();
var root = Assert.IsType<UiTabPanel>(layout.Root);
Assert.Equal(0x10000227u, root.DatElementId);
Assert.NotEmpty(root.Tabs); // the authored table IS present…
Assert.False(root.BehaviorActive); // …but nobody has activated it
Assert.Equal(0u, root.ActivePageElementId);
Assert.True(root.ClickThrough);
Assert.IsAssignableFrom<IUiDatStateful>(root);
}
/// <summary>Spellbook root `0x100002A8` — same shape/claim as the character
/// sheet, owned end-to-end by <c>SpellbookWindowController</c>.</summary>
[Fact]
public void SpellbookRoot_StaysClickThrough_AndPropagatesState_WithoutActivation()
{
var layout = FixtureLoader.LoadSpellbook();
var root = Assert.IsType<UiTabPanel>(layout.Root);
Assert.Equal(0x100002A8u, root.DatElementId);
Assert.NotEmpty(root.Tabs);
Assert.False(root.BehaviorActive);
Assert.Equal(0u, root.ActivePageElementId);
Assert.True(root.ClickThrough);
Assert.IsAssignableFrom<IUiDatStateful>(root);
}
// ── Type 8 — combat, which has NO controller re-binder at all ───────────
/// <summary>
/// Combat `0x100000A2` authors an 8-entry tab table and — unlike character/
/// spellbook/vendor — has NO controller that re-binds it after import. Blast-
/// review MUST-FIX 1(d): the OP2-as-landed <c>OnChildrenAttached</c> ran at
/// import time regardless, so this element would have taken over its 8 stance
/// pages outright with nothing to override it. Every child must remain exactly
/// as imported: all Visible (retail's plain default), no page hidden, no click
/// bound.
/// </summary>
[Fact]
public void Combat_TabHost_PerformsNoImportTimeTakeover()
{
var layout = FixtureLoader.LoadCombat();
var host = Assert.IsType<UiTabPanel>(layout.FindElement(0x100000A2u));
Assert.Equal(8, host.Tabs.Count); // the authored table IS present…
Assert.False(host.BehaviorActive); // …but nothing ever activates it
Assert.Equal(0u, host.ActivePageElementId);
Assert.Equal(16, host.Children.Count); // no children lost/consumed
Assert.All(host.Children, child => Assert.True(child.Visible));
}
// ── Type 5 — a representative pre-existing ListBox with an authored template ──
/// <summary>
/// Effects list `0x10000123` (`EffectsUiController.ListId`) authors a 1-row
/// template array. Blast-review MUST-FIX 2: the OP2-as-landed unconditional
/// mapping lost the authored media, defaulted <c>ClickThrough=false</c>, and
/// unconditionally injected a hit-testable viewport as child 0 — before
/// <c>EffectsUiController.Bind</c> ever runs. This pins the dormant baseline
/// directly; <c>EffectsUiControllerTests</c> pins the controller's own
/// subsequent <see cref="UiElement.AddChild"/> behavior.
/// </summary>
[Fact]
public void EffectsList_StaysDormant_ClickThrough_NoInjectedViewport()
{
var layout = FixtureLoader.LoadPositiveEffects();
var host = Assert.IsType<UiTemplateListBox>(
layout.FindElement(EffectsUiController.ListId));
Assert.NotEmpty(host.Templates); // the authored 0x64 array IS present…
Assert.Empty(host.Children); // …but no viewport was injected
Assert.Equal(0, host.ContentHeight);
Assert.True(host.ClickThrough);
}
}