@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 100 lines 3.38 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { describe, expect } from "@alchemy.run/test";
3 import * as Test from "@alchemy.run/test/Alchemy";
4 import * as Core from "@alchemy.run/test/Core";
5 import * as Effect from "effect/Effect";
6 import * as HttpClient from "effect/http/HttpClient";
7 import * as Schedule from "effect/Schedule";
8 import SageMakerEndpointTestFunctionLive, {
9 SageMakerEndpointTestFunction,
10 } from "./endpoint-handler";
11
12 // A live endpoint deploys real serving capacity (~3-10 min to InService) and
13 // requires a working inference container. Same gate as Endpoint.test.ts:
14 // AWS_TEST_SAGEMAKER_ENDPOINT=1
15 // AWS_TEST_SAGEMAKER_IMAGE=<ECR URI of a serving container>
16 const gated = !process.env.AWS_TEST_SAGEMAKER_ENDPOINT || !process.env.AWS_TEST_SAGEMAKER_IMAGE;
17
18 const testOptions = { providers: AWS.providers() };
19 const { test, beforeAll, afterAll } = Test.make(testOptions);
20 const sharedStack = Core.scratchStack(testOptions, "SageMakerEndpointBindings");
21
22 let baseUrl: string;
23
24 describe(
25 "SageMaker Endpoint Bindings",
26 {
27 tags: [
28 "provider:aws",
29 "provider:aws:iam",
30 "provider:aws:lambda",
31 "provider:aws:sagemaker",
32 "live",
33 ],
34 },
35 () => {
36 beforeAll(
37 Effect.gen(function* () {
38 if (gated) return;
39
40 yield* sharedStack.destroy();
41 const attrs = yield* sharedStack.deploy(
42 Effect.gen(function* () {
43 return yield* SageMakerEndpointTestFunction;
44 }).pipe(Effect.provide(SageMakerEndpointTestFunctionLive)),
45 );
46
47 expect(attrs.functionUrl).toBeTruthy();
48 baseUrl = attrs.functionUrl!.replace(/\/+$/, "");
49
50 yield* HttpClient.get(`${baseUrl}/health`).pipe(
51 Effect.flatMap((response) =>
52 response.status === 200
53 ? Effect.succeed(response)
54 : Effect.fail(new Error(`Function not ready: ${response.status}`)),
55 ),
56 Effect.retry({
57 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(75)]),
58 }),
59 );
60 }),
61 { timeout: 1_500_000 },
62 );
63
64 afterAll.skipIf(gated)(sharedStack.destroy(), { timeout: 1_200_000 });
65
66 describe("DescribeEndpoint", () => {
67 test.provider.skipIf(gated)(
68 "reads the bound endpoint's live status (injected endpoint name)",
69 () =>
70 Effect.gen(function* () {
71 const client = yield* HttpClient.HttpClient;
72 const response = yield* client.get(`${baseUrl}/describe-endpoint`);
73 expect(response.status).toBe(200);
74 const body = (yield* response.json) as {
75 endpointName: string;
76 status: string;
77 variants: string[];
78 };
79 expect(body.status).toBe("InService");
80 expect(body.variants).toContain("AllTraffic");
81 }),
82 { timeout: 120_000 },
83 );
84 });
85
86 describe("UpdateEndpointWeightsAndCapacities", () => {
87 test.provider.skipIf(gated)(
88 "the binding registers on the runtime (IAM grant proven by deploy)",
89 () =>
90 Effect.gen(function* () {
91 const client = yield* HttpClient.HttpClient;
92 const response = yield* client.get(`${baseUrl}/bindings`);
93 const body = (yield* response.json) as { bound: string[] };
94 expect(body.bound).toContain("updateWeights");
95 }),
96 { timeout: 60_000 },
97 );
98 });
99 },
100 );