fix(copies): close the fourth verification round of owner review 6

The fourth verification round of the matches work found 18 defects in
the merge, Integrate and Matches surfaces. This commit fixes them:

- An Integrate job now carries the planning account's id, so its re-plan
  decides ownership the way the dialog did.
- A merge skips only a project the kept sequence holds a real copy of
  (name, offset head and history content) and re-points its renders to
  that copy.
- A merge runs its trash checks before the Links stage and records an
  undo, so an abandoned merge gives the other sequence back its link,
  session keys and pairs.
- The metered hold adopts automatic transfers that were paused before a
  restart.
- Apply in the Compare dialog re-plans when the plan is pending or stale.
- The Library's Two versions... lists the second versions a Union merge
  leaves, each with Drop... (dry run, confirmation, verified partner).
  A merge job's Open shows that list.
- The merge's typed confirmation is the invariant count, and the prompt
  names it in all 38 languages.
- Italian text uses Principale and Gemello. The Main project is named
  through WorkspaceText in the Projects part and in the twin tooltip.
- The session keys tooltip is split into two keys, and To trash... and
  Delete on server... say why they are disabled.
- The capture restores the editor account before the Matches scenes.
- Upload again follows SyncHost.CanSendSync (Upload with Edit).
- Matches rows trim archive names in the middle on a rebalanced grid;
  the Projects part rows trim, with the full text in the tooltip.
- The sample project targets use ProjectTransplant.FreeName.

DECISIONS, CHANGELOG, STATUS 8.7, the request doc and the 16 changed
capture baselines are updated.

Refs #73

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-17 19:20:30 +01:00
1 parent 3c99badcfe
commit 2c06e7ac2b
171 files changed
+1591 -218

No files matched your search

