refactor(測試): 模板結構的三項檢查抽到共用斷言
段落順序、正本的編號清單、圖表段落不寫死圍欄——這三件事需求議題與工作包議題 都要驗,第二份模板出現時就該抽出來。兩份測試原本各抄一份,其中佔位數的斷言 還悄悄長成不同寫法(一邊 >=、一邊 ==);抽出來之後這種分歧會被逼著講清楚。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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}\\}\\}$`));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user