acdream/tests/AcDream.App.Tests/Rendering/Walk/WalkOracleTraceTests.cs
Erik be81475cf9 fix(render): S3 chunk 1 round 1 — SC at DrawSortCell entry, the weather OC, real pins with mutation checks
Campaign OVERHAUL S3 chunk 1 fix round 1 (docs/research/2026-09-01-overhaul/
s3-walk-ownership-map.md §11.5), applied on top of 079483bb6 after the
three-lens review. G1-G10, each verified against source and (where the item
adds a pin) mutation-checked.

G1 — the flag-off integration test was vacuous: Collect_TranscriptFlagOff_
ProducesNoConsoleOutput drove ONE frame, and WalkOracleTrace.Parse
structurally discards the last (open) frame, so it passed whether or not
the flag gate worked. Now drives TWO frames and asserts BOTH that Parse
sees zero frames AND that no captured line starts with any of the ten
transcript-kind prefixes (F /P /LS/LC /SC /BLD /DI /DC /EC /OC ) — robust
to unrelated console noise from parallel test classes.

G2 — LC/SC computed LodCellId before testing the flag (~1,300 land-cell
turns/frame of division/modulo/checked-conversion work paid even when the
flag is off). Both OnLandCellTurn and the new OnSortCellTurn now guard the
LodCellId call itself, not just WalkTranscriptDump's internal check.

G3 — the flag-on round trip never exercised LC/SC/BLD (the T2 fixture's
stub 1x1 landscape has zero blocks). New
OutdoorRoot_TranscriptFlagOn_PrintsLandscapeThenLandCellThenSortCellThen
Building_InOrder drives RetailFrameWalk.DrawLandscape directly (the same
deterministic "CY-only" admission technique the existing outdoor LandCell
test uses) over a landscape with one block + one building, and asserts
LS < LC < SC < BLD by position, with the exact cell/building ids.

G4 — the parts/alpha-depth smoke tests asserted FL/PC (Flushes/
DrawCellsSamples) but never AM/PM (MeshAdds/PortalPolyDraws) for the
alpha-depth log, even though PD/DM were already asserted for the parts
log. Added the missing Assert.Contains for MeshAdds and PortalPolyDraws.

