feat(workspace): refresh desktop editing experience and prepare 0.1.2
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
Gitea CI / Build Android APK (pull_request) Canceled after 0s
Gitea CI / Build Windows x64 app (pull_request) Canceled after 0s
Gitea CI / Audit and package Windows x64 (pull_request) Canceled after 0s
Gitea CI / Assemble and validate CI artifacts (pull_request) Canceled after 0s
Gitea CI / Gitea CI passed (pull_request) Canceled after 0s
Gitea CI / Check code and tests (pull_request) Canceled after 6m29s
This commit is contained in:
1 parent
aa5255d1e4
commit
2e0033ce2d
260 files changed
+43963
-5591
No files matched your search
@@ -0,0 +1,334 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:cutdex/app/editor_theme.dart';
|
||||
import 'package:cutdex/features/projects/conversation_sidebar.dart';
|
||||
import 'package:cutdex/features/projects/project_sidebar.dart';
|
||||
import 'package:cutdex/integrations/agent/conversation_repository.dart';
|
||||
import 'package:cutdex/l10n/app_localizations.dart';
|
||||
import 'package:cutdex/workspace/project_state.dart';
|
||||
import 'package:cutdex/workspace/projects.dart';
|
||||
import 'package:cutdex/workspace/workspace_mode.dart';
|
||||
import 'package:cutdex_sdk/project.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'missing conversation timeline still allows the project default',
|
||||
(tester) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await tester.pump();
|
||||
sidebar.projects.opened.complete(false);
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 2);
|
||||
sidebar.projects._publish(_recent[1], timelineId: 'default');
|
||||
expect(sidebar.projects._openGuards.last!(), isTrue);
|
||||
sidebar.projects._fallbackOpened.complete(true);
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.conversations.activated, ['chat']);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('project change invalidates a still mounted sidebar request', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.projects._publish(_recent[2]);
|
||||
await tester.pump();
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'returning to the source project does not revive old navigation',
|
||||
(tester) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.projects._publish(_recent[2]);
|
||||
sidebar.projects._publish(_recent[0]);
|
||||
await tester.pump();
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('timeline change invalidates a pending conversation selection', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar(activeProject: _recent[1]);
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.projects._publish(_recent[1], timelineId: 'other');
|
||||
await tester.pump();
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'latest conversation wins when selection saves finish in reverse',
|
||||
(tester) async {
|
||||
final sidebar = _Sidebar(activeProject: _recent[1]);
|
||||
await sidebar.mount(tester);
|
||||
final first = sidebar.select(tester);
|
||||
final second = sidebar.select(tester, id: 'next');
|
||||
sidebar.conversations.nextRemembered.complete();
|
||||
await expectLater(second, completes);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(first, completes);
|
||||
expect(sidebar.conversations.activated, ['next']);
|
||||
expect(sidebar.navigationCompletions, 1);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('navigation allows the project transition it requested', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 1);
|
||||
expect(sidebar.projects._openGuards.single!(), isTrue);
|
||||
sidebar.projects._publish(_recent[1], timelineId: 'timeline');
|
||||
sidebar.projects.opened.complete(true);
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.conversations.activated, ['chat']);
|
||||
expect(sidebar.modes, [WorkspaceMode.agent]);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('removed sidebar stops navigation after remembering selection', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
await tester.pump();
|
||||
await tester.pumpWidget(sidebar.host(const SizedBox()));
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('removed sidebar does not retry a failed project open', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar();
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 1);
|
||||
await tester.pumpWidget(sidebar.host(const SizedBox()));
|
||||
expect(sidebar.projects._openGuards.single!(), isFalse);
|
||||
sidebar.projects.opened.complete(false);
|
||||
await expectLater(operation, completes);
|
||||
expect(sidebar.projects._openCalls, 1);
|
||||
expect(sidebar.conversations.activated, isEmpty);
|
||||
expect(sidebar.modes, isEmpty);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
|
||||
testWidgets('mounted sidebar still activates the selected conversation', (
|
||||
tester,
|
||||
) async {
|
||||
final sidebar = _Sidebar(activeProject: _recent[1]);
|
||||
await sidebar.mount(tester);
|
||||
final operation = sidebar.select(tester);
|
||||
sidebar.conversations.remembered.complete();
|
||||
await expectLater(operation, completes);
|
||||
await tester.pump();
|
||||
expect(sidebar.projects._openCalls, 0);
|
||||
expect(sidebar.conversations.activated, ['chat']);
|
||||
expect(sidebar.modes, [WorkspaceMode.agent]);
|
||||
expect(sidebar.navigationCompletions, 1);
|
||||
expect(tester.takeException(), isNull);
|
||||
await tester.pumpWidget(const SizedBox());
|
||||
});
|
||||
}
|
||||
|
||||
const _recent = [
|
||||
RecentProject(id: 'a', name: 'A', path: '/a'),
|
||||
RecentProject(id: 'b', name: 'B', path: '/b'),
|
||||
RecentProject(id: 'c', name: 'C', path: '/c'),
|
||||
];
|
||||
|
||||
class _Sidebar {
|
||||
_Sidebar({
|
||||
RecentProject activeProject = const RecentProject(
|
||||
id: 'a',
|
||||
name: 'A',
|
||||
path: '/a',
|
||||
),
|
||||
}) {
|
||||
initial = ProjectState(activeProject: activeProject, recent: _recent);
|
||||
projects = _Projects(initial);
|
||||
conversations = _Conversations(item);
|
||||
container = ProviderContainer(
|
||||
overrides: [
|
||||
projectsProvider.overrideWith(() => projects),
|
||||
conversationSidebarProvider.overrideWith(() => conversations),
|
||||
conversationSelectionProvider.overrideWith2((_) => _Selected()),
|
||||
],
|
||||
);
|
||||
addTearDown(container.dispose);
|
||||
}
|
||||
|
||||
late final ProjectState initial;
|
||||
late final _Projects projects;
|
||||
late final _Conversations conversations;
|
||||
late final ProviderContainer container;
|
||||
final modes = <WorkspaceMode>[];
|
||||
int navigationCompletions = 0;
|
||||
final item = ConversationMetadata(
|
||||
id: 'chat',
|
||||
projectId: 'b',
|
||||
title: 'Chat',
|
||||
createdAt: DateTime.utc(2026),
|
||||
updatedAt: DateTime.utc(2026),
|
||||
providerId: 'provider',
|
||||
modelId: 'model',
|
||||
timelineId: 'timeline',
|
||||
pending: false,
|
||||
responseDurationsMs: const [],
|
||||
);
|
||||
|
||||
Future<void> select(WidgetTester tester, {String id = 'chat'}) {
|
||||
final row = tester.widget<InkWell>(
|
||||
find.byKey(ValueKey('sidebar-conversation-$id')),
|
||||
);
|
||||
// InkWell declares a void callback, but navigation returns a future.
|
||||
// Await that operation so async lifecycle exceptions fail this test.
|
||||
return Function.apply(row.onTap!, []) as Future<void>;
|
||||
}
|
||||
|
||||
Widget host(Widget child) => UncontrolledProviderScope(
|
||||
container: container,
|
||||
child: MaterialApp(
|
||||
theme: EditorTheme.desktop(EditorTheme.penLight),
|
||||
localizationsDelegates: AppLocalizations.localizationsDelegates,
|
||||
supportedLocales: AppLocalizations.supportedLocales,
|
||||
locale: const Locale('zh'),
|
||||
home: Scaffold(body: SizedBox(width: 350, child: child)),
|
||||
),
|
||||
);
|
||||
|
||||
Future<void> mount(WidgetTester tester) async {
|
||||
await container.read(projectsProvider.future);
|
||||
await container.read(conversationSidebarProvider.future);
|
||||
await tester.pumpWidget(
|
||||
host(
|
||||
ProjectSidebar(
|
||||
agent: const SizedBox(),
|
||||
navigationOnly: true,
|
||||
mode: WorkspaceMode.agent,
|
||||
onModeChanged: modes.add,
|
||||
onNavigationComplete: () => navigationCompletions++,
|
||||
navigationWidth: 350,
|
||||
navigationCollapsed: false,
|
||||
agentHeaderLeading: const SizedBox(),
|
||||
editorHidden: false,
|
||||
onExpandEditor: null,
|
||||
state: initial,
|
||||
selectedProjectId: initial.activeProject!.id,
|
||||
integratedTitlebar: false,
|
||||
onCreateProject: null,
|
||||
onSelectProject: null,
|
||||
onRenameProject: (_) async => false,
|
||||
headerControls: const SizedBox(),
|
||||
),
|
||||
),
|
||||
);
|
||||
await tester.pumpAndSettle();
|
||||
}
|
||||
}
|
||||
|
||||
class _Projects extends Projects {
|
||||
_Projects(this.initial);
|
||||
final ProjectState initial;
|
||||
final opened = Completer<bool>();
|
||||
final _fallbackOpened = Completer<bool>();
|
||||
int _openCalls = 0;
|
||||
final _openGuards = <bool Function()?>[];
|
||||
|
||||
void _publish(RecentProject project, {String? timelineId}) {
|
||||
state = AsyncData(
|
||||
state.requireValue.copyWith(
|
||||
activeProject: project,
|
||||
timeline: timelineId == null
|
||||
? null
|
||||
: TimelineDocument(id: timelineId, name: timelineId, sequences: []),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ProjectState> build() async => initial;
|
||||
|
||||
@override
|
||||
Future<bool> open(
|
||||
String path, {
|
||||
String? name,
|
||||
String? expectedId,
|
||||
String? timelineId,
|
||||
String? initialTimelineName,
|
||||
bool Function()? isCurrent,
|
||||
}) {
|
||||
_openCalls++;
|
||||
_openGuards.add(isCurrent);
|
||||
return _openCalls == 1 ? opened.future : _fallbackOpened.future;
|
||||
}
|
||||
}
|
||||
|
||||
class _Selected extends ConversationSelection {
|
||||
@override
|
||||
ConversationSelectionState build(String? projectId) =>
|
||||
const ConversationSelectionState(draftKey: 'draft', initialized: true);
|
||||
}
|
||||
|
||||
class _Conversations extends ConversationSidebar {
|
||||
_Conversations(this.item);
|
||||
final ConversationMetadata item;
|
||||
final remembered = Completer<void>();
|
||||
final nextRemembered = Completer<void>();
|
||||
final activated = <String>[];
|
||||
|
||||
@override
|
||||
Future<ConversationSnapshot> build() async => ConversationSnapshot(
|
||||
groups: {
|
||||
'b': [item, item.copyWith(id: 'next')],
|
||||
},
|
||||
);
|
||||
|
||||
@override
|
||||
Future<void> rememberSelection(ConversationMetadata item) =>
|
||||
item.id == 'next' ? nextRemembered.future : remembered.future;
|
||||
|
||||
@override
|
||||
void activate(ConversationMetadata item) => activated.add(item.id);
|
||||
}
|
||||
Reference in new issue
Block a user