Completes local-dev-master-slave-setup: dual-instance frontend tooling, module-capability gating, and master/slave protocol self-healing fixes

Frontend (Unit 2 completion): dual dev-server tooling (pnpm dev:slave,
pnpm dev:all), per-instance browser tab titles, and a backend
capability check (SystemController + useSystemCapabilities +
ModuleGuard) so a Master-only page is hidden on a slave instance
instead of assuming every backend has every module.

Master/slave protocol fixes surfaced by actually running master and
slave side by side locally:
- Deactivating a CMS instance (Inactive) now releases the slave's
  master gate instead of leaving it stuck on its last pushed status.
- The periodic integrity check now also re-pushes status to every
  reachable slave (previously URL-verification only) and runs once
  immediately on startup.
- Added the originally-specified (but never implemented) slave-pull
  path: a slave now periodically polls its own status from the master
  (GET /api/v1/SlaveStatus) and fails open to Available if the master
  is unreachable for too long, complementing the existing push.
- The slave's own Settings page can no longer "successfully" change
  local availability while the master controls it; it's now locked
  with an explanatory banner and the backend rejects the write with
  409 instead of silently no-op'ing it.
- CMS instance status badges now match the dashboard's color/icon
  styling instead of a plain grey badge.

Also corrected the master-cms-module design docs to match this
as-built behavior, and flagged (without a full rewrite) a larger,
pre-existing divergence between its inception-stage application
design and what construction actually built.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-04 19:53:52 +02:00
co-authored by Claude Sonnet 5
parent 274946dbff
commit 0447993181
81 changed files with 2191 additions and 86 deletions
@@ -0,0 +1,95 @@
using FluentAssertions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NSubstitute;
using NSubstitute.ExceptionExtensions;
using SlpModularCms.Modules.Availability.BackgroundServices;
using SlpModularCms.Modules.Availability.Config;
using SlpModularCms.Modules.Availability.Services;
namespace SlpModularCms.Modules.Availability.Tests.BackgroundServices;
public class MasterStatusPollingBackgroundServiceTests
{
[Fact]
public async Task ExecuteTickAsync_DoesNothing_WhenNoMasterRegistered()
{
var masterAvailabilityService = Substitute.For<IMasterAvailabilityService>();
masterAvailabilityService.GetPollTargetAsync().Returns((MasterPollTarget?)null);
var pollClient = Substitute.For<IMasterStatusPollClient>();
var sut = CreateSut(masterAvailabilityService, pollClient);
await sut.ExecuteTickAsync(CancellationToken.None);
await pollClient.DidNotReceive().GetStatusAsync(Arg.Any<string>(), Arg.Any<string>());
await masterAvailabilityService.DidNotReceive().ApplyPolledStatusAsync(Arg.Any<bool>(), Arg.Any<string?>());
await masterAvailabilityService.DidNotReceive().RecordPollFailureAsync(Arg.Any<TimeSpan>());
}
[Fact]
public async Task ExecuteTickAsync_AppliesPolledStatus_WhenPollSucceeds()
{
var masterAvailabilityService = Substitute.For<IMasterAvailabilityService>();
masterAvailabilityService.GetPollTargetAsync().Returns(new MasterPollTarget("https://master.test", "key"));
var pollClient = Substitute.For<IMasterStatusPollClient>();
pollClient.GetStatusAsync("https://master.test", "key").Returns(new PolledMasterStatus(false, "Onderhoud"));
var sut = CreateSut(masterAvailabilityService, pollClient);
await sut.ExecuteTickAsync(CancellationToken.None);
await masterAvailabilityService.Received(1).ApplyPolledStatusAsync(false, "Onderhoud");
await masterAvailabilityService.DidNotReceive().RecordPollFailureAsync(Arg.Any<TimeSpan>());
}
[Fact]
public async Task ExecuteTickAsync_RecordsPollFailure_WhenPollFails()
{
var masterAvailabilityService = Substitute.For<IMasterAvailabilityService>();
masterAvailabilityService.GetPollTargetAsync().Returns(new MasterPollTarget("https://master.test", "key"));
var pollClient = Substitute.For<IMasterStatusPollClient>();
pollClient.GetStatusAsync("https://master.test", "key").Returns((PolledMasterStatus?)null);
var sut = CreateSut(masterAvailabilityService, pollClient, failOpenAfterMinutes: 5);
await sut.ExecuteTickAsync(CancellationToken.None);
await masterAvailabilityService.DidNotReceive().ApplyPolledStatusAsync(Arg.Any<bool>(), Arg.Any<string?>());
await masterAvailabilityService.Received(1).RecordPollFailureAsync(TimeSpan.FromMinutes(5));
}
[Fact]
public async Task ExecuteTickAsync_DoesNotThrow_WhenPollTargetLookupThrows()
{
var masterAvailabilityService = Substitute.For<IMasterAvailabilityService>();
masterAvailabilityService.GetPollTargetAsync().Throws(new InvalidOperationException("boom"));
var pollClient = Substitute.For<IMasterStatusPollClient>();
var sut = CreateSut(masterAvailabilityService, pollClient);
var act = async () => await sut.ExecuteTickAsync(CancellationToken.None);
await act.Should().NotThrowAsync();
}
private static MasterStatusPollingBackgroundService CreateSut(
IMasterAvailabilityService masterAvailabilityService,
IMasterStatusPollClient pollClient,
int failOpenAfterMinutes = 5)
{
var provider = Substitute.For<IServiceProvider>();
provider.GetService(typeof(IMasterAvailabilityService)).Returns(masterAvailabilityService);
provider.GetService(typeof(IMasterStatusPollClient)).Returns(pollClient);
var scope = Substitute.For<IServiceScope>();
scope.ServiceProvider.Returns(provider);
var factory = Substitute.For<IServiceScopeFactory>();
factory.CreateAsyncScope().Returns(new AsyncServiceScope(scope));
var options = Options.Create(new MasterPollingOptions { FailOpenAfterMinutes = failOpenAfterMinutes });
return new MasterStatusPollingBackgroundService(
factory,
options,
Substitute.For<ILogger<MasterStatusPollingBackgroundService>>());
}
}