Files
Alby96andClaude Opus 5.5 db389a54f2
CI / Build and test (push) Successful in 9m26s
CI / Windows tests and installer (push) Skipped
CI / YAML check (push) Successful in 8s
Release / Build, test and publish (push) Successful in 14m31s
CI / PostgreSQL 16 integration (push) Successful in 9m53s
CI / PostgreSQL 17 integration (push) Successful in 9m22s
CI / Docker image (push) Successful in 44s
Release / Server image (push) Successful in 1m36s
feat: owner review 2 phase 5c: originals, local render, clean-up and the workspace settings (#18)
Originals in the workspace, local render and send home with provenance, the workspace clean-up, size limit and trash, moving the workspace folder, and the complete Settings › Workspace page (owner review 2, R8, phase 5c). One adversarial review round (35 findings, 32 fixed), a copy-cancel race fixed, 184 strings in all 38 languages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Alberto Balbo <alberto.balbo.96@gmail.com>
2026-11-04 20:03:52 +01:00

121 lines
5.5 KiB
C#

using Chronos.App.Editor;
using Chronos.Core.Model;
using Chronos.Testing;
namespace Chronos.App.Tests.Editor;
/// <summary>The jobs of the open sequence: the busy lock, Analyse queued twice, and the server job the header shows.</summary>
public sealed class SequenceJobsTests
{
private static readonly Guid Sunset = Guid.CreateVersion7();
[Test]
public void OnlyAnalysesAndRendersOfTheSequenceCount()
{
var jobs = new SequenceJobs(Sunset);
Assert.False(jobs.Track(Job(JobKind.Render, JobState.Running, Guid.CreateVersion7())), "another sequence");
Assert.False(jobs.Track(Job(JobKind.Proxies, JobState.Running)), "not an analysis or a render");
Assert.Null(jobs.Shown);
Assert.False(jobs.IsBusy);
}
[Test]
public void StatesChangeTheLockProgressAloneDoesNot()
{
var jobs = new SequenceJobs(Sunset);
var render = Job(JobKind.Render, JobState.Queued);
Assert.True(jobs.Track(render), "joined");
Assert.True(jobs.IsActive(render.Id));
Assert.False(jobs.IsBusy, "waiting does not lock the settings");
Assert.True(jobs.Track(render with { State = JobState.Running }), "started");
Assert.True(jobs.IsBusy);
Assert.False(jobs.Track(render with { State = JobState.Running, ProgressDone = 40, ProgressTotal = 96 }), "progress only");
Assert.Equal(40, jobs.Shown!.ProgressDone);
Assert.True(jobs.Track(render with { State = JobState.Paused }));
Assert.False(jobs.IsBusy, "a paused render holds nothing");
Assert.True(jobs.Track(render with { State = JobState.Failed }), "left");
Assert.False(jobs.IsActive(render.Id));
Assert.False(jobs.Track(render with { State = JobState.Failed }), "an ended job that is not tracked changes nothing");
}
[Test]
public void AnAnalysisWaitingOrPausedStillCountsAsQueued()
{
var jobs = new SequenceJobs(Sunset);
var analysis = Job(JobKind.DeepAnalyse, JobState.Paused);
jobs.Track(analysis);
Assert.True(jobs.IsAnalysing, "Analyse would queue a second one");
jobs.Track(analysis with { State = JobState.Done });
Assert.False(jobs.IsAnalysing);
}
[Test]
public void TheHeaderShowsTheRunningJobThenThePausedThenTheOldestWaiting()
{
var jobs = new SequenceJobs(Sunset);
var now = DateTimeOffset.UtcNow;
var later = Job(JobKind.Render, JobState.Queued) with { Created = now };
var first = Job(JobKind.Render, JobState.Queued) with { Created = now.AddMinutes(-5) };
var paused = Job(JobKind.DeepAnalyse, JobState.Paused) with { Created = now.AddMinutes(-9), Started = now.AddMinutes(-8) };
var running = Job(JobKind.Render, JobState.Running) with { Created = now.AddMinutes(-1), Started = now };
foreach (var job in new[] { later, first }) jobs.Track(job);
Assert.Equal(first.Id, jobs.Shown!.Id);
jobs.Track(paused);
Assert.Equal(paused.Id, jobs.Shown!.Id);
jobs.Track(running);
Assert.Equal(running.Id, jobs.Shown!.Id);
jobs.Track(running with { State = JobState.Done });
Assert.Equal(paused.Id, jobs.Shown!.Id);
}
[Test]
public void EachStepFollowsTheRunningJobOfItsKindThenThePausedThenTheOldestWaiting()
{
var jobs = new SequenceJobs(Sunset);
var now = DateTimeOffset.UtcNow;
var waiting = Job(JobKind.DeepAnalyse, JobState.Queued) with { Created = now.AddMinutes(-9) };
var paused = Job(JobKind.DeepAnalyse, JobState.Paused) with { Created = now.AddMinutes(-1), Started = now.AddMinutes(-1) };
var render = Job(JobKind.Render, JobState.Running) with { Started = now };
Assert.Null(jobs.Active(JobKind.DeepAnalyse));
jobs.Track(waiting);
Assert.Equal(waiting.Id, jobs.Active(JobKind.DeepAnalyse)!.Id);
jobs.Track(paused);
Assert.Equal(paused.Id, jobs.Active(JobKind.DeepAnalyse)!.Id, "a paused one before a waiting one");
jobs.Track(render);
Assert.Equal(paused.Id, jobs.Active(JobKind.DeepAnalyse)!.Id, "the running render is of another kind");
Assert.Equal(render.Id, jobs.Active(JobKind.Render)!.Id);
jobs.Track(waiting with { State = JobState.Running, Started = now });
Assert.Equal(waiting.Id, jobs.Active(JobKind.DeepAnalyse)!.Id, "a running one first");
Assert.Null(jobs.Active(JobKind.LightAnalyse));
}
[Test]
public void TheServerHeaderNeverShowsAWorkspaceRenderOrSendOfThisPc()
{
var jobs = new SequenceJobs(Sunset);
var now = DateTimeOffset.UtcNow;
var local = Job(JobKind.WorkspaceRender, JobState.Running) with { Started = now };
var send = Job(JobKind.WorkspaceSend, JobState.Queued);
jobs.Track(local);
jobs.Track(send);
Assert.Equal(local.Id, jobs.Shown!.Id, "the editor follows it");
Assert.Null(jobs.ShownAtHome, "the server header and its Cancel do not");
var atHome = Job(JobKind.DeepAnalyse, JobState.Queued) with { Created = now.AddMinutes(-3) };
jobs.Track(atHome);
Assert.Equal(atHome.Id, jobs.ShownAtHome!.Id, "a job at the home waits behind the local render, and is the one shown");
Assert.True(SequenceJobs.IsLocalKind(JobKind.WorkspaceSend));
Assert.False(SequenceJobs.IsLocalKind(JobKind.Render));
}
private static Job Job(JobKind kind, JobState state, Guid? target = null) => new()
{
Id = Guid.CreateVersion7(),
Kind = kind,
TargetIds = [target ?? Sunset],
State = state,
Created = DateTimeOffset.UtcNow,
};
}