Skip to content

test(autofix): single-source the infra-signature list from the workflow - #7565

Merged
wenshao merged 7 commits into
mainfrom
ci/autofix-infra-signature-single-source
Jul 23, 2026
Merged

test(autofix): single-source the infra-signature list from the workflow#7565
wenshao merged 7 commits into
mainfrom
ci/autofix-infra-signature-single-source

Conversation

@wenshao

@wenshao wenshao commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

What this PR does

Removes a hand-synced copy: the infra-rerun test re-typed INFRA_FAILURE_SIGNATURES as an inline mirror of the workflow's value. This extracts it from the workflow source instead, so there is exactly one copy and the two can never drift.

Stacked on #7562 (base is ci/autofix-rerun-infra-flake, which introduces INFRA_FAILURE_SIGNATURES). GitHub will retarget this to main when #7562 merges. Review/merge #7562 first.

Why it's needed

INFRA_FAILURE_SIGNATURES lived in two places: the workflow env (production) and an inline literal in the test. Two copies that must be hand-synced can drift — the test can keep passing against a stale list while production changed, or vice versa. The git-transport follow-up on #7562 had to remember to edit both; the next change might not.

The file already solves this for a sibling value: NON_BLOCKING_CHECKS is extracted from the workflow source and reused, so there is nothing to keep in sync. This applies the same idiom to the signature list.

How

The infra test reads the module-level workflow source (already loaded at the top of the file) and pulls the value with workflow.match(/INFRA_FAILURE_SIGNATURES: '([^']*)'/), then feeds that into the extracted bash block — replacing the inline literal. A toContain('lost communication with the server') guard sits right after the extraction: if the env is renamed or the regex breaks, the extraction returns '', and rather than an empty pattern silently matching every annotation line (which would mask the failure), the guard fails the test loudly.

Reviewer Test Plan

How to verify

  1. npx vitest run scripts/tests/qwen-autofix-workflow.test.js -t infrastructure — green; the test now runs against the workflow's own value.
  2. Mutation-verified: renaming the env in the workflow (INFRA_FAILURE_SIGNATURES…_X) makes the extraction return '' and the toContain guard fails the test in ~18ms — proving the test is now coupled to the production value instead of a private copy.
  3. Full suite: 94/94 (one run hits the pre-existing load flakes eligibility recheck / permanent API failures terminal, green on re-run). Prettier clean. Test-only change — no workflow edit, so no bash/actionlint delta.

Evidence (Before & After)

BEFORE  workflow env  : INFRA_FAILURE_SIGNATURES = 'A|B|C'
        test literal   : INFRA_FAILURE_SIGNATURES = 'A|B|C'   (hand-copied)
        change one, forget the other -> test passes against a stale list

AFTER   workflow env  : INFRA_FAILURE_SIGNATURES = 'A|B|C'
        test          : extracts 'A|B|C' from the workflow  -> one copy
        rename/break   : toContain guard fails loudly

Tested on

OS Status
🍏 macOS ✅ tested
🪟 Windows N/A
🐧 Linux ⚠️ CI

Risk & Scope

  • Test-only. No production behaviour changes.
  • The extraction regex assumes the value is a single-quoted, single-line YAML scalar with no embedded single quote — true of every current signature phrase, and prettier/yaml keep it on one line. If a future phrase needs an apostrophe, the value would move to a different YAML style and the regex would need updating (the toContain guard would catch it immediately).
  • Breaking changes / migration notes: none.

Linked Issues

Follow-up to #7562 (which introduced INFRA_FAILURE_SIGNATURES and the two-copy pattern this removes).

中文说明

本 PR 做了什么

去掉一份需手工同步的副本:infra 重跑测试把 INFRA_FAILURE_SIGNATURES 重新誊写为工作流值的内联镜像。本 PR 改为从工作流源提取,于是全局只有一份,二者永不漂移。

Stack 在 #7562 之上(base 为 ci/autofix-rerun-infra-flake,该分支引入了 INFRA_FAILURE_SIGNATURES)。#7562 合并后 GitHub 会自动把本 PR retarget 到 main。请先评审/合并 #7562

