Skip to content

Commit 267ed48

Browse files
committed
fix: strip GCL_VARIABLE_ (empty suffix) from env, add ignorePredefinedVars tests
Always delete GCL_VARIABLE_* entries from process.env before yargs parses, including the bare GCL_VARIABLE_ key, so strictOptions() does not reject it. Add tests for Argv.ignorePredefinedVars getter.
1 parent 7bbb580 commit 267ed48

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

src/argv.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ export function stripGclVariableEnvVars (env: Record<string, string | undefined>
2727
const stripped: Record<string, string> = {};
2828
for (const key of Object.keys(env)) {
2929
if (!key.startsWith(prefix) || env[key] == null) continue;
30-
if (key.length <= prefix.length) continue;
31-
stripped[key] = env[key]!;
30+
if (key.length > prefix.length) {
31+
stripped[key] = env[key]!;
32+
}
3233
delete env[key];
3334
}
3435
return stripped;

tests/test-cases/gcl-variable-env/integration.test.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import {stripGclVariableEnvVars, injectGclVariableEnvVars} from "../../../src/argv.js";
1+
import {stripGclVariableEnvVars, injectGclVariableEnvVars, Argv} from "../../../src/argv.js";
22
import {execFile} from "child_process";
33
import {promisify} from "util";
4+
import {WriteStreamsMock} from "../../../src/write-streams.js";
45

56
const execFileAsync = promisify(execFile);
67

@@ -23,11 +24,11 @@ describe("stripGclVariableEnvVars", () => {
2324
expect(env["GCL_CWD"]).toBe("/tmp");
2425
});
2526

26-
test("skips GCL_VARIABLE_ with empty name", () => {
27+
test("strips GCL_VARIABLE_ with empty name from env but does not return it", () => {
2728
const env: Record<string, string | undefined> = {"GCL_VARIABLE_": "empty"};
2829
const stripped = stripGclVariableEnvVars(env);
2930
expect(stripped).toEqual({});
30-
expect(env["GCL_VARIABLE_"]).toBe("empty");
31+
expect(env["GCL_VARIABLE_"]).toBeUndefined();
3132
});
3233

3334
test("skips null/undefined values", () => {
@@ -92,6 +93,28 @@ describe("injectGclVariableEnvVars", () => {
9293
});
9394
});
9495

96+
describe("Argv.ignorePredefinedVars", () => {
97+
test("returns empty array by default", async () => {
98+
const argv = await Argv.build({cwd: "tests/test-cases/gcl-variable-env"}, new WriteStreamsMock());
99+
expect(argv.ignorePredefinedVars).toEqual([]);
100+
});
101+
102+
test("handles array input", async () => {
103+
const argv = await Argv.build({cwd: "tests/test-cases/gcl-variable-env", ignorePredefinedVars: ["VAR1", "VAR2"]}, new WriteStreamsMock());
104+
expect(argv.ignorePredefinedVars).toEqual(["VAR1", "VAR2"]);
105+
});
106+
107+
test("splits comma-separated values in array elements", async () => {
108+
const argv = await Argv.build({cwd: "tests/test-cases/gcl-variable-env", ignorePredefinedVars: ["VAR1,VAR2"]}, new WriteStreamsMock());
109+
expect(argv.ignorePredefinedVars).toEqual(["VAR1", "VAR2"]);
110+
});
111+
112+
test("handles string input for backwards compatibility", async () => {
113+
const argv = await Argv.build({cwd: "tests/test-cases/gcl-variable-env", ignorePredefinedVars: "VAR1,VAR2"}, new WriteStreamsMock());
114+
expect(argv.ignorePredefinedVars).toEqual(["VAR1", "VAR2"]);
115+
});
116+
});
117+
95118
test("GCL_VARIABLE_* env vars are injected into job output via CLI", async () => {
96119
const {stdout} = await execFileAsync("bun", ["src/index.ts", "test-job", "--cwd", "tests/test-cases/gcl-variable-env"], {
97120
env: {

0 commit comments

Comments
 (0)