diff --git a/docs/branch-lines.md b/docs/branch-lines.md index 0e4366b68..097d10ef6 100644 --- a/docs/branch-lines.md +++ b/docs/branch-lines.md @@ -2,7 +2,7 @@ ## 功能 -源仓当前以 `main` 为默认分支,另有 `legacy` 和 `releases/v0.3.0.beta`。CI、E2E、Coverage 三页在页首提供“分支线”切换,每次只显示一条分支线的数据,各线互不混合: +默认分支(通常是 `main`)和已有配置分支保持独立;展示窗口内观测到的 `release/*`、`releases/*` 分支自动增加独立分支线,无需逐版本修改配置。CI、E2E、Coverage 三页在页首提供“分支线”切换,每次只显示一条分支线的数据,各线互不混合: - 每个 run 归入它的工作所针对的分支:PR 运行归入 PR 的目标分支,push、手动、定时运行归入运行所在分支。 - 目标分支不是任何已配置分支线的 run(版本 tag、其他分支的 push、无法匹配 PR 的运行)归入默认分支线,因此每个 run 只计一次。Nightly 按运行所在分支归线,手动在 release 分支执行也归 release 线。 @@ -26,7 +26,9 @@ - `key` 用于页面状态,只能是小写字母、数字和连字符;`ref` 是分支名。切换按钮、CI 层名和各处文案都显示完整分支名,不做缩写。 - `historical_refs` 只重归类早于 `before` 的已采集运行,不改 GitHub 原始记录:旧 `main` 归 `legacy`,旧 `feat/jiuwenswarm` 归现在的 `main`。切换点选在 2026-09-26 20:27 UTC 的最后一次旧 `main` 运行与 2026-09-27 13:19 UTC 的首次新 `main` 运行之间。运行和覆盖率摘要按新分支名展示;缺少原始产物的旧标签目录不能凭分支重命名补造。 -- 默认分支总是第一条线,即使未列出;重复的 key 或分支会被忽略。未配置 `branch_lines` 时不显示切换控件。 +- 默认分支在配置与数据中保持第一条线,即使未列出;重复的 key 或分支会被忽略。自动发现的 release 分支按完整名称排序,使用稳定键,已配置的同名分支沿用原 key。 +- 页面入口只显示 CI 日期窗口(近 30 天、UTC+8)内有实际可展示 run 的分支;只有旧覆盖率、空目录、窗口外历史或被排除类别时不显示。失败、取消、运行中的 run 也算有数据,不要求构建成功。默认分支同样适用,空 main 不会留下空入口;全部为空时不显示切换条。 +- 刷新后当前分支不再有窗口内数据时,切换到第一个仍有数据的分支并更新本机选择。CI、E2E、Coverage 的入口与选择保持一致。 - 页面选择保存在本浏览器,三页共用;切换时重置“最近 run”的分支筛选与覆盖率周次。 各页在非默认分支线上的内容: @@ -41,10 +43,10 @@ ## 主要实现 -- `gsb/lines.py`:`configured_lines` 读取配置,`target_of` 求 run 的目标分支,`line_of` 映射到分支线。 +- `gsb/lines.py`:`configured_lines` 读取配置并从窗口内已保存 run 的运行分支/PR 目标分支发现 release 分支,`target_of` 求 run 的目标分支,`line_of` 映射到分支线。 - run 记录新增 `base_branch`(同仓 PR 的目标分支,来自 run 的 `pull_requests`)。fork PR 的 run 没有关联 PR,沿用 [CI 分层历史](ci-history-lanes.md)的按 head 分支匹配 PR,再取 PR 的 `base`。 - 历史索引新增 run 的 `pull_requests`、`base_branch`、`head_repo` 与 PR 的 `head`、`base`、`head_sha`、`head_repo`。早期索引行缺少这些字段时,快照从记录重建一次索引行,不改记录与计数。 -- `incremental_project.build_snapshot` 按分支线分别计算 CI、分层历史、测试补充数据和覆盖率:`sections.ci` / `sections.tests` 是默认分支线,`line_sections.` 是其他分支线,`lines` 列出全部分支线。Actions 产物列表每次构建只读取一次;覆盖率产物按所属 run 归线,run 不在历史中时按其分支。 +- `incremental_project.build_snapshot` 按分支线分别计算 CI、分层历史、测试补充数据和覆盖率:`sections.ci` / `sections.tests` 是默认分支线,`line_sections.` 是其他分支线,`lines` 保留配置及自动发现的分支线,前端根据对应 CI 日期格内实际 run 过滤可见入口。Actions 产物列表每次构建只读取一次;覆盖率产物按所属 run 归线,run 不在历史中时按其分支。 - `.sync/supplements.json` 的 `lines.` 缓存各分支线的测试补充数据,随该线 run 集合变化刷新。 - `.sync/tagged.json` 版本 2 按分支保存标签化测试的组合与目录;版本 1(只有默认分支)自动迁移。 - 覆盖率基线接受 `*-coverage-summary-push-*` 与 `*-coverage-summary-workflow_dispatch-*`,前提是该分支、且各层均完整成功。 @@ -52,6 +54,7 @@ ## 边界 +- 自动发现与隐藏入口不列远端分支、不回扫 Actions 历史,不改变采集查询、预算、E2E 记录版本或产物保留规则。 - 分支线只影响 CI、E2E、Coverage 三页的展示与归类,不改变采集范围、历史记录和 Bot 触发策略。 - `legacy` 和 `releases/v0.3.0.beta` 的标签化目录和完整覆盖率基线需要来自各自分支的 push 或手动运行;目标为它们的 PR 可能修改规则,不作为基线依据。 - 已归档到默认分支、后来才配置分支线的历史 run 会在重建快照时按目标分支重新归类;标签化目录只从配置后的新运行读取。 @@ -63,4 +66,4 @@ PYTHONDONTWRITEBYTECODE=1 python3 -m unittest discover -s tests -p 'test_lines.p node .e2e/node_modules/playwright/cli.js test --config test/playwright.config.cjs -g "CI, tests and coverage" ``` -单元测试覆盖配置校验、同仓 / fork / 手动 / tag 运行的归线、release 手动 Nightly 与 legacy Daily 可见、合并队列优先归类、工作流调用和其他工作流不展示但保留记录、旧分层快照重建、各线成功率、覆盖率产物归线、标签化目录分线与迁移。浏览器用例在桌面和窄屏验证切换、跨页与刷新后保持、Daily 与合并队列链接、空合并队列、各线数据不混合,以及总览列出其他分支线的失败。 +单元测试覆盖配置校验、同仓 / fork / 手动 / tag 运行的归线、release 手动 Nightly 与 legacy Daily 可见、合并队列优先归类、工作流调用和其他工作流不展示但保留记录、旧分层快照重建、各线成功率、覆盖率产物归线、标签化目录分线与迁移。另外覆盖自动发现 `release/*`/`releases/*`、PR 目标分支、键名稳定与窗口外 run 不生成自动分支。浏览器用例在桌面和窄屏验证空入口隐藏、当前入口失效后回退、运行中仍可见、全部为空,以及切换、跨页与刷新后保持、Daily 与合并队列链接、空合并队列、各线数据不混合,以及总览列出其他分支线的失败。 diff --git a/docs/ci-history-lanes.md b/docs/ci-history-lanes.md index 52edd8692..fa8afa900 100644 --- a/docs/ci-history-lanes.md +++ b/docs/ci-history-lanes.md @@ -12,7 +12,7 @@ CI 页的「CI 分层历史」按触发方式展示该分支线窗口内的 PR | Daily | 名称匹配 daily 规则(Nightly)的 run,包括 `schedule` 和手动 `workflow_dispatch` | | 版本 | 名称匹配 release 规则(Release)的 run,包括版本 tag 推送或手动运行 | -[分支线](branch-lines.md)的每条线都有上述完整分层。非默认分支的 push / 手动门禁层使用完整分支名;例如在 `releases/v0.3.0.beta` 手动运行 Nightly,会出现在该分支线的 Daily 层。 +[分支线](branch-lines.md)的每条线都有上述完整分层;窗口内有数据的 `release/*`、`releases/*` 自动列为独立分支,窗口内没有可展示 run 的分支入口隐藏。非默认分支的 push / 手动门禁层使用完整分支名;例如在 `releases/v0.3.0.beta` 手动运行 Nightly,会出现在该分支线的 Daily 层。 `merge_group` 优先归入合并队列;其余名称规则取 `board-config.json` 的 `workflows.gate` / `daily` / `release`,缺省时使用相同默认值。`workflow_call` 子 run、其他工作流、缺少事件且没有关联 PR 的门禁 run,以及不属于该线门禁层的分支事件,不在分层图或最近 run 表中展示,也不追加脚注计数。采集仍保存所有 run,不过滤 Actions 查询;同一 run 的重试只展示最后一次尝试。没有事件但有关联 PR 的门禁 run 仍归 PR。 diff --git a/docs/dashboard-pages.md b/docs/dashboard-pages.md index a72b7b7a8..d810f9024 100644 --- a/docs/dashboard-pages.md +++ b/docs/dashboard-pages.md @@ -1,6 +1,6 @@ # 页面与交互 -看板只展示已采集的稳定状态,不运行测试。页面依次为:总览、Issue、PR、CI、E2E、Coverage、GitCode 同步(见 [GitCode 同步记录](gitcode-sync.md))。配置了[分支线](branch-lines.md)时,CI、E2E、Coverage 页首可在 main、legacy 与 release 分支之间切换,每次只显示一条分支线。旧的“看板”“构建报告”“历史数据”页已移除;看板形式并入 Issue 与 PR 页,历史分片仍作为采集器的存储保留。 +看板只展示已采集的稳定状态,不运行测试。页面依次为:总览、Issue、PR、CI、E2E、Coverage、GitCode 同步(见 [GitCode 同步记录](gitcode-sync.md))。[分支线](branch-lines.md)自动包含已观测到的 `release/*` 与 `releases/*`,CI、E2E、Coverage 页首只显示近 30 天 CI 日期格内有可展示运行的分支入口,每次查看一条分支线;刷新后失效的选择自动回到仍有数据的分支。旧的“看板”“构建报告”“历史数据”页已移除;看板形式并入 Issue 与 PR 页,历史分片仍作为采集器的存储保留。 页首显示快照时间。没有数据变化的采集不改快照时间,新的 UTC 日期会重建一次,Bot 至少每 8 小时采集一次;所以快照超过 36 小时未更新时,页面提示采集可能已停止。 diff --git a/gsb/incremental_project.py b/gsb/incremental_project.py index b991b03f1..7b0a1df06 100644 --- a/gsb/incremental_project.py +++ b/gsb/incremental_project.py @@ -5,7 +5,7 @@ from zoneinfo import ZoneInfo from .board import BoardStore -from .ci_lanes import LANES, PR_EVENTS, build_lanes, window_start +from .ci_lanes import DISPLAY_ZONE, LANES, PR_EVENTS, build_lanes, window_start from .collectors import Context, collect_ci, summarize_issues, summarize_prs, days_between from .coverage_store import CoverageStore from .history import read_json, encode @@ -171,7 +171,10 @@ def build_snapshot(sync): midnight = sync.now.replace(hour=0, minute=0, second=0) cutoff = stamp(midnight - timedelta(days=30)) progress = sync.progress() - lines = configured_lines(sync.settings, meta["default_branch"]) + start = stamp(window_start(sync.now)) + observed = [row for _, row in history.rows("runs") if start <= (row.get("created_at") or "") <= stamp(sync.now)] + lines = configured_lines(sync.settings, meta["default_branch"], runs=observed, + prs=[row for _, row in history.rows("prs")]) # A successful poll with no changed records does not manufacture a Pages # deployment. Daily aging and health metadata still get a regular refresh. cache_upgrade = supplements.get("tests_version") != SUPPLEMENT_TESTS_VERSION @@ -180,15 +183,16 @@ def build_snapshot(sync): old_ci = ((old.get("sections") or {}).get("ci") or {}).get("data") or {} old_tests = ((old.get("sections") or {}).get("tests") or {}).get("data") cache_upgrade = (cache_upgrade or "lanes" not in old_ci or (isinstance(old_tests, dict) and "tagged" not in old_tests) - or old.get("lines") != lines or any("median_duration_s" not in lane.get("summary", {}) for lane in old_ci["lanes"].get("lanes", []))) # Snapshots from before the Issue / PR trend charts are rebuilt once (without refreshing test data). trend_upgrade = any(isinstance(((old.get("sections") or {}).get(kind) or {}).get("data"), dict) and "trend" not in old["sections"][kind]["data"] for kind in ("issues", "prs")) - lanes_upgrade = False + lanes_upgrade = old.get("lines") != lines + last_day = sync.now.astimezone(DISPLAY_ZONE).date().isoformat() for line in lines: sections = old.get("sections", {}) if line["default"] else old.get("line_sections", {}).get(line["key"], {}) view = ((sections.get("ci") or {}).get("data") or {}).get("lanes") or {} + lanes_upgrade = lanes_upgrade or view.get("days", [])[-1:] != [last_day] lanes_upgrade = lanes_upgrade or [lane["key"] for lane in view.get("lanes", [])] != [key for key, _ in LANES] # Reprojecting stored run categories must not invalidate test-artifact caches. if (not history.changed and not sync.tagged.changed and not cache_upgrade and not lanes_upgrade and not trend_upgrade and old.get("sync") == progress @@ -271,7 +275,6 @@ def coverage_owner(artifact): store = CoverageStore(read_json(history.root / ".sync/coverage.json", None), read_json(history.root / ".sync/coverage-sources.json", None)) lines_read = 0 - start = stamp(window_start(sync.now)) lane_prs = [history.get("prs", str(row["number"])) for row in all_prs if not row.get("closed_at") or row["closed_at"] >= start] refreshed = day_changed or "ops" not in supplements if refreshed: diff --git a/gsb/lines.py b/gsb/lines.py index 30ab6468e..9036a8427 100644 --- a/gsb/lines.py +++ b/gsb/lines.py @@ -1,16 +1,17 @@ -"""Branch lines: long-lived branches whose CI, tests and coverage are viewed apart. +"""Branch lines: configured and observed release branches viewed apart. A run belongs to the line its work targets: a pull request's base branch, or the branch a push, dispatch or schedule ran on. Everything that targets no -other configured line (release tags, nightly, unmatched runs) stays with the +other line (release tags, unmatched runs) stays with the default branch, so no run is counted twice. """ from __future__ import annotations +import hashlib import re from datetime import datetime, timezone -from .ci_lanes import PR_EVENTS, pr_number +from .ci_lanes import PR_EVENTS, lane_of, pr_number, workflow_name KEY_RE = re.compile(r"[a-z0-9][a-z0-9-]{0,30}\Z") @@ -33,8 +34,8 @@ def _historical_refs(entry): return refs -def configured_lines(settings, default_branch): - """Lines from ``branch_lines`` in board-config.json, the default branch first.""" +def configured_lines(settings, default_branch, *, runs=(), prs=()): + """Configured lines plus release branches observed in the supplied run window.""" lines, seen = [], set() for entry in (settings or {}).get("branch_lines") or []: if not isinstance(entry, dict): @@ -47,6 +48,25 @@ def configured_lines(settings, default_branch): if aliases: line["historical_refs"] = aliases lines.append(line) + # Discover from stored runs, including PR base branches; never list remote branches or old Actions pages. + runs, prs = list(runs), list(prs) + by_number = {pr.get("number"): pr for pr in prs} + names = {row.get("workflow_id"): row["name"] for row in runs if row.get("name") and not re.search(r"\.ya?ml$", row["name"])} + refs = set() + for row in runs: + ref = target_of(row, prs, by_number) + if isinstance(ref, str) and ref.startswith(("release/", "releases/")) and ref.split("/", 1)[1]: + if lane_of({**row, "name": workflow_name(row, names)}, (settings or {}).get("workflows"), ref): + refs.add(ref) + for ref in sorted(refs - {line["ref"] for line in lines} - {default_branch}): + salt = 0 + while True: + key = "release-" + hashlib.sha256(f"{ref}:{salt}".encode()).hexdigest()[:20] + if key not in seen: + break + salt += 1 + seen.add(key) + lines.append({"key": key, "ref": ref}) default = next((line for line in lines if line["ref"] == default_branch), None) if not default: default = {"key": default_branch if KEY_RE.match(default_branch) else "default", "ref": default_branch} diff --git a/site/app.js b/site/app.js index 31565eb61..6cf73d6fc 100644 --- a/site/app.js +++ b/site/app.js @@ -265,11 +265,15 @@ }; // Branch lines: CI, E2E and Coverage show one long-lived branch at a time. PR runs // belong to the branch they target; sections hold the default line. - const currentLine = (snap) => { const lines = snap?.lines || []; return lines.find((l) => l.key === STATE.line) || lines[0] || { key: '', ref: snap?.repository?.default_branch, default: true }; }; + const visibleLines = (snap) => (snap?.lines || []).filter((line) => { + const ci = (line.default ? snap.sections : snap.line_sections?.[line.key])?.ci?.data; + return ci?.lanes?.lanes?.some((lane) => Object.hasOwn(LANE_SOURCE, lane.key) && lane.days.some((day) => day.length)); + }); + const currentLine = (snap) => { const lines = visibleLines(snap); return lines.find((l) => l.key === STATE.line) || lines[0] || { key: '', ref: snap?.repository?.default_branch, default: true }; }; const lineSection = (snap, name) => { const line = currentLine(snap); return line.default ? snap.sections[name] : snap.line_sections?.[line.key]?.[name]; }; const lineBar = (snap) => { - const lines = snap.lines || [], line = currentLine(snap); - if (lines.length < 2) return ''; + const lines = visibleLines(snap), line = currentLine(snap); + if (!lines.length) return ''; return `
分支线${lines.map((l) => ``).join('')}
` + `当前 ${esc(line.ref)}:按运行分支及 PR 目标分支归类,按 PR、分支门禁、合并队列、Daily 与版本展示;各分支线的数据互不混合。
`; }; @@ -1415,6 +1419,10 @@ safe('issues', () => renderIssues(snap.sections.issues)); safe('prs', () => renderPRs(snap.sections.prs)); const line = currentLine(snap); + if (STATE.line !== line.key) { + STATE.line = line.key; + try { localStorage.setItem(LINE_KEY, STATE.line); } catch (e) { /* private mode */ } + } safe('ci', () => lineBar(snap) + renderCI(lineSection(snap, 'ci'), line)); safe('tests', () => lineBar(snap) + renderTests(lineSection(snap, 'tests'), line)); safe('coverage', () => lineBar(snap) + renderCoverage(lineSection(snap, 'tests'), line)); diff --git a/site/index.html b/site/index.html index a4a0542d5..0f0702ab0 100644 --- a/site/index.html +++ b/site/index.html @@ -5,7 +5,7 @@ GitHub 状态看板 - +
@@ -44,8 +44,8 @@ - - - + + + diff --git a/site/style.css b/site/style.css index 6bfbf78f9..0784e113c 100644 --- a/site/style.css +++ b/site/style.css @@ -371,6 +371,8 @@ details { margin-top: 4px; } .seg button.on { background: var(--s1); color: #fff; } /* Branch line switch above the CI, test and coverage pages. */ .line-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0 0 14px; } +.line-switch { flex-wrap: wrap; max-width: 100%; } +.line-switch button { flex: 0 1 auto; max-width: 100%; white-space: normal; overflow-wrap: anywhere; } .line-bar > .muted { font-size: 12.5px; min-width: 0; } .check { font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 4px; } .grow { flex: 1 1 auto; } diff --git a/static/app.js b/static/app.js index 31565eb61..6cf73d6fc 100644 --- a/static/app.js +++ b/static/app.js @@ -265,11 +265,15 @@ }; // Branch lines: CI, E2E and Coverage show one long-lived branch at a time. PR runs // belong to the branch they target; sections hold the default line. - const currentLine = (snap) => { const lines = snap?.lines || []; return lines.find((l) => l.key === STATE.line) || lines[0] || { key: '', ref: snap?.repository?.default_branch, default: true }; }; + const visibleLines = (snap) => (snap?.lines || []).filter((line) => { + const ci = (line.default ? snap.sections : snap.line_sections?.[line.key])?.ci?.data; + return ci?.lanes?.lanes?.some((lane) => Object.hasOwn(LANE_SOURCE, lane.key) && lane.days.some((day) => day.length)); + }); + const currentLine = (snap) => { const lines = visibleLines(snap); return lines.find((l) => l.key === STATE.line) || lines[0] || { key: '', ref: snap?.repository?.default_branch, default: true }; }; const lineSection = (snap, name) => { const line = currentLine(snap); return line.default ? snap.sections[name] : snap.line_sections?.[line.key]?.[name]; }; const lineBar = (snap) => { - const lines = snap.lines || [], line = currentLine(snap); - if (lines.length < 2) return ''; + const lines = visibleLines(snap), line = currentLine(snap); + if (!lines.length) return ''; return `
分支线${lines.map((l) => ``).join('')}
` + `当前 ${esc(line.ref)}:按运行分支及 PR 目标分支归类,按 PR、分支门禁、合并队列、Daily 与版本展示;各分支线的数据互不混合。
`; }; @@ -1415,6 +1419,10 @@ safe('issues', () => renderIssues(snap.sections.issues)); safe('prs', () => renderPRs(snap.sections.prs)); const line = currentLine(snap); + if (STATE.line !== line.key) { + STATE.line = line.key; + try { localStorage.setItem(LINE_KEY, STATE.line); } catch (e) { /* private mode */ } + } safe('ci', () => lineBar(snap) + renderCI(lineSection(snap, 'ci'), line)); safe('tests', () => lineBar(snap) + renderTests(lineSection(snap, 'tests'), line)); safe('coverage', () => lineBar(snap) + renderCoverage(lineSection(snap, 'tests'), line)); diff --git a/static/index.html b/static/index.html index a4a0542d5..0f0702ab0 100644 --- a/static/index.html +++ b/static/index.html @@ -5,7 +5,7 @@ GitHub 状态看板 - +
@@ -44,8 +44,8 @@ - - - + + + diff --git a/static/style.css b/static/style.css index 6bfbf78f9..0784e113c 100644 --- a/static/style.css +++ b/static/style.css @@ -371,6 +371,8 @@ details { margin-top: 4px; } .seg button.on { background: var(--s1); color: #fff; } /* Branch line switch above the CI, test and coverage pages. */ .line-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0 0 14px; } +.line-switch { flex-wrap: wrap; max-width: 100%; } +.line-switch button { flex: 0 1 auto; max-width: 100%; white-space: normal; overflow-wrap: anywhere; } .line-bar > .muted { font-size: 12.5px; min-width: 0; } .check { font-size: 13px; color: var(--ink-2); display: inline-flex; align-items: center; gap: 4px; } .grow { flex: 1 1 auto; } diff --git a/test/journey-board.spec.cjs b/test/journey-board.spec.cjs index eaa22c30e..19c2ed394 100644 --- a/test/journey-board.spec.cjs +++ b/test/journey-board.spec.cjs @@ -1299,3 +1299,74 @@ test('production and test sites show their source and isolate browser fields', a await page.reload(); await note(); await expect(page.locator('[data-dfield="note"]')).toHaveValue('正式项目备注'); }); + +test('release branch entries show window data and hide empty or expired lines after refresh', async ({ page }) => { + const refs = ['main', 'releases/v0.4.0.rc1', 'release/v0.4.1']; + let hideRc = false, hideMain = false, hideAll = false; + const errors = []; page.on('pageerror', error => errors.push(error.message)); + const empty = ci => { for (const lane of ci.lanes.lanes) { lane.days = lane.days.map(() => []); lane.summary = { total: 0, success: 0, failure: 0, cancelled: 0, running: 0, other: 0, success_rate: null, median_duration_s: null }; } }; + await page.route('**/data/snapshot.json*', async route => { + const source = await (await route.fetch()).json(); + const branch = (key, ref, id, running = false) => { + const sections = structuredClone(source.line_sections.release); + const ci = sections.ci.data; + ci.default_branch = ref; ci.lanes.branch = ref; + const main = ci.lanes.lanes.find(lane => lane.key === 'main'); + const point = structuredClone(main.days.flat()[0]); + empty(ci); main.label = ref; + Object.assign(point, { id, branch: ref, url: `https://github.com/ScienceDiscovery/sciencediscovery/actions/runs/${id}`, + conclusion: running ? null : 'failure', status: running ? 'in_progress' : 'completed', outcome: running ? 'running' : 'failure' }); + main.days.at(-1).push(point); Object.assign(main.summary, { total: 1, failure: running ? 0 : 1, running: running ? 1 : 0, success_rate: running ? null : 0 }); + ci.recent_runs = [point]; ci.latest_main.run = { ...point, title: `Full validation on ${ref}` }; + for (const workflow of ci.workflows) workflow.last_run = ci.latest_main.run; + source.lines.push({ key, ref, default: false }); source.line_sections[key] = sections; + return ci; + }; + const rc = branch('auto-rc1', refs[1], 42805465980); + const queued = branch('auto-next', refs[2], 42805465981, true); + empty(source.line_sections.legacy.ci.data); empty(source.line_sections.release.ci.data); + if (hideRc || hideAll) empty(rc); + if (hideMain || hideAll) empty(source.sections.ci.data); + if (hideAll) empty(queued); + await route.fulfill({ json: source }); + }); + await page.goto('/github-status-board/#ci'); + const ci = page.locator('#tab-ci'), buttons = ci.locator('.line-switch button'); + await expect(buttons).toHaveText(refs); + await expect(ci.locator('.line-switch')).not.toContainText('legacy'); + await expect(ci.locator('.line-switch')).not.toContainText('releases/v0.3.0.beta'); + await buttons.filter({ hasText: refs[1] }).click(); + await expect(ci.locator('[data-lane="main"] .ci-lane-head b')).toHaveText(refs[1]); + await expect(ci.locator('[data-lane="main"] .ci-run')).toHaveAttribute('href', /\/runs\/42805465980$/); + await expect(ci.locator('.card').filter({ hasText: '最近一次' }).first()).toContainText(`Full validation on ${refs[1]}`); + await ci.locator('.line-bar').screenshot({ path: shot('ci-release-entries-desktop') }); + await page.evaluate(() => scrollTo(0, 0)); + await page.screenshot({ path: shot('ci-release-rc1-desktop') }); + await page.setViewportSize({ width: 390, height: 844 }); + expect(await page.evaluate(() => document.documentElement.scrollWidth <= innerWidth)).toBe(true); + const label = ci.locator('[data-lane="main"] .ci-lane-head b'); + expect(await label.evaluate(el => el.scrollWidth <= el.clientWidth + 1)).toBe(true); + expect(await buttons.evaluateAll(nodes => nodes.every(el => el.scrollWidth <= el.clientWidth + 1 && el.getBoundingClientRect().right <= el.closest('.line-switch').getBoundingClientRect().right + 1))).toBe(true); + await ci.locator('.line-bar').screenshot({ path: shot('ci-release-entries-narrow') }); + await ci.locator('.card:has(.ci-lanes)').screenshot({ path: shot('ci-release-rc1-narrow') }); + await page.locator('[data-tab="tests"]').click(); + await expect(page.locator('#tab-tests .line-switch button.on')).toHaveText(refs[1]); + await page.locator('[data-tab="coverage"]').click(); + await expect(page.locator('#tab-coverage .line-switch button.on')).toHaveText(refs[1]); + await page.locator('[data-tab="ci"]').click(); + hideRc = true; + await page.locator('#refresh-btn').click(); + await expect(buttons).toHaveText([refs[0], refs[2]]); + await expect(ci.locator('.line-switch button.on')).toHaveText(refs[0]); + await page.reload(); + await expect(ci.locator('.line-switch button.on')).toHaveText(refs[0]); + hideMain = true; + await page.locator('#refresh-btn').click(); + await expect(buttons).toHaveText([refs[2]]); + await expect(ci.locator('.line-switch button.on')).toHaveText(refs[2]); + await expect(ci.locator('[data-lane="main"] .ci-run')).toHaveClass(/running/); + hideAll = true; + await page.locator('#refresh-btn').click(); + await expect(ci.locator('.line-switch')).toHaveCount(0); + expect(errors).toEqual([]); +}); diff --git a/tests/test_lines.py b/tests/test_lines.py index f9170884f..813ddfec0 100644 --- a/tests/test_lines.py +++ b/tests/test_lines.py @@ -30,6 +30,30 @@ def test_default_branch_comes_first_and_invalid_entries_are_dropped(self): [("main", "main", True), ("jiuwen", "feat/jiuwenswarm", False)]) self.assertEqual(configured_lines({}, "main"), [{"key": "main", "ref": "main", "default": True}]) + def test_release_branches_are_discovered_from_visible_runs_and_pr_targets(self): + runs = [ + dict(name="CI", id=42805465980, event="workflow_dispatch", branch="releases/v0.4.0.rc1"), + dict(name="CI", id=2, event="pull_request", branch="fix", base_branch="release/v0.4.1"), + dict(name="Nightly", id=3, event="schedule", branch="releases/v0.3.0.beta"), + dict(name="CI", id=4, event="workflow_call", branch="release/hidden-call"), + dict(name="Maintenance", id=5, event="push", branch="release/hidden-other"), + dict(name="CI", id=6, branch="release/hidden-unknown"), + dict(name="CI", id=7, event="push", branch="feature/release-not-a-line"), + dict(name="CI", id=8, event="pull_request", branch="fix", pull_requests=[88]), + ] + settings = {"branch_lines": RENAMED_LINES, "workflows": RULES} + prs = [dict(number=88, base="release/pr-base")] + lines = configured_lines(settings, "main", runs=runs, prs=prs) + self.assertEqual([line["ref"] for line in lines], + ["main", "legacy", "releases/v0.3.0.beta", "release/pr-base", "release/v0.4.1", "releases/v0.4.0.rc1"]) + self.assertEqual(lines, configured_lines(settings, "main", runs=list(reversed(runs)), prs=prs)) + self.assertEqual(len({line["key"] for line in lines}), len(lines)) + rc = next(line for line in lines if line["ref"] == "releases/v0.4.0.rc1") + self.assertEqual(line_of("releases/v0.4.0.rc1", lines), rc["key"]) + self.assertRegex(rc["key"], r"^[a-z0-9-]+$") + # A manually configured line keeps its stable key instead of being added twice. + self.assertEqual(next(line["key"] for line in lines if line["ref"] == "releases/v0.3.0.beta"), "release") + def test_runs_belong_to_the_branch_their_work_targets(self): lines = configured_lines({"branch_lines": LINES}, "main") prs = [dict(number=9, head="swarm-fork", head_repo="fork/source", base="feat/jiuwenswarm", @@ -182,6 +206,54 @@ def check(snapshot): for ident in (11, 12, 13, 16): self.assertIn(ident, {row["id"] for _, row in sync.history.rows("runs")}) + def test_lane_window_ages_at_beijing_midnight_without_refreshing_artifacts(self): + source = self.source() + source.runs.append({**source.runs[1], "id": 93, "head_branch": "legacy", "created_at": "2026-08-24T00:00:00Z", "updated_at": "2026-08-24T00:00:00Z"}) + settings = {"workflows": RULES, "branch_lines": [{"key": "legacy", "ref": "legacy"}]} + sync = Sync(source, self.root, REPO, settings=settings, now=NOW).collect() + with patch("gsb.incremental_project.public_ops", return_value={}), patch("gsb.incremental_project.public_tests", return_value={}): + before = build_snapshot(sync) + self.assertEqual(points(before["line_sections"]["legacy"]["ci"]["data"]["lanes"]["lanes"][1]), [93]) + for name, content in {**sync.files(), "site/data/snapshot.json": json.dumps(before)}.items(): + path = self.root / name; path.parent.mkdir(parents=True, exist_ok=True); path.write_text(content) + # Same UTC day, next Beijing day: the oldest displayed day must disappear. + again = Sync(source, self.root, REPO, settings=settings, now=NOW + timedelta(hours=5)) + again.meta = sync.meta + with patch("gsb.incremental_project.public_tests") as tests: + after = build_snapshot(again) + self.assertEqual(after["line_sections"]["legacy"]["ci"]["data"]["lanes"]["days"][0], "2026-08-25") + self.assertEqual(points(after["line_sections"]["legacy"]["ci"]["data"]["lanes"]["lanes"][1]), []) + tests.assert_not_called() + + def test_release_full_run_gets_its_own_line_from_existing_window_records(self): + source = self.source() + source.runs += [ + {**source.runs[1], "id": 42805465980, "run_attempt": 1, "event": "workflow_dispatch", "head_branch": "releases/v0.4.0.rc1"}, + {**source.runs[1], "id": 91, "head_branch": "release/expired", "created_at": "2026-07-01T00:00:00Z"}, + {**source.runs[1], "id": 92, "head_branch": "release/future", "created_at": "2026-09-23T00:00:00Z"}, + ] + sync = Sync(source, self.root, REPO, settings={"workflows": RULES}, now=NOW).collect() + source.calls.clear() + with patch("gsb.incremental_project.public_ops", return_value={}), patch("gsb.incremental_project.public_tests", return_value={}): + doc = build_snapshot(sync) + self.assertEqual([line["ref"] for line in doc["lines"]], ["main", "releases/v0.4.0.rc1"]) + key = doc["lines"][1]["key"] + ci = doc["line_sections"][key]["ci"]["data"] + self.assertEqual(ci["default_branch"], "releases/v0.4.0.rc1") + self.assertEqual(ci["latest_main"]["run"]["id"], 42805465980) + self.assertEqual(points(ci["lanes"]["lanes"][1]), [42805465980]) + self.assertEqual(ci["lanes"]["lanes"][1]["label"], "releases/v0.4.0.rc1") + self.assertNotIn(42805465980, [ident for lane in doc["sections"]["ci"]["data"]["lanes"]["lanes"] for ident in points(lane)]) + self.assertEqual(source.calls, [], "discovery and lane projection use stored data, not new Actions or branch queries") + for name, content in {**sync.files(), "site/data/snapshot.json": json.dumps(doc)}.items(): + path = self.root / name; path.parent.mkdir(parents=True, exist_ok=True); path.write_text(content) + # The next unchanged build reuses the snapshot, without refreshing all test artifacts. + again = Sync(source, self.root, REPO, settings={"workflows": RULES}, now=NOW) + again.meta = sync.meta + with patch("gsb.incremental_project.public_tests") as tests, patch("gsb.incremental_project.collect_ci") as ci: + self.assertEqual(build_snapshot(again), doc) + tests.assert_not_called(); ci.assert_not_called() + def test_renamed_branches_project_historical_runs_into_their_current_lines(self): source = self.source() created = (NOW - timedelta(minutes=1)).isoformat().replace("+00:00", "Z")