Commit b93bef10 authored by Christos Tranoris's avatar Christos Tranoris
Browse files

fix cancel reservation and add correlationid

parent 619a5d67
Loading
Loading
Loading
Loading
+1 −1

File changed.

Preview size limit exceeded, changes collapsed.

+96
Changes for docs/20260720_2150_activity_reservation_type_hold_expiry.md: 96 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Activity view: display `type` and `holdExpiry`

**Date:** 2026-07-20 21:50

## Goal

`GET /api/v1/activity/reservations` gained two fields on `ReservationView` that the UI
was silently dropping at the codec boundary. Surface them in the Activity views.

| Wire field | Type | Domain |
|---|---|---|
| `type` | enum `TENTATIVE_HOLD` \| `FIRM` | `Reservation.type?: ReservationType` |
| `holdExpiry` | `date-time` | `Reservation.holdExpiry?: DateTime` |

Verified against the running backend's spec at `http://localhost:8888/v3/api-docs`. A deep
diff of every shared schema confirmed `ReservationView` was the **only** schema with drift;
no new query parameters were added, so there is no server-side `type` filter to wire up and
this is a display-only change.

## Changes

### Contract + generated types
- `api-docs.json` refreshed from the live spec. Additive: two new paths
  (`/api/v1/reservations/by-resource`, `/api/v1/memberships/by-resource/{tmf639Id}`), one new
  schema (`ResourceFirmRequest`), and the two `ReservationView` fields. Nothing removed.
- `src/adapters/api/generated/schema.d.ts` regenerated via `npm run gen:types`.

### Domain — `src/domain/reservation.ts`
- Added `RESERVATION_TYPES` const, `ReservationType` union, and an `isReservationType`
  guard, mirroring the existing `CONFLICT_FLAGS` / `isConflictFlag` pattern.
- Added optional `type` and `holdExpiry` to `Reservation`.

### Codec — `src/adapters/api/mappers/feasibility.ts`
- `decodeReservation` now decodes both fields using the existing conditional-spread idiom,
  so absent wire fields stay **absent** rather than becoming `undefined` keys.
- `holdExpiry` decodes through `decodeOptionalDateTime` into the tenant zone.
- An unrecognised `type` token is dropped rather than cast through, so an invalid union
  member can never reach the UI.
- This single mapper feeds both the list and detail gateways, so no gateway change was needed.

### UI — `src/features/activity/`
- **`ActivityPage.tsx`**: new **Type** column rendering a `StatusChip` (`FIRM` → `ok`,
  `TENTATIVE_HOLD` → `info`), `—` when absent. `RowIndicators` gained a `HoldExpiryChip`:
  `error` / "Hold expired" once `holdExpiry` has passed, otherwise `warn` /
  "Expires {datetime}".
- **`ReservationDetailPage.tsx`**: Type and Hold expiry metadata rows, plus a status alert
  distinguishing a lapsed hold (`error`) from one still counting down (`warning`).
- **`ReservationsCalendar.tsx`**: holds marked `(hold)` in the event title; tooltip gained a
  hold-expiry line.

### Fixtures + tests
- `F_RESERVATION_ACTIVITY` gained `type: 'FIRM'`; new `F_RESERVATION_HOLD` fixture covers an
  already-expired tentative hold.
- Mapper tests: both fields round-trip, keys absent when the wire omits them, unknown tokens
  dropped, `holdExpiry` decoded into the tenant zone.
- Page tests: Type column/row renders, live vs expired holds get distinct treatments, and a
  typeless reservation shows neither.

## Verification

- `npx vitest run` — **697 passed / 57 files**.
- `npm run lint` — 114 errors, **matching the pre-change baseline exactly** (verified by
  stashing). All are pre-existing `no-explicit-any` violations in test files; none in the
  files touched here. An `as any` initially added in `ActivityPage.test.tsx` was rewritten as
  `as unknown as ReturnType<typeof useReservations>` to avoid adding to that debt.
- `npx vite build` — succeeds. (`npm run build` remains broken on the pre-existing MUI v9
  theme typing errors, unrelated to this work.)
- `npm run gen:types` confirmed deterministic across consecutive runs.

**Not verified:** the endpoint returns `401 AUTHN` to unauthenticated curl, so the fields
were not confirmed against live reservation data. Worth a look in the browser once signed in
— particularly whether real records populate `type`, since the mapper deliberately renders
`—` rather than guessing when it is absent.

## Incidental finding — `check:types-drift` was already failing on master

The committed `schema.d.ts` was **stale relative to the committed `api-docs.json`** before
this change: it lacked `SuggestedResource` (added to the contract in 86e7ed2 without
regenerating) and still carried `localStartTime`/`localEndTime` on `AddWeeklyWindowRequest`,
which the contract had already renamed to `startTime`/`endTime`. Regenerating here fixes
that drift as a side effect — it accounts for the 4 removed lines in the `schema.d.ts` diff,
which do **not** come from the live spec.

## Pre-existing bugs found while researching (not addressed)

1. **The flags list is always empty against a real backend.** Both specs declare
   `GET /api/v1/activity/flags` as a bare JSON array, but `activityGateway.ts:46` calls
   `decodePage(...).content`, and `decodePage` reads `w?.content ?? []` — `undefined` on an
   array. The MSW handler wraps the fixture in a page envelope, so tests pass and hide it.
2. **`resolveFlag` targets an endpoint that exists in neither spec.**
   `POST /activity/flags/{id}/resolve` is mocked in MSW but should 404 against the service.
3. **Calendar mode requests `size: 500`** (`ActivityPage.tsx`) but the documented server max
   is 200. Note `buildActivityParams` (`mappers/pagination.ts:145`) already clamps size,
   whitelists sort, and encodes `lifecycleState` as an array — but `listReservations`
   hand-rolls its params and bypasses it, so `lifecycleState` goes out as a single value and
   `tmf639Id` / `inconsistentOnly` / `sort` are never sent at all.
+81
Changes for docs/20260721_0008_activity_cancel_reservations.md: 81 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Cancel reservations and tentative holds from the Activity views

**Date:** 2026-07-21 00:08

## Goal

Let users cancel an existing reservation, or release a tentative hold, from the Activity
list and detail pages. Two backend endpoints cover this (confirmed against the live spec at
`http://localhost:8888/v3/api-docs`):

| Endpoint | Purpose | Response |
|---|---|---|
| `DELETE /api/v1/reservations/{id}` | Cancel a reservation | 204 |
| `DELETE /api/v1/reservations/holds/{holdId}` | Cancel a tentative hold | 204 |

## What already existed

The whole lower stack was already in place and used only in the **booking** flow
(`ActiveHoldsPanel`, `FirmReservationForm`), where you can cancel something you just created:

- Domain port methods `cancel(id)` / `cancelHold(holdId)` (`domain/gateways.ts`).
- Gateway implementations issuing the two DELETEs (`adapters/api/gateways/reservationGateway.ts`).
- Hooks `useCancelReservation` / `useCancelHold` (`app/reservations.ts`), already invalidating
  the reservations, activity, and inventory query keys on success.
- MSW handlers for both DELETEs (`test/handlers.ts:61-62`).

The gap was purely in the **Activity views** — there was no way to cancel a pre-existing
reservation you were browsing. So this change is UI-only; no new hook, gateway, or contract
work was needed.

## Changes

### New shared component — `src/features/activity/CancelReservationButton.tsx`
- Chooses the endpoint from the reservation's `type`: `TENTATIVE_HOLD` → `useCancelHold`,
  otherwise `useCancelReservation`. (This leans on the `type` field added in the previous
  task, 20260720_2150.)
- Two render variants: `icon` (a red cancel `IconButton` for table rows, which
  `stopPropagation`s so it doesn't trigger the row's navigate-to-detail click) and `button`
  (a text button for the detail page).
- Gated on the `canCreateReservations` capability — renders nothing otherwise.
- Disabled outside a cancellable lifecycle state, or when `cancelPending` is already set, with
  a tooltip explaining why. Cancellable states: `CREATED`, `PROVISIONING`, `ACTIVE`,
  `PROVISIONING_FAILED`, `RELEASE_FAILED` (terminal `RELEASED`/`CANCELLED` and in-flight
  `RELEASING` are excluded; the failed states stay cancellable so a stuck reservation can be
  cleaned up).
- Confirmation via the existing `ConfirmDialog` (`@feedback`), with hold-vs-reservation
  wording. Errors surface through the existing `ProblemDetailAlert`; a success `Alert` shows
  on completion.

### Wiring
- **`ActivityPage.tsx`**: new right-aligned **Actions** column (header + body) rendering the
  `icon` variant per row.
- **`ReservationDetailPage.tsx`**: a divider plus the `button` variant at the foot of the
  detail card.

### Tests
- **`CancelReservationButton.test.tsx`** (new, 9 tests): endpoint selection by type,
  disabled/terminal states, `cancelPending` disabling, capability gating (auditor sees
  nothing), and `ProblemDetail` error surfacing.
- Extended the two existing activity page tests to mock `@app/reservations` and, for the
  detail page, wrap the render in an `AuthContext.Provider` (the component reads
  `useCapabilities`).

## Verification

- `npx vitest run` — **706 passed / 58 files** (was 697/57; +9 new, no regressions).
- `npm run lint` — 114 errors, **exactly the pre-existing baseline**; the new component and
  test files are clean (verified by grep).
- `npx vite build` — succeeds. (`npm run build` stays broken on the unrelated pre-existing
  MUI v9 theme typing errors.)

**Not verified against live data:** the endpoint requires a bearer token (returns 401 to
unauthenticated curl), so cancellation was exercised only through MSW. Worth confirming in the
browser once signed in — in particular that the server sets `cancelPending` / advances the
lifecycle state as expected after a DELETE, since the button's disabled logic keys off those.

## Design note

