| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | import { codexScriptProgressConfig } from "./codexScriptProgress.ts"; |
| 3 | |
| 4 | const progress = { |
| 5 | NODE_OPTIONS: '--import="/private/progress.mjs"', |
| 6 | T3_SCRIPT_PROGRESS_ENDPOINT: "http://127.0.0.1:1234/ingest", |
| 7 | T3_SCRIPT_PROGRESS_TOKEN: "thread-one", |
| 8 | }; |
| 9 | |
| 10 | describe("Codex script progress environment", () => { |
| 11 | it("preserves user overrides and Node options without weakening exclusions", () => { |
| 12 | const policy = { |
| 13 | inherit: "core", |
| 14 | ignore_default_excludes: false, |
| 15 | exclude: ["PRIVATE_*"], |
| 16 | include_only: ["PATH", "MY_SETTING"], |
| 17 | set: { MY_SETTING: "keep", NODE_OPTIONS: "--trace-warnings" }, |
| 18 | }; |
| 19 | expect(codexScriptProgressConfig(policy, progress, "--max-old-space-size=2048")).toEqual({ |
| 20 | "shell_environment_policy.set": { |
| 21 | MY_SETTING: "keep", |
| 22 | ...progress, |
| 23 | NODE_OPTIONS: '--import="/private/progress.mjs" --max-old-space-size=2048 --trace-warnings', |
| 24 | }, |
| 25 | "shell_environment_policy.include_only": [ |
| 26 | "PATH", |
| 27 | "MY_SETTING", |
| 28 | "NODE_OPTIONS", |
| 29 | "T3_SCRIPT_PROGRESS_ENDPOINT", |
| 30 | "T3_SCRIPT_PROGRESS_TOKEN", |
| 31 | ], |
| 32 | }); |
| 33 | expect(policy.set.NODE_OPTIONS).toBe("--trace-warnings"); |
| 34 | expect(policy.include_only).toEqual(["PATH", "MY_SETTING"]); |
| 35 | }); |
| 36 | |
| 37 | it("accepts null optional fields returned by Codex config/read", () => { |
| 38 | expect( |
| 39 | codexScriptProgressConfig( |
| 40 | { |
| 41 | inherit: null, |
| 42 | ignore_default_excludes: null, |
| 43 | exclude: null, |
| 44 | set: {}, |
| 45 | include_only: null, |
| 46 | filters: null, |
| 47 | experimental_use_profile: null, |
| 48 | }, |
| 49 | progress, |
| 50 | ), |
| 51 | ).toEqual({ "shell_environment_policy.set": progress }); |
| 52 | expect(codexScriptProgressConfig({ set: null, include_only: null }, progress)).toEqual({ |
| 53 | "shell_environment_policy.set": progress, |
| 54 | }); |
| 55 | }); |
| 56 | |
| 57 | it("does not create an allowlist when the user inherits the normal environment", () => { |
| 58 | expect(codexScriptProgressConfig(undefined, progress)).toEqual({ |
| 59 | "shell_environment_policy.set": progress, |
| 60 | }); |
| 61 | expect(codexScriptProgressConfig({ include_only: [] }, progress)).toEqual({ |
| 62 | "shell_environment_policy.set": progress, |
| 63 | }); |
| 64 | }); |
| 65 | }); |