feat(time-log): 對既有議題重跑時補到當下,每一輪各記一筆
原本的終點一律是議題的建立時間,所以對既有議題重跑時相減為負,補登直接 no-op—— 那一輪的規劃時間就這樣掉了,而那正是這顆議題要修的毛病,只是換個位置出現。 終點改成看議題是不是這一輪建立的:是就補到議題建立那一刻(第一次跑),不是就補到 補登的當下(重跑)。回報多出 `迄` 與 `依據` 兩個欄位,讓人一眼看出這一筆補的是哪一段。 「這顆議題上已經有工時就跳過」這條規則拿掉了,它與累計互斥。防重複只剩一條:錶已經 跑在這顆議題上——那一段已經有錶在記,補下去會與錶涵蓋的區間重疊。連帶把 lib 的 listIssueTimes 一起移除,沒有人再用它。 實跑驗過(議題 #57):補登 121 秒、起錶、停錶 7 秒,兩筆都進得了週報,驗完刪除。 議題 #57 的規格同步更正,另外兩處過期的敘述也一併改掉。 議題 #57 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+34
-31
@@ -2,9 +2,9 @@
|
||||
* 補登工時。
|
||||
*
|
||||
* 規劃階段最耗時的那一段發生在議題建立之前——那時候沒有標的可起錶,時間只能事後補登。
|
||||
* 這一支的價值全在「補多少」與「什麼時候不該補」:長度由議題的建立時間減掉指令開始
|
||||
* 時間算出來,不由 agent 自己做減法;已經補過的不再補一次,否則重跑會把同一段時間
|
||||
* 記兩遍,而報表看不出來那是重複的。
|
||||
* 這一支的價值全在「補多少」:長度由腳本自己算,不由 agent 做減法。終點看議題是不是
|
||||
* 這一輪建立的——是就補到建立那一刻,不是就補到現在,那一輪的規劃時間照樣要進報表。
|
||||
* 唯一不補的情形是錶已經在這顆議題上跑著,那一段已經有錶在記了。
|
||||
*/
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
@@ -27,7 +27,7 @@ const stopwatchOn = (index, repo = REPO) => ({
|
||||
repo_name: repo.split('/')[1],
|
||||
});
|
||||
|
||||
function routes(overrides = {}, { stopwatches = [], times = [] } = {}) {
|
||||
function routes(overrides = {}, { stopwatches = [] } = {}) {
|
||||
return healthyRoutes(REPO, {
|
||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}`]: {
|
||||
status: 200,
|
||||
@@ -39,7 +39,6 @@ function routes(overrides = {}, { stopwatches = [], times = [] } = {}) {
|
||||
},
|
||||
},
|
||||
'GET /api/v1/user/stopwatches': { status: 200, body: stopwatches },
|
||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/times`]: { status: 200, body: times },
|
||||
[`POST /api/v1/repos/${REPO}/issues/${INDEX}/times`]: { status: 200, body: { id: 1 } },
|
||||
...overrides,
|
||||
});
|
||||
@@ -75,7 +74,8 @@ test('長度由腳本自己算:議題的建立時間減掉 --since,agent 不
|
||||
const { json } = await run(早於建立(90), [], stub);
|
||||
|
||||
assert.equal(json.data.秒數, 90);
|
||||
assert.equal(json.data.議題建立時間, CREATED);
|
||||
assert.equal(Date.parse(json.data.迄), Date.parse(CREATED), '終點就是議題建立那一刻');
|
||||
assert.equal(json.data.依據, '議題建立');
|
||||
});
|
||||
|
||||
test('不設時間上限:中間去開會的那幾個小時照實補登,不改口問使用者', async (t) => {
|
||||
@@ -89,7 +89,7 @@ test('不設時間上限:中間去開會的那幾個小時照實補登,不
|
||||
assert.deepEqual(writes(stub).at(0).body, { time: 十小時 });
|
||||
});
|
||||
|
||||
test('錶已經跑在這顆議題上時跳過:補登排在起錶之前,代表這一步做過了', async (t) => {
|
||||
test('錶已經跑在這顆議題上時跳過:補下去會與錶涵蓋的區間重疊', async (t) => {
|
||||
const stub = await withStub(t, {}, { stopwatches: [stopwatchOn(INDEX)] });
|
||||
|
||||
const { code, json } = await run(早於建立(600), [], stub);
|
||||
@@ -97,18 +97,34 @@ test('錶已經跑在這顆議題上時跳過:補登排在起錶之前,代
|
||||
assert.equal(code, 0, json.error?.message);
|
||||
assert.equal(json.data.補登, false);
|
||||
assert.match(json.data.note, /起錶/);
|
||||
assert.deepEqual(writes(stub), [], '重跑不該把同一段時間記第二遍');
|
||||
assert.deepEqual(writes(stub), [], '那一段已經有錶在記,補下去就記了兩遍');
|
||||
});
|
||||
|
||||
test('這顆議題上已經有自己的工時時跳過,重跑不會愈補愈多', async (t) => {
|
||||
const stub = await withStub(t, {}, { times: [{ id: 3, time: 1500 }] });
|
||||
test('對既有議題重跑時補到現在,那一輪的規劃時間照樣進報表', async (t) => {
|
||||
// 議題比 --since 還早,代表這不是這一輪建立的;拿舊的建立時間當終點會算出負數,
|
||||
// 等於把這一輪的工夫丟掉
|
||||
const stub = await withStub(t);
|
||||
const 起 = new Date(Date.now() - 20 * 60 * 1000).toISOString();
|
||||
|
||||
const { code, json } = await run(早於建立(600), [], stub);
|
||||
const { code, json } = await run(起, [], stub);
|
||||
|
||||
assert.equal(code, 0, json.error?.message);
|
||||
assert.equal(json.data.補登, false);
|
||||
assert.match(json.data.note, /工時/);
|
||||
assert.deepEqual(writes(stub), []);
|
||||
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) => {
|
||||
@@ -125,10 +141,10 @@ test('錶跑在別顆議題上不影響補登:補登只寫工時,不動任
|
||||
);
|
||||
});
|
||||
|
||||
test('指令開始時間不早於議題建立時間時什麼都不補,也不算失敗', async (t) => {
|
||||
test('指令開始時間落在未來時什麼都不補,也不算失敗', async (t) => {
|
||||
const stub = await withStub(t);
|
||||
|
||||
const { code, json } = await run(new Date(Date.parse(CREATED) + 1000).toISOString(), [], stub);
|
||||
const { code, json } = await run(new Date(Date.now() + 60 * 1000).toISOString(), [], stub);
|
||||
|
||||
assert.equal(code, 0, '兩邊時鐘差幾秒是常事,不該讓整個流程停在這裡');
|
||||
assert.equal(json.data.補登, false);
|
||||
@@ -156,19 +172,6 @@ test('議題不存在時回可區分的錯誤碼', async (t) => {
|
||||
assert.deepEqual(writes(stub), []);
|
||||
});
|
||||
|
||||
test('repo 的時間追蹤關著時,訊息與前置檢查第四層說的是同一件事', async (t) => {
|
||||
// 議題讀得到卻在 times 上 404,代表時間追蹤關著;試跑不跑前置檢查,這句話得由這裡說
|
||||
const stub = await withStub(t, {
|
||||
[`GET /api/v1/repos/${REPO}/issues/${INDEX}/times`]: { status: 404, body: { message: 'not found' } },
|
||||
});
|
||||
|
||||
const { code, json } = await run(早於建立(600), ['--dry-run'], stub);
|
||||
|
||||
assert.equal(code, 1);
|
||||
assert.equal(json.error.code, 'TIME_TRACKER_OFF');
|
||||
assert.match(json.error.message, /Enable Time Tracker/);
|
||||
});
|
||||
|
||||
test('--dry-run 印出將發出的補登,但一個字都不寫進去', async (t) => {
|
||||
const stub = await withStub(t);
|
||||
|
||||
@@ -183,8 +186,8 @@ test('--dry-run 印出將發出的補登,但一個字都不寫進去', async (
|
||||
assert.deepEqual(writes(stub), [], '預覽不得真的寫入');
|
||||
});
|
||||
|
||||
test('--dry-run 會先讀現況:已經補過的預覽出來就是什麼都不做', async (t) => {
|
||||
const stub = await withStub(t, {}, { times: [{ id: 3, time: 1500 }] });
|
||||
test('--dry-run 會先讀現況:錶已經在跑時預覽出來就是什麼都不做', async (t) => {
|
||||
const stub = await withStub(t, {}, { stopwatches: [stopwatchOn(INDEX)] });
|
||||
|
||||
const { json } = await run(早於建立(1800), ['--dry-run'], stub);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user