Files
tea-sdlc/test/sdlc-fix-assets.test.js
T
jiantw83andClaude Opus 5 03ce382220 refactor(issue-body): 工作包的歸屬判準收成一個函式
wp-extract 與 wp-list 都在問「這顆工作包掛在哪顆需求底下」。規則寫兩份,
某天只會有一邊被改到,而分岔的樣子是「清單裡看得到、抽取卻說不是」。
順手把測試裡兩種取段落的寫法統一,並刪掉沒有人傳過的參數。

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

279 lines
12 KiB
JavaScript

/**
* /sdlc-fix 的流程正本。
*
* 這一段有四件事只有正本做得到,腳本擋不住:把三種輸入判到對的路上、分類必改/建議、
* 不確定時停下來問、以及最後那則摘要。寫漏任何一件,reviewer 的意見就會被靜靜跳過——
* 而那正是這個指令存在的理由。
*/
import test from 'node:test';
import assert from 'node:assert/strict';
import { assertNeutralPrompt, readPrompt } from './helpers/prompt-doc.js';
const prompt = readPrompt('sdlc-fix');
const steps = prompt.slice(prompt.indexOf('## 1.'), prompt.indexOf('## 邊界'));
/** 框出一個步驟的範圍,讓各步驟分開看 */
const step = (from, to) => steps.slice(steps.indexOf(from), steps.indexOf(to));
/** 判定輸入是哪一種 */
const 判定 = step('## 1.', '## 2.');
/** 議題交棒那一步 */
const 交棒 = step('## 2.', '## 3.');
/** 工作包議題與需求議題各自的小節 */
const 工作包路 = 交棒.slice(交棒.indexOf('### 工作包議題'), 交棒.indexOf('### 需求議題'));
const 需求路 = 交棒.slice(交棒.indexOf('### 需求議題'));
/** 定位工作樹那一步,與後面處理留言的步驟分開看 */
const locate = step('## 3.', '## 4.');
// ── 輸入判定:三種輸入走三條路 ─────────────────────────────────────
test('輸入接受 PR 編號或議題編號', () => {
const 輸入 = prompt.slice(prompt.indexOf('## 輸入'), prompt.indexOf('## 1.'));
assert.match(輸入, /PR 編號或議題編號/);
});
test('PR 與議題的分界用既有的留言讀取契約,不另發明判準', () => {
assert.match(判定, /pr-comments\.js/);
assert.match(判定, /類型/);
assert.match(判定, /每個 PR 都是議題/, '要說出為什麼只能從議題那一端問');
assert.match(判定, /不另發明判準/);
});
test('兩種議題的分界是工作包抽取的母議題欄位', () => {
assert.match(判定, /wp-extract\.js/);
assert.match(判定, /需求議題.*母議題|母議題/);
assert.match(判定, /解析得出編號的就是工作包議題/);
assert.match(判定, /解析不出來的就當需求\s*議題/);
});
test('三種判定各自寫明下一步,不留一種讓 agent 自由發揮', () => {
const rows = 判定.slice(判定.indexOf('| 判定'));
assert.match(rows, /`類型` 為 `PR`/);
assert.match(rows, /抽得出 `需求議題`/);
assert.match(rows, /抽不出 `需求議題`/);
});
// ── 議題:交棒給 /sdlc-feat ────────────────────────────────────────
test('工作包議題交棒給 /sdlc-feat,指的是它的正本而不是複述它', () => {
assert.match(工作包路, /sdlc-feat/);
assert.match(工作包路, /prompts\/sdlc-feat\.md/);
assert.match(工作包路, /不要把它的步驟搬過來重講一遍/);
assert.match(工作包路, /第二份正本/, '要說出為什麼不抄');
});
test('交棒不要求使用者重打指令,並指名沿用既有的接回機制', () => {
assert.match(交棒, /sdlc-sync/);
assert.match(交棒, /接回|接下去/);
assert.match(交棒, /不要求使用者重打\s*指令/);
});
test('工作包議題不在這裡先整併留言:那一步 /sdlc-feat 自己會做', () => {
assert.match(工作包路, /未處理留言數/);
assert.match(工作包路, /不必在這裡先做/);
});
test('正本裡不出現 /sdlc-feat 步驟的複製', () => {
for (const 腳本 of ['claim.js', 'branch-prep.js', 'timer.js', 'commit-split.js', 'pr-create.js']) {
assert.equal(prompt.includes(腳本), false, `這是 /sdlc-feat 的步驟,不該被抄進來:${腳本}`);
}
});
test('需求議題先讓 /sdlc-sync 整併,再談改不改碼', () => {
assert.match(需求路, /sdlc-sync/);
assert.match(需求路, /prompts\/sdlc-sync\.md/);
assert.match(需求路, /絕大多數是決策討論/, '要說出為什麼先 sync');
assert.ok(
需求路.indexOf('sdlc-sync') < 需求路.indexOf('wp-list.js'),
'整併要排在選工作包之前',
);
});
test('整併完沒有改碼要求就停下來,不硬找一顆工作包來改', () => {
assert.match(需求路, /一則都沒有就到此為止/);
assert.match(需求路, /根本不會觸發/);
});
test('有改碼要求時列出底下的工作包讓使用者挑,不報錯把事推回去', () => {
assert.match(需求路, /wp-list\.js/);
assert.match(需求路, /--requirement/);
assert.match(需求路, /不要因為「輸入不是工作包」就報錯/);
assert.match(需求路, /一次問一題/);
assert.match(需求路, /手動輸入/);
});
test('清單為空時照實說,並指出該跑的是哪一支', () => {
assert.match(需求路, /清單是空的/);
assert.match(需求路, /sdlc-analyze/);
});
test('挑定之後一樣交棒給 /sdlc-feat,留言只帶脈絡不搬走', () => {
assert.match(需求路, /交棒給 `\/sdlc-feat`/);
assert.match(需求路, /不搬走/);
});
test('PR 的第一步先看現況,終止狀態就停下來不白做工', () => {
assert.match(locate, /pr-watch\.js/);
assert.match(locate, /terminal/);
assert.match(locate, /不要繼續處理留言/);
assert.match(locate, /白做工/, '要說明為什麼停:那棵工作樹已經該被清掉了');
});
test('查現況帶 --dry-run,看一下留言不該順手清掉工作樹', () => {
const 指令 = locate.slice(locate.indexOf('pr-watch.js'));
assert.match(指令.slice(0, 120), /--dry-run/);
assert.match(locate, /清不清理是使用者的決定/);
});
test('三個建議動作的意思都交代了,不留一個讓 agent 自由發揮', () => {
for (const 值 of ['nothing-to-do', 'cleanup', 'blocked-dirty']) {
assert.match(locate, new RegExp(值));
}
});
test('工作樹由工作包推導,不要求使用者自己切目錄', () => {
assert.match(locate, /worktree-ensure\.js/);
assert.match(locate, /--path/, '目標專案不是當前目錄時要指得出來,否則會找錯 repo');
assert.match(locate, /branch/, '輸入是 pr-watch 給的分支名');
assert.match(locate, /不必也不該由使用者自己去記/);
assert.match(locate, /都在那棵工作樹裡做/);
});
test('不存在就重建,並說明那是常態不是例外', () => {
assert.match(locate, /常態不是例外/);
assert.match(locate, /換一台機器/, '要說明為什麼工作樹常常不在');
assert.match(locate, /同一套建立方式/, '重建不另寫一套');
});
test('兩種擋下來的情況各自寫明處置,且不替使用者決定', () => {
assert.match(locate, /BRANCH_NOT_FOUND/);
assert.match(locate, /WORKTREE_PATH_TAKEN/);
assert.match(locate, /不要自己刪/);
});
test('邊界擋住「回主工作區處理留言」與「PR 結束了還繼續改」', () => {
const boundary = prompt.slice(prompt.indexOf('## 邊界'));
assert.match(boundary, /不在主工作區處理留言/);
assert.match(boundary, /已經合併或關閉時不繼續處理留言/);
});
test('正本平台中立,description 前綴正確', () => {
assertNeutralPrompt(prompt, 'sdlc-fix');
});
test('指名兩支腳本,順序為先讀再回', () => {
const order = ['pr-comments.js', 'pr-reply.js'];
const positions = order.map((name) => steps.indexOf(name));
assert.equal(positions.every((p) => p >= 0), true, '兩支腳本都要被指名');
assert.deepEqual([...positions].sort((a, b) => a - b), positions);
});
test('三類留言都點名,且交代行內的 diff 要看', () => {
for (const kind of ['一般留言', 'review 總評', '行內留言']) {
assert.match(steps, new RegExp(kind), `缺少:${kind}`);
}
assert.match(steps, /不要略過不看/);
});
test('三類的標記機制都交代了,並說明 +1 要是自己打的', () => {
assert.match(steps, /三類都標記得了/);
assert.match(steps, /resolve/);
assert.match(steps, /自己打的/);
assert.match(steps, /我同意/, '要說出為什麼別人的 \+1 不算');
});
test('標不了的那幾則要在摘要裡單獨點出來', () => {
assert.match(steps, /可標記/);
assert.match(steps, /單獨點出來|單獨\n? 列出來|單獨列出來/);
});
test('留言指向的程式碼已被改掉時的處置有交代', () => {
assert.match(steps, /位置對不上/);
assert.match(steps, /不要硬試/);
});
// ── 分類 ───────────────────────────────────────────────────────────
test('必改與建議各有判斷依據,不是只給兩個詞', () => {
assert.match(steps, /\*\*必改\*\* — .{10,}/);
assert.match(steps, /\*\*建議\*\* — .{10,}/);
});
test('分類結果要先呈現給使用者再動手', () => {
assert.match(steps, /先呈現給使用者/);
});
test('拿不準時往必改那邊靠,並說明為什麼', () => {
assert.match(steps, /歸到必改/);
assert.match(steps, /代價不對稱/);
});
// ── 不確定就問 ─────────────────────────────────────────────────────
test('一次問一題,選項含手動輸入', () => {
assert.match(steps, /一次問一題/);
assert.match(steps, /手動輸入/);
});
test('該問的情況有列舉,不是一句「不確定就問」', () => {
const section = step('## 6.', '## 7.');
const bullets = section.match(/^- /gm) ?? [];
assert.ok(bullets.length >= 3, `該問的情況要列得出來,只找到 ${bullets.length} 條`);
assert.match(section, /推了新 commit/, '位置對不上是最常見的一種,要點名');
});
test('說明了硬改的代價', () => {
assert.match(steps, /比多問一題貴得多/);
});
// ── 逐則處理 ───────────────────────────────────────────────────────
test('要一則一則回,不是全部改完才一起回', () => {
assert.match(steps, /不要全部改完才一起回/);
assert.match(steps, /中途斷掉/);
});
test('三類與 --kind 的對應寫出來了,並警告 id 各自獨立', () => {
assert.match(steps, /行內.*inline/);
assert.match(steps, /一般.*general/);
assert.match(steps, /總評.*review/);
assert.match(steps, /id 各自獨立/);
});
test('回覆要說出做了什麼,且決定不改的也要回', () => {
assert.match(steps, /不是「已修正」/);
assert.match(steps, /決定不改的也要回/);
assert.match(steps, /沉默會讓 reviewer 以為被忽略/);
});
test('回覆失敗就不標記的理由有寫', () => {
assert.match(steps, /謊稱處理過/);
});
test('寫入前要求先試跑', () => {
assert.match(steps, /--dry-run/);
});
// ── 摘要 ───────────────────────────────────────────────────────────
test('摘要要逐則列出,並單獨點出沒有記號的那幾則', () => {
const section = steps.slice(steps.indexOf('## 8.')); // 最後一步,到結尾為止
assert.match(section, /逐則一行/);
assert.match(section, /沒有留下記號的那幾則/);
assert.match(section, /以為它們被跳過/, '要說出為什麼得單獨列');
});
test('摘要不自動張貼', () => {
assert.match(steps, /不自動張貼/);
});
// ── 邊界 ───────────────────────────────────────────────────────────
test('邊界列出不做的事,含不動 review 狀態', () => {
const boundary = prompt.slice(prompt.indexOf('## 邊界'));
assert.match(boundary, /不改與留言無關的程式碼/);
assert.match(boundary, /不跳過任何一則留言/);
assert.match(boundary, /不自動張貼修正摘要/);
assert.match(boundary, /不動 PR 的 review 狀態/);
});