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

main
ts 112 lines 4.48 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { ConnectorProfile } from "@alchemy.run/aws/AppFlow";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as appflow from "@distilled.cloud/aws/appflow";
6 import * as Effect from "effect/Effect";
7
8 const { test } = Test.make({ providers: AWS.providers() });
9
10 // Every AppFlow connector validates the vendor connection at
11 // createConnectorProfile time (verified live for Salesforce and Snowflake),
12 // so a connector profile cannot be provisioned without real vendor
13 // credentials. The ungated probes below pin the typed error the API returns
14 // for an unreachable/unauthorized connector — the exact failure mode the
15 // gated lifecycle hits without credentials.
16
17 test.provider(
18 "createConnectorProfile with an unreachable connector fails with a typed error",
19 () =>
20 Effect.gen(function* () {
21 const error = yield* Effect.flip(
22 appflow.createConnectorProfile({
23 connectorProfileName: "alchemy-test-appflow-cp-probe",
24 connectorType: "Salesforce",
25 connectionMode: "Public",
26 connectorProfileConfig: {
27 connectorProfileProperties: {
28 Salesforce: { instanceUrl: "https://invalid-example.my.salesforce.com" },
29 },
30 connectorProfileCredentials: {
31 Salesforce: {
32 accessToken: "bogus-access-token",
33 refreshToken: "bogus-refresh-token",
34 },
35 },
36 },
37 }),
38 );
39 // ConnectorServerException (unreachable host) is the observed tag;
40 // ConnectorAuthenticationException covers a reachable-but-unauthorized
41 // vendor. Both are typed via the distilled patch for this operation.
42 expect(["ConnectorServerException", "ConnectorAuthenticationException"]).toContain(
43 error._tag,
44 );
45 }),
46 { tags: ["provider:aws", "provider:aws:appflow", "live"] },
47 );
48
49 test.provider(
50 "describeConnectorProfiles returns an empty list for an unknown name",
51 () =>
52 Effect.gen(function* () {
53 const response = yield* appflow.describeConnectorProfiles({
54 connectorProfileNames: ["alchemy-test-appflow-cp-missing"],
55 });
56 expect(response.connectorProfileDetails ?? []).toHaveLength(0);
57 }),
58 { tags: ["provider:aws", "provider:aws:appflow", "live"] },
59 );
60
61 // Full lifecycle requires real vendor credentials (human-in-the-loop OAuth
62 // or a live Snowflake/Redshift endpoint). Entitled runs supply them via env:
63 // AWS_TEST_APPFLOW_CONNECTOR=1
64 // APPFLOW_SALESFORCE_INSTANCE_URL, APPFLOW_SALESFORCE_ACCESS_TOKEN,
65 // APPFLOW_SALESFORCE_REFRESH_TOKEN
66 test.provider.skipIf(!process.env.AWS_TEST_APPFLOW_CONNECTOR)(
67 "create, update, and destroy a Salesforce connector profile",
68 (stack) =>
69 Effect.gen(function* () {
70 yield* stack.destroy();
71
72 const props = {
73 connectorProfileName: "alchemy-test-appflow-cp",
74 connectorType: "Salesforce" as const,
75 connectionMode: "Public" as const,
76 connectorProfileConfig: {
77 connectorProfileProperties: {
78 Salesforce: { instanceUrl: process.env.APPFLOW_SALESFORCE_INSTANCE_URL! },
79 },
80 connectorProfileCredentials: {
81 Salesforce: {
82 accessToken: process.env.APPFLOW_SALESFORCE_ACCESS_TOKEN!,
83 refreshToken: process.env.APPFLOW_SALESFORCE_REFRESH_TOKEN!,
84 },
85 },
86 },
87 };
88
89 const created = yield* stack.deploy(ConnectorProfile("Salesforce", props));
90 expect(created.connectorProfileName).toBe("alchemy-test-appflow-cp");
91 expect(created.connectorProfileArn).toContain(":appflow:");
92 expect(created.connectorType).toBe("Salesforce");
93
94 // Out-of-band verification.
95 const described = yield* appflow.describeConnectorProfiles({
96 connectorProfileNames: ["alchemy-test-appflow-cp"],
97 });
98 expect(described.connectorProfileDetails ?? []).toHaveLength(1);
99
100 // No-op redeploy keeps the same ARN (credentials are re-pushed since
101 // they cannot be read back).
102 const noop = yield* stack.deploy(ConnectorProfile("Salesforce", props));
103 expect(noop.connectorProfileArn).toBe(created.connectorProfileArn);
104
105 yield* stack.destroy();
106 const gone = yield* appflow.describeConnectorProfiles({
107 connectorProfileNames: ["alchemy-test-appflow-cp"],
108 });
109 expect(gone.connectorProfileDetails ?? []).toHaveLength(0);
110 }),
111 { tags: ["provider:aws", "provider:aws:appflow", "live"], timeout: 120_000 },
112 );