Files
autocraft/test/implement-rows.ts
T
aiongg 2df22f1d5b Implement code reads and writes attempts through the implement module; questions, stuck and close become workflow recommendations and blockers
- questions: maintainer questions and the question limit are question rounds with options and a recommended option; answers are answer rounds
- stuck: a stuck attempt records a blocker question round (Try again, Open as draft PR); the build job carries out the answer after it
- close.ts goes: closing the issue or PR is the close command
- store.ts goes; src/implement/attempt.ts holds the step writes over recordSteps
- the fixissue approval reads and writes control's repo step approvals
- gate and the PR step read the live workflow (started_by, approved_by); fast track reads and writes go
- mirror, build, runners, control, review, inference and jobs reads go through their modules
2026-11-25 07:17:33 +00:00

29 lines
1.8 KiB
TypeScript

// The implement tests' reads and writes of attempts by id, over the implement module and its row shapes.
import type { Db } from "../src/db/index.ts";
import { recordSteps, startAttempt } from "../src/data/implement/index.ts";
import { IMPL_COLS, ofRow, roundOf, type ImplRow, type RoundRow } from "../src/data/implement/rows.ts";
import { currentAttempt } from "../src/implement/attempt.ts";
import type { Implementation, ImplementationPatch, ImplementationRound, ImplementationState } from "../src/implement/types.ts";
export async function startImplementation(db: Db, o: { repo: string; number: number; queuedBy: string; textHash: string; baseSha?: string | null }, at?: string): Promise<Implementation> {
const r = await startAttempt(db, o, at);
if (!r) throw new Error(`${o.repo}#${o.number} has a current attempt`);
return r;
}
export async function setImplementationState(db: Db, id: number, state: ImplementationState, patch: ImplementationPatch = {}, at?: string): Promise<void> {
await recordSteps(db, [{ id, to: state, patch }], at);
}
export async function implementationById(db: Db, id: number): Promise<Implementation | null> {
const r = await db.get(db.k.selectFrom("main.implementations").select([...IMPL_COLS] as never).where("id", "=", id));
return r ? ofRow(r as unknown as ImplRow) : null;
}
export const currentImplementation = async (db: Db, repo: string, number: number): Promise<Implementation | null> => (await currentAttempt(db, repo, number))?.impl ?? null;
export async function roundsOf(db: Db, implementationId: number): Promise<ImplementationRound[]> {
const rows = await db.all(db.k.selectFrom("main.implementation_rounds").select(["id", "implementation_id", "kind", "call_id", "result", "at"]).where("implementation_id", "=", implementationId).orderBy("id"));
return rows.map((r) => roundOf(r as unknown as RoundRow));
}