@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, 06:00 UTC

main
ts 125 lines 4.97 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { AWSEnvironment } from "@alchemy.run/aws/Environment";
3 import { Role } from "@alchemy.run/aws/IAM/Role";
4 import { Bucket } from "@alchemy.run/aws/S3/Bucket";
5 import { Cluster } from "@alchemy.run/aws/SageMaker";
6 import { expect } from "@alchemy.run/test";
7 import * as Test from "@alchemy.run/test/Alchemy";
8 import * as s3 from "@distilled.cloud/aws/s3";
9 import * as sagemaker from "@distilled.cloud/aws/sagemaker";
10 import * as Effect from "effect/Effect";
11
12 const { test } = Test.make({ providers: AWS.providers() });
13
14 // Ungated typed-error probe: prove describeCluster returns the typed
15 // ResourceNotFound for a nonexistent HyperPod cluster. Runs in every CI pass.
16 test.provider(
17 "describeCluster on a nonexistent cluster fails with ResourceNotFound",
18 () =>
19 Effect.gen(function* () {
20 const error = yield* Effect.flip(
21 sagemaker.describeCluster({ ClusterName: "alchemy-nonexistent-hyperpod-cluster-probe" }),
22 );
23 expect(error._tag).toBe("ResourceNotFound");
24 }),
25 { tags: ["provider:aws", "provider:aws:sagemaker", "live"] },
26 );
27
28 const findCluster = (name: string) =>
29 sagemaker
30 .describeCluster({ ClusterName: name })
31 .pipe(Effect.catchTag("ResourceNotFound", () => Effect.succeed(undefined)));
32
33 // A live HyperPod cluster provisions real ML compute and takes 10-25 minutes
34 // to reach InService (plus several minutes to delete). Gated behind:
35 // AWS_TEST_SAGEMAKER_HYPERPOD=1
36 test.provider.skipIf(!process.env.AWS_TEST_SAGEMAKER_HYPERPOD)(
37 "create minimal Slurm HyperPod cluster, wait InService, destroy",
38 (stack) =>
39 Effect.gen(function* () {
40 yield* stack.destroy();
41
42 const { accountId } = yield* AWSEnvironment.current;
43 // The AmazonSageMakerClusterInstanceRolePolicy managed policy only
44 // grants read access to buckets whose name starts with `sagemaker-`.
45 const bucketName = `sagemaker-alchemy-hyperpod-test-${accountId}`;
46
47 const supporting = Effect.gen(function* () {
48 const bucket = yield* Bucket("HyperPodLifecycleBucket", { bucketName, forceDestroy: true });
49 const role = yield* Role("HyperPodInstanceRole", {
50 assumeRolePolicyDocument: {
51 Version: "2012-10-17",
52 Statement: [
53 {
54 Effect: "Allow",
55 Principal: { Service: "sagemaker.amazonaws.com" },
56 Action: ["sts:AssumeRole"],
57 },
58 ],
59 },
60 managedPolicyArns: ["arn:aws:iam::aws:policy/AmazonSageMakerClusterInstanceRolePolicy"],
61 });
62 return { bucket, role };
63 });
64
65 // Step 1: bucket + role only — the lifecycle script must exist in S3
66 // before cluster creation starts.
67 const { bucket } = yield* stack.deploy(supporting);
68 yield* s3.putObject({
69 Bucket: bucket.bucketName,
70 Key: "lifecycle/on_create.sh",
71 Body: new TextEncoder().encode(
72 '#!/bin/bash\nset -e\necho "alchemy hyperpod on_create complete"\n',
73 ),
74 ContentType: "text/x-shellscript",
75 });
76
77 // Step 2: add the cluster.
78 const { cluster } = yield* stack.deploy(
79 Effect.gen(function* () {
80 const { role } = yield* supporting;
81 const cluster = yield* Cluster("TestHyperPod", {
82 instanceGroups: {
83 controller: {
84 InstanceType: "ml.t3.medium",
85 InstanceCount: 1,
86 ExecutionRole: role.roleArn,
87 // HyperPod provisions new Slurm clusters in Continuous mode,
88 // which rejects a cluster with no instance group carrying a
89 // SlurmConfig ("has no InstanceGroup with SlurmConfig which is
90 // required for Continuous Node Provisioning Mode clusters").
91 SlurmConfig: { NodeType: "Controller" },
92 LifeCycleConfig: {
93 // bucketName is the deterministic string computed above —
94 // interpolating bucket.bucketName here would coerce an
95 // unresolved Output.
96 SourceS3Uri: `s3://${bucketName}/lifecycle`,
97 OnCreate: "on_create.sh",
98 },
99 },
100 },
101 nodeRecovery: "None",
102 tags: { purpose: "alchemy-test" },
103 });
104 return { cluster };
105 }),
106 );
107
108 expect(cluster.clusterArn).toContain(":cluster/");
109 expect(cluster.clusterStatus).toBe("InService");
110
111 // Out-of-band verification via distilled.
112 const described = yield* findCluster(cluster.clusterName);
113 expect(described?.ClusterStatus).toBe("InService");
114 expect(described?.InstanceGroups?.map((g) => g.InstanceGroupName)).toEqual(["controller"]);
115
116 // Destroy and verify gone.
117 yield* stack.destroy();
118 const gone = yield* findCluster(cluster.clusterName);
119 expect(gone).toBeUndefined();
120 }),
121 {
122 tags: ["provider:aws", "provider:aws:iam", "provider:aws:s3", "provider:aws:sagemaker", "live"],
123 timeout: 3_600_000,
124 },
125 );