Files
poli0981andClaude Fable 5.2 94eec7831c refactor: .NET 11's API where it reads better, and why no C# 15 construct is used yet - the canary, the table, the dispatch trigger for CodeQL (D96) (beta.37 PR-3) (#380)
The owner asked for C# 15 in the release that moved the main line to
.NET 11. The rule approved with the plan: a construct is used only
where the build, CodeQL and Qodana all read it. Each of the four was
written once, in a file of its own, and shown to each tool (draft pull
request #377, closed unmerged; spike-notes section 29):

- The compiler and every analyzer take collection expression arguments,
  closed hierarchies and labeled jumps; a union draws CA1815 from the
  SDK's own rules.
- ReSharper's engine - InspectCode 2026.2.3.1, which Qodana 2026.2
  runs, and 2026.3.0 - reads none: `closed` and `union` are not parsed,
  the other two are called preview features. On a gate of zero every
  file using one would be an error.
- What CodeQL extracts of them is not established: a pull request's C#
  analysis is an overlay on main's database and prints no per-file
  result.

So beta.37 takes API, not syntax:
- sixteen char searches name their comparison through
  string.StartsWith/EndsWith/LastIndexOf(char, StringComparison), where
  they went through a span to satisfy .NET 10 and 11 alike;
- AgentLauncher finds the Agent it started with
  Process.TryGetProcessById instead of a caught ArgumentException.
Nothing changes in what the software does.

codeql.yml takes workflow_dispatch, so a branch can have a full
analysis. 13_CI_CD (C# 15 and the analyses), 20_OPEN_QUESTIONS (a new
row, with what answers it), CLAUDE.md, the decisions index.

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

94 lines
3.3 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.Infrastructure.Detection;
namespace FrameLedger.Infrastructure.Tests.Detection;
/// <summary>
/// The install-root cases both resolvers read (beta.33): <c>tests/fixtures/install-roots/cases.txt</c>, answered here by
/// <see cref="InstallRoot.Resolve"/> and in <c>fl_guard_test</c> by the native <c>ResolveInstallRoot</c>. They had drifted:
/// the managed list carried <c>GamesInstalled</c> from #17 and the native one never did. A GDK package root is marked by
/// FILES (<c>MicrosoftGame.config</c> beside <c>appxmanifest.xml</c>, <c>spike-notes</c> §25), so each case builds its tree
/// in a folder of its own under the temp directory.
/// </summary>
public sealed class InstallRootCasesTests : IDisposable
{
private readonly string _temp = Path.Combine(Path.GetTempPath(), "fl-install-roots-" + Guid.NewGuid().ToString("N"));
private static string RepoRoot()
{
var dir = new DirectoryInfo(AppContext.BaseDirectory);
while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "FrameLedger.slnx")))
{
dir = dir.Parent;
}
dir.Should().NotBeNull("the cases live in the repository");
return dir.FullName;
}
public static TheoryData<string, string, string> Cases()
{
var data = new TheoryData<string, string, string>();
foreach (string line in File.ReadAllLines(Path.Combine(RepoRoot(), "tests", "fixtures", "install-roots", "cases.txt")))
{
if (line.Length == 0 || line[0] == '#')
{
continue;
}
string[] fields = line.Split('|');
fields.Should().HaveCount(3, $"'{line}' must be <files>|<exe>|<root>");
data.Add(fields[0], fields[1], fields[2]);
}
return data;
}
[Fact]
public void TheListIsNotEmpty() =>
Cases().Should().HaveCountGreaterThanOrEqualTo(10, "an empty list is a green theory that compared nothing");
[Theory]
[MemberData(nameof(Cases))]
public void EachSharedCaseResolvesToItsRoot(string files, string exe, string root)
{
ArgumentNullException.ThrowIfNull(files);
ArgumentNullException.ThrowIfNull(exe);
ArgumentNullException.ThrowIfNull(root);
Directory.CreateDirectory(_temp);
foreach (string item in files.Split(';', StringSplitOptions.RemoveEmptyEntries))
{
string path = Path.Combine(_temp, item);
if (item.EndsWith('\\', StringComparison.Ordinal))
{
Directory.CreateDirectory(path);
}
else
{
Directory.CreateDirectory(Path.GetDirectoryName(path)!);
File.WriteAllBytes(path, []);
}
}
InstallRoot.Resolve(Path.Combine(_temp, exe)).Should().Be(Path.Combine(_temp, root), $"the case for {exe}");
}
public void Dispose()
{
try
{
if (Directory.Exists(_temp))
{
Directory.Delete(_temp, recursive: true);
}
}
catch (IOException)
{
// A folder still in use is the OS's to clean; the case already answered.
}
}
}