fix(cli): close the remaining rough edges in paths, recall, yams and baselines #4
2 changed files with 33 additions and 1 deletions
fix(baseline): record the project root relative to the baseline file
A committed baseline carried one machine's absolute path and churned whenever another checkout rewrote it. Matching never reads root.
commit
6a700222eb
|
|
@ -122,7 +122,11 @@ void _writeBaseline(ArgResults results, String root, List<Finding> findings) {
|
|||
final path = results['write-baseline'] as String?;
|
||||
if (path == null) return;
|
||||
try {
|
||||
File(path).writeAsStringSync(encodeBaseline(root, findings));
|
||||
// Record the project root relative to the baseline file, so a committed
|
||||
// baseline does not carry one machine's absolute path (and does not churn
|
||||
// when another checkout rewrites it). Matching never reads `root`.
|
||||
final relativeRoot = p.relative(root, from: p.dirname(p.absolute(path)));
|
||||
File(path).writeAsStringSync(encodeBaseline(relativeRoot, findings));
|
||||
} on FileSystemException catch (error) {
|
||||
throw PipeException(
|
||||
'cannot write baseline $path: '
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:args/command_runner.dart';
|
||||
|
|
@ -86,4 +87,31 @@ void main() {
|
|||
expect(result.stderr as String, contains('fake yams down'));
|
||||
expect(File(baseline).existsSync(), isTrue);
|
||||
});
|
||||
|
||||
test('a written baseline records its root relative to the file', () async {
|
||||
// It used to store the absolute project path, so a committed baseline
|
||||
// leaked one machine's home directory and churned on every checkout.
|
||||
final temp = Directory.systemTemp.createTempSync('pipe-baseline-root');
|
||||
final baseline = p.join(temp.path, 'baseline.json');
|
||||
final result = await Process.run(Platform.resolvedExecutable, [
|
||||
'bin/pipe.dart',
|
||||
'check',
|
||||
'test/fixtures/stuck_loading',
|
||||
'--write-baseline',
|
||||
baseline,
|
||||
'-c',
|
||||
'1',
|
||||
]);
|
||||
expect(result.exitCode, 0, reason: '${result.stderr}');
|
||||
final root = (jsonDecode(File(baseline).readAsStringSync()) as Map)['root'];
|
||||
expect(p.isAbsolute(root as String), isFalse, reason: root);
|
||||
expect(
|
||||
p.equals(
|
||||
p.normalize(p.join(temp.path, root)),
|
||||
p.absolute('test/fixtures/stuck_loading'),
|
||||
),
|
||||
isTrue,
|
||||
reason: root,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue