@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 98 lines 3.66 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Role } from "@alchemy.run/aws/IAM/Role";
3 import { Endpoint, EndpointConfig, Model } from "@alchemy.run/aws/SageMaker";
4 import { expect } from "@alchemy.run/test";
5 import * as Test from "@alchemy.run/test/Alchemy";
6 import * as sagemaker from "@distilled.cloud/aws/sagemaker";
7 import * as Effect from "effect/Effect";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 // Ungated typed-error probe: prove the distilled patch carves EndpointNotFound
12 // out of the overloaded ValidationException. Runs in every CI pass.
13 test.provider(
14 "describeEndpoint on a nonexistent endpoint fails with EndpointNotFound",
15 () =>
16 Effect.gen(function* () {
17 const error = yield* Effect.flip(
18 sagemaker.describeEndpoint({
19 EndpointName: "alchemy-nonexistent-sagemaker-endpoint-probe",
20 }),
21 );
22 expect(error._tag).toBe("EndpointNotFound");
23 }),
24 { tags: ["provider:aws", "provider:aws:sagemaker", "live"] },
25 );
26
27 const findEndpoint = (name: string) =>
28 sagemaker
29 .describeEndpoint({ EndpointName: name })
30 .pipe(Effect.catchTag("EndpointNotFound", () => Effect.succeed(undefined)));
31
32 // A live endpoint deploys real serving capacity: it takes ~3-10 minutes to
33 // reach InService and REQUIRES a working inference container. Gated behind:
34 // AWS_TEST_SAGEMAKER_ENDPOINT=1
35 // AWS_TEST_SAGEMAKER_IMAGE=<ECR URI of a serving container>
36 // AWS_TEST_SAGEMAKER_MODEL_DATA=<s3://... model.tar.gz> (optional)
37 test.provider.skipIf(
38 !process.env.AWS_TEST_SAGEMAKER_ENDPOINT || !process.env.AWS_TEST_SAGEMAKER_IMAGE,
39 )(
40 "create serverless endpoint, wait InService, destroy",
41 (stack) =>
42 Effect.gen(function* () {
43 yield* stack.destroy();
44
45 const image = process.env.AWS_TEST_SAGEMAKER_IMAGE!;
46 const modelData = process.env.AWS_TEST_SAGEMAKER_MODEL_DATA;
47
48 const { endpoint } = yield* stack.deploy(
49 Effect.gen(function* () {
50 const role = yield* Role("SageMakerEndpointRole", {
51 assumeRolePolicyDocument: {
52 Version: "2012-10-17",
53 Statement: [
54 {
55 Effect: "Allow",
56 Principal: { Service: "sagemaker.amazonaws.com" },
57 Action: ["sts:AssumeRole"],
58 },
59 ],
60 },
61 managedPolicyArns: ["arn:aws:iam::aws:policy/AmazonSageMakerFullAccess"],
62 });
63 const model = yield* Model("EndpointTestModel", {
64 executionRoleArn: role.roleArn,
65 primaryContainer: { Image: image, ...(modelData ? { ModelDataUrl: modelData } : {}) },
66 });
67 const config = yield* EndpointConfig("EndpointTestConfig", {
68 productionVariants: [
69 {
70 VariantName: "AllTraffic",
71 ModelName: model.modelName,
72 ServerlessConfig: { MemorySizeInMB: 2048, MaxConcurrency: 1 },
73 },
74 ],
75 });
76 const endpoint = yield* Endpoint("TestEndpoint", {
77 endpointConfigName: config.endpointConfigName,
78 });
79 return { endpoint };
80 }),
81 );
82
83 expect(endpoint.endpointArn).toContain(":endpoint/");
84 expect(endpoint.endpointStatus).toBe("InService");
85
86 // out-of-band verification via distilled
87 const observed = yield* findEndpoint(endpoint.endpointName);
88 expect(observed?.EndpointStatus).toBe("InService");
89
90 // delete waits until the endpoint is fully gone
91 yield* stack.destroy();
92 expect(yield* findEndpoint(endpoint.endpointName)).toBeUndefined();
93 }),
94 {
95 tags: ["provider:aws", "provider:aws:iam", "provider:aws:sagemaker", "live"],
96 timeout: 1_500_000,
97 },
98 );