refactor(inventory): consolidate IsCurrency, skip num=0 grants in history

- Drop IsWalletCurrency (duplicate of IsCurrency); use IsCurrency in WriteAcquireHistory.
- Add comment on first SaveChangesAsync in CommitAsync explaining the two-phase flush.
- Guard WriteAcquireHistory loop with grant.Num == 0 check so synthetic DebitItem post-state ops do not produce history rows.
- Add InventoryHistoryTests.Commit_writes_no_history_row_for_item_debit to lock in the fix.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-09 14:37:50 -04:00
parent bea5a1efd4
commit fb1e6829b7
2 changed files with 28 additions and 7 deletions

View File

@@ -195,6 +195,31 @@ public class InventoryHistoryTests
Assert.That(rows[1].Message, Is.EqualTo("Card cosmetic"));
}
[Test]
public async Task Commit_writes_no_history_row_for_item_debit()
{
using var factory = new SVSim.UnitTests.Infrastructure.SVSimTestFactory();
long viewerId = await factory.SeedViewerAsync();
// Seed an item the viewer owns so DebitItem has something to spend.
const int itemId = 5550001;
await factory.SeedOwnedItemAsync(viewerId, itemId, 5);
using var scope = factory.Services.CreateScope();
var inv = scope.ServiceProvider.GetRequiredService<SVSim.Database.Services.Inventory.IInventoryService>();
await using (var tx = await inv.BeginAsync(viewerId, configure: c => c.Source = GrantSource.ItemPurchase))
{
await tx.TryDebitAsync(SVSim.Database.Enums.UserGoodsType.Item, itemId, 1);
await tx.CommitAsync();
}
using var verifyScope = factory.Services.CreateScope();
var ctx2 = verifyScope.ServiceProvider.GetRequiredService<SVSim.Database.SVSimDbContext>();
var rows = await ctx2.ViewerAcquireHistory.AsNoTracking()
.Where(h => h.ViewerId == viewerId).ToListAsync();
Assert.That(rows, Is.Empty, "item debit should not produce a history row");
}
[Test]
public async Task Commit_zero_pads_detail_id_for_wallet_currencies()
{