Merge pull request 'feat/plan-analyze-timing/main' (#63) from feat/plan-analyze-timing/main into master
Reviewed-on: #63 Reviewed-by: 系統管理員 <1+admin@noreply.localhost>
This commit was merged in pull request #63.
This commit is contained in:
@@ -66,6 +66,22 @@ export function assertNeutralPrompt(prompt, command) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 取出正本裡某一個編號步驟的內容,**以名字取而不是以編號取**。
|
||||
* 步驟會增刪、編號會整批位移,名字不會;用編號寫的測試會在別人插一步時無聲地
|
||||
* 框到另一段內容上,而那種失敗看起來像是正本掉了東西。
|
||||
* @param {string} prompt 正本內容
|
||||
* @param {string} name 步驟名,例如 '產生圖解版總覽'
|
||||
* @returns {string} 該步驟的標題與內文,到下一個 `### ` 為止
|
||||
*/
|
||||
export function promptStep(prompt, name) {
|
||||
const start = prompt.search(new RegExp(`^### \\d+\\. ${name}$`, 'm'));
|
||||
assert.ok(start >= 0, `正本裡找不到「${name}」這一步`);
|
||||
const rest = prompt.slice(start);
|
||||
const end = rest.slice(1).search(/^### /m);
|
||||
return end === -1 ? rest : rest.slice(0, end + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 斷言模板的 `## 標題` 就是這組段落,順序一致。
|
||||
* 段落順序即下游抽取契約的解析依據,兩邊必須一起改。
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
*/
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readPrompt, readTemplateFile } from './helpers/prompt-doc.js';
|
||||
import { promptStep, readPrompt, readTemplateFile } from './helpers/prompt-doc.js';
|
||||
|
||||
const template = readTemplateFile('overview-artifact.html');
|
||||
const planPrompt = readPrompt('sdlc-plan');
|
||||
const analyzePrompt = readPrompt('sdlc-analyze');
|
||||
/** 只看產生總覽那一步,避免拿整份正本的任何一處來充數 */
|
||||
const planStep = planPrompt.slice(planPrompt.indexOf('### 6.'), planPrompt.indexOf('### 7.'));
|
||||
const planStep = promptStep(planPrompt, '產生圖解版總覽');
|
||||
/** 分析版的那一步,同樣只看它自己 */
|
||||
const analyzeStep = promptStep(analyzePrompt, '產生分析版的圖解總覽');
|
||||
|
||||
/** 模板要填的欄位 */
|
||||
const PLACEHOLDERS = ['標題', '來源議題', '總覽', '目標', '流程圖', '工作包全景', '頁尾'];
|
||||
@@ -86,7 +88,7 @@ test('正本說明這份網頁是給非技術的人看的', () => {
|
||||
// ── sdlc-analyze 的步驟 ────────────────────────────────────────────
|
||||
|
||||
test('分析正本的全景圖用 graph TD,並畫出相依與時程', () => {
|
||||
const step = analyzePrompt.slice(analyzePrompt.indexOf('### 11.'));
|
||||
const step = analyzeStep;
|
||||
assert.match(step, /graph TD/);
|
||||
assert.match(step, /相依/);
|
||||
assert.match(step, /截止日/);
|
||||
@@ -97,13 +99,13 @@ test('分析正本沿用同一份模板,不另立一份', () => {
|
||||
});
|
||||
|
||||
test('全景圖一樣有節點上限,超過時的做法有交代', () => {
|
||||
const step = analyzePrompt.slice(analyzePrompt.indexOf('### 11.'));
|
||||
const step = analyzeStep;
|
||||
assert.match(step, /12/);
|
||||
assert.match(step, /最長路徑/);
|
||||
});
|
||||
|
||||
test('分析正本說明重跑會就地更新,不會留下兩個連結', () => {
|
||||
const step = analyzePrompt.slice(analyzePrompt.indexOf('### 11.'));
|
||||
const step = analyzeStep;
|
||||
assert.match(step, /就地更新/);
|
||||
assert.match(step, /只掛一個總覽網址/);
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { assertNeutralPrompt, readPrompt, readReference } from './helpers/prompt-doc.js';
|
||||
import { assertNeutralPrompt, promptStep, readPrompt, readReference } from './helpers/prompt-doc.js';
|
||||
|
||||
const prompt = readPrompt('sdlc-analyze');
|
||||
|
||||
@@ -78,16 +78,54 @@ test('正本規定最後輸出共識摘要,且摘要只印不寫', () => {
|
||||
|
||||
test('正本把「共識摘要之前不寫入」寫成明確邊界', () => {
|
||||
const boundary = prompt.slice(prompt.indexOf('## 邊界'));
|
||||
assert.match(boundary, /共識摘要之前不對 Gitea 產生任何寫入/);
|
||||
assert.match(boundary, /共識摘要之前不對 Gitea 寫入任何內容/);
|
||||
assert.match(boundary, /不建議題/);
|
||||
assert.match(boundary, /不留留言/);
|
||||
});
|
||||
|
||||
test('第一段在共識摘要之前不叫用任何寫入型腳本', () => {
|
||||
test('第一段在共識摘要之前不寫入任何內容,碼錶是唯一的例外', () => {
|
||||
const analysis = prompt.slice(prompt.indexOf('## 第一段'), prompt.indexOf('## 第二段'));
|
||||
for (const writer of ['issue-create', 'issue-update', 'issue-link', 'project-add', 'timer']) {
|
||||
for (const writer of ['issue-create', 'issue-update', 'issue-link', 'project-add']) {
|
||||
assert.equal(analysis.includes(writer), false, `第一段不該出現寫入型腳本 ${writer}`);
|
||||
}
|
||||
assert.match(analysis, /timer\.js/, '錶要起在第一段開頭,分析最耗時的正是共識之前那一段');
|
||||
});
|
||||
|
||||
// ── 計時 ───────────────────────────────────────────────────────────
|
||||
|
||||
test('起錶排在第一段開頭,停錶排在最後的回報,兩者成對出現', () => {
|
||||
const 起 = prompt.indexOf(promptStep(prompt, '起錶'));
|
||||
assert.ok(起 > prompt.indexOf(promptStep(prompt, '讀議題')), '讀完議題確認它存在之後才起');
|
||||
assert.ok(起 < prompt.indexOf('## 第二段'), '起錶要在第一段之內:分析最耗時的是共識之前那一段');
|
||||
assert.match(promptStep(prompt, '停錶並回報'), /--stop/, '停錶與最後的回報寫在同一步');
|
||||
});
|
||||
|
||||
test('起錶與停錶指的都是同一顆需求議題', () => {
|
||||
const 計時段 = [...prompt.matchAll(/node scripts\/timer\.js[^\n]*/g)].map((m) => m[0]);
|
||||
assert.ok(計時段.length >= 2, '起錶與停錶都要寫在正本裡');
|
||||
for (const line of 計時段) {
|
||||
assert.match(line, /--index <需求議題編號>/, `錶要起停在需求議題上:${line}`);
|
||||
}
|
||||
});
|
||||
|
||||
test('正本寫出這段計時涵蓋到哪,讀的人不必自己推', () => {
|
||||
assert.match(prompt, /## 計時範圍/);
|
||||
assert.match(prompt, /錶不跨階段跑/);
|
||||
});
|
||||
|
||||
test('正本交代錶已經跑在同一顆上時不重起,不把累積時間切成兩段', () => {
|
||||
assert.match(prompt, /切成兩段/);
|
||||
});
|
||||
|
||||
test('正本明令不代停別顆議題上的錶', () => {
|
||||
assert.match(prompt, /請他自己去停/);
|
||||
assert.match(prompt, /不停別顆議題上的錶/);
|
||||
});
|
||||
|
||||
test('邊界把碼錶從「不寫入」裡明文除外,並寫出理由', () => {
|
||||
const boundary = prompt.slice(prompt.indexOf('## 邊界'));
|
||||
assert.match(boundary, /碼錶除外/);
|
||||
assert.match(boundary, /工時/, '要說清楚碼錶記的是工時不是內容,否則下一個人會把它刪掉');
|
||||
});
|
||||
|
||||
test('正本要求先看未處理留言數,不是 0 就提示先整併', () => {
|
||||
|
||||
@@ -74,7 +74,7 @@ test('領取鎖的四種狀態各自交代了下一步,含放行那一種', ()
|
||||
});
|
||||
|
||||
test('缺標籤是前置條件,不混進領取鎖的四種狀態裡', () => {
|
||||
const table = phase1.slice(phase1.indexOf('| 狀態'), phase1.indexOf('碼錶一律由使用者自己停'));
|
||||
const table = phase1.slice(phase1.indexOf('| 狀態'), phase1.indexOf('鎖以外還有一個前置條件'));
|
||||
assert.equal(table.includes('LABEL_NOT_FOUND'), false, '它不是鎖的狀態,別讓四種變五種');
|
||||
assert.match(phase1, /LABEL_NOT_FOUND/, '但仍要交代它,否則使用者不知道怎麼辦');
|
||||
});
|
||||
@@ -96,9 +96,11 @@ test('被碼錶擋下時要說明停錶不會動到工作樹', () => {
|
||||
assert.match(phase1, /以為停錶等於放棄那顆工作包/, '要說明不講清楚的後果');
|
||||
});
|
||||
|
||||
test('碼錶只由使用者自己停,並說明為什麼不代勞', () => {
|
||||
assert.match(phase1, /由使用者自己停/);
|
||||
test('別顆議題上的錶只由使用者自己停,並說明為什麼不代勞', () => {
|
||||
assert.match(phase1, /別顆議題上的錶一律由使用者自己停/);
|
||||
assert.match(phase1, /工時記錯地方/);
|
||||
// 這一道自己起的那一支要自己停,否則錶會跨階段跑;兩件事不能混成一句「一律不停」
|
||||
assert.match(phase1, /停掉的只有自己起的那一支/);
|
||||
});
|
||||
|
||||
test('來源分支要問過使用者,且一次一題、附理由與手動輸入', () => {
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
assertNeutralPrompt,
|
||||
assertPromptListsSections,
|
||||
assertTemplateSections,
|
||||
promptStep,
|
||||
readPrompt,
|
||||
readTemplate,
|
||||
} from './helpers/prompt-doc.js';
|
||||
@@ -19,6 +20,9 @@ import {
|
||||
const template = readTemplate('requirement-issue');
|
||||
const prompt = readPrompt('sdlc-plan');
|
||||
|
||||
/** 某一步在正本裡的位置;以名字取而不是以編號取,插一步不會讓這些測試框錯段落 */
|
||||
const at = (name) => prompt.indexOf(promptStep(prompt, name));
|
||||
|
||||
/** 需求議題的九個段落,順序即議題裡的順序 */
|
||||
const SECTIONS = [
|
||||
'總覽',
|
||||
@@ -99,3 +103,46 @@ 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, /不停別顆議題上的錶/);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/**
|
||||
* 補登工時。
|
||||
*
|
||||
* 規劃階段最耗時的那一段發生在議題建立之前——那時候沒有標的可起錶,時間只能事後補登。
|
||||
* 這一支的價值全在「補多少」:長度由腳本自己算,不由 agent 做減法。終點看議題是不是
|
||||
* 這一輪建立的——是就補到建立那一刻,不是就補到現在,那一輪的規劃時間照樣要進報表。
|
||||
* 唯一不補的情形是錶已經在這顆議題上跑著,那一段已經有錶在記了。
|
||||
*/
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { runScript } from './helpers/run-script.js';
|
||||
import { healthyRoutes, stubEnv as envFor, withStubGitea } from './helpers/stub-gitea.js';
|
||||
|
||||
const REPO = 'plugins/tea-sdlc';
|
||||
const INDEX = 42;
|
||||
|
||||
/** 議題建立於此刻;每支測試的 --since 都相對它往前推 */
|
||||
const CREATED = '2026-09-17T10:30:00Z';
|
||||
|
||||
/** CREATED 往前推 n 秒的 ISO 時間 */
|
||||
const 早於建立 = (seconds) => new Date(Date.parse(CREATED) - seconds * 1000).toISOString();
|
||||
|
||||
/** 議題上跑著的碼錶長什麼樣 */
|
||||
const stopwatchOn = (index, repo = REPO) => ({
|
||||
issue_index: index,
|
||||
repo_owner_name: repo.split('/')[0],
|
||||
repo_name: repo.split('/')[1],
|
||||
});
|
||||
|
||||
function routes(overrides = {}, { stopwatches = [] } = {}) {
|
||||
return healthyRoutes(REPO, {
|
||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}`]: {
|
||||
status: 200,
|
||||
body: {
|
||||
number: INDEX,
|
||||
title: '為規劃與分析階段計時並補登規劃時間',
|
||||
created_at: CREATED,
|
||||
html_url: `https://gitea.jsc.idv.tw/${REPO}/issues/${INDEX}`,
|
||||
},
|
||||
},
|
||||
'GET /api/v1/user/stopwatches': { status: 200, body: stopwatches },
|
||||
[`POST /api/v1/repos/${REPO}/issues/${INDEX}/times`]: { status: 200, body: { id: 1 } },
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
|
||||
const withStub = (t, overrides = {}, options) => withStubGitea(t, routes(overrides, options));
|
||||
|
||||
const run = (since, args, stub) =>
|
||||
runScript('time-log.js', ['--repo', REPO, '--index', String(INDEX), '--since', since, ...args], {
|
||||
env: envFor(stub),
|
||||
});
|
||||
|
||||
/** 會改動 Gitea 的請求;前置檢查打在 issues/0 的探針不算(見 lib 的 checkIssueWrite) */
|
||||
const writes = (stub) =>
|
||||
stub.requests.filter((r) => r.method !== 'GET').filter((r) => !r.path.endsWith('/issues/0'));
|
||||
|
||||
test('補登時長等於指令開始到議題建立的差值', async (t) => {
|
||||
const stub = await withStub(t);
|
||||
|
||||
const { code, json } = await run(早於建立(25 * 60), [], stub);
|
||||
|
||||
assert.equal(code, 0, json.error?.message);
|
||||
assert.equal(json.data.補登, true);
|
||||
assert.equal(json.data.秒數, 25 * 60);
|
||||
const [write] = writes(stub);
|
||||
assert.equal(write.path, `/api/v1/repos/${REPO}/issues/${INDEX}/times`);
|
||||
assert.deepEqual(write.body, { time: 25 * 60 });
|
||||
});
|
||||
|
||||
test('長度由腳本自己算:議題的建立時間減掉 --since,agent 不必做減法', async (t) => {
|
||||
const stub = await withStub(t);
|
||||
|
||||
const { json } = await run(早於建立(90), [], stub);
|
||||
|
||||
assert.equal(json.data.秒數, 90);
|
||||
assert.equal(Date.parse(json.data.迄), Date.parse(CREATED), '終點就是議題建立那一刻');
|
||||
assert.equal(json.data.依據, '議題建立');
|
||||
});
|
||||
|
||||
test('不設時間上限:中間去開會的那幾個小時照實補登,不改口問使用者', async (t) => {
|
||||
const stub = await withStub(t);
|
||||
const 十小時 = 10 * 60 * 60;
|
||||
|
||||
const { code, json } = await run(早於建立(十小時), [], stub);
|
||||
|
||||
assert.equal(code, 0, '時間長不是失敗;記多了看得出來,記不到就永遠找不回來');
|
||||
assert.equal(json.data.秒數, 十小時);
|
||||
assert.deepEqual(writes(stub).at(0).body, { time: 十小時 });
|
||||
});
|
||||
|
||||
test('錶已經跑在這顆議題上時跳過:補下去會與錶涵蓋的區間重疊', async (t) => {
|
||||
const stub = await withStub(t, {}, { stopwatches: [stopwatchOn(INDEX)] });
|
||||
|
||||
const { code, json } = await run(早於建立(600), [], stub);
|
||||
|
||||
assert.equal(code, 0, json.error?.message);
|
||||
assert.equal(json.data.補登, false);
|
||||
assert.match(json.data.note, /起錶/);
|
||||
assert.deepEqual(writes(stub), [], '那一段已經有錶在記,補下去就記了兩遍');
|
||||
});
|
||||
|
||||
test('對既有議題重跑時補到現在,那一輪的規劃時間照樣進報表', async (t) => {
|
||||
// 議題比 --since 還早,代表這不是這一輪建立的;拿舊的建立時間當終點會算出負數,
|
||||
// 等於把這一輪的工夫丟掉
|
||||
const stub = await withStub(t);
|
||||
const 起 = new Date(Date.now() - 20 * 60 * 1000).toISOString();
|
||||
|
||||
const { code, json } = await run(起, [], stub);
|
||||
|
||||
assert.equal(code, 0, json.error?.message);
|
||||
assert.equal(json.data.補登, true);
|
||||
assert.equal(json.data.依據, '補登當下');
|
||||
assert.ok(Math.abs(json.data.秒數 - 20 * 60) <= 5, `補的應是這一輪的長度,實際 ${json.data.秒數}`);
|
||||
assert.equal(writes(stub).at(0).body.time, json.data.秒數);
|
||||
});
|
||||
|
||||
test('重跑是累計不是覆蓋:每一輪各記一筆,加總才是這顆議題真正的規劃時間', async (t) => {
|
||||
const stub = await withStub(t);
|
||||
const 起 = new Date(Date.now() - 10 * 60 * 1000).toISOString();
|
||||
|
||||
const 第一輪 = await run(起, [], stub);
|
||||
const 第二輪 = await run(起, [], stub);
|
||||
|
||||
assert.equal(第一輪.json.data.補登, true);
|
||||
assert.equal(第二輪.json.data.補登, true, '前一輪記過了不是跳過的理由');
|
||||
assert.equal(writes(stub).length, 2, '兩輪各記一筆');
|
||||
});
|
||||
|
||||
test('錶跑在別顆議題上不影響補登:補登只寫工時,不動任何錶', async (t) => {
|
||||
const stub = await withStub(t, {}, { stopwatches: [stopwatchOn(7)] });
|
||||
|
||||
const { code, json } = await run(早於建立(600), [], stub);
|
||||
|
||||
assert.equal(code, 0, json.error?.message);
|
||||
assert.equal(json.data.補登, true);
|
||||
assert.deepEqual(
|
||||
writes(stub).map((r) => r.path),
|
||||
[`/api/v1/repos/${REPO}/issues/${INDEX}/times`],
|
||||
'不得順手停掉別顆議題上的錶',
|
||||
);
|
||||
});
|
||||
|
||||
test('指令開始時間落在未來時什麼都不補,也不算失敗', async (t) => {
|
||||
const stub = await withStub(t);
|
||||
|
||||
const { code, json } = await run(new Date(Date.now() + 60 * 1000).toISOString(), [], stub);
|
||||
|
||||
assert.equal(code, 0, '兩邊時鐘差幾秒是常事,不該讓整個流程停在這裡');
|
||||
assert.equal(json.data.補登, false);
|
||||
assert.deepEqual(writes(stub), []);
|
||||
});
|
||||
|
||||
test('--since 不是可解析的時間時擋在打 Gitea 之前', async (t) => {
|
||||
const stub = await withStub(t);
|
||||
|
||||
const { code, json } = await run('剛剛', [], stub);
|
||||
|
||||
assert.equal(code, 1);
|
||||
assert.equal(json.error.code, 'BAD_SINCE');
|
||||
assert.equal(stub.requests.length, 0);
|
||||
});
|
||||
|
||||
test('議題不存在時回可區分的錯誤碼', async (t) => {
|
||||
const stub = await withStub(t, {
|
||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}`]: { status: 404, body: { message: 'not found' } },
|
||||
});
|
||||
|
||||
const { json } = await run(早於建立(600), [], stub);
|
||||
|
||||
assert.equal(json.error.code, 'ISSUE_NOT_FOUND');
|
||||
assert.deepEqual(writes(stub), []);
|
||||
});
|
||||
|
||||
test('--dry-run 印出將發出的補登,但一個字都不寫進去', async (t) => {
|
||||
const stub = await withStub(t);
|
||||
|
||||
const { code, json } = await run(早於建立(1800), ['--dry-run'], stub);
|
||||
|
||||
assert.equal(code, 0);
|
||||
assert.equal(json.data.dryRun, true);
|
||||
assert.equal(json.data.秒數, 1800);
|
||||
assert.deepEqual(json.data.requests, [
|
||||
{ method: 'POST', path: `/repos/${REPO}/issues/${INDEX}/times`, body: { time: 1800 } },
|
||||
]);
|
||||
assert.deepEqual(writes(stub), [], '預覽不得真的寫入');
|
||||
});
|
||||
|
||||
test('--dry-run 會先讀現況:錶已經在跑時預覽出來就是什麼都不做', async (t) => {
|
||||
const stub = await withStub(t, {}, { stopwatches: [stopwatchOn(INDEX)] });
|
||||
|
||||
const { json } = await run(早於建立(1800), ['--dry-run'], stub);
|
||||
|
||||
assert.deepEqual(json.data.requests, [], '手寫一份固定的清單會跟實作走鐘');
|
||||
assert.equal(json.data.補登, false);
|
||||
});
|
||||
+98
-3
@@ -1,9 +1,13 @@
|
||||
/**
|
||||
* 起錶。
|
||||
* 起錶與停錶。
|
||||
*
|
||||
* 錶是工時報表的唯一來源,所以這一支的價值全在「什麼時候不該起」:工作樹還沒建好
|
||||
* 錶是工時報表的唯一來源,所以起錶那一半的價值全在「什麼時候不該起」:工作樹還沒建好
|
||||
* 不該起(那由流程的順序保證),自己的錶已經跑在別顆議題上更不該起——那會把兩顆
|
||||
* 工作包的時間攪在一起。停錶一律由使用者自己來,這裡不提供。
|
||||
* 工作包的時間攪在一起。
|
||||
*
|
||||
* `--stop` 只停 `--index` 指的那一顆。每個階段停掉自己起的那支錶,錶就不會跨階段跑;
|
||||
* 但別顆議題上的錶一律不碰——那一段時間該記在哪顆議題上只有人知道,而靜默替人結算
|
||||
* 正是領取鎖那條規則當初要擋的事。
|
||||
*/
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
@@ -32,6 +36,7 @@ function routes(overrides = {}, { stopwatches = [] } = {}) {
|
||||
},
|
||||
'GET /api/v1/user/stopwatches': { status: 200, body: stopwatches },
|
||||
[`POST /api/v1/repos/${REPO}/issues/${INDEX}/stopwatch/start`]: { status: 201, body: {} },
|
||||
[`POST /api/v1/repos/${REPO}/issues/${INDEX}/stopwatch/stop`]: { status: 200, body: {} },
|
||||
...overrides,
|
||||
});
|
||||
}
|
||||
@@ -147,3 +152,93 @@ test('--dry-run 會先讀現況:已經在計時時預覽出來就是什麼都
|
||||
assert.deepEqual(json.data.requests, [], '手寫一份固定的清單會跟實作走鐘');
|
||||
assert.equal(json.data.已在計時, true);
|
||||
});
|
||||
|
||||
// ── 停錶 ───────────────────────────────────────────────────────────
|
||||
|
||||
test('--stop 停掉跑在這顆議題上的錶', async (t) => {
|
||||
const stub = await withStub(t, {}, { stopwatches: [stopwatchOn(INDEX)] });
|
||||
|
||||
const { code, json } = await run(['--stop'], stub);
|
||||
|
||||
assert.equal(code, 0, json.error?.message);
|
||||
assert.equal(json.data.碼錶已停, true);
|
||||
assert.deepEqual(
|
||||
writes(stub).map((r) => `${r.method} ${r.path}`),
|
||||
[`POST /api/v1/repos/${REPO}/issues/${INDEX}/stopwatch/stop`],
|
||||
);
|
||||
});
|
||||
|
||||
test('--stop 在錶本來就沒在跑時不算失敗,並說明這一步略過了', async (t) => {
|
||||
const stub = await withStub(t);
|
||||
|
||||
const { code, json } = await run(['--stop'], stub);
|
||||
|
||||
assert.equal(code, 0, '這一步多半排在回報之前,報成失敗會讓人以為前面那件事沒做成');
|
||||
assert.equal(json.data.碼錶已停, false);
|
||||
assert.match(json.data.note, /沒在/);
|
||||
assert.deepEqual(writes(stub), []);
|
||||
});
|
||||
|
||||
test('--stop 不碰別顆議題上的錶:錶在別顆時什麼都不停', async (t) => {
|
||||
const stub = await withStub(t, {}, { stopwatches: [stopwatchOn(7)] });
|
||||
|
||||
const { code, json } = await run(['--stop'], stub);
|
||||
|
||||
assert.equal(code, 0);
|
||||
assert.equal(json.data.碼錶已停, false);
|
||||
assert.deepEqual(writes(stub), [], '靜默替人結算別顆議題,正是領取鎖那條規則要擋的事');
|
||||
});
|
||||
|
||||
test('--stop 的 --dry-run 印出將發出的停錶,且不真的停', async (t) => {
|
||||
const stub = await withStub(t, {}, { stopwatches: [stopwatchOn(INDEX)] });
|
||||
|
||||
const { code, json } = await run(['--stop', '--dry-run'], stub);
|
||||
|
||||
assert.equal(code, 0);
|
||||
assert.equal(json.data.dryRun, true);
|
||||
assert.deepEqual(
|
||||
json.data.requests.map((r) => `${r.method} ${r.path}`),
|
||||
[`POST /repos/${REPO}/issues/${INDEX}/stopwatch/stop`],
|
||||
);
|
||||
assert.deepEqual(writes(stub), []);
|
||||
});
|
||||
|
||||
test('--stop 認得站台把「沒有錶在跑」回成 409 或 500 的兩種寫法', async (t) => {
|
||||
for (const status of [409, 500]) {
|
||||
const stub = await withStubGitea(
|
||||
t,
|
||||
routes(
|
||||
{
|
||||
[`POST /api/v1/repos/${REPO}/issues/${INDEX}/stopwatch/stop`]: {
|
||||
status,
|
||||
body: { message: 'cannot stop non existent stopwatch' },
|
||||
},
|
||||
},
|
||||
{ stopwatches: [stopwatchOn(INDEX)] },
|
||||
),
|
||||
);
|
||||
|
||||
const { code, json } = await run(['--stop'], stub);
|
||||
|
||||
assert.equal(code, 0, `${status} 若說的是碼錶,就不是真的伺服器錯誤`);
|
||||
assert.equal(json.data.碼錶已停, false);
|
||||
}
|
||||
});
|
||||
|
||||
test('--stop 遇到真的伺服器錯誤時照樣失敗,不吞掉', async (t) => {
|
||||
const stub = await withStub(
|
||||
t,
|
||||
{
|
||||
[`POST /api/v1/repos/${REPO}/issues/${INDEX}/stopwatch/stop`]: {
|
||||
status: 500,
|
||||
body: { message: 'database is on fire' },
|
||||
},
|
||||
},
|
||||
{ stopwatches: [stopwatchOn(INDEX)] },
|
||||
);
|
||||
|
||||
const { code, json } = await run(['--stop'], stub);
|
||||
|
||||
assert.equal(code, 1);
|
||||
assert.equal(json.error.code, 'HTTP_ERROR');
|
||||
});
|
||||
|
||||
@@ -62,7 +62,7 @@ test('人天估算的 API 限制寫成獨立一節,不是藏在行文裡', ()
|
||||
|
||||
test('邊界把三段各自不做的事分開列', () => {
|
||||
const boundary = prompt.slice(prompt.indexOf('## 邊界'));
|
||||
assert.match(boundary, /共識摘要之前不對 Gitea 產生任何寫入/);
|
||||
assert.match(boundary, /共識摘要之前不對 Gitea 寫入任何內容/);
|
||||
assert.match(boundary, /第二段只建立工作包議題/);
|
||||
assert.match(boundary, /第三段只掛既有的 Milestone 與看板/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user