Refuse to re-seed an Elimination Final that has been played
Some checks failed
🚀 Deploy / 🧪 Test (pull_request) Successful in 3m12s
🚀 Deploy / ʦ🔍 Typecheck & Lint (pull_request) Failing after 46s
🚀 Deploy / 🐳 Build (pull_request) Has been skipped
🚀 Deploy / 🚀 Deploy (pull_request) Has been skipped

Reconciling both slots on every Wildcard result means a late correction
could otherwise rewrite who contested a game that already has a recorded
winner. Raise instead — with a message callers do not swallow, so the admin
sees it and can clear and regenerate.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01VDbHrCce1UhahbkwKkc7hK
This commit is contained in:
Claude 2026-09-04 15:30:05 +00:00
parent 273735e572
commit a747d73a4c
No known key found for this signature in database
2 changed files with 17 additions and 0 deletions

View file

@ -215,6 +215,14 @@ describe("AFL Wildcard Round advancement", () => {
expect(row("ef2").participant2Id).toBe(seed(8));
});
it("refuses to re-seed an Elimination Final that has already been played", async () => {
await winWildcard("wc1", seed(7));
Object.assign(row("ef2"), { isComplete: true, winnerId: seed(6), loserId: seed(7) });
await expect(winWildcard("wc1", seed(10))).rejects.toThrow(/already has a recorded result/);
expect(row("ef2").participant2Id).toBe(seed(7));
});
it("leaves the bracket alone when the pairings are already right", async () => {
await winWildcard("wc1", seed(7));
await winWildcard("wc2", seed(8));

View file

@ -942,6 +942,15 @@ async function advanceAFLWinner(
if (occupant !== null && !wildcardParticipants.has(occupant)) {
throw new Error(`EF ${efMatch.matchNumber} participant2 already filled`);
}
// Re-seeding a game that has already been played would rewrite who contested a
// recorded result. Surface that (this message is not one callers swallow) rather
// than quietly corrupting the bracket.
if (occupant !== null && (efMatch.isComplete || efMatch.winnerId)) {
throw new Error(
`Elimination Finals match ${efMatch.matchNumber} already has a recorded result, ` +
`so its Wildcard qualifier cannot be re-seeded — clear and regenerate the bracket`
);
}
// A Wildcard team in the wrong slot is a placement this result supersedes: a
// corrected Wildcard winner, or one placed before the re-seeding rule existed.
if (occupant !== null) slotsToClear.push(efMatch.id);