Finish an interrupted rebuild and replay the past without acting on it

The independent review found that a rebuild cut halfway was never finished
(stops canceled or lowered), that old stop executions replayed from the broker
queued a real sale, that a pending "close all" survived the restore, and that
reconciliation and corporate actions touched accounts not rebuilt yet. The
rebuild now keeps its starting point until it ends, protects the bot before the
first row, meets the splits at their date and leaves the ledger alone until it
is done. Dividends count the shares of after a split. A failed restore of a
missing SQLite file leaves no empty database, and a failed migration can be
tried again from the choice page.

refs #69 #75

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 22:15:34 +01:00
1 parent 24e20584d4
commit 5ef54b6f2a
17 files changed
+613 -80

No files matched your search

+60
View File
@@ -94,6 +94,24 @@ public sealed class RestoreServerTests
StringAssert.Contains(ServerHarness.Location(unknown), "errore=scelta");
}
// A damaged archive: refused, and the file is still not there, however many turns the loop makes.
foreach (var damage in new[] { "index.json", "users.jsonl" })
{
var saved = new Backups(new DataDirectory(data), SystemClock.Instance).List().Single(b => b.Reason == "a-mano");
var part = Path.Combine(saved.Folder, Backups.ArchiveFolder, damage);
var good = await File.ReadAllTextAsync(part);
await File.WriteAllTextAsync(part, good[..(good.Length / 2)]);
using (var failed = await server.PostFormAsync("/", "/azioni/servizio/ripristina", ("password", ServerHarness.AdminPassword), ("salvataggio", saved.Name)))
{
StringAssert.Contains(ServerHarness.Location(failed), "errore=importazione", damage);
}
await File.WriteAllTextAsync(part, good);
await Task.Delay(6000);
Assert.IsFalse(File.Exists(file), "Trap 20, after a damaged " + damage);
StringAssert.Contains(await server.TextAsync("/"), "Il file del database non c'è");
}
Assert.IsFalse(File.Exists(file), "Trap 20: no database by itself.");
File.Copy(away, file);
await server.WaitForAsync(HostMode.Ready);
@@ -260,6 +278,48 @@ public sealed class RestoreServerTests
TempFolder.Delete(data);
}
[TestMethod]
public async Task AfterAFailedMigrationTheDatabaseCanBeChosenAgain()
{
var (env, postgres) = await ServerHarness.DockerOnEngineAsync();
await using var engine = postgres;
var data = TempFolder.Create("migration-choice");
var directory = new DataDirectory(data);
directory.Ensure();
var settings = postgres?.Settings ?? new DbSettings { Engine = DbEngine.Sqlite, SqlitePath = directory.SqliteFile };
await using (var db = Database.Open(settings))
{
await Migrations.MigrateAsync(db, SystemClock.Instance, null, CancellationToken.None, upTo: 12);
await Installation.CheckAsync(db, directory, SystemClock.Instance);
await db.WriteAsync(s => s.ExecuteAsync("CREATE TABLE cost_estimates (x INTEGER)"));
}
File.Delete(directory.InstallationFile);
await using (var server = await ServerHarness.StartAsync("docker", env, dataDir: data, waitReady: false))
{
await server.WaitForAsync(HostMode.IdentityProblem);
for (var i = 0; i < 2; i++)
{
using var failed = await server.PostFormAsync("/", "/azioni/servizio/usa-questo", ("password", ServerHarness.AdminPassword));
StringAssert.Contains(ServerHarness.Location(failed), "errore=importazione");
}
await using (var db = Database.Open(settings))
{
await db.WriteAsync(s => s.ExecuteAsync("DROP TABLE cost_estimates"));
}
using (var again = await server.PostFormAsync("/", "/azioni/servizio/usa-questo", ("password", ServerHarness.AdminPassword)))
{
Assert.AreEqual("/", ServerHarness.Location(again));
}
await server.WaitForAsync(HostMode.Ready);
}
TempFolder.Delete(data);
}
[TestMethod]
public async Task WithAnotherSecretKeyNothingCrashesAndTheAccessIsResetFromTheCommandLine()
{