fix(cli): close the remaining rough edges in paths, recall, yams and baselines #4

Merged
trevon merged 2 commits from trevon/cli-rough-edges into main 2026-09-24 02:36:11 +00:00 AGit
2 changed files with 33 additions and 1 deletions
Showing only changes of commit 6a700222eb - Show all commits

fix(baseline): record the project root relative to the baseline file
Some checks failed
Lint Commits / commitlint (pull_request) Successful in 18s
Tests / Static Analysis (pull_request) Has been cancelled
Tests / Tests (pull_request) Has been cancelled

A committed baseline carried one machine's absolute path and churned whenever another checkout rewrote it. Matching never reads root.
trvon 2026-09-22 15:30:46 -06:00
Signed by: trevon
GPG key ID: 38686EA797D7A8A7

View file

@ -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: '

View file

@ -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,
);
});
}