clone

a deno framework for local-first web apps that open instantly, work offline and sync when users choose

feat/fix-sync-enrollment-startup
lofi / package / tooling / environment_test.ts
environment_test.ts 2.0K
1// Package contract tests for child-process environment projection.2import { childEnvironment, validateEnvironment } from "./environment.ts";34function assert(condition: unknown, message: string): asserts condition {5 if (!condition) throw new Error(message);6}78Deno.test("child environments keep Windows-cased and bootstrap variables", () => {9 const validation = validateEnvironment({});10 assert(validation.ok, "an empty environment must validate as local-only");11 const child = childEnvironment(validation, {12 Path: "C:\\Windows;C:\\bin",13 SystemRoot: "C:\\Windows",14 ComSpec: "C:\\Windows\\system32\\cmd.exe",15 USERPROFILE: "C:\\Users\\dev",16 SECRET_TOKEN: "never",17 });18 // Children run with a cleared environment; Windows delivers names with19 // arbitrary casing, and dropping them breaks DLL and executable resolution.20 assert(child.Path === "C:\\Windows;C:\\bin", "Windows-cased Path must be forwarded");21 assert(child.SystemRoot === "C:\\Windows", "SystemRoot must survive the cleared environment");22 assert(child.ComSpec?.endsWith("cmd.exe"), "ComSpec must be forwarded");23 assert(child.USERPROFILE === "C:\\Users\\dev", "per-user state must be forwarded");24 assert(!("SECRET_TOKEN" in child), "unlisted variables must never be forwarded");25 assert(26 child.JAZZ_ADMIN_SECRET === "" && child.BACKEND_SECRET === "",27 "server secrets remain explicitly cleared",28 );29});3031Deno.test("child environments still forward the POSIX allowlist exactly", () => {32 const validation = validateEnvironment({});33 assert(validation.ok, "an empty environment must validate as local-only");34 const child = childEnvironment(validation, {35 PATH: "/usr/bin",36 HOME: "/home/dev",37 LANG: "en_US.UTF-8",38 LD_PRELOAD: "/tmp/evil.so",39 });40 assert(child.PATH === "/usr/bin" && child.HOME === "/home/dev", "allowlist must be forwarded");41 assert(child.LANG === "en_US.UTF-8", "locale must be forwarded");42 assert(!("LD_PRELOAD" in child), "non-allowlisted variables must be dropped");43});