Skip to content

Commit 323f7bd

Browse files
authored
test: split apply decision tests (#368)
1 parent 1c19987 commit 323f7bd

4 files changed

Lines changed: 1735 additions & 1698 deletions
Lines changed: 317 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,317 @@
1+
import assert from "node:assert/strict";
2+
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3+
import { join } from "node:path";
4+
import test from "node:test";
5+
6+
import {
7+
lowSignalCloseReport,
8+
promotionGhMock,
9+
reportWithSyncedReviewComment,
10+
runApplyDecisionsForTest,
11+
stalePullRequestReport,
12+
tmpPrefix,
13+
withMockGh,
14+
} from "./helpers.ts";
15+
16+
test("apply-decisions does not promote PRs superseded by PRs already proposed for close", () => {
17+
const root = mkdtempSync(tmpPrefix);
18+
try {
19+
const itemsDir = join(root, "items");
20+
const closedDir = join(root, "closed");
21+
const plansDir = join(root, "plans");
22+
const reportPath = join(root, "apply-report.json");
23+
mkdirSync(itemsDir, { recursive: true });
24+
mkdirSync(plansDir, { recursive: true });
25+
const synced = reportWithSyncedReviewComment(
26+
stalePullRequestReport({
27+
number: 337,
28+
title: "Old activity PR",
29+
pr_rating_overall: "D",
30+
pr_rating_proof: "D",
31+
work_cluster_refs: JSON.stringify([
32+
"Superseded by https://github.com/openclaw/openclaw/pull/400",
33+
]),
34+
}),
35+
337,
36+
"none",
37+
);
38+
writeFileSync(join(itemsDir, "337.md"), synced.report, "utf8");
39+
writeFileSync(
40+
join(itemsDir, "400.md"),
41+
lowSignalCloseReport({
42+
number: 400,
43+
title: "Canonical PR proposed for close",
44+
}),
45+
"utf8",
46+
);
47+
48+
withMockGh(
49+
root,
50+
promotionGhMock({
51+
number: 337,
52+
title: "Old activity PR",
53+
comment: synced.comment,
54+
linkedPulls: {
55+
400: {
56+
number: 400,
57+
title: "Canonical PR proposed for close",
58+
html_url: "https://github.com/openclaw/openclaw/pull/400",
59+
state: "open",
60+
merged_at: null,
61+
mergeable_state: "clean",
62+
labels: [],
63+
},
64+
},
65+
}),
66+
() => {
67+
runApplyDecisionsForTest({
68+
itemsDir,
69+
closedDir,
70+
plansDir,
71+
reportPath,
72+
extraArgs: [
73+
"--target-repo",
74+
"openclaw/openclaw",
75+
"--dry-run",
76+
"--apply-kind",
77+
"all",
78+
"--item-numbers",
79+
"337",
80+
"--processed-limit",
81+
"3",
82+
],
83+
});
84+
},
85+
);
86+
87+
const report = JSON.parse(readFileSync(reportPath, "utf8")) as Array<{ action: string }>;
88+
assert.equal(
89+
report.some((entry) => entry.action === "closed"),
90+
false,
91+
);
92+
} finally {
93+
rmSync(root, { recursive: true, force: true });
94+
}
95+
});
96+
97+
test("apply-decisions does not promote PRs superseded by skipped close proposal PRs", () => {
98+
const root = mkdtempSync(tmpPrefix);
99+
try {
100+
const itemsDir = join(root, "items");
101+
const closedDir = join(root, "closed");
102+
const plansDir = join(root, "plans");
103+
const reportPath = join(root, "apply-report.json");
104+
mkdirSync(itemsDir, { recursive: true });
105+
mkdirSync(plansDir, { recursive: true });
106+
const sourceReport = stalePullRequestReport({
107+
number: 339,
108+
title: "Old activity PR",
109+
labels: JSON.stringify([]),
110+
pr_rating_overall: "D",
111+
pr_rating_proof: "D",
112+
pr_rating_patch: "D",
113+
work_cluster_refs: JSON.stringify([
114+
"Superseded by https://github.com/openclaw/openclaw/pull/400",
115+
]),
116+
})
117+
.replace("Status: missing", "Status: sufficient")
118+
.replace(
119+
"Overall tier: F\nProof tier: F\nPatch tier: F",
120+
"Overall tier: D\nProof tier: D\nPatch tier: D",
121+
);
122+
const synced = reportWithSyncedReviewComment(sourceReport, 339, "none");
123+
writeFileSync(join(itemsDir, "339.md"), synced.report, "utf8");
124+
writeFileSync(
125+
join(itemsDir, "400.md"),
126+
lowSignalCloseReport({
127+
number: 400,
128+
title: "Canonical PR blocked from close",
129+
action_taken: "skipped_changed_since_review",
130+
}),
131+
"utf8",
132+
);
133+
134+
withMockGh(
135+
root,
136+
promotionGhMock({
137+
number: 339,
138+
title: "Old activity PR",
139+
comment: synced.comment,
140+
linkedPulls: {
141+
400: {
142+
number: 400,
143+
title: "Canonical PR blocked from close",
144+
html_url: "https://github.com/openclaw/openclaw/pull/400",
145+
state: "open",
146+
merged_at: null,
147+
mergeable_state: "clean",
148+
labels: [],
149+
},
150+
},
151+
}),
152+
() => {
153+
runApplyDecisionsForTest({
154+
itemsDir,
155+
closedDir,
156+
plansDir,
157+
reportPath,
158+
extraArgs: [
159+
"--target-repo",
160+
"openclaw/openclaw",
161+
"--dry-run",
162+
"--apply-kind",
163+
"all",
164+
"--item-numbers",
165+
"339",
166+
"--processed-limit",
167+
"3",
168+
],
169+
});
170+
},
171+
);
172+
173+
const report = JSON.parse(readFileSync(reportPath, "utf8")) as Array<{ action: string }>;
174+
assert.equal(
175+
report.some((entry) => entry.action === "closed"),
176+
false,
177+
);
178+
} finally {
179+
rmSync(root, { recursive: true, force: true });
180+
}
181+
});
182+
183+
test("apply-decisions does not promote unrelated linked open PRs", () => {
184+
const root = mkdtempSync(tmpPrefix);
185+
try {
186+
const itemsDir = join(root, "items");
187+
const closedDir = join(root, "closed");
188+
const plansDir = join(root, "plans");
189+
const reportPath = join(root, "apply-report.json");
190+
mkdirSync(itemsDir, { recursive: true });
191+
mkdirSync(plansDir, { recursive: true });
192+
const synced = reportWithSyncedReviewComment(
193+
stalePullRequestReport({
194+
number: 333,
195+
title: "Related activity PR",
196+
pr_rating_overall: "D",
197+
pr_rating_proof: "D",
198+
work_cluster_refs: JSON.stringify(["https://github.com/openclaw/openclaw/pull/401"]),
199+
}),
200+
333,
201+
"none",
202+
);
203+
writeFileSync(join(itemsDir, "333.md"), synced.report, "utf8");
204+
205+
withMockGh(
206+
root,
207+
promotionGhMock({
208+
number: 333,
209+
title: "Related activity PR",
210+
itemCreatedAt: "2026-05-20T00:00:00Z",
211+
comment: synced.comment,
212+
linkedPulls: {
213+
401: {
214+
number: 401,
215+
title: "Related activity PR",
216+
html_url: "https://github.com/openclaw/openclaw/pull/401",
217+
state: "open",
218+
merged_at: null,
219+
},
220+
},
221+
}),
222+
() => {
223+
runApplyDecisionsForTest({
224+
itemsDir,
225+
closedDir,
226+
plansDir,
227+
reportPath,
228+
extraArgs: [
229+
"--target-repo",
230+
"openclaw/openclaw",
231+
"--dry-run",
232+
"--apply-kind",
233+
"all",
234+
"--processed-limit",
235+
"3",
236+
],
237+
});
238+
},
239+
);
240+
241+
const report = JSON.parse(readFileSync(reportPath, "utf8")) as Array<{ action: string }>;
242+
assert.equal(
243+
report.some((entry) => entry.action === "closed"),
244+
false,
245+
);
246+
} finally {
247+
rmSync(root, { recursive: true, force: true });
248+
}
249+
});
250+
251+
test("apply-decisions does not promote unrelated linked merged PRs", () => {
252+
const root = mkdtempSync(tmpPrefix);
253+
try {
254+
const itemsDir = join(root, "items");
255+
const closedDir = join(root, "closed");
256+
const plansDir = join(root, "plans");
257+
const reportPath = join(root, "apply-report.json");
258+
mkdirSync(itemsDir, { recursive: true });
259+
mkdirSync(plansDir, { recursive: true });
260+
const synced = reportWithSyncedReviewComment(
261+
stalePullRequestReport({
262+
number: 334,
263+
title: "Related merged activity PR",
264+
pr_rating_overall: "D",
265+
pr_rating_proof: "D",
266+
work_cluster_refs: JSON.stringify(["https://github.com/openclaw/openclaw/pull/402"]),
267+
}),
268+
334,
269+
"none",
270+
);
271+
writeFileSync(join(itemsDir, "334.md"), synced.report, "utf8");
272+
273+
withMockGh(
274+
root,
275+
promotionGhMock({
276+
number: 334,
277+
title: "Related merged activity PR",
278+
itemCreatedAt: "2026-05-20T00:00:00Z",
279+
comment: synced.comment,
280+
linkedPulls: {
281+
402: {
282+
number: 402,
283+
title: "Related merged PR",
284+
html_url: "https://github.com/openclaw/openclaw/pull/402",
285+
state: "closed",
286+
merged_at: "2026-05-21T00:00:00Z",
287+
},
288+
},
289+
}),
290+
() => {
291+
runApplyDecisionsForTest({
292+
itemsDir,
293+
closedDir,
294+
plansDir,
295+
reportPath,
296+
extraArgs: [
297+
"--target-repo",
298+
"openclaw/openclaw",
299+
"--dry-run",
300+
"--apply-kind",
301+
"all",
302+
"--processed-limit",
303+
"3",
304+
],
305+
});
306+
},
307+
);
308+
309+
const report = JSON.parse(readFileSync(reportPath, "utf8")) as Array<{ action: string }>;
310+
assert.equal(
311+
report.some((entry) => entry.action === "closed"),
312+
false,
313+
);
314+
} finally {
315+
rmSync(root, { recursive: true, force: true });
316+
}
317+
});

0 commit comments

Comments
 (0)