The best way to control Claude Code, Codex and more from any computer or phone

main
ts 79 lines 3.28 KB
Raw
1 import * as ACME from "@alchemy.run/acme";
2 import { expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as acme from "@distilled.cloud/acme/acme";
5 import * as Effect from "effect/Effect";
6 import * as Redacted from "effect/Redacted";
7 import * as Result from "effect/Result";
8
9 const { test } = Test.make({ providers: ACME.providers() });
10 const ca = ACME.LetsEncryptStaging;
11
12 const lookup = (privateKey: Redacted.Redacted<string>) =>
13 acme
14 .newAccount({ onlyReturnExisting: true })
15 .pipe(Effect.provide(ACME.accountLayer({ ca, accountKey: privateKey })), Effect.result);
16
17 test.provider(
18 "creates an account, keeps its key, synchronizes contacts and deactivates",
19 (stack) =>
20 Effect.gen(function* () {
21 yield* stack.destroy();
22 const program = (contact?: string[]) =>
23 ACME.Account("Account", {
24 ca,
25 contact,
26 termsOfServiceAgreed: true,
27 });
28 const first = yield* stack.deploy(program(["mailto:ops@alchemy.run"]));
29 expect(first.directoryUrl).toBe(ca.directoryUrl);
30 expect(first.accountUrl).toContain("acme-staging-v02.api.letsencrypt.org");
31 expect(first.status).toBe("valid");
32 expect(first.keyAlgorithm).toBe("ES256");
33 expect(Redacted.isRedacted(first.privateKey)).toBe(true);
34 const found = yield* lookup(first.privateKey);
35 expect(Result.isSuccess(found)).toBe(true);
36 if (Result.isSuccess(found)) expect(found.success.location).toBe(first.accountUrl);
37
38 const again = yield* stack.deploy(program(["mailto:ops@alchemy.run"]));
39 expect(again.accountUrl).toBe(first.accountUrl);
40 expect(Redacted.value(again.privateKey) === Redacted.value(first.privateKey)).toBe(true);
41
42 const updated = yield* stack.deploy(program());
43 expect(updated.accountUrl).toBe(first.accountUrl);
44 const observed = yield* lookup(first.privateKey);
45 expect(Result.isSuccess(observed)).toBe(true);
46 if (Result.isSuccess(observed)) expect(observed.success.contact ?? []).toEqual([]);
47 yield* stack.destroy();
48 const gone = yield* lookup(first.privateKey);
49 expect(Result.isFailure(gone)).toBe(true);
50 if (Result.isFailure(gone))
51 expect(["AcmeUnauthorized", "AcmeAccountDoesNotExist"]).toContain(gone.failure._tag);
52 }),
53 { tags: ["provider:acme", "provider:acme:account", "live"], timeout: 90_000 },
54 );
55
56 test.provider(
57 "changing the key algorithm replaces and deactivates the old account",
58 (stack) =>
59 Effect.gen(function* () {
60 yield* stack.destroy();
61 const first = yield* stack.deploy(
62 ACME.Account("Account", { ca, termsOfServiceAgreed: true }),
63 );
64 const replaced = yield* stack.deploy(
65 ACME.Account("Account", {
66 ca,
67 termsOfServiceAgreed: true,
68 keyAlgorithm: "RS256",
69 }),
70 );
71 expect(replaced.keyAlgorithm).toBe("RS256");
72 expect(replaced.accountUrl).not.toBe(first.accountUrl);
73 expect((JSON.parse(Redacted.value(replaced.privateKey)) as { kty: string }).kty).toBe("RSA");
74 expect(Result.isFailure(yield* lookup(first.privateKey))).toBe(true);
75 yield* stack.destroy();
76 expect(Result.isFailure(yield* lookup(replaced.privateKey))).toBe(true);
77 }),
78 { tags: ["provider:acme", "provider:acme:account", "live"], timeout: 90_000 },
79 );