The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { functionEnvironment, functionSlug } from "@alchemy.run/neon/FunctionConfig"; |
| 2 | import { expect, test } from "@alchemy.run/test"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Redacted from "effect/Redacted"; |
| 5 | |
| 6 | const props = { branch: { projectId: "project", branchId: "branch" }, main: "index.ts" }; |
| 7 | for (const key of [ |
| 8 | "NEON_API_KEY", |
| 9 | "DATABASE_URL", |
| 10 | "AWS_SECRET_ACCESS_KEY", |
| 11 | "NEON_AI_GATEWAY_TOKEN", |
| 12 | "NEON_DATA_API_URL", |
| 13 | "NEON_BRANCH", |
| 14 | "ALCHEMY_STAGE", |
| 15 | ]) { |
| 16 | test.effect( |
| 17 | `rejects overriding injected environment ${key}`, |
| 18 | () => |
| 19 | Effect.gen(function* () { |
| 20 | const rejected = yield* functionEnvironment( |
| 21 | { ...props, env: { [key]: "must-not-deploy" } }, |
| 22 | [], |
| 23 | ).pipe( |
| 24 | Effect.as(false), |
| 25 | Effect.catchTag("FunctionConfigurationError", () => Effect.succeed(true)), |
| 26 | ); |
| 27 | expect(rejected).toBe(true); |
| 28 | }), |
| 29 | { tags: ["unit", "provider:neon", "provider:neon:function", "local"] }, |
| 30 | ); |
| 31 | } |
| 32 | test.effect( |
| 33 | "unwraps redacted application values only at deployment", |
| 34 | () => |
| 35 | Effect.gen(function* () { |
| 36 | expect( |
| 37 | yield* functionEnvironment( |
| 38 | { ...props, env: { APP_TOKEN: Redacted.make("test-token"), OMITTED: undefined } }, |
| 39 | [], |
| 40 | ), |
| 41 | ).toEqual({ APP_TOKEN: "test-token" }); |
| 42 | }), |
| 43 | { tags: ["unit", "provider:neon", "provider:neon:function", "local"] }, |
| 44 | ); |
| 45 | for (const slug of ["contains-hyphen", "Uppercase", "morethan20characterslong", ""]) { |
| 46 | test.effect( |
| 47 | `rejects invalid explicit slug ${JSON.stringify(slug)}`, |
| 48 | () => |
| 49 | Effect.gen(function* () { |
| 50 | expect( |
| 51 | yield* functionSlug("Api", slug).pipe( |
| 52 | Effect.as(false), |
| 53 | Effect.catchTag("FunctionConfigurationError", () => Effect.succeed(true)), |
| 54 | ), |
| 55 | ).toBe(true); |
| 56 | }), |
| 57 | { tags: ["unit", "provider:neon", "provider:neon:function", "local"] }, |
| 58 | ); |
| 59 | } |