为什么需要

INFRA_FAILURE_SIGNATURES 存在两处:工作流 env(生产)与测试里的内联字面量。两份手工同步的副本会漂移 —— 测试可能一直对着陈旧列表通过,而生产已改,反之亦然。#7562 上的 git-transport 跟进就必须记得两处都改;下一次未必。

文件对同类值已有解:NON_BLOCKING_CHECKS从工作流源提取再复用,无需同步。本 PR 把同一惯例用于签名列表。

怎么做

infra 测试读取文件顶部已加载的模块级 workflow 源,用 workflow.match(/INFRA_FAILURE_SIGNATURES: '([^']*)'/) 取值,喂给提取出的 bash 块 —— 替换内联字面量。提取后紧跟一句 toContain('lost communication with the server') 守卫:若 env 被改名或正则失效,提取返回 '',此时空模式会静默匹配每一行 annotation(掩盖失败),而守卫会让测试响亮地变红。

评审验证

  1. npx vitest run ... -t infrastructure —— 绿;测试现在对着工作流自身的值运行。
  2. 变异验证:把工作流里的 env 改名(INFRA_FAILURE_SIGNATURES…_X),提取返回 '',toContain 守卫约 18ms 令测试变红 —— 证明测试已耦合到生产值而非私有副本。
  3. 全量:94/94(一次命中既有 load flake eligibility recheck / permanent API failures terminal,重跑即绿)。prettier clean。纯测试改动,无工作流编辑,无 bash/actionlint 增量。

风险与范围

  • 纯测试改动,不改生产行为。
  • 提取正则假定该值是单引号、单行 YAML 标量且不含单引号 —— 当前所有签名短语均满足,prettier/yaml 也会保持单行。若未来某短语需要撇号,值会转为另一种 YAML 样式、正则需相应更新(toContain 守卫会立即捕获)。
  • 破坏性变更:无。

关联 Issue

#7562 的跟进(该 PR 引入了 INFRA_FAILURE_SIGNATURES 与本 PR 去除的两副本模式)。

wenshao and others added 4 commits July 23, 2026 12:07
A failed check can be red because the machine died, not the code — a
self-hosted runner losing the server, the disk filling. #7490's E2E
failed with "runner lost communication with the server" and went green
on a rerun. The scan now reruns such a check's failed jobs automatically.

Detection is a conservative annotation whitelist (INFRA_FAILURE_SIGNATURES)
— only unambiguous machine failures, never a test-level timeout, which
could be a real regression. The one-shot guard is run_attempt, not a
marker: a run already retried to attempt 2 and still infra-failing is
persistent, so it is left for a human; after a rerun the attempt
increments, so the next scan will not rerun it. Every step is fail-safe
(any API error → no rerun), it runs only when the PR actually has a
failed check, and the gate carries the same review-address carve-out as
the other check selectors so the loop never reruns its own runs.

This is the transient-infra sibling of #7554 (stale-base): that merges
current main when a check is base-inherited; this reruns when a check
died on the runner. Neither touches a check that is a genuine failure.

Note: rerun-failed-jobs needs the PAT to hold `actions: write`.
#6506's checkout died mid-transfer — "fetch-pack: invalid index-pack
output" and "RPC failed; curl 92 ... CANCEL" — which then hung the job
into the 20m limit. That is infra, not the PR (it only touches a doc),
and a re-run made it green. But the infra-signature whitelist did not
cover it, so the auto-rerun did not fire and it waited on a human.

Add `invalid index-pack output` and `RPC failed` — the two canonical
git-transport-death phrases — to INFRA_FAILURE_SIGNATURES. A co-present
job-timeout line does not block the match (one matching line classifies
the run), and a BARE timeout with no transport signature is still left
alone, since it can be a real regression. Both new signatures are pinned
in the test's per-signature loop, plus a case on #6506's real composite
annotation and a bare-timeout-is-not-rerun guard.
The infra-rerun test re-typed INFRA_FAILURE_SIGNATURES as an inline
mirror of the workflow's env value. Two copies that must be hand-synced
can drift — the test could keep passing against a stale list while
production changed, or vice versa. That is exactly the copy the
git-transport follow-up had to remember to update in two places.

