Skip to content
Merged
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
16 changes: 10 additions & 6 deletions src/commands/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ async function runWatchOneShot(
const outPath = await writeRunArtifact(artifact, outDir);

// Find the PREVIOUS run for this target (excluding the one just written)
const latestPath = await findLatestArtifact(outDir, target.targetId);
if (latestPath && latestPath !== outPath) {
const previousRaw = await readArtifact(latestPath);
const previousPath = await findLatestArtifact(outDir, target.targetId, outPath);
if (previousPath) {
const previousRaw = await readArtifact(previousPath);
if (previousRaw.artifactType === "run") {
const previous = previousRaw;
const diffResult = diff(previous, artifact);
const diffResult = diff(previousRaw, artifact);

process.stdout.write(formatOutput(diffResult, options.format as "terminal" | "json") + "\n");
if (diffResult.summary.regressions === 0 && diffResult.summary.recoveries === 0 && diffResult.summary.added === 0 && diffResult.summary.removed === 0) {
process.stdout.write(formatOutput(artifact, options.format as "terminal" | "json") + "\n");
process.stdout.write(`${c(ANSI.green, "✓ No changes")} since last run\n`);
} else {
process.stdout.write(formatOutput(diffResult, options.format as "terminal" | "json") + "\n");
}
process.stdout.write(`${c(ANSI.dim, `Artifact: ${outPath}`)}\n`);

if (options.failOnRegression && diffResult.summary.regressions > 0) {
Expand Down
8 changes: 5 additions & 3 deletions src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ export async function writeRunArtifact(
return filePath;
}

export async function findLatestArtifact(outDir: string, targetId: string): Promise<string | null> {
export async function findLatestArtifact(outDir: string, targetId: string, excludePath?: string): Promise<string | null> {
const slug = slugify(targetId);
const suffix = `--${slug}.json`;
try {
const entries = await readdir(outDir);
const matching = entries
.filter(f => f.endsWith(suffix))
.sort()
.reverse();
.reverse()
.map(f => path.join(outDir, f))
.filter(f => f !== excludePath);
if (matching.length === 0) return null;
return path.join(outDir, matching[0]!);
return matching[0]!;
} catch {
return null;
}
Expand Down
Loading