Fix what the review of Phase 9 found in accounts, access, capital, health and publication

A position left out together with its stop kept the account prudent for good: the
stop was still asked for shares that no longer exist. The cover required now stops
at what the account holds, the stops are compared again after the choice, and where
one is still missing Align takes the excluded position up again. After the choice
the account waits for the stop with its own reason, so it returns to normal by
itself also past the 15 minutes; a new difference still gets its own 15 minutes.

A right password alone no longer clears the wrong second-factor codes: it takes
back only its own attempt.

Capital and shares are planned and written in one transaction, so overlapping
changes cannot apply twice and an interruption leaves nothing halfway; sending the
same figures again completes what an old one left. The cash that purchases under
way still hold is no longer given away, counted as the risk engine counts it.

/health said healthy when the trading engine had failed to start. It now says so at
once, or after ten minutes of a stalled start, and the host tries the start again
every minute; the guard still sees a start that does not move.

The image of the manual publication says its version and its commit, marked when
the tree is dirty, and publish.sh refuses before any login an image that does not
come from the commit of the tag.

refs #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:07:46 +01:00
1 parent 24e20584d4
commit 81d6c5f667
20 files changed
+814 -174

No files matched your search

+73 -7
View File
@@ -193,10 +193,14 @@ public sealed partial class DeliveryTests
{
var now = new DateTimeOffset(2026, 12, 1, 9, 0, 0, TimeSpan.Zero);
DateTimeOffset? Ago(double minutes) => now.AddMinutes(-minutes);
Assert.IsTrue(HealthRules.Loop(now, false, Ago(60)).Ok, "Not started, as on the error page or without keys.");
Assert.IsTrue(HealthRules.Loop(now, true, null).Ok);
Assert.IsTrue(HealthRules.Loop(now, true, Ago(1.9)).Ok);
Assert.AreEqual(("fermo", false), HealthRules.Loop(now, true, Ago(2.1)));
Assert.AreEqual(("non avviato", true), HealthRules.Loop(now, null, false, false, null), "No engine to start, as in the demo. Without keys the simulators start as the others.");
Assert.AreEqual(("in avvio", true), HealthRules.Loop(now, Ago(9.9), false, false, null));
Assert.AreEqual(("non avviato", false), HealthRules.Loop(now, Ago(10.1), false, false, null), "Stalled.");
Assert.AreEqual(("non avviato", false), HealthRules.Loop(now, Ago(0.1), false, true, null), "Failed: known at once.");
Assert.AreEqual(new GuardOptions().StalledStart, HealthRules.StartLimit);
Assert.AreEqual(("in avvio", true), HealthRules.Loop(now, Ago(60), true, false, null));
Assert.AreEqual(("ok", true), HealthRules.Loop(now, Ago(60), true, false, Ago(1.9)));
Assert.AreEqual(("fermo", false), HealthRules.Loop(now, Ago(60), true, false, Ago(2.1)));
Assert.AreEqual(new GuardOptions().Silence, HealthRules.LoopLimit);
Assert.IsTrue(HealthRules.Feed(now, null, null).Ok, "No instrument to follow yet.");
@@ -311,6 +315,23 @@ public sealed partial class DeliveryTests
Assert.IsTrue(docker.All(r => r.Contains("\"$IMAGE\"", StringComparison.Ordinal)));
}
[TestMethod]
[TestCategory(Category.Unit)]
public void TheImageSaysTheVersionAndTheCommitItIsMadeFrom()
{
// The image of the manual publication comes from the tasks, that of a tag from the workflow: both say what they are.
var tasks = Text("tools/Anubis.Tasks/Program.cs");
StringAssert.Contains(tasks, "$\"ANUBIS_VERSION={Version()}\"");
StringAssert.Contains(tasks, "$\"ANUBIS_COMMIT={Commit()}\"");
StringAssert.Contains(tasks, "\"-dirty\"");
var build = (string)Steps("image").Single(s => ((string)s["run"]).Contains("docker build", StringComparison.Ordinal))["run"];
StringAssert.Contains(build, "version=${REF_NAME#v}");
StringAssert.Contains(build, "\"ANUBIS_VERSION=$version\"");
StringAssert.Contains(build, "\"ANUBIS_COMMIT=$(git rev-parse HEAD)\"");
var publish = Text("deploy/docker/publish.sh");
Assert.IsLessThan(publish.IndexOf("docker login", StringComparison.Ordinal), publish.IndexOf("docker image inspect", StringComparison.Ordinal), "Checked before anything leaves the house.");
}
[TestMethod]
[TestCategory(Category.Unit)]
public void TheYamlReaderRefusesWhatItDoesNotKnow()
@@ -381,22 +402,66 @@ public sealed partial class DeliveryTests
Assert.IsEmpty(offline.Pushed());
}
[TestMethod]
[TestCategory(Category.Integration)]
[OSCondition(OperatingSystems.Linux)]
[DataRow("v0.9.0", "ci", PublishRun.Commit, false)]
[DataRow("v0.9.0", "0.8.0", PublishRun.Commit, false)]
[DataRow("v0.9.0", "0.9.0-rc.1", PublishRun.Commit, false)]
[DataRow("v0.9.0", "0.9.0", PublishRun.Commit + "-dirty", false)]
[DataRow("v0.9.0", "0.9.0", "fedcba9876543210fedcba9876543210fedcba98", false)]
[DataRow("v0.9.0", "0.9.0", "", false)]
[DataRow("v0.9.0", "0.9.0", PublishRun.Commit, true)]
public async Task TheScriptRefusesAnImageThatIsNotTheOneOfTheTag(string tag, string version, string revision, bool tagged)
{
using var run = new PublishRun("v0.7.0", version: version, revision: revision, tagged: tagged);
var (code, output) = await run.RunAsync(tag, PublishRun.Token);
Assert.AreEqual(1, code, output);
StringAssert.Contains(output, "Pubblicazione non riuscita: l'immagine");
Assert.IsEmpty(run.Pushed());
Assert.AreEqual("", run.Input, "Not even the login.");
}
[TestMethod]
[TestCategory(Category.Integration)]
[OSCondition(OperatingSystems.Linux)]
[DataRow("v0.9.0", PublishRun.TagCommit, true)]
[DataRow("v0.9.0-rc.1", PublishRun.TagCommit, true)]
[DataRow("v0.9.0-rc.1", PublishRun.Commit, false)]
public async Task TheScriptTakesTheImageOfTheTasksAtTheCommitOfTheTag(string tag, string revision, bool tagged)
{
// The commit of the tag when the tag is here, otherwise the one checked out: in the workflow they are the same.
using var run = new PublishRun("v0.7.0", version: "0.9.0", revision: revision, tagged: tagged);
var (code, output) = await run.RunAsync(tag, PublishRun.Token);
Assert.AreEqual(0, code, output);
Assert.IsNotEmpty(run.Pushed());
}
private sealed class PublishRun : IDisposable
{
public const string Token = "a-token-only-for-the-test";
public const string Commit = "0123456789abcdef0123456789abcdef01234567";
public const string TagCommit = "89abcdef0123456789abcdef0123456789abcdef";
private readonly string _root = Path.Combine(Path.GetTempPath(), "anubis-publish-" + Guid.NewGuid().ToString("N"));
public PublishRun(string others, bool gitFails = false)
public PublishRun(string others, bool gitFails = false, string? version = null, string revision = Commit, bool tagged = false)
{
Directory.CreateDirectory(Path.Combine(_root, "deploy", "docker"));
Directory.CreateDirectory(Path.Combine(_root, "bin"));
File.WriteAllText(Path.Combine(_root, "deploy", "docker", "publish.sh"), Text("deploy/docker/publish.sh"));
File.WriteAllText(Path.Combine(_root, "Directory.Build.props"), "<Project>\n <Version>0.9.0</Version>\n</Project>\n");
Tool("docker", "printf '%s\\n' \"$*\" >> \"$RECORD/calls\"\nif [ \"$1\" = login ]; then cat > \"$RECORD/input\"; printf '%s' \"$DOCKER_CONFIG\" > \"$RECORD/config\"; fi\n");
Tool("git", gitFails ? "exit 128\n" : string.Concat(others.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(o => $"printf 'abc\\trefs/tags/{o}\\n'\n")));
_version = version;
Tool("docker", "printf '%s\\n' \"$*\" >> \"$RECORD/calls\"\nif [ \"$1\" = login ]; then cat > \"$RECORD/input\"; printf '%s' \"$DOCKER_CONFIG\" > \"$RECORD/config\"; fi\n" +
$"case \"$*\" in *image.version*) printf '%s\\n' \"$VERSION\" ;; *image.revision*) printf '%s\\n' '{revision}' ;; esac\n");
var tagCommit = tagged ? $"printf '%s\\n' {TagCommit}; exit 0" : "exit 1";
Tool("git", $"case \"$*\" in *rev-parse*refs/tags/*) {tagCommit} ;; *rev-parse*HEAD*) printf '%s\\n' {Commit}; exit 0 ;; esac\n" +
(gitFails ? "exit 128\n" : string.Concat(others.Split(',', StringSplitOptions.RemoveEmptyEntries).Select(o => $"printf 'abc\\trefs/tags/{o}\\n'\n"))));
}
// What the image says of itself when the test says nothing: the version of the tag.
private readonly string? _version;
public string Calls => Recorded("calls");
public string Input => Recorded("input");
@@ -413,6 +478,7 @@ public sealed partial class DeliveryTests
info.ArgumentList.Add(tag);
info.Environment["PATH"] = Path.Combine(_root, "bin") + ":" + Environment.GetEnvironmentVariable("PATH");
info.Environment["RECORD"] = _root;
info.Environment["VERSION"] = _version ?? tag[1..];
info.Environment["REGISTRY"] = "registry.test";
info.Environment["REGISTRY_USER"] = "someone";
info.Environment["REGISTRY_TOKEN"] = token;