Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dev-docs/runtime-migration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ The rows below are the ones that still need a named person or an external answer
| PR 08 Task 1 and Task 2 step 2 (from #15341, the `execProcess` UTF-8 fix on `main`) | The plan's premise that `src/deno_ral/process.ts` is 10 lines (context section, `08-ral-process.md:25`) is stale: `execPath(): string` already exists there with the planned signature. Task 2 step 2 imports `pooledMap` (`:933`) and its `processOutput` snippet (`:1047-1066`) restores the per-chunk body that decodes each chunk twice, which would revert the fix; applied as written over the current body, which already prints through its own helper, it would also print inherited output twice. Re-derive the snippet from the current `processOutput` (decode once with `{ stream: true }`, flush at the end, skip empty text) and make `writeStdoutSync`/`writeStderrSync` the only change; drop `pooledMap` from the import as `filteredAsyncIterator` no longer uses it. Add `unit/exec-process-utf8-chunks.test.ts` to Task 2's verification | PR 08 executor | PR 08 step 0 |
| PR 28 Task 4 step 3 (from #15341) | the merged-mode `addStream` snippet (`28-ral-process-on-node-apis.md:894-900`) wraps only filtered streams (`filter ? filteredAsyncIterator(iterator, filter) : iterator`), which drops the per-stream decoding that keeps a character split across chunks whole when both streams are merged. Keep `filteredAsyncIterator(iterator, filter)` on both streams, and add `unit/exec-process-utf8-chunks.test.ts` to the PR's gate | PR 28 executor | PR 28 step 0 |
| PRs 23 and 31 (from #15341) | `tests/unit/exec-process-utf8-chunks.test.ts` starts its child as `execPath() eval '<script>'`, a Deno-only invocation (the `eval` subcommand; the script body itself uses only `node:fs`). Add it to PR 23's runtime re-invocation inventory (`23-codemod-tests.md:42-43`) so PR 31's `runtimeScriptCommand` converts it | PR 23 executor | PR 23 step 0 |
| PR 33 Task 9 Step 4 (from #15365, the `quarto.cmd` argument fix on `main`) | The full `quarto.cmd` listing (`33-build-tooling-node.md:2111-2207`) predates three launcher fixes on `main` and would revert them. Its launch line and `QUARTO_LAUNCHER_DEBUG` line put `%*` on a line that uses `!VAR!` under `ENABLEDELAYEDEXPANSION`, so arguments containing `!` or `^` are altered; `main` builds the command with `!VAR!`, carries it through `FOR /F`, and runs it on an unparenthesized `DO SETLOCAL DISABLEDELAYEDEXPANSION & %%C %*`. Its `IF "%1"==` shortcuts never match when the caller quotes the argument, as Deno does for every batch-file argument; `main` compares `"%~1"`. Its `call !QUARTO_ROOT!\win_configuration.bat` drops the quotes #15276 added. Re-derive the Windows launcher from current `main` instead of pasting the listing, and keep `tests/unit/launcher-arguments.test.ts`, `dev-launcher-path-with-space.test.ts` and `bundled-launcher-path-with-space.test.ts` green. | PR 33 executor | PR 33 step 0 |

## Shared rules and tables

Expand Down
23 changes: 13 additions & 10 deletions package/scripts/windows/quarto.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SET "QUARTO_LOCK_OPTIONS=--no-lock"
IF EXIST "!QUARTO_TS_PATH!" (
set QUARTO_DEV_MODE=true

IF "%1"=="--version" (
IF "%~1"=="--version" (
IF DEFINED QUARTO_FORCE_VERSION (
ECHO !QUARTO_FORCE_VERSION!
GOTO end
Expand All @@ -23,7 +23,7 @@ IF EXIST "!QUARTO_TS_PATH!" (
GOTO end
)

IF "%1"=="-v" (
IF "%~1"=="-v" (
IF DEFINED QUARTO_FORCE_VERSION (
ECHO !QUARTO_FORCE_VERSION!
GOTO end
Expand Down Expand Up @@ -84,7 +84,7 @@ IF EXIST "!QUARTO_TS_PATH!" (
for %%i in ("!SCRIPT_PATH!\..\share") do SET "QUARTO_SHARE_PATH=%%~fi"
)

IF "%1"=="-v" (
IF "%~1"=="-v" (
IF DEFINED QUARTO_FORCE_VERSION (
ECHO !QUARTO_FORCE_VERSION!
GOTO end
Expand All @@ -93,7 +93,7 @@ IF EXIST "!QUARTO_TS_PATH!" (
GOTO end
)

IF "%1"=="--version" (
IF "%~1"=="--version" (
IF DEFINED QUARTO_FORCE_VERSION (
ECHO !QUARTO_FORCE_VERSION!
GOTO end
Expand All @@ -103,13 +103,14 @@ IF EXIST "!QUARTO_TS_PATH!" (
)

SET QUARTO_DENO_OPTIONS=--no-check
SET QUARTO_IMPORT_MAP_ARG=
SET QUARTO_ACTION=run
SET "QUARTO_TARGET=%SCRIPT_PATH%\quarto.js"
SET "QUARTO_BIN_PATH=%SCRIPT_PATH%"
SET QUARTO_CACHE_OPTIONS=--cached-only
)

IF "%1"=="--paths" (
IF "%~1"=="--paths" (
ECHO !QUARTO_BIN_PATH!
ECHO !QUARTO_SHARE_PATH!
GOTO end
Expand Down Expand Up @@ -167,11 +168,13 @@ IF DEFINED QUARTO_TS_PROFILE (
SET "QUARTO_TS_PROFILE=true"
)

IF DEFINED QUARTO_DEV_MODE (
"!QUARTO_DENO!" !QUARTO_ACTION! !QUARTO_CACHE_OPTIONS! !QUARTO_DENO_OPTIONS! !QUARTO_DENO_EXTRA_OPTIONS! !QUARTO_IMPORT_MAP_ARG! "!QUARTO_TARGET!" %*
) ELSE (
"!QUARTO_DENO!" !QUARTO_ACTION! !QUARTO_CACHE_OPTIONS! !QUARTO_DENO_OPTIONS! !QUARTO_DENO_EXTRA_OPTIONS! "!QUARTO_TARGET!" %*
)
REM The command is built with !VAR!, so cmd does not interpret & or ^ in option values,
REM and runs with delayed expansion off: %* is substituted before delayed expansion,
REM which would consume any "!" or "^" in the arguments. %%C is substituted after cmd
REM parses the line, which keeps the built command literal. No parentheses around the
REM DO command: a ")" in an unquoted argument would close them.
SET "QUARTO_DENO_CMD="!QUARTO_DENO!" !QUARTO_ACTION! !QUARTO_CACHE_OPTIONS! !QUARTO_DENO_OPTIONS! !QUARTO_DENO_EXTRA_OPTIONS! !QUARTO_IMPORT_MAP_ARG! "!QUARTO_TARGET!""
FOR /F "delims=" %%C IN ("!QUARTO_DENO_CMD!") DO SETLOCAL DISABLEDELAYEDEXPANSION & %%C %*


:end
218 changes: 218 additions & 0 deletions tests/unit/launcher-arguments.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,218 @@
/*
* launcher-arguments.test.ts
*
* The Windows launcher quarto.cmd must pass its arguments to Deno unchanged,
* including "!" and "^", which delayed expansion would otherwise consume, and
* must short-circuit --version, -v and --paths when the caller quotes them.
* Covered for both the dev layout (package/dist/bin/quarto.cmd) and the
* bundled layout (bin/quarto.cmd next to quarto.js).
*
* 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,
removeSync,
writeTextFileSync,
} from "../../src/deno_ral/fs.ts";
import { execProcess } from "../../src/core/process.ts";
import { withTempDir } from "../utils.ts";

const repoRoot = join(dirname(fromFileUrl(import.meta.url)), "..", "..");

// Prints the arguments and, when Deno got a --location option, its URL.
const probe = 'import process from "node:process";\n' +
'console.log("ARGS=" + JSON.stringify(process.argv.slice(2)));\n' +
'let loc = "";\n' +
"try { loc = globalThis.location.href; } catch { /* no --location */ }\n" +
'console.log("LOC=" + loc);\n';

// A Deno option whose value holds characters cmd would otherwise interpret.
const location = "http://example.com/?a=1&b=^c!d";

const specialArgs = [
"C:\\work\\notes!",
"C:\\x!OS!y",
"c^d",
"a & b",
"100%",
"%OS%",
"p (1)",
"sp ace",
];

interface Launcher {
cmd: string;
env: Record<string, string>;
}

async function launch(launcher: Launcher, args: string[], cwd: string) {
const result = await execProcess({
cmd: launcher.cmd,
args,
cwd,
stdout: "piped",
stderr: "piped",
env: launcher.env,
});
const stdout = result.stdout ?? "";
const details = `(exit ${result.code})\nstdout:\n${stdout}\nstderr:\n${
result.stderr ?? ""
}`;
return { result, stdout, details };
}

async function assertArgumentsReachDeno(
launcher: Launcher,
args: string[],
cwd: string,
) {
const { result, stdout, details } = await launch(launcher, args, cwd);
const argsLine = stdout.split(/\r?\n/).find((line) =>
line.startsWith("ARGS=")
);
assertEquals(
argsLine,
"ARGS=" + JSON.stringify(args),
`quarto.cmd changed its arguments ${details}`,
);
assert(result.success, `quarto.cmd exited with an error ${details}`);
}

// Runs quarto.cmd through cmd with an unquoted command line, as typed in a
// terminal, where cmd itself sees the ")" in "report(1).qmd".
async function assertTypedArgumentsReachDeno(launcher: Launcher, cwd: string) {
const result = await execProcess({
cmd: "cmd",
args: ["/d", "/s", "/c", `""${launcher.cmd}" run report(1).qmd C:\\notes!"`],
windowsRawArguments: true,
cwd,
stdout: "piped",
stderr: "piped",
env: launcher.env,
});
const stdout = result.stdout ?? "";
const details = `(exit ${result.code})\nstdout:\n${stdout}\nstderr:\n${
result.stderr ?? ""
}`;
const argsLine = stdout.split(/\r?\n/).find((line) =>
line.startsWith("ARGS=")
);
assertEquals(
argsLine,
'ARGS=["run","report(1).qmd","C:\\\\notes!"]',
`quarto.cmd changed a typed command line ${details}`,
);
assert(result.success, `quarto.cmd exited with an error ${details}`);
}

async function assertOptionsReachDeno(launcher: Launcher, cwd: string) {
const { result, stdout, details } = await launch({
cmd: launcher.cmd,
env: {
...launcher.env,
QUARTO_DENO_EXTRA_OPTIONS: `--location=${location}`,
},
}, ["run"], cwd);
const locLine = stdout.split(/\r?\n/).find((line) => line.startsWith("LOC="));
assertEquals(
locLine,
`LOC=${location}`,
`quarto.cmd changed QUARTO_DENO_EXTRA_OPTIONS ${details}`,
);
assert(result.success, `quarto.cmd exited with an error ${details}`);
}

async function assertShortCircuits(launcher: Launcher, cwd: string) {
for (const flag of ["--version", "-v"]) {
const { stdout, details } = await launch(launcher, [flag], cwd);
assertEquals(
stdout.trim(),
"9.8.7",
`quarto.cmd ${flag} did not print the forced version ${details}`,
);
}
const { stdout, details } = await launch(launcher, ["--paths"], cwd);
assert(
!stdout.includes("ARGS=") && stdout.trim().split(/\r?\n/).length === 2,
`quarto.cmd --paths did not print the bin and share paths ${details}`,
);
}

unitTest(
"launcher-arguments - bundled quarto.cmd passes arguments unchanged",
async () => {
await withTempDir(async (dir) => {
// Minimal bundled install layout, as in
// bundled-launcher-path-with-space.test.ts.
const bin = join(dir, "bin");
ensureDirSync(bin);
copySync(
join(repoRoot, "package", "scripts", "windows", "quarto.cmd"),
join(bin, "quarto.cmd"),
);
writeTextFileSync(join(bin, "quarto.js"), probe);
const tools = join(bin, "tools");
const mklink = await execProcess({
cmd: "cmd",
args: [
"/c",
"mklink",
"/J",
tools,
join(repoRoot, "package", "dist", "bin", "tools"),
],
stdout: "piped",
stderr: "piped",
});
assert(mklink.success, `creating the junction failed: ${mklink.stderr}`);
try {
const launcher = {
cmd: join(bin, "quarto.cmd"),
env: { QUARTO_FORCE_VERSION: "9.8.7" },
};
await assertArgumentsReachDeno(launcher, ["run", ...specialArgs], dir);
await assertArgumentsReachDeno(launcher, ["a & b", "x"], dir);
await assertOptionsReachDeno(launcher, dir);
await assertTypedArgumentsReachDeno(launcher, dir);
await assertShortCircuits(launcher, dir);
} finally {
// Remove the junction itself (not its target) before the temp dir goes.
removeSync(tools);
}
});
},
{ ignore: !isWindows },
);

unitTest(
"launcher-arguments - dev quarto.cmd passes arguments unchanged",
async () => {
await withTempDir(async (dir) => {
const target = join(dir, "probe.ts");
writeTextFileSync(target, probe);
const launcher = {
cmd: join(repoRoot, "package", "dist", "bin", "quarto.cmd"),
env: {
QUARTO_TARGET: target,
QUARTO_NO_TYPECHECK: "true",
QUARTO_FORCE_VERSION: "9.8.7",
// See dev-launcher-path-with-space.test.ts: keeps a failed launch
// from running configure.cmd in the checkout under test.
NoDefaultCurrentDirectoryInExePath: "1",
},
};
await assertArgumentsReachDeno(launcher, ["run", ...specialArgs], dir);
await assertArgumentsReachDeno(launcher, ["a & b", "x"], dir);
await assertOptionsReachDeno(launcher, dir);
await assertTypedArgumentsReachDeno(launcher, dir);
await assertShortCircuits(launcher, dir);
});
},
{ ignore: !isWindows, requiresDevQuarto: true },
);
Loading