A field setter is not a rule
Cursor can easily write a PATCH route that sets a field. That is not the same as implementing a business rule. In Part 2.3 the backend must decide whether a requested status change is allowed, based on both the current status and the requested new one. The UI can hide invalid buttons, but a user can still call the API directly with curl, Postman or another client. The backend is the trusted enforcement point.
Key ideaUI buttons can hide invalid actions; only the backend can refuse them.
The transition rules
Three moves are allowed. Everything else, including staying on the same status, is rejected.
- ToDoCan only move to InProgress.
- InProgressCan move to Done.
- DoneCan be reopened to InProgress, never back to ToDo.
Any pair not in VALID_TRANSITIONS, including same -> same, returns 422.
| Transition | Valid? | Reason |
|---|---|---|
| ToDo -> InProgress | Yes | Work has started. |
| InProgress -> Done | Yes | Work is finished. |
| Done -> InProgress | Yes | A completed task can be reopened. |
| ToDo -> Done | No | Cannot skip InProgress. |
| Done -> ToDo | No | Cannot revert to the beginning. |
| Same status -> same status | No | No-op moves are rejected in the intended rule set. |
Read with careInProgress -> ToDo is not listed in the notes’ table. Prompt C1’s set of allowed pairs leaves it out, so it is rejected too.
Prompt C1: a rule module and a PATCH update
Prompt C1 creates a new module, app/business_rules.py, and modifies only the existing PATCH route. The rule is a frozenset of allowed (current, new) pairs and one function, validate_status_transition, that raises a 422 for any pair outside it. In the route, validation runs only when payload.status is provided, and only after the existing task has been fetched, so a missing id still returns 404 first. The prompt forbids inlining the rules as if/elif chains: the set is the rule.
Part of Prompt C1, as the library prints it (indentation flattened in the PDF)VALID_TRANSITIONS: frozenset[tuple[TaskStatus, TaskStatus]] = frozenset({ (TaskStatus.TODO, TaskStatus.IN_PROGRESS), (TaskStatus.IN_PROGRESS, TaskStatus.DONE), (TaskStatus.DONE, TaskStatus.IN_PROGRESS), }) Create this function: def validate_status_transition(current: TaskStatus, new: TaskStatus) -> None: # Same -> same is invalid. Anything not in VALID_TRANSITIONS is invalid. if (current, new) not in VALID_TRANSITIONS: allowed = sorted({f"{f.value}->{t.value}" for f, t in VALID_TRANSITIONS}) raise HTTPException( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail=f"Invalid status transition from {current.value} to {new.value}. Allowed transitions: {allowed}", )
What to review in the validator
Before applying C1’s output, the notes ask for six checks. The first and the last two are where generated code most often goes wrong.
- app/business_rules.py defines VALID_TRANSITIONS as a frozenset of allowed pairs.
- The validator checks the pair (current, new), not just whether new is a valid enum value.
- Same-to-same transitions are not included in VALID_TRANSITIONS; if Cursor includes them, remove them.
- Invalid transitions return 422.
- The route fetches the existing task first, so a missing id returns 404 before transition validation.
- Title-only or description-only updates skip transition validation.
Verification C: the six-test matrix
Run a transition sequence against one created task. The intended pattern of status codes is 200, 200, 422, 200, 422, 200. Because the checks run in order on the same task, each one starts from the status the previous check left behind. If the pattern is off, Prompt C2 takes the failing lines as evidence, lists the usual root causes, and forbids making a check pass by weakening the rules.
- T1: ToDo -> InProgress returns 200.
- T2: InProgress -> Done returns 200.
- T3: Done -> ToDo returns 422.
- T4: Done -> InProgress returns 200.
- T5: InProgress -> InProgress returns 422.
- T6: title-only update, no status field, returns 200.
Read with careThe notes describe the six checks but don’t print the script that runs them; it was not supplied.
Common AI mistakes in business rules
The notes list five, and C2’s root-cause checklist repeats most of them.
- Allows every enum value because it checks only whether the new status is valid.
- Returns 400 instead of the expected 422.
- Validates status before confirming the task exists, causing the wrong error for missing ids.
- Runs transition validation even when status is not in the PATCH payload.
- Allows same-to-same transitions because the generated set includes them or because the rule was not explicit enough.
What you leave Part 2.3 with
Part 2.3 ends with the rule, the updated route, the matrix result and notes on what you corrected.
- app/business_rules.py with VALID_TRANSITIONS and validate_status_transition.
- PATCH updated to enforce transitions only when status is being changed.
- The six-test matrix returns the expected pattern.
- Notes about any AI-generated assumptions you corrected.
Key takeaways
- The backend is the trusted enforcement point; the UI only hides buttons.
- Three moves are allowed: ToDo to InProgress, InProgress to Done, Done back to InProgress.
- Validate the (current, new) pair, after the 404 check, and only when status is in the payload.
- The matrix pattern is 200, 200, 422, 200, 422, 200.