Skip to content

Commit b130f14

Browse files
authored
test(cli): Re-enable tests on Windows (#249)
1 parent 550ba2a commit b130f14

File tree

14 files changed

+148
-71
lines changed

14 files changed

+148
-71
lines changed

.github/workflows/celest_cli.yaml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,29 +23,20 @@ jobs:
2323
matrix:
2424
os:
2525
- ubuntu-latest
26-
- macos-14
27-
# TODO: Need to fix tests on Windows
28-
# - windows-latest
26+
- macos-latest
27+
- windows-latest
2928
runs-on: ${{ matrix.os }}
3029
timeout-minutes: 20
3130
steps:
3231
- name: Git Checkout
3332
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
34-
with:
35-
submodules: recursive
36-
# Needed for flutter-version-file: https://github.com/subosito/flutter-action?tab=readme-ov-file#use-version-from-pubspecyaml
37-
- name: Install yq
38-
if: runner.os == 'Windows'
39-
shell: bash
40-
run: |
41-
curl -sL "https://github.com/mikefarah/yq/releases/download/v4.43.1/yq_windows_amd64.exe" -o yq.exe
42-
echo "$PWD" >> "$GITHUB_PATH"
4333
- name: Setup Flutter
4434
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # 2.18.0
4535
with:
4636
cache: true
47-
# Locks version to repo constraint (for golden test alignment)
48-
flutter-version-file: pubspec.yaml
37+
# Because many golden tests encode the precise Dart/Flutter SDKs used to generate
38+
# them, these values must be consistently used when running tests locally and in CI.
39+
flutter-version: 3.29.1
4940
- name: Setup Libsecret
5041
if: runner.os == 'Linux'
5142
run: tool/setup-ci.sh

apps/cli/lib/codegen/allocator.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import 'package:celest_cli/project/project_paths.dart';
12
import 'package:celest_cli/src/context.dart';
23
import 'package:celest_cli/src/utils/error.dart';
34
import 'package:celest_cli/src/utils/path.dart';
@@ -37,9 +38,11 @@ final class CelestAllocator implements Allocator {
3738
required this.pathStrategy,
3839
@visibleForTesting String? packageName,
3940
@visibleForTesting String? clientPackageName,
41+
@visibleForTesting ProjectPaths? projectPaths,
4042
}) : packageName = packageName ?? celestProject.pubspec.name,
4143
clientPackageName =
42-
clientPackageName ?? celestProject.clientPubspec.name;
44+
clientPackageName ?? celestProject.clientPubspec.name,
45+
projectPaths = projectPaths ?? celestProject.projectPaths;
4346

