Merge branch 'main' into pipelines/run-20261113-1324-centre-a-lone-more-button-in-narrow-chat-d027
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/application/open_in_chat.dart';
|
||||
import 'package:pipelines_app/application/open_in_chat_preferences.dart';
|
||||
import 'package:pipelines_app/features/chat/chat_runtime.dart';
|
||||
import 'package:pipelines_app/features/chat/ui/sessions/chat_create_fields.dart';
|
||||
import 'package:pipelines_app/features/pipelines/pipeline_models.dart';
|
||||
@@ -18,6 +20,75 @@ import '../features/pipelines/fixtures.dart';
|
||||
import '../features/pipelines/test_helpers.dart';
|
||||
|
||||
void main() {
|
||||
setUp(() => SharedPreferences.setMockInitialValues({}));
|
||||
|
||||
testWidgets('the harness and model chosen in Settings start the chat', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final gateway = FakeChatGateway()
|
||||
..backendsHandler = () async => const {
|
||||
'chat_backends': ['opencode', 'claude'],
|
||||
};
|
||||
await const OpenInChatPreferences(
|
||||
harness: 'claude',
|
||||
provider: 'anthropic',
|
||||
model: 'claude-opus-5-5',
|
||||
).save(gateway);
|
||||
final runtime = ChatRuntime(gateway: gateway);
|
||||
|
||||
await tester.pumpWidget(const MaterialApp(home: Scaffold()));
|
||||
await openReferenceInChat(
|
||||
context: tester.element(find.byType(Scaffold)),
|
||||
runtime: runtime,
|
||||
selectChat: (_) {},
|
||||
directory: '/work/run',
|
||||
title: 'Run #42: Build',
|
||||
draft: 'About Pipelines run #42.',
|
||||
);
|
||||
|
||||
final create = gateway.lastFields('chat_create')!['chat_create'] as Map;
|
||||
expect(create['backend'], 'claude');
|
||||
final model = gateway.lastFields('chat_model')!['chat_model'] as Map;
|
||||
expect(model['session_id'], 'created');
|
||||
expect(model['provider'], 'anthropic');
|
||||
expect(model['model'], 'claude-opus-5-5');
|
||||
// Opened for work: beside the active chat, with the keyboard in it.
|
||||
expect(runtime.openedForWork, contains('created'));
|
||||
runtime.dispose();
|
||||
});
|
||||
|
||||
testWidgets('a harness the server no longer offers falls back to the '
|
||||
'default, without the saved model', (tester) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final gateway = FakeChatGateway()
|
||||
..backendsHandler = () async => const {
|
||||
'chat_backends': ['opencode', 'codex'],
|
||||
};
|
||||
await const OpenInChatPreferences(
|
||||
harness: 'claude',
|
||||
provider: 'anthropic',
|
||||
model: 'claude-opus-5-5',
|
||||
).save(gateway);
|
||||
final runtime = ChatRuntime(gateway: gateway);
|
||||
|
||||
await tester.pumpWidget(const MaterialApp(home: Scaffold()));
|
||||
await openReferenceInChat(
|
||||
context: tester.element(find.byType(Scaffold)),
|
||||
runtime: runtime,
|
||||
selectChat: (_) {},
|
||||
directory: '/work/run',
|
||||
title: 'Run #42: Build',
|
||||
draft: 'About Pipelines run #42.',
|
||||
);
|
||||
|
||||
final create = gateway.lastFields('chat_create')!['chat_create'] as Map;
|
||||
// The default harness (OpenCode) is the request's default: not claude.
|
||||
expect(create['backend'], anyOf(isNull, 'opencode'));
|
||||
expect(gateway.lastFields('chat_model'), isNull);
|
||||
runtime.dispose();
|
||||
});
|
||||
|
||||
test('a run summary names its pipeline in name', () {
|
||||
final draft = runChatReference({
|
||||
'id': 7,
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/chat/chat_runtime.dart';
|
||||
import 'package:pipelines_app/features/chat/screen.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace.dart';
|
||||
import 'package:pipelines_app/features/chat/workspace/chat_workspace_store.dart';
|
||||
|
||||
import 'conversation/chat_thread_fixtures.dart';
|
||||
|
||||
class _Gateway extends FakeChatGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) {
|
||||
if (type == 'chat_sessions') {
|
||||
return Future.value({
|
||||
'chat_sessions': [
|
||||
for (final id in ['a', 'b', 'new'])
|
||||
{'id': id, 'title': 'Chat $id', 'directory': '/home/$id'},
|
||||
],
|
||||
});
|
||||
}
|
||||
if (type == 'chat_shells') return Future.value({'chat_shells': []});
|
||||
return super.call(type, fields);
|
||||
}
|
||||
}
|
||||
|
||||
ChatWorkspaceController _workspace(WidgetTester tester) => tester
|
||||
.widget<ChatWorkspace>(find.byType(ChatWorkspace, skipOffstage: false))
|
||||
.controller;
|
||||
|
||||
void main() {
|
||||
testWidgets('a chat opened for work goes beside the active chat, becomes '
|
||||
'active and takes the keyboard', (tester) async {
|
||||
final layout = ChatWorkspaceController()..open('a');
|
||||
SharedPreferences.setMockInitialValues({
|
||||
chatWorkspacePreferenceKey: layout.snapshot()!.encode(),
|
||||
});
|
||||
tester.view.physicalSize = const Size(1600, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
addTearDown(gateway.close);
|
||||
final runtime = ChatRuntime(gateway: gateway);
|
||||
addTearDown(runtime.dispose);
|
||||
|
||||
Widget screen(String? routed) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatScreen(
|
||||
gateway: gateway,
|
||||
runtime: runtime,
|
||||
persistWorkspace: true,
|
||||
initialSessionId: routed,
|
||||
onSessionSelected: (_) {},
|
||||
onBack: () {},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.pumpWidget(screen('a'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_workspace(tester).panes.map((p) => p.sessionId), ['a']);
|
||||
|
||||
runtime.openedForWork.add('new');
|
||||
await tester.pumpWidget(screen('new'));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
final workspace = _workspace(tester);
|
||||
expect(workspace.panes.map((p) => p.sessionId), ['a', 'new']);
|
||||
expect(workspace.activePane?.sessionId, 'new');
|
||||
expect(runtime.openedForWork, isEmpty);
|
||||
final composer = tester
|
||||
.widgetList<EditableText>(
|
||||
find.descendant(
|
||||
of: find.byKey(const ValueKey('chat-composer-new')),
|
||||
matching: find.byType(EditableText),
|
||||
),
|
||||
)
|
||||
.first;
|
||||
expect(composer.focusNode.hasFocus, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('an ordinary routed chat still opens in the active pane', (
|
||||
tester,
|
||||
) async {
|
||||
final layout = ChatWorkspaceController()..open('a');
|
||||
SharedPreferences.setMockInitialValues({
|
||||
chatWorkspacePreferenceKey: layout.snapshot()!.encode(),
|
||||
});
|
||||
tester.view.physicalSize = const Size(1600, 1000);
|
||||
tester.view.devicePixelRatio = 1;
|
||||
addTearDown(tester.view.reset);
|
||||
final gateway = _Gateway()..history = (_) async => chatPage([]);
|
||||
addTearDown(gateway.close);
|
||||
final runtime = ChatRuntime(gateway: gateway);
|
||||
addTearDown(runtime.dispose);
|
||||
Widget screen(String? routed) => MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ChatScreen(
|
||||
gateway: gateway,
|
||||
runtime: runtime,
|
||||
persistWorkspace: true,
|
||||
initialSessionId: routed,
|
||||
onSessionSelected: (_) {},
|
||||
onBack: () {},
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpWidget(screen('a'));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.pumpWidget(screen('b'));
|
||||
await tester.pumpAndSettle();
|
||||
expect(_workspace(tester).panes.map((p) => p.sessionId), ['b']);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:pipelines_app/application/open_in_chat_preferences.dart';
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
import 'package:pipelines_app/features/settings/settings_open_in_chat_section.dart';
|
||||
|
||||
import '../chat/ui/sessions/fake_chat_gateway.dart';
|
||||
|
||||
class _Gateway extends FakeChatGateway {
|
||||
@override
|
||||
Future<JsonMap> call(String type, [JsonMap fields = const {}]) async {
|
||||
switch (type) {
|
||||
case 'chat_backends':
|
||||
return {
|
||||
'chat_backends': ['opencode', 'claude'],
|
||||
};
|
||||
case 'chat_sessions':
|
||||
return {
|
||||
'chat_sessions': [
|
||||
{'id': 'old', 'backend': 'claude', 'updated_at': '2026-01-01'},
|
||||
{'id': 'new', 'backend': 'claude', 'updated_at': '2026-02-01'},
|
||||
],
|
||||
};
|
||||
case 'chat_models':
|
||||
final session = (fields['chat_query'] as Map)['session_id'];
|
||||
return {
|
||||
'chat_models': [
|
||||
{
|
||||
'id': 'claude-opus-5-5',
|
||||
'provider': 'anthropic',
|
||||
'name': 'Opus from $session',
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
return super.call(type, fields);
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('choosing a harness and model saves them for Open in chat', (
|
||||
tester,
|
||||
) async {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
final gateway = _Gateway();
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: SettingsOpenInChatSection(gateway: gateway),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Open in chat'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.byKey(const Key('open-in-chat-harness')));
|
||||
await tester.pumpAndSettle();
|
||||
await tester.tap(find.text('claude').last);
|
||||
await tester.pumpAndSettle();
|
||||
expect((await OpenInChatPreferences.load(gateway)).harness, 'claude');
|
||||
|
||||
// Models come from the harness's most recent chat.
|
||||
await tester.tap(find.byKey(const ValueKey('open-in-chat-model-claude')));
|
||||
await tester.pumpAndSettle();
|
||||
expect(find.text('Opus from new'), findsWidgets);
|
||||
await tester.tap(find.text('Opus from new').last);
|
||||
await tester.pumpAndSettle();
|
||||
final saved = await OpenInChatPreferences.load(gateway);
|
||||
expect(saved.provider, 'anthropic');
|
||||
expect(saved.model, 'claude-opus-5-5');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user