@getcirrus/space-conformance 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/base-D8a-ZK57.d.ts +249 -0
  2. package/dist/base-D8a-ZK57.d.ts.map +1 -0
  3. package/dist/cli.d.ts +1 -0
  4. package/dist/cli.js +373 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/coverage-DhJZu8P8.js +1914 -0
  7. package/dist/coverage-DhJZu8P8.js.map +1 -0
  8. package/dist/full-D4ufJLcw.js +409 -0
  9. package/dist/full-D4ufJLcw.js.map +1 -0
  10. package/dist/full.d.ts +59 -0
  11. package/dist/full.d.ts.map +1 -0
  12. package/dist/full.js +4 -0
  13. package/dist/index.d.ts +178 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +114 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/operator-BErXCDow.js +923 -0
  18. package/dist/operator-BErXCDow.js.map +1 -0
  19. package/lexicons/MANIFEST.json +7 -0
  20. package/lexicons/simplespace/addMember.json +37 -0
  21. package/lexicons/simplespace/checkUserAccess.json +43 -0
  22. package/lexicons/simplespace/createSpace.json +74 -0
  23. package/lexicons/simplespace/defs.json +47 -0
  24. package/lexicons/simplespace/deleteSpace.json +32 -0
  25. package/lexicons/simplespace/getSpace.json +53 -0
  26. package/lexicons/simplespace/listMembers.json +65 -0
  27. package/lexicons/simplespace/removeMember.json +37 -0
  28. package/lexicons/simplespace/updateSpace.json +57 -0
  29. package/lexicons/space/applyWrites.json +163 -0
  30. package/lexicons/space/createRecord.json +79 -0
  31. package/lexicons/space/defs.json +38 -0
  32. package/lexicons/space/deleteRecord.json +51 -0
  33. package/lexicons/space/getBlob.json +54 -0
  34. package/lexicons/space/getDelegationToken.json +34 -0
  35. package/lexicons/space/getLatestCommit.json +57 -0
  36. package/lexicons/space/getRecord.json +76 -0
  37. package/lexicons/space/getRepo.json +41 -0
  38. package/lexicons/space/getSpaceCredential.json +67 -0
  39. package/lexicons/space/listBlobs.json +59 -0
  40. package/lexicons/space/listRecords.json +108 -0
  41. package/lexicons/space/listRepoOps.json +111 -0
  42. package/lexicons/space/listRepos.json +75 -0
  43. package/lexicons/space/listSpaces.json +65 -0
  44. package/lexicons/space/notifySpaceDeleted.json +24 -0
  45. package/lexicons/space/notifyWrite.json +38 -0
  46. package/lexicons/space/putRecord.json +75 -0
  47. package/lexicons/space/registerNotify.json +49 -0
  48. package/lexicons/space/unregisterNotify.json +29 -0
  49. package/package.json +53 -0
