Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

fix(mobile): point Sign in a computer to harness login --qr

tony73c72e813a70
diff --git a/mobile/lib/phone/approve_sign_in.dart b/mobile/lib/phone/approve_sign_in.dart
index 7808a890c..df840180e 100644
--- a/mobile/lib/phone/approve_sign_in.dart
+++ b/mobile/lib/phone/approve_sign_in.dart
@@ -17,7 +17,7 @@ import 'tty.dart';
import 'welcome/connect_code.dart';
import 'welcome/scan_to_connect.dart';
-/// Settings ▸ Sign in a computer: scan the QR a computer shows (`harness login`, or the desktop
+/// Settings ▸ Sign in a computer: scan the QR a computer shows (`harness login --qr`, or the web
/// app's "Scan with your phone") and approve its sign-in with this phone's account.
///
/// Approving hands that computer the account's terminals — signing in is what makes the account's
diff --git a/mobile/lib/phone/settings_page.dart b/mobile/lib/phone/settings_page.dart
index 87bafb89a..000addb65 100644
--- a/mobile/lib/phone/settings_page.dart
+++ b/mobile/lib/phone/settings_page.dart
@@ -204,7 +204,7 @@ class _Body extends StatelessWidget {
),
// Every device signed in to the account — each trusted by the others because of that, so
// this is where one that is not yours is seen and taken out.
- // A computer showing its sign-in QR (`harness login`, or the desktop app's "Scan with your
+ // A computer showing its sign-in QR (`harness login --qr`, or the web app's "Scan with your
// phone"): this phone approves it with its own account.
SettingsRow(
key: const Key('settings-sign-in-computer'),
diff --git a/mobile/lib/phone/welcome/scan_to_connect.dart b/mobile/lib/phone/welcome/scan_to_connect.dart
index 2d5bb92e2..a309b08e6 100644
--- a/mobile/lib/phone/welcome/scan_to_connect.dart
+++ b/mobile/lib/phone/welcome/scan_to_connect.dart
@@ -471,6 +471,9 @@ Future<ConnectCode?> scanForCode(
/// The camera over the current page, for a computer's sign-in QR only — Settings ▸ Sign in a
/// computer. Null when the person went back.
+///
+/// The steps name the terminal's way only: the desktop app signs in on its own page and no longer
+/// shows a QR, so this is for a server or a computer without the app, `harness login --qr`.
Future<SignInCode?> scanForSignIn(BuildContext context, {Widget? camera}) async {
SignInCode? scanned;
await Navigator.of(context).push(
@@ -480,8 +483,8 @@ Future<SignInCode?> scanForSignIn(BuildContext context, {Widget? camera}) async
body: SafeArea(
child: ScanToConnectPage(
camera: camera,
- title: 'Scan the code on the computer',
- step: 'On the computer: Sign in ▸ Scan with your phone',
+ title: 'Scan the code in the terminal',
+ step: 'On a server, run harness login --qr',
fallbackLabel: 'Not now',
acceptConnectCodes: false,
onCode: (_) {},
diff --git a/mobile/test/approve_sign_in_test.dart b/mobile/test/approve_sign_in_test.dart
index f825e9960..75632cb63 100644
--- a/mobile/test/approve_sign_in_test.dart
+++ b/mobile/test/approve_sign_in_test.dart
@@ -5,6 +5,7 @@ import 'package:harness_mobile/auth/auth_session.dart';
import 'package:harness_mobile/core/config.dart';
import 'package:harness_mobile/phone/approve_sign_in.dart';
import 'package:harness_mobile/phone/welcome/connect_code.dart';
+import 'package:harness_mobile/phone/welcome/scan_to_connect.dart';
import 'package:harness_mobile/state/app_state.dart';
/// Answers the QR sign-in routes from a script, and records what the phone said.
@@ -12,10 +13,14 @@ class _Api extends ApiClient {
_Api(this.asking) : super(config: AppConfig.dev, session: AuthSession());
final Map<String, dynamic> asking;
+ final looked = <String>[];
final answers = <String>[];
@override
- Future<Map<String, dynamic>> signInLookup(String code) async => asking;
+ Future<Map<String, dynamic>> signInLookup(String code) async {
+ looked.add(code);
+ return asking;
+ }
@override
Future<void> approveSignIn(String code) async => answers.add('approve:$code');
@override
@@ -92,4 +97,69 @@ void main() {
expect(find.byKey(const Key('approve-sign-in-title')), findsNothing);
expect(api.answers, isEmpty);
});
+
+ group('Settings ▸ Sign in a computer', () {
+ /// Settings' row opening the camera — [signInAComputer] with no real camera behind it.
+ Future<_Api> open(WidgetTester tester, {Size size = const Size(430, 932)}) async {
+ tester.view.devicePixelRatio = 1;
+ tester.view.physicalSize = size;
+ addTearDown(tester.view.reset);
+ final app = AppNotifier(config: AppConfig.dev, authSession: AuthSession(), configStore: null);
+ addTearDown(app.dispose);
+ final api = _Api({'label': 'build-box', 'kind': 'computer', 'sameNetwork': true, 'status': 'pending'});
+ app.api = api;
+ await tester.pumpWidget(
+ MaterialApp(
+ home: Scaffold(
+ body: Builder(
+ builder: (context) => TextButton(
+ onPressed: () => signInAComputer(context, app, camera: const SizedBox()),
+ child: const Text('go'),
+ ),
+ ),
+ ),
+ ),
+ );
+ await tester.tap(find.text('go'));
+ await tester.pumpAndSettle();
+ return api;
+ }
+
+ testWidgets('the camera sends the person to a terminal: harness login --qr', (tester) async {
+ await open(tester);
+ expect(find.text('Scan the code in the terminal'), findsOneWidget);
+ expect(find.text('On a server, run harness login --qr'), findsOneWidget);
+ // The desktop app signs in on its own page and shows no QR any more.
+ expect(find.textContaining('Scan with your phone'), findsNothing);
+ });
+
+ testWidgets('on a narrow phone the hint wraps whole rather than running off the screen', (tester) async {
+ await open(tester, size: const Size(320, 568));
+ expect(tester.takeException(), isNull);
+ final hint = tester.getRect(find.byKey(const ValueKey('scan-hint')));
+ expect(hint.left, greaterThanOrEqualTo(0));
+ expect(hint.right, lessThanOrEqualTo(320));
+ expect(hint.bottom, lessThanOrEqualTo(568));
+ });
+
+ testWidgets('a scanned code goes on to the approval', (tester) async {
+ final api = await open(tester);
+ tester.widget<ScanToConnectPage>(find.byType(ScanToConnectPage)).onSignInCode!(SignInCode(_code));
+ await tester.pumpAndSettle();
+ expect(find.byType(ScanToConnectPage), findsNothing);
+ expect(find.text('Sign in build-box?'), findsOneWidget);
+ await tester.tap(find.byKey(const Key('approve-sign-in-approve')));
+ await tester.pumpAndSettle();
+ expect(api.answers, ['approve:$_code']);
+ });
+
+ testWidgets('Not now goes back and asks nothing', (tester) async {
+ final api = await open(tester);
+ await tester.tap(find.text('Not now'));
+ await tester.pumpAndSettle();
+ expect(find.byType(ScanToConnectPage), findsNothing);
+ expect(api.looked, isEmpty);
+ expect(api.answers, isEmpty);
+ });
+ });
}