feat(returns): add authoritative return preview

The return-review step predicted operational consequences independently in
the frontend, and got it wrong: damage or a technical warning was described
as routing to "maintenance" when the actual domain rule (returns.py) routes
it to "blocked", and the no-contradiction case was described as becoming
"available" when the vehicle actually always goes to "cleaning" first
(only reaching "maintenance" if the service threshold was crossed).

Extract the evaluation returns.py already performed inline into a pure
evaluate_return() function with no writes -- resulting status (with an
explanation), odometer regression, would-create-quality-issue,
next-booking-risk -- and share it between a new non-mutating
POST /bookings/{ref}/return-preview endpoint and the existing commit path,
so preview and commit can never drift apart again. The result screen also
now distinguishes local commit success from n8n delivery (still queued/
unconfirmed) instead of implying both succeeded, and links to any created
quality issue for Operations Manager.
This commit is contained in:
NuklearRabbit
2026-08-02 05:33:12 +02:00
parent 62ac9f825c
commit f5212959b4
8 changed files with 435 additions and 77 deletions
+10 -4
View File
@@ -35,14 +35,20 @@ test("return review separates capture from irreversible commit", async ({ page }
await page.getByLabel("End odometer (km)").fill("60000");
await page.getByLabel("Fuel level (%)").fill("65");
let returnRequests = 0;
let commitRequests = 0;
let previewRequests = 0;
page.on("request", (request) => {
if (request.url().includes("/return") && request.method() === "POST") returnRequests += 1;
if (request.method() !== "POST") return;
if (request.url().endsWith("/return-preview")) previewRequests += 1;
else if (request.url().endsWith("/return")) commitRequests += 1;
});
await page.getByRole("button", { name: "Review return" }).click();
expect(returnRequests).toBe(0);
await expect(page.getByText("Expected fleet state")).toBeVisible();
await expect(page.getByText(/Expected fleet state/)).toBeVisible();
expect(commitRequests).toBe(0);
// The review step is server-evaluated (not client-guessed), so exactly one non-mutating
// preview call is expected before any commit.
expect(previewRequests).toBe(1);
await expect(page.getByText("Queue n8n delivery after the local commit")).toBeVisible();
await page.getByRole("button", { name: "Edit details" }).click();