/** * 流程正本與輸出模板的結構驗證。 * * 這兩份是檔案而非程式,但它們是 #4 實際交付的東西:模板段落順序決定了下游 * issue-extract 解析得到什麼,正本的平台中立性決定了轉接檔能不能一份寫到底。 * 用測試釘住,比靠人記得住可靠。 */ import test from 'node:test'; import assert from 'node:assert/strict'; import { assertNeutralPrompt, readPrompt, readTemplate } from './helpers/prompt-doc.js'; const template = readTemplate('requirement-issue'); const prompt = readPrompt('sdlc-plan'); /** 需求議題的九個段落,順序即議題裡的順序 */ 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 前綴正確', () => { assertNeutralPrompt(prompt, 'sdlc-plan'); }); 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, /不要加圍欄|不加圍欄/); });