Skip to content

Commit 2d3a904

Browse files
authored
Merge pull request #13907 from quarto-dev/ai-config-files-render
Ignore AI assistant config files in project scanning
2 parents 74b1bc2 + cc4f920 commit 2d3a904

11 files changed

Lines changed: 392 additions & 1 deletion

File tree

‎llm-docs/testing-patterns.md‎

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
# Quarto Test Patterns
2+
3+
This document describes the standard patterns for writing smoke tests in the Quarto CLI test suite.
4+
5+
## Test Structure Overview
6+
7+
Quarto uses Deno for testing with custom verification helpers located in:
8+
- `tests/test.ts` - Core test runner (`testQuartoCmd`)
9+
- `tests/verify.ts` - Verification helpers (`fileExists`, `pathDoNotExists`, etc.)
10+
- `tests/utils.ts` - Utility functions (`docs()`, `outputForInput()`, etc.)
11+
12+
## Common Test Patterns
13+
14+
### Project Rendering Tests
15+
16+
For testing project rendering (especially website projects):
17+
18+
```typescript
19+
import { docs } from "../../utils.ts";
20+
import { join } from "../../../src/deno_ral/path.ts";
21+
import { existsSync } from "../../../src/deno_ral/fs.ts";
22+
import { testQuartoCmd } from "../../test.ts";
23+
import { fileExists, pathDoNotExists, noErrors } from "../../verify.ts";
24+
25+
const projectDir = docs("project/my-test"); // Relative path via docs()
26+
const outputDir = join(projectDir, "_site"); // Append output dir for websites
27+
28+
testQuartoCmd(
29+
"render",
30+
[projectDir],
31+
[
32+
noErrors, // Check for no errors
33+
fileExists(join(outputDir, "index.html")), // Verify expected file exists
34+
pathDoNotExists(join(outputDir, "ignored.html")), // Verify file doesn't exist
35+
],
36+
{
37+
teardown: async () => {
38+
if (existsSync(outputDir)) {
39+
await Deno.remove(outputDir, { recursive: true });
40+
}
41+
},
42+
},
43+
);
44+
```
45+
46+
**Key points:**
47+
- Use `docs()` helper to create relative paths from `tests/docs/`
48+
- For website projects, output goes to `_site` subdirectory
49+
- Use absolute paths with `join()` for file verification
50+
- Clean up output directories in teardown
51+
52+
### Extension Template Tests
53+
54+
For testing `quarto use template`:
55+
56+
```typescript
57+
import { testQuartoCmd } from "../../test.ts";
58+
import { fileExists, noErrorsOrWarnings, pathDoNotExists } from "../../verify.ts";
59+
import { join } from "../../../src/deno_ral/path.ts";
60+
import { ensureDirSync } from "../../../src/deno_ral/fs.ts";
61+
62+
const tempDir = Deno.makeTempDirSync();
63+
64+
// Create mock template source
65+
const templateSourceDir = join(tempDir, "template-source");
66+
ensureDirSync(templateSourceDir);
67+
Deno.writeTextFileSync(join(templateSourceDir, "template.qmd"), "...");
68+
Deno.writeTextFileSync(join(templateSourceDir, "config.yml"), "...");
69+
70+
const templateFolder = "my-test-template";
71+
const workingDir = join(tempDir, templateFolder);
72+
ensureDirSync(workingDir);
73+
74+
testQuartoCmd(
75+
"use",
76+
["template", templateSourceDir, "--no-prompt"],
77+
[
78+
noErrorsOrWarnings,
79+
fileExists(`${templateFolder}.qmd`), // Relative - template file renamed to folder name
80+
pathDoNotExists(join(workingDir, "README.md")), // Absolute - excluded file
81+
],
82+
{
83+
cwd: () => workingDir, // Set working directory
84+
teardown: () => {
85+
try {
86+
Deno.removeSync(tempDir, { recursive: true });
87+
} catch {
88+
// Ignore cleanup errors
89+
}
90+
return Promise.resolve();
91+
}
92+
}
93+
);
94+
```
95+
96+
**Key points:**
97+
- Use `Deno.makeTempDirSync()` for isolated test environment
98+
- Create mock template source with test files
99+
- Template files get renamed to match target directory name
100+
- Use `cwd()` function to set working directory for command execution
101+
- Clean up entire temp directory including source files
102+
- File verification uses relative paths when checking files in `cwd()`
103+
104+
## Verification Helpers
105+
106+
### Core Verifiers
107+
108+
```typescript
109+
// No errors in output
110+
noErrors
111+
112+
// No errors or warnings
113+
noErrorsOrWarnings
114+
115+
// File exists at path
116+
fileExists(path: string)
117+
118+
// Path does not exist
119+
pathDoNotExists(path: string)
120+
121+
// Folder exists at path
122+
folderExists(path: string)
123+
124+
// Directory contains only allowed paths
125+
directoryEmptyButFor(dir: string, allowedFiles: string[])
126+
```
127+
128+
### Path Helpers
129+
130+
```typescript
131+
// Create relative path from tests/docs/
132+
docs(path: string): string
133+
// Example: docs("project/site") → "tests/docs/project/site"
134+
135+
// Get expected output for input file
136+
outputForInput(input: string, to: string, projectOutDir?: string, projectRoot?: string)
137+
138+
// Find project directory
139+
findProjectDir(input: string, until?: RegExp)
140+
141+
// Find project output directory (_site, _book, etc.)
142+
findProjectOutputDir(projectdir: string)
143+
```
144+
145+
## Output Directory Patterns
146+
147+
Different project types use different output directories:
148+
149+
```typescript
150+
// Website project
151+
const outputDir = join(projectDir, "_site");
152+
153+
// Book project
154+
const outputDir = join(projectDir, "_book");
155+
156+
// Manuscript project
157+
const outputDir = join(projectDir, "_manuscript");
158+
159+
// Plain project (no type specified)
160+
// Output goes directly in project directory
161+
const outputDir = projectDir;
162+
```
163+
164+
## Test File Organization
165+
166+
Tests follow this directory structure:
167+
168+
```
169+
tests/
170+
├── docs/ # Test fixtures
171+
│ └── project/
172+
│ └── my-test/
173+
│ ├── _quarto.yml
174+
│ ├── index.qmd
175+
│ └── other-files.qmd
176+
├── smoke/ # Smoke tests
177+
│ ├── project/
178+
│ │ └── project-my-test.test.ts
179+
│ ├── render/
180+
│ ├── use/
181+
│ └── ...
182+
├── test.ts # Test runner
183+
├── verify.ts # Verification helpers
184+
└── utils.ts # Utility functions
185+
```
186+
187+
## Common Patterns
188+
189+
### Cleanup Pattern
190+
191+
Always clean up generated files in teardown:
192+
193+
```typescript
194+
teardown: async () => {
195+
if (existsSync(outputPath)) {
196+
await Deno.remove(outputPath, { recursive: true });
197+
}
198+
}
199+
```
200+
201+
### Multiple Test Cases
202+
203+
When testing multiple scenarios, declare constants at module level:
204+
205+
```typescript
206+
const tempDir = Deno.makeTempDirSync();
207+
208+
// Test case 1
209+
const folder1 = "test-case-1";
210+
const workingDir1 = join(tempDir, folder1);
211+
ensureDirSync(workingDir1);
212+
testQuartoCmd(...);
213+
214+
// Test case 2
215+
const folder2 = "test-case-2";
216+
const workingDir2 = join(tempDir, folder2);
217+
ensureDirSync(workingDir2);
218+
testQuartoCmd(...);
219+
```
220+
221+
### Path Construction
222+
223+
- **Absolute paths**: Use `join()` for all path operations
224+
- **Relative to docs**: Use `docs()` helper
225+
- **Relative to cwd**: Use plain strings or template literals in template tests
226+
227+
## Examples from Codebase
228+
229+
### Project Ignore Test
230+
See `tests/smoke/project/project-ignore-dirs.test.ts` for testing directory exclusion patterns.
231+
232+
### Website Rendering Test
233+
See `tests/smoke/project/project-website.test.ts` for website project rendering patterns.
234+
235+
### Template Usage Test
236+
See `tests/smoke/use/template.test.ts` for extension template patterns.
237+
238+
## Best Practices
239+
240+
1. **Always clean up**: Use teardown to remove generated files
241+
2. **Use helpers**: Leverage `docs()`, `fileExists()`, etc. instead of manual checks
242+
3. **Absolute paths**: Use `join()` for all path construction to handle platform differences
243+
4. **Test isolation**: Use temp directories for tests that create files
244+
5. **Clear names**: Use descriptive variable names like `projectDir`, `outputDir`, `templateFolder`
245+
6. **Comment intent**: Add comments explaining what should/shouldn't happen
246+
7. **Handle errors**: Wrap cleanup in try-catch to avoid test suite failures from cleanup issues
247+
248+
## Testing File Exclusion
249+
250+
When testing that files are excluded (like AI config files):
251+
252+
```typescript
253+
// Test that files are NOT rendered
254+
testQuartoCmd(
255+
"render",
256+
[projectDir],
257+
[
258+
noErrors,
259+
fileExists(join(outputDir, "expected.html")), // Should exist
260+
pathDoNotExists(join(outputDir, "excluded.html")), // Should NOT exist
261+
],
262+
// ...
263+
);
264+
```
265+
266+
Run test **without fix** first to verify it fails, then verify it passes with fix.

