conformance

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 23 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Echo connector conformance

A connector lives inside a site (WordPress, Laravel, Node, or one you write for Django or Rails), reports every email and outbound HTTP request to Echo and obeys Echo's answer. This folder is what a connector author needs to get that right without reading Echo's Go code.

Piece What it is
../wire/schema.json The wire protocol as a JSON Schema (draft 2020-12), generated from ../wire/wire.go. Capture is what a connector posts, Decision is what Echo answers.
testdata/*.json Shared vectors: captures with the decision Echo gives them, broken captures with what is wrong, plus what a connector must do when Echo gives no decision.
rhythm echo conformance A strict stand-in Echo for a connector's end-to-end test. Until the command ships, run it with GOWORK=off go run ./conformance/cmd/conformance.

The protocol in short

  • POST /v1/capture with a Capture, X-Echo-Token when Echo has a token. Echo answers 200 with a Decision.
  • HTTP requests are reported phase: before. The decision's action is allow (send it, then report phase: after with the id and the response), fake (don't send: hand response to the app as the provider's answer) or block (don't send: fail the request).
  • Emails are reported before sending. fake means Echo keeps it: report success to the app and send nothing. allow (observe mode) means send it, then report phase: after with the id and any error.
  • No decision (Echo unreachable, any status but 200, no answer within the connector's own short timeout): sealed, nothing is sent; observing, it is sent. Which applies is the mode Echo last reported (Node) or the connector's configured fallback mode (Laravel, WordPress), seal by default.
  • v is the wire version, now 2. Send 2. When Echo answers 400 with "newer than Echo", read GET /v1/health: an Echo that says "wire": 1 gets captures with v: 1 and without the fields marked x-since: 2 in the schema (source.site, email.attachments). Remember that for the process.
  • Mask credentials before they leave the site: see the connectors' READMEs for the header rule.

Vectors

Each testdata/*.json file other than run-signature.json is one vector:

{
  "name": "a sealed Twilio call is faked",
  "about": "why the rule exists",
  "valid": true,
  "problems": ["for broken captures: text the validator's problems must contain"],
  "mode": "seal",
  "echo": "up | unreachable | 5xx | timeout",
  "capture": { "v": 2, "kind": "http", "...": "..." },
  "decision": { "mode": "seal", "action": "fake", "response": { "status": 201 } },
  "connector": "fake | send | block"
}
  • capture-*.json: valid captures and the decision Echo's real catcher gives them (decision lists the fields that must match).
  • broken-*.json: captures the schema refuses, with the problems a validator must find.
  • fail-*.json: Echo gives no decision; connector says whether the connector must block or send.
  • run-signature.json: the X-Echo-Run signing vectors (wire.SignRun, wire.VerifyRun) and which run a connector takes from a request. A run value longer than max_run (512 bytes, signature included) is ignored whole, never cut.

The Go tests (go test ./conformance/) post every valid capture to Echo's real catcher and check the decision. The Node, Laravel and WordPress suites check their own captures against schema.json and run the fail-* vectors through their hooks.

The stand-in

GOWORK=off go run ./conformance/cmd/conformance --listen 127.0.0.1:8025 --expect email,http-before
# point the connector at it (RHYTHM_ECHO_URL=http://127.0.0.1:8025), run the site's test, then Ctrl-C

It is Echo's real catcher (same decisions, same /v1/messages to read back) with every capture checked against the schema first. A capture that breaks it is answered 400 conformance: <path>: <problem> and counted. When it stops (SIGINT or SIGTERM) it prints a table and exits 1 on any fail:

CHECK        RESULT  DETAIL
schema       PASS    5 captures, all valid
email        PASS    1: an email reported before it is sent
http-before  PASS    4: an HTTP request reported before it is sent
run          INFO    5: a capture tied to a run

PASS

GET /v1/conformance returns the same report as JSON, for scripts. Flags:

Flag Meaning
--listen <addr> API address (default 127.0.0.1:8025)
--smtp <addr> also run Echo's SMTP sink (default off)
--mode seal|observe Echo's mode (default seal)
--token <t> require this X-Echo-Token
--allow <hosts> hosts reachable when sealed
--wire 1 act like an Echo that speaks wire 1: health says so, v2 captures get its refusal and the report checks the connector fell back
--expect <list> scenarios the run must include: email, email-after, http-before, http-after, run, site, attachments, wire-1, wire-2
--json print the report as JSON

The Node (connectors/node/fixtures/e2e.mjs) and Laravel (connectors/laravel/fixtures/e2e.sh) end-to-end tests run against it.

Changing the protocol

Edit the types in wire/wire.go (tags: enum:"a,b" lists a field's values, since:"2" marks the version that added it), then:

GOWORK=off go generate ./wire/

conformance/gen fails its test when schema.json is out of date.

Documentation

Overview

Package conformance checks a connector against Echo's wire protocol. It has three parts:

  • Schema validates captures and decisions against wire/schema.json, the protocol as a JSON Schema generated from package wire.
  • testdata/*.json holds the shared vectors: capture and decision pairs, including what a connector must do when Echo is unreachable, answers 5xx or times out (fail closed). Connector suites in other languages read them too.
  • Main runs a strict stand-in Echo (`rhythm echo conformance`) that a connector's end-to-end test points at. It validates every capture it gets, refuses the bad ones, answers the rest like Echo and prints a pass or fail table when it stops.

Index

Constants

This section is empty.

Variables

View Source
var Scenarios = []Scenario{
	{"email", "an email reported before it is sent", func(c wire.Capture) bool { return c.Kind == "email" && c.Phase == "" }},
	{"email-after", "a real send's outcome reported after (observe)", func(c wire.Capture) bool { return c.Kind == "email" && c.Phase == wire.After }},
	{"http-before", "an HTTP request reported before it is sent", func(c wire.Capture) bool { return c.Kind == "http" && c.Phase == wire.Before }},
	{"http-after", "an allowed request's response reported after", func(c wire.Capture) bool { return c.Kind == "http" && c.Phase == wire.After }},
	{"run", "a capture tied to a run", func(c wire.Capture) bool { return c.Run != "" }},
	{"site", "a capture that names its site", func(c wire.Capture) bool { return c.Source.Site != "" }},
	{"attachments", "an email that lists its attachments", func(c wire.Capture) bool { return c.Email != nil && len(c.Email.Attachments) > 0 }},
	{"wire-1", "a capture in wire 1", func(c wire.Capture) bool { return c.Version == 1 }},
	{"wire-2", "a capture in wire 2", func(c wire.Capture) bool { return c.Version == 2 }},
}

Scenarios are what the stand-in recognizes in captures, for Expect and the report, in report order.

View Source
var Usage = `rhythm echo conformance: a strict stand-in Echo for a connector's end-to-end test

Usage:
  rhythm echo conformance [flags]

Runs a strict stand-in Echo for a connector's end-to-end test. Point the
connector at it (RHYTHM_ECHO_URL), run the test, then stop it (Ctrl-C or
SIGTERM): it prints a pass or fail table and exits 1 on any fail. Every
capture is checked against Echo's wire schema; a bad one is answered 400
with what is wrong. GET /v1/conformance returns the report so far as JSON.

Flags:
      --listen <addr>    API address (default 127.0.0.1:8025)
      --smtp <addr>      also run Echo's SMTP sink there (default off)
      --mode <m>         seal (default) or observe
      --token <t>        require this X-Echo-Token
      --allow <hosts>    hosts reachable when sealed, comma separated
      --wire <n>         speak this wire version, to check a connector falls back (default ` + strconv.Itoa(wire.Version) + `)
      --expect <list>    scenarios the run must include, comma separated:
                         email, email-after, http-before, http-after, run, site,
                         attachments, wire-1, wire-2
      --json             print the report as JSON instead of a table

Exit codes: 0 every check passed, 1 a check failed, 2 usage error, 3 couldn't
listen.
` + flagtext.Footer

Usage is the help for `rhythm echo conformance`.

Functions

func Main

func Main(args []string, _ io.Reader, stdout, stderr io.Writer) int

Main runs the stand-in until SIGINT or SIGTERM, then prints its report. The exit code is 0 when every check passed, 1 when one failed, 2 for bad flags and 3 when it can't listen.

Types

type Options

type Options struct {
	Mode  string   // seal (default) or observe
	Token string   // required in X-Echo-Token when set
	Allow []string // hosts reachable when sealed
	// Wire is the wire version the stand-in speaks: 0 for this Echo's
	// (wire.Version), or an older one to check that a connector falls back.
	// Speaking 1 it says so in /v1/health and refuses newer captures the way
	// an Echo of that version does.
	Wire int
	// Expect lists the scenarios the run must include (see Scenarios); the
	// report fails each one no capture showed.
	Expect []string
}

Options configure the stand-in.

type Problem

type Problem struct {
	Problems []string        `json:"problems"` // each way it broke the schema
	Capture  json.RawMessage `json:"capture"`  // as the connector sent it
}

Problem is a capture the stand-in refused, with why.

type Report

type Report struct {
	OK       bool      `json:"ok"`       // no row failed
	Captures int       `json:"captures"` // how many arrived, valid or not
	Rows     []Row     `json:"rows"`
	Problems []Problem `json:"problems,omitempty"`
}

Report is what the stand-in saw: one row per check, then the refused captures.

func (Report) Table

func (r Report) Table(w io.Writer)

Table writes the report as a table, then each refused capture's problems.

type Row

type Row struct {
	Check  string `json:"check"`
	Result string `json:"result"`
	Detail string `json:"detail"`
}

Row is one line of the report. Result is pass, fail or info.

type Scenario

type Scenario struct {
	Name  string                  // the ID Options.Expect lists and the report names
	About string                  // what it is, for the report
	Match func(wire.Capture) bool // whether a capture is one
}

Scenario is one kind of capture the stand-in recognizes.

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

Schema validates documents against a JSON Schema in the subset conformance/gen writes: type, properties, required, additionalProperties, items, enum, minimum, maximum, $ref to $defs and x-since (the wire version that added a field).

func ParseSchema

func ParseSchema(b []byte) (*Schema, error)

ParseSchema reads a schema.

func WireSchema

func WireSchema() (*Schema, error)

WireSchema is the schema for the wire protocol this Echo speaks.

func (*Schema) Capture

func (s *Schema) Capture(doc []byte) []string

Capture returns what is wrong with a capture, as "path: problem" lines; none means it follows the protocol. Fields newer than the capture's own "v" count as problems: a connector talking to an older Echo must leave them out.

func (*Schema) Decision

func (s *Schema) Decision(doc []byte) []string

Decision returns what is wrong with Echo's answer to a capture.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the strict stand-in: Echo's real catcher behind a check of every capture against the wire schema.

func New

func New(o Options) (*Server, error)

New returns a stand-in.

func (*Server) Catcher

func (s *Server) Catcher() *catcher.Server

Catcher is the Echo behind the stand-in, for its SMTP sink and inbox.

func (*Server) Report

func (s *Server) Report() Report

Report sums up the captures so far.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP answers like Echo, with captures checked first. It also serves the report at GET /v1/conformance.

Directories

Path Synopsis
cmd
conformance command
Command conformance runs Echo's strict stand-in on its own, for the connectors' end-to-end tests until `rhythm echo conformance` exists:
Command conformance runs Echo's strict stand-in on its own, for the connectors' end-to-end tests until `rhythm echo conformance` exists:
Command gen writes wire/schema.json, Echo's wire protocol as a JSON Schema, from the Go types in package wire.
Command gen writes wire/schema.json, Echo's wire protocol as a JSON Schema, from the Go types in package wire.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL