Skip to content

Commit 45fd08e

Browse files
authored
fix(cli): Always halt when seraching for pubspec.yaml (#443)
The `==` for directory objects doesn't succeed leading to an infinite loop when reaching the root directory.
1 parent 8d6f21b commit 45fd08e

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

apps/cli/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## NEXT
22

33
- feat: Allow overriding client environment with Dart define
4+
- fix: Searching parent directories for a `pubspec.yaml` file always halts now
45
- chore: Update dependencies
56

67
## 1.0.13

apps/cli/lib/src/init/project_init.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ base mixin Configure on CelestCommand {
185185
} else {
186186
// For other commands, search recursively for the Celest pubspec file.
187187
while (!pubspecFile.existsSync()) {
188-
if (currentDir == currentDir.parent) {
188+
if (fileSystem.identicalSync(currentDir.path, currentDir.parent.path)) {
189189
_throwNoProject();
190190
}
191191
currentDir = currentDir.parent;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import 'package:celest_cli/src/commands/celest_command.dart';
2+
import 'package:celest_cli/src/context.dart';
3+
import 'package:celest_cli/src/exceptions.dart';
4+
import 'package:celest_cli/src/init/project_init.dart';
5+
import 'package:mason_logger/src/mason_logger.dart';
6+
import 'package:test/test.dart';
7+
8+
final class TestCommand extends CelestCommand with Configure {
9+
@override
10+
String get name => 'test';
11+
12+
@override
13+
String get description => 'test';
14+
15+
@override
16+
Progress? currentProgress;
17+
18+
@override
19+
// ignore: must_call_super
20+
Future<int> run() async {
21+
await configure();
22+
return 0;
23+
}
24+
}
25+
26+
void main() {
27+
group('init', () {
28+
test('throws when no project found', () async {
29+
final projectRoot = await fileSystem.systemTempDirectory.createTemp(
30+
'test_project_',
31+
);
32+
fileSystem.currentDirectory = projectRoot;
33+
34+
addTearDown(() async {
35+
try {
36+
await projectRoot.delete(recursive: true);
37+
} on Object {
38+
// OK
39+
}
40+
});
41+
42+
await expectLater(
43+
() => TestCommand().run(),
44+
throwsA(
45+
isA<CliException>().having(
46+
(e) => e.message,
47+
'message',
48+
contains('No Celest project found in the current directory'),
49+
),
50+
),
51+
);
52+
});
53+
});
54+
}

0 commit comments

Comments
 (0)