Merge branch 'review2-p5a-fix2-merge' into review2-p5a-int2

This commit is contained in:
Alby96 committed 2026-11-03 12:10:16 +01:00
commit fd35e83dfc
10 files changed
+321 -19

No files matched your search

@@ -118,6 +118,102 @@ public abstract class WorkspaceMergeTests(TestContext context) : DatabaseTest(co
Assert.Null(await sync.CommitAsync(id, cancellationToken: fx.Ct));
}
[Test]
public async Task ABaseNamingAPhotoByItsHashReadsAsTheWorkingStateOnMediaThatHaveNotLearntIt()
{
var fx = await FixtureAsync();
await UnhashAsync(fx, 2);
var (_, sync) = fx.Workspace();
var project = await fx.CheckoutAsync(sync);
var id = project.ProjectId;
var copied = project.ReadMedia()!;
await EditAsync(sync, id, s => s with { ExcludedFrames = [2] }, fx.Ct);
await sync.CommitAsync(id, cancellationToken: fx.Ct);
await sync.PushAsync(id, fx.Home, fx.Ct);
await VerifyAsync(fx);
await WriteAtHomeAsync(fx, s => s with { Exposure = s.Exposure with { ExposureOffsetEv = 0.7 } });
Assert.Equal(WorkspaceState.InSync, (await sync.PullAsync(id, fx.Home, fx.Ct)).Status.State);
var hashed = (await fx.Db.Frames.ListBySequenceAsync(fx.Sequence.Id))[2].Sha256!;
Assert.Contains(hashed, (await fx.Home.HeadAsync(id, fx.Ct)).SettingsJson);
// Media that have not learnt the hash (copied so, the home out of reach since): the base still holds the working state.
project.WriteMedia(copied);
var status = await sync.StatusAsync(id, cancellationToken: fx.Ct);
Assert.Equal((WorkspaceState.InSync, false), (status.State, status.Modified));
Assert.Null(await sync.CommitAsync(id, cancellationToken: fx.Ct));
Assert.Empty(sync.Unpushed(id));
// A change of the user's own still reads as one, and its version keeps the exclusion.
await EditAsync(sync, id, s => s with { Exposure = s.Exposure with { ExposureOffsetEv = 0.9 } }, fx.Ct);
Assert.True((await sync.StatusAsync(id, cancellationToken: fx.Ct)).Modified);
var saved = Assert.NotNull(await sync.CommitAsync(id, cancellationToken: fx.Ct));
Assert.SequenceEqual([2], ProjectSettings.FromJson(ProjectContent.Place(saved.SettingsJson, copied.Photos)).ExcludedFrames);
Assert.Equal(WorkspaceState.InSync, (await sync.PushAsync(id, fx.Home, fx.Ct)).Status.State);
var settings = await SequenceSettingsAsync(fx);
Assert.Equal((0.9, 2), (settings.Exposure.ExposureOffsetEv, settings.ExcludedFrames.Single()));
}
[Test]
public async Task APhotoHashedAtTheHomeIsOutdatedMediaUntilTheMediaLearnItsHash()
{
var fx = await FixtureAsync();
await UnhashAsync(fx, 2);
var (_, sync) = fx.Workspace();
var project = await fx.CheckoutAsync(sync);
var id = project.ProjectId;
await EditAsync(sync, id, s => s with { ExcludedFrames = [2] }, fx.Ct);
await sync.CommitAsync(id, cancellationToken: fx.Ct);
await sync.PushAsync(id, fx.Home, fx.Ct);
Assert.False((await sync.StatusAsync(id, fx.Home, fx.Ct)).MediaOutdated);
await VerifyAsync(fx);
await WriteAtHomeAsync(fx, s => s with { Exposure = s.Exposure with { ExposureOffsetEv = 0.7 } });
var hashed = (await fx.Db.Frames.ListBySequenceAsync(fx.Sequence.Id))[2].Sha256!;
// Asked while another operation holds the project: outdated, the media as they were, nothing to save here.
WorkspaceStatus busy;
using (await project.LockAsync(TimeSpan.FromSeconds(TestTiming.Budget(10)), fx.Ct))
busy = await sync.StatusAsync(id, fx.Home, fx.Ct);
Assert.True(busy.MediaOutdated);
Assert.Equal((WorkspaceState.Behind, false), (busy.State, busy.Modified));
Assert.Null(project.ReadMedia()!.Frames[2].Sha256);
Assert.False((await sync.StatusAsync(id, cancellationToken: fx.Ct)).MediaOutdated, "without a home nothing is known of it");
// Asked again with the project free: the media learn the hash, the frames and their files as copied.
var learnt = await sync.StatusAsync(id, fx.Home, fx.Ct);
Assert.False(learnt.MediaOutdated);
Assert.Equal((WorkspaceState.Behind, false), (learnt.State, learnt.Modified));
Assert.Equal(hashed, project.ReadMedia()!.Frames[2].Sha256);
var pulled = await sync.PullAsync(id, fx.Home, fx.Ct);
Assert.Equal((WorkspaceState.InSync, false), (pulled.Status.State, pulled.Status.MediaOutdated));
Assert.SequenceEqual([2], (await sync.OpenAsync(id, fx.Ct)).Working.ExcludedFrames);
}
[Test]
public async Task APhotoConvertedAtTheHomeIsOutdatedMediaAndTheMediaLearnItsEncodings()
{
var fx = await FixtureAsync(4);
var (store, sync) = fx.Workspace();
var project = await fx.CheckoutAsync(sync);
var id = project.ProjectId;
var copied = project.ReadMedia()!;
Assert.Null(copied.Aliases);
await ProjectServiceTests.ConvertAsync(fx.Archive, fx.Sequence.Id, [1], 700);
var converted = (await fx.Db.Frames.ListBySequenceAsync(fx.Sequence.Id))[1].Sha256!;
// Opened again: the media learn the encodings the conversion joined, but still hold the photo as copied.
await sync.CheckoutAsync(fx.Home, id, cancellationToken: fx.Ct);
var link = Assert.NotNull(project.ReadMedia()!.Aliases).Single();
Assert.Equal((copied.Frames[1].Sha256!.ToLowerInvariant(), converted.ToLowerInvariant()), (link.Sha256.ToLowerInvariant(), link.Replacement.ToLowerInvariant()));
Assert.Equal(copied.Frames[1].Sha256, project.ReadMedia()!.Frames[1].Sha256);
var status = await sync.StatusAsync(id, fx.Home, fx.Ct);
Assert.True(status.MediaOutdated, "the file is not the library's any more: Update media copies it again");
Assert.False(status.Modified);
await fx.CopyAsync(store, id);
Assert.False((await sync.StatusAsync(id, fx.Home, fx.Ct)).MediaOutdated);
Assert.Equal(converted, project.ReadMedia()!.Frames[1].Sha256);
}
[Test]
public async Task AVersionSavedBeforeAnotherWorkspaceNamedThePhotoByItsHashKeepsItsEdit()
{