Write the manuals and fix what following them found

The manual, the runbook and the go-live list are written and checked claim by
claim against the code, and the installation is done from zero by following
them on both engines. That found real defects, now fixed:

- with SQLite a missing database file left no way to restore a backup: the
  choices appear, and the file is created only by the user's choice;
- an account whose difference vanished after the 15 minutes stayed prudent
  with no button, a missing stop could be left out for good, and a choice
  made while the broker was silent used old numbers;
- after "Ferma tutto" the positions could not be closed without restarting;
- a refused key looked like a silent broker: it has its own notice now;
- the split of the capital between the strategies of a broker (SPEC 13.5)
  could not be changed from the interface.

refs #72 #68

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-12-01 21:38:33 +01:00
1 parent 2257c3e16c
commit 24e20584d4
28 files changed
+1147 -57

No files matched your search

+55
View File
@@ -1,6 +1,7 @@
using System.Net;
using Anubis.Db;
using Anubis.Server;
using Anubis.Trading;
namespace Anubis.Tests;
@@ -146,6 +147,60 @@ public sealed class AccountsScreenTests
StringAssert.Contains(await server.TextAsync("/impostazioni"), "Trend crypto: quota 100%");
}
[TestMethod]
[TestCategory(Category.Integration)]
public async Task TheUserSplitsTheCapitalAndWithRealMoneyOnlyThroughTheProcedure()
{
await using var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite(), trading: true);
var password = await server.SignInFirstTimeAsync();
var db = server.Host.Services!.Db;
async Task<string> SplitAsync(string momentum, string meanrev, params (string, string)[] more)
{
using var answer = await server.PostFormAsync("/impostazioni", "/azioni/quote/alpaca",
[("quota-" + StrategyNames.EquityMomentum, momentum), ("quota-" + StrategyNames.EquityMeanrev, meanrev), .. more]);
return ServerHarness.Location(answer);
}
Task<List<decimal?>> SharesAsync() => db.ReadAsync(s => s.QueryAsync("SELECT share FROM strategy_state WHERE strategy IN (@m, @r) ORDER BY strategy DESC",
r => r.MoneyOrNull("share"), ("m", StrategyNames.EquityMomentum), ("r", StrategyNames.EquityMeanrev)));
var page = await server.TextAsync("/impostazioni");
StringAssert.Contains(page, "Ripartizione tra le strategie di Alpaca");
Assert.DoesNotContain("Ripartizione tra le strategie di OKX", page, "A single strategy has nothing to split.");
Assert.AreEqual("/impostazioni?ok=quote#conti", await SplitAsync("62,5%", "37,5"));
CollectionAssert.AreEqual(new decimal?[] { 0.625m, 0.375m }, (await SharesAsync()).ToArray());
foreach (var (momentum, meanrev) in new[] { ("60", "30"), ("110", "-10"), ("molto", "40"), ("", "") })
{
Assert.AreEqual("/impostazioni?errore=quote#conti", await SplitAsync(momentum, meanrev), momentum + "/" + meanrev);
}
using (var unknown = await server.PostFormAsync("/impostazioni", "/azioni/quote/binance", ("quota-x", "100")))
{
Assert.AreEqual("/impostazioni?errore=conto#conti", ServerHarness.Location(unknown));
}
// The old and the new value stay, in the changes and in the diary; the same split again adds nothing.
Assert.AreEqual("/impostazioni?ok=quote#conti", await SplitAsync("62,5", "37,5"));
var log = await db.ReadAsync(s => s.QueryAsync("SELECT old_value, new_value FROM config_history WHERE key = @k", r => (r.Text("old_value"), r.Text("new_value")),
("k", "strategy." + StrategyNames.EquityMomentum + ".share")));
Assert.HasCount(1, log);
StringAssert.Contains(log[0].Item2, "62,5%");
var diary = await db.ReadAsync(s => s.QueryAsync("SELECT message FROM journal WHERE code = 'shares_changed'", r => r.Text("message")));
Assert.HasCount(1, diary);
StringAssert.Contains(diary[0], "→ 62,5%");
Assert.DoesNotContain(StrategyNames.EquityMomentum, diary[0]);
// Real money on the account: any new split needs the phrase and the password.
await db.WriteAsync(s => s.ExecuteAsync("UPDATE strategy_state SET stage = 'reduced' WHERE strategy = @s", ("s", StrategyNames.EquityMomentum)));
StringAssert.Contains(await server.TextAsync("/impostazioni"), "Una strategia di questo conto usa soldi veri");
Assert.AreEqual("/impostazioni?errore=frase-rischio#conti", await SplitAsync("50", "50"));
Assert.AreEqual("/impostazioni?errore=password-rischio#conti", await SplitAsync("50", "50", ("frase", StageBook.RaisePhrase), ("password", "sbagliata")));
CollectionAssert.AreEqual(new decimal?[] { 0.625m, 0.375m }, (await SharesAsync()).ToArray());
Assert.AreEqual("/impostazioni?ok=quote#conti", await SplitAsync("50", "50", ("frase", StageBook.RaisePhrase), ("password", password)));
CollectionAssert.AreEqual(new decimal?[] { 0.5m, 0.5m }, (await SharesAsync()).ToArray());
}
[TestMethod]
[TestCategory(Category.Unit)]
[DataRow("4000", "4000")]