Repository navigation
fix(ci): render the queued-acknowledgement comment #8726
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
254b8e8
5d29984
e781f47
aff47ff
ab4af89
798cb71
0259892
9bb5a8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -2274,3 +2274,111 @@ describe('command shape matching', () => { | |||||||||
| expect(stripCr).toBeGreaterThan(firstLine); | ||||||||||
| }); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| describe('bot comment markers', () => { | ||||||||||
| // A line that opens with `<!--` starts an HTML block, and that block runs to | ||||||||||
| // the line holding the closing delimiter INCLUSIVE — the rest of that line | ||||||||||
| // stays inside it and is never parsed as Markdown. The queued-ack comment | ||||||||||
| // glued its prose straight onto the marker and reached every PR as raw | ||||||||||
| // source with a dead link. Measured through GitHub's own renderer | ||||||||||
| // (POST /markdown, mode=gfm): marker+text -> 0 <a>/0 <em>; marker+"\n"+text | ||||||||||
| // and marker+"\n\n"+text -> 1 <a>/1 <em>. | ||||||||||
| // | ||||||||||
| // The rule keys off ONE thing: a marker that opens a string literal, and | ||||||||||
| // what remains inside that literal after it. That is what distinguishes | ||||||||||
| // BUILDING a comment body from merely REFERENCING a marker — `jq | ||||||||||
| // contains("<!-- m -->")` and `printf '<!-- m -->' "$VAR"` leave nothing | ||||||||||
| // after the marker and are fine, while `="<!-- m -->prose"` does not. The | ||||||||||
| // scan is bounded to the marker's physical line: a glued body is by | ||||||||||
| // definition on that line, and searching past it would couple the guard to | ||||||||||
| // unrelated quotes elsewhere in the file — a doc example quoting an unclosed | ||||||||||
| // `--body "<!-- m -->` would break the moment any later line gained a `"`. | ||||||||||
| // | ||||||||||
| // Known gaps, stated rather than papered over: bodies split across printf | ||||||||||
| // arguments (`printf '%s%s' '<!-- m -->' 'prose'`) — detecting them means | ||||||||||
| // modelling which literal is the format string, and every cheap | ||||||||||
| // approximation flagged the legitimate `printf '<!-- m -->' "$VAR"` form; | ||||||||||
| // bodies assembled across statements or files (one `echo` per line into a | ||||||||||
| // `--body-file`); markers at physical line start (heredocs, YAML block | ||||||||||
| // scalars); markers mid-literal that only land at a rendered line start | ||||||||||
| // after `\n` expansion (`printf 'x\n<!-- m -->prose'`); multi-line literals | ||||||||||
| // whose closing quote sits on a later line; and a line-wrapped printf whose | ||||||||||
| // format opens with the marker (the `\n` exemption reads one physical | ||||||||||
| // line). All are latent — no workflow uses these shapes today. | ||||||||||
| const dir = '.github/workflows'; | ||||||||||
| const files = readdirSync(dir).filter((f) => /\.ya?ml$/.test(f)); | ||||||||||
|
|
||||||||||
| it('never glues prose onto a comment marker, in any workflow', () => { | ||||||||||
| expect(files.length).toBeGreaterThan(0); | ||||||||||
| const offenders = []; | ||||||||||
| for (const file of files) { | ||||||||||
| const text = readFileSync(join(dir, file), 'utf8'); | ||||||||||
| // `[^>\n]` and not `[^>]`: a `<!--` inside a nearby comment would | ||||||||||
| // otherwise let one match span lines, swallow the real marker, and get | ||||||||||
| // discarded by the comment skip below — the guard would then pass with | ||||||||||
| // the very regression present. | ||||||||||
| const re = /<!--[^>\n]*-->/g; | ||||||||||
| let m; | ||||||||||
| while ((m = re.exec(text)) !== null) { | ||||||||||
| const lineStart = text.lastIndexOf('\n', m.index) + 1; | ||||||||||
| const prefix = text.slice(lineStart, m.index); | ||||||||||
| // Prose in a YAML or shell comment never reaches a comment body. | ||||||||||
| if (/^\s*#/.test(prefix)) continue; | ||||||||||
| const quote = m.index === lineStart ? null : text[m.index - 1]; | ||||||||||
| // Only a marker that OPENS a string literal can be building a body. | ||||||||||
| if (quote !== "'" && quote !== '"') continue; | ||||||||||
| const rest = text.slice(m.index + m[0].length); | ||||||||||
| const lineEnd = rest.indexOf('\n'); | ||||||||||
| const line = lineEnd === -1 ? rest : rest.slice(0, lineEnd); | ||||||||||
| const end = line.indexOf(quote); | ||||||||||
| // No closing quote on this line means either the marker ends the line | ||||||||||
| // inside a multi-line literal (a real newline separates the body, | ||||||||||
| // which renders) or the quote is prose in a doc example — neither | ||||||||||
| // glues anything ON the marker's line. | ||||||||||
| if (end === -1) continue; | ||||||||||
| let glued = line.slice(0, end); | ||||||||||
| if (glued === '') { | ||||||||||
| // The literal ended at the marker — but an adjacent literal on the | ||||||||||
| // same line concatenates onto it at runtime, and so does an | ||||||||||
| // unquoted `$(…)` (its output is invisible to this scan). | ||||||||||
| const after = line.slice(end + 1); | ||||||||||
| if (after[0] === "'" || after[0] === '"') { | ||||||||||
| const q2 = after[0]; | ||||||||||
| const e2 = after.slice(1).indexOf(q2); | ||||||||||
| glued = e2 === -1 ? '' : after.slice(1, 1 + e2); | ||||||||||
| } else if (after[0] === '$' && after[1] === '(') { | ||||||||||
| glued = after; | ||||||||||
| } | ||||||||||
| } | ||||||||||
| if (glued === '') continue; | ||||||||||
| // The two-character `\n` escape separates only where the shell | ||||||||||
| // expands it: a printf format string or ANSI-C `$'…'` opened at the | ||||||||||
| // END of the prefix — an unrelated printf earlier on the same line | ||||||||||
| // must not bless a plain double-quoted assignment, where `\n` stays | ||||||||||
| // a literal backslash-n and the prose stays on the marker's line. | ||||||||||
| if (glued.startsWith('\\n') && /printf\s+['"]$|\$'$/.test(prefix)) { | ||||||||||
| continue; | ||||||||||
| } | ||||||||||
| offenders.push( | ||||||||||
| `${file}: ${text.slice(m.index, m.index + 56).split('\n')[0]}`, | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| } | ||||||||||
| expect(offenders).toEqual([]); | ||||||||||
| }); | ||||||||||
|
|
||||||||||
| it('pins the workflow-run URL into the ack printf', () => { | ||||||||||
| // bash printf with a leftover argument and no conversion spec exits 0 | ||||||||||
| // under `set -euo pipefail` and emits `[workflow run]()`, so nothing | ||||||||||
| // else catches a dropped `%s` or `"$RUN_URL"` on the ack line. | ||||||||||
| const text = readFileSync(join(dir, 'qwen-code-pr-review.yml'), 'utf8'); | ||||||||||
| const ackLine = text | ||||||||||
| .split('\n') | ||||||||||
| .find( | ||||||||||
| (l) => l.includes('printf') && l.includes('<!-- qwen-review-ack -->'), | ||||||||||
| ); | ||||||||||
| expect(ackLine).toBeDefined(); | ||||||||||
| expect(ackLine).toContain('%s'); | ||||||||||
| expect(ackLine).toContain('"$RUN_URL"'); | ||||||||||
|
Comment on lines
+2400
to
+2402
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The URL-pin test asserts Failure scenario: a future edit rewrites the ack line to
Suggested change
中文说明URL 固定测试只断言 — DeepSeek/deepseek-v4-flash via Qwen Code /review (v0.21.8) |
||||||||||
| }); | ||||||||||
| }); | ||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Suggestion] The new guard pastes the identical workflow-directory scan idiom already present 130 lines above in this file (
describe('workflow expression length')at lines 2178-2179) — two independent enumerations of.github/workflowswith the same\.ya?ml$filter.Failure scenario: any future change to the scan — a new workflow-file extension, excluding a subdirectory, or the dir moving — must be applied in both places; applying it in one silently leaves the two guards scanning different file sets with no failure signal and no way to notice.
中文说明
新守卫把本文件 130 行之前已有的工作流目录扫描惯用法又粘贴了一遍(
workflow expression lengthdescribe 块,2178-2179 行)——两处各自枚举.github/workflows且使用相同的\.ya?ml$过滤。失败场景:将来任何对扫描范围的改动(新增扩展名、排除子目录、目录迁移)都必须在两处同时进行;只改一处会让两个守卫静默扫描不同的文件集合,没有任何失败信号。建议把枚举提升到模块作用域(第 23 行已有的const workflow = readFileSync(...)旁),两个 describe 共用。— DeepSeek/deepseek-v4-flash via Qwen Code /review (v0.21.8)