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

main
ts 93 lines 3.56 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Workspace } from "@alchemy.run/aws/Grafana";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as grafana from "@distilled.cloud/aws/grafana";
6 import * as Data from "effect/Data";
7 import * as Effect from "effect/Effect";
8 import * as Schedule from "effect/Schedule";
9
10 const { test } = Test.make({ providers: AWS.providers() });
11
12 // Ungated typed-error probe: proves the distilled error union carries the
13 // not-found tag the read/delete paths depend on.
14 test.provider(
15 "describeWorkspace on a nonexistent id fails with ResourceNotFoundException",
16 () =>
17 Effect.gen(function* () {
18 const error = yield* Effect.flip(grafana.describeWorkspace({ workspaceId: "g-0000000000" }));
19 expect(error._tag).toBe("ResourceNotFoundException");
20 }),
21 { tags: ["provider:aws", "provider:aws:grafana", "live"] },
22 );
23
24 class WorkspaceStillExists extends Data.TaggedError("WorkspaceStillExists")<{
25 readonly workspaceId: string;
26 }> {}
27
28 const assertWorkspaceDeleted = (workspaceId: string) =>
29 grafana.describeWorkspace({ workspaceId }).pipe(
30 Effect.flatMap((r) =>
31 r.workspace.status === "DELETING"
32 ? Effect.fail(new WorkspaceStillExists({ workspaceId }))
33 : Effect.succeed(undefined),
34 ),
35 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
36 Effect.retry({
37 while: (e) => e._tag === "WorkspaceStillExists",
38 schedule: Schedule.max([Schedule.spaced("5 seconds"), Schedule.recurs(24)]),
39 }),
40 );
41
42 // GATED: Grafana workspace provisioning is asynchronous (a few minutes) and
43 // `AWS_SSO` authentication requires IAM Identity Center to be enabled in the
44 // account. Run with AWS_TEST_GRAFANA=1 in an entitled account.
45 test.provider.skipIf(!process.env.AWS_TEST_GRAFANA)(
46 "create, update, and destroy a Grafana workspace",
47 (stack) =>
48 Effect.gen(function* () {
49 yield* stack.destroy();
50
51 const created = yield* stack.deploy(
52 Effect.gen(function* () {
53 return yield* Workspace("Dashboards", {
54 name: "alchemy-test-grafana",
55 description: "initial",
56 accountAccessType: "CURRENT_ACCOUNT",
57 authenticationProviders: ["AWS_SSO"],
58 permissionType: "SERVICE_MANAGED",
59 dataSources: ["PROMETHEUS", "CLOUDWATCH"],
60 tags: { Environment: "test" },
61 });
62 }),
63 );
64
65 expect(created.workspaceId).toMatch(/^g-/);
66 expect(created.workspaceArn).toContain(":/workspaces/");
67 expect(created.status).toBe("ACTIVE");
68 expect(created.endpoint).toContain("grafana-workspace");
69
70 const describedWs = yield* grafana.describeWorkspace({ workspaceId: created.workspaceId });
71 expect(describedWs.workspace.tags?.["alchemy::id"]).toBe("Dashboards");
72
73 // Update the description in place.
74 const updated = yield* stack.deploy(
75 Effect.gen(function* () {
76 return yield* Workspace("Dashboards", {
77 name: "alchemy-test-grafana",
78 description: "updated",
79 accountAccessType: "CURRENT_ACCOUNT",
80 authenticationProviders: ["AWS_SSO"],
81 permissionType: "SERVICE_MANAGED",
82 dataSources: ["PROMETHEUS", "CLOUDWATCH"],
83 tags: { Environment: "test", Extra: "yes" },
84 });
85 }),
86 );
87 expect(updated.workspaceId).toBe(created.workspaceId);
88
89 yield* stack.destroy();
90 yield* assertWorkspaceDeleted(created.workspaceId);
91 }),
92 { tags: ["provider:aws", "provider:aws:grafana", "live"], timeout: 600_000 },
93 );