Skip to content

Commit 675a899

Browse files
committed
refactor(scheduler): keep test helpers out of runtime
1 parent 5e9445b commit 675a899

3 files changed

Lines changed: 29 additions & 89 deletions

File tree

‎src/clawsweeper.ts‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@ export {
116116
isLockedConversationCommentError,
117117
shouldRetryGh,
118118
} from "./github-retry.js";
119-
export {
120-
appendFloorBackfillCandidateNumbersForTest,
121-
hotIntakeRecencyMs,
122-
reviewPriority,
123-
selectDueCandidateNumbersForTest,
124-
shouldReviewItem,
125-
shouldStopSaturatedPlanScan,
126-
} from "./scheduler-policy.js";
127-
128119
type ItemKind = "issue" | "pull_request";
129120
type ApplyKind = ItemKind | "all";
130121
type DecisionKind = "close" | "keep_open";

‎src/scheduler-policy.ts‎

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -320,64 +320,6 @@ export function appendFloorBackfillCandidates<
320320
return filled;
321321
}
322322

323-
export function selectDueCandidateNumbersForTest(
324-
due: Array<{
325-
item: SchedulerItem;
326-
bucket: SchedulerBucket;
327-
priority?: number;
328-
reviewedAt?: number;
329-
nextDueAt?: number;
330-
}>,
331-
limit: number,
332-
now = Date.now(),
333-
): number[] {
334-
return selectDueCandidates(
335-
due.map((candidate) => ({
336-
item: candidate.item,
337-
review: null,
338-
priority: candidate.priority ?? reviewPriority(candidate.item, null),
339-
reviewedAt: candidate.reviewedAt ?? 0,
340-
nextDueAt: candidate.nextDueAt ?? 0,
341-
bucket: candidate.bucket,
342-
})),
343-
limit,
344-
compareDueCandidates,
345-
now,
346-
).map((candidate) => candidate.item.number);
347-
}
348-
349-
export function appendFloorBackfillCandidateNumbersForTest(
350-
selected: Array<{
351-
item: SchedulerItem;
352-
bucket: SchedulerBucket;
353-
priority?: number;
354-
reviewedAt?: number;
355-
nextDueAt?: number;
356-
}>,
357-
backfill: Array<{
358-
item: SchedulerItem;
359-
bucket: SchedulerBucket;
360-
priority?: number;
361-
reviewedAt?: number;
362-
nextDueAt?: number;
363-
}>,
364-
activeFloor: number,
365-
capacity: number,
366-
): number[] {
367-
const normalize = (candidate: (typeof selected)[number]): SchedulerDueCandidate => ({
368-
item: candidate.item,
369-
review: null,
370-
priority: candidate.priority ?? reviewPriority(candidate.item, null),
371-
reviewedAt: candidate.reviewedAt ?? 0,
372-
nextDueAt: candidate.nextDueAt ?? 0,
373-
bucket: candidate.bucket,
374-
});
375-
return appendFloorBackfillCandidates(selected.map(normalize), backfill.map(normalize), {
376-
activeFloor,
377-
capacity,
378-
}).map((candidate) => candidate.item.number);
379-
}
380-
381323
export function compareHotIntakeDueCandidates<
382324
ItemT extends SchedulerItem,
383325
ReviewT extends SchedulerExistingReview,

‎test/scheduler-policy.test.ts‎

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,40 @@ import assert from "node:assert/strict";
22
import test from "node:test";
33

44
import {
5-
appendFloorBackfillCandidateNumbersForTest,
5+
appendFloorBackfillCandidates,
66
hotIntakeRecencyMs,
77
reviewPriority,
8-
selectDueCandidateNumbersForTest,
8+
selectDueCandidates,
99
shouldReviewItem,
1010
shouldStopSaturatedPlanScan,
1111
} from "../dist/scheduler-policy.js";
12+
import { item } from "./helpers.ts";
1213

