|
| 1 | +// Testbox env hydration tests keep custom helper profiles self-contained. |
| 2 | +import { execFileSync } from "node:child_process"; |
| 3 | +import { existsSync, readFileSync, statSync } from "node:fs"; |
| 4 | +import { join } from "node:path"; |
| 5 | +import { afterEach, describe, expect, it } from "vitest"; |
| 6 | +import { cleanupTempDirs, makeTempDir } from "../helpers/temp-dir.js"; |
| 7 | + |
| 8 | +const tempDirs = new Set<string>(); |
| 9 | +const SCRIPT = "scripts/ci-hydrate-testbox-env.sh"; |
| 10 | + |
| 11 | +afterEach(() => { |
| 12 | +cleanupTempDirs(tempDirs); |
| 13 | +}); |
| 14 | + |
| 15 | +function runBash(args: string[], env: NodeJS.ProcessEnv = {}): string { |
| 16 | +return execFileSync("/bin/bash", ["--noprofile", "--norc", ...args], { |
| 17 | +cwd: process.cwd(), |
| 18 | +encoding: "utf8", |
| 19 | +env: { |
| 20 | + ...process.env, |
| 21 | + ...env, |
| 22 | +}, |
| 23 | +stdio: ["ignore", "pipe", "pipe"], |
| 24 | +}); |
| 25 | +} |
| 26 | + |
| 27 | +describe("scripts/ci-hydrate-testbox-env.sh", () => { |
| 28 | +it("bakes custom profile paths into the generated helper default", () => { |
| 29 | +const root = makeTempDir(tempDirs, "openclaw-testbox-env-"); |
| 30 | +const home = join(root, "home"); |
| 31 | +const profilePath = join(root, "custom profile.env"); |
| 32 | +const helperPath = join(root, "bin", "openclaw-testbox-env"); |
| 33 | + |
| 34 | +runBash([SCRIPT, profilePath, helperPath], { |
| 35 | +HOME: home, |
| 36 | +OPENAI_API_KEY: "testbox-sentinel-key", |
| 37 | +}); |
| 38 | + |
| 39 | +expect(existsSync(profilePath)).toBe(true); |
| 40 | +expect(readFileSync(profilePath, "utf8")).toContain( |
| 41 | +"export OPENAI_API_KEY=testbox-sentinel-key", |
| 42 | +); |
| 43 | +expect(statSync(helperPath).mode & 0o777).toBe(0o700); |
| 44 | + |
| 45 | +const helper = readFileSync(helperPath, "utf8"); |
| 46 | +expect(helper).toContain("default_profile_path="); |
| 47 | +expect(helper).toContain("custom\\ profile.env"); |
| 48 | +expect(helper).not.toContain(".openclaw-testbox-live.profile"); |
| 49 | + |
| 50 | +const output = runBash([helperPath, "env"], { |
| 51 | +HOME: home, |
| 52 | +OPENCLAW_TESTBOX_PROFILE_FILE: "", |
| 53 | +}); |
| 54 | +expect(output).toContain("OPENAI_API_KEY=testbox-sentinel-key\n"); |
| 55 | +}); |
| 56 | +}); |