fix: stop verify, reports and briefs from claiming more than pipe checked #1

Merged
trevon merged 12 commits from fix/verify-soundness-and-injection into main 2026-09-22 18:24:06 +00:00
2 changed files with 31 additions and 2 deletions
Showing only changes of commit ac7cce1f76 - Show all commits

fix(cli): keep status messages off stdout so JSON output stays parseable

`check --format json --write-baseline b.json` printed "wrote baseline to ..."
after the JSON document, and `guide --yams` printed "persisted to yams as ..."
after the brief, so stdout was no longer a single JSON document (or a clean
brief) and `| jq` failed. Both status lines now go to stderr.
trvon 2026-09-22 11:51:49 -06:00
Signed by: trevon
GPG key ID: 38686EA797D7A8A7

View file

@ -110,7 +110,9 @@ void _writeBaseline(ArgResults results, String root, List<Finding> findings) {
final path = results['write-baseline'] as String?;
if (path == null) return;
File(path).writeAsStringSync(encodeBaseline(root, findings));
stdout.writeln(
// Status goes to stderr: after `--format json` stdout is the JSON document,
// and a trailing status line made it unparseable.
stderr.writeln(
'wrote baseline to $path (${findings.length} findings accepted)',
);
}
@ -753,7 +755,7 @@ class GuideCommand extends Command<int> {
stderr.writeln('pipe: could not persist to yams: $error');
return 1;
}
stdout.writeln('persisted to yams as $name');
stderr.writeln('persisted to yams as $name');
}
_writeBaseline(results, project.root, analysis.report.findings);
} finally {

View file

@ -0,0 +1,27 @@
import 'dart:convert';
import 'dart:io';
import 'package:test/test.dart';
void main() {
test('check --format json --write-baseline keeps stdout pure JSON', () async {
// The "wrote baseline" status line used to follow the JSON document on
// stdout, so `pipe check --format json --write-baseline b.json | jq` failed.
final temp = Directory.systemTemp.createTempSync('pipe-json-stdout');
final baseline = '${temp.path}/baseline.json';
final result = await Process.run(Platform.resolvedExecutable, [
'bin/pipe.dart',
'check',
'test/fixtures/stuck_loading',
'--format',
'json',
'--write-baseline',
baseline,
'-c',
'1',
]);
expect(result.exitCode, 0, reason: '${result.stderr}');
expect(() => jsonDecode(result.stdout as String), returnsNormally);
expect(result.stderr as String, contains('wrote baseline'));
});
}