forge
Explore
Log in

Don't you dare go Hollow

🧭 name the ceiling a class refusal actually hit

Browse files at this commit

82c0ee20a8f6ef7d9d6f0158c312faa990d11a8fAhmet Kaan GümüşParent: 574b977
  • fix
    • 🧭 name the ceiling a class refusal actually hit
Show full message
fix: 🧭 name the ceiling a class refusal actually hit

The refusal codes shipped one commit ago read the same on both axes,
but two of them mean opposite things depending on which side is being
attached: a class at its ceiling is out of course places when a course
arrives and out of seats when a student does. So adding a student to a
full section answered class_at_course_ceiling next to a sentence about
students, and a section carrying too many courses answered
class_roster_too_large. The two tests covering it pinned the wrong
answer, one of them while asserting the prose was right.

The ceiling codes now live on the axis, so each names what it hit, and
the member route gains the two it needed.

Its documentation was wrong in the other direction too: it derived the
manual code set from the pump's, which quietly promised codes only a
pump can answer — a deleted class or course is a 404 there, never a
409. Each route now states its own set, and the spec guard compares
those sets rather than searching the whole document for the strings,
which is why it never caught any of this.
README.mdmodified+28 -11
@@ -2984,18 +2984,35 @@ the run**: it says nothing about the (section, course) pair it names, so every
29842984 remaining section would only repeat it. It is reported once, the sections
29852985 already stocked stay stocked, and the call still succeeds.
29862986
2987-**The manual attaches answer the same vocabulary.** A `409` from
2988-`POST /classes/{id}/members` or `POST /classes/{id}/courses` is
2987+**The manual attaches answer the same vocabulary**, each route with its own
2988+set. A `409` from either is
29892989 `{"error": "<sentence>", "code": "<machine code>"}` — the prose unchanged, the
2990-code out of the set above plus two a pump never reports: `duplicate` (already a
2991-member / already attached) and `linked_course_missing` (another course already
2992-attached to that section no longer exists — detach it first), which only
2993-`POST /classes/{id}/members` can meet, since a member add is the one attach
2994-that walks the section's existing course links while a pump attaches a course
2995-it has just proved alive. One cause therefore reads the same whether a manager
2996-hit it by hand or a pump hit it in bulk, which is what lets a bilingual client
2997-branch and word it once. `code` is published on those two routes only and is simply **absent**
2998-from every other error body.
2990+code out of:
2991+
2992+| route | codes |
2993+| --- | --- |
2994+| `POST /classes/{id}/courses` | `duplicate`, `class_at_course_ceiling`, `class_roster_too_large`, `course_full` |
2995+| `POST /classes/{id}/members` | `duplicate`, `class_at_roster_ceiling`, `class_course_list_too_large`, `course_full`, `linked_course_missing` |
2996+
2997+The three *deleted* codes are a pump's alone: on a manual attach a deleted class
2998+or course is a `404`, and `blueprint_deleted` needs a blueprint nobody handed
2999+it. `duplicate` (already a member / already attached) is a refusal on either
3000+route and no skip for a pump, which asked for a row that is already in place,
3001+and `linked_course_missing` (another course already attached to that section no
3002+longer exists — detach it first) only `POST /classes/{id}/members` can meet,
3003+since a member add is the one attach that walks the section's existing course
3004+links while a pump attaches a course it has just proved alive.
3005+
3006+The **ceiling** pair differs by route because the ceiling does: a member add is
3007+refused by a full roster (`class_at_roster_ceiling`, the section already holds
3008+`max_class_members`) or by a course list longer than one add may enroll at once
3009+(`class_course_list_too_large`); a course attach by the mirror of both
3010+(`class_at_course_ceiling`, `class_roster_too_large`) — which is also why the
3011+pump, which only ever attaches courses, reports that second pair. One cause
3012+therefore reads the same whether a manager hit it by hand or a pump hit it in
3013+bulk, which is what lets a bilingual client branch and word it once. `code` is
3014+published on those two routes only and is simply **absent** from every other
3015+error body.
29993016
30003017 **Removal spares what a human placed.** Every attachment a blueprint makes is
30013018 tagged with it. Dropping a course from the list detaches it only where the
src/domain/class_blueprint.rsmodified+47 -3
@@ -167,10 +167,14 @@ struct Held {
167167 /// blueprint asks for, so re-running a pump must report nothing — while a *hand*
168168 /// attach's duplicate is a genuine refusal (`duplicate`), because that call
169169 /// asked for the row and did not get it.
170+///
171+/// Always the course axis: a pump attaches courses to sections, so the two
172+/// ceiling codes are read on that side ([`Attached::refusal_code`] takes the
173+/// axis because they differ per axis).
170174 fn skip_reason(landed: &Attached<ClassCourse>) -> Option<&'static str> {
171175 match landed {
172176 Attached::Duplicate => None,
173- other => other.refusal_code(),
177+ other => other.refusal_code(&Axis::Course),
174178 }
175179 }
176180
@@ -1100,7 +1104,7 @@ mod tests {
11001104 // row — the arm itself is the only thing to check for it.
11011105 assert!(skip_reason(&Attached::Duplicate).is_none());
11021106 assert_eq!(
1103- Attached::<ClassCourse>::Duplicate.refusal_code(),
1107+ Attached::<ClassCourse>::Duplicate.refusal_code(&Axis::Course),
11041108 Some("duplicate"),
11051109 "a hand attach's duplicate is a refusal even though a pump's is not"
11061110 );
@@ -1122,10 +1126,50 @@ mod tests {
11221126 "{refusal:?} must be reported as its own code, not swallowed or reworded"
11231127 );
11241128 assert_eq!(
1125- refusal.refusal_code(),
1129+ refusal.refusal_code(&Axis::Course),
11261130 skip_reason(&refusal),
11271131 "{refusal:?} must read the same on a manual 409 as in a pump's skip list"
11281132 );
11291133 }
11301134 }
1135+
1136+ /// The two ceiling refusals mean the *opposite* ceiling on the two axes —
1137+ /// `ClassFull` is the axis being attached, `ClassOverloaded` the other one —
1138+ /// so the member add's pair must be the member add's own, and a code that
1139+ /// reads the same on both axes is the bug this pins: the roster being full
1140+ /// was published as `class_at_course_ceiling`.
1141+ #[test]
1142+ fn each_axis_names_the_ceiling_it_actually_hit() {
1143+ for (refusal, course_axis, member_axis) in [
1144+ (
1145+ Attached::<ClassCourse>::ClassFull,
1146+ "class_at_course_ceiling",
1147+ "class_at_roster_ceiling",
1148+ ),
1149+ (
1150+ Attached::ClassOverloaded,
1151+ "class_roster_too_large",
1152+ "class_course_list_too_large",
1153+ ),
1154+ ] {
1155+ assert_eq!(refusal.refusal_code(&Axis::Course), Some(course_axis));
1156+ assert_eq!(refusal.refusal_code(&Axis::Member), Some(member_axis));
1157+ }
1158+ // Every other code is axis-free, and must stay that way: they name a
1159+ // record, not a ceiling.
1160+ for refusal in [
1161+ Attached::<ClassCourse>::Duplicate,
1162+ Attached::Gone,
1163+ Attached::PivotGone,
1164+ Attached::Full("course:algebra".into()),
1165+ Attached::CourseGone("course:algebra".into()),
1166+ Attached::SourceGone,
1167+ ] {
1168+ assert_eq!(
1169+ refusal.refusal_code(&Axis::Course),
1170+ refusal.refusal_code(&Axis::Member),
1171+ "{refusal:?} names a record, so it must read the same on both axes"
1172+ );
1173+ }
1174+ }
11311175 }
src/domain/class_course.rsmodified+9 -3
@@ -97,7 +97,7 @@ impl ClassCourse {
9797 // Read off the refusal, never respelled here: this route and a
9898 // blueprint pump answer one vocabulary. `Made` is the only `None`, and
9999 // it takes the `Ok` arm below.
100- let code = landed.refusal_code().unwrap_or_default();
100+ let code = landed.refusal_code(&Axis::Course).unwrap_or_default();
101101 match landed {
102102 Attached::Made(saved) => Ok(saved),
103103 Attached::Duplicate => Err(AppError::ConflictCoded {
@@ -126,8 +126,14 @@ impl ClassCourse {
126126 code,
127127 message: format!("{full} cannot hold the whole class"),
128128 }),
129- // Another of the class's links points at a deleted course. This
130- // axis claims its own pivot, so it is never *this* course.
129+ // Unreachable on this axis, and kept because the match is
130+ // exhaustive: the pair loop enrolls the roster into `$pivot` and
131+ // nothing else, and the pivot claim already proved *that* course
132+ // alive inside the same transaction. Only a member add walks a
133+ // class's existing course links, so `linked_course_missing` is that
134+ // route's alone — which is why this route's `409` does not publish
135+ // it. Left mapped rather than folded into an `Internal`, so a future
136+ // axis change is a wrong-looking 409, not a 500.
131137 Attached::CourseGone(course) => Err(AppError::ConflictCoded {
132138 code,
133139 message: format!("{course} no longer exists — detach it from this class first"),
src/domain/class_member.rsmodified+1 -1
@@ -102,7 +102,7 @@ impl ClassMember {
102102 // Read off the refusal, never respelled here: this route and a
103103 // blueprint pump answer one vocabulary. `Made` is the only `None`, and
104104 // it takes the `Ok` arm below.
105- let code = landed.refusal_code().unwrap_or_default();
105+ let code = landed.refusal_code(&Axis::Member).unwrap_or_default();
106106 match landed {
107107 Attached::Made(saved) => Ok(saved),
108108 Attached::Duplicate => Err(AppError::ConflictCoded {
src/domain/class_pump.rsmodified+32 -3
@@ -149,14 +149,21 @@ impl<T> Attached<T> {
149149 /// detached before this attach can be retried. `blueprint_deleted` is a
150150 /// pump losing the template itself mid-run — the only refusal that says
151151 /// nothing about the (class, course) pair it names.
152- pub(crate) fn refusal_code(&self) -> Option<&'static str> {
152+ ///
153+ /// The `axis` is a parameter because two of these answers name a *different
154+ /// ceiling* on each of them: [`Attached::ClassFull`] is the ceiling of the
155+ /// axis being attached and [`Attached::ClassOverloaded`] the other axis's,
156+ /// so a member add's "full" is a full roster where a course attach's is a
157+ /// full course list ([`Axis::at_ceiling_code`]). Read blind, the same code
158+ /// worded a full roster as a full course list.
159+ pub(crate) fn refusal_code(&self, axis: &Axis) -> Option<&'static str> {
153160 match self {
154161 Attached::Made(_) => None,
155162 Attached::Duplicate => Some("duplicate"),
156163 Attached::Gone => Some("class_deleted"),
157164 Attached::PivotGone => Some("course_deleted"),
158- Attached::ClassFull => Some("class_at_course_ceiling"),
159- Attached::ClassOverloaded => Some("class_roster_too_large"),
165+ Attached::ClassFull => Some(axis.at_ceiling_code()),
166+ Attached::ClassOverloaded => Some(axis.other().over_ceiling_code()),
160167 Attached::Full(_) => Some("course_full"),
161168 Attached::CourseGone(_) => Some("linked_course_missing"),
162169 Attached::SourceGone => Some("blueprint_deleted"),
@@ -272,6 +279,28 @@ impl Axis {
272279 }
273280 }
274281
282+ /// The refusal code for "the class is *at* this axis's ceiling"
283+ /// ([`Attached::ClassFull`]), taken off the axis beside the `cap` it
284+ /// reports, because that ceiling and its name are one fact.
285+ fn at_ceiling_code(&self) -> &'static str {
286+ match self {
287+ Axis::Member => "class_at_roster_ceiling",
288+ Axis::Course => "class_at_course_ceiling",
289+ }
290+ }
291+
292+ /// The refusal code for "the class stands *above* this axis's ceiling", so
293+ /// the other axis's attach would run a write loop longer than a transaction
294+ /// may be ([`Attached::ClassOverloaded`]). Answered off the axis that is
295+ /// over, never the one being attached — the two are always different axes,
296+ /// which is exactly what the blind version got wrong.
297+ fn over_ceiling_code(&self) -> &'static str {
298+ match self {
299+ Axis::Member => "class_roster_too_large",
300+ Axis::Course => "class_course_list_too_large",
301+ }
302+ }
303+
275304 /// The axis whose link rows this one's write loop iterates — its counter is
276305 /// the length of that loop, and its ceiling is therefore the second half of
277306 /// the bound.
src/lib.rsmodified+1 -1
@@ -50,7 +50,7 @@ use crate::state::AppState;
5050 (name = "appointments", description = "Teacher availability slots and the meetings booked on them. A teacher+ publishes windows (`POST /appointments/slots`), optionally repeating weekly up to an `until` date (at most 52 occurrences, all sharing a `series` id that deletes as one). A published window may not overlap another of the *same teacher's* (`409`): the check is half-open, so 10:00–10:30 and 10:30–11:00 are two slots and not a collision, and a weekly publish is all-or-nothing — one colliding occurrence refuses the whole series. Students and parents book one with a required reason — a parent books for themselves, this is the parent-teacher conference — and the request lands `pending`: publishing availability is not consent to a person and a topic. The teacher approves, rejects, or counter-proposes another time; a counter-proposal sends the booking back to `pending` and clears `decided_by`, and the requester either accepts it (approval at the new time) or declines, which cancels the booking. A window that has already opened is closed on every side (409): such a slot cannot be booked, an underway time cannot be approved, accepted, or counter-proposed, and the requester may cancel — declining included, since a decline *is* a cancel — only until the meeting's effective window starts. Cancelling is the **requester's** route alone (`403` for anyone else, the slot's teacher and a manager/admin included, since the guard compares ids and not roles): a teacher ends a booking by rejecting it while it is `pending`, and an approved one by counter-proposing another time (back to `pending`) and then rejecting it, or simply by rescheduling. Both the reject and the cancel take an optional `reason`, and the row records who settled it (`decided_by`, `cancelled_by`) with that text (`reject_reason`, `cancel_reason`) — visible only to the requester and the slot's teacher, since that is who a booking is ever rendered to. One live booking holds a slot (rejecting or cancelling frees it), no approved meeting may overlap another for the teacher *or* the requester (409), and a slot with a live booking refuses deletion (409). A teacher demoted after publishing leaves inert slots: they drop out of the bookable list and booking one is refused"),
5151 (name = "events", description = "Calendar events and attendance. An event's `audience` is its expected-attendee roster, not a visibility wall: everyone sees every event. Aim it at the whole school, one role, a course's enrollment, a class section's (ÅŸube) roster, or a hand-built registration list. Rosters resolve live, so role changes, (un)enrollments and class-roster changes move people in and out by themselves. Attendance: teacher+ marks people in the audience (students never mark, not even themselves), and the roster report joins the expected list with the marks to show who missed. Registration lists are filled seat by seat (teachers place students, staff place only themselves), optionally capped by `capacity`, and close once the event starts. `GET /events` takes an optional `?starts_after=&ends_after=` schedule window (unix-millis) that keeps only upcoming/unfinished events and lists them soonest-first; without it the list stays newest-first"),
5252 (name = "courses", description = "Courses — kind `course` (a regular taught course), `study` (etüt, a supervised study session), or `club` (kulüp, a student club; same behavior, different label) — optional enroll-time seat `capacity`, enrollment (students only), course exams, and course sessions. A course is run by its creator plus any teachers a manager assigned to it (`POST /courses/{id}/teachers`): assigned teachers manage everything inside the course but cannot delete it or change the assignment list. Both rights are re-checked against the caller's live role on every request: `creator` is a historical column no demotion sweeps, so an account that falls below `teacher` keeps neither management nor deletion of a course it made (the course stays reachable to its assigned teachers and to manager+), and the course drops out of their `/courses`, `/exams` and `/homework` catalogs unless they are enrolled in it. A session's `teacher` column carries the same floor: teaching a session grants neither its roll call nor a view of it once the account falls below `teacher`. A roster is also filled in bulk by attaching the course to a class (see `classes`), which writes the same ordinary enrollment rows one at a time. A course with anyone still enrolled refuses deletion (409) — empty the roster first"),
53- (name = "classes", description = "Class sections (şube): a named set of students the school moves as one. A class is bulk enrollment, not a second kind of membership — adding a student enrolls them into every course the class carries, attaching a course enrolls the whole roster into it, and the rows written are ordinary enrollments, each tagged with the class that pumped it (a row with no such tag was placed individually). A course with too few seats takes none of the class — the whole call is a 409 naming the course that ran out, and not one of the seats claimed earlier in the same run is kept — and a student already enrolled by hand keeps their own row (never adopted, never swept). Removing a member or detaching a course takes back only the rows that class pumped, and even then repairs before it deletes: a row a *second* class still claims (it holds the same student and the same course) is re-tagged to that class instead of being dropped, so nobody loses a seat someone is still responsible for. Unenrolling a pumped student by hand is allowed and permanent — the class does not put them back; staff re-enroll them or detach and re-attach the course. A class may link an academic term (which then refuses deletion while it does), and a class still holding students or courses refuses deletion itself (409). A class may also name a homeroom teacher (sınıf öğretmeni) with `teacher_id` — any teacher+ account, a pure label that grants nothing, cleared on every class it held the moment that account is demoted below `teacher`. The class itself and its roster are manager+, every read is teacher+, and attaching or detaching a course takes management rights on *that course*, since it writes that course's roster. Two reads sit outside that bar so a student can learn their own section: `GET /classes/me` (any authenticated role — staff, never members, get an empty page) and `GET /classes/user/{user}` (teacher+, or a parent linked to that student); both hide the class's `creator` (always a manager or admin) from a caller below teacher+, since the office's account names are otherwise unreachable at that level. Naming a homeroom teacher who is demoted while the request runs is a `409`: the assignment is taken back, and a create is rolled back whole. A grade may also carry a **blueprint** (`/classes/blueprints`): the list of courses every section at that grade takes. It reaches sections in both directions — creating or editing one retro-pumps every class already at the grade, and a class created afterwards at a blueprinted grade is stocked from it by `POST /classes` itself, whose `201` therefore answers `{class, skipped, stocked_from}` (`stocked_from` is the grade label of the template that stocked it, `null` when none covers the grade, which is what tells that apart from a template that applied cleanly; a stocking that could not be carried out reads `null` too, and the retry for both is the idempotent `POST /classes/{id}/blueprint`). Pumping is best-effort — a section that cannot take a course (it is at its course ceiling, or the course has no free seat for the whole section) is skipped and returned in `skipped`, while every other section is still stocked, so a blueprint edit can leave a deliberately partial state. The same body carries `matched`, the number of sections the pump actually reached: a grade label is free text matched exactly, so `\"9 \"` and `\"9-A\"` are not `\"9\"`, and `matched: 0` with an empty `skipped` is a saved template that stocked nothing rather than one that stocked everything. `GET /classes?grade=<label>` is the read that goes with it: the sections carrying that exact label (matched verbatim, since normalizing it would disagree with the pump this exists to debug), `?grade=` on its own the sections carrying no grade at all, an unknown label an empty page rather than a `404`, and a `total` counting the filtered set so `?limit=&offset=` pages through it. `GET /classes/blueprints/{grade}/status` closes the loop: a read-only `{grade, courses, matched, sections[{class, class_name, missing}]}` naming, for every section carrying the label, the template courses it does not carry — unpaged, since the set is the şube one school runs at one grade — because a pump's `skipped` list otherwise lives only in the one response that reported it. A course a human attached **by hand** counts as carried, exactly as it does for the pump, and a course in the template that no longer exists reads as missing everywhere until the next pump drops the dangling id. Both fixes it points at are idempotent: `POST /classes/{id}/blueprint` re-stocks one section, and `PATCH`ing a blueprint with the list it already holds re-runs the whole grade's pump (the compare-and-set matches the unchanged list, nothing is dropped, everything is re-attached). A class whose `grade` is edited **after** it was stocked keeps the courses the *old* grade's blueprint attached — they still carry that blueprint's tag, so dropping one from that template still detaches them — and takes nothing from the new grade's template until one of those two calls runs; that is deliberate, since reconciling on a label `PATCH` would delete live enrollments as a side effect of a rename, and this status read is what makes the drift visible instead of silent. Each skip's `reason` is a machine code out of a closed set the client words itself (`class_deleted`, `course_deleted`, `class_at_course_ceiling`, `class_roster_too_large`, `course_full`, `blueprint_deleted`), like every other enum here. The **manual** attaches answer that same vocabulary: a `409` from `POST /classes/{id}/members` or `POST /classes/{id}/courses` carries a `code` beside its sentence, out of the same set plus two a pump never reports — `duplicate` (already attached / already a member — a refusal there, and no skip for a pump, which asked for a row that is already in place) and `linked_course_missing` (another course on that section no longer exists — detach it first), which only the member add can meet, since it is the one attach that walks the section's existing course links while a pump attaches a course it has just proved alive. No other route publishes a `code`, and the field is simply absent where it does not. Dropping a course from a blueprint detaches it wherever the blueprint attached it (and deleting the blueprint drops its whole list — the row goes first and the attachments are then swept by their tag, so a course another manager added and pumped while the delete ran is swept too, and a pump that loses its blueprint mid-run attaches nothing and reports `blueprint_deleted`; deleting a blueprint whose list moved since the caller read it is a `409`), but a course a human attached to a class by hand carries no blueprint tag and always survives — the same absent-key rule that protects an individually placed enrollment. A blueprint names no term; the class names its own. The grade label is the blueprint's id, so there is exactly one per grade, and it must be non-empty and free of `/ \\ ? # %`"),
53+ (name = "classes", description = "Class sections (şube): a named set of students the school moves as one. A class is bulk enrollment, not a second kind of membership — adding a student enrolls them into every course the class carries, attaching a course enrolls the whole roster into it, and the rows written are ordinary enrollments, each tagged with the class that pumped it (a row with no such tag was placed individually). A course with too few seats takes none of the class — the whole call is a 409 naming the course that ran out, and not one of the seats claimed earlier in the same run is kept — and a student already enrolled by hand keeps their own row (never adopted, never swept). Removing a member or detaching a course takes back only the rows that class pumped, and even then repairs before it deletes: a row a *second* class still claims (it holds the same student and the same course) is re-tagged to that class instead of being dropped, so nobody loses a seat someone is still responsible for. Unenrolling a pumped student by hand is allowed and permanent — the class does not put them back; staff re-enroll them or detach and re-attach the course. A class may link an academic term (which then refuses deletion while it does), and a class still holding students or courses refuses deletion itself (409). A class may also name a homeroom teacher (sınıf öğretmeni) with `teacher_id` — any teacher+ account, a pure label that grants nothing, cleared on every class it held the moment that account is demoted below `teacher`. The class itself and its roster are manager+, every read is teacher+, and attaching or detaching a course takes management rights on *that course*, since it writes that course's roster. Two reads sit outside that bar so a student can learn their own section: `GET /classes/me` (any authenticated role — staff, never members, get an empty page) and `GET /classes/user/{user}` (teacher+, or a parent linked to that student); both hide the class's `creator` (always a manager or admin) from a caller below teacher+, since the office's account names are otherwise unreachable at that level. Naming a homeroom teacher who is demoted while the request runs is a `409`: the assignment is taken back, and a create is rolled back whole. A grade may also carry a **blueprint** (`/classes/blueprints`): the list of courses every section at that grade takes. It reaches sections in both directions — creating or editing one retro-pumps every class already at the grade, and a class created afterwards at a blueprinted grade is stocked from it by `POST /classes` itself, whose `201` therefore answers `{class, skipped, stocked_from}` (`stocked_from` is the grade label of the template that stocked it, `null` when none covers the grade, which is what tells that apart from a template that applied cleanly; a stocking that could not be carried out reads `null` too, and the retry for both is the idempotent `POST /classes/{id}/blueprint`). Pumping is best-effort — a section that cannot take a course (it is at its course ceiling, or the course has no free seat for the whole section) is skipped and returned in `skipped`, while every other section is still stocked, so a blueprint edit can leave a deliberately partial state. The same body carries `matched`, the number of sections the pump actually reached: a grade label is free text matched exactly, so `\"9 \"` and `\"9-A\"` are not `\"9\"`, and `matched: 0` with an empty `skipped` is a saved template that stocked nothing rather than one that stocked everything. `GET /classes?grade=<label>` is the read that goes with it: the sections carrying that exact label (matched verbatim, since normalizing it would disagree with the pump this exists to debug), `?grade=` on its own the sections carrying no grade at all, an unknown label an empty page rather than a `404`, and a `total` counting the filtered set so `?limit=&offset=` pages through it. `GET /classes/blueprints/{grade}/status` closes the loop: a read-only `{grade, courses, matched, sections[{class, class_name, missing}]}` naming, for every section carrying the label, the template courses it does not carry — unpaged, since the set is the şube one school runs at one grade — because a pump's `skipped` list otherwise lives only in the one response that reported it. A course a human attached **by hand** counts as carried, exactly as it does for the pump, and a course in the template that no longer exists reads as missing everywhere until the next pump drops the dangling id. Both fixes it points at are idempotent: `POST /classes/{id}/blueprint` re-stocks one section, and `PATCH`ing a blueprint with the list it already holds re-runs the whole grade's pump (the compare-and-set matches the unchanged list, nothing is dropped, everything is re-attached). A class whose `grade` is edited **after** it was stocked keeps the courses the *old* grade's blueprint attached — they still carry that blueprint's tag, so dropping one from that template still detaches them — and takes nothing from the new grade's template until one of those two calls runs; that is deliberate, since reconciling on a label `PATCH` would delete live enrollments as a side effect of a rename, and this status read is what makes the drift visible instead of silent. Each skip's `reason` is a machine code out of a closed set the client words itself (`class_deleted`, `course_deleted`, `class_at_course_ceiling`, `class_roster_too_large`, `course_full`, `blueprint_deleted`), like every other enum here. The **manual** attaches answer that same vocabulary, each route with its own set: a `409` from `POST /classes/{id}/courses` carries `duplicate`, `class_at_course_ceiling`, `class_roster_too_large` or `course_full`, and one from `POST /classes/{id}/members` carries `duplicate`, `class_at_roster_ceiling`, `class_course_list_too_large`, `course_full` or `linked_course_missing`. The three *deleted* codes are a pump's alone — on a manual attach a deleted class or course is a `404`, never a `409` — and the ceiling pair differs by route because the ceilings do: a member add is refused by a full roster (`class_at_roster_ceiling`) or by a course list longer than one add may enroll at once (`class_course_list_too_large`), a course attach by the mirror of both. `duplicate` (already attached / already a member) is a refusal on either route, and no skip for a pump, which asked for a row that is already in place; `linked_course_missing` (another course on that section no longer exists — detach it first) only the member add can meet, since it is the one attach that walks the section's existing course links while a pump attaches a course it has just proved alive. No other route publishes a `code`, and the field is simply absent where it does not. Dropping a course from a blueprint detaches it wherever the blueprint attached it (and deleting the blueprint drops its whole list — the row goes first and the attachments are then swept by their tag, so a course another manager added and pumped while the delete ran is swept too, and a pump that loses its blueprint mid-run attaches nothing and reports `blueprint_deleted`; deleting a blueprint whose list moved since the caller read it is a `409`), but a course a human attached to a class by hand carries no blueprint tag and always survives — the same absent-key rule that protects an individually placed enrollment. A blueprint names no term; the class names its own. The grade label is the blueprint's id, so there is exactly one per grade, and it must be non-empty and free of `/ \\ ? # %`"),
5454 (name = "sessions", description = "Lesson sessions and their roll call (session teacher or course manager marks enrolled students; manager+ marks the teacher). Roll call is also what feeds two badge counters (see `users`): the first mark taken for a lesson credits its teacher's `lessons_held_total` once, and a student marked `present` or `late` gains a `lessons_attended_total` a later correction gives back"),
5555 (name = "work", description = "Staff work log: check-in/check-out stamped by the server clock, manager corrections"),
5656 (name = "pomodoro", description = "Student pomodoro focus log: start/finish stamped by the server clock (starting discards any dangling unfinished session, so a crashed timer never blocks the next one), own history with the unpaged `total_focus_ms` sum, and teacher+ (or linked-parent) reads of any student's log. Breaks and the work/break rhythm stay in the frontend — the backend records only focus stints"),
src/web/classes.rsmodified+14 -10
@@ -726,7 +726,7 @@ async fn delete_class(
726726 (status = 401, description = "Not authenticated", body = ErrorResponse),
727727 (status = 403, description = "Requires manager role or higher", body = ErrorResponse),
728728 (status = 404, description = "Class not found", body = ErrorResponse),
729- (status = 409, description = "Already in this class, the class is at its student ceiling (max_class_members), one of its courses is full, or one of them no longer exists (a stale attachment — detach it). The body carries a machine `code` beside the prose, out of the same closed set a blueprint pump reports: `duplicate`, `class_at_course_ceiling`, `class_roster_too_large`, `course_full`, `linked_course_missing`", body = ErrorResponse),
729+ (status = 409, description = "Already in this class, the class is at its student ceiling (max_class_members), it carries more courses than one add may enroll at once, one of its courses is full, or one of them no longer exists (a stale attachment — detach it). The body carries a machine `code` beside the prose, and this route answers exactly these: `duplicate`, `class_at_roster_ceiling`, `class_course_list_too_large`, `course_full`, `linked_course_missing`", body = ErrorResponse),
730730 (status = 422, description = "The body does not fit this request: a field has the wrong type, or a required field is missing"),
731731 ),
732732 )]
@@ -853,7 +853,7 @@ async fn remove_member(
853853 (status = 401, description = "Not authenticated", body = ErrorResponse),
854854 (status = 403, description = "Not the course creator or an assigned teacher (and not a manager/admin)", body = ErrorResponse),
855855 (status = 404, description = "Class not found", body = ErrorResponse),
856- (status = 409, description = "Already attached, the class is at its course ceiling (max_class_courses), or the course cannot hold the whole class. The body carries a machine `code` beside the prose, out of the same closed set a blueprint pump reports: `duplicate`, `class_at_course_ceiling`, `class_roster_too_large`, `course_full`", body = ErrorResponse),
856+ (status = 409, description = "Already attached, the class is at its course ceiling (max_class_courses), it holds more students than one attach may enroll at once, or the course cannot hold the whole class. The body carries a machine `code` beside the prose, and this route answers exactly these: `duplicate`, `class_at_course_ceiling`, `class_roster_too_large`, `course_full`", body = ErrorResponse),
857857 (status = 422, description = "The body does not fit this request: a field has the wrong type, or a required field is missing"),
858858 ),
859859 )]
@@ -1039,14 +1039,18 @@ struct SkipResponse {
10391039 /// ran; nothing was attached, and there is nothing left to retry — it ends
10401040 /// the run, so it appears once however many sections were left).
10411041 ///
1042- /// The **same vocabulary** answers the manual routes: a `409` from
1043- /// `POST /classes/{id}/members` or `POST /classes/{id}/courses` carries
1044- /// these codes as its `code` field, plus two a pump never reports —
1045- /// `duplicate`, a refusal there (the call asked for a row and did not get
1046- /// it) but not here (the course is already on the class, which is what the
1047- /// blueprint asks for), and `linked_course_missing` (another course
1048- /// already attached to that section no longer exists — detach it first),
1049- /// which only a member add can meet: it is the one attach that walks the
1042+ /// The **same vocabulary** answers the manual routes as their `code`
1043+ /// field. `POST /classes/{id}/courses` attaches along this very axis and so
1044+ /// answers this list's ceilings, plus `duplicate` — a refusal there (the
1045+ /// call asked for a row and did not get it) but not here (the course is
1046+ /// already on the class, which is what the blueprint asks for).
1047+ /// `POST /classes/{id}/members` attaches along the *other* axis, so its two
1048+ /// ceilings are the mirror ones, named for the ceiling actually hit:
1049+ /// `class_at_roster_ceiling` (the section already holds
1050+ /// `max_class_members`) and `class_course_list_too_large` (it carries more
1051+ /// courses than one member add may enroll at once). It also owns
1052+ /// `linked_course_missing` (another course already attached to that section
1053+ /// no longer exists — detach it first): it is the one attach that walks the
10501054 /// section's existing course links, while a pump attaches a course it has
10511055 /// just proved alive.
10521056 #[schema(example = "course_full")]
tests/regress_classes.rsmodified+6 -4
@@ -654,9 +654,10 @@ async fn a_class_refuses_the_member_past_its_ceiling() {
654654 let refused = ClassMember::add(&class, &UserId::from_key("over"), &manager, &db).await;
655655 assert!(
656656 matches!(refused, Err(AppError::ConflictCoded { code, ref message })
657- if code == "class_at_course_ceiling"
657+ if code == "class_at_roster_ceiling"
658658 && message.contains(&MAX_CLASS_MEMBERS.to_string())),
659- "a full class is a 409 naming its ceiling and coded, never a 404: {refused:?}"
659+ "a full class is a 409 naming its ceiling and coded, never a 404, and the code \
660+ must name the ceiling the prose does — the roster, not the course list: {refused:?}"
660661 );
661662 assert_eq!(
662663 counter("SELECT VALUE class_member_count ?? 0 FROM class_group", &db).await,
@@ -778,9 +779,10 @@ async fn a_class_over_the_course_ceiling_takes_no_member() {
778779 let refused = ClassMember::add(&class, &UserId::from_key("ali"), &manager, &db).await;
779780 assert!(
780781 matches!(refused, Err(AppError::ConflictCoded { code, ref message })
781- if code == "class_roster_too_large"
782+ if code == "class_course_list_too_large"
782783 && message.contains(&MAX_CLASS_COURSES.to_string())),
783- "the refusal must name the courses, not the roster: {refused:?}"
784+ "the refusal must name the courses, not the roster — in its code as well as \
785+ its prose: {refused:?}"
784786 );
785787 assert_eq!(rows("SELECT VALUE id FROM class_member", &db).await, 0);
786788 assert_eq!(
tests/spec_bounds.rsmodified+84 -11
@@ -1123,27 +1123,100 @@ async fn the_image_meta_bodies_stay_the_same_shape() {
11231123
11241124 /// The class refusal codes are a **published** vocabulary: a blueprint pump
11251125 /// reports them as a skip `reason`, and the two manual attach routes answer
1126-/// them as the `code` on their `409`. A client branches on them, so a code the
1127-/// spec never names is one nobody can build against — this asserts the emitted
1128-/// document still spells every one of them, wherever it does it.
1126+/// them as the `code` on their `409`. A client branches on them *per route*,
1127+/// and the two ceiling codes are not the same on the two attach axes — a full
1128+/// roster and a full course list are different refusals — so this asserts each
1129+/// route's `409` names **exactly** its own set, and that the whole vocabulary
1130+/// is accounted for on the `SkipResponse.reason` field that documents it.
1131+///
1132+/// Anywhere-in-the-document containment was the earlier shape and could not
1133+/// fail: `course_full` survived as a `#[schema(example)]` and `duplicate` in
1134+/// prose, so a code dropped from a `409` description, moved to the wrong route
1135+/// or added undocumented all passed.
11291136 #[tokio::test]
11301137 async fn the_class_refusal_codes_stay_published() {
11311138 let spec = spec().await;
1132- let text = spec.to_string();
1133- for code in [
1134- "duplicate",
1139+
1140+ // Every backticked snake_case word in a description, minus the terms that
1141+ // are not codes — so a code added to (or moved into) a description shows up
1142+ // here without the test being told about it.
1143+ let quoted = |text: &str| -> Vec<String> {
1144+ text.split('`')
1145+ .skip(1)
1146+ .step_by(2)
1147+ .filter(|word| {
1148+ word.chars().all(|c| c.is_ascii_lowercase() || c == '_')
1149+ && !matches!(*word, "code" | "max_class_members" | "max_class_courses")
1150+ })
1151+ .map(str::to_string)
1152+ .collect()
1153+ };
1154+ let sorted = |mut codes: Vec<String>| -> Vec<String> {
1155+ codes.sort();
1156+ codes.dedup();
1157+ codes
1158+ };
1159+ let want = |codes: &[&str]| sorted(codes.iter().map(|c| c.to_string()).collect());
1160+
1161+ // The pump's own half, on the field that carries it. `Attached::refusal_code`
1162+ // answers these on the course axis, which is the only axis a pump runs.
1163+ let pump = [
11351164 "class_deleted",
11361165 "course_deleted",
11371166 "class_at_course_ceiling",
11381167 "class_roster_too_large",
11391168 "course_full",
1140- "linked_course_missing",
11411169 "blueprint_deleted",
1170+ ];
1171+ // Per route, in the axis's own words: `class_at_*_ceiling` is the axis being
1172+ // attached, the `*_too_large` pair the other one.
1173+ let courses = [
1174+ "duplicate",
1175+ "class_at_course_ceiling",
1176+ "class_roster_too_large",
1177+ "course_full",
1178+ ];
1179+ let members = [
1180+ "duplicate",
1181+ "class_at_roster_ceiling",
1182+ "class_course_list_too_large",
1183+ "course_full",
1184+ "linked_course_missing",
1185+ ];
1186+
1187+ for (path, expected) in [
1188+ ("/classes/{id}/courses", courses.as_slice()),
1189+ ("/classes/{id}/members", members.as_slice()),
11421190 ] {
1143- assert!(
1144- text.contains(code),
1145- "the OpenAPI document no longer names the refusal code `{code}` — it is answered \
1146- by `Attached::refusal_code` and must stay documented on the class routes"
1191+ let description = spec["paths"][path]["post"]["responses"]["409"]["description"]
1192+ .as_str()
1193+ .unwrap_or_else(|| panic!("{path} must declare a 409 with a description"));
1194+ assert_eq!(
1195+ sorted(quoted(description)),
1196+ want(expected),
1197+ "the `409` on POST {path} must name exactly the refusal codes that route \
1198+ answers — a client branches on them, and one it never sees documented (or \
1199+ one it is promised and never gets) is a branch written against nothing"
11471200 );
11481201 }
1202+
1203+ // …and the closed set itself, on the one field that explains all of it: the
1204+ // union of both routes plus the pump, so a code documented on no surface at
1205+ // all still fails here.
1206+ let reason =
1207+ spec["components"]["schemas"]["SkipResponse"]["properties"]["reason"]["description"]
1208+ .as_str()
1209+ .expect("SkipResponse.reason must document the code vocabulary");
1210+ let everything: Vec<&str> = pump
1211+ .iter()
1212+ .chain(courses.iter())
1213+ .chain(members.iter())
1214+ .copied()
1215+ .collect();
1216+ assert_eq!(
1217+ sorted(quoted(reason)),
1218+ want(&everything),
1219+ "`SkipResponse.reason` is where the whole closed vocabulary is written down — \
1220+ every code either route or a pump can answer must appear there, and nothing else"
1221+ );
11491222 }