refactor: rename ScadaLink → ZB.MOM.WW.ScadaBridge (code + projects + namespaces)

Solution + 23 src projects + 26 test projects renamed; folders, csproj,
namespaces, and ScadaLinkDbContext/ScadaBridgeDbContext class updated.
ActorSystem "scadalink" → "scadabridge", Akka seed-node URLs migrated.
SQL roles/logins, LDAP domains, CLI command name, and CLI config dir
(~/.scadalink → ~/.scadabridge) also renamed.

Build green; 5 Host.Tests fail awaiting SQL login rename in next commit.
Pre-existing StaleTagMonitor timing flakes unchanged.

Rename script committed at tools/rename-to-scadabridge.sh.
This commit is contained in:
Joseph Doherty
2026-05-28 09:37:45 -04:00
parent 6d87ee3c3b
commit 7b0b9c7365
1531 changed files with 11180 additions and 11054 deletions
@@ -0,0 +1,156 @@
using Microsoft.Extensions.Logging.Abstractions;
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Persistence;
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Persistence;
/// <summary>
/// WP-33: Local Artifact Storage tests — shared scripts, external systems,
/// database connections, notification lists.
/// </summary>
public class ArtifactStorageTests : IAsyncLifetime, IDisposable
{
private readonly string _dbFile;
private SiteStorageService _storage = null!;
public ArtifactStorageTests()
{
_dbFile = Path.Combine(Path.GetTempPath(), $"artifact-test-{Guid.NewGuid():N}.db");
}
public async Task InitializeAsync()
{
_storage = new SiteStorageService(
$"Data Source={_dbFile}",
NullLogger<SiteStorageService>.Instance);
await _storage.InitializeAsync();
}
public Task DisposeAsync() => Task.CompletedTask;
public void Dispose()
{
try { File.Delete(_dbFile); } catch { /* cleanup */ }
}
// ── Shared Script Storage ──
[Fact]
public async Task StoreSharedScript_RoundTrips()
{
await _storage.StoreSharedScriptAsync("CalcAvg", "return 42;", "{}", "int");
var scripts = await _storage.GetAllSharedScriptsAsync();
Assert.Single(scripts);
Assert.Equal("CalcAvg", scripts[0].Name);
Assert.Equal("return 42;", scripts[0].Code);
Assert.Equal("{}", scripts[0].ParameterDefinitions);
Assert.Equal("int", scripts[0].ReturnDefinition);
}
[Fact]
public async Task StoreSharedScript_Upserts_OnConflict()
{
await _storage.StoreSharedScriptAsync("CalcAvg", "return 1;", null, null);
await _storage.StoreSharedScriptAsync("CalcAvg", "return 2;", "{\"x\":\"int\"}", "int");
var scripts = await _storage.GetAllSharedScriptsAsync();
Assert.Single(scripts);
Assert.Equal("return 2;", scripts[0].Code);
Assert.Equal("{\"x\":\"int\"}", scripts[0].ParameterDefinitions);
}
[Fact]
public async Task StoreSharedScript_MultipleScripts()
{
await _storage.StoreSharedScriptAsync("Script1", "1", null, null);
await _storage.StoreSharedScriptAsync("Script2", "2", null, null);
await _storage.StoreSharedScriptAsync("Script3", "3", null, null);
var scripts = await _storage.GetAllSharedScriptsAsync();
Assert.Equal(3, scripts.Count);
}
[Fact]
public async Task StoreSharedScript_NullableFields()
{
await _storage.StoreSharedScriptAsync("Simple", "42", null, null);
var scripts = await _storage.GetAllSharedScriptsAsync();
Assert.Single(scripts);
Assert.Null(scripts[0].ParameterDefinitions);
Assert.Null(scripts[0].ReturnDefinition);
}
// ── External System Storage ──
[Fact]
public async Task StoreExternalSystem_DoesNotThrow()
{
await _storage.StoreExternalSystemAsync(
"WeatherAPI", "https://api.weather.com",
"ApiKey", "{\"key\":\"abc\"}", "{\"getForecast\":{}}");
// No exception = success. Query verification would need a Get method.
}
[Fact]
public async Task StoreExternalSystem_Upserts()
{
await _storage.StoreExternalSystemAsync("API1", "https://v1", "Basic", null, null);
await _storage.StoreExternalSystemAsync("API1", "https://v2", "ApiKey", "{}", null);
// Upsert should not throw
}
// ── Database Connection Storage ──
[Fact]
public async Task StoreDatabaseConnection_DoesNotThrow()
{
await _storage.StoreDatabaseConnectionAsync(
"MainDB", "Server=localhost;Database=main", 3, TimeSpan.FromSeconds(1));
}
[Fact]
public async Task StoreDatabaseConnection_Upserts()
{
await _storage.StoreDatabaseConnectionAsync(
"DB1", "Server=old", 3, TimeSpan.FromSeconds(1));
await _storage.StoreDatabaseConnectionAsync(
"DB1", "Server=new", 5, TimeSpan.FromSeconds(2));
// Upsert should not throw
}
// ── Notification List Storage ──
[Fact]
public async Task StoreNotificationList_DoesNotThrow()
{
await _storage.StoreNotificationListAsync(
"Ops Team", ["ops@example.com", "admin@example.com"]);
}
[Fact]
public async Task StoreNotificationList_Upserts()
{
await _storage.StoreNotificationListAsync("Team1", ["a@b.com"]);
await _storage.StoreNotificationListAsync("Team1", ["x@y.com", "z@w.com"]);
// Upsert should not throw
}
// ── Schema includes all WP-33 tables ──
[Fact]
public async Task Initialize_CreatesAllArtifactTables()
{
// The initialize already ran. Verify by storing to each table.
await _storage.StoreSharedScriptAsync("s", "code", null, null);
await _storage.StoreExternalSystemAsync("e", "url", "None", null, null);
await _storage.StoreDatabaseConnectionAsync("d", "connstr", 1, TimeSpan.Zero);
await _storage.StoreNotificationListAsync("n", ["email@test.com"]);
// All succeeded without exceptions = tables exist
}
}
@@ -0,0 +1,197 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using ZB.MOM.WW.ScadaBridge.SiteRuntime.Persistence;
namespace ZB.MOM.WW.ScadaBridge.SiteRuntime.Tests.Persistence;
/// <summary>
/// Tests for SiteStorageService using file-based SQLite (temp files).
/// Validates the schema, CRUD operations, and constraint behavior.
/// </summary>
public class SiteStorageServiceTests : IAsyncLifetime, IDisposable
{
private readonly string _dbFile;
private SiteStorageService _storage = null!;
public SiteStorageServiceTests()
{
_dbFile = Path.Combine(Path.GetTempPath(), $"site-storage-test-{Guid.NewGuid():N}.db");
}
public async Task InitializeAsync()
{
_storage = new SiteStorageService(
$"Data Source={_dbFile}",
NullLogger<SiteStorageService>.Instance);
await _storage.InitializeAsync();
}
public Task DisposeAsync() => Task.CompletedTask;
public void Dispose()
{
try { File.Delete(_dbFile); } catch { /* cleanup */ }
}
[Fact]
public async Task InitializeAsync_CreatesTablesWithoutError()
{
// Already called in InitializeAsync — just verify no exception
// Call again to verify idempotency (CREATE IF NOT EXISTS)
await _storage.InitializeAsync();
}
[Fact]
public async Task StoreAndRetrieve_DeployedConfig_RoundTrips()
{
await _storage.StoreDeployedConfigAsync(
"Pump1", "{\"test\":true}", "dep-001", "sha256:abc", isEnabled: true);
var configs = await _storage.GetAllDeployedConfigsAsync();
Assert.Single(configs);
Assert.Equal("Pump1", configs[0].InstanceUniqueName);
Assert.Equal("{\"test\":true}", configs[0].ConfigJson);
Assert.Equal("dep-001", configs[0].DeploymentId);
Assert.Equal("sha256:abc", configs[0].RevisionHash);
Assert.True(configs[0].IsEnabled);
}
[Fact]
public async Task StoreDeployedConfig_Upserts_OnConflict()
{
await _storage.StoreDeployedConfigAsync(
"Pump1", "{\"v\":1}", "dep-001", "sha256:aaa", isEnabled: true);
await _storage.StoreDeployedConfigAsync(
"Pump1", "{\"v\":2}", "dep-002", "sha256:bbb", isEnabled: false);
var configs = await _storage.GetAllDeployedConfigsAsync();
Assert.Single(configs);
Assert.Equal("{\"v\":2}", configs[0].ConfigJson);
Assert.Equal("dep-002", configs[0].DeploymentId);
Assert.False(configs[0].IsEnabled);
}
[Fact]
public async Task RemoveDeployedConfig_RemovesConfigAndOverrides()
{
await _storage.StoreDeployedConfigAsync(
"Pump1", "{}", "dep-001", "sha256:aaa", isEnabled: true);
await _storage.SetStaticOverrideAsync("Pump1", "Temperature", "100");
await _storage.RemoveDeployedConfigAsync("Pump1");
var configs = await _storage.GetAllDeployedConfigsAsync();
var overrides = await _storage.GetStaticOverridesAsync("Pump1");
Assert.Empty(configs);
Assert.Empty(overrides);
}
[Fact]
public async Task SetInstanceEnabled_UpdatesFlag()
{
await _storage.StoreDeployedConfigAsync(
"Pump1", "{}", "dep-001", "sha256:aaa", isEnabled: true);
await _storage.SetInstanceEnabledAsync("Pump1", false);
var configs = await _storage.GetAllDeployedConfigsAsync();
Assert.False(configs[0].IsEnabled);
await _storage.SetInstanceEnabledAsync("Pump1", true);
configs = await _storage.GetAllDeployedConfigsAsync();
Assert.True(configs[0].IsEnabled);
}
[Fact]
public async Task SetInstanceEnabled_NonExistent_DoesNotThrow()
{
// Should not throw for a missing instance
await _storage.SetInstanceEnabledAsync("DoesNotExist", true);
}
// ── Static Override Tests ──
[Fact]
public async Task SetAndGetStaticOverride_RoundTrips()
{
await _storage.SetStaticOverrideAsync("Pump1", "Temperature", "98.6");
var overrides = await _storage.GetStaticOverridesAsync("Pump1");
Assert.Single(overrides);
Assert.Equal("98.6", overrides["Temperature"]);
}
[Fact]
public async Task SetStaticOverride_Upserts_OnConflict()
{
await _storage.SetStaticOverrideAsync("Pump1", "Temperature", "98.6");
await _storage.SetStaticOverrideAsync("Pump1", "Temperature", "100.0");
var overrides = await _storage.GetStaticOverridesAsync("Pump1");
Assert.Single(overrides);
Assert.Equal("100.0", overrides["Temperature"]);
}
[Fact]
public async Task ClearStaticOverrides_RemovesAll()
{
await _storage.SetStaticOverrideAsync("Pump1", "Temperature", "98.6");
await _storage.SetStaticOverrideAsync("Pump1", "Pressure", "50.0");
await _storage.ClearStaticOverridesAsync("Pump1");
var overrides = await _storage.GetStaticOverridesAsync("Pump1");
Assert.Empty(overrides);
}
[Fact]
public async Task GetStaticOverrides_IsolatedPerInstance()
{
await _storage.SetStaticOverrideAsync("Pump1", "Temperature", "98.6");
await _storage.SetStaticOverrideAsync("Pump2", "Pressure", "50.0");
var pump1 = await _storage.GetStaticOverridesAsync("Pump1");
var pump2 = await _storage.GetStaticOverridesAsync("Pump2");
Assert.Single(pump1);
Assert.Single(pump2);
Assert.True(pump1.ContainsKey("Temperature"));
Assert.True(pump2.ContainsKey("Pressure"));
}
[Fact]
public async Task MultipleInstances_IndependentLifecycle()
{
await _storage.StoreDeployedConfigAsync("Pump1", "{}", "d1", "h1", true);
await _storage.StoreDeployedConfigAsync("Pump2", "{}", "d2", "h2", true);
await _storage.StoreDeployedConfigAsync("Pump3", "{}", "d3", "h3", false);
var configs = await _storage.GetAllDeployedConfigsAsync();
Assert.Equal(3, configs.Count);
await _storage.RemoveDeployedConfigAsync("Pump2");
configs = await _storage.GetAllDeployedConfigsAsync();
Assert.Equal(2, configs.Count);
Assert.DoesNotContain(configs, c => c.InstanceUniqueName == "Pump2");
}
// ── Negative Tests ──
[Fact]
public async Task Schema_DoesNotContain_AlarmStateTable()
{
// Per design: no alarm state table in site SQLite
var configs = await _storage.GetAllDeployedConfigsAsync();
var overrides = await _storage.GetStaticOverridesAsync("nonexistent");
Assert.Empty(configs);
Assert.Empty(overrides);
}
}