feat(render): S3 chunk 1 — print-only walk transcript, OH fixtures, offline signature diff

Campaign OVERHAUL S3 chunk 1 (docs/research/2026-09-01-overhaul/s3-walk-ownership-map.md
§11): the transcript-kinds/fixtures/print-only-emitter half of the walk work,
built AFTER chunk 3 landed LC/SC (the per-land-cell interleave).

B1 — the emitter (print-only, never gates admission/depth/order):
- ACDREAM_DUMP_WALK_TRANSCRIPT=1 is read once into RuntimeOptions.DumpWalkTranscript
  (rule 4) and handed to RenderingDiagnostics.DumpWalkTranscriptEnabled (rule 5,
  a settable static, not a second env read) once at GameWindow construction — the
  deep walk call sites have no reachable RuntimeOptions reference.
- WalkTranscriptDump (new) prints the OH line kinds — F/P/LS/LC/SC/BLD/DI/DC/EC/OC —
  to Console at the exact points retail's cdb breakpoints sit
  (tools/walk-oracle/oh/oh-capture-walk.cdb.template), gated internally so every
  method bails out before any string work when the flag is off.
- Every call site lives in WalkFrameDriver.cs, at the point the driver already
  processes that turn: Collect (F/P, after BeginFrame), Emit's DI/LS/DC/BLD cases,
  OnLandCellTurn/OnLandscapeCellTurn (LC/SC, at LOD resolution via the new
  WalkTranscriptDump.LodCellId helper, before the 8x8-bucket expansion), and the
  EmitFloodTurns/EmitCellContentsTurn loops (EC/OC — both UNCONDITIONAL per flood
  visit, matching the OH captures' always-equal EC/OC counts; retail's own
  DrawEnvCell stamp dedupe sits past the breakpoint, inside the function).
- DC's "pv=" field encodes interior(0)/outdoor(1) as an 8-hex-digit 0/1 so it
  satisfies the same pv=[0-9a-f]{8} regex real captures use; derived from
  _currentDcStage at the DC event (CellStatic = interior pview, else outdoor).
- The frame-root pose (origin, quaternion) is a reasonable orthonormal basis built
  from the walk's own CyPlane.Normal forward vector and WalkLandscape's own
  ViewerWorldOriginX/Y block origin — self-consistent for the round-trip parser,
  not a byte-exact reproduction of retail's Frame (B4's diff never compares P).

B2 — WalkOracleTrace learns EC/OC event kinds (LC/SC already existed from chunk 3).
New WalkOraclePartsTrace.cs holds two small read-only parsers for the parts log
(PD/DM) and the alpha-depth log (AM/FL/PM/PC) — records only, no validator, no
canonical JSONL, no new tool.

