Skip to content

Commit 7a43a39

Browse files
committed
chore(auth): Update example
- Updates to latest Flutter - Adds integration test
1 parent a74682c commit 7a43a39

File tree

26 files changed

+448
-137
lines changed

26 files changed

+448
-137
lines changed

.github/workflows/celest_auth.yaml

Lines changed: 182 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ concurrency:
1111
group: ${{ github.repository }}-${{ github.workflow }}-${{ github.ref }}-${{ github.ref == 'refs/heads/main' && github.sha || ''}}
1212
cancel-in-progress: true
1313

14+
env:
15+
CELEST: ${{ github.workspace }}/apps/cli/bin/celest.dart
16+
defaults:
17+
run:
18+
shell: bash
19+
1420
jobs:
15-
build:
21+
test:
1622
runs-on: macos-latest-xlarge
1723
timeout-minutes: 15
1824
steps:
@@ -39,12 +45,180 @@ jobs:
3945
# - name: Test
4046
# working-directory: packages/celest_auth
4147
# run: dart test
42-
- name: Test (Example)
43-
working-directory: packages/celest_auth/example/celest
44-
run: dart test
45-
- name: Build Example (iOS)
48+
test_darwin:
49+
needs: [test]
50+
runs-on: macos-latest-xlarge
51+
timeout-minutes: 20
52+
steps:
53+
- name: Git Checkout
54+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
55+
- name: Setup Flutter
56+
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # 2.18.0
57+
with:
58+
cache: true
59+
- name: Get Packages
60+
working-directory: apps/cli
61+
run: dart pub get
62+
- name: Get Packages (Example)
63+
working-directory: packages/celest_auth/example
64+
run: flutter pub get
65+
- name: Setup iOS Simulator
66+
run: |
67+
RUNTIME=$(xcrun simctl list runtimes | grep 'iOS 18' | tail -n 1 | cut -d' ' -f 7)
68+
echo "Using runtime: $RUNTIME"
69+
xcrun simctl create ios 'iPhone 16 Pro Max' $RUNTIME
70+
echo "Booting simulator"
71+
xcrun simctl boot ios
72+
echo "Booted simulator"
73+
- name: Integration Test (iOS)
74+
working-directory: packages/celest_auth/example
75+
run: dart run $CELEST start --verbose -- flutter test -d ios integration_test
76+
- name: Integration Test (macOS)
4677
working-directory: packages/celest_auth/example
47-
run: flutter build ios --no-codesign
48-
- name: Build Example (Web)
78+
run: dart run $CELEST start --verbose -- flutter test -d macos integration_test
79+
# TODO: Keeps timing out on Linux. Fails hard on macOS...
80+
# test_android:
81+
# needs: [test]
82+
# runs-on: macos-latest-xlarge
83+
# timeout-minutes: 30
84+
# steps:
85+
# - name: Git Checkout
86+
# uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
87+
# - name: Setup Flutter
88+
# uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # 2.18.0
89+
# with:
90+
# cache: true
91+
# - name: Get Packages
92+
# working-directory: apps/cli
93+
# run: dart pub get
94+
# - name: Get Packages (Example)
95+
# working-directory: packages/celest_auth/example
96+
# run: flutter pub get
97+
# - name: Start Celest
98+
# working-directory: packages/celest_auth/example
99+
# run: dart run $CELEST start --verbose &
100+
# - name: Build APK
101+
# working-directory: packages/celest_auth/example
102+
# run: flutter build apk --debug
103+
# # - name: Enable KVM
104+
# # run: |
105+
# # echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
106+
# # sudo udevadm control --reload-rules
107+
# # sudo udevadm trigger --name-match=kvm
108+
# - name: Test (API 31)
109+
# uses: ReactiveCircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d # 2.33.0
110+
# with:
111+
# # Matches `package:jni` compileSdkVersion
112+
# # https://github.com/dart-lang/native/blob/001910c9f40d637cb25c19bb500fb89cebdf7450/pkgs/jni/android/build.gradle#L57C23-L57C25
113+
# api-level: 31
114+
# arch: arm64-v8a
115+
# working-directory: packages/celest_auth/example
116+
# script: flutter test -d emulator integration_test
117+
# - name: Test (API 21)
118+
# uses: ReactiveCircus/android-emulator-runner@62dbb605bba737720e10b196cb4220d374026a6d # 2.33.0
119+
# with:
120+
# # Minimum supported API level
121+
# # Should match build.gradle: https://github.com/celest-dev/celest/blob/main/packages/native/storage/android/build.gradle#L49
122+
# api-level: 21
123+
# arch: arm64-v8a
124+
# working-directory: packages/celest_auth/example
125+
# script: flutter test -d emulator integration_test
126+
test_linux:
127+
needs: [test]
128+
runs-on: ubuntu-latest
129+
timeout-minutes: 15
130+
steps:
131+
- name: Git Checkout
132+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
133+
- name: Setup Flutter
134+
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # 2.18.0
135+
with:
136+
cache: true
137+
- name: Install Build Dependencies
138+
run: |
139+
sudo apt-get update && \
140+
sudo apt-get install -y clang cmake git ninja-build pkg-config libgtk-3-dev liblzma-dev libstdc++-12-dev
141+
- name: Setup Test Environment
142+
run: tool/setup-ci.sh
143+
- name: Get Packages
144+
working-directory: apps/cli
145+
run: dart pub get
146+
- name: Get Packages (Example)
49147
working-directory: packages/celest_auth/example
50-
run: flutter build web
148+
run: flutter pub get
149+
- name: Integration Test (Linux)
150+
working-directory: packages/celest_auth/example
151+
run: |
152+
# Headless tests require virtual display for the linux tests to run.
153+
export DISPLAY=:99
154+
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
155+
dart run $CELEST start --verbose -- flutter test -d linux integration_test
156+
test_windows:
157+
needs: [test]
158+
runs-on: windows-latest
159+
timeout-minutes: 15
160+
steps:
161+
- name: Git Checkout
162+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
163+
- name: Setup Flutter
164+
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # 2.18.0
165+
with:
166+
cache: true
167+
- name: Get Packages
168+
working-directory: apps/cli
169+
run: dart pub get
170+
- name: Get Packages (Example)
171+
working-directory: packages/celest_auth/example
172+
run: flutter pub get
173+
- name: Test (Windows)
174+
working-directory: packages/celest_auth/example
175+
run: dart run "$CELEST" start --verbose -- flutter test -d windows integration_test
176+
test_web:
177+
needs: [test]
178+
runs-on: ubuntu-latest
179+
timeout-minutes: 10
180+
steps:
181+
- name: Git Checkout
182+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # 4.2.2
183+
- name: Setup Flutter
184+
uses: subosito/flutter-action@f2c4f6686ca8e8d6e6d0f28410eeef506ed66aff # 2.18.0
185+
with:
186+
cache: true
187+
- name: Setup Chromedriver
188+
uses: nanasess/setup-chromedriver@v2
189+
- name: Get Packages
190+
working-directory: apps/cli
191+
run: dart pub get
192+
- name: Get Packages (Example)
193+
working-directory: packages/celest_auth/example
194+
run: flutter pub get
195+
- name: Start Chromedriver
196+
run: |
197+
# Headless tests require virtual display for the chromedriver tests to run.
198+
export DISPLAY=:99
199+
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 &
200+
201+
chromedriver --port=4444 &
202+
- name: Test (Web/JS)
203+
working-directory: packages/celest_auth/example
204+
run: |
205+
dart run "$CELEST" start --verbose -- \
206+
flutter drive \
207+
--driver=test_driver/integration_test.dart \
208+
--target=integration_test/integration_test.dart \
209+
-d web-server \
210+
--debug \
211+
--browser-name=chrome \
212+
--no-headless
213+
- name: Test (Web/WASM)
214+
working-directory: packages/celest_auth/example
215+
run: |
216+
dart run "$CELEST" start --verbose -- \
217+
flutter drive \
218+
--driver=test_driver/integration_test.dart \
219+
--target=integration_test/integration_test.dart \
220+
-d web-server \
221+
--debug \
222+
--browser-name=chrome \
223+
--no-headless \
224+
--wasm

