Settings no longer makes a folder an archive on its own: a typed or picked folder without archive.json is made one only after a confirmation naming it, and Settings > Import keeps this PC's archive folder and never creates one. A half-typed path or another PC's drive letter could otherwise get .chronos and sidecars written unasked. The server's structure check creates nothing in a root that lost its archive.json (an unmounted disk's empty mount point) and reports it unavailable; /health re-checks when its last check is over 10 s old, so a fix on the host shows without a dashboard read. The admin board reads the server newest first with Order off, counts Published over the server's total, and a Shift range runs along the lane picked in. Admin sizes keep number and unit together. A sent workspace render whose file left exports/ is no longer listed as missing. Desktop Board cards put their actions under the text while the player is open. Start-up range errors name the CHRONOS_* variable; the deploy guide documents the parallelism clamp and the log rule. Refs #29 #31 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
120 lines
5.7 KiB
C#
120 lines
5.7 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Chronos.Core.Archiving;
|
|
using Chronos.Data;
|
|
using Chronos.Data.Archiving;
|
|
using Chronos.Protocol;
|
|
using Chronos.Server.Storage;
|
|
using Chronos.Testing;
|
|
|
|
namespace Chronos.Server.Tests.Hosting;
|
|
|
|
/// <summary>The server lays out its archive folder whole at start (owner request 2026-11-06) and says when it cannot.</summary>
|
|
[Category("server")]
|
|
public sealed class ArchiveStructureStartupTests(TestContext context)
|
|
{
|
|
[Test]
|
|
public async Task StartingTheServerLaysOutTheArchiveFolder()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
|
|
var paths = new ArchivePaths(server.Options.ArchivePath);
|
|
Assert.FileExists(paths.ManifestPath);
|
|
Assert.Empty(ArchiveStructure.Missing(paths));
|
|
Assert.True(Assert.NotNull(server.Services.GetRequiredService<ServerArchive>().Structure).IsComplete);
|
|
var health = Assert.NotNull(await server.Client.GetFromJsonAsync("/health", ProtocolJson.Default.HealthStatus));
|
|
Assert.Equal("ok", health.Checks["archive"]);
|
|
}
|
|
|
|
[Test]
|
|
public async Task AnArchiveMissingFoldersGetsThemAtStart()
|
|
{
|
|
var root = Path.Combine(context.CreateTempDirectory("existing"), "archive");
|
|
await using (var db = await ChronosDatabase.OpenAsync(DatabaseOptions.Sqlite(Path.Combine(context.CreateTempDirectory("db"), "chronos.db")), context.Cancellation))
|
|
await new ArchiveService(db).CreateAsync(root, "Older", cancellationToken: context.Cancellation);
|
|
var paths = new ArchivePaths(root);
|
|
Directory.Delete(paths.TrashDirectory, recursive: true);
|
|
Directory.Delete(paths.StagingDirectory);
|
|
var notes = Path.Combine(root, "notes.txt");
|
|
File.WriteAllText(notes, "mine");
|
|
|
|
await using var server = await TestServer.StartAsync(context, o => o.ArchivePath = root);
|
|
|
|
Assert.Empty(ArchiveStructure.Missing(paths));
|
|
Assert.Equal("mine", File.ReadAllText(notes));
|
|
}
|
|
|
|
[Test]
|
|
public async Task TheDashboardWarnsWhileAFolderCannotBeCreated()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var admin = await server.AdminAsync();
|
|
var paths = new ArchivePaths(server.Options.ArchivePath);
|
|
Directory.Delete(paths.TrashVideosDirectory);
|
|
File.WriteAllText(paths.TrashVideosDirectory, "in the way");
|
|
|
|
var warned = await DashboardAsync(admin);
|
|
var problem = Assert.NotNull(warned.ArchiveProblem);
|
|
Assert.Equal(("failed", paths.TrashVideosDirectory), (problem.Code, problem.Folder));
|
|
var health = Assert.NotNull(await server.Client.GetFromJsonAsync("/health", ProtocolJson.Default.HealthStatus));
|
|
Assert.Equal(("ok", "incomplete"), (health.Status, health.Checks["archive"]));
|
|
Assert.Equal("in the way", File.ReadAllText(paths.TrashVideosDirectory));
|
|
|
|
// Once the file is out of the way, the next look at the dashboard makes the folder and the warning goes.
|
|
File.Delete(paths.TrashVideosDirectory);
|
|
Assert.Null((await DashboardAsync(admin)).ArchiveProblem);
|
|
Assert.True(Directory.Exists(paths.TrashVideosDirectory));
|
|
health = Assert.NotNull(await server.Client.GetFromJsonAsync("/health", ProtocolJson.Default.HealthStatus));
|
|
Assert.Equal("ok", health.Checks["archive"]);
|
|
}
|
|
|
|
[Test]
|
|
public async Task HealthSeesAFixOnTheHostWithoutTheDashboard()
|
|
{
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var archive = server.Services.GetRequiredService<ServerArchive>();
|
|
var paths = new ArchivePaths(server.Options.ArchivePath);
|
|
Directory.Delete(paths.TrashVideosDirectory);
|
|
File.WriteAllText(paths.TrashVideosDirectory, "in the way");
|
|
archive.HealthRecheck = TimeSpan.Zero;
|
|
|
|
var health = Assert.NotNull(await server.Client.GetFromJsonAsync("/health", ProtocolJson.Default.HealthStatus));
|
|
Assert.Equal("incomplete", health.Checks["archive"]);
|
|
File.Delete(paths.TrashVideosDirectory);
|
|
health = Assert.NotNull(await server.Client.GetFromJsonAsync("/health", ProtocolJson.Default.HealthStatus));
|
|
Assert.Equal("ok", health.Checks["archive"]);
|
|
Assert.True(Directory.Exists(paths.TrashVideosDirectory));
|
|
}
|
|
|
|
[Test]
|
|
public async Task ARootThatLostItsArchiveJsonGetsNoFolders()
|
|
{
|
|
// Rc.14 review: an unmounted disk leaves an empty mount point; nothing is written onto the disk beneath it.
|
|
await using var server = await TestServer.StartAsync(context);
|
|
var admin = await server.AdminAsync();
|
|
var paths = new ArchivePaths(server.Options.ArchivePath);
|
|
var manifest = File.ReadAllBytes(paths.ManifestPath);
|
|
File.Delete(paths.ManifestPath);
|
|
Directory.Delete(paths.TrashDirectory, recursive: true);
|
|
|
|
var problem = Assert.NotNull((await DashboardAsync(admin)).ArchiveProblem);
|
|
Assert.Equal("unavailable", problem.Code);
|
|
Assert.False(Directory.Exists(paths.TrashDirectory), "nothing created");
|
|
var health = Assert.NotNull(await server.Client.GetFromJsonAsync("/health", ProtocolJson.Default.HealthStatus));
|
|
Assert.Equal("missing", health.Checks["archive"]);
|
|
|
|
// The disk is back: the next look completes the layout.
|
|
File.WriteAllBytes(paths.ManifestPath, manifest);
|
|
Assert.Null((await DashboardAsync(admin)).ArchiveProblem);
|
|
Assert.Empty(ArchiveStructure.Missing(paths));
|
|
}
|
|
|
|
private static async Task<DashboardDto> DashboardAsync(HttpClient admin)
|
|
{
|
|
using var response = await admin.GetAsync("/api/v1/server/dashboard");
|
|
await response.ExpectAsync(HttpStatusCode.OK);
|
|
return await response.ReadAsync(ProtocolJson.Default.DashboardDto);
|
|
}
|
|
}
|