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();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user