packages/celest_auth/example/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
*.swp
66
.DS_Store
77
.atom/
8+
.build/
89
.buildlog/
910
.history
1011
.svn/
12+
.swiftpm/
1113
migrate_working_dir/
1214

1315
# IntelliJ related

packages/celest_auth/example/android/.gitignore

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/celest_auth/example/android/gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/celest_auth/example/android/settings.gradle

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/celest_auth/example/celest/client/lib/celest_auth_example_client.dart

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ enum CelestEnvironment {
2727

2828
Uri get baseUri => switch (this) {
2929
local => _$celest.kIsWeb || !Platform.isAndroid
30-
? Uri.parse('http://localhost:51375')
31-
: Uri.parse('http://10.0.2.2:51375'),
30+
? Uri.parse('http://localhost:61552')
31+
: Uri.parse('http://10.0.2.2:61552'),
3232
};
3333
}
3434

@@ -48,7 +48,7 @@ class Celest with _$celest.CelestBase {
4848

4949
final _functions = CelestFunctions();
5050

51-
late final CelestAuth _auth = CelestAuth(
51+
late CelestAuth _auth = CelestAuth(
5252
this,
5353
storage: nativeStorage,
5454
);
@@ -75,15 +75,22 @@ class Celest with _$celest.CelestBase {
7575
CelestEnvironment environment = CelestEnvironment.local,
7676
_$celest.Serializers? serializers,
7777
}) {
78-
if (_initialized && environment != _currentEnvironment) {
79-
_auth.signOut();
78+
if (_initialized) {
79+
_reset();
8080
}
8181
_currentEnvironment = environment;
8282
_baseUri = environment.baseUri;
83-
scheduleMicrotask(_auth.init);
84-
if (!_initialized) {
85-
initSerializers(serializers: serializers);
86-
}
83+
scheduleMicrotask(() => _auth.init());
84+
initSerializers(serializers: serializers);
8785
_initialized = true;
8886
}
87+
88+
void _reset() {
89+
_auth.close().ignore();
90+
_auth = CelestAuth(
91+
this,
92+
storage: nativeStorage,
93+
);
94+
_initialized = false;
95+
}
8996
}

packages/celest_auth/example/celest/client/pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ description: The Celest client for celest_auth_example.
33
publish_to: none
44

55
environment:
6-
sdk: ^3.4.0
6+
sdk: ^3.5.0
77

88
dependencies:
99
celest: ^1.0.0
1010
celest_backend:
1111
path: ../
1212
celest_core: ^1.0.0
1313
http: ^1.0.0
14+
meta: ^1.12.0
1415
native_storage: ^0.2.2
1516

1617
dev_dependencies:
17-
lints: ^4.0.0
18+
lints: ^5.0.0
1819
test: ^1.25.0
1920
dependency_overrides:
2021
celest:

packages/celest_auth/example/celest/lib/src/generated/auth.celest.dart

Lines changed: 12 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22
// it can be checked into version control.
33
// ignore_for_file: type=lint, unused_local_variable, unnecessary_cast, unnecessary_import, deprecated_member_use, invalid_use_of_internal_member
44

5-
library;
5+
library; // ignore_for_file: no_leading_underscores_for_library_prefixes
66

7-
import 'package:celest/celest.dart';
8-
import 'package:celest/src/core/context.dart';
9-
import 'package:celest_cloud_auth/celest_cloud_auth.dart';
10-
import 'package:drift/native.dart';
11-
import 'package:drift/src/runtime/api/runtime_api.dart';
12-
import 'package:drift/src/runtime/executor/executor.dart';
13-
import 'package:drift_hrana/drift_hrana.dart';
7+
import 'package:celest/celest.dart' as _$celest;
8+
import 'package:celest/src/core/context.dart' as _$celest;
9+
import 'package:celest/src/runtime/data/connect.dart' as _$celest;
10+
import 'package:celest_cloud_auth/celest_cloud_auth.dart' as _$celest;
1411

1512
/// The auth service for the Celest backend.
1613
///
@@ -20,59 +17,22 @@ class CelestAuth {
2017
const CelestAuth();
2118

2219
/// Initializes the Celest Auth service in the given [context].
23-
static Future<void> init(Context context) async {
24-
final database = await _connect(
20+
static Future<void> init(_$celest.Context context) async {
21+
final database = await _$celest.connect(
2522
context,
2623
name: 'CelestAuthDatabase',
27-
factory: AuthDatabase.new,
28-
hostnameVariable: const env('CELEST_AUTH_DATABASE_HOST'),
29-
tokenSecret: const secret('CELEST_AUTH_DATABASE_TOKEN'),
24+
factory: _$celest.AuthDatabase.new,
25+
hostnameVariable: const _$celest.env('CELEST_AUTH_DATABASE_HOST'),
26+
tokenSecret: const _$celest.secret('CELEST_AUTH_DATABASE_TOKEN'),
3027
);
31-
final service = await CelestCloudAuth.create(database: database);
28+
final service = await _$celest.CelestCloudAuth.create(database: database);
3229
context.router.mount(
3330
'/v1alpha1/auth/',
3431
service.handler,
3532
);
3633
context.put(
37-
CelestCloudAuth.contextKey,
34+
_$celest.CelestCloudAuth.contextKey,
3835
service,
3936
);
4037
}
4138
}
42-
43-
/// Checks the connection to the database by running a simple query.
44-
Future<Database> _checkConnection<Database extends GeneratedDatabase>(
45-
Database db) async {
46-
await db.transaction(() async {
47-
await db.customSelect('SELECT 1').get();
48-
});
49-
return db;
50-
}
51-
52-
/// Constructs a new [Database] and connects to it using the provided
53-
/// [hostnameVariable] and [tokenSecret] configuration values.
54-
Future<Database> _connect<Database extends GeneratedDatabase>(
55-
Context context, {
56-
required String name,
57-
required Database Function(QueryExecutor) factory,
58-
required env hostnameVariable,
59-
required secret tokenSecret,
60-
}) async {
61-
if (context.environment == Environment.local) {
62-
return _checkConnection(factory(NativeDatabase.memory()));
63-
}
64-
final host = context.get(hostnameVariable);
65-
final token = context.get(tokenSecret);
66-
if (host == null || token == null) {
67-
throw StateError(
68-
'Missing database hostname or token for $name. '
69-
'Please set the `$hostnameVariable` and `$tokenSecret` values '
70-
'in the environment or Celest configuration file.',
71-
);
72-
}
73-
final connector = HranaDatabase(
74-
Uri(scheme: 'libsql', host: host),
75-
jwtToken: token,
76-
);
77-
return _checkConnection(factory(connector));
78-
}

0 commit comments

Comments
 (0)