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

main
ts 101 lines 3.74 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 { EndpointConfig, Model } from "@alchemy.run/aws/SageMaker";
5 import { expect } from "@alchemy.run/test";
6 import * as Test from "@alchemy.run/test/Alchemy";
7 import * as sagemaker from "@distilled.cloud/aws/sagemaker";
8 import * as Effect from "effect/Effect";
9 import { sklearnImage } from "./images.ts";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 // Ungated typed-error probe: prove the distilled patch carves
14 // EndpointConfigNotFound out of the overloaded ValidationException.
15 test.provider(
16 "describeEndpointConfig on a nonexistent config fails with EndpointConfigNotFound",
17 () =>
18 Effect.gen(function* () {
19 const error = yield* Effect.flip(
20 sagemaker.describeEndpointConfig({
21 EndpointConfigName: "alchemy-nonexistent-sagemaker-config-probe",
22 }),
23 );
24 expect(error._tag).toBe("EndpointConfigNotFound");
25 }),
26 { tags: ["provider:aws", "provider:aws:sagemaker", "live"] },
27 );
28
29 const findConfig = (name: string) =>
30 sagemaker
31 .describeEndpointConfig({ EndpointConfigName: name })
32 .pipe(Effect.catchTag("EndpointConfigNotFound", () => Effect.succeed(undefined)));
33
34 test.provider(
35 "create serverless endpoint config, verify out-of-band, destroy",
36 (stack) =>
37 Effect.gen(function* () {
38 yield* stack.destroy();
39
40 const { region } = yield* AWSEnvironment.current;
41 const image = sklearnImage(region);
42
43 const { model, config } = yield* stack.deploy(
44 Effect.gen(function* () {
45 const role = yield* Role("SageMakerConfigRole", {
46 assumeRolePolicyDocument: {
47 Version: "2012-10-17",
48 Statement: [
49 {
50 Effect: "Allow",
51 Principal: { Service: "sagemaker.amazonaws.com" },
52 Action: ["sts:AssumeRole"],
53 },
54 ],
55 },
56 managedPolicyArns: ["arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"],
57 });
58 const model = yield* Model("ConfigTestModel", {
59 executionRoleArn: role.roleArn,
60 primaryContainer: { Image: image },
61 });
62 const config = yield* EndpointConfig("TestConfig", {
63 productionVariants: [
64 {
65 VariantName: "AllTraffic",
66 ModelName: model.modelName,
67 ServerlessConfig: { MemorySizeInMB: 1024, MaxConcurrency: 1 },
68 },
69 ],
70 tags: { purpose: "alchemy-test" },
71 });
72 return { model, config };
73 }),
74 );
75
76 expect(config.endpointConfigName).toBeDefined();
77 expect(config.endpointConfigArn).toContain(":endpoint-config/");
78
79 // out-of-band verification via distilled
80 const observed = yield* findConfig(config.endpointConfigName);
81 expect(observed?.EndpointConfigArn).toBe(config.endpointConfigArn);
82 const variant = observed?.ProductionVariants?.[0];
83 expect(variant?.ModelName).toBe(model.modelName);
84 expect(variant?.ServerlessConfig?.MemorySizeInMB).toBe(1024);
85
86 // internal ownership tags applied
87 const tags = yield* sagemaker
88 .listTags({ ResourceArn: config.endpointConfigArn })
89 .pipe(Effect.map((r) => r.Tags ?? []));
90 const tagMap = Object.fromEntries(tags.map((t) => [t.Key, t.Value]));
91 expect(tagMap["alchemy::id"]).toBe("TestConfig");
92 expect(tagMap.purpose).toBe("alchemy-test");
93
94 yield* stack.destroy();
95 expect(yield* findConfig(config.endpointConfigName)).toBeUndefined();
96 }),
97 {
98 tags: ["provider:aws", "provider:aws:iam", "provider:aws:sagemaker", "live"],
99 timeout: 240_000,
100 },
101 );