Keep the guard drill's engine off the internet (refs #102)
ci / test (postgres) (push) Successful in 3m38s
ci / test (sqlite) (push) Successful in 4m6s
ci / test (postgres) (pull_request) Failing after 4m7s
ci / test (sqlite) (pull_request) Successful in 4m24s
ci / image (pull_request) Skipped
ci / image (push) Successful in 1m25s
ci / test (postgres) (push) Successful in 3m38s
ci / test (sqlite) (push) Successful in 4m6s
ci / test (postgres) (pull_request) Failing after 4m7s
ci / test (sqlite) (pull_request) Successful in 4m24s
ci / image (pull_request) Skipped
ci / image (push) Successful in 1m25s
Since Phase 7 the drill's child engine read the real news feeds every two minutes and downloaded the ONNX tone model, and it already asked the ECB, the mood and calendar sources and the Binance archives. The drill is meant to stay on the computer (ADR 0012 point 5) and that extra work loaded the slow CI runner while the drill timed the engine. Under a guard with the drill's loopback OKX, the market data now runs offline: no news job, no model, and every request goes through a loopback-only handler that answers anything else with a final 403, so no source retries with back-off and the engine keeps its pace. No new variable: the drill is recognised by the same conditions as its fake OKX. The drill gains an eighth check (no news read, no model downloaded), and a test runs every market data job, a history round and a news round as the drill builds them and finds only loopback requests on the network. ADR 0016. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
a77aa1b7eb
commit
a5a6918dae
6 files changed
+184
-13
No files matched your search
@@ -297,6 +297,63 @@ public sealed class GuardTests
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The drill's engine stays on this computer (issue #102, ADR 0016). Its market data, built as the host builds it
|
||||
/// under a guard with the drill's OKX, has no news job. Every job once, a history round and a news round send
|
||||
/// nothing outside loopback: the news sources were tried and refused before reaching the network, and no model came.
|
||||
/// </summary>
|
||||
[TestMethod]
|
||||
[TestCategory(Category.Integration)]
|
||||
public async Task TheDrillsEngineReadsNoNewsAndSendsNothingOutsideLoopback()
|
||||
{
|
||||
await using var test = await DatabaseTests.MigratedAsync().ConfigureAwait(false);
|
||||
var clock = new ManualClock(new DateTimeOffset(2026, 11, 16, 9, 0, 0, TimeSpan.Zero));
|
||||
var folder = TempFolder.Create("drill-data");
|
||||
try
|
||||
{
|
||||
var data = new Anubis.Platform.DataDirectory(folder);
|
||||
data.Ensure();
|
||||
using var network = new FakeHttp().On(_ => true, _ => FakeHttp.Respond("""{"code":"0","msg":"","data":[]}"""));
|
||||
var okx = GuardDrill.DrillOkx(new Dictionary<string, string?>(StringComparer.Ordinal) { [GuardDrill.DrillOkxVariable] = "http://127.0.0.1:9/" });
|
||||
Assert.IsNotNull(okx);
|
||||
var bus = new EventBus();
|
||||
using var market = new MarketDataService(test.Db, clock, bus, new SettingsStore(test.Db, clock, bus), new SecretStore(test.Db, clock, new byte[32]), data,
|
||||
network, () => new FakeSocket(), NullLogger.Instance, okx, offline: true);
|
||||
|
||||
var jobs = market.Jobs();
|
||||
Assert.IsFalse(jobs.Any(j => j.Name == Anubis.News.NewsCollector.JobName), "no news job in the drill");
|
||||
using var timeout = new CancellationTokenSource(TimeSpan.FromMinutes(2));
|
||||
foreach (var job in jobs)
|
||||
{
|
||||
await job.Run(timeout.Token).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await market.HistoryRoundAsync(timeout.Token).ConfigureAwait(false);
|
||||
|
||||
// The news round pauses a second between two feeds, on the manual clock.
|
||||
var reading = market.News.RunOnceAsync(timeout.Token);
|
||||
while (!reading.IsCompleted)
|
||||
{
|
||||
clock.Advance(TimeSpan.FromSeconds(1));
|
||||
await Task.Delay(10, _none).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
await reading.ConfigureAwait(false);
|
||||
|
||||
var urls = network.Urls.ToList();
|
||||
Assert.IsTrue(urls.Count > 0, "the drill's OKX answers");
|
||||
Assert.IsTrue(urls.All(LoopbackOnlyHandler.Allowed), string.Join(", ", urls.Select(u => u.Host).Distinct()));
|
||||
var sources = await market.News.Store.ListSourcesAsync(_none).ConfigureAwait(false);
|
||||
Assert.IsTrue(sources.Where(s => s.Enabled && s.Kind == Anubis.News.NewsSourceKinds.Rss).All(s => s.Failures > 0), "every feed was stopped here");
|
||||
Assert.AreEqual(0L, await test.Db.ReadAsync(s => s.CountAsync("SELECT COUNT(*) FROM news_items"), _none).ConfigureAwait(false));
|
||||
Assert.IsFalse(Directory.EnumerateFileSystemEntries(data.Models).Any(), "no model downloaded");
|
||||
}
|
||||
finally
|
||||
{
|
||||
TempFolder.Delete(folder);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The same proof with real processes (the drill that also runs in the Docker image): the real guard, the real
|
||||
/// engine as its child, a sale blocked halfway on the internal simulator, then the restart by SPEC 9.4.
|
||||
|
||||
Reference in new issue
Block a user