fix: address the phase 5 review
Video trash moves across volumes commit once the verified copy has its name and leave an undeletable source whole behind a .leftover marker that the next start settles; deletes rehash under the lease. Restores honour the names renders are writing, and encoders never overwrite an output. Routing floors at the stored settings' format, kindless stills read as stills, star trails restart per loop, and settings the encoder ignored become render warnings. The Videos section fits beside the player, plays downloaded server copies, names blocked videos and says why actions are off; the admin panel offers no download for sequences or missing files and names a filtered sequence from its record. Refs #21 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6d87a1bc6d
commit
1be273d0e4
38 files changed
+958
-160
No files matched your search
@@ -57,6 +57,54 @@ public sealed class VideoSourcesTests
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.Missing"), VideoText.PlayToolTip(local[1] with { Missing = true }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AServersVideoDownloadedHerePlaysFromItsCopy()
|
||||
{
|
||||
var remote = Server(Guid.CreateVersion7(), Comet, "Comet", 300, copies: ["/videos/comet.mp4"]);
|
||||
var gone = Server(Guid.CreateVersion7(), Comet, "Comet", 300);
|
||||
var local = Local(Guid.CreateVersion7(), Harbour, "Harbour sunset", 100);
|
||||
var copy = @"C:\Users\me\Videos\Chronos\comet.mp4";
|
||||
var copies = new Dictionary<Guid, IReadOnlyList<string>>
|
||||
{
|
||||
[remote.Id] = [copy],
|
||||
[gone.Id] = [@"C:\Users\me\Videos\Chronos\deleted.mp4"],
|
||||
[local.Id] = [@"C:\elsewhere\harbour.mp4"],
|
||||
};
|
||||
|
||||
var entries = VideoSources.WithLocalCopies([remote, gone, local], copies, path => path == copy);
|
||||
|
||||
var downloaded = entries[0];
|
||||
Assert.Equal(copy, downloaded.LocalPath);
|
||||
Assert.True(downloaded.HasLocalFile, "Play and Show in folder use the copy");
|
||||
Assert.SequenceEqual(["/videos/comet.mp4", copy], downloaded.Copies);
|
||||
Assert.Contains(VideoText.States(downloaded), s => s.Text == Loc.L("Videos.State.Copied"));
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.Play"), VideoText.PlayToolTip(downloaded));
|
||||
// A copy deleted since names no file to play, but is still listed; this PC's own render keeps its file.
|
||||
Assert.True(entries[1] is { LocalPath: null, HasLocalFile: false });
|
||||
Assert.Same(local, entries[2]);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void AServersVideoThatStaysIsNamedNotNumbered()
|
||||
{
|
||||
var known = Server(Guid.CreateVersion7(), Comet, "Comet", 300);
|
||||
var unknown = Guid.CreateVersion7();
|
||||
var server = new VideoDeletePlanDto([], 0, [new VideoBlockedDto(known.Id, VideoBlockReasons.Busy), new VideoBlockedDto(unknown, VideoBlockReasons.NotFound)], "f", DryRun: true);
|
||||
var lines = new VideoDeletePlans(null, server, new Dictionary<Guid, string> { [known.Id] = VideoDeletePlans.NameOf(known) }).Lines();
|
||||
Assert.Contains("Comet" + Loc.Separator + Formatting.LeftToRight("comet.mp4") + Loc.Separator + VideoText.BlockReason(VideoBlockReasons.Busy), lines);
|
||||
Assert.Contains(unknown.ToString("D") + Loc.Separator + VideoText.BlockReason(VideoBlockReasons.NotFound), lines, "an id the section does not show");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheDetailsLeaveOutWhatARenderDoesNotHave()
|
||||
{
|
||||
var video = Local(Guid.CreateVersion7(), Harbour, "Harbour sunset", 1_000_000);
|
||||
var still = video with { Kind = RenderKind.Still, Codec = "PngSequence", DurationSeconds = 0, Width = 6000, Height = 4000 };
|
||||
Assert.Equal(string.Join(Loc.Separator, "3840×2160", "H.264", VideoText.Duration(video), Formatting.Bytes(video.Bytes)), VideoText.Details(video));
|
||||
Assert.Equal(string.Join(Loc.Separator, "6000×4000", "PNG", Formatting.Bytes(still.Bytes)), VideoText.Details(still), "no empty duration");
|
||||
Assert.Equal(string.Join(Loc.Separator, "6000×4000", Formatting.Bytes(still.Bytes)), VideoText.Details(still with { Codec = null }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TheFiltersNarrowAndTheOrdersSort()
|
||||
{
|
||||
@@ -281,9 +329,9 @@ public sealed class VideosSectionTests(TestContext context)
|
||||
public Task DeleteRunsTheDryRunFirstAndShowsItsBytesAndWhatStays() => WithSectionAsync(async (shell, section, library, dialogs) =>
|
||||
{
|
||||
await section.RefreshAsync();
|
||||
foreach (var row in section.Rows.Where(r => r.Entry.Id != library.Items[2].Render.Id)) row.IsSelected = true;
|
||||
foreach (var row in section.Rows) row.IsSelected = true;
|
||||
var selected = section.SelectedRows;
|
||||
Assert.Equal(2, selected.Count);
|
||||
Assert.Equal(3, selected.Count);
|
||||
Assert.Null(section.DeleteBlocker(selected));
|
||||
|
||||
// Kept: the plan was made, nothing was deleted.
|
||||
@@ -299,14 +347,45 @@ public sealed class VideosSectionTests(TestContext context)
|
||||
Assert.Contains(Loc.L("Videos.Delete.Blocked", Formatting.Count(1)), request.Detail!);
|
||||
Assert.Contains(VideoText.BlockReason(VideoBlockReasons.Busy), request.Detail!);
|
||||
|
||||
// Confirmed: the delete gives back the plan's fingerprint.
|
||||
// Confirmed: the delete gives back the plan's fingerprint with exactly the ids planned, the one that stays included
|
||||
// (a fingerprint of fewer ids would never match).
|
||||
dialogs.Answer = true;
|
||||
var asked = selected.Select(r => r.Entry.Id).ToList();
|
||||
await section.DeleteAsync(selected);
|
||||
Assert.SequenceEqual(["plan", "plan", "delete:fingerprint-2"], library.Calls);
|
||||
Assert.SequenceEqual(asked.Order(), library.DeletedIds.Order());
|
||||
Assert.Contains(shell.PendingToasts, t => t.Title == Loc.L("Videos.Delete.Done", Formatting.Count(2)) && !t.IsError);
|
||||
Assert.Equal(1, section.Rows.Count);
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task ADisabledActionSaysWhyInTheBarAndInTheMenu() => WithSectionAsync(async (shell, section, library, _) =>
|
||||
{
|
||||
await section.RefreshAsync();
|
||||
var video = section.Rows.Single(r => r.Entry.Id == library.Items[0].Render.Id);
|
||||
var missing = section.Rows.Single(r => r.Entry.Id == library.Items[1].Render.Id);
|
||||
// Signed out: Copy on server gives the server's reason, in the row's menu too.
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.ServerOffline"), video.MenuCopyOnServerToolTip);
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.Missing"), missing.MenuShowInFolderToolTip);
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.ShowInFolder"), video.MenuShowInFolderToolTip);
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.Missing"), missing.MenuCopyToolTip, "the menu's Copy gives the row's reason");
|
||||
|
||||
// Two selected: Play, Show in folder and Open in Edit act on one video, and say so.
|
||||
video.IsSelected = true;
|
||||
missing.IsSelected = true;
|
||||
Assert.False(section.PlayCommand.CanExecute(null));
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.SelectOne"), section.PlayToolTip);
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.SelectOne"), section.ShowInFolderToolTip);
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.SelectOne"), section.OpenInEditToolTip);
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.SelectOne"), video.MenuPlayToolTip, "a selected row's menu acts on the selection");
|
||||
|
||||
// A server's video alone: not on this PC.
|
||||
var remote = new VideoRowViewModel(VideoSources.FromServer(Dto(library.Items[0]) with { Id = Guid.CreateVersion7() }));
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.ServerOnly"), VideosViewModel.OpenInEditToolTipOf([remote]));
|
||||
Assert.Equal(Loc.L("Tooltips.Videos.ServerOnly"), VideosViewModel.ShowInFolderToolTipOf([remote]));
|
||||
Assert.Equal(Loc.L("Videos.Download"), VideosViewModel.CopyTextOf([remote]));
|
||||
});
|
||||
|
||||
[Test]
|
||||
public Task ACopyWithoutAVideosFolderSaysWhy() => WithSectionAsync(async (shell, section, library, _) =>
|
||||
{
|
||||
@@ -393,6 +472,19 @@ public sealed class VideosSectionTests(TestContext context)
|
||||
var player = Assert.NotNull(section.Player);
|
||||
Assert.Equal(library.Items[0].Render.Id, player.Entry.Id);
|
||||
Layout(view);
|
||||
// Beside the player, at 1000 px too (a 1200 px window with the rail open), the list keeps its state column in view:
|
||||
// the preset, format and date columns give way.
|
||||
Layout(view, 1000);
|
||||
var pane = Descendants(view).OfType<VideoPlayerPane>().Single();
|
||||
var paneLeft = pane.TranslatePoint(new System.Windows.Point(0, 0), view).X;
|
||||
foreach (var header in new[] { "Videos.Column.State", "Videos.Column.Size" })
|
||||
{
|
||||
var cell = Descendants(view).OfType<System.Windows.Controls.TextBlock>().First(t => t.Text == Loc.L(header));
|
||||
Assert.True(cell.ActualWidth > 0, header);
|
||||
Assert.True(cell.TranslatePoint(new System.Windows.Point(cell.ActualWidth, 0), view).X <= paneLeft, $"{header} runs under the player");
|
||||
}
|
||||
Assert.Equal(System.Windows.Visibility.Collapsed,
|
||||
Descendants(view).OfType<System.Windows.Controls.TextBlock>().First(t => t.Text == Loc.L("Videos.Column.Date")).Visibility);
|
||||
section.ClosePlayerCommand.Execute(null);
|
||||
Assert.False(section.IsPlayerOpen);
|
||||
// Settings › Archive shows the videos folder row.
|
||||
@@ -413,13 +505,23 @@ public sealed class VideosSectionTests(TestContext context)
|
||||
Assert.True(shell.Settings.OpenVideosFolderCommand.CanExecute(null));
|
||||
});
|
||||
|
||||
private static void Layout(System.Windows.FrameworkElement view)
|
||||
private static void Layout(System.Windows.FrameworkElement view, double width = 1200)
|
||||
{
|
||||
view.Measure(new System.Windows.Size(1200, 800));
|
||||
view.Arrange(new System.Windows.Rect(0, 0, 1200, 800));
|
||||
view.Measure(new System.Windows.Size(width, 800));
|
||||
view.Arrange(new System.Windows.Rect(0, 0, width, 800));
|
||||
view.UpdateLayout();
|
||||
}
|
||||
|
||||
private static IEnumerable<System.Windows.DependencyObject> Descendants(System.Windows.DependencyObject root)
|
||||
{
|
||||
for (var i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(root); i++)
|
||||
{
|
||||
var child = System.Windows.Media.VisualTreeHelper.GetChild(root, i);
|
||||
yield return child;
|
||||
foreach (var below in Descendants(child)) yield return below;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The section of a shell on a fresh data folder, reading <see cref="FakeLibrary"/>, signed out, no workspace renders.</summary>
|
||||
private Task WithSectionAsync(Func<ShellViewModel, VideosViewModel, FakeLibrary, ScriptedDialogs, Task> body) => ScreenHost.RunAsync(async () =>
|
||||
{
|
||||
@@ -475,6 +577,9 @@ public sealed class VideosSectionTests(TestContext context)
|
||||
|
||||
public List<string> Calls { get; } = [];
|
||||
|
||||
/// <summary>The ids the last delete was asked for.</summary>
|
||||
public List<Guid> DeletedIds { get; private set; } = [];
|
||||
|
||||
public bool IsAvailable => true;
|
||||
|
||||
public Task<VideoPage> ListAsync(VideoQuery query, CancellationToken cancellationToken = default) => Task.FromResult(new VideoPage([.. Items], null, Items.Count));
|
||||
@@ -484,16 +589,17 @@ public sealed class VideosSectionTests(TestContext context)
|
||||
public Task<VideoDeletePlan> PlanDeleteAsync(IReadOnlyList<Guid> renderIds, CancellationToken cancellationToken = default)
|
||||
{
|
||||
lock (Calls) Calls.Add("plan");
|
||||
// Both go (the missing one only loses its row); another render, being sent, is named as staying.
|
||||
var wanted = Items.Where(i => renderIds.Contains(i.Render.Id)).ToList();
|
||||
// Both go (the missing one only loses its row); the still, being sent, is named as staying.
|
||||
var stays = new VideoBlocked(Items[2].Render.Id, VideoBlockReasons.Busy, Items[2]);
|
||||
var wanted = Items.Where(i => renderIds.Contains(i.Render.Id) && i.Render.Id != stays.RenderId).ToList();
|
||||
return Task.FromResult(new VideoDeletePlan(wanted, [stays], "fingerprint-" + Interlocked.Increment(ref _plans)));
|
||||
}
|
||||
|
||||
public Task<VideoDeleteResult> DeleteAsync(IReadOnlyList<Guid> renderIds, string fingerprint, string? deletedBy, CancellationToken cancellationToken = default)
|
||||
{
|
||||
lock (Calls) Calls.Add("delete:" + fingerprint);
|
||||
var gone = Items.Where(i => renderIds.Contains(i.Render.Id)).ToList();
|
||||
DeletedIds = [.. renderIds];
|
||||
var gone = Items.Where(i => renderIds.Contains(i.Render.Id) && i != Items[2]).ToList();
|
||||
Items.RemoveAll(gone.Contains);
|
||||
return Task.FromResult(new VideoDeleteResult(gone, [], []));
|
||||
}
|
||||
|
||||
@@ -26,6 +26,9 @@ internal sealed class CapturingEncoderProvider(string name, params EncoderCapabi
|
||||
/// <summary>When set, WriteFrame throws this for the frame with that zero-based index.</summary>
|
||||
public (int Frame, Exception Error)? FailAt { get; set; }
|
||||
|
||||
/// <summary>The settings each session says it did not take (<see cref="IVideoEncoderSession.Ignored"/>).</summary>
|
||||
public IReadOnlyList<EncoderSetting> Ignores { get; set; } = [];
|
||||
|
||||
public bool CanEncode(EncodeSettings settings) => capabilities.Any(c =>
|
||||
c.Codec == settings.Codec && EncoderSelector.Takes(c, settings.Width, settings.Height) && (settings.BitDepth == 8 || c.SupportsTenBit));
|
||||
|
||||
@@ -54,5 +57,7 @@ internal sealed class CapturingEncoderProvider(string name, params EncoderCapabi
|
||||
public void Complete() => encode.Completed = true;
|
||||
|
||||
public void Dispose() => encode.Disposed = true;
|
||||
|
||||
public IReadOnlyList<EncoderSetting> Ignored => owner.Ignores;
|
||||
}
|
||||
}
|
||||
@@ -82,6 +82,20 @@ public sealed class PlaybackRenderTests
|
||||
Assert.Contains(result.Warnings, w => w.Key == OutputProgram.BoomerangStackWarning);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task EachLoopOfStarTrailsGrowsItsTrailsAgain()
|
||||
{
|
||||
var stars = Source(6, motion: i => (1.0 * i, 0), configure: o => o with { StarField = true, StartEv = 0, EndEv = 0, StarCount = 60 });
|
||||
var trails = new StackSettings { Mode = StackSetting.StarTrails, Length = 0 };
|
||||
var (looped, _) = await CaptureAsync(Input(stars, Playing(new PlaybackSettings { Loops = 2 }) with { Stack = trails }),
|
||||
cancellationToken: _context.Cancellation);
|
||||
Assert.Equal(12, looped.Frames.Count);
|
||||
// The second pass starts from nothing again: frame 6 + k is frame k, never the finished trails of the first pass.
|
||||
for (var k = 0; k < 6; k++)
|
||||
Assert.True(double.IsPositiveInfinity(Psnr(looped.Frames[k], looped.Frames[6 + k])), $"frame {6 + k} differs from frame {k}");
|
||||
Assert.False(double.IsPositiveInfinity(Psnr(looped.Frames[5], looped.Frames[6])), "the loop seam shows the trails start again");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AMedianWindowIsTheSameFrameInEitherDirection()
|
||||
{
|
||||
|
||||
@@ -142,6 +142,21 @@ public sealed class RenderPipelineTests
|
||||
Assert.Equal(4, encode.Frames.Count);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task SettingsTheEncoderIgnoredAreRenderWarnings()
|
||||
{
|
||||
var capture = new CapturingEncoderProvider("capture", new EncoderCapability(VideoCodec.PngSequence, "Capture", false, 4096, 4096, true))
|
||||
{
|
||||
Ignores = [EncoderSetting.RateControl, EncoderSetting.BFrames],
|
||||
};
|
||||
var result = await Pipeline(capture).RenderAsync(Input(Source()), Target(_context.CreateTempDirectory(), Preset("png-sequence")));
|
||||
Assert.Contains(result.Warnings, w => w.Key == "Export.Encoder.Ignored.RateControl");
|
||||
Assert.Contains(result.Warnings, w => w.Key == "Export.Encoder.Ignored.BFrames");
|
||||
// Each key is a message of the catalogue.
|
||||
foreach (var setting in Enum.GetValues<EncoderSetting>())
|
||||
Assert.NotEqual("Export.Encoder.Ignored." + setting, Chronos.Core.Localization.Loc.L("Export.Encoder.Ignored." + setting));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ProgressReportsEveryFrameAndPreviews()
|
||||
{
|
||||
|
||||
@@ -67,6 +67,35 @@ public sealed class VideoLibraryTests(TestContext context)
|
||||
Assert.True((await fx.Library.GetAsync(gif.Id, fx.Ct))!.Missing);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task AStillWhoseKindWasLostIsStillAStill()
|
||||
{
|
||||
// A still a server of before phase 5 stored (and a PC then synced) has no kind: its image codec, fps 0 and duration 0 tell it.
|
||||
await using var fx = await VideoFixture.CreateAsync(context);
|
||||
var roof = await fx.SequenceAsync("Roof", 2);
|
||||
var kindless = new Render
|
||||
{
|
||||
Id = Guid.CreateVersion7(),
|
||||
SequenceId = roof.Id,
|
||||
PresetName = "PNG",
|
||||
OutputPath = "Roof/exports/roof - 0007.png",
|
||||
Codec = "PngSequence",
|
||||
Width = 96,
|
||||
Height = 64,
|
||||
Created = Day,
|
||||
};
|
||||
await fx.Db.Renders.InsertAsync(kindless, fx.Ct);
|
||||
var pngs = await fx.SequenceRenderAsync(roof, "roof-PNG", 2);
|
||||
|
||||
Assert.Equal(RenderKind.Still, RenderKind.Of(kindless));
|
||||
Assert.Equal(RenderKind.Sequence, RenderKind.Of(pngs), "an image sequence has a frame rate");
|
||||
async Task<List<Guid>> Ids(string kind) => [.. (await fx.Library.ListAsync(new VideoQuery { Kind = kind }, fx.Ct)).Items.Select(i => i.Render.Id)];
|
||||
Assert.SequenceEqual([kindless.Id], await Ids(RenderKind.Still));
|
||||
Assert.SequenceEqual([pngs.Id], await Ids(RenderKind.Sequence));
|
||||
Assert.Empty(await Ids(RenderKind.Video));
|
||||
Assert.Equal(RenderKind.Still, (await fx.Library.GetAsync(kindless.Id, fx.Ct))!.Kind);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task TheDryRunFingerprintChangesWhenTheVideosDo()
|
||||
{
|
||||
@@ -208,4 +237,80 @@ public sealed class VideoLibraryTests(TestContext context)
|
||||
Assert.Equal((pngs.Id, (string?)null), (restored.Id, restored.Sha256));
|
||||
Assert.Equal(4, Directory.GetFiles(fx.FileOf(pngs)).Length);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public async Task AFileHeldOpenWhileItIsCopiedToTheTrashStaysWholeUntilTheNextStart()
|
||||
{
|
||||
await using var fx = await VideoFixture.CreateAsync(context);
|
||||
var sequence = await fx.SequenceAsync();
|
||||
var render = await fx.RenderAsync(sequence, "sunset.mp4", 3000);
|
||||
var source = fx.FileOf(render);
|
||||
fx.Library.Trash.ForceCopy = true;
|
||||
var plan = await fx.Library.PlanDeleteAsync([render.Id], fx.Ct);
|
||||
|
||||
// A player holds the file open: it copies and verifies, but the original cannot be deleted.
|
||||
string name;
|
||||
using (new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
name = (await fx.Library.DeleteAsync([render.Id], plan.Fingerprint, null, fx.Ct)).TrashEntries.Single();
|
||||
|
||||
// The delete is done (row gone, verified copy listed); the original stays whole and is marked as left over.
|
||||
var (folder, _) = VideoTrash.Location(fx.Archive.Paths, name);
|
||||
Assert.Null(await fx.Db.Renders.GetAsync(render.Id, fx.Ct));
|
||||
Assert.Equal(3000L, new FileInfo(Path.Combine(folder, "sunset.mp4")).Length);
|
||||
Assert.Equal(3000L, new FileInfo(source).Length);
|
||||
Assert.True(File.Exists(folder + VideoTrash.LeftoverSuffix));
|
||||
Assert.Equal(name, (await fx.Archive.Service.Trash.ListAsync(fx.Archive.Archive, fx.Ct)).Single(e => e.Kind == Chronos.Data.Archiving.TrashKind.Videos).Name);
|
||||
|
||||
// The next start removes it, and the render comes back under its own name.
|
||||
Assert.Equal(1, await fx.Library.RecoverAsync(fx.Archive.Archive, fx.Ct));
|
||||
Assert.False(File.Exists(source));
|
||||
Assert.False(File.Exists(folder + VideoTrash.LeftoverSuffix));
|
||||
Assert.Equal(render.OutputPath, (await fx.Library.RestoreAsync(fx.Archive.Archive.Id, name, fx.Ct)).OutputPath);
|
||||
}
|
||||
|
||||
[Test]
|
||||
[WindowsOnly]
|
||||
public async Task AnImageSequenceWithAFileHeldOpenKeepsEveryFileUntilTheNextStart()
|
||||
{
|
||||
await using var fx = await VideoFixture.CreateAsync(context);
|
||||
var sequence = await fx.SequenceAsync();
|
||||
var pngs = await fx.SequenceRenderAsync(sequence, "clip-PNG", 4);
|
||||
var source = fx.FileOf(pngs);
|
||||
var files = Directory.GetFiles(source).Order(StringComparer.Ordinal).ToList();
|
||||
fx.Library.Trash.ForceCopy = true;
|
||||
var plan = await fx.Library.PlanDeleteAsync([pngs.Id], fx.Ct);
|
||||
|
||||
string name;
|
||||
using (new FileStream(files[2], FileMode.Open, FileAccess.Read, FileShare.Read))
|
||||
name = (await fx.Library.DeleteAsync([pngs.Id], plan.Fingerprint, null, fx.Ct)).TrashEntries.Single();
|
||||
|
||||
// Never half a folder: every file stays where it was, and every one is in the trash.
|
||||
var (folder, _) = VideoTrash.Location(fx.Archive.Paths, name);
|
||||
Assert.SequenceEqual(files, Directory.GetFiles(source).Order(StringComparer.Ordinal));
|
||||
Assert.Equal(4, Directory.GetFiles(Path.Combine(folder, Path.GetFileName(source))).Length);
|
||||
Assert.True(File.Exists(folder + VideoTrash.LeftoverSuffix));
|
||||
|
||||
Assert.Equal(1, await fx.Library.RecoverAsync(fx.Archive.Archive, fx.Ct));
|
||||
Assert.False(Directory.Exists(source));
|
||||
Assert.Empty(Directory.GetDirectories(Path.GetDirectoryName(source)!, ".*removing-*"));
|
||||
Assert.Equal(4, Directory.GetFiles(Path.Combine(folder, Path.GetFileName(source))).Length, "the trash keeps its copy");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task ARestoreSkipsANameARenderIsWriting()
|
||||
{
|
||||
await using var fx = await VideoFixture.CreateAsync(context);
|
||||
var sequence = await fx.SequenceAsync();
|
||||
var render = await fx.RenderAsync(sequence, "sunset.mp4", 2000);
|
||||
var plan = await fx.Library.PlanDeleteAsync([render.Id], fx.Ct);
|
||||
var name = (await fx.Library.DeleteAsync([render.Id], plan.Fingerprint, null, fx.Ct)).TrashEntries.Single();
|
||||
|
||||
// A render of this process picked the free name meanwhile and is still encoding it.
|
||||
using var writing = new Chronos.Data.Processing.OutputNames();
|
||||
Assert.True(writing.TryReserve(fx.FileOf(render)));
|
||||
var restored = await fx.Library.RestoreAsync(fx.Archive.Archive.Id, name, fx.Ct);
|
||||
Assert.Equal("sunset (2).mp4", Path.GetFileName(restored.OutputPath));
|
||||
Assert.False(File.Exists(fx.FileOf(render)));
|
||||
}
|
||||
}
|
||||
@@ -50,10 +50,11 @@ public sealed class VideoRenderTests(TestContext context)
|
||||
// Only a batch preset plays back: the job of that preset needs format 3, the plain one does not.
|
||||
var split = ProcessingJobs.Split(Read(ProcessingJobs.Render(sequence, Mjpeg with { Batch = ["gif-preview"] }, 96, 64, new ProjectSettings())), 96, 64, new ProjectSettings());
|
||||
Assert.SequenceEqual([1, 1], split.Select(p => p.RequiredSettingsFormat));
|
||||
// Routed with settings whose own export plays back, the job's export (which does not) is what counts, and the other way round.
|
||||
// Routed with settings whose own export plays back, the job's export does not, but the settings text the node reads is
|
||||
// format 3: a node of format 2 could not parse it. The other way round, the job's export counts.
|
||||
var plain = Read(ProcessingJobs.Render(sequence, Mjpeg, 96, 64, new ProjectSettings()));
|
||||
var playing = new ProjectSettings { Export = Mjpeg with { Playback = Boomerang } };
|
||||
Assert.Equal(1, ProcessingJobs.Routed(plain, playing, 96, 64).RequiredSettingsFormat);
|
||||
Assert.Equal(ProjectSettings.PlaybackVersion, ProcessingJobs.Routed(plain, playing, 96, 64).RequiredSettingsFormat);
|
||||
var posted = Read(ProcessingJobs.Render(sequence, Mjpeg with { Playback = Boomerang }, 96, 64, new ProjectSettings())) with { RequiredSettingsFormat = 1 };
|
||||
Assert.Equal(ProjectSettings.PlaybackVersion, ProcessingJobs.Routed(posted, new ProjectSettings(), 96, 64).RequiredSettingsFormat);
|
||||
Assert.Equal(ProjectSettings.PlaybackVersion, ProcessingJobs.RequiredFormat(new ProjectSettings(), Mjpeg with { Batch = ["gif-preview"], Playback = Boomerang }, 96, 64));
|
||||
@@ -124,7 +125,8 @@ public sealed class VideoRenderTests(TestContext context)
|
||||
var set = new SequenceFrames(sequence, frames, frames.Select(f => (string?)f.RelativePath).ToList());
|
||||
Assert.Equal(3, SequenceRender.StillIndex(set, 1, new string('d', 64)));
|
||||
Assert.Equal(3, SequenceRender.StillIndex(set, 1, new string('D', 64)), "any case");
|
||||
Assert.Equal(1, SequenceRender.StillIndex(set, 1, new string('z', 64)), "a photo no longer there: the index");
|
||||
Assert.Null(SequenceRender.StillIndex(set, 1, new string('z', 64)), "a photo no longer there: its index names another photo now");
|
||||
Assert.Equal(1, SequenceRender.StillIndex(set, 1, null), "no hash: the index");
|
||||
Assert.Null(SequenceRender.StillIndex(set, 9, null));
|
||||
// Named by the export's template and the frame number from 1; a taken name gets " (2)".
|
||||
var folder = context.CreateTempDirectory("still");
|
||||
|
||||
@@ -48,12 +48,12 @@ public sealed partial class AdminVideosTests(TestContext context)
|
||||
var page = await server.Client.GetStringAsync("/admin/pages/videos.js");
|
||||
var calls = ApiCall().Matches(page).Select(m => (Method: m.Groups[1].Value, Target: m.Groups[2].Value)).ToList();
|
||||
Assert.True(calls.Count >= 4, string.Join(", ", calls));
|
||||
// Reads the list and the server's videos folder; writes only the videos' delete and copy: no settings, no project,
|
||||
// no render, no job of its own.
|
||||
// Reads the list, the server's videos folder and a filtered sequence's title; writes only the videos' delete and copy:
|
||||
// no settings, no project, no render, no job of its own.
|
||||
foreach (var (method, target) in calls)
|
||||
{
|
||||
Assert.True(method is "get" or "post", $"api.{method}({target}");
|
||||
if (method == "get") Assert.True(target is "listQuery(" or @"""/api/v1/server/settings""", target);
|
||||
if (method == "get") Assert.True(target is "listQuery(" or @"""/api/v1/server/settings""" or "`/api/v1/sequences/${encodeURIComponent(id)}`", target);
|
||||
else Assert.True(target is @"""/api/v1/videos/copy""" or @"""/api/v1/videos/delete""", target);
|
||||
}
|
||||
Assert.Contains("return `/api/v1/videos?${p}`;", page);
|
||||
@@ -82,6 +82,14 @@ public sealed partial class AdminVideosTests(TestContext context)
|
||||
Assert.Contains(@"<video controls autoplay preload=""metadata"" src=""${attr(fileUrl(v))}""></video>", page);
|
||||
Assert.Contains("return `/api/v1/renders/${encodeURIComponent(v.id)}/file`;", page);
|
||||
Assert.Contains(@"shown?.addEventListener(""error"", () => {", page);
|
||||
// An image sequence (a folder, no single file) and a missing file have no download, in the bar or the player.
|
||||
Assert.Contains(@"if (videoKind(v) === ""sequence"") return ""Admin.Videos.Download.Folder.Tip"";", page);
|
||||
Assert.Contains(@"if (v.state === ""missing"") return ""Admin.Videos.Download.Missing.Tip"";", page);
|
||||
Assert.Contains(@"const downloadWhy = one ? downloadBlock(rows.find((v) => v.id === only)) : ""Admin.Videos.Download.One.Tip"";", page);
|
||||
Assert.Contains("if (!v || downloadBlock(v)) return;", page);
|
||||
Assert.Contains("${downloadBlock(v)\n", page);
|
||||
// A sequence filter whose videos are not on the page names the sequence from its own record.
|
||||
Assert.Contains("api.get(`/api/v1/sequences/${encodeURIComponent(id)}`)", page);
|
||||
// The list follows the jobs that end (a copy, a render), the sequences that change and a reconnection.
|
||||
Assert.Contains(@"if (e.type === ""jobState"" && JOB_ENDED.has(e.state)) refreshSoon(1500);", page);
|
||||
Assert.Contains(@"else if (e.type === ""reconnected"") refreshSoon(0);", page);
|
||||
|
||||
@@ -36,4 +36,24 @@ public sealed class PlaybackRoutingTests
|
||||
var still = ProcessingJobs.ReadRender(ProcessingJobs.Still(sequence, Mjpeg, VideoCodec.JpegSequence, 0, null, 96, 64, new ProjectSettings()).ParametersJson).Parameters;
|
||||
Assert.False(RenderNodeService.Renders(Node(2) with { Encoders = [new NodeEncoder(still.Codec, "managed", false, false)] }, still));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SettingsWrittenInFormatThreeNeverGoToAFormatTwoNodeEvenWhenTheJobDoesNotPlayBack()
|
||||
{
|
||||
// The sequence's own export plays back, so its settings text is stamped version 3; the job's preset does not.
|
||||
var stored = new ProjectSettings { Export = Mjpeg with { Playback = new PlaybackSettings { Loops = 3 } } }.ToJson();
|
||||
var read = ProcessingJobs.ReadSettings(stored)!;
|
||||
var sequence = new Sequence { Id = Guid.CreateVersion7(), ArchiveId = Guid.CreateVersion7(), Folder = "Roof", Title = "Roof" };
|
||||
var job = ProcessingJobs.ReadRender(ProcessingJobs.Render(sequence, Mjpeg, 96, 64, new ProjectSettings()).ParametersJson).Parameters;
|
||||
Assert.Equal(1, job.RequiredSettingsFormat);
|
||||
|
||||
var routed = ProcessingJobs.Routed(job, read, 96, 64);
|
||||
var split = ProcessingJobs.Split(job, 96, 64, read);
|
||||
|
||||
Assert.Equal(3, routed.RequiredSettingsFormat);
|
||||
Assert.True(split.All(p => p.RequiredSettingsFormat == 3));
|
||||
RegisterNodeRequest Node(int format) => new("node", [new NodeEncoder("mjpeg", "managed", false, false)], 0, 0, format);
|
||||
Assert.False(RenderNodeService.Renders(Node(2), routed), "a format-2 node cannot parse the settings it would be handed");
|
||||
Assert.True(RenderNodeService.Renders(Node(3), routed));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user