|
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import type { BuildContext, BuildLayer } from "@trigger.dev/core/v3/build"; |
| 3 | +import { syncEnvVars, type SyncEnvVarsFunction } from "./syncEnvVars.js"; |
| 4 | + |
| 5 | +async function runExtension(fn: SyncEnvVarsFunction): Promise<BuildLayer | undefined> { |
| 6 | + let captured: BuildLayer | undefined; |
| 7 | + |
| 8 | + const context = { |
| 9 | + target: "deploy", |
| 10 | + config: { project: "proj_test" }, |
| 11 | + logger: { |
| 12 | + spinner: () => ({ stop: () => {} }), |
| 13 | + }, |
| 14 | + addLayer: (layer: BuildLayer) => { |
| 15 | + captured = layer; |
| 16 | + }, |
| 17 | + } as unknown as BuildContext; |
| 18 | + |
| 19 | + const manifest = { |
| 20 | + deploy: { env: {} }, |
| 21 | + environment: "prod", |
| 22 | + branch: undefined, |
| 23 | + } as any; |
| 24 | + |
| 25 | + const extension = syncEnvVars(fn); |
| 26 | + await extension.onBuildComplete!(context, manifest); |
| 27 | + |
| 28 | + return captured; |
| 29 | +} |
| 30 | + |
| 31 | +describe("syncEnvVars isSecret", () => { |
| 32 | + it("partitions secret and non-secret vars across child and parent", async () => { |
| 33 | + const layer = await runExtension(() => [ |
| 34 | + { name: "PUBLIC_URL", value: "https://example.com" }, |
| 35 | + { name: "API_KEY", value: "secret-key", isSecret: true }, |
| 36 | + { name: "PARENT_PUBLIC", value: "parent", isParentEnv: true }, |
| 37 | + { name: "PARENT_SECRET", value: "parent-secret", isParentEnv: true, isSecret: true }, |
| 38 | + ]); |
| 39 | + |
| 40 | + expect(layer?.deploy?.env).toEqual({ PUBLIC_URL: "https://example.com" }); |
| 41 | + expect(layer?.deploy?.secretEnv).toEqual({ API_KEY: "secret-key" }); |
| 42 | + expect(layer?.deploy?.parentEnv).toEqual({ PARENT_PUBLIC: "parent" }); |
| 43 | + expect(layer?.deploy?.secretParentEnv).toEqual({ PARENT_SECRET: "parent-secret" }); |
| 44 | + }); |
| 45 | + |
| 46 | + it("treats the record form as all non-secret", async () => { |
| 47 | + const layer = await runExtension(() => ({ DATABASE_URL: "postgres://..." })); |
| 48 | + |
| 49 | + expect(layer?.deploy?.env).toEqual({ DATABASE_URL: "postgres://..." }); |
| 50 | + expect(layer?.deploy?.secretEnv).toBeUndefined(); |
| 51 | + expect(layer?.deploy?.secretParentEnv).toBeUndefined(); |
| 52 | + }); |
| 53 | + |
| 54 | + it("omits secret buckets when no var is marked secret", async () => { |
| 55 | + const layer = await runExtension(() => [{ name: "PUBLIC_URL", value: "https://example.com" }]); |
| 56 | + |
| 57 | + expect(layer?.deploy?.env).toEqual({ PUBLIC_URL: "https://example.com" }); |
| 58 | + expect(layer?.deploy?.secretEnv).toBeUndefined(); |
| 59 | + expect(layer?.deploy?.secretParentEnv).toBeUndefined(); |
| 60 | + }); |
| 61 | +}); |
0 commit comments