+55 -22
View File
@@ -443,19 +443,18 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
}
/// <summary>
/// The drop's non-Main projects, each with the name it gets at the kept sequence's home; one whose head the kept
/// sequence's projects hold already (by content: a merge planned again after an earlier run copied it) is not copied again.
/// The drop's non-Main projects, each with the name it gets at the kept sequence's home; one the kept sequence holds a
/// copy of already (<see cref="HeldAsync"/>: a merge planned again after an earlier run copied it) is not copied again.
/// </summary>
private async Task<List<ProjectStep>> ProjectStepsAsync(Guid keep, Guid drop, string dropArchiveName, CancellationToken ct)
{
var keepProjects = await _db.Projects.ListBySequenceAsync(keep, includeDeleted: false, ct).ConfigureAwait(false);
var taken = keepProjects.Select(p => p.Name).ToHashSet(StringComparer.OrdinalIgnoreCase);
var keepHeads = await HeadHashesAsync(keepProjects, ct).ConfigureAwait(false);
var steps = new List<ProjectStep>();
foreach (var project in (await _db.Projects.ListBySequenceAsync(drop, includeDeleted: false, ct).ConfigureAwait(false))
.Where(p => !p.IsMain).OrderBy(p => p.CreatedAt).ThenBy(p => p.Id))
{
if (await HeldAlreadyAsync(project, keepHeads, ct).ConfigureAwait(false)) continue;
if (await HeldAsync(project, keepProjects, dropArchiveName, ct).ConfigureAwait(false) is not null) continue;
var name = FreeName(project.Name, dropArchiveName, taken);
taken.Add(name);
steps.Add(new ProjectStep(CopySide.Other, project.Id, project.Name, name, project.HeadNumber, project.HeadVersionId ?? Guid.Empty));
@@ -463,26 +462,56 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
return steps;
}
/// <summary>The content hashes of the heads of <paramref name="projects"/> (Main and versionless ones left out; an unreadable head too).</summary>
internal async Task<HashSet<string>> HeadHashesAsync(IEnumerable<SequenceProject> projects, CancellationToken ct)
/// <summary>
/// The copy of the drop's <paramref name="project"/> a merge made in the kept sequence already, among
/// <paramref name="keepProjects"/>: named after it (its name, or the free name a merge gives it), and holding its whole
/// history by content after the Main version it was made from (a transplant). Another project that merely has an
/// equal head (two projects made from equal Mains) is not one. Null when there is none, or a history cannot be read.
/// </summary>
internal async Task<HeldProject?> HeldAsync(SequenceProject project, IReadOnlyList<SequenceProject> keepProjects, string dropArchiveName,
CancellationToken ct)
{
var hashes = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (var project in projects.Where(p => !p.IsMain && p.HeadVersionId is not null))
if (project.IsMain || project.HeadVersionId is null || project.HeadNumber <= 0) return null;
List<ProjectVersion>? source = null;
foreach (var kept in keepProjects.Where(k => !k.IsMain && k.HeadNumber == project.HeadNumber + 1 && NamedAfter(k.Name, project.Name, dropArchiveName)))
{
if (await HeadHashAsync(project.Id, ct).ConfigureAwait(false) is { } hash) hashes.Add(hash);
source ??= await HistoryAsync(project.Id, ct).ConfigureAwait(false);
if (source is null || source.Count != project.HeadNumber) return null;
if (await HistoryAsync(kept.Id, ct).ConfigureAwait(false) is not { } copy || copy.Count != source.Count + 1) continue;
if (!source.Select((v, i) => string.Equals(v.ContentHash, copy[i + 1].ContentHash, StringComparison.OrdinalIgnoreCase)).All(same => same)) continue;
return new HeldProject(kept.Id, source.Select((v, i) => (Source: v.Id, Copy: copy[i + 1].Id)).ToDictionary(m => m.Source, m => m.Copy));
}
return hashes;
return null;
}
/// <summary>Whether the head of <paramref name="project"/> is one of <paramref name="heads"/> (by content).</summary>
internal async Task<bool> HeldAlreadyAsync(SequenceProject project, IReadOnlySet<string> heads, CancellationToken ct) =>
heads.Count > 0 && project.HeadVersionId is not null && await HeadHashAsync(project.Id, ct).ConfigureAwait(false) is { } head && heads.Contains(head);
private async Task<string?> HeadHashAsync(Guid projectId, CancellationToken ct)
/// <summary>Whether <paramref name="kept"/> is a name a merge gives the drop's project <paramref name="name"/> (<see cref="FreeName"/>, or a transplant's numbered one).</summary>
private static bool NamedAfter(string kept, string name, string archiveName)
{
foreach (var stem in (string[])[name, Fit(name, $" ({archiveName})")])
{
if (string.Equals(kept, stem, StringComparison.OrdinalIgnoreCase)) return true;
var open = kept.LastIndexOf(" (", StringComparison.Ordinal);
if (open < 0 || !kept.EndsWith(')')
|| !int.TryParse(kept.AsSpan(open + 2, kept.Length - open - 3), NumberStyles.None, CultureInfo.InvariantCulture, out var n) || n < 2)
continue;
if (string.Equals(kept, Fit(stem, string.Create(CultureInfo.InvariantCulture, $" ({n})")), StringComparison.OrdinalIgnoreCase)) return true;
}
return false;
}
/// <summary>A project's whole history, oldest first; null when it cannot be read.</summary>
private async Task<List<ProjectVersion>?> HistoryAsync(Guid projectId, CancellationToken ct)
{
const int page = 200;
try
{
return (await _archives.Projects.HeadAsync(projectId, ct).ConfigureAwait(false)).ContentHash;
var all = new List<ProjectVersion>();
while (true)
{
var next = await _archives.Projects.VersionsAfterAsync(projectId, all.Count == 0 ? 0 : all[^1].Number, page, ct).ConfigureAwait(false);
all.AddRange(next);
if (next.Count < page) return all;
}
}
catch (Exception ex) when (ex is ProjectException or IOException or UnauthorizedAccessException)
{
@@ -501,13 +530,14 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
var candidate = Fit(stem, string.Create(CultureInfo.InvariantCulture, $" ({n})"));
if (!taken.Contains(candidate)) return candidate;
}
}
static string Fit(string stem, string suffix)
{
const int max = ProjectService.MaxNameLength;
if (suffix.Length >= max) suffix = suffix[..(max / 2)];
return (stem.Length + suffix.Length > max ? stem[..(max - suffix.Length)].TrimEnd() : stem) + suffix;
}
/// <summary>Appends <paramref name="suffix"/>, shortening <paramref name="stem"/> so the whole fits a project name.</summary>
private static string Fit(string stem, string suffix)
{
const int max = ProjectService.MaxNameLength;
if (suffix.Length >= max) suffix = suffix[..(max / 2)];
return (stem.Length + suffix.Length > max ? stem[..(max - suffix.Length)].TrimEnd() : stem) + suffix;
}
/// <summary>The drop's session keys that move to the kept sequence, and those the kept archive maps to a third sequence already.</summary>
@@ -564,3 +594,6 @@ public sealed class SequenceMerger(ChronosDatabase db, ArchiveService archives,
foreach (var key in skippedKeys) yield return "skipped:" + key;
}
}
/// <summary>A copy of a drop project the kept sequence holds already: the kept project and each drop version's copy there.</summary>
internal sealed record HeldProject(Guid KeptId, IReadOnlyDictionary<Guid, Guid> Versions);