Files
tea-sdlc/test/sdlc-plan-assets.test.js
T
jiantw83andClaude Opus 5 7ee050de2f docs(sdlc-plan,sdlc-analyze): 兩份正本各自起停自己的錶
起錶與停錶寫在同一份正本裡成對出現,讀的人一眼看得出這段計時涵蓋到哪;兩份各加一節
「計時範圍」把兩端指出來。

sdlc-plan 記兩段:議題建立之前那段在第一步記下開始時間、議題建立之後以補登記上去;
之後起錶,回報那一步停錶。補登排在議題建立之後、起錶之前,順序反過來的話補登會被
time-log 當成「這一步做過了」而跳過。

sdlc-analyze 在它分析的那顆需求議題上起錶,起點放在第一段開頭——分析最耗時的正是
共識之前那一段,從第二段才起的話那段時間永遠是零。因此「共識摘要之前不對 Gitea
產生任何寫入」改寫成「不寫入任何**內容**」,並把碼錶明文除外、寫上理由:它記的是
工時,不是內容。這一條與 repo 擁有者確認過。

sdlc-feat 的「碼錶一律由使用者自己停」收斂成「**別顆議題上的**錶一律由使用者自己停」
——它原本讀起來像全域規則,而現在每道指令都會停自己起的那一支。

正本之間改以步驟**名稱**互指,不用編號:編號會整批位移,名字不會。測試跟著改用新的
promptStep 輔助函式,以名字框出某一步的內容,別人插一步時不會無聲地框到另一段上。

議題 #57

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

149 lines
5.9 KiB
JavaScript

/**
* 流程正本與輸出模板的結構驗證。
*
* 這兩份是檔案而非程式,但它們是 #4 實際交付的東西:模板段落順序決定了下游
* issue-extract 解析得到什麼,正本的平台中立性決定了轉接檔能不能一份寫到底。
* 用測試釘住,比靠人記得住可靠。
*/
import test from 'node:test';
import assert from 'node:assert/strict';
import {
assertDiagramPlaceholderOnly,
assertNeutralPrompt,
assertPromptListsSections,
assertTemplateSections,
promptStep,
readPrompt,
readTemplate,
} from './helpers/prompt-doc.js';
const template = readTemplate('requirement-issue');
const prompt = readPrompt('sdlc-plan');
/** 某一步在正本裡的位置;以名字取而不是以編號取,插一步不會讓這些測試框錯段落 */
const at = (name) => prompt.indexOf(promptStep(prompt, name));
/** 需求議題的九個段落,順序即議題裡的順序 */
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, /不要加圍欄|不加圍欄/);
});
// ── 計時 ───────────────────────────────────────────────────────────
test('正本寫出這段計時涵蓋到哪,讀的人不必自己推', () => {
assert.match(prompt, /## 計時範圍/);
assert.match(prompt, /錶不跨階段跑/);
});
test('議題建立之前先記下開始時間:那時候還沒有標的可起錶', () => {
assert.ok(at('記下開始時間') < at('先試跑,再寫入'), '要在議題建立之前就記下');
assert.match(promptStep(prompt, '記下開始時間'), /不要憑印象回推/);
});
test('補登排在議題建立之後、起錶之前,三者指向同一顆議題', () => {
const 補登 = prompt.indexOf('time-log.js');
const 起錶 = prompt.indexOf('timer.js');
assert.ok(at('先試跑,再寫入') < 補登, '議題還不存在時無處可補');
assert.ok(補登 < 起錶, '順序反過來的話補登會被當成做過了而跳過');
for (const line of [...prompt.matchAll(/node scripts\/(?:time-log|timer)\.js[^\n]*/g)]) {
assert.match(line[0], /--index <編號>/, `補登與起錶要指向同一顆議題:${line[0]}`);
}
});
test('補登的長度由腳本算,不要 agent 自己做減法', () => {
assert.match(prompt, /--since <記下的開始時間>/);
assert.match(prompt, /不必自己做減法/);
});
test('補登不設時間上限,也不因為時間長就改口問使用者', () => {
assert.match(prompt, /不設時間上限/);
assert.match(prompt, /不必為此多長一題出來問使用者/);
});
test('停錶排在最後的回報那一步,與起錶成對', () => {
assert.match(promptStep(prompt, '停錶並回報'), /--stop/, '停錶與回報寫在同一步');
assert.ok(at('補登規劃時間,然後起錶') < at('停錶並回報'), '先起才有得停');
});
test('正本明令不代停別顆議題上的錶', () => {
assert.match(prompt, /請他自己去停/);
const boundary = prompt.slice(prompt.indexOf('## 邊界'));
assert.match(boundary, /不停別顆議題上的錶/);
});