# AI Handover

## Current task

Epic 007 is complete. REFUND-TASK-001 through REFUND-TASK-007 are implemented on
`refund-007-complete-journeys-and-release-evidence`. Task 007 added desktop/mobile browser journeys
for active and delivered refunds, definitive failure, unknown outcome, duplicate-safe requests, and
refunded-history presentation, plus final release evidence. Full validation passed: `pnpm quality`,
`pnpm build`, `pnpm test:coverage` (100% frontend and backend), supply-chain checks,
`pnpm docs:build`, `pnpm docs:site:check`, and `pnpm validate:docker` (92 integration tests and 88
desktop/mobile browser tests). Commit the task changes, then continue with hosted CI/external
evidence for Epic 006/Surfboard prerequisites.

A new specification-only epic has been created:

- **Epic 008 — Full Surfboard ECR integration** at `docs/specs/008-surfboard-ecr/README.md`, with 31
  small task descriptions in `docs/specs/008-surfboard-ecr/tasks/`. The `SurfboardECRGateway`
  adapter (`backend/src/integrations/surfboard-ecr-gateway.ts`) is implemented and tested;
  `surfboard-ecr-gateway.test.ts` now has 98 tests and `surfboard-ecr-gateway.ts` is at 100%
  statements/branches/functions/lines coverage (verified via `pnpm test:coverage`).

## Changes

- Added original payment reference/method persistence, provider-neutral refund contracts, the
  terminal `Refunded` status, and a PostgreSQL refund-operation repository with atomic claims and
  result/history updates.
- Added migrated PostgreSQL evidence for eligibility, concurrent claims, unresolved-state restart
  durability, definitive-refusal retry, and success-only refund transitions.
- REFUND-TASK-002 currently implements the Surfboard return-order payload, stable error-code
  redaction, terminal outcome mapping, bounded status polling, and GET-only status lookup. Its
  adapter tests cover documented reason/status behavior and ambiguous failures; no live provider
  requests were made. Its task documentation and evidence matrix are complete.
- REFUND-TASK-003 adds deterministic fake and Mocking Bird refund gateways, a separate local refund
  store and composition, protected redacted refund-console endpoints, frontend API validation and
  controls, and English/Swedish/Hungarian strings. OpenAPI now documents the refund-console routes
  and refund state counters. The browser projection excludes original payment/order references and
  payment method; no Surfboard calls were made.
- REFUND-TASK-004 adds durable application orchestration, safe repeat/status-only resolution,
  authenticated and mutation-protected refund routes, and refunded-order history with provider
  reference redaction. Its task/index/evidence matrix, OpenAPI, architecture, testing guidance,
  current state, and handover are synchronized. The migration lifecycle assertion includes the
  refund-operation table.
- REFUND-TASK-005 adds a server-computed active-queue eligibility and latest-operation projection
  that omits provider references, plus a confirmed full-refund action in the detailed KDS menu.
  Pending/unknown states suppress issuance and allow status-only resolution only when possible;
  success invalidates queue/history without optimistic removal. Localized UI, OpenAPI, generated API
  docs, focused component/API tests, PostgreSQL integration, and traceability evidence are
  synchronized.
- REFUND-TASK-006 adds the matching safe eligibility/status projection to delivered history, a
  confirmed refund action only in expanded order details, and accessible refunded-state total,
  notice, and timeline presentation. Confirmed success retains the order and refreshes history.
  OpenAPI, generated docs, localization, component/PostgreSQL evidence, architecture/testing docs,
  and scenario traceability are synchronized.
- Updated the [Epic 007 specification](specs/007-refund-flow/README.md), task evidence,
  architecture, testing strategy, current state, and handover.

## Previous changes

- Fixed `pnpm user:create` failing in a clean local checkout: it now builds `@foodtruck-order/db`
  first and falls back to the documented default local PostgreSQL URL when `DATABASE_URL` is unset
  in non-hosted environments. Hosted/production behavior is unchanged.
- Root `pnpm user:create` builds the database workspace before running the backend command.
- `backend/src/tooling/create-user.ts` derives the documented local `DATABASE_URL` only outside
  staging/production; `loadConfig` still requires it.
