Files
james.maesandCodex GPT-6 38dd5c1488 feat: implement Windows MarkdownViewr (#35)
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:** both
baee14f492 and
e605df62c4 have exact Git tree
a85912cbad. 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 tree baee14f / 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>
2026-10-12 14:01:42 -05:00

135 lines
5.5 KiB
C#

/*
* Copyright (c) 2026 James Maes
* SPDX-License-Identifier: MIT
*/
using MarkdownViewr.Windows.Core.Editors;
using MarkdownViewr.Windows.Core.Printing;
namespace MarkdownViewr.Windows.Core.Tests;
/// <summary>Independent document windows cannot overwrite sibling changes by saving an older preference snapshot.</summary>
public sealed class SettingsChangesTests
{
/// <summary>Legacy remembered panel visibility does not opt new windows into showing panels, while explicit defaults survive source-generated persistence.</summary>
[Fact]
public void Copy_NewWindowDefaults_AreIndependentOfRememberedPanels()
{
var legacy = new AppSettings { ShowOutline = true, ShowSource = true };
AppSettings restored = SettingsChanges.Copy(legacy);
Assert.False(restored.ShowOutlineByDefault);
Assert.False(restored.ShowSourceByDefault);
restored.ShowOutlineByDefault = true;
restored.ShowSourceByDefault = true;
AppSettings selected = SettingsChanges.Copy(restored);
Assert.True(selected.ShowOutlineByDefault);
Assert.True(selected.ShowSourceByDefault);
Assert.False(legacy.ShowOutlineByDefault);
Assert.False(legacy.ShowSourceByDefault);
}
/// <summary>A local panel toggle cannot overwrite newer startup defaults chosen in another Settings window.</summary>
[Fact]
public void Merge_LocalPanelToggle_PreservesNewerStartupDefaults()
{
var baseline = new AppSettings();
AppSettings local = SettingsChanges.Copy(baseline);
local.ShowSource = true;
local.ShowOutline = true;
var saved = new AppSettings { ShowOutlineByDefault = true, ShowSourceByDefault = true };
AppSettings merged = SettingsChanges.Merge(saved, baseline, local);
Assert.True(merged.ShowOutline);
Assert.True(merged.ShowSource);
Assert.True(merged.ShowOutlineByDefault);
Assert.True(merged.ShowSourceByDefault);
}
/// <summary>Legacy settings use truncated unmarked Contents; saved presentation choices survive an unrelated stale-reader edit.</summary>
[Fact]
public void Merge_ContentsPresentation_PersistsWithoutChangingPanelDefaults()
{
var before = new AppSettings();
Assert.False(before.WrapOutlineEntries);
Assert.False(before.ShowOutlineDepthMarkers);
AppSettings edited = SettingsChanges.Copy(before);
edited.OutlineDepth = 5;
edited.ShowOutline = true;
var current = new AppSettings { WrapOutlineEntries = true, ShowOutlineDepthMarkers = true, DocumentTheme = "Nord" };
AppSettings result = SettingsChanges.Copy(SettingsChanges.Merge(current, before, edited));
Assert.True(result.WrapOutlineEntries);
Assert.True(result.ShowOutlineDepthMarkers);
Assert.True(result.ShowOutline);
Assert.Equal(5, result.OutlineDepth);
Assert.Equal("Nord", result.DocumentTheme);
Assert.False(result.ShowOutlineByDefault);
Assert.False(result.ShowSourceByDefault);
Assert.False(before.WrapOutlineEntries);
Assert.False(before.ShowOutlineDepthMarkers);
}
/// <summary>A window's source change preserves newer history, theme, editor and print choices from its sibling.</summary>
[Fact]
public void Merge_StaleWindow_PreservesUnchangedSiblingPreferences()
{
var before = new AppSettings();
AppSettings edited = SettingsChanges.Copy(before);
edited.ShowSource = true;
edited.SourceWidth = 280;
var current = new AppSettings
{
DocumentTheme = "Nord",
RecentFiles = [Path.Combine(Path.GetTempPath(), "second.md")],
ConfiguredEditors = [new EditorConfiguration(Guid.NewGuid(), "Sibling", "C:\\editor.exe")],
Print = new PrintOptions("Plain HTML", PaddingPixels: 12),
};
AppSettings result = SettingsChanges.Merge(current, before, edited);
Assert.True(result.ShowSource);
Assert.Equal(280, result.SourceWidth);
Assert.Equal("Nord", result.DocumentTheme);
Assert.Equal(current.RecentFiles, result.RecentFiles);
Assert.Equal(current.ConfiguredEditors, result.ConfiguredEditors);
Assert.Equal(current.Print, result.Print);
Assert.False(current.ShowSource);
}
/// <summary>An explicit current-window edit wins for that field, while a cleared history cannot reappear.</summary>
[Fact]
public void Merge_ExplicitEdit_AppliesOnlyChangedProperties()
{
var before = new AppSettings { DocumentTheme = "Nord", RecentFiles = [Path.Combine(Path.GetTempPath(), "old.md")] };
AppSettings edited = SettingsChanges.Copy(before);
edited.DocumentTheme = "Dracula";
edited.UserThemes = ["owned fixture"];
edited.Print = null!;
var current = new AppSettings { DocumentTheme = "Light", RecentFiles = [] };
AppSettings result = SettingsChanges.Merge(current, before, edited);
Assert.Equal("Dracula", result.DocumentTheme);
Assert.Equal(["owned fixture"], result.UserThemes);
Assert.Empty(result.RecentFiles);
Assert.Null(result.Print);
}
/// <summary>Nested arrays are copied; mutation of a working draft cannot alter its baseline.</summary>
[Fact]
public void Copy_MutableArrays_RemainsIndependent()
{
var before = new AppSettings { RecentFiles = [Path.Combine(Path.GetTempPath(), "original.md")], UserThemes = ["original"] };
AppSettings copy = SettingsChanges.Copy(before);
copy.RecentFiles[0] = "changed";
copy.UserThemes[0] = "changed";
Assert.EndsWith("original.md", before.RecentFiles[0], StringComparison.Ordinal);
Assert.Equal("original", before.UserThemes[0]);
}
}