@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 86 lines 3.22 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Cluster } from "@alchemy.run/aws/ECS/Cluster";
3 import { every } from "@alchemy.run/aws/ECS/Schedule";
4 import { Task } from "@alchemy.run/aws/ECS/Task";
5 import { expect } from "@alchemy.run/test";
6 import * as Test from "@alchemy.run/test/Alchemy";
7 import * as scheduler from "@distilled.cloud/aws/scheduler";
8 import * as Effect from "effect/Effect";
9 import { getDefaultVpcNetwork } from "../DefaultVpc.ts";
10
11 const { test } = Test.make({ providers: AWS.providers() });
12
13 // `AWS.ECS.every` synthesizes an EventBridge Scheduler schedule plus the
14 // invoke role required to `ecs:RunTask` the target definition. Deploy a
15 // cluster + external busybox task + schedule, verify the schedule wiring
16 // out-of-band via the Scheduler API (expression, ECS target, network
17 // config, role), then destroy and verify the schedule is gone.
18 test.provider(
19 "every schedules an ECS RunTask target",
20 (stack) =>
21 Effect.gen(function* () {
22 yield* stack.destroy();
23
24 const { subnetIds } = yield* getDefaultVpcNetwork;
25 const subnets = subnetIds.slice(0, 2);
26
27 const { scheduleName, taskDefinitionArn, clusterArn } = yield* stack.deploy(
28 Effect.gen(function* () {
29 const cluster = yield* Cluster("EveryCluster", {
30 clusterName: "alchemy-test-ecs-every",
31 });
32 const task = yield* Task("EveryTask", {
33 image: "busybox:stable",
34 command: ["sh", "-c", "echo alchemy-ecs-every"],
35 cpu: 256,
36 memory: 512,
37 taskName: "alchemy-test-ecs-every",
38 });
39 // The id doubles as the schedule's physical name.
40 const schedule = yield* every("alchemy-test-ecs-every-heartbeat", "cron(0 3 * * ? *)", {
41 cluster,
42 task,
43 subnets,
44 });
45 return {
46 scheduleName: schedule.scheduleName,
47 taskDefinitionArn: task.taskDefinitionArn,
48 clusterArn: cluster.clusterArn,
49 };
50 }),
51 );
52
53 // Observe the schedule out-of-band: the cron expression passes
54 // through untouched, and the ECS target carries the task definition,
55 // the cluster as the target ARN, the awsvpc network config, and the
56 // synthesized invoke role.
57 const described = yield* scheduler.getSchedule({
58 Name: scheduleName,
59 });
60 expect(described.ScheduleExpression).toBe("cron(0 3 * * ? *)");
61 expect(described.Target?.Arn).toBe(clusterArn);
62 expect(described.Target?.EcsParameters?.TaskDefinitionArn).toBe(taskDefinitionArn);
63 expect(described.Target?.EcsParameters?.LaunchType).toBe("FARGATE");
64 expect(
65 described.Target?.EcsParameters?.NetworkConfiguration?.awsvpcConfiguration?.Subnets,
66 ).toEqual(subnets);
67 expect(described.Target?.RoleArn).toContain(":role/");
68
69 yield* stack.destroy();
70
71 const gone = yield* scheduler
72 .getSchedule({ Name: scheduleName })
73 .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined)));
74 expect(gone).toBeUndefined();
75 }),
76 {
77 tags: [
78 "provider:aws",
79 "provider:aws:ec2",
80 "provider:aws:ecs",
81 "provider:aws:scheduler",
82 "live",
83 ],
84 timeout: 240_000,
85 },
86 );