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
| 1 | import * as AWS from "@alchemy.run/aws"; |
| 2 | import { Recipe } from "@alchemy.run/aws/DataBrew"; |
| 3 | import { expect } from "@alchemy.run/test"; |
| 4 | import * as Test from "@alchemy.run/test/Alchemy"; |
| 5 | import * as databrew from "@distilled.cloud/aws/databrew"; |
| 6 | import * as Effect from "effect/Effect"; |
| 7 | |
| 8 | const { test } = Test.make({ providers: AWS.providers() }); |
| 9 | |
| 10 | const getWorkingRecipe = (name: string) => |
| 11 | databrew |
| 12 | .describeRecipe({ Name: name, RecipeVersion: "LATEST_WORKING" }) |
| 13 | .pipe(Effect.catchTag("ResourceNotFoundException", () => Effect.succeed(undefined))); |
| 14 | |
| 15 | test.provider( |
| 16 | "create, publish, update, delete DataBrew recipe", |
| 17 | (stack) => |
| 18 | Effect.gen(function* () { |
| 19 | yield* stack.destroy(); |
| 20 | |
| 21 | const created = yield* stack.deploy( |
| 22 | Effect.gen(function* () { |
| 23 | const recipe = yield* Recipe("Clean", { |
| 24 | description: "normalize names", |
| 25 | publish: true, |
| 26 | steps: [ |
| 27 | { |
| 28 | action: { |
| 29 | operation: "UPPER_CASE", |
| 30 | parameters: { sourceColumn: "name" }, |
| 31 | }, |
| 32 | }, |
| 33 | ], |
| 34 | tags: { Environment: "test" }, |
| 35 | }); |
| 36 | return { recipe }; |
| 37 | }), |
| 38 | ); |
| 39 | |
| 40 | expect(created.recipe.recipeName).toBeDefined(); |
| 41 | expect(created.recipe.recipeArn).toContain(`:recipe/${created.recipe.recipeName}`); |
| 42 | // publish: true snapshots version 1.0 on create |
| 43 | expect(created.recipe.recipeVersion).toEqual("1.0"); |
| 44 | |
| 45 | // out-of-band verification of the working copy |
| 46 | const observed = yield* getWorkingRecipe(created.recipe.recipeName); |
| 47 | expect(observed?.Description).toEqual("normalize names"); |
| 48 | expect(observed?.Steps?.length).toEqual(1); |
| 49 | expect(observed?.Steps?.[0]?.Action.Operation).toEqual("UPPER_CASE"); |
| 50 | expect(observed?.Tags?.["alchemy::id"]).toBeDefined(); |
| 51 | |
| 52 | // idempotent re-deploy: no step change -> no new published version |
| 53 | const same = yield* stack.deploy( |
| 54 | Effect.gen(function* () { |
| 55 | const recipe = yield* Recipe("Clean", { |
| 56 | description: "normalize names", |
| 57 | publish: true, |
| 58 | steps: [ |
| 59 | { |
| 60 | action: { |
| 61 | operation: "UPPER_CASE", |
| 62 | parameters: { sourceColumn: "name" }, |
| 63 | }, |
| 64 | }, |
| 65 | ], |
| 66 | tags: { Environment: "test" }, |
| 67 | }); |
| 68 | return { recipe }; |
| 69 | }), |
| 70 | ); |
| 71 | expect(same.recipe.recipeVersion).toEqual("1.0"); |
| 72 | |
| 73 | // update the steps -> working copy changes -> version 2.0 published |
| 74 | const updated = yield* stack.deploy( |
| 75 | Effect.gen(function* () { |
| 76 | const recipe = yield* Recipe("Clean", { |
| 77 | description: "normalize names", |
| 78 | publish: true, |
| 79 | steps: [ |
| 80 | { |
| 81 | action: { |
| 82 | operation: "UPPER_CASE", |
| 83 | parameters: { sourceColumn: "name" }, |
| 84 | }, |
| 85 | }, |
| 86 | { |
| 87 | action: { |
| 88 | operation: "REMOVE_VALUES", |
| 89 | parameters: { sourceColumn: "email" }, |
| 90 | }, |
| 91 | conditionExpressions: [{ condition: "IS_MISSING", targetColumn: "email" }], |
| 92 | }, |
| 93 | ], |
| 94 | tags: { Environment: "test" }, |
| 95 | }); |
| 96 | return { recipe }; |
| 97 | }), |
| 98 | ); |
| 99 | expect(updated.recipe.recipeVersion).toEqual("2.0"); |
| 100 | |
| 101 | const reobserved = yield* getWorkingRecipe(created.recipe.recipeName); |
| 102 | expect(reobserved?.Steps?.length).toEqual(2); |
| 103 | expect(reobserved?.Steps?.[1]?.Action.Operation).toEqual("REMOVE_VALUES"); |
| 104 | expect(reobserved?.Steps?.[1]?.ConditionExpressions?.[0]?.Condition).toEqual("IS_MISSING"); |
| 105 | |
| 106 | // destroy deletes every version (published + working) |
| 107 | yield* stack.destroy(); |
| 108 | const gone = yield* getWorkingRecipe(created.recipe.recipeName); |
| 109 | expect(gone).toBeUndefined(); |
| 110 | }), |
| 111 | { tags: ["provider:aws", "provider:aws:databrew", "live"], timeout: 120_000 }, |
| 112 | ); |