fix(tutorial): /tutorial/update preserves max TutorialState
The endpoint used to write the client-supplied step verbatim, so a stale or replayed request with tutorial_step=0 against any later-stage viewer would regress the persisted state to 0. NextSceneSwitcher routes step==0 to AreaSelect section 0, which has no chapter data — the client LINQ-Single() crashes on next /load/index, bricking the viewer. Math.Max-preserve matches the 31→41 pattern in GiftController.TutorialGiftReceive. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -77,4 +77,26 @@ public class TutorialControllerTests
|
||||
Assert.That(doc.RootElement.GetProperty("tutorial_step").GetInt32(), Is.EqualTo(100));
|
||||
Assert.That(await factory.GetViewerTutorialStateAsync(viewerId), Is.EqualTo(100));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public async Task Update_does_not_regress_step()
|
||||
{
|
||||
using var factory = new SVSimTestFactory();
|
||||
long viewerId = await factory.SeedViewerAsync(tutorialState: 100);
|
||||
using var client = factory.CreateAuthenticatedClient(viewerId);
|
||||
|
||||
// Stale/replayed request: client thinks state is still 11 and sends an update for it.
|
||||
var requestJson = """{"tutorial_step":11,"is_skip":0,"viewer_id":"0","steam_id":0,"steam_session_ticket":""}""";
|
||||
var response = await client.PostAsync("/tutorial/update",
|
||||
new StringContent(requestJson, Encoding.UTF8, "application/json"));
|
||||
|
||||
Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
|
||||
using var doc = JsonDocument.Parse(await response.Content.ReadAsStringAsync());
|
||||
Assert.That(doc.RootElement.GetProperty("tutorial_step").GetInt32(), Is.EqualTo(11),
|
||||
"Response echoes the requested step (the client confirms its own transition).");
|
||||
|
||||
Assert.That(await factory.GetViewerTutorialStateAsync(viewerId), Is.EqualTo(100),
|
||||
"Persisted state must NOT regress. Math.Max(current, requested) — mirrors the " +
|
||||
"31→41 max-preserve pattern in GiftController.TutorialGiftReceive.");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user