B3 — fixtures: the five OH walk captures join WalkOracleTraceTests.AllFixtures
(now (root, name) pairs — FW0's own root plus the OH capture directory) for
parse + complete-frame pins. The four kit poses join WalkTraceConformanceTests'
still-fixture coverage as NEW rows (the OH cathedral-arrival root is f4180108,
not FW0's f4180106): terrace-edge/cathedral-arrival extend the existing theory
(now (root, fixture) parameterized); holtburg-doorway-still and foundry-deep get
dedicated tests mirroring their FW0 siblings' own structure. Finding: the OH
foundry-deep capture's own retail transcript draws 12 real town buildings through
its exit chain (unlike the FW0 capture, which apparently reached none at that
pose) — the FW0 test's stub 1x1 landscape undershoots it (first divergence:
nothing after "LS" vs retail's real BLD content); fixed by building the full
landscape/building world via WalkLandscapeDatBuilder.Build, matching the shared
theory's own approach, not by skipping or weakening the row.
WalkTraceReplayContext.Signature(WalkOracleFrame) now filters to the DI/DC/BLD/LS
kinds (LC/SC/EC/OC never had a WalkEvent analogue in RetailFrameWalk's own
four-kind vocabulary) instead of mapping them to a "?" placeholder, so the still-
fixture comparison stays apples-to-apples on both sides.

B4 — WalkTranscriptSignatureDiff (test-side only, no runner/tool): diffs two
transcripts (raw lines or parsed frames) at the full DI/DC/BLD/LS/LC/SC/EC/OC
level, reporting the first divergent event and position per frame. Proven over a
synthetic self-vs-self-minus-one-event pair (SignatureDiff_ReportsTheExactRemovedEvent).

Tests: T1 (flag off) is split into a unit-level zero-allocation/zero-output check
on WalkTranscriptDump itself (the walk's pre-existing allocation, e.g.
RetailFrameWalk.EmitDrawCells's per-call array, is untouched by this chunk and not
independently zero-alloc) and an integration-level Collect() check; both assert via
WalkOracleTrace.Parse returning zero frames rather than raw string equality, which
is robust to unrelated Console.WriteLine noise from other test classes running in
parallel (a real, observed hazard — WalkFrameDriverTests joins
CameraDiagnosticsCollection for the same reason CornerFloodReplayTests/
Issue181WallPressEquilibriumTests already do, issue #251). T2 proves the
emitter/parser round trip on a synthetic interior frame. T3's InstalledDat rows all
pass. T4: LaunchOptionsDocumentationTests green with the ACDREAM_DUMP_WALK_TRANSCRIPT
row (both directions).

Gates: hermetic lane 6,814/0 (was 6,795 baseline + new tests), three consecutive
clean runs; InstalledDat lane 245/3 known-failures (the two pre-existing #383
layout tests + TowerAscent) unchanged from baseline.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Erik 2026-09-03 10:48:41 +02:00
parent e813aa1f45
commit 02a8288172
17 changed files with 1267 additions and 22 deletions

View file

@ -31,8 +31,12 @@ namespace AcDream.App.Tests.Rendering;
/// <item><description><c>AcDream.Core.Rendering.RenderingDiagnostics.ProbeFlapEnabled</c>
/// — written by <c>CornerFloodReplayTests</c> and
/// <c>Issue181WallPressEquilibriumTests</c>.</description></item>
/// <item><description><c>AcDream.Core.Rendering.RenderingDiagnostics.DumpWalkTranscriptEnabled</c>
/// (Campaign OVERHAUL S3 chunk 1) — written by
/// <c>WalkFrameDriverTests</c>' transcript-emitter tests
/// (<c>WalkFrameDriverTranscriptTests.cs</c>).</description></item>
/// <item><description><c>System.Console.Out</c> — redirected via
/// <c>Console.SetOut</c> by those same two classes to capture probe output.
/// <c>Console.SetOut</c> by those same classes to capture probe output.
/// Interleaved redirection can restore a DISPOSED <c>StringWriter</c> as the
/// process-wide <c>Console.Out</c>, which then throws in unrelated
/// tests.</description></item>

View file

@ -33,7 +33,7 @@ namespace AcDream.App.Tests.Rendering.Walk;
/// still does not construct this driver); every world-data/leaf-renderer
/// dependency here is a synthetic fake per plan §FW3.2b-1.
/// </summary>
public sealed class WalkFrameDriverTests
public sealed partial class WalkFrameDriverTests
{
// ── Shared ordered log: BOTH the fake leaf renderer and the fake trace
// write into ONE list, so a single sequence assertion proves the FULL

View file

@ -0,0 +1,344 @@
using System.Numerics;
using AcDream.App.Rendering;
using AcDream.App.Rendering.Gpu;
using AcDream.App.Rendering.Walk;
using AcDream.App.Tests.Rendering;
using AcDream.Core.Rendering;
namespace AcDream.App.Tests.Rendering.Walk;
/// <summary>
/// Campaign OVERHAUL S3 chunk 1 (§11.2): tests T1/T2 for the print-only walk
/// transcript emitter (<see cref="WalkTranscriptDump"/>, gated by
/// <see cref="RenderingDiagnostics.DumpWalkTranscriptEnabled"/>), plus the
/// §11.2 B4 offline signature-diff self-check. Reuses
/// <see cref="WalkFrameDriverTests"/>'s own private fixture types via the
/// shared <c>partial class</c> — the SAME minimal interior two-cell flood
/// (one exit view) that file's own
/// <c>RunFrame_InteriorFloodWithExitView_FreshDriverSkipsTheGatedClearThenDrawsSealsAndFloodCells</c>
/// test already exercises and proves correct; here only
/// <see cref="WalkFrameDriver.Collect"/> runs (no <c>Replay</c>/GPU
/// submission), since every transcript print fires synchronously during the
/// walk itself.
///
/// <para>
/// <see cref="RenderingDiagnostics.DumpWalkTranscriptEnabled"/> and
/// <see cref="Console.Out"/> are both process-wide mutable statics — joins
/// <see cref="CameraDiagnosticsCollection"/> for the SAME reason
/// <c>CornerFloodReplayTests</c>/<c>Issue181WallPressEquilibriumTests</c> do
/// (that collection's own doc comment, issue #251): interleaved
/// <c>Console.SetOut</c> redirection across parallel test classes can
/// restore a disposed <see cref="StringWriter"/> process-wide.
/// </para>
/// </summary>
[Collection(CameraDiagnosticsCollection.Name)]
public sealed partial class WalkFrameDriverTests
{
private static (WalkCell Cell1, WalkCell Cell2) BuildTranscriptFixtureCells(TestContext ctx)
{
var cell1 = new WalkCell
{
CellId = 0x100,
StabList = [0x101u],
Portals =
[
new WalkCellPortal
{
OtherCellId = 0x101, PolygonIndex = 0, PortalSide = 0, OtherPortalId = 0,
},
// The exit portal — raises ov to 1, so the flood draws the
// (empty, zero-block) landscape too, exercising LS.
new WalkCellPortal
{
OtherCellId = 0xFFFFFFFF, PolygonIndex = 1, PortalSide = 0, OtherPortalId = -1,
},
],
PortalPolygons = [Quad(-2f), Quad(-3f)],
};
var cell2 = new WalkCell
{
CellId = 0x101,
Portals = [new WalkCellPortal
{
OtherCellId = 0x100, PolygonIndex = 0, PortalSide = 1, OtherPortalId = 0,
}],
PortalPolygons = [Quad(-2f)],
};
ctx.Cells[cell1.CellId] = cell1;
ctx.Cells[cell2.CellId] = cell2;
return (cell1, cell2);
}
/// <summary>T1 (§11.3): the flag off — zero output, and the emitter's
/// own methods (the only code this chunk adds to the walk path)
/// allocate nothing. The walk itself is NOT independently zero-alloc
/// (e.g. <c>RetailFrameWalk.EmitDrawCells</c> allocates its cell-id
/// array on every call — pre-existing, unrelated to this chunk), so the
/// allocation bound below is scoped to <see cref="WalkTranscriptDump"/>
/// itself, matching B1's actual contract ("allocates nothing EXTRA").</summary>
[Fact]
public void TranscriptEmitter_FlagOff_EveryPrintMethodIsAZeroCostNoOp()
{
bool previous = RenderingDiagnostics.DumpWalkTranscriptEnabled;
RenderingDiagnostics.DumpWalkTranscriptEnabled = false;
TextWriter originalOut = Console.Out;
var capture = new StringWriter();
try
{
Console.SetOut(capture);
var cells = new List<uint> { 0x100u, 0x101u };
void Step()
{
WalkTranscriptDump.PrintFrameRoot(1, 0x100u, Vector3.Zero, Vector3.UnitY);
WalkTranscriptDump.PrintLandscape();
WalkTranscriptDump.PrintBuilding(0x100u);
WalkTranscriptDump.PrintDrawInside(0x100u);
WalkTranscriptDump.PrintDrawCells(outdoorPview: false, 1, cells);
WalkTranscriptDump.PrintLandCell(0xF4180001u);
WalkTranscriptDump.PrintSortCell(0xF4180001u);
WalkTranscriptDump.PrintEnvCellShell(0x101u);
WalkTranscriptDump.PrintObjectCellTurn(0x101u);
}
ZeroAllocationProbe.AssertAllocatesNothing(
"WalkTranscriptDump.Print* (flag off)", Step);
AssertNoTranscriptLines(capture);
}
finally
{
Console.SetOut(originalOut);
RenderingDiagnostics.DumpWalkTranscriptEnabled = previous;
}
}
/// <summary>T1's integration half: a full synthetic interior frame,
/// driven through the SAME <see cref="WalkFrameDriver.Collect"/> path
/// production uses, produces literally NO transcript output when the
/// flag is off.</summary>
[Fact]
public void Collect_TranscriptFlagOff_ProducesNoConsoleOutput()
{
bool previous = RenderingDiagnostics.DumpWalkTranscriptEnabled;
RenderingDiagnostics.DumpWalkTranscriptEnabled = false;
TextWriter originalOut = Console.Out;
var capture = new StringWriter();
try
{
Console.SetOut(capture);
using var fx = new DispatcherFixture();
var ctx = new TestContext();
(WalkCell cell1, _) = BuildTranscriptFixtureCells(ctx);
var landscape = new WalkLandscape { MidWidth = 1, Blocks = new WalkLandBlock?[1] };
var worldData = new FakeWorldData();
var leaf = new RecordingLeafRenderer(new List<string>());
using ClipFrame clipFrame = ClipFrame.NoClip();
var driver = new WalkFrameDriver(fx.Dispatcher, leaf, worldData, clipFrame: clipFrame);
var walk = new RetailFrameWalk();
driver.Collect(
walk, cell1.CellId, cell1, landscape, ctx, Matrix4x4.Identity, Vector3.Zero);
AssertNoTranscriptLines(capture);
}
finally
{
Console.SetOut(originalOut);
RenderingDiagnostics.DumpWalkTranscriptEnabled = previous;
}
}
/// <summary>
/// Asserts NONE of <see cref="WalkTranscriptDump"/>'s own line kinds
/// appear in <paramref name="capture"/> — robust to unrelated
/// <see cref="Console"/> noise from another test class running in
/// parallel (a real, observed hazard: xUnit runs distinct classes
/// concurrently by default, and <see cref="Console.Out"/> is a
/// process-wide static — see <c>CameraDiagnosticsCollection</c>'s own
/// doc comment, issue #251). A plain <c>Assert.Empty(capture.ToString())</c>
/// is NOT this robust: an unrelated class's unconditional
/// <c>Console.WriteLine</c> can land inside this test's redirect window
/// and fail it for a reason that has nothing to do with the transcript
/// flag. <see cref="WalkOracleTrace.Parse"/> only ever appends a frame
/// once it sees a well-formed <c>F &lt;n&gt;</c> marker line — arbitrary
/// unrelated text can never satisfy that regex, so a truly EMPTY parsed
/// frame list is exactly as strong a proof that THIS code printed
/// nothing, without being sensitive to what else shares the process
/// console.
/// </summary>
private static void AssertNoTranscriptLines(StringWriter capture)
{
string[] lines = capture.ToString()
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
.Select(l => l.TrimEnd('\r'))
.ToArray();
Assert.Empty(WalkOracleTrace.Parse(lines));
}
/// <summary>T2 (§11.3): flag on, one synthetic interior frame — the
/// printed lines parse with the extended <see cref="WalkOracleTrace"/>
/// into the same events the driver recorded (emitter/parser round
/// trip). Asserted structurally (kinds, cell ids, counts) rather than
/// against a hand-predicted exact ordering, so the test does not
/// silently pin an assumption about traversal order it never
/// independently verified.</summary>
[Fact]
public void Collect_TranscriptFlagOn_PrintedLinesRoundTripThroughTheParser()
{
bool previous = RenderingDiagnostics.DumpWalkTranscriptEnabled;
RenderingDiagnostics.DumpWalkTranscriptEnabled = true;
TextWriter originalOut = Console.Out;
var capture = new StringWriter();
try
{
Console.SetOut(capture);
using var fx = new DispatcherFixture();
var ctx = new TestContext();
(WalkCell cell1, WalkCell cell2) = BuildTranscriptFixtureCells(ctx);
var landscape = new WalkLandscape { MidWidth = 1, Blocks = new WalkLandBlock?[1] };
var worldData = new FakeWorldData();
var leaf = new RecordingLeafRenderer(new List<string>());
using ClipFrame clipFrame = ClipFrame.NoClip();
var driver = new WalkFrameDriver(fx.Dispatcher, leaf, worldData, clipFrame: clipFrame);
var walk = new RetailFrameWalk();
// Two Collect calls: WalkOracleTrace.Parse (like every real
// capture) only flushes a frame once the NEXT "F n" marker
// appears — it deliberately drops the final in-progress frame
// (the detach-frame rule). One frame alone would parse to zero
// complete frames.
driver.Collect(
walk, cell1.CellId, cell1, landscape, ctx, Matrix4x4.Identity, Vector3.Zero);
driver.Collect(
walk, cell1.CellId, cell1, landscape, ctx, Matrix4x4.Identity, Vector3.Zero);
Console.Out.Flush();
string[] lines = capture.ToString()
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
.Select(l => l.TrimEnd('\r'))
.ToArray();
Assert.NotEmpty(lines);
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Parse(lines);
WalkOracleFrame frame = Assert.Single(frames);
Assert.Equal(1, frame.Number);
Assert.NotNull(frame.Pose);
Assert.Equal(cell1.CellId, frame.Pose!.CellId);
Assert.Equal(cell1.CellId, frame.InteriorRootCell);
Assert.True(frame.HasLandscape);
WalkOracleEvent dc = Assert.Single(
frame.Events, e => e.Kind == WalkOracleEventKind.DrawCells);
Assert.Equal(1, dc.OutsideViewCount);
Assert.Equal(
new HashSet<uint> { cell1.CellId, cell2.CellId },
dc.Cells.ToHashSet());
// The interior root's own flood visits both cells for a shell
// AND an object-list turn — EC/OC pair, one line per cell, no
// dedupe (WalkTranscriptDump.PrintEnvCellShell's own doc
// comment: EC/OC counts are always exactly equal per pose).
List<uint> ec = frame.Events
.Where(e => e.Kind == WalkOracleEventKind.EnvCellShell)
.Select(e => e.CellId!.Value).ToList();
List<uint> oc = frame.Events
.Where(e => e.Kind == WalkOracleEventKind.ObjectCellTurn)
.Select(e => e.CellId!.Value).ToList();
Assert.Equal(new HashSet<uint> { cell1.CellId, cell2.CellId }, ec.ToHashSet());
Assert.Equal(new HashSet<uint> { cell1.CellId, cell2.CellId }, oc.ToHashSet());
Assert.Equal(2, ec.Count);
Assert.Equal(2, oc.Count);
// No landblocks were published (the stub 1x1 landscape), so no
// LC/SC/BLD turns exist this frame — the transcript format for
// those three kinds is proven separately, against real retail
// data, by WalkOracleTraceTests.AllFixtures and
// WalkLandCellOrderTests.
Assert.DoesNotContain(frame.Events, e => e.Kind
is WalkOracleEventKind.LandCell or WalkOracleEventKind.SortCell
or WalkOracleEventKind.Building);
}
finally
{
Console.SetOut(originalOut);
RenderingDiagnostics.DumpWalkTranscriptEnabled = previous;
}
}
/// <summary>§11.2 B4: the offline signature diff, self-checked over a
/// synthetic pair — the SAME captured T2 transcript versus itself with
/// its own LAST event removed. Reuses <c>Collect_TranscriptFlagOn_…</c>'s
/// own capture rather than duplicating the walk drive.</summary>
[Fact]
public void SignatureDiff_ReportsTheExactRemovedEvent()
{
bool previous = RenderingDiagnostics.DumpWalkTranscriptEnabled;
RenderingDiagnostics.DumpWalkTranscriptEnabled = true;
TextWriter originalOut = Console.Out;
var capture = new StringWriter();
try
{
Console.SetOut(capture);
using var fx = new DispatcherFixture();
var ctx = new TestContext();
(WalkCell cell1, _) = BuildTranscriptFixtureCells(ctx);
var landscape = new WalkLandscape { MidWidth = 1, Blocks = new WalkLandBlock?[1] };
var worldData = new FakeWorldData();
var leaf = new RecordingLeafRenderer(new List<string>());
using ClipFrame clipFrame = ClipFrame.NoClip();
var driver = new WalkFrameDriver(fx.Dispatcher, leaf, worldData, clipFrame: clipFrame);
var walk = new RetailFrameWalk();
// Two Collect calls — see the round-trip test's own comment on
// why one alone parses to zero complete frames.
driver.Collect(
walk, cell1.CellId, cell1, landscape, ctx, Matrix4x4.Identity, Vector3.Zero);
driver.Collect(
walk, cell1.CellId, cell1, landscape, ctx, Matrix4x4.Identity, Vector3.Zero);
Console.Out.Flush();
string[] lines = capture.ToString()
.Split('\n', StringSplitOptions.RemoveEmptyEntries)
.Select(l => l.TrimEnd('\r'))
.ToArray();
IReadOnlyList<WalkOracleFrame> expected = WalkOracleTrace.Parse(lines);
WalkOracleFrame expectedFrame = Assert.Single(expected);
Assert.NotEmpty(expectedFrame.Events);
// Self-vs-self (unmutated copy): no divergence at all.
IReadOnlyList<WalkOracleFrame> unchanged =
[expectedFrame with { Events = expectedFrame.Events.ToList() }];
Assert.Null(WalkTranscriptSignatureDiff.FirstDivergence(expected, unchanged));
// Self-vs-self-minus-one (the LAST event removed): the reported
// divergence is exact — same frame number, position exactly at
// the new (shorter) end, expected = the removed event's own
// signature string, actual = "<end of frame>".
int lastIndex = expectedFrame.Events.Count - 1;
List<WalkOracleEvent> truncated = expectedFrame.Events.Take(lastIndex).ToList();
IReadOnlyList<WalkOracleFrame> actual =
[expectedFrame with { Events = truncated }];
WalkTranscriptSignatureDiff.Divergence? divergence =
WalkTranscriptSignatureDiff.FirstDivergence(expected, actual);
Assert.NotNull(divergence);
Assert.Equal(expectedFrame.Number, divergence!.Value.FrameNumber);
Assert.Equal(lastIndex, divergence.Value.Position);
Assert.Equal("<end of frame>", divergence.Value.Actual);
Assert.NotEqual("<end of frame>", divergence.Value.Expected);
}
finally
{
Console.SetOut(originalOut);
RenderingDiagnostics.DumpWalkTranscriptEnabled = previous;
}
}
}

View file

@ -0,0 +1,273 @@
using System.Globalization;
using System.Text.RegularExpressions;
namespace AcDream.App.Tests.Rendering.Walk;
/// <summary>
/// S3 chunk 1 (§11.2 B2): small, read-only parsers for the OH capture
/// family's two companion logs — the PARTS log
/// (<c>tools/walk-oracle/oh/oh-capture-parts.cdb.template</c>: PD/DM) and
/// the ALPHA-DEPTH log
/// (<c>tools/walk-oracle/oh/oh-capture-alpha-depth.cdb.template</c>: AM/FL/
/// PM/PC), both dumped from the SAME <c>docs/research/2026-09-01-overhaul/
/// oh-capture/</c> directory as the walk log <see cref="WalkOracleTrace"/>
/// already parses. These are records only — no validator, no canonical
/// JSONL, no new tool ([[feedback-evidence-infrastructure-sink]]) — a later
/// chunk/S4 names the first real consumer and pins specific values then.
/// </summary>
public static class WalkOraclePartsTrace
{
/// <summary>Parses a PARTS log (<c>&lt;pose&gt;.parts.log</c>). Same
/// F/P framing and truncated-last-frame drop rule as
/// <see cref="WalkOracleTrace.Parse"/> — the harness detaches at the
/// frame marker, so the final "F n" never records its own PD/DM lines.</summary>
public static IReadOnlyList<WalkOraclePartsFrame> Parse(IEnumerable<string> lines)
{
var frames = new List<WalkOraclePartsFrame>();
List<WalkOraclePartDraw>? partDraws = null;
List<WalkOracleMeshDraw>? meshDraws = null;
int currentNumber = 0;
foreach (string line in lines)
{
Match frameMatch = FramePattern.Match(line);
if (frameMatch.Success)
{
if (partDraws is not null)
{
frames.Add(new WalkOraclePartsFrame(currentNumber, partDraws, meshDraws!));
}
currentNumber = int.Parse(
frameMatch.Groups[1].Value, CultureInfo.InvariantCulture);
partDraws = new List<WalkOraclePartDraw>();
meshDraws = new List<WalkOracleMeshDraw>();
continue;
}
if (partDraws is null)
continue;
Match pd = PartDrawPattern.Match(line);
if (pd.Success)
{
partDraws.Add(new WalkOraclePartDraw(
ParseHex(pd.Groups[1].Value),
ParseHex(pd.Groups[2].Value),
pd.Groups[3].Value != "0",
ParseHex(pd.Groups[4].Value)));
continue;
}
Match dm = MeshDrawPattern.Match(line);
if (dm.Success)
{
meshDraws!.Add(new WalkOracleMeshDraw(
ParseHex(dm.Groups[1].Value),
ParseHex(dm.Groups[2].Value),
dm.Groups[3].Value != "0",
int.Parse(dm.Groups[4].Value, CultureInfo.InvariantCulture),
ParseHex(dm.Groups[5].Value)));
continue;
}
// Anything else (the "P …" pose line included — parts fixtures
// carry no pose consumer today) is ignored, matching
// WalkOracleTrace's own "cdb chrome" tolerance.
}
return frames;
}
public static IReadOnlyList<WalkOraclePartsFrame> Load(string root, string fixtureName)
=> Parse(File.ReadLines(FixturePath(root, fixtureName, ".parts.log")));
private static string FixturePath(string root, string fixtureName, string suffix)
{
string repoRoot = WalkOracleTraceRepoRoot.Find();
return Path.Combine(
repoRoot, Path.Combine(root.Split('/')), fixtureName + suffix);
}
private static uint ParseHex(string hex)
=> uint.Parse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
private static readonly Regex FramePattern = new(@"^F (\d+)\s*$", RegexOptions.Compiled);
// PD gfx=<hex8> did=<hex8> force=<0|1> cell=<hex8>
private static readonly Regex PartDrawPattern = new(
@"^PD gfx=([0-9a-f]{8}) did=([0-9a-f]{8}) force=(\d) cell=([0-9a-f]{8})\s*$",
RegexOptions.Compiled);
// DM gfx=<hex8> did=<hex8> force=<0|1> bound=<0|1|2> cell=<hex8>
private static readonly Regex MeshDrawPattern = new(
@"^DM gfx=([0-9a-f]{8}) did=([0-9a-f]{8}) force=(\d) bound=(\d) cell=([0-9a-f]{8})\s*$",
RegexOptions.Compiled);
}
/// <summary>One <c>CPhysicsPart::Draw</c> @0x0050D7A0 entry (PD line).</summary>
public sealed record WalkOraclePartDraw(uint Gfx, uint DataId, bool Force, uint Cell);
/// <summary>One <c>RenderDeviceD3D::DrawMeshInternal</c> @0x0059F360 entry
/// (DM line). <paramref name="Bound"/> is retail's BoundingType (0=OUTSIDE,
/// 1=PARTIALLY_INSIDE, 2=ENTIRELY_INSIDE).</summary>
public sealed record WalkOracleMeshDraw(uint Gfx, uint DataId, bool Force, int Bound, uint Cell);
public sealed record WalkOraclePartsFrame(
int Number,
IReadOnlyList<WalkOraclePartDraw> PartDraws,
IReadOnlyList<WalkOracleMeshDraw> MeshDraws);
/// <summary>
/// S3 chunk 1 (§11.2 B2): parses an ALPHA-DEPTH log
/// (<c>&lt;pose&gt;.alphadepth.log</c>). Same F/P framing and
/// truncated-last-frame drop rule as <see cref="WalkOracleTrace.Parse"/>.
/// </summary>
public static class WalkOracleAlphaDepthTrace
{
public static IReadOnlyList<WalkOracleAlphaDepthFrame> Parse(IEnumerable<string> lines)
{
var frames = new List<WalkOracleAlphaDepthFrame>();
List<WalkOracleAlphaMeshAdd>? meshAdds = null;
List<WalkOracleAlphaFlush>? flushes = null;
List<WalkOraclePortalPolyDraw>? portalPolyDraws = null;
List<WalkOracleDrawCellsSample>? drawCellsSamples = null;
int currentNumber = 0;
foreach (string line in lines)
{
Match frameMatch = FramePattern.Match(line);
if (frameMatch.Success)
{
if (meshAdds is not null)
{
frames.Add(new WalkOracleAlphaDepthFrame(
currentNumber, meshAdds, flushes!, portalPolyDraws!, drawCellsSamples!));
}
currentNumber = int.Parse(
frameMatch.Groups[1].Value, CultureInfo.InvariantCulture);
meshAdds = new List<WalkOracleAlphaMeshAdd>();
flushes = new List<WalkOracleAlphaFlush>();
portalPolyDraws = new List<WalkOraclePortalPolyDraw>();
drawCellsSamples = new List<WalkOracleDrawCellsSample>();
continue;
}
if (meshAdds is null)
continue;
Match am = MeshAddPattern.Match(line);
if (am.Success)
{
meshAdds.Add(new WalkOracleAlphaMeshAdd(
ParseHex(am.Groups[1].Value),
int.Parse(am.Groups[2].Value, CultureInfo.InvariantCulture),
ParseHex(am.Groups[3].Value),
am.Groups[4].Value != "0",
am.Groups[5].Value != "0",
int.Parse(am.Groups[6].Value, CultureInfo.InvariantCulture)));
continue;
}
Match fl = FlushPattern.Match(line);
if (fl.Success)
{
flushes!.Add(new WalkOracleAlphaFlush(
ParseHex(fl.Groups[1].Value), ParseHex(fl.Groups[2].Value)));
continue;
}
Match pm = PortalPolyPattern.Match(line);
if (pm.Success)
{
portalPolyDraws!.Add(new WalkOraclePortalPolyDraw(
ParseHex(pm.Groups[1].Value),
int.Parse(pm.Groups[2].Value, CultureInfo.InvariantCulture),
int.Parse(pm.Groups[3].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture)));
continue;
}
Match pc = DrawCellsSamplePattern.Match(line);
if (pc.Success)
{
drawCellsSamples!.Add(new WalkOracleDrawCellsSample(
int.Parse(pc.Groups[1].Value, CultureInfo.InvariantCulture),
int.Parse(pc.Groups[2].Value, NumberStyles.HexNumber, CultureInfo.InvariantCulture),
pc.Groups[3].Value != "0"));
continue;
}
}
return frames;
}
public static IReadOnlyList<WalkOracleAlphaDepthFrame> Load(string root, string fixtureName)
=> Parse(File.ReadLines(Path.Combine(
WalkOracleTraceRepoRoot.Find(),
Path.Combine(root.Split('/')),
fixtureName + ".alphadepth.log")));
private static uint ParseHex(string hex)
=> uint.Parse(hex, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
private static readonly Regex FramePattern = new(@"^F (\d+)\s*$", RegexOptions.Compiled);
// AM mesh=<hex8> surf=<n> csurf=<hex8> new=<0|1> clip=<0|1> listSel=<n>
private static readonly Regex MeshAddPattern = new(
@"^AM mesh=([0-9a-f]{8}) surf=(\d+) csurf=([0-9a-f]{8}) new=(\d) clip=(\d) listSel=(\d+)\s*$",
RegexOptions.Compiled);
// FL thresh=<hex8> ret=<hex8>
private static readonly Regex FlushPattern = new(
@"^FL thresh=([0-9a-f]{8}) ret=([0-9a-f]{8})\s*$", RegexOptions.Compiled);
// PM poly=<hex8> mode=<n> counterBefore=<hex4>
private static readonly Regex PortalPolyPattern = new(
@"^PM poly=([0-9a-f]{8}) mode=(\d) counterBefore=([0-9a-f]{4})\s*$",
RegexOptions.Compiled);
// PC ov=<n> counter=<hex4> fc=<0|1>
private static readonly Regex DrawCellsSamplePattern = new(
@"^PC ov=(\d+) counter=([0-9a-f]{4}) fc=(\d)\s*$", RegexOptions.Compiled);
}
/// <summary>One <c>D3DPolyRender::AddMeshToAlphaList</c> @0x0059C230 entry
/// (AM line). <paramref name="ListSelector"/> 0 selects the ALPHA list,
/// nonzero the CLIP list.</summary>
public sealed record WalkOracleAlphaMeshAdd(
uint Mesh, int Surface, uint ClipSurface, bool New, bool Clip, int ListSelector);
/// <summary>One <c>D3DPolyRender::FlushAlphaList</c> @0x0059D2E0 entry (FL
/// line). <paramref name="ThresholdBits"/> is the raw IEEE-754 bits of the
/// threshold float argument.</summary>
public sealed record WalkOracleAlphaFlush(uint ThresholdBits, uint ReturnAddress);
/// <summary>One <c>D3DPolyRender::DrawPortalPolyInternal</c> @0x0059BC90
/// entry (PM line). <paramref name="Mode"/> 0 = true-depth/exit-seal,
/// nonzero = far-Z/building punch.</summary>
public sealed record WalkOraclePortalPolyDraw(uint Poly, int Mode, int CounterBefore);
/// <summary>One <c>PView::DrawCells</c> @0x005A4840 entry, sampled for the
/// persistent <c>portalsDrawnCount</c> depth-lifecycle state machine (PC
/// line) — same breakpoint address as the walk log's DC line, but this is a
/// SEPARATE capture that does not also record the cell roster.</summary>
public sealed record WalkOracleDrawCellsSample(int OutsideViewCount, int Counter, bool ForceClear);
public sealed record WalkOracleAlphaDepthFrame(
int Number,
IReadOnlyList<WalkOracleAlphaMeshAdd> MeshAdds,
IReadOnlyList<WalkOracleAlphaFlush> Flushes,
IReadOnlyList<WalkOraclePortalPolyDraw> PortalPolyDraws,
IReadOnlyList<WalkOracleDrawCellsSample> DrawCellsSamples);
/// <summary>Shared repo-root finder — the SAME walk-up-to-<c>AcDream.slnx</c>
/// logic <see cref="WalkOracleTrace"/> already has privately; factored out
/// so the parts/alpha-depth parsers don't duplicate it a second and third
/// time.</summary>
internal static class WalkOracleTraceRepoRoot
{
internal static string Find()
{
DirectoryInfo? dir = new(AppContext.BaseDirectory);
while (dir is not null)
{
if (File.Exists(Path.Combine(dir.FullName, "AcDream.slnx")))
return dir.FullName;
dir = dir.Parent;
}
throw new InvalidOperationException(
"AcDream.slnx not found above the test base directory; walk-oracle fixtures unavailable.");
}
}

View file

@ -0,0 +1,51 @@
namespace AcDream.App.Tests.Rendering.Walk;
/// <summary>
/// S3 chunk 1 (§11.2 B2/B3): proves the parts/alpha-depth readers actually
/// parse the five committed OH captures — "imported and parsed", not just
/// compiled. No content is pinned (§11.2 B3: "pinned only where a later
/// chunk/S4 names a consumer — no speculative assertions"); this is the
/// same non-empty/complete-frame shape
/// <c>WalkOracleTraceTests.Fixture_parses_with_complete_frames</c> already
/// applies to the walk logs.
/// </summary>
public sealed class WalkOraclePartsTraceTests
{
private const string OhRoot = "docs/research/2026-09-01-overhaul/oh-capture";
public static readonly TheoryData<string> AllPoses = new()
{
"holtburg-doorway-still",
"terrace-edge",
"cathedral-arrival",
"foundry-deep",
"cathedral-leak",
};
[Theory]
[MemberData(nameof(AllPoses))]
public void Parts_log_parses_with_nonempty_draws(string pose)
{
IReadOnlyList<WalkOraclePartsFrame> frames = WalkOraclePartsTrace.Load(OhRoot, pose);
Assert.NotEmpty(frames);
Assert.Equal(1, frames[0].Number);
Assert.Equal(frames.Count, frames[^1].Number);
Assert.Contains(frames, f => f.PartDraws.Count > 0);
Assert.Contains(frames, f => f.MeshDraws.Count > 0);
}
[Theory]
[MemberData(nameof(AllPoses))]
public void Alpha_depth_log_parses_with_nonempty_samples(string pose)
{
IReadOnlyList<WalkOracleAlphaDepthFrame> frames =
WalkOracleAlphaDepthTrace.Load(OhRoot, pose);
Assert.NotEmpty(frames);
Assert.Equal(1, frames[0].Number);
Assert.Equal(frames.Count, frames[^1].Number);
Assert.Contains(frames, f => f.Flushes.Count > 0);
Assert.Contains(frames, f => f.DrawCellsSamples.Count > 0);
}
}

View file

@ -110,6 +110,22 @@ public static class WalkOracleTrace
current.Add(WalkOracleEvent.SortCell(ParseId(sortCellMatch.Groups[1].Value)));
continue;
}
// S3 chunk 1 (§11.2 B2): EC/OC — RenderDeviceD3D::DrawEnvCell
// 0x0059f170 / DrawObjCellForDummies 0x005a0760, added to the OH
// capture templates 2026-09-02
// (tools/walk-oracle/oh/oh-capture-walk.cdb.template).
Match envCellMatch = EnvCellShellPattern.Match(line);
if (envCellMatch.Success)
{
current.Add(WalkOracleEvent.EnvCellShell(ParseId(envCellMatch.Groups[1].Value)));
continue;
}
Match objCellMatch = ObjectCellTurnPattern.Match(line);
if (objCellMatch.Success)
{
current.Add(WalkOracleEvent.ObjectCellTurn(ParseId(objCellMatch.Groups[1].Value)));
continue;
}
// Anything else is cdb chrome (banner, prompts, symbol notes) — ignored.
}
@ -160,6 +176,8 @@ public static class WalkOracleTrace
@"^DC pv=[0-9a-f]{8} ov=(\d+) n=(\d+):((?: [0-9a-f]{8})*)\s*$", RegexOptions.Compiled);
private static readonly Regex LandCellPattern = new(@"^LC ([0-9a-f]{8})\s*$", RegexOptions.Compiled);
private static readonly Regex SortCellPattern = new(@"^SC ([0-9a-f]{8})\s*$", RegexOptions.Compiled);
private static readonly Regex EnvCellShellPattern = new(@"^EC ([0-9a-f]{8})\s*$", RegexOptions.Compiled);
private static readonly Regex ObjectCellTurnPattern = new(@"^OC ([0-9a-f]{8})\s*$", RegexOptions.Compiled);
}
/// <summary>The camera pose dumped at the frame marker (raw dwords from
@ -204,6 +222,16 @@ public enum WalkOracleEventKind
/// <summary>S3 chunk 3: <c>SC &lt;cellid&gt;</c> — <c>RenderDeviceD3D::
/// DrawSortCell</c> @0x0059f140 entry.</summary>
SortCell,
/// <summary>S3 chunk 1 (§11.2 B2): <c>EC &lt;cellid&gt;</c> —
/// <c>RenderDeviceD3D::DrawEnvCell</c> @0x0059f170 entry (one cell
/// SHELL draw).</summary>
EnvCellShell,
/// <summary>S3 chunk 1 (§11.2 B2): <c>OC &lt;cellid&gt;</c> —
/// <c>RenderDeviceD3D::DrawObjCellForDummies</c> @0x005a0760 entry (one
/// cell OBJECT-LIST turn).</summary>
ObjectCellTurn,
}
public sealed record WalkOracleEvent(
@ -231,4 +259,10 @@ public sealed record WalkOracleEvent(
public static WalkOracleEvent SortCell(uint cellId)
=> new(WalkOracleEventKind.SortCell, cellId, 0, 0, Array.Empty<uint>());
public static WalkOracleEvent EnvCellShell(uint cellId)
=> new(WalkOracleEventKind.EnvCellShell, cellId, 0, 0, Array.Empty<uint>());
public static WalkOracleEvent ObjectCellTurn(uint cellId)
=> new(WalkOracleEventKind.ObjectCellTurn, cellId, 0, 0, Array.Empty<uint>());
}

View file

@ -10,25 +10,43 @@ public sealed class WalkOracleTraceTests
{
private const uint FarBuilding = 0xF518002Eu;
public static readonly TheoryData<string> AllFixtures = new()
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()
{
"terrace-center",
"terrace-edge",
"cathedral-arrival",
"holtburg-doorway-still",
"holtburg-walkout",
"holtburg-street-porchcam",
"holtburg-street-outdoor",
"holtburg-walkabout",
"foundry-entry",
"foundry-deep",
{ 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 name)
public void Fixture_parses_with_complete_frames(string root, string name)
{
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load(name);
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load(root, name);
Assert.NotEmpty(frames);
// Frame numbers are contiguous from 1; the truncated final frame is dropped.

View file

@ -100,13 +100,57 @@ public sealed class WalkTraceConformanceTests
$"walk diverged from retail\nEXPECTED: {expected}\nACTUAL: {actual}");
}
[Theory]
[InlineData("posed/terrace-center")]
[InlineData("posed/terrace-edge")]
[InlineData("posed/cathedral-arrival")]
public void Still_fixture_first_frame_reproduces_exactly(string fixture)
[Fact]
public void Oh_doorway_still_first_frame_diff()
{
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load(fixture);
// S3 chunk 1 (§11.2 B3): the OH kit pose's own doorway-still capture
// — DI f4180108... no, a9b4013f, DC(ov=2, n=3) per §6b. Mirrors
// Doorway_still_first_frame_diff's own structure (this pose needs
// the interior camera cell, unlike the plain outdoor/theory rows).
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load(
"docs/research/2026-09-01-overhaul/oh-capture", "holtburg-doorway-still.walk");
Assert.NotEmpty(frames);
using DatCollection dats = OpenDats();
WalkOracleFrame frame = frames[1];
Assert.NotNull(frame.Pose);
WalkLandscapeDatBuilder.BuiltWorld world =
WalkLandscapeDatBuilder.Build(dats, frame.Pose!.CellId, frame.Pose.Origin);
var ctx = new WalkTraceReplayContext(frame.Pose, world.Cells)
{
Buildings = world.Buildings,
};
WalkCell camera = Assert.Contains(frame.Pose.CellId, world.Cells);
var walk = new RetailFrameWalk();
var recorder = new Recorder();
walk.WalkFrame(frame.Pose.CellId, camera, world.Landscape, ctx, recorder);
string expected = WalkTraceReplayContext.Signature(frame);
string actual = WalkTraceReplayContext.Signature(recorder.Events);
Assert.True(
expected == actual,
$"walk diverged from retail\nEXPECTED: {expected}\nACTUAL: {actual}");
}
private const string FwOracleRoot = "docs/research/2026-08-30-fw-walk-oracle";
/// <summary>S3 chunk 1 (§11.2 B3): the OH capture directory — its OWN
/// pose-stamped kit-pose captures, a DIFFERENT root than the FW0 still
/// fixtures above.</summary>
private const string OhCaptureRoot = "docs/research/2026-09-01-overhaul/oh-capture";
[Theory]
[InlineData(FwOracleRoot, "posed/terrace-center")]
[InlineData(FwOracleRoot, "posed/terrace-edge")]
[InlineData(FwOracleRoot, "posed/cathedral-arrival")]
// S3 chunk 1 (§11.2 B3): the OH kit poses, as NEW rows — the OH
// cathedral-arrival root is f4180108, NOT FW0's f4180106 (a new pose,
// not a replacement of the FW0 row above).
[InlineData(OhCaptureRoot, "terrace-edge.walk")]
[InlineData(OhCaptureRoot, "cathedral-arrival.walk")]
public void Still_fixture_first_frame_reproduces_exactly(string root, string fixture)
{
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load(root, fixture);
Assert.NotEmpty(frames);
using DatCollection dats = OpenDats();
WalkOracleFrame frame = frames[1];
@ -240,4 +284,48 @@ public sealed class WalkTraceConformanceTests
WalkTraceReplayContext.Signature(recorder.Events));
}
}
[Fact]
public void Oh_foundry_deep_reproduces_every_complete_frame_exactly()
{
// S3 chunk 1 (§11.2 B3): the OH kit pose's own foundry-deep capture
// — DI a9b40176, DC(ov=1, n=2), 12 town buildings drawn through the
// surviving exit chain (§6b). UNLIKE the FW0 sibling above, this
// capture's own retail transcript shows real BLD content at that
// depth, so the stub 1x1 landscape (which has no blocks/buildings to
// walk at all) undershoots it — first divergence, run without the
// fix below: "DI:a9b40176|DC:ov=1:a9b40176,a9b40177|LS" (nothing
// after LS) vs retail's "…|LS|BLD:a9b40031|BLD:a9b…" (12 real
// buildings). The full landscape/building assembler
// (WalkLandscapeDatBuilder.Build — the SAME one the shared theory
// and Oh_doorway_still_first_frame_diff use) reproduces them; the
// camera is stationary across this still pose, so one build serves
// every frame in the loop, matching the FW0 sibling's "build once"
// shape.
IReadOnlyList<WalkOracleFrame> frames = WalkOracleTrace.Load(
"docs/research/2026-09-01-overhaul/oh-capture", "foundry-deep.walk");
Assert.NotEmpty(frames);
using DatCollection dats = OpenDats();
Assert.NotNull(frames[0].Pose);
WalkLandscapeDatBuilder.BuiltWorld world = WalkLandscapeDatBuilder.Build(
dats, frames[0].Pose!.CellId, frames[0].Pose!.Origin);
foreach (WalkOracleFrame frame in frames)
{
Assert.NotNull(frame.Pose);
WalkCell camera = Assert.Contains(frame.Pose!.CellId, world.Cells);
var ctx = new WalkTraceReplayContext(frame.Pose, world.Cells)
{
Buildings = world.Buildings,
};
var walk = new RetailFrameWalk();
var recorder = new Recorder();
walk.WalkFrame(frame.Pose.CellId, camera, world.Landscape, ctx, recorder);
Assert.Equal(
WalkTraceReplayContext.Signature(frame),
WalkTraceReplayContext.Signature(recorder.Events));
}
}
}