Extract the list from the workflow source instead, the same
extract-from-source idiom the file already uses for NON_BLOCKING_CHECKS,
so there is only one copy and drift is impossible. A toContain guard
fails loudly if the env is renamed or the regex breaks, rather than
letting an empty pattern match every line and silently pass.
@qwen-code-ci-bot

qwen-code-ci-bot commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR!

Template looks good ✓

Problem: observed maintenance hazard — INFRA_FAILURE_SIGNATURES lived in two places (workflow env + inline test literal) that had to be hand-synced. The #7562 git-transport follow-up already had to remember to edit both. The file has the exact same extract-from-source idiom for NON_BLOCKING_CHECKS, so this is applying a proven pattern, not theoretical hardening.

Direction: aligned — eliminating a hand-synced copy in test infrastructure is squarely within scope. No CHANGELOG reference needed for a test-only change.

Size: not applicable (no core paths touched; single test file, +10/−2).

Approach: the scope is exactly right — one regex extraction, one guard assertion, one inline-literal replacement. Mirrors the existing NON_BLOCKING_CHECKS pattern at line 346. Nothing to cut.

Moving on to code review. 🔍

中文说明

感谢贡献!

模板完整 ✓

问题:已观测到的维护隐患——INFRA_FAILURE_SIGNATURES 存在两处(工作流 env + 测试内联字面量),需手工同步。#7562 的 git-transport 跟进已经必须记得两处都改。文件对同类值 NON_BLOCKING_CHECKS 已有从源提取的惯例,本 PR 是复用已验证的模式,非理论性加固。

方向:对齐——消除测试基础设施中的手工同步副本完全在范围内。纯测试改动无需 CHANGELOG 引用。

规模:不适用(未触及核心路径;单个测试文件,+10/−2)。

方案:范围恰好——一处正则提取、一处守卫断言、一处内联字面量替换。与第 346 行已有的 NON_BLOCKING_CHECKS 模式一致。无可砍削。

进入代码审查 🔍

Qwen Code · qwen3.8-max-preview

Reviewed at 6aea34ca019723e370d4012795657204b96d5df6 · re-run with @qwen-code /triage

@qwen-code-ci-bot

qwen-code-ci-bot commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Code Review

Independent proposal: given two copies of INFRA_FAILURE_SIGNATURES that can drift, I'd extract the value from the workflow source with a regex — the same idiom the file already uses for NON_BLOCKING_CHECKS (line 346) — add a guard assertion so a broken extraction fails loudly instead of silently matching everything, and replace the inline literal. One extraction, one guard, one replacement.

Comparison with the diff: the PR does exactly this. The regex workflow.match(/INFRA_FAILURE_SIGNATURES: '([^']*)'/)?.[1] ?? '' mirrors the NON_BLOCKING_CHECKS extraction. The toContain('lost communication with the server') guard catches both a renamed env and a broken regex — without it, an empty pattern would match every annotation line and the test would pass vacuously. The comment explaining the empty-pattern risk is warranted (the invariant is genuinely non-obvious). No correctness bugs, no regressions, no convention violations. Nothing to flag.

Testing

Test-only change with no user-visible behavior — the real-scenario test here is running the test suite itself.

Infrastructure test (targeted):

 ✓  scripts  tests/qwen-autofix-workflow.test.js (96 tests | 95 skipped) 318ms
   ✓ qwen-autofix workflow > auto-reruns a check that died on infrastructure, once, guarded by run_attempt  316ms

 Test Files  1 passed (1)
      Tests  1 passed | 95 skipped (96)
   Duration  927ms