13-
function item(overrides = {}) {
14+
function schedulerCandidate(candidate) {
1415
return {
15-
repo: "openclaw/openclaw",
16-
number: 123,
17-
kind: "issue",
18-
title: "Sample item",
19-
url: "https://github.com/openclaw/openclaw/issues/123",
20-
createdAt: "2026-01-01T00:00:00Z",
21-
updatedAt: "2026-01-01T00:00:00Z",
22-
author: "contributor",
23-
authorAssociation: "NONE",
24-
labels: [],
25-
...overrides,
16+
item: candidate.item,
17+
review: null,
18+
priority: candidate.priority ?? reviewPriority(candidate.item, null),
19+
reviewedAt: candidate.reviewedAt ?? 0,
20+
nextDueAt: candidate.nextDueAt ?? 0,
21+
bucket: candidate.bucket,
2622
};
2723
}
2824

25+
function selectedNumbers(due, limit, now) {
26+
return selectDueCandidates(due.map(schedulerCandidate), limit, undefined, now).map(
27+
(candidate) => candidate.item.number,
28+
);
29+
}
30+
31+
function backfilledNumbers(selected, backfill, activeFloor, capacity) {
32+
return appendFloorBackfillCandidates(
33+
selected.map(schedulerCandidate),
34+
backfill.map(schedulerCandidate),
35+
{ activeFloor, capacity },
36+
).map((candidate) => candidate.item.number);
37+
}
38+
2939
test("review policy changes force fresh complete reports back into planning", () => {
3040
const reviewedAt = new Date().toISOString();
3141
const review = {
@@ -345,7 +355,7 @@ test("normal scheduler reserves throughput for PR and older buckets", () => {
345355
},
346356
);
347357

348-
assert.deepEqual(selectDueCandidateNumbersForTest(due, 8, now), [1, 2, 3, 4, 101, 201, 301, 5]);
358+
assert.deepEqual(selectedNumbers(due, 8, now), [1, 2, 3, 4, 101, 201, 301, 5]);
349359
});
350360

351361
test("normal scheduler prioritizes items already breaching weekly freshness", () => {
@@ -383,7 +393,7 @@ test("normal scheduler prioritizes items already breaching weekly freshness", ()
383393
},
384394
];
385395

386-
assert.deepEqual(selectDueCandidateNumbersForTest(due, 3, now), [3, 2, 1]);
396+
assert.deepEqual(selectedNumbers(due, 3, now), [3, 2, 1]);
387397
});
388398

389399
test("weekly freshness preselection still fills remaining scheduler capacity", () => {
@@ -421,7 +431,7 @@ test("weekly freshness preselection still fills remaining scheduler capacity", (
421431
},
422432
);
423433

424-
assert.deepEqual(selectDueCandidateNumbersForTest(due, 7, now), [1, 2, 3, 4, 5, 7, 6]);
434+
assert.deepEqual(selectedNumbers(due, 7, now), [1, 2, 3, 4, 5, 7, 6]);
425435
});
426436

427437
test("normal scheduler can fill active floor from stale current reviews", () => {
@@ -457,11 +467,8 @@ test("normal scheduler can fill active floor from stale current reviews", () =>
457467
},
458468
];
459469

460-
assert.deepEqual(
461-
appendFloorBackfillCandidateNumbersForTest(selected, backfill, 3, 10),
462-
[1, 10, 11],
463-
);
464-
assert.deepEqual(appendFloorBackfillCandidateNumbersForTest(selected, backfill, 3, 2), [1, 10]);
470+
assert.deepEqual(backfilledNumbers(selected, backfill, 3, 10), [1, 10, 11]);
471+
assert.deepEqual(backfilledNumbers(selected, backfill, 3, 2), [1, 10]);
465472
});
466473

467474
test("normal scheduler can stop scanning once planned capacity is saturated", () => {

0 commit comments

Comments
 (0)