Record the course the user chose on 2 December 2026 and make the container the only form of Anubis. - ADR 0021-0026: new roadmap (phases 10-24, readings per phase, the spec-to-ADR table, merge and tag only after the user's yes), Docker only, maths-only decisions, bans turned into limits on margin accounts, eToro Demo as currency venue and forward tests, strategy championship. ROADMAP rewritten from phase 10; STATE, CLAUDE.md, SVILUPPO, README, API-NOTES and the manuals without the desktop. - Remove the desktop: Anubis.Desktop, Anubis.Setup, deploy/windows, release-win and desktop-win, config.toml, PlatformKind, ANUBIS_PLATFORM, DPAPI with the ProtectedData package and the first-run wizard. Outside a container the server needs --data-dir, listens on 127.0.0.1 only and refuses foreign hosts; server and guard refuse --platform desktop with an Italian message and exit code 2. The demo keeps its key in a file and its error-page choices need no startup password. The diagnostics report says where the server runs from its own environment. - Lighter image: restore and publish for linux-x64 only, and leave out the Windows libraries ONNX Runtime copies anyway (829 MB to 410 MB on disk, /app from 282 MB to 42 MB). Rotating Docker logs in the Unraid template, the manual and the compose; backtest and learning run as one-shot commands. tasks dev uses artifacts/dev-data. refs #113 #114 #115 #78 #80 #81 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
147 lines
6.5 KiB
C#
147 lines
6.5 KiB
C#
using System.Text.Json;
|
|
using System.Xml.Linq;
|
|
|
|
namespace Anubis.Tests;
|
|
|
|
/// <summary>ADR 0004 and 0006: only the packages the user authorised, and nothing else sneaking in.</summary>
|
|
[TestClass]
|
|
public sealed class DependencyPolicyTests
|
|
{
|
|
/// <summary>The list of ADR 0004 as precised by ADR 0006 and shortened by ADR 0022. Changing it needs the user's permission and a new ADR.</summary>
|
|
private static readonly HashSet<string> _authorised = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
"Microsoft.Data.Sqlite",
|
|
"MSTest.TestFramework",
|
|
"MSTest.TestAdapter",
|
|
"Microsoft.NET.Test.Sdk",
|
|
"Npgsql",
|
|
"Microsoft.ML",
|
|
"Microsoft.ML.LightGbm",
|
|
"Microsoft.ML.FastTree",
|
|
"Microsoft.ML.OnnxRuntime",
|
|
"Microsoft.ML.Tokenizers",
|
|
};
|
|
|
|
/// <summary>
|
|
/// Third-party packages pulled in by an authorised one. Each must also be listed in docs/API-NOTES.md
|
|
/// and reported to the user (checked below). Microsoft.* and System.* ids are reserved to Microsoft on nuget.org.
|
|
/// </summary>
|
|
private static readonly HashSet<string> _knownThirdPartyTransitive = new(StringComparer.OrdinalIgnoreCase)
|
|
{
|
|
// Native SQLite library and its loader, brought by Microsoft.Data.Sqlite (phase 1).
|
|
"SQLitePCLRaw.bundle_e_sqlite3",
|
|
"SQLitePCLRaw.core",
|
|
"SQLitePCLRaw.lib.e_sqlite3",
|
|
"SQLitePCLRaw.provider.e_sqlite3",
|
|
|
|
// Protocol buffers, brought by Microsoft.ML.Tokenizers (phase 7).
|
|
"Google.Protobuf",
|
|
};
|
|
|
|
private static readonly string[] _packageElements = ["PackageReference", "GlobalPackageReference", "PackageDownload"];
|
|
|
|
[TestMethod]
|
|
[TestCategory(Category.Unit)]
|
|
public void CentralVersionsListOnlyAuthorisedPackages()
|
|
{
|
|
var props = XDocument.Load(Path.Combine(Repo.Root.FullName, "Directory.Packages.props"));
|
|
var listed = props.Descendants()
|
|
.Where(e => e.Name.LocalName is "PackageVersion" or "GlobalPackageReference")
|
|
.Select(e => (string?)e.Attribute("Include") ?? "?")
|
|
.ToList();
|
|
|
|
var notAllowed = listed.Where(id => !_authorised.Contains(id)).ToList();
|
|
Assert.IsEmpty(notAllowed, "Pacchetti non autorizzati (ADR 0004): " + string.Join(", ", notAllowed));
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory(Category.Unit)]
|
|
public void ProjectsDoNotPinVersionsOrBypassTheCentralList()
|
|
{
|
|
string[] msbuildExtensions = [".csproj", ".props", ".targets"];
|
|
var problems = new List<string>();
|
|
foreach (var file in Repo.Files().Where(f => msbuildExtensions.Contains(f.Extension, StringComparer.OrdinalIgnoreCase)))
|
|
{
|
|
var isCentralList = file.Name.Equals("Directory.Packages.props", StringComparison.OrdinalIgnoreCase);
|
|
var doc = XDocument.Load(file.FullName);
|
|
foreach (var reference in doc.Descendants().Where(e => _packageElements.Contains(e.Name.LocalName)))
|
|
{
|
|
var id = (string?)reference.Attribute("Include") ?? (string?)reference.Attribute("Update") ?? "?";
|
|
if (!_authorised.Contains(id))
|
|
{
|
|
problems.Add($"{Repo.Relative(file)}: {id} non è autorizzato");
|
|
}
|
|
|
|
var ownVersion = reference.Attribute("Version") is not null
|
|
|| reference.Attribute("VersionOverride") is not null
|
|
|| reference.Elements().Any(e => e.Name.LocalName is "Version" or "VersionOverride");
|
|
if (ownVersion && !isCentralList)
|
|
{
|
|
problems.Add($"{Repo.Relative(file)}: {id} ha una versione propria");
|
|
}
|
|
}
|
|
}
|
|
|
|
Assert.IsEmpty(problems, string.Join(Environment.NewLine, problems));
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory(Category.Unit)]
|
|
public void LockFilesContainOnlyAuthorisedDirectPackagesAndKnownIndirectOnes()
|
|
{
|
|
var lockFiles = Repo.Files().Where(f => f.Name.Equals("packages.lock.json", StringComparison.OrdinalIgnoreCase)).ToList();
|
|
Assert.IsNotEmpty(lockFiles, "Nessun packages.lock.json: i file di blocco devono essere nel repository.");
|
|
|
|
var problems = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
|
|
foreach (var file in lockFiles)
|
|
{
|
|
using var doc = JsonDocument.Parse(File.ReadAllText(file.FullName));
|
|
foreach (var framework in doc.RootElement.GetProperty("dependencies").EnumerateObject())
|
|
{
|
|
foreach (var package in framework.Value.EnumerateObject())
|
|
{
|
|
var type = package.Value.TryGetProperty("type", out var t) ? t.GetString() : null;
|
|
var id = package.Name;
|
|
switch (type)
|
|
{
|
|
case "Project":
|
|
break;
|
|
case "Direct" or "CentralTransitive":
|
|
// Whatever a project asks for directly must be on the list, Microsoft or not.
|
|
if (!_authorised.Contains(id))
|
|
{
|
|
problems.Add($"{id} diretto non autorizzato (in {Repo.Relative(file)})");
|
|
}
|
|
|
|
break;
|
|
default:
|
|
if (!_authorised.Contains(id) && !IsMicrosoftId(id) && !_knownThirdPartyTransitive.Contains(id))
|
|
{
|
|
problems.Add($"{id} indiretto di terze parti non dichiarato (in {Repo.Relative(file)})");
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
Assert.IsEmpty(problems, string.Join(", ", problems));
|
|
}
|
|
|
|
[TestMethod]
|
|
[TestCategory(Category.Unit)]
|
|
public void KnownThirdPartyPackagesAreDocumentedInApiNotes()
|
|
{
|
|
var notes = File.ReadAllText(Path.Combine(Repo.Root.FullName, "docs", "API-NOTES.md"));
|
|
var missing = _knownThirdPartyTransitive.Where(id => !notes.Contains($"`{id}`", StringComparison.OrdinalIgnoreCase)).ToList();
|
|
Assert.IsEmpty(missing, "Dipendenze di terze parti non elencate in docs/API-NOTES.md: " + string.Join(", ", missing));
|
|
}
|
|
|
|
private static bool IsMicrosoftId(string id) =>
|
|
id.StartsWith("Microsoft.", StringComparison.OrdinalIgnoreCase)
|
|
|| id.StartsWith("System.", StringComparison.OrdinalIgnoreCase)
|
|
|| id.StartsWith("MSTest.", StringComparison.OrdinalIgnoreCase)
|
|
|| id.Equals("NETStandard.Library", StringComparison.OrdinalIgnoreCase);
|
|
}
|