feat(packs): PackImporter stubs pass + IsEnabled gate in active-packs
PackImporter now runs a second pass over pack-stubs.json, inserting PackConfigEntry placeholders for any pack_id NOT already present from the live-capture packs.json pass. Synthesized stubs default IsEnabled=false; live-capture rows default IsEnabled=true. PackRepository.GetActivePacks filters by IsEnabled in addition to the date window, so synthesized stubs stay hidden until an operator opts them in (UPDATE Packs SET IsEnabled=true WHERE Id=...). Bundles Task 6 + Task 11 because adding pack-stubs.json to the test-fixture set surfaces an extra row in PackControllerFullCatalogTests' 35-pack count assertion; the filter is what makes the test resilient. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
54
SVSim.Bootstrap/Data/test-fixtures/seeds/pack-stubs.json
Normal file
54
SVSim.Bootstrap/Data/test-fixtures/seeds/pack-stubs.json
Normal file
@@ -0,0 +1,54 @@
|
||||
[
|
||||
{
|
||||
"parent_gacha_id": 10001,
|
||||
"base_pack_id": 10001,
|
||||
"gacha_type": 1,
|
||||
"pack_category": 0,
|
||||
"poster_type": 0,
|
||||
"commence_date": "2016-06-17 00:00:00",
|
||||
"complete_date": "2026-06-30 23:59:59",
|
||||
"sleeve_id": 0,
|
||||
"special_sleeve_id": 0,
|
||||
"override_draw_effect_pack_id": 0,
|
||||
"override_ui_effect_pack_id": 0,
|
||||
"gacha_detail": "STUB CLC",
|
||||
"is_hide": false,
|
||||
"is_new": false,
|
||||
"is_pre_release": false,
|
||||
"open_count_limit": 0,
|
||||
"sales_period_time": null,
|
||||
"gacha_point": null,
|
||||
"child_gachas": [
|
||||
{ "gacha_id": 100011, "type_detail": 2, "cost": 200, "card_count": 1 },
|
||||
{ "gacha_id": 100012, "type_detail": 2, "cost": 1800, "card_count": 10 }
|
||||
],
|
||||
"banners": [],
|
||||
"is_enabled": false
|
||||
},
|
||||
{
|
||||
"parent_gacha_id": 95001,
|
||||
"base_pack_id": 95001,
|
||||
"gacha_type": 1,
|
||||
"pack_category": 2,
|
||||
"poster_type": 0,
|
||||
"commence_date": "2016-06-17 00:00:00",
|
||||
"complete_date": "2026-06-30 23:59:59",
|
||||
"sleeve_id": 0,
|
||||
"special_sleeve_id": 0,
|
||||
"override_draw_effect_pack_id": 0,
|
||||
"override_ui_effect_pack_id": 0,
|
||||
"gacha_detail": "7th Anniv stub",
|
||||
"is_hide": false,
|
||||
"is_new": false,
|
||||
"is_pre_release": false,
|
||||
"open_count_limit": 0,
|
||||
"sales_period_time": null,
|
||||
"gacha_point": null,
|
||||
"child_gachas": [
|
||||
{ "gacha_id": 950011, "type_detail": 2, "cost": 200, "card_count": 1 },
|
||||
{ "gacha_id": 950012, "type_detail": 2, "cost": 1800, "card_count": 10 }
|
||||
],
|
||||
"banners": [],
|
||||
"is_enabled": false
|
||||
}
|
||||
]
|
||||
@@ -61,6 +61,7 @@ public class PackImporter
|
||||
ExchangeablePoint = s.GachaPoint.ExchangeablePoint,
|
||||
IncreaseGachaPoint = s.GachaPoint.IncreaseGachaPoint,
|
||||
};
|
||||
pack.IsEnabled = s.IsEnabled;
|
||||
|
||||
// Owned collections -- clear and rehydrate (matches the previous wholesale-replace semantics).
|
||||
pack.ChildGachas.Clear();
|
||||
@@ -101,7 +102,75 @@ public class PackImporter
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
Console.WriteLine($"[PackImporter] +{created}/~{updated}");
|
||||
return created + updated;
|
||||
Console.WriteLine($"[PackImporter] capture: +{created}/~{updated}");
|
||||
|
||||
// Second pass: synthesized stubs from pack-stubs.json. Skip any pack_id that already
|
||||
// exists from the live-capture pass (capture wins on conflict).
|
||||
var stubs = SeedLoader.LoadList<PackSeed>(Path.Combine(seedDir, "pack-stubs.json"));
|
||||
int stubsAdded = 0;
|
||||
foreach (var s in stubs)
|
||||
{
|
||||
if (s.ParentGachaId == 0) continue;
|
||||
if (existing.ContainsKey(s.ParentGachaId)) continue;
|
||||
|
||||
var pack = new PackConfigEntry
|
||||
{
|
||||
Id = s.ParentGachaId,
|
||||
BasePackId = s.BasePackId,
|
||||
GachaType = s.GachaType,
|
||||
PackCategory = (PackCategory)s.PackCategory,
|
||||
PosterType = s.PosterType,
|
||||
CommenceDate = ParseWireDateTime(s.CommenceDate),
|
||||
CompleteDate = ParseWireDateTime(s.CompleteDate),
|
||||
SleeveId = s.SleeveId,
|
||||
SpecialSleeveId = s.SpecialSleeveId,
|
||||
OverrideDrawEffectPackId = s.OverrideDrawEffectPackId,
|
||||
OverrideUiEffectPackId = s.OverrideUiEffectPackId,
|
||||
GachaDetail = s.GachaDetail,
|
||||
IsHide = s.IsHide,
|
||||
IsNew = s.IsNew,
|
||||
IsPreRelease = s.IsPreRelease,
|
||||
OpenCountLimit = s.OpenCountLimit,
|
||||
SalesPeriodTime = string.IsNullOrEmpty(s.SalesPeriodTime) ? null : ParseWireDateTime(s.SalesPeriodTime),
|
||||
GachaPointConfig = s.GachaPoint is null ? null : new PackGachaPointConfig
|
||||
{
|
||||
ExchangeablePoint = s.GachaPoint.ExchangeablePoint,
|
||||
IncreaseGachaPoint = s.GachaPoint.IncreaseGachaPoint,
|
||||
},
|
||||
IsEnabled = s.IsEnabled,
|
||||
};
|
||||
foreach (var c in s.ChildGachas)
|
||||
{
|
||||
pack.ChildGachas.Add(new PackChildGachaEntry
|
||||
{
|
||||
GachaId = c.GachaId,
|
||||
TypeDetail = c.TypeDetail,
|
||||
Cost = c.Cost,
|
||||
CardCount = c.CardCount,
|
||||
ItemId = c.ItemId,
|
||||
IsDailySingle = c.IsDailySingle,
|
||||
OverrideIncreaseGachaPoint = c.OverrideIncreaseGachaPoint,
|
||||
PurchaseLimitCount = c.PurchaseLimitCount,
|
||||
FreeGachaCampaignId = c.FreeGachaCampaignId,
|
||||
CampaignName = c.CampaignName,
|
||||
});
|
||||
}
|
||||
foreach (var b in s.Banners)
|
||||
{
|
||||
pack.Banners.Add(new PackBannerEntry
|
||||
{
|
||||
BannerName = b.BannerName,
|
||||
DialogTitle = b.DialogTitle,
|
||||
});
|
||||
}
|
||||
context.Packs.Add(pack);
|
||||
existing[s.ParentGachaId] = pack;
|
||||
stubsAdded++;
|
||||
}
|
||||
|
||||
await context.SaveChangesAsync();
|
||||
Console.WriteLine($"[PackImporter] stubs: +{stubsAdded}");
|
||||
|
||||
return created + updated + stubsAdded;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class PackRepository : IPackRepository
|
||||
await _db.Packs
|
||||
.Include(p => p.ChildGachas)
|
||||
.Include(p => p.Banners)
|
||||
.Where(p => p.CommenceDate <= now && p.CompleteDate >= now)
|
||||
.Where(p => p.IsEnabled && p.CommenceDate <= now && p.CompleteDate >= now)
|
||||
// parent_gacha_id DESC matches the prod /pack/info wire order. The tutorial pack
|
||||
// UI runs with controls locked and auto-selects the FIRST entry in
|
||||
// pack_config_list, so the legendary starter pack (99047) MUST be index 0 for the
|
||||
|
||||
44
SVSim.UnitTests/Importers/PackImporterStubsTests.cs
Normal file
44
SVSim.UnitTests/Importers/PackImporterStubsTests.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SVSim.Bootstrap.Importers;
|
||||
using SVSim.Database;
|
||||
using SVSim.UnitTests.Infrastructure;
|
||||
|
||||
namespace SVSim.UnitTests.Importers;
|
||||
|
||||
public class PackImporterStubsTests
|
||||
{
|
||||
private static string SeedDir => Path.Combine(AppContext.BaseDirectory, "Data", "seeds");
|
||||
|
||||
[Test]
|
||||
public async Task Live_capture_overrides_stub_on_conflict()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
await new PackImporter().ImportAsync(db, SeedDir);
|
||||
|
||||
// 10001 is in both packs.json (no is_enabled -> defaults true) and pack-stubs.json
|
||||
// (is_enabled=false). Live capture wins -> IsEnabled stays true and gacha_detail
|
||||
// is the packs.json value, not "STUB CLC".
|
||||
var live = await db.Packs.FirstAsync(p => p.Id == 10001);
|
||||
Assert.That(live.IsEnabled, Is.True);
|
||||
Assert.That(live.GachaDetail, Does.Not.Contain("STUB"));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Stub_only_packs_are_inserted_with_IsEnabled_false()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
using var scope = factory.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
|
||||
await new PackImporter().ImportAsync(db, SeedDir);
|
||||
|
||||
// 95001 is stub-only -> inserted with IsEnabled=false and the stub's gacha_detail.
|
||||
var stub = await db.Packs.FirstAsync(p => p.Id == 95001);
|
||||
Assert.That(stub.IsEnabled, Is.False);
|
||||
Assert.That(stub.GachaDetail, Is.EqualTo("7th Anniv stub"));
|
||||
}
|
||||
}
|
||||
@@ -41,6 +41,33 @@ public class PackRepositoryTests
|
||||
Assert.That(packs.Select(p => p.Id), Is.EquivalentTo(new[] { 10001 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetActivePacks_excludes_IsEnabled_false_rows()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
var now = new DateTime(2026, 5, 24, 12, 0, 0, DateTimeKind.Utc);
|
||||
await SeedPack(factory, 10001, 10001, PackCategory.None, now.AddDays(-1), now.AddDays(1));
|
||||
|
||||
using (var scope = factory.Services.CreateScope())
|
||||
{
|
||||
var db = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
db.Packs.Add(new PackConfigEntry
|
||||
{
|
||||
Id = 10002, BasePackId = 10002, PackCategory = PackCategory.None,
|
||||
CommenceDate = now.AddDays(-1), CompleteDate = now.AddDays(1),
|
||||
GachaType = 1, GachaDetail = "disabled",
|
||||
IsEnabled = false,
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
using var scopeRepo = factory.Services.CreateScope();
|
||||
var repo = scopeRepo.ServiceProvider.GetRequiredService<IPackRepository>();
|
||||
var packs = await repo.GetActivePacks(now);
|
||||
|
||||
Assert.That(packs.Select(p => p.Id), Is.EquivalentTo(new[] { 10001 }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task GetPack_includes_child_gachas_and_banners()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user