fix: stop verify, reports and briefs from claiming more than pipe checked #1
2 changed files with 31 additions and 2 deletions
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.
commit
ac7cce1f76
|
|
@ -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 {
|
||||
|
|
|
|||
27
test/stdout_json_test.dart
Normal file
27
test/stdout_json_test.dart
Normal 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'));
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue