mirror of
https://github.com/storytold/autocraft.git
synced 2026-11-27 16:49:34 +01:00
plannedItems() and planned() without a PlanSet loaded and decided every open item (or PR) to find the few due for one step. They now load facts only for the candidates the stored Plans name: items whose cached Plan holds the action, items in the change log since the planner read it, and open items without a cached Plan. Each candidate is decided again on fresh facts, so the set and order match a full load except for items that turned due since the planner's last pass for a reason the log does not name (the clock, a global input, a bulk write); the next pass decides those. A caller asking for another time, run or embedding model, or for every PR's Plan, still gets the full load, as does a database with no cached Plan. Classify loads its Plans once per job and reuses them for the Jev and Haiku passes, deciding again only the items Jev answered in the job. Item text and class_hash come in one query instead of two per item. Items a maintainer started work on (a live workflow, or the PR of a live implement workflow) go first in both passes; the rule is shared with the scope test in pilot.ts.
28 lines
1.9 KiB
TypeScript
28 lines
1.9 KiB
TypeScript
// Classify's selection: work a maintainer started goes ahead of the backlog, so a cut to the job's limit keeps it.
|
|
import assert from "node:assert/strict";
|
|
import { test } from "node:test";
|
|
import { refreshPlanCache } from "../src/core/plan-cache.ts";
|
|
import { fillClassHashes } from "../src/itemhash.ts";
|
|
import { classifyPlans, jevItems } from "../src/runner/classify.ts";
|
|
import { OPERATOR, T0, world } from "./world-db.ts";
|
|
|
|
test("an item with a live workflow is taken before older due items", async () => {
|
|
const w = await (await world()).repo();
|
|
const db = w.db;
|
|
await db.prepare("INSERT INTO settings (key, value) VALUES ('classify_run', 'r1')").run();
|
|
await db.prepare("UPDATE tracked_repos SET workflow = 'new' WHERE name = 'app'").run();
|
|
// Newest first without a started item: 1, 2, 3, then the started item 4, updated longest ago.
|
|
for (const [n, at] of [[1, "2026-03-04"], [2, "2026-03-03"], [3, "2026-03-02"], [4, "2026-03-01"]] as const) {
|
|
await db.prepare("INSERT INTO items (repo, number, kind, state, title, body, author, created_at, updated_at) VALUES ('app', ?, 'issue', 'OPEN', ?, 'b', 'someone', ?, ?)").run(n, `t${n}`, T0, at);
|
|
}
|
|
await fillClassHashes(db);
|
|
await refreshPlanCache(db);
|
|
const before = (await jevItems(db, "r1", "new", await classifyPlans(db, "r1"))).due.map((x) => x.number);
|
|
assert.equal(before.at(-1), 4, "a backlog item updated longest ago comes last");
|
|
|
|
await db.prepare("INSERT INTO item_workflows (repo, number, kind, entry, state, started_by, started_at, started_via, updated_at) VALUES ('app', 4, 'issue', 'review', 'running', ?, ?, 'github', ?)").run(OPERATOR, T0, T0);
|
|
const due = (await jevItems(db, "r1", "new", await classifyPlans(db, "r1"))).due.map((x) => x.number);
|
|
assert.equal(due[0], 4, "the started item comes first");
|
|
assert.deepEqual(due.slice(1), before.slice(0, -1), "the others keep their order");
|
|
});
|