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

main
ts 86 lines 3.45 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Domain, Project } from "@alchemy.run/aws/DataZone";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as datazone from "@distilled.cloud/aws/datazone";
6 import * as Effect from "effect/Effect";
7 import * as Redacted from "effect/Redacted";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 const unredact = (value: string | Redacted.Redacted<string>): string =>
12 Redacted.isRedacted(value) ? Redacted.value(value) : value;
13
14 // Once the parent domain is deleted, GetProject is reported as
15 // AccessDeniedException rather than ResourceNotFoundException — DataZone
16 // checks domain-scoped auth before existence. Both mean "absent".
17 const findProject = (domainId: string, projectId: string) =>
18 datazone.getProject({ domainIdentifier: domainId, identifier: projectId }).pipe(
19 Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)),
20 Effect.catchTag("AccessDeniedException", () => Effect.succeed(undefined)),
21 );
22
23 test.provider(
24 "create project in a domain, update description, delete",
25 (stack) =>
26 Effect.gen(function* () {
27 yield* stack.destroy();
28
29 // 1. Deploy a domain and a project inside it.
30 const result = yield* stack.deploy(
31 Effect.gen(function* () {
32 const domain = yield* Domain("ProjectTestDomain", {
33 description: "alchemy datazone project test",
34 });
35 const project = yield* Project("TestProject", {
36 domainId: domain.domainId,
37 description: "analytics project",
38 });
39 return {
40 domainId: domain.domainId,
41 projectId: project.projectId,
42 projectName: project.name,
43 projectStatus: project.projectStatus,
44 domainUnitId: project.domainUnitId,
45 };
46 }),
47 );
48
49 expect(result.projectId).toBeDefined();
50 expect(result.projectStatus).toBe("ACTIVE");
51
52 // out-of-band: project exists inside the domain.
53 const created = yield* findProject(result.domainId, result.projectId);
54 expect(created).toBeDefined();
55 expect(unredact(created!.name)).toBe(result.projectName);
56 expect(created!.description === undefined ? undefined : unredact(created!.description)).toBe(
57 "analytics project",
58 );
59
60 // 2. Update the description — converges via updateProject, same project.
61 const updated = yield* stack.deploy(
62 Effect.gen(function* () {
63 const domain = yield* Domain("ProjectTestDomain", {
64 description: "alchemy datazone project test",
65 });
66 const project = yield* Project("TestProject", {
67 domainId: domain.domainId,
68 description: "analytics project (updated)",
69 });
70 return { projectId: project.projectId };
71 }),
72 );
73 expect(updated.projectId).toBe(result.projectId);
74
75 const observed = yield* findProject(result.domainId, result.projectId);
76 expect(
77 observed!.description === undefined ? undefined : unredact(observed!.description),
78 ).toBe("analytics project (updated)");
79
80 // 3. Destroy — the project is deleted before its domain.
81 yield* stack.destroy();
82 const gone = yield* findProject(result.domainId, result.projectId);
83 expect(gone === undefined || gone.projectStatus === "DELETING").toBe(true);
84 }),
85 { tags: ["provider:aws", "provider:aws:datazone", "live"], timeout: 480_000 },
86 );