G5 — launch-options.md's side-effects column now states the flag off/on
costs explicitly ("one bool read per print site, nothing else" / "one
console line per walk turn, ≈600-800 lines per outdoor frame").

G6 — removed the "DI f4180108... no, a9b4013f" self-correction in
Oh_doorway_still_first_frame_diff's comment; added a one-line note on why
it and Oh_foundry_deep_... stay bespoke Facts rather than folding into the
Theory (no functional reason, just history).

G7 — SC printed from OnLandscapeCellTurn, which RetailFrameWalk.
DrawLandscape calls AFTER DrawBuilding — retail's own order is
LC -> SC -> BLD (terrace-edge.walk.log:2331-2333), not LC -> BLD -> SC.
Fixed by adding IWalkEventSink.OnSortCellTurn, fired at the DrawSortCell
entry point (same alwaysDrawObjects||cellInView gate, before DrawBuilding);
the driver moves its SC print there and OnLandscapeCellTurn no longer
prints one.

G8 — the trailing "OC <viewer land cell>" retail prints once per complete
outdoor frame is GameSky::Draw's weather branch calling
DrawObjCellForDummies(after_sky_cell) @0x005070da, not a walk turn.
RetailPViewPassExecutor.DrawLandscapeSliceLate now prints it at the point
it actually calls RenderWeather; PrintObjectCellTurn's doc, which denied
this line existed, is corrected. New
Oh_terrace_edge_outdoor_frame_ends_with_the_weather_ObjectCellTurn pins
this directly against the OH capture: every complete outdoor frame's last
event is an OC whose cell id equals that same frame's own P-line cell id.

G9 — "EC and OC counts are always exactly equal per pose" was false
(terrace-edge: 12 EC vs 16 OC, the extra 4 being G8's weather OC, which
has no EC counterpart). The visit-scoped/stamp-dedupe conclusion was
right; only the count claim needed fixing. Both doc sites corrected.

G10 — the conformance signature dropped LC/SC/EC/OC entirely, which is
how G7 shipped green: no test ever compared their placement. Recorder now
tracks LC/SC via the new OnLandCellTurn/OnSortCellTurn hooks and derives
EC/OC per DC from PView::DrawCells's own two reverse loops (shell
far-to-near, then object-list far-to-near) — a look-in flood's DC derives
them immediately, the interior root's OWN flood defers to
OnInteriorFloodDrawTurn (verified against cathedral-leak.walk.log:4,1328,
where the root DC's own EC/OC print last). WalkTraceReplayContext.
Signature8 applies the identical derivation to oracle frames and never
produces the trailing weather OC (G8's own dedicated pin covers that
separately, matching the spec's "exclude from the comparison, assert
separately" instruction). Used ONLY for the four OH-capture-rooted
conformance rows (the older FW0 fixtures predate the LC/SC/EC/OC
breakpoints and carry none of those lines).

Applying the eight-kind check surfaced a real, separate bug: WalkLandscape
DatBuilder never set WalkLandBlock.LandblockId, so every LC/SC token any
DAT-built world ever produced read landblockId=0 — latent because the old
four-kind signature filtered LC/SC out. Fixed (one field, test-fixture-
only, no production behavior change). With that fixed, three of the four
OH rows (terrace-edge, cathedral-arrival, foundry-deep) reproduce EXACTLY
at the eight-kind level. Oh_doorway_still_first_frame_diff still diverges
by one extra LC/SC pair (token index 165: replay draws LC:a9c90001|
SC:a9c90001 that retail never does) — a real WalkLandscape.CheckBlocks
visibility question at a ring-2/ring-3 LOD boundary, out of this round's
print-only scope, needing the retail oracle to resolve. Marked
[Trait("Status","KnownFailure")] with the exact position recorded in its
own doc comment, matching TowerAscent's existing pattern — the InstalledDat
lane now shows FOUR known failures (the pre-existing two #383 layout tests
+ TowerAscent, plus this new finding), not three; never weakened the pin
itself.

Mutation checks (all four restored after observing the failure):
- G1: forcing WalkTranscriptDump.Enabled true made
  Collect_TranscriptFlagOff_ProducesNoConsoleOutput fail with
  "Assert.DoesNotContain() Failure: Filter matched in collection ... Collection:
  [\"DI 00000100\", \"DC pv=00000000 ov=1 n=2: 00000100 00000101\", \"LS\", ...]".
- G3: deleting PrintLandCell's Console.WriteLine made the new outdoor test
  fail with "expected an LC line".
- G4: making MeshAddPattern unmatchable made all five
  Alpha_depth_log_parses_with_nonempty_samples rows fail with
  "Assert.Contains() Failure: Filter not matched in collection".
- G7/G10: moving OnSortCellTurn back after DrawBuilding made the
  terrace-edge conformance row fail with "walk diverged from retail
  (terrace-edge.walk)", first divergence exactly at its first building
  (f518002e): expected ...SC:f518002e|BLD:f518002e..., actual
  ...BLD:f518002e|SC:f518002e....

Gates: hermetic lane 6,816/0 (baseline 6,814 + G3's new test + G8's new
test); InstalledDat lane 244/4 known failures (two pre-existing #383
layout tests + TowerAscent + the new Oh_doorway_still_first_frame_diff
finding, documented above).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-03 11:49:42 +02:00

214 lines
8.5 KiB
C#

namespace AcDream.App.Tests.Rendering.Walk;
/// <summary>
/// Integrity tests for the FW0 walk-oracle fixtures: every checked-in
/// trace parses, and the load-bearing shapes recorded in the fixture
/// README hold. FW1's conformance suite builds on these parsed frames;
/// if a fixture is edited or recaptured, these goldens catch drift.
/// </summary>
public sealed class WalkOracleTraceTests
{
private const uint FarBuilding = 0xF518002Eu;
private const string FwRoot = "docs/research/2026-08-30-fw-walk-oracle";
/// <summary>S3 chunk 1 (§11.2 B3): the OH capture directory. Its walk
/// logs are named <c>&lt;pose&gt;.walk.log</c> — the trailing
/// <c>.walk</c> below is the fixture-name half of that filename, not a
/// subdirectory (matching <see cref="WalkLandCellOrderTests"/>'s own
/// convention).</summary>
private const string OhRoot = "docs/research/2026-09-01-overhaul/oh-capture";
/// <summary>(root, fixture name) pairs. Every FW0 still/posed fixture
/// keeps its old bare name under <see cref="FwRoot"/>; the five OH
/// walk captures (§11.2 B3) join under <see cref="OhRoot"/> with the
/// <c>.walk</c> filename-half suffix.</summary>
public static readonly TheoryData<string, string> AllFixtures = new()
{
{ FwRoot, "terrace-center" },
{ FwRoot, "terrace-edge" },
{ FwRoot, "cathedral-arrival" },
{ FwRoot, "holtburg-doorway-still" },
{ FwRoot, "holtburg-walkout" },
{ FwRoot, "holtburg-street-porchcam" },
{ FwRoot, "holtburg-street-outdoor" },
{ FwRoot, "holtburg-walkabout" },
{ FwRoot, "foundry-entry" },
{ FwRoot, "foundry-deep" },
{ OhRoot, "holtburg-doorway-still.walk" },
{ OhRoot, "terrace-edge.walk" },
{ OhRoot, "cathedral-arrival.walk" },
{ OhRoot, "foundry-deep.walk" },
{ OhRoot, "cathedral-leak.walk" },
};
[Theory]
[MemberData(nameof(AllFixtures))]
public void Fixture_parses_with_complete_frames(string root, string name)
{
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load(root, name);
Assert.NotEmpty(frames);
// Frame numbers are contiguous from 1; the truncated final frame is dropped.
Assert.Equal(1, frames[0].Number);
Assert.Equal(frames.Count, frames[^1].Number);
Assert.All(frames, f => Assert.NotEmpty(f.Events));
}
/// <summary>S3 chunk 1 fix round 1 (G8/G10): the "assert separately"
/// half of <see cref="WalkTraceReplayContext.Signature8(WalkOracleFrame)"/>'s
/// own doc comment — that method's derivation never produces the
/// trailing weather OC (G8: <c>GameSky::Draw</c> @0x00506ff0's weather
/// branch calling <c>DrawObjCellForDummies(after_sky_cell)</c>
/// @0x005070da), so its presence/position is pinned here instead,
/// directly against the OH capture (the FW0 <c>terrace-edge</c> fixture
/// predates the OC breakpoint and carries none). Every complete outdoor
/// frame's LAST event is an <c>OC</c> whose cell id equals that SAME
/// frame's own <c>P</c> line cell id (the viewer's land cell).</summary>
[Fact]
public void Oh_terrace_edge_outdoor_frame_ends_with_the_weather_ObjectCellTurn()
{
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load(OhRoot, "terrace-edge.walk");
Assert.NotEmpty(frames);
Assert.All(frames, f =>
{
Assert.NotNull(f.Pose);
WalkOracleEvent last = f.Events[^1];
Assert.Equal(WalkOracleEventKind.ObjectCellTurn, last.Kind);
Assert.Equal(f.Pose!.CellId, last.CellId);
});
}
[Fact]
public void Terrace_edge_draws_the_far_building_every_outdoor_frame()
{
// The #456 acceptance oracle: retail HIDES the vista by depth cover,
// not by omission — 0xF518002E is submitted every single frame.
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load("terrace-edge");
Assert.All(frames, f =>
{
Assert.Null(f.InteriorRootCell);
Assert.True(f.HasLandscape);
Assert.Contains(FarBuilding, f.Buildings);
});
}
[Fact]
public void Cathedral_arrival_roots_interior_and_culls_the_far_building()
{
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load("cathedral-arrival");
Assert.All(frames, f =>
{
Assert.Equal(0xF4180106u, f.InteriorRootCell);
Assert.True(f.HasLandscape); // drawn THROUGH the exit view
Assert.DoesNotContain(FarBuilding, f.Buildings);
});
}
[Fact]
public void Doorway_root_is_stable_across_every_frame()
{
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load("holtburg-doorway-still");
Assert.All(frames, f => Assert.Equal(0xA9B4013Fu, f.InteriorRootCell));
}
[Fact]
public void Walkout_hands_over_between_interior_cells_in_one_frame()
{
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load("holtburg-walkout");
uint?[] roots = frames.Select(f => f.InteriorRootCell).Distinct().ToArray();
Assert.Equal(new uint?[] { 0xA9B4013Fu, 0xA9B40150u }, roots);
// Exactly one handover: the root sequence is two contiguous runs.
int transitions = frames.Zip(frames.Skip(1))
.Count(pair => pair.First.InteriorRootCell != pair.Second.InteriorRootCell);
Assert.Equal(1, transitions);
}
[Fact]
public void Street_porchcam_roots_at_the_camera_cell_not_the_player()
{
// The player stood in the street; the chase camera sat inside the
// cottage porch — and retail rooted the frame at the CAMERA's cell.
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load("holtburg-street-porchcam");
Assert.All(frames, f => Assert.Equal(0xA9B40150u, f.InteriorRootCell));
}
[Fact]
public void Street_outdoor_never_enters_an_interior_root()
{
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load("holtburg-street-outdoor");
Assert.All(frames, f =>
{
Assert.Null(f.InteriorRootCell);
Assert.True(f.HasLandscape);
});
}
[Fact]
public void Foundry_entry_flips_outdoor_to_interior_and_drops_the_landscape()
{
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load("foundry-entry");
WalkOracleFrame flip = frames.First(f => f.InteriorRootCell is not null);
Assert.Equal(0xA9B40178u, flip.InteriorRootCell);
// The frame before the flip is fully outdoor; the flip frame itself
// draws NO landscape and NO buildings — the pure-interior shape.
WalkOracleFrame before = frames[flip.Number - 2];
Assert.Null(before.InteriorRootCell);
Assert.True(before.HasLandscape);
Assert.False(flip.HasLandscape);
Assert.Empty(flip.Buildings);
}
[Fact]
public void Foundry_deep_draws_the_town_through_the_surviving_chain()
{
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load("foundry-deep");
Assert.All(frames, f =>
{
Assert.Equal(0xA9B40176u, f.InteriorRootCell);
Assert.True(f.HasLandscape);
Assert.NotEmpty(f.Buildings);
});
}
[Fact]
public void Stationary_frames_repeat_their_event_sequence_exactly()
{
// README finding 6: while the camera is still, the whole-frame
// sequence repeats bit-for-bit. Assert it on the terrace fixture.
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load("terrace-center");
WalkOracleFrame first = frames[0];
Assert.All(frames.Skip(1), f =>
{
Assert.Equal(first.Events.Count, f.Events.Count);
for (int i = 0; i < first.Events.Count; i++)
Assert.Equal(first.Events[i], f.Events[i], WalkOracleEventComparer.Instance);
});
}
private sealed class WalkOracleEventComparer : IEqualityComparer<WalkOracleEvent>
{
public static readonly WalkOracleEventComparer Instance = new();
public bool Equals(WalkOracleEvent? x, WalkOracleEvent? y)
=> x is not null && y is not null
&& x.Kind == y.Kind
&& x.CellId == y.CellId
&& x.OutsideViewCount == y.OutsideViewCount
&& x.DeclaredCellCount == y.DeclaredCellCount
&& x.Cells.SequenceEqual(y.Cells);
public int GetHashCode(WalkOracleEvent obj)
=> HashCode.Combine(obj.Kind, obj.CellId, obj.Cells.Count);
}
}