refactor(測試): 模板結構的三項檢查抽到共用斷言

段落順序、正本的編號清單、圖表段落不寫死圍欄——這三件事需求議題與工作包議題
都要驗,第二份模板出現時就該抽出來。兩份測試原本各抄一份,其中佔位數的斷言
還悄悄長成不同寫法(一邊 >=、一邊 ==);抽出來之後這種分歧會被逼著講清楚。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-17 05:43:26 +00:00
co-authored by Claude Opus 5
parent 9a67c8074f
commit 6457d68874
3 changed files with 56 additions and 16 deletions
+15 -8
View File
@@ -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, /只在超過上限拆不開、或畫了不會比文字更清楚時/);
});