diff --git a/src/commands/watch.ts b/src/commands/watch.ts index 43c14a8..0151dcf 100644 --- a/src/commands/watch.ts +++ b/src/commands/watch.ts @@ -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) { diff --git a/src/storage.ts b/src/storage.ts index 9211cb4..f75d99b 100644 --- a/src/storage.ts +++ b/src/storage.ts @@ -28,7 +28,7 @@ export async function writeRunArtifact( return filePath; } -export async function findLatestArtifact(outDir: string, targetId: string): Promise { +export async function findLatestArtifact(outDir: string, targetId: string, excludePath?: string): Promise { const slug = slugify(targetId); const suffix = `--${slug}.json`; try { @@ -36,9 +36,11 @@ export async function findLatestArtifact(outDir: string, targetId: string): Prom 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; }