Skip to content

test(dotenv): add regression test for CLI_ARGS with root-level dotenv#2763

Open
pawciobiel wants to merge 1 commit intogo-task:mainfrom
pawciobiel:test-dotenv-cli-args-regression
Open

test(dotenv): add regression test for CLI_ARGS with root-level dotenv#2763
pawciobiel wants to merge 1 commit intogo-task:mainfrom
pawciobiel:test-dotenv-cli-args-regression

Conversation

@pawciobiel
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a regression test ensuring CLI_ARGS remains available for templating when a Taskfile declares a root-level dotenv.

Changes:

  • Added a new test fixture Taskfile that declares dotenv: ['.env'] and echoes {{.CLI_ARGS}}.
  • Added a corresponding .env fixture file for the root-level dotenv declaration.
  • Added TestDotenvWithCLIArgs in task_test.go to validate output when CLI_ARGS is set.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
testdata/dotenv/cli_args/Taskfile.yml New fixture Taskfile enabling root-level dotenv and exercising {{.CLI_ARGS}} templating.
testdata/dotenv/cli_args/.env New fixture dotenv file used by the Taskfile.
task_test.go New regression test that runs the fixture and asserts the rendered CLI_ARGS output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1808 to +1823
var buff bytes.Buffer
e := task.NewExecutor(
task.WithDir("testdata/dotenv/cli_args"),
task.WithStdout(&buff),
task.WithStderr(&buff),
task.WithSilent(true),
)
require.NoError(t, e.Setup())

specialVars := ast.NewVars()
specialVars.Set("CLI_ARGS", ast.Var{Value: "hello world"})
e.Taskfile.Vars.ReverseMerge(specialVars, nil)

err := e.Run(t.Context(), &task.Call{Task: "default"})
require.NoError(t, err)
assert.Equal(t, "args=hello world\n", buff.String())
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn’t currently assert that the root-level dotenv file was actually loaded/applied (the .env contents aren’t used anywhere), so it could pass even if readDotEnvFiles/root dotenv behavior regresses. Consider asserting a value sourced from the .env file (ideally with a unique var name unlikely to exist in the process environment) alongside CLI_ARGS, and update the expected output accordingly.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants