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.

1.3 KB
Raw Blame
import 'dart:async';
import 'dart:io';

import 'package:flutter_test/flutter_test.dart';
import 'package:harness_mobile/core/harness_file_store.dart';

import 'temp_folder.dart';

/// Runs before every test file under `test/`.
///
/// ⚠️ **Every default path points into a throwaway home.** The app's stores,
/// logs, crash log and snapshots all resolve under
/// `~/.harness` through [HarnessFileStore.defaultDirectoryPath], and a test
/// that builds the app without handing each one a fake would otherwise read and
/// write the developer's real state — sessions and E2EE keys included. See the
/// rules in `mobile/README.md`.
Future<void> testExecutable(FutureOr<void> Function() testMain) async {
  HttpOverrides.global = _NoNetwork();
  final home = Directory.systemTemp.createTempSync('harness-test-home-');
  HarnessFileStore.homeForTest = home.path;
  // Hosts built without a Home or kept chats of their own keep them here, in
  // the background, so the last test's can still be landing.
  tearDownAll(() => deleteTempFolder(home));
  await testMain();
}

class _NoNetwork extends HttpOverrides {
  @override
  HttpClient createHttpClient(SecurityContext? context) => throw StateError(
    'Network is disabled in tests. Inject an in-memory transport.',
  );
}