~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

harness: the compatibility check kept apart from the checks the gates run

Merged chadtmiller.com asked to merge into main from chadtmiller.com/monolith:compat-isolation
compat/README.md+40−9
@@ -3,7 +3,7 @@
`harness/compat.mjs` checks how closely a PDS behaves like the reference
(`@atproto/pds`, the version `harness/package-lock.json` pins), area by
area. It runs the core of `harness/compare.mjs`'s checks against any
implementation that has an adapter in `harness/lib/adapters.mjs`: the same
implementation that has an adapter in `harness/lib/adapters/`: the same
random requests to the server and to a reference beside it, their answers
compared as `compare.mjs` compares them. Unlike `compare.mjs`, it keeps going
past a difference: each area records its checks that agree and that differ,
@@ -116,9 +116,11 @@ and both answers, as `compare.mjs` prints them.
## The adapters
`harness/lib/adapters.mjs` has an adapter per implementation; `compare.mjs
--impl <name>` picks one (spec-pds by default). An adapter says how to make
the server for the run's setup, and what it is:
`harness/lib/adapters/` has an adapter per implementation, a module each,
named in its `index.mjs`, and `common.mjs`, what they share (the server as
a process or a container, a rotation key, a browser's way through a form);
`compare.mjs --impl <name>` picks one (spec-pds by default). An adapter says
how to make the server for the run's setup, and what it is:
- `start(o)` makes the server for the setup `o` (port, data directory, PLC
directory, the reference's recovery key, crawlers, AppView, the web of
@@ -134,6 +136,14 @@ the server for the run's setup, and what it is:
- `pageApi`, or `signIn` (below).
- `own`: whether spec-pds's own rules hold it. Only spec-pds's does.
The checks read none of this. What a check may take of the server beyond
what the protocol says, it asks `harness/lib/server.mjs`: `own()`, whether
spec-pds's own rules hold it; `can(setting)`, whether it can be given a
setting `unsupported` names; `pageApi()`; and `issuer(side)`. Each answers
for spec-pds what the check did before it asked. What only a compatibility
run needs, as making a one-account server's account, is in
`harness/lib/areas.mjs`, the compatibility run itself, not in `checks/`.
**spec-pds**'s adapter is the harness as it always ran it: the command after
`--`, given the `PDS_*` environment `compare.mjs`'s header lists, its mail
read from `PDS_DEV_MAIL_DIR`, killed and restarted as a process.
@@ -252,15 +262,36 @@ those.
## Adding an implementation
`harness/checks/` is what spec-pds's gates run against the reference, and
adding an implementation must not change it for spec-pds: not one request,
and not one draw from the seeded source. So an implementation brings, in
order of preference:
1. an adapter, and the settings it cannot be given, with why (their checks
are skipped);
2. where it differs from what the harness assumes in a way the protocol
allows (one account, its own TLS), a capability in `spec/COMPAT.md`,
answered in `lib/server.mjs` or handled in `lib/areas.mjs`, the same for
every implementation that needs it, and as before for spec-pds;
3. and nothing else: a quirk of its own, which no protocol rule allows, is
a difference, or a check skipped, never a check bent around it.
No check names an implementation. A change of the second kind is shown to
leave spec-pds's runs as they were: `compare.mjs --tally <file>` writes how
many requests of each kind a run made, the same for two runs of one seed,
and a few seeds' tallies, before and after the change, are the same.
The steps:
1. Pin it in `bench/impls.json`, and give it a benchmark adapter
(`bench/README.md`) unless the benchmark's workload is not one it can
serve (pds.js, which hosts one account); put its Docker configuration in
`harness/lib/impls.mjs`.
2. Give it an adapter in `harness/lib/adapters.mjs`: `start`, `port`,
`info`, `unsupported` with why, `signIn` unless it serves the
reference's page API, `readyMs` if it starts slowly, and for a server
that hosts one account, `accounts` in `unsupported` and `password` and
`claim` from `start`.
2. Give it an adapter, a module of its own in `harness/lib/adapters/` named
in its `index.mjs`: `start`, `port`, `info`, `unsupported` with why,
`signIn` unless it serves the reference's page API, `readyMs` if it
starts slowly, and for a server that hosts one account, `accounts` in
`unsupported` and `password` and `claim` from `start`.
3. Add its name to `IMPLS` in `harness/compat.mjs`, and the differences its
documentation says are on purpose to `DELIBERATE` there.
4. `node compat.mjs --impls <name> --steps 60` to try it, then a full run.
harness/checks/accounts.mjs+5−39
@@ -9,6 +9,7 @@ import { COLLECTIONS, RKEYS, below, chance, goodRecord, pick, rand } from '../li
import { cand, ref } from '../lib/processes.mjs'
import { checkDidDoc, fail, plcLog } from '../lib/plc.mjs'
import { allow, count, differ } from '../lib/report.mjs'
import { own } from '../lib/server.mjs'
import { accounts, addAccount, didOf } from '../lib/state.mjs'
import { METHODS, commandLine, runCli, viaCommand, viaTool } from '../lib/via.mjs'
import { both, normalize, shown, xrpc, xrpcHttp } from '../lib/xrpc.mjs'
@@ -59,7 +60,7 @@ export const EDGE_BAD_EMAILS = [
/// A new account's handle, email and password: sometimes an email at the
/// edge of what is accepted; sometimes a password at the limit of 256 UTF-16
/// units, none, or an empty one, which is the same as none.
function newDetails(withPassword) {
export function newDetails(withPassword) {
const front = freshFront()
const r = rand()
const password = withPassword || r >= 0.2 ? (chance(0.1) ? pick([EMOJI.repeat(128), E_ACUTE.repeat(256)]) : `pw-${front}`) : r < 0.1 ? undefined : ''
@@ -74,7 +75,7 @@ function inputOf(d, mixed) {
}
/// Note the account both sides made from `body`, answered `a` and `b`.
const made = (body, a, b) =>
export const made = (body, a, b) =>
addAccount(
{ handle: a.body.handle, email: body.email.toLowerCase(), password: body.password },
{ reference: { did: a.body.did, token: a.body.accessJwt, refresh: a.body.refreshJwt }, server: { did: b.body.did, token: b.body.accessJwt, refresh: b.body.refreshJwt } },
@@ -128,8 +129,8 @@ async function checkNewAccount(acct, answers, body) {
const key = op.verificationMethods?.atproto
const kem = op.verificationMethods?.atproto_kem
const verificationMethods = { atproto: typeof key === 'string' && key.startsWith('did:key:') ? key : '<the signing key, a did:key>' }
if (side === cand && (cand.adapter.own || kem !== undefined)) verificationMethods.atproto_kem = isP256DidKey(kem) && kem !== key ? kem : '<the KEM key, a P-256 did:key other than the signing key>'
if (side === cand && !cand.adapter.own && kem !== undefined) allow('a KEM key (atproto_kem) in the genesis operation, as spec-pds\'s (spec/SPACES.md)')
if (side === cand && (own() || kem !== undefined)) verificationMethods.atproto_kem = isP256DidKey(kem) && kem !== key ? kem : '<the KEM key, a P-256 did:key other than the signing key>'
if (side === cand && !own() && kem !== undefined) allow('a KEM key (atproto_kem) in the genesis operation, as spec-pds\'s (spec/SPACES.md)')
const want = {
type: 'plc_operation',
verificationMethods,
@@ -152,41 +153,6 @@ export async function createFirstAccounts() {
for (let i = 2 + below(2); i > 0; i--) await createAccount({ withPassword: true })
}
/// The one account of a server that hosts one (spec/COMPAT.md, "One
/// account"): the reference makes it with createAccount, the server through
/// its adapter's `claim`, with the same handle and email and the password
/// the server was started with. Their answers are not compared, nor is the
/// server's genesis operation; the account's signing keys, and the server's
/// rotation key, are read from the PLC directory. Then it is checked as a
/// new account is, from getSession on. Answers the account, or null.
export async function claimAccount() {
const { handle, email } = newDetails(true)
const body = { handle, email, password: cand.password }
const [a, b] = await Promise.all([xrpc(ref, CREATE, { body }), cand.claim({ handle, email })])
count('createAccount (the server\'s one account)', a.status === 200 && b.status === 200)
if (a.status !== 200) await differ(CREATE, body, 'an account', a.body, 'the reference refuses an account the harness means to make')
if (b.status !== 200) await differ('the server\'s one account, made by its adapter', { handle, email }, 'an account', b.body, 'the adapter fails its own step')
if (a.status !== 200 || b.status !== 200) return null
const acct = made(body, a, b)
for (const side of [ref, cand]) {
const log = await plcLog(didOf(side, acct))
const op = Array.isArray(log.body) ? log.body[0] : null
if (!op) {
await fail(side, 'PLC log', shown({ body }), 'a genesis operation', log)
continue
}
acct.sides[side.name].key = op.verificationMethods?.atproto
if (side === cand) {
acct.sides[side.name].kem = op.verificationMethods?.atproto_kem
cand.rotationKey ??= op.rotationKeys?.[0]
}
}
await both('getSession of a new account', 'com.atproto.server.getSession', { token: acct })
await syncHeads(acct)
await checkRepo(acct)
return acct
}
/// Emails a new account may have although an account has had them: those
/// only accounts without a password had, which keep no email.
const freeEmails = () => accounts.filter((a) => !a.password && !accounts.some((b) => b.password && b.email === a.email)).map((a) => a.email)
harness/checks/blobs.mjs+3−2
@@ -15,6 +15,7 @@ import { COMMANDS } from '../lib/args.mjs'
import { RKEYS, below, chance, pick, rand } from '../lib/random.mjs'
import { cand, ref } from '../lib/processes.mjs'
import { count, differ } from '../lib/report.mjs'
import { own } from '../lib/server.mjs'
import { accounts, cids, didOf, exists, nextBatch, noteCommit, noteWrite, tokenOf } from '../lib/state.mjs'
import { runCli } from '../lib/via.mjs'
import { both, normalize, shown, xrpc } from '../lib/xrpc.mjs'
@@ -326,7 +327,7 @@ export async function uploadBlob(acct) {
bytes = make(Buffer.from(`spec-pds ${++serial}`))
sniffed = type
await sniffs(bytes, type)
} else if (r < 0.97 || !cand.adapter.own) {
} else if (r < 0.97 || !own()) {
bytes = Buffer.alloc(0)
} else {
bytes = bigBody(LIMIT + below(2))
@@ -343,7 +344,7 @@ export async function uploadBlob(acct) {
const u = await runCli(['repo', 'upload-blob'], { token: tokenOf(cand, acct), stdin: Buffer.from('x') })
if (u.code !== 2) await differ('pds repo upload-blob without --encoding', {}, 'a usage error: exit 2', { code: u.code, stdout: u.stdout.toString().slice(0, 200) })
}
if (cand.adapter.own && chance(0.05)) {
if (own() && chance(0.05)) {
const [da, db] = await Promise.all([ref, cand].map((side) => xrpc(side, 'com.atproto.server.describeServer')))
if (da.body?.blobUploadLimit !== LIMIT) throw new Error(`the reference's blobUploadLimit is ${da.body?.blobUploadLimit}, not ${LIMIT}`)
if (db.body?.blobUploadLimit !== LIMIT) await differ('describeServer blobUploadLimit', {}, LIMIT, db.body?.blobUploadLimit ?? null)
harness/checks/identity.mjs+3−2
@@ -13,6 +13,7 @@ import { checkDidDoc, fail, plcDocument, plcLog } from '../lib/plc.mjs'
import { count, differ } from '../lib/report.mjs'
import { accounts, didOf } from '../lib/state.mjs'
import { both, normalize, shown, strip, xrpcHttp } from '../lib/xrpc.mjs'
import { can, own } from '../lib/server.mjs'
import { DISALLOWED_TLDS, RESERVABLE, freshFront, mixCase } from './accounts.mjs'
const RESOLVE = 'com.atproto.identity.resolveHandle'
@@ -151,7 +152,7 @@ async function outsideOperation(acct) {
/// account had before. Sometimes after an operation the server did not
/// post.
export async function updateHandle(acct) {
if (chance(0.15) && acct.handles.server.length < 6 && !cand.adapter.unsupported.rotationKey) await outsideOperation(acct)
if (chance(0.15) && acct.handles.server.length < 6 && can('rotationKey')) await outsideOperation(acct)
const r = rand()
if (r < 0.15) return change(acct, mixCase(acct.handle), 'updateHandle to its own handle')
if (r < 0.3 && freed.length) return change(acct, pick(freed), 'updateHandle to a handle an account had')
@@ -277,7 +278,7 @@ export async function recommendedCredentials(acct) {
for (const [side, res] of [[ref, a], [cand, b]]) {
if (res.status !== 200) continue
const verificationMethods = { atproto: acct.sides[side.name].key }
if (side === cand && (cand.adapter.own || acct.sides[side.name].kem !== undefined)) verificationMethods.atproto_kem = acct.sides[side.name].kem
if (side === cand && (own() || acct.sides[side.name].kem !== undefined)) verificationMethods.atproto_kem = acct.sides[side.name].kem
const want = {
alsoKnownAs: [`at://${acct.handle}`],
verificationMethods,
harness/checks/lifecycle.mjs+2−1
@@ -22,7 +22,8 @@ import { createAccount, freshFront } from './accounts.mjs'
import { subscribe } from './firehose.mjs'
import { Browser, wwwError } from '../lib/oauth.mjs'
import { services } from '../lib/services.mjs'
import { approved, codeOf, exchange as oauthExchange, handleOf, issuer, loadPage, login as oauthLogin, token as tokenOn } from './oauth.mjs'
import { issuer } from '../lib/server.mjs'
import { approved, codeOf, exchange as oauthExchange, handleOf, loadPage, login as oauthLogin, token as tokenOn } from './oauth.mjs'
import { clientLogin, clientRequest, exchangeAndKeep, silent, standing } from './oauth-clients.mjs'
const S = 'com.atproto.server.'
harness/checks/logging.mjs+1−1
@@ -8,7 +8,7 @@
import { readFileSync } from 'node:fs'
import { server } from '../lib/processes.mjs'
import { OTLP_KEY } from '../lib/adapters.mjs'
import { OTLP_KEY } from '../lib/adapters/spec-pds.mjs'
import { now, secrets, sent, settled, tokenDids } from '../lib/observe.mjs'
import { count, differ } from '../lib/report.mjs'
import { accounts } from '../lib/state.mjs'
harness/checks/oauth-clients.mjs+3−2
@@ -18,8 +18,9 @@ import { count } from '../lib/report.mjs'
import { accounts, didOf } from '../lib/state.mjs'
import { HOSTS, ageReferenceCaches, fetchCount, serve } from '../lib/clients.mjs'
import { Browser, Dpop, b64u, fresh, newKey, pkce, signJwt } from '../lib/oauth.mjs'
import { can, issuer, pageApi } from '../lib/server.mjs'
import {
RENEW_AFTER_MS, URN, approve, codeOf, codesOf, compare, consent, dpops, exchange, getSessionBoth, handleOf, holdToken, issuer, loadPage, oauthOf, pageApi, par, redirectBoth, revokeOn, sides, signIn, token, tokenBody, view,
RENEW_AFTER_MS, URN, approve, codeOf, codesOf, compare, consent, dpops, exchange, getSessionBoth, handleOf, holdToken, loadPage, oauthOf, par, redirectBoth, revokeOn, sides, signIn, token, tokenBody, view,
} from './oauth.mjs'
const H = `https://${HOSTS[0]}`
@@ -235,7 +236,7 @@ export async function clientLogin(acct, c, { browsers, remember, prompt, hint, s
else if (own && remember === false) st.remembered = false
if (si.reference.json.ephemeralToken) bearer = { reference: si.reference.json.ephemeralToken, server: si.server?.json?.ephemeralToken }
}
const narrow = chance(0.15) && !cand.adapter.unsupported.narrowScope ? req.scope.filter((t) => t === 'atproto' || chance(0.5)).join(' ') : undefined
const narrow = chance(0.15) && can('narrowScope') ? req.scope.filter((t) => t === 'atproto' || chance(0.5)).join(' ') : undefined
const decided = await consent(acct, req, browsers, { scope: narrow, bearer, kind: `consent (${kind})` })
if (decided.reference.status !== 200 || !codesOf(decided)) return null
back = await redirectBoth(acct, req, browsers, { reference: decided.reference.json.url, server: decided.server?.json?.url }, { kind: `redirect (${kind})` })
harness/checks/oauth-limits.mjs+2−1
@@ -13,7 +13,8 @@ import { didOf, tokenOf } from '../lib/state.mjs'
import { API, Browser, Dpop, answer, form, fresh, newKey, pkce, signInCall, target, wwwError } from '../lib/oauth.mjs'
import { ownHost } from '../lib/services.mjs'
import { RESERVABLE, createAccount, freshFront } from './accounts.mjs'
import { handleOf, issuer, login } from './oauth.mjs'
import { issuer } from '../lib/server.mjs'
import { handleOf, login } from './oauth.mjs'
const sides = () => [ref, cand]
const REDIRECT = 'http://127.0.0.1/callback'
harness/checks/oauth-scopes.mjs+2−1
@@ -12,7 +12,8 @@ import { COLLECTIONS, RKEYS, below, chance, goodRecord, pick, rand } from '../li
import { accounts, cids, didOf, exists, nextBatch, noteCommit, noteKeys, noteWrite } from '../lib/state.mjs'
import { normalize } from '../lib/xrpc.mjs'
import { newKey, proof, wwwError } from '../lib/oauth.mjs'
import { DPOP_FAULTS, compare, dpops, freshNonce, handleOf, issuer, login, pickSession, sides } from './oauth.mjs'
import { issuer } from '../lib/server.mjs'
import { DPOP_FAULTS, compare, dpops, freshNonce, handleOf, login, pickSession, sides } from './oauth.mjs'
const REDIRECT = 'http://127.0.0.1/callback'
harness/checks/oauth.mjs+5−14
@@ -17,11 +17,9 @@ import { allow, count, differ } from '../lib/report.mjs'
import { accounts, didOf } from '../lib/state.mjs'
import { strip } from '../lib/xrpc.mjs'
import { API, Browser, Dpop, answer, b64u, form, formPost, fresh, newKey, pkce, proof, sha256, signJwt, target, wwwError } from '../lib/oauth.mjs'
import { can, issuer, own, pageApi } from '../lib/server.mjs'
export const sides = () => [ref, cand]
/// The side's OAuth issuer: its public URL's origin, unless its adapter
/// names another (lib/adapters.mjs).
export const issuer = (side) => new URL(side.issuer ?? side.publicUrl).origin
const URN = 'urn:ietf:params:oauth:request_uri:'
const REDIRECT = 'http://127.0.0.1/callback'
const DEFAULT_REDIRECTS = ['http://127.0.0.1/', 'http://[::1]/']
@@ -89,13 +87,6 @@ export async function compare(kind, request, send, show) {
return { reference: a, server: b }
}
/// Whether the server signs in through the reference's page API
/// (`/@atproto/oauth-provider/~api/*`), as spec-pds does. Without it, it
/// has a sign-in hook (lib/adapters.mjs): the reference's page, its API and
/// its answers are then the reference's alone, not compared, and only the
/// redirect to the client is (`redirectBoth`).
export const pageApi = () => cand.adapter.pageApi
/// A step of the reference's page API: compared on both sides as `compare`
/// compares, when the server has the page API; on the reference alone when
/// it has a sign-in hook instead, its `server` answer then undefined.
@@ -241,7 +232,7 @@ export async function checkOAuthMetadata() {
}
const sm = as.server.body ?? {}
const extra = Object.keys(sm).filter((k) => k.startsWith('request_object_'))
if (cand.adapter.own && (sm.request_parameter_supported !== false || extra.length)) await fail(cand, 'authorization server metadata (spec/OAUTH.md)', { get: '/.well-known/oauth-authorization-server' }, { request_parameter_supported: false }, { request_parameter_supported: sm.request_parameter_supported, ...(extra.length ? { extra } : {}) })
if (own() && (sm.request_parameter_supported !== false || extra.length)) await fail(cand, 'authorization server metadata (spec/OAUTH.md)', { get: '/.well-known/oauth-authorization-server' }, { request_parameter_supported: false }, { request_parameter_supported: sm.request_parameter_supported, ...(extra.length ? { extra } : {}) })
await compare('JWKS', { get: '/oauth/jwks' }, async (side) => answer(await fetch(`${issuer(side)}/oauth/jwks`)),
(side, r) => ({ status: r.status, cors: corsOf(r.headers), keys: Array.isArray(r.body?.keys) }))
for (const path of ['/.well-known/oauth-authorization-server', '/oauth/jwks', '/oauth/par', '/oauth/token', '/oauth/revoke']) {
@@ -396,7 +387,7 @@ async function holdToken(side, acct, res, request) {
const [lo, hi] = TOKEN_LIFE[side.name]
const bad = []
const within = ([l, h]) => b.expires_in >= l && b.expires_in <= h
if (side === cand && !cand.adapter.own && !within(TOKEN_LIFE.server) && within(TOKEN_LIFE.reference)) allow('OAuth access tokens of the reference\'s 60 minutes, not spec/OAUTH.md\'s 15')
if (side === cand && !own() && !within(TOKEN_LIFE.server) && within(TOKEN_LIFE.reference)) allow('OAuth access tokens of the reference\'s 60 minutes, not spec/OAUTH.md\'s 15')
else if (!within([lo, hi])) bad.push(`expires_in ${b.expires_in}, not ${lo} to ${hi}`)
// A client without the refresh_token grant is given none
// (spec/OAUTH-CLIENTS.md); whether there is one is compared.
@@ -436,7 +427,7 @@ export async function login(acct, { client, reject = chance(0.08), narrow = chan
if (chance(0.2)) await loadPage(req, st.browsers, 'authorization page after sign-in')
}
let scope
if (narrow && !cand.adapter.unsupported.narrowScope) {
if (narrow && can('narrowScope')) {
const kept = req.scope.filter((t) => ['atproto', 'transition:email', 'transition:generic', 'transition:chat.bsky', 'repo:*', 'blob:image/*', 'account:email?action=manage', 'identity:handle', 'rpc:app.bsky.feed.getTimeline?aud=*'].includes(t))
let picked = kept.filter((t) => (t === 'atproto' ? chance(0.9) : chance(0.5)))
// The narrowed scope's order depends on how many tokens `scope` names,
@@ -703,7 +694,7 @@ const PAR_FAULTS = [
/// One PAR with one thing wrong, on both sides with a fresh nonce.
export async function oauthParRefused() {
const [name, change] = pick(cand.adapter.own ? PAR_FAULTS : PAR_FAULTS.filter(([n]) => !n.includes('100 KiB')))
const [name, change] = pick(own() ? PAR_FAULTS : PAR_FAULTS.filter(([n]) => !n.includes('100 KiB')))
const p = basePar()
change(p)
const d = dpops(await newKey())
harness/checks/operations.mjs+1−1
harness/checks/pages.mjs+2−1
harness/checks/proxy.mjs+2−1
harness/checks/session.mjs+2−1
harness/lib/adapters/common.mjsnew+145−0
harness/lib/adapters/index.mjsnew+58−0
harness/lib/adapters/pds.js.mjsnew+86−0
harness/lib/adapters/spec-pds.mjsnew+75−0
harness/lib/adapters/vlpds.mjsnew+95−0
harness/lib/adapters/zds.mjsnew+83−0
harness/lib/adapters.mjsdeleted+0−500
500 lines changed: not loaded until asked for.
harness/lib/areas.mjs+47−8
harness/lib/args.mjs+7−2
harness/lib/impls.mjs+1−1
harness/lib/mail.mjs+1−1
harness/lib/processes.mjs+3−3
harness/lib/report.mjs+18−1
harness/lib/server.mjsnew+28−0
harness/compare.mjs+4−1
harness/compat.mjs+1−1
AGENTS.md+5−1
README.md+1−1