Mutation verification (rename INFRA_FAILURE_SIGNATURESINFRA_FAILURE_SIGNATURES_X in the workflow):

 × qwen-autofix workflow > auto-reruns a check that died on infrastructure, once, guarded by run_attempt 40ms
     → expected '' to contain 'lost communication with the server'

 ❯ tests/qwen-autofix-workflow.test.js:423:30
    421|     const INFRA_SIGNATURES =
    422|       workflow.match(/INFRA_FAILURE_SIGNATURES: '([^']*)'/)?.[1] ?? '';
    423|     expect(INFRA_SIGNATURES).toContain('lost communication with the se…
       |                              ^

 Test Files  1 failed (1)
      Tests  1 failed | 95 skipped (96)

Guard fails loudly in ~42ms, as claimed — the test is now coupled to the production value.

Full suite:

 ✓  scripts  tests/qwen-autofix-workflow.test.js (96 tests) 10462ms

 Test Files  1 passed (1)
      Tests  96 passed (96)
   Duration  11.01s

96/96 green. No flakes on this run.

中文说明

代码审查

独立方案: 面对两份可能漂移的 INFRA_FAILURE_SIGNATURES,我会用正则从工作流源提取——与文件第 346 行 NON_BLOCKING_CHECKS 已有的惯例相同——加一句守卫断言使提取失败时响亮报错(否则空模式会静默匹配每一行),再替换内联字面量。一处提取、一处守卫、一处替换。

与 diff 对比: PR 完全如此。正则与 NON_BLOCKING_CHECKS 提取一致。toContain 守卫同时捕获 env 改名和正则失效——没有它,空模式会让测试空转通过。解释空模式风险的注释是必要的(该不变量确实不直观)。无正确性 bug、无回归、无规范违反。无需标记。

测试

纯测试改动,无用户可见行为——真实场景测试即运行测试套件本身。

基础设施测试(定向): 1 通过,95 跳过。

变异验证: 改名后守卫约 42ms 内响亮失败——测试已耦合到生产值。

全量套件: 96/96 全绿。

Qwen Code · qwen3.8-max-preview

Reviewed at 6aea34ca019723e370d4012795657204b96d5df6 · re-run with @qwen-code /triage

@qwen-code-ci-bot

qwen-code-ci-bot commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

Confidence: 5/5 — clean across every stage; would merge without hesitation.

This is exactly the kind of follow-up that keeps test infrastructure honest. The two-copy pattern already bit once during #7562's git-transport edit, and the fix applies the same extract-from-source idiom the file uses for NON_BLOCKING_CHECKS — no new pattern, no new abstraction, just consistency. The toContain guard is the right touch: without it a broken extraction would silently match everything and the test would pass vacuously. Mutation-verified, full suite green (96/96), +10/−2 in one file. Nothing to maintain, nothing to curse in six months.

#7562 has merged and this PR is now based on main — clear to land.

中文说明

置信度:5/5——每个阶段都干净;毫不犹豫可合并。

这正是保持测试基础设施诚实的那种跟进。两副本模式在 #7562 的 git-transport 编辑时已经咬过一次,修复复用了文件对 NON_BLOCKING_CHECKS 已有的从源提取惯例——无新模式、无新抽象,只是一致性。toContain 守卫恰到好处:没有它,提取失效会静默匹配一切、测试空转通过。变异验证通过,全量套件绿(96/96),单文件 +10/−2。六个月后不会骂作者。

#7562 已合并,本 PR 现已基于 main——可以合并。

Qwen Code · qwen3.8-max-preview

Reviewed at 6aea34ca019723e370d4012795657204b96d5df6 · re-run with @qwen-code /triage

@qwen-code-ci-bot qwen-code-ci-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, looks ready to ship. ✅

@qwen-code-ci-bot qwen-code-ci-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found. LGTM! ✅

— qwen3.7-max via Qwen Code /review

qwen-code-ci-bot and others added 3 commits July 23, 2026 06:22
…nature-single-source

The base advanced under #7562's takeover: the bot's "paginate
annotations and filter Autofix runs" commit reflowed the infra test's
run() signature (added crName/wfName) exactly where this branch inserts
the INFRA_SIGNATURES extraction. Union both — keep the extraction +
toContain guard and the new multi-line signature. The mirror →
INFRA_SIGNATURES replacement auto-merged (base left that line
unchanged). Test-only; infra test + mutation green against the new base.
#7562 (this PR's original base) squash-merged into main, which orphaned
the stack: retargeting straight to main would show a misleading diff
re-adding all of #7562. Merge current main in instead so the branch
sits directly on top of it — the PR diff collapses to just this change
(extract INFRA_FAILURE_SIGNATURES instead of mirroring it). Both
conflicts were this change vs main's pre-change state; kept this side.
#7569's bilingual test (also now on main) is preserved. No force-push.
@wenshao
wenshao changed the base branch from ci/autofix-rerun-infra-flake to main July 23, 2026 07:30
@wenshao
wenshao dismissed qwen-code-ci-bot’s stale review July 23, 2026 07:30

The base branch was changed.

@wenshao

wenshao commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator Author

@qwen-code /triage

@qwen-code-ci-bot qwen-code-ci-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, looks ready to ship. ✅

@wenshao wenshao left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Downgraded from Approve to Comment: self-PR; CI still running. Reviewed.

— qwen3.8-max-preview via Qwen Code /review

@qwen-code-ci-bot qwen-code-ci-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed. Not reviewed: 6a (attacker mindset) — the agent returned substantively twice but the automated transcript check reports it never opened its brief file. Not reviewed: Agent 6a: Undirected audit — attacker mindset — never opened its brief (/home/github-runner/actions-runner-test-10/_work/qwen-code/qwen-code/.qwen/tmp/qwen-review-pr-7565-fetch-prompts/6a.brief.md), so it reviewed without the instructions it was launched to follow.

— qwen3.7-max via Qwen Code /review

@wenshao
wenshao added this pull request to the merge queue Jul 23, 2026
Merged via the queue into main with commit 9d02983 Jul 23, 2026
69 checks passed

@gwinthis gwinthis left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: APPROVE (C=0)

Summary

Clean, minimal test-only change (+10/-2) that eliminates a hand-synced copy of INFRA_FAILURE_SIGNATURES by extracting it from the workflow source — the same single-source idiom already used for NON_BLOCKING_CHECKS in this file.

Findings

None blocking. The change is well-structured:

  1. Extraction regex (/INFRA_FAILURE_SIGNATURES: '([^']*)'/) is appropriate for the single-quoted, single-line YAML scalar format. Prettier/YAML keeps it on one line.
  2. toContain guard fails loudly if the env is renamed or regex breaks — preventing the empty-pattern-silently-matches-everything failure mode.
  3. Follows established patternNON_BLOCKING_CHECKS already uses this exact extract-from-source idiom in the same file.
  4. Mutation-verified per the PR description — renaming the env makes the guard fail in ~18ms.

Engineering Pattern

Single-source of truth for test fixtures: When a test needs a value that exists in production config, extract it from the source rather than re-typing it. Add a guard assertion that fails loudly if extraction breaks. This prevents the "test passes against stale copy" drift bug.

Verification

  • Test-only change, no production behavior modified
  • Stacked on #7562 (merge that first)
中文说明

评审:APPROVE (C=0)

概要

干净、最小化的纯测试改动(+10/-2),通过从工作流源提取 INFRA_FAILURE_SIGNATURES 来消除手工同步的副本——与文件中 NON_BLOCKING_CHECKS 已使用的 single-source 惯例一致。

发现

无阻断项。 改动结构良好:

  1. 提取正则 适用于单引号、单行 YAML 标量格式
  2. toContain 守卫 在 env 改名或正则失效时响亮报错
  3. 遵循既有模式NON_BLOCKING_CHECKS 已在同文件使用完全相同的惯例
  4. 变异验证 — 改名后守卫约 18ms 令测试变红

工程模式

测试 fixture 的单一事实来源: 当测试需要生产配置中的值时,从源提取而非重新誊写。添加守卫断言在提取失败时响亮报错。

— qwen3.7-max via Qwen Code /review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants