Skip to content

Latest commit

 

History

History
76 lines (52 loc) · 4.93 KB

ARCHITECTURE.md

File metadata and controls

76 lines (52 loc) · 4.93 KB

Architecture and invariants

One capture, several development artifacts

                 ┌──────────────────────────────────────────┐
 existing SDK →  │ EQUAL record → redacted equal/v1 JSONL  │  → original API
                 └───────────────────┬──────────────────────┘
                                     │ one cassette
                  ┌──────────────────┼──────────────────┐
                  ▼                  ▼                  ▼
           EQUAL replay       EQUAL export       EQUAL verify
                  │                  │                  │
        local API server      OpenAPI 3.1 JSON   candidate implementation
                  │                  │                  │
        offline development   existing API tools   field-level JSON report

The cassette is the product boundary. It is not a hidden cache tied to a process or a vendor account. It can be reviewed, edited, versioned, generated by another tool, or read by an implementation in another language. OpenAPI export turns the same observed evidence into a portable artifact for the existing API ecosystem rather than forcing users to stay inside EQUAL.

Capture path

  1. The recorder buffers one request up to the configured limit and forwards the original credentials and body to the upstream.
  2. The upstream response is buffered and returned to the caller without redaction.
  3. Independent request and response copies are redacted before cassette storage.
  4. The cassette writer is mutex-protected. Interaction IDs come from request arrival; loading restores ID order after concurrent completions.
  5. An existing file requires explicit --overwrite. Optional --fsync requests persistence after every entry.

A cassette write failure produces an explicit server error instead of pretending the interaction was captured.

Replay path

At startup, EQUAL validates the complete cassette and precomputes request keys into queues. Lookup is constant-time on average after startup rather than scanning every interaction per request.

The key contains:

  • uppercase method;
  • escaped path;
  • canonical query encoding;
  • canonical JSON body when valid, or exact bytes otherwise;
  • explicitly selected headers only.

Common credential values are redacted on both the stored and incoming request before matching. Repeated keys consume their response queue in capture order. Strict mode additionally consumes one global sequence.

There is no upstream field or fallback branch in ReplayHandler. Misses cannot silently become live network calls.

OpenAPI export path

Export reads the same validated cassette and groups interactions by generalized path, method, and response status. Numeric and UUID path segments become explicitly documented inferred parameters. Query presence across observations determines whether a parameter is required.

JSON request and response examples are decoded with arbitrary-precision numbers and converted into observed JSON Schema types. The exporter preserves examples and interaction IDs, emits binary content encodings, and retains alternative responses in a provenance extension. It does not invent unobserved endpoints, provider-wide required fields, or authoritative schemas.

Verification path

Verification is deliberately separate from replay. It reads stored requests and sends them to the candidate in capture order. Candidate credentials can be injected without changing the cassette.

The comparator checks status and selected headers, then:

  • decodes JSON with arbitrary-precision json.Number values;
  • treats numerically equal forms such as 1, 1.0, and 1e0 as equal;
  • preserves object member and array index paths in differences;
  • applies explicit JSON Pointer removals, including * for one wildcard segment;
  • compares non-JSON bodies byte for byte.

Transport failure is a failed interaction, never a pass. Any difference produces a report and CLI exit code 3.

Deliberate exclusions

  • No implicit volatile-field detection. Automatically ignoring id or timestamp can hide the exact incompatibility a test should catch.
  • No production ingress claims. Buffering, authentication, multi-tenancy, streaming, and rate limiting have different requirements.
  • No universal protocol claim. Version 0.2.0 handles ordinary HTTP request-response exchanges, not every network protocol.
  • No automatic completeness claim. Observed traffic is evidence about observed behavior only.

Dependency boundary

The implementation uses the Go standard library only. Release builds disable CGO and produce static binaries for Linux, macOS, and Windows on amd64 and arm64. The JSONL format and CLI exit codes are the compatibility surface; internal Go packages are not presented as a stable public API.