‎news/changelog-1.9.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,4 @@ All changes included in 1.9:
130130
- ([#13656](https://github.com/quarto-dev/quarto-cli/issues/13656)): Fix R code cells with empty `lang: ""` option producing invalid markdown class attributes.
131131
- ([#13832](https://github.com/quarto-dev/quarto-cli/pull/13832)): Fix `license.text` metadata not being accessible when using an inline license (`license: "text"`), and populate it with the license name for CC licenses instead of empty string. (author: @mcanouil)
132132
- ([#13856](https://github.com/quarto-dev/quarto-cli/issues/13856)): Add code annotation support for Typst and Observable.js code blocks. (author: @mcanouil)
133+
- ([#13907](https://github.com/quarto-dev/quarto-cli/issues/13907)): Ignore AI assistant configuration files (`CLAUDE.md`, `AGENTS.md`) when scanning for project input files and in extension templates, similar to how `README.md` is handled.

‎src/extension/template.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,6 @@ const kBuiltInExcludes = [
5757
"COPYRIGHT",
5858
"LICENSE",
5959
"_extensions",
60+
"CLAUDE.md",
61+
"AGENTS.md",
6062
];

‎src/project/project-context.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,9 @@ function projectHiddenIgnoreGlob(dir: string) {
873873
return projectIgnoreGlobs(dir) // standard ignores for all projects
874874
.concat(["**/_*", "**/_*/**"]) // underscore prefx
875875
.concat(["**/.*", "**/.*/**"]) // hidden (dot prefix)
876-
.concat(["**/README.?([Rrq])md"]); // README
876+
.concat(["**/README.?([Rrq])md"]) // README
877+
.concat(["**/CLAUDE.md"]) // Anthropic claude code file
878+
.concat(["**/AGENTS.md"]); // https://agents.md/
877879
}
878880

879881
export const projectInputFiles = makeTimedFunctionAsync(
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.quarto/
2+
**/*.quarto_ipynb
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "Agents Configuration"
3+
---
4+
5+
This is an agents.md configuration file that should be ignored during project scanning.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "Claude Configuration"
3+
---
4+
5+
This is an AI assistant configuration file that should be ignored during project scanning.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
project:
2+
type: website
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: "Home"
3+
---
4+
5+
This is the home page that should be rendered.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* project-ai-config.test.ts
3+
*
4+
* Verifies that AI assistant configuration files (CLAUDE.md, AGENTS.md)
5+
* are properly excluded from project file discovery and rendering.
6+
*
7+
* Copyright (C) 2020-2025 Posit Software, PBC
8+
*/
9+
10+
import { docs } from "../../utils.ts";
11+
import { join } from "../../../src/deno_ral/path.ts";
12+
import { existsSync } from "../../../src/deno_ral/fs.ts";
13+
import { testQuartoCmd } from "../../test.ts";
14+
import { fileExists, pathDoNotExists, noErrors } from "../../verify.ts";
15+
16+
const projectDir = docs("project/ai-config-files");
17+
const outputDir = join(projectDir, "_site");
18+
19+
// Test that AI assistant config files are properly excluded
20+
testQuartoCmd(
21+
"render",
22+
[projectDir],
23+
[
24+
noErrors,
25+
fileExists(join(outputDir, "index.html")), // Control: regular file should be rendered
26+
pathDoNotExists(join(outputDir, "CLAUDE.html")), // CLAUDE.md should be ignored
27+
pathDoNotExists(join(outputDir, "AGENTS.html")), // AGENTS.md should be ignored
28+
],
29+
{
30+
teardown: async () => {
31+
// Clean up _site directory
32+
if (existsSync(outputDir)) {
33+
await Deno.remove(outputDir, { recursive: true });
34+
}
35+
},
36+
},
37+
);

0 commit comments

Comments
 (0)