chadtmiller.com/monolith
An atproto PDS
0
0
// Starts a server and runs MCP's conformance suite against its `/mcp`
// endpoint, anonymously, for the scenarios that need none of the suite's own
// test tools: the modern revision's, and the legacy ones of 2025-11-25,
// which the endpoint serves beside it (spec/COMMANDS.md, "The MCP
// endpoint"). `conformance.yaml` names the checks within them that do.
//
// node conformance.mjs -- <pds> serve
import { spawn } from 'node:child_process'
import { mkdtempSync, openSync } from 'node:fs'
import { createServer } from 'node:net'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { TestPlc } from '@atproto/dev-env'
import { serverEnv } from './lib/env.mjs'
/// Each scenario, with the revision whose requirements it is run against.
const SCENARIOS = [
...['server-stateless', 'tools-list', 'caching', 'dns-rebinding-protection', 'http-header-validation'].map((s) => [s, '2026-07-28']),
...['server-initialize', 'server-session-lifecycle', 'ping', 'tools-list', 'dns-rebinding-protection'].map((s) => [s, '2025-11-25']),
]
const dash = process.argv.indexOf('--')
if (dash === -1 || dash === process.argv.length - 1) {
console.error('usage: node conformance.mjs -- <server command...>')
process.exit(2)
}
const command = process.argv.slice(dash + 1)
const port = await new Promise((ok) => {
const s = createServer()
s.listen(0, '127.0.0.1', () => {
const { port } = s.address()
s.close(() => ok(port))
})
})
// The server starts with no accounts, and makes none here, but is given a
// PLC directory as it always is.
const plc = await TestPlc.create({})
const dataDir = mkdtempSync(join(tmpdir(), 'pds-conformance-'))
const logPath = join(dataDir, 'server.log')
const { env } = await serverEnv({ port, dataDir, plc: plc.url })
const server = spawn(command[0], command.slice(1), {
env: { ...process.env, ...env },
stdio: ['ignore', openSync(logPath, 'a'), openSync(logPath, 'a')],
})
const url = `http://127.0.0.1:${port}`
const started = Date.now()
for (;;) {
try {
if ((await fetch(`${url}/xrpc/com.atproto.server.describeServer`)).ok) break
} catch {}
if (Date.now() - started > 30_000 || server.exitCode !== null) {
console.error(`the server did not start; its log is ${logPath}`)
server.kill()
await plc.close()
process.exit(1)
}
await new Promise((ok) => setTimeout(ok, 20))
}
let failed = []
for (const [scenario, version] of SCENARIOS) {
const run = spawn(
'npx',
['conformance', 'server', '--url', `${url}/mcp`, '--scenario', scenario, '--spec-version', version, '--expected-failures', new URL('conformance.yaml', import.meta.url).pathname],
{ stdio: 'inherit', cwd: new URL('.', import.meta.url).pathname },
)
const code = await new Promise((ok) => run.on('exit', ok))
if (code !== 0) failed.push(`${scenario} (${version})`)
}
// The MCP issuer's metadata (spec/OAUTH-MCP.md, "Metadata"), as the suite
// holds an authorization server's; its code grant needs a person at a
// browser.
const auth = spawn('npx', ['conformance', 'authorization', '--url', `${url}/oauth/mcp`, '--scenario', 'authorization-server-metadata-endpoint'], { stdio: 'inherit', cwd: new URL('.', import.meta.url).pathname })
if ((await new Promise((ok) => auth.on('exit', ok))) !== 0) failed.push('authorization-server-metadata-endpoint (the MCP issuer)')
server.kill()
await plc.close()
console.error(failed.length ? `\nfailed: ${failed.join(', ')} (server log: ${logPath})` : `\nall ${SCENARIOS.length + 1} scenarios pass`)
process.exit(failed.length ? 1 : 0)