feat: bootstrap solution, Docker image and Gitea pipelines (M0)
CI / Build and test (SQLite) (pull_request) Successful in 43s
CI / PostgreSQL 16 integration (pull_request) Skipped
CI / PostgreSQL 17 integration (pull_request) Skipped
CI / YAML check (pull_request) Successful in 15s
CI / Docker image (pull_request) Successful in 59s

Start development with the skeleton every later milestone builds on, so
that code, image and release path exist and are verified from day one.

- Khaemhat.sln with the ten projects of SPEC section 3 and six MSTest
  projects; shared build rules with warnings as errors, analyzers and
  Central Package Management restricted to the allowlist.
- Architecture tests and scripts/check-packages.sh fail on any project
  reference or package that SPEC does not allow.
- Khaemhat.Web serves an Italian "under construction" page with the
  official icons and version, plus /health/live, /health/ready and
  /health (ADR 0012); honours KHAEMHAT_URLS and KHAEMHAT_LOG_LEVEL.
- docker/Dockerfile (non-root app user aligned to PUID/PGID by the
  entrypoint, pg_dump 17, healthcheck, OCI and Unraid labels) and
  compose files for PostgreSQL and a standalone SQLite demo.
- Gitea Actions: ci.yml (build, tests, image smoke test, PostgreSQL
  16/17 on tags, YAML check), release.yml (image and release from a
  vX.Y.Z tag, skipping versions already published) and wiki.yml.
- Development scripts, VS Code launch/tasks for debugging, and ADR
  0012-0017 deciding the M0 open points of docs/STATUS.md.

Closes #1, #2, #3, #4, #5, #114

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-11 11:53:39 +01:00
1 parent 88de272b3e
commit 12277733f5
101 files changed
+3245 -67

No files matched your search

