Prepare strategies before the host is ready; stop demo servers first (refs #44 #45)
ci / test (postgres) (push) Successful in 4m39s
ci / test (sqlite) (push) Successful in 2m57s
ci / image (push) Successful in 56s
ci / test (postgres) (pull_request) Successful in 5m27s
ci / test (sqlite) (pull_request) Successful in 3m14s
ci / image (pull_request) Successful in 10s

Loading the outcomes before "ready" was not enough: on a fresh database the
strategy rows did not exist yet, so the load did nothing and CI run 220
failed the same way on PostgreSQL. The new TradingService.PrepareAsync
creates accounts and strategies, then loads the outcomes; the host runs it
before it is ready and logs a failure without blocking the interface.
StartAsync repeats it, which changes nothing.

The demo tests deleted the demo folder while the server still held its
SQLite file, which Windows refuses at random. They now stop the server
first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Alby96andClaude Opus 5.5 committed 2026-11-11 17:19:15 +01:00
1 parent dc1ba4e701
commit fc5df0146e
5 files changed
+74 -41

No files matched your search

+3 -1
View File
@@ -12,7 +12,7 @@ public sealed class AccountsScreenTests
[TestCategory(Category.Integration)]
public async Task TheDemoShowsTheFiguresOfTheMockup()
{
await using var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite(), extraArgs: ["--demo"]);
var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite(), extraArgs: ["--demo"]);
var demoRoot = server.Host.Config.Data.Root;
try
{
@@ -58,6 +58,8 @@ public sealed class AccountsScreenTests
}
finally
{
// The server first: on Windows a database still open cannot be deleted.
await server.DisposeAsync();
TempFolder.Delete(demoRoot);
}
}
+45 -36
View File
@@ -147,18 +147,23 @@ public sealed class ServerTests
[TestMethod]
public async Task ComputerOnlyModesRefuseForeignHostNames()
{
await using var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite(), extraArgs: ["--demo"]);
var demoRoot = server.Host.Config.Data.Root;
using (var mine = await server.GetAsync("/api/me"))
// The server stops before its folder is deleted: on Windows an open database cannot be deleted.
string demoRoot;
{
Assert.AreEqual(HttpStatusCode.OK, mine.StatusCode);
await using var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite(), extraArgs: ["--demo"]);
demoRoot = server.Host.Config.Data.Root;
using (var mine = await server.GetAsync("/api/me"))
{
Assert.AreEqual(HttpStatusCode.OK, mine.StatusCode);
}
// DNS rebinding: a page whose name now points at 127.0.0.1 arrives from the loopback with its own Host.
using var request = new HttpRequestMessage(HttpMethod.Get, new Uri("/api/me", UriKind.Relative));
request.Headers.Host = "evil.example:" + server.BaseAddress.Port.ToString(System.Globalization.CultureInfo.InvariantCulture);
using var foreign = await server.Http.SendAsync(request);
Assert.AreEqual(HttpStatusCode.Forbidden, foreign.StatusCode);
}
// DNS rebinding: a page whose name now points at 127.0.0.1 arrives from the loopback with its own Host.
using var request = new HttpRequestMessage(HttpMethod.Get, new Uri("/api/me", UriKind.Relative));
request.Headers.Host = "evil.example:" + server.BaseAddress.Port.ToString(System.Globalization.CultureInfo.InvariantCulture);
using var foreign = await server.Http.SendAsync(request);
Assert.AreEqual(HttpStatusCode.Forbidden, foreign.StatusCode);
TempFolder.Delete(demoRoot);
}
@@ -368,34 +373,38 @@ public sealed class ServerTests
Microsoft.Data.Sqlite.SqliteConnection.ClearAllPools();
var before = Snapshot(configured);
Assert.IsTrue(before.Keys.Any(k => k.EndsWith(".sqlite3", StringComparison.Ordinal)));
await using var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite(), dataDir: configured, extraArgs: ["--demo"]);
// Its own folder under the temporary directory, the configured one untouched.
var demoRoot = server.Host.Config.Data.Root;
StringAssert.StartsWith(demoRoot, Path.Combine(Path.GetTempPath(), "anubis-demo"));
// Appendix F on screen, frozen clock, signed in by itself, the footer says it.
var html = await server.TextAsync("/");
StringAssert.Contains(html, "+412,46 €");
StringAssert.Contains(html, "Venerdì 9 ottobre 2026, ore 08:21");
StringAssert.Contains(html, "Sorveglio 10 posizioni, ognuna con il suo stop.");
StringAssert.Contains(html, "Modalità dimostrativa. Numeri, titoli e notizie sono dati di esempio.");
// The live status arrives over the WebSocket.
using var socket = new ClientWebSocket();
await socket.ConnectAsync(new Uri(server.BaseAddress.ToString().Replace("http", "ws", StringComparison.Ordinal) + "ws"), CancellationToken.None);
var buffer = new byte[4096];
var received = await socket.ReceiveAsync(buffer, CancellationToken.None);
var message = Encoding.UTF8.GetString(buffer, 0, received.Count);
StringAssert.Contains(message, "\"type\":\"status\"");
StringAssert.Contains(message, "\"bot\":\"active\"");
await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None);
var after = Snapshot(configured);
CollectionAssert.AreEquivalent(before.Keys.ToList(), after.Keys.ToList(), "No file added or removed in the configured data folder.");
foreach (var (name, hash) in before)
// The server stops before its folder is deleted: on Windows an open database cannot be deleted.
string demoRoot;
{
Assert.AreEqual(hash, after[name], name + " changed");
await using var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite(), dataDir: configured, extraArgs: ["--demo"]);
// Its own folder under the temporary directory, the configured one untouched.
demoRoot = server.Host.Config.Data.Root;
StringAssert.StartsWith(demoRoot, Path.Combine(Path.GetTempPath(), "anubis-demo"));
// Appendix F on screen, frozen clock, signed in by itself, the footer says it.
var html = await server.TextAsync("/");
StringAssert.Contains(html, "+412,46 €");
StringAssert.Contains(html, "Venerdì 9 ottobre 2026, ore 08:21");
StringAssert.Contains(html, "Sorveglio 10 posizioni, ognuna con il suo stop.");
StringAssert.Contains(html, "Modalità dimostrativa. Numeri, titoli e notizie sono dati di esempio.");
// The live status arrives over the WebSocket.
using var socket = new ClientWebSocket();
await socket.ConnectAsync(new Uri(server.BaseAddress.ToString().Replace("http", "ws", StringComparison.Ordinal) + "ws"), CancellationToken.None);
var buffer = new byte[4096];
var received = await socket.ReceiveAsync(buffer, CancellationToken.None);
var message = Encoding.UTF8.GetString(buffer, 0, received.Count);
StringAssert.Contains(message, "\"type\":\"status\"");
StringAssert.Contains(message, "\"bot\":\"active\"");
await socket.CloseAsync(WebSocketCloseStatus.NormalClosure, null, CancellationToken.None);
var after = Snapshot(configured);
CollectionAssert.AreEquivalent(before.Keys.ToList(), after.Keys.ToList(), "No file added or removed in the configured data folder.");
foreach (var (name, hash) in before)
{
Assert.AreEqual(hash, after[name], name + " changed");
}
}
TempFolder.Delete(demoRoot);
+3 -1
View File
@@ -17,7 +17,7 @@ public sealed class StrategyScreensTests
[TestCategory(Category.Integration)]
public async Task TheDemoShowsTradesStrategiesAndRiskAsInTheMockups()
{
await using var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite(), extraArgs: ["--demo"]);
var server = await ServerHarness.StartAsync("docker", ServerHarness.DockerSqlite(), extraArgs: ["--demo"]);
var demoRoot = server.Host.Config.Data.Root;
try
{
@@ -63,6 +63,8 @@ public sealed class StrategyScreensTests
}
finally
{
// The server first: on Windows a database still open cannot be deleted.
await server.DisposeAsync();
TempFolder.Delete(demoRoot);
}
}