internal/workflow:directLastActivity 排除跨 issue 引用事件(#34)

同步 agents #34/#38/#40 三個停滯判定修補到 Go 端:

- Source 介面新增 IssueTimeline(GET /repos/{o}/{r}/issues/{n}/timeline,分頁),
  giteaapi.go 與 cmd/xcheck 同步實作
- 新增 directLastActivity:updated_at 晚於全部已知直接活動時拉 timeline 核對,
  排除 comment_ref/issue_ref 引用事件後取最晚;全為引用事件回退已知直接活動
  最晚時刻(agents #40);timeline 失敗保守沿用 updated_at
- considerIssue/considerPull 對自身 updated_at、childActivity 對子項 updated_at
  (含子項 created_at 入已知活動)套用同一排除邏輯(agents #38)
- 回歸測試:子項 updated_at 被引用刷新(TestRunStalledChildXrefRefresh)、
  timeline 全引用事件回退與拉取失敗保守路徑(TestRunStalledTimelineAllXrefFallback)
- 修正 workflow_test.go:timelines 須在 ScanStalled 呼叫前設定

驗證:go build/vet/test 全綠;xcheck 對真實 API 掃描,
stalled 輸出與 gitea.py(agents @ 78769ec)位元組一致(5833 bytes)。
This commit is contained in:
ceo
2026-09-12 15:10:31 +08:00
parent a2baf55fce
commit e4212b9c90
6 changed files with 262 additions and 20 deletions
+16
View File
@@ -28,6 +28,8 @@ type fakeSource struct {
pulls map[string][]PullRequest
// comments[owner/repo/number]
comments map[string][]Comment
// timelines[owner/repo/number]:issue timeline 事件(nil → 空 timeline)。
timelines map[string][]TimelineEvent
}
func (f *fakeSource) MyOrganizations() ([]string, error) { return f.orgs, nil }
@@ -52,6 +54,10 @@ func (f *fakeSource) IssueComments(owner, repo string, number int64) ([]Comment,
return f.comments[fmt.Sprintf("%s/%s/%d", owner, repo, number)], nil
}
func (f *fakeSource) IssueTimeline(owner, repo string, number int64) ([]TimelineEvent, error) {
return f.timelines[fmt.Sprintf("%s/%s/%d", owner, repo, number)], nil
}
func (f *fakeSource) TryGetIssue(owner, repo string, number int64) (Issue, bool, error) {
i, ok := f.issues[owner+"/"+repo][number]
if !ok {
@@ -314,6 +320,13 @@ func TestScanStalledParentTrackingNotChild(t *testing.T) {
},
},
}
// timeline:#47 的 updated_at 對應直接事件(assignees)、#39 對應 label
//(agents #34 後 updated_at 需經 timeline 核對才採計;直接事件可對應 → 採用)。
// 必須在 ScanStalled 之前設定——掃描當下讀不到的事後修改無效。
src.timelines = map[string][]TimelineEvent{
"alterminal/teai/47": {{Type: "assignees", CreatedAt: iso(-600)}},
"alterminal/teai/39": {{Type: "label", CreatedAt: iso(-60)}},
}
got, err := ScanStalled(src, "admin", 4.0, now)
if err != nil {
t.Fatalf("ScanStalled: %v", err)
@@ -515,6 +528,9 @@ func (e errSource) IssueComments(string, string, int64) ([]Comment, error) {
func (e errSource) TryGetIssue(string, string, int64) (Issue, bool, error) {
return Issue{}, false, errors.New("boom")
}
func (e errSource) IssueTimeline(string, string, int64) ([]TimelineEvent, error) {
return nil, errors.New("boom")
}
// TestRound1 round1 十進位舍入到一位小數(與 Python round(x,1) 半偶數一致)。
func TestRound1(t *testing.T) {