import assert from "node:assert/strict"; import { readdir, readFile } from "node:fs/promises"; import { dirname, extname, join, relative } from "node:path"; import test from "node:test"; import { fileURLToPath } from "node:url"; import { renderSddPreflightPrompt, type SddPreflightPreferences, } from "../lib/sdd-preflight.ts"; const ROOT = dirname(dirname(fileURLToPath(import.meta.url))); const TEXT_EXTENSIONS = new Set([".md", ".ts", ".mjs", ".json"]); async function collectTextFiles(dir: string): Promise { const entries = await readdir(dir, { withFileTypes: true }); const files: string[] = []; for (const entry of entries) { const path = join(dir, entry.name); if (entry.isDirectory()) { files.push(...(await collectTextFiles(path))); continue; } if (entry.isFile() && TEXT_EXTENSIONS.has(extname(entry.name))) { files.push(path); } } return files; } const SPANISH_PREFLIGHT_COPY = [ /Antes de continuar con SDD/i, /Antes de seguir con SDD/i, /una opci[oó]n por grupo/i, /usar recomendad[oa]/i, /\bRitmo\b/i, /\bArtefactos\b/i, /\bPreguntarme\b/i, /l[ií]neas cambiadas/i, /\bhacelo\b/i, /\bSoy el Gentleman\b/i, ]; test("orchestrator keeps conversation language separate from generated artifact language", async () => { const orchestrator = await readFile(join(ROOT, "assets/orchestrator.md"), "utf8"); assert.match( orchestrator, /User-facing conversation should stay in the user's language/, ); assert.match( orchestrator, /Generated artifacts[\s\S]*default to English, regardless of the user's conversation language/, ); }); test("rendered SDD preflight prompt is English artifact copy", () => { const prefs: SddPreflightPreferences = { executionMode: "interactive", artifactStore: "openspec", chainedPrStrategy: "ask-always", reviewBudgetLines: 400, engramAvailable: false, prompted: true, }; const prompt = renderSddPreflightPrompt(prefs); assert.match(prompt, /The user already chose these SDD preferences/); assert.match(prompt, /Review budget: 400 changed lines/); for (const pattern of SPANISH_PREFLIGHT_COPY) { assert.doesNotMatch(prompt, pattern); } }); test("persistent harness prompt assets do not hardcode Spanish SDD artifact copy", async () => { const files = [ ...(await collectTextFiles(join(ROOT, "assets"))), ...(await collectTextFiles(join(ROOT, "prompts"))), ]; const failures: string[] = []; for (const file of files) { const text = await readFile(file, "utf8"); for (const pattern of SPANISH_PREFLIGHT_COPY) { if (pattern.test(text)) { failures.push(`${relative(ROOT, file)} matched ${pattern}`); } } } assert.deepEqual(failures, []); });