Close phase 0 review findings: stricter policy scans, property generator, hook
ci / test (postgres) (push) Successful in 1m24s
ci / test (sqlite) (push) Successful in 1m35s
ci / image (push) Successful in 16s
ci / test (postgres) (pull_request) Successful in 1m11s
ci / test (sqlite) (pull_request) Successful in 1m24s
ci / image (pull_request) Successful in 14s

The independent review found that the policy tests could be bypassed:
Microsoft-named direct packages and GlobalPackageReference slipped past
the dependency check, the live-money scan missed the JSON, Dockerfile
and Unraid template forms, the secret scan missed short project
secrets but would have failed on the user's own ignored .env. The
scans now read only the files git would commit and cover those cases.

Also adds the fixed-seed generator for property tests, the REGISTRY
variables reserved for phase 9 in the CI, a git pre-commit hook in
place of the pre-commit tool (tasks hooks), the missing SPEC 4 facts
in API-NOTES (Fed/ECB/BLS times, USDC depth on OKX) and the full list
of today's indirect packages.

refs #3 refs #5 refs #6

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-10 10:05:10 +01:00
1 parent b4bf864f74
commit 52550ee6d1
15 files changed
+400 -83

No files matched your search

+55 -25
View File
@@ -3,11 +3,11 @@ using System.Xml.Linq;
namespace Anubis.Tests;
/// <summary>ADR 0004: only the packages the user authorised, and nothing else sneaking in.</summary>
/// <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. Changing it needs the user's permission and a new ADR.</summary>
/// <summary>The list of ADR 0004 as precised by ADR 0006. Changing it needs the user's permission and a new ADR.</summary>
private static readonly HashSet<string> _authorised = new(StringComparer.OrdinalIgnoreCase)
{
"Microsoft.Data.Sqlite",
@@ -25,17 +25,22 @@ public sealed class DependencyPolicyTests
};
/// <summary>
/// Third-party packages pulled in by an authorised one, each listed in docs/API-NOTES.md and
/// reported to the user. Microsoft.* and System.* ids are reserved to Microsoft on nuget.org.
/// 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);
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("PackageVersion").Select(e => (string)e.Attribute("Include")!).ToList();
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));
@@ -45,21 +50,26 @@ public sealed class DependencyPolicyTests
[TestCategory(Category.Unit)]
public void ProjectsDoNotPinVersionsOrBypassTheCentralList()
{
string[] msbuildExtensions = [".csproj", ".props", ".targets"];
var problems = new List<string>();
foreach (var project in Repo.Files().Where(f => f.Extension.Equals(".csproj", StringComparison.OrdinalIgnoreCase)))
foreach (var file in Repo.Files().Where(f => msbuildExtensions.Contains(f.Extension, StringComparer.OrdinalIgnoreCase)))
{
var doc = XDocument.Load(project.FullName);
foreach (var reference in doc.Descendants("PackageReference"))
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") ?? "?";
if (reference.Attribute("Version") is not null || reference.Attribute("VersionOverride") is not null)
{
problems.Add($"{Repo.Relative(project)}: {id} ha una versione propria");
}
var id = (string?)reference.Attribute("Include") ?? (string?)reference.Attribute("Update") ?? "?";
if (!_authorised.Contains(id))
{
problems.Add($"{Repo.Relative(project)}: {id} non è autorizzato");
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");
}
}
}
@@ -69,12 +79,12 @@ public sealed class DependencyPolicyTests
[TestMethod]
[TestCategory(Category.Unit)]
public void LockFilesContainNoUnknownThirdPartyPackage()
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 unknown = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
var problems = new SortedSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var file in lockFiles)
{
using var doc = JsonDocument.Parse(File.ReadAllText(file.FullName));
@@ -83,21 +93,41 @@ public sealed class DependencyPolicyTests
foreach (var package in framework.Value.EnumerateObject())
{
var type = package.Value.TryGetProperty("type", out var t) ? t.GetString() : null;
if (type == "Project")
{
continue;
}
var id = package.Name;
if (!_authorised.Contains(id) && !IsMicrosoftId(id) && !_knownThirdPartyTransitive.Contains(id))
switch (type)
{
unknown.Add($"{id} (in {Repo.Relative(file)})");
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(unknown, "Dipendenze di terze parti non dichiarate: " + string.Join(", ", unknown));
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) =>