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.

3.0 KB
Raw Blame
import 'dart:ui' show SemanticsAction;

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:harness/state/new_harness.dart';
import 'package:harness/terminal/terminal_binary.dart';
import 'package:harness/widgets/new_harness_form.dart';

import 'keymap_host_test.dart' show MemoryKeymap, key;
import 'keymap_runtime_test.dart' show mount;
import 'support/mixed_agents.dart';
import 'support/launch_menu.dart' show harnessChoicesActive;
import 'swarm_screen_test.dart' show terminal;
import 'swarm_state_test.dart' show createApp;

void main() {
  testWidgets('New Harness defaults expose working accessibility actions', (
    tester,
  ) async {
    newHarnessOpensInBox = true;
    addTearDown(() => newHarnessOpensInBox = false);
    final app = createApp();
    seedMixedAgents(app);
    app.machineStates['m']!.localOnly = true;
    app.gitProjectReaderForTest = (_, _) async => {'isGit': false};
    await app.agentPreference.remember('codex');
    await app.projectHistory.select('m', '/work/openharness');
    final map = MemoryKeymap();
    final input = <TerminalBinaryFrame>[];
    app.adoptSessionForTest(terminal('a0', input));
    await mount(tester, app, map);
    final semantics = tester.ensureSemantics();
    await key(tester, LogicalKeyboardKey.keyN, cmd: true);
    final row = tester.getSemantics(find.bySemanticsLabel('Agent, Codex'));
    expect(row.getSemanticsData().hasAction(SemanticsAction.tap), isTrue);
    tester
        .renderObject(find.bySemanticsLabel('Agent, Codex'))
        .owner!
        .semanticsOwner!
        .performAction(row.id, SemanticsAction.tap);
    await tester.pump();
    expect(
      tester
          .widget<NewHarnessForm>(find.byType(NewHarnessForm))
          .controller
          .field,
      NewHarnessField.harness,
    );
    expect(input, isEmpty);
    // Pointer users can open the same choices and return to field navigation.
    await key(tester, LogicalKeyboardKey.escape);
    await tester.tap(find.byKey(const ValueKey('new-harness-field-agent')));
    await tester.pump();
    expect(harnessChoicesActive(tester), isTrue);
    await tester.tap(find.byKey(const ValueKey('new-harness-option-claude')));
    await tester.pump();
    final box = tester
        .widget<NewHarnessForm>(find.byType(NewHarnessForm))
        .controller;
    expect(box.engine, 'claude');
    expect(harnessChoicesActive(tester), isFalse);
    // A choice returns to its originating accessible control.
    final agentButton = find.descendant(
      of: find.byKey(const ValueKey('new-harness-field-agent')),
      matching: find.byType(TextButton),
    );
    expect(tester.widget<TextButton>(agentButton).focusNode!.hasFocus, isTrue);
    await tester.tap(find.byKey(const ValueKey('new-harness-field-project')));
    expect(box.field, NewHarnessField.projectMenu);
    expect(input, isEmpty);
    semantics.dispose();
    await tester.pumpWidget(const SizedBox());
    app.dispose();
    map.dispose();
  });
}