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.

4.9 KB
Raw Blame
import 'dart:io';

import 'package:flutter_test/flutter_test.dart';
import 'package:harness_mobile/swarm/swarm_buddy.dart';

/// The Swarm models the phone carries as copies of the desktop's
/// (`../desktop/lib/super_tabs`): phone path → desktop path. The phone is a
/// standalone package (README), so it cannot import them.
///
/// ⚠️ A fix made to one side only fails nowhere else: a field the backend adds
/// would parse on a computer and be dropped on the phone. Here a drift fails
/// until the change is carried across — or, if the two are meant to differ now,
/// until the file leaves this list on purpose.
const _copies = {
  'lib/swarm/parts.dart': 'lib/super_tabs/parts.dart',
  'lib/swarm/tasks/personal_tasks.dart':
      'lib/super_tabs/tasks/personal_tasks.dart',
  'lib/swarm/profile_model.dart': 'lib/super_tabs/profile_model.dart',
  // Live cards (Slack parity, #2212): which messages are cards, and the
  // linked tasks a card shows. The phone reads no GitHub yet (Lead, 10-29:
  // that request is a security change of its own), so Desktop's PR facts
  // reader has no copy here.
  'lib/swarm/live_card_model.dart': 'lib/super_tabs/live_card_model.dart',
  'lib/swarm/linked_tasks.dart': 'lib/super_tabs/linked_tasks.dart',
  // Task steps design: a task's steps and its merged chat.
  'lib/swarm/task_steps.dart': 'lib/super_tabs/task_steps.dart',
  'lib/swarm/instructions_model.dart': 'lib/super_tabs/instructions_model.dart',
  // Board pulse (task #3384): what waits for the PM and who works.
  'lib/swarm/pulse_model.dart': 'lib/super_tabs/pulse.dart',
};

/// The phone's model is ahead of main's desktop copy, so it is no exact copy
/// for now: it also keeps a read's lookups by id, cached once per read, and
/// each conversation's reaction counter (`reactionSeq`), which the phone's
/// chat needs and the desktop's model has not taken yet (the phone line,
/// merged into main without its desktop changes, 10-29). It still reads
/// every field the desktop's does, so nothing the backend adds is parsed on
/// a computer and dropped on the phone. Back in [_copies] once the desktop's
/// model carries them.
///
/// Chat threads (#2132): the phone reads a message's thread and the thread
/// summaries as the desktop does, and draws them as it does (Tony, option B,
/// 10-29): the line under a root, a reply only in its thread out of the chat,
/// and the thread on a screen of its own. Unread and bold follow the
/// desktop's main-stream rule (`lastMainSequence`,
/// [SuperTabConversation.mainSequence]) on both.
const _model = ('lib/swarm/model.dart', 'lib/super_tabs/model.dart');

void main() {
  test("${_model.$1} reads every field the desktop's ${_model.$2} reads", () {
    final reads = RegExp(
      r"(?:row|start|json)\['(\w+)'\]|_text\(row, '(\w+)'\)",
    );
    Set<String> fields(String path) => {
      for (final m in reads.allMatches(File(path).readAsStringSync()))
        (m.group(1) ?? m.group(2))!,
    };
    final desktop = fields('../desktop/${_model.$2}');
    expect(desktop, isNotEmpty);
    expect(desktop.difference(fields(_model.$1)), isEmpty);
  });

  test('the phone offers a Buddy the desktop\'s engines, none turned off', () {
    // Codex is offered as Claude is since #2832 (Ken, 11-04): neither side
    // keeps a list of refused engines.
    final desktop = File(
      '../desktop/lib/super_tabs/buddies.dart',
    ).readAsStringSync();
    final engines = RegExp(
      r"kBuddyEngines = \{((?:\s*'\w+':\s*'[^']*',?)*)\s*\}",
    ).firstMatch(desktop)!.group(1)!;
    expect(swarmBuddyEngines, {
      for (final m in RegExp(r"'(\w+)':\s*'([^']*)'").allMatches(engines))
        m.group(1)!: m.group(2)!,
    });
    expect(desktop, isNot(contains('kBuddyEngineRefusals')));
  });

  test('the phone names a sent message as the desktop does', () {
    // The phone matches a post to its row by this id (swarm_outbox.dart); a
    // drift shows a second copy that never leaves (Dee, 11-01).
    final function = RegExp(
      r'String superTabMessageId\(\{[\s\S]*?\.substring\(0, 24\);',
    );
    String of(String path) =>
        function.firstMatch(File(path).readAsStringSync())!.group(0)!;
    expect(
      of('lib/swarm/swarm_outbox.dart'),
      of('../desktop/lib/super_tabs/controller.dart'),
    );
  });

  for (final MapEntry(key: phone, value: desktop) in _copies.entries) {
    test("$phone matches the desktop's $desktop", () {
      final source = File('../desktop/$desktop');
      if (!source.existsSync()) {
        throw StateError(
          '${source.path} missing — run from mobile/ in the monorepo',
        );
      }
      final copy = File(phone);
      expect(copy.existsSync(), isTrue, reason: '$phone is missing');
      expect(
        copy.readAsStringSync(),
        source.readAsStringSync(),
        reason:
            'carry the change to both copies (or drop the pair from '
            'test/swarm/desktop_parity_test.dart if they are meant to differ)',
      );
    });
  }
}