|
| 1 | +// Test Live Gateway Models Docker tests cover gateway live model Docker script behavior. |
| 2 | +import { spawnSync } from "node:child_process"; |
| 3 | +import fs from "node:fs"; |
| 4 | +import path from "node:path"; |
| 5 | +import { describe, expect, it } from "vitest"; |
| 6 | + |
| 7 | +const SCRIPT_PATH = path.resolve( |
| 8 | +import.meta.dirname, |
| 9 | +"../../scripts/test-live-gateway-models-docker.sh", |
| 10 | +); |
| 11 | + |
| 12 | +describe("scripts/test-live-gateway-models-docker.sh", () => { |
| 13 | +it("validates numeric live gateway limits before auth or Docker setup", () => { |
| 14 | +const script = fs.readFileSync(SCRIPT_PATH, "utf8"); |
| 15 | + |
| 16 | +expect(script).toContain( |
| 17 | +'LIVE_GATEWAY_MAX_MODELS="$(openclaw_live_read_positive_int_env OPENCLAW_LIVE_GATEWAY_MAX_MODELS 8)"', |
| 18 | +); |
| 19 | +expect(script).toContain( |
| 20 | +'LIVE_GATEWAY_STEP_TIMEOUT_MS="$(openclaw_live_read_positive_int_env OPENCLAW_LIVE_GATEWAY_STEP_TIMEOUT_MS 45000)"', |
| 21 | +); |
| 22 | +expect(script).toContain( |
| 23 | +'LIVE_GATEWAY_MODEL_TIMEOUT_MS="$(openclaw_live_read_positive_int_env OPENCLAW_LIVE_GATEWAY_MODEL_TIMEOUT_MS 90000)"', |
| 24 | +); |
| 25 | +expect(script).toContain('-e OPENCLAW_LIVE_GATEWAY_MAX_MODELS="$LIVE_GATEWAY_MAX_MODELS"'); |
| 26 | +expect(script).toContain( |
| 27 | +'-e OPENCLAW_LIVE_GATEWAY_STEP_TIMEOUT_MS="$LIVE_GATEWAY_STEP_TIMEOUT_MS"', |
| 28 | +); |
| 29 | +expect(script).toContain( |
| 30 | +'-e OPENCLAW_LIVE_GATEWAY_MODEL_TIMEOUT_MS="$LIVE_GATEWAY_MODEL_TIMEOUT_MS"', |
| 31 | +); |
| 32 | +}); |
| 33 | + |
| 34 | +it.each([ |
| 35 | +["max models", "OPENCLAW_LIVE_GATEWAY_MAX_MODELS", "two"], |
| 36 | +["step timeout", "OPENCLAW_LIVE_GATEWAY_STEP_TIMEOUT_MS", "45s"], |
| 37 | +["model timeout", "OPENCLAW_LIVE_GATEWAY_MODEL_TIMEOUT_MS", "90s"], |
| 38 | +])("rejects invalid %s values before live Docker setup", (_label, envName, value) => { |
| 39 | +const result = spawnSync("bash", [SCRIPT_PATH], { |
| 40 | +encoding: "utf8", |
| 41 | +env: { |
| 42 | + ...process.env, |
| 43 | +[envName]: value, |
| 44 | +}, |
| 45 | +}); |
| 46 | + |
| 47 | +expect(result.status).toBe(2); |
| 48 | +expect(result.stderr).toContain(`invalid ${envName}: ${value}`); |
| 49 | +expect(result.stderr).not.toContain("docker"); |
| 50 | +expect(result.stderr).not.toContain("Cannot find package 'tsx'"); |
| 51 | +}); |
| 52 | +}); |