From add6df658c04bb9e2881aa3aa79c608ae275d447 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Fri, 20 Mar 2026 14:19:51 +0100 Subject: [PATCH] fix: restore env vars in finally block to prevent test pollution Move environment variable restoration from the try block to a finally block so env vars passed via the test harness are always cleaned up, even when the command fails and Deno's exit sanitizer intercepts the Deno.exit() call. Without this, a test that sets env vars (e.g. QUARTO_PDF_STANDARD) via TestContext.env could leak those values to subsequent tests when running in the same deno test process. --- src/quarto.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/quarto.ts b/src/quarto.ts index 616bf8928be..57e92c727b8 100644 --- a/src/quarto.ts +++ b/src/quarto.ts @@ -196,13 +196,6 @@ export async function quarto( try { await promise; - for (const [key, value] of Object.entries(oldEnv)) { - if (value === undefined) { - Deno.env.delete(key); - } else { - Deno.env.set(key, value); - } - } if (commandFailed()) { exitWithCleanup(1); } @@ -213,6 +206,14 @@ export async function quarto( } else { throw e; } + } finally { + for (const [key, value] of Object.entries(oldEnv)) { + if (value === undefined) { + Deno.env.delete(key); + } else { + Deno.env.set(key, value); + } + } } }