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
test(mobile): the viewer's services wiring, and a welcome over a malformed key
dee1c4aac3b1892
diff --git a/mobile/test/e2ee/relay_session_crypto_test.dart b/mobile/test/e2ee/relay_session_crypto_test.dartindex 6edfd3e63..5273081e9 100644--- a/mobile/test/e2ee/relay_session_crypto_test.dart+++ b/mobile/test/e2ee/relay_session_crypto_test.dart@@ -125,6 +125,25 @@ void main() {expect(session.ready, isFalse);});+ test('a signed welcome over a malformed key is refused, not thrown', () async {+ final session = await client();+ final hello = session.helloFrame()['payload'] as Map<String, dynamic>;+ final webEphPub = b64d(hello['ephPub'] as String);+ final shortKey = List.filled(31, 9);+ final sig = await machineIdentity.sign(+ lvCat(['e2e-welcome-v1', machineId, webEphPub, shortKey]),+ );+ expect(+ await session.handleWelcome({+ 'ephPub': b64e(shortKey),+ 'sig': b64e(sig),+ 'enc': b64e(List.filled(40, 1)),+ }),+ isFalse,+ );+ expect(session.ready, isFalse);+ });+// ⚠️ A welcome is signed, but nothing in it is fresh: the relay can hand the same one back at// any time. Taken twice, it reset the group key to the one it carried, undoing the rekey the// machine sent when it revoked a client — and that client still holds the old key.diff --git a/mobile/test/viewer/viewer_services_test.dart b/mobile/test/viewer/viewer_services_test.dartnew file mode 100644index 000000000..584b86d56--- /dev/null+++ b/mobile/test/viewer/viewer_services_test.dart@@ -0,0 +1,99 @@+import 'package:flutter_test/flutter_test.dart';++import 'package:harness_mobile/auth/auth_session.dart';+import 'package:harness_mobile/core/config.dart';+import 'package:harness_mobile/viewer/direct_auth_api.dart';+import 'package:harness_mobile/viewer/viewer_key_store.dart';+import 'package:harness_mobile/viewer/viewer_services.dart';+import 'package:harness_mobile/ws/terminal_transport_plugin.dart';++import '../voice_fakes.dart' show MemoryKeyValueStore;++/// What a phone runs in place of the harness CLI, built once — and the parts of the CLI's+/// sign-in contract a phone still answers (whether it is signed in; signing out).+void main() {+ const config = AppConfig(+ apiBaseUrl: 'https://h.invalid',+ autonomousEnv: 'stag',+ );++ test('one session and one key store behind every service', () async {+ final session = AuthSession(storage: MemoryKeyValueStore());+ final keys = ViewerKeyStore(storage: MemoryKeyValueStore());+ final services = ViewerServices(+ config: config,+ session: session,+ keys: keys,+ );++ expect(services.keys, same(keys));+ expect(services.auth.session, same(session));+ expect(services.login.auth, same(services.auth));+ expect(services.emailLogin.auth, same(services.auth));+ expect(services.links.keys, same(keys));+ expect(services.links.config.autonomousEnv, 'stag');+ // No machine linked yet: nothing to open a session with.+ expect(await services.relayCodecs('m'), isNull);+ });++ test('the second wire is the one main() set, unless one is given', () {+ final session = AuthSession(storage: MemoryKeyValueStore());+ final keys = ViewerKeyStore(storage: MemoryKeyValueStore());+ final previous = harnessTransportPlugins;+ addTearDown(() => harnessTransportPlugins = previous);++ harnessTransportPlugins = null;+ expect(+ ViewerServices(+ config: config,+ session: session,+ keys: keys,+ ).transportPlugins,+ isNull,+ );++ TerminalTransportPlugin set(TerminalTransportHost host, String id) =>+ throw UnimplementedError();+ TerminalTransportPlugin given(TerminalTransportHost host, String id) =>+ throw UnimplementedError();+ harnessTransportPlugins = set;+ expect(+ ViewerServices(+ config: config,+ session: session,+ keys: keys,+ ).transportPlugins,+ same(set),+ );+ expect(+ ViewerServices(+ config: config,+ session: session,+ keys: keys,+ transportPlugins: given,+ ).transportPlugins,+ same(given),+ );+ });++ group('the sign-in client', () {+ test('is signed in exactly when a token is saved', () async {+ final session = AuthSession(storage: MemoryKeyValueStore());+ final login = ViewerServices(+ config: config,+ session: session,+ keys: ViewerKeyStore(storage: MemoryKeyValueStore()),+ ).login;+ expect((await login.checkStatus()).loggedIn, isFalse);+ await login.auth.signIn(const IssuedTokens(token: 't'));+ expect((await login.checkStatus()).loggedIn, isTrue);++ // Cancelling with nothing in progress is nothing.+ login.cancel();++ await login.logout();+ expect((await login.checkStatus()).loggedIn, isFalse);+ expect(await session.accessToken(), isNull);+ });+ });+}