Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 45 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,8 +476,19 @@ export async function revalidateCommand(
await writeRun(loaded.paths, run);
const results: Array<{ finding: string; outcome: FindingRecord["status"]; reasoning: string }> =
[];
emitRevalidateProgress(context, "start", {
run: currentRunId,
findings: findings.length,
});
try {
for (const finding of findings) {
for (const [index, finding] of findings.entries()) {
const started = Date.now();
emitRevalidateProgress(context, "finding-start", {
index: index + 1,
total: findings.length,
finding: finding.findingId,
title: finding.title,
});
const prompt = await buildRevalidatePrompt(loaded.root, JSON.stringify(finding, null, 2));
const output = await provider.revalidate(loaded.root, prompt, config.provider.model);
const updated = appendFindingHistory(
Expand All @@ -503,13 +514,28 @@ export async function revalidateCommand(
outcome: output.outcome,
reasoning: output.reasoning,
});
emitRevalidateProgress(context, "finding-done", {
index: index + 1,
total: findings.length,
finding: finding.findingId,
outcome: output.outcome,
elapsed: `${Math.round((Date.now() - started) / 1000)}s`,
});
}
await writeRun(loaded.paths, {
...run,
status: "completed",
finishedAt: nowIso(),
findingIds: results.map((result) => result.finding),
});
emitRevalidateProgress(context, "done", {
run: currentRunId,
revalidated: results.length,
fixed: results.filter((result) => result.outcome === "fixed").length,
open: results.filter((result) => result.outcome === "open").length,
uncertain: results.filter((result) => result.outcome === "uncertain").length,
falsePositive: results.filter((result) => result.outcome === "false-positive").length,
});
} catch (error: unknown) {
const message = error instanceof Error ? error.message : String(error);
await writeRun(loaded.paths, {
Expand All @@ -519,6 +545,10 @@ export async function revalidateCommand(
findingIds: run.findingIds,
errors: [{ message, code: error instanceof ClawpatchError ? error.code : null }],
});
emitRevalidateProgress(context, "failed", {
run: currentRunId,
error: message,
});
throw error;
}
if (flags["all"] === true) {
Expand Down Expand Up @@ -905,6 +935,20 @@ function emitReviewProgress(
process.stderr.write(`clawpatch review ${event}${values.length > 0 ? ` ${values}` : ""}\n`);
}

function emitRevalidateProgress(
context: AppContext,
event: string,
fields: Record<string, string | number | boolean>,
): void {
if (context.options.quiet) {
return;
}
const values = Object.entries(fields)
.map(([key, value]) => `${key}=${String(value)}`)
.join(" ");
process.stderr.write(`clawpatch revalidate ${event}${values.length > 0 ? ` ${values}` : ""}\n`);
}

function lockFeature(feature: FeatureRecord, currentRunId: string): FeatureRecord {
if (feature.lock !== null) {
throw new ClawpatchError(`feature locked: ${feature.featureId}`, 7, "lock-conflict");
Expand Down
12 changes: 11 additions & 1 deletion src/workflow.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, expect, it } from "vitest";
import { describe, expect, it, vi } from "vitest";
import { access, mkdir, readFile, rm, symlink, unlink } from "node:fs/promises";
import { join } from "node:path";
import {
Expand Down Expand Up @@ -275,7 +275,13 @@ describe("workflow", () => {
await writeFinding(paths, { ...finding, reasoning: markers[index] ?? "" });
}

let progress = "";
const stderr = vi.spyOn(process.stderr, "write").mockImplementation((chunk) => {
progress += String(chunk);
return true;
});
const result = await revalidateCommand(context, { all: true, status: "open", limit: "4" });
stderr.mockRestore();
const updated = await readFindings(paths);
const features = await readFeatures(paths);

Expand All @@ -293,6 +299,10 @@ describe("workflow", () => {
"uncertain",
]);
expect(updated.every((finding) => finding.history.at(-1)?.kind === "revalidate")).toBe(true);
expect(progress).toContain("clawpatch revalidate start");
expect(progress).toContain("clawpatch revalidate finding-start");
expect(progress).toContain("clawpatch revalidate finding-done");
expect(progress).toContain("clawpatch revalidate done");
const uncertain = updated.find((finding) => finding.status === "uncertain");
const uncertainFeature = features.find((feature) => feature.featureId === uncertain?.featureId);
expect(uncertainFeature?.status).toBe("needs-fix");
Expand Down