# Local Compatibility Harness

## Purpose
Run a local, deterministic compatibility harness that exercises the current requirements for:

- Admin navigation pages (`Edit Calendar`, `Users`, `Setup`)
- API CRUD and user lifecycle endpoints
- Shared-calendar CalDAV read/write flows
- ICS export endpoint

Seed data includes canonical test fixtures `CE-001` through `CE-010` from `tests/calendar_entries.md`.

## Quick Start
From repository root:

```bash
./compatibility-layer/reset.sh
./compatibility-layer/seed.sh
./compatibility-layer/run.sh
```

Server default:

- `http://127.0.0.1:8080`

## WP Emulation Check
Run the stand-alone local WordPress emulation check (loads plugin code from `code/` and runs a minimal E2E flow):

```bash
./compatibility-layer/e2e_wp_emulation.php
```

## Harness Authentication Model
This harness uses simple test auth headers/credentials to emulate behavior.

### Admin/API (WordPress-style harness auth)
- Header: `X-WP-User: admin` (full admin)
- Header: `X-WP-User: editor` (editor-limited)

### CalDAV (plugin user basic auth over local HTTP harness)
Seeded users:

- `rw_user@example.test` / `rwpass123456` (`write`)
- `ro_user@example.test` / `ropass123456` (`read_only`)

## Key Endpoints

### Admin Pages
- `/wp-admin/admin.php?page=calendar-edit&as=admin`
- `/wp-admin/admin.php?page=calendar-users&as=admin`
- `/wp-admin/admin.php?page=calendar-setup&as=admin`

Interactive pages available:

- Public calendar UI: `/calendar`
- User self-service portal: `/users`

If setup `url_slug` is configured (for example `demo`), canonical URLs move under that prefix (for example `/demo/calendar`, `/demo/users`, `/demo/wp-json/calendar/v1/...`, `/demo/calendar.ics`, `/demo/caldav/...`).

### API
- `/wp-json/calendar/v1/events`
- `/wp-json/calendar/v1/events/{id}`
- `/wp-json/calendar/v1/events/{id}/occurrences/{occurrence_key}`
- `/wp-json/calendar/v1/users/register`
- `/wp-json/calendar/v1/users/verify`
- `/wp-json/calendar/v1/users/forgot-password`
- `/wp-json/calendar/v1/users/reset-password`
- `/wp-json/calendar/v1/users/{id}/request-write`
- `/wp-json/calendar/v1/admin/users`
- `/wp-json/calendar/v1/admin/users/{id}`
- `/wp-json/calendar/v1/admin/setup`
- `/wp-json/calendar/v1/public/events`
- `/wp-json/calendar/v1/users/me`

### ICS
- `/calendar.ics`

### CalDAV (single shared public calendar)
- `/caldav/`
- `/caldav/calendars/`
- `/caldav/calendars/public/`
- `/caldav/calendars/public/{object_id}.ics`

## Smoke Commands

List events:

```bash
curl -sS -H 'X-WP-User: admin' http://127.0.0.1:8080/wp-json/calendar/v1/events
```

Delete one recurring occurrence as exception:

```bash
curl -sS -X DELETE \
  -H 'X-WP-User: admin' \
  "http://127.0.0.1:8080/wp-json/calendar/v1/events/10/occurrences/2026-04-17T14:00:00+01:00" \
  -i
```

Fetch ICS:

```bash
curl -sS http://127.0.0.1:8080/calendar.ics
```

CalDAV read as read-only user:

```bash
curl -sS -u ro_user@example.test:ropass123456 \
  http://127.0.0.1:8080/caldav/calendars/public/1.ics -i
```

## Notes
- This compatibility harness is intentionally minimal and deterministic for local development.
- It is not a production security implementation.
- It enforces the shared-calendar model with per-user read/write permissions.
- Current implementation delegates to `fixture/` internals via wrapper scripts in `compatibility-layer/`.
