Add opt-in PostIt exception reporting

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Paul Schneider 2026-11-14 18:09:45 +00:00
commit 6839d9cac9
Signed by: notazof
GPG key ID: AD4B9B545FBD7D12
12 changed files with 165 additions and 13 deletions

View file

@ -175,6 +175,20 @@ public class SettingsLoadTests
Assert.Equal("bonjour", roundTrip.SearchText);
}
[Fact]
public void Exception_reports_are_disabled_by_default_and_persist_when_enabled()
{
var defaults = new PostIt.ViewModels.Settings();
Assert.False(defaults.ShareExceptionReports);
defaults.ShareExceptionReports = true;
var roundTrip = JsonSerializer.Deserialize<PostIt.ViewModels.Settings>(
JsonSerializer.Serialize(defaults));
Assert.NotNull(roundTrip);
Assert.True(roundTrip.ShareExceptionReports);
}
/// <summary>
/// First-start regression guard: older settings payloads can
/// still contain <c>ActionStatus</c> from a previous write. This

View file

@ -19,6 +19,51 @@ namespace PostIt.Tests;
[Trait("Category", "non-reg")]
public class YavscApiClientTests
{
[Fact]
public async Task Exception_reports_are_sent_only_after_local_opt_in()
{
using var apiServer = new StubApiServer();
await apiServer.StartAsync();
var tokensPath = TokensPath();
try
{
var settings = new Settings
{
ApiUrl = apiServer.BaseUrl + "/api/v1/",
ShareExceptionReports = true,
Authentication = new AuthenticationSettings
{
Authority = "https://example.test/"
}
};
settings.Load();
var store = new TokenStore(tokensPath);
store.Save(new RefreshTokenRecord(
"access", "refresh", DateTimeOffset.UtcNow.AddMinutes(5)));
await using var client = new YavscApiClient(settings, store);
Assert.True(settings.ShareExceptionReports);
Assert.True(client.HasValidSession);
var reportWasSent = await client.ReportExceptionAsync(
new InvalidOperationException("Messaging service unavailable"),
"PostIt.Android.Chat",
TestContext.Current.CancellationToken);
Assert.True(reportWasSent, $"share={settings.ShareExceptionReports}; session={client.HasValidSession}");
Assert.Equal(1, apiServer.RequestCount);
settings.ShareExceptionReports = false;
Assert.False(await client.ReportExceptionAsync(
new InvalidOperationException("Do not send"),
"PostIt.Android.Chat",
TestContext.Current.CancellationToken));
Assert.Equal(1, apiServer.RequestCount);
}
finally
{
if (File.Exists(tokensPath)) File.Delete(tokensPath);
}
}
[Theory]
[InlineData(false)]
[InlineData(true)]