返回 DeepSeek-Reasonix
release-verify-issues.test.mjs
根目录 / scripts / release-verify-issues.test.mjs
1 import assert from "node:assert/strict";
2 import { test } from "node:test";
3 import {
4 parseIssueRefs,
5 parsePullRequestNumbers,
6 previousTag,
7 renderComment,
8 isNotifiable,
9 selectTargets,
10 tagSeries,
11 verificationMarker,
12 } from "./release-verify-issues.mjs";
13
14 test("upstream references are not mistaken for our issue numbers", () => {
15 const body = "Follows wailsapp/wails#5544 and ScoopInstaller/Extras#18363. Refs #3470, fixes (#4092).";
16 assert.deepEqual([...parseIssueRefs(body)].sort((a, b) => a - b), [3470, 4092]);
17 });
18
19 test("issue refs survive the punctuation PR bodies actually use", () => {
20 const refs = parseIssueRefs("Addresses #6607 (also the mechanism behind #6346 / #5760).\n- #6225\nRelated: #6259, #6333");
21 assert.deepEqual([...refs].sort((a, b) => a - b), [5760, 6225, 6259, 6333, 6346, 6607]);
22 });
23
24 test("pull request numbers come from both merge and squash subjects", () => {
25 const log = [
26 "Merge pull request #7053 from esengine/fix/cli-colour-profile",
27 "fix(cli): resolve colour support from colorprofile",
28 "polish(desktop): tighten spacing (#7019)",
29 ].join("\n");
30 assert.deepEqual(parsePullRequestNumbers(log), [7019, 7053]);
31 });
32
33 test("a release only follows its own tag series", () => {
34 const tags = ["desktop-v1.18.0", "npm-v1.18.0", "v1.18.0", "desktop-v1.17.21", "npm-v1.17.21", "v1.17.21"];
35 assert.equal(previousTag(tags, "desktop-v1.18.0"), "desktop-v1.17.21");
36 assert.equal(previousTag(tags, "npm-v1.18.0"), "npm-v1.17.21");
37 assert.equal(previousTag(tags, "v1.18.0"), "v1.17.21");
38 assert.equal(tagSeries("desktop-v1.18.0"), "desktop-");
39 assert.equal(tagSeries("v1.18.0"), "");
40 });
41
42 test("the oldest tag in a series has nothing to compare against", () => {
43 assert.equal(previousTag(["desktop-v1.0.0"], "desktop-v1.0.0"), null);
44 assert.equal(previousTag(["desktop-v1.0.0"], "desktop-v9.9.9"), null);
45 });
46
47 test("a referenced pull request is never treated as a reportable issue", () => {
48 const tag = "desktop-v1.18.0";
49 // GitHub's issues API answers for pull requests too, so this is the only
50 // thing separating a consolidation PR's "PR #5576 by @x" from a real report.
51 assert.equal(isNotifiable({ state: "open", isPullRequest: true, commentBodies: [] }, tag), false);
52 assert.equal(isNotifiable({ state: "open", isPullRequest: false, commentBodies: [] }, tag), true);
53 });
54
55 test("closed and already-notified issues are skipped", () => {
56 const tag = "desktop-v1.18.0";
57 assert.equal(isNotifiable({ state: "closed", isPullRequest: false, commentBodies: [] }, tag), false);
58 assert.equal(
59 isNotifiable({ state: "open", isPullRequest: false, commentBodies: [`x ${verificationMarker(tag)} y`] }, tag),
60 false,
61 );
62 // a marker from a different release must not suppress this one
63 assert.equal(
64 isNotifiable({ state: "open", isPullRequest: false, commentBodies: [verificationMarker("desktop-v1.17.21")] }, tag),
65 true,
66 );
67 });
68
69 test("selectTargets keeps only notifiable issues, sorted, with their source PRs", () => {
70 const tag = "desktop-v1.18.0";
71 const refsByIssue = new Map([
72 [300, new Set([30])],
73 [100, new Set([10])],
74 [200, new Set([21, 20])],
75 ]);
76 const records = new Map([
77 [100, { state: "open", isPullRequest: false, commentBodies: [verificationMarker(tag)] }],
78 [200, { state: "open", isPullRequest: false, commentBodies: [] }],
79 [300, { state: "open", isPullRequest: true, commentBodies: [] }],
80 ]);
81 assert.deepEqual(selectTargets({ refsByIssue, records, tag }), [{ issue: 200, pullNumbers: [20, 21] }]);
82 });
83
84 test("the comment carries a per-tag marker that the skip check matches", () => {
85 const body = renderComment({ tag: "desktop-v1.18.0", pullNumbers: [7019] });
86 assert.ok(body.includes(verificationMarker("desktop-v1.18.0")));
87 assert.ok(!body.includes(verificationMarker("desktop-v1.17.21")));
88 assert.match(body, /#7019 is in that release/);
89 });
90
91 test("the comment asks for verification and never claims the issue is fixed", () => {
92 const body = renderComment({ tag: "desktop-v1.18.0", pullNumbers: [1, 2] });
93 assert.match(body, /#1, #2 are in that release/);
94 assert.match(body, /request to verify rather than a fix announcement/);
95 assert.doesNotMatch(body, /\bclosing\b|\bfixed in\b/i);
96 });
97
97 lines Plain Text