feat: phase 5 groundwork (playback format 3, videos contracts, migration 0010, strings)
Lays down every contract the later parcels of owner review 1 phase 5 build on, so they compile against shared types without touching each other's files. - Settings format 3: export.playback (direction, loops, fades, hold), omitted at its default and member by member; RequiredFormat is 3 only while used. - OutputProgram public API with a forward-only body; still-frame job parameters (StillFrame, StillPhoto) routed to format-3 nodes only. - Render.Sha256/Kind, RenderCopy, RenderKind; JobKind.VideoCopy = 24. - Migration 0010 (sqlite, postgres): renders.sha256/kind, ix_renders_created, render_copies without a foreign key. - Videos protocol DTOs, client calls, ServerCapabilities.Videos (declared, not announced yet), ServerSettingsDto.VideosPath. - IVideoLibrary with a NotImplemented stub registered on the server; TrashKind.Videos, VideoTrashNames, VideoErrors. - en and it strings for the whole phase, five icons, decisions 1-22 and the open-question defaults; tests that used format 3 as "newer" now use 4. Refs #21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
86aa07c1d7
commit
d472dfdec1
67 files changed
+2233
-244
No files matched your search
@@ -508,7 +508,7 @@ public sealed class ProjectTests(TestContext context)
|
||||
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
|
||||
using (var anonymous = new ChronosClient(server.HttpBase, new CertificatePinning([]), "tests"))
|
||||
Assert.Equal(ProjectSettings.CurrentVersion, (await anonymous.GetInfoAsync(context.Cancellation)).SettingsFormat);
|
||||
Assert.Equal(2, ProjectSettings.CurrentVersion);
|
||||
Assert.Equal(3, ProjectSettings.CurrentVersion);
|
||||
|
||||
var (http, _, token) = await server.UserAsync("alberto", "editor");
|
||||
using var alberto = Client(server, token);
|
||||
@@ -527,8 +527,8 @@ public sealed class ProjectTests(TestContext context)
|
||||
var mirrored = ProjectSettings.FromJson(Assert.NotNull((await server.Database.Sequences.GetAsync(sid))!.SettingsJson));
|
||||
Assert.Equal((90, true, "sepia"), (mirrored.Camera.Rotate, mirrored.Camera.Mirror, mirrored.Look?.Filter), "Main's head is the sequence's settings");
|
||||
|
||||
const string future = """{"version":3,"camera":{"rotate":90}}""";
|
||||
var newer = Version(v3, new ProjectSettings(), home) with { SettingsJson = future, ContentHash = ProjectContent.Hash(future), SettingsFormat = 3 };
|
||||
const string future = """{"version":4,"camera":{"rotate":90}}""";
|
||||
var newer = Version(v3, new ProjectSettings(), home) with { SettingsJson = future, ContentHash = ProjectContent.Hash(future), SettingsFormat = 4 };
|
||||
using (var raw = await http.PostAsJsonAsync($"/api/v1/sequences/{sid}/projects/{main.Id}/versions", newer, ProtocolJson.Default.ProjectVersionDto))
|
||||
await raw.ExpectErrorAsync(HttpStatusCode.UnprocessableEntity, ProjectErrors.NewerFormat);
|
||||
Assert.Equal(3, (await alberto.GetProjectAsync(sid, main.Id)).HeadNumber);
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Nodes;
|
||||
using Chronos.Core.Model;
|
||||
using Chronos.Data.Archiving;
|
||||
using Chronos.Data.Videos;
|
||||
using Chronos.Protocol;
|
||||
using Chronos.Testing;
|
||||
|
||||
namespace Chronos.Server.Tests.Api;
|
||||
|
||||
/// <summary>
|
||||
/// The wire shapes of the videos library (owner review 1, phase 5): camelCase members, nulls left out, and the members
|
||||
/// added to existing DTOs trailing and optional, so a client or server of before reads and writes them as it did.
|
||||
/// </summary>
|
||||
public sealed class VideoContractTests
|
||||
{
|
||||
private static readonly Guid RenderId = Guid.Parse("01890000-0000-7000-8000-000000000001");
|
||||
private static readonly Guid SequenceId = Guid.Parse("01890000-0000-7000-8000-000000000002");
|
||||
private static readonly DateTimeOffset Created = new(2026, 11, 5, 18, 30, 0, TimeSpan.Zero);
|
||||
|
||||
[Test]
|
||||
public void AVideoTravelsWithItsSequenceStateAndCopies()
|
||||
{
|
||||
var video = new VideoDto(RenderId, SequenceId, "Web 1080p", "h264", 1920, 1080, 25, 12.5, 4_000_000, Created, "PC-A", null, null,
|
||||
new string('a', 64), RenderKind.Video, "Harbour sunset", new DateTime(2026, 10, 1, 18, 0, 0), "Main", 3, VideoStates.Ok,
|
||||
[new VideoCopyDto("/videos/Harbour sunset.mp4", Created)], "Harbour sunset.mp4");
|
||||
var json = JsonNode.Parse(JsonSerializer.Serialize(video, ProtocolJson.Default.VideoDto))!.AsObject();
|
||||
Assert.SequenceEqual(
|
||||
["id", "sequenceId", "presetName", "codec", "width", "height", "fps", "durationSeconds", "bytes", "created", "producedBy", "sha256",
|
||||
"kind", "sequenceTitle", "sequenceFirstCapture", "projectName", "projectVersionNumber", "state", "copies", "fileName"],
|
||||
json.Select(p => p.Key));
|
||||
Assert.Equal("video", json["kind"]!.GetValue<string>());
|
||||
Assert.Equal("/videos/Harbour sunset.mp4", json["copies"]![0]!["path"]!.GetValue<string>());
|
||||
var back = JsonSerializer.Deserialize(json.ToJsonString(), ProtocolJson.Default.VideoDto)!;
|
||||
Assert.Equal(video with { Copies = back.Copies }, back);
|
||||
Assert.Equal(video.Copies[0], back.Copies[0]);
|
||||
|
||||
var page = new VideoPageDto([video], "cursor-2");
|
||||
var pageJson = JsonNode.Parse(JsonSerializer.Serialize(page, ProtocolJson.Default.VideoPageDto))!.AsObject();
|
||||
Assert.SequenceEqual(["items", "next"], pageJson.Select(p => p.Key));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeletingIsADryRunThenTheSameFingerprint()
|
||||
{
|
||||
var request = JsonSerializer.Serialize(new VideoDeleteRequest([RenderId], DryRun: true), ProtocolJson.Default.VideoDeleteRequest);
|
||||
Assert.Equal($$"""{"ids":["{{RenderId}}"],"dryRun":true}""", request);
|
||||
var real = JsonSerializer.Deserialize("""{ "ids": [], "dryRun": false, "fingerprint": "abc" }""", ProtocolJson.Default.VideoDeleteRequest)!;
|
||||
Assert.Equal((false, "abc"), (real.DryRun, real.Fingerprint));
|
||||
|
||||
var plan = new VideoDeletePlanDto([new VideoDeleteItemDto(RenderId, SequenceId, "Harbour sunset", "a.mp4", 10, Missing: false)], 10,
|
||||
[new VideoBlockedDto(Guid.Empty, VideoBlockReasons.Busy)], "f1", DryRun: true);
|
||||
var json = JsonNode.Parse(JsonSerializer.Serialize(plan, ProtocolJson.Default.VideoDeletePlanDto))!.AsObject();
|
||||
Assert.SequenceEqual(["items", "bytes", "blocked", "fingerprint", "dryRun"], json.Select(p => p.Key));
|
||||
Assert.Equal("busy", json["blocked"]![0]!["reason"]!.GetValue<string>());
|
||||
|
||||
var copy = JsonSerializer.Serialize(new VideoCopyRequest([RenderId]), ProtocolJson.Default.VideoCopyRequest);
|
||||
Assert.Equal($$"""{"ids":["{{RenderId}}"]}""", copy);
|
||||
Assert.Equal(RenderId, JsonSerializer.Deserialize($$"""{"jobId":"{{RenderId}}"}""", ProtocolJson.Default.VideoCopyResultDto)!.JobId);
|
||||
Assert.Equal("videos", ServerCapabilities.Videos);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheMembersAddedToOlderDtosAreLeftOutUntilSet()
|
||||
{
|
||||
var render = new RenderDto(RenderId, "MJPEG", "mjpeg", 96, 64, 25, 1, 10, Created, null);
|
||||
var renderJson = JsonSerializer.Serialize(render, ProtocolJson.Default.RenderDto);
|
||||
Assert.False(renderJson.Contains("sha256", StringComparison.Ordinal) || renderJson.Contains("kind", StringComparison.Ordinal), renderJson);
|
||||
var hashed = JsonNode.Parse(JsonSerializer.Serialize(render with { Sha256 = "ab", Kind = RenderKind.Still }, ProtocolJson.Default.RenderDto))!;
|
||||
Assert.Equal(("ab", "still"), (hashed["sha256"]!.GetValue<string>(), hashed["kind"]!.GetValue<string>()));
|
||||
|
||||
var parameters = new RenderJobParameters("MJPEG", "{}", "mjpeg", 96, 64, false, null);
|
||||
var parametersJson = JsonSerializer.Serialize(parameters, ProtocolJson.Default.RenderJobParameters);
|
||||
Assert.False(parametersJson.Contains("still", StringComparison.OrdinalIgnoreCase), parametersJson);
|
||||
Assert.False(parameters.IsStill);
|
||||
var still = JsonSerializer.Deserialize(
|
||||
JsonSerializer.Serialize(parameters with { StillFrame = 41, StillPhoto = "cd", RequiredSettingsFormat = 3 }, ProtocolJson.Default.RenderJobParameters),
|
||||
ProtocolJson.Default.RenderJobParameters)!;
|
||||
Assert.Equal(((int?)41, "cd", 3, true), (still.StillFrame, still.StillPhoto, still.RequiredSettingsFormat, still.IsStill));
|
||||
|
||||
var result = JsonSerializer.Deserialize("""{ "fileName": "a.png", "size": 1, "sha256": "ab", "presetName": "PNG", "width": 1, "height": 1, "fps": 0, "durationSeconds": 0 }""",
|
||||
ProtocolJson.Default.RenderResultRequest)!;
|
||||
Assert.Null(result.Kind);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheLibraryStubAnswersEmptyUntilTheLibraryLands()
|
||||
{
|
||||
var stub = NotImplementedVideoLibrary.Instance;
|
||||
Assert.False(stub.IsAvailable);
|
||||
Assert.Equal(VideoErrors.FolderUnset, stub.FolderProblem(" "));
|
||||
Assert.Null(stub.FolderProblem("/videos"));
|
||||
Assert.Empty(stub.ListAsync(new VideoQuery()).GetAwaiter().GetResult().Items);
|
||||
Assert.Null(stub.GetAsync(RenderId).GetAwaiter().GetResult());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TrashEntriesAndCopyParametersReadBack()
|
||||
{
|
||||
var name = VideoTrashNames.EntryName(RenderId, Created);
|
||||
Assert.True(name.StartsWith(VideoTrashNames.Prefix, StringComparison.Ordinal));
|
||||
Assert.True(VideoTrashNames.TryParse(name, out var id, out var ticks));
|
||||
Assert.Equal((RenderId, Created.UtcTicks), (id, ticks));
|
||||
Assert.False(VideoTrashNames.IsEntryName($"sequence-{RenderId}"));
|
||||
Assert.False(VideoTrashNames.IsEntryName(null));
|
||||
Assert.Equal("videos", TrashKind.Videos.ToString().ToLowerInvariant());
|
||||
|
||||
var parameters = new VideoCopyParameters([RenderId], "/videos", FromServer: true, RequestedBy: "alberto");
|
||||
var back = Assert.NotNull(VideoCopyParameters.Read(parameters.ToJson()));
|
||||
Assert.Equal((parameters.Folder, parameters.FromServer, parameters.RequestedBy), (back.Folder, back.FromServer, back.RequestedBy));
|
||||
Assert.SequenceEqual(parameters.RenderIds, back.RenderIds);
|
||||
Assert.Null(VideoCopyParameters.Read("not json"));
|
||||
Assert.Equal(24, (int)JobKind.VideoCopy);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user