4447
static const _doNotPrefix = ['dart:core', 'package:meta/meta.dart'];
4548
static final Logger _logger = Logger('CelestAllocator');
@@ -50,6 +53,7 @@ final class CelestAllocator implements Allocator {
5053

5154
final String packageName;
5255
final String clientPackageName;
56+
final ProjectPaths projectPaths;
5357

5458
late final _fileContext = path.Context(
5559
current: p.dirname(forFile),

apps/cli/lib/project/celest_project.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ final class CelestProject {
121121
parentProject: parentProject,
122122
cacheDb: cacheDb,
123123
byteStore: byteStore,
124+
projectDb: projectDb,
124125
);
125126
return project;
126127
}

apps/cli/lib/pub/pub_cache.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ final class PubCache {
2626
'celest_auth': '>=$currentMinorVersion <2.0.0',
2727
'celest': '>=$currentMinorVersion <2.0.0',
2828
'celest_core': '>=$currentMinorVersion <2.0.0',
29-
'objective_c': '>=2.0.0',
29+
'objective_c': '>=2.0.0 <8.0.0',
3030
};
3131
static final _logger = Logger('PubCache');
3232

@@ -101,7 +101,7 @@ final class PubCache {
101101
for (final package in packagesToFix.entries) {
102102
// Run serially to avoid flutter lock
103103
final result = await processManager
104-
.start([
104+
.start(runInShell: true, [
105105
Sdk.current.sdkType.name,
106106
'pub',
107107
'cache',

apps/cli/lib/src/context.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ FileSystem fileSystem = const LocalFileSystem();
186186
FileSystem get localFileSystem => const LocalFileSystem();
187187

188188
/// Global path context.
189-
path.Context get p => fileSystem.path;
189+
path.Context get p => localFileSystem.path;
190190

191191
/// Global platform.
192192
///

apps/cli/lib/src/sdk/sdk_finder.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,17 @@ final class SdkNotFound extends SdkFinderResult<Never> {
5656
String toString() {
5757
final buffer = StringBuffer('Could not find SDK');
5858
if (candidates.isNotEmpty) {
59-
buffer.writeln(' candidates:');
59+
buffer
60+
..writeln()
61+
..writeln(' candidates:');
6062
for (final candidate in candidates) {
6163
buffer.writeln(' - $candidate');
6264
}
6365
}
6466
if (searchPath.isNotEmpty) {
65-
buffer.writeln(' search path:');
67+
buffer
68+
..writeln()
69+
..writeln(' search path:');
6670
for (final path in searchPath) {
6771
buffer.writeln(' - $path');
6872
}
@@ -118,7 +122,7 @@ final class DartSdkFinder implements SdkFinder<SdkType> {
118122
)!; // never null when `throwOnFailure: true`
119123
} on ProcessPackageExecutableNotFoundException catch (e) {
120124
_logger.finest('Could not find Flutter SDK in PATH.', e);
121-
return SdkNotFound(searchPath: e.candidates);
125+
return SdkNotFound(searchPath: e.searchPath, candidates: e.candidates);
122126
}
123127

124128
final searchPath = <String>[];

apps/cli/test/analyzer/celest_analyzer_test.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'package:celest/http.dart';
44
import 'package:celest_ast/celest_ast.dart';
55
import 'package:celest_cli/analyzer/analysis_result.dart';
66
import 'package:celest_cli/analyzer/celest_analyzer.dart';
7+
import 'package:celest_cli/database/cache/cache_database.dart';
8+
import 'package:celest_cli/database/project/project_database.dart';
79
import 'package:celest_cli/project/celest_project.dart';
810
import 'package:celest_cli/pub/pub_cache.dart';
911
import 'package:celest_cli/pub/pub_environment.dart';
@@ -133,7 +135,11 @@ $contents
133135
]);
134136
await project.create(parentDirectory);
135137
final projectRoot = p.join(parentDirectory ?? d.sandbox, name);
136-
await init(projectRoot: projectRoot);
138+
await init(
139+
projectRoot: projectRoot,
140+
cacheDb: await CacheDatabase.memory(),
141+
projectDb: ProjectDatabase.memory(),
142+
);
137143
return celestProject;
138144
}
139145

apps/cli/test/codegen/allocator_test.dart

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,10 @@
11
import 'package:celest_cli/codegen/allocator.dart';
2+
import 'package:celest_cli/project/project_paths.dart';
23
import 'package:code_builder/code_builder.dart';
34
import 'package:test/test.dart';
45

56
void main() {
67
group('CelestAllocator', () {
7-
group('Windows', testOn: 'windows', () {
8-
// When the temp dir (generated outputs) is on a separate drive from the source project,
9-
// ensure that paths are absolute and not relative since there is no way to express a
10-
// relative path between drives.
11-
test('separate drives', () {
12-
final reference = refer(
13-
'sayHello',
14-
r'D:\workspace\celest_example\celest\functions\greeting.dart',
15-
);
16-
const generatingForPath =
17-
r'C:\Users\celest\AppData\Local\Temp\af0ceaa9\functions\greeting\sayHello.dart';
18-
final allocator = CelestAllocator(
19-
forFile: generatingForPath,
20-
pathStrategy: PathStrategy.robust,
21-
prefixingStrategy: PrefixingStrategy.pretty,
22-
);
23-
final symbol = allocator.allocate(reference);
24-
expect(symbol, r'_$greeting.sayHello');
25-
expect(
26-
allocator.imports.single,
27-
isA<Directive>().having(
28-
(d) => d.url,
29-
'url',
30-
'file:///D:/workspace/celest_example/celest/functions/greeting.dart',
31-
),
32-
);
33-
});
34-
});
35-
368
test('de-dups import prefixes', () async {
379
// Only applies in pretty mode.
3810
const prefixingStrategy = PrefixingStrategy.pretty;
@@ -50,6 +22,7 @@ void main() {
5022
prefixingStrategy: prefixingStrategy,
5123
packageName: 'celest_backend',
5224
clientPackageName: 'test_client',
25+
projectPaths: ProjectPaths('/'),
5326
);
5427
for (final uri in uris) {
5528
allocator.allocate(refer('A', uri.toString()));

apps/cli/test/commands/uninstall_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void main() {
4141
});
4242

4343
group('uninstall AOT', () {
44-
test('windows', () async {
44+
test('windows', testOn: 'windows', () async {
4545
ctx.fileSystem = MemoryFileSystem.test(style: FileSystemStyle.windows);
4646

4747
const appData = r'C:\Users\test\AppData\Local\Microsoft\WindowsApps';
@@ -114,7 +114,7 @@ void main() {
114114
).called(1);
115115
});
116116

117-
test('macos', () async {
117+
test('macos', testOn: 'posix', () async {
118118
ctx.fileSystem = MemoryFileSystem.test(style: FileSystemStyle.posix);
119119
final configDir = ctx.fileSystem.systemTempDirectory
120120
.childDirectory('Library')
@@ -182,7 +182,7 @@ void main() {
182182
).called(1);
183183
});
184184

185-
group('linux', () {
185+
group('linux', testOn: 'posix', () {
186186
test('deb installation', () async {
187187
ctx.fileSystem = MemoryFileSystem.test(style: FileSystemStyle.posix);
188188
final configDir = ctx.fileSystem.systemTempDirectory

apps/cli/test/env/firebase_config_value_solver_test.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ Future<List<FirebaseProject>> _resolveProjectTest({
2020
String? globalProjectPointer,
2121
Map<String, Object?>? firebaseJson,
2222
}) async {
23-
fileSystem = MemoryFileSystem.test();
23+
fileSystem = MemoryFileSystem.test(
24+
style: switch (platform.operatingSystem) {
25+
'windows' => FileSystemStyle.windows,
26+
_ => FileSystemStyle.posix,
27+
},
28+
);
2429
final appDir = fileSystem.systemTempDirectory.createTempSync('app_');
2530
if (firebaseJson != null) {
2631
appDir
@@ -34,7 +39,7 @@ Future<List<FirebaseProject>> _resolveProjectTest({
3439
}
3540
if (globalProjectPointer != null) {
3641
final configPath = fileSystem.path.join(
37-
platform.environment['HOME']!,
42+
(platform.environment['HOME'] ?? platform.environment['USERPROFILE'])!,
3843
'.config',
3944
'configstore',
4045
'firebase-tools.json',

0 commit comments

Comments
 (0)