@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 143 lines 4.96 KB
Raw
1 import * as AWS from "@alchemy.run/aws";
2 import { Registry, Schema } from "@alchemy.run/aws/Schemas";
3 import { describe, expect } from "@alchemy.run/test";
4 import * as Test from "@alchemy.run/test/Alchemy";
5 import * as schemas from "@distilled.cloud/aws/schemas";
6 import * as Effect from "effect/Effect";
7 import * as Schedule from "effect/Schedule";
8
9 const { test } = Test.make({ providers: AWS.providers() });
10
11 const contentV1 = JSON.stringify({
12 openapi: "3.0.0",
13 info: { version: "1.0.0", title: "OrderCreated" },
14 paths: {},
15 components: {
16 schemas: {
17 OrderCreated: {
18 type: "object",
19 properties: {
20 orderId: { type: "string" },
21 },
22 },
23 },
24 },
25 });
26
27 const contentV2 = JSON.stringify({
28 openapi: "3.0.0",
29 info: { version: "1.0.0", title: "OrderCreated" },
30 paths: {},
31 components: {
32 schemas: {
33 OrderCreated: {
34 type: "object",
35 properties: {
36 orderId: { type: "string" },
37 amount: { type: "number" },
38 },
39 },
40 },
41 },
42 });
43
44 const assertSchemaGone = (registryName: string, schemaName: string) =>
45 schemas.describeSchema({ RegistryName: registryName, SchemaName: schemaName }).pipe(
46 Effect.flatMap(() => Effect.fail(new Error(`schema ${schemaName} still exists`))),
47 Effect.catchTag("NotFoundException", () => Effect.void),
48 Effect.retry({
49 while: (e) => e instanceof Error,
50 schedule: Schedule.max([Schedule.fixed("2 seconds"), Schedule.recurs(10)]),
51 }),
52 );
53
54 describe("AWS.Schemas.Schema", { tags: ["provider:aws", "provider:aws:schemas", "live"] }, () => {
55 test.provider(
56 "creates a schema, publishes a new version on content change, and deletes it",
57 (stack) =>
58 Effect.gen(function* () {
59 yield* stack.destroy();
60
61 // CREATE — registry + schema.
62 const created = yield* stack.deploy(
63 Effect.gen(function* () {
64 const registry = yield* Registry("SchemaTestRegistry", {});
65 const schema = yield* Schema("OrderCreated", {
66 registryName: registry.registryName,
67 type: "OpenApi3",
68 content: contentV1,
69 description: "Order created event",
70 tags: { purpose: "alchemy-test" },
71 });
72 return {
73 registryName: registry.registryName,
74 schemaName: schema.schemaName,
75 schemaArn: schema.schemaArn,
76 schemaVersion: schema.schemaVersion,
77 };
78 }),
79 );
80 expect(created.schemaVersion).toEqual("1");
81
82 // Verify out-of-band via distilled.
83 const observed = yield* schemas.describeSchema({
84 RegistryName: created.registryName,
85 SchemaName: created.schemaName,
86 });
87 expect(observed.SchemaArn).toEqual(created.schemaArn);
88 expect(observed.Type).toEqual("OpenApi3");
89 expect(observed.Description).toEqual("Order created event");
90 expect(JSON.parse(observed.Content!)).toEqual(JSON.parse(contentV1));
91 expect(observed.Tags?.purpose).toEqual("alchemy-test");
92 expect(observed.Tags?.["alchemy::id"]).toEqual("OrderCreated");
93
94 // NO-OP — redeploying identical desired state must not publish a new
95 // schema version (content comparison is canonical).
96 const noop = yield* stack.deploy(
97 Effect.gen(function* () {
98 const registry = yield* Registry("SchemaTestRegistry", {});
99 const schema = yield* Schema("OrderCreated", {
100 registryName: registry.registryName,
101 type: "OpenApi3",
102 content: contentV1,
103 description: "Order created event",
104 tags: { purpose: "alchemy-test" },
105 });
106 return { schemaVersion: schema.schemaVersion };
107 }),
108 );
109 expect(noop.schemaVersion).toEqual("1");
110
111 // UPDATE — new content publishes a new schema version.
112 const updated = yield* stack.deploy(
113 Effect.gen(function* () {
114 const registry = yield* Registry("SchemaTestRegistry", {});
115 const schema = yield* Schema("OrderCreated", {
116 registryName: registry.registryName,
117 type: "OpenApi3",
118 content: contentV2,
119 description: "Order created event",
120 tags: { purpose: "alchemy-test" },
121 });
122 return {
123 schemaName: schema.schemaName,
124 schemaVersion: schema.schemaVersion,
125 };
126 }),
127 );
128 expect(updated.schemaName).toEqual(created.schemaName);
129 expect(updated.schemaVersion).toEqual("2");
130
131 const afterUpdate = yield* schemas.describeSchema({
132 RegistryName: created.registryName,
133 SchemaName: created.schemaName,
134 });
135 expect(JSON.parse(afterUpdate.Content!)).toEqual(JSON.parse(contentV2));
136
137 // DELETE
138 yield* stack.destroy();
139 yield* assertSchemaGone(created.registryName, created.schemaName);
140 }),
141 { timeout: 120_000 },
142 );
143 });