Files
CommandForge/tests/CommandForge.Tests/ReportBugTemplateTests.cs
T
poli0981andClaude Opus 4.8 899bd93e37 Phase 5b: Log Viewer, Debug panel, global crash handler, bug report
Diagnostics slice of Phase 5 (builds on 5a's in-shell nav):
- Structured logging: InMemoryLogStore now stores LogEntry (timestamp/level/message)
  + raises EntriesChanged; new ILogReader contract. A shared Serilog LoggingLevelSwitch
  (ILogLevelController) makes the level runtime-adjustable. ILogMaintenance exports a
  .zip (streams each log-*.txt with shared read so today's locked file is included),
  reports size, and deletes rolled files.
- Log Viewer (in-shell section, Ctrl+L / Tools menu): live entries, level + text filter,
  per-level color (theme-safe; Information inherits body), auto-scroll, open-folder /
  export-.zip / clear.
- Debug panel (in-shell, Tools + Settings>Advanced): verbose log dump, catalog
  counts + validation errors (now exposed via ICatalogProvider.ValidationErrors),
  system-info dump with copy.
- Global crash handler: Dispatcher/AppDomain/TaskScheduler -> structured Serilog log
  (no sensitive data) + friendly ErrorDialog (message, error code, Copy details,
  Report bug, Close); re-entrancy guard; recovers dispatcher exceptions.
- Report a bug (Help menu + from ErrorDialog): auto-gathered environment, export
  log .zip with review reminder, opens a prefilled GitHub issue. User-initiated; no
  auto-send (Privacy).
- Settings: new Logs (level / size / open / export / clear) and Advanced (run mode /
  config path / open Debug panel / reset-to-defaults — preserves terms + logs) sections;
  ISettingsService.LogLevel persisted and applied at startup.

EN/VI strings + AutomationProperties added. Dry-run deferred. 87 tests pass
(store/filter/report-template/catalog-errors/settings/DI/resx); 0-warning Release build;
Log Viewer smoke-verified live in dark mode.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-18 13:25:08 +07:00

37 lines
1.5 KiB
C#

using System.Runtime.InteropServices;
using CommandForge.Wpf.ViewModels;
namespace CommandForge.Tests;
/// <summary>Tests the pure bug-report builders (environment block + issue body + URL escaping).</summary>
public sealed class ReportBugTemplateTests
{
[Fact]
public void BuildEnvironment_IncludesVersionOsAndArchitecture()
{
var env = ReportBugViewModel.BuildEnvironment("1.2.3", "Windows 11", Architecture.X64);
Assert.Contains("1.2.3", env, StringComparison.Ordinal);
Assert.Contains("Windows 11", env, StringComparison.Ordinal);
Assert.Contains("X64", env, StringComparison.Ordinal);
}
[Fact]
public void BuildIssueBody_ContainsEnvironmentDescriptionCodeAndAttachmentNote()
{
var body = ReportBugViewModel.BuildIssueBody("App version: 1.0", "it broke", "240101-000000-ABCD");
Assert.Contains("App version: 1.0", body, StringComparison.Ordinal);
Assert.Contains("it broke", body, StringComparison.Ordinal);
Assert.Contains("240101-000000-ABCD", body, StringComparison.Ordinal);
Assert.Contains("## Environment", body, StringComparison.Ordinal);
Assert.Contains("Attach the exported", body, StringComparison.Ordinal);
}
[Fact]
public void BuildIssueBody_UrlEscapingRoundTrips()
{
var body = ReportBugViewModel.BuildIssueBody("env", "spaces and #hash & more", errorCode: null);
var escaped = Uri.EscapeDataString(body);
Assert.Equal(body, Uri.UnescapeDataString(escaped));
}
}