* 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>
180 lines
8.0 KiB
C#
180 lines
8.0 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.App.ViewModels;
|
|
using FrameLedger.Infrastructure.Ipc;
|
|
using FrameLedger.Shared.Ipc;
|
|
using FrameLedger.Shared.Safety;
|
|
|
|
namespace FrameLedger.App.Tests;
|
|
|
|
/// <summary>
|
|
/// D33 (owner decision 2026-09-26) from the App's side: the version handshake gates the disclosure, a declined disclosure
|
|
/// sends nothing, an accepted one sends exactly <c>SetAntiCheatException { enabled: true, disclosureVersion: ours }</c>, and the
|
|
/// Agent's answers — granted, refused, option off, version mismatch — come back as what they are.
|
|
/// </summary>
|
|
[Collection(StringsCultureCollection.Name)]
|
|
public sealed class AntiCheatExceptionsTests
|
|
{
|
|
private static CancellationToken Ct => TestContext.Current.CancellationToken;
|
|
|
|
private static readonly AntiCheatExceptionFacts _gf2 = new("GIRLS' FRONTLINE 2: EXILIUM", "NetEase Yidun", "NEP2.dll");
|
|
|
|
private static HelloAck Hello(string? exceptionDisclosure) =>
|
|
new("agent", IpcProtocol.Version, 1, false, "b", false, "l1", false, SafetyDisclosure.Version, exceptionDisclosure);
|
|
|
|
private sealed class FakeAgent : IAgentRequests
|
|
{
|
|
public HelloAck? Hello { get; set; }
|
|
|
|
public bool IsConnected { get; set; } = true;
|
|
|
|
public List<(string Type, object Payload)> Sent { get; } = [];
|
|
|
|
public Func<object, IpcEnvelope> Answer { get; set; } = static _ => throw new InvalidOperationException("no answer scripted");
|
|
|
|
public Task<IpcEnvelope> RequestAsync<TRequest>(string type, TRequest payload, CancellationToken ct = default)
|
|
where TRequest : class
|
|
{
|
|
Sent.Add((type, payload));
|
|
return Task.FromResult(Answer(payload));
|
|
}
|
|
}
|
|
|
|
private sealed class FakePrompt : IAntiCheatExceptionPrompt
|
|
{
|
|
public bool Accepts { get; set; }
|
|
|
|
public List<AntiCheatExceptionFacts> Shown { get; } = [];
|
|
|
|
public Task<bool> ShowAsync(AntiCheatExceptionFacts facts, CancellationToken ct = default)
|
|
{
|
|
Shown.Add(facts);
|
|
return Task.FromResult(Accepts);
|
|
}
|
|
}
|
|
|
|
private static IpcEnvelope Ack<T>(string type, T payload) where T : class => IpcCodec.Decode(IpcCodec.Encode(type, "1", payload));
|
|
|
|
[Fact]
|
|
public async Task AnAgentThatGrantsAgainstOtherTextGetsNoDialogAndNoRequest()
|
|
{
|
|
var agent = new FakeAgent { Hello = Hello("ac-exception-dialog/0") };
|
|
var prompt = new FakePrompt { Accepts = true };
|
|
|
|
AntiCheatExceptionResult result = await new AntiCheatExceptions(agent, prompt).GrantAsync(56, _gf2, Ct);
|
|
|
|
result.Outcome.Should().Be(AntiCheatExceptionOutcome.VersionMismatch);
|
|
prompt.Shown.Should().BeEmpty();
|
|
agent.Sent.Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task ADeclinedDisclosureSendsNothing()
|
|
{
|
|
var agent = new FakeAgent { Hello = Hello(AntiCheatExceptionDisclosure.Version) };
|
|
var prompt = new FakePrompt { Accepts = false };
|
|
|
|
(await new AntiCheatExceptions(agent, prompt).GrantAsync(56, _gf2, Ct)).Outcome.Should().Be(AntiCheatExceptionOutcome.Declined);
|
|
|
|
prompt.Shown.Should().Equal(_gf2);
|
|
agent.Sent.Should().BeEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AnAcceptedDisclosureSendsOurVersionAndAGrantIsAGrant()
|
|
{
|
|
var agent = new FakeAgent
|
|
{
|
|
Hello = Hello(AntiCheatExceptionDisclosure.Version),
|
|
Answer = static _ => Ack(IpcMessageType.AntiCheatExceptionAck, new AntiCheatExceptionAck(56, true, "Written", "NetEase Yidun")),
|
|
};
|
|
|
|
AntiCheatExceptionResult result = await new AntiCheatExceptions(agent, new FakePrompt { Accepts = true }).GrantAsync(56, _gf2, Ct);
|
|
|
|
result.Outcome.Should().Be(AntiCheatExceptionOutcome.Granted);
|
|
agent.Sent.Should().ContainSingle().Which.Should().Be((IpcMessageType.SetAntiCheatException,
|
|
new SetAntiCheatExceptionRequest(56, true, AntiCheatExceptionDisclosure.Version)));
|
|
}
|
|
|
|
[Fact]
|
|
public async Task TheAgentsRefusalsComeBackAsWhatTheyAre()
|
|
{
|
|
var agent = new FakeAgent
|
|
{
|
|
Hello = Hello(AntiCheatExceptionDisclosure.Version),
|
|
// D38: a game whose exception once failed its trial is refused for good; the signal is when, in unix ms.
|
|
Answer = static _ => Ack(IpcMessageType.Refused, new RefusedAck(56, "TrialFailed", "NetEase Yidun", "1759449600000")),
|
|
};
|
|
var exceptions = new AntiCheatExceptions(agent, new FakePrompt { Accepts = true });
|
|
|
|
AntiCheatExceptionResult failed = await exceptions.GrantAsync(56, _gf2, Ct);
|
|
failed.Outcome.Should().Be(AntiCheatExceptionOutcome.Refused);
|
|
failed.RefusalText().Should().Contain("trial").And.Contain(Formats.Date(DateTimeOffset.FromUnixTimeMilliseconds(1759449600000)));
|
|
|
|
agent.Answer = static _ => throw new IpcRequestException(IpcErrorCode.ExceptionsOff, "off");
|
|
(await exceptions.GrantAsync(56, _gf2, Ct)).Outcome.Should().Be(AntiCheatExceptionOutcome.OptionOff);
|
|
|
|
agent.Answer = static _ => throw new IpcRequestException(IpcErrorCode.DisclosureVersionMismatch, "restart");
|
|
(await exceptions.GrantAsync(56, _gf2, Ct)).Outcome.Should().Be(AntiCheatExceptionOutcome.VersionMismatch);
|
|
}
|
|
|
|
/// <summary>
|
|
/// beta.22: an ask the Agent never answered is not known, and its notice says so in words — it read "IOException"; one the
|
|
/// connection was gone before is "no agent", which changed nothing.
|
|
/// </summary>
|
|
[Fact]
|
|
public async Task AnAskTheAgentNeverAnsweredIsNotKnownAndSaidInWords()
|
|
{
|
|
var agent = new FakeAgent
|
|
{
|
|
Hello = Hello(AntiCheatExceptionDisclosure.Version),
|
|
Answer = static _ => throw new IOException("the connection to the Agent closed before it answered"),
|
|
};
|
|
var exceptions = new AntiCheatExceptions(agent, new FakePrompt { Accepts = true });
|
|
|
|
AntiCheatExceptionResult closed = await exceptions.GrantAsync(56, _gf2, Ct);
|
|
closed.Outcome.Should().Be(AntiCheatExceptionOutcome.Unanswered);
|
|
closed.MessageFor("GIRLS' FRONTLINE 2").Should().Be(Strings.Agent_Unanswered);
|
|
|
|
agent.Answer = static _ => throw new TimeoutException();
|
|
(await exceptions.WithdrawAsync(56, Ct)).Outcome.Should().Be(AntiCheatExceptionOutcome.Unanswered);
|
|
|
|
agent.Answer = static _ => throw new InvalidOperationException("the Agent is not connected");
|
|
(await exceptions.WithdrawAsync(56, Ct)).Outcome.Should().Be(AntiCheatExceptionOutcome.AgentUnavailable, "nothing was sent");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task AWithdrawalNeedsNoDialog()
|
|
{
|
|
var agent = new FakeAgent
|
|
{
|
|
Hello = Hello(AntiCheatExceptionDisclosure.Version),
|
|
Answer = static _ => Ack(IpcMessageType.AntiCheatExceptionAck, new AntiCheatExceptionAck(56, false, "Written", "NetEase Yidun")),
|
|
};
|
|
var prompt = new FakePrompt();
|
|
|
|
(await new AntiCheatExceptions(agent, prompt).WithdrawAsync(56, Ct)).Outcome.Should().Be(AntiCheatExceptionOutcome.Withdrawn);
|
|
|
|
prompt.Shown.Should().BeEmpty();
|
|
agent.Sent.Should().ContainSingle().Which.Payload.Should().Be(new SetAntiCheatExceptionRequest(56, false, null));
|
|
}
|
|
|
|
[Fact]
|
|
public void TheDisclosuresButtonWaitsForTheTick()
|
|
{
|
|
var viewModel = new AntiCheatExceptionDialogViewModel(_gf2);
|
|
|
|
viewModel.Accepted.Should().BeFalse("the dialog opens with the risk unaccepted");
|
|
viewModel.Intro.Should().Contain("NetEase Yidun").And.Contain("NEP2.dll");
|
|
viewModel.Why.Should().Contain("NetEase Yidun").And.NotContain("{1}", "D38: the disclosure names no session count");
|
|
AntiCheatExceptionDialogViewModel.Trial.Should().Contain("trial", "D38: the grant's first two sessions are a trial, and the disclosure says so");
|
|
viewModel.Risk.Should().Contain("NetEase Yidun");
|
|
viewModel.Accepted = true;
|
|
viewModel.Accepted.Should().BeTrue();
|
|
}
|
|
}
|