@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 06:00 UTC

main
ts 113 lines 4.47 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as sns from "@distilled.cloud/aws/sns";
5 import * as Data from "effect/Data";
6 import * as Effect from "effect/Effect";
7 import * as HttpClient from "effect/http/HttpClient";
8 import * as HttpClientRequest from "effect/http/HttpClientRequest";
9 import * as Result from "effect/Result";
10 import * as Schedule from "effect/Schedule";
11 import {
12 PlatformApiFunction,
13 PlatformApiFunctionLive,
14 PlatformFixture,
15 } from "./platform-handler.ts";
16
17 const { test } = Test.make({ providers: AWS.providers() });
18
19 describe.sequential(
20 "SNS PlatformApplication",
21 { tags: ["provider:aws", "provider:aws:sns", "live"] },
22 () => {
23 // Ungated typed-error probe: SNS validates platform credentials at
24 // CreatePlatformApplication time, so a fake GCM API key must surface as a
25 // typed `InvalidParameterException` ("Platform credentials are invalid").
26 // This proves the distilled error mapping and documents exactly why the
27 // full lifecycle below is credential-gated, at near-zero cost (nothing is
28 // created).
29 test.provider(
30 "createPlatformApplication rejects fake credentials with a typed error",
31 (_stack) =>
32 Effect.gen(function* () {
33 const result = yield* Effect.result(
34 sns.createPlatformApplication({
35 Name: "alchemy-test-sns-platform-probe",
36 Platform: "GCM",
37 Attributes: { PlatformCredential: "invalid-api-key-probe" },
38 }),
39 );
40
41 expect(Result.isFailure(result)).toBe(true);
42 if (Result.isFailure(result)) {
43 expect(result.failure._tag).toBe("InvalidParameterException");
44 }
45 }),
46 { timeout: 60_000 },
47 );
48
49 // Full lifecycle + mobile-push bindings — requires real push-service
50 // credentials:
51 // AWS_TEST_SNS_PLATFORM=1
52 // AWS_TEST_SNS_PLATFORM_NAME (default GCM)
53 // AWS_TEST_SNS_PLATFORM_CREDENTIAL
54 // AWS_TEST_SNS_PLATFORM_TOKEN
55 test.provider.skipIf(!process.env.AWS_TEST_SNS_PLATFORM)(
56 "platform application lifecycle + endpoint bindings",
57 (stack) =>
58 Effect.gen(function* () {
59 if (!process.env.NO_DESTROY) {
60 yield* stack.destroy();
61 }
62
63 const deployed = yield* stack.deploy(
64 Effect.gen(function* () {
65 const { application } = yield* PlatformFixture;
66 const apiFunction = yield* PlatformApiFunction;
67 return { application, apiFunction };
68 }).pipe(Effect.provide(PlatformApiFunctionLive)),
69 );
70
71 expect(deployed.application.platformApplicationArn).toContain(":app/");
72 expect(deployed.application.enabled).toBe(true);
73
74 const baseUrl = deployed.apiFunction.functionUrl!.replace(/\/+$/, "");
75 const response = yield* HttpClient.execute(
76 HttpClientRequest.bodyJsonUnsafe(HttpClientRequest.post(`${baseUrl}/endpoint-cycle`), {
77 token: process.env.AWS_TEST_SNS_PLATFORM_TOKEN,
78 }),
79 ).pipe(
80 Effect.retry({ schedule: Schedule.exponential("2 seconds"), times: 8 }),
81 Effect.flatMap((res) => res.json),
82 );
83
84 expect((response as any).ok).toBe(true);
85 expect((response as any).endpointArn).toContain(":endpoint/");
86 expect((response as any).endpointCount).toBeGreaterThanOrEqual(0);
87
88 if (!process.env.NO_DESTROY) {
89 yield* stack.destroy();
90 yield* assertPlatformApplicationGone(deployed.application.platformApplicationArn);
91 }
92 }),
93 { tags: ["provider:aws:lambda"], timeout: 300_000 },
94 );
95 },
96 );
97
98 class PlatformApplicationStillExists extends Data.TaggedError("PlatformApplicationStillExists") {}
99
100 // Out-of-band proof the trailing destroy left nothing behind: the platform
101 // application must be observably gone (typed NotFoundException) after destroy.
102 const assertPlatformApplicationGone = Effect.fn(function* (arn: string) {
103 yield* sns.getPlatformApplicationAttributes({ PlatformApplicationArn: arn }).pipe(
104 Effect.flatMap(() => Effect.fail(new PlatformApplicationStillExists())),
105 Effect.retry({
106 while: (error) => error._tag === "PlatformApplicationStillExists",
107 schedule: Schedule.exponential(100),
108 times: 8,
109 }),
110 Effect.catchTag("NotFoundException", () => Effect.void),
111 Effect.catchTag("InvalidParameterException", () => Effect.void),
112 );
113 });