* 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>
73 lines
3.2 KiB
C#
73 lines
3.2 KiB
C#
// SPDX-License-Identifier: GPL-3.0-only
|
|
// Copyright (C) 2026 poli0981 - additional terms under GPLv3 section 7: see NOTICE
|
|
|
|
using FluentAssertions;
|
|
using FrameLedger.App.Services;
|
|
|
|
namespace FrameLedger.App.Tests;
|
|
|
|
/// <summary>
|
|
/// One App per data folder (2026-09-21): the owner's log showed two started 360 ms apart, each with a shell and a tray
|
|
/// icon. The first claim wins; a later one is told so, asks the first to show itself, and must not start; and the
|
|
/// claim ends with the process that holds it.
|
|
/// </summary>
|
|
public sealed class SingleInstanceTests
|
|
{
|
|
private static string UniqueKey() => SingleInstance.KeyOf(@"C:\fl-tests\" + Guid.NewGuid().ToString("N"));
|
|
|
|
[Fact]
|
|
public void TheFirstStartClaimsTheFolderAndALaterOneHandsOverAndIsRefused()
|
|
{
|
|
string key = UniqueKey();
|
|
SingleInstance.TryClaim(key, out SingleInstance? first).Should().Be(SingleInstance.Claim.Acquired);
|
|
using (first)
|
|
{
|
|
first.Should().NotBeNull();
|
|
using var revealed = new ManualResetEventSlim(false);
|
|
first.RevealRequested += (_, _) => revealed.Set();
|
|
|
|
SingleInstance.Claim later = SingleInstance.TryClaim(key, out SingleInstance? second);
|
|
using (second)
|
|
{
|
|
later.Should().Be(SingleInstance.Claim.AnotherInstanceIsRunning);
|
|
second.Should().BeNull("the second start gets nothing to hold: it exits");
|
|
}
|
|
|
|
revealed.Wait(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken).Should().BeTrue("the running instance is asked to bring its window forward");
|
|
|
|
// And again: the event is not one-shot, because the user can click the shortcut any number of times.
|
|
revealed.Reset();
|
|
SingleInstance.Claim third = SingleInstance.TryClaim(key, out SingleInstance? none);
|
|
none?.Dispose();
|
|
third.Should().Be(SingleInstance.Claim.AnotherInstanceIsRunning);
|
|
revealed.Wait(TimeSpan.FromSeconds(5), TestContext.Current.CancellationToken).Should().BeTrue();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void TheClaimEndsWithItsHolderAndAnotherFolderIsAnotherInstance()
|
|
{
|
|
string key = UniqueKey();
|
|
SingleInstance.TryClaim(key, out SingleInstance? first).Should().Be(SingleInstance.Claim.Acquired);
|
|
first!.Dispose();
|
|
first.Dispose();
|
|
|
|
SingleInstance.TryClaim(key, out SingleInstance? again).Should().Be(SingleInstance.Claim.Acquired, "the App that held it has exited");
|
|
using (again)
|
|
{
|
|
SingleInstance.TryClaim(UniqueKey(), out SingleInstance? elsewhere).Should().Be(SingleInstance.Claim.Acquired, "an App pointed at another data folder is its own instance");
|
|
elsewhere!.Dispose();
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void TheKeyIsTheFolderWhateverItsCaseOrTrailingSeparator()
|
|
{
|
|
string key = SingleInstance.KeyOf(@"C:\Users\someone\AppData\Local\FrameLedger");
|
|
|
|
SingleInstance.KeyOf(@"c:\users\SOMEONE\appdata\local\frameledger\").Should().Be(key);
|
|
SingleInstance.KeyOf(@"C:\Users\someone\AppData\Local\Other").Should().NotBe(key);
|
|
key.Should().MatchRegex("^[0-9A-F]{16}$", "a path is not a legal kernel object name; a hash is");
|
|
}
|
|
}
|