Skip to content

Commit 2328a39

Browse files
mikepitreclaude
andcommitted
test(expo): take the verify core of clerk-ios 5ace2cee
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent db5246e commit 2328a39

20 files changed

Lines changed: 823 additions & 198 deletions
Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
469e9a5518fd9b5a50f37ba1e6f6a879245f68f2a36559dc5372cfe01a068541 agent-device.ts
2-
7d5405cff4fab81d1735848cbed3ef9df123df8d79332c81c13e8e8808b08879 broker.ts
2+
bfbf9d7356d877fcb209cea60c9c2be06855711ce3e0c1c71ad6b43637c21713 broker.ts
33
b04c0026c6ff1ef3d73fb1cddd6c39fcd423022abcba2b268b6c7d5bf13f6bc3 claims.ts
4-
3b24d4d6cca5eef7f949faef19a8316434937a2f539cef5cc01f6a3aa71ba756 clerk.ts
5-
9d98899a0bf2b856b574a5c1e738e6087afb5aea2d8b77fba94955bb348a6b29 cli.ts
4+
4977244f79466fe3070df8cfe5a64ffaf485c781ecbae6abdfde892e076a4650 clerk.ts
5+
64e49242ffc3a01915e709aba5e1d7b5a9a35849788c4b77fefa42de9b722c21 cli.ts
66
a8352ed6efc0a90dcf1ad1cd18ca33956bccb45a94f14fba384468605362cba3 device-command.ts
77
1f70b01052b175c8bfd941719c7c6b119017c35b1d151ce85d7b87c90a7a302d devices.ts
88
0a7f334ba9f56ea77b410ffd370cc9bab8f71af88829f0cffb4220bfc96bfc72 e2e-config.ts
9-
5cdd4841fb69d9754d3d6df1df49f2e1a623c3bbffc5234e6815be8d968065be e2e.ts
10-
acba2846864be826dd05e9bbfbeac375b30c47b3c6609c3cb25a57b1aaeb97ea evidence.ts
9+
fb0a42e16e39f6de1bd49446b240a7b14f841de0f20b77163d044d453fd3e60e e2e.ts
10+
c9363e98e46ae796357bb661488f09b888ba07a11a719f6386c174ffa3a2143c evidence.ts
1111
da1d7bd2f27eb4857a6c7620885ac8c0e53a6b643bf4f6ab85e3250f9ce9a18d exec.ts
1212
a783d02979eed9282dd460579dd513a67b5979033a3dbaabc4f537fd7586c3c5 instances/base.json
13-
9a73ebc79119b0431764100b36eac4bf9b2f620ff9bc48ed7b128bca5275f75a instances/definitions.ts
14-
6490cc36768f6a74b4946ce33328ea4bd46e903518d870d294ca5136a1118ed5 instances/instances.ts
15-
7bb735876956e607d552fa99c9895776b6bdb1c3c5cfbd5c0224267fa3944439 instances/platform.ts
16-
5c9414868d6f703d4e28c8a0e2bded46cd3497673f928282ebc3b136cab49c70 instances/settings.ts
17-
16507caed0baec51dc21ef6d3abf3738a419a35a43a693f66a9537144b3c8765 instances/throwaway.ts
18-
22bfbc3765f957aec843e15fdb2f55558ec0ce32235debb4a00b14022af027c8 keys.ts
13+
da44c94d46a3852fa7f5419714090a49ed5ba38878dcf489dbc20bb39b0293cc instances/definitions.ts
14+
b014bb43946588b1f67453aaf8af0b0e9c670245f4e6eae34c7461c4b7a857ac instances/instances.ts
15+
429d6a9ee475ef8a52d6adf20336f76b19062f836b7b6289f9ce3375d8cf68dd instances/platform.ts
16+
63cd38bfd51cc0e9b30ea2b680a6ce346739d646f742a86f969e2ebfca877155 instances/settings.ts
17+
af98064629f556ad8c26c6577e2c61231afc363738e2a6aee2e9e59dbcf92b34 instances/throwaway.ts
18+
92c818e5b37e2af58cb0d8adbaa4900592c057899a26e98df18d166c4a0439d1 keys.ts
1919
ead2e0e4285493c275361058e3e74b78acbf81b1faa63e83a24efd4e7ae14dce launch.d.mts
2020
56d123c39cb0a97446a2cdb874d21024e1c234c8367117ca3906278e984591be launch.mjs
2121
fef6e3af1bf6bf3aeff68cd90118057c93d09a4041a138ddd30bd235420c505e ledgers.ts
@@ -33,6 +33,6 @@ e75c8133fedb5bbc7459c7b03e01038a93f7fa2d3f901975064da0b88cba4570 remote/tunnel.
3333
45926ab47dbc307da2bdd9424c3df9abf15dd0aed62e02e63da97cf30ba3469e secret.ts
3434
685eabf010c7f63d076cfd3da1a681b5cc8024720538c1bf3a99792b563d8b60 slot.ts
3535
8f6054f5c57a7416f1e86165f6cb6fd3ea72b0c4071e96b243d0b00e9c268f9b state.ts
36-
75e498f9741b9951d7824a5fc6249dcec1be6a9dcf1d08e5b6dce9b5e5a13040 types.ts
37-
6632ce6e1d9e047ede70c6ce26e0aa6724c39a0e077f9bf297a8ef587e6eec31 verbs.ts
36+
fd65cd13bce9490c3fe3f7da11386a1e5e360a6185eafeff3ce15e1bc649e878 types.ts
37+
ce661bea66ff6a38063d4091ba2b5a0fb82099b5a23481d8a64e8f52573e35e6 verbs.ts
3838
eb9d5993cbb2c53d299c0747061f864cc2b8bd679997ed976431a852bee4a87d workspace.ts

