This replaces the blocked history in PR #3 with one properly attributed, signed/DCO commit. The owner personally reviewed and approved PR #3 in the release session. **No file changes from the approved candidate:** bothbaee14f492ande605df62c4have exact Git treea85912cbad. Original PR #3 and its commits are preserved for review history. Historical commits were locally signed but GitHub reported no_user; protected merge checks those introduced commits even for squash merging. This commit resolves attribution without bypassing or weakening signature rules. The reader, Settings, themes, source highlighting/split, live reload, file associations, Print/PDF, About credits, toolbar/footer/editor fixes, user-first README/screenshots and developer guides are exactly the approved implementation. Stable/dev separation and protected Azure signing caller are unchanged. Evidence: - Approved treebaee14f/ CI38285775463 passes all checks. Downloaded focused29/29, published111/111, stable110/110 and dev110/110 TRXs have zero failures/skips. Core coverage100% lines/98.86% branches; actual update/restart/coexistence/default-preservation receipts verify. - New single-commit hooks, online workflow security, signing and DCO pass. GitHub must rerun all required checks on this commit; results are not copied across SHAs. - Live repository setup validates18 Actions-bound checks, with only fuzzing added and all prior protections preserved. - OpenSSF project15417 is now owner-reviewed and saved at70% under owner-confirmed CDLA-Permissive2.0. This is an in-progress assessment, not a passing badge. - Production CI OIDC and signed1.0/dev publication remain required; local representative signing is not CI proof. Substantial AI assistance: Codex (GPT-6). Supersedes PR #3. Release work remains tracked in #33. Closes #4, #6, #7, #8, #9, #10, #11, #12, #13, #14, #15, #16, #17, #18, #19, #20, #21, #22, #23, #24, #25, #26, #27, #28, #29, #32, #34. Refs #1, #5, #30, #31, #33. Signed-off-by: James Maes <james@kof22.com> Co-authored-by: Codex GPT-6 <noreply@openai.com>
107 lines
4.2 KiB
C#
107 lines
4.2 KiB
C#
/*
|
|
* Copyright (c) 2026 James Maes
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
using MarkdownViewr.Windows.Core.Documents;
|
|
|
|
|
|
namespace MarkdownViewr.Windows.Core.Tests;
|
|
|
|
/// <summary>Proves bounded fixed-query geometry and paired heading interpolation without executing arbitrary data.</summary>
|
|
public sealed class DocumentScrollStateTests
|
|
{
|
|
/// <summary>Finite generated geometry is preserved and viewport overshoot is bounded.</summary>
|
|
[Fact]
|
|
public void FromBrowserResult_ValidFrame_PreservesGeneratedGeometry()
|
|
{
|
|
DocumentScrollState state = DocumentScrollState.FromBrowserResult("[120,100,[[0,12],[2,90]],[1,2]]", 3)!;
|
|
Assert.Equal(100, state.Position);
|
|
Assert.Equal(100, state.Maximum);
|
|
Assert.Equal(12, state.Headings[0]);
|
|
Assert.Equal(90, state.Headings[2]);
|
|
Assert.Equal(new[] { 1, 2 }, state.Collapsed);
|
|
Assert.Equal(0, DocumentScrollState.FromBrowserResult("[-5,100,[],[]]", 0)!.Position);
|
|
Assert.Equal(0, DocumentScrollState.FromBrowserResult("[0,0,[],[]]", 0)!.Maximum);
|
|
}
|
|
|
|
|
|
|
|
/// <summary>Untrusted shapes, identities, duplicate entries and nonfinite geometry cannot become scroll commands.</summary>
|
|
[Theory]
|
|
[InlineData(null)]
|
|
[InlineData("")]
|
|
[InlineData("null")]
|
|
[InlineData("{}")]
|
|
[InlineData("[0,100,[]]")]
|
|
[InlineData("[\"0\",100,[],[]]")]
|
|
[InlineData("[0,-1,[],[]]")]
|
|
[InlineData("[0,1e999,[],[]]")]
|
|
[InlineData("[0,100,{},[]]")]
|
|
[InlineData("[0,100,[],{}]")]
|
|
[InlineData("[0,100,[[0,1],[1,2],[2,3]],[]]")]
|
|
[InlineData("[0,100,[],[0,1,1]]")]
|
|
[InlineData("[0,100,[0],[]]")]
|
|
[InlineData("[0,100,[[0]],[]]")]
|
|
[InlineData("[0,100,[[\"0\",1]],[]]")]
|
|
[InlineData("[0,100,[[-1,1]],[]]")]
|
|
[InlineData("[0,100,[[2,1]],[]]")]
|
|
[InlineData("[0,100,[[0.5,1]],[]]")]
|
|
[InlineData("[0,100,[[0,\"one\"]],[]]")]
|
|
[InlineData("[0,100,[[0,1e999]],[]]")]
|
|
[InlineData("[0,100,[[0,1],[0,2]],[]]")]
|
|
[InlineData("[0,100,[],[0,0]]")]
|
|
[InlineData("[0,100,[],[\"0\"]]")]
|
|
[InlineData("[0,100,[],[2]]")]
|
|
public void FromBrowserResult_InvalidFrame_ReturnsNoGeometry(string? json)
|
|
{
|
|
Assert.Null(DocumentScrollState.FromBrowserResult(json, 2));
|
|
}
|
|
|
|
|
|
|
|
/// <summary>Query payload size scales only with the current generated heading count.</summary>
|
|
[Fact]
|
|
public void FromBrowserResult_OversizedOrInvalidCount_RejectsFrame()
|
|
{
|
|
Assert.Null(DocumentScrollState.FromBrowserResult(new string(' ', 513), 0));
|
|
Assert.Throws<ArgumentOutOfRangeException>(() => DocumentScrollState.FromBrowserResult("[]", -1));
|
|
}
|
|
|
|
|
|
|
|
/// <summary>Paired anchors retain viewport fractions between headings and reach exact document ends.</summary>
|
|
[Theory]
|
|
[InlineData(-1, 0)]
|
|
[InlineData(0, 0)]
|
|
[InlineData(12.5, 50)]
|
|
[InlineData(25, 100)]
|
|
[InlineData(50, 120)]
|
|
[InlineData(75, 140)]
|
|
[InlineData(87.5, 170)]
|
|
[InlineData(100, 200)]
|
|
[InlineData(110, 200)]
|
|
public void MapPosition_PairedHeadings_InterpolatesAndClamps(double position, double expected)
|
|
{
|
|
Assert.Equal(expected, DocumentScrollState.MapPosition(position, 100, 200, [(75, 140), (25, 100)]));
|
|
}
|
|
|
|
|
|
|
|
/// <summary>No headings use relative scroll; duplicate/nonfinite/off-range anchors cannot corrupt interpolation.</summary>
|
|
[Fact]
|
|
public void MapPosition_MissingOrUnusableAnchors_UsesBoundedGeometry()
|
|
{
|
|
Assert.Equal(200, DocumentScrollState.MapPosition(50, 100, 400, []));
|
|
Assert.Equal(120, DocumentScrollState.MapPosition(50, 100, 200, [(25, 100), (25, 110), (75, 140), (double.NaN, 1), (1, double.PositiveInfinity), (-1, 1), (100, 1)]));
|
|
Assert.Equal(100, DocumentScrollState.MapPosition(25, 100, 100, [(25, 200)]));
|
|
Assert.Equal(0, DocumentScrollState.MapPosition(25, 100, 100, [(25, -1)]));
|
|
Assert.Equal(0, DocumentScrollState.MapPosition(double.NaN, 100, 100, []));
|
|
Assert.Equal(0, DocumentScrollState.MapPosition(0, double.PositiveInfinity, 100, []));
|
|
Assert.Equal(0, DocumentScrollState.MapPosition(0, 100, double.NaN, []));
|
|
Assert.Equal(0, DocumentScrollState.MapPosition(0, 0, 100, []));
|
|
Assert.Equal(0, DocumentScrollState.MapPosition(0, 100, -1, []));
|
|
Assert.Throws<ArgumentNullException>(() => DocumentScrollState.MapPosition(0, 1, 1, null!));
|
|
}
|
|
}
|