-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfeatures.test.ts
More file actions
395 lines (326 loc) · 19.1 KB
/
Copy pathfeatures.test.ts
File metadata and controls
395 lines (326 loc) · 19.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
import { test } from "node:test";
import assert from "node:assert/strict";
import {
FakeClient,
makeConfig,
makeCtx,
makeGraph,
makeItem,
statusField,
statusValue,
priorityField,
priorityValue,
numberField,
iterationField,
iterationValue,
estimateValue,
} from "./helpers.js";
import { runRollover } from "../src/features/rollover.js";
import { runSprintStart } from "../src/features/sprintStart.js";
import { runAutoAssign } from "../src/features/autoAssign.js";
import { runSprintRunway } from "../src/features/sprintRunway.js";
import { runStaleNudge } from "../src/features/staleNudge.js";
import { runSubIssueGate } from "../src/features/subIssueGate.js";
import { runPrioritySort } from "../src/features/prioritySort.js";
import { runDigest } from "../src/features/digest.js";
test("rollover moves unfinished items from the completed iteration into the active one", async () => {
const cfg = makeConfig({ features: { rollover: { enabled: true } } });
const fields = [statusField(["Todo", "In Progress", "Done"]), iterationField([{ id: "it2", title: "Sprint 2" }], [{ id: "it1", title: "Sprint 1" }])];
const toMove = makeItem([statusValue("In Progress", "2026-07-01T00:00:00Z"), iterationValue("it1", "Sprint 1")], { number: 1 });
const doneItem = makeItem([statusValue("Done", "2026-07-01T00:00:00Z"), iterationValue("it1", "Sprint 1")], { number: 2 });
const nextSprint = makeItem([statusValue("Todo", "2026-07-01T00:00:00Z"), iterationValue("it2", "Sprint 2")], { number: 3 });
const client = new FakeClient();
await runRollover(makeCtx(makeGraph(fields, [toMove, doneItem, nextSprint]), cfg, client));
assert.deepEqual(client.iterations, [{ itemId: toMove.id, iterationId: "it2" }]);
});
test("rollover in dry-run records intent but mutates nothing", async () => {
const cfg = makeConfig({ features: { rollover: { enabled: true } } });
const fields = [statusField(["Todo", "Done"]), iterationField([{ id: "it2", title: "S2" }], [{ id: "it1", title: "S1" }])];
const item = makeItem([statusValue("Todo", "2026-07-01T00:00:00Z"), iterationValue("it1", "S1")], { number: 1 });
const client = new FakeClient();
const ctx = makeCtx(makeGraph(fields, [item]), cfg, client, true);
await runRollover(ctx);
assert.equal(client.iterations.length, 0);
assert.equal(ctx.audit.count, 1);
});
test("rollover adds the new sprint label, creating it once per repo, and skips items already labelled", async () => {
const cfg = makeConfig({ features: { rollover: { enabled: true, addSprintLabel: true, sprintLabelColor: "772fd1" } } });
const fields = [statusField(["Todo", "Done"]), iterationField([{ id: "it2", title: "2026-S06" }], [{ id: "it1", title: "2026-S05" }])];
const needsLabel = makeItem([statusValue("Todo", "2026-07-01T00:00:00Z"), iterationValue("it1", "2026-S05")], { number: 1 });
const alreadyLabelled = makeItem([statusValue("Todo", "2026-07-01T00:00:00Z"), iterationValue("it1", "2026-S05")], { number: 2, labels: ["2026-S06"] });
const client = new FakeClient();
await runRollover(makeCtx(makeGraph(fields, [needsLabel, alreadyLabelled]), cfg, client));
// Both items move iterations...
assert.equal(client.iterations.length, 2);
// ...but only the unlabelled one gets the label, and the label is created once.
assert.deepEqual(client.ensuredLabels, [{ name: "2026-S06", color: "772fd1" }]);
assert.deepEqual(client.labelsAdded, [{ number: 1, labels: ["2026-S06"] }]);
});
test("rollover label add in dry-run records intent but creates/adds nothing", async () => {
const cfg = makeConfig({ features: { rollover: { enabled: true, addSprintLabel: true } } });
const fields = [statusField(["Todo", "Done"]), iterationField([{ id: "it2", title: "S6" }], [{ id: "it1", title: "S5" }])];
const item = makeItem([statusValue("Todo", "2026-07-01T00:00:00Z"), iterationValue("it1", "S5")], { number: 1 });
const client = new FakeClient();
const ctx = makeCtx(makeGraph(fields, [item]), cfg, client, true);
await runRollover(ctx);
assert.equal(client.ensuredLabels.length, 0);
assert.equal(client.labelsAdded.length, 0);
// one move-iteration record + one add-label record
assert.equal(ctx.audit.count, 2);
});
test("rollover strips pulled-in label variants (case/hyphen/space insensitive), keeps other labels", async () => {
const cfg = makeConfig({ features: { rollover: { enabled: true, removeLabels: ["pulled-in", "pull-in"] } } });
const fields = [statusField(["Todo", "Done"]), iterationField([{ id: "it2", title: "S6" }], [{ id: "it1", title: "S5" }])];
// Each rolled card carries a differently-spelled pulled-in label plus one to keep.
const a = makeItem([statusValue("Todo", "2026-07-01T00:00:00Z"), iterationValue("it1", "S5")], { number: 1, labels: ["Pulled In", "keep"] });
const b = makeItem([statusValue("Todo", "2026-07-01T00:00:00Z"), iterationValue("it1", "S5")], { number: 2, labels: ["pulled-in"] });
const c = makeItem([statusValue("Todo", "2026-07-01T00:00:00Z"), iterationValue("it1", "S5")], { number: 3, labels: ["pull in"] });
const d = makeItem([statusValue("Todo", "2026-07-01T00:00:00Z"), iterationValue("it1", "S5")], { number: 4, labels: ["PULL_IN"] });
const client = new FakeClient();
await runRollover(makeCtx(makeGraph(fields, [a, b, c, d]), cfg, client));
// The actual (original-cased) label name is removed; "keep" is left alone.
assert.deepEqual(client.labelsRemoved, [
{ number: 1, name: "Pulled In" },
{ number: 2, name: "pulled-in" },
{ number: 3, name: "pull in" },
{ number: 4, name: "PULL_IN" },
]);
});
test("sprint-start promotes cards parked before the sprint started, skipping mid-sprint moves and non-backlog", async () => {
const cfg = makeConfig({ features: { sprintStart: { enabled: true, fromStatuses: ["Backlog"], toStatus: "Ready" } } });
// Helper's iterationField start date is 2026-06-01, before NOW (2026-07-09) → the sprint has started.
const fields = [statusField(["Backlog", "Ready", "Done"]), iterationField([{ id: "it1", title: "2026-S08" }], [])];
const parked = makeItem([statusValue("Backlog", "2026-05-01T00:00:00Z"), iterationValue("it1", "2026-S08")], { number: 1 });
const movedBack = makeItem([statusValue("Backlog", "2026-07-01T00:00:00Z"), iterationValue("it1", "2026-S08")], { number: 2 });
const alreadyReady = makeItem([statusValue("Ready", "2026-05-01T00:00:00Z"), iterationValue("it1", "2026-S08")], { number: 3 });
const client = new FakeClient();
await runSprintStart(makeCtx(makeGraph(fields, [parked, movedBack, alreadyReady]), cfg, client));
assert.deepEqual(client.singleSelects, [{ itemId: parked.id, optionId: "opt-Ready" }]);
});
test("sprint-start does nothing until the iteration has actually started", async () => {
const cfg = makeConfig({ features: { sprintStart: { enabled: true } } });
const futureSprint: import("../src/types.js").ProjectField = {
id: "F_sprint", name: "Sprint", dataType: "ITERATION",
iterations: [{ id: "it1", title: "2026-S09", startDate: "2026-08-01", duration: 14 }],
completedIterations: [],
};
const fields = [statusField(["Backlog", "Ready"]), futureSprint];
const parked = makeItem([statusValue("Backlog", "2026-05-01T00:00:00Z"), iterationValue("it1", "2026-S09")], { number: 1 });
const client = new FakeClient();
await runSprintStart(makeCtx(makeGraph(fields, [parked]), cfg, client));
assert.equal(client.singleSelects.length, 0);
});
test("sprint-start in dry-run records intent but mutates nothing", async () => {
const cfg = makeConfig({ features: { sprintStart: { enabled: true } } });
const fields = [statusField(["Backlog", "Ready", "Done"]), iterationField([{ id: "it1", title: "2026-S08" }], [])];
const parked = makeItem([statusValue("Backlog", "2026-05-01T00:00:00Z"), iterationValue("it1", "2026-S08")], { number: 1 });
const client = new FakeClient();
const ctx = makeCtx(makeGraph(fields, [parked]), cfg, client, true);
await runSprintStart(ctx);
assert.equal(client.singleSelects.length, 0);
assert.equal(ctx.audit.count, 1);
});
test("auto-assign maps labels to owners, unions multiple matches, and skips assigned/non-Ready/unmapped", async () => {
const cfg = makeConfig({
features: {
autoAssign: {
enabled: true,
onlyStatuses: ["Ready"],
rules: [
{ label: "UI", assignees: ["zach"] },
{ label: "security", assignees: ["rajan"] },
],
},
},
});
const fields = [statusField(["Ready", "Backlog", "Done"])];
const ui = makeItem([statusValue("Ready", "2026-07-09T00:00:00Z")], { number: 1, labels: ["UI"] });
const both = makeItem([statusValue("Ready", "2026-07-09T00:00:00Z")], { number: 2, labels: ["UI", "security"] });
const alreadyOwned = makeItem([statusValue("Ready", "2026-07-09T00:00:00Z")], { number: 3, labels: ["UI"], assignees: ["someone"] });
const notReady = makeItem([statusValue("Backlog", "2026-07-09T00:00:00Z")], { number: 4, labels: ["UI"] });
const unmapped = makeItem([statusValue("Ready", "2026-07-09T00:00:00Z")], { number: 5, labels: ["docs"] });
const client = new FakeClient();
await runAutoAssign(makeCtx(makeGraph(fields, [ui, both, alreadyOwned, notReady, unmapped]), cfg, client));
assert.deepEqual(client.assigneesAdded, [
{ number: 1, assignees: ["zach"] },
{ number: 2, assignees: ["zach", "rajan"] },
]);
});
test("auto-assign matches labels case-insensitively (rule casing vs board casing)", async () => {
const cfg = makeConfig({
features: { autoAssign: { enabled: true, onlyStatuses: ["Ready"], rules: [{ label: "uI", assignees: ["zach"] }] } },
});
const fields = [statusField(["Ready"])];
// Rule says "uI"; board labels use assorted casings — all must match.
const a = makeItem([statusValue("Ready", "2026-07-09T00:00:00Z")], { number: 1, labels: ["UI"] });
const b = makeItem([statusValue("Ready", "2026-07-09T00:00:00Z")], { number: 2, labels: ["ui"] });
const c = makeItem([statusValue("Ready", "2026-07-09T00:00:00Z")], { number: 3, labels: ["Ui"] });
const client = new FakeClient();
await runAutoAssign(makeCtx(makeGraph(fields, [a, b, c]), cfg, client));
assert.deepEqual(client.assigneesAdded, [
{ number: 1, assignees: ["zach"] },
{ number: 2, assignees: ["zach"] },
{ number: 3, assignees: ["zach"] },
]);
});
test("auto-assign in dry-run records intent but assigns nobody", async () => {
const cfg = makeConfig({
features: { autoAssign: { enabled: true, onlyStatuses: ["Ready"], rules: [{ label: "UI", assignees: ["zach"] }] } },
});
const item = makeItem([statusValue("Ready", "2026-07-09T00:00:00Z")], { number: 1, labels: ["UI"] });
const client = new FakeClient();
const ctx = makeCtx(makeGraph([statusField(["Ready"])], [item]), cfg, client, true);
await runAutoAssign(ctx);
assert.equal(client.assigneesAdded.length, 0);
assert.equal(ctx.audit.count, 1);
});
test("sprint-runway warns when no future iteration is planned beyond the current one", async () => {
const cfg = makeConfig({ features: { sprintRunway: { enabled: true, minFuture: 1 } } });
// Helper iterations start 2026-06-01 (before NOW) → current only, zero future planned.
const fields = [iterationField([{ id: "it1", title: "2026-S08" }], [])];
const client = new FakeClient();
const ctx = makeCtx(makeGraph(fields, []), cfg, client);
await runSprintRunway(ctx);
assert.equal(ctx.audit.count, 1);
});
test("sprint-runway stays quiet when enough future iterations are planned", async () => {
const cfg = makeConfig({ features: { sprintRunway: { enabled: true, minFuture: 1 } } });
const field: import("../src/types.js").ProjectField = {
id: "F_sprint", name: "Sprint", dataType: "ITERATION",
iterations: [
{ id: "it1", title: "2026-S08", startDate: "2026-06-01", duration: 14 }, // current
{ id: "it2", title: "2026-S09", startDate: "2026-08-01", duration: 14 }, // future
],
completedIterations: [],
};
const ctx = makeCtx(makeGraph([field], []), cfg, new FakeClient());
await runSprintRunway(ctx);
assert.equal(ctx.audit.count, 0);
});
test("stale-nudge comments and @-mentions assignees past the threshold", async () => {
const cfg = makeConfig({
features: { staleNudge: { enabled: true, rules: [{ status: "In Progress", days: 3, notify: "assignees" }] } },
});
const stale = makeItem([statusValue("In Progress", "2026-07-01T00:00:00Z")], { number: 5, assignees: ["alice"] });
const fresh = makeItem([statusValue("In Progress", "2026-07-08T12:00:00Z")], { number: 6, assignees: ["bob"] });
const client = new FakeClient().withComments([]);
await runStaleNudge(makeCtx(makeGraph([statusField(["In Progress"])], [stale, fresh]), cfg, client));
assert.equal(client.comments.length, 1);
assert.equal(client.comments[0].number, 5);
assert.match(client.comments[0].body, /@alice/);
});
test("stale-nudge 'reviewers' token @-mentions the card's pending reviewers", async () => {
const cfg = makeConfig({
features: { staleNudge: { enabled: true, rules: [{ status: "In Review", days: 2, notify: "reviewers" }] } },
});
const stale = makeItem([statusValue("In Review", "2026-07-01T00:00:00Z")], {
number: 9,
assignees: ["alice"],
reviewers: ["carol", "acme/platform"],
});
const client = new FakeClient().withComments([]);
await runStaleNudge(makeCtx(makeGraph([statusField(["In Review"])], [stale]), cfg, client));
assert.equal(client.comments.length, 1);
assert.match(client.comments[0].body, /@carol/);
assert.match(client.comments[0].body, /@acme\/platform/);
// Reviewers were found, so it does NOT fall back to the assignee.
assert.doesNotMatch(client.comments[0].body, /@alice/);
});
test("stale-nudge 'reviewers' falls back to assignees when no review is pending", async () => {
const cfg = makeConfig({
features: { staleNudge: { enabled: true, rules: [{ status: "In Review", days: 2, notify: "reviewers" }] } },
});
const stale = makeItem([statusValue("In Review", "2026-07-01T00:00:00Z")], {
number: 10,
assignees: ["alice"],
reviewers: [],
});
const client = new FakeClient().withComments([]);
await runStaleNudge(makeCtx(makeGraph([statusField(["In Review"])], [stale]), cfg, client));
assert.equal(client.comments.length, 1);
assert.match(client.comments[0].body, /@alice/);
});
test("stale-nudge expands 'assignees' inside a list and de-dupes with an explicit login", async () => {
const cfg = makeConfig({
features: { staleNudge: { enabled: true, rules: [{ status: "Blocked", days: 1, notify: ["assignees", "eng-lead"] }] } },
});
const stale = makeItem([statusValue("Blocked", "2026-07-01T00:00:00Z")], { number: 11, assignees: ["alice"] });
const client = new FakeClient().withComments([]);
await runStaleNudge(makeCtx(makeGraph([statusField(["Blocked"])], [stale]), cfg, client));
assert.equal(client.comments.length, 1);
// The literal token "assignees" must NOT leak through as @assignees.
assert.doesNotMatch(client.comments[0].body, /@assignees/);
assert.match(client.comments[0].body, /@alice/);
assert.match(client.comments[0].body, /@eng-lead/);
});
test("stale-nudge does not re-nudge when a marker comment already exists for this stint", async () => {
const cfg = makeConfig({
features: { staleNudge: { enabled: true, rules: [{ status: "In Progress", days: 3, notify: "assignees" }] } },
});
const stale = makeItem([statusValue("In Progress", "2026-07-01T00:00:00Z")], { number: 5, assignees: ["alice"] });
const client = new FakeClient().withComments([
{ body: "<!-- boardly:stale-nudge:in progress -->\nnudge", createdAt: "2026-07-05T00:00:00Z" },
]);
await runStaleNudge(makeCtx(makeGraph([statusField(["In Progress"])], [stale]), cfg, client));
assert.equal(client.comments.length, 0);
});
test("sub-issue gate warns when a Done item has open sub-issues and rolls up progress", async () => {
const cfg = makeConfig({ features: { subIssueGate: { enabled: true, guardStatuses: ["Done"], action: "comment" } } });
const item = makeItem([statusValue("Done", "2026-07-08T00:00:00Z")], {
number: 7,
subIssues: { total: 3, completed: 1, percentCompleted: 33 },
});
const client = new FakeClient().withComments([]);
await runSubIssueGate(makeCtx(makeGraph([statusField(["Done", "In Progress"]), numberField("Progress")], [item]), cfg, client));
assert.equal(client.comments.length, 1);
assert.match(client.comments[0].body, /1\/3 sub-issues/);
assert.deepEqual(client.numbers, [{ itemId: item.id, value: 33 }]);
});
test("sub-issue gate reverts status when action is revert", async () => {
const cfg = makeConfig({
features: { subIssueGate: { enabled: true, guardStatuses: ["Done"], action: "revert", revertStatus: "In Progress" } },
});
const item = makeItem([statusValue("Done", "2026-07-08T00:00:00Z")], {
number: 8,
subIssues: { total: 2, completed: 0, percentCompleted: 0 },
});
const client = new FakeClient().withComments([]);
await runSubIssueGate(makeCtx(makeGraph([statusField(["Done", "In Progress"])], [item]), cfg, client));
assert.deepEqual(client.singleSelects, [{ itemId: item.id, optionId: "opt-In Progress" }]);
});
test("priority sort reorders items highest priority first, unknown last", async () => {
const cfg = makeConfig({ features: { prioritySort: { enabled: true, order: ["High", "Medium", "Low"] } } });
const low = makeItem([priorityValue("Low")], { number: 1 });
const high = makeItem([priorityValue("High")], { number: 2 });
const none = makeItem([], { number: 3 });
const medium = makeItem([priorityValue("Medium")], { number: 4 });
const client = new FakeClient();
await runPrioritySort(makeCtx(makeGraph([priorityField(["High", "Medium", "Low"])], [low, high, none, medium]), cfg, client));
assert.deepEqual(
client.positions.map((p) => p.itemId),
[high.id, medium.id, low.id, none.id],
);
assert.equal(client.positions[0].afterId, null);
assert.equal(client.positions[1].afterId, high.id);
});
test("priority sort is a no-op when already ordered", async () => {
const cfg = makeConfig({ features: { prioritySort: { enabled: true, order: ["High", "Low"] } } });
const high = makeItem([priorityValue("High")], { number: 1 });
const low = makeItem([priorityValue("Low")], { number: 2 });
const client = new FakeClient();
await runPrioritySort(makeCtx(makeGraph([priorityField(["High", "Low"])], [high, low]), cfg, client));
assert.equal(client.positions.length, 0);
});
test("digest reports completed vs carried-over and velocity for the last iteration", async () => {
const cfg = makeConfig({ features: { digest: { enabled: true, postTo: { issue: 42 } } } });
const fields = [statusField(["Todo", "Done"]), iterationField([], [{ id: "it1", title: "Sprint 1" }]), numberField("Estimate")];
const doneItem = makeItem([statusValue("Done", "2026-07-08T00:00:00Z"), iterationValue("it1", "Sprint 1"), estimateValue(5)], { number: 1 });
const carried = makeItem([statusValue("Todo", "2026-07-08T00:00:00Z"), iterationValue("it1", "Sprint 1"), estimateValue(3)], { number: 2 });
const client = new FakeClient();
await runDigest(makeCtx(makeGraph(fields, [doneItem, carried]), cfg, client));
assert.equal(client.comments.length, 1);
const body = client.comments[0].body;
assert.match(body, /Completed:\*\* 1 \/ 2/);
assert.match(body, /Carried over:\*\* 1/);
assert.match(body, /Velocity:\*\* 5 of 8/);
});