@@ -0,0 +1,249 @@
1
+ //#region src/model.d.ts
2
+ /**
3
+ * The check model.
4
+ *
5
+ * A check is a black-box probe of a live spaces implementation: an async
6
+ * function over a transport, plus machine-readable metadata that says what
7
+ * it tests, on whose authority, and what it needs from the harness.
8
+ *
9
+ * Tiers, and why they matter: a conformance suite that fails
10
+ * implementations on its author's opinions poisons its own authority.
11
+ * Every `must` check cites specified behavior — a lexicon shape, a
12
+ * declared error name, a requirement in the proposal or the upstream PDS
13
+ * design spec. `should` checks encode reference-implementation behavior
14
+ * the spec leaves open, and are calibrated by running this suite against
15
+ * the reference: a `should` the reference fails is stale by definition.
16
+ * `info` checks report implementation choices and never fail anyone.
17
+ */
18
+ type Tier = "must" | "should" | "info";
19
+ /** Where a check's claim comes from. Every `must` check needs at least one. */
20
+ interface Citation {
21
+ /** e.g. "lexicon", "proposal", "pds-design-spec", "reference" */
22
+ source: "lexicon" | "proposal" | "pds-design-spec" | "reference";
23
+ /**
24
+ * Locator within the source: a lexicon id (optionally `#def` or
25
+ * `@error:Name`), a proposal section anchor, or a design-spec heading.
26
+ * Lexicon locators are machine-checked by the coverage generator.
27
+ */
28
+ ref: string;
29
+ }
30
+ /**
31
+ * What the harness must supply for a check to run. A runner skips (and
32
+ * reports as "not testable") any check whose needs it cannot meet.
33
+ *
34
+ * - `operator`: an authenticated session on the target (any full-access
35
+ * scheme; how it was obtained is the harness's business).
36
+ * - `oauth-session`: specifically an OAuth-granted session with `space:`
37
+ * scopes — only harnesses that can drive the target's consent flow.
38
+ * - `identities`: harness-controlled DIDs with resolvable documents and
39
+ * held keys, for playing reader/writer roles.
40
+ * - `syncer-inbox`: an HTTPS endpoint the harness controls that the
41
+ * target can deliver notifications to.
42
+ * - `pds-blobs`: the target is a full PDS implementing
43
+ * `com.atproto.repo.uploadBlob` and `com.atproto.sync.getBlob` — needed
44
+ * to prove a space blob is not served publicly. A standalone space host,
45
+ * or an isolated space-routes fixture, does not provide it.
46
+ * - `pds-delegation`: the target implements
47
+ * `com.atproto.space.getDelegationToken`, so the operator can obtain a
48
+ * credential for its own space (the bulletin self-flow) with no
49
+ * harness-held reader key. A space-routes fixture does not provide it.
50
+ * - `alpha-libs`: the transport can execute the alpha crypto libraries
51
+ * (`@atproto/space`), whose bundle pulls node-only dependencies. Real
52
+ * checks never declare it — importing the full entry implies it — but
53
+ * the browser catalog's metadata stubs do, so a browser harness (which
54
+ * never declares it) reports them "not testable here" instead of
55
+ * running a stub.
56
+ */
57
+ type Capability = "operator" | "oauth-session" | "identities" | "syncer-inbox" | "pds-blobs" | "pds-delegation" | "alpha-libs";
58
+ type CheckStatus = "pass" | "fail" | "skipped" | "error";
59
+ interface CheckResult {
60
+ id: string;
61
+ tier: Tier;
62
+ status: CheckStatus;
63
+ /** One line: what was observed, or why skipped/errored. */
64
+ detail: string;
65
+ citations: Citation[];
66
+ /** Optional request/response evidence for the report. */
67
+ evidence?: unknown;
68
+ durationMs?: number;
69
+ }
70
+ /** An identity the harness controls: a resolvable DID plus its keys. */
71
+ interface HarnessIdentity {
72
+ did: string;
73
+ /** Sign bytes with the identity's atproto signing key (ES256K/ES256). */
74
+ sign(bytes: Uint8Array): Promise<Uint8Array>;
75
+ /** JWT `alg` for {@link sign}. */
76
+ jwtAlg: string;
77
+ }
78
+ /** A DPoP key the harness controls (always ES256, per the proposal). */
79
+ interface DpopKey {
80
+ bareJwk: Record<string, unknown>;
81
+ /** Algorithms the key supports; `["ES256"]` for DPoP. */
82
+ algorithms: readonly string[];
83
+ /** RFC 7638 thumbprint of {@link bareJwk}. */
84
+ jkt: string;
85
+ createJwt(header: Record<string, unknown>, payload: Record<string, unknown>): Promise<string>;
86
+ }
87
+ interface IdentityProvider {
88
+ /** Mint (or reuse) a harness identity by role label. */
89
+ identity(role: string): Promise<HarnessIdentity>;
90
+ /** Mint a fresh DPoP key. */
91
+ dpopKey(): Promise<DpopKey>;
92
+ }
93
+ interface SyncerInbox {
94
+ /** The service identifier to register (did, optionally with #fragment). */
95
+ service: string;
96
+ /** Wait for a delivery matching the predicate, or time out (null). */
97
+ waitFor(predicate: (delivery: InboxDelivery) => boolean, timeoutMs: number): Promise<InboxDelivery | null>;
98
+ }
99
+ interface InboxDelivery {
100
+ lxm: string;
101
+ body: unknown;
102
+ authorization?: string;
103
+ receivedAt: number;
104
+ }
105
+ /** Description of the implementation under test. */
106
+ interface Target {
107
+ /** Public origin, e.g. https://pds.example.com */
108
+ origin: string;
109
+ /** The DID whose repos / spaces the target serves. */
110
+ did: string;
111
+ /** Free-form implementation label for the report ("cirrus", "reference"). */
112
+ implementation?: string;
113
+ }
114
+ interface CheckContext {
115
+ target: Target;
116
+ fetch: typeof fetch;
117
+ /**
118
+ * Present when the harness has an authenticated session on the target.
119
+ * Provide `authorize` when auth is plain header injection (a bearer
120
+ * token), or `fetch` when each request must be individually signed — a
121
+ * DPoP-bound OAuth session, where the proof depends on the method and
122
+ * URL, cannot be expressed as headers alone. At least one is required;
123
+ * `fetch` wins when both are present.
124
+ */
125
+ operator?: {
126
+ /** Add auth to a request (header injection). */
127
+ authorize?(init: RequestInit & {
128
+ headers: Headers;
129
+ }): Promise<void>;
130
+ /** A fetch that carries the operator's credentials on every request. */
131
+ fetch?: typeof fetch;
132
+ /** True when this session came from an OAuth grant with space: scopes. */
133
+ oauth: boolean;
134
+ };
135
+ identities?: IdentityProvider;
136
+ syncerInbox?: SyncerInbox;
137
+ /**
138
+ * Scratch space shared across checks in one run — e.g. the probe space
139
+ * a setup check created, reused by later checks. Keys are namespaced by
140
+ * convention (`"probe.space.uri"`).
141
+ */
142
+ state: Map<string, unknown>;
143
+ /** Structured logging into the run report. */
144
+ log(message: string): void;
145
+ }
146
+ interface Check {
147
+ id: string;
148
+ title: string;
149
+ tier: Tier;
150
+ citations: Citation[];
151
+ needs: Capability[];
152
+ /** Creates or deletes state on the target (probe spaces, records). */
153
+ destructive?: boolean;
154
+ /** Depends on real time passing (expiry windows); excluded by default. */
155
+ slow?: boolean;
156
+ run(ctx: CheckContext): Promise<CheckOutcome>;
157
+ }
158
+ /** What a check's run() returns; the runner wraps it into a CheckResult. */
159
+ interface CheckOutcome {
160
+ status: "pass" | "fail";
161
+ detail: string;
162
+ evidence?: unknown;
163
+ }
164
+ declare const pass: (detail: string, evidence?: unknown) => CheckOutcome;
165
+ declare const fail: (detail: string, evidence?: unknown) => CheckOutcome;
166
+ //#endregion
167
+ //#region src/dpop.d.ts
168
+ /**
169
+ * WebCrypto ES256 DPoP key implementing the minimal surface a DPoP proof
170
+ * needs (`bareJwk`, `algorithms`, `createJwt`) plus the RFC 7638
171
+ * thumbprint. Hand-rolled to avoid `@atproto/jwk-jose`, whose bundled jose
172
+ * resolves to its Node build under the workers test pool and cannot sign.
173
+ */
174
+ declare function createDpopKey(): Promise<DpopKey>;
175
+ /**
176
+ * An RFC 9449 DPoP proof over `key`, matching the reference verifier:
177
+ * header `{alg, typ: "dpop+jwt", jwk}`; claims `jti` (random), `htm`,
178
+ * `htu` (query and fragment stripped, RFC 9449 §4.2), `iat`, and — only
179
+ * when presenting a credential — `ath`, the base64url SHA-256 of it.
180
+ */
181
+ declare function createDpopProofJwt(key: DpopKey, opts: {
182
+ htm: string;
183
+ htu: string;
184
+ credential?: string;
185
+ }): Promise<string>;
186
+ //#endregion
187
+ //#region src/http.d.ts
188
+ declare function xrpcUrl(origin: string, nsid: string, params?: Record<string, string | undefined>): string;
189
+ interface XrpcResult {
190
+ status: number;
191
+ /** Parsed JSON body, or undefined for non-JSON responses. */
192
+ json?: unknown;
193
+ /** The atproto `error` name, when the body carries one. */
194
+ error?: string;
195
+ headers: Headers;
196
+ response: Response;
197
+ }
198
+ /** GET an XRPC query. `headers` may carry auth. */
199
+ declare function xrpcGet(ctx: CheckContext, nsid: string, params?: Record<string, string | undefined>, headers?: HeadersInit): Promise<XrpcResult>;
200
+ /** POST an XRPC procedure with a JSON body. */
201
+ declare function xrpcPost(ctx: CheckContext, nsid: string, body: unknown, headers?: HeadersInit): Promise<XrpcResult>;
202
+ /** Add the operator's auth to a headers object, if a session is present. */
203
+ declare function operatorHeaders(ctx: CheckContext, extra?: HeadersInit): Promise<Headers>;
204
+ //#endregion
205
+ //#region src/checks/operator.d.ts
206
+ interface ProbeSpace {
207
+ uri: string;
208
+ type: string;
209
+ skey: string;
210
+ }
211
+ /**
212
+ * Create a probe space owned by the target and cache it for the run.
213
+ * Requires an operator session with space management authority.
214
+ */
215
+ declare function createProbeSpace(ctx: CheckContext, policy?: Record<string, unknown>, appAccess?: Record<string, unknown>): Promise<ProbeSpace>;
216
+ /** Delete a probe space, best-effort (cleanup). */
217
+ declare function deleteProbeSpace(ctx: CheckContext, space: string): Promise<void>;
218
+ /** Operator creates a record in a space; returns the response. */
219
+ declare function operatorCreateRecord(ctx: CheckContext, space: string, collection: string, rkey: string, record: Record<string, unknown>): Promise<XrpcResult>;
220
+ interface Credential {
221
+ credential: string;
222
+ dpopKey: DpopKey;
223
+ }
224
+ /**
225
+ * Obtain a credential the way a real app does: ask the target's own
226
+ * `getDelegationToken` (with the operator session) for a delegation token,
227
+ * then exchange it at `getSpaceCredential`. This is the bulletin self-flow
228
+ * — it needs no harness-held reader key, so it runs against any real PDS
229
+ * (Cirrus, the reference) and exercises the target's own token minting.
230
+ */
231
+ declare function obtainCredentialViaDelegation(ctx: CheckContext, space: string): Promise<{
232
+ result: XrpcResult;
233
+ credential?: Credential;
234
+ delegation: XrpcResult;
235
+ }>;
236
+ /** A credential-authenticated GET, with a fresh proof bound to the request. */
237
+ declare function credentialGet(ctx: CheckContext, credential: Credential, nsid: string, params: Record<string, string | undefined>): Promise<XrpcResult>;
238
+ /**
239
+ * The operator catalog: runnable anywhere the harness has an operator
240
+ * session — browser included.
241
+ */
242
+ declare const operatorChecks: Check[];
243
+ //#endregion
244
+ //#region src/checks/base.d.ts
245
+ /** Checks that need no crypto and no session — safe in any transport. */
246
+ declare const baseChecks: Check[];
247
+ //#endregion
248
+ export { Tier as A, Citation as C, InboxDelivery as D, IdentityProvider as E, pass as M, SyncerInbox as O, CheckStatus as S, HarnessIdentity as T, Capability as _, credentialGet as a, CheckOutcome as b, operatorChecks as c, operatorHeaders as d, xrpcGet as f, createDpopProofJwt as g, createDpopKey as h, createProbeSpace as i, fail as j, Target as k, operatorCreateRecord as l, xrpcUrl as m, Credential as n, deleteProbeSpace as o, xrpcPost as p, ProbeSpace as r, obtainCredentialViaDelegation as s, baseChecks as t, XrpcResult as u, Check as v, DpopKey as w, CheckResult as x, CheckContext as y };
249
+ //# sourceMappingURL=base-D8a-ZK57.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-D8a-ZK57.d.ts","names":[],"sources":["../src/model.ts","../src/dpop.ts","../src/http.ts","../src/checks/operator.ts","../src/checks/base.ts"],"sourcesContent":[],"mappings":";;AAiBA;AAGA;AAsCA;AASA;AAMA;;;;;AAaA;;;;;AASA;AACU,KA/EE,IAAA,GA+EF,MAAA,GAAA,QAAA,GAAA,MAAA;;AAOC,UAnFM,QAAA,CAmFN;EACP;EAAO,MAAA,EAAA,SAAA,GAAA,UAAA,GAAA,iBAAA,GAAA,WAAA;EAGM;;;;;EAIE,GAAA,EAAA,MAAA;AAGnB;;;;;AAUA;AAQA;AASA;;;;;;;;;;;AA+BA;;;;;;;;AAcA;AAMA;AAMa,KA5ID,UAAA,GA4I8C,UAAA,GAIxD,eAAA,GAAA,YAAA,GAAA,cAAA,GAAA,WAAA,GAAA,gBAAA,GAAA,YAAA;KAvIU,WA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AAA,UAAA,EGhBZ,UHgBY,EAAA,IAAA,EAAA,MAAA,EAAA,MAAA,EGdhB,MHcgB,CAAA,MAAA,EAAA,MAAA,GAAA,SAAA,CAAA,CAAA,EGbtB,OHasB,CGbd,UHac,CAAA;;AAIzB;AAMA;AAMA;cG6nBa,gBAAgB;;;;AHpvBT,cIqDP,UJrDO,EIqDK,KJrDL,EAAA"}
package/dist/cli.d.ts ADDED
@@ -0,0 +1 @@
1
+ export { };
package/dist/cli.js ADDED
@@ -0,0 +1,373 @@
1
+ #!/usr/bin/env node
2
+ import { b as filterCatalog } from "./operator-BErXCDow.js";
3
+ import { a as runChecks, i as renderReport, t as coverageReport } from "./coverage-DhJZu8P8.js";
4
+ import { n as KeypairIdentityProvider, t as fullCatalog } from "./full-D4ufJLcw.js";
5
+ import { parseArgs } from "node:util";
6
+ import { readFileSync, writeFileSync } from "node:fs";
7
+ import { fileURLToPath } from "node:url";
8
+ import { dirname, join } from "node:path";
9
+ import { createInterface } from "node:readline";
10
+ import { createServer } from "node:http";
11
+ import { spawn } from "node:child_process";
12
+ import { NodeOAuthClient } from "@atproto/oauth-client-node";
13
+
14
+ //#region src/cli/run.ts
15
+ /**
16
+ * The CLI's core: resolve a target, assemble a context from what the
17
+ * invocation can provide, run the catalog. Exported separately from the
18
+ * bin so it can be driven in tests against an injected fetch without
19
+ * spawning a process.
20
+ */
21
+ /** The alpha build the suite's verifiers are pinned to (from our deps). */
22
+ const ALPHA_BUILD = "0.0.0-spaces-alpha-20260818163953";
23
+ async function runConformance(options) {
24
+ const doFetch = options.fetch ?? fetch;
25
+ const origin = options.origin.replace(/\/+$/, "");
26
+ const did = options.did ?? await resolveDid(doFetch, origin);
27
+ let operatorToken = options.operatorToken;
28
+ if (!operatorToken && !options.operatorFetch && options.handle) {
29
+ if (!options.password) throw new Error("--handle needs a password: set SPACE_CONFORMANCE_PASSWORD in the environment (or use --oauth)");
30
+ operatorToken = await createSession(doFetch, origin, options.handle, options.password);
31
+ }
32
+ const capabilities = [];
33
+ if (operatorToken || options.operatorFetch) {
34
+ capabilities.push("operator");
35
+ if (!options.standaloneHost) capabilities.push("pds-blobs", "pds-delegation");
36
+ }
37
+ if (options.identities) capabilities.push("identities");
38
+ const context = {
39
+ target: {
40
+ origin,
41
+ did,
42
+ implementation: options.implementation
43
+ },
44
+ fetch: doFetch,
45
+ ...options.operatorFetch ? { operator: {
46
+ oauth: true,
47
+ fetch: options.operatorFetch
48
+ } } : operatorToken ? { operator: {
49
+ oauth: false,
50
+ async authorize(init) {
51
+ init.headers.set("Authorization", `Bearer ${operatorToken}`);
52
+ }
53
+ } } : {},
54
+ ...options.identities ? { identities: new KeypairIdentityProvider() } : {}
55
+ };
56
+ return runChecks({
57
+ catalog: filterCatalog(fullCatalog, {
58
+ tiers: options.tiers,
59
+ capabilities,
60
+ destructive: options.destructive,
61
+ slow: options.slow
62
+ }),
63
+ context,
64
+ suiteVersion: options.suiteVersion,
65
+ alphaBuild: ALPHA_BUILD
66
+ });
67
+ }
68
+ /**
69
+ * Sign in at the target and return the session's access token. This is the
70
+ * portable way to get operator auth: every standard PDS implements
71
+ * `com.atproto.server.createSession`, where a static bearer like Cirrus's
72
+ * AUTH_TOKEN is deployment-specific.
73
+ */
74
+ async function createSession(doFetch, origin, identifier, password) {
75
+ const res = await doFetch(`${origin}/xrpc/com.atproto.server.createSession`, {
76
+ method: "POST",
77
+ headers: { "Content-Type": "application/json" },
78
+ body: JSON.stringify({
79
+ identifier,
80
+ password
81
+ })
82
+ });
83
+ const body = await res.json().catch(() => ({}));
84
+ if (!res.ok || !body.accessJwt) throw new Error(`createSession failed for ${identifier} at ${origin}: ${res.status} ${body.error ?? ""} ${body.message ?? ""}`.trim());
85
+ return body.accessJwt;
86
+ }
87
+ async function resolveDid(doFetch, origin) {
88
+ const res = await doFetch(`${origin}/.well-known/did.json`);
89
+ if (!res.ok) throw new Error(`could not resolve target DID from ${origin}/.well-known/did.json (${res.status}); pass --did`);
90
+ const doc = await res.json();
91
+ if (!doc.id) throw new Error("did.json has no id; pass --did");
92
+ return doc.id;
93
+ }
94
+
95
+ //#endregion
96
+ //#region src/cli/oauth.ts
97
+ /**
98
+ * OAuth loopback sign-in for the CLI — the `gh auth login` shape: start an
99
+ * ephemeral 127.0.0.1 callback server, register as an atproto loopback
100
+ * client, open the authorization URL in the user's browser, and exchange
101
+ * the callback for a DPoP-bound session.
102
+ *
103
+ * This is the auth path that involves no password at all and works against
104
+ * any PDS with an atproto OAuth server. The session's tokens are DPoP-bound
105
+ * — unusable as a plain bearer — so the run authenticates through
106
+ * `operator.fetch`, with the client library signing every request (and
107
+ * handling nonce challenges) rather than a static header.
108
+ */
109
+ /**
110
+ * The scope the conformance run signs in with: generic repo access (for
111
+ * uploadBlob) plus full record actions and space management on the probe
112
+ * space type under the user's own authority. Mirrors the web checker.
113
+ */
114
+ const OAUTH_SCOPE = "atproto transition:generic space:app.bsky.group?collection=*&manage=create&manage=update&manage=delete";
115
+ /** How long to wait for the user to complete the browser flow. */
116
+ const CALLBACK_TIMEOUT_MS = 300 * 1e3;
117
+ /**
118
+ * A fetch that routes requests for `origin` through the session (which
119
+ * signs them) and everything else through the plain global fetch — the
120
+ * same shape as the web adapter, so checks keep their bare `ctx.fetch`
121
+ * for deliberately-anonymous requests.
122
+ */
123
+ function originGatedFetch(signing, origin) {
124
+ return (input, init) => {
125
+ const url = new URL(typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url);
126
+ if (url.origin === origin) return signing(url.pathname + url.search, init);
127
+ return fetch(input, init);
128
+ };
129
+ }
130
+ /** Open a URL in the platform browser, best-effort; never throws. */
131
+ function openBrowser(url) {
132
+ const [cmd, args] = process.platform === "darwin" ? ["open", [url]] : process.platform === "win32" ? ["cmd", [
133
+ "/c",
134
+ "start",
135
+ "",
136
+ url
137
+ ]] : ["xdg-open", [url]];
138
+ try {
139
+ spawn(cmd, args, {
140
+ stdio: "ignore",
141
+ detached: true
142
+ }).unref();
143
+ } catch {}
144
+ }
145
+ async function oauthSignIn(options) {
146
+ const log = options.log ?? (() => {});
147
+ let resolveParams;
148
+ let rejectParams;
149
+ const paramsPromise = new Promise((resolve, reject) => {
150
+ resolveParams = resolve;
151
+ rejectParams = reject;
152
+ });
153
+ const server = createServer((req, res) => {
154
+ const url = new URL(req.url ?? "/", "http://127.0.0.1");
155
+ if (url.pathname !== "/callback") {
156
+ res.writeHead(404).end();
157
+ return;
158
+ }
159
+ res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }).end("<!doctype html><meta charset=utf-8><title>space-conformance</title><p style='font:16px system-ui;margin:3em'>Signed in — you can close this tab and return to the terminal.</p>");
160
+ resolveParams(url.searchParams);
161
+ });
162
+ await new Promise((resolve) => server.listen(0, "127.0.0.1", resolve));
163
+ const address = server.address();
164
+ if (address === null || typeof address !== "object") {
165
+ server.close();
166
+ throw new Error("could not bind the OAuth callback server");
167
+ }
168
+ const redirectUri = `http://127.0.0.1:${address.port}/callback`;
169
+ const timer = setTimeout(() => {
170
+ rejectParams(/* @__PURE__ */ new Error(`timed out after ${CALLBACK_TIMEOUT_MS / 6e4} minutes waiting for the browser sign-in`));
171
+ }, CALLBACK_TIMEOUT_MS);
172
+ try {
173
+ const clientId = `http://localhost?${new URLSearchParams({
174
+ redirect_uri: redirectUri,
175
+ scope: OAUTH_SCOPE
176
+ }).toString()}`;
177
+ const stateStore = /* @__PURE__ */ new Map();
178
+ const sessionStore = /* @__PURE__ */ new Map();
179
+ const client = new NodeOAuthClient({
180
+ clientMetadata: {
181
+ client_id: clientId,
182
+ redirect_uris: [redirectUri],
183
+ scope: OAUTH_SCOPE,
184
+ token_endpoint_auth_method: "none",
185
+ grant_types: ["authorization_code", "refresh_token"],
186
+ response_types: ["code"],
187
+ dpop_bound_access_tokens: true
188
+ },
189
+ stateStore: {
190
+ set: async (key, value) => void stateStore.set(key, value),
191
+ get: async (key) => stateStore.get(key),
192
+ del: async (key) => void stateStore.delete(key)
193
+ },
194
+ sessionStore: {
195
+ set: async (key, value) => void sessionStore.set(key, value),
196
+ get: async (key) => sessionStore.get(key),
197
+ del: async (key) => void sessionStore.delete(key)
198
+ },
199
+ allowHttp: options.targetOrigin.startsWith("http://")
200
+ });
201
+ const authorizeUrl = await client.authorize(options.handle, { scope: OAUTH_SCOPE });
202
+ log(`Opening browser to authorize ${options.handle}…`);
203
+ log(`If it does not open, visit:\n ${authorizeUrl.toString()}`);
204
+ openBrowser(authorizeUrl.toString());
205
+ const params = await paramsPromise;
206
+ const { session } = await client.callback(params);
207
+ log(`Signed in as ${session.did}`);
208
+ return {
209
+ did: session.did,
210
+ fetch: originGatedFetch((pathname, init) => session.fetchHandler(pathname, init), options.targetOrigin),
211
+ signOut: () => sessionSignOut(session)
212
+ };
213
+ } finally {
214
+ clearTimeout(timer);
215
+ server.close();
216
+ }
217
+ }
218
+ async function sessionSignOut(session) {
219
+ try {
220
+ await session.signOut();
221
+ } catch {}
222
+ }
223
+
224
+ //#endregion
225
+ //#region src/cli/main.ts
226
+ /**
227
+ * space-conformance CLI.
228
+ *
229
+ * space-conformance run --target https://host [--did did:...] \
230
+ * [--handle alice.example.com] [--oauth] [--standalone-host] \
231
+ * [--destructive] [--tier must,should] [--report out.json] [--json]
232
+ * space-conformance coverage [--json]
233
+ *
234
+ * Operator auth (any one of):
235
+ * --oauth --handle you.example.com — browser sign-in via the atproto
236
+ * OAuth loopback flow; no password ever touches this process. Works
237
+ * against any PDS with an OAuth server.
238
+ * --handle + password — signs in via com.atproto.server.createSession;
239
+ * the password comes from SPACE_CONFORMANCE_PASSWORD or an interactive
240
+ * hidden prompt, never argv. Use the main password: app passwords are
241
+ * refused on space routes.
242
+ * SPACE_CONFORMANCE_TOKEN env — a bearer the target accepts (a session
243
+ * accessJwt, or a deployment-specific static token).
244
+ * --operator-token TOKEN — same, via argv; prefer the env var, since
245
+ * argv leaks into shell history and process listings.
246
+ *
247
+ * Exit code is non-zero when any `must` check fails or errors, so it
248
+ * gates CI.
249
+ */
250
+ /**
251
+ * Read a password from the terminal with echo suppressed. Only offered on
252
+ * a TTY — a piped stdin gets the env-var error instead, so scripts fail
253
+ * loudly rather than hanging on a prompt nobody sees.
254
+ */
255
+ function promptPassword(prompt) {
256
+ return new Promise((resolve, reject) => {
257
+ const stdin = process.stdin;
258
+ const stderr = process.stderr;
259
+ stderr.write(prompt);
260
+ const rl = createInterface({
261
+ input: stdin,
262
+ terminal: true
263
+ });
264
+ rl.question("", (answer) => {
265
+ stderr.write("\n");
266
+ rl.close();
267
+ resolve(answer);
268
+ });
269
+ rl.on("error", reject);
270
+ });
271
+ }
272
+ function suiteVersion() {
273
+ try {
274
+ const here = dirname(fileURLToPath(import.meta.url));
275
+ return JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8")).version ?? "0.0.0";
276
+ } catch {
277
+ return "0.0.0";
278
+ }
279
+ }
280
+ function parseTiers(value) {
281
+ if (!value) return void 0;
282
+ const tiers = value.split(",").map((t) => t.trim());
283
+ for (const tier of tiers) if (tier !== "must" && tier !== "should" && tier !== "info") throw new Error(`unknown tier: ${tier}`);
284
+ return tiers;
285
+ }
286
+ async function main(argv) {
287
+ const command = argv[0];
288
+ if (command === "coverage") {
289
+ const { values } = parseArgs({
290
+ args: argv.slice(1),
291
+ options: { json: { type: "boolean" } }
292
+ });
293
+ const report = coverageReport(fullCatalog);
294
+ if (values.json) process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
295
+ else {
296
+ process.stdout.write(`${report.covered.length}/${report.requirements.length} requirements covered, ${report.gaps.length} gaps\n`);
297
+ for (const gap of report.gaps) process.stdout.write(` gap: ${gap.ref}\n`);
298
+ for (const d of report.danglingCitations) process.stdout.write(` dangling: ${d.checkId} → ${d.ref}\n`);
299
+ }
300
+ return report.danglingCitations.length > 0 ? 1 : 0;
301
+ }
302
+ if (command === "run") {
303
+ const { values } = parseArgs({
304
+ args: argv.slice(1),
305
+ options: {
306
+ target: { type: "string" },
307
+ did: { type: "string" },
308
+ implementation: { type: "string" },
309
+ "operator-token": { type: "string" },
310
+ handle: { type: "string" },
311
+ oauth: { type: "boolean" },
312
+ "standalone-host": { type: "boolean" },
313
+ identities: { type: "boolean" },
314
+ destructive: { type: "boolean" },
315
+ slow: { type: "boolean" },
316
+ tier: { type: "string" },
317
+ report: { type: "string" },
318
+ json: { type: "boolean" }
319
+ }
320
+ });
321
+ if (!values.target) {
322
+ process.stderr.write("run requires --target <origin>\n");
323
+ return 2;
324
+ }
325
+ const origin = values.target.replace(/\/+$/, "");
326
+ const operatorToken = values["operator-token"] ?? process.env.SPACE_CONFORMANCE_TOKEN;
327
+ let oauthOperator;
328
+ if (values.oauth) {
329
+ if (!values.handle) {
330
+ process.stderr.write("--oauth requires --handle <your handle>\n");
331
+ return 2;
332
+ }
333
+ oauthOperator = await oauthSignIn({
334
+ handle: values.handle,
335
+ targetOrigin: origin,
336
+ log: (message) => process.stderr.write(`${message}\n`)
337
+ });
338
+ }
339
+ let password = process.env.SPACE_CONFORMANCE_PASSWORD;
340
+ if (!password && values.handle && !values.oauth && !operatorToken && process.stdin.isTTY) password = await promptPassword(`Password for ${values.handle}: `);
341
+ const report = await runConformance({
342
+ origin,
343
+ did: values.did,
344
+ implementation: values.implementation,
345
+ operatorToken,
346
+ operatorFetch: oauthOperator?.fetch,
347
+ handle: values.handle,
348
+ password,
349
+ standaloneHost: values["standalone-host"],
350
+ identities: values.identities,
351
+ destructive: values.destructive,
352
+ slow: values.slow,
353
+ tiers: parseTiers(values.tier),
354
+ suiteVersion: suiteVersion()
355
+ });
356
+ if (oauthOperator) await oauthOperator.signOut();
357
+ if (values.report) writeFileSync(values.report, `${JSON.stringify(report, null, 2)}\n`);
358
+ process.stdout.write(values.json ? `${JSON.stringify(report, null, 2)}\n` : `${renderReport(report)}\n`);
359
+ return report.summary.mustFail > 0 || report.summary.mustError > 0 ? 1 : 0;
360
+ }
361
+ process.stderr.write("usage: space-conformance <run|coverage> [options]\n");
362
+ return 2;
363
+ }
364
+ main(process.argv.slice(2)).then((code) => {
365
+ process.exitCode = code;
366
+ }, (err) => {
367
+ process.stderr.write(`${err instanceof Error ? err.stack : String(err)}\n`);
368
+ process.exitCode = 1;
369
+ });
370
+
371
+ //#endregion
372
+ export { };
373
+ //# sourceMappingURL=cli.js.map