Skip to content

fix: detect Quarto engines from file content when quarto inspect is u…#4128

Draft
zackverham wants to merge 1 commit into
mainfrom
fix/quarto-engines-fallback-3993
Draft

fix: detect Quarto engines from file content when quarto inspect is u…#4128
zackverham wants to merge 1 commit into
mainfrom
fix/quarto-engines-fallback-3993

Conversation

@zackverham

@zackverham zackverham commented May 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes #3993 — Quarto documents with R code chunks (e.g. source("script.R")) were generating an empty engines field in the manifest, causing Connect to skip renv restore.

Root cause: Two gaps in engine detection:

  1. When quarto inspect fails (quarto not in the extension host's PATH), the fallback path handled .ipynbengines: ["jupyter"] and .Rmdengines: ["knitr"], but for .qmd files it never read the file content to detect {r} or {python} code chunks — leaving engines empty.

  2. When quarto inspect succeeds on a directory but returns an empty engines array (edge case with certain quarto configurations), the code skipped file-content language detection entirely.

Fix: In both paths, scan .qmd file content using the existing detectMarkdownLanguagesInContent helper to identify code chunks and populate engines accordingly.

Test plan

  • New test: fallback .qmd with {r} chunks → engines: ["knitr"]
  • New test: fallback .qmd with {python} chunks → engines: ["jupyter"]
  • New test: directory inspection with empty engines falls back to file scanning
  • All 37 quarto detector tests pass
  • All 450 inspect + bundler tests pass
  • Manual: publish a .qmd with source("script.R") from Positron without quarto in PATH — verify TOML config gets engines = ["knitr"]

🤖 Generated with Claude Code

…navailable (#3993)

When `quarto inspect` fails (e.g. quarto not in PATH) or returns empty
engines for a directory inspection, the fallback path for .qmd files
did not detect R/Python code chunks — resulting in an empty engines
field in the manifest. Connect uses this field to decide whether to
restore renv, so empty engines caused renv restore to be skipped.

Now the fallback scans .qmd file content for `{r}` and `{python}` code
chunks and sets engines to ["knitr"] / ["jupyter"] accordingly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zackverham zackverham requested a review from a team as a code owner May 5, 2026 17:03
@posit-connect-projects

posit-connect-projects Bot commented May 5, 2026

Copy link
Copy Markdown
Contributor

Claude finished @zackverham's task in 1m 14s —— View job


Code Review Complete

  • Read changed files and understand implementation
  • Review code for correctness, bugs, and edge cases
  • Check test coverage
  • Provide detailed feedback

Summary

This PR fixes issue #3993 where quarto inspect failures (e.g., quarto not installed) or empty engine results caused the fallback path to not detect R/Python code chunks from .qmd files, resulting in empty engines and skipped renv restore on Connect.

Changes:

  1. Enhanced genNonInspectConfig() to scan .qmd file content for {r} and {python} code chunks
  2. Added fallback in configFromInspect() for when quarto inspect succeeds but returns empty engines

Review: ✅ Approved

The implementation is well-structured and addresses the issue correctly.

What's good:

Code correctness verified:

  • quarto.ts:543 - The condition if (!needR || !needPython) correctly continues scanning until both languages are detected
  • quarto.ts:187 - The if (needR && needPython) break; correctly short-circuits the loop
  • quarto.ts:565-568 - Engines array only updates cfg.quarto when non-empty

Test coverage:

  • ✅ Fallback with R chunks detects knitr engine (lines 351-371)
  • ✅ Fallback with Python chunks detects jupyter engine (lines 373-389)
  • ✅ Directory inspection with empty engines falls back to file scanning (lines 429-448)

Minor Suggestions (non-blocking)

  1. PR template is incomplete - The checkboxes for Type of Change, Approach, User Impact, etc. are all unchecked. Consider filling these out for better documentation.

  2. CHANGELOG entry - The PR checklist indicates no CHANGELOG update. Given this is a user-impacting bug fix, consider adding an entry under "Fixed" referencing issue Quarto document with sourced R file generates empty engines field in manifest, causing Connect to skip renv restore #3993.


Verdict: This is a solid, well-tested fix. The implementation correctly addresses both scenarios: (1) when quarto inspect fails entirely, and (2) when it succeeds but returns empty engines. Ship it! 🚢

@zackverham zackverham marked this pull request as draft May 5, 2026 20:07
@zackverham zackverham marked this pull request as draft May 5, 2026 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quarto document with sourced R file generates empty engines field in manifest, causing Connect to skip renv restore

1 participant