1import * as AWS from "@/AWS";
2import { Connection } from "@/AWS/CodeConnections/Connection.ts";
3import * as Provider from "@/Provider";
4import * as Test from "@/Test/Alchemy";
5import * as codeconnections from "@distilled.cloud/aws/codeconnections";
6import { expect } from "alchemy-test";
7import * as Effect from "effect/Effect";
8
9const { test } = Test.make({ providers: AWS.providers() });
10
11// Connection names are capped at 32 chars.
12const connectionName = "alchemy-test-conn";
13
14test.provider(
15 "lifecycle: create GitHub connection (PENDING), destroy",
16 (stack) =>
17 Effect.gen(function* () {
18 yield* stack.destroy();
19
20 // Create — the connection is created in PENDING; completing the OAuth
21 // handshake is a manual console step with no API, so PENDING is the
22 // only state we can assert without human interaction.
23 const deployed = yield* stack.deploy(
24 Effect.gen(function* () {
25 return yield* Connection("GitHubConn", {
26 connectionName,
27 providerType: "GitHub",
28 });
29 }),
30 );
31 expect(deployed.connectionArn).toContain(":connection/");
32 expect(deployed.connectionStatus).toBe("PENDING");
33 expect(deployed.providerType).toBe("GitHub");
34
35 // Out-of-band verification via distilled.
36 const created = yield* codeconnections.getConnection({
37 ConnectionArn: deployed.connectionArn,
38 });
39 expect(created.Connection?.ConnectionName).toBe(connectionName);
40 expect(created.Connection?.ConnectionStatus).toBe("PENDING");
41 expect(created.Connection?.ProviderType).toBe("GitHub");
42
43 // Canonical list() coverage.
44 const provider = yield* Provider.findProvider(Connection);
45 const all = yield* provider.list();
46 expect(all.some((c) => c.connectionArn === deployed.connectionArn)).toBe(
47 true,
48 );
49
50 // Destroy — connection is deleted; verify it is gone out-of-band.
51 yield* stack.destroy();
52 const after = yield* codeconnections
53 .getConnection({ ConnectionArn: deployed.connectionArn })
54 .pipe(
55 Effect.map((res) => res.Connection),
56 Effect.catchTag("ResourceNotFoundException", () =>
57 Effect.succeed(undefined),
58 ),
59 );
60 expect(after).toBeUndefined();
61 }),
62 {
63 tags: ["provider:aws", "provider:aws:codeconnections", "live"],
64 timeout: 120_000,
65 },
66);