-
Notifications
You must be signed in to change notification settings - Fork 202
Add GCL_VARIABLE_<name> env var support, replace yargs .env("GCL") #1805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+139
−1
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3203791
Add GCL_VARIABLE_<name> environment variable support
firecow 353ba40
fix: integration test now exercises full GCL_VARIABLE_* env path
firecow c7fe62d
refactor: replace yargs .env("GCL") with manual env var injection
firecow 4dfcf2d
fix: typecheck errors, CLI precedence over GCL_ env vars, completion …
firecow 7bbb580
fix: restore .env("GCL") and strip GCL_VARIABLE_* before yargs parse
firecow 267ed48
fix: strip GCL_VARIABLE_ (empty suffix) from env, add ignorePredefine…
firecow 2a314f1
revert: remove unrelated ignore-predefined-vars changes
firecow cc65b41
fix: extract shared prefix constant, use ??= operator, narrow types
firecow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| test-job: | ||
| script: | ||
| - echo ${MY_VAR} | ||
| - echo ${ANOTHER_VAR} | ||
| - echo ${EMPTY_VAR} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| import {WriteStreamsMock} from "../../../src/write-streams.js"; | ||
| import {handler} from "../../../src/handler.js"; | ||
| import {injectGclVariableEnvVars} from "../../../src/argv.js"; | ||
| import chalk from "chalk-template"; | ||
| import {initSpawnSpy} from "../../mocks/utils.mock.js"; | ||
| import {WhenStatics} from "../../mocks/when-statics.js"; | ||
|
|
||
| beforeAll(() => { | ||
| initSpawnSpy(WhenStatics.all); | ||
| }); | ||
|
|
||
| describe("injectGclVariableEnvVars unit tests", () => { | ||
| test("injects single GCL_VARIABLE_ entry", () => { | ||
| const argv: {variable?: string[]} = {}; | ||
| injectGclVariableEnvVars(argv, {"GCL_VARIABLE_MY_VAR": "hello"}); | ||
| expect(argv.variable).toEqual(["MY_VAR=hello"]); | ||
| }); | ||
|
|
||
| test("injects multiple GCL_VARIABLE_ entries", () => { | ||
| const argv: {variable?: string[]} = {}; | ||
| injectGclVariableEnvVars(argv, { | ||
| "GCL_VARIABLE_VAR1": "one", | ||
| "GCL_VARIABLE_VAR2": "two", | ||
| }); | ||
| expect(argv.variable).toEqual(expect.arrayContaining(["VAR1=one", "VAR2=two"])); | ||
| expect(argv.variable).toHaveLength(2); | ||
| }); | ||
|
|
||
| test("prepends to existing variable array", () => { | ||
| const argv: {variable?: string[]} = {variable: ["EXISTING=val"]}; | ||
| injectGclVariableEnvVars(argv, {"GCL_VARIABLE_NEW": "injected"}); | ||
| expect(argv.variable).toEqual(["NEW=injected", "EXISTING=val"]); | ||
| }); | ||
|
|
||
| test("CLI --variable takes precedence over GCL_VARIABLE_", () => { | ||
| const argv: {variable?: string[]} = {variable: ["SAME=from_cli"]}; | ||
| injectGclVariableEnvVars(argv, {"GCL_VARIABLE_SAME": "from_env"}); | ||
| // "SAME=from_env" is prepended, "SAME=from_cli" comes last and wins | ||
| expect(argv.variable).toEqual(["SAME=from_env", "SAME=from_cli"]); | ||
| }); | ||
|
|
||
| test("skips non GCL_VARIABLE_ env vars", () => { | ||
| const argv: {variable?: string[]} = {}; | ||
| injectGclVariableEnvVars(argv, { | ||
| "GCL_CWD": "/tmp", | ||
| "HOME": "/home/user", | ||
| "GCL_VARIABLE_REAL": "yes", | ||
| }); | ||
| expect(argv.variable).toEqual(["REAL=yes"]); | ||
| }); | ||
|
|
||
| test("skips GCL_VARIABLE_ with empty name", () => { | ||
| const argv: {variable?: string[]} = {}; | ||
| injectGclVariableEnvVars(argv, {"GCL_VARIABLE_": "empty_name"}); | ||
| expect(argv.variable).toBeUndefined(); | ||
| }); | ||
|
|
||
| test("skips null/undefined env values", () => { | ||
| const argv: {variable?: string[]} = {}; | ||
| injectGclVariableEnvVars(argv, {"GCL_VARIABLE_FOO": undefined}); | ||
| expect(argv.variable).toBeUndefined(); | ||
| }); | ||
|
|
||
| test("handles empty value", () => { | ||
| const argv: {variable?: string[]} = {}; | ||
| injectGclVariableEnvVars(argv, {"GCL_VARIABLE_FOO": ""}); | ||
| expect(argv.variable).toEqual(["FOO="]); | ||
| }); | ||
|
|
||
| test("handles value with equals sign", () => { | ||
| const argv: {variable?: string[]} = {}; | ||
| injectGclVariableEnvVars(argv, {"GCL_VARIABLE_FOO": "key=value"}); | ||
| expect(argv.variable).toEqual(["FOO=key=value"]); | ||
| }); | ||
|
|
||
| test("does not split on semicolons", () => { | ||
| const argv: {variable?: string[]} = {}; | ||
| injectGclVariableEnvVars(argv, {"GCL_VARIABLE_FOO": "a;b;c"}); | ||
| expect(argv.variable).toEqual(["FOO=a;b;c"]); | ||
| }); | ||
| }); | ||
|
|
||
| describe("injectGclVariableEnvVars integration", () => { | ||
| test.concurrent("GCL_VARIABLE_MY_VAR=hello injects variable into job", async () => { | ||
| const writeStreams = new WriteStreamsMock(); | ||
| await handler({ | ||
| cwd: "tests/test-cases/gcl-variable-env", | ||
| job: ["test-job"], | ||
| variable: ["MY_VAR=hello", "ANOTHER_VAR=world", "EMPTY_VAR="], | ||
cubic-dev-ai[bot] marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }, writeStreams); | ||
|
|
||
| const expected = [ | ||
| chalk`{blueBright test-job} {greenBright >} hello`, | ||
| chalk`{blueBright test-job} {greenBright >} world`, | ||
| ]; | ||
| expect(writeStreams.stdoutLines).toEqual(expect.arrayContaining(expected)); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.