Skip to content

Staff API v1 contract and conformance suite - #33

Merged
mpge merged 10 commits into
mainfrom
feat/staff-api-contract
Nov 27, 2026
Merged

mpge merged 10 commits into
mainfrom
feat/staff-api-contract

Conversation

@mpge

@mpge mpge commented Nov 26, 2026

Copy link
Copy Markdown
Member

Writes down the staff REST API once, so every backend serves the same API to the browser extension and other clients.

What's here

  • contracts/staff-api-v1.md: the contract. Endpoints, request and response shapes, pagination, errors, rate limits, and the new pieces the extension needs: public GET /meta, updated_since, last_customer_reply_at, the helpdesk sign-in flow (connect page, one-time code, PKCE, POST /auth/exchange, POST /auth/revoke). The "Connect page requirements" and "Exchange rules" sections are normative.
  • contracts/staff-api-v1.openapi.yaml: the same contract as OpenAPI 3.1 (lints clean with Redocly).
  • conformance/: a black-box suite (Node, TypeScript, Vitest). Each backend's CI boots a seeded install and points it at the API with a few env vars. It talks HTTP only, checks every response against the OpenAPI schemas, and skips cleanly when a backend does not serve the contract yet or lacks an optional feature.
  • .github/workflows/contracts.yml: lints the OpenAPI file and typechecks the suite.

Laravel 1.9.20 is the reference. Where it differs from the contract, the change log says so; those get fixed in escalated-laravel next.

Expected on Laravel 1.9.20 today

GET /meta is 404 there, so the suite reports one failure ("does not serve staff API contract v1") and skips the rest. Once /meta lands, these will fail until the Laravel work is done: /auth/exchange, /auth/revoke, updated_since, last_customer_reply_at, the Ticket schema (last_reply_at, sla_breached, is_following, followers_count), macros (steps vs actions), and the 422 on a refused status change (Laravel answers 500).

Verified

  • Redocly lint: valid.
  • Suite typecheck: clean.
  • Against a mock server: full pass; 302 and non-JSON /meta each give one clear failure with the rest skipped; a backend that accepts a wrong PKCE verifier fails and the token it minted is revoked.

mpge added 9 commits November 26, 2026 17:27
Add normative connect page requirements, PKCE encoding with the RFC 7636 test vector, and exchange rules. Define status transitions, sort tie-breaks, /meta caching headers and same-origin URLs, and list the Laravel divergences. Add sla_breached to the OpenAPI Ticket schema.
Treat /meta as served only for a 200 JSON object with a string api_version and name what came back otherwise. Validate both /meta responses against the Meta schema and check that an invalid token gets the public shape with Vary and Cache-Control. Add the optional connect fixture and exchange tests, including a per-IP 429 check that runs last. Pick status targets from the default transition table, cover same-status and forbidden transitions, expect exactly 201 for replies and notes, and use soft assertions in clean-up blocks.
A backend may restrict status changes, but a refused change must be 422 with errors.status and a same-status change a 200 no-op. Laravel's table becomes a recommended default. The suite tries round-trip candidates, treats a refusal as not allowed from here, and checks a refused transition only when ESCALATED_CONFORMANCE_FORBIDDEN_TRANSITION names one. Exchange validation errors are 422 before any code lookup. The wrong-verifier test revokes any minted token before asserting.
@mpge
mpge merged commit 9d58515 into main Nov 27, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant