fix(projects): never revert a server's index settings to an older project.json

Before phase 5b the server's settings PATCH wrote the index alone, and every
desktop edit of a linked sequence arrives as one, so an upgraded server holds
sequences whose index settings are newer than their project.json. Main's birth
read project.json first and mirrored it over the index; sequenceChanged then
carried the loss to the desktops' linked copies.

ArchiveServiceOptions.IndexSettingsMayLead, set by the server, keeps both: Main
is born with project.json's settings as version 1 and the index's as version 2,
in force and mirrored (on a read-only archive both go to the index only). A Main
the sidecars already hold, met with no mirror known, keeps index settings that
none of its versions hold as an External version below what project.json gives
(the head again as a Restore, a merge, or the file's). The desktop is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-04 13:35:47 +01:00
1 parent ccc10ec8b8
commit ab6cad51b2
11 files changed
+245 -18

No files matched your search

@@ -9,6 +9,7 @@ using Chronos.Core.Project;
using Chronos.Data;
using Chronos.Data.Archiving;
using Chronos.Data.Projects;
using Chronos.Data.Repositories;
using Chronos.Protocol;
using Chronos.Protocol.Client;
using Chronos.Server.Api;
@@ -430,6 +431,37 @@ public sealed class ProjectTests(TestContext context)
Assert.Equal(0.7, ProjectSettings.FromJson(File.ReadAllText(folder.ProjectPath)).Exposure.ExposureOffsetEv);
}
[Test]
public async Task ASequencePatchedBeforeTheServerKeptProjectsKeepsItsSettingsWhenMainIsBorn()
{
await using var server = await TestServer.StartAsync(context, services: ArchiveModule.Register);
var (_, _, token) = await server.UserAsync("alberto", "editor");
using var client = Client(server, token);
var sid = await SequenceAsync(server, token, 2);
var row = (await server.Database.Sequences.GetAsync(sid))!;
var folder = new ArchivePaths((await server.Database.Archives.ListAsync()).Single().RootPath).Sequence(row.Folder);
Directory.CreateDirectory(Path.GetDirectoryName(folder.ProjectPath)!);
File.WriteAllText(folder.ProjectPath, new ProjectSettings { Exposure = new ExposureSettings { ExposureOffsetEv = 0.2 } }.ToJson());
// An earlier release's PATCH (the desktop's sync of a linked copy) wrote the index alone, after project.json.
var patched = new ProjectSettings { Exposure = new ExposureSettings { ExposureOffsetEv = 0.7 } }.ToJson();
Assert.Equal(SequenceEditOutcome.Updated,
(await server.Database.Sequences.EditAsync(sid, new SequenceEdit { SettingsJson = patched }, row.SettingsVersion, context.Cancellation)).Outcome);
// Upgraded, the first list makes Main: the index's settings stay in force, project.json's are version 1.
var main = (await client.ListProjectsAsync(sid, context.Cancellation)).Single();
Assert.Equal((2, "external"), (main.HeadNumber, main.HeadKind));
var versions = (await client.ListProjectVersionsAsync(sid, main.Id, ct: context.Cancellation)).Items;
Assert.SequenceEqual([2, 1], versions.Select(v => v.Number));
Assert.Equal(0.7, ProjectSettings.FromJson((await client.GetProjectHeadAsync(sid, main.Id, context.Cancellation)).SettingsJson).Exposure.ExposureOffsetEv);
var first = Assert.NotNull(await client.GetProjectVersionAsync(sid, main.Id, versions[1].Id, context.Cancellation));
Assert.Equal("imported", first.Kind);
Assert.Equal(0.2, ProjectSettings.FromJson(first.SettingsJson).Exposure.ExposureOffsetEv);
Assert.Equal(0.7, ProjectSettings.FromJson((await server.Database.Sequences.GetAsync(sid))!.SettingsJson!).Exposure.ExposureOffsetEv);
Assert.Equal(0.7, ProjectSettings.FromJson(File.ReadAllText(folder.ProjectPath)).Exposure.ExposureOffsetEv);
// Read again, nothing moves.
Assert.Equal(2, (await client.ListProjectsAsync(sid, context.Cancellation)).Single().HeadNumber);
}
[Test]
public async Task AServerHomeHoldsOnlyWhatItsFilesHold()
{