feature: In-App Simulation Runner (Backend)
CI / frontend (push) Canceled after 0s
CI / backend (push) Canceled after 8m32s

This commit is contained in:
voltsrage
2026-08-06 01:52:53 +08:00
parent 943d41339c
commit 24f45851e9
83 changed files with 3974 additions and 120 deletions
+34 -1
View File
@@ -167,6 +167,23 @@ try
builder.Services.Configure<AlertQualityOptions>(
builder.Configuration.GetSection(AlertQualityOptions.Section));
builder.Services.Configure<SimulationOptions>(
builder.Configuration.GetSection(SimulationOptions.Section));
var simulationOptions = builder.Configuration
.GetSection(SimulationOptions.Section).Get<SimulationOptions>() ?? new();
if (simulationOptions.Enabled)
{
builder.Services.AddHttpClient("simulation-loopback", c =>
c.BaseAddress = new Uri(simulationOptions.LoopbackBaseUrl));
builder.Services.AddSingleton<ISimulationClientFactory, SimulationClientFactory>();
builder.Services.AddSingleton<IScenarioCatalog, ScenarioCatalog>();
builder.Services.AddSingleton<SimulationRunner>();
builder.Services.AddSingleton<ISimulationRunner>(sp => sp.GetRequiredService<SimulationRunner>());
builder.Services.AddHostedService(sp => sp.GetRequiredService<SimulationRunner>());
}
builder.Services.AddCors(options =>
{
options.AddPolicy("Dashboard", policy =>
@@ -345,6 +362,13 @@ try
|| args.Contains("create-admin")
|| args.Contains("register-gateway");
if (simulationOptions.Enabled && !isCliCommand)
{
Log.Warning(
"Simulation mode ENABLED — scenario replay endpoints are exposed. " +
"Do not run this configuration against real patient data.");
}
// Demo data — including the seeded demo users with well-known passwords —
// must never be created in production. Seeding:EnableDemoData defaults to
// true so local development and the existing verification scripts are
@@ -360,7 +384,16 @@ try
var redis = scope.ServiceProvider.GetRequiredService<IConnectionMultiplexer>();
await DataSeeder.SeedAsync(db, redis);
await GatewayRegistrySeeder.SeedAsync(db);
await UserSeeder.SeedAsync(db);
await UserSeeder.SeedAsync(
db,
simulationEnabled: simulationOptions.Enabled,
simulationRunnerPassword: simulationOptions.RunnerPassword);
}
else if (simulationOptions.Enabled && !isCliCommand && !app.Environment.IsEnvironment("Testing"))
{
using var scope = app.Services.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
await UserSeeder.EnsureSimulationRunnerAsync(db, simulationOptions.RunnerPassword);
}
if (!app.Environment.IsEnvironment("Testing"))