From 1d326f2da1ad2572c48cdaf17c51ca82f20c1171 Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Nov 2026 14:06:44 +0100 Subject: [PATCH 1/2] Record deno-version only after Deno is installed on Windows The dev launcher quarto.cmd wrote the pinned Deno version to config/deno-version before calling configure.cmd. If that configure failed before wiping package/dist, the file claimed the new Deno while the old deno.exe stayed on disk, so the stale-Deno check passed on every later run and the reconfigure was never offered again. The write-first order came from the original auto-reconfigure, where configure called back into the launcher and the early write stopped it from looping. The Unix launcher moved the write into configure.sh in 2022; the Windows launcher kept the old order. On Windows the callback no longer matters: configure.cmd only runs `quarto --version`, which returns before the check. configure.cmd now writes the file right after the Deno bootstrap succeeds, as configure.sh does, and the launcher no longer writes it in either branch. A failed reconfigure leaves the previous version in place, so the next run tries again; a successful one records the new version, so one retry is enough. When the file is missing, the launcher now skips the check instead of recording a version it never checked, matching the Unix launcher. --- configure.cmd | 4 + package/scripts/windows/quarto.cmd | 5 +- tests/unit/dev-launcher-deno-version.test.ts | 115 ++++++++++++++++++ .../unit/dev-launcher-path-with-space.test.ts | 4 +- 4 files changed, 122 insertions(+), 6 deletions(-) create mode 100644 tests/unit/dev-launcher-deno-version.test.ts diff --git a/configure.cmd b/configure.cmd index 06af7b0ca12..73032232f53 100644 --- a/configure.cmd +++ b/configure.cmd @@ -76,6 +76,10 @@ if "%QUARTO_VENDOR_BINARIES%" == "true" ( deno upgrade --canary --version %DENO_CANARY_COMMIT% ) + REM Record the installed Deno version for the dev launcher's stale-Deno check + IF NOT EXIST "!QUARTO_DIST_PATH!\config" MKDIR "!QUARTO_DIST_PATH!\config" + ECHO !DENO!>"!QUARTO_DIST_PATH!\config\deno-version" + SET QUARTO_DENO=!QUARTO_BIN_PATH!\tools\!DENO_ARCH_DIR!\deno.exe POPD POPD diff --git a/package/scripts/windows/quarto.cmd b/package/scripts/windows/quarto.cmd index 6183f4b00aa..51d52bdf309 100644 --- a/package/scripts/windows/quarto.cmd +++ b/package/scripts/windows/quarto.cmd @@ -61,8 +61,7 @@ IF EXIST "!QUARTO_TS_PATH!" ( set /p DENO_INSTALLED_VERSION=<"!DENO_VERSION_FILE!" if NOT "!DENO!"=="!DENO_INSTALLED_VERSION!" ( - echo !DENO!>"!DENO_VERSION_FILE!" - + REM configure.cmd records the new version once Deno is installed cd "!QUARTO_ROOT!" call configure.cmd echo @@ -70,8 +69,6 @@ IF EXIST "!QUARTO_TS_PATH!" ( echo Quarto required reconfiguration to install Deno !DENO!. Please try command again. exit /b 1 ) - ) else ( - echo !DENO!>"!DENO_VERSION_FILE!" ) SET QUARTO_CACHE_OPTIONS=--cached-only diff --git a/tests/unit/dev-launcher-deno-version.test.ts b/tests/unit/dev-launcher-deno-version.test.ts new file mode 100644 index 00000000000..571ccc02953 --- /dev/null +++ b/tests/unit/dev-launcher-deno-version.test.ts @@ -0,0 +1,115 @@ +/* + * dev-launcher-deno-version.test.ts + * + * The dev launcher package/scripts/windows/quarto.cmd must leave + * config/deno-version to configure.cmd, so a failed reconfigure keeps the + * stale-Deno check armed. + * + * Copyright (C) 2026 Posit Software, PBC + */ + +import { unitTest } from "../test.ts"; +import { assert, assertEquals } from "../asserts.ts"; +import { isWindows } from "../../src/deno_ral/platform.ts"; +import { dirname, fromFileUrl, join } from "../../src/deno_ral/path.ts"; +import { + copySync, + ensureDirSync, + existsSync, + readTextFileSync, + writeTextFileSync, +} from "../../src/deno_ral/fs.ts"; +import { execProcess } from "../../src/core/process.ts"; +import { getenv } from "../../src/core/env.ts"; +import { withTempDir } from "../utils.ts"; + +const repoRoot = join(dirname(fromFileUrl(import.meta.url)), "..", ".."); +const launcherSource = join( + repoRoot, + "package", + "scripts", + "windows", + "quarto.cmd", +); + +// Lays out the minimum the dev launcher needs in `root`: a src/quarto.ts so it +// takes the dev branch, a win_configuration.bat pinning DENO, a configure.cmd +// stub that records its run and fails, and the launcher in package/dist/bin. +// Running the launcher there can never reconfigure the real checkout. +function createFakeCheckout(root: string, pinnedDeno: string) { + ensureDirSync(join(root, "src")); + writeTextFileSync(join(root, "src", "quarto.ts"), ""); + writeTextFileSync( + join(root, "win_configuration.bat"), + `SET "DENO=${pinnedDeno}"\r\nset "QUARTO_SRC_PATH=%~dp0src"\r\nset "QUARTO_BIN_PATH=%~dp0package\\dist\\bin"\r\n`, + ); + writeTextFileSync( + join(root, "configure.cmd"), + `@ECHO OFF\r\nECHO ran>"%~dp0configure-ran"\r\nEXIT /B 1\r\n`, + ); + const bin = join(root, "package", "dist", "bin"); + ensureDirSync(bin); + ensureDirSync(join(root, "package", "dist", "config")); + copySync(launcherSource, join(bin, "quarto.cmd")); + return { + launcher: join(bin, "quarto.cmd"), + denoVersionFile: join(root, "package", "dist", "config", "deno-version"), + configureRan: join(root, "configure-ran"), + }; +} + +function runLauncher(launcher: string, root: string) { + return execProcess({ + cmd: launcher, + args: ["--help"], + cwd: root, + stdout: "piped", + stderr: "piped", + env: { + QUARTO_NO_TYPECHECK: "true", + // Resolve `call configure.cmd` to the stub even when the parent + // environment sets NoDefaultCurrentDirectoryInExePath. + PATH: `${root};${getenv("PATH", "")}`, + }, + }); +} + +unitTest( + "dev-launcher - a failed reconfigure keeps the previous deno-version", + async () => { + await withTempDir(async (root) => { + const fake = createFakeCheckout(root, "v99.0.0"); + writeTextFileSync(fake.denoVersionFile, "v1.0.0\r\n"); + + const result = await runLauncher(fake.launcher, root); + + assert( + existsSync(fake.configureRan), + `the stale-Deno branch did not call configure.cmd\nstdout:\n${result.stdout}\nstderr:\n${result.stderr}`, + ); + assertEquals( + readTextFileSync(fake.denoVersionFile).trim(), + "v1.0.0", + "deno-version must keep naming the installed Deno after a failed reconfigure", + ); + }); + }, + { ignore: !isWindows }, +); + +unitTest( + "dev-launcher - a missing deno-version is not created from the pinned version", + async () => { + await withTempDir(async (root) => { + const fake = createFakeCheckout(root, "v99.0.0"); + + await runLauncher(fake.launcher, root); + + assert( + !existsSync(fake.denoVersionFile), + "the launcher recorded a Deno version it never verified", + ); + }); + }, + { ignore: !isWindows }, +); diff --git a/tests/unit/dev-launcher-path-with-space.test.ts b/tests/unit/dev-launcher-path-with-space.test.ts index 5db5dbee518..804cb53a65b 100644 --- a/tests/unit/dev-launcher-path-with-space.test.ts +++ b/tests/unit/dev-launcher-path-with-space.test.ts @@ -68,8 +68,8 @@ unitTest( const denoVersionAfter = existsSync(denoVersionFile) ? readTextFileSync(denoVersionFile) : undefined; - // The launcher writes the file on first run, so it may not have - // existed before; either way it must hold the configured version. + // configure.cmd writes the file after installing Deno; the launcher + // must leave it holding the configured version. assertEquals( denoVersionAfter?.trim(), configuredDenoVersion(), From bbd287953d8ebff98858412c2ab91428ddb2a27a Mon Sep 17 00:00:00 2001 From: Christophe Dervieux Date: Wed, 4 Nov 2026 14:13:12 +0100 Subject: [PATCH 2/2] Drop the missing deno-version launcher test It pinned the choice to skip the stale-Deno check when the file is absent, which is a design decision rather than the reported bug, and would block a later verified write. The failed-reconfigure test still covers the bug. --- tests/unit/dev-launcher-deno-version.test.ts | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/tests/unit/dev-launcher-deno-version.test.ts b/tests/unit/dev-launcher-deno-version.test.ts index 571ccc02953..929181872c5 100644 --- a/tests/unit/dev-launcher-deno-version.test.ts +++ b/tests/unit/dev-launcher-deno-version.test.ts @@ -96,20 +96,3 @@ unitTest( }, { ignore: !isWindows }, ); - -unitTest( - "dev-launcher - a missing deno-version is not created from the pinned version", - async () => { - await withTempDir(async (root) => { - const fake = createFakeCheckout(root, "v99.0.0"); - - await runLauncher(fake.launcher, root); - - assert( - !existsSync(fake.denoVersionFile), - "the launcher recorded a Deno version it never verified", - ); - }); - }, - { ignore: !isWindows }, -);