Loading files
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/core/models.dart';
import 'package:harness/state/swarm_navigation.dart';
import 'package:harness/state/swarm_search.dart';
import 'package:harness/widgets/engine_identity.dart';
import 'package:harness/widgets/box_chrome.dart' show kBoxFaint;
import 'package:harness/terminal/terminal_text.dart';
import 'package:harness/widgets/new_harness_form.dart';
import 'package:harness/widgets/swarm_switcher.dart';
import 'keymap_host_test.dart' show MemoryKeymap, key;
import 'keymap_runtime_test.dart' as configured;
import 'support/launch_menu.dart';
import 'support/mixed_agents.dart';
import 'swarm_screen_test.dart' show terminal;
import 'swarm_state_test.dart' show createApp;
void main() {
setUp(() => newHarnessOpensInBox = true);
tearDown(() => newHarnessOpensInBox = false);
testWidgets('setup rows edit in place and only the launch action starts', (
tester,
) async {
final app = createApp();
seedMixedAgents(app);
final map = MemoryKeymap();
addTearDown(app.dispose);
addTearDown(map.dispose);
app.adoptSessionForTest(terminal('a0', []));
await configured.mount(tester, app, map);
await key(tester, LogicalKeyboardKey.keyN, cmd: true);
final box = tester
.widget<NewHarnessForm>(find.byType(NewHarnessForm))
.controller;
await openLaunchRow(tester, 'agent');
await typeHarnessQuery(tester, 'Claude Code');
await key(tester, LogicalKeyboardKey.enter);
expect(box.engine, 'claude');
expect(app.panes, hasLength(1));
await openLaunchRow(tester, 'approvals');
await typeHarnessQuery(tester, 'Ask first');
await key(tester, LogicalKeyboardKey.enter);
expect(box.mode, 'ask');
expect(app.panes, hasLength(1));
await key(tester, LogicalKeyboardKey.escape);
expect(find.byType(NewHarnessForm), findsNothing);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
});
testWidgets(
'session context and activity are visible beside a distinct create action',
(tester) async {
final app = createApp();
final map = MemoryKeymap();
addTearDown(app.dispose);
addTearDown(map.dispose);
seedMixedAgents(app);
final previous = app.machineStates['m']!.agents.first;
app.machineStates['m']!.agents = [
Agent(
id: previous.id,
name: previous.name,
engine: previous.engine,
project: previous.project,
terminalAvailable: true,
lastActivityAt: DateTime.now().subtract(const Duration(minutes: 33)),
),
...app.machineStates['m']!.agents.skip(1),
];
await configured.mount(tester, app, map);
await key(tester, LogicalKeyboardKey.keyO, cmd: true);
final row = find.byKey(ValueKey(agentDestinationId('m', 'a0')));
expect(tester.widget<ListTile>(row).leading, isA<EngineMark>());
for (final value in [
'M2',
'openharness',
'feature/login-redirect',
'33m',
]) {
expect(
find.descendant(of: row, matching: find.text(value)),
findsOneWidget,
);
}
for (final label in ['M2', 'openharness', 'feature/login-redirect']) {
final text = tester.widget<Text>(
find.descendant(of: row, matching: find.text(label)),
);
expect(text.style!.fontFamily, terminalFontStore.value.fontFamily);
expect(text.style!.fontSize, terminalFontStore.size);
expect(text.style!.height, terminalFontStore.value.height);
expect(text.style!.color, kBoxFaint);
}
final create = tester.widget<ListTile>(
find.byKey(const ValueKey(kSwarmCreateRowId)),
);
expect(create.leading, isA<Icon>());
expect(find.text('Harness:'), findsNothing);
expect(find.byKey(const ValueKey('swarm-search-hints')), findsNothing);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
},
);
for (final size in [const Size(1280, 800), const Size(600, 700)]) {
testWidgets(
'Open Harness stays minimal and keeps its frame while filtering at $size',
(tester) async {
final app = createApp();
final map = MemoryKeymap();
addTearDown(app.dispose);
addTearDown(map.dispose);
final pane = app.adoptSessionForTest(terminal('a0', []));
await configured.mount(tester, app, map);
tester.view.physicalSize = size;
await tester.pump();
final paneBounds = tester.getRect(find.byKey(pane.cellKey));
await key(tester, LogicalKeyboardKey.keyO, cmd: true);
final panel = find.byKey(const ValueKey('swarm-search-results'));
final input = find.byKey(const ValueKey('swarm-search-input'));
final count = find.byKey(const ValueKey('swarm-search-count'));
final bounds = tester.getRect(panel);
expect(tester.widget<TextField>(input).cursorWidth, greaterThan(2));
expect(find.text('>'), findsOneWidget);
expect(find.text('Harness:'), findsNothing);
expect(find.text('[ New Harness ]'), findsNothing);
expect(find.text('Select Item'), findsNothing);
expect(find.byKey(const ValueKey('swarm-search-hints')), findsNothing);
final search = tester
.widget<SwarmSearchResults>(find.byType(SwarmSearchResults))
.search;
expect(search.rows.first.isCreate, isTrue);
await key(tester, LogicalKeyboardKey.tab);
expect(tester.widget<TextField>(input).focusNode!.hasFocus, isTrue);
await tester.enterText(input, 'nothing-like-this');
await tester.pump();
expect(search.rows.single.isCreate, isTrue);
expect(tester.getRect(panel), bounds);
expect(count, findsNothing);
expect(tester.getRect(find.byKey(pane.cellKey)), paneBounds);
expect(find.text('New Harness'), findsOneWidget);
await key(tester, LogicalKeyboardKey.escape);
expect(panel, findsNothing);
expect(tester.takeException(), isNull);
// Let the terminal's resize debounce settle before disposing the fixture.
await tester.pump(const Duration(milliseconds: 60));
await tester.pumpWidget(const SizedBox());
},
);
}
}
59e2a9d01This file is pinned to the selected release. Download the original to open it in your design tool.