fix(lsp): honor --env-file from deno.json `test` task in test runner (#34905)
## Summary
When a user's `deno.json` declares a `test` task with `--env-file=…`,
the LSP test runner (used by the VSCode test gutter) silently ignored
it. Tests that read env vars at module load —
`Deno.env.get("MY_SECRET")` — threw before any test ran, and VSCode
surfaced this as the confusing "The test run did not record any output".
The "no-output" silent-drop symptom was fixed in #34641 (#17119). This
PR addresses the remaining maintainer-raised question from that thread:
should the LSP runner honor the `test` task's flags? It picks up
`--env-file`/`--env` from the `test` task and merges them into the LSP
test run.
Mechanics:
- `TestRun::init` now walks each unique scope reached by the queued
specifiers and parses the scope's deno.json `test` task command with
shlex, harvesting `--env-file=…` / `--env=…` / bare `--env-file` (→
`.env`) flags from `deno test ...` command segments. Each path is
resolved against the deno.json's directory so the LSP process's CWD
doesn't change the answer.
- `get_args` appends those env-file flags to the LSP test run unless the
user already supplied an env-file flag via `deno.testing.args` (so
existing setups keep their explicit value). Inherited paths are kept as
`PathBuf` until CLI arg emission; non-UTF8 paths are skipped with an LSP
log entry rather than lossy-converted.
- The LSP test execution path calls
`WatchEnvTracker::snapshot().load_env_variables_from_env_files(...)`
before constructing the worker factory, mirroring the CLI test behavior
while allowing subsequent LSP runs to refresh changed/removed env-file
variables. The remaining shared-process limitation is documented and
covered by a regression test: two scopes setting the same key cannot
both observe their own value in one LSP process.
## Test plan
- [x] `cargo test -p deno --lib
lsp::testing::execution::tests::test_extract_env_files_from_command
--features rustls/ring -- --nocapture` — unit test covering `=`-form,
bare flag (→ `.env`), `--env` alias, multiple, compound shell tasks,
quoted paths with whitespace, unrelated non-test env flags, and
malformed input.
- [x] `cargo test -p integration_tests --test integration
lsp_testing_api_inherits_test_task_env_file -- --nocapture` — LSP
integration test: deno.json with `tasks.test: deno test
--env-file=.env.test -A`, test.ts reads `MY_SECRET` at module load,
asserts the test passes (would throw at module eval without the env
file).
- [x] `cargo test -p integration_tests --test integration
lsp_testing_api_test_task_env_file_conflicting_scopes_first_wins --
--nocapture` — documents the current same-key shared-process env
limitation across scopes.
- [x] `cargo build -p deno -p test_server`.
- [x] `cargo clippy -p deno --bin deno --no-deps` clean.
- [x] `cargo fmt --check` clean.
Refs #28797
Closes denoland/divybot#487
---------
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>