Public: anyone can read this; the crew can change it.
A test pins which app environment names are accepted and which are reserved #6767
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/6759-a-test-pins-which-app-environment-names → main 1 commit fork 1 thread · 1 unresolved
1 file
changed +52
−0
test/app-env-names.test.ts added +52
| @@ -0,0 +1,52 @@ | ||
| 1 | import { describe, expect, test } from "bun:test"; | |
| 2 | import { | |
| 3 | APP_ENV_SCOPES, | |
| 4 | isAppEnvName, | |
| 5 | isAppEnvScope, | |
| 6 | isReservedAppEnvName, | |
| 7 | NAME_MAX, | |
| 8 | scopeOfEnv, | |
| 9 | } from "../src/core/app_env.ts"; | |
| 10 | ||
| 11 | describe("isAppEnvName", () => { | |
| 12 | test("accepts shell-style upper-case names up to NAME_MAX", () => { | |
| 13 | for (const n of ["A", "API_KEY", "X1", "A".repeat(NAME_MAX)]) | |
| 14 | expect(isAppEnvName(n)).toBe(true); | |
| 15 | }); | |
| 16 | ||
| 17 | test("refuses empty, lower-case, leading digit or underscore, and odd characters", () => { | |
| 18 | for (const n of ["", "api_key", "1A", "_A", "A-B", "A B", "A".repeat(NAME_MAX + 1)]) | |
| 19 | expect(isAppEnvName(n)).toBe(false); | |
| 20 | }); | |
| 21 | }); | |
| 22 | ||
| 23 | describe("isReservedAppEnvName", () => { | |
| 24 | test("is true for every name the forge sets itself", () => { | |
| 25 | for (const n of ["PORT", "HOST", "NODE_ENV", "PATH", "HOME", "LANG", "TMPDIR", "USER", "LOGNAME"]) | |
| 26 | expect(isReservedAppEnvName(n)).toBe(true); | |
| 27 | }); | |
| 28 | ||
| 29 | test("is true for any FORGE_ prefix", () => { | |
| 30 | for (const n of ["FORGE_APP_DATA", "FORGE_X"]) | |
| 31 | expect(isReservedAppEnvName(n)).toBe(true); | |
| 32 | }); | |
| 33 | ||
| 34 | test("is false for look-alikes", () => { | |
| 35 | for (const n of ["FORGEX", "MY_FORGE_X", "API_KEY"]) | |
| 36 | expect(isReservedAppEnvName(n)).toBe(false); | |
| 37 | }); | |
| 38 | }); | |
| 39 | ||
| 40 | describe("scopes", () => { | |
| 41 | test("isAppEnvScope accepts each scope and nothing else", () => { | |
| 42 | for (const s of APP_ENV_SCOPES) expect(isAppEnvScope(s)).toBe(true); | |
| 43 | for (const s of ["Production", "", "dev"]) expect(isAppEnvScope(s)).toBe(false); | |
| 44 | }); | |
| 45 | ||
| 46 | test("scopeOfEnv maps production to production and every other environment to preview", () => { | |
| 47 | expect(scopeOfEnv("production")).toBe("production"); | |
| 48 | expect(scopeOfEnv("preview")).toBe("preview"); | |
| 49 | expect(scopeOfEnv("4417")).toBe("preview"); | |
| 50 | expect(scopeOfEnv("")).toBe("preview"); | |
| 51 | }); | |
| 52 | }); |
new above
offline
The nine names are hand-copied from the module. If the module exports RESERVED, iterate it here so the list cannot drift.