Files
slp-modular-cms/aidlc-docs/features/master-cms-module/construction/plans/slave-availability-extension-code-generation-plan.md
T

4.6 KiB

Code Generation Plan — Unit 2: slave-availability-extension

Scope

Modify: src/SlpModularCms.Modules.Availability/ (existing project) Create: src/SlpModularCms.Modules.Availability.Master.Tests/ (new test project) Update: SlpModularCms.sln (add new test project) Update: existing AvailabilityMiddlewareTests.cs in Availability.Tests (new 3-param signature)


Steps

Part A — Production Code (Availability module)

  • Step 1SlpModularCms.Modules.Availability.csproj — add InternalsVisibleTo for new test project
  • Step 2Data/Entities/MasterRegistration.cs — entity with singleton Id constant
  • Step 3Data/AvailabilityDbContext.cs — DbContext with MasterRegistrations DbSet + OnModelCreating
  • Step 4Repositories/IMasterRegistrationRepository.csGetAsync, AddAsync, Update, SaveChangesAsync
  • Step 5Repositories/MasterRegistrationRepository.cs — EF Core implementation
  • Step 6Services/IMasterApiKeyProtector.csProtect + Unprotect (null on crypto failure)
  • Step 7Services/MasterApiKeyProtector.cs — wraps IDataProtectionProvider; purpose "SlpModularCms.Availability.MasterApiKey"
  • Step 8Services/MasterGateStatus.csrecord MasterGateStatus(bool IsAvailable, string? DisableMessage)
  • Step 9Services/MasterAvailabilityServiceDependencies.cs — record with repo, protector, logger
  • Step 10Services/IMasterAvailabilityService.csRegisterAsync(bool), PushStatusAsync(bool), GetRegisteredUrlAsync(string?), GetMasterStatus()
  • Step 11Services/MasterAvailabilityService.cs — volatile static fields + implementation of all 4 methods
  • Step 12Models/RegisterMasterRequest.cs + Models/PushStatusRequest.cs[ExcludeFromCodeCoverage] records
  • Step 13Controllers/MasterController.cs — 3 endpoints; header extraction; delegate to service; Unauthorized() on false/null
  • Step 14Middleware/AvailabilityMiddleware.cs — extend: add /api/v1/master/ bypass; move admin check before local gate; add master gate between admin check and local gate
  • Step 15AvailabilityModule.cs — add DbContext, protector, repo, deps, service registrations; add MigrateAsync in UseModule

Part B — Test Project (new)

  • Step 16SlpModularCms.Modules.Availability.Master.Tests.csproj — new project; copy packages from Master.Tests; add Microsoft.IdentityModel.Tokens for JWT tests
  • Step 17Repositories/MasterRegistrationRepositoryTests.cs — EF InMemory; GetAsync (null + found); AddAsync; Update; SaveChanges
  • Step 18Services/MasterApiKeyProtectorTests.csEphemeralDataProtectionProvider; round-trip; invalid ciphertext returns null
  • Step 19Services/MasterAvailabilityServiceTests.cs — NSubstitute; all 4 public methods; key mismatch; first registration; re-registration; static cache state
  • Step 20Controllers/MasterControllerTests.cs — NSubstitute; missing header → 401; success → 200; service returns false/null → 401
  • Step 21Middleware/AvailabilityMiddlewareMasterGateTests.cs — NSubstitute; master gate blocks → 503; master gate passes → local gate evaluated; /api/v1/master/ bypasses; master gate + admin JWT → pass through

Part C — Cross-cutting

  • Step 22SlpModularCms.sln — add Availability.Master.Tests project with new GUID
  • Step 23src/SlpModularCms.Modules.Availability.Tests/AvailabilityMiddlewareTests.cs — update all InvokeAsync(context, _service) calls to InvokeAsync(context, _service, masterSvc) (masterSvc stub returning IsAvailable=true)

Key Design Notes

Concern Decision
Singleton Id public static readonly Guid SingletonId = new("00000000-0000-0000-0000-000000000001")
IMasterAvailabilityService.RegisterAsync Returns bool (true=ok, false=key mismatch)
IMasterAvailabilityService.PushStatusAsync Returns bool (true=ok, false=key mismatch)
IMasterAvailabilityService.GetRegisteredUrlAsync Returns string? (null=unauthorized)
Unprotect null guard storedKey is null || storedKey != incoming → treat as mismatch
Middleware InvokeAsync order bypass paths → admin JWT → master gate → local gate
Existing AvailabilityMiddlewareTests Add stub IMasterAvailabilityService returning IsAvailable=true as 3rd param

Artifact path: aidlc-docs/features/master-cms-module/construction/plans/slave-availability-extension-code-generation-plan.md