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>
2026-10-19 15:18:49 +02:00
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
|
import 'package:halkyon_app/halkyon_app.dart';
|
|
|
|
|
import 'package:halkyon_app/testing.dart';
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
|
late FakeAuthGateway gateway;
|
|
|
|
|
late MemorySignedOutMark mark;
|
|
|
|
|
late SessionBloc bloc;
|
|
|
|
|
|
|
|
|
|
SessionStateActive anonymous(int number) => SessionStateActive(
|
|
|
|
|
SignedIn(authUserId: 'anonymous-$number', isIdentified: false),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
void start({AuthStatus status = const SignedOut(), bool signedOut = false}) {
|
|
|
|
|
gateway = FakeAuthGateway(status: status);
|
|
|
|
|
mark = MemorySignedOutMark(signedOut);
|
|
|
|
|
bloc = SessionBloc(AuthRepository(gateway, MemorySignInAddresses()), mark);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tearDown(() => bloc.close());
|
|
|
|
|
|
|
|
|
|
test('signs in anonymously at a first start, nobody having signed out '
|
|
|
|
|
'here', () async {
|
|
|
|
|
start();
|
|
|
|
|
|
|
|
|
|
bloc.add(const SessionEventStarted());
|
|
|
|
|
|
|
|
|
|
await expectLater(
|
|
|
|
|
bloc.stream,
|
|
|
|
|
emitsInOrder([const SessionStateLoading(), anonymous(1)]),
|
|
|
|
|
);
|
|
|
|
|
expect(gateway.signIns, 1);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('keeps a stored session instead of creating a second account', () async {
|
|
|
|
|
const stored = SignedIn(authUserId: 'stored', isIdentified: false);
|
|
|
|
|
start(status: stored);
|
|
|
|
|
|
|
|
|
|
bloc.add(const SessionEventStarted());
|
|
|
|
|
|
|
|
|
|
await expectLater(bloc.stream, emits(const SessionStateActive(stored)));
|
|
|
|
|
expect(gateway.signIns, 0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('reports a failed sign-in and signs in when asked again', () async {
|
|
|
|
|
start();
|
|
|
|
|
gateway.signInError = Exception('No connection');
|
|
|
|
|
|
|
|
|
|
bloc.add(const SessionEventStarted());
|
|
|
|
|
await expectLater(
|
|
|
|
|
bloc.stream,
|
|
|
|
|
emitsInOrder([const SessionStateLoading(), const SessionStateFailed()]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
gateway.signInError = null;
|
|
|
|
|
bloc.add(const SessionEventSignInRequested());
|
|
|
|
|
await expectLater(
|
|
|
|
|
bloc.stream,
|
|
|
|
|
emitsInOrder([const SessionStateLoading(), anonymous(2)]),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('after signing out, asks how to start, making no account; the next '
|
|
|
|
|
'start of the app asks again', () async {
|
|
|
|
|
const stored = SignedIn(authUserId: 'stored', isIdentified: false);
|
|
|
|
|
start(status: stored);
|
|
|
|
|
bloc.add(const SessionEventStarted());
|
|
|
|
|
await expectLater(bloc.stream, emits(const SessionStateActive(stored)));
|
|
|
|
|
|
|
|
|
|
bloc.add(const SessionEventSignOutRequested());
|
|
|
|
|
|
|
|
|
|
await expectLater(
|
|
|
|
|
bloc.stream,
|
|
|
|
|
emitsInOrder([
|
|
|
|
|
const SessionStateLoading(),
|
|
|
|
|
const SessionStateSignedOut(),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
// Signing out of an anonymous account deletes it.
|
|
|
|
|
expect(gateway.accountDeletions, 1);
|
|
|
|
|
expect(gateway.signIns, 0);
|
|
|
|
|
expect(mark.signedOut, isTrue);
|
|
|
|
|
|
|
|
|
|
await bloc.close();
|
|
|
|
|
bloc = SessionBloc(AuthRepository(gateway, MemorySignInAddresses()), mark)
|
|
|
|
|
..add(const SessionEventStarted());
|
|
|
|
|
await expectLater(bloc.stream, emits(const SessionStateSignedOut()));
|
|
|
|
|
expect(gateway.signIns, 0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('starting without an account from there signs in anonymously, and '
|
|
|
|
|
'the device is no longer signed out', () async {
|
|
|
|
|
start(signedOut: true);
|
|
|
|
|
bloc.add(const SessionEventStarted());
|
|
|
|
|
await expectLater(bloc.stream, emits(const SessionStateSignedOut()));
|
|
|
|
|
|
|
|
|
|
bloc.add(const SessionEventStartedAnonymously());
|
|
|
|
|
|
|
|
|
|
await expectLater(
|
|
|
|
|
bloc.stream,
|
|
|
|
|
emitsInOrder([const SessionStateLoading(), anonymous(1)]),
|
|
|
|
|
);
|
|
|
|
|
expect(mark.signedOut, isFalse);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('signing in with GitHub from there switches to its person; '
|
|
|
|
|
'cancelled, it asks again', () async {
|
|
|
|
|
start(signedOut: true);
|
|
|
|
|
bloc.add(const SessionEventStarted());
|
|
|
|
|
await expectLater(bloc.stream, emits(const SessionStateSignedOut()));
|
|
|
|
|
|
|
|
|
|
bloc.add(const SessionEventGitHubRequested());
|
|
|
|
|
|
fix(auth)!: a first password takes a fresh proof of the account's way in
The fourth reading's first finding: password.set took a session alone,
so whoever took one made a GitHub-only account, or an address account
without a password, theirs for good (their address or password, their
authenticator; GitHub then refused the owner).
- An account with an address proves it anew: a code mailed to that
address for this (EmailCodePurpose.firstPassword, its own mail), never
the session alone, a code asked for anything else, or another address.
- An account that signs in with GitHub alone does it within 10 minutes of
a GitHub sign-in (the session's method and creation time, where the
session lives; members tell the register), refused signInAgain before
any code is used; the address it adds is proved as before.
- Anonymous people still become identified with a code to the address
they add.
The app mails the code to the person's own address (asking for it where
the device doesn't know it), offers a password right after a GitHub
sign-in (D2's "at their next sign-in") before the person's app, and asks
for a GitHub sign-in anew when the instance refuses an older one, keeping
the code typed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-21 11:31:22 +02:00
|
|
|
// A password is offered first (ADR 0017, D2), then the person's app.
|
|
|
|
|
const person = SignedIn(authUserId: 'github-person', isIdentified: true);
|
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>
2026-10-19 15:18:49 +02:00
|
|
|
await expectLater(
|
|
|
|
|
bloc.stream,
|
fix(auth)!: a first password takes a fresh proof of the account's way in
The fourth reading's first finding: password.set took a session alone,
so whoever took one made a GitHub-only account, or an address account
without a password, theirs for good (their address or password, their
authenticator; GitHub then refused the owner).
- An account with an address proves it anew: a code mailed to that
address for this (EmailCodePurpose.firstPassword, its own mail), never
the session alone, a code asked for anything else, or another address.
- An account that signs in with GitHub alone does it within 10 minutes of
a GitHub sign-in (the session's method and creation time, where the
session lives; members tell the register), refused signInAgain before
any code is used; the address it adds is proved as before.
- Anonymous people still become identified with a code to the address
they add.
The app mails the code to the person's own address (asking for it where
the device doesn't know it), offers a password right after a GitHub
sign-in (D2's "at their next sign-in") before the person's app, and asks
for a GitHub sign-in anew when the instance refuses an older one, keeping
the code typed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-21 11:31:22 +02:00
|
|
|
emitsThrough(const SessionStateGitHubSignedIn(person)),
|
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>
2026-10-19 15:18:49 +02:00
|
|
|
);
|
fix(auth)!: a first password takes a fresh proof of the account's way in
The fourth reading's first finding: password.set took a session alone,
so whoever took one made a GitHub-only account, or an address account
without a password, theirs for good (their address or password, their
authenticator; GitHub then refused the owner).
- An account with an address proves it anew: a code mailed to that
address for this (EmailCodePurpose.firstPassword, its own mail), never
the session alone, a code asked for anything else, or another address.
- An account that signs in with GitHub alone does it within 10 minutes of
a GitHub sign-in (the session's method and creation time, where the
session lives; members tell the register), refused signInAgain before
any code is used; the address it adds is proved as before.
- Anonymous people still become identified with a code to the address
they add.
The app mails the code to the person's own address (asking for it where
the device doesn't know it), offers a password right after a GitHub
sign-in (D2's "at their next sign-in") before the person's app, and asks
for a GitHub sign-in anew when the instance refuses an older one, keeping
the code typed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-21 11:31:22 +02:00
|
|
|
bloc.add(const SessionEventPasswordOfferDone());
|
|
|
|
|
await expectLater(bloc.stream, emits(const SessionStateActive(person)));
|
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>
2026-10-19 15:18:49 +02:00
|
|
|
expect(gateway.signIns, 0);
|
|
|
|
|
expect(mark.signedOut, isFalse);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('a GitHub account nobody here signs in with yet is said so; any '
|
|
|
|
|
'other refusal fails, and nothing is made either way', () async {
|
|
|
|
|
start(signedOut: true);
|
|
|
|
|
bloc.add(const SessionEventStarted());
|
|
|
|
|
await expectLater(bloc.stream, emits(const SessionStateSignedOut()));
|
|
|
|
|
|
|
|
|
|
gateway.gitHubError = const GitHubSignInFailed(
|
|
|
|
|
GitHubSignInProblem.unknownAccount,
|
|
|
|
|
);
|
|
|
|
|
bloc.add(const SessionEventGitHubRequested());
|
|
|
|
|
await expectLater(
|
|
|
|
|
bloc.stream,
|
|
|
|
|
emitsInOrder([
|
|
|
|
|
const SessionStateSignedOut(busy: true),
|
|
|
|
|
const SessionStateSignedOut(problem: SignedOutProblem.noGitHubAccount),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
gateway.gitHubError = const GitHubSignInFailed(GitHubSignInProblem.refused);
|
|
|
|
|
bloc.add(const SessionEventGitHubRequested());
|
|
|
|
|
await expectLater(
|
|
|
|
|
bloc.stream,
|
|
|
|
|
emitsInOrder([
|
|
|
|
|
const SessionStateSignedOut(busy: true),
|
|
|
|
|
const SessionStateSignedOut(problem: SignedOutProblem.failed),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
expect(gateway.signIns, 0);
|
|
|
|
|
expect(gateway.gitHubSwitches, 0);
|
fix(app): GitHub's refusals say why, and no hint adds GitHub where passwords are offered
Where an instance offers password sign-in, GitHub is added to nobody (ADR
0017, D2), yet the start screen still said "then add GitHub" after a GitHub
account nobody has, and every refusal but an unknown account read
"Couldn't sign in with GitHub." (the end-to-end test of 21 Oct).
- The gateway tells from one read of the basics whether GitHub signs in and
whether it is added to people (`gitHubOffer`, in place of
`gitHubClientId`); the GitHub bloc keeps it (`Ready.linking`) for the
profile, with why an attempt failed (`Ready.problem`).
- The instance's `usePassword`, `deprecated` and `ended` become problems of
their own (`gitHubSignInProblemOf`), worded by `gitHubProblemText` and on
the start screen; an anonymous person refused a link is told the GitHub
account is nobody's and offered the password instead.
- Where passwords are offered, the start screen offers an account to create
in place of the app's hint on adding GitHub.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Tizian 「ティツィアーン」 <raisondetredev@pm.me>
2026-10-21 19:19:28 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('an account that signs in with its password now, and GitHub having '
|
|
|
|
|
'ended, are each said so, signing nobody in', () async {
|
|
|
|
|
start(signedOut: true);
|
|
|
|
|
bloc.add(const SessionEventStarted());
|
|
|
|
|
await expectLater(bloc.stream, emits(const SessionStateSignedOut()));
|
|
|
|
|
|
|
|
|
|
gateway.gitHubError = const GitHubSignInFailed(
|
|
|
|
|
GitHubSignInProblem.usePassword,
|
|
|
|
|
);
|
|
|
|
|
bloc.add(const SessionEventGitHubRequested());
|
|
|
|
|
await expectLater(
|
|
|
|
|
bloc.stream,
|
|
|
|
|
emitsInOrder([
|
|
|
|
|
const SessionStateSignedOut(busy: true),
|
|
|
|
|
const SessionStateSignedOut(problem: SignedOutProblem.usePassword),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
gateway.gitHubError = const GitHubSignInFailed(GitHubSignInProblem.ended);
|
|
|
|
|
bloc.add(const SessionEventGitHubRequested());
|
|
|
|
|
await expectLater(
|
|
|
|
|
bloc.stream,
|
|
|
|
|
emitsInOrder([
|
|
|
|
|
const SessionStateSignedOut(busy: true),
|
|
|
|
|
const SessionStateSignedOut(problem: SignedOutProblem.gitHubEnded),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
expect(gateway.signIns, 0);
|
|
|
|
|
expect(gateway.gitHubSwitches, 0);
|
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>
2026-10-19 15:18:49 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('a session the server ended asks how to start too', () async {
|
|
|
|
|
const stored = SignedIn(authUserId: 'github-1', isIdentified: true);
|
|
|
|
|
start(status: stored);
|
|
|
|
|
bloc.add(const SessionEventStarted());
|
|
|
|
|
await expectLater(bloc.stream, emits(const SessionStateActive(stored)));
|
|
|
|
|
|
|
|
|
|
gateway.revokeSession();
|
|
|
|
|
|
|
|
|
|
await expectLater(bloc.stream, emits(const SessionStateSignedOut()));
|
|
|
|
|
expect(gateway.signIns, 0);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
test('deleting the account asks how to start', () async {
|
|
|
|
|
const stored = SignedIn(authUserId: 'github-1', isIdentified: true);
|
|
|
|
|
start(status: stored);
|
|
|
|
|
bloc.add(const SessionEventStarted());
|
|
|
|
|
await expectLater(bloc.stream, emits(const SessionStateActive(stored)));
|
|
|
|
|
|
|
|
|
|
bloc.add(const SessionEventDeleteRequested());
|
|
|
|
|
|
|
|
|
|
await expectLater(
|
|
|
|
|
bloc.stream,
|
|
|
|
|
emitsInOrder([
|
|
|
|
|
const SessionStateLoading(),
|
|
|
|
|
const SessionStateSignedOut(),
|
|
|
|
|
]),
|
|
|
|
|
);
|
|
|
|
|
expect(gateway.accountDeletions, 1);
|
|
|
|
|
expect(gateway.signIns, 0);
|
|
|
|
|
});
|
|
|
|
|
}
|