Files
tea-sdlc/test/sdlc-plan-assets.test.js
T
jiantw83andClaude Opus 5 2acdcea755 refactor(測試): 模板結構的三項檢查抽到共用斷言
段落順序、正本的編號清單、圖表段落不寫死圍欄——這三件事需求議題與工作包議題
都要驗,第二份模板出現時就該抽出來。兩份測試原本各抄一份,其中佔位數的斷言
還悄悄長成不同寫法(一邊 >=、一邊 ==);抽出來之後這種分歧會被逼著講清楚。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-17 13:43:07 +08:00

102 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 流程正本與輸出模板的結構驗證。
*
* 這兩份是檔案而非程式,但它們是 #4 實際交付的東西:模板段落順序決定了下游
* issue-extract 解析得到什麼,正本的平台中立性決定了轉接檔能不能一份寫到底。
* 用測試釘住,比靠人記得住可靠。
*/
import test from 'node:test';
import assert from 'node:assert/strict';
import {
assertDiagramPlaceholderOnly,
assertNeutralPrompt,
assertPromptListsSections,
assertTemplateSections,
readPrompt,
readTemplate,
} from './helpers/prompt-doc.js';
const template = readTemplate('requirement-issue');
const prompt = readPrompt('sdlc-plan');
/** 需求議題的九個段落,順序即議題裡的順序 */
const SECTIONS = [
'總覽',
'背景',
'目標',
'非目標',
'領域名詞表',
'流程圖',
'驗收標準',
'影響範圍',
'未決事項',
];
// ── 輸出模板 ───────────────────────────────────────────────────────
test('模板依序包含九個段落', () => {
assertTemplateSections(template, 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('正本逐一交代九個段落,且順序與模板一致', () => {
// 只看「組出議題內容」那份編號清單,不看散落在行文裡的提及
assertPromptListsSections(prompt, SECTIONS);
});
test('模板不把 mermaid 圍欄寫死:不畫圖時才不會留下渲染失敗的空區塊', () => {
assertDiagramPlaceholderOnly(template, '流程圖', '驗收標準');
});
test('正本交代了畫與不畫兩種情況各該填什麼', () => {
assert.match(prompt, /```mermaid/);
assert.match(prompt, /不要加圍欄|不加圍欄/);
});