‎.claude/skills/verify-clerk-expo/src/core/broker.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export const TICKET_SECONDS = 120;
2828
export interface BrokerDeps {
2929
/** The Backend API of the instance the run is on when a request arrives. */
3030
readonly clerk: () => ClerkBackend;
31-
/** That instance's publishable key, and where an identity made in it lives. */
3231
readonly instance: () => { readonly pk: PublishableKey; readonly home: IdentityHome };
3332
readonly screens: readonly string[];
3433
readonly platforms: readonly Platform[];

‎.claude/skills/verify-clerk-expo/src/core/clerk.ts‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,24 @@ export function parseTestPhone(value: string): TestPhone {
5151
/** What `deleteByEmail` would delete: a user, or an organization that user created. */
5252
export type OwnedTarget = { readonly kind: 'user'; readonly id: string; readonly email: TestEmail } | { readonly kind: 'organization'; readonly id: string; readonly name: string };
5353

54-
/** The Backend API of one instance: the one whose keys the backend was made with. No call names an instance. */
54+
/** The Backend API of the one instance whose keys the backend was made with. */
5555
export interface ClerkBackend {
5656
createUser(email: TestEmail, phone: TestPhone | null): Promise<SeededUser>;
5757
mintTicket(user: SeededUser, expiresInSeconds: number): Promise<Secret<'ticket'>>;
5858
deleteByEmail(email: TestEmail): Promise<{ readonly users: number; readonly organizations: number }>;
5959
previewDeleteByEmail(email: TestEmail): Promise<readonly OwnedTarget[]>;
6060
findUserId(email: TestEmail): Promise<string | null>;
61-
/** How many users the instance holds. A development instance refuses its 101st. */
61+
/** A development instance refuses its 101st user. */
6262
userCount(): Promise<number>;
6363
settings(): Promise<InstanceRequirements>;
6464
/** Makes one read with the instance's own key and returns the Backend API host that accepted it. */
6565
apiHost(): Promise<BackendApiHost>;
6666
}
6767

68-
/** The Backend API of a standing instance, which only its name can pick. */
6968
export type StandingClerk = (instance: InstanceName) => ClerkBackend;
7069

7170
export const DEVELOPMENT_USER_LIMIT = 100;
72-
/** An instance that holds this many users is replaced before a run starts on it. One full golden run seeds about twelve. */
71+
/** An instance that holds this many users is replaced before a run starts on it. A full run of a repository's specs seeds about twelve. */
7372
export const REPLACE_AT_USERS = 60;
7473

7574
/**

‎.claude/skills/verify-clerk-expo/src/core/cli.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { execFileSync } from 'node:child_process';
22
import { basename, dirname, isAbsolute, join, relative } from 'node:path';
33
import { fileURLToPath } from 'node:url';
44
import { run as defaultRunner } from './exec.ts';
5-
import { PLATFORM_CREDENTIAL_VARIABLES } from './launch.mjs';
5+
import { CLERK_KEY_VARIABLES } from './keys.ts';
66
import { redact } from './secret.ts';
77
import { leaseLine } from './devices.ts';
88
import { RUNNER_LABEL } from './remote/protocol.ts';
@@ -317,14 +317,14 @@ export function exitCodeFor(value: VerbResult): number {
317317
export const SKILL_DIR = join(dirname(fileURLToPath(import.meta.url)), '..', '..');
318318

319319
/**
320-
* Removes the Platform API key, and the variables that say where it is kept, from `env` and returns a copy that still
321-
* has them. Only the instances layer gets the copy, so nothing this CLI starts or passes its environment to (git, the
322-
* build, e2e, agent-device) ever holds the key or learns where it is.
320+
* Removes the Platform API key, the variables that say where it is kept, and the standing instances' secret keys from
321+
* `env` and returns a copy that still has them. Only the instances layer gets the copy, so nothing this CLI starts or
322+
* passes its environment to (git, the build, e2e, agent-device) ever holds a Clerk key or learns where one is.
323323
*/
324324
export function takePlatformKey(env: NodeJS.ProcessEnv): Readonly<Record<string, string | undefined>> {
325-
const withKey = { ...env };
326-
for (const name of PLATFORM_CREDENTIAL_VARIABLES) delete env[name];
327-
return withKey;
325+
const withKeys = { ...env };
326+
for (const name of CLERK_KEY_VARIABLES) delete env[name];
327+
return withKeys;
328328
}
329329

330330
export async function main(argv: readonly string[], host: HostAdapter): Promise<number> {

‎.claude/skills/verify-clerk-expo/src/core/e2e.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ export function writeRunContext(file: string, context: RunContext): void {
106106
writeFileSync(file, `${JSON.stringify(context, null, 2)}\n`, { mode: 0o600 });
107107
}
108108

109-
/** Where the nth e2e invocation of a run writes. The first keeps the name a run with one invocation always had. */
109+
/** The first invocation writes where a run with one invocation writes. */
110110
export function e2eOutputDir(runDir: EvidencePath, index: number): EvidencePath {
111111
return join(runDir, index === 0 ? 'e2e' : `e2e-${index + 1}`) as EvidencePath;
112112
}
@@ -239,7 +239,6 @@ function platformSkip(reason: string | undefined): string {
239239
return declared === undefined ? `skipped: ${reason ?? 'other platform'}` : `skipped: ${declared.split(/,\s*/).join(' and ')} only`;
240240
}
241241

242-
/** `outputDir` is the directory the invocation that wrote the report was given. */
243242
export function parseE2EReport(reportJson: unknown, specs: readonly SpecRef[], outputDir: EvidencePath, excluded: readonly OptInTag[] = [KNOWN_BUG_TAG]): readonly SpecResult[] {
244243
const failuresDir = join(outputDir, 'failures');
245244
const pages = existsSync(failuresDir) ? readdirSync(failuresDir) : [];
@@ -292,7 +291,7 @@ export function parseE2EReport(reportJson: unknown, specs: readonly SpecRef[], o
292291
});
293292
}
294293

295-
/** Copies the labelled screenshots of one invocation into the run's `screenshots/`. A later invocation's label replaces an earlier one's. */
294+
/** A later invocation's label replaces an earlier one's. */
296295
export function collectScreenshots(reportJson: unknown, runDir: EvidencePath, outputDir: EvidencePath): readonly { readonly label: string; readonly path: EvidencePath }[] {
297296
const out = new Map<string, EvidencePath>();
298297
const dir = join(runDir, 'screenshots');

‎.claude/skills/verify-clerk-expo/src/core/evidence.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { existsSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
22
import { join } from 'node:path';
33
import { parseTestEmail } from './clerk.ts';
44
import { usedSecretValues } from './secret.ts';
5-
import { parseVerifyState } from './state.ts';
5+
import { count, parseVerifyState } from './state.ts';
66
import { VerifyFailure, type Brand, type EvidencePath, type EvidenceRecord, type VerifyState } from './types.ts';
77

88
function files(dir: string): string[] {
@@ -58,6 +58,9 @@ export function assertPublishable(record: EvidenceRecord, states: readonly Verif
5858
if (record.tainted.length > 0) refuse(`run ${record.run} has secret values in ${record.tainted.join(', ')}`, 'do not attach this run; rerun and attach the new run');
5959
const failed = record.results.filter((r) => r.status === 'failed' || r.status === 'interrupted');
6060
if (failed.length > 0) refuse(`run ${record.run} has ${failed.length} failing spec(s)`, 'fix the failures and attach a passing run');
61+
// Absent from a record sealed before a run recorded its groups.
62+
const incomplete = ((record.settings as EvidenceRecord['settings'] | undefined) ?? []).filter((group) => group.held === false || group.e2eReport === null);
63+
if (incomplete.length > 0) refuse(`run ${record.run} has ${count(incomplete.length, 'group')} that did not run in full on its settings: ${incomplete.map((group) => group.label).join('; ')}`, 'attach a run in which every group ran on the settings it declares');
6164
if (!record.results.some((r) => r.status === 'passed' || r.status === 'flaky')) refuse(`run ${record.run} passed no specs`, 'attach a run whose specs ran and passed');
6265
for (const identity of record.identities) parseTestEmail(identity.email);
6366
const own = new Set(record.identities.flatMap((i) => (i.userId === null ? [] : [i.userId])));

‎.claude/skills/verify-clerk-expo/src/core/instances/definitions.ts‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ export interface EnvironmentComparison {
3535
readonly unknown: readonly string[];
3636
}
3737

38-
/**
39-
* Compares a live public environment with what is expected of it. A difference in `environment` is `differing`; one in
40-
* `defaults` is `drifted`.
41-
*/
38+
/** A difference in `environment` is `differing`; one in `defaults` is `drifted`. */
4239
export function compareEnvironment(definition: { readonly environment: Leaves; readonly defaults: Leaves }, live: Json): EnvironmentComparison {
4340
const found = flattenEnvironment(live);
4441
const differences = (expected: Leaves): EnvironmentDifference[] =>

‎.claude/skills/verify-clerk-expo/src/core/instances/instances.ts‎

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,12 @@ export interface FinishedInstances {
4242
/** The instance one group of a run drives on, from `apply` until `release`. */
4343
export interface AppliedInstance {
4444
readonly keys: InstanceKeys;
45-
/** The throwaway application, or the standing instance that stands in for the settings. */
4645
readonly instance: { readonly source: 'throwaway'; readonly id: string; readonly name: string } | { readonly source: 'standing'; readonly instance: InstanceName };
4746
/** How long the config PATCH for this group took, or null when none was sent. */
4847
readonly changed: { readonly answeredMs: number; readonly visibleMs: number } | null;
49-
/** Reads the public environment once and says whether the settings still hold. Call it before `release`. */
48+
/** Reads the public environment once and says whether the settings still hold. Throws when it cannot be read. Call it before `release`. */
5049
stillApplied(): Promise<boolean>;
51-
/** Ends this process's use of the instance. After it, `keys` and `clerk` of `Instances` throw until the next `apply`. */
50+
/** After it, `keys` and `clerk` of `Instances` throw until the next `apply`. */
5251
release(): Promise<void>;
5352
}
5453

@@ -69,9 +68,9 @@ export interface Instances {
6968
ensure(options: { readonly willChange: boolean }, progress: (line: string) => void): Promise<{ readonly choice: InstanceChoice; readonly instances: readonly InstanceView[] }>;
7069
/** Puts an instance on the group's settings for this process to drive on. One at a time: release it before the next. */
7170
apply(group: SettingsGroup, progress: (line: string) => void): Promise<AppliedInstance>;
72-
/** The applied instance's keys, and where an identity made in it lives. Throws when nothing is applied. */
71+
/** Of the applied instance. Throws when nothing is applied. */
7372
keys(): InstanceKeys & { readonly home: IdentityHome };
74-
/** The Backend API of the applied instance. Throws when nothing is applied. */
73+
/** Of the applied instance. Throws when nothing is applied. */
7574
clerk(): ClerkBackend;
7675
/**
7776
* Finishes what a ledger still holds: deletes its throwaway applications unless `keepApplications`, closes the
@@ -92,7 +91,6 @@ export interface InstancesDeps {
9291
readonly fetch?: typeof fetch;
9392
readonly sleep?: (ms: number) => Promise<void>;
9493
readonly now?: () => number;
95-
/** This process as a driver of an application, and how to tell whether another driver is alive. */
9694
readonly drivers?: { readonly self: ProcessRef; readonly isRunning: (driver: ProcessRef) => boolean };
9795
}
9896

@@ -138,10 +136,13 @@ export function createInstances(deps: InstancesDeps): Instances {
138136
};
139137
const appliedClerk = backends(() => current().keys);
140138

139+
const wanted = env.VERIFY_INSTANCES?.trim() || undefined;
140+
const inline = (env.CLERK_TEST_KEYS_JSON ?? '').trim() !== '';
141+
/** With neither variable set, the instances are standing only because this machine has no Platform credential. */
142+
const toThrowaway = `run on a throwaway instance: ${inline || wanted === 'standing' ? 'unset CLERK_TEST_KEYS_JSON and VERIFY_INSTANCES=standing' : '`VERIFY_INSTANCES=throwaway {cli} doctor` prints what credential this machine is missing'}`;
143+
141144
async function choose(): Promise<InstanceChoice> {
142-
const wanted = env.VERIFY_INSTANCES?.trim() || undefined;
143145
if (wanted !== undefined && wanted !== 'standing' && wanted !== 'throwaway') throw new VerifyFailure('USAGE', `VERIFY_INSTANCES=${wanted} is not standing or throwaway`, 'unset VERIFY_INSTANCES, or set it to standing or throwaway');
144-
const inline = (env.CLERK_TEST_KEYS_JSON ?? '').trim() !== '';
145146
const holding = openApplications(workspace).length > 0;
146147
const standing = (why: string): InstanceChoice => {
147148
if (holding) throw new VerifyFailure('NOT_READY', `this worktree holds throwaway instances, and ${why} asks for the standing ones`, '{cli} down, then rerun');
@@ -156,7 +157,7 @@ export function createInstances(deps: InstancesDeps): Instances {
156157
return { source: 'throwaway', why: `${describeCredential(open.credential)} reaches the verification workspace ${open.workspace}` };
157158
} catch (error) {
158159
if (wanted === 'throwaway' || !(error instanceof NoPlatformCredential) || !existsSync(keysFilePath(host, workspace.worktree))) throw error;
159-
return { source: 'standing', why: `${host.keysFile} is in the main worktree and ${error.message}` };
160+
return { source: 'standing', why: `${host.keysFile} is in the main worktree and ${error.message}. To get throwaway instances: ${error.setUp}` };
160161
}
161162
}
162163

@@ -190,6 +191,14 @@ export function createInstances(deps: InstancesDeps): Instances {
190191
}
191192
}
192193

194+
/** The first call with a new instance's own key is where a replaced Authorization header shows. */
195+
async function ownKeyAccepted(id: string, keys: InstanceKeys, progress: (line: string) => void): Promise<void> {
196+
const used = await apiHost(keys).catch((error: unknown) => {
197+
throw new VerifyFailure('NOT_READY', `neither ${BACKEND_API_HOSTS.join(' nor ')} accepts the own secret key of ${id}: ${(error as Error).message}`, `${BACKEND_API_FIX}; \`{cli} down\` deletes the instance`);
198+
});
199+
progress(`clerk Backend API on ${used}`);
200+
}
201+
193202
async function standingChecks(): Promise<readonly DoctorCheck[]> {
194203
const checks: DoctorCheck[] = [];
195204
let keyed: readonly InstanceName[] = [];
@@ -294,14 +303,7 @@ export function createInstances(deps: InstancesDeps): Instances {
294303
progress(`instances ${made.source} ${made.why}`);
295304
if (made.source === 'standing') return { choice: made, instances: [{ source: 'standing', instance: DEFAULT_INSTANCE }] };
296305
const up = await throwaway.ensure(options, progress);
297-
if (up.created !== null) {
298-
const { id, keys } = up.created;
299-
// The first call with a new instance's own key is where a replaced Authorization header shows.
300-
const used = await apiHost(keys).catch((error: unknown) => {
301-
throw new VerifyFailure('NOT_READY', `neither ${BACKEND_API_HOSTS.join(' nor ')} accepts the own secret key of ${id}: ${(error as Error).message}`, `${BACKEND_API_FIX}; \`{cli} down\` deletes the instance`);
302-
});
303-
progress(`clerk Backend API on ${used}`);
304-
}
306+
if (up.created !== null) await ownKeyAccepted(up.created.id, up.created.keys, progress);
305307
return { choice: made, instances: up.views };
306308
}
307309

@@ -316,7 +318,7 @@ export function createInstances(deps: InstancesDeps): Instances {
316318
const { settings } = group;
317319
const instance = standingStandIn(settings);
318320
if (instance === null) {
319-
throw new SettingsRefused(`${settings.askedBy} declares ${settings.label}, and no standing instance has those settings; a standing instance cannot be changed`, 'run on a throwaway instance: unset CLERK_TEST_KEYS_JSON and VERIFY_INSTANCES=standing');
321+
throw new SettingsRefused(`${settings.askedBy} declares ${settings.label}, and no standing instance has those settings; a standing instance cannot be changed`, toThrowaway);
320322
}
321323
const keys = standingKeys(instance);
322324
const declared = Object.keys(settings.declared?.environment ?? {});
@@ -328,7 +330,7 @@ export function createInstances(deps: InstancesDeps): Instances {
328330
};
329331
const unmet = await missing();
330332
if (unmet.length > 0) {
331-
throw new SettingsRefused(`${settings.askedBy} declares ${settings.label}, and the standing instance ${instance} does not show it: ${unmet.join('; ')}`, `a standing instance cannot be changed: correct ${instance} in the Clerk dashboard, or run on a throwaway instance by unsetting CLERK_TEST_KEYS_JSON and VERIFY_INSTANCES=standing`);
333+
throw new SettingsRefused(`${settings.askedBy} declares ${settings.label}, and the standing instance ${instance} does not show it: ${unmet.join('; ')}`, `a standing instance cannot be changed: correct ${instance} in the Clerk dashboard, or ${toThrowaway}`);
332334
}
333335
progress(`settings ${settings.label} on the standing instance ${instance}, which already has it`);
334336
return {
@@ -344,7 +346,11 @@ export function createInstances(deps: InstancesDeps): Instances {
344346
}
345347

346348
async function applyThrowaway(group: SettingsGroup, progress: (line: string) => void): Promise<AppliedInstance & { readonly home: IdentityHome }> {
347-
const application = await locked(() => throwaway.apply(group, progress));
349+
const application = await locked(async () => {
350+
const made = await throwaway.apply(group, progress);
351+
if (made.created) await ownKeyAccepted(made.id, made.keys, progress);
352+
return made;
353+
});
348354
return {
349355
keys: application.keys,
350356
home: { application: application.name },

0 commit comments

Comments
 (0)