Skip to content

test: contract tests against the providers' official specs and opt-in live suites - #15

Merged
Schero94 merged 8 commits into
mainfrom
test/provider-contracts
Nov 20, 2026
Merged

Schero94 merged 8 commits into
mainfrom
test/provider-contracts

Conversation

@Schero94

Copy link
Copy Markdown
Owner

Stacked on #13 (base fix/provider-audit; GitHub retargets it to main when #13 is merged). The contract tests assert the fixed behaviour from #13.

Contract tests (offline, part of npm test)

tests/contract-{meta,twilio,seven,telegram}.test.js capture every adapter request in memory and validate it against the provider's own pinned specification; the specs' examples are fed back through the adapters and webhook handlers.

Provider Official source (pinned in tests/contract/specs/)
Meta facebook/openapi business-messaging-api_v23.0.yaml @ e96a1c9d + sha256
Twilio twilio/twilio-oai tag 2.11.1 (api_v2010, lookups_v2, content_v1) + sha256; Twilio's own signature test vector from twilio-node
seven.io seven-io/api-schemes json/openapi.json @ 0c976749 + sha256; webhook examples from docs.seven.io
Telegram no OpenAPI exists: method/type tables of core.telegram.org/bots/api (Bot API 10.4) converted to JSON Schema

npm run contract:specs rebuilds the snapshots, -- --check reports upstream changes (network, maintainer only). Dependency-free validator in tests/contract/validator.js; yaml (maintained, already in the lockfile) added as a dev dependency for the Meta YAML.

Found by the contract tests:

  • fix(meta): the official spec requires template.language.policy → MessageGate now sends "deterministic" (separate fix commit).
  • Defects in the official specs themselves (Meta button index pattern, missing copy_code sub_type, incoming webhook schemas inheriting outgoing required fields; Twilio twilio/card missing body, Lookup fields not nullable; seven.io example sender invalid). Each is listed with evidence in docs/contract-tests.md and ignored explicitly; every other error fails.

Live suites (npm run test:live, never in CI)

tests/live/{telegram,twilio,meta,seven}.live.test.js, modelled on Magic Mail's suites. Credentials only from ~/.config/magic-messagegate-live/.env (mode 600 enforced), never printed; request log masks tokens/SIDs/numbers; host allowlist. LIVE_PROVIDERS selects providers. Safe by default (Twilio test credentials + magic numbers through the full send path, Meta test number, own Telegram chat, seven.io balance only). Paid sends (LIVE_ALLOW_PAID=1), webhook changes (LIVE_WEBHOOKS=1, cloudflared quick tunnel) and owner interaction (LIVE_INTERACTIVE=1) each need a switch; webhook tests restore what they change (Telegram webhook, Meta number-level override, seven.io hooks created/deleted by id, Twilio per-message callback). Keys per provider: docs/live-tests.md.

Not run live yet: no credentials file exists on the maintainer machine. Without it all 24 live tests skip with the reason. The harness itself is tested offline (tests/live-harness.test.js), and the tunnel path was checked manually: a seven.io-signed DLR posted to the public trycloudflare.com URL → 200, unsigned → 401.

Local: lint, format:check, npm test 201 pass (twice), test:admin, build, verify, npm pack --dry-run (30 files, no tests/specs shipped).

🤖 Generated with Claude Code

Schero94 and others added 6 commits November 20, 2026 00:30
Audit of the Meta, Twilio, seven.io and Telegram adapters against the
providers' official specs and docs (docs/audits/2026-11-20-provider-apis.md).

- seven.io: tell the owner to use the JSON webhook request method and log
  signed non-JSON webhooks instead of dropping them silently; cut SMS at
  the documented 1520 characters; map 101/500/501/407004 correctly; read
  sms_mo Unix timestamps and the HLR roaming object.
- Twilio: 21610 and OptOutType=STOP revoke consent; 21611 is transient.
- Telegram: never cut the HTML text inside an entity.
- Follow api.rest.prefix for webhook URLs, status callbacks, file links and
  the raw-body middleware.
- Keep surrogate pairs whole when cutting text; honour HTTP-date
  Retry-After.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Meta's official OpenAPI (facebook/openapi business-messaging-api_v23.0.yaml)
requires template.language.policy; "deterministic" is its only value.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… add opt-in live suites

- tests/contract-*.test.js (offline, in npm test): requests, responses and
  webhooks checked against Meta's facebook/openapi, Twilio's twilio-oai,
  seven.io's api-schemes and the Telegram Bot API tables, pinned in
  tests/contract/specs by scripts/contract-specs.mjs (commit + sha256 for
  the OpenAPI sources). Known defects of the official specs are listed and
  ignored explicitly.
- tests/live/*.live.test.js (npm run test:live, never in CI): Telegram,
  Twilio test credentials, Meta test number, seven.io; credentials only from
  ~/.config/magic-messagegate-live/.env (mode 600); paid sends, webhook
  changes and interactive steps behind their own switches; webhook end to
  end through a cloudflared tunnel with restore.
- yaml (maintained, already in the tree) as a dev dependency for the Meta
  spec.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Base automatically changed from fix/provider-audit to main November 20, 2026 00:10
@Schero94
Schero94 merged commit fa36efd into main Nov 20, 2026
16 checks passed
@Schero94
Schero94 deleted the test/provider-contracts branch November 20, 2026 00:16
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