Skip to content

Commit cfad62c

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

File tree

26 files changed

+443
-129
lines changed

26 files changed

+443
-129
lines changed

.github/workflows/celest_auth.yaml

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