Skip to content

Add tests for CLI flag parsing, --inject modes and env file discovery - #1327

Open
Trenyx wants to merge 1 commit into
dmno-dev:mainfrom
Trenyx:test-cli-flags-inject-env-files
Open

Trenyx wants to merge 1 commit into
dmno-dev:mainfrom
Trenyx:test-cli-flags-inject-env-files

Conversation

@Trenyx

@Trenyx Trenyx commented Dec 2, 2026

Copy link
Copy Markdown

Congrats on the Cloudflare news. This adds three small tests around the CLI, tests only.

Misspelled flags are rejected. cli-executable.ts runs gunshi with strict: true, so a typo like --formt or --injct stops the command with a "did you mean" instead of running it with the default the user meant to change. Nothing covers that setting: with it flipped to false the suite stays green. The new src/cli/cli-executable.test.ts runs the real entry in-process (exit, telemetry and the load/run commands stubbed) and checks that a correctly spelled flag reaches the command, and that three misspelled ones exit 1, name the bad flag on stderr and never run the command.

--inject modes. If resolveInjectMode ever mapped vars and blob the wrong way round, --inject blob would still inject every value as a plain env var and --inject vars would inject none, so the child process would get the opposite of what was asked. inject-mode.test.ts pins all three modes, the fallback, and that an explicit --inject wins over the fallback (the --no-inject-graph path in varlock run).

findEnvFiles skips .envrc. varlock init uses it to pick the env files it reads. The comment says .envrc is ignored, and only the '.env.' prefix check makes that true: with startsWith('.env'), init would pick up .envrc, .env-backup and the like. find-env-files.test.ts writes a mix of names to a temp dir and checks that only .env and .env.* come back (.d.ts and .md still skipped).

Checked on main 658da7e: the varlock package suite passes with the tests added (150 files, 2,616 tests) and tsc --noEmit is clean. Each test fails when the line it covers is changed (strict: false; 'vars' swapped for 'blob' in injectVars; startsWith('.env')), with nothing else failing.

This is a gap in the tests, not a bug in varlock today: main behaves correctly. Part of Trenyx's hardening run (trenyx.io). Saurabh (SK)

- the CLI rejects a misspelled flag instead of running without it (strict: true)
- resolveInjectMode maps all / vars / blob to the right injection booleans, flag and fallback
- findEnvFiles skips .envrc and other names that only start with .env

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Approach: Focused regression tests exercise the real CLI parser and existing helpers without changing production behavior.

Reviewed changes cover all four files, with all 12 added tests, package typechecking, and targeted lint passing.

  • CLI flag parsing: Verifies valid flag forwarding and rejects three misspellings without executing commands.
  • Injection modes: Checks all, vars, and blob, fallback resolution, and explicit flag precedence.
  • Env file discovery: Checks accepted filenames and exclusions using an isolated temporary directory.
  • Release metadata: Records the tests-only change with varlock: none.

Pullfrog  | View workflow run | Using gpt-6.1-sol | 𝕏

This branch has not been deployed

No deployments
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.

1 participant