The `type`-based endpoint routing means a hold that has been promoted to firm (so `type` is
no longer `TENTATIVE_HOLD`) correctly cancels via the reservation endpoint. If a record ever
lacks `type` entirely, it defaults to the reservation endpoint — the safe majority case.
+51
Changes for docs/20260721_1700_activity_correlation_id.md: 51 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Activity view: `correlationId`

**Date:** 2026-07-21 17:00

## Goal

`ReservationView` gained a `correlationId` field on the Chronos backend. Surface it
in the views that show reservations — primarily Activity — and let operators search
by it.

## Contract refresh

Fetched the live contract from `http://localhost:8888/v3/api-docs` and replaced
`api-docs.json`, then regenerated `src/adapters/api/generated/schema.d.ts`
(`npm run gen:types`). Delta vs. the committed contract:

- `correlationId` added to `ReservationView`, `FeasibilityRequest`, `ResourceFirmRequest`.
- `correlationId` added as a query parameter on `GET /api/v1/activity/reservations`.
- New `POST /api/v1/reservations/cancel` endpoint plus `CancelRequest`,
  `CancellationResult`, `ReservationCancellationResult` schemas (not consumed yet —
  the cancel feature still uses `DELETE /reservations/{id}`, which the backend
  continues to expose).

## Changes

| Layer | Change |
|---|---|
| `domain/reservation.ts` | `Reservation.correlationId?: string` |
| `domain/gateways.ts` | `ReservationQuery.correlationId?: string` |
| `adapters/api/mappers/feasibility.ts` | `decodeReservation` decodes `correlationId`; absent → field omitted |
| `adapters/api/gateways/activityGateway.ts` | `correlationId` forwarded as a list query param |
| `features/activity/ActivityPage.tsx` | New **Correlation ID** table column (monospace, `—` when absent) and a **Correlation ID** filter field feeding both the table query and the calendar query |
| `features/activity/ReservationDetailPage.tsx` | **Correlation ID** detail row, rendered only when present |
| `src/test/fixtures.ts` | `F_RESERVATION_ACTIVITY` carries `correlationId: 'corr-1'` |

The field is read-only in the UI. `FeasibilityRequest.correlationId` exists in the
contract but the reservation forms do not set it — the backend assigns it.

## Tests

- `feasibility.test.ts` — decodes `correlationId` when present, omits it when absent.
- `ActivityPage.test.tsx` — renders the column header + value; the filter reaches
  `useReservations` as `correlationId` on Search.
- `ReservationDetailPage.test.tsx` — detail row renders when present.

`npx vitest run` → 710 tests, 709 passing. One test times out (5s limit) per full-suite
run, but a *different* one each time (`OpenSliceBrowsePage`, `AvailabilitySearchPage`,
`FirmReservationForm`) — pre-existing `userEvent` flakiness under load; each passes in
isolation and none is touched by this change. `npx eslint` on the
touched files reports no new errors — only the repo's pre-existing
`no-explicit-any` debt.
+3
Changes for docs/index.md: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -70,3 +70,6 @@
| 2026-06-14 00:20 | [Blackouts page: pool and resource dropdowns](20260614_0020_blackouts_pool_resource_dropdowns.md) | Replaced free-text Scope Ref field with guided pool + conditional resource dropdowns in BlackoutsPage; New Blackout button disabled until scope selected; 675 tests passing |
| 2026-06-14 00:40 | [Pool Inventory page enhancements](20260614_0040_inventory_page_enhancements.md) | Added summary stat cards, utilization bars, pool category, StatusChip per resource, full resource list, and quick-nav buttons; 680 tests passing |
| 2026-06-15 00:42 | [Availability search: SuggestedResource support](20260615_0042_availability_suggested_resource.md) | Added SuggestedResource domain type; codec decodes it from AvailabilityWindow wire shape; UI shows Suggested Resource column and passes it to /reservations when no explicit resource is chosen; 683 tests passing |
| 2026-07-20 21:50 | [Activity view: display `type` and `holdExpiry`](20260720_2150_activity_reservation_type_hold_expiry.md) | Refreshed contract from live backend; new ReservationType domain union + codec decode; Type column, hold-expiry chips, detail rows and calendar markers for tentative holds; also fixes pre-existing schema.d.ts drift; 697 tests passing |
| 2026-07-21 00:08 | [Activity view: cancel reservations and holds](20260721_0008_activity_cancel_reservations.md) | New CancelReservationButton (icon + button variants) wired into the Activity table and detail page; routes to DELETE /reservations/{id} or /reservations/holds/{holdId} by reservation type; capability-gated, state-aware, ConfirmDialog + ProblemDetailAlert; 706 tests passing |
| 2026-07-21 17:00 | [Activity view: `correlationId`](20260721_1700_activity_correlation_id.md) | Refreshed contract from live backend (correlationId on ReservationView + activity query param, new /reservations/cancel schemas); domain + codec + gateway wiring; Correlation ID column and filter on ActivityPage, detail row on ReservationDetailPage; 710 tests |
Loading