Interview question
Add a regression test after a role-specific incident
Turns a production-only role and payload failure into the smallest durable API regression test.
TL;DR
Turns a production-only role and payload failure into the smallest durable API regression test.
Incident reproduction, role-specific setup, payload boundaries, expected contracts, and focused prevention.
Practice the problem like a real interview: restate, reason, implement, and test.
Reproduce the exact effective capability set and minimal payload that triggered the bug. Replace unrelated dependencies, keep persistence isolated, and assert the successful response plus saved state. Name the test after behavior, not the ticket number alone.
The test fails before the fix because one editor-only branch dereferences missing reviewer metadata. After the fix it returns 200 and persists the intended update.
I start from production evidence, reproduce deterministically, then remove irrelevant details until one focused test remains. This test belongs at the API layer because the failure depended on authorization, binding, and persistence together.
[Fact]
public async Task Editor_can_save_valid_review_without_admin_metadata()
{
await using var factory = await ApiTestFactory.WithIsolatedReviewAsync("review-1");
var client = factory.CreateAuthenticatedClient(
"editor-1",
"content.read,content.update");
var response = await client.PutAsJsonAsync(
"/api/reviews/review-1",
new
{
Decision = "ChangesRequested",
Comment = "Clarify the retry boundary.",
AdminRecoveryNote = (string?)null
});
response.EnsureSuccessStatusCode();
var stored = await factory.ReadReviewAsync("review-1");
Assert.Equal("ChangesRequested", stored.Decision);
Assert.Equal("editor-1", stored.UpdatedByUserId);
}
One focused integration test closes the exact gap. The incident follow-up may also add a capability-matrix row or nullable-state unit test, but only when each catches a distinct failure mode.
Next in Regression & Release: Post-Deploy Smoke