diff --git a/test/sdlc-plan-assets.test.js b/test/sdlc-plan-assets.test.js new file mode 100644 index 0000000..f281f55 --- /dev/null +++ b/test/sdlc-plan-assets.test.js @@ -0,0 +1,127 @@ +/** + * 流程正本與輸出模板的結構驗證。 + * + * 這兩份是檔案而非程式,但它們是 #4 實際交付的東西:模板段落順序決定了下游 + * issue-extract 解析得到什麼,正本的平台中立性決定了轉接檔能不能一份寫到底。 + * 用測試釘住,比靠人記得住可靠。 + */ +import test from 'node:test'; +import assert from 'node:assert/strict'; +import { readFileSync } from 'node:fs'; +import { join } from 'node:path'; +import { repoRoot } from './helpers/run-script.js'; + +const template = readFileSync(join(repoRoot, 'templates', 'requirement-issue.md'), 'utf8'); +const prompt = readFileSync(join(repoRoot, 'prompts', 'sdlc-plan.md'), 'utf8'); + +/** 需求議題的九個段落,順序即議題裡的順序 */ +const SECTIONS = [ + '總覽', + '背景', + '目標', + '非目標', + '領域名詞表', + '流程圖', + '驗收標準', + '影響範圍', + '未決事項', +]; + +// ── 輸出模板 ─────────────────────────────────────────────────────── + +test('模板依序包含九個段落', () => { + const headings = [...template.matchAll(/^## (.+)$/gm)].map((m) => m[1].trim()); + assert.deepEqual(headings, SECTIONS); +}); + +test('模板以 {{變數}} 佔位,不留任何空白待填欄位', () => { + const placeholders = [...template.matchAll(/\{\{([^}]+)\}\}/g)].map((m) => m[1]); + assert.ok(placeholders.length >= SECTIONS.length, '每個段落至少要有一個佔位'); + for (const name of placeholders) { + assert.match(name, /^[a-z一-龥]+$/u, `佔位名稱 ${name} 應為單一詞,不含空白或符號`); + } +}); + +test('總覽段落預留了總覽網頁的連結佔位', () => { + const overview = template.slice(template.indexOf('## 總覽'), template.indexOf('## 背景')); + assert.match(overview, /\{\{總覽\}\}/); + assert.match(overview, /\{\{總覽網頁\}\}/); +}); + +// ── 流程正本 ─────────────────────────────────────────────────────── + +test('正本的 description 以「僅由 /sdlc-plan 指令叫用。」起頭', () => { + const description = prompt.match(/^description:\s*(.+)$/m)?.[1]; + assert.ok(description, '正本需要一行 description 供轉接檔取用'); + assert.ok( + description.startsWith('僅由 /sdlc-plan 指令叫用。'), + `description 前綴不符:${description}`, + ); +}); + +test('正本是平台中立的:不出現任何特定助理的語法或名稱', () => { + const platformSpecific = [ + 'AskUserQuestion', + 'Claude', + 'Codex', + 'Antigravity', + 'Copilot', + 'Kiro', + 'OpenCode', + 'oh-my-pi', + '.claude', + '$sdlc-plan', + ]; + for (const token of platformSpecific) { + assert.equal(prompt.includes(token), false, `正本不該出現平台專屬字樣:${token}`); + } +}); + +test('正本沒有 YAML frontmatter:那是各平台轉接檔的事', () => { + assert.equal(prompt.startsWith('---'), false); +}); + +test('正本交代了三種輸入都要能吃', () => { + for (const kind of ['自由文字', '規格檔', '議題編號']) { + assert.match(prompt, new RegExp(kind), `正本要說明輸入可為${kind}`); + } +}); + +test('正本明令缺漏資訊要逐項問,不得自行編造', () => { + assert.match(prompt, /一次問一題|逐項詢問/); + assert.match(prompt, /不得(自行|替使用者)?(編造|填入)/); +}); + +test('正本釘住 Mermaid flowchart 的節點上限與字數上限', () => { + assert.match(prompt, /flowchart/); + assert.match(prompt, /12/); + assert.match(prompt, /8\s*字/); + assert.match(prompt, /拆(成多)?圖|不畫/); +}); + +test('正本要求標籤只能從既有標籤挑,並指名用 labels-list 取得', () => { + assert.match(prompt, /labels-list/); + assert.match(prompt, /不(得|能)(自行)?建立(新)?標籤/); +}); + +test('正本指名由 issue-create 寫入,並提醒先以 --dry-run 檢查', () => { + assert.match(prompt, /issue-create/); + assert.match(prompt, /--dry-run/); +}); + +test('正本逐一交代九個段落,且順序與模板一致', () => { + // 只看「組出議題內容」那份編號清單,不看散落在行文裡的提及 + const listed = [...prompt.matchAll(/^\d+\.\s+\*\*(.+?)\*\*/gm)].map((m) => m[1].trim()); + assert.deepEqual(listed, SECTIONS); +}); + +test('模板不把 mermaid 圍欄寫死:不畫圖時才不會留下渲染失敗的空區塊', () => { + assert.equal(template.includes('```mermaid'), false); + const section = template.slice(template.indexOf('## 流程圖'), template.indexOf('## 驗收標準')); + assert.match(section.trim(), /^## 流程圖\s+\{\{流程圖\}\}$/); +}); + +test('正本交代了畫與不畫兩種情況各該填什麼', () => { + assert.match(prompt, /```mermaid/); + assert.match(prompt, /不要加圍欄|不加圍欄/); +});