diff --git a/test/helpers/prompt-doc.js b/test/helpers/prompt-doc.js index 292bd54..8b405b3 100644 --- a/test/helpers/prompt-doc.js +++ b/test/helpers/prompt-doc.js @@ -60,3 +60,33 @@ export function assertNeutralPrompt(prompt, command) { assert.equal(prompt.includes(token), false, `正本不該出現平台專屬字樣:${token}`); } } + +/** + * 斷言模板的 `## 標題` 就是這組段落,順序一致。 + * 段落順序即下游抽取契約的解析依據,兩邊必須一起改。 + */ +export function assertTemplateSections(template, sections) { + const headings = [...template.matchAll(/^## (.+)$/gm)].map((m) => m[1].trim()); + assert.deepEqual(headings, sections); +} + +/** + * 斷言正本的編號清單逐一交代了這組段落,順序與模板一致。 + * @param {string} text 正本內容,或其中相關的一段 + */ +export function assertPromptListsSections(text, sections) { + const listed = [...text.matchAll(/^\d+\.\s+\*\*(.+?)\*\*/gm)].map((m) => m[1].trim()); + assert.deepEqual(listed, sections); +} + +/** + * 斷言圖表段落只有佔位、沒有寫死的 mermaid 圍欄。 + * 正本允許「乾脆不畫」,圍欄寫死在模板裡的話,不畫時會在議題頁留下一塊渲染失敗的空區塊。 + * @param {string} heading 圖表段落的標題,例如 '流程圖' + * @param {string} nextHeading 其後一個段落的標題,用來框出範圍 + */ +export function assertDiagramPlaceholderOnly(template, heading, nextHeading) { + assert.equal(template.includes('```mermaid'), false); + const section = template.slice(template.indexOf(`## ${heading}`), template.indexOf(`## ${nextHeading}`)); + assert.match(section.trim(), new RegExp(`^## ${heading}\\s+\\{\\{${heading}\\}\\}$`)); +} diff --git a/test/sdlc-plan-assets.test.js b/test/sdlc-plan-assets.test.js index c3add9f..d18ed26 100644 --- a/test/sdlc-plan-assets.test.js +++ b/test/sdlc-plan-assets.test.js @@ -7,7 +7,14 @@ */ import test from 'node:test'; import assert from 'node:assert/strict'; -import { assertNeutralPrompt, readPrompt, readTemplate } from './helpers/prompt-doc.js'; +import { + assertDiagramPlaceholderOnly, + assertNeutralPrompt, + assertPromptListsSections, + assertTemplateSections, + readPrompt, + readTemplate, +} from './helpers/prompt-doc.js'; const template = readTemplate('requirement-issue'); const prompt = readPrompt('sdlc-plan'); @@ -28,8 +35,7 @@ const SECTIONS = [ // ── 輸出模板 ─────────────────────────────────────────────────────── test('模板依序包含九個段落', () => { - const headings = [...template.matchAll(/^## (.+)$/gm)].map((m) => m[1].trim()); - assert.deepEqual(headings, SECTIONS); + assertTemplateSections(template, SECTIONS); }); test('模板以 {{變數}} 佔位,不留任何空白待填欄位', () => { @@ -82,14 +88,11 @@ test('正本指名由 issue-create 寫入,並提醒先以 --dry-run 檢查', ( test('正本逐一交代九個段落,且順序與模板一致', () => { // 只看「組出議題內容」那份編號清單,不看散落在行文裡的提及 - const listed = [...prompt.matchAll(/^\d+\.\s+\*\*(.+?)\*\*/gm)].map((m) => m[1].trim()); - assert.deepEqual(listed, SECTIONS); + assertPromptListsSections(prompt, SECTIONS); }); test('模板不把 mermaid 圍欄寫死:不畫圖時才不會留下渲染失敗的空區塊', () => { - assert.equal(template.includes('```mermaid'), false); - const section = template.slice(template.indexOf('## 流程圖'), template.indexOf('## 驗收標準')); - assert.match(section.trim(), /^## 流程圖\s+\{\{流程圖\}\}$/); + assertDiagramPlaceholderOnly(template, '流程圖', '驗收標準'); }); test('正本交代了畫與不畫兩種情況各該填什麼', () => { diff --git a/test/work-package-assets.test.js b/test/work-package-assets.test.js index e7416b3..fa398e0 100644 --- a/test/work-package-assets.test.js +++ b/test/work-package-assets.test.js @@ -6,7 +6,13 @@ */ import test from 'node:test'; import assert from 'node:assert/strict'; -import { readPrompt, readTemplate } from './helpers/prompt-doc.js'; +import { + assertDiagramPlaceholderOnly, + assertPromptListsSections, + assertTemplateSections, + readPrompt, + readTemplate, +} from './helpers/prompt-doc.js'; const template = readTemplate('work-package-issue'); const prompt = readPrompt('sdlc-analyze'); @@ -29,8 +35,7 @@ const SECTIONS = [ // ── 輸出模板 ─────────────────────────────────────────────────────── test('模板依序包含九個段落', () => { - const headings = [...template.matchAll(/^## (.+)$/gm)].map((m) => m[1].trim()); - assert.deepEqual(headings, SECTIONS); + assertTemplateSections(template, SECTIONS); }); test('模板每個段落都有 {{變數}} 佔位', () => { @@ -45,9 +50,7 @@ test('介面契約是四欄表格:介面/產出者/消費者/形狀', () }); test('模板不把 mermaid 圍欄寫死:不畫圖時才不會留下渲染失敗的空區塊', () => { - assert.equal(template.includes('```mermaid'), false); - const section = template.slice(template.indexOf('## 架構圖'), template.indexOf('## 範圍邊界')); - assert.match(section.trim(), /^## 架構圖\s+\{\{架構圖\}\}$/); + assertDiagramPlaceholderOnly(template, '架構圖', '範圍邊界'); }); // ── 產生工作包那一段 ─────────────────────────────────────────────── @@ -58,8 +61,7 @@ test('第二段要等使用者對共識摘要點頭才開始', () => { }); test('正本逐一交代九個段落,且順序與模板一致', () => { - const listed = [...phase2.matchAll(/^\d+\.\s+\*\*(.+?)\*\*/gm)].map((m) => m[1].trim()); - assert.deepEqual(listed, SECTIONS); + assertPromptListsSections(phase2, SECTIONS); }); test('標題規則為動詞加名詞,且明令禁止流水編號', () => { @@ -129,3 +131,8 @@ test('第二段明列它「不做」的事,避免搶走後續流程的工作', assert.match(boundary, /不加看板/); assert.match(boundary, /不寫人天估算/); }); + +test('「不畫圖」是有條件的退路,不是免死金牌', () => { + const limits = prompt.slice(prompt.indexOf('## 架構圖的限制')); + assert.match(limits, /只在超過上限拆不開、或畫了不會比文字更清楚時/); +});