@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 121 lines 4.57 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { ClusterSchedulerConfig } from "@alchemy.run/aws/SageMaker";
3 import { expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as sagemaker from "@distilled.cloud/aws/sagemaker";
6 import * as Effect from "effect/Effect";
7
8 const { test } = Test.make({ providers: AWS.providers() });
9
10 // Ungated typed-error probe: prove describeClusterSchedulerConfig returns
11 // the typed ResourceNotFound for a nonexistent policy id.
12 test.provider(
13 "describeClusterSchedulerConfig on a nonexistent id fails with ResourceNotFound",
14 () =>
15 Effect.gen(function* () {
16 const error = yield* Effect.flip(
17 sagemaker.describeClusterSchedulerConfig({
18 ClusterSchedulerConfigId: "abcdef012345",
19 }),
20 );
21 expect(error._tag).toBe("ResourceNotFound");
22 }),
23 { tags: ["provider:aws", "provider:aws:sagemaker", "live"] },
24 );
25
26 const findConfig = (configId: string) =>
27 sagemaker
28 .describeClusterSchedulerConfig({ ClusterSchedulerConfigId: configId })
29 .pipe(Effect.catchTag("ResourceNotFound", () => Effect.succeed(undefined)));
30
31 // Cluster policies require an EKS-orchestrated HyperPod cluster, which takes
32 // ~30 minutes and real ML + EKS capacity to stand up. Gated behind an
33 // existing cluster:
34 // AWS_TEST_SAGEMAKER_HYPERPOD_EKS_CLUSTER_ARN=<arn of an EKS HyperPod cluster>
35 //
36 // AWS allows ONE cluster policy per cluster. When the provided cluster
37 // already carries one (e.g. the examples/aws-hyperpod stack's), this test
38 // verifies the typed conflict instead of the full lifecycle.
39 test.provider.skipIf(!process.env.AWS_TEST_SAGEMAKER_HYPERPOD_EKS_CLUSTER_ARN)(
40 "create cluster policy, update it, destroy",
41 (stack) =>
42 Effect.gen(function* () {
43 yield* stack.destroy();
44
45 const clusterArn = process.env.AWS_TEST_SAGEMAKER_HYPERPOD_EKS_CLUSTER_ARN!;
46
47 const existing = yield* sagemaker.listClusterSchedulerConfigs({
48 ClusterArn: clusterArn,
49 });
50 if ((existing.ClusterSchedulerConfigSummaries ?? []).some((s) => s.Status !== "Deleted")) {
51 // One policy per cluster: creating a second must fail with the
52 // typed ClusterSchedulerConfigAlreadyExists tag.
53 const error = yield* Effect.flip(
54 sagemaker.createClusterSchedulerConfig({
55 Name: "alchemy-conflict-probe",
56 ClusterArn: clusterArn,
57 SchedulerConfig: { FairShare: "Enabled" },
58 }),
59 );
60 expect(error._tag).toBe("ClusterSchedulerConfigAlreadyExists");
61 return;
62 }
63
64 const { policy } = yield* stack.deploy(
65 Effect.gen(function* () {
66 const policy = yield* ClusterSchedulerConfig("TestPolicy", {
67 clusterArn,
68 schedulerConfig: {
69 PriorityClasses: [{ Name: "training", Weight: 75 }],
70 FairShare: "Enabled",
71 },
72 description: "alchemy test policy",
73 tags: { purpose: "alchemy-test" },
74 });
75 return { policy };
76 }),
77 );
78
79 expect(policy.clusterSchedulerConfigArn).toContain(":cluster-scheduler-config/");
80 expect(policy.clusterArn).toBe(clusterArn);
81
82 // Out-of-band verification via distilled.
83 const described = yield* findConfig(policy.clusterSchedulerConfigId);
84 expect(described?.Status).toBe("Created");
85 expect(described?.SchedulerConfig?.PriorityClasses).toEqual([
86 { Name: "training", Weight: 75 },
87 ]);
88
89 // Update in place — the id must remain stable and the version bump.
90 const { policy: updated } = yield* stack.deploy(
91 Effect.gen(function* () {
92 const policy = yield* ClusterSchedulerConfig("TestPolicy", {
93 clusterArn,
94 schedulerConfig: {
95 PriorityClasses: [
96 { Name: "inference", Weight: 100 },
97 { Name: "training", Weight: 75 },
98 ],
99 FairShare: "Enabled",
100 },
101 description: "alchemy test policy v2",
102 tags: { purpose: "alchemy-test" },
103 });
104 return { policy };
105 }),
106 );
107 expect(updated.clusterSchedulerConfigId).toBe(policy.clusterSchedulerConfigId);
108 expect(updated.clusterSchedulerConfigVersion).toBeGreaterThan(
109 policy.clusterSchedulerConfigVersion,
110 );
111
112 // Destroy and verify gone.
113 yield* stack.destroy();
114 const gone = yield* findConfig(policy.clusterSchedulerConfigId);
115 expect(gone === undefined || gone.Status === "Deleted").toBe(true);
116 }),
117 {
118 tags: ["provider:aws", "provider:aws:sagemaker", "live"],
119 timeout: 600_000,
120 },
121 );