Files
Alby96andClaude Opus 5.5 e9ac6dccc9 Phase 10: new course and Docker only
Record the course the user chose on 2 December 2026 and make the
container the only form of Anubis.

- ADR 0021-0026: new roadmap (phases 10-24, readings per phase, the
  spec-to-ADR table, merge and tag only after the user's yes),
  Docker only, maths-only decisions, bans turned into limits on margin
  accounts, eToro Demo as currency venue and forward tests, strategy
  championship. ROADMAP rewritten from phase 10; STATE, CLAUDE.md,
  SVILUPPO, README, API-NOTES and the manuals without the desktop.
- Remove the desktop: Anubis.Desktop, Anubis.Setup, deploy/windows,
  release-win and desktop-win, config.toml, PlatformKind,
  ANUBIS_PLATFORM, DPAPI with the ProtectedData package and the
  first-run wizard. Outside a container the server needs --data-dir,
  listens on 127.0.0.1 only and refuses foreign hosts; server and guard
  refuse --platform desktop with an Italian message and exit code 2.
  The demo keeps its key in a file and its error-page choices need no
  startup password. The diagnostics report says where the server runs
  from its own environment.
- Lighter image: restore and publish for linux-x64 only, and leave out
  the Windows libraries ONNX Runtime copies anyway (829 MB to 410 MB on
  disk, /app from 282 MB to 42 MB). Rotating Docker logs in the Unraid
  template, the manual and the compose; backtest and learning run as
  one-shot commands. tasks dev uses artifacts/dev-data.

refs #113 #114 #115 #78 #80 #81

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 17:35:17 +01:00

192 lines
8.5 KiB
C#

using Anubis.Demo;
using Anubis.Platform;
namespace Anubis.Tests;
/// <summary>Startup configuration of the container, and what is left outside it (issue #7, SPEC 15.1, ADR 0022).</summary>
[TestClass]
public sealed class PlatformTests
{
private static readonly string _key = new('k', 40);
private static Dictionary<string, string?> Env(params (string Key, string? Value)[] values)
{
var env = new Dictionary<string, string?>
{
["ANUBIS_DB_ENGINE"] = "sqlite",
["ANUBIS_SECRET_KEY"] = _key,
["ANUBIS_ADMIN_PASSWORD"] = "initial-pass-1",
};
foreach (var (key, value) in values)
{
env[key] = value;
}
return env;
}
[TestMethod]
[TestCategory(Category.Unit)]
public void DockerWithSqliteNeedsNothingElse()
{
var config = DockerPlatform.Load(Env(), "/data");
Assert.IsTrue(config.IsComplete, string.Join("; ", config.Problems.Select(p => p.What)));
Assert.AreEqual(DbEngine.Sqlite, config.Db!.Engine);
Assert.AreEqual(Path.Combine("/data", "db", "anubis.sqlite3"), config.Db.SqlitePath);
Assert.AreEqual(8787, config.Port);
Assert.AreEqual(99, config.Puid);
Assert.AreEqual(100, config.Pgid);
Assert.IsFalse(config.AllowLive);
Assert.AreEqual("Europe/Rome", config.TimeZone.Id);
Assert.IsTrue(config.SecretKey.HasKey);
Assert.HasCount(32, config.SecretKey.GetOrCreateKey());
}
[TestMethod]
[TestCategory(Category.Unit)]
public void DockerPostgresUsesDefaultsAndNeverShowsThePassword()
{
var config = DockerPlatform.Load(Env(("ANUBIS_DB_ENGINE", "postgres"), ("ANUBIS_DB_HOST", "192.168.30.23"), ("ANUBIS_DB_PASSWORD", "pg-password-xyz")));
Assert.IsTrue(config.IsComplete);
Assert.AreEqual(5432, config.Db!.Port);
Assert.AreEqual("anubis", config.Db.Database);
Assert.AreEqual("anubis", config.Db.User);
Assert.IsFalse(config.Db.Describe().Contains("pg-password-xyz", StringComparison.Ordinal));
Assert.IsFalse(config.Db.ToString().Contains("pg-password-xyz", StringComparison.Ordinal));
}
[TestMethod]
[TestCategory(Category.Unit)]
public void MissingOrWrongValuesBecomeProblemsAndNoDatabaseIsChosen()
{
var empty = DockerPlatform.Load(new Dictionary<string, string?>());
Assert.IsNull(empty.Db, "senza ANUBIS_DB_ENGINE nessun database viene scelto al posto dell'utente");
CollectionAssert.IsSubsetOf(new[] { "ANUBIS_DB_ENGINE", "ANUBIS_SECRET_KEY", "ANUBIS_ADMIN_PASSWORD" }, empty.Problems.Select(p => p.Setting).ToList());
Assert.IsTrue(empty.Problems.All(p => p.Remedy.Length > 0));
var wrong = DockerPlatform.Load(Env(("ANUBIS_DB_ENGINE", "mysql")));
Assert.IsNull(wrong.Db);
Assert.IsFalse(wrong.IsComplete);
var postgresWithoutHost = DockerPlatform.Load(Env(("ANUBIS_DB_ENGINE", "postgres")));
Assert.IsNull(postgresWithoutHost.Db, "PostgreSQL incompleto non ripiega su SQLite");
CollectionAssert.IsSubsetOf(new[] { "ANUBIS_DB_HOST", "ANUBIS_DB_PASSWORD" }, postgresWithoutHost.Problems.Select(p => p.Setting).ToList());
var shortKey = DockerPlatform.Load(Env(("ANUBIS_SECRET_KEY", "short")));
Assert.IsTrue(shortKey.Problems.Any(p => p.Setting == "ANUBIS_SECRET_KEY"));
var badLive = DockerPlatform.Load(Env(("ANUBIS_ALLOW_LIVE", "yes")));
Assert.IsFalse(badLive.AllowLive);
Assert.IsTrue(badLive.Problems.Any(p => p.Setting == "ANUBIS_ALLOW_LIVE"));
var badZone = DockerPlatform.Load(Env(("TZ", "Mars/Olympus")));
Assert.IsTrue(badZone.Problems.Any(p => p.Setting == "TZ"));
}
[TestMethod]
[TestCategory(Category.Unit)]
public void OptionalKeysAreReadWithTheDemoSuffix()
{
var config = DockerPlatform.Load(Env(("OKX_API_KEY_DEMO", "demo-key-123456"), ("TELEGRAM_CHAT_ID", "12345")));
Assert.AreEqual("demo-key-123456", config.EnvironmentKeys["OKX_API_KEY_DEMO"]);
Assert.AreEqual("12345", config.EnvironmentKeys["TELEGRAM_CHAT_ID"]);
Assert.IsFalse(config.EnvironmentKeys.ContainsKey("OKX_API_KEY"));
}
[TestMethod]
[TestCategory(Category.Unit)]
public void TheContainerFindsItsDataAndOutsideItTheFolderIsGivenByHand()
{
// The rule of the server and of the guard alike (ADR 0022): no ANUBIS_PLATFORM, no user folder.
var container = new Dictionary<string, string?> { ["DOTNET_RUNNING_IN_CONTAINER"] = "true" };
Assert.AreEqual("/data", DataDirectory.Locate(null, container));
Assert.AreEqual(Path.GetFullPath("dati-di-prova"), DataDirectory.Locate("dati-di-prova", container));
Assert.AreEqual(Path.GetFullPath("dati-di-prova"), DataDirectory.Locate("dati-di-prova", new Dictionary<string, string?>()));
var outside = new Dictionary<string, string?> { ["ANUBIS_PLATFORM"] = "docker" };
var refused = Assert.Throws<StartupRefusedException>(() => DataDirectory.Locate(null, outside));
Assert.Contains("--data-dir", refused.Message);
Assert.Contains("Fuori da un container", refused.Message);
}
[TestMethod]
[TestCategory(Category.Integration)]
public void TheDemoStartsFromAnEmptyFolderAndCreatesItsOwnKey()
{
var folder = TempFolder.Create("demo-key");
try
{
var data = new DataDirectory(folder);
var first = DemoMode.Config(data);
Assert.IsTrue(first.IsComplete, string.Join("; ", first.Problems.Select(p => p.What)));
Assert.AreEqual(data.SqliteFile, first.Db!.SqlitePath);
Assert.IsFalse(first.AllowLive);
Assert.IsFalse(first.SecretKey.HasKey, "An empty folder has no key yet.");
var key = first.SecretKey.GetOrCreateKey();
Assert.HasCount(32, key);
Assert.IsNotEmpty(Directory.EnumerateFiles(Path.Combine(folder, "keys")).ToList(), "The key lives in a file of the demo folder.");
CollectionAssert.AreEqual(key, DemoMode.Config(data).SecretKey.GetOrCreateKey(), "The same key at the next start.");
Assert.DoesNotContain("Windows", first.SecretKey.Description);
}
finally
{
TempFolder.Delete(folder);
}
}
[TestMethod]
[TestCategory(Category.Unit)]
public void NothingOfTheDesktopIsLeftInTheProduct()
{
// ADR 0022: the desktop application, its configuration file and its guided first run are gone.
string[] words = ["config.toml", "primo-avvio", "PlatformKind", "ANUBIS_PLATFORM", "DesktopPlatform", "ProtectedData"];
var found = Repo.Files()
.Where(file => Repo.Relative(file) is var path && (path.StartsWith("src/", StringComparison.Ordinal) ||
path.StartsWith("tools/", StringComparison.Ordinal) || path.StartsWith("deploy/", StringComparison.Ordinal)))
.Where(file => file.Extension is not (".png" or ".ico" or ".ttf" or ".onnx"))
.SelectMany(file => words.Where(word => File.ReadAllText(file.FullName).Contains(word, StringComparison.Ordinal))
.Select(word => Repo.Relative(file) + ": " + word))
.ToList();
Assert.IsEmpty(found, string.Join("; ", found));
}
[TestMethod]
[TestCategory(Category.Unit)]
public void TheSolutionHasFiveProjects()
{
var solution = System.Xml.Linq.XDocument.Load(Path.Combine(Repo.Root.FullName, "Anubis.slnx"));
var projects = solution.Descendants("Project").Select(p => (string)p.Attribute("Path")!).Order(StringComparer.Ordinal).ToList();
CollectionAssert.AreEqual(new[]
{
"src/Anubis.Guard/Anubis.Guard.csproj",
"src/Anubis.Server/Anubis.Server.csproj",
"src/Anubis/Anubis.csproj",
"tests/Anubis.Tests/Anubis.Tests.csproj",
"tools/Anubis.Tasks/Anubis.Tasks.csproj",
}, projects);
}
[TestMethod]
[TestCategory(Category.Unit)]
public void DataFolderHasTheLayoutOfSpec152()
{
var folder = TempFolder.Create("layout");
try
{
var data = new DataDirectory(Path.Combine(folder, "data"));
data.Ensure();
foreach (var name in new[] { "db", "models", "research", "import", "backups", "logs" })
{
Assert.IsTrue(Directory.Exists(Path.Combine(data.Root, name)), name);
}
Assert.AreEqual(Path.Combine(data.Root, "installation.json"), data.InstallationFile);
}
finally
{
TempFolder.Delete(folder);
}
}
}