Skip to content

Move src environment variable access to deno_ral - #15429

Merged
cderv merged 12 commits into
mainfrom
rt/14-ral-env
Nov 27, 2026
Merged

cderv merged 12 commits into
mainfrom
rt/14-ral-env

Conversation

@cderv

@cderv cderv commented Nov 26, 2026

Copy link
Copy Markdown
Member

Part of the runtime migration (#15133). Follows #15418, #15423, #15426 and #15427, which moved src file operations to deno_ral/fs.ts. This does the same for environment variables: src/deno_ral/env.ts adds an env object (get, set, delete, toObject), and the codemod rewrites every Deno.env call in src to use it. A call like Deno.env.get("HOME") becomes env.get("HOME"). The layer still calls Deno underneath.

Most of the diff is the codemod output (148 calls in 50 files), in its own commit (eb7d469). The rest is done by hand:

  • Six files already have a local binding named env (a parameter, a const), so the codemod leaves them alone. They import the layer as env as runtimeEnv and their 17 calls use that name (a1474dc). In axe/cmd.ts, rewriting the default value (key) => Deno.env.get(key) to env.get would have made the default read its own parameter.
  • The env methods use no this, because dotenv.ts passes env.delete as a callback to forEach when it removes the variables it loaded on a previous render.
  • env.get, set and delete reject an empty name or one containing = or NUL with a TypeError. Deno already throws on these names, so nothing changes today. Node's process.env does not, and the check keeps both runtimes rejecting the same names.
  • The runtime boundary check now reports a new Deno.env.* call in src or package/src as covered by the layer, like the fs calls since Move src/core, src/quarto-core and src/config file operations to deno_ral #15418 (f00958c).

The runtime boundary baseline for src drops from 384 to 219 Deno.* calls (-165: 148 from the codemod, 17 by hand). Left on Deno.env: src/core/performance/metrics.ts, which the codemod skips while it patches Deno, the julia-engine subtree under src/resources, and two comments. package/src and tests follow in later PRs.

No changelog entry: nothing changes for users.

The branch also carries the PR 14 plan, refreshed against current main before the codemod ran, and a follow-up to the PR 13 hand-off notes under dev-docs/runtime-migration/.

Pending checks

  • test-smokes-parallel.yml on Ubuntu and Windows
  • test-quarto-latexmk.yml on all three OSes (the codemod rewrites the whole of src, tinytex.ts and github.ts among the files quarto-latexmk imports)
  • Runtime boundary delta report against the PR base

Test plan

  • Codemod dry run over src after the commits: 0 calls would be rewritten
  • deno check quarto.ts passes
  • Runtime boundary ratchet: src at 219, every other scope unchanged
  • Unit tests around environment handling, the new env test included (262 passed, 0 failed), and smoke tests for profiles, dotenv, pre/post render scripts, drafts, check and run (41 passed, 0 failed), on Windows
  • Rendering with _environment setting a variable: the R chunk reads it
  • quarto check shows the same Python and R rows as the main build
  • QUARTO_CAPTURE_RENDER_COMMAND writes the environment snapshot (--to html; the capture fails on docx with the main build too)

Checklist

I have (if applicable):

  • referenced the GitHub issue this PR closes
  • updated the appropriate changelog in the PR
  • ensured the present test suite passes
  • added new tests
  • created a separate documentation PR in Quarto's website repo and linked it to this PR
AI-assisted PR
  • AI tool used: Kimi K3 / K3.1 Pro (in Pi and Posit Assistant) for the implementation, Claude Code (Opus, Sonnet) for the rest
  • Codebase grounding: local clone
  • Human review: I have reviewed, tested, and verified the AI-generated content before submitting.

Note: autonomous AI agents submitting PRs without human oversight are not permitted — see the Code of Conduct.

cderv added 12 commits November 26, 2026 19:16
Step 0 of the env codemod plan, measured at 83432c0 on Windows with
Deno 2.9.8.

The tinytex rate-limit fix (#15388) moved one Deno.env site in
src/tools/github.ts into a default parameter, so the dry run now reports
148 replacements instead of 149 and the src ratchet count falls by 165
(384 to 219). Cited lines moved by up to 11 lines; none changed or
disappeared, and the tables carry the new numbers.

The plan also gains what PRs 10-13 learned: deno check needs
--allow-import while src/core/yaml.ts imports from skypack; seven of the
PR's files are already unformatted on main, so deno fmt skips them to
keep unrelated hunks out; staging uses explicit paths; the dry-run report
lives in .claude/docs/ where a later session can read it; conflicts
rebase on upstream/main, since origin is a fork.

Task 4 now registers env.get/set/delete/toObject as ratchet replacement
keys for src and package/src, matching the fs keys. The ratchet only
reports a covered API where a file's count rises, so the 48 package/src
sites PR 24 converts stay plain counts.

The env contract test gains a Windows-only check that names are
case-insensitive: Deno 2.9.8 and Node 24.21 both behave that way, and
the Node port of the layer must keep it.
The codemod commit landed with the plan's message and exactly the
dry run's 50 rewritten files, but its checkbox stayed unticked.
Task 4 was ticked without an execution-log entry, so the wrap-up
writes it from the saved run logs and records the coordinator reruns.
The env.ts row of the deno_ral module table was two characters wider
than the rest of the table.
The Task 4 entry was rebuilt from logs that hold test output only;
say so, and give the exact Windows invocation of the wrap-up reruns.
command-passthrough.test.ts spawns bare quarto.cmd, so the reruns
exercised whichever launcher PATH found first. Record the rerun with
the worktree's package/dist/bin first on PATH.
run-script.test.ts also spawns bare quarto.cmd, so the PATH rerun
covers the three smoke/run tests that call quartoDevCmd(), not only
command-passthrough.
Mark the PR 14 audit counts as historical next to the step 0 measurement,
state when the ratchet actually reports a covered API, add PR 33's
workflow residue scan to the babel-hyphen row, and list the files the
filesystem codemod deliberately leaves as Deno.*.
@posit-snyk-bot

posit-snyk-bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@cderv
cderv merged commit 6c6123b into main Nov 27, 2026
58 checks passed
@cderv
cderv deleted the rt/14-ral-env branch November 27, 2026 09:24
cderv added a commit that referenced this pull request Nov 27, 2026
…r own file

Record the merged env layer and codemod over src (56 files; src/core/performance/metrics.ts keeps its Deno.env read, which PR 25 Task 6 converts once PR 20b removes that file's Deno patch) and the new ratchet baseline (src 219), and point the handoff to PR 08, whose dependencies are now all merged. In the open decisions, retire the three PR 14 rows and the 10-13-then-14 landing-order decision, narrow the shared replacement-keys row to PR 08 (PR 14 added the env keys with the same scopes), and update the PR 05 and PR 20b split rows, whose PR 14 condition is now met.

The "Open decisions with an owner" table was about half of the README, and every plan's step 0 read the whole README to find the few rows that name its PR. The table moves unchanged to OPEN-DECISIONS.md, which opens with rg commands that print the rows for one plan; they match only PR context ("PR NN", "PRs 25, 33 and 37"), so dates and line numbers do not match. The README heading stays as a pointer, so the frozen plans and execution logs that cite README "Open decisions" still resolve. The live instructions in README, AGENTS.md, HANDOFF.md and _TEMPLATE.md that say where to read or record rows now name the new file, and the PR 04 decider "external contact above" now names README "Roles".
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.

2 participants