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.
TypeScript 3d-modelingagent-frameworkagent-harnessai-agentscadclaude-codecodexcoding-agentsdeveloper-toolsesp32game-developmentmcp-servermulti-agentopen-hardwareopencodeopenharnesspcbroboticsterminaltmux
fix(desktop): Settings ▸ Connectors follows a sign-in to the end
bubu-dudueabde6784b85
diff --git a/cli/src/services/connectors.spec.ts b/cli/src/services/connectors.spec.tsindex cd914b447..f588e0432 100644--- a/cli/src/services/connectors.spec.ts+++ b/cli/src/services/connectors.spec.ts@@ -7,6 +7,7 @@ import { fakeCore } from '../testing/fakeCore.js'import { CONNECTORS_REQUESTS, startConnectors } from './connectors.js'import { Store } from '../lib/connectors/store.js'import * as gateway from '../lib/connectors/gateway.js'+import { FakeGateway } from '../testing/connectorServers.js'const OWNER = { local: true, owner: true }@@ -64,6 +65,29 @@ describe('the connectors service', () => {expect(started).toMatchObject({ error: 'CONNECTORS_FAILED', detail: expect.stringContaining('reach') })})+ it('says how a gateway sign-in goes without ever an `error` key, which the desktop reads as the request failing', async () => {+ const fake = await new FakeGateway().start()+ const original = { ...gateway.backend }+ Object.assign(gateway.backend, { signedIn: () => true, base: async () => fake.base, headers: async () => ({ authorization: 'Bearer harness-session' }) })+ try {+ const vault = new Store(join(home, 'store'), env)+ const requests = startConnectors(fakeCore(), { vault, env, port: 0 })+ const ask = (flow: string) => requests.connectors!({ action: 'flow', flow }, OWNER) as Promise<Record<string, unknown>>+ const started = await requests.connectors!({ action: 'connect', connector: 'github' }, OWNER) as { flow: string }+ const seen: Record<string, unknown>[] = [await ask(started.flow)]+ while (seen.at(-1)!.state === 'pending') { await new Promise(resolve => setTimeout(resolve, 100)); seen.push(await ask(started.flow)) }+ expect(seen[0]).toEqual({ connector: 'github', state: 'pending' })+ expect(seen.at(-1)).toEqual({ connector: 'github', state: 'connected' })+ expect(vault.token('github')).toMatchObject({ source: 'gateway' })+ fake.polls = 0+ const again = await requests.connectors!({ action: 'connect', connector: 'github' }, OWNER) as { flow: string }+ fake.fail = { status: 400, code: 'BAD', message: 'The service said no.' }+ let failed = await ask(again.flow)+ while (failed.state === 'pending') { await new Promise(resolve => setTimeout(resolve, 100)); failed = await ask(again.flow) }+ expect(failed).toEqual({ connector: 'github', state: 'failed', reason: 'The service said no.' })+ } finally { Object.assign(gateway.backend, original); fake.close() }+ }, 15_000)+it('a failure that is not a connection\'s own says only that connections are unavailable', async () => {const vault = new Store(join(home, 'store'), env)const requests = startConnectors(fakeCore(), { vault, env, port: 0, offered: async () => { throw new Error('boom') } })diff --git a/cli/src/services/connectors.ts b/cli/src/services/connectors.tsindex b3a8911d1..57b452243 100644--- a/cli/src/services/connectors.ts+++ b/cli/src/services/connectors.ts@@ -64,7 +64,12 @@ export function startConnectors(_core: CoreApi, overrides: Partial<ConnectorsDepconst code = validateCode(payload.connector)return { ...(await flows.start(code, signInFor(vault, code, services(await gatewayOffers())))) }}- case 'flow': return { ...flows.get(String(payload.flow ?? '')) }+ case 'flow': {+ // Never an `error` key on an answer: the desktop's socket reads one, even empty, as the request+ // failing, and would never see the sign-in finish. Why one failed rides as `reason`.+ const { connector, state, error } = flows.get(String(payload.flow ?? ''))+ return { connector, state, ...(error ? { reason: error } : {}) }+ }case 'disconnect': {const code = validateCode(payload.connector)await disconnect(vault, code, env)diff --git a/desktop/lib/connectors/connectors_controller.dart b/desktop/lib/connectors/connectors_controller.dartindex dd3613651..cc417f46a 100644--- a/desktop/lib/connectors/connectors_controller.dart+++ b/desktop/lib/connectors/connectors_controller.dart@@ -78,8 +78,7 @@ class ConnectorsController extends ChangeNotifier {final Set<String> pending = {};bool _disposed = false;- String? get _target =>- machineId ?? app.localMachineState?.machine.machineId;+ String? get _target => machineId ?? app.localMachineState?.machine.machineId;Future<Map<String, dynamic>> _ask(Map<String, dynamic> payload) async {final target = _target;@@ -87,7 +86,7 @@ class ConnectorsController extends ChangeNotifier {final answer = await app.connectors(target, payload);final failure = answer['error'];if (failure != null) {- throw StateError(+ throw _Refused(answer['detail'] as String? ??(failure == 'SERVICE_UNAVAILABLE' || failure == 'UNSUPPORTED'? 'Update Harness on this computer to use Connectors.'@@ -132,6 +131,12 @@ class ConnectorsController extends ChangeNotifier {} finally {pending.remove(card.code);await refresh();+ // Back from the browser, the link to the computer may still be coming back: the card shows the+ // new connection as soon as it answers, not on the next manual refresh.+ for (var i = 0; error != null && !_disposed && i < 5; i++) {+ await Future<void>.delayed(pollEvery);+ await refresh();+ }}}@@ -144,18 +149,31 @@ class ConnectorsController extends ChangeNotifier {final flow = started['flow'] as String?;if (flow == null) return;final deadline = DateTime.now().add(_signInFor);+ Object? lastError;while (!_disposed && DateTime.now().isBefore(deadline)) {await Future<void>.delayed(pollEvery);- final status = await _ask({'action': 'flow', 'flow': flow});+ final Map<String, dynamic> status;+ try {+ status = await _ask({'action': 'flow', 'flow': flow});+ } on _Refused {+ rethrow;+ } catch (e) {+ // The link to the computer can drop for a moment while the person is in the browser signing in;+ // the sign-in goes on in the daemon all the same. Ask again rather than give up on it.+ lastError = e;+ continue;+ }if (status['state'] == 'connected') {notice = '$name connected. Your agents can use it now.';return;}if (status['state'] == 'failed') {- notice = '$name: ${status['error'] ?? 'The sign-in did not finish.'}';+ // `reason`, not `error`: a reply carrying `error` never reaches here (WsConn reads it as a failure).+ notice = '$name: ${status['reason'] ?? 'The sign-in did not finish.'}';return;}}+ if (lastError != null) throw lastError;}Future<void> disconnect(ConnectorCard card) async {@@ -183,9 +201,11 @@ class ConnectorsController extends ChangeNotifier {});if (started['flow'] != null) {unawaited(- _follow(name, started).catchError((Object e) {- notice = '$name: ${_message(e)}';- }).whenComplete(refresh),+ _follow(name, started)+ .catchError((Object e) {+ notice = '$name: ${_message(e)}';+ })+ .whenComplete(refresh),);} else {notice = '$name added. Your agents can use it now.';@@ -197,8 +217,11 @@ class ConnectorsController extends ChangeNotifier {}}- static String _message(Object e) =>- e is StateError ? e.message : 'Connections are unavailable. Try again.';+ static String _message(Object e) => switch (e) {+ _Refused(:final message) => message,+ StateError(:final message) => message,+ _ => 'Connections are unavailable. Try again.',+ };@overridevoid dispose() {@@ -206,3 +229,13 @@ class ConnectorsController extends ChangeNotifier {super.dispose();}}++/// The computer answered, and said no: a reason to stop, unlike a request that did not get through.+class _Refused implements Exception {+ const _Refused(this.message);++ final String message;++ @override+ String toString() => message;+}diff --git a/desktop/test/connectors_section_test.dart b/desktop/test/connectors_section_test.dartindex f2f9420b2..3d5e17fc3 100644--- a/desktop/test/connectors_section_test.dart+++ b/desktop/test/connectors_section_test.dart@@ -1,3 +1,5 @@+import 'dart:async';+import 'package:flutter/material.dart';import 'package:flutter_test/flutter_test.dart';import 'package:harness/connectors/connector_icons.dart';@@ -15,6 +17,7 @@ class _ConnectorsApp extends ModelManagerTestApp {final requests = <Map<String, dynamic>>[];bool gridSignedIn = false;final connected = <String>{};+ final flowScript = <Object>[];Map<String, dynamic> _card(String code, String name, String auth) => {'connector': code,@@ -46,10 +49,20 @@ class _ConnectorsApp extends ModelManagerTestApp {],};case 'connect':- return {'flow': 'flow-1', 'authorize_url': 'https://linear.app/oauth/authorize?x=1'};+ return {+ 'flow': 'flow-1',+ 'authorize_url': 'https://linear.app/oauth/authorize?x=1',+ };case 'flow':+ // What each poll meets, in turn: an answer, or the request failing on the way.+ if (flowScript.isNotEmpty) {+ final next = flowScript.removeAt(0);+ if (next is Exception) throw next;+ return next as Map<String, dynamic>;+ }connected.add('linear');- return {'connector': 'linear', 'state': 'connected', 'error': ''};+ // As the daemon answers: never an `error` key, which WsConn reads as the request failing.+ return {'connector': 'linear', 'state': 'connected'};case 'disconnect':connected.remove(payload['connector']);return {'connector': payload['connector'], 'state': 'not_connected'};@@ -64,7 +77,10 @@ void main() {late List<Uri> opened;setUp(() {opened = [];- browserOpener = (url) async { opened.add(url); return true; };+ browserOpener = (url) async {+ opened.add(url);+ return true;+ };ConnectorsController.pollEvery = Duration.zero;});@@ -73,31 +89,80 @@ void main() {tester.view.physicalSize = const Size(1200, 900);tester.view.devicePixelRatio = 1;addTearDown(tester.view.reset);- await tester.pumpWidget(MaterialApp(home: Scaffold(body: ConnectorsSection(notifier: app))));+ await tester.pumpWidget(+ MaterialApp(+ home: Scaffold(body: ConnectorsSection(notifier: app)),+ ),+ );await tester.pumpAndSettle();return app;}- testWidgets('lists every service; signed out, the Harness account ones wait for harness login', (tester) async {- await pump(tester);- expect(find.text('Connectors'), findsOneWidget);- for (final name in ['Linear', 'GitHub', 'Notion']) {- expect(find.text(name), findsOneWidget);- }- expect(find.text('Needs harness login'), findsOneWidget);- expect(find.textContaining('Run harness login'), findsOneWidget);- expect(find.text('AVAILABLE 3'), findsOneWidget);- });+ testWidgets(+ 'lists every service; signed out, the Harness account ones wait for harness login',+ (tester) async {+ await pump(tester);+ expect(find.text('Connectors'), findsOneWidget);+ for (final name in ['Linear', 'GitHub', 'Notion']) {+ expect(find.text(name), findsOneWidget);+ }+ expect(find.text('Needs harness login'), findsOneWidget);+ expect(find.textContaining('Run harness login'), findsOneWidget);+ expect(find.text('AVAILABLE 3'), findsOneWidget);+ },+ );++ testWidgets(+ 'a sign-in opens the service in the browser and is followed until it is connected',+ (tester) async {+ final app = await pump(tester);+ await tester.tap(find.byTooltip('Connect Linear'));+ await tester.pumpAndSettle();+ expect(opened.single.host, 'linear.app');+ expect(+ app.requests.map((r) => r['action']),+ containsAllInOrder(['connect', 'flow', 'list']),+ );+ expect(find.text('CONNECTED 1'), findsOneWidget);+ expect(find.text('Signed in'), findsOneWidget);+ expect(+ find.text('Linear connected. Your agents can use it now.'),+ findsOneWidget,+ );+ },+ );++ testWidgets(+ 'a poll lost on the way while the person is in the browser does not end following the sign-in',+ (tester) async {+ final app = await pump(tester);+ app.flowScript.addAll([+ {'connector': 'linear', 'state': 'pending'},+ TimeoutException('WS request timed out: connectors'),+ StateError('Reconnect this computer to manage its connections.'),+ ]);+ await tester.tap(find.byTooltip('Connect Linear'));+ await tester.pumpAndSettle();+ expect(app.requests.where((r) => r['action'] == 'flow'), hasLength(4));+ expect(find.text('CONNECTED 1'), findsOneWidget);+ expect(+ find.text('Linear connected. Your agents can use it now.'),+ findsOneWidget,+ );+ },+ );- testWidgets('a sign-in opens the service in the browser and is followed until it is connected', (tester) async {+ testWidgets('a sign-in that failed says why, from `reason`', (tester) async {final app = await pump(tester);+ app.flowScript.add({+ 'connector': 'linear',+ 'state': 'failed',+ 'reason': 'The service said no.',+ });await tester.tap(find.byTooltip('Connect Linear'));await tester.pumpAndSettle();- expect(opened.single.host, 'linear.app');- expect(app.requests.map((r) => r['action']), containsAllInOrder(['connect', 'flow', 'list']));- expect(find.text('CONNECTED 1'), findsOneWidget);- expect(find.text('Signed in'), findsOneWidget);- expect(find.text('Linear connected. Your agents can use it now.'), findsOneWidget);+ expect(find.text('Linear: The service said no.'), findsOneWidget);+ expect(find.text('CONNECTED 0'), findsOneWidget);});testWidgets('disconnect asks first', (tester) async {@@ -111,13 +176,21 @@ void main() {await tester.tap(find.widgetWithText(FilledButton, 'Disconnect'));await tester.pumpAndSettle();expect(app.requests.last['action'], 'list');- expect(app.requests.any((r) => r['action'] == 'disconnect' && r['connector'] == 'notion'), isTrue);+ expect(+ app.requests.any(+ (r) => r['action'] == 'disconnect' && r['connector'] == 'notion',+ ),+ isTrue,+ );expect(find.text('CONNECTED 0'), findsOneWidget);});testWidgets('search and the Connected pill narrow the list', (tester) async {await pump(tester);- await tester.enterText(find.byKey(const ValueKey('connectors-search')), 'notion');+ await tester.enterText(+ find.byKey(const ValueKey('connectors-search')),+ 'notion',+ );await tester.pumpAndSettle();expect(find.text('Linear'), findsNothing);expect(find.text('Notion'), findsOneWidget);@@ -126,18 +199,29 @@ void main() {expect(find.text('Notion'), findsNothing);});- testWidgets('Add custom sends a remote server with its headers', (tester) async {+ testWidgets('Add custom sends a remote server with its headers', (+ tester,+ ) async {final app = await pump(tester);await tester.tap(find.byKey(const ValueKey('connectors-add-custom')));await tester.pumpAndSettle();await tester.enterText(find.byKey(const ValueKey('custom-name')), 'Mine');- await tester.enterText(find.byKey(const ValueKey('custom-url')), 'https://mine.example/mcp');+ await tester.enterText(+ find.byKey(const ValueKey('custom-url')),+ 'https://mine.example/mcp',+ );await tester.tap(find.text('Continue'));await tester.pumpAndSettle();expect(app.requests.firstWhere((r) => r['action'] == 'custom'), {- 'action': 'custom', 'name': 'Mine', 'url': 'https://mine.example/mcp', 'headers': <String, String>{},+ 'action': 'custom',+ 'name': 'Mine',+ 'url': 'https://mine.example/mcp',+ 'headers': <String, String>{},});- expect(find.text('Mine added. Your agents can use it now.'), findsOneWidget);+ expect(+ find.text('Mine added. Your agents can use it now.'),+ findsOneWidget,+ );});test('bundles an icon for the services', () {