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..929181872c5 --- /dev/null +++ b/tests/unit/dev-launcher-deno-version.test.ts @@ -0,0 +1,98 @@ +/* + * 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 }, +); 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(),