fix(guild): final-review remediation — replay_detail flat, FK on leader, transaction wraps, _db extraction

C1: replay_detail — flatten stored payload to data level. ChatReplayDetailTask.Parse() calls
new ReplayDetailInfo(data) which unguardedly accesses data[battleId], data[seed], data[vid1],
etc. Wrapping under replay_info key crashes the client. Controller now returns Ok(JsonElement)
directly so stored battle fields are at data root. Wire-shape test added.

C2: Guild.LeaderViewerId long to long?; add HasOne<Viewer> FK with OnDelete=SetNull; migration
AddGuildLeaderViewerIdFk; all consumers null-guarded with ?? 0L.

C3: BreakupAsync — wrap 6 destructive ops in IDbContextTransaction with InMemory fallback.

C4: CommitJoinAsync — wrap member-add + viewer-guildId-set + invite/request cleanup in
IDbContextTransaction with InMemory fallback. Chat event emitted after commit.

I1: GuildController — remove SVSimDbContext field; inject IViewerRepository + IGuildMemberRepository.
Add IGuildMemberRepository.GetViewerIdsInAGuildAsync (batch guild-membership check).
All _db.Viewers / _db.GuildMembers queries replaced with repo calls.

I2: GuildService — extract 3 _db.Viewers queries: GetEquippedEmblemIdAsync (CreateAsync),
LoadGuildProfileBatchAsync (ListOutgoingInvitesAsync + ListPendingJoinRequestsForMyGuildAsync).
Add GuildMemberProfile record with IsOfficialMarkDisplayed. GetEmblemListAsync for EmblemList.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gamer147
2026-06-27 16:33:59 -04:00
parent 754b2ca466
commit ff77d5e5b6
14 changed files with 5378 additions and 136 deletions

View File

@@ -211,6 +211,40 @@ public class GuildWireShape
"root must not be an object — no 'friends' wrapper allowed");
}
[Test]
public void ReplayDetail_response_passes_payload_fields_flat_not_wrapped()
{
// ChatReplayDetailTask.Parse() calls new ReplayDetailInfo(base.ResponseData["data"]).
// ReplayDetailInfo constructor accesses data["battleId"].ToLong(), data["seed"].ToInt(), etc.
// WITHOUT Keys.Contains guards. Wrapping under a "replay_info" key would crash the client.
// The controller emits the stored JSON element directly as the data payload — verify that
// the serialized shape does NOT have a wrapper key.
//
// Decompile evidence (ReplayDetailInfo.cs line 209-210):
// battle_id = data["battleId"].ToLong(); // unguarded
// seed = data["seed"].ToInt(); // unguarded
// Therefore: option (b) gate-off when payload is null; flat pass-through when it exists.
// Simulate what the controller does: serialize the payload element directly.
const string storedPayloadJson = """{"battleId":"999","seed":42,"fieldId":1,"firstTurn":1,"card_master_id":100,"vid1":1,"name1":"A","charaId1":1,"classId1":1,"emblemId1":100000000,"degreeId1":0,"countryCode1":"JP","sleeveId1":3000011,"battlePoint1":0,"masterPoint1":0,"rank1":1,"isOfficial1":false,"deck1":[],"vid2":2,"name2":"B","charaId2":1,"classId2":2,"emblemId2":100000000,"degreeId2":0,"countryCode2":"JP","sleeveId2":3000011,"battlePoint2":0,"masterPoint2":0,"rank2":1,"isOfficial2":false,"deck2":[]}""";
using var doc = JsonDocument.Parse(storedPayloadJson);
var element = doc.RootElement.Clone();
// Re-serialize as if returned from Ok(element) — should be flat
var json = JsonSerializer.Serialize(element, Opts);
using var resultDoc = JsonDocument.Parse(json);
var root = resultDoc.RootElement;
// battleId must be at root level, NOT under a "replay_info" wrapper
Assert.That(root.TryGetProperty("battleId", out var battleId), Is.True,
"battleId must be at root level — no replay_info wrapper");
Assert.That(battleId.GetString(), Is.EqualTo("999"));
// replay_info key must NOT exist
Assert.That(root.TryGetProperty("replay_info", out _), Is.False,
"replay_info wrapper must NOT be present — client reads data[\"battleId\"] directly");
}
[Test]
public void GuildInfo_non_joined_serializes_to_prod_shape()
{