- guide/: eight short English pages for players (install and first start, record a game, read your results, anti-cheat and safety, your data, questions and answers, the terms in plain words), embedded in the App and shown under Help > User guide - the first Help item - with Limitations last; links between pages open in the window. Help > Documentation becomes Online documentation: the README at this build's source. - The Legal Gate: LegalDocument.RequiresAcceptance; the GPL is listed as "your licence", with a line saying GPLv3 section 9 needs no acceptance, and Accept writes three rows (an old gpl row stays, unread). The summary names the user-mode exception (it said there was no way to override the refusal) and the one network request (it said nothing is sent anywhere). - EULA 1.5: an unmeasured session also records the game's memory use; the GPL needs no acceptance; where the third-party notices are in an installed copy; consumer rights no agreement can limit, and severability. Disclaimer 2.10: what it reads about a game from outside it; the maintainers' preface moves to docs/legal-drift-history.md. Privacy 2.6: the game's memory use (replacing a video-memory figure never read), a new section 3A on what an export or a bug report carries about you; the history notes move to the same file. - README: a pointer to the guide up front, the safety table's D38 rule and the feature list's memory line corrected, Tier 2 names the game's memory, NOTICE beside the licence, and a section for developers and forks. - Strings: 3 new keys, 6 changed, en/vi/ja (ja marked review). - Tests: GuideDocumentsTests (every page listed and titled, every link leads somewhere, the section anchor exists), the guide in the renderer's nothing-dropped test (17 documents), the guide window, three acceptance rows and the old gpl row left alone, the documentation link. - Docs: 02_SPEC FR-11, 06_DATA_MODEL, 08_UI, 09_I18N, CLAUDE.md layout, CHANGELOG. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
210 lines
10 KiB
C#
210 lines
10 KiB
C#
// SPDX-License-Identifier: GPL-3.0-only
|
||
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
||
|
||
using System.IO;
|
||
using System.IO.Compression;
|
||
using FluentAssertions;
|
||
using FrameLedger.App.Services;
|
||
using FrameLedger.Application.Persistence;
|
||
using FrameLedger.Application.Settings;
|
||
using FrameLedger.Infrastructure.Persistence;
|
||
using FrameLedger.Shared.Ipc;
|
||
|
||
namespace FrameLedger.App.Tests;
|
||
|
||
/// <summary>
|
||
/// <c>10_LOGGING</c> §Bug report flow steps 2–4 (P4 PR-3): the zip goes where the user says and the preview lists what
|
||
/// it holds; "Open GitHub issue" opens the form with the two short fields prefilled by their real ids; the fallback
|
||
/// puts the environment summary on the clipboard as Markdown; a cancelled save does nothing; nothing is ever sent.
|
||
/// </summary>
|
||
public sealed class BugReportFlowTests : IDisposable
|
||
{
|
||
private readonly string _dir = Path.Combine(Path.GetTempPath(), "fl-bugflow-" + Guid.NewGuid().ToString("N"));
|
||
|
||
public BugReportFlowTests() => Directory.CreateDirectory(_dir);
|
||
|
||
public void Dispose() => Directory.Delete(_dir, recursive: true);
|
||
|
||
private static CancellationToken Ct => TestContext.Current.CancellationToken;
|
||
|
||
private sealed class PathSaver(string? path) : IFileSaver
|
||
{
|
||
public string? PickSavePath(string filter, string suggestedName) => path;
|
||
}
|
||
|
||
private sealed class RecordingStrip : IMessageStrip
|
||
{
|
||
public List<(string Kind, string Title, string Body)> Shown { get; } = [];
|
||
|
||
public void Info(string title, string body) => Shown.Add(("info", title, body));
|
||
|
||
public void Success(string title, string body) => Shown.Add(("success", title, body));
|
||
|
||
public void Warn(string title, string body) => Shown.Add(("warn", title, body));
|
||
}
|
||
|
||
private sealed record Harness(BugReportFlow Flow, ClosePreview Preview, NoUrlOpener Urls, NoClipboard Clipboard, RecordingStrip Strip, string Zip);
|
||
|
||
private async Task<Harness> BuildAsync(ScratchLedger s, BugReportChoice choice, bool cancel = false, BugBundleOptions? options = null)
|
||
{
|
||
await File.WriteAllTextAsync(Path.Combine(_dir, "ui-20260914.log"), "[12:00:00.000 INF] hello\n", Ct).ConfigureAwait(false);
|
||
var builder = new BugBundleBuilder(_dir, new RegisteredSettings(new SqliteSettingsStore(s.Db)), crashDumpDirectory: Path.Combine(_dir, "crashdumps"));
|
||
string zip = Path.Combine(_dir, "bundle.zip");
|
||
var preview = new ClosePreview(choice, options);
|
||
var urls = new NoUrlOpener();
|
||
var clipboard = new NoClipboard();
|
||
var strip = new RecordingStrip();
|
||
var agent = new FakeAgentLink { Hello = new HelloAck("9.9.9", IpcProtocol.Version, 4, false, "build-z", false, "l1", false, "consent-dialog/1") };
|
||
var lastSession = new LastSessionSummary(s.Sessions, s.Games, new SqliteHardwareSnapshotRepository(s.Db));
|
||
return new Harness(new BugReportFlow(builder, new PathSaver(cancel ? null : zip), agent, preview, urls, clipboard, strip, lastSession: lastSession), preview, urls, clipboard, strip, zip);
|
||
}
|
||
|
||
[Fact]
|
||
public async Task TheZipIsWrittenThePreviewListsItAndOpenIssueOpensTheFormPrefilledByFieldId()
|
||
{
|
||
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
||
Harness h = await BuildAsync(s, BugReportChoice.OpenIssue);
|
||
|
||
BugReportOutcome o = await h.Flow.RunAsync(Ct);
|
||
|
||
o.Written.Should().BeTrue();
|
||
o.Choice.Should().Be(BugReportChoice.OpenIssue);
|
||
File.Exists(h.Zip).Should().BeTrue();
|
||
BugReportPreviewModel shown = h.Preview.Shown.Should().ContainSingle().Subject;
|
||
shown.ZipPath.Should().Be(h.Zip);
|
||
using (ZipArchive archive = await ZipFile.OpenReadAsync(h.Zip, Ct))
|
||
{
|
||
shown.Entries.Should().BeEquivalentTo(archive.Entries.Select(static e => e.FullName), "the preview lists exactly what the zip holds");
|
||
}
|
||
|
||
shown.Entries.Should().Contain("logs/ui-20260914.log").And.Contain("sysinfo.json");
|
||
h.Urls.Opened.Should().ContainSingle().Which.AbsoluteUri.Should().StartWith(IssueLink.Repository + "/issues/new?template=bug_report.yml&title=%5BBug%5D%20&labels=bug&app-version=")
|
||
.And.Contain("&os=Windows%20", "the form's field ids are app-version and os, hyphenated");
|
||
h.Clipboard.Texts.Should().BeEmpty();
|
||
h.Strip.Shown.Should().BeEmpty("the browser opened; there is nothing to say");
|
||
h.Preview.Offers.Should().BeEmpty("no crash dump and no session: no question");
|
||
}
|
||
|
||
[Theory]
|
||
[InlineData(false)]
|
||
[InlineData(true)]
|
||
public async Task ARecentCrashDumpIsOfferedAndGoesInOnlyWhenTicked(bool included)
|
||
{
|
||
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
||
string dump = WriteDump();
|
||
Harness h = await BuildAsync(s, BugReportChoice.Close, options: new BugBundleOptions(Cancelled: false, IncludeCrashDump: included, IncludeLastSession: false));
|
||
|
||
BugReportOutcome o = await h.Flow.RunAsync(Ct);
|
||
|
||
o.Written.Should().BeTrue();
|
||
h.Preview.Offers.Should().ContainSingle().Which.CrashDump!.Path.Should().Be(dump);
|
||
IReadOnlyList<string> entries = h.Preview.Shown.Should().ContainSingle().Subject.Entries;
|
||
string entry = "crashdumps/" + Path.GetFileName(dump);
|
||
if (included)
|
||
{
|
||
entries.Should().Contain(entry);
|
||
}
|
||
else
|
||
{
|
||
entries.Should().NotContain(entry, "the box starts clear and was left so");
|
||
}
|
||
}
|
||
|
||
[Fact]
|
||
public async Task ClosingTheCrashDumpQuestionWritesNothing()
|
||
{
|
||
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
||
WriteDump();
|
||
Harness h = await BuildAsync(s, BugReportChoice.OpenIssue, options: BugBundleOptions.Cancel);
|
||
|
||
BugReportOutcome o = await h.Flow.RunAsync(Ct);
|
||
|
||
o.Written.Should().BeFalse();
|
||
o.ZipPath.Should().BeNull();
|
||
File.Exists(h.Zip).Should().BeFalse("the question comes before the save dialog");
|
||
h.Preview.Shown.Should().BeEmpty();
|
||
h.Urls.Opened.Should().BeEmpty();
|
||
}
|
||
|
||
[Theory]
|
||
[InlineData(false)]
|
||
[InlineData(true)]
|
||
public async Task TheLastSessionIsOfferedAndGoesInOnlyWhenTickedWithItsPathsRedacted(bool included)
|
||
{
|
||
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
||
GameRow game = await s.GameAsync("Title", @"C:\Users\tester\Games\Title\title.exe");
|
||
long id = await s.SessionAsync(game.Id, new DateTimeOffset(2026, 9, 14, 10, 0, 0, TimeSpan.Zero));
|
||
Harness h = await BuildAsync(s, BugReportChoice.Close, options: new BugBundleOptions(Cancelled: false, IncludeCrashDump: false, IncludeLastSession: included));
|
||
|
||
BugReportOutcome o = await h.Flow.RunAsync(Ct);
|
||
|
||
o.Written.Should().BeTrue();
|
||
BugBundleOffer offer = h.Preview.Offers.Should().ContainSingle().Subject;
|
||
offer.CrashDump.Should().BeNull();
|
||
offer.LastSession.Should().Be(new LastSessionInfo(id, "Title", new DateTimeOffset(2026, 9, 14, 10, 0, 0, TimeSpan.Zero)));
|
||
IReadOnlyList<string> entries = h.Preview.Shown.Should().ContainSingle().Subject.Entries;
|
||
if (!included)
|
||
{
|
||
entries.Should().NotContain("session.json", "the box starts clear and was left so");
|
||
return;
|
||
}
|
||
|
||
entries.Should().Contain("session.json");
|
||
using ZipArchive archive = await ZipFile.OpenReadAsync(h.Zip, Ct);
|
||
using var reader = new StreamReader(await archive.GetEntry("session.json")!.OpenAsync(Ct));
|
||
string json = await reader.ReadToEndAsync(Ct);
|
||
json.Should().Contain("Title").And.NotContain("tester", "a path in the summary is redacted like a log");
|
||
}
|
||
|
||
private string WriteDump()
|
||
{
|
||
string dumps = Path.Combine(_dir, "crashdumps");
|
||
Directory.CreateDirectory(dumps);
|
||
string path = Path.Combine(dumps, "ui-20260915-010203-42.dmp");
|
||
File.WriteAllBytes(path, "MDMP"u8.ToArray());
|
||
return path;
|
||
}
|
||
|
||
[Fact]
|
||
public async Task CopyMarkdownPutsTheEnvironmentSummaryOnTheClipboard()
|
||
{
|
||
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
||
Harness h = await BuildAsync(s, BugReportChoice.CopyMarkdown);
|
||
|
||
await h.Flow.RunAsync(Ct);
|
||
|
||
h.Urls.Opened.Should().BeEmpty();
|
||
string md = h.Clipboard.Texts.Should().ContainSingle().Subject;
|
||
md.Should().StartWith("| Key | Value |").And.Contain("| `app_version` | ").And.Contain("| `agent_version` | 9.9.9 |").And.Contain("| `overlay_build_id` | build-z |");
|
||
h.Strip.Shown.Should().ContainSingle().Which.Kind.Should().Be("info");
|
||
}
|
||
|
||
[Fact]
|
||
public async Task ClosingKeepsTheZipAndSaysSoAndACancelledSaveWritesNothing()
|
||
{
|
||
await using ScratchLedger s = await ScratchLedger.OpenAsync();
|
||
Harness closed = await BuildAsync(s, BugReportChoice.Close);
|
||
(await closed.Flow.RunAsync(Ct)).Choice.Should().Be(BugReportChoice.Close);
|
||
File.Exists(closed.Zip).Should().BeTrue();
|
||
closed.Urls.Opened.Should().BeEmpty();
|
||
closed.Strip.Shown.Should().ContainSingle().Which.Kind.Should().Be("success");
|
||
|
||
Harness cancelled = await BuildAsync(s, BugReportChoice.OpenIssue, cancel: true);
|
||
BugReportOutcome o = await cancelled.Flow.RunAsync(Ct);
|
||
o.Written.Should().BeFalse();
|
||
cancelled.Preview.Shown.Should().BeEmpty("no zip, no preview");
|
||
cancelled.Strip.Shown.Should().BeEmpty();
|
||
}
|
||
|
||
[Fact]
|
||
public void TheIssueLinkAndTheOsLineAreTheFormsSpelling()
|
||
{
|
||
IssueLink.NewIssue("0.1.0", "Windows 11 26100.2314").AbsoluteUri.Should().Be(
|
||
"https://github.com/poli0981/frameledger/issues/new?template=bug_report.yml&title=%5BBug%5D%20&labels=bug&app-version=0.1.0&os=Windows%2011%2026100.2314");
|
||
IssueLink.OsText(new Version(10, 0, 26100, 2314)).Should().Be("Windows 11 26100.2314");
|
||
IssueLink.OsText(new Version(10, 0, 19045, 0)).Should().Be("Windows 10 19045");
|
||
IssueLink.Documentation.AbsoluteUri.Should().Be("https://github.com/poli0981/frameledger/blob/main/README.md", "the README at this build's source (main for a test build), beta.12");
|
||
IssueLink.Markdown(new Dictionary<string, string>(StringComparer.Ordinal) { ["a"] = "x|y" }).Should().Contain("| `a` | x\\|y |", "a pipe in a value must not break the table");
|
||
}
|
||
}
|