View file

@ -146,8 +146,26 @@ public sealed class WalkTraceReplayContext : IWalkFrameContext, IRetailFrameWalk
_ => "?",
}));
/// <summary>
/// S3 chunk 1 (§11.2 B3): the OH captures interleave <c>LC</c>/<c>SC</c>/
/// <c>EC</c>/<c>OC</c> lines the pre-chunk-3 FW0 fixtures never had.
/// <see cref="RetailFrameWalk"/>'s own <c>WalkEvent</c> vocabulary has
/// exactly four kinds (Landscape/Building/DrawInside/DrawCells) — LC/SC/
/// EC/OC are separate <see cref="IWalkEventSink"/> hooks
/// <see cref="Recorder"/> never overrides, so the replay side of a
/// signature diff is silent on them by construction. Filtering them out
/// here (rather than mapping to a "?" placeholder) keeps this
/// comparison at the SAME DI/DC/BLD/LS level on both sides — S3's own
/// scope note ("no speculative pins" for LC/SC/EC/OC content) means this
/// method must not even attempt to compare them, not merely fail to.
/// </summary>
public static string Signature(WalkOracleFrame frame)
=> string.Join("|", frame.Events.Select(e => e.Kind switch
=> string.Join("|", frame.Events
.Where(e => e.Kind is WalkOracleEventKind.Landscape
or WalkOracleEventKind.Building
or WalkOracleEventKind.DrawInside
or WalkOracleEventKind.DrawCells)
.Select(e => e.Kind switch
{
WalkOracleEventKind.Landscape => "LS",
WalkOracleEventKind.Building => $"BLD:{e.CellId!.Value:x8}",

View file

@ -0,0 +1,93 @@
namespace AcDream.App.Tests.Rendering.Walk;
/// <summary>
/// S3 chunk 1 (§11.2 B4): the offline transcript signature diff. Given an
/// acdream transcript (printed by the production
/// <c>ACDREAM_DUMP_WALK_TRANSCRIPT=1</c> emitter — <c>WalkTranscriptDump</c>)
/// and a retail capture (or any two <see cref="WalkOracleTrace"/>-parsed
/// transcripts), reports the FIRST divergent event and its position, frame
/// by frame, at the DI/DC/BLD/LS/LC/SC/EC/OC level. A test-side comparison
/// utility only — no runner, no dashboard, no new tool under
/// <c>tools/</c> ([[feedback-evidence-infrastructure-sink]]); the S3 review
/// and G3 consume its report by hand.
/// </summary>
public static class WalkTranscriptSignatureDiff
{
/// <summary>The first point two transcripts disagree, or
/// <see langword="null"/> when every frame both sides share matches
/// exactly. <paramref name="FrameNumber"/> is the retail-side frame's
/// own number (matching the "F n" line); <paramref name="Position"/>
/// is the zero-based index into that frame's DI/DC/BLD/LS/LC/SC/EC/OC
/// event signature. <c>"&lt;end of frame&gt;"</c>/<c>"&lt;missing
/// frame&gt;"</c> mark a length mismatch rather than a content
/// mismatch.</summary>
public readonly record struct Divergence(
int FrameNumber, int Position, string Expected, string Actual);
/// <summary>Diffs two raw transcripts (e.g. one file read as lines each)
/// — the file-to-file form B4 names directly.</summary>
public static Divergence? FirstDivergence(
IEnumerable<string> expectedLines, IEnumerable<string> actualLines)
=> FirstDivergence(
WalkOracleTrace.Parse(expectedLines), WalkOracleTrace.Parse(actualLines));
/// <summary>Diffs two already-parsed frame lists — the form the
/// synthetic self-test below uses directly, without a round trip
/// through a temp file.</summary>
public static Divergence? FirstDivergence(
IReadOnlyList<WalkOracleFrame> expected, IReadOnlyList<WalkOracleFrame> actual)
{
int frameCount = Math.Min(expected.Count, actual.Count);
for (int f = 0; f < frameCount; f++)
{
IReadOnlyList<string> e = Signature(expected[f]);
IReadOnlyList<string> a = Signature(actual[f]);
int shared = Math.Min(e.Count, a.Count);
for (int i = 0; i < shared; i++)
{
if (!string.Equals(e[i], a[i], StringComparison.Ordinal))
return new Divergence(expected[f].Number, i, e[i], a[i]);
}
if (e.Count != a.Count)
{
return new Divergence(
expected[f].Number,
shared,
shared < e.Count ? e[shared] : "<end of frame>",
shared < a.Count ? a[shared] : "<end of frame>");
}
}
if (expected.Count != actual.Count)
{
int frameNumber = frameCount < expected.Count
? expected[frameCount].Number
: actual[frameCount].Number;
return new Divergence(
frameNumber,
0,
frameCount < expected.Count ? "<frame present>" : "<missing frame>",
frameCount < actual.Count ? "<frame present>" : "<missing frame>");
}
return null;
}
/// <summary>One frame's DI/DC/BLD/LS/LC/SC/EC/OC turns, in transcript
/// order — the full eight-kind vocabulary B4 names (unlike
/// <see cref="WalkTraceReplayContext.Signature(WalkOracleFrame)"/>,
/// which deliberately stays at the pre-S3-chunk-3 four-kind level for
/// the B3 still-fixture rows).</summary>
private static IReadOnlyList<string> Signature(WalkOracleFrame frame)
=> frame.Events.Select(e => e.Kind switch
{
WalkOracleEventKind.Landscape => "LS",
WalkOracleEventKind.Building => $"BLD:{e.CellId!.Value:x8}",
WalkOracleEventKind.DrawInside => $"DI:{e.CellId!.Value:x8}",
WalkOracleEventKind.DrawCells =>
$"DC:ov={e.OutsideViewCount}:{string.Join(',', e.Cells.Select(c => c.ToString("x8")))}",
WalkOracleEventKind.LandCell => $"LC:{e.CellId!.Value:x8}",
WalkOracleEventKind.SortCell => $"SC:{e.CellId!.Value:x8}",
WalkOracleEventKind.EnvCellShell => $"EC:{e.CellId!.Value:x8}",
WalkOracleEventKind.ObjectCellTurn => $"OC:{e.CellId!.Value:x8}",
_ => "?",
}).ToList();
}