@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, 04:45 UTC

main
ts 118 lines 4.58 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Connection } from "@alchemy.run/aws/CodeConnections/Connection";
3 import { RepositoryLink } from "@alchemy.run/aws/CodeConnections/RepositoryLink";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as codeconnections from "@distilled.cloud/aws/codeconnections";
7 import * as Effect from "effect/Effect";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // A repository link requires a connection in the AVAILABLE state, and
12 // completing a connection's OAuth handshake is a manual console step with no
13 // API. The ungated probe below proves the request wiring end-to-end against
14 // the real service (the call reaches CodeConnections and returns its typed
15 // domain error for a PENDING connection); the full lifecycle is gated on a
16 // manually-completed connection.
17 const AVAILABLE_CONNECTION_ARN = process.env.AWS_TEST_CODECONNECTIONS_CONNECTION_ARN;
18 const OWNER_ID = process.env.AWS_TEST_CODECONNECTIONS_OWNER_ID;
19 const REPOSITORY_NAME = process.env.AWS_TEST_CODECONNECTIONS_REPOSITORY_NAME;
20
21 test.provider(
22 "probe: creating a link on a PENDING connection surfaces a typed error",
23 (stack) =>
24 Effect.gen(function* () {
25 yield* stack.destroy();
26
27 const connection = yield* stack.deploy(
28 Effect.gen(function* () {
29 return yield* Connection("RepoLinkProbeConn", {
30 connectionName: "alchemy-test-repolink-conn",
31 providerType: "GitHub",
32 });
33 }),
34 );
35 expect(connection.connectionStatus).toBe("PENDING");
36
37 // The connection has not completed its OAuth handshake. Whichever way
38 // the service answers, the request wiring is proven end-to-end: either
39 // the link is rejected with a TYPED tag (not an unmatched catch-all),
40 // or it is created — in which case we clean it up out-of-band.
41 const result = yield* codeconnections
42 .createRepositoryLink({
43 ConnectionArn: connection.connectionArn,
44 OwnerId: "alchemy-test",
45 RepositoryName: "alchemy-test-repo",
46 })
47 .pipe(
48 Effect.map((res) => ({ kind: "created", link: res.RepositoryLinkInfo }) as const),
49 Effect.catchTag(
50 [
51 "InvalidInputException",
52 "AccessDeniedException",
53 "ConcurrentModificationException",
54 "ResourceAlreadyExistsException",
55 ],
56 (e) => Effect.succeed({ kind: "rejected", tag: e._tag } as const),
57 ),
58 );
59 if (result.kind === "created") {
60 expect(result.link.RepositoryLinkId).toBeTruthy();
61 yield* codeconnections
62 .deleteRepositoryLink({
63 RepositoryLinkId: result.link.RepositoryLinkId,
64 })
65 .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.void));
66 } else {
67 expect(result.tag).toBeTruthy();
68 }
69
70 yield* stack.destroy();
71 }),
72 {
73 tags: ["provider:aws", "provider:aws:codeconnections", "live"],
74 timeout: 120_000,
75 },
76 );
77
78 test.provider.skipIf(!AVAILABLE_CONNECTION_ARN || !OWNER_ID || !REPOSITORY_NAME)(
79 "lifecycle: create link on an AVAILABLE connection, destroy (gated: AWS_TEST_CODECONNECTIONS_CONNECTION_ARN)",
80 (stack) =>
81 Effect.gen(function* () {
82 yield* stack.destroy();
83
84 const deployed = yield* stack.deploy(
85 Effect.gen(function* () {
86 return yield* RepositoryLink("Repo", {
87 connectionArn: AVAILABLE_CONNECTION_ARN!,
88 ownerId: OWNER_ID!,
89 repositoryName: REPOSITORY_NAME!,
90 });
91 }),
92 );
93 expect(deployed.repositoryLinkArn).toContain(":repository-link/");
94 expect(deployed.repositoryLinkId).toBeTruthy();
95 expect(deployed.ownerId).toBe(OWNER_ID);
96 expect(deployed.repositoryName).toBe(REPOSITORY_NAME);
97
98 // Out-of-band verification via distilled.
99 const created = yield* codeconnections.getRepositoryLink({
100 RepositoryLinkId: deployed.repositoryLinkId,
101 });
102 expect(created.RepositoryLinkInfo.ConnectionArn).toBe(AVAILABLE_CONNECTION_ARN);
103
104 // Destroy — link is deleted; verify it is gone out-of-band.
105 yield* stack.destroy();
106 const after = yield* codeconnections
107 .getRepositoryLink({ RepositoryLinkId: deployed.repositoryLinkId })
108 .pipe(
109 Effect.map((res) => res.RepositoryLinkInfo),
110 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
111 );
112 expect(after).toBeUndefined();
113 }),
114 {
115 tags: ["provider:aws", "provider:aws:codeconnections", "live"],
116 timeout: 120_000,
117 },
118 );