|
| 1 | +/* |
| 2 | + * template-ai-config.test.ts |
| 3 | + * |
| 4 | + * Verifies that AI assistant configuration files (CLAUDE.md, AGENTS.md) |
| 5 | + * are properly excluded from extension templates when using "quarto use template". |
| 6 | + * |
| 7 | + * Copyright (C) 2020-2025 Posit Software, PBC |
| 8 | + */ |
| 9 | + |
| 10 | +import { testQuartoCmd } from "../../test.ts"; |
| 11 | +import { fileExists, noErrorsOrWarnings, pathDoNotExists } from "../../verify.ts"; |
| 12 | +import { join } from "../../../src/deno_ral/path.ts"; |
| 13 | +import { ensureDirSync } from "../../../src/deno_ral/fs.ts"; |
| 14 | + |
| 15 | +const tempDir = Deno.makeTempDirSync(); |
| 16 | + |
| 17 | +// Create a mock template source with AI config files |
| 18 | +const templateSourceDir = join(tempDir, "template-source"); |
| 19 | +ensureDirSync(templateSourceDir); |
| 20 | +Deno.writeTextFileSync( |
| 21 | + join(templateSourceDir, "template.qmd"), |
| 22 | + "---\ntitle: Template Document\n---\n\nThis is a template document." |
| 23 | +); |
| 24 | +Deno.writeTextFileSync( |
| 25 | + join(templateSourceDir, "CLAUDE.md"), |
| 26 | + "# Claude Configuration\n\nThis should be excluded." |
| 27 | +); |
| 28 | +Deno.writeTextFileSync( |
| 29 | + join(templateSourceDir, "AGENTS.md"), |
| 30 | + "# Agents Configuration\n\nThis should be excluded." |
| 31 | +); |
| 32 | +Deno.writeTextFileSync( |
| 33 | + join(templateSourceDir, "README.md"), |
| 34 | + "# Template README\n\nThis should also be excluded." |
| 35 | +); |
| 36 | + |
| 37 | +const templateFolder = "test-ai-config-template"; |
| 38 | +const workingDir = join(tempDir, templateFolder); |
| 39 | +ensureDirSync(workingDir); |
| 40 | + |
| 41 | +testQuartoCmd( |
| 42 | + "use", |
| 43 | + ["template", templateSourceDir, "--no-prompt"], |
| 44 | + [ |
| 45 | + noErrorsOrWarnings, |
| 46 | + fileExists(`${templateFolder}.qmd`), // Template file should be copied and renamed |
| 47 | + pathDoNotExists(join(workingDir, "CLAUDE.md")), // CLAUDE.md should be excluded |
| 48 | + pathDoNotExists(join(workingDir, "AGENTS.md")), // AGENTS.md should be excluded |
| 49 | + pathDoNotExists(join(workingDir, "README.md")), // README.md should also be excluded (sanity check) |
| 50 | + ], |
| 51 | + { |
| 52 | + cwd: () => { |
| 53 | + return workingDir; |
| 54 | + }, |
| 55 | + teardown: () => { |
| 56 | + try { |
| 57 | + Deno.removeSync(tempDir, { recursive: true }); |
| 58 | + } catch { |
| 59 | + // Ignore cleanup errors |
| 60 | + } |
| 61 | + return Promise.resolve(); |
| 62 | + } |
| 63 | + } |
| 64 | +); |
0 commit comments