feat: enhance workflow and testing infrastructure

- Introduced ExecutionMode type for project execution modes (parallel, sequential).
- Updated SetupOpts to use ExecutionMode instead of string literals.
- Enhanced workflow states to include a new "In Review" state with appropriate transitions.
- Implemented TestHarness for end-to-end testing, including command interception and workspace setup.
- Created TestProvider for in-memory issue tracking during tests.
- Refactored project registration and setup tools to utilize ExecutionMode.
- Updated various tools to ensure compatibility with new workflow and execution modes.
- Added new dependencies: cockatiel for resilience and zod for schema validation.
This commit is contained in:
Lauren ten Hoor
2026-02-16 13:27:14 +08:00
parent a359ffed34
commit 371e760d94
37 changed files with 2444 additions and 263 deletions

View File

@@ -11,84 +11,15 @@ import { createProvider } from "../providers/index.js";
import { selectLevel } from "../model-selector.js";
import { getWorker, getSessionForLevel, readProjects } from "../projects.js";
import { dispatchTask } from "../dispatch.js";
import { getLevelsForRole, getAllLevels, roleForLevel } from "../roles/index.js";
import { roleForLevel } from "../roles/index.js";
import { loadConfig } from "../config/index.js";
import {
getQueueLabels,
getAllQueueLabels,
ExecutionMode,
getActiveLabel,
detectRoleFromLabel as workflowDetectRole,
type WorkflowConfig,
type Role,
} from "../workflow.js";
// ---------------------------------------------------------------------------
// Shared helpers (used by tick, work-start, auto-pickup)
// ---------------------------------------------------------------------------
export function detectLevelFromLabels(labels: string[]): string | null {
const lower = labels.map((l) => l.toLowerCase());
// Match role.level labels (e.g., "dev.senior", "qa.mid", "architect.junior")
for (const l of lower) {
const dot = l.indexOf(".");
if (dot === -1) continue;
const role = l.slice(0, dot);
const level = l.slice(dot + 1);
const roleLevels = getLevelsForRole(role);
if (roleLevels.includes(level)) return level;
}
// Fallback: plain level name
const all = getAllLevels();
return all.find((l) => lower.includes(l)) ?? null;
}
/**
* Detect role from a label using workflow config.
*/
export function detectRoleFromLabel(
label: StateLabel,
workflow: WorkflowConfig,
): Role | null {
return workflowDetectRole(workflow, label);
}
export async function findNextIssueForRole(
provider: Pick<IssueProvider, "listIssuesByLabel">,
role: Role,
workflow: WorkflowConfig,
): Promise<{ issue: Issue; label: StateLabel } | null> {
const labels = getQueueLabels(workflow, role);
for (const label of labels) {
try {
const issues = await provider.listIssuesByLabel(label);
if (issues.length > 0) return { issue: issues[issues.length - 1], label };
} catch { /* continue */ }
}
return null;
}
/**
* Find next issue for any role (optional filter). Used by work_start for auto-detection.
*/
export async function findNextIssue(
provider: Pick<IssueProvider, "listIssuesByLabel">,
role: Role | undefined,
workflow: WorkflowConfig,
): Promise<{ issue: Issue; label: StateLabel } | null> {
const labels = role
? getQueueLabels(workflow, role)
: getAllQueueLabels(workflow);
for (const label of labels) {
try {
const issues = await provider.listIssuesByLabel(label);
if (issues.length > 0) return { issue: issues[issues.length - 1], label };
} catch { /* continue */ }
}
return null;
}
import { detectLevelFromLabels, findNextIssueForRole } from "./queue-scan.js";
// ---------------------------------------------------------------------------
// projectTick
@@ -146,7 +77,7 @@ export async function projectTick(opts: {
const workflow = opts.workflow ?? resolvedConfig.workflow;
const provider = opts.provider ?? (await createProvider({ repo: project.repo, provider: project.provider })).provider;
const roleExecution = project.roleExecution ?? "parallel";
const roleExecution = project.roleExecution ?? ExecutionMode.PARALLEL;
const enabledRoles = Object.entries(resolvedConfig.roles)
.filter(([, r]) => r.enabled)
.map(([id]) => id);
@@ -173,7 +104,7 @@ export async function projectTick(opts: {
}
// Check sequential role execution: any other role must be inactive
const otherRoles = enabledRoles.filter((r: string) => r !== role);
if (roleExecution === "sequential" && otherRoles.some((r: string) => getWorker(fresh, r).active)) {
if (roleExecution === ExecutionMode.SEQUENTIAL && otherRoles.some((r: string) => getWorker(fresh, r).active)) {
skipped.push({ role, reason: "Sequential: other role active" });
continue;
}