64 lines
2.7 KiB
JavaScript
64 lines
2.7 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { readReference, readPrompt, assertNeutralPrompt } from './helpers/prompt-doc.js';
|
|
|
|
const RULES = readReference('delegation');
|
|
const PROMPTS = ['sdlc-plan', 'sdlc-analyze', 'sdlc-feat', 'sdlc-fix', 'sdlc-sync', 'sdlc-report'];
|
|
const EXPECTED = [
|
|
['sdlc-plan', '列出九段落依據與缺漏'],
|
|
['sdlc-analyze', '對四份清單列出疑點'],
|
|
['sdlc-analyze', '算出截止日'],
|
|
['sdlc-feat', '把議題標題翻成英文'],
|
|
['sdlc-feat', '分批提交方案'],
|
|
];
|
|
|
|
function tableEntries() {
|
|
return [...RULES.matchAll(/^\| `([^`]+)` \| ([^|]+) \|/gm)]
|
|
.map((match) => [match[1], match[2].trim()]);
|
|
}
|
|
|
|
function promptMarkers(name) {
|
|
const prompt = readPrompt(name);
|
|
return [...prompt.matchAll(/^### (?:\d+\.\s+)?(.+?)〔可委派〕\s*$/gm)]
|
|
.map((match) => [name, match[1].trim()]);
|
|
}
|
|
|
|
// ── 四條判準與雙向集合 ────────────────────────────────────────────
|
|
|
|
test('委派規則保留四條判準與兩條硬排除', () => {
|
|
for (const term of ['可驗證的成品', '不會詢問使用者', '失敗能被呼叫端偵測', '不直接寫入 Gitea 或 git']) {
|
|
assert.match(RULES, new RegExp(term));
|
|
}
|
|
});
|
|
|
|
test('委派表與六份正本的標記集合完全一致', () => {
|
|
const table = tableEntries();
|
|
const markers = PROMPTS.flatMap(promptMarkers);
|
|
assert.deepEqual(table, EXPECTED);
|
|
assert.deepEqual(markers, EXPECTED);
|
|
});
|
|
|
|
test('每個標記步驟都說明能力降級與部分委派邊界', () => {
|
|
for (const [name, step] of EXPECTED) {
|
|
const prompt = readPrompt(name);
|
|
const marker = prompt.match(new RegExp(`^### (?:\\d+\\.\\s+)?${step}〔可委派〕\\s*$`, 'm'));
|
|
assert.ok(marker, `${name} 缺少標記:${step}`);
|
|
const start = marker.index;
|
|
const body = prompt.slice(start, prompt.indexOf('\n### ', start + 1) === -1 ? prompt.length : prompt.indexOf('\n### ', start + 1));
|
|
assert.match(body, /你的環境若能把工作交給子代理|實際執行.*不委派/);
|
|
}
|
|
});
|
|
|
|
// ── 六份正本的平台與文字契約 ──────────────────────────────────────
|
|
|
|
test('六份流程正本均為平台中立且使用正確 description 前綴', () => {
|
|
for (const name of PROMPTS) assertNeutralPrompt(readPrompt(name), name);
|
|
});
|
|
|
|
test('沒有委派標記的流程仍明確列入規則表的空集合', () => {
|
|
for (const name of ['sdlc-fix', 'sdlc-sync', 'sdlc-report']) {
|
|
assert.equal(promptMarkers(name).length, 0, `${name} 不應偷偷出現委派步驟`);
|
|
}
|
|
assert.match(RULES, /sdlc-sync.*sdlc-fix.*sdlc-report/);
|
|
});
|