+11
View File
@@ -0,0 +1,11 @@
<Project>
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
<!-- Test projects: MSTest only (SPEC §1.2). -->
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="MSTest" />
</ItemGroup>
<ItemGroup>
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
</ItemGroup>
</Project>
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Khaemhat.Application.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/Khaemhat.Application/Khaemhat.Application.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,10 @@
namespace Khaemhat.Application.Tests;
/// <summary>Keeps the test project runnable until the milestone that fills it (see docs/STATUS.md).</summary>
[TestClass]
public sealed class ProjectSmokeTests
{
[TestMethod]
public void TestedAssembly_IsKhaemhat() =>
StringAssert.StartsWith(typeof(ProjectSmokeTests).Assembly.GetName().Name, "Khaemhat.");
}
@@ -0,0 +1,117 @@
using System.Xml.Linq;
namespace Khaemhat.Core.Tests.Architecture;
/// <summary>
/// Project dependency rules of SPEC §3 and the package allowlist of SPEC §1.2 (ADR 0002). They read the project
/// files, so a forbidden reference fails here before anyone builds on it.
/// </summary>
[TestClass]
public sealed class DependencyRulesTests
{
// What each production project may reference: exactly SPEC §3.
private static readonly Dictionary<string, string[]> AllowedReferences = new(StringComparer.Ordinal)
{
["Khaemhat.Core"] = [],
["Khaemhat.Fiscal.Abstractions"] = ["Khaemhat.Core"],
["Khaemhat.Fiscal.Italy"] = ["Khaemhat.Core", "Khaemhat.Fiscal.Abstractions", "Khaemhat.Infrastructure"],
["Khaemhat.Data"] = ["Khaemhat.Core"],
["Khaemhat.Data.Sqlite"] = ["Khaemhat.Data"],
["Khaemhat.Data.PostgreSql"] = ["Khaemhat.Data"],
["Khaemhat.Infrastructure"] = ["Khaemhat.Core", "Khaemhat.Data"],
["Khaemhat.Application"] = ["Khaemhat.Core", "Khaemhat.Data", "Khaemhat.Infrastructure", "Khaemhat.Fiscal.Abstractions"],
["Khaemhat.Web"] = ["Khaemhat.Application", "Khaemhat.Data.Sqlite", "Khaemhat.Data.PostgreSql", "Khaemhat.Fiscal.Italy"],
["Khaemhat.LicenseTool"] = ["Khaemhat.Core", "Khaemhat.Infrastructure"],
};
// The only packages, and where each may be referenced.
private static readonly Dictionary<string, Func<string, bool>> AllowedPackages = new(StringComparer.OrdinalIgnoreCase)
{
["Npgsql"] = file => Name(file) == "Khaemhat.Data.PostgreSql",
["Microsoft.Data.Sqlite"] = file => Name(file) == "Khaemhat.Data.Sqlite",
["Microsoft.NET.Test.Sdk"] = IsTestFile,
["MSTest"] = IsTestFile,
};
[TestMethod]
public void EveryProductionProject_HasDependencyRules()
{
var unknown = RepositoryLayout.Projects().Keys
.Where(name => !name.EndsWith(".Tests", StringComparison.Ordinal) && !AllowedReferences.ContainsKey(name))
.ToList();
Assert.IsEmpty(unknown, "Projects without dependency rules (add them to SPEC §3 and this test): " + string.Join(", ", unknown));
}
[TestMethod]
public void ProductionProjects_ReferenceOnlyWhatSpecSection3Allows()
{
var violations = new List<string>();
foreach (var (name, file) in RepositoryLayout.Projects())
{
if (!AllowedReferences.TryGetValue(name, out var allowed))
{
continue;
}
foreach (var reference in RepositoryLayout.ProjectReferences(file).Except(allowed, StringComparer.Ordinal))
{
violations.Add($"{name} -> {reference}");
}
}
Assert.IsEmpty(violations, "Forbidden project references: " + string.Join("; ", violations));
}
[TestMethod]
public void TestProjects_ReferenceOnlyKhaemhatProjects()
{
var violations = RepositoryLayout.Projects()
.Where(p => p.Key.EndsWith(".Tests", StringComparison.Ordinal))
.SelectMany(p => RepositoryLayout.ProjectReferences(p.Value)
.Where(r => !r.StartsWith("Khaemhat.", StringComparison.Ordinal))
.Select(r => $"{p.Key} -> {r}"))
.ToList();
Assert.IsEmpty(violations, string.Join("; ", violations));
}
[TestMethod]
public void Packages_AreOnTheAllowlistAndInTheirProjects()
{
var violations = new List<string>();
foreach (var file in RepositoryLayout.MsBuildFiles())
{
foreach (var package in RepositoryLayout.PackageReferences(file))
{
if (!AllowedPackages.TryGetValue(package, out var allowedIn))
{
violations.Add($"{RepositoryLayout.Relative(file)}: {package} is not on the allowlist (SPEC §1.2)");
}
else if (!allowedIn(file))
{
violations.Add($"{RepositoryLayout.Relative(file)}: {package} is not allowed in this project");
}
}
}
Assert.IsEmpty(violations, string.Join(Environment.NewLine, violations));
}
[TestMethod]
public void CentralPackageVersions_ListOnlyAllowedPackages()
{
var file = Path.Combine(RepositoryLayout.Root, "Directory.Packages.props");
var extra = XDocument.Load(file).Descendants()
.Where(e => e.Name.LocalName == "PackageVersion")
.Select(e => (string?)e.Attribute("Include") ?? string.Empty)
.Where(p => !AllowedPackages.ContainsKey(p))
.ToList();
Assert.IsEmpty(extra, "Directory.Packages.props declares packages outside the allowlist: " + string.Join(", ", extra));
}
private static string Name(string file) => Path.GetFileNameWithoutExtension(file);
private static bool IsTestFile(string file) => RepositoryLayout.Relative(file).StartsWith("tests/", StringComparison.Ordinal);
}
@@ -0,0 +1,88 @@
using System.Xml.Linq;
namespace Khaemhat.Core.Tests.Architecture;
/// <summary>Reads the solution's project files from the repository, without loading the projects.</summary>
internal static class RepositoryLayout
{
private static readonly Lazy<string> RootPath = new(FindRoot);
/// <summary>The repository root (the folder holding <c>Khaemhat.sln</c>).</summary>
public static string Root => RootPath.Value;
/// <summary>Every project file under <c>src/</c>, <c>tests/</c> and <c>tools/</c>, by project name.</summary>
public static IReadOnlyDictionary<string, string> Projects()
{
var result = new Dictionary<string, string>(StringComparer.Ordinal);
foreach (var folder in new[] { "src", "tests", "tools" })
{
var path = Path.Combine(Root, folder);
if (!Directory.Exists(path))
{
continue;
}
foreach (var file in Directory.EnumerateFiles(path, "*.csproj", SearchOption.AllDirectories))
{
if (!IsBuildOutput(file))
{
result[Path.GetFileNameWithoutExtension(file)] = file;
}
}
}
return result;
}
/// <summary>Names of the projects referenced by a project file.</summary>
public static IReadOnlySet<string> ProjectReferences(string projectFile) =>
Includes(projectFile, "ProjectReference")
.Select(include => Path.GetFileNameWithoutExtension(include.Replace('\\', '/')))
.ToHashSet(StringComparer.Ordinal);
/// <summary>Package ids referenced by a project or props file.</summary>
public static IReadOnlySet<string> PackageReferences(string file) =>
Includes(file, "PackageReference").ToHashSet(StringComparer.OrdinalIgnoreCase);
/// <summary>Every MSBuild file (projects, props, targets) of the repository that could declare packages.</summary>
public static IEnumerable<string> MsBuildFiles() =>
Directory.EnumerateFiles(Root, "*.*", SearchOption.AllDirectories)
.Where(f => f.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase)
|| f.EndsWith(".props", StringComparison.OrdinalIgnoreCase)
|| f.EndsWith(".targets", StringComparison.OrdinalIgnoreCase))
.Where(f => !IsBuildOutput(f) && !IsUnderIgnoredFolder(f));
/// <summary>The path of a file relative to the repository root, with forward slashes.</summary>
public static string Relative(string file) => Path.GetRelativePath(Root, file).Replace('\\', '/');
private static IEnumerable<string> Includes(string file, string element) =>
XDocument.Load(file).Descendants()
.Where(e => e.Name.LocalName == element)
.Select(e => (string?)e.Attribute("Include") ?? (string?)e.Attribute("Update") ?? string.Empty)
.Where(s => s.Length > 0);
private static bool IsBuildOutput(string path)
{
var p = path.Replace('\\', '/');
return p.Contains("/bin/", StringComparison.Ordinal) || p.Contains("/obj/", StringComparison.Ordinal);
}
private static bool IsUnderIgnoredFolder(string path)
{
var relative = Relative(path);
return relative.StartsWith(".git/", StringComparison.Ordinal)
|| relative.StartsWith(".claude/", StringComparison.Ordinal)
|| relative.StartsWith("out/", StringComparison.Ordinal);
}
private static string FindRoot()
{
var dir = new DirectoryInfo(AppContext.BaseDirectory);
while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "Khaemhat.sln")))
{
dir = dir.Parent;
}
return dir?.FullName ?? throw new InvalidOperationException("Repository root (Khaemhat.sln) not found.");
}
}
@@ -0,0 +1,31 @@
using Khaemhat.Core.Common;
namespace Khaemhat.Core.Tests.Common;
[TestClass]
public sealed class ProductVersionTests
{
[TestMethod]
[DataRow("1.2.3+abcdef1234567890", "1.2.3", "abcdef1", "1.2", "1.2.3+abcdef1")]
[DataRow("0.1.0-dev+abc1234", "0.1.0-dev", "abc1234", "0.1", "0.1.0-dev+abc1234")]
[DataRow("2.0.0", "2.0.0", "", "2.0", "2.0.0")]
[DataRow("", "0.0.0-dev", "", "0.0", "0.0.0-dev")]
[DataRow(null, "0.0.0-dev", "", "0.0", "0.0.0-dev")]
public void Parse_ReadsVersionRevisionAndShortForms(string? input, string version, string revision, string majorMinor, string full)
{
var parsed = ProductVersion.Parse(input);
Assert.AreEqual(version, parsed.Version);
Assert.AreEqual(revision, parsed.Revision);
Assert.AreEqual(majorMinor, parsed.MajorMinor);
Assert.AreEqual(full, parsed.Full);
}
[TestMethod]
public void FromAssembly_ReadsTheInformationalVersion()
{
var version = ProductVersion.FromAssembly(typeof(ProductVersion).Assembly);
Assert.IsFalse(string.IsNullOrEmpty(version.Version));
}
}
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Khaemhat.Core.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/Khaemhat.Core/Khaemhat.Core.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Khaemhat.Data.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/Khaemhat.Data/Khaemhat.Data.csproj" />
<ProjectReference Include="../../src/Khaemhat.Data.Sqlite/Khaemhat.Data.Sqlite.csproj" />
<ProjectReference Include="../../src/Khaemhat.Data.PostgreSql/Khaemhat.Data.PostgreSql.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,10 @@
namespace Khaemhat.Data.Tests;
/// <summary>Keeps the test project runnable until the milestone that fills it (see docs/STATUS.md).</summary>
[TestClass]
public sealed class ProjectSmokeTests
{
[TestMethod]
public void TestedAssembly_IsKhaemhat() =>
StringAssert.StartsWith(typeof(ProjectSmokeTests).Assembly.GetName().Name, "Khaemhat.");
}
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Khaemhat.Fiscal.Italy.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/Khaemhat.Fiscal.Italy/Khaemhat.Fiscal.Italy.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,10 @@
namespace Khaemhat.Fiscal.Italy.Tests;
/// <summary>Keeps the test project runnable until the milestone that fills it (see docs/STATUS.md).</summary>
[TestClass]
public sealed class ProjectSmokeTests
{
[TestMethod]
public void TestedAssembly_IsKhaemhat() =>
StringAssert.StartsWith(typeof(ProjectSmokeTests).Assembly.GetName().Name, "Khaemhat.");
}
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Khaemhat.Infrastructure.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/Khaemhat.Infrastructure/Khaemhat.Infrastructure.csproj" />
</ItemGroup>
</Project>
@@ -0,0 +1,10 @@
namespace Khaemhat.Infrastructure.Tests;
/// <summary>Keeps the test project runnable until the milestone that fills it (see docs/STATUS.md).</summary>
[TestClass]
public sealed class ProjectSmokeTests
{
[TestMethod]
public void TestedAssembly_IsKhaemhat() =>
StringAssert.StartsWith(typeof(ProjectSmokeTests).Assembly.GetName().Name, "Khaemhat.");
}
@@ -0,0 +1,78 @@
using System.Net;
using System.Net.Http.Json;
using Khaemhat.Web.Hosting;
using Microsoft.AspNetCore.Builder;
namespace Khaemhat.Web.Tests.Hosting;
/// <summary>
/// Starts the real host on a free loopback port (no test-host package: SPEC §1.2) and calls it over HTTP.
/// </summary>
[TestClass]
public sealed class HostTests
{
private static WebApplication? _app;
private static HttpClient? _client;
[ClassInitialize]
public static async Task StartAsync(TestContext context)
{
_app = KhaemhatApp.Build(["--urls", "http://127.0.0.1:0", "--environment", "Production"]);
await _app.StartAsync(context.CancellationToken);
_client = new HttpClient { BaseAddress = new Uri(_app.Urls.First()) };
}
[ClassCleanup]
public static async Task StopAsync()
{
_client?.Dispose();
if (_app is not null)
{
await _app.StopAsync();
await _app.DisposeAsync();
}
}
[TestMethod]
[DataRow("/health/live", "live")]
[DataRow("/health/ready", "ready")]
public async Task HealthProbes_AnswerOk(string path, string body)
{
using var response = await Client.GetAsync(new Uri(path, UriKind.Relative));
Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
Assert.AreEqual(body, await response.Content.ReadAsStringAsync());
}
[TestMethod]
public async Task Health_ReportsStatusAndVersion()
{
var report = await Client.GetFromJsonAsync<HealthEndpoints.HealthReport>(new Uri("/health", UriKind.Relative));
Assert.IsNotNull(report);
Assert.AreEqual("ok", report.Status);
Assert.IsTrue(report.Live);
Assert.IsTrue(report.Ready);
Assert.IsFalse(string.IsNullOrEmpty(report.Version));
}
[TestMethod]
public async Task HomePage_ShowsTheUnderConstructionPage()
{
var html = await Client.GetStringAsync(new Uri("/", UriKind.Relative));
StringAssert.Contains(html, "Khaemhat");
StringAssert.Contains(html, "in costruzione");
StringAssert.Contains(html, "lang=\"it\"");
}
[TestMethod]
public async Task UnknownPage_AnswersNotFound()
{
using var response = await Client.GetAsync(new Uri("/does-not-exist", UriKind.Relative));
Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
}
private static HttpClient Client => _client ?? throw new InvalidOperationException("Host not started.");
}
@@ -0,0 +1,33 @@
namespace Khaemhat.Web.Tests.Hosting;
/// <summary>
/// The icons served by the app are copies of the official ones in <c>assets/</c> (SPEC §16.6): they must not drift.
/// </summary>
[TestClass]
public sealed class IconTests
{
[TestMethod]
[DataRow("favicon.ico")]
[DataRow("icon.svg")]
[DataRow("icon-256.png")]
[DataRow("icon-512.png")]
public void ServedIcon_MatchesTheOfficialAsset(string file)
{
var root = FindRoot();
var official = File.ReadAllBytes(Path.Combine(root, "assets", file));
var served = File.ReadAllBytes(Path.Combine(root, "src", "Khaemhat.Web", "wwwroot", file));
CollectionAssert.AreEqual(official, served, $"wwwroot/{file} differs from assets/{file}: copy it again.");
}
private static string FindRoot()
{
var dir = new DirectoryInfo(AppContext.BaseDirectory);
while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "Khaemhat.sln")))
{
dir = dir.Parent;
}
return dir?.FullName ?? throw new InvalidOperationException("Repository root (Khaemhat.sln) not found.");
}
}
@@ -0,0 +1,36 @@
using Khaemhat.Web.Hosting;
namespace Khaemhat.Web.Tests.Hosting;
/// <summary>
/// KHAEMHAT_* variables read by the host (SPEC §6). Command-line keys feed the same configuration as environment
/// variables, so the tests pass them as arguments instead of touching the process environment.
/// </summary>
[TestClass]
public sealed class InstanceVariablesTests
{
[TestMethod]
public async Task LogLevel_SetsTheDefaultLevel()
{
await using var app = KhaemhatApp.Build(["--urls", "http://127.0.0.1:0", "--KHAEMHAT_LOG_LEVEL=warning"]);
Assert.AreEqual("Warning", app.Configuration["Logging:LogLevel:Default"]);
}
[TestMethod]
public void LogLevel_RejectsAnUnknownValue()
{
var error = Assert.ThrowsExactly<InvalidOperationException>(
() => KhaemhatApp.Build(["--urls", "http://127.0.0.1:0", "--KHAEMHAT_LOG_LEVEL=loud"]));
StringAssert.Contains(error.Message, "KHAEMHAT_LOG_LEVEL");
}
[TestMethod]
public async Task Urls_AreTakenFromTheVariable()
{
await using var app = KhaemhatApp.Build(["--KHAEMHAT_URLS=http://127.0.0.1:0"]);
Assert.AreEqual("http://127.0.0.1:0", app.Configuration["urls"]);
}
}
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Khaemhat.Web.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../src/Khaemhat.Web/Khaemhat.Web.csproj" />
</ItemGroup>
</Project>