Empty but complete solution so every later phase starts from a working toolchain: analyzers as errors, locked restore, format check, policy tests that keep packages within ADR 0004 and keep live trading switched off, a /health endpoint served from Docker, and a Gitea workflow with only run steps. API facts of SPEC section 4 re-checked in docs/API-NOTES.md; ADR 0006 records what changed (MSTest base packages, Ubuntu images, OKX WebSocket on 443, Alpaca margin-only accounts). refs #1 refs #2 refs #3 refs #4 refs #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
90 lines
3.2 KiB
C#
90 lines
3.2 KiB
C#
using System.Net.Sockets;
|
|
|
|
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
|
|
|
|
namespace Anubis.Tests;
|
|
|
|
/// <summary>Test categories (ADR 0003). <see cref="LiveDemo"/> never runs in the normal suite.</summary>
|
|
internal static class Category
|
|
{
|
|
public const string Unit = "Unit";
|
|
public const string Integration = "Integration";
|
|
public const string Simulation = "Simulation";
|
|
public const string LiveDemo = "LiveDemo";
|
|
public const string Golden = "Golden";
|
|
}
|
|
|
|
/// <summary>Locates the repository so policy tests can read its files.</summary>
|
|
internal static class Repo
|
|
{
|
|
public static DirectoryInfo Root { get; } = FindRoot();
|
|
|
|
private static DirectoryInfo FindRoot()
|
|
{
|
|
for (var dir = new DirectoryInfo(AppContext.BaseDirectory); dir is not null; dir = dir.Parent)
|
|
{
|
|
if (File.Exists(Path.Combine(dir.FullName, "Anubis.slnx")))
|
|
{
|
|
return dir;
|
|
}
|
|
}
|
|
|
|
throw new InvalidOperationException("Repository root (Anubis.slnx) not found above " + AppContext.BaseDirectory);
|
|
}
|
|
|
|
private static readonly string[] _skippedDirectories = ["bin", "obj", ".git", ".vs", ".claude", "artifacts", "TestResults", "publish", "screenshots"];
|
|
|
|
/// <summary>All files of the working tree, without build output and tool folders.</summary>
|
|
public static IEnumerable<FileInfo> Files()
|
|
{
|
|
var pending = new Stack<DirectoryInfo>();
|
|
pending.Push(Root);
|
|
while (pending.Count > 0)
|
|
{
|
|
var dir = pending.Pop();
|
|
foreach (var sub in dir.EnumerateDirectories())
|
|
{
|
|
if (!_skippedDirectories.Contains(sub.Name, StringComparer.OrdinalIgnoreCase))
|
|
{
|
|
pending.Push(sub);
|
|
}
|
|
}
|
|
|
|
foreach (var file in dir.EnumerateFiles())
|
|
{
|
|
yield return file;
|
|
}
|
|
}
|
|
}
|
|
|
|
public static string Relative(FileInfo file) =>
|
|
Path.GetRelativePath(Root.FullName, file.FullName).Replace('\\', '/');
|
|
}
|
|
|
|
/// <summary>Database engine the suite runs against: <c>ANUBIS_TEST_DB</c> = sqlite (default) or postgres.</summary>
|
|
internal static class TestDatabase
|
|
{
|
|
public static string Engine { get; } =
|
|
(Environment.GetEnvironmentVariable("ANUBIS_TEST_DB") ?? "sqlite").Trim().ToLowerInvariant();
|
|
|
|
/// <summary>Host and port of the PostgreSQL used by the tests, from <c>ANUBIS_TEST_PG_HOST</c> and <c>ANUBIS_TEST_PG_PORT</c>.</summary>
|
|
public static (string Host, int Port) Postgres { get; } = (
|
|
Environment.GetEnvironmentVariable("ANUBIS_TEST_PG_HOST") ?? "localhost",
|
|
int.TryParse(Environment.GetEnvironmentVariable("ANUBIS_TEST_PG_PORT"), out var port) ? port : 55432);
|
|
|
|
public static async Task<bool> PostgresReachableAsync(TimeSpan timeout)
|
|
{
|
|
using var client = new TcpClient();
|
|
using var cts = new CancellationTokenSource(timeout);
|
|
try
|
|
{
|
|
await client.ConnectAsync(Postgres.Host, Postgres.Port, cts.Token).ConfigureAwait(false);
|
|
return true;
|
|
}
|
|
catch (Exception ex) when (ex is SocketException or OperationCanceledException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|