E5: il lavoratore delle copie automatiche, all'avvio e ogni ora
AutoExportWorker copia da solo nelle cartelle con «Automatica» accesa: il giro di recupero all'avvio e ogni ora (IClock), una passata due minuti dopo l'ultima riga di _febe.jsonl (il segnale parte da LibraryIngest, anche per le righe scritte in ritardo), subito con un segnale urgente. Mai durante una sessione del motore: aspetta e dice perché; i lavori di Alberto vengono prima e, finiti, il lavoro automatico spostato riprende da solo (risposta 49). Al giro riprova le cartelle in pausa (una copia manuale «In pausa» resta di Alberto, risposta 48) e tutti i «Non riuscito» (risposta 50b); «Interrompi» lo ferma fino alla fine della sosta (risposta 53). Un lavoro finito non ne fa partire un altro da solo, così un file che non cambia torna solo al giro. La composizione lo avvia solo nell'avvio normale (mai nella dimostrazione) e lo ferma per primo alla chiusura. Prove: AutoExportWorkerTests (le prove di accettazione di §15: «Tolto» e «Superato» non si ricopiano, una cartella irraggiungibile va in pausa e un giro dopo riprende, nessuna copia durante una sessione), il segnale del giornale, la composizione. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
0ff4a0d632
commit
e66e322d35
12 files changed
+1821
-5
No files matched your search
@@ -51,6 +51,9 @@ internal sealed class ExportTestBed : IAsyncDisposable
|
||||
|
||||
public LongWorkGate Gate { get; }
|
||||
|
||||
/// <summary>The automatic export's signal of this bed: its journal lines and its destinations raise it.</summary>
|
||||
public AutoExportSignal Signal => Library.AutoExport;
|
||||
|
||||
/// <summary>The folder of the general destination (created, empty).</summary>
|
||||
public string Usb => Temp.Combine("usb");
|
||||
|
||||
@@ -78,6 +81,7 @@ internal sealed class ExportTestBed : IAsyncDisposable
|
||||
Disk = disk,
|
||||
Session = session,
|
||||
Gate = gate,
|
||||
AutoSignal = library.AutoExport,
|
||||
};
|
||||
return new ExportTestBed(temp, library, configure is null ? env : configure(env), marta, luca, disk, session, gate);
|
||||
}
|
||||
@@ -178,6 +182,144 @@ internal sealed class WaitingClock(IClock inner) : IClock
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A clock whose delays end only when the test moves the time past them (<see cref="Advance"/>), shared by the worker
|
||||
/// and the service in the loop tests of the automatic export (tappa E5). The time is the library's manual clock.
|
||||
/// </summary>
|
||||
internal sealed class GatedClock(ManualClock inner) : IClock
|
||||
{
|
||||
private readonly Lock _gate = new();
|
||||
private readonly List<(DateTimeOffset Due, TaskCompletionSource Done)> _pending = [];
|
||||
private long _asked;
|
||||
|
||||
public DateTimeOffset Now => inner.Now;
|
||||
|
||||
public TimeZoneInfo LocalZone => inner.LocalZone;
|
||||
|
||||
/// <summary>How many delays were asked so far.</summary>
|
||||
public long Asked => Interlocked.Read(ref _asked);
|
||||
|
||||
/// <summary>When the delays waiting now end, earliest first.</summary>
|
||||
public IReadOnlyList<DateTimeOffset> Pending
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
return [.. _pending.Select(p => p.Due).Order()];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Task Delay(TimeSpan time, CancellationToken ct)
|
||||
{
|
||||
Interlocked.Increment(ref _asked);
|
||||
if (time <= TimeSpan.Zero)
|
||||
{
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
var done = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||
var entry = (Now + time, done);
|
||||
lock (_gate)
|
||||
{
|
||||
_pending.Add(entry);
|
||||
}
|
||||
|
||||
ct.Register(() =>
|
||||
{
|
||||
lock (_gate)
|
||||
{
|
||||
_pending.Remove(entry);
|
||||
}
|
||||
|
||||
done.TrySetCanceled(ct);
|
||||
});
|
||||
return done.Task;
|
||||
}
|
||||
|
||||
/// <summary>Moves the time on and ends every delay that is due.</summary>
|
||||
public void Advance(TimeSpan time)
|
||||
{
|
||||
List<TaskCompletionSource> due;
|
||||
lock (_gate)
|
||||
{
|
||||
inner.Now += time;
|
||||
due = [.. _pending.Where(p => p.Due <= inner.Now).Select(p => p.Done)];
|
||||
_pending.RemoveAll(p => p.Due <= inner.Now);
|
||||
}
|
||||
|
||||
foreach (var done in due)
|
||||
{
|
||||
done.TrySetResult();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Waits (real time, at most 30 s) until more than <paramref name="asked"/> delays were asked and one waits.</summary>
|
||||
public async Task<DateTimeOffset> WaitForDelayAsync(long asked, CancellationToken ct)
|
||||
{
|
||||
var watch = System.Diagnostics.Stopwatch.StartNew();
|
||||
while (true)
|
||||
{
|
||||
if (Asked > asked && Pending is [var first, ..])
|
||||
{
|
||||
return first;
|
||||
}
|
||||
|
||||
if (watch.Elapsed > TimeSpan.FromSeconds(30))
|
||||
{
|
||||
Assert.Fail("nessuna attesa sull'orologio");
|
||||
}
|
||||
|
||||
await Task.Delay(5, ct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The file system of the copies, recording every file opened or hashed while an engine session is under way: the
|
||||
/// automatic export never reads during a session (tappa E5, §15). Wraps another file system (the real one by default);
|
||||
/// <c>watched</c> chooses the files that count (the library's, say).
|
||||
/// </summary>
|
||||
internal sealed class SessionRecordingFileSystem(IEngineSessionState session, IExportFileSystem? inner = null, Func<string, bool>? watched = null) : IExportFileSystem
|
||||
{
|
||||
private readonly IExportFileSystem _inner = inner ?? ExportFileSystem.Instance;
|
||||
private int _violations;
|
||||
|
||||
/// <summary>Files opened or hashed during a session.</summary>
|
||||
public int Violations => Volatile.Read(ref _violations);
|
||||
|
||||
public Stream OpenRead(string path)
|
||||
{
|
||||
Check(path);
|
||||
return _inner.OpenRead(path);
|
||||
}
|
||||
|
||||
public Stream OpenRandomAccess(string path)
|
||||
{
|
||||
Check(path);
|
||||
return _inner.OpenRandomAccess(path);
|
||||
}
|
||||
|
||||
public Task<string> ComputeSha256Async(string path, CancellationToken ct)
|
||||
{
|
||||
Check(path);
|
||||
return _inner.ComputeSha256Async(path, ct);
|
||||
}
|
||||
|
||||
public bool FileExists(string path) => _inner.FileExists(path);
|
||||
|
||||
public long? FileLength(string path) => _inner.FileLength(path);
|
||||
|
||||
private void Check(string path)
|
||||
{
|
||||
if (session.InSession && (watched is null || watched(path)))
|
||||
{
|
||||
Interlocked.Increment(ref _violations);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A mount table given by the test, on any platform (the longest mount point that holds the path wins).</summary>
|
||||
internal sealed class FixedMounts(params ExportMount[] mounts) : IExportMounts
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user