Written by an AI agent working in this repository.
This morning the league schedule generator gained a "Who's playing" section (PR #17272): each player marks In, Maybe or Out for their team's next games, and the organiser sees which teams are short before the night. A red-team run picked that new file, availability.mjs, as its target a few hours later.
What the seeded faults showed
The run seeded 8 small faults into the file, one at a time, and ran the venture's whole test suite (about 230 s) after each one. The suite caught 5 of the 8. The 3 it missed sat in one place: the player page when the organiser has not set a minimum number of players. Nothing tested that case. A change that printed "enough" beside every team, or set the default minimum to 1, would have passed CI. One new test now renders the page with no minimum, a blank one, a non-number and null, and checks that the counts stay plain.
The real bug
Answers are stored in a plain JavaScript object keyed by fixture id and then by team name, and the organiser types the team names. In JavaScript a plain object {} already "has" keys like constructor, toString and __proto__, inherited from Object.prototype. So for a team named constructor:
- a player answering for that team got an error (
list.findIndex is not a function), and - as soon as anyone answered for that game, including the other team, the public league page and the organiser's page both threw while rendering.
A league with a team called "Constructors" would have been fine, because the keys are case-sensitive and must match exactly. A team called constructor or toString is unlikely. But team names are typed by strangers, and a page that falls over on one exact word is a page that falls over.
The fix reads only the object's own keys (Object.hasOwn) and writes new ones with Object.defineProperty, so even __proto__ becomes an ordinary key. The saved state file format did not change: JSON.stringify writes such a key and JSON.parse reads it back as an ordinary one, and a test now checks that round trip.
While this run was going, another session added rosters, team contacts, a CSV export and email reminders to the same file, and they looked names up the same way. The new test caught it in CI the first time the branch was tested against the updated main: an inherited constructor reached notAnswered, which tried to call .map on a function. Every lookup by a typed name in the file now goes through the same three own-key helpers.
The same bug, quieter, next door
The multi-division side of the generator shares duties (snack stand, scoreboard) among the teams playing each night. It counted each team's duties in a {} keyed by the duty's typed name. For a duty named constructor or toString, the count started from the inherited function, and adding 1 to a function in JavaScript gives a string, so the count became function Object() { [native code] }1. Nothing crashed, and the schedule's own validator still passed. The "fewest of this duty" fairness rule had just stopped working for that duty. It now counts in an object with no prototype (Object.create(null)).
Numbers
- Seeded faults caught by the existing tests: 5 of 8 (62.5%). After the new test,
redteam.py rerunre-applies each missed fault to check that the test catches it: all 3 are now caught (8 of 8). - Real defects found: 2, both patched with a test written to fail first.
The lesson is an old one: if a name a user types becomes an object key, use a Map, an object with no prototype, or own-key checks. The run record is in prompts/runs/2026-11-18-session_01E5sJKkQCuVbWMx1bnd43Vu.json.