feat(historian): QuestDb provider, registry + consumer-gated validator, compose env

Claude-Session: https://claude.ai/code/session_01Ef2ozxS7QPanGT8uoATbTe
This commit is contained in:
Joseph Doherty
2026-10-11 02:23:21 -04:00
parent 18e85265f9
commit 13d628a07f
8 changed files with 351 additions and 0 deletions
@@ -375,4 +375,89 @@ public sealed class ServerHistorianOptionsValidatorTests
result.Failed.ShouldBeTrue();
result.Failures.ShouldContain(f => f.Contains("ServerHistorian:SqlServer:Schema"));
}
private static ServerHistorianOptionsValidator QuestDbSut(string? connectionString, string? prefix = null, bool alarmHistorianEnabled = false)
{
var values = new Dictionary<string, string?> { ["AlarmHistorian:Enabled"] = alarmHistorianEnabled ? "true" : "false" };
if (connectionString is not null) values["ServerHistorian:QuestDb:ConnectionString"] = connectionString;
if (prefix is not null) values["ServerHistorian:QuestDb:TablePrefix"] = prefix;
return new ServerHistorianOptionsValidator(new ConfigurationBuilder().AddInMemoryCollection(values).Build());
}
/// <summary>QuestDb with a connection string passes; the gateway Endpoint/ApiKey/UseTls checks do not fire.</summary>
[Fact]
public void QuestDb_backend_with_connection_string_passes_without_gateway_settings()
{
var result = QuestDbSut("Host=questdb;Port=8812").Validate(null,
new ServerHistorianOptions { Backend = "QuestDb", Enabled = true });
result.Failed.ShouldBeFalse(string.Join("; ", result.Failures ?? []));
}
/// <summary>QuestDb with no connection string fails, naming the key, and never asks for gateway settings.</summary>
[Fact]
public void QuestDb_backend_without_connection_string_fails_naming_the_key()
{
var result = QuestDbSut(null).Validate(null, new ServerHistorianOptions { Backend = "questdb", Enabled = true });
result.Failed.ShouldBeTrue();
result.Failures.ShouldContain(f => f.Contains("ServerHistorian:QuestDb:ConnectionString"));
result.Failures.ShouldNotContain(f => f.Contains("ServerHistorian:Endpoint"));
result.Failures.ShouldNotContain(f => f.Contains("ServerHistorian:ApiKey"));
}
/// <summary>Every <c>QuestDbHistorianOptions.Validate()</c> error is reported, each naming its key.</summary>
[Fact]
public void QuestDb_backend_reports_every_options_error_naming_the_key()
{
var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
{
["AlarmHistorian:Enabled"] = "false",
["ServerHistorian:QuestDb:TablePrefix"] = "bad;prefix",
["ServerHistorian:QuestDb:RetentionDays"] = "0",
["ServerHistorian:QuestDb:CommandTimeout"] = "00:00:00",
["ServerHistorian:QuestDb:VisibilityTimeout"] = "-00:00:01",
}).Build();
var result = new ServerHistorianOptionsValidator(configuration)
.Validate(null, new ServerHistorianOptions { Backend = "QuestDb", Enabled = true });
result.Failed.ShouldBeTrue();
foreach (var key in new[] { "ConnectionString", "TablePrefix", "RetentionDays", "CommandTimeout", "VisibilityTimeout" })
result.Failures.ShouldContain(f => f.Contains($"ServerHistorian:QuestDb:{key}"), key);
}
/// <summary>Unconsumed QuestDb section (nothing enabled) is not validated.</summary>
[Fact]
public void QuestDb_backend_not_consumed_passes_without_connection_string() =>
QuestDbSut(null).Validate(null, new ServerHistorianOptions { Backend = "QuestDb" }).Failed.ShouldBeFalse();
/// <summary>
/// An invalid <c>ServerHistorian:QuestDb:TablePrefix</c> must not fail the host when nothing consumes the
/// section: <see cref="HistorianBackendRegistry.Resolve"/> does not throw and the validator does not check it.
/// </summary>
[Fact]
public void QuestDb_invalid_prefix_not_consumed_neither_resolve_nor_validation_fails()
{
var configuration = new ConfigurationBuilder().AddInMemoryCollection(new Dictionary<string, string?>
{
["AlarmHistorian:Enabled"] = "false",
["ServerHistorian:QuestDb:ConnectionString"] = "Host=questdb;Port=8812",
["ServerHistorian:QuestDb:TablePrefix"] = "bad;prefix",
}).Build();
var options = new ServerHistorianOptions { Backend = "QuestDb" };
Should.NotThrow(() => HistorianBackendRegistry.Resolve(options, configuration));
new ServerHistorianOptionsValidator(configuration).Validate(null, options).Failed.ShouldBeFalse();
}
/// <summary>Consumed (here by AlarmHistorian alone), the same invalid prefix is a named validator error.</summary>
[Fact]
public void QuestDb_invalid_prefix_consumed_is_a_validator_error_naming_the_key()
{
var options = new ServerHistorianOptions { Backend = "QuestDb" };
var result = QuestDbSut("Host=questdb;Port=8812", "bad;prefix", alarmHistorianEnabled: true).Validate(null, options);
result.Failed.ShouldBeTrue();
result.Failures.ShouldContain(f => f.Contains("ServerHistorian:QuestDb:TablePrefix"));
}
}