- Increased bounded backend Vitest test PostgreSQL migration and database-cleanup work on slow
  storage. Updated the two explicit migration-test overrides and the testing strategy.
- Simplified auth-route cache headers to apply uniformly inside the auth plugin, removing a
  URL-prefix condition that could never take its false branch for the plugin's registered routes.
- Added coverage cases for response-stream cancellation failure and non-string provider payment
  statuses; removed an impossible index guard while trimming entries from the same array.
- Preserved the staged dependency/test updates already present when validation began.

## Findings and continuation

Aggregate coverage requires a reachable PostgreSQL instance; the initial run without `DATABASE_URL`
failed authentication. It passed when pointed at the local Docker PostgreSQL service, where tests
create/drop only their dedicated test databases. Hosted CI status and persisted artifacts have not
been checked. Epic 006 still needs its documented staging/production TLS, headers, cookies,
deployment topology, and effective-limit evidence; business privacy/retention decisions remain
external. The separate Surfboard Demo prerequisites and accessibility review remain as recorded in
[current state](current-state.md).

## Validation

- `pnpm quality`: passed.
- Focused backend unit tests: passed (148 tests).
- PostgreSQL integration tests: passed (42 tests across refund operations, order persistence, and
  order history) against Docker PostgreSQL on host port 55432.
- `pnpm build`: passed; the default production build omitted the Mocking Bird console chunk.
- `pnpm test`: passed (56 CI tests, 307 frontend tests, 496 backend unit tests).
- `pnpm test:coverage`: passed with local PostgreSQL (307 frontend and 588 backend tests); both
  applications met 100% statements, branches, functions, and lines.
- ECR gateway coverage task: `backend/src/integrations/surfboard-ecr-gateway.test.ts` (98 tests) and
  `backend/src/integrations/surfboard-ecr-gateway.ts` verified at 100% statements/branches/
  functions/lines via targeted `vitest run --coverage` and full `pnpm test:coverage`; backend unit
  suite 686 tests passed; prettier/eslint/tsc clean on the changed test file.
- `pnpm quality` passed. Existing non-blocking warnings remain for the OpenAPI health-route 4xx
  response and Redux Toolkit inherited TypeDoc summary.
- REFUND-TASK-003 focused validation passed: 40 backend refund/API/OpenAPI tests, 41 frontend
  API/console tests, `pnpm quality`, and `pnpm docs:build`. The documentation checks retain the
  existing health-route and inherited TypeDoc warnings.
- REFUND-TASK-004 validation passed: frontend tests (312), backend unit tests (523), and PostgreSQL
  refund/history/migration integration tests (18) against Docker PostgreSQL on port 55432. After
  final test cleanup, affected frontend tests (23) and backend tests (55) passed. Backend/frontend
  type checks and `pnpm quality` passed. The existing health-route and inherited TypeDoc warnings
  remain.
- REFUND-TASK-005 validation passed: focused KDS/queue tests (18), refund OpenAPI/HTTP tests (7),
  frontend refund API tests (17), and PostgreSQL refund-operation integration tests (5) against
  Docker PostgreSQL on port 55432. `pnpm docs:build` and `pnpm quality` passed; existing
  health-route and inherited TypeDoc warnings remain.
- REFUND-TASK-006 validation passed: focused history/KDS component tests (26), refund OpenAPI/HTTP
  tests (7), and PostgreSQL refund-operation integration tests (6) against Docker PostgreSQL on
  port 55432. `pnpm docs:build` and `pnpm quality` passed; existing health-route and inherited
  TypeDoc warnings remain.
- `pnpm docs:build` and `pnpm docs:site:check` passed.
- `pnpm validate:docker` passed against the isolated validation Compose project: 92 PostgreSQL
  integration tests, the backend restart/durability lifecycle, and 82 desktop/mobile browser tests.

## Next action

Commit the completed REFUND-TASK-007 changes on the current branch. Epic 007 is otherwise complete;
remaining work is hosted CI, persisted artifacts, and external Surfboard/Epic 006 prerequisites.

For Epic 008, the next step is to begin Phase 1 investigation tasks (ECR-TASK-001 through
ECR-TASK-006), starting with inspecting the current payment/order/KDS architecture and Surfboard ECR
documentation via the official docs/MCP server.
