diff --git a/.github/scripts/issue-version-triage.cjs b/.github/scripts/issue-version-triage.cjs index 1f88c4e3c5..098c0a27ae 100644 --- a/.github/scripts/issue-version-triage.cjs +++ b/.github/scripts/issue-version-triage.cjs @@ -118,29 +118,40 @@ function firstFieldValue(lines) { return value ? value.text.trim() : ""; } -function extractSectionValue(body, heading, followingHeadings = [], report = parseReportMarkdown(body)) { - if (!body) return null; +function extractSectionValues(body, heading, followingHeadings = [], report = parseReportMarkdown(body)) { + if (!body) return []; const lines = report.lines; const pattern = new RegExp(`^${escapeRegExp(heading)}$`, "i"); - const start = lines.findIndex((line) => line.heading !== null && pattern.test(line.heading)); - if (start === -1) return null; const boundary = followingHeadings.length - ? new RegExp(`^(?:${followingHeadings.map(escapeRegExp).join("|")})$`, "i") : null; - let end = start + 1; - while (end < lines.length && !(lines[end].heading !== null && - (!boundary || (lines[end].headingDepth <= lines[start].headingDepth && - boundary.test(lines[end].heading))))) { - end += 1; + ? new RegExp(`^(?:${[heading, ...followingHeadings].map(escapeRegExp).join("|")})$`, "i") : null; + const values = []; + for (let start = 0; start < lines.length; start += 1) { + if (lines[start].heading === null || !pattern.test(lines[start].heading)) continue; + let end = start + 1; + while (end < lines.length && !(lines[end].heading !== null && + (!boundary || (lines[end].headingDepth <= lines[start].headingDepth && + boundary.test(lines[end].heading))))) { + end += 1; + } + values.push(lines.slice(start + 1, end).map((line) => line.text).join("\n").trim()); + // A deeper, form-named subheading is part of this value, not another + // declaration. Only resume at the boundary that ended the field. + start = end - 1; } - // An empty declared field differs from a legacy report with no field. - return lines.slice(start + 1, end).map((line) => line.text).join("\n").trim(); + return values; } -function additionalActionableTopicsValue(body, report = parseReportMarkdown(body)) { +function extractSectionValue(body, heading, followingHeadings = [], report = parseReportMarkdown(body)) { + const values = extractSectionValues(body, heading, followingHeadings, report); + // An empty declared field differs from a legacy report with no field. + return values.length ? values[0] : null; +} + +function additionalActionableTopicDeclarations(body, report = parseReportMarkdown(body)) { // Edited reports can move this field beside any other form field. Context // from those fields must not invent a topic or reopen a completed review. // Deeper subheadings still belong to the topic, even with a familiar name. - return extractSectionValue(body, "Additional actionable topics", [ + const values = extractSectionValues(body, "Additional actionable topics", [ "Describe the bug", "Steps or original sequence", "Expected behavior", @@ -167,12 +178,21 @@ function additionalActionableTopicsValue(body, report = parseReportMarkdown(body "Desired outcome", "Alternatives considered", ], report); + if (!values.length) return null; + // A reporter may append a second field rather than replace the first. + // Assess each independently: neither an earlier None nor a later empty + // field can erase a task. Empty/identical copies and field order alone do + // not create a new task after Community has completed its review. + return [...new Set(values.filter((value) => isActionableTopicValue(value, report)) + .map((value) => value.replace(/\s+/g, " ").trim()))].sort(); } function classifyAdditionalActionableTopics(body, report = parseReportMarkdown(body)) { - const value = additionalActionableTopicsValue(body, report); - if (value === null) return null; + const declarations = additionalActionableTopicDeclarations(body, report); + return declarations === null ? null : declarations.length > 0; +} +function isActionableTopicValue(value, report) { // Ordinary inline formatting does not turn "None" into a second topic. // Keep block evidence, images and any qualifying text intact for review; // only a single paragraph can supply an explicit no-topic response. @@ -413,8 +433,9 @@ function buildTriageState(issue, core, latestVersion) { nextLabels.add(v6FeedbackClass); } - const additionalTopicsValue = additionalActionableTopicsValue(issue.body, report); - const hasAdditionalActionableTopics = classifyAdditionalActionableTopics(issue.body, report); + const additionalTopicDeclarations = additionalActionableTopicDeclarations(issue.body, report); + const hasAdditionalActionableTopics = additionalTopicDeclarations === null + ? null : additionalTopicDeclarations.length > 0; const reportedVersion = extractPulseVersion(issue.title, issue.body, report); core.info(`Reported Pulse version: ${reportedVersion || "not found"}`); @@ -426,7 +447,7 @@ function buildTriageState(issue, core, latestVersion) { reportedVersion, v6FeedbackClass, hasAdditionalActionableTopics, - additionalTopicsValue, + additionalTopicDeclarations, isBugLike: nextLabels.has(BUG_LABEL), comparison: reportedVersion && latestVersion ? compareCore(reportedVersion, latestVersion) : null, @@ -581,7 +602,7 @@ async function syncLabels({ github, context, core }) { nextLabels, reportedVersion, hasAdditionalActionableTopics, - additionalTopicsValue, + additionalTopicDeclarations, isBugLike, } = buildTriageState(issue, core, null); @@ -589,14 +610,14 @@ async function syncLabels({ github, context, core }) { // empty field cannot prove that comment topics were dispositioned, and an // unrelated or superseded event must not restore a label Community cleared. const previousBody = context.payload.changes?.body?.from; - const topicText = (value) => (value || "").replace(/\s+/g, " ").trim(); const eventIsCurrent = typeof issue.updated_at === "string" && issue.body === eventIssue.body && issue.updated_at === eventIssue.updated_at; const declarationChanged = hasAdditionalActionableTopics === true && ( context.payload.action === "opened" || (context.payload.action === "edited" && previousBody !== undefined && - topicText(additionalActionableTopicsValue(previousBody)) !== topicText(additionalTopicsValue)) + JSON.stringify(additionalActionableTopicDeclarations(previousBody) || []) !== + JSON.stringify(additionalTopicDeclarations)) ); const newlyDeclared = declarationChanged && !nextLabels.has(NEEDS_DECOMPOSITION_LABEL) && ( eventIsCurrent || await declarationSurvivesLaterComments(github, context, issue, eventIssue) diff --git a/.github/scripts/issue-version-triage.test.cjs b/.github/scripts/issue-version-triage.test.cjs index 106af75c96..377e9656fb 100644 --- a/.github/scripts/issue-version-triage.test.cjs +++ b/.github/scripts/issue-version-triage.test.cjs @@ -710,6 +710,122 @@ test("topic classification stops at form fields but retains topic subheadings", } }); +test("every repeated topic field is assessed without inventing topics from empty copies", () => { + const { classifyAdditionalActionableTopics } = triage.internals; + for (const newline of ["\n", "\r\n"]) { + for (const separator of ["", "### Pulse version\n6.6.0\n\n", + "## Logs, screenshots, or diagnostics\nExisting context only.\n\n"]) { + for (const [first, second, expected] of [ + ["None", "A separate backup identity problem.", true], + ["A separate backup identity problem.", "None", true], + ["None", "_No response_", false], + ["", "[None][empty]", false], + ["", "", false], + ]) { + const body = `### Additional actionable topics\n${first}\n\n${separator}` + + `### **[Additional actionable topics][field]**\n${second}\n\n` + + "### Confirmations\nExisting context only.\n\n" + + "[empty]: https://example.invalid/another-problem\n" + + "[field]: https://example.invalid/another-problem\n"; + assert.equal(classifyAdditionalActionableTopics(body.replaceAll("\n", newline)), expected, body); + } + } + } +}); + +test("opened intake retains a later topic field and preserves unrelated Community labels", async () => { + const { github, calls } = createGithub(); + const issue = { number: 2933, title: "Backup posture", labels: ["bug", "needs-human", + "needs-retest-on-latest", "operator-reviewed"].map(name => ({ name })), + body: "### Additional actionable topics\nNone\n\n### Pulse version\n6.6.0\n\n" + + "### Additional actionable topics\nBackup destination identity is also wrong.\n" }; + await syncLabels({ github, context: createContext({ issue }), core: createCore() }); + assert.deepEqual(calls.addLabels.map(call => call.labels), [["affects-6.6.0", "needs-decomposition"]]); + assert.deepEqual(calls.removeLabel, []); + assert.deepEqual(calls.createComment, []); + assert.deepEqual(calls.getLatestRelease, []); + assert.deepEqual(calls.paginate, []); +}); + +test("a revised later topic field creates a new review after the earlier disposition", async () => { + const first = "### Additional actionable topics\nAn earlier storage topic.\n\n" + + "### Pulse version\n6.6.0\n\n"; + for (const previous of ["", "### Additional actionable topics\nNone\n", + "### Additional actionable topics\nA previously reviewed second topic.\n"]) { + const { github, calls } = createGithub(); + const issue = { number: 2934, title: "Reviewed feedback", labels: [{ name: "enhancement" }], + body: first + "### Additional actionable topics\nAnother independent workflow problem.\n" }; + await syncLabels({ github, core: createCore(), context: createContext({ + action: "edited", issue, previousBody: first + previous, + }) }); + assert.deepEqual(calls.addLabels.map(call => call.labels), [["needs-decomposition"]], previous); + assert.deepEqual(calls.removeLabel, []); + assert.deepEqual(calls.createComment, []); + assert.deepEqual(calls.getLatestRelease, []); + assert.deepEqual(calls.paginate, []); + } +}); + +test("empty duplicates, identical copies and reordered fields cannot restore a completed review", async () => { + const field = value => `### Additional actionable topics\n${value}\n\n`; + const boundary = "### Pulse version\n6.6.0\n\n"; + const prior = field("A storage problem.") + boundary + field("A navigation problem."); + const candidates = [ + prior + boundary + field("None"), + prior + field(""), + field("None") + boundary + prior, + prior + boundary + field("A storage problem."), + field("A navigation problem.") + boundary + field("A storage problem."), + field("A storage\nproblem.") + boundary + field("A navigation problem."), + ]; + for (const body of candidates) { + const { github, calls } = createGithub(); + const issue = { number: 2935, title: "Reviewed feedback", body, + labels: ["enhancement", "needs-human", "operator-reviewed"].map(name => ({ name })) }; + await syncLabels({ github, core: createCore(), context: createContext({ + action: "edited", issue, previousBody: prior, + }) }); + assert.deepEqual(calls.addLabels, [], body); + assert.deepEqual(calls.removeLabel, [], body); + assert.deepEqual(calls.createLabel, [], body); + assert.deepEqual(calls.createComment, [], body); + assert.deepEqual(calls.getLatestRelease, [], body); + assert.deepEqual(calls.paginate, [], body); + } +}); + +test("repeated empty topic fields cannot close an existing comment-topic review", async () => { + for (const action of ["opened", "edited", "reopened"]) { + const { github, calls } = createGithub(); + const body = "### Additional actionable topics\nNone\n\n" + + "### Pulse version\n6.6.0\n\n### Additional actionable topics\n_No response_\n"; + const issue = { number: 2936, title: "Existing feedback", body, + labels: ["enhancement", "needs-decomposition"].map(name => ({ name })) }; + await syncLabels({ github, core: createCore(), context: createContext({ action, issue, + previousBody: "### Additional actionable topics\nAn existing topic.\n", + }) }); + assert.deepEqual(calls.addLabels, []); + assert.deepEqual(calls.removeLabel, []); + assert.deepEqual(calls.createLabel, []); + assert.deepEqual(calls.createComment, []); + } +}); + +test("copied topic headings outside genuine fields cannot become later declarations", () => { + for (const copy of [ + "```markdown\n### Additional actionable topics\nAnother problem.\n```", + "> ### Additional actionable topics\n> Another problem.", + "
\n### Additional actionable topics\nAnother problem.\n", + "", + "- Copied template\n\n ### Additional actionable topics\n Another problem.", + ]) { + assert.equal(triage.internals.classifyAdditionalActionableTopics(copy), null, copy); + assert.equal(triage.internals.classifyAdditionalActionableTopics( + "### Additional actionable topics\nNone\n\n### Additional context\n" + copy + ), false, copy); + } +}); + function topicBoundaryFields() { const fields = new Set(["Additional context"]); const directory = path.resolve(__dirname, "../ISSUE_TEMPLATE");