const test = require("node:test"); const assert = require("node:assert/strict"); const fs = require("node:fs"); const path = require("node:path"); const source = fs.readFileSync(path.join( __dirname, "..", "..", "src", "MBN_STOCK_WEBVIEW.LegacyParityApp", "MainWindow.Playout.cs"), "utf8"); const preflight = source.slice( source.indexOf("private async Task CreateFreshPagedPlayoutRequestAsync("), source.indexOf("private async Task ExecuteGateAPrepareAsync(")); test("first PREPARE and TAKE IN preflight only the selected forward-enabled PageN row", () => { assert.ok((source.match(/CreateFreshPagedPlayoutRequestAsync\(/g) || []).length >= 3); assert.match(preflight, /Skip\(Math\.Max\(0, request\.SelectedIndexZeroBased\)\)[\s\S]*FirstOrDefault\(static entry => entry\.IsEnabled\)/u); assert.match(preflight, /PreflightPagePlansAsync\([\s\S]*Array\.AsReadOnly\(new\[\] \{ targetEntry \}\)/u); assert.doesNotMatch(preflight, /foreach \(var entry in/u); assert.doesNotMatch(preflight, /catch \(LegacySceneDataException\)/u); assert.match(preflight, /ReflectSuccessfulPlayout\([\s\S]*plan\.EntryId,[\s\S]*pageIndexZeroBased: 0,[\s\S]*plan\.PageCount,[\s\S]*synchronizeOperatorSelection: false\)/u); }); test("the selected PageN preflight is strictly validated before vendor dispatch", () => { assert.match(preflight, /plans\.Count != 1/u); assert.match(preflight, /!string\.Equals\(plan\.EntryId, targetEntry\.EntryId, StringComparison\.Ordinal\)/u); assert.match(preflight, /plan\.PageSize != \(int\)expectedPageSize/u); assert.match(preflight, /plan\.PageCount is < 1 or > ScenePaging\.MaximumPageCount/u); assert.match(preflight, /workflow\.State\.CurrentEntryId is not null/u); });