E2: prove del motore, dell'archivio e del servizio delle copie

Le prove della tappa E2 (WP5a) coprono il montaggio di /esporta, la
radice, il controllo delle cartelle, le destinazioni, i percorsi, la
copia, gli stati «Tolto» e «Superato», lo stesso post in due account,
il lavoro in sottofondo (interrompi, riprendi, annulla, riavvio, porta
condivisa con importazione e ricostruzione, sessione del motore,
interruttore dell'account, Docker senza montaggio) e il filtro «Copie».
Si appoggiano a un banco comune con falsi per disco, sessione, montaggi
e file system, senza permessi dei file, così girano anche da root.

Le prove hanno trovato due difetti, corretti:
- MarkCopiesRemovedAsync riusava il comando in cache del primo blocco
  di 900 id: «Controlla le copie» falliva con più di 900 file mancanti
  in una pagina.
- ReplacedStatesSql senza statistiche leggeva tutte le copie tolte o
  superate della destinazione: «+state» la tiene sul suo indice.

Il controllo delle cartelle accetta una scrittura di prova sostituibile,
per provare il guasto della sonda senza permessi.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-27 13:28:20 +01:00
1 parent 31cfdac051
commit 736d241a38
18 files changed
+3124 -12

No files matched your search

@@ -564,6 +564,9 @@ public sealed class ExportConstraintTests
await using var db = await TestDatabase.OpenAsync(temp);
var w = await CreateAsync(db);
await FillAsync(db, w);
// Two copies of the files of the world, so that the «Copie» filter has copies and history to look at.
await db.Exports.AddCopyAsync(w.WholeCopy("marta.demo/a.jpg"));
await db.Exports.AddCopyAsync(w.WholeCopy("marta.demo/b.jpg") with { SourceSha256 = Make.Sha(2), CopySha256 = Make.Sha(2), State = ExportCopyState.Removed });
// Without statistics the planner's choice is the point for the «Copie» set shape and the latest row of an identity.
var setShape = await PlanAsync(
@@ -627,6 +630,51 @@ public sealed class ExportConstraintTests
}
}
// The lookups of tappa E2 (WP1.11). The handful of destinations in use may be read whole; never the copies.
var shas = string.Join(", ", Enumerable.Range(0, 3).Select(i => $"@x{i}"));
(string, object?)[] Shas(params (string, object?)[] more) => [.. Enumerable.Range(0, 3).Select(i => ($"@x{i}", (object?)Make.Sha(i * 7))), .. more];
// «Una copia sola» may sort the few rows of one SHA-256 (its key is in the index the planner picks either way).
var lookupsE2 = new (string Name, string Sql, (string, object?)[] Parameters, bool SortAllowed)[]
{
("FindReplacedCopyAsync", ExportStore.ReplacedCopySql, [("@h", Make.Sha(5008)), ("@d", w.General), ("@a", w.Marta)], false),
("FindCopiedElsewhereAsync", ExportStore.CopiedElsewhereSql, [("@h", Make.Sha(17)), ("@v", "Whole"), ("@f", "Original")], true),
("GetCopyStatesAsync", ExportStore.CopyStatesSql(shas), Shas(("@d", w.General)), false),
("GetCopyStatesAsync (sostituiti)", ExportStore.ReplacedStatesSql(shas), Shas(("@d", w.General)), false),
};
foreach (var (name, sql, parameters, sortAllowed) in lookupsE2)
{
var plan = await PlanAsync(db, sql, parameters);
var copies = plan.Replace("SCAN export_destination", string.Empty, StringComparison.Ordinal);
var withoutAllowedSort = sortAllowed ? plan.Replace("USE TEMP B-TREE FOR ORDER BY", string.Empty, StringComparison.Ordinal) : plan;
if (!plan.Contains("SEARCH export_copy USING", StringComparison.Ordinal) || !plan.Contains("sha256=?", StringComparison.Ordinal)
|| copies.Contains("SCAN", StringComparison.Ordinal) || withoutAllowedSort.Contains("TEMP B-TREE", StringComparison.Ordinal))
{
problems.Add($"{name}: {plan}");
}
}
// The «Copie» filter: the two prefilter lists of the grouped mosaic read the copies of the destinations in use
// through ix_export_copy_destination, and the files through their SHA-256.
var x = await db.ReadAsync(ExportFilterSql.Load, default);
foreach (var filter in new[] { Core.Storage.LibraryCopiesFilter.Copied, Core.Storage.LibraryCopiesFilter.RemovedOrSuperseded })
{
var term = ExportFilterSql.EntryTerm(x, filter);
var start = term.IndexOf("+e.id IN (", StringComparison.Ordinal) + "+e.id IN (".Length;
var end = term.IndexOf(") AND EXISTS", start, StringComparison.Ordinal);
Assert.IsGreaterThan(start, end, term);
var plan = await PlanAsync(db, term[start..end]);
// With statistics that say the files are fewer than the copies (this small world), the planner may walk the
// SHA-256 index of the files first; the copies are always searched by destination and state.
var searchesCopies = plan.Contains("SEARCH c USING INDEX ix_export_copy_destination (destination_id=? AND state=?", StringComparison.Ordinal)
|| plan.Contains("SEARCH c USING COVERING INDEX ix_export_copy_destination (destination_id=? AND state=?", StringComparison.Ordinal);
var otherScans = plan.Replace("SCAN m2 USING INDEX ix_media_sha256", string.Empty, StringComparison.Ordinal)
.Replace("SCAN m2 USING COVERING INDEX ix_media_sha256", string.Empty, StringComparison.Ordinal).Contains("SCAN", StringComparison.Ordinal);
if (!searchesCopies || !plan.Contains("m2 USING", StringComparison.Ordinal) || otherScans || plan.Contains("TEMP B-TREE", StringComparison.Ordinal))
{
problems.Add($"prefiltro {filter}: {plan}");
}
}
Assert.IsEmpty(problems, $"{when}: {string.Join(" || ", problems)}");
}