E3: conversione della libreria in sottofondo con righe sempre vere

La libreria può ora tenere accanto a ogni originale una copia nel
formato scelto, preparata in sottofondo senza mai sostituire o
cancellare l'originale.

- LongWorkGate ha un permesso di sottofondo che il lavoro in primo
  piano (importazione, copie, ricostruzione) interrompe; il
  salvataggio in corso si aspetta al più CommitWait.
- La coda e il lavoratore: nuovi file accodati all'arrivo, quelli già
  in libreria solo su richiesta, pausa, nuovo tentativo, attesa
  durante una sessione del motore o con poco spazio, nomi liberi e
  adozione di un file identico già presente.
- Le righe di media_conversion restano vere in ogni via: eliminazione
  (Ricorda e Consenti il ritorno, con RemoveWithConversionsAsync per
  il vincolo RESTRICT), perdente del ripasso dei doppioni, file
  cambiato (superate e riaccodate), ricostruzione (conta e riconosce
  i convertiti, accoda solo Pending), importazione (una copia
  convertita o un fotogramma non rientra come file nuovo).
- FebeApp avvia il lavoratore con InBackground; la demo mai.
  _febe.jsonl non cambia.

La prova RecordsCannotBeDeletedFromUnderTheirCopies usa ora una riga
Converted: RemoveAsync toglie da sé le righe senza file, e il vincolo
si verifica sia in SQL sia attraverso il magazzino.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-27 23:57:48 +01:00
1 parent b746aff45d
commit 724c5bda6f
25 files changed
+2621 -38

No files matched your search

@@ -37,6 +37,79 @@ public sealed class ExportFoundationTests
rebuild.Dispose();
}
[TestMethod]
public void AForegroundLeasePreemptsTheBackgroundOneAndBusyIgnoresIt()
{
var gate = new LongWorkGate();
Assert.IsTrue(gate.TryEnterBackground(out var background));
Assert.IsNull(gate.Busy, "Busy ignores the background lease");
Assert.IsTrue(gate.BackgroundRunning);
Assert.IsFalse(gate.TryEnterBackground(out _));
Assert.IsTrue(gate.TryEnter(LongWorkKind.Import, out var import, out _));
Assert.IsTrue(background.Preempted.IsCancellationRequested);
Assert.IsTrue(background.IsPreempted);
Assert.IsFalse(background.TryBeginCommit(out _), "no commit once pre-empted");
Assert.IsFalse(gate.BackgroundRunning);
Assert.AreEqual(LongWorkKind.Import, gate.Busy);
background.Dispose();
Assert.IsFalse(gate.TryEnterBackground(out _), "the background waits for the foreground");
import.Dispose();
Assert.IsTrue(gate.TryEnterBackground(out var again));
again.Dispose();
Assert.IsFalse(gate.BackgroundRunning);
Assert.IsTrue(gate.TryEnter(LongWorkKind.Export, out var export, out _));
export.Dispose();
}
[TestMethod]
public async Task AForegroundLeaseWaitsForACommit()
{
var gate = new LongWorkGate();
Assert.IsTrue(gate.TryEnterBackground(out var background));
Assert.IsTrue(background.TryBeginCommit(out var commit));
var entering = Task.Run(() => gate.TryEnter(LongWorkKind.Rebuild, out var lease, out _) ? lease : null, TestContext.CancellationToken);
while (!background.Preempted.IsCancellationRequested)
{
await Task.Yield();
}
Assert.IsFalse(entering.IsCompleted, "the rebuild waits for the commit");
commit.Dispose();
var rebuild = await entering;
Assert.IsNotNull(rebuild);
rebuild.Dispose();
background.Dispose();
// A commit that does not end in time: the foreground job is refused with its own message.
var quick = new LongWorkGate { CommitWait = TimeSpan.FromMilliseconds(20) };
Assert.IsTrue(quick.TryEnterBackground(out var slow));
Assert.IsTrue(slow.TryBeginCommit(out var held));
Assert.IsFalse(quick.TryEnter(LongWorkKind.Export, out _, out var busy));
Assert.AreEqual(LongWorkKind.LibraryConversion, busy);
Assert.IsNull(quick.Busy);
held.Dispose();
slow.Dispose();
}
[TestMethod]
public void NewKindsHaveTheirOwnMessages()
{
Assert.AreEqual(
"La conversione della libreria sta salvando un file: riprova fra un attimo.",
LongWorkGate.BusyMessage(LongWorkKind.Import, LongWorkKind.LibraryConversion));
Assert.AreEqual(
"Si sta preparando uno zip di fotogrammi: aspetta che finisca, poi importa.",
LongWorkGate.BusyMessage(LongWorkKind.Import, LongWorkKind.FrameDownload));
Assert.AreEqual(
"C'è un'importazione al lavoro: aspetta che finisca o interrompila, poi scarica i fotogrammi.",
LongWorkGate.BusyMessage(LongWorkKind.FrameDownload, LongWorkKind.Import));
Assert.AreEqual(
"La ricostruzione del database è in corso: aspetta che finisca.",
LongWorkGate.BusyMessage(LongWorkKind.FrameDownload, LongWorkKind.Rebuild));
}
[TestMethod]
public async Task AnImportDoesNotStartWhileTheGateIsHeld()
{