You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 839948c
Browse filesBrowse the repository at this point in the historyBrowse files
Fix quarto preview crash on knitr document in a project subdirectory (#14699)
Previewing a knitr document in a project subdirectory — running
`quarto preview` from that subdirectory with a bare filename, the
shape RStudio's Render button uses — failed with
`rmarkdown:::abs_path(input): The file 'doc.qmd' does not exist.`
This is a regression from #13804, live in stable 1.9.38 and main.
#13804 shared one ProjectContext (and its fileInformationCache)
between preview's format-resolution and render steps, with cache
keys normalized to absolute paths, but the cached
ExecutionTarget.input/source kept whatever form the caller passed.
Format-resolution seeds the cache with a cwd-relative bare filename;
renderProject later looks the same file up by its absolute path,
collides on the same cache key, and inherits the stale relative
input. The knitr subprocess runs with cwd set to the project
directory, where the subdirectory-relative filename doesn't
resolve.
Normalize the path to absolute once, at the single convergence
point (fileExecutionEngineAndTarget in src/execute/engine.ts), so
target.source/target.input are always absolute regardless of how
the caller spelled the path — consistent with project renders,
which were already absolute. This also fixes#12401:
QUARTO_DOCUMENT_PATH was relative for single-file renders but
absolute for project renders, since both derive from target.source.
Adds a regression test exercising the real knitr subprocess and a
manual preview-matrix entry (T33) with an on-disk fixture, since
`quarto preview` itself can't run under the automated test harness.
Fixes#14683, fixes#12401, fixes#14151
Copy file name to clipboardExpand all lines: .claude/rules/testing/test-anti-patterns.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -17,3 +17,9 @@ paths:
17
17
Never create `Project.toml`, `.venv/`, or `renv.lock` in test fixture directories.
18
18
19
19
**Details:**`llm-docs/testing-patterns.md` → "Shared Test Environments"
20
+
21
+
## Don't: `Deno.chdir()` inside the test body
22
+
23
+
`Deno.chdir()` mutates process-global cwd, so a test that changes it can leak into other tests in the same process. The harness already changes and restores the working directory: return the directory from `TestContext.cwd`, create fixtures in `setup`, clean up in `teardown` (examples: `tests/unit/dotenv-config.test.ts`, `tests/smoke/use/template.test.ts`). For a temp directory you don't need to run *from*, use `withTempDir` (`tests/utils.ts`). A test that only needs a *relative* input can pass a path relative to the current cwd without changing it.
**Note:** While Quarto supports local Project.toml files in document directories for production use, the quarto-cli test infrastructure specifically does NOT support this pattern. All test dependencies must be in the main `tests/` environment.
365
399
400
+
### R Tests That Change Working Directory
401
+
402
+
R resolves `.Rprofile` from the **exact** process cwd (no parent-directory
403
+
search). On CI, rmarkdown/knitr live only in `tests/renv`'s project library,
404
+
activated when cwd is `tests/` (via `tests/.Rprofile` sourcing
405
+
`renv/activate.R`). Most knitr tests never leave `tests/` — they pass paths
406
+
relative to the current cwd instead of changing directories — so activation
407
+
happens automatically.
408
+
409
+
A test that must run with cwd set elsewhere (a scratch temp dir, via
410
+
`TestContext.cwd()` — see "Working-Directory-Sensitive Tests" above) loses
411
+
that activation: the R subprocess starts outside `tests/`, renv never
412
+
activates, and package loads fail with `there is no package called
413
+
'rmarkdown'`. This is CI-only — a developer machine with rmarkdown on the
414
+
default `.libPaths()` masks it entirely. The render pipeline also tends to
415
+
swallow the underlying subprocess error, so the failure can be silent beyond
416
+
the bare package-load message.
417
+
418
+
**Fix:** in the fixture's cwd, write a `.Rprofile` that re-points renv at the
419
+
real project, regardless of where the test's cwd actually is:
420
+
421
+
```r
422
+
Sys.setenv(RENV_PROJECT="<absolute path to tests/>")
423
+
source("<absolute path to tests/>/renv/activate.R")
424
+
```
425
+
426
+
`renv/activate.R` reads `RENV_PROJECT` to determine the project root if set,
427
+
falling back to `getwd()` otherwise — setting it explicitly decouples renv
428
+
activation from the test's cwd.
429
+
366
430
## Best Practices
367
431
368
432
1.**Always clean up**: Use teardown to remove generated files
Copy file name to clipboardExpand all lines: news/changelog-1.10.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,6 +6,7 @@ All changes included in 1.10:
6
6
- ([#14281](https://github.com/quarto-dev/quarto-cli/issues/14281)): Fix transient `.quarto_ipynb` files accumulating during `quarto preview` with Jupyter engine.
7
7
- ([#14298](https://github.com/quarto-dev/quarto-cli/issues/14298)): Fix `quarto preview` browse URL including output filename (e.g., `hello.html`) for single-file documents, breaking Posit Workbench proxied server access.
8
8
- ([#14489](https://github.com/quarto-dev/quarto-cli/issues/14489)): Restore `--output-dir` support for `quarto preview` of single files when no `_quarto.yml` is present (e.g. R-package workspaces). Regression introduced in v1.9.18.
9
+
- ([#14683](https://github.com/quarto-dev/quarto-cli/issues/14683)): Fix `quarto preview` of a knitr document in a project subdirectory failing when run from that subdirectory with a bare filename (the shape RStudio's Render button uses). Regression introduced in v1.9.18.
9
10
- ([rstudio/rstudio#17333](https://github.com/rstudio/rstudio/issues/17333)): Fix `quarto inspect` on standalone files emitting project metadata that breaks RStudio's publishing wizard.
10
11
11
12
## Dependencies
@@ -115,6 +116,7 @@ All changes included in 1.10:
115
116
- ([#6092](https://github.com/quarto-dev/quarto-cli/issues/6092)): Fix the `default-image-extension` being appended to an extensionless URL ending in a slash (e.g. ``), which broke the embed/iframe image syntax.
116
117
- ([#6651](https://github.com/quarto-dev/quarto-cli/issues/6651)): Fix dart-sass compilation failing in enterprise environments where `.bat` files are blocked by group policy.
117
118
- ([#11703](https://github.com/quarto-dev/quarto-cli/issues/11703)): Fix SCSS color-variable export (`--quarto-scss-export-*`) being silently skipped when a theme rule contains consecutive semicolons (e.g. `max-height: 100% !important;;`).
119
+
- ([#12401](https://github.com/quarto-dev/quarto-cli/issues/12401)): Fix `QUARTO_DOCUMENT_PATH` being a relative path for single-file renders, inconsistent with project renders where it was absolute. Execution target paths are now normalized to absolute at a single point, so single-file and project renders behave the same.
118
120
- ([#14255](https://github.com/quarto-dev/quarto-cli/issues/14255)): Fix shortcodes inside inline and display math expressions not being resolved.
119
121
- ([#14342](https://github.com/quarto-dev/quarto-cli/issues/14342)): Work around TOCTOU race in Deno's `expandGlobSync` that can cause unexpected exceptions to be raised while traversing directories during project initialization.
120
122
- ([#14445](https://github.com/quarto-dev/quarto-cli/issues/14445)): Fix intermittent `Uncaught (in promise) TypeError: Writable stream is closed or errored.` aborting renders on Linux. `execProcess` now awaits and swallows the rejection from `process.stdin.close()` when the child closes its stdin first. The captured stderr is now also surfaced when `typst-gather analyze` falls back to staging all packages, so failures are diagnosable without bypassing `quarto`.
Copy file name to clipboardExpand all lines: tests/docs/manual/preview/README.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -161,6 +161,13 @@ After every change to preview URL or handler logic, verify that single-file prev
161
161
-**Expected:** HTTP 200. Browse URL may include path for non-index files in project context.
162
162
-**Catches:**`isSingleFile` guard accidentally excluding real project files from path computation
163
163
164
+
#### T33: knitr doc in a subdirectory — preview from that subdirectory (#14683)
165
+
166
+
-**Setup:** Fixture `knitr-subdir-14683/` — a website project with a knitr doc at `labs/doc.qmd` (an `{r}` chunk plus a `QUARTO_DOCUMENT_PATH` echo). Requires R + `rmarkdown`/`knitr`.
167
+
-**Steps:** From `knitr-subdir-14683/labs/` (the doc's own directory), run `quarto preview doc.qmd --to html --no-watch-inputs --no-browser --port XXXX` — the shape RStudio's Render button uses (bare filename, cwd = the doc's subdirectory).
168
+
-**Expected:** Renders without `Error in rmarkdown:::abs_path(input)`; `_site/labs/doc.html` is produced showing `[1] 2` (the R chunk executed). The echoed `QUARTO_DOCUMENT_PATH` is the doc's absolute subdirectory (ends in `labs`), not `.` / the project root (#12401).
169
+
-**Catches:**`fileExecutionEngineAndTarget` not normalizing the input to absolute — a cwd-relative `target.input`/`source` in the shared preview cache makes the knitr R subprocess (cwd = project dir) fail `abs_path` on the subdirectory-relative filename.
170
+
164
171
## Test Matrix: Format Change Detection (#14533)
165
172
166
173
After every change to `previewRenderRequestIsCompatible` or the
0 commit comments