feat: Phase 0 shells, design system, server skeleton, Docker and CI
- Titano.Ui: DESIGN.md tokens (dark/light), generated 16-px icon set, styles for all standard controls, custom chrome window with snap layouts, rail, job bar, Auto/manual slider, chips, toasts. - Titano desktop shell with sections, Settings (language, theme), About and a --capture screenshot mode. - Titano Server skeleton: env/server.json configuration, self-signed TLS with fingerprint, /health, /server/info, i18n endpoint and the embedded admin panel; in-process server tests. - Docker image (multi-arch, PUID/PGID, health check), compose file, Unraid template; CI, release and nightly workflows; changelog tool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
122 files changed
+6838
-22
No files matched your search
@@ -0,0 +1,126 @@
|
||||
using System.Net;
|
||||
using System.Net.Http.Json;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using Titano.Protocol;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Server.Tests.Hosting;
|
||||
|
||||
[Category("server")]
|
||||
public sealed class SystemEndpointTests(TestContext context)
|
||||
{
|
||||
[Test]
|
||||
public async Task HealthReportsOk()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var health = await server.Client.GetFromJsonAsync("/health", ProtocolJson.Default.HealthStatus);
|
||||
Assert.Equal("ok", Assert.NotNull(health).Status);
|
||||
Assert.Equal("ok", health.Checks["archive"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ServerInfoCarriesFingerprintAndApiHeader()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
using var response = await server.Client.GetAsync("/api/v1/server/info");
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal("1", response.Headers.GetValues(ApiVersion.Header).Single());
|
||||
var info = await response.Content.ReadFromJsonAsync(ProtocolJson.Default.ServerInfo);
|
||||
Assert.Equal(1, Assert.NotNull(info).ApiVersion);
|
||||
Assert.Equal(95, Assert.NotNull(info.TlsFingerprint).Length); // 32 bytes as XX: pairs
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task HttpsServesTheAdvertisedCertificate()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var info = await server.Client.GetFromJsonAsync("/api/v1/server/info", ProtocolJson.Default.ServerInfo);
|
||||
string? seen = null;
|
||||
using var handler = new HttpClientHandler
|
||||
{
|
||||
ServerCertificateCustomValidationCallback = (_, cert, _, _) =>
|
||||
{
|
||||
seen = cert is null ? null : string.Join(':', cert.GetCertHash(System.Security.Cryptography.HashAlgorithmName.SHA256).Select(b => b.ToString("X2", System.Globalization.CultureInfo.InvariantCulture)));
|
||||
return true;
|
||||
},
|
||||
};
|
||||
using var https = new HttpClient(handler) { BaseAddress = Assert.NotNull(server.HttpsBase) };
|
||||
using var response = await https.GetAsync("/health");
|
||||
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
|
||||
Assert.Equal(Assert.NotNull(info).TlsFingerprint, seen);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task CertificateIsReusedAcrossRestarts()
|
||||
{
|
||||
var root = context.CreateTempDirectory("restart");
|
||||
string? first;
|
||||
await using (var a = await TestServer.StartAsync(context, o => o.DataPath = Path.Combine(root, "data")))
|
||||
first = (await a.Client.GetFromJsonAsync("/api/v1/server/info", ProtocolJson.Default.ServerInfo))!.TlsFingerprint;
|
||||
await using var b = await TestServer.StartAsync(context, o => o.DataPath = Path.Combine(root, "data"));
|
||||
var second = (await b.Client.GetFromJsonAsync("/api/v1/server/info", ProtocolJson.Default.ServerInfo))!.TlsFingerprint;
|
||||
Assert.Equal(first, second);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task UnknownApiRouteReturnsJsonError()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
using var response = await server.Client.GetAsync("/api/v1/does-not-exist");
|
||||
Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
|
||||
var error = await response.Content.ReadFromJsonAsync(ProtocolJson.Default.ApiError);
|
||||
Assert.Equal("not_found", Assert.NotNull(error).Code);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AdminPanelIsServedWithEtags()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
using var redirect = await new HttpClient(new HttpClientHandler { AllowAutoRedirect = false }) { BaseAddress = server.HttpBase }.GetAsync("/admin");
|
||||
Assert.Equal(HttpStatusCode.Redirect, redirect.StatusCode);
|
||||
using var page = await server.Client.GetAsync("/admin/");
|
||||
Assert.Equal(HttpStatusCode.OK, page.StatusCode);
|
||||
Assert.Contains("app.js", await page.Content.ReadAsStringAsync());
|
||||
var etag = page.Headers.ETag;
|
||||
using var request = new HttpRequestMessage(HttpMethod.Get, "/admin/");
|
||||
request.Headers.IfNoneMatch.Add(Assert.NotNull(etag));
|
||||
using var cached = await server.Client.SendAsync(request);
|
||||
Assert.Equal(HttpStatusCode.NotModified, cached.StatusCode);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task I18nEndpointFallsBackToEnglish()
|
||||
{
|
||||
await using var server = await TestServer.StartAsync(context);
|
||||
var it = await server.Client.GetFromJsonAsync("/api/v1/i18n/it-IT", ProtocolJson.Default.DictionaryStringString);
|
||||
Assert.Equal("Accedi", Assert.NotNull(it)["Admin.Login.SignIn"]);
|
||||
var unknown = await server.Client.GetFromJsonAsync("/api/v1/i18n/xx", ProtocolJson.Default.DictionaryStringString);
|
||||
Assert.Equal("Sign in", Assert.NotNull(unknown)["Admin.Login.SignIn"]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void LinuxRefusesSqlite()
|
||||
{
|
||||
if (OperatingSystem.IsWindows()) TestContext.Skip("SQLite is allowed on Windows");
|
||||
var options = new Titano.Server.Configuration.ServerOptions { Database = Titano.Server.Configuration.DatabaseKind.Sqlite };
|
||||
Assert.Throws<InvalidOperationException>(options.Validate);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EnvironmentOverridesDefaults()
|
||||
{
|
||||
var root = context.CreateTempDirectory("env");
|
||||
var env = new Dictionary<string, string?>
|
||||
{
|
||||
["TITANO_DATA_PATH"] = root,
|
||||
["TITANO_HTTP_PORT"] = "9090",
|
||||
["TITANO_TLS_MODE"] = "proxy",
|
||||
["TITANO_DB"] = "postgres",
|
||||
["TITANO_SERVER_NAME"] = "Studio NAS",
|
||||
};
|
||||
var options = Titano.Server.Configuration.ServerOptions.Load(env);
|
||||
Assert.Equal(9090, options.HttpPort);
|
||||
Assert.Equal(Titano.Server.Configuration.TlsMode.Proxy, options.TlsMode);
|
||||
Assert.Equal("Studio NAS", options.ServerName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting.Server;
|
||||
using Microsoft.AspNetCore.Hosting.Server.Features;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Titano.Server.Configuration;
|
||||
using Titano.Server.Hosting;
|
||||
using Titano.Testing;
|
||||
|
||||
namespace Titano.Server.Tests;
|
||||
|
||||
/// <summary>In-process Kestrel on ephemeral ports with temporary archive/data folders (BRIEF §20.1).</summary>
|
||||
public sealed class TestServer : IAsyncDisposable
|
||||
{
|
||||
private readonly WebApplication _app;
|
||||
|
||||
private TestServer(WebApplication app, ServerOptions options, Uri http, Uri? https)
|
||||
{
|
||||
_app = app;
|
||||
Options = options;
|
||||
HttpBase = http;
|
||||
HttpsBase = https;
|
||||
Client = new HttpClient { BaseAddress = http, Timeout = TimeSpan.FromSeconds(30) };
|
||||
}
|
||||
|
||||
public ServerOptions Options { get; }
|
||||
public Uri HttpBase { get; }
|
||||
public Uri? HttpsBase { get; }
|
||||
public HttpClient Client { get; }
|
||||
public IServiceProvider Services => _app.Services;
|
||||
|
||||
public static async Task<TestServer> StartAsync(TestContext context, Action<ServerOptions>? configure = null)
|
||||
{
|
||||
var root = context.CreateTempDirectory("server");
|
||||
var options = new ServerOptions
|
||||
{
|
||||
DataPath = Path.Combine(root, "data"),
|
||||
ArchivePath = Path.Combine(root, "archive"),
|
||||
HttpPort = 0,
|
||||
HttpsPort = 0,
|
||||
TlsMode = TlsMode.Auto,
|
||||
Database = DatabaseKind.Sqlite,
|
||||
};
|
||||
Directory.CreateDirectory(options.ArchivePath);
|
||||
configure?.Invoke(options);
|
||||
var app = ServerHost.Build(options, []);
|
||||
await app.StartAsync(context.Cancellation);
|
||||
var addresses = app.Services.GetRequiredService<IServer>().Features.Get<IServerAddressesFeature>()!.Addresses
|
||||
.Select(a => new Uri(a.Replace("[::]", "127.0.0.1", StringComparison.Ordinal).Replace("0.0.0.0", "127.0.0.1", StringComparison.Ordinal)))
|
||||
.ToList();
|
||||
var http = addresses.First(a => a.Scheme == "http");
|
||||
var https = addresses.FirstOrDefault(a => a.Scheme == "https");
|
||||
return new TestServer(app, options, http, https);
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
Client.Dispose();
|
||||
await _app.StopAsync();
|
||||
await _app.DisposeAsync();
|
||||
}
|
||||
}
|
||||
@@ -7,12 +7,12 @@ namespace Titano.Testing;
|
||||
/// <summary>Assertions with messages that state expected and actual values.</summary>
|
||||
public static class Assert
|
||||
{
|
||||
public static void True(bool condition, string? message = null, [CallerArgumentExpression(nameof(condition))] string? expression = null)
|
||||
public static void True([System.Diagnostics.CodeAnalysis.DoesNotReturnIf(false)] bool condition, string? message = null, [CallerArgumentExpression(nameof(condition))] string? expression = null)
|
||||
{
|
||||
if (!condition) Fail(message ?? $"Expected true: {expression}");
|
||||
}
|
||||
|
||||
public static void False(bool condition, string? message = null, [CallerArgumentExpression(nameof(condition))] string? expression = null)
|
||||
public static void False([System.Diagnostics.CodeAnalysis.DoesNotReturnIf(true)] bool condition, string? message = null, [CallerArgumentExpression(nameof(condition))] string? expression = null)
|
||||
{
|
||||
if (condition) Fail(message ?? $"Expected false: {expression}");
|
||||
}
|
||||
@@ -22,13 +22,13 @@ public static class Assert
|
||||
if (value is not null) Fail($"Expected null: {expression} was {Format(value)}");
|
||||
}
|
||||
|
||||
public static T NotNull<T>(T? value, [CallerArgumentExpression(nameof(value))] string? expression = null) where T : class
|
||||
public static T NotNull<T>([System.Diagnostics.CodeAnalysis.NotNull] T? value, [CallerArgumentExpression(nameof(value))] string? expression = null) where T : class
|
||||
{
|
||||
if (value is null) Fail($"Expected non-null: {expression}");
|
||||
return value!;
|
||||
}
|
||||
|
||||
public static T NotNull<T>(T? value, [CallerArgumentExpression(nameof(value))] string? expression = null) where T : struct
|
||||
public static T NotNull<T>([System.Diagnostics.CodeAnalysis.NotNull] T? value, [CallerArgumentExpression(nameof(value))] string? expression = null) where T : struct
|
||||
{
|
||||
if (value is null) Fail($"Expected non-null: {expression}");
|
||||
return value!.Value;
|
||||
|
||||
@@ -13,6 +13,8 @@ internal sealed class ConsoleReporter(bool verbose) : IDisposable
|
||||
switch (r.Outcome)
|
||||
{
|
||||
case TestOutcome.Failed:
|
||||
if (GitHubActions)
|
||||
Console.WriteLine($"::error title=Test failed::{Escape(r.Test.FullName)}: {Escape(r.Message ?? "failed")}");
|
||||
Write(ConsoleColor.Red, "FAIL ");
|
||||
Console.WriteLine($"{r.Test.FullName} ({Ms(r.Duration)})");
|
||||
Console.WriteLine(" " + r.Message);
|
||||
@@ -50,6 +52,11 @@ internal sealed class ConsoleReporter(bool verbose) : IDisposable
|
||||
|
||||
public void Dispose() => Console.Out.Flush();
|
||||
|
||||
private static bool GitHubActions { get; } = Environment.GetEnvironmentVariable("GITHUB_ACTIONS") == "true";
|
||||
|
||||
/// <summary>Workflow-command escaping (https://docs.github.com/actions/reference/workflow-commands).</summary>
|
||||
private static string Escape(string s) => s.Replace("%", "%25", StringComparison.Ordinal).Replace("\r", "%0D", StringComparison.Ordinal).Replace("\n", "%0A", StringComparison.Ordinal);
|
||||
|
||||
private static string Ms(TimeSpan t) => t.TotalMilliseconds.ToString("F0", CultureInfo.InvariantCulture) + " ms";
|
||||
|
||||
private static string Indent(string s) => string.Join(Environment.NewLine, s.TrimEnd().Split('\n').Select(l => " " + l.TrimEnd('\r')));
|
||||
|
||||
@@ -43,8 +43,10 @@ public static class TestRunner
|
||||
}
|
||||
if (selected.Count == 0)
|
||||
{
|
||||
Console.Error.WriteLine("No tests matched.");
|
||||
return 2;
|
||||
// An empty project is not a failure; a filter that matches nothing is a usage error.
|
||||
var filtered = options.HasFilters;
|
||||
Console.Error.WriteLine(filtered ? "No tests matched." : "No tests discovered.");
|
||||
return filtered ? 2 : 0;
|
||||
}
|
||||
|
||||
var stopwatch = Stopwatch.StartNew();
|
||||
@@ -284,6 +286,7 @@ public static class TestRunner
|
||||
public int Parallelism { get; private set; } = Math.Max(1, Environment.ProcessorCount);
|
||||
public bool List { get; private set; }
|
||||
public bool Verbose { get; private set; }
|
||||
public bool HasFilters => Filters.Count > 0 || Excludes.Count > 0;
|
||||
|
||||
public static Options Parse(string[] args)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user