Files
frameledger/tests/FrameLedger.App.Tests/AlphaStartTests.cs
poli0981andClaude Fable 5.2 1342979353 ci: Qodana - JetBrains' code analysis from a workflow of its own, and what its first run reported settled (D93) (#373)
* ci: Qodana - a workflow of its own from JetBrains' template, Qodana Community for .NET over FrameLedger.slnx (D93)

The first run: the linter in its Linux container, EnableWindowsTargeting passed
to it, no quality gate yet - what it builds and what it reports decides the rest.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* ci: Qodana's gate is zero problems, and the inspections this project argues with are off in .editorconfig, each with its reason (D93)

Pushed before the fixes on purpose: the run this starts has the settings and
none of the fixes, so it shows the gate failing on what is left.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix: what Qodana's first run reported, settled - about 400 fixes in 181 files, none changing behaviour; the documents (D93)

Redundant qualifiers, casts, using directives, nullable suppressions and unsafe
modifiers removed from the report's own positions; var for built-in types and
one-line block bodies brought to .editorconfig's style by dotnet format; every
XAML item template names its DataType and a binding that reached its page through
DataContext.ViewModel names the page's type; two unread fields, two overwritten
initialisers and an unused parameter removed; SpokenTextAutomationPeer no longer
assumes the base peer's name is a string.

docs/13_CI_CD.md §Qodana, CLAUDE.md, the wiki's workflow table, HANDOFF's
decisions index (D93) and the changelog entry.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-10 16:13:04 +00:00

93 lines
3.6 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 FluentAssertions;
using FrameLedger.App.Services;
using FrameLedger.Infrastructure.Persistence;
using FrameLedger.Shared;
namespace FrameLedger.App.Tests;
/// <summary>
/// What an alpha does at the App's start (D73, D74): the ledger copy it asks for — none on the main line, none in a viewer —
/// and the Agent held while its Legal Gate waits for the Alpha notice, released only by the Accept.
/// </summary>
public sealed class AlphaStartTests
{
private static CancellationToken Ct => TestContext.Current.CancellationToken;
private static IReadOnlyList<LegalDocument> AlphaDocs { get; } =
[
new("eula", "EULA", "1.0", "text", new Uri("https://github.com/x/eula")),
new(LegalDocuments.Alpha, "Alpha notice", AlphaNotice.Version, "text", new Uri("https://github.com/x/a")),
];
[Fact]
public void OnlyAnAlphaOverItsOwnFolderAsksForTheLedgerCopy()
{
string database = Path.Combine(Path.GetTempPath(), "fl-alpha-start", LedgerPaths.DatabaseFileName);
AlphaStart.BackupFor(BuildLine.Main, viewer: false, database, "0.1.0-beta.32").Should().BeNull("the main line copies nothing");
AlphaStart.BackupFor(BuildLine.Alpha, viewer: true, database, "0.1.0-alpha.1").Should().BeNull("a viewer reads a copy already");
LedgerBackupRequest? request = AlphaStart.BackupFor(BuildLine.Alpha, viewer: false, database, "0.1.0-alpha.1");
request.Should().NotBeNull();
request.Directory.Should().Be(LedgerPaths.BackupsDirectoryOf(database));
request.Version.Should().Be("0.1.0-alpha.1");
request.Keep.Should().Be(3);
}
[Fact]
public async Task AnAlphaWithTheNoticeOutstandingHoldsTheAgent()
{
await using ScratchLedger s = await ScratchLedger.OpenAsync();
var link = new FakeAgentLink();
(await AlphaStart.HoldTheAgentForTheNoticeAsync(BuildLine.Alpha, new LegalGate(new SqliteLegalAcceptanceStore(s.Db), AlphaDocs), link, Ct)).Should().BeTrue();
link.NoticeHolds.Should().Equal([true]);
}
[Fact]
public async Task AnAcceptedNoticeOrTheMainLineHoldsNothing()
{
await using ScratchLedger s = await ScratchLedger.OpenAsync();
var store = new SqliteLegalAcceptanceStore(s.Db);
var gate = new LegalGate(store, AlphaDocs);
var link = new FakeAgentLink();
(await AlphaStart.HoldTheAgentForTheNoticeAsync(BuildLine.Main, gate, link, Ct)).Should().BeFalse("the main line's Agent never waits for a notice");
await store.RecordAsync(new Application.Persistence.LegalAcceptance(LegalDocuments.Alpha, AlphaNotice.Version, DateTimeOffset.UnixEpoch), Ct);
(await AlphaStart.HoldTheAgentForTheNoticeAsync(BuildLine.Alpha, gate, link, Ct)).Should().BeFalse("the notice is accepted; only the EULA is outstanding");
link.NoticeHolds.Should().BeEmpty();
}
[Fact]
public void ALinkOrAWindowSetThatHasNothingToHoldOrShowAcceptsTheCall()
{
IAgentLink viewer = new ViewerAgentLink();
IDocumentWindows none = new NoDocuments();
viewer.Invoking(static v => v.SetNoticeHold(true)).Should().NotThrow("a viewer starts no Agent, so there is nothing to hold");
none.Invoking(static d => d.ShowAlphaNotice()).Should().NotThrow();
}
private sealed class NoDocuments : IDocumentWindows
{
public void ShowGuide()
{
}
public void ShowLimitations()
{
}
public void ShowAbout()
{
}
}
}