halkyon_app: instances, sign-in and sync plumbing for Halkyon's apps

What every Halkyon app's shell needs, taken from Halkyon Learn's and set
on halkyon_base's client: the instances a device keeps an account on,
the first start's tiles and where an instance keeps people's data, the
account switcher; signing in anonymously, with GitHub or an email code,
switching person and the start screen; the gates that build an app's
dependencies per instance and per person; and the sync service with its
status, Settings card and banner. Texts of its own in English and
German take the app's name; what only the app can say, it passes in.
Fakes for apps' tests are in testing.dart.

An instance's basics now name the app it serves (`app`, set by the
host's configuration), and an app accepts only an instance of its own.
SerialQueue and CoalescingRunner move into halkyon_core.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
This commit is contained in:
Tizian 「ティツィアーン」 2026-10-19 15:18:49 +02:00
commit e23cc77f7c
Signed by: raisondetredev
GPG key ID: 07F6FCF405488B64

View file

@ -0,0 +1,173 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:halkyon_app/halkyon_app.dart';
import 'package:halkyon_app/testing.dart';
import 'package:material_ui/material_ui.dart';
/// A signed-in person's app as a test makes one: whose it is, whether
/// they asked to continue with email, and a way to sign out.
class const _PersonApp(final SignedIn person) extends StatelessWidget {
@override
Widget build(BuildContext context) => MaterialApp(
localizationsDelegates: testLocalizationsDelegates,
supportedLocales: HalkyonAppLocalizations.supportedLocales,
home: Scaffold(
body: Builder(
builder: (context) => Column(
children: [
Text('App of ${person.authUserId}'),
if (context.watch<SessionBloc>().state case SessionStateActive(
signsInWithEmail: true,
))
const Text('Asks for the address'),
TextButton(
onPressed: () => context.read<SessionBloc>().add(
const SessionEventSignOutRequested(),
),
child: const Text('Sign out'),
),
],
),
),
),
);
}
void main() {
late FakeAuthGateway gateway;
late TestAppDependencies dependencies;
setUp(() {
gateway = FakeAuthGateway();
dependencies = TestAppDependencies(gateway: gateway);
});
Future<void> start(WidgetTester tester) async {
await tester.pumpWidget(
AppFrameScope(
frame: testFrame(),
child: AppScope(
dependencies: dependencies,
child: SessionGate(
look: (context) => (themeMode: ThemeMode.light, locale: null),
app: _PersonApp.new,
),
),
),
);
await tester.pumpAndSettle();
}
testWidgets('shows the app once signed in anonymously at a first start', (
tester,
) async {
await start(tester);
expect(find.text('App of anonymous-1'), findsOneWidget);
});
testWidgets('offers to try again when signing in fails', (tester) async {
gateway.signInError = Exception('No connection');
await start(tester);
expect(find.text("Couldn't reach the server."), findsOneWidget);
gateway.signInError = null;
await tester.tap(find.text('Try again'));
await tester.pumpAndSettle();
expect(find.text('App of anonymous-2'), findsOneWidget);
});
testWidgets('signed out, it asks how to start on the instance, making no '
'account; starting without one makes one', (tester) async {
await dependencies.signedOut.write(signedOut: true);
await start(tester);
expect(find.text('Signed out'), findsOneWidget);
expect(find.text('Start on test.example.org:'), findsOneWidget);
expect(find.text('Sign in with GitHub'), findsOneWidget);
expect(find.text('Continue with email'), findsOneWidget);
expect(
find.text('Use another instance'),
findsNothing,
reason: 'no instances to choose among here',
);
expect(gateway.signIns, 0);
await tester.tap(find.text('Start without an account'));
await tester.pumpAndSettle();
expect(find.text('App of anonymous-1'), findsOneWidget);
expect(dependencies.signedOut.signedOut, isFalse);
});
testWidgets('from there, GitHub signs in its person; a GitHub account '
'nobody here has yet is said so', (tester) async {
await dependencies.signedOut.write(signedOut: true);
await start(tester);
gateway.gitHubError = const GitHubSignInFailed(
GitHubSignInProblem.unknownAccount,
);
await tester.tap(find.text('Sign in with GitHub'));
await tester.pumpAndSettle();
expect(
find.text(
'No account here signs in with this GitHub account yet. Start '
'without an account, then add GitHub in Profile.',
),
findsOneWidget,
);
gateway.gitHubError = null;
await tester.tap(find.text('Sign in with GitHub'));
await tester.pumpAndSettle();
expect(find.text('App of github-person'), findsOneWidget);
expect(gateway.signIns, 0);
});
testWidgets('from there, an email address starts without an account and '
'asks for the address in the app', (tester) async {
await dependencies.signedOut.write(signedOut: true);
await start(tester);
await tester.tap(find.text('Continue with email'));
await tester.pumpAndSettle();
expect(find.text('App of anonymous-1'), findsOneWidget);
expect(find.text('Asks for the address'), findsOneWidget);
});
testWidgets('offers only the ways the instance has', (tester) async {
gateway
..offersGitHub = false
..offersEmail = false;
await dependencies.signedOut.write(signedOut: true);
await start(tester);
expect(find.text('Sign in with GitHub'), findsNothing);
expect(find.text('Continue with email'), findsNothing);
expect(find.text('Start without an account'), findsOneWidget);
});
testWidgets('signing out, or the instance ending the session, asks how to '
'start', (tester) async {
gateway = FakeAuthGateway(
status: const SignedIn(authUserId: 'ada', isIdentified: true),
);
dependencies = TestAppDependencies(gateway: gateway);
await start(tester);
expect(find.text('App of ada'), findsOneWidget);
await tester.tap(find.text('Sign out'));
await tester.pumpAndSettle();
expect(find.text('Signed out'), findsOneWidget);
expect(dependencies.signedOut.signedOut, isTrue);
await tester.tap(find.text('Start without an account'));
await tester.pumpAndSettle();
gateway.revokeSession();
await tester.pumpAndSettle();
expect(find.text('Signed out